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