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