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