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