X86Subtarget.cpp revision 263508
11541Srgrimes//===-- X86Subtarget.cpp - X86 Subtarget Information ----------------------===// 21541Srgrimes// 31541Srgrimes// The LLVM Compiler Infrastructure 41541Srgrimes// 51541Srgrimes// This file is distributed under the University of Illinois Open Source 61541Srgrimes// License. See LICENSE.TXT for details. 71541Srgrimes// 81541Srgrimes//===----------------------------------------------------------------------===// 91541Srgrimes// 101541Srgrimes// This file implements the X86 specific subclass of TargetSubtargetInfo. 111541Srgrimes// 121541Srgrimes//===----------------------------------------------------------------------===// 131541Srgrimes 141541Srgrimes#define DEBUG_TYPE "subtarget" 151541Srgrimes#include "X86Subtarget.h" 161541Srgrimes#include "X86InstrInfo.h" 171541Srgrimes#include "llvm/IR/Attributes.h" 181541Srgrimes#include "llvm/IR/Function.h" 191541Srgrimes#include "llvm/IR/GlobalValue.h" 201541Srgrimes#include "llvm/Support/Debug.h" 211541Srgrimes#include "llvm/Support/ErrorHandling.h" 221541Srgrimes#include "llvm/Support/Host.h" 231541Srgrimes#include "llvm/Support/raw_ostream.h" 241541Srgrimes#include "llvm/Target/TargetMachine.h" 251541Srgrimes#include "llvm/Target/TargetOptions.h" 261541Srgrimes 271541Srgrimes#define GET_SUBTARGETINFO_TARGET_DESC 281541Srgrimes#define GET_SUBTARGETINFO_CTOR 291541Srgrimes#include "X86GenSubtargetInfo.inc" 301541Srgrimes 311541Srgrimesusing namespace llvm; 321541Srgrimes 331541Srgrimes#if defined(_MSC_VER) 3413228Swollman#include <intrin.h> 351541Srgrimes#endif 361541Srgrimes 371541Srgrimes/// ClassifyBlockAddressReference - Classify a blockaddress reference for the 381541Srgrimes/// current subtarget according to how we should reference it in a non-pcrel 391541Srgrimes/// context. 401541Srgrimesunsigned char X86Subtarget::ClassifyBlockAddressReference() const { 4113228Swollman if (isPICStyleGOT()) // 32-bit ELF targets. 4213228Swollman return X86II::MO_GOTOFF; 431541Srgrimes 441541Srgrimes if (isPICStyleStubPIC()) // Darwin/32 in PIC mode. 451541Srgrimes return X86II::MO_PIC_BASE_OFFSET; 461541Srgrimes 471541Srgrimes // Direct static reference to label. 481541Srgrimes return X86II::MO_NO_FLAG; 491541Srgrimes} 501541Srgrimes 511541Srgrimes/// ClassifyGlobalReference - Classify a global variable reference for the 521541Srgrimes/// current subtarget according to how we should reference it in a non-pcrel 531541Srgrimes/// context. 541541Srgrimesunsigned char X86Subtarget:: 551541SrgrimesClassifyGlobalReference(const GlobalValue *GV, const TargetMachine &TM) const { 561541Srgrimes // DLLImport only exists on windows, it is implemented as a load from a 571541Srgrimes // DLLIMPORT stub. 581541Srgrimes if (GV->hasDLLImportLinkage()) 591541Srgrimes return X86II::MO_DLLIMPORT; 601541Srgrimes 611541Srgrimes // Determine whether this is a reference to a definition or a declaration. 621541Srgrimes // Materializable GVs (in JIT lazy compilation mode) do not require an extra 631541Srgrimes // load from stub. 641541Srgrimes bool isDecl = GV->hasAvailableExternallyLinkage(); 651541Srgrimes if (GV->isDeclaration() && !GV->isMaterializable()) 661541Srgrimes isDecl = true; 671541Srgrimes 681541Srgrimes // X86-64 in PIC mode. 691541Srgrimes if (isPICStyleRIPRel()) { 701541Srgrimes // Large model never uses stubs. 711541Srgrimes if (TM.getCodeModel() == CodeModel::Large) 721541Srgrimes return X86II::MO_NO_FLAG; 731541Srgrimes 741541Srgrimes if (isTargetDarwin()) { 751541Srgrimes // If symbol visibility is hidden, the extra load is not needed if 763487Sphk // target is x86-64 or the symbol is definitely defined in the current 773487Sphk // translation unit. 781541Srgrimes if (GV->hasDefaultVisibility() && 791541Srgrimes (isDecl || GV->isWeakForLinker())) 801541Srgrimes return X86II::MO_GOTPCREL; 811541Srgrimes } else if (!isTargetWin64()) { 821541Srgrimes assert(isTargetELF() && "Unknown rip-relative target"); 831541Srgrimes 841541Srgrimes // Extra load is needed for all externally visible. 851541Srgrimes if (!GV->hasLocalLinkage() && GV->hasDefaultVisibility()) 861541Srgrimes return X86II::MO_GOTPCREL; 871541Srgrimes } 881541Srgrimes 898876Srgrimes return X86II::MO_NO_FLAG; 901541Srgrimes } 911541Srgrimes 921541Srgrimes if (isPICStyleGOT()) { // 32-bit ELF targets. 931541Srgrimes // Extra load is needed for all externally visible. 941541Srgrimes if (GV->hasLocalLinkage() || GV->hasHiddenVisibility()) 951541Srgrimes return X86II::MO_GOTOFF; 961541Srgrimes return X86II::MO_GOT; 971541Srgrimes } 981541Srgrimes 991541Srgrimes if (isPICStyleStubPIC()) { // Darwin/32 in PIC mode. 1001541Srgrimes // Determine whether we have a stub reference and/or whether the reference 1011541Srgrimes // is relative to the PIC base or not. 1021541Srgrimes 1031541Srgrimes // If this is a strong reference to a definition, it is definitely not 1041541Srgrimes // through a stub. 1051541Srgrimes if (!isDecl && !GV->isWeakForLinker()) 1061541Srgrimes return X86II::MO_PIC_BASE_OFFSET; 1071541Srgrimes 1081541Srgrimes // Unless we have a symbol with hidden visibility, we have to go through a 1091541Srgrimes // normal $non_lazy_ptr stub because this symbol might be resolved late. 1101541Srgrimes if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference. 1111541Srgrimes return X86II::MO_DARWIN_NONLAZY_PIC_BASE; 1121541Srgrimes 1131541Srgrimes // If symbol visibility is hidden, we have a stub for common symbol 1141541Srgrimes // references and external declarations. 1151541Srgrimes if (isDecl || GV->hasCommonLinkage()) { 1161541Srgrimes // Hidden $non_lazy_ptr reference. 1171541Srgrimes return X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE; 1181541Srgrimes } 1191541Srgrimes 1201541Srgrimes // Otherwise, no stub. 1211541Srgrimes return X86II::MO_PIC_BASE_OFFSET; 1221541Srgrimes } 12312911Sphk 1241541Srgrimes if (isPICStyleStubNoDynamic()) { // Darwin/32 in -mdynamic-no-pic mode. 1251541Srgrimes // Determine whether we have a stub reference. 1261541Srgrimes 1271541Srgrimes // If this is a strong reference to a definition, it is definitely not 1281541Srgrimes // through a stub. 1291541Srgrimes if (!isDecl && !GV->isWeakForLinker()) 1301541Srgrimes return X86II::MO_NO_FLAG; 1311541Srgrimes 1321541Srgrimes // Unless we have a symbol with hidden visibility, we have to go through a 1331541Srgrimes // normal $non_lazy_ptr stub because this symbol might be resolved late. 1341541Srgrimes if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference. 1351541Srgrimes return X86II::MO_DARWIN_NONLAZY; 1361541Srgrimes 1371541Srgrimes // Otherwise, no stub. 1381541Srgrimes return X86II::MO_NO_FLAG; 1391541Srgrimes } 14010551Sdyson 1411541Srgrimes // Direct static reference to global. 1421541Srgrimes return X86II::MO_NO_FLAG; 1431541Srgrimes} 1441541Srgrimes 1451541Srgrimes 1461541Srgrimes/// getBZeroEntry - This function returns the name of a function which has an 1471541Srgrimes/// interface like the non-standard bzero function, if such a function exists on 1481541Srgrimes/// the current subtarget and it is considered prefereable over memset with zero 1493487Sphk/// passed as the second argument. Otherwise it returns null. 1503487Sphkconst char *X86Subtarget::getBZeroEntry() const { 1513487Sphk // Darwin 10 has a __bzero entry point for this purpose. 1521541Srgrimes if (getTargetTriple().isMacOSX() && 1531541Srgrimes !getTargetTriple().isMacOSXVersionLT(10, 6)) 1541541Srgrimes return "__bzero"; 1551541Srgrimes 1561541Srgrimes return 0; 1571541Srgrimes} 1581541Srgrimes 1591541Srgrimesbool X86Subtarget::hasSinCos() const { 1601541Srgrimes return getTargetTriple().isMacOSX() && 1611541Srgrimes !getTargetTriple().isMacOSXVersionLT(10, 9) && 1621541Srgrimes is64Bit(); 1631541Srgrimes} 1641541Srgrimes 1651541Srgrimes/// IsLegalToCallImmediateAddr - Return true if the subtarget allows calls 1661541Srgrimes/// to immediate address. 1671541Srgrimesbool X86Subtarget::IsLegalToCallImmediateAddr(const TargetMachine &TM) const { 1681541Srgrimes if (In64BitMode) 1691541Srgrimes return false; 1701541Srgrimes return isTargetELF() || TM.getRelocationModel() == Reloc::Static; 1711541Srgrimes} 1721541Srgrimes 1731541Srgrimesstatic bool OSHasAVXSupport() { 1741541Srgrimes#if defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86)\ 1751541Srgrimes || defined(__x86_64__) || defined(_M_AMD64) || defined (_M_X64) 1761541Srgrimes#if defined(__GNUC__) 1771541Srgrimes // Check xgetbv; this uses a .byte sequence instead of the instruction 1781541Srgrimes // directly because older assemblers do not include support for xgetbv and 1791541Srgrimes // there is no easy way to conditionally compile based on the assembler used. 1801541Srgrimes int rEAX, rEDX; 1811541Srgrimes __asm__ (".byte 0x0f, 0x01, 0xd0" : "=a" (rEAX), "=d" (rEDX) : "c" (0)); 1821541Srgrimes#elif defined(_MSC_FULL_VER) && defined(_XCR_XFEATURE_ENABLED_MASK) 1831541Srgrimes unsigned long long rEAX = _xgetbv(_XCR_XFEATURE_ENABLED_MASK); 1841541Srgrimes#else 1851541Srgrimes int rEAX = 0; // Ensures we return false 1861541Srgrimes#endif 1871541Srgrimes return (rEAX & 6) == 6; 1881541Srgrimes#else 1891541Srgrimes return false; 1901541Srgrimes#endif 1911541Srgrimes} 1921541Srgrimes 1931541Srgrimesvoid X86Subtarget::AutoDetectSubtargetFeatures() { 1941541Srgrimes unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0; 1951541Srgrimes unsigned MaxLevel; 1961541Srgrimes union { 1971541Srgrimes unsigned u[3]; 1981541Srgrimes char c[12]; 1991541Srgrimes } text; 2001541Srgrimes 2011541Srgrimes if (X86_MC::GetCpuIDAndInfo(0, &MaxLevel, text.u+0, text.u+2, text.u+1) || 2021541Srgrimes MaxLevel < 1) 2031541Srgrimes return; 2041541Srgrimes 2051541Srgrimes X86_MC::GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX); 2061541Srgrimes 2071541Srgrimes if ((EDX >> 15) & 1) { HasCMov = true; ToggleFeature(X86::FeatureCMOV); } 2081541Srgrimes if ((EDX >> 23) & 1) { X86SSELevel = MMX; ToggleFeature(X86::FeatureMMX); } 2091541Srgrimes if ((EDX >> 25) & 1) { X86SSELevel = SSE1; ToggleFeature(X86::FeatureSSE1); } 2101541Srgrimes if ((EDX >> 26) & 1) { X86SSELevel = SSE2; ToggleFeature(X86::FeatureSSE2); } 2111541Srgrimes if (ECX & 0x1) { X86SSELevel = SSE3; ToggleFeature(X86::FeatureSSE3); } 2121541Srgrimes if ((ECX >> 9) & 1) { X86SSELevel = SSSE3; ToggleFeature(X86::FeatureSSSE3);} 2131541Srgrimes if ((ECX >> 19) & 1) { X86SSELevel = SSE41; ToggleFeature(X86::FeatureSSE41);} 2141541Srgrimes if ((ECX >> 20) & 1) { X86SSELevel = SSE42; ToggleFeature(X86::FeatureSSE42);} 2151541Srgrimes if (((ECX >> 27) & 1) && ((ECX >> 28) & 1) && OSHasAVXSupport()) { 2161541Srgrimes X86SSELevel = AVX; ToggleFeature(X86::FeatureAVX); 2171541Srgrimes } 2181541Srgrimes 2191541Srgrimes bool IsIntel = memcmp(text.c, "GenuineIntel", 12) == 0; 2201541Srgrimes bool IsAMD = !IsIntel && memcmp(text.c, "AuthenticAMD", 12) == 0; 2211541Srgrimes 2221541Srgrimes if ((ECX >> 1) & 0x1) { 2231541Srgrimes HasPCLMUL = true; 2241541Srgrimes ToggleFeature(X86::FeaturePCLMUL); 2251541Srgrimes } 2261541Srgrimes if ((ECX >> 12) & 0x1) { 2271541Srgrimes HasFMA = true; 2281541Srgrimes ToggleFeature(X86::FeatureFMA); 2291541Srgrimes } 2301541Srgrimes if (IsIntel && ((ECX >> 22) & 0x1)) { 2311541Srgrimes HasMOVBE = true; 2321541Srgrimes ToggleFeature(X86::FeatureMOVBE); 2331541Srgrimes } 2341541Srgrimes if ((ECX >> 23) & 0x1) { 2351541Srgrimes HasPOPCNT = true; 2361541Srgrimes ToggleFeature(X86::FeaturePOPCNT); 2371541Srgrimes } 2381541Srgrimes if ((ECX >> 25) & 0x1) { 2391541Srgrimes HasAES = true; 2401541Srgrimes ToggleFeature(X86::FeatureAES); 2411541Srgrimes } 2421541Srgrimes if ((ECX >> 29) & 0x1) { 243 HasF16C = true; 244 ToggleFeature(X86::FeatureF16C); 245 } 246 if (IsIntel && ((ECX >> 30) & 0x1)) { 247 HasRDRAND = true; 248 ToggleFeature(X86::FeatureRDRAND); 249 } 250 251 if ((ECX >> 13) & 0x1) { 252 HasCmpxchg16b = true; 253 ToggleFeature(X86::FeatureCMPXCHG16B); 254 } 255 256 if (IsIntel || IsAMD) { 257 // Determine if bit test memory instructions are slow. 258 unsigned Family = 0; 259 unsigned Model = 0; 260 X86_MC::DetectFamilyModel(EAX, Family, Model); 261 if (IsAMD || (Family == 6 && Model >= 13)) { 262 IsBTMemSlow = true; 263 ToggleFeature(X86::FeatureSlowBTMem); 264 } 265 266 // If it's an Intel chip since Nehalem and not an Atom chip, unaligned 267 // memory access is fast. We hard code model numbers here because they 268 // aren't strictly increasing for Intel chips it seems. 269 if (IsIntel && 270 ((Family == 6 && Model == 0x1E) || // Nehalem: Clarksfield, Lynnfield, 271 // Jasper Froest 272 (Family == 6 && Model == 0x1A) || // Nehalem: Bloomfield, Nehalem-EP 273 (Family == 6 && Model == 0x2E) || // Nehalem: Nehalem-EX 274 (Family == 6 && Model == 0x25) || // Westmere: Arrandale, Clarksdale 275 (Family == 6 && Model == 0x2C) || // Westmere: Gulftown, Westmere-EP 276 (Family == 6 && Model == 0x2F) || // Westmere: Westmere-EX 277 (Family == 6 && Model == 0x2A) || // SandyBridge 278 (Family == 6 && Model == 0x2D) || // SandyBridge: SandyBridge-E* 279 (Family == 6 && Model == 0x3A) || // IvyBridge 280 (Family == 6 && Model == 0x3E) || // IvyBridge EP 281 (Family == 6 && Model == 0x3C) || // Haswell 282 (Family == 6 && Model == 0x3F) || // ... 283 (Family == 6 && Model == 0x45) || // ... 284 (Family == 6 && Model == 0x46))) { // ... 285 IsUAMemFast = true; 286 ToggleFeature(X86::FeatureFastUAMem); 287 } 288 289 // Set processor type. Currently only Atom or Silvermont (SLM) is detected. 290 if (Family == 6 && 291 (Model == 28 || Model == 38 || Model == 39 || 292 Model == 53 || Model == 54)) { 293 X86ProcFamily = IntelAtom; 294 295 UseLeaForSP = true; 296 ToggleFeature(X86::FeatureLeaForSP); 297 } 298 else if (Family == 6 && 299 (Model == 55 || Model == 74 || Model == 77)) { 300 X86ProcFamily = IntelSLM; 301 } 302 303 unsigned MaxExtLevel; 304 X86_MC::GetCpuIDAndInfo(0x80000000, &MaxExtLevel, &EBX, &ECX, &EDX); 305 306 if (MaxExtLevel >= 0x80000001) { 307 X86_MC::GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX); 308 if ((EDX >> 29) & 0x1) { 309 HasX86_64 = true; 310 ToggleFeature(X86::Feature64Bit); 311 } 312 if ((ECX >> 5) & 0x1) { 313 HasLZCNT = true; 314 ToggleFeature(X86::FeatureLZCNT); 315 } 316 if (IsIntel && ((ECX >> 8) & 0x1)) { 317 HasPRFCHW = true; 318 ToggleFeature(X86::FeaturePRFCHW); 319 } 320 if (IsAMD) { 321 if ((ECX >> 6) & 0x1) { 322 HasSSE4A = true; 323 ToggleFeature(X86::FeatureSSE4A); 324 } 325 if ((ECX >> 11) & 0x1) { 326 HasXOP = true; 327 ToggleFeature(X86::FeatureXOP); 328 } 329 if ((ECX >> 16) & 0x1) { 330 HasFMA4 = true; 331 ToggleFeature(X86::FeatureFMA4); 332 } 333 } 334 } 335 } 336 337 if (MaxLevel >= 7) { 338 if (!X86_MC::GetCpuIDAndInfoEx(0x7, 0x0, &EAX, &EBX, &ECX, &EDX)) { 339 if (IsIntel && (EBX & 0x1)) { 340 HasFSGSBase = true; 341 ToggleFeature(X86::FeatureFSGSBase); 342 } 343 if ((EBX >> 3) & 0x1) { 344 HasBMI = true; 345 ToggleFeature(X86::FeatureBMI); 346 } 347 if ((EBX >> 4) & 0x1) { 348 HasHLE = true; 349 ToggleFeature(X86::FeatureHLE); 350 } 351 if (IsIntel && ((EBX >> 5) & 0x1)) { 352 X86SSELevel = AVX2; 353 ToggleFeature(X86::FeatureAVX2); 354 } 355 if (IsIntel && ((EBX >> 8) & 0x1)) { 356 HasBMI2 = true; 357 ToggleFeature(X86::FeatureBMI2); 358 } 359 if (IsIntel && ((EBX >> 11) & 0x1)) { 360 HasRTM = true; 361 ToggleFeature(X86::FeatureRTM); 362 } 363 if (IsIntel && ((EBX >> 16) & 0x1)) { 364 X86SSELevel = AVX512F; 365 ToggleFeature(X86::FeatureAVX512); 366 } 367 if (IsIntel && ((EBX >> 18) & 0x1)) { 368 HasRDSEED = true; 369 ToggleFeature(X86::FeatureRDSEED); 370 } 371 if (IsIntel && ((EBX >> 19) & 0x1)) { 372 HasADX = true; 373 ToggleFeature(X86::FeatureADX); 374 } 375 if (IsIntel && ((EBX >> 26) & 0x1)) { 376 HasPFI = true; 377 ToggleFeature(X86::FeaturePFI); 378 } 379 if (IsIntel && ((EBX >> 27) & 0x1)) { 380 HasERI = true; 381 ToggleFeature(X86::FeatureERI); 382 } 383 if (IsIntel && ((EBX >> 28) & 0x1)) { 384 HasCDI = true; 385 ToggleFeature(X86::FeatureCDI); 386 } 387 if (IsIntel && ((EBX >> 29) & 0x1)) { 388 HasSHA = true; 389 ToggleFeature(X86::FeatureSHA); 390 } 391 } 392 if (IsAMD && ((ECX >> 21) & 0x1)) { 393 HasTBM = true; 394 ToggleFeature(X86::FeatureTBM); 395 } 396 } 397} 398 399void X86Subtarget::resetSubtargetFeatures(const MachineFunction *MF) { 400 AttributeSet FnAttrs = MF->getFunction()->getAttributes(); 401 Attribute CPUAttr = FnAttrs.getAttribute(AttributeSet::FunctionIndex, 402 "target-cpu"); 403 Attribute FSAttr = FnAttrs.getAttribute(AttributeSet::FunctionIndex, 404 "target-features"); 405 std::string CPU = 406 !CPUAttr.hasAttribute(Attribute::None) ?CPUAttr.getValueAsString() : ""; 407 std::string FS = 408 !FSAttr.hasAttribute(Attribute::None) ? FSAttr.getValueAsString() : ""; 409 if (!FS.empty()) { 410 initializeEnvironment(); 411 resetSubtargetFeatures(CPU, FS); 412 } 413} 414 415void X86Subtarget::resetSubtargetFeatures(StringRef CPU, StringRef FS) { 416 std::string CPUName = CPU; 417 if (!FS.empty() || !CPU.empty()) { 418 if (CPUName.empty()) { 419#if defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86)\ 420 || defined(__x86_64__) || defined(_M_AMD64) || defined (_M_X64) 421 CPUName = sys::getHostCPUName(); 422#else 423 CPUName = "generic"; 424#endif 425 } 426 427 // Make sure 64-bit features are available in 64-bit mode. (But make sure 428 // SSE2 can be turned off explicitly.) 429 std::string FullFS = FS; 430 if (In64BitMode) { 431 if (!FullFS.empty()) 432 FullFS = "+64bit,+sse2," + FullFS; 433 else 434 FullFS = "+64bit,+sse2"; 435 } 436 437 // If feature string is not empty, parse features string. 438 ParseSubtargetFeatures(CPUName, FullFS); 439 } else { 440 if (CPUName.empty()) { 441#if defined (__x86_64__) || defined(__i386__) 442 CPUName = sys::getHostCPUName(); 443#else 444 CPUName = "generic"; 445#endif 446 } 447 // Otherwise, use CPUID to auto-detect feature set. 448 AutoDetectSubtargetFeatures(); 449 450 // Make sure 64-bit features are available in 64-bit mode. 451 if (In64BitMode) { 452 if (!HasX86_64) { HasX86_64 = true; ToggleFeature(X86::Feature64Bit); } 453 if (!HasCMov) { HasCMov = true; ToggleFeature(X86::FeatureCMOV); } 454 455 if (X86SSELevel < SSE2) { 456 X86SSELevel = SSE2; 457 ToggleFeature(X86::FeatureSSE1); 458 ToggleFeature(X86::FeatureSSE2); 459 } 460 } 461 } 462 463 // CPUName may have been set by the CPU detection code. Make sure the 464 // new MCSchedModel is used. 465 InitCPUSchedModel(CPUName); 466 467 if (X86ProcFamily == IntelAtom || X86ProcFamily == IntelSLM) 468 PostRAScheduler = true; 469 470 InstrItins = getInstrItineraryForCPU(CPUName); 471 472 // It's important to keep the MCSubtargetInfo feature bits in sync with 473 // target data structure which is shared with MC code emitter, etc. 474 if (In64BitMode) 475 ToggleFeature(X86::Mode64Bit); 476 477 DEBUG(dbgs() << "Subtarget features: SSELevel " << X86SSELevel 478 << ", 3DNowLevel " << X863DNowLevel 479 << ", 64bit " << HasX86_64 << "\n"); 480 assert((!In64BitMode || HasX86_64) && 481 "64-bit code requested on a subtarget that doesn't support it!"); 482 483 // Stack alignment is 16 bytes on Darwin, Linux and Solaris (both 484 // 32 and 64 bit) and for all 64-bit targets. 485 if (StackAlignOverride) 486 stackAlignment = StackAlignOverride; 487 else if (isTargetDarwin() || isTargetLinux() || isTargetSolaris() || 488 In64BitMode) 489 stackAlignment = 16; 490} 491 492void X86Subtarget::initializeEnvironment() { 493 X86SSELevel = NoMMXSSE; 494 X863DNowLevel = NoThreeDNow; 495 HasCMov = false; 496 HasX86_64 = false; 497 HasPOPCNT = false; 498 HasSSE4A = false; 499 HasAES = false; 500 HasPCLMUL = false; 501 HasFMA = false; 502 HasFMA4 = false; 503 HasXOP = false; 504 HasTBM = false; 505 HasMOVBE = false; 506 HasRDRAND = false; 507 HasF16C = false; 508 HasFSGSBase = false; 509 HasLZCNT = false; 510 HasBMI = false; 511 HasBMI2 = false; 512 HasRTM = false; 513 HasHLE = false; 514 HasERI = false; 515 HasCDI = false; 516 HasPFI = false; 517 HasADX = false; 518 HasSHA = false; 519 HasPRFCHW = false; 520 HasRDSEED = false; 521 IsBTMemSlow = false; 522 IsUAMemFast = false; 523 HasVectorUAMem = false; 524 HasCmpxchg16b = false; 525 UseLeaForSP = false; 526 HasSlowDivide = false; 527 PostRAScheduler = false; 528 PadShortFunctions = false; 529 CallRegIndirect = false; 530 LEAUsesAG = false; 531 stackAlignment = 4; 532 // FIXME: this is a known good value for Yonah. How about others? 533 MaxInlineSizeThreshold = 128; 534} 535 536X86Subtarget::X86Subtarget(const std::string &TT, const std::string &CPU, 537 const std::string &FS, 538 unsigned StackAlignOverride, bool is64Bit) 539 : X86GenSubtargetInfo(TT, CPU, FS) 540 , X86ProcFamily(Others) 541 , PICStyle(PICStyles::None) 542 , TargetTriple(TT) 543 , StackAlignOverride(StackAlignOverride) 544 , In64BitMode(is64Bit) { 545 initializeEnvironment(); 546 resetSubtargetFeatures(CPU, FS); 547} 548 549bool X86Subtarget::enablePostRAScheduler( 550 CodeGenOpt::Level OptLevel, 551 TargetSubtargetInfo::AntiDepBreakMode& Mode, 552 RegClassVector& CriticalPathRCs) const { 553 Mode = TargetSubtargetInfo::ANTIDEP_CRITICAL; 554 CriticalPathRCs.clear(); 555 return PostRAScheduler && OptLevel >= CodeGenOpt::Default; 556} 557