Targets.cpp revision fe1ea7b3e4552a612a1b0a11734598651e5ddfdf
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 IntPtrType = SignedLong; 1240 PtrDiffType = SignedLong; 1241 } 1242 virtual void getTargetDefines(const LangOptions &Opts, 1243 MacroBuilder &Builder) const { 1244 X86_32TargetInfo::getTargetDefines(Opts, Builder); 1245 Builder.defineMacro("__INTEL__"); 1246 Builder.defineMacro("__HAIKU__"); 1247 } 1248}; 1249} // end anonymous namespace 1250 1251namespace { 1252// x86-64 generic target 1253class X86_64TargetInfo : public X86TargetInfo { 1254public: 1255 X86_64TargetInfo(const std::string &triple) : X86TargetInfo(triple) { 1256 LongWidth = LongAlign = PointerWidth = PointerAlign = 64; 1257 LongDoubleWidth = 128; 1258 LongDoubleAlign = 128; 1259 IntMaxType = SignedLong; 1260 UIntMaxType = UnsignedLong; 1261 Int64Type = SignedLong; 1262 RegParmMax = 6; 1263 1264 DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 1265 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-" 1266 "a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"; 1267 } 1268 virtual const char *getVAListDeclaration() const { 1269 return "typedef struct __va_list_tag {" 1270 " unsigned gp_offset;" 1271 " unsigned fp_offset;" 1272 " void* overflow_arg_area;" 1273 " void* reg_save_area;" 1274 "} __va_list_tag;" 1275 "typedef __va_list_tag __builtin_va_list[1];"; 1276 } 1277 1278 int getEHDataRegisterNumber(unsigned RegNo) const { 1279 if (RegNo == 0) return 0; 1280 if (RegNo == 1) return 1; 1281 return -1; 1282 } 1283}; 1284} // end anonymous namespace 1285 1286namespace { 1287// x86-64 Windows target 1288class WindowsX86_64TargetInfo : public X86_64TargetInfo { 1289public: 1290 WindowsX86_64TargetInfo(const std::string& triple) 1291 : X86_64TargetInfo(triple) { 1292 TLSSupported = false; 1293 WCharType = UnsignedShort; 1294 LongWidth = LongAlign = 32; 1295 DoubleAlign = LongLongAlign = 64; 1296 } 1297 virtual void getTargetDefines(const LangOptions &Opts, 1298 MacroBuilder &Builder) const { 1299 X86_64TargetInfo::getTargetDefines(Opts, Builder); 1300 Builder.defineMacro("_WIN64"); 1301 DefineStd(Builder, "WIN64", Opts); 1302 } 1303}; 1304} // end anonymous namespace 1305 1306namespace { 1307// x86-64 Windows Visual Studio target 1308class VisualStudioWindowsX86_64TargetInfo : public WindowsX86_64TargetInfo { 1309public: 1310 VisualStudioWindowsX86_64TargetInfo(const std::string& triple) 1311 : WindowsX86_64TargetInfo(triple) { 1312 } 1313 virtual void getTargetDefines(const LangOptions &Opts, 1314 MacroBuilder &Builder) const { 1315 WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder); 1316 Builder.defineMacro("_M_X64"); 1317 } 1318 virtual const char *getVAListDeclaration() const { 1319 return "typedef char* va_list;"; 1320 } 1321}; 1322} // end anonymous namespace 1323 1324namespace { 1325// x86-64 MinGW target 1326class MinGWX86_64TargetInfo : public WindowsX86_64TargetInfo { 1327public: 1328 MinGWX86_64TargetInfo(const std::string& triple) 1329 : WindowsX86_64TargetInfo(triple) { 1330 } 1331 virtual void getTargetDefines(const LangOptions &Opts, 1332 MacroBuilder &Builder) const { 1333 WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder); 1334 Builder.defineMacro("__MSVCRT__"); 1335 Builder.defineMacro("__MINGW64__"); 1336 Builder.defineMacro("__declspec"); 1337 } 1338}; 1339} // end anonymous namespace 1340 1341namespace { 1342class DarwinX86_64TargetInfo : public DarwinTargetInfo<X86_64TargetInfo> { 1343public: 1344 DarwinX86_64TargetInfo(const std::string& triple) 1345 : DarwinTargetInfo<X86_64TargetInfo>(triple) { 1346 Int64Type = SignedLongLong; 1347 } 1348}; 1349} // end anonymous namespace 1350 1351namespace { 1352class OpenBSDX86_64TargetInfo : public OpenBSDTargetInfo<X86_64TargetInfo> { 1353public: 1354 OpenBSDX86_64TargetInfo(const std::string& triple) 1355 : OpenBSDTargetInfo<X86_64TargetInfo>(triple) { 1356 IntMaxType = SignedLongLong; 1357 UIntMaxType = UnsignedLongLong; 1358 Int64Type = SignedLongLong; 1359 } 1360}; 1361} // end anonymous namespace 1362 1363namespace { 1364class ARMTargetInfo : public TargetInfo { 1365 // Possible FPU choices. 1366 enum FPUMode { 1367 NoFPU, 1368 VFP2FPU, 1369 VFP3FPU, 1370 NeonFPU 1371 }; 1372 1373 static bool FPUModeIsVFP(FPUMode Mode) { 1374 return Mode >= VFP2FPU && Mode <= NeonFPU; 1375 } 1376 1377 static const TargetInfo::GCCRegAlias GCCRegAliases[]; 1378 static const char * const GCCRegNames[]; 1379 1380 std::string ABI, CPU; 1381 1382 unsigned FPU : 3; 1383 1384 unsigned IsThumb : 1; 1385 1386 // Initialized via features. 1387 unsigned SoftFloat : 1; 1388 unsigned SoftFloatABI : 1; 1389 1390 static const Builtin::Info BuiltinInfo[]; 1391 1392public: 1393 ARMTargetInfo(const std::string &TripleStr) 1394 : TargetInfo(TripleStr), ABI("aapcs-linux"), CPU("arm1136j-s") 1395 { 1396 SizeType = UnsignedInt; 1397 PtrDiffType = SignedInt; 1398 1399 // FIXME: Should we just treat this as a feature? 1400 IsThumb = getTriple().getArchName().startswith("thumb"); 1401 if (IsThumb) { 1402 DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-" 1403 "i64:64:64-f32:32:32-f64:64:64-" 1404 "v64:64:64-v128:128:128-a0:0:32-n32"); 1405 } else { 1406 DescriptionString = ("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 1407 "i64:64:64-f32:32:32-f64:64:64-" 1408 "v64:64:64-v128:128:128-a0:0:64-n32"); 1409 } 1410 } 1411 virtual const char *getABI() const { return ABI.c_str(); } 1412 virtual bool setABI(const std::string &Name) { 1413 ABI = Name; 1414 1415 // The defaults (above) are for AAPCS, check if we need to change them. 1416 // 1417 // FIXME: We need support for -meabi... we could just mangle it into the 1418 // name. 1419 if (Name == "apcs-gnu") { 1420 DoubleAlign = LongLongAlign = LongDoubleAlign = 32; 1421 SizeType = UnsignedLong; 1422 1423 // Do not respect the alignment of bit-field types when laying out 1424 // structures. This corresponds to PCC_BITFIELD_TYPE_MATTERS in gcc. 1425 UseBitFieldTypeAlignment = false; 1426 1427 if (IsThumb) { 1428 DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-" 1429 "i64:32:32-f32:32:32-f64:32:32-" 1430 "v64:64:64-v128:128:128-a0:0:32-n32"); 1431 } else { 1432 DescriptionString = ("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 1433 "i64:32:32-f32:32:32-f64:32:32-" 1434 "v64:64:64-v128:128:128-a0:0:64-n32"); 1435 } 1436 1437 // FIXME: Override "preferred align" for double and long long. 1438 } else if (Name == "aapcs") { 1439 // FIXME: Enumerated types are variable width in straight AAPCS. 1440 } else if (Name == "aapcs-linux") { 1441 ; 1442 } else 1443 return false; 1444 1445 return true; 1446 } 1447 1448 void getDefaultFeatures(const std::string &CPU, 1449 llvm::StringMap<bool> &Features) const { 1450 // FIXME: This should not be here. 1451 Features["vfp2"] = false; 1452 Features["vfp3"] = false; 1453 Features["neon"] = false; 1454 1455 if (CPU == "arm1136jf-s" || CPU == "arm1176jzf-s" || CPU == "mpcore") 1456 Features["vfp2"] = true; 1457 else if (CPU == "cortex-a8" || CPU == "cortex-a9") 1458 Features["neon"] = true; 1459 } 1460 1461 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features, 1462 const std::string &Name, 1463 bool Enabled) const { 1464 if (Name == "soft-float" || Name == "soft-float-abi") { 1465 Features[Name] = Enabled; 1466 } else if (Name == "vfp2" || Name == "vfp3" || Name == "neon") { 1467 // These effectively are a single option, reset them when any is enabled. 1468 if (Enabled) 1469 Features["vfp2"] = Features["vfp3"] = Features["neon"] = false; 1470 Features[Name] = Enabled; 1471 } else 1472 return false; 1473 1474 return true; 1475 } 1476 1477 virtual void HandleTargetFeatures(std::vector<std::string> &Features) { 1478 FPU = NoFPU; 1479 SoftFloat = SoftFloatABI = false; 1480 for (unsigned i = 0, e = Features.size(); i != e; ++i) { 1481 if (Features[i] == "+soft-float") 1482 SoftFloat = true; 1483 else if (Features[i] == "+soft-float-abi") 1484 SoftFloatABI = true; 1485 else if (Features[i] == "+vfp2") 1486 FPU = VFP2FPU; 1487 else if (Features[i] == "+vfp3") 1488 FPU = VFP3FPU; 1489 else if (Features[i] == "+neon") 1490 FPU = NeonFPU; 1491 } 1492 1493 // Remove front-end specific options which the backend handles differently. 1494 std::vector<std::string>::iterator it; 1495 it = std::find(Features.begin(), Features.end(), "+soft-float"); 1496 if (it != Features.end()) 1497 Features.erase(it); 1498 it = std::find(Features.begin(), Features.end(), "+soft-float-abi"); 1499 if (it != Features.end()) 1500 Features.erase(it); 1501 } 1502 1503 static const char *getCPUDefineSuffix(llvm::StringRef Name) { 1504 return llvm::StringSwitch<const char*>(Name) 1505 .Cases("arm8", "arm810", "4") 1506 .Cases("strongarm", "strongarm110", "strongarm1100", "strongarm1110", "4") 1507 .Cases("arm7tdmi", "arm7tdmi-s", "arm710t", "arm720t", "arm9", "4T") 1508 .Cases("arm9tdmi", "arm920", "arm920t", "arm922t", "arm940t", "4T") 1509 .Case("ep9312", "4T") 1510 .Cases("arm10tdmi", "arm1020t", "5T") 1511 .Cases("arm9e", "arm946e-s", "arm966e-s", "arm968e-s", "5TE") 1512 .Case("arm926ej-s", "5TEJ") 1513 .Cases("arm10e", "arm1020e", "arm1022e", "5TE") 1514 .Cases("xscale", "iwmmxt", "5TE") 1515 .Case("arm1136j-s", "6J") 1516 .Cases("arm1176jz-s", "arm1176jzf-s", "6ZK") 1517 .Cases("arm1136jf-s", "mpcorenovfp", "mpcore", "6K") 1518 .Cases("arm1156t2-s", "arm1156t2f-s", "6T2") 1519 .Cases("cortex-a8", "cortex-a9", "7A") 1520 .Default(0); 1521 } 1522 virtual bool setCPU(const std::string &Name) { 1523 if (!getCPUDefineSuffix(Name)) 1524 return false; 1525 1526 CPU = Name; 1527 return true; 1528 } 1529 virtual void getTargetDefines(const LangOptions &Opts, 1530 MacroBuilder &Builder) const { 1531 // Target identification. 1532 Builder.defineMacro("__arm"); 1533 Builder.defineMacro("__arm__"); 1534 1535 // Target properties. 1536 Builder.defineMacro("__ARMEL__"); 1537 Builder.defineMacro("__LITTLE_ENDIAN__"); 1538 Builder.defineMacro("__REGISTER_PREFIX__", ""); 1539 1540 llvm::StringRef CPUArch = getCPUDefineSuffix(CPU); 1541 Builder.defineMacro("__ARM_ARCH_" + CPUArch + "__"); 1542 1543 // Subtarget options. 1544 1545 // FIXME: It's more complicated than this and we don't really support 1546 // interworking. 1547 if ('5' <= CPUArch[0] && CPUArch[0] <= '7') 1548 Builder.defineMacro("__THUMB_INTERWORK__"); 1549 1550 if (ABI == "aapcs" || ABI == "aapcs-linux") 1551 Builder.defineMacro("__ARM_EABI__"); 1552 1553 if (SoftFloat) 1554 Builder.defineMacro("__SOFTFP__"); 1555 1556 if (CPU == "xscale") 1557 Builder.defineMacro("__XSCALE__"); 1558 1559 bool IsThumb2 = IsThumb && (CPUArch == "6T2" || CPUArch.startswith("7")); 1560 if (IsThumb) { 1561 Builder.defineMacro("__THUMBEL__"); 1562 Builder.defineMacro("__thumb__"); 1563 if (IsThumb2) 1564 Builder.defineMacro("__thumb2__"); 1565 } 1566 1567 // Note, this is always on in gcc, even though it doesn't make sense. 1568 Builder.defineMacro("__APCS_32__"); 1569 1570 if (FPUModeIsVFP((FPUMode) FPU)) 1571 Builder.defineMacro("__VFP_FP__"); 1572 1573 // This only gets set when Neon instructions are actually available, unlike 1574 // the VFP define, hence the soft float and arch check. This is subtly 1575 // different from gcc, we follow the intent which was that it should be set 1576 // when Neon instructions are actually available. 1577 if (FPU == NeonFPU && !SoftFloat && IsThumb2) 1578 Builder.defineMacro("__ARM_NEON__"); 1579 } 1580 virtual void getTargetBuiltins(const Builtin::Info *&Records, 1581 unsigned &NumRecords) const { 1582 Records = BuiltinInfo; 1583 NumRecords = clang::ARM::LastTSBuiltin-Builtin::FirstTSBuiltin; 1584 } 1585 virtual const char *getVAListDeclaration() const { 1586 return "typedef char* __builtin_va_list;"; 1587 } 1588 virtual void getGCCRegNames(const char * const *&Names, 1589 unsigned &NumNames) const; 1590 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 1591 unsigned &NumAliases) const; 1592 virtual bool validateAsmConstraint(const char *&Name, 1593 TargetInfo::ConstraintInfo &Info) const { 1594 // FIXME: Check if this is complete 1595 switch (*Name) { 1596 default: 1597 case 'l': // r0-r7 1598 case 'h': // r8-r15 1599 case 'w': // VFP Floating point register single precision 1600 case 'P': // VFP Floating point register double precision 1601 Info.setAllowsRegister(); 1602 return true; 1603 } 1604 return false; 1605 } 1606 virtual const char *getClobbers() const { 1607 // FIXME: Is this really right? 1608 return ""; 1609 } 1610}; 1611 1612const char * const ARMTargetInfo::GCCRegNames[] = { 1613 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 1614 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" 1615}; 1616 1617void ARMTargetInfo::getGCCRegNames(const char * const *&Names, 1618 unsigned &NumNames) const { 1619 Names = GCCRegNames; 1620 NumNames = llvm::array_lengthof(GCCRegNames); 1621} 1622 1623const TargetInfo::GCCRegAlias ARMTargetInfo::GCCRegAliases[] = { 1624 1625 { { "a1" }, "r0" }, 1626 { { "a2" }, "r1" }, 1627 { { "a3" }, "r2" }, 1628 { { "a4" }, "r3" }, 1629 { { "v1" }, "r4" }, 1630 { { "v2" }, "r5" }, 1631 { { "v3" }, "r6" }, 1632 { { "v4" }, "r7" }, 1633 { { "v5" }, "r8" }, 1634 { { "v6", "rfp" }, "r9" }, 1635 { { "sl" }, "r10" }, 1636 { { "fp" }, "r11" }, 1637 { { "ip" }, "r12" }, 1638 { { "sp" }, "r13" }, 1639 { { "lr" }, "r14" }, 1640 { { "pc" }, "r15" }, 1641}; 1642 1643void ARMTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, 1644 unsigned &NumAliases) const { 1645 Aliases = GCCRegAliases; 1646 NumAliases = llvm::array_lengthof(GCCRegAliases); 1647} 1648 1649const Builtin::Info ARMTargetInfo::BuiltinInfo[] = { 1650#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false }, 1651#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false }, 1652#include "clang/Basic/BuiltinsARM.def" 1653}; 1654} // end anonymous namespace. 1655 1656 1657namespace { 1658class DarwinARMTargetInfo : 1659 public DarwinTargetInfo<ARMTargetInfo> { 1660protected: 1661 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 1662 MacroBuilder &Builder) const { 1663 getDarwinDefines(Builder, Opts, Triple); 1664 } 1665 1666public: 1667 DarwinARMTargetInfo(const std::string& triple) 1668 : DarwinTargetInfo<ARMTargetInfo>(triple) {} 1669}; 1670} // end anonymous namespace. 1671 1672namespace { 1673class SparcV8TargetInfo : public TargetInfo { 1674 static const TargetInfo::GCCRegAlias GCCRegAliases[]; 1675 static const char * const GCCRegNames[]; 1676public: 1677 SparcV8TargetInfo(const std::string& triple) : TargetInfo(triple) { 1678 // FIXME: Support Sparc quad-precision long double? 1679 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 1680 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32"; 1681 } 1682 virtual void getTargetDefines(const LangOptions &Opts, 1683 MacroBuilder &Builder) const { 1684 DefineStd(Builder, "sparc", Opts); 1685 Builder.defineMacro("__sparcv8"); 1686 Builder.defineMacro("__REGISTER_PREFIX__", ""); 1687 } 1688 virtual void getTargetBuiltins(const Builtin::Info *&Records, 1689 unsigned &NumRecords) const { 1690 // FIXME: Implement! 1691 } 1692 virtual const char *getVAListDeclaration() const { 1693 return "typedef void* __builtin_va_list;"; 1694 } 1695 virtual void getGCCRegNames(const char * const *&Names, 1696 unsigned &NumNames) const; 1697 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 1698 unsigned &NumAliases) const; 1699 virtual bool validateAsmConstraint(const char *&Name, 1700 TargetInfo::ConstraintInfo &info) const { 1701 // FIXME: Implement! 1702 return false; 1703 } 1704 virtual const char *getClobbers() const { 1705 // FIXME: Implement! 1706 return ""; 1707 } 1708}; 1709 1710const char * const SparcV8TargetInfo::GCCRegNames[] = { 1711 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 1712 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 1713 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", 1714 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" 1715}; 1716 1717void SparcV8TargetInfo::getGCCRegNames(const char * const *&Names, 1718 unsigned &NumNames) const { 1719 Names = GCCRegNames; 1720 NumNames = llvm::array_lengthof(GCCRegNames); 1721} 1722 1723const TargetInfo::GCCRegAlias SparcV8TargetInfo::GCCRegAliases[] = { 1724 { { "g0" }, "r0" }, 1725 { { "g1" }, "r1" }, 1726 { { "g2" }, "r2" }, 1727 { { "g3" }, "r3" }, 1728 { { "g4" }, "r4" }, 1729 { { "g5" }, "r5" }, 1730 { { "g6" }, "r6" }, 1731 { { "g7" }, "r7" }, 1732 { { "o0" }, "r8" }, 1733 { { "o1" }, "r9" }, 1734 { { "o2" }, "r10" }, 1735 { { "o3" }, "r11" }, 1736 { { "o4" }, "r12" }, 1737 { { "o5" }, "r13" }, 1738 { { "o6", "sp" }, "r14" }, 1739 { { "o7" }, "r15" }, 1740 { { "l0" }, "r16" }, 1741 { { "l1" }, "r17" }, 1742 { { "l2" }, "r18" }, 1743 { { "l3" }, "r19" }, 1744 { { "l4" }, "r20" }, 1745 { { "l5" }, "r21" }, 1746 { { "l6" }, "r22" }, 1747 { { "l7" }, "r23" }, 1748 { { "i0" }, "r24" }, 1749 { { "i1" }, "r25" }, 1750 { { "i2" }, "r26" }, 1751 { { "i3" }, "r27" }, 1752 { { "i4" }, "r28" }, 1753 { { "i5" }, "r29" }, 1754 { { "i6", "fp" }, "r30" }, 1755 { { "i7" }, "r31" }, 1756}; 1757 1758void SparcV8TargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, 1759 unsigned &NumAliases) const { 1760 Aliases = GCCRegAliases; 1761 NumAliases = llvm::array_lengthof(GCCRegAliases); 1762} 1763} // end anonymous namespace. 1764 1765namespace { 1766class AuroraUXSparcV8TargetInfo : public AuroraUXTargetInfo<SparcV8TargetInfo> { 1767public: 1768 AuroraUXSparcV8TargetInfo(const std::string& triple) : 1769 AuroraUXTargetInfo<SparcV8TargetInfo>(triple) { 1770 SizeType = UnsignedInt; 1771 PtrDiffType = SignedInt; 1772 } 1773}; 1774class SolarisSparcV8TargetInfo : public SolarisTargetInfo<SparcV8TargetInfo> { 1775public: 1776 SolarisSparcV8TargetInfo(const std::string& triple) : 1777 SolarisTargetInfo<SparcV8TargetInfo>(triple) { 1778 SizeType = UnsignedInt; 1779 PtrDiffType = SignedInt; 1780 } 1781}; 1782} // end anonymous namespace. 1783 1784namespace { 1785 class PIC16TargetInfo : public TargetInfo{ 1786 public: 1787 PIC16TargetInfo(const std::string& triple) : TargetInfo(triple) { 1788 TLSSupported = false; 1789 IntWidth = 16; 1790 LongWidth = LongLongWidth = 32; 1791 PointerWidth = 16; 1792 IntAlign = 8; 1793 LongAlign = LongLongAlign = 8; 1794 PointerAlign = 8; 1795 SizeType = UnsignedInt; 1796 IntMaxType = SignedLong; 1797 UIntMaxType = UnsignedLong; 1798 IntPtrType = SignedShort; 1799 PtrDiffType = SignedInt; 1800 SigAtomicType = SignedLong; 1801 FloatWidth = 32; 1802 FloatAlign = 32; 1803 DoubleWidth = 32; 1804 DoubleAlign = 32; 1805 LongDoubleWidth = 32; 1806 LongDoubleAlign = 32; 1807 FloatFormat = &llvm::APFloat::IEEEsingle; 1808 DoubleFormat = &llvm::APFloat::IEEEsingle; 1809 LongDoubleFormat = &llvm::APFloat::IEEEsingle; 1810 DescriptionString = "e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8-f32:32:32-n8"; 1811 1812 } 1813 virtual uint64_t getPointerWidthV(unsigned AddrSpace) const { return 16; } 1814 virtual uint64_t getPointerAlignV(unsigned AddrSpace) const { return 8; } 1815 virtual void getTargetDefines(const LangOptions &Opts, 1816 MacroBuilder &Builder) const { 1817 Builder.defineMacro("__pic16"); 1818 Builder.defineMacro("__PIC16"); 1819 Builder.defineMacro("rom", "__attribute__((address_space(1)))"); 1820 Builder.defineMacro("ram", "__attribute__((address_space(0)))"); 1821 Builder.defineMacro("__section(SectName)", 1822 "__attribute__((section(SectName)))"); 1823 Builder.defineMacro("near", 1824 "__attribute__((section(\"Address=NEAR\")))"); 1825 Builder.defineMacro("__address(Addr)", 1826 "__attribute__((section(\"Address=\"#Addr)))"); 1827 Builder.defineMacro("__config(conf)", "asm(\"CONFIG \"#conf)"); 1828 Builder.defineMacro("__idlocs(value)", "asm(\"__IDLOCS \"#value)"); 1829 Builder.defineMacro("interrupt", 1830 "__attribute__((section(\"interrupt=0x4\"))) \ 1831 __attribute__((used))"); 1832 } 1833 virtual void getTargetBuiltins(const Builtin::Info *&Records, 1834 unsigned &NumRecords) const {} 1835 virtual const char *getVAListDeclaration() const { 1836 return "typedef char* __builtin_va_list;"; 1837 } 1838 virtual const char *getClobbers() const { 1839 return ""; 1840 } 1841 virtual void getGCCRegNames(const char * const *&Names, 1842 unsigned &NumNames) const {} 1843 virtual bool validateAsmConstraint(const char *&Name, 1844 TargetInfo::ConstraintInfo &info) const { 1845 return true; 1846 } 1847 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 1848 unsigned &NumAliases) const {} 1849 virtual bool useGlobalsForAutomaticVariables() const {return true;} 1850 }; 1851} 1852 1853namespace { 1854 class MSP430TargetInfo : public TargetInfo { 1855 static const char * const GCCRegNames[]; 1856 public: 1857 MSP430TargetInfo(const std::string& triple) : TargetInfo(triple) { 1858 TLSSupported = false; 1859 IntWidth = 16; IntAlign = 16; 1860 LongWidth = 32; LongLongWidth = 64; 1861 LongAlign = LongLongAlign = 16; 1862 PointerWidth = 16; PointerAlign = 16; 1863 SizeType = UnsignedInt; 1864 IntMaxType = SignedLong; 1865 UIntMaxType = UnsignedLong; 1866 IntPtrType = SignedShort; 1867 PtrDiffType = SignedInt; 1868 SigAtomicType = SignedLong; 1869 DescriptionString = "e-p:16:16:16-i8:8:8-i16:16:16-i32:16:32-n8:16"; 1870 } 1871 virtual void getTargetDefines(const LangOptions &Opts, 1872 MacroBuilder &Builder) const { 1873 Builder.defineMacro("MSP430"); 1874 Builder.defineMacro("__MSP430__"); 1875 // FIXME: defines for different 'flavours' of MCU 1876 } 1877 virtual void getTargetBuiltins(const Builtin::Info *&Records, 1878 unsigned &NumRecords) const { 1879 // FIXME: Implement. 1880 Records = 0; 1881 NumRecords = 0; 1882 } 1883 virtual void getGCCRegNames(const char * const *&Names, 1884 unsigned &NumNames) const; 1885 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 1886 unsigned &NumAliases) const { 1887 // No aliases. 1888 Aliases = 0; 1889 NumAliases = 0; 1890 } 1891 virtual bool validateAsmConstraint(const char *&Name, 1892 TargetInfo::ConstraintInfo &info) const { 1893 // No target constraints for now. 1894 return false; 1895 } 1896 virtual const char *getClobbers() const { 1897 // FIXME: Is this really right? 1898 return ""; 1899 } 1900 virtual const char *getVAListDeclaration() const { 1901 // FIXME: implement 1902 return "typedef char* __builtin_va_list;"; 1903 } 1904 }; 1905 1906 const char * const MSP430TargetInfo::GCCRegNames[] = { 1907 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 1908 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" 1909 }; 1910 1911 void MSP430TargetInfo::getGCCRegNames(const char * const *&Names, 1912 unsigned &NumNames) const { 1913 Names = GCCRegNames; 1914 NumNames = llvm::array_lengthof(GCCRegNames); 1915 } 1916} 1917 1918 1919namespace { 1920 class SystemZTargetInfo : public TargetInfo { 1921 static const char * const GCCRegNames[]; 1922 public: 1923 SystemZTargetInfo(const std::string& triple) : TargetInfo(triple) { 1924 TLSSupported = false; 1925 IntWidth = IntAlign = 32; 1926 LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64; 1927 PointerWidth = PointerAlign = 64; 1928 DescriptionString = "E-p:64:64:64-i8:8:16-i16:16:16-i32:32:32-" 1929 "i64:64:64-f32:32:32-f64:64:64-f128:128:128-a0:16:16-n32:64"; 1930 } 1931 virtual void getTargetDefines(const LangOptions &Opts, 1932 MacroBuilder &Builder) const { 1933 Builder.defineMacro("__s390__"); 1934 Builder.defineMacro("__s390x__"); 1935 } 1936 virtual void getTargetBuiltins(const Builtin::Info *&Records, 1937 unsigned &NumRecords) const { 1938 // FIXME: Implement. 1939 Records = 0; 1940 NumRecords = 0; 1941 } 1942 1943 virtual void getGCCRegNames(const char * const *&Names, 1944 unsigned &NumNames) const; 1945 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 1946 unsigned &NumAliases) const { 1947 // No aliases. 1948 Aliases = 0; 1949 NumAliases = 0; 1950 } 1951 virtual bool validateAsmConstraint(const char *&Name, 1952 TargetInfo::ConstraintInfo &info) const { 1953 // FIXME: implement 1954 return true; 1955 } 1956 virtual const char *getClobbers() const { 1957 // FIXME: Is this really right? 1958 return ""; 1959 } 1960 virtual const char *getVAListDeclaration() const { 1961 // FIXME: implement 1962 return "typedef char* __builtin_va_list;"; 1963 } 1964 }; 1965 1966 const char * const SystemZTargetInfo::GCCRegNames[] = { 1967 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 1968 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" 1969 }; 1970 1971 void SystemZTargetInfo::getGCCRegNames(const char * const *&Names, 1972 unsigned &NumNames) const { 1973 Names = GCCRegNames; 1974 NumNames = llvm::array_lengthof(GCCRegNames); 1975 } 1976} 1977 1978namespace { 1979 class BlackfinTargetInfo : public TargetInfo { 1980 static const char * const GCCRegNames[]; 1981 public: 1982 BlackfinTargetInfo(const std::string& triple) : TargetInfo(triple) { 1983 TLSSupported = false; 1984 DoubleAlign = 32; 1985 LongLongAlign = 32; 1986 LongDoubleAlign = 32; 1987 DescriptionString = "e-p:32:32-i64:32-f64:32-n32"; 1988 } 1989 1990 virtual void getTargetDefines(const LangOptions &Opts, 1991 MacroBuilder &Builder) const { 1992 DefineStd(Builder, "bfin", Opts); 1993 DefineStd(Builder, "BFIN", Opts); 1994 Builder.defineMacro("__ADSPBLACKFIN__"); 1995 // FIXME: This one is really dependent on -mcpu 1996 Builder.defineMacro("__ADSPLPBLACKFIN__"); 1997 // FIXME: Add cpu-dependent defines and __SILICON_REVISION__ 1998 } 1999 2000 virtual void getTargetBuiltins(const Builtin::Info *&Records, 2001 unsigned &NumRecords) const { 2002 // FIXME: Implement. 2003 Records = 0; 2004 NumRecords = 0; 2005 } 2006 2007 virtual void getGCCRegNames(const char * const *&Names, 2008 unsigned &NumNames) const; 2009 2010 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 2011 unsigned &NumAliases) const { 2012 // No aliases. 2013 Aliases = 0; 2014 NumAliases = 0; 2015 } 2016 2017 virtual bool validateAsmConstraint(const char *&Name, 2018 TargetInfo::ConstraintInfo &Info) const { 2019 if (strchr("adzDWeABbvfcCtukxywZY", Name[0])) { 2020 Info.setAllowsRegister(); 2021 return true; 2022 } 2023 return false; 2024 } 2025 2026 virtual const char *getClobbers() const { 2027 return ""; 2028 } 2029 2030 virtual const char *getVAListDeclaration() const { 2031 return "typedef char* __builtin_va_list;"; 2032 } 2033 }; 2034 2035 const char * const BlackfinTargetInfo::GCCRegNames[] = { 2036 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 2037 "p0", "p1", "p2", "p3", "p4", "p5", "sp", "fp", 2038 "i0", "i1", "i2", "i3", "b0", "b1", "b2", "b3", 2039 "l0", "l1", "l2", "l3", "m0", "m1", "m2", "m3", 2040 "a0", "a1", "cc", 2041 "rets", "reti", "retx", "retn", "rete", "astat", "seqstat", "usp", 2042 "argp", "lt0", "lt1", "lc0", "lc1", "lb0", "lb1" 2043 }; 2044 2045 void BlackfinTargetInfo::getGCCRegNames(const char * const *&Names, 2046 unsigned &NumNames) const { 2047 Names = GCCRegNames; 2048 NumNames = llvm::array_lengthof(GCCRegNames); 2049 } 2050} 2051 2052namespace { 2053 2054 // LLVM and Clang cannot be used directly to output native binaries for 2055 // target, but is used to compile C code to llvm bitcode with correct 2056 // type and alignment information. 2057 // 2058 // TCE uses the llvm bitcode as input and uses it for generating customized 2059 // target processor and program binary. TCE co-design environment is 2060 // publicly available in http://tce.cs.tut.fi 2061 2062 class TCETargetInfo : public TargetInfo{ 2063 public: 2064 TCETargetInfo(const std::string& triple) : TargetInfo(triple) { 2065 TLSSupported = false; 2066 IntWidth = 32; 2067 LongWidth = LongLongWidth = 32; 2068 PointerWidth = 32; 2069 IntAlign = 32; 2070 LongAlign = LongLongAlign = 32; 2071 PointerAlign = 32; 2072 SizeType = UnsignedInt; 2073 IntMaxType = SignedLong; 2074 UIntMaxType = UnsignedLong; 2075 IntPtrType = SignedInt; 2076 PtrDiffType = SignedInt; 2077 FloatWidth = 32; 2078 FloatAlign = 32; 2079 DoubleWidth = 32; 2080 DoubleAlign = 32; 2081 LongDoubleWidth = 32; 2082 LongDoubleAlign = 32; 2083 FloatFormat = &llvm::APFloat::IEEEsingle; 2084 DoubleFormat = &llvm::APFloat::IEEEsingle; 2085 LongDoubleFormat = &llvm::APFloat::IEEEsingle; 2086 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-" 2087 "i16:16:32-i32:32:32-i64:32:32-" 2088 "f32:32:32-f64:64:64-v64:64:64-" 2089 "v128:128:128-a0:0:64-n32"; 2090 } 2091 2092 virtual void getTargetDefines(const LangOptions &Opts, 2093 MacroBuilder &Builder) const { 2094 DefineStd(Builder, "tce", Opts); 2095 Builder.defineMacro("__TCE__"); 2096 Builder.defineMacro("__TCE_V1__"); 2097 } 2098 virtual void getTargetBuiltins(const Builtin::Info *&Records, 2099 unsigned &NumRecords) const {} 2100 virtual const char *getClobbers() const { 2101 return ""; 2102 } 2103 virtual const char *getVAListDeclaration() const { 2104 return "typedef void* __builtin_va_list;"; 2105 } 2106 virtual void getGCCRegNames(const char * const *&Names, 2107 unsigned &NumNames) const {} 2108 virtual bool validateAsmConstraint(const char *&Name, 2109 TargetInfo::ConstraintInfo &info) const { 2110 return true; 2111 } 2112 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 2113 unsigned &NumAliases) const {} 2114 }; 2115} 2116 2117namespace { 2118class MipsTargetInfo : public TargetInfo { 2119 std::string ABI, CPU; 2120 static const TargetInfo::GCCRegAlias GCCRegAliases[]; 2121 static const char * const GCCRegNames[]; 2122public: 2123 MipsTargetInfo(const std::string& triple) : TargetInfo(triple), ABI("o32") { 2124 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-" 2125 "i64:32:64-f32:32:32-f64:64:64-v64:64:64-n32"; 2126 } 2127 virtual const char *getABI() const { return ABI.c_str(); } 2128 virtual bool setABI(const std::string &Name) { 2129 2130 if ((Name == "o32") || (Name == "eabi")) { 2131 ABI = Name; 2132 return true; 2133 } else 2134 return false; 2135 } 2136 virtual bool setCPU(const std::string &Name) { 2137 CPU = Name; 2138 return true; 2139 } 2140 void getDefaultFeatures(const std::string &CPU, 2141 llvm::StringMap<bool> &Features) const { 2142 Features[ABI] = true; 2143 Features[CPU] = true; 2144 } 2145 virtual void getArchDefines(const LangOptions &Opts, 2146 MacroBuilder &Builder) const { 2147 if (ABI == "o32") 2148 Builder.defineMacro("__mips_o32"); 2149 else if (ABI == "eabi") 2150 Builder.defineMacro("__mips_eabi"); 2151 } 2152 virtual void getTargetDefines(const LangOptions &Opts, 2153 MacroBuilder &Builder) const { 2154 DefineStd(Builder, "mips", Opts); 2155 Builder.defineMacro("_mips"); 2156 DefineStd(Builder, "MIPSEB", Opts); 2157 Builder.defineMacro("_MIPSEB"); 2158 Builder.defineMacro("__REGISTER_PREFIX__", ""); 2159 getArchDefines(Opts, Builder); 2160 } 2161 virtual void getTargetBuiltins(const Builtin::Info *&Records, 2162 unsigned &NumRecords) const { 2163 // FIXME: Implement! 2164 } 2165 virtual const char *getVAListDeclaration() const { 2166 return "typedef void* __builtin_va_list;"; 2167 } 2168 virtual void getGCCRegNames(const char * const *&Names, 2169 unsigned &NumNames) const; 2170 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 2171 unsigned &NumAliases) const; 2172 virtual bool validateAsmConstraint(const char *&Name, 2173 TargetInfo::ConstraintInfo &Info) const { 2174 switch (*Name) { 2175 default: 2176 case 'r': // CPU registers. 2177 case 'd': // Equivalent to "r" unless generating MIPS16 code. 2178 case 'y': // Equivalent to "r", backwards compatibility only. 2179 case 'f': // floating-point registers. 2180 Info.setAllowsRegister(); 2181 return true; 2182 } 2183 return false; 2184 } 2185 2186 virtual const char *getClobbers() const { 2187 // FIXME: Implement! 2188 return ""; 2189 } 2190}; 2191 2192const char * const MipsTargetInfo::GCCRegNames[] = { 2193 "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7", 2194 "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", 2195 "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23", 2196 "$24", "$25", "$26", "$27", "$28", "$sp", "$fp", "$31", 2197 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7", 2198 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15", 2199 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23", 2200 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31", 2201 "hi", "lo", "", "$fcc0","$fcc1","$fcc2","$fcc3","$fcc4", 2202 "$fcc5","$fcc6","$fcc7" 2203}; 2204 2205void MipsTargetInfo::getGCCRegNames(const char * const *&Names, 2206 unsigned &NumNames) const { 2207 Names = GCCRegNames; 2208 NumNames = llvm::array_lengthof(GCCRegNames); 2209} 2210 2211const TargetInfo::GCCRegAlias MipsTargetInfo::GCCRegAliases[] = { 2212 { { "at" }, "$1" }, 2213 { { "v0" }, "$2" }, 2214 { { "v1" }, "$3" }, 2215 { { "a0" }, "$4" }, 2216 { { "a1" }, "$5" }, 2217 { { "a2" }, "$6" }, 2218 { { "a3" }, "$7" }, 2219 { { "t0" }, "$8" }, 2220 { { "t1" }, "$9" }, 2221 { { "t2" }, "$10" }, 2222 { { "t3" }, "$11" }, 2223 { { "t4" }, "$12" }, 2224 { { "t5" }, "$13" }, 2225 { { "t6" }, "$14" }, 2226 { { "t7" }, "$15" }, 2227 { { "s0" }, "$16" }, 2228 { { "s1" }, "$17" }, 2229 { { "s2" }, "$18" }, 2230 { { "s3" }, "$19" }, 2231 { { "s4" }, "$20" }, 2232 { { "s5" }, "$21" }, 2233 { { "s6" }, "$22" }, 2234 { { "s7" }, "$23" }, 2235 { { "t8" }, "$24" }, 2236 { { "t9" }, "$25" }, 2237 { { "k0" }, "$26" }, 2238 { { "k1" }, "$27" }, 2239 { { "gp" }, "$28" }, 2240 { { "sp" }, "$29" }, 2241 { { "fp" }, "$30" }, 2242 { { "ra" }, "$31" } 2243}; 2244 2245void MipsTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, 2246 unsigned &NumAliases) const { 2247 Aliases = GCCRegAliases; 2248 NumAliases = llvm::array_lengthof(GCCRegAliases); 2249} 2250} // end anonymous namespace. 2251 2252namespace { 2253class MipselTargetInfo : public MipsTargetInfo { 2254public: 2255 MipselTargetInfo(const std::string& triple) : MipsTargetInfo(triple) { 2256 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-" 2257 "i64:32:64-f32:32:32-f64:64:64-v64:64:64-n32"; 2258 } 2259 2260 virtual void getTargetDefines(const LangOptions &Opts, 2261 MacroBuilder &Builder) const; 2262}; 2263 2264void MipselTargetInfo::getTargetDefines(const LangOptions &Opts, 2265 MacroBuilder &Builder) const { 2266 DefineStd(Builder, "mips", Opts); 2267 Builder.defineMacro("_mips"); 2268 DefineStd(Builder, "MIPSEL", Opts); 2269 Builder.defineMacro("_MIPSEL"); 2270 Builder.defineMacro("__REGISTER_PREFIX__", ""); 2271 getArchDefines(Opts, Builder); 2272} 2273} // end anonymous namespace. 2274 2275//===----------------------------------------------------------------------===// 2276// Driver code 2277//===----------------------------------------------------------------------===// 2278 2279static TargetInfo *AllocateTarget(const std::string &T) { 2280 llvm::Triple Triple(T); 2281 llvm::Triple::OSType os = Triple.getOS(); 2282 2283 switch (Triple.getArch()) { 2284 default: 2285 return NULL; 2286 2287 case llvm::Triple::arm: 2288 case llvm::Triple::thumb: 2289 switch (os) { 2290 case llvm::Triple::Darwin: 2291 return new DarwinARMTargetInfo(T); 2292 case llvm::Triple::FreeBSD: 2293 return new FreeBSDTargetInfo<ARMTargetInfo>(T); 2294 default: 2295 return new ARMTargetInfo(T); 2296 } 2297 2298 case llvm::Triple::bfin: 2299 return new BlackfinTargetInfo(T); 2300 2301 case llvm::Triple::msp430: 2302 return new MSP430TargetInfo(T); 2303 2304 case llvm::Triple::mips: 2305 if (os == llvm::Triple::Psp) 2306 return new PSPTargetInfo<MipsTargetInfo>(T); 2307 if (os == llvm::Triple::Linux) 2308 return new LinuxTargetInfo<MipsTargetInfo>(T); 2309 return new MipsTargetInfo(T); 2310 2311 case llvm::Triple::mipsel: 2312 if (os == llvm::Triple::Psp) 2313 return new PSPTargetInfo<MipselTargetInfo>(T); 2314 if (os == llvm::Triple::Linux) 2315 return new LinuxTargetInfo<MipselTargetInfo>(T); 2316 return new MipselTargetInfo(T); 2317 2318 case llvm::Triple::pic16: 2319 return new PIC16TargetInfo(T); 2320 2321 case llvm::Triple::ppc: 2322 if (os == llvm::Triple::Darwin) 2323 return new DarwinTargetInfo<PPCTargetInfo>(T); 2324 else if (os == llvm::Triple::FreeBSD) 2325 return new FreeBSDTargetInfo<PPC32TargetInfo>(T); 2326 return new PPC32TargetInfo(T); 2327 2328 case llvm::Triple::ppc64: 2329 if (os == llvm::Triple::Darwin) 2330 return new DarwinTargetInfo<PPC64TargetInfo>(T); 2331 else if (os == llvm::Triple::Lv2) 2332 return new PS3PPUTargetInfo<PPC64TargetInfo>(T); 2333 else if (os == llvm::Triple::FreeBSD) 2334 return new FreeBSDTargetInfo<PPC64TargetInfo>(T); 2335 return new PPC64TargetInfo(T); 2336 2337 case llvm::Triple::mblaze: 2338 return new MBlazeTargetInfo(T); 2339 2340 case llvm::Triple::sparc: 2341 if (os == llvm::Triple::AuroraUX) 2342 return new AuroraUXSparcV8TargetInfo(T); 2343 if (os == llvm::Triple::Solaris) 2344 return new SolarisSparcV8TargetInfo(T); 2345 return new SparcV8TargetInfo(T); 2346 2347 // FIXME: Need a real SPU target. 2348 case llvm::Triple::cellspu: 2349 return new PS3SPUTargetInfo<PPC64TargetInfo>(T); 2350 2351 case llvm::Triple::systemz: 2352 return new SystemZTargetInfo(T); 2353 2354 case llvm::Triple::tce: 2355 return new TCETargetInfo(T); 2356 2357 case llvm::Triple::x86: 2358 switch (os) { 2359 case llvm::Triple::AuroraUX: 2360 return new AuroraUXTargetInfo<X86_32TargetInfo>(T); 2361 case llvm::Triple::Darwin: 2362 return new DarwinI386TargetInfo(T); 2363 case llvm::Triple::Linux: 2364 return new LinuxTargetInfo<X86_32TargetInfo>(T); 2365 case llvm::Triple::DragonFly: 2366 return new DragonFlyBSDTargetInfo<X86_32TargetInfo>(T); 2367 case llvm::Triple::NetBSD: 2368 return new NetBSDTargetInfo<X86_32TargetInfo>(T); 2369 case llvm::Triple::OpenBSD: 2370 return new OpenBSDI386TargetInfo(T); 2371 case llvm::Triple::FreeBSD: 2372 return new FreeBSDTargetInfo<X86_32TargetInfo>(T); 2373 case llvm::Triple::Solaris: 2374 return new SolarisTargetInfo<X86_32TargetInfo>(T); 2375 case llvm::Triple::Cygwin: 2376 return new CygwinX86_32TargetInfo(T); 2377 case llvm::Triple::MinGW32: 2378 return new MinGWX86_32TargetInfo(T); 2379 case llvm::Triple::Win32: 2380 return new VisualStudioWindowsX86_32TargetInfo(T); 2381 case llvm::Triple::Haiku: 2382 return new HaikuX86_32TargetInfo(T); 2383 default: 2384 return new X86_32TargetInfo(T); 2385 } 2386 2387 case llvm::Triple::x86_64: 2388 switch (os) { 2389 case llvm::Triple::AuroraUX: 2390 return new AuroraUXTargetInfo<X86_64TargetInfo>(T); 2391 case llvm::Triple::Darwin: 2392 return new DarwinX86_64TargetInfo(T); 2393 case llvm::Triple::Linux: 2394 return new LinuxTargetInfo<X86_64TargetInfo>(T); 2395 case llvm::Triple::DragonFly: 2396 return new DragonFlyBSDTargetInfo<X86_64TargetInfo>(T); 2397 case llvm::Triple::NetBSD: 2398 return new NetBSDTargetInfo<X86_64TargetInfo>(T); 2399 case llvm::Triple::OpenBSD: 2400 return new OpenBSDX86_64TargetInfo(T); 2401 case llvm::Triple::FreeBSD: 2402 return new FreeBSDTargetInfo<X86_64TargetInfo>(T); 2403 case llvm::Triple::Solaris: 2404 return new SolarisTargetInfo<X86_64TargetInfo>(T); 2405 case llvm::Triple::MinGW64: 2406 return new MinGWX86_64TargetInfo(T); 2407 case llvm::Triple::Win32: // This is what Triple.h supports now. 2408 return new VisualStudioWindowsX86_64TargetInfo(T); 2409 default: 2410 return new X86_64TargetInfo(T); 2411 } 2412 } 2413} 2414 2415/// CreateTargetInfo - Return the target info object for the specified target 2416/// triple. 2417TargetInfo *TargetInfo::CreateTargetInfo(Diagnostic &Diags, 2418 TargetOptions &Opts) { 2419 llvm::Triple Triple(Opts.Triple); 2420 2421 // Construct the target 2422 llvm::OwningPtr<TargetInfo> Target(AllocateTarget(Triple.str())); 2423 if (!Target) { 2424 Diags.Report(diag::err_target_unknown_triple) << Triple.str(); 2425 return 0; 2426 } 2427 2428 // Set the target CPU if specified. 2429 if (!Opts.CPU.empty() && !Target->setCPU(Opts.CPU)) { 2430 Diags.Report(diag::err_target_unknown_cpu) << Opts.CPU; 2431 return 0; 2432 } 2433 2434 // Set the target ABI if specified. 2435 if (!Opts.ABI.empty() && !Target->setABI(Opts.ABI)) { 2436 Diags.Report(diag::err_target_unknown_abi) << Opts.ABI; 2437 return 0; 2438 } 2439 2440 // Compute the default target features, we need the target to handle this 2441 // because features may have dependencies on one another. 2442 llvm::StringMap<bool> Features; 2443 Target->getDefaultFeatures(Opts.CPU, Features); 2444 2445 // Apply the user specified deltas. 2446 for (std::vector<std::string>::const_iterator it = Opts.Features.begin(), 2447 ie = Opts.Features.end(); it != ie; ++it) { 2448 const char *Name = it->c_str(); 2449 2450 // Apply the feature via the target. 2451 if ((Name[0] != '-' && Name[0] != '+') || 2452 !Target->setFeatureEnabled(Features, Name + 1, (Name[0] == '+'))) { 2453 Diags.Report(diag::err_target_invalid_feature) << Name; 2454 return 0; 2455 } 2456 } 2457 2458 // Add the features to the compile options. 2459 // 2460 // FIXME: If we are completely confident that we have the right set, we only 2461 // need to pass the minuses. 2462 Opts.Features.clear(); 2463 for (llvm::StringMap<bool>::const_iterator it = Features.begin(), 2464 ie = Features.end(); it != ie; ++it) 2465 Opts.Features.push_back(std::string(it->second ? "+" : "-") + it->first()); 2466 Target->HandleTargetFeatures(Opts.Features); 2467 2468 return Target.take(); 2469} 2470