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