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