Targets.cpp revision 64f853101a23276621e160cc9b145f0bd699956d
1//===--- Targets.cpp - Implement -arch option and targets -----------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file implements construction of a TargetInfo object from a 11// target triple. 12// 13//===----------------------------------------------------------------------===// 14 15#include "clang/Basic/TargetInfo.h" 16#include "clang/Basic/Builtins.h" 17#include "clang/Basic/Diagnostic.h" 18#include "clang/Basic/LangOptions.h" 19#include "clang/Basic/MacroBuilder.h" 20#include "clang/Basic/TargetBuiltins.h" 21#include "clang/Basic/TargetOptions.h" 22#include "llvm/ADT/APFloat.h" 23#include "llvm/ADT/OwningPtr.h" 24#include "llvm/ADT/STLExtras.h" 25#include "llvm/ADT/StringRef.h" 26#include "llvm/ADT/StringSwitch.h" 27#include "llvm/ADT/Triple.h" 28#include "llvm/MC/MCSectionMachO.h" 29#include "llvm/Type.h" 30#include <algorithm> 31using namespace clang; 32 33//===----------------------------------------------------------------------===// 34// Common code shared among targets. 35//===----------------------------------------------------------------------===// 36 37/// DefineStd - Define a macro name and standard variants. For example if 38/// MacroName is "unix", then this will define "__unix", "__unix__", and "unix" 39/// when in GNU mode. 40static void DefineStd(MacroBuilder &Builder, llvm::StringRef MacroName, 41 const LangOptions &Opts) { 42 assert(MacroName[0] != '_' && "Identifier should be in the user's namespace"); 43 44 // If in GNU mode (e.g. -std=gnu99 but not -std=c99) define the raw identifier 45 // in the user's namespace. 46 if (Opts.GNUMode) 47 Builder.defineMacro(MacroName); 48 49 // Define __unix. 50 Builder.defineMacro("__" + MacroName); 51 52 // Define __unix__. 53 Builder.defineMacro("__" + MacroName + "__"); 54} 55 56//===----------------------------------------------------------------------===// 57// Defines specific to certain operating systems. 58//===----------------------------------------------------------------------===// 59 60namespace { 61template<typename TgtInfo> 62class OSTargetInfo : public TgtInfo { 63protected: 64 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 65 MacroBuilder &Builder) const=0; 66public: 67 OSTargetInfo(const std::string& triple) : TgtInfo(triple) {} 68 virtual void getTargetDefines(const LangOptions &Opts, 69 MacroBuilder &Builder) const { 70 TgtInfo::getTargetDefines(Opts, Builder); 71 getOSDefines(Opts, TgtInfo::getTriple(), Builder); 72 } 73 74}; 75} // end anonymous namespace 76 77 78static void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts, 79 const llvm::Triple &Triple, 80 llvm::StringRef &PlatformName, 81 VersionTuple &PlatformMinVersion) { 82 Builder.defineMacro("__APPLE_CC__", "5621"); 83 Builder.defineMacro("__APPLE__"); 84 Builder.defineMacro("__MACH__"); 85 Builder.defineMacro("OBJC_NEW_PROPERTIES"); 86 87 if (!Opts.ObjCAutoRefCount) { 88 // __weak is always defined, for use in blocks and with objc pointers. 89 Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))"); 90 91 // Darwin defines __strong even in C mode (just to nothing). 92 if (Opts.getGCMode() != LangOptions::NonGC) 93 Builder.defineMacro("__strong", "__attribute__((objc_gc(strong)))"); 94 else 95 Builder.defineMacro("__strong", ""); 96 97 // __unsafe_unretained is defined to nothing in non-ARC mode. We even 98 // allow this in C, since one might have block pointers in structs that 99 // are used in pure C code and in Objective-C ARC. 100 Builder.defineMacro("__unsafe_unretained", ""); 101 102 // The Objective-C bridged cast keywords are defined to nothing in non-ARC 103 // mode; then they become normal, C-style casts. 104 Builder.defineMacro("__bridge", ""); 105 Builder.defineMacro("__bridge_transfer", ""); 106 Builder.defineMacro("__bridge_retained", ""); 107 Builder.defineMacro("__bridge_retain", ""); 108 } 109 110 if (Opts.Static) 111 Builder.defineMacro("__STATIC__"); 112 else 113 Builder.defineMacro("__DYNAMIC__"); 114 115 if (Opts.POSIXThreads) 116 Builder.defineMacro("_REENTRANT"); 117 118 // Get the platform type and version number from the triple. 119 unsigned Maj, Min, Rev; 120 121 // If no version was given, default to to 10.4.0, for simplifying tests. 122 if (Triple.getOSName() == "darwin" || Triple.getOSName() == "osx") { 123 PlatformName = "macosx"; 124 Min = Rev = 0; 125 Maj = 8; 126 } else { 127 // Otherwise, honor all three triple forms ("-darwinNNN[-iphoneos]", 128 // "-osxNNN", and "-iosNNN"). 129 130 if (Triple.getOS() == llvm::Triple::Darwin) { 131 // For historical reasons that make little sense, the version passed here 132 // is the "darwin" version, which drops the 10 and offsets by 4. 133 Triple.getOSVersion(Maj, Min, Rev); 134 135 if (Triple.getEnvironmentName() == "iphoneos") { 136 PlatformName = "ios"; 137 } else { 138 PlatformName = "macosx"; 139 Rev = Min; 140 Min = Maj - 4; 141 Maj = 10; 142 } 143 } else { 144 Triple.getOSVersion(Maj, Min, Rev); 145 PlatformName = llvm::Triple::getOSTypeName(Triple.getOS()); 146 } 147 } 148 149 // If -ccc-host-triple arch-pc-win32-macho option specified, we're 150 // generating code for Win32 ABI. No need to emit 151 // __ENVIRONMENT_XX_OS_VERSION_MIN_REQUIRED__. 152 if (PlatformName == "win32") { 153 PlatformMinVersion = VersionTuple(Maj, Min, Rev); 154 return; 155 } 156 157 // Set the appropriate OS version define. 158 if (PlatformName == "ios") { 159 assert(Maj < 10 && Min < 100 && Rev < 100 && "Invalid version!"); 160 char Str[6]; 161 Str[0] = '0' + Maj; 162 Str[1] = '0' + (Min / 10); 163 Str[2] = '0' + (Min % 10); 164 Str[3] = '0' + (Rev / 10); 165 Str[4] = '0' + (Rev % 10); 166 Str[5] = '\0'; 167 Builder.defineMacro("__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__", Str); 168 } else { 169 // Note that the Driver allows versions which aren't representable in the 170 // define (because we only get a single digit for the minor and micro 171 // revision numbers). So, we limit them to the maximum representable 172 // version. 173 assert(Triple.getEnvironmentName().empty() && "Invalid environment!"); 174 assert(Maj < 100 && Min < 100 && Rev < 100 && "Invalid version!"); 175 char Str[5]; 176 Str[0] = '0' + (Maj / 10); 177 Str[1] = '0' + (Maj % 10); 178 Str[2] = '0' + std::min(Min, 9U); 179 Str[3] = '0' + std::min(Rev, 9U); 180 Str[4] = '\0'; 181 Builder.defineMacro("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", Str); 182 } 183 184 PlatformMinVersion = VersionTuple(Maj, Min, Rev); 185} 186 187namespace { 188template<typename Target> 189class DarwinTargetInfo : public OSTargetInfo<Target> { 190protected: 191 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 192 MacroBuilder &Builder) const { 193 getDarwinDefines(Builder, Opts, Triple, this->PlatformName, 194 this->PlatformMinVersion); 195 } 196 197public: 198 DarwinTargetInfo(const std::string& triple) : 199 OSTargetInfo<Target>(triple) { 200 llvm::Triple T = llvm::Triple(triple); 201 this->TLSSupported = T.isMacOSX() && !T.isMacOSXVersionLT(10,7); 202 this->MCountName = "\01mcount"; 203 } 204 205 virtual std::string isValidSectionSpecifier(llvm::StringRef SR) const { 206 // Let MCSectionMachO validate this. 207 llvm::StringRef Segment, Section; 208 unsigned TAA, StubSize; 209 bool HasTAA; 210 return llvm::MCSectionMachO::ParseSectionSpecifier(SR, Segment, Section, 211 TAA, HasTAA, StubSize); 212 } 213 214 virtual const char *getStaticInitSectionSpecifier() const { 215 // FIXME: We should return 0 when building kexts. 216 return "__TEXT,__StaticInit,regular,pure_instructions"; 217 } 218 219}; 220 221 222// DragonFlyBSD Target 223template<typename Target> 224class DragonFlyBSDTargetInfo : public OSTargetInfo<Target> { 225protected: 226 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 227 MacroBuilder &Builder) const { 228 // DragonFly defines; list based off of gcc output 229 Builder.defineMacro("__DragonFly__"); 230 Builder.defineMacro("__DragonFly_cc_version", "100001"); 231 Builder.defineMacro("__ELF__"); 232 Builder.defineMacro("__KPRINTF_ATTRIBUTE__"); 233 Builder.defineMacro("__tune_i386__"); 234 DefineStd(Builder, "unix", Opts); 235 } 236public: 237 DragonFlyBSDTargetInfo(const std::string &triple) 238 : OSTargetInfo<Target>(triple) {} 239}; 240 241// FreeBSD Target 242template<typename Target> 243class FreeBSDTargetInfo : public OSTargetInfo<Target> { 244protected: 245 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 246 MacroBuilder &Builder) const { 247 // FreeBSD defines; list based off of gcc output 248 249 // FIXME: Move version number handling to llvm::Triple. 250 llvm::StringRef Release = Triple.getOSName().substr(strlen("freebsd"), 1); 251 252 Builder.defineMacro("__FreeBSD__", Release); 253 Builder.defineMacro("__FreeBSD_cc_version", Release + "00001"); 254 Builder.defineMacro("__KPRINTF_ATTRIBUTE__"); 255 DefineStd(Builder, "unix", Opts); 256 Builder.defineMacro("__ELF__"); 257 } 258public: 259 FreeBSDTargetInfo(const std::string &triple) 260 : OSTargetInfo<Target>(triple) { 261 this->UserLabelPrefix = ""; 262 263 llvm::Triple Triple(triple); 264 switch (Triple.getArch()) { 265 default: 266 case llvm::Triple::x86: 267 case llvm::Triple::x86_64: 268 this->MCountName = ".mcount"; 269 break; 270 case llvm::Triple::mips: 271 case llvm::Triple::mipsel: 272 case llvm::Triple::ppc: 273 case llvm::Triple::ppc64: 274 this->MCountName = "_mcount"; 275 break; 276 case llvm::Triple::arm: 277 this->MCountName = "__mcount"; 278 break; 279 } 280 281 } 282}; 283 284// Minix Target 285template<typename Target> 286class MinixTargetInfo : public OSTargetInfo<Target> { 287protected: 288 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 289 MacroBuilder &Builder) const { 290 // Minix defines 291 292 Builder.defineMacro("__minix", "3"); 293 Builder.defineMacro("_EM_WSIZE", "4"); 294 Builder.defineMacro("_EM_PSIZE", "4"); 295 Builder.defineMacro("_EM_SSIZE", "2"); 296 Builder.defineMacro("_EM_LSIZE", "4"); 297 Builder.defineMacro("_EM_FSIZE", "4"); 298 Builder.defineMacro("_EM_DSIZE", "8"); 299 DefineStd(Builder, "unix", Opts); 300 } 301public: 302 MinixTargetInfo(const std::string &triple) 303 : OSTargetInfo<Target>(triple) { 304 this->UserLabelPrefix = ""; 305 } 306}; 307 308// Linux target 309template<typename Target> 310class LinuxTargetInfo : public OSTargetInfo<Target> { 311protected: 312 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 313 MacroBuilder &Builder) const { 314 // Linux defines; list based off of gcc output 315 DefineStd(Builder, "unix", Opts); 316 DefineStd(Builder, "linux", Opts); 317 Builder.defineMacro("__gnu_linux__"); 318 Builder.defineMacro("__ELF__"); 319 if (Opts.POSIXThreads) 320 Builder.defineMacro("_REENTRANT"); 321 if (Opts.CPlusPlus) 322 Builder.defineMacro("_GNU_SOURCE"); 323 } 324public: 325 LinuxTargetInfo(const std::string& triple) 326 : OSTargetInfo<Target>(triple) { 327 this->UserLabelPrefix = ""; 328 this->WIntType = TargetInfo::UnsignedInt; 329 } 330}; 331 332// NetBSD Target 333template<typename Target> 334class NetBSDTargetInfo : public OSTargetInfo<Target> { 335protected: 336 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 337 MacroBuilder &Builder) const { 338 // NetBSD defines; list based off of gcc output 339 Builder.defineMacro("__NetBSD__"); 340 Builder.defineMacro("__unix__"); 341 Builder.defineMacro("__ELF__"); 342 if (Opts.POSIXThreads) 343 Builder.defineMacro("_POSIX_THREADS"); 344 } 345public: 346 NetBSDTargetInfo(const std::string &triple) 347 : OSTargetInfo<Target>(triple) { 348 this->UserLabelPrefix = ""; 349 } 350}; 351 352// OpenBSD Target 353template<typename Target> 354class OpenBSDTargetInfo : public OSTargetInfo<Target> { 355protected: 356 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 357 MacroBuilder &Builder) const { 358 // OpenBSD defines; list based off of gcc output 359 360 Builder.defineMacro("__OpenBSD__"); 361 DefineStd(Builder, "unix", Opts); 362 Builder.defineMacro("__ELF__"); 363 if (Opts.POSIXThreads) 364 Builder.defineMacro("_POSIX_THREADS"); 365 } 366public: 367 OpenBSDTargetInfo(const std::string &triple) 368 : OSTargetInfo<Target>(triple) {} 369}; 370 371// PSP Target 372template<typename Target> 373class PSPTargetInfo : public OSTargetInfo<Target> { 374protected: 375 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 376 MacroBuilder &Builder) const { 377 // PSP defines; list based on the output of the pspdev gcc toolchain. 378 Builder.defineMacro("PSP"); 379 Builder.defineMacro("_PSP"); 380 Builder.defineMacro("__psp__"); 381 Builder.defineMacro("__ELF__"); 382 } 383public: 384 PSPTargetInfo(const std::string& triple) 385 : OSTargetInfo<Target>(triple) { 386 this->UserLabelPrefix = ""; 387 } 388}; 389 390// PS3 PPU Target 391template<typename Target> 392class PS3PPUTargetInfo : public OSTargetInfo<Target> { 393protected: 394 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 395 MacroBuilder &Builder) const { 396 // PS3 PPU defines. 397 Builder.defineMacro("__PPC__"); 398 Builder.defineMacro("__PPU__"); 399 Builder.defineMacro("__CELLOS_LV2__"); 400 Builder.defineMacro("__ELF__"); 401 Builder.defineMacro("__LP32__"); 402 Builder.defineMacro("_ARCH_PPC64"); 403 Builder.defineMacro("__powerpc64__"); 404 } 405public: 406 PS3PPUTargetInfo(const std::string& triple) 407 : OSTargetInfo<Target>(triple) { 408 this->UserLabelPrefix = ""; 409 this->LongWidth = this->LongAlign = this->PointerWidth = this->PointerAlign = 32; 410 this->IntMaxType = TargetInfo::SignedLongLong; 411 this->UIntMaxType = TargetInfo::UnsignedLongLong; 412 this->Int64Type = TargetInfo::SignedLongLong; 413 this->SizeType = TargetInfo::UnsignedInt; 414 this->DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 415 "i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32"; 416 } 417}; 418 419// FIXME: Need a real SPU target. 420// PS3 SPU Target 421template<typename Target> 422class PS3SPUTargetInfo : public OSTargetInfo<Target> { 423protected: 424 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 425 MacroBuilder &Builder) const { 426 // PS3 PPU defines. 427 Builder.defineMacro("__SPU__"); 428 Builder.defineMacro("__ELF__"); 429 } 430public: 431 PS3SPUTargetInfo(const std::string& triple) 432 : OSTargetInfo<Target>(triple) { 433 this->UserLabelPrefix = ""; 434 } 435}; 436 437// AuroraUX target 438template<typename Target> 439class AuroraUXTargetInfo : public OSTargetInfo<Target> { 440protected: 441 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 442 MacroBuilder &Builder) const { 443 DefineStd(Builder, "sun", Opts); 444 DefineStd(Builder, "unix", Opts); 445 Builder.defineMacro("__ELF__"); 446 Builder.defineMacro("__svr4__"); 447 Builder.defineMacro("__SVR4"); 448 } 449public: 450 AuroraUXTargetInfo(const std::string& triple) 451 : OSTargetInfo<Target>(triple) { 452 this->UserLabelPrefix = ""; 453 this->WCharType = this->SignedLong; 454 // FIXME: WIntType should be SignedLong 455 } 456}; 457 458// Solaris target 459template<typename Target> 460class SolarisTargetInfo : public OSTargetInfo<Target> { 461protected: 462 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 463 MacroBuilder &Builder) const { 464 DefineStd(Builder, "sun", Opts); 465 DefineStd(Builder, "unix", Opts); 466 Builder.defineMacro("__ELF__"); 467 Builder.defineMacro("__svr4__"); 468 Builder.defineMacro("__SVR4"); 469 } 470public: 471 SolarisTargetInfo(const std::string& triple) 472 : OSTargetInfo<Target>(triple) { 473 this->UserLabelPrefix = ""; 474 this->WCharType = this->SignedLong; 475 // FIXME: WIntType should be SignedLong 476 } 477}; 478 479// Windows target 480template<typename Target> 481class WindowsTargetInfo : public OSTargetInfo<Target> { 482protected: 483 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 484 MacroBuilder &Builder) const { 485 Builder.defineMacro("_WIN32"); 486 } 487 void getVisualStudioDefines(const LangOptions &Opts, 488 MacroBuilder &Builder) const { 489 if (Opts.CPlusPlus) { 490 if (Opts.RTTI) 491 Builder.defineMacro("_CPPRTTI"); 492 493 if (Opts.Exceptions) 494 Builder.defineMacro("_CPPUNWIND"); 495 } 496 497 if (!Opts.CharIsSigned) 498 Builder.defineMacro("_CHAR_UNSIGNED"); 499 500 // FIXME: POSIXThreads isn't exactly the option this should be defined for, 501 // but it works for now. 502 if (Opts.POSIXThreads) 503 Builder.defineMacro("_MT"); 504 505 if (Opts.MSCVersion != 0) 506 Builder.defineMacro("_MSC_VER", llvm::Twine(Opts.MSCVersion)); 507 508 if (Opts.Microsoft) { 509 Builder.defineMacro("_MSC_EXTENSIONS"); 510 511 if (Opts.CPlusPlus0x) { 512 Builder.defineMacro("_RVALUE_REFERENCES_V2_SUPPORTED"); 513 Builder.defineMacro("_RVALUE_REFERENCES_SUPPORTED"); 514 Builder.defineMacro("_NATIVE_NULLPTR_SUPPORTED"); 515 } 516 } 517 518 Builder.defineMacro("_INTEGRAL_MAX_BITS", "64"); 519 } 520 521public: 522 WindowsTargetInfo(const std::string &triple) 523 : OSTargetInfo<Target>(triple) {} 524}; 525 526} // end anonymous namespace. 527 528//===----------------------------------------------------------------------===// 529// Specific target implementations. 530//===----------------------------------------------------------------------===// 531 532namespace { 533// PPC abstract base class 534class PPCTargetInfo : public TargetInfo { 535 static const Builtin::Info BuiltinInfo[]; 536 static const char * const GCCRegNames[]; 537 static const TargetInfo::GCCRegAlias GCCRegAliases[]; 538public: 539 PPCTargetInfo(const std::string& triple) : TargetInfo(triple) {} 540 541 virtual void getTargetBuiltins(const Builtin::Info *&Records, 542 unsigned &NumRecords) const { 543 Records = BuiltinInfo; 544 NumRecords = clang::PPC::LastTSBuiltin-Builtin::FirstTSBuiltin; 545 } 546 547 virtual void getTargetDefines(const LangOptions &Opts, 548 MacroBuilder &Builder) const; 549 550 virtual void getGCCRegNames(const char * const *&Names, 551 unsigned &NumNames) const; 552 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 553 unsigned &NumAliases) const; 554 virtual bool validateAsmConstraint(const char *&Name, 555 TargetInfo::ConstraintInfo &Info) const { 556 switch (*Name) { 557 default: return false; 558 case 'O': // Zero 559 break; 560 case 'b': // Base register 561 case 'f': // Floating point register 562 Info.setAllowsRegister(); 563 break; 564 // FIXME: The following are added to allow parsing. 565 // I just took a guess at what the actions should be. 566 // Also, is more specific checking needed? I.e. specific registers? 567 case 'd': // Floating point register (containing 64-bit value) 568 case 'v': // Altivec vector register 569 Info.setAllowsRegister(); 570 break; 571 case 'w': 572 switch (Name[1]) { 573 case 'd':// VSX vector register to hold vector double data 574 case 'f':// VSX vector register to hold vector float data 575 case 's':// VSX vector register to hold scalar float data 576 case 'a':// Any VSX register 577 break; 578 default: 579 return false; 580 } 581 Info.setAllowsRegister(); 582 Name++; // Skip over 'w'. 583 break; 584 case 'h': // `MQ', `CTR', or `LINK' register 585 case 'q': // `MQ' register 586 case 'c': // `CTR' register 587 case 'l': // `LINK' register 588 case 'x': // `CR' register (condition register) number 0 589 case 'y': // `CR' register (condition register) 590 case 'z': // `XER[CA]' carry bit (part of the XER register) 591 Info.setAllowsRegister(); 592 break; 593 case 'I': // Signed 16-bit constant 594 case 'J': // Unsigned 16-bit constant shifted left 16 bits 595 // (use `L' instead for SImode constants) 596 case 'K': // Unsigned 16-bit constant 597 case 'L': // Signed 16-bit constant shifted left 16 bits 598 case 'M': // Constant larger than 31 599 case 'N': // Exact power of 2 600 case 'P': // Constant whose negation is a signed 16-bit constant 601 case 'G': // Floating point constant that can be loaded into a 602 // register with one instruction per word 603 case 'H': // Integer/Floating point constant that can be loaded 604 // into a register using three instructions 605 break; 606 case 'm': // Memory operand. Note that on PowerPC targets, m can 607 // include addresses that update the base register. It 608 // is therefore only safe to use `m' in an asm statement 609 // if that asm statement accesses the operand exactly once. 610 // The asm statement must also use `%U<opno>' as a 611 // placeholder for the "update" flag in the corresponding 612 // load or store instruction. For example: 613 // asm ("st%U0 %1,%0" : "=m" (mem) : "r" (val)); 614 // is correct but: 615 // asm ("st %1,%0" : "=m" (mem) : "r" (val)); 616 // is not. Use es rather than m if you don't want the base 617 // register to be updated. 618 case 'e': 619 if (Name[1] != 's') 620 return false; 621 // es: A "stable" memory operand; that is, one which does not 622 // include any automodification of the base register. Unlike 623 // `m', this constraint can be used in asm statements that 624 // might access the operand several times, or that might not 625 // access it at all. 626 Info.setAllowsMemory(); 627 Name++; // Skip over 'e'. 628 break; 629 case 'Q': // Memory operand that is an offset from a register (it is 630 // usually better to use `m' or `es' in asm statements) 631 case 'Z': // Memory operand that is an indexed or indirect from a 632 // register (it is usually better to use `m' or `es' in 633 // asm statements) 634 Info.setAllowsMemory(); 635 Info.setAllowsRegister(); 636 break; 637 case 'R': // AIX TOC entry 638 case 'a': // Address operand that is an indexed or indirect from a 639 // register (`p' is preferable for asm statements) 640 case 'S': // Constant suitable as a 64-bit mask operand 641 case 'T': // Constant suitable as a 32-bit mask operand 642 case 'U': // System V Release 4 small data area reference 643 case 't': // AND masks that can be performed by two rldic{l, r} 644 // instructions 645 case 'W': // Vector constant that does not require memory 646 case 'j': // Vector constant that is all zeros. 647 break; 648 // End FIXME. 649 } 650 return true; 651 } 652 virtual const char *getClobbers() const { 653 return ""; 654 } 655}; 656 657const Builtin::Info PPCTargetInfo::BuiltinInfo[] = { 658#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES }, 659#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\ 660 ALL_LANGUAGES }, 661#include "clang/Basic/BuiltinsPPC.def" 662}; 663 664 665/// PPCTargetInfo::getTargetDefines - Return a set of the PowerPC-specific 666/// #defines that are not tied to a specific subtarget. 667void PPCTargetInfo::getTargetDefines(const LangOptions &Opts, 668 MacroBuilder &Builder) const { 669 // Target identification. 670 Builder.defineMacro("__ppc__"); 671 Builder.defineMacro("_ARCH_PPC"); 672 Builder.defineMacro("__powerpc__"); 673 Builder.defineMacro("__POWERPC__"); 674 if (PointerWidth == 64) { 675 Builder.defineMacro("_ARCH_PPC64"); 676 Builder.defineMacro("_LP64"); 677 Builder.defineMacro("__LP64__"); 678 Builder.defineMacro("__powerpc64__"); 679 Builder.defineMacro("__ppc64__"); 680 } else { 681 Builder.defineMacro("__ppc__"); 682 } 683 684 // Target properties. 685 if (getTriple().getOS() != llvm::Triple::NetBSD) 686 Builder.defineMacro("_BIG_ENDIAN"); 687 Builder.defineMacro("__BIG_ENDIAN__"); 688 689 // Subtarget options. 690 Builder.defineMacro("__NATURAL_ALIGNMENT__"); 691 Builder.defineMacro("__REGISTER_PREFIX__", ""); 692 693 // FIXME: Should be controlled by command line option. 694 Builder.defineMacro("__LONG_DOUBLE_128__"); 695 696 if (Opts.AltiVec) { 697 Builder.defineMacro("__VEC__", "10206"); 698 Builder.defineMacro("__ALTIVEC__"); 699 } 700} 701 702 703const char * const PPCTargetInfo::GCCRegNames[] = { 704 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 705 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 706 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", 707 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", 708 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", 709 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", 710 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", 711 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", 712 "mq", "lr", "ctr", "ap", 713 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", 714 "xer", 715 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", 716 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", 717 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", 718 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", 719 "vrsave", "vscr", 720 "spe_acc", "spefscr", 721 "sfp" 722}; 723 724void PPCTargetInfo::getGCCRegNames(const char * const *&Names, 725 unsigned &NumNames) const { 726 Names = GCCRegNames; 727 NumNames = llvm::array_lengthof(GCCRegNames); 728} 729 730const TargetInfo::GCCRegAlias PPCTargetInfo::GCCRegAliases[] = { 731 // While some of these aliases do map to different registers 732 // they still share the same register name. 733 { { "0" }, "r0" }, 734 { { "1"}, "r1" }, 735 { { "2" }, "r2" }, 736 { { "3" }, "r3" }, 737 { { "4" }, "r4" }, 738 { { "5" }, "r5" }, 739 { { "6" }, "r6" }, 740 { { "7" }, "r7" }, 741 { { "8" }, "r8" }, 742 { { "9" }, "r9" }, 743 { { "10" }, "r10" }, 744 { { "11" }, "r11" }, 745 { { "12" }, "r12" }, 746 { { "13" }, "r13" }, 747 { { "14" }, "r14" }, 748 { { "15" }, "r15" }, 749 { { "16" }, "r16" }, 750 { { "17" }, "r17" }, 751 { { "18" }, "r18" }, 752 { { "19" }, "r19" }, 753 { { "20" }, "r20" }, 754 { { "21" }, "r21" }, 755 { { "22" }, "r22" }, 756 { { "23" }, "r23" }, 757 { { "24" }, "r24" }, 758 { { "25" }, "r25" }, 759 { { "26" }, "r26" }, 760 { { "27" }, "r27" }, 761 { { "28" }, "r28" }, 762 { { "29" }, "r29" }, 763 { { "30" }, "r30" }, 764 { { "31" }, "r31" }, 765 { { "fr0" }, "f0" }, 766 { { "fr1" }, "f1" }, 767 { { "fr2" }, "f2" }, 768 { { "fr3" }, "f3" }, 769 { { "fr4" }, "f4" }, 770 { { "fr5" }, "f5" }, 771 { { "fr6" }, "f6" }, 772 { { "fr7" }, "f7" }, 773 { { "fr8" }, "f8" }, 774 { { "fr9" }, "f9" }, 775 { { "fr10" }, "f10" }, 776 { { "fr11" }, "f11" }, 777 { { "fr12" }, "f12" }, 778 { { "fr13" }, "f13" }, 779 { { "fr14" }, "f14" }, 780 { { "fr15" }, "f15" }, 781 { { "fr16" }, "f16" }, 782 { { "fr17" }, "f17" }, 783 { { "fr18" }, "f18" }, 784 { { "fr19" }, "f19" }, 785 { { "fr20" }, "f20" }, 786 { { "fr21" }, "f21" }, 787 { { "fr22" }, "f22" }, 788 { { "fr23" }, "f23" }, 789 { { "fr24" }, "f24" }, 790 { { "fr25" }, "f25" }, 791 { { "fr26" }, "f26" }, 792 { { "fr27" }, "f27" }, 793 { { "fr28" }, "f28" }, 794 { { "fr29" }, "f29" }, 795 { { "fr30" }, "f30" }, 796 { { "fr31" }, "f31" }, 797 { { "cc" }, "cr0" }, 798}; 799 800void PPCTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, 801 unsigned &NumAliases) const { 802 Aliases = GCCRegAliases; 803 NumAliases = llvm::array_lengthof(GCCRegAliases); 804} 805} // end anonymous namespace. 806 807namespace { 808class PPC32TargetInfo : public PPCTargetInfo { 809public: 810 PPC32TargetInfo(const std::string &triple) : PPCTargetInfo(triple) { 811 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 812 "i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32"; 813 814 switch (getTriple().getOS()) { 815 case llvm::Triple::FreeBSD: 816 case llvm::Triple::NetBSD: 817 SizeType = UnsignedInt; 818 break; 819 default: 820 break; 821 } 822 } 823 824 virtual const char *getVAListDeclaration() const { 825 // This is the ELF definition, and is overridden by the Darwin sub-target 826 return "typedef struct __va_list_tag {" 827 " unsigned char gpr;" 828 " unsigned char fpr;" 829 " unsigned short reserved;" 830 " void* overflow_arg_area;" 831 " void* reg_save_area;" 832 "} __builtin_va_list[1];"; 833 } 834}; 835} // end anonymous namespace. 836 837namespace { 838class PPC64TargetInfo : public PPCTargetInfo { 839public: 840 PPC64TargetInfo(const std::string& triple) : PPCTargetInfo(triple) { 841 LongWidth = LongAlign = PointerWidth = PointerAlign = 64; 842 IntMaxType = SignedLong; 843 UIntMaxType = UnsignedLong; 844 Int64Type = SignedLong; 845 DescriptionString = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 846 "i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32:64"; 847 } 848 virtual const char *getVAListDeclaration() const { 849 return "typedef char* __builtin_va_list;"; 850 } 851}; 852} // end anonymous namespace. 853 854 855namespace { 856class DarwinPPC32TargetInfo : 857 public DarwinTargetInfo<PPC32TargetInfo> { 858public: 859 DarwinPPC32TargetInfo(const std::string& triple) 860 : DarwinTargetInfo<PPC32TargetInfo>(triple) { 861 HasAlignMac68kSupport = true; 862 BoolWidth = BoolAlign = 32; //XXX support -mone-byte-bool? 863 } 864 virtual const char *getVAListDeclaration() const { 865 return "typedef char* __builtin_va_list;"; 866 } 867}; 868 869class DarwinPPC64TargetInfo : 870 public DarwinTargetInfo<PPC64TargetInfo> { 871public: 872 DarwinPPC64TargetInfo(const std::string& triple) 873 : DarwinTargetInfo<PPC64TargetInfo>(triple) { 874 HasAlignMac68kSupport = true; 875 } 876}; 877} // end anonymous namespace. 878 879namespace { 880 class PTXTargetInfo : public TargetInfo { 881 static const char * const GCCRegNames[]; 882 static const Builtin::Info BuiltinInfo[]; 883 public: 884 PTXTargetInfo(const std::string& triple) : TargetInfo(triple) { 885 TLSSupported = false; 886 LongWidth = LongAlign = 64; 887 } 888 virtual void getTargetDefines(const LangOptions &Opts, 889 MacroBuilder &Builder) const { 890 Builder.defineMacro("__PTX__"); 891 } 892 virtual void getTargetBuiltins(const Builtin::Info *&Records, 893 unsigned &NumRecords) const { 894 Records = BuiltinInfo; 895 NumRecords = clang::PTX::LastTSBuiltin-Builtin::FirstTSBuiltin; 896 } 897 898 virtual void getGCCRegNames(const char * const *&Names, 899 unsigned &NumNames) const; 900 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 901 unsigned &NumAliases) const { 902 // No aliases. 903 Aliases = 0; 904 NumAliases = 0; 905 } 906 virtual bool validateAsmConstraint(const char *&Name, 907 TargetInfo::ConstraintInfo &info) const { 908 // FIXME: implement 909 return true; 910 } 911 virtual const char *getClobbers() const { 912 // FIXME: Is this really right? 913 return ""; 914 } 915 virtual const char *getVAListDeclaration() const { 916 // FIXME: implement 917 return "typedef char* __builtin_va_list;"; 918 } 919 }; 920 921 const Builtin::Info PTXTargetInfo::BuiltinInfo[] = { 922#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES }, 923#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\ 924 ALL_LANGUAGES }, 925#include "clang/Basic/BuiltinsPTX.def" 926 }; 927 928 const char * const PTXTargetInfo::GCCRegNames[] = { 929 "r0" 930 }; 931 932 void PTXTargetInfo::getGCCRegNames(const char * const *&Names, 933 unsigned &NumNames) const { 934 Names = GCCRegNames; 935 NumNames = llvm::array_lengthof(GCCRegNames); 936 } 937 938 939 class PTX32TargetInfo : public PTXTargetInfo { 940 public: 941 PTX32TargetInfo(const std::string& triple) : PTXTargetInfo(triple) { 942 PointerWidth = PointerAlign = 32; 943 SizeType = PtrDiffType = IntPtrType = TargetInfo::UnsignedInt; 944 DescriptionString 945 = "e-p:32:32-i64:64:64-f64:64:64-n1:8:16:32:64"; 946 } 947 }; 948 949 class PTX64TargetInfo : public PTXTargetInfo { 950 public: 951 PTX64TargetInfo(const std::string& triple) : PTXTargetInfo(triple) { 952 PointerWidth = PointerAlign = 64; 953 SizeType = PtrDiffType = IntPtrType = TargetInfo::UnsignedLongLong; 954 DescriptionString 955 = "e-p:64:64-i64:64:64-f64:64:64-n1:8:16:32:64"; 956 } 957 }; 958} 959 960namespace { 961// MBlaze abstract base class 962class MBlazeTargetInfo : public TargetInfo { 963 static const char * const GCCRegNames[]; 964 static const TargetInfo::GCCRegAlias GCCRegAliases[]; 965 966public: 967 MBlazeTargetInfo(const std::string& triple) : TargetInfo(triple) { 968 DescriptionString = "E-p:32:32:32-i8:8:8-i16:16:16"; 969 } 970 971 virtual void getTargetBuiltins(const Builtin::Info *&Records, 972 unsigned &NumRecords) const { 973 // FIXME: Implement. 974 Records = 0; 975 NumRecords = 0; 976 } 977 978 virtual void getTargetDefines(const LangOptions &Opts, 979 MacroBuilder &Builder) const; 980 981 virtual const char *getVAListDeclaration() const { 982 return "typedef char* __builtin_va_list;"; 983 } 984 virtual const char *getTargetPrefix() const { 985 return "mblaze"; 986 } 987 virtual void getGCCRegNames(const char * const *&Names, 988 unsigned &NumNames) const; 989 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 990 unsigned &NumAliases) const; 991 virtual bool validateAsmConstraint(const char *&Name, 992 TargetInfo::ConstraintInfo &Info) const { 993 switch (*Name) { 994 default: return false; 995 case 'O': // Zero 996 return true; 997 case 'b': // Base register 998 case 'f': // Floating point register 999 Info.setAllowsRegister(); 1000 return true; 1001 } 1002 } 1003 virtual const char *getClobbers() const { 1004 return ""; 1005 } 1006}; 1007 1008/// MBlazeTargetInfo::getTargetDefines - Return a set of the MBlaze-specific 1009/// #defines that are not tied to a specific subtarget. 1010void MBlazeTargetInfo::getTargetDefines(const LangOptions &Opts, 1011 MacroBuilder &Builder) const { 1012 // Target identification. 1013 Builder.defineMacro("__microblaze__"); 1014 Builder.defineMacro("_ARCH_MICROBLAZE"); 1015 Builder.defineMacro("__MICROBLAZE__"); 1016 1017 // Target properties. 1018 Builder.defineMacro("_BIG_ENDIAN"); 1019 Builder.defineMacro("__BIG_ENDIAN__"); 1020 1021 // Subtarget options. 1022 Builder.defineMacro("__REGISTER_PREFIX__", ""); 1023} 1024 1025 1026const char * const MBlazeTargetInfo::GCCRegNames[] = { 1027 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 1028 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 1029 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", 1030 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", 1031 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7", 1032 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15", 1033 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23", 1034 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31", 1035 "hi", "lo", "accum","rmsr", "$fcc1","$fcc2","$fcc3","$fcc4", 1036 "$fcc5","$fcc6","$fcc7","$ap", "$rap", "$frp" 1037}; 1038 1039void MBlazeTargetInfo::getGCCRegNames(const char * const *&Names, 1040 unsigned &NumNames) const { 1041 Names = GCCRegNames; 1042 NumNames = llvm::array_lengthof(GCCRegNames); 1043} 1044 1045const TargetInfo::GCCRegAlias MBlazeTargetInfo::GCCRegAliases[] = { 1046 { {"f0"}, "r0" }, 1047 { {"f1"}, "r1" }, 1048 { {"f2"}, "r2" }, 1049 { {"f3"}, "r3" }, 1050 { {"f4"}, "r4" }, 1051 { {"f5"}, "r5" }, 1052 { {"f6"}, "r6" }, 1053 { {"f7"}, "r7" }, 1054 { {"f8"}, "r8" }, 1055 { {"f9"}, "r9" }, 1056 { {"f10"}, "r10" }, 1057 { {"f11"}, "r11" }, 1058 { {"f12"}, "r12" }, 1059 { {"f13"}, "r13" }, 1060 { {"f14"}, "r14" }, 1061 { {"f15"}, "r15" }, 1062 { {"f16"}, "r16" }, 1063 { {"f17"}, "r17" }, 1064 { {"f18"}, "r18" }, 1065 { {"f19"}, "r19" }, 1066 { {"f20"}, "r20" }, 1067 { {"f21"}, "r21" }, 1068 { {"f22"}, "r22" }, 1069 { {"f23"}, "r23" }, 1070 { {"f24"}, "r24" }, 1071 { {"f25"}, "r25" }, 1072 { {"f26"}, "r26" }, 1073 { {"f27"}, "r27" }, 1074 { {"f28"}, "r28" }, 1075 { {"f29"}, "r29" }, 1076 { {"f30"}, "r30" }, 1077 { {"f31"}, "r31" }, 1078}; 1079 1080void MBlazeTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, 1081 unsigned &NumAliases) const { 1082 Aliases = GCCRegAliases; 1083 NumAliases = llvm::array_lengthof(GCCRegAliases); 1084} 1085} // end anonymous namespace. 1086 1087namespace { 1088// Namespace for x86 abstract base class 1089const Builtin::Info BuiltinInfo[] = { 1090#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES }, 1091#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\ 1092 ALL_LANGUAGES }, 1093#include "clang/Basic/BuiltinsX86.def" 1094}; 1095 1096static const char* const GCCRegNames[] = { 1097 "ax", "dx", "cx", "bx", "si", "di", "bp", "sp", 1098 "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)", 1099 "argp", "flags", "fpcr", "fpsr", "dirflag", "frame", 1100 "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7", 1101 "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7", 1102 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 1103 "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15", 1104}; 1105 1106const TargetInfo::AddlRegName AddlRegNames[] = { 1107 { { "al", "ah", "eax", "rax" }, 0 }, 1108 { { "bl", "bh", "ebx", "rbx" }, 3 }, 1109 { { "cl", "ch", "ecx", "rcx" }, 2 }, 1110 { { "dl", "dh", "edx", "rdx" }, 1 }, 1111 { { "esi", "rsi" }, 4 }, 1112 { { "edi", "rdi" }, 5 }, 1113 { { "esp", "rsp" }, 7 }, 1114 { { "ebp", "rbp" }, 6 }, 1115}; 1116 1117// X86 target abstract base class; x86-32 and x86-64 are very close, so 1118// most of the implementation can be shared. 1119class X86TargetInfo : public TargetInfo { 1120 enum X86SSEEnum { 1121 NoSSE, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42 1122 } SSELevel; 1123 enum MMX3DNowEnum { 1124 NoMMX3DNow, MMX, AMD3DNow, AMD3DNowAthlon 1125 } MMX3DNowLevel; 1126 1127 bool HasAES; 1128 bool HasAVX; 1129 1130public: 1131 X86TargetInfo(const std::string& triple) 1132 : TargetInfo(triple), SSELevel(NoSSE), MMX3DNowLevel(NoMMX3DNow), 1133 HasAES(false), HasAVX(false) { 1134 LongDoubleFormat = &llvm::APFloat::x87DoubleExtended; 1135 } 1136 virtual void getTargetBuiltins(const Builtin::Info *&Records, 1137 unsigned &NumRecords) const { 1138 Records = BuiltinInfo; 1139 NumRecords = clang::X86::LastTSBuiltin-Builtin::FirstTSBuiltin; 1140 } 1141 virtual void getGCCRegNames(const char * const *&Names, 1142 unsigned &NumNames) const { 1143 Names = GCCRegNames; 1144 NumNames = llvm::array_lengthof(GCCRegNames); 1145 } 1146 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 1147 unsigned &NumAliases) const { 1148 Aliases = 0; 1149 NumAliases = 0; 1150 } 1151 virtual void getGCCAddlRegNames(const AddlRegName *&Names, 1152 unsigned &NumNames) const { 1153 Names = AddlRegNames; 1154 NumNames = llvm::array_lengthof(AddlRegNames); 1155 } 1156 virtual bool validateAsmConstraint(const char *&Name, 1157 TargetInfo::ConstraintInfo &info) const; 1158 virtual std::string convertConstraint(const char *&Constraint) const; 1159 virtual const char *getClobbers() const { 1160 return "~{dirflag},~{fpsr},~{flags}"; 1161 } 1162 virtual void getTargetDefines(const LangOptions &Opts, 1163 MacroBuilder &Builder) const; 1164 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features, 1165 const std::string &Name, 1166 bool Enabled) const; 1167 virtual void getDefaultFeatures(const std::string &CPU, 1168 llvm::StringMap<bool> &Features) const; 1169 virtual void HandleTargetFeatures(std::vector<std::string> &Features); 1170 virtual const char* getABI() const { 1171 return MMX3DNowLevel == NoMMX3DNow ? "no-mmx" : ""; 1172 } 1173}; 1174 1175void X86TargetInfo::getDefaultFeatures(const std::string &CPU, 1176 llvm::StringMap<bool> &Features) const { 1177 // FIXME: This should not be here. 1178 Features["3dnow"] = false; 1179 Features["3dnowa"] = false; 1180 Features["mmx"] = false; 1181 Features["sse"] = false; 1182 Features["sse2"] = false; 1183 Features["sse3"] = false; 1184 Features["ssse3"] = false; 1185 Features["sse41"] = false; 1186 Features["sse42"] = false; 1187 Features["aes"] = false; 1188 Features["avx"] = false; 1189 1190 // LLVM does not currently recognize this. 1191 // Features["sse4a"] = false; 1192 1193 // FIXME: This *really* should not be here. 1194 1195 // X86_64 always has SSE2. 1196 if (PointerWidth == 64) 1197 Features["sse2"] = Features["sse"] = Features["mmx"] = true; 1198 1199 if (CPU == "generic" || CPU == "i386" || CPU == "i486" || CPU == "i586" || 1200 CPU == "pentium" || CPU == "i686" || CPU == "pentiumpro") 1201 ; 1202 else if (CPU == "pentium-mmx" || CPU == "pentium2") 1203 setFeatureEnabled(Features, "mmx", true); 1204 else if (CPU == "pentium3") { 1205 setFeatureEnabled(Features, "mmx", true); 1206 setFeatureEnabled(Features, "sse", true); 1207 } else if (CPU == "pentium-m" || CPU == "pentium4" || CPU == "x86-64") { 1208 setFeatureEnabled(Features, "mmx", true); 1209 setFeatureEnabled(Features, "sse2", true); 1210 } else if (CPU == "yonah" || CPU == "prescott" || CPU == "nocona") { 1211 setFeatureEnabled(Features, "mmx", true); 1212 setFeatureEnabled(Features, "sse3", true); 1213 } else if (CPU == "core2") { 1214 setFeatureEnabled(Features, "mmx", true); 1215 setFeatureEnabled(Features, "ssse3", true); 1216 } else if (CPU == "penryn") { 1217 setFeatureEnabled(Features, "mmx", true); 1218 setFeatureEnabled(Features, "sse4", true); 1219 Features["sse42"] = false; 1220 } else if (CPU == "atom") { 1221 setFeatureEnabled(Features, "mmx", true); 1222 setFeatureEnabled(Features, "sse3", true); 1223 } else if (CPU == "corei7") { 1224 setFeatureEnabled(Features, "mmx", true); 1225 setFeatureEnabled(Features, "sse4", true); 1226 setFeatureEnabled(Features, "aes", true); 1227 } else if (CPU == "corei7-avx") { 1228 setFeatureEnabled(Features, "mmx", true); 1229 setFeatureEnabled(Features, "sse4", true); 1230 setFeatureEnabled(Features, "aes", true); 1231 //setFeatureEnabled(Features, "avx", true); 1232 } else if (CPU == "k6" || CPU == "winchip-c6") 1233 setFeatureEnabled(Features, "mmx", true); 1234 else if (CPU == "k6-2" || CPU == "k6-3" || CPU == "athlon" || 1235 CPU == "athlon-tbird" || CPU == "winchip2" || CPU == "c3") { 1236 setFeatureEnabled(Features, "3dnow", true); 1237 } else if (CPU == "athlon-4" || CPU == "athlon-xp" || CPU == "athlon-mp") { 1238 setFeatureEnabled(Features, "sse", true); 1239 setFeatureEnabled(Features, "3dnowa", true); 1240 } else if (CPU == "k8" || CPU == "opteron" || CPU == "athlon64" || 1241 CPU == "athlon-fx") { 1242 setFeatureEnabled(Features, "sse2", true); 1243 setFeatureEnabled(Features, "3dnowa", true); 1244 } else if (CPU == "k8-sse3") { 1245 setFeatureEnabled(Features, "sse3", true); 1246 setFeatureEnabled(Features, "3dnowa", true); 1247 } else if (CPU == "c3-2") { 1248 setFeatureEnabled(Features, "mmx", true); 1249 setFeatureEnabled(Features, "sse", true); 1250 } 1251} 1252 1253bool X86TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features, 1254 const std::string &Name, 1255 bool Enabled) const { 1256 // FIXME: This *really* should not be here. We need some way of translating 1257 // options into llvm subtarget features. 1258 if (!Features.count(Name) && 1259 (Name != "sse4" && Name != "sse4.2" && Name != "sse4.1")) 1260 return false; 1261 1262 if (Enabled) { 1263 if (Name == "mmx") 1264 Features["mmx"] = true; 1265 else if (Name == "sse") 1266 Features["sse"] = true; 1267 else if (Name == "sse2") 1268 Features["sse"] = Features["sse2"] = true; 1269 else if (Name == "sse3") 1270 Features["sse"] = Features["sse2"] = Features["sse3"] = true; 1271 else if (Name == "ssse3") 1272 Features["sse"] = Features["sse2"] = Features["sse3"] = 1273 Features["ssse3"] = true; 1274 else if (Name == "sse4" || Name == "sse4.2") 1275 Features["sse"] = Features["sse2"] = Features["sse3"] = 1276 Features["ssse3"] = Features["sse41"] = Features["sse42"] = true; 1277 else if (Name == "sse4.1") 1278 Features["sse"] = Features["sse2"] = Features["sse3"] = 1279 Features["ssse3"] = Features["sse41"] = true; 1280 else if (Name == "3dnow") 1281 Features["mmx"] = Features["3dnow"] = true; 1282 else if (Name == "3dnowa") 1283 Features["mmx"] = Features["3dnow"] = Features["3dnowa"] = true; 1284 else if (Name == "aes") 1285 Features["aes"] = true; 1286 else if (Name == "avx") 1287 Features["avx"] = true; 1288 } else { 1289 if (Name == "mmx") 1290 Features["mmx"] = Features["3dnow"] = Features["3dnowa"] = false; 1291 else if (Name == "sse") 1292 Features["sse"] = Features["sse2"] = Features["sse3"] = 1293 Features["ssse3"] = Features["sse41"] = Features["sse42"] = false; 1294 else if (Name == "sse2") 1295 Features["sse2"] = Features["sse3"] = Features["ssse3"] = 1296 Features["sse41"] = Features["sse42"] = false; 1297 else if (Name == "sse3") 1298 Features["sse3"] = Features["ssse3"] = Features["sse41"] = 1299 Features["sse42"] = false; 1300 else if (Name == "ssse3") 1301 Features["ssse3"] = Features["sse41"] = Features["sse42"] = false; 1302 else if (Name == "sse4" || Name == "sse4.1") 1303 Features["sse41"] = Features["sse42"] = false; 1304 else if (Name == "sse4.2") 1305 Features["sse42"] = false; 1306 else if (Name == "3dnow") 1307 Features["3dnow"] = Features["3dnowa"] = false; 1308 else if (Name == "3dnowa") 1309 Features["3dnowa"] = false; 1310 else if (Name == "aes") 1311 Features["aes"] = false; 1312 else if (Name == "avx") 1313 Features["avx"] = false; 1314 } 1315 1316 return true; 1317} 1318 1319/// HandleTargetOptions - Perform initialization based on the user 1320/// configured set of features. 1321void X86TargetInfo::HandleTargetFeatures(std::vector<std::string> &Features) { 1322 // Remember the maximum enabled sselevel. 1323 for (unsigned i = 0, e = Features.size(); i !=e; ++i) { 1324 // Ignore disabled features. 1325 if (Features[i][0] == '-') 1326 continue; 1327 1328 if (Features[i].substr(1) == "aes") { 1329 HasAES = true; 1330 continue; 1331 } 1332 1333 // FIXME: Not sure yet how to treat AVX in regard to SSE levels. 1334 // For now let it be enabled together with other SSE levels. 1335 if (Features[i].substr(1) == "avx") { 1336 HasAVX = true; 1337 continue; 1338 } 1339 1340 assert(Features[i][0] == '+' && "Invalid target feature!"); 1341 X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(Features[i].substr(1)) 1342 .Case("sse42", SSE42) 1343 .Case("sse41", SSE41) 1344 .Case("ssse3", SSSE3) 1345 .Case("sse3", SSE3) 1346 .Case("sse2", SSE2) 1347 .Case("sse", SSE1) 1348 .Default(NoSSE); 1349 SSELevel = std::max(SSELevel, Level); 1350 1351 MMX3DNowEnum ThreeDNowLevel = 1352 llvm::StringSwitch<MMX3DNowEnum>(Features[i].substr(1)) 1353 .Case("3dnowa", AMD3DNowAthlon) 1354 .Case("3dnow", AMD3DNow) 1355 .Case("mmx", MMX) 1356 .Default(NoMMX3DNow); 1357 1358 MMX3DNowLevel = std::max(MMX3DNowLevel, ThreeDNowLevel); 1359 } 1360 1361 // Don't tell the backend if we're turning off mmx; it will end up disabling 1362 // SSE, which we don't want. 1363 std::vector<std::string>::iterator it; 1364 it = std::find(Features.begin(), Features.end(), "-mmx"); 1365 if (it != Features.end()) 1366 Features.erase(it); 1367} 1368 1369/// X86TargetInfo::getTargetDefines - Return a set of the X86-specific #defines 1370/// that are not tied to a specific subtarget. 1371void X86TargetInfo::getTargetDefines(const LangOptions &Opts, 1372 MacroBuilder &Builder) const { 1373 // Target identification. 1374 if (PointerWidth == 64) { 1375 Builder.defineMacro("_LP64"); 1376 Builder.defineMacro("__LP64__"); 1377 Builder.defineMacro("__amd64__"); 1378 Builder.defineMacro("__amd64"); 1379 Builder.defineMacro("__x86_64"); 1380 Builder.defineMacro("__x86_64__"); 1381 } else { 1382 DefineStd(Builder, "i386", Opts); 1383 } 1384 1385 if (HasAES) 1386 Builder.defineMacro("__AES__"); 1387 1388 if (HasAVX) 1389 Builder.defineMacro("__AVX__"); 1390 1391 // Target properties. 1392 Builder.defineMacro("__LITTLE_ENDIAN__"); 1393 1394 // Subtarget options. 1395 Builder.defineMacro("__nocona"); 1396 Builder.defineMacro("__nocona__"); 1397 Builder.defineMacro("__tune_nocona__"); 1398 Builder.defineMacro("__REGISTER_PREFIX__", ""); 1399 1400 // Define __NO_MATH_INLINES on linux/x86 so that we don't get inline 1401 // functions in glibc header files that use FP Stack inline asm which the 1402 // backend can't deal with (PR879). 1403 Builder.defineMacro("__NO_MATH_INLINES"); 1404 1405 // Each case falls through to the previous one here. 1406 switch (SSELevel) { 1407 case SSE42: 1408 Builder.defineMacro("__SSE4_2__"); 1409 case SSE41: 1410 Builder.defineMacro("__SSE4_1__"); 1411 case SSSE3: 1412 Builder.defineMacro("__SSSE3__"); 1413 case SSE3: 1414 Builder.defineMacro("__SSE3__"); 1415 case SSE2: 1416 Builder.defineMacro("__SSE2__"); 1417 Builder.defineMacro("__SSE2_MATH__"); // -mfp-math=sse always implied. 1418 case SSE1: 1419 Builder.defineMacro("__SSE__"); 1420 Builder.defineMacro("__SSE_MATH__"); // -mfp-math=sse always implied. 1421 case NoSSE: 1422 break; 1423 } 1424 1425 if (Opts.Microsoft && PointerWidth == 32) { 1426 switch (SSELevel) { 1427 case SSE42: 1428 case SSE41: 1429 case SSSE3: 1430 case SSE3: 1431 case SSE2: 1432 Builder.defineMacro("_M_IX86_FP", llvm::Twine(2)); 1433 break; 1434 case SSE1: 1435 Builder.defineMacro("_M_IX86_FP", llvm::Twine(1)); 1436 break; 1437 default: 1438 Builder.defineMacro("_M_IX86_FP", llvm::Twine(0)); 1439 } 1440 } 1441 1442 // Each case falls through to the previous one here. 1443 switch (MMX3DNowLevel) { 1444 case AMD3DNowAthlon: 1445 Builder.defineMacro("__3dNOW_A__"); 1446 case AMD3DNow: 1447 Builder.defineMacro("__3dNOW__"); 1448 case MMX: 1449 Builder.defineMacro("__MMX__"); 1450 case NoMMX3DNow: 1451 break; 1452 } 1453} 1454 1455 1456bool 1457X86TargetInfo::validateAsmConstraint(const char *&Name, 1458 TargetInfo::ConstraintInfo &Info) const { 1459 switch (*Name) { 1460 default: return false; 1461 case 'Y': // first letter of a pair: 1462 switch (*(Name+1)) { 1463 default: return false; 1464 case '0': // First SSE register. 1465 case 't': // Any SSE register, when SSE2 is enabled. 1466 case 'i': // Any SSE register, when SSE2 and inter-unit moves enabled. 1467 case 'm': // any MMX register, when inter-unit moves enabled. 1468 break; // falls through to setAllowsRegister. 1469 } 1470 case 'a': // eax. 1471 case 'b': // ebx. 1472 case 'c': // ecx. 1473 case 'd': // edx. 1474 case 'S': // esi. 1475 case 'D': // edi. 1476 case 'A': // edx:eax. 1477 case 'f': // any x87 floating point stack register. 1478 case 't': // top of floating point stack. 1479 case 'u': // second from top of floating point stack. 1480 case 'q': // Any register accessible as [r]l: a, b, c, and d. 1481 case 'y': // Any MMX register. 1482 case 'x': // Any SSE register. 1483 case 'Q': // Any register accessible as [r]h: a, b, c, and d. 1484 case 'R': // "Legacy" registers: ax, bx, cx, dx, di, si, sp, bp. 1485 case 'l': // "Index" registers: any general register that can be used as an 1486 // index in a base+index memory access. 1487 Info.setAllowsRegister(); 1488 return true; 1489 case 'C': // SSE floating point constant. 1490 case 'G': // x87 floating point constant. 1491 case 'e': // 32-bit signed integer constant for use with zero-extending 1492 // x86_64 instructions. 1493 case 'Z': // 32-bit unsigned integer constant for use with zero-extending 1494 // x86_64 instructions. 1495 return true; 1496 } 1497 return false; 1498} 1499 1500 1501std::string 1502X86TargetInfo::convertConstraint(const char *&Constraint) const { 1503 switch (*Constraint) { 1504 case 'a': return std::string("{ax}"); 1505 case 'b': return std::string("{bx}"); 1506 case 'c': return std::string("{cx}"); 1507 case 'd': return std::string("{dx}"); 1508 case 'S': return std::string("{si}"); 1509 case 'D': return std::string("{di}"); 1510 case 'p': // address 1511 return std::string("im"); 1512 case 't': // top of floating point stack. 1513 return std::string("{st}"); 1514 case 'u': // second from top of floating point stack. 1515 return std::string("{st(1)}"); // second from top of floating point stack. 1516 default: 1517 return std::string(1, *Constraint); 1518 } 1519} 1520} // end anonymous namespace 1521 1522namespace { 1523// X86-32 generic target 1524class X86_32TargetInfo : public X86TargetInfo { 1525public: 1526 X86_32TargetInfo(const std::string& triple) : X86TargetInfo(triple) { 1527 DoubleAlign = LongLongAlign = 32; 1528 LongDoubleWidth = 96; 1529 LongDoubleAlign = 32; 1530 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 1531 "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-" 1532 "a0:0:64-f80:32:32-n8:16:32"; 1533 SizeType = UnsignedInt; 1534 PtrDiffType = SignedInt; 1535 IntPtrType = SignedInt; 1536 RegParmMax = 3; 1537 1538 // Use fpret for all types. 1539 RealTypeUsesObjCFPRet = ((1 << TargetInfo::Float) | 1540 (1 << TargetInfo::Double) | 1541 (1 << TargetInfo::LongDouble)); 1542 } 1543 virtual const char *getVAListDeclaration() const { 1544 return "typedef char* __builtin_va_list;"; 1545 } 1546 1547 int getEHDataRegisterNumber(unsigned RegNo) const { 1548 if (RegNo == 0) return 0; 1549 if (RegNo == 1) return 2; 1550 return -1; 1551 } 1552}; 1553} // end anonymous namespace 1554 1555namespace { 1556class OpenBSDI386TargetInfo : public OpenBSDTargetInfo<X86_32TargetInfo> { 1557public: 1558 OpenBSDI386TargetInfo(const std::string& triple) : 1559 OpenBSDTargetInfo<X86_32TargetInfo>(triple) { 1560 SizeType = UnsignedLong; 1561 IntPtrType = SignedLong; 1562 PtrDiffType = SignedLong; 1563 } 1564}; 1565} // end anonymous namespace 1566 1567namespace { 1568class DarwinI386TargetInfo : public DarwinTargetInfo<X86_32TargetInfo> { 1569public: 1570 DarwinI386TargetInfo(const std::string& triple) : 1571 DarwinTargetInfo<X86_32TargetInfo>(triple) { 1572 LongDoubleWidth = 128; 1573 LongDoubleAlign = 128; 1574 SizeType = UnsignedLong; 1575 IntPtrType = SignedLong; 1576 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 1577 "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-" 1578 "a0:0:64-f80:128:128-n8:16:32"; 1579 HasAlignMac68kSupport = true; 1580 } 1581 1582}; 1583} // end anonymous namespace 1584 1585namespace { 1586// x86-32 Windows target 1587class WindowsX86_32TargetInfo : public WindowsTargetInfo<X86_32TargetInfo> { 1588public: 1589 WindowsX86_32TargetInfo(const std::string& triple) 1590 : WindowsTargetInfo<X86_32TargetInfo>(triple) { 1591 TLSSupported = false; 1592 WCharType = UnsignedShort; 1593 DoubleAlign = LongLongAlign = 64; 1594 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 1595 "i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-" 1596 "v128:128:128-a0:0:64-f80:32:32-n8:16:32"; 1597 } 1598 virtual void getTargetDefines(const LangOptions &Opts, 1599 MacroBuilder &Builder) const { 1600 WindowsTargetInfo<X86_32TargetInfo>::getTargetDefines(Opts, Builder); 1601 } 1602}; 1603} // end anonymous namespace 1604 1605namespace { 1606 1607// x86-32 Windows Visual Studio target 1608class VisualStudioWindowsX86_32TargetInfo : public WindowsX86_32TargetInfo { 1609public: 1610 VisualStudioWindowsX86_32TargetInfo(const std::string& triple) 1611 : WindowsX86_32TargetInfo(triple) { 1612 LongDoubleWidth = LongDoubleAlign = 64; 1613 LongDoubleFormat = &llvm::APFloat::IEEEdouble; 1614 } 1615 virtual void getTargetDefines(const LangOptions &Opts, 1616 MacroBuilder &Builder) const { 1617 WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder); 1618 WindowsX86_32TargetInfo::getVisualStudioDefines(Opts, Builder); 1619 // The value of the following reflects processor type. 1620 // 300=386, 400=486, 500=Pentium, 600=Blend (default) 1621 // We lost the original triple, so we use the default. 1622 Builder.defineMacro("_M_IX86", "600"); 1623 } 1624}; 1625} // end anonymous namespace 1626 1627namespace { 1628// x86-32 MinGW target 1629class MinGWX86_32TargetInfo : public WindowsX86_32TargetInfo { 1630public: 1631 MinGWX86_32TargetInfo(const std::string& triple) 1632 : WindowsX86_32TargetInfo(triple) { 1633 } 1634 virtual void getTargetDefines(const LangOptions &Opts, 1635 MacroBuilder &Builder) const { 1636 WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder); 1637 DefineStd(Builder, "WIN32", Opts); 1638 DefineStd(Builder, "WINNT", Opts); 1639 Builder.defineMacro("_X86_"); 1640 Builder.defineMacro("__MSVCRT__"); 1641 Builder.defineMacro("__MINGW32__"); 1642 1643 // mingw32-gcc provides __declspec(a) as alias of __attribute__((a)). 1644 // In contrast, clang-cc1 provides __declspec(a) with -fms-extensions. 1645 if (Opts.Microsoft) 1646 // Provide "as-is" __declspec. 1647 Builder.defineMacro("__declspec", "__declspec"); 1648 else 1649 // Provide alias of __attribute__ like mingw32-gcc. 1650 Builder.defineMacro("__declspec(a)", "__attribute__((a))"); 1651 } 1652}; 1653} // end anonymous namespace 1654 1655namespace { 1656// x86-32 Cygwin target 1657class CygwinX86_32TargetInfo : public X86_32TargetInfo { 1658public: 1659 CygwinX86_32TargetInfo(const std::string& triple) 1660 : X86_32TargetInfo(triple) { 1661 TLSSupported = false; 1662 WCharType = UnsignedShort; 1663 DoubleAlign = LongLongAlign = 64; 1664 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 1665 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-" 1666 "a0:0:64-f80:32:32-n8:16:32"; 1667 } 1668 virtual void getTargetDefines(const LangOptions &Opts, 1669 MacroBuilder &Builder) const { 1670 X86_32TargetInfo::getTargetDefines(Opts, Builder); 1671 Builder.defineMacro("__CYGWIN__"); 1672 Builder.defineMacro("__CYGWIN32__"); 1673 DefineStd(Builder, "unix", Opts); 1674 if (Opts.CPlusPlus) 1675 Builder.defineMacro("_GNU_SOURCE"); 1676 } 1677}; 1678} // end anonymous namespace 1679 1680namespace { 1681// x86-32 Haiku target 1682class HaikuX86_32TargetInfo : public X86_32TargetInfo { 1683public: 1684 HaikuX86_32TargetInfo(const std::string& triple) 1685 : X86_32TargetInfo(triple) { 1686 SizeType = UnsignedLong; 1687 IntPtrType = SignedLong; 1688 PtrDiffType = SignedLong; 1689 this->UserLabelPrefix = ""; 1690 } 1691 virtual void getTargetDefines(const LangOptions &Opts, 1692 MacroBuilder &Builder) const { 1693 X86_32TargetInfo::getTargetDefines(Opts, Builder); 1694 Builder.defineMacro("__INTEL__"); 1695 Builder.defineMacro("__HAIKU__"); 1696 } 1697}; 1698} // end anonymous namespace 1699 1700// RTEMS Target 1701template<typename Target> 1702class RTEMSTargetInfo : public OSTargetInfo<Target> { 1703protected: 1704 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 1705 MacroBuilder &Builder) const { 1706 // RTEMS defines; list based off of gcc output 1707 1708 // FIXME: Move version number handling to llvm::Triple. 1709 llvm::StringRef Release = Triple.getOSName().substr(strlen("rtems"), 1); 1710 1711 Builder.defineMacro("__rtems__"); 1712 Builder.defineMacro("__ELF__"); 1713 } 1714public: 1715 RTEMSTargetInfo(const std::string &triple) 1716 : OSTargetInfo<Target>(triple) { 1717 this->UserLabelPrefix = ""; 1718 1719 llvm::Triple Triple(triple); 1720 switch (Triple.getArch()) { 1721 default: 1722 case llvm::Triple::x86: 1723 // this->MCountName = ".mcount"; 1724 break; 1725 case llvm::Triple::mips: 1726 case llvm::Triple::mipsel: 1727 case llvm::Triple::ppc: 1728 case llvm::Triple::ppc64: 1729 // this->MCountName = "_mcount"; 1730 break; 1731 case llvm::Triple::arm: 1732 // this->MCountName = "__mcount"; 1733 break; 1734 } 1735 1736 } 1737}; 1738 1739namespace { 1740// x86-32 RTEMS target 1741class RTEMSX86_32TargetInfo : public X86_32TargetInfo { 1742public: 1743 RTEMSX86_32TargetInfo(const std::string& triple) 1744 : X86_32TargetInfo(triple) { 1745 SizeType = UnsignedLong; 1746 IntPtrType = SignedLong; 1747 PtrDiffType = SignedLong; 1748 this->UserLabelPrefix = ""; 1749 } 1750 virtual void getTargetDefines(const LangOptions &Opts, 1751 MacroBuilder &Builder) const { 1752 X86_32TargetInfo::getTargetDefines(Opts, Builder); 1753 Builder.defineMacro("__INTEL__"); 1754 Builder.defineMacro("__rtems__"); 1755 } 1756}; 1757} // end anonymous namespace 1758 1759namespace { 1760// x86-64 generic target 1761class X86_64TargetInfo : public X86TargetInfo { 1762public: 1763 X86_64TargetInfo(const std::string &triple) : X86TargetInfo(triple) { 1764 LongWidth = LongAlign = PointerWidth = PointerAlign = 64; 1765 LongDoubleWidth = 128; 1766 LongDoubleAlign = 128; 1767 LargeArrayMinWidth = 128; 1768 LargeArrayAlign = 128; 1769 IntMaxType = SignedLong; 1770 UIntMaxType = UnsignedLong; 1771 Int64Type = SignedLong; 1772 RegParmMax = 6; 1773 1774 DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 1775 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-" 1776 "a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"; 1777 1778 // Use fpret only for long double. 1779 RealTypeUsesObjCFPRet = (1 << TargetInfo::LongDouble); 1780 } 1781 virtual const char *getVAListDeclaration() const { 1782 return "typedef struct __va_list_tag {" 1783 " unsigned gp_offset;" 1784 " unsigned fp_offset;" 1785 " void* overflow_arg_area;" 1786 " void* reg_save_area;" 1787 "} __va_list_tag;" 1788 "typedef __va_list_tag __builtin_va_list[1];"; 1789 } 1790 1791 int getEHDataRegisterNumber(unsigned RegNo) const { 1792 if (RegNo == 0) return 0; 1793 if (RegNo == 1) return 1; 1794 return -1; 1795 } 1796}; 1797} // end anonymous namespace 1798 1799namespace { 1800// x86-64 Windows target 1801class WindowsX86_64TargetInfo : public WindowsTargetInfo<X86_64TargetInfo> { 1802public: 1803 WindowsX86_64TargetInfo(const std::string& triple) 1804 : WindowsTargetInfo<X86_64TargetInfo>(triple) { 1805 TLSSupported = false; 1806 WCharType = UnsignedShort; 1807 LongWidth = LongAlign = 32; 1808 DoubleAlign = LongLongAlign = 64; 1809 IntMaxType = SignedLongLong; 1810 UIntMaxType = UnsignedLongLong; 1811 Int64Type = SignedLongLong; 1812 SizeType = UnsignedLongLong; 1813 PtrDiffType = SignedLongLong; 1814 IntPtrType = SignedLongLong; 1815 this->UserLabelPrefix = ""; 1816 } 1817 virtual void getTargetDefines(const LangOptions &Opts, 1818 MacroBuilder &Builder) const { 1819 WindowsTargetInfo<X86_64TargetInfo>::getTargetDefines(Opts, Builder); 1820 Builder.defineMacro("_WIN64"); 1821 } 1822 virtual const char *getVAListDeclaration() const { 1823 return "typedef char* __builtin_va_list;"; 1824 } 1825}; 1826} // end anonymous namespace 1827 1828namespace { 1829// x86-64 Windows Visual Studio target 1830class VisualStudioWindowsX86_64TargetInfo : public WindowsX86_64TargetInfo { 1831public: 1832 VisualStudioWindowsX86_64TargetInfo(const std::string& triple) 1833 : WindowsX86_64TargetInfo(triple) { 1834 LongDoubleWidth = LongDoubleAlign = 64; 1835 LongDoubleFormat = &llvm::APFloat::IEEEdouble; 1836 } 1837 virtual void getTargetDefines(const LangOptions &Opts, 1838 MacroBuilder &Builder) const { 1839 WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder); 1840 WindowsX86_64TargetInfo::getVisualStudioDefines(Opts, Builder); 1841 Builder.defineMacro("_M_X64"); 1842 Builder.defineMacro("_M_AMD64"); 1843 } 1844}; 1845} // end anonymous namespace 1846 1847namespace { 1848// x86-64 MinGW target 1849class MinGWX86_64TargetInfo : public WindowsX86_64TargetInfo { 1850public: 1851 MinGWX86_64TargetInfo(const std::string& triple) 1852 : WindowsX86_64TargetInfo(triple) { 1853 } 1854 virtual void getTargetDefines(const LangOptions &Opts, 1855 MacroBuilder &Builder) const { 1856 WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder); 1857 DefineStd(Builder, "WIN64", Opts); 1858 Builder.defineMacro("__MSVCRT__"); 1859 Builder.defineMacro("__MINGW32__"); 1860 Builder.defineMacro("__MINGW64__"); 1861 1862 // mingw32-gcc provides __declspec(a) as alias of __attribute__((a)). 1863 // In contrast, clang-cc1 provides __declspec(a) with -fms-extensions. 1864 if (Opts.Microsoft) 1865 // Provide "as-is" __declspec. 1866 Builder.defineMacro("__declspec", "__declspec"); 1867 else 1868 // Provide alias of __attribute__ like mingw32-gcc. 1869 Builder.defineMacro("__declspec(a)", "__attribute__((a))"); 1870 } 1871}; 1872} // end anonymous namespace 1873 1874namespace { 1875class DarwinX86_64TargetInfo : public DarwinTargetInfo<X86_64TargetInfo> { 1876public: 1877 DarwinX86_64TargetInfo(const std::string& triple) 1878 : DarwinTargetInfo<X86_64TargetInfo>(triple) { 1879 Int64Type = SignedLongLong; 1880 } 1881}; 1882} // end anonymous namespace 1883 1884namespace { 1885class OpenBSDX86_64TargetInfo : public OpenBSDTargetInfo<X86_64TargetInfo> { 1886public: 1887 OpenBSDX86_64TargetInfo(const std::string& triple) 1888 : OpenBSDTargetInfo<X86_64TargetInfo>(triple) { 1889 IntMaxType = SignedLongLong; 1890 UIntMaxType = UnsignedLongLong; 1891 Int64Type = SignedLongLong; 1892 } 1893}; 1894} // end anonymous namespace 1895 1896namespace { 1897class ARMTargetInfo : public TargetInfo { 1898 // Possible FPU choices. 1899 enum FPUMode { 1900 NoFPU, 1901 VFP2FPU, 1902 VFP3FPU, 1903 NeonFPU 1904 }; 1905 1906 static bool FPUModeIsVFP(FPUMode Mode) { 1907 return Mode >= VFP2FPU && Mode <= NeonFPU; 1908 } 1909 1910 static const TargetInfo::GCCRegAlias GCCRegAliases[]; 1911 static const char * const GCCRegNames[]; 1912 1913 std::string ABI, CPU; 1914 1915 unsigned FPU : 3; 1916 1917 unsigned IsThumb : 1; 1918 1919 // Initialized via features. 1920 unsigned SoftFloat : 1; 1921 unsigned SoftFloatABI : 1; 1922 1923 static const Builtin::Info BuiltinInfo[]; 1924 1925public: 1926 ARMTargetInfo(const std::string &TripleStr) 1927 : TargetInfo(TripleStr), ABI("aapcs-linux"), CPU("arm1136j-s") 1928 { 1929 SizeType = UnsignedInt; 1930 PtrDiffType = SignedInt; 1931 1932 // {} in inline assembly are neon specifiers, not assembly variant 1933 // specifiers. 1934 NoAsmVariants = true; 1935 1936 // FIXME: Should we just treat this as a feature? 1937 IsThumb = getTriple().getArchName().startswith("thumb"); 1938 if (IsThumb) { 1939 // Thumb1 add sp, #imm requires the immediate value be multiple of 4, 1940 // so set preferred for small types to 32. 1941 DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-" 1942 "i64:64:64-f32:32:32-f64:64:64-" 1943 "v64:64:64-v128:64:128-a0:0:32-n32"); 1944 } else { 1945 DescriptionString = ("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 1946 "i64:64:64-f32:32:32-f64:64:64-" 1947 "v64:64:64-v128:64:128-a0:0:64-n32"); 1948 } 1949 1950 // ARM targets default to using the ARM C++ ABI. 1951 CXXABI = CXXABI_ARM; 1952 } 1953 virtual const char *getABI() const { return ABI.c_str(); } 1954 virtual bool setABI(const std::string &Name) { 1955 ABI = Name; 1956 1957 // The defaults (above) are for AAPCS, check if we need to change them. 1958 // 1959 // FIXME: We need support for -meabi... we could just mangle it into the 1960 // name. 1961 if (Name == "apcs-gnu") { 1962 DoubleAlign = LongLongAlign = LongDoubleAlign = 32; 1963 SizeType = UnsignedLong; 1964 1965 // Do not respect the alignment of bit-field types when laying out 1966 // structures. This corresponds to PCC_BITFIELD_TYPE_MATTERS in gcc. 1967 UseBitFieldTypeAlignment = false; 1968 1969 if (IsThumb) { 1970 // Thumb1 add sp, #imm requires the immediate value be multiple of 4, 1971 // so set preferred for small types to 32. 1972 DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-" 1973 "i64:32:64-f32:32:32-f64:32:64-" 1974 "v64:32:64-v128:32:128-a0:0:32-n32"); 1975 } else { 1976 DescriptionString = ("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 1977 "i64:32:64-f32:32:32-f64:32:64-" 1978 "v64:32:64-v128:32:128-a0:0:32-n32"); 1979 } 1980 1981 // FIXME: Override "preferred align" for double and long long. 1982 } else if (Name == "aapcs") { 1983 // FIXME: Enumerated types are variable width in straight AAPCS. 1984 } else if (Name == "aapcs-linux") { 1985 ; 1986 } else 1987 return false; 1988 1989 return true; 1990 } 1991 1992 void getDefaultFeatures(const std::string &CPU, 1993 llvm::StringMap<bool> &Features) const { 1994 if (CPU == "arm1136jf-s" || CPU == "arm1176jzf-s" || CPU == "mpcore") 1995 Features["vfp2"] = true; 1996 else if (CPU == "cortex-a8" || CPU == "cortex-a9") 1997 Features["neon"] = true; 1998 } 1999 2000 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features, 2001 const std::string &Name, 2002 bool Enabled) const { 2003 if (Name == "soft-float" || Name == "soft-float-abi" || 2004 Name == "vfp2" || Name == "vfp3" || Name == "neon" || 2005 Name == "long64") { 2006 Features[Name] = Enabled; 2007 } else 2008 return false; 2009 2010 return true; 2011 } 2012 2013 virtual void HandleTargetFeatures(std::vector<std::string> &Features) { 2014 FPU = NoFPU; 2015 SoftFloat = SoftFloatABI = false; 2016 for (unsigned i = 0, e = Features.size(); i != e; ++i) { 2017 if (Features[i] == "+soft-float") 2018 SoftFloat = true; 2019 else if (Features[i] == "+soft-float-abi") 2020 SoftFloatABI = true; 2021 else if (Features[i] == "+vfp2") 2022 FPU = VFP2FPU; 2023 else if (Features[i] == "+vfp3") 2024 FPU = VFP3FPU; 2025 else if (Features[i] == "+neon") 2026 FPU = NeonFPU; 2027 else if (Features[i] == "+long64") 2028 LongWidth = LongAlign = 64; // RenderScript uses a 64-bit long type 2029 } 2030 2031 // Remove front-end specific options which the backend handles differently. 2032 std::vector<std::string>::iterator it; 2033 it = std::find(Features.begin(), Features.end(), "+soft-float"); 2034 if (it != Features.end()) 2035 Features.erase(it); 2036 it = std::find(Features.begin(), Features.end(), "+soft-float-abi"); 2037 if (it != Features.end()) 2038 Features.erase(it); 2039 } 2040 2041 static const char *getCPUDefineSuffix(llvm::StringRef Name) { 2042 return llvm::StringSwitch<const char*>(Name) 2043 .Cases("arm8", "arm810", "4") 2044 .Cases("strongarm", "strongarm110", "strongarm1100", "strongarm1110", "4") 2045 .Cases("arm7tdmi", "arm7tdmi-s", "arm710t", "arm720t", "arm9", "4T") 2046 .Cases("arm9tdmi", "arm920", "arm920t", "arm922t", "arm940t", "4T") 2047 .Case("ep9312", "4T") 2048 .Cases("arm10tdmi", "arm1020t", "5T") 2049 .Cases("arm9e", "arm946e-s", "arm966e-s", "arm968e-s", "5TE") 2050 .Case("arm926ej-s", "5TEJ") 2051 .Cases("arm10e", "arm1020e", "arm1022e", "5TE") 2052 .Cases("xscale", "iwmmxt", "5TE") 2053 .Case("arm1136j-s", "6J") 2054 .Cases("arm1176jz-s", "arm1176jzf-s", "6ZK") 2055 .Cases("arm1136jf-s", "mpcorenovfp", "mpcore", "6K") 2056 .Cases("arm1156t2-s", "arm1156t2f-s", "6T2") 2057 .Cases("cortex-a8", "cortex-a9", "7A") 2058 .Case("cortex-m3", "7M") 2059 .Case("cortex-m0", "6M") 2060 .Default(0); 2061 } 2062 virtual bool setCPU(const std::string &Name) { 2063 if (!getCPUDefineSuffix(Name)) 2064 return false; 2065 2066 CPU = Name; 2067 return true; 2068 } 2069 virtual void getTargetDefines(const LangOptions &Opts, 2070 MacroBuilder &Builder) const { 2071 // Target identification. 2072 Builder.defineMacro("__arm"); 2073 Builder.defineMacro("__arm__"); 2074 2075 // Target properties. 2076 Builder.defineMacro("__ARMEL__"); 2077 Builder.defineMacro("__LITTLE_ENDIAN__"); 2078 Builder.defineMacro("__REGISTER_PREFIX__", ""); 2079 2080 llvm::StringRef CPUArch = getCPUDefineSuffix(CPU); 2081 Builder.defineMacro("__ARM_ARCH_" + CPUArch + "__"); 2082 2083 // Subtarget options. 2084 2085 // FIXME: It's more complicated than this and we don't really support 2086 // interworking. 2087 if ('5' <= CPUArch[0] && CPUArch[0] <= '7') 2088 Builder.defineMacro("__THUMB_INTERWORK__"); 2089 2090 if (ABI == "aapcs" || ABI == "aapcs-linux") 2091 Builder.defineMacro("__ARM_EABI__"); 2092 2093 if (SoftFloat) 2094 Builder.defineMacro("__SOFTFP__"); 2095 2096 if (CPU == "xscale") 2097 Builder.defineMacro("__XSCALE__"); 2098 2099 bool IsARMv7 = CPUArch.startswith("7"); 2100 if (IsThumb) { 2101 Builder.defineMacro("__THUMBEL__"); 2102 Builder.defineMacro("__thumb__"); 2103 if (CPUArch == "6T2" || IsARMv7) 2104 Builder.defineMacro("__thumb2__"); 2105 } 2106 2107 // Note, this is always on in gcc, even though it doesn't make sense. 2108 Builder.defineMacro("__APCS_32__"); 2109 2110 if (FPUModeIsVFP((FPUMode) FPU)) 2111 Builder.defineMacro("__VFP_FP__"); 2112 2113 // This only gets set when Neon instructions are actually available, unlike 2114 // the VFP define, hence the soft float and arch check. This is subtly 2115 // different from gcc, we follow the intent which was that it should be set 2116 // when Neon instructions are actually available. 2117 if (FPU == NeonFPU && !SoftFloat && IsARMv7) 2118 Builder.defineMacro("__ARM_NEON__"); 2119 } 2120 virtual void getTargetBuiltins(const Builtin::Info *&Records, 2121 unsigned &NumRecords) const { 2122 Records = BuiltinInfo; 2123 NumRecords = clang::ARM::LastTSBuiltin-Builtin::FirstTSBuiltin; 2124 } 2125 virtual const char *getVAListDeclaration() const { 2126 return "typedef void* __builtin_va_list;"; 2127 } 2128 virtual void getGCCRegNames(const char * const *&Names, 2129 unsigned &NumNames) const; 2130 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 2131 unsigned &NumAliases) const; 2132 virtual bool validateAsmConstraint(const char *&Name, 2133 TargetInfo::ConstraintInfo &Info) const { 2134 // FIXME: Check if this is complete 2135 switch (*Name) { 2136 default: 2137 case 'l': // r0-r7 2138 case 'h': // r8-r15 2139 case 'w': // VFP Floating point register single precision 2140 case 'P': // VFP Floating point register double precision 2141 Info.setAllowsRegister(); 2142 return true; 2143 case 'U': // a memory reference... 2144 switch (Name[1]) { 2145 case 'q': // ...ARMV4 ldrsb 2146 case 'v': // ...VFP load/store (reg+constant offset) 2147 case 'y': // ...iWMMXt load/store 2148 case 't': // address valid for load/store opaque types wider 2149 // than 128-bits 2150 case 'n': // valid address for Neon doubleword vector load/store 2151 case 'm': // valid address for Neon element and structure load/store 2152 case 's': // valid address for non-offset loads/stores of quad-word 2153 // values in four ARM registers 2154 Info.setAllowsMemory(); 2155 Name++; 2156 return true; 2157 } 2158 } 2159 return false; 2160 } 2161 virtual std::string convertConstraint(const char *&Constraint) const { 2162 std::string R; 2163 switch (*Constraint) { 2164 case 'U': // Two-character constraint; add "^" hint for later parsing. 2165 R = std::string("^") + std::string(Constraint, 2); 2166 Constraint++; 2167 break; 2168 case 'p': // 'p' should be translated to 'r' by default. 2169 R = std::string("r"); 2170 break; 2171 default: 2172 return std::string(1, *Constraint); 2173 } 2174 return R; 2175 } 2176 virtual const char *getClobbers() const { 2177 // FIXME: Is this really right? 2178 return ""; 2179 } 2180}; 2181 2182const char * const ARMTargetInfo::GCCRegNames[] = { 2183 // Integer registers 2184 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 2185 "r8", "r9", "r10", "r11", "r12", "sp", "lr", "pc", 2186 2187 // Float registers 2188 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", 2189 "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15", 2190 "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23", 2191 "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31", 2192 2193 // Double registers 2194 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", 2195 "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15", 2196 "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", 2197 "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31", 2198 2199 // Quad registers 2200 "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", 2201 "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15" 2202}; 2203 2204void ARMTargetInfo::getGCCRegNames(const char * const *&Names, 2205 unsigned &NumNames) const { 2206 Names = GCCRegNames; 2207 NumNames = llvm::array_lengthof(GCCRegNames); 2208} 2209 2210const TargetInfo::GCCRegAlias ARMTargetInfo::GCCRegAliases[] = { 2211 { { "a1" }, "r0" }, 2212 { { "a2" }, "r1" }, 2213 { { "a3" }, "r2" }, 2214 { { "a4" }, "r3" }, 2215 { { "v1" }, "r4" }, 2216 { { "v2" }, "r5" }, 2217 { { "v3" }, "r6" }, 2218 { { "v4" }, "r7" }, 2219 { { "v5" }, "r8" }, 2220 { { "v6", "rfp" }, "r9" }, 2221 { { "sl" }, "r10" }, 2222 { { "fp" }, "r11" }, 2223 { { "ip" }, "r12" }, 2224 { { "r13" }, "sp" }, 2225 { { "r14" }, "lr" }, 2226 { { "r15" }, "pc" }, 2227 // The S, D and Q registers overlap, but aren't really aliases; we 2228 // don't want to substitute one of these for a different-sized one. 2229}; 2230 2231void ARMTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, 2232 unsigned &NumAliases) const { 2233 Aliases = GCCRegAliases; 2234 NumAliases = llvm::array_lengthof(GCCRegAliases); 2235} 2236 2237const Builtin::Info ARMTargetInfo::BuiltinInfo[] = { 2238#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES }, 2239#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\ 2240 ALL_LANGUAGES }, 2241#include "clang/Basic/BuiltinsARM.def" 2242}; 2243} // end anonymous namespace. 2244 2245 2246namespace { 2247class DarwinARMTargetInfo : 2248 public DarwinTargetInfo<ARMTargetInfo> { 2249protected: 2250 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 2251 MacroBuilder &Builder) const { 2252 getDarwinDefines(Builder, Opts, Triple, PlatformName, PlatformMinVersion); 2253 } 2254 2255public: 2256 DarwinARMTargetInfo(const std::string& triple) 2257 : DarwinTargetInfo<ARMTargetInfo>(triple) { 2258 HasAlignMac68kSupport = true; 2259 } 2260}; 2261} // end anonymous namespace. 2262 2263namespace { 2264class SparcV8TargetInfo : public TargetInfo { 2265 static const TargetInfo::GCCRegAlias GCCRegAliases[]; 2266 static const char * const GCCRegNames[]; 2267 bool SoftFloat; 2268public: 2269 SparcV8TargetInfo(const std::string& triple) : TargetInfo(triple) { 2270 // FIXME: Support Sparc quad-precision long double? 2271 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 2272 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32"; 2273 } 2274 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features, 2275 const std::string &Name, 2276 bool Enabled) const { 2277 if (Name == "soft-float") 2278 Features[Name] = Enabled; 2279 else 2280 return false; 2281 2282 return true; 2283 } 2284 virtual void HandleTargetFeatures(std::vector<std::string> &Features) { 2285 SoftFloat = false; 2286 for (unsigned i = 0, e = Features.size(); i != e; ++i) 2287 if (Features[i] == "+soft-float") 2288 SoftFloat = true; 2289 } 2290 virtual void getTargetDefines(const LangOptions &Opts, 2291 MacroBuilder &Builder) const { 2292 DefineStd(Builder, "sparc", Opts); 2293 Builder.defineMacro("__sparcv8"); 2294 Builder.defineMacro("__REGISTER_PREFIX__", ""); 2295 2296 if (SoftFloat) 2297 Builder.defineMacro("SOFT_FLOAT", "1"); 2298 } 2299 virtual void getTargetBuiltins(const Builtin::Info *&Records, 2300 unsigned &NumRecords) const { 2301 // FIXME: Implement! 2302 } 2303 virtual const char *getVAListDeclaration() const { 2304 return "typedef void* __builtin_va_list;"; 2305 } 2306 virtual void getGCCRegNames(const char * const *&Names, 2307 unsigned &NumNames) const; 2308 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 2309 unsigned &NumAliases) const; 2310 virtual bool validateAsmConstraint(const char *&Name, 2311 TargetInfo::ConstraintInfo &info) const { 2312 // FIXME: Implement! 2313 return false; 2314 } 2315 virtual const char *getClobbers() const { 2316 // FIXME: Implement! 2317 return ""; 2318 } 2319}; 2320 2321const char * const SparcV8TargetInfo::GCCRegNames[] = { 2322 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 2323 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 2324 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", 2325 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" 2326}; 2327 2328void SparcV8TargetInfo::getGCCRegNames(const char * const *&Names, 2329 unsigned &NumNames) const { 2330 Names = GCCRegNames; 2331 NumNames = llvm::array_lengthof(GCCRegNames); 2332} 2333 2334const TargetInfo::GCCRegAlias SparcV8TargetInfo::GCCRegAliases[] = { 2335 { { "g0" }, "r0" }, 2336 { { "g1" }, "r1" }, 2337 { { "g2" }, "r2" }, 2338 { { "g3" }, "r3" }, 2339 { { "g4" }, "r4" }, 2340 { { "g5" }, "r5" }, 2341 { { "g6" }, "r6" }, 2342 { { "g7" }, "r7" }, 2343 { { "o0" }, "r8" }, 2344 { { "o1" }, "r9" }, 2345 { { "o2" }, "r10" }, 2346 { { "o3" }, "r11" }, 2347 { { "o4" }, "r12" }, 2348 { { "o5" }, "r13" }, 2349 { { "o6", "sp" }, "r14" }, 2350 { { "o7" }, "r15" }, 2351 { { "l0" }, "r16" }, 2352 { { "l1" }, "r17" }, 2353 { { "l2" }, "r18" }, 2354 { { "l3" }, "r19" }, 2355 { { "l4" }, "r20" }, 2356 { { "l5" }, "r21" }, 2357 { { "l6" }, "r22" }, 2358 { { "l7" }, "r23" }, 2359 { { "i0" }, "r24" }, 2360 { { "i1" }, "r25" }, 2361 { { "i2" }, "r26" }, 2362 { { "i3" }, "r27" }, 2363 { { "i4" }, "r28" }, 2364 { { "i5" }, "r29" }, 2365 { { "i6", "fp" }, "r30" }, 2366 { { "i7" }, "r31" }, 2367}; 2368 2369void SparcV8TargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, 2370 unsigned &NumAliases) const { 2371 Aliases = GCCRegAliases; 2372 NumAliases = llvm::array_lengthof(GCCRegAliases); 2373} 2374} // end anonymous namespace. 2375 2376namespace { 2377class AuroraUXSparcV8TargetInfo : public AuroraUXTargetInfo<SparcV8TargetInfo> { 2378public: 2379 AuroraUXSparcV8TargetInfo(const std::string& triple) : 2380 AuroraUXTargetInfo<SparcV8TargetInfo>(triple) { 2381 SizeType = UnsignedInt; 2382 PtrDiffType = SignedInt; 2383 } 2384}; 2385class SolarisSparcV8TargetInfo : public SolarisTargetInfo<SparcV8TargetInfo> { 2386public: 2387 SolarisSparcV8TargetInfo(const std::string& triple) : 2388 SolarisTargetInfo<SparcV8TargetInfo>(triple) { 2389 SizeType = UnsignedInt; 2390 PtrDiffType = SignedInt; 2391 } 2392}; 2393} // end anonymous namespace. 2394 2395namespace { 2396 class MSP430TargetInfo : public TargetInfo { 2397 static const char * const GCCRegNames[]; 2398 public: 2399 MSP430TargetInfo(const std::string& triple) : TargetInfo(triple) { 2400 TLSSupported = false; 2401 IntWidth = 16; IntAlign = 16; 2402 LongWidth = 32; LongLongWidth = 64; 2403 LongAlign = LongLongAlign = 16; 2404 PointerWidth = 16; PointerAlign = 16; 2405 SizeType = UnsignedInt; 2406 IntMaxType = SignedLong; 2407 UIntMaxType = UnsignedLong; 2408 IntPtrType = SignedShort; 2409 PtrDiffType = SignedInt; 2410 SigAtomicType = SignedLong; 2411 DescriptionString = "e-p:16:16:16-i8:8:8-i16:16:16-i32:16:32-n8:16"; 2412 } 2413 virtual void getTargetDefines(const LangOptions &Opts, 2414 MacroBuilder &Builder) const { 2415 Builder.defineMacro("MSP430"); 2416 Builder.defineMacro("__MSP430__"); 2417 // FIXME: defines for different 'flavours' of MCU 2418 } 2419 virtual void getTargetBuiltins(const Builtin::Info *&Records, 2420 unsigned &NumRecords) const { 2421 // FIXME: Implement. 2422 Records = 0; 2423 NumRecords = 0; 2424 } 2425 virtual void getGCCRegNames(const char * const *&Names, 2426 unsigned &NumNames) const; 2427 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 2428 unsigned &NumAliases) const { 2429 // No aliases. 2430 Aliases = 0; 2431 NumAliases = 0; 2432 } 2433 virtual bool validateAsmConstraint(const char *&Name, 2434 TargetInfo::ConstraintInfo &info) const { 2435 // No target constraints for now. 2436 return false; 2437 } 2438 virtual const char *getClobbers() const { 2439 // FIXME: Is this really right? 2440 return ""; 2441 } 2442 virtual const char *getVAListDeclaration() const { 2443 // FIXME: implement 2444 return "typedef char* __builtin_va_list;"; 2445 } 2446 }; 2447 2448 const char * const MSP430TargetInfo::GCCRegNames[] = { 2449 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 2450 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" 2451 }; 2452 2453 void MSP430TargetInfo::getGCCRegNames(const char * const *&Names, 2454 unsigned &NumNames) const { 2455 Names = GCCRegNames; 2456 NumNames = llvm::array_lengthof(GCCRegNames); 2457 } 2458} 2459 2460 2461namespace { 2462 class SystemZTargetInfo : public TargetInfo { 2463 static const char * const GCCRegNames[]; 2464 public: 2465 SystemZTargetInfo(const std::string& triple) : TargetInfo(triple) { 2466 TLSSupported = false; 2467 IntWidth = IntAlign = 32; 2468 LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64; 2469 PointerWidth = PointerAlign = 64; 2470 DescriptionString = "E-p:64:64:64-i8:8:16-i16:16:16-i32:32:32-" 2471 "i64:64:64-f32:32:32-f64:64:64-f128:128:128-a0:16:16-n32:64"; 2472 } 2473 virtual void getTargetDefines(const LangOptions &Opts, 2474 MacroBuilder &Builder) const { 2475 Builder.defineMacro("__s390__"); 2476 Builder.defineMacro("__s390x__"); 2477 } 2478 virtual void getTargetBuiltins(const Builtin::Info *&Records, 2479 unsigned &NumRecords) const { 2480 // FIXME: Implement. 2481 Records = 0; 2482 NumRecords = 0; 2483 } 2484 2485 virtual void getGCCRegNames(const char * const *&Names, 2486 unsigned &NumNames) const; 2487 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 2488 unsigned &NumAliases) const { 2489 // No aliases. 2490 Aliases = 0; 2491 NumAliases = 0; 2492 } 2493 virtual bool validateAsmConstraint(const char *&Name, 2494 TargetInfo::ConstraintInfo &info) const { 2495 // FIXME: implement 2496 return true; 2497 } 2498 virtual const char *getClobbers() const { 2499 // FIXME: Is this really right? 2500 return ""; 2501 } 2502 virtual const char *getVAListDeclaration() const { 2503 // FIXME: implement 2504 return "typedef char* __builtin_va_list;"; 2505 } 2506 }; 2507 2508 const char * const SystemZTargetInfo::GCCRegNames[] = { 2509 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 2510 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" 2511 }; 2512 2513 void SystemZTargetInfo::getGCCRegNames(const char * const *&Names, 2514 unsigned &NumNames) const { 2515 Names = GCCRegNames; 2516 NumNames = llvm::array_lengthof(GCCRegNames); 2517 } 2518} 2519 2520namespace { 2521 class BlackfinTargetInfo : public TargetInfo { 2522 static const char * const GCCRegNames[]; 2523 public: 2524 BlackfinTargetInfo(const std::string& triple) : TargetInfo(triple) { 2525 TLSSupported = false; 2526 DoubleAlign = 32; 2527 LongLongAlign = 32; 2528 LongDoubleAlign = 32; 2529 DescriptionString = "e-p:32:32-i64:32-f64:32-n32"; 2530 } 2531 2532 virtual void getTargetDefines(const LangOptions &Opts, 2533 MacroBuilder &Builder) const { 2534 DefineStd(Builder, "bfin", Opts); 2535 DefineStd(Builder, "BFIN", Opts); 2536 Builder.defineMacro("__ADSPBLACKFIN__"); 2537 // FIXME: This one is really dependent on -mcpu 2538 Builder.defineMacro("__ADSPLPBLACKFIN__"); 2539 // FIXME: Add cpu-dependent defines and __SILICON_REVISION__ 2540 } 2541 2542 virtual void getTargetBuiltins(const Builtin::Info *&Records, 2543 unsigned &NumRecords) const { 2544 // FIXME: Implement. 2545 Records = 0; 2546 NumRecords = 0; 2547 } 2548 2549 virtual void getGCCRegNames(const char * const *&Names, 2550 unsigned &NumNames) const; 2551 2552 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 2553 unsigned &NumAliases) const { 2554 // No aliases. 2555 Aliases = 0; 2556 NumAliases = 0; 2557 } 2558 2559 virtual bool validateAsmConstraint(const char *&Name, 2560 TargetInfo::ConstraintInfo &Info) const { 2561 if (strchr("adzDWeABbvfcCtukxywZY", Name[0])) { 2562 Info.setAllowsRegister(); 2563 return true; 2564 } 2565 return false; 2566 } 2567 2568 virtual const char *getClobbers() const { 2569 return ""; 2570 } 2571 2572 virtual const char *getVAListDeclaration() const { 2573 return "typedef char* __builtin_va_list;"; 2574 } 2575 }; 2576 2577 const char * const BlackfinTargetInfo::GCCRegNames[] = { 2578 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 2579 "p0", "p1", "p2", "p3", "p4", "p5", "sp", "fp", 2580 "i0", "i1", "i2", "i3", "b0", "b1", "b2", "b3", 2581 "l0", "l1", "l2", "l3", "m0", "m1", "m2", "m3", 2582 "a0", "a1", "cc", 2583 "rets", "reti", "retx", "retn", "rete", "astat", "seqstat", "usp", 2584 "argp", "lt0", "lt1", "lc0", "lc1", "lb0", "lb1" 2585 }; 2586 2587 void BlackfinTargetInfo::getGCCRegNames(const char * const *&Names, 2588 unsigned &NumNames) const { 2589 Names = GCCRegNames; 2590 NumNames = llvm::array_lengthof(GCCRegNames); 2591 } 2592} 2593 2594namespace { 2595 2596 // LLVM and Clang cannot be used directly to output native binaries for 2597 // target, but is used to compile C code to llvm bitcode with correct 2598 // type and alignment information. 2599 // 2600 // TCE uses the llvm bitcode as input and uses it for generating customized 2601 // target processor and program binary. TCE co-design environment is 2602 // publicly available in http://tce.cs.tut.fi 2603 2604 class TCETargetInfo : public TargetInfo{ 2605 public: 2606 TCETargetInfo(const std::string& triple) : TargetInfo(triple) { 2607 TLSSupported = false; 2608 IntWidth = 32; 2609 LongWidth = LongLongWidth = 32; 2610 PointerWidth = 32; 2611 IntAlign = 32; 2612 LongAlign = LongLongAlign = 32; 2613 PointerAlign = 32; 2614 SizeType = UnsignedInt; 2615 IntMaxType = SignedLong; 2616 UIntMaxType = UnsignedLong; 2617 IntPtrType = SignedInt; 2618 PtrDiffType = SignedInt; 2619 FloatWidth = 32; 2620 FloatAlign = 32; 2621 DoubleWidth = 32; 2622 DoubleAlign = 32; 2623 LongDoubleWidth = 32; 2624 LongDoubleAlign = 32; 2625 FloatFormat = &llvm::APFloat::IEEEsingle; 2626 DoubleFormat = &llvm::APFloat::IEEEsingle; 2627 LongDoubleFormat = &llvm::APFloat::IEEEsingle; 2628 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-" 2629 "i16:16:32-i32:32:32-i64:32:32-" 2630 "f32:32:32-f64:32:32-v64:32:32-" 2631 "v128:32:32-a0:0:32-n32"; 2632 } 2633 2634 virtual void getTargetDefines(const LangOptions &Opts, 2635 MacroBuilder &Builder) const { 2636 DefineStd(Builder, "tce", Opts); 2637 Builder.defineMacro("__TCE__"); 2638 Builder.defineMacro("__TCE_V1__"); 2639 } 2640 virtual void getTargetBuiltins(const Builtin::Info *&Records, 2641 unsigned &NumRecords) const {} 2642 virtual const char *getClobbers() const { 2643 return ""; 2644 } 2645 virtual const char *getVAListDeclaration() const { 2646 return "typedef void* __builtin_va_list;"; 2647 } 2648 virtual void getGCCRegNames(const char * const *&Names, 2649 unsigned &NumNames) const {} 2650 virtual bool validateAsmConstraint(const char *&Name, 2651 TargetInfo::ConstraintInfo &info) const { 2652 return true; 2653 } 2654 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 2655 unsigned &NumAliases) const {} 2656 }; 2657} 2658 2659namespace { 2660class MipsTargetInfo : public TargetInfo { 2661 std::string ABI, CPU; 2662 static const TargetInfo::GCCRegAlias GCCRegAliases[]; 2663 static const char * const GCCRegNames[]; 2664public: 2665 MipsTargetInfo(const std::string& triple) : TargetInfo(triple), ABI("o32") { 2666 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-" 2667 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32"; 2668 SizeType = UnsignedInt; 2669 PtrDiffType = SignedInt; 2670 } 2671 virtual const char *getABI() const { return ABI.c_str(); } 2672 virtual bool setABI(const std::string &Name) { 2673 2674 if ((Name == "o32") || (Name == "eabi")) { 2675 ABI = Name; 2676 return true; 2677 } else 2678 return false; 2679 } 2680 virtual bool setCPU(const std::string &Name) { 2681 CPU = Name; 2682 return true; 2683 } 2684 void getDefaultFeatures(const std::string &CPU, 2685 llvm::StringMap<bool> &Features) const { 2686 Features[ABI] = true; 2687 Features[CPU] = true; 2688 } 2689 virtual void getArchDefines(const LangOptions &Opts, 2690 MacroBuilder &Builder) const { 2691 if (ABI == "o32") 2692 Builder.defineMacro("__mips_o32"); 2693 else if (ABI == "eabi") 2694 Builder.defineMacro("__mips_eabi"); 2695 } 2696 virtual void getTargetDefines(const LangOptions &Opts, 2697 MacroBuilder &Builder) const { 2698 DefineStd(Builder, "mips", Opts); 2699 Builder.defineMacro("_mips"); 2700 DefineStd(Builder, "MIPSEB", Opts); 2701 Builder.defineMacro("_MIPSEB"); 2702 Builder.defineMacro("__REGISTER_PREFIX__", ""); 2703 getArchDefines(Opts, Builder); 2704 } 2705 virtual void getTargetBuiltins(const Builtin::Info *&Records, 2706 unsigned &NumRecords) const { 2707 // FIXME: Implement! 2708 } 2709 virtual const char *getVAListDeclaration() const { 2710 return "typedef void* __builtin_va_list;"; 2711 } 2712 virtual void getGCCRegNames(const char * const *&Names, 2713 unsigned &NumNames) const; 2714 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 2715 unsigned &NumAliases) const; 2716 virtual bool validateAsmConstraint(const char *&Name, 2717 TargetInfo::ConstraintInfo &Info) const { 2718 switch (*Name) { 2719 default: 2720 case 'r': // CPU registers. 2721 case 'd': // Equivalent to "r" unless generating MIPS16 code. 2722 case 'y': // Equivalent to "r", backwards compatibility only. 2723 case 'f': // floating-point registers. 2724 Info.setAllowsRegister(); 2725 return true; 2726 } 2727 return false; 2728 } 2729 2730 virtual const char *getClobbers() const { 2731 // FIXME: Implement! 2732 return ""; 2733 } 2734}; 2735 2736const char * const MipsTargetInfo::GCCRegNames[] = { 2737 "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7", 2738 "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", 2739 "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23", 2740 "$24", "$25", "$26", "$27", "$28", "$sp", "$fp", "$31", 2741 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7", 2742 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15", 2743 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23", 2744 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31", 2745 "hi", "lo", "", "$fcc0","$fcc1","$fcc2","$fcc3","$fcc4", 2746 "$fcc5","$fcc6","$fcc7" 2747}; 2748 2749void MipsTargetInfo::getGCCRegNames(const char * const *&Names, 2750 unsigned &NumNames) const { 2751 Names = GCCRegNames; 2752 NumNames = llvm::array_lengthof(GCCRegNames); 2753} 2754 2755const TargetInfo::GCCRegAlias MipsTargetInfo::GCCRegAliases[] = { 2756 { { "at" }, "$1" }, 2757 { { "v0" }, "$2" }, 2758 { { "v1" }, "$3" }, 2759 { { "a0" }, "$4" }, 2760 { { "a1" }, "$5" }, 2761 { { "a2" }, "$6" }, 2762 { { "a3" }, "$7" }, 2763 { { "t0" }, "$8" }, 2764 { { "t1" }, "$9" }, 2765 { { "t2" }, "$10" }, 2766 { { "t3" }, "$11" }, 2767 { { "t4" }, "$12" }, 2768 { { "t5" }, "$13" }, 2769 { { "t6" }, "$14" }, 2770 { { "t7" }, "$15" }, 2771 { { "s0" }, "$16" }, 2772 { { "s1" }, "$17" }, 2773 { { "s2" }, "$18" }, 2774 { { "s3" }, "$19" }, 2775 { { "s4" }, "$20" }, 2776 { { "s5" }, "$21" }, 2777 { { "s6" }, "$22" }, 2778 { { "s7" }, "$23" }, 2779 { { "t8" }, "$24" }, 2780 { { "t9" }, "$25" }, 2781 { { "k0" }, "$26" }, 2782 { { "k1" }, "$27" }, 2783 { { "gp" }, "$28" }, 2784 { { "sp" }, "$29" }, 2785 { { "fp" }, "$30" }, 2786 { { "ra" }, "$31" } 2787}; 2788 2789void MipsTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, 2790 unsigned &NumAliases) const { 2791 Aliases = GCCRegAliases; 2792 NumAliases = llvm::array_lengthof(GCCRegAliases); 2793} 2794} // end anonymous namespace. 2795 2796namespace { 2797class MipselTargetInfo : public MipsTargetInfo { 2798public: 2799 MipselTargetInfo(const std::string& triple) : MipsTargetInfo(triple) { 2800 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-" 2801 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32"; 2802 } 2803 2804 virtual void getTargetDefines(const LangOptions &Opts, 2805 MacroBuilder &Builder) const; 2806}; 2807 2808void MipselTargetInfo::getTargetDefines(const LangOptions &Opts, 2809 MacroBuilder &Builder) const { 2810 DefineStd(Builder, "mips", Opts); 2811 Builder.defineMacro("_mips"); 2812 DefineStd(Builder, "MIPSEL", Opts); 2813 Builder.defineMacro("_MIPSEL"); 2814 Builder.defineMacro("__REGISTER_PREFIX__", ""); 2815 getArchDefines(Opts, Builder); 2816} 2817} // end anonymous namespace. 2818 2819//===----------------------------------------------------------------------===// 2820// Driver code 2821//===----------------------------------------------------------------------===// 2822 2823static TargetInfo *AllocateTarget(const std::string &T) { 2824 llvm::Triple Triple(T); 2825 llvm::Triple::OSType os = Triple.getOS(); 2826 2827 switch (Triple.getArch()) { 2828 default: 2829 return NULL; 2830 2831 case llvm::Triple::arm: 2832 case llvm::Triple::thumb: 2833 if (Triple.isOSDarwin()) 2834 return new DarwinARMTargetInfo(T); 2835 2836 switch (os) { 2837 case llvm::Triple::Linux: 2838 return new LinuxTargetInfo<ARMTargetInfo>(T); 2839 case llvm::Triple::FreeBSD: 2840 return new FreeBSDTargetInfo<ARMTargetInfo>(T); 2841 case llvm::Triple::NetBSD: 2842 return new NetBSDTargetInfo<ARMTargetInfo>(T); 2843 case llvm::Triple::RTEMS: 2844 return new RTEMSTargetInfo<ARMTargetInfo>(T); 2845 default: 2846 return new ARMTargetInfo(T); 2847 } 2848 2849 case llvm::Triple::bfin: 2850 if ( os == llvm::Triple::RTEMS ) 2851 return new RTEMSTargetInfo<BlackfinTargetInfo>(T); 2852 return new BlackfinTargetInfo(T); 2853 2854 case llvm::Triple::msp430: 2855 return new MSP430TargetInfo(T); 2856 2857 case llvm::Triple::mips: 2858 switch (os) { 2859 case llvm::Triple::Psp: 2860 return new PSPTargetInfo<MipsTargetInfo>(T); 2861 case llvm::Triple::Linux: 2862 return new LinuxTargetInfo<MipsTargetInfo>(T); 2863 case llvm::Triple::RTEMS: 2864 return new RTEMSTargetInfo<MipsTargetInfo>(T); 2865 case llvm::Triple::FreeBSD: 2866 return new FreeBSDTargetInfo<MipsTargetInfo>(T); 2867 case llvm::Triple::NetBSD: 2868 return new NetBSDTargetInfo<MipsTargetInfo>(T); 2869 default: 2870 return new MipsTargetInfo(T); 2871 } 2872 2873 case llvm::Triple::mipsel: 2874 switch (os) { 2875 case llvm::Triple::Psp: 2876 return new PSPTargetInfo<MipselTargetInfo>(T); 2877 case llvm::Triple::Linux: 2878 return new LinuxTargetInfo<MipselTargetInfo>(T); 2879 case llvm::Triple::RTEMS: 2880 return new RTEMSTargetInfo<MipselTargetInfo>(T); 2881 case llvm::Triple::FreeBSD: 2882 return new FreeBSDTargetInfo<MipselTargetInfo>(T); 2883 case llvm::Triple::NetBSD: 2884 return new NetBSDTargetInfo<MipselTargetInfo>(T); 2885 default: 2886 return new MipsTargetInfo(T); 2887 } 2888 2889 case llvm::Triple::ppc: 2890 if (Triple.isOSDarwin()) 2891 return new DarwinPPC32TargetInfo(T); 2892 switch (os) { 2893 case llvm::Triple::FreeBSD: 2894 return new FreeBSDTargetInfo<PPC32TargetInfo>(T); 2895 case llvm::Triple::NetBSD: 2896 return new NetBSDTargetInfo<PPC32TargetInfo>(T); 2897 case llvm::Triple::RTEMS: 2898 return new RTEMSTargetInfo<PPC32TargetInfo>(T); 2899 default: 2900 return new PPC32TargetInfo(T); 2901 } 2902 2903 case llvm::Triple::ppc64: 2904 if (Triple.isOSDarwin()) 2905 return new DarwinPPC64TargetInfo(T); 2906 switch (os) { 2907 case llvm::Triple::Lv2: 2908 return new PS3PPUTargetInfo<PPC64TargetInfo>(T); 2909 case llvm::Triple::FreeBSD: 2910 return new FreeBSDTargetInfo<PPC64TargetInfo>(T); 2911 case llvm::Triple::NetBSD: 2912 return new NetBSDTargetInfo<PPC64TargetInfo>(T); 2913 default: 2914 return new PPC64TargetInfo(T); 2915 } 2916 2917 case llvm::Triple::ptx32: 2918 return new PTX32TargetInfo(T); 2919 case llvm::Triple::ptx64: 2920 return new PTX64TargetInfo(T); 2921 2922 case llvm::Triple::mblaze: 2923 return new MBlazeTargetInfo(T); 2924 2925 case llvm::Triple::sparc: 2926 switch (os) { 2927 case llvm::Triple::AuroraUX: 2928 return new AuroraUXSparcV8TargetInfo(T); 2929 case llvm::Triple::Solaris: 2930 return new SolarisSparcV8TargetInfo(T); 2931 case llvm::Triple::NetBSD: 2932 return new NetBSDTargetInfo<SparcV8TargetInfo>(T); 2933 case llvm::Triple::RTEMS: 2934 return new RTEMSTargetInfo<SparcV8TargetInfo>(T); 2935 default: 2936 return new SparcV8TargetInfo(T); 2937 } 2938 2939 // FIXME: Need a real SPU target. 2940 case llvm::Triple::cellspu: 2941 return new PS3SPUTargetInfo<PPC64TargetInfo>(T); 2942 2943 case llvm::Triple::systemz: 2944 return new SystemZTargetInfo(T); 2945 2946 case llvm::Triple::tce: 2947 return new TCETargetInfo(T); 2948 2949 case llvm::Triple::x86: 2950 if (Triple.isOSDarwin()) 2951 return new DarwinI386TargetInfo(T); 2952 2953 switch (os) { 2954 case llvm::Triple::AuroraUX: 2955 return new AuroraUXTargetInfo<X86_32TargetInfo>(T); 2956 case llvm::Triple::Linux: 2957 return new LinuxTargetInfo<X86_32TargetInfo>(T); 2958 case llvm::Triple::DragonFly: 2959 return new DragonFlyBSDTargetInfo<X86_32TargetInfo>(T); 2960 case llvm::Triple::NetBSD: 2961 return new NetBSDTargetInfo<X86_32TargetInfo>(T); 2962 case llvm::Triple::OpenBSD: 2963 return new OpenBSDI386TargetInfo(T); 2964 case llvm::Triple::FreeBSD: 2965 return new FreeBSDTargetInfo<X86_32TargetInfo>(T); 2966 case llvm::Triple::Minix: 2967 return new MinixTargetInfo<X86_32TargetInfo>(T); 2968 case llvm::Triple::Solaris: 2969 return new SolarisTargetInfo<X86_32TargetInfo>(T); 2970 case llvm::Triple::Cygwin: 2971 return new CygwinX86_32TargetInfo(T); 2972 case llvm::Triple::MinGW32: 2973 return new MinGWX86_32TargetInfo(T); 2974 case llvm::Triple::Win32: 2975 return new VisualStudioWindowsX86_32TargetInfo(T); 2976 case llvm::Triple::Haiku: 2977 return new HaikuX86_32TargetInfo(T); 2978 case llvm::Triple::RTEMS: 2979 return new RTEMSX86_32TargetInfo(T); 2980 default: 2981 return new X86_32TargetInfo(T); 2982 } 2983 2984 case llvm::Triple::x86_64: 2985 if (Triple.isOSDarwin() || Triple.getEnvironment() == llvm::Triple::MachO) 2986 return new DarwinX86_64TargetInfo(T); 2987 2988 switch (os) { 2989 case llvm::Triple::AuroraUX: 2990 return new AuroraUXTargetInfo<X86_64TargetInfo>(T); 2991 case llvm::Triple::Linux: 2992 return new LinuxTargetInfo<X86_64TargetInfo>(T); 2993 case llvm::Triple::DragonFly: 2994 return new DragonFlyBSDTargetInfo<X86_64TargetInfo>(T); 2995 case llvm::Triple::NetBSD: 2996 return new NetBSDTargetInfo<X86_64TargetInfo>(T); 2997 case llvm::Triple::OpenBSD: 2998 return new OpenBSDX86_64TargetInfo(T); 2999 case llvm::Triple::FreeBSD: 3000 return new FreeBSDTargetInfo<X86_64TargetInfo>(T); 3001 case llvm::Triple::Solaris: 3002 return new SolarisTargetInfo<X86_64TargetInfo>(T); 3003 case llvm::Triple::MinGW32: 3004 return new MinGWX86_64TargetInfo(T); 3005 case llvm::Triple::Win32: // This is what Triple.h supports now. 3006 return new VisualStudioWindowsX86_64TargetInfo(T); 3007 default: 3008 return new X86_64TargetInfo(T); 3009 } 3010 } 3011} 3012 3013/// CreateTargetInfo - Return the target info object for the specified target 3014/// triple. 3015TargetInfo *TargetInfo::CreateTargetInfo(Diagnostic &Diags, 3016 TargetOptions &Opts) { 3017 llvm::Triple Triple(Opts.Triple); 3018 3019 // Construct the target 3020 llvm::OwningPtr<TargetInfo> Target(AllocateTarget(Triple.str())); 3021 if (!Target) { 3022 Diags.Report(diag::err_target_unknown_triple) << Triple.str(); 3023 return 0; 3024 } 3025 3026 // Set the target CPU if specified. 3027 if (!Opts.CPU.empty() && !Target->setCPU(Opts.CPU)) { 3028 Diags.Report(diag::err_target_unknown_cpu) << Opts.CPU; 3029 return 0; 3030 } 3031 3032 // Set the target ABI if specified. 3033 if (!Opts.ABI.empty() && !Target->setABI(Opts.ABI)) { 3034 Diags.Report(diag::err_target_unknown_abi) << Opts.ABI; 3035 return 0; 3036 } 3037 3038 // Set the target C++ ABI. 3039 if (!Opts.CXXABI.empty() && !Target->setCXXABI(Opts.CXXABI)) { 3040 Diags.Report(diag::err_target_unknown_cxxabi) << Opts.CXXABI; 3041 return 0; 3042 } 3043 3044 // Compute the default target features, we need the target to handle this 3045 // because features may have dependencies on one another. 3046 llvm::StringMap<bool> Features; 3047 Target->getDefaultFeatures(Opts.CPU, Features); 3048 3049 // Apply the user specified deltas. 3050 for (std::vector<std::string>::const_iterator it = Opts.Features.begin(), 3051 ie = Opts.Features.end(); it != ie; ++it) { 3052 const char *Name = it->c_str(); 3053 3054 // Apply the feature via the target. 3055 if ((Name[0] != '-' && Name[0] != '+') || 3056 !Target->setFeatureEnabled(Features, Name + 1, (Name[0] == '+'))) { 3057 Diags.Report(diag::err_target_invalid_feature) << Name; 3058 return 0; 3059 } 3060 } 3061 3062 // Add the features to the compile options. 3063 // 3064 // FIXME: If we are completely confident that we have the right set, we only 3065 // need to pass the minuses. 3066 Opts.Features.clear(); 3067 for (llvm::StringMap<bool>::const_iterator it = Features.begin(), 3068 ie = Features.end(); it != ie; ++it) 3069 Opts.Features.push_back(std::string(it->second ? "+" : "-") + 3070 it->first().str()); 3071 Target->HandleTargetFeatures(Opts.Features); 3072 3073 return Target.take(); 3074} 3075