Targets.cpp revision 4da7a1673aac9afa26f409fd9834a229c9436afc
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/Builtins.h" 16#include "clang/Basic/TargetBuiltins.h" 17#include "clang/Basic/TargetInfo.h" 18#include "clang/Basic/LangOptions.h" 19#include "llvm/ADT/APFloat.h" 20#include "llvm/ADT/SmallString.h" 21#include "llvm/ADT/StringRef.h" 22#include "llvm/ADT/STLExtras.h" 23#include "llvm/ADT/Triple.h" 24#include "llvm/MC/MCSectionMachO.h" 25using namespace clang; 26 27//===----------------------------------------------------------------------===// 28// Common code shared among targets. 29//===----------------------------------------------------------------------===// 30 31static void Define(std::vector<char> &Buf, const llvm::StringRef &Macro, 32 const llvm::StringRef &Val = "1") { 33 const char *Def = "#define "; 34 Buf.insert(Buf.end(), Def, Def+strlen(Def)); 35 Buf.insert(Buf.end(), Macro.begin(), Macro.end()); 36 Buf.push_back(' '); 37 Buf.insert(Buf.end(), Val.begin(), Val.end()); 38 Buf.push_back('\n'); 39} 40 41/// DefineStd - Define a macro name and standard variants. For example if 42/// MacroName is "unix", then this will define "__unix", "__unix__", and "unix" 43/// when in GNU mode. 44static void DefineStd(std::vector<char> &Buf, const char *MacroName, 45 const LangOptions &Opts) { 46 assert(MacroName[0] != '_' && "Identifier should be in the user's namespace"); 47 48 // If in GNU mode (e.g. -std=gnu99 but not -std=c99) define the raw identifier 49 // in the user's namespace. 50 if (Opts.GNUMode) 51 Define(Buf, MacroName); 52 53 // Define __unix. 54 llvm::SmallString<20> TmpStr; 55 TmpStr = "__"; 56 TmpStr += MacroName; 57 Define(Buf, TmpStr.str()); 58 59 // Define __unix__. 60 TmpStr += "__"; 61 Define(Buf, TmpStr.str()); 62} 63 64//===----------------------------------------------------------------------===// 65// Defines specific to certain operating systems. 66//===----------------------------------------------------------------------===// 67 68namespace { 69template<typename TgtInfo> 70class OSTargetInfo : public TgtInfo { 71protected: 72 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 73 std::vector<char> &Defines) const=0; 74public: 75 OSTargetInfo(const std::string& triple) : TgtInfo(triple) {} 76 virtual void getTargetDefines(const LangOptions &Opts, 77 std::vector<char> &Defines) const { 78 TgtInfo::getTargetDefines(Opts, Defines); 79 getOSDefines(Opts, TgtInfo::getTriple(), Defines); 80 } 81 82}; 83} // end anonymous namespace 84 85 86static void getDarwinDefines(std::vector<char> &Defs, const LangOptions &Opts) { 87 Define(Defs, "__APPLE_CC__", "5621"); 88 Define(Defs, "__APPLE__"); 89 Define(Defs, "__MACH__"); 90 Define(Defs, "OBJC_NEW_PROPERTIES"); 91 92 // __weak is always defined, for use in blocks and with objc pointers. 93 Define(Defs, "__weak", "__attribute__((objc_gc(weak)))"); 94 95 // Darwin defines __strong even in C mode (just to nothing). 96 if (!Opts.ObjC1 || Opts.getGCMode() == LangOptions::NonGC) 97 Define(Defs, "__strong", ""); 98 else 99 Define(Defs, "__strong", "__attribute__((objc_gc(strong)))"); 100 101 if (Opts.Static) 102 Define(Defs, "__STATIC__"); 103 else 104 Define(Defs, "__DYNAMIC__"); 105 106 if (Opts.POSIXThreads) 107 Define(Defs, "_REENTRANT", "1"); 108} 109 110static void getDarwinOSXDefines(std::vector<char> &Defs, 111 const llvm::Triple &Triple) { 112 if (Triple.getOS() != llvm::Triple::Darwin) 113 return; 114 115 // Figure out which "darwin number" the target triple is. "darwin9" -> 10.5. 116 unsigned Maj, Min, Rev; 117 Triple.getDarwinNumber(Maj, Min, Rev); 118 119 char MacOSXStr[] = "1000"; 120 if (Maj >= 4 && Maj <= 13) { // 10.0-10.9 121 // darwin7 -> 1030, darwin8 -> 1040, darwin9 -> 1050, etc. 122 MacOSXStr[2] = '0' + Maj-4; 123 } 124 125 // Handle minor version: 10.4.9 -> darwin8.9 -> "1049" 126 // Cap 10.4.11 -> darwin8.11 -> "1049" 127 MacOSXStr[3] = std::min(Min, 9U)+'0'; 128 Define(Defs, "__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", MacOSXStr); 129} 130 131static void getDarwinIPhoneOSDefines(std::vector<char> &Defs, 132 const llvm::Triple &Triple) { 133 if (Triple.getOS() != llvm::Triple::Darwin) 134 return; 135 136 // Figure out which "darwin number" the target triple is. "darwin9" -> 10.5. 137 unsigned Maj, Min, Rev; 138 Triple.getDarwinNumber(Maj, Min, Rev); 139 140 // When targetting iPhone OS, interpret the minor version and 141 // revision as the iPhone OS version 142 char iPhoneOSStr[] = "10000"; 143 if (Min >= 2 && Min <= 9) { // iPhone OS 2.0-9.0 144 // darwin9.2.0 -> 20000, darwin9.3.0 -> 30000, etc. 145 iPhoneOSStr[0] = '0' + Min; 146 } 147 148 // Handle minor version: 2.2 -> darwin9.2.2 -> 20200 149 iPhoneOSStr[2] = std::min(Rev, 9U)+'0'; 150 Define(Defs, "__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__", 151 iPhoneOSStr); 152} 153 154/// GetDarwinLanguageOptions - Set the default language options for darwin. 155static void GetDarwinLanguageOptions(LangOptions &Opts, 156 const llvm::Triple &Triple) { 157 Opts.NeXTRuntime = true; 158 159 if (Triple.getOS() != llvm::Triple::Darwin) 160 return; 161 162 unsigned MajorVersion = Triple.getDarwinMajorNumber(); 163 164 // Blocks and stack protectors default to on for 10.6 (darwin10) and beyond. 165 if (MajorVersion > 9) { 166 Opts.Blocks = 1; 167 Opts.setStackProtectorMode(LangOptions::SSPOn); 168 } 169 170 // Non-fragile ABI (in 64-bit mode) default to on for 10.5 (darwin9) and 171 // beyond. 172 if (MajorVersion >= 9 && Opts.ObjC1 && 173 Triple.getArch() == llvm::Triple::x86_64) 174 Opts.ObjCNonFragileABI = 1; 175} 176 177namespace { 178template<typename Target> 179class DarwinTargetInfo : public OSTargetInfo<Target> { 180protected: 181 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 182 std::vector<char> &Defines) const { 183 getDarwinDefines(Defines, Opts); 184 getDarwinOSXDefines(Defines, Triple); 185 } 186 187 /// getDefaultLangOptions - Allow the target to specify default settings for 188 /// various language options. These may be overridden by command line 189 /// options. 190 virtual void getDefaultLangOptions(LangOptions &Opts) { 191 TargetInfo::getDefaultLangOptions(Opts); 192 GetDarwinLanguageOptions(Opts, TargetInfo::getTriple()); 193 } 194public: 195 DarwinTargetInfo(const std::string& triple) : 196 OSTargetInfo<Target>(triple) { 197 this->TLSSupported = false; 198 } 199 200 virtual const char *getUnicodeStringSymbolPrefix() const { 201 return "__utf16_string_"; 202 } 203 204 virtual const char *getUnicodeStringSection() const { 205 return "__TEXT,__ustring"; 206 } 207 208 virtual std::string isValidSectionSpecifier(const llvm::StringRef &SR) const { 209 // Let MCSectionMachO validate this. 210 llvm::StringRef Segment, Section; 211 unsigned TAA, StubSize; 212 return llvm::MCSectionMachO::ParseSectionSpecifier(SR, Segment, Section, 213 TAA, StubSize); 214 } 215}; 216 217 218// DragonFlyBSD Target 219template<typename Target> 220class DragonFlyBSDTargetInfo : public OSTargetInfo<Target> { 221protected: 222 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 223 std::vector<char> &Defs) const { 224 // DragonFly defines; list based off of gcc output 225 Define(Defs, "__DragonFly__"); 226 Define(Defs, "__DragonFly_cc_version", "100001"); 227 Define(Defs, "__ELF__"); 228 Define(Defs, "__KPRINTF_ATTRIBUTE__"); 229 Define(Defs, "__tune_i386__"); 230 DefineStd(Defs, "unix", Opts); 231 } 232public: 233 DragonFlyBSDTargetInfo(const std::string &triple) 234 : OSTargetInfo<Target>(triple) {} 235}; 236 237// FreeBSD Target 238template<typename Target> 239class FreeBSDTargetInfo : public OSTargetInfo<Target> { 240protected: 241 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 242 std::vector<char> &Defs) const { 243 // FreeBSD defines; list based off of gcc output 244 245 // FIXME: Move version number handling to llvm::Triple. 246 const char *FreeBSD = strstr(Triple.getTriple().c_str(), 247 "-freebsd"); 248 FreeBSD += strlen("-freebsd"); 249 char release[] = "X"; 250 release[0] = FreeBSD[0]; 251 char version[] = "X00001"; 252 version[0] = FreeBSD[0]; 253 254 Define(Defs, "__FreeBSD__", release); 255 Define(Defs, "__FreeBSD_cc_version", version); 256 Define(Defs, "__KPRINTF_ATTRIBUTE__"); 257 DefineStd(Defs, "unix", Opts); 258 Define(Defs, "__ELF__", "1"); 259 } 260public: 261 FreeBSDTargetInfo(const std::string &triple) 262 : OSTargetInfo<Target>(triple) { 263 this->UserLabelPrefix = ""; 264 } 265}; 266 267// Linux target 268template<typename Target> 269class LinuxTargetInfo : public OSTargetInfo<Target> { 270protected: 271 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 272 std::vector<char> &Defs) const { 273 // Linux defines; list based off of gcc output 274 DefineStd(Defs, "unix", Opts); 275 DefineStd(Defs, "linux", Opts); 276 Define(Defs, "__gnu_linux__"); 277 Define(Defs, "__ELF__", "1"); 278 if (Opts.POSIXThreads) 279 Define(Defs, "_REENTRANT", "1"); 280 } 281public: 282 LinuxTargetInfo(const std::string& triple) 283 : OSTargetInfo<Target>(triple) { 284 this->UserLabelPrefix = ""; 285 } 286}; 287 288// NetBSD Target 289template<typename Target> 290class NetBSDTargetInfo : public OSTargetInfo<Target> { 291protected: 292 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 293 std::vector<char> &Defs) const { 294 // NetBSD defines; list based off of gcc output 295 Define(Defs, "__NetBSD__", "1"); 296 Define(Defs, "__unix__", "1"); 297 Define(Defs, "__ELF__", "1"); 298 if (Opts.POSIXThreads) 299 Define(Defs, "_POSIX_THREADS", "1"); 300 } 301public: 302 NetBSDTargetInfo(const std::string &triple) 303 : OSTargetInfo<Target>(triple) { 304 this->UserLabelPrefix = ""; 305 } 306}; 307 308// OpenBSD Target 309template<typename Target> 310class OpenBSDTargetInfo : public OSTargetInfo<Target> { 311protected: 312 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 313 std::vector<char> &Defs) const { 314 // OpenBSD defines; list based off of gcc output 315 316 Define(Defs, "__OpenBSD__", "1"); 317 DefineStd(Defs, "unix", Opts); 318 Define(Defs, "__ELF__", "1"); 319 if (Opts.POSIXThreads) 320 Define(Defs, "_POSIX_THREADS", "1"); 321 } 322public: 323 OpenBSDTargetInfo(const std::string &triple) 324 : OSTargetInfo<Target>(triple) {} 325}; 326 327// Solaris target 328template<typename Target> 329class SolarisTargetInfo : public OSTargetInfo<Target> { 330protected: 331 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 332 std::vector<char> &Defs) const { 333 DefineStd(Defs, "sun", Opts); 334 DefineStd(Defs, "unix", Opts); 335 Define(Defs, "__ELF__"); 336 Define(Defs, "__svr4__"); 337 Define(Defs, "__SVR4"); 338 } 339public: 340 SolarisTargetInfo(const std::string& triple) 341 : OSTargetInfo<Target>(triple) { 342 this->UserLabelPrefix = ""; 343 this->WCharType = this->SignedLong; 344 // FIXME: WIntType should be SignedLong 345 } 346}; 347} // end anonymous namespace. 348 349//===----------------------------------------------------------------------===// 350// Specific target implementations. 351//===----------------------------------------------------------------------===// 352 353namespace { 354// PPC abstract base class 355class PPCTargetInfo : public TargetInfo { 356 static const Builtin::Info BuiltinInfo[]; 357 static const char * const GCCRegNames[]; 358 static const TargetInfo::GCCRegAlias GCCRegAliases[]; 359 360public: 361 PPCTargetInfo(const std::string& triple) : TargetInfo(triple) {} 362 363 virtual void getTargetBuiltins(const Builtin::Info *&Records, 364 unsigned &NumRecords) const { 365 Records = BuiltinInfo; 366 NumRecords = clang::PPC::LastTSBuiltin-Builtin::FirstTSBuiltin; 367 } 368 369 virtual void getTargetDefines(const LangOptions &Opts, 370 std::vector<char> &Defines) const; 371 372 virtual const char *getVAListDeclaration() const { 373 return "typedef char* __builtin_va_list;"; 374 // This is the right definition for ABI/V4: System V.4/eabi. 375 /*return "typedef struct __va_list_tag {" 376 " unsigned char gpr;" 377 " unsigned char fpr;" 378 " unsigned short reserved;" 379 " void* overflow_arg_area;" 380 " void* reg_save_area;" 381 "} __builtin_va_list[1];";*/ 382 } 383 virtual void getGCCRegNames(const char * const *&Names, 384 unsigned &NumNames) const; 385 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 386 unsigned &NumAliases) const; 387 virtual bool validateAsmConstraint(const char *&Name, 388 TargetInfo::ConstraintInfo &Info) const { 389 switch (*Name) { 390 default: return false; 391 case 'O': // Zero 392 return true; 393 case 'b': // Base register 394 case 'f': // Floating point register 395 Info.setAllowsRegister(); 396 return true; 397 } 398 } 399 virtual void getDefaultLangOptions(LangOptions &Opts) { 400 TargetInfo::getDefaultLangOptions(Opts); 401 Opts.CharIsSigned = false; 402 } 403 virtual const char *getClobbers() const { 404 return ""; 405 } 406}; 407 408const Builtin::Info PPCTargetInfo::BuiltinInfo[] = { 409#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false }, 410#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false }, 411#include "clang/Basic/BuiltinsPPC.def" 412}; 413 414 415/// PPCTargetInfo::getTargetDefines - Return a set of the PowerPC-specific 416/// #defines that are not tied to a specific subtarget. 417void PPCTargetInfo::getTargetDefines(const LangOptions &Opts, 418 std::vector<char> &Defs) const { 419 // Target identification. 420 Define(Defs, "__ppc__"); 421 Define(Defs, "_ARCH_PPC"); 422 Define(Defs, "__POWERPC__"); 423 if (PointerWidth == 64) { 424 Define(Defs, "_ARCH_PPC64"); 425 Define(Defs, "_LP64"); 426 Define(Defs, "__LP64__"); 427 Define(Defs, "__ppc64__"); 428 } else { 429 Define(Defs, "__ppc__"); 430 } 431 432 // Target properties. 433 Define(Defs, "_BIG_ENDIAN"); 434 Define(Defs, "__BIG_ENDIAN__"); 435 436 // Subtarget options. 437 Define(Defs, "__NATURAL_ALIGNMENT__"); 438 Define(Defs, "__REGISTER_PREFIX__", ""); 439 440 // FIXME: Should be controlled by command line option. 441 Define(Defs, "__LONG_DOUBLE_128__"); 442} 443 444 445const char * const PPCTargetInfo::GCCRegNames[] = { 446 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 447 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 448 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", 449 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", 450 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", 451 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", 452 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", 453 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", 454 "mq", "lr", "ctr", "ap", 455 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", 456 "xer", 457 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", 458 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", 459 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", 460 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", 461 "vrsave", "vscr", 462 "spe_acc", "spefscr", 463 "sfp" 464}; 465 466void PPCTargetInfo::getGCCRegNames(const char * const *&Names, 467 unsigned &NumNames) const { 468 Names = GCCRegNames; 469 NumNames = llvm::array_lengthof(GCCRegNames); 470} 471 472const TargetInfo::GCCRegAlias PPCTargetInfo::GCCRegAliases[] = { 473 // While some of these aliases do map to different registers 474 // they still share the same register name. 475 { { "0" }, "r0" }, 476 { { "1"}, "r1" }, 477 { { "2" }, "r2" }, 478 { { "3" }, "r3" }, 479 { { "4" }, "r4" }, 480 { { "5" }, "r5" }, 481 { { "6" }, "r6" }, 482 { { "7" }, "r7" }, 483 { { "8" }, "r8" }, 484 { { "9" }, "r9" }, 485 { { "10" }, "r10" }, 486 { { "11" }, "r11" }, 487 { { "12" }, "r12" }, 488 { { "13" }, "r13" }, 489 { { "14" }, "r14" }, 490 { { "15" }, "r15" }, 491 { { "16" }, "r16" }, 492 { { "17" }, "r17" }, 493 { { "18" }, "r18" }, 494 { { "19" }, "r19" }, 495 { { "20" }, "r20" }, 496 { { "21" }, "r21" }, 497 { { "22" }, "r22" }, 498 { { "23" }, "r23" }, 499 { { "24" }, "r24" }, 500 { { "25" }, "r25" }, 501 { { "26" }, "r26" }, 502 { { "27" }, "r27" }, 503 { { "28" }, "r28" }, 504 { { "29" }, "r29" }, 505 { { "30" }, "r30" }, 506 { { "31" }, "r31" }, 507 { { "fr0" }, "f0" }, 508 { { "fr1" }, "f1" }, 509 { { "fr2" }, "f2" }, 510 { { "fr3" }, "f3" }, 511 { { "fr4" }, "f4" }, 512 { { "fr5" }, "f5" }, 513 { { "fr6" }, "f6" }, 514 { { "fr7" }, "f7" }, 515 { { "fr8" }, "f8" }, 516 { { "fr9" }, "f9" }, 517 { { "fr10" }, "f10" }, 518 { { "fr11" }, "f11" }, 519 { { "fr12" }, "f12" }, 520 { { "fr13" }, "f13" }, 521 { { "fr14" }, "f14" }, 522 { { "fr15" }, "f15" }, 523 { { "fr16" }, "f16" }, 524 { { "fr17" }, "f17" }, 525 { { "fr18" }, "f18" }, 526 { { "fr19" }, "f19" }, 527 { { "fr20" }, "f20" }, 528 { { "fr21" }, "f21" }, 529 { { "fr22" }, "f22" }, 530 { { "fr23" }, "f23" }, 531 { { "fr24" }, "f24" }, 532 { { "fr25" }, "f25" }, 533 { { "fr26" }, "f26" }, 534 { { "fr27" }, "f27" }, 535 { { "fr28" }, "f28" }, 536 { { "fr29" }, "f29" }, 537 { { "fr30" }, "f30" }, 538 { { "fr31" }, "f31" }, 539 { { "cc" }, "cr0" }, 540}; 541 542void PPCTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, 543 unsigned &NumAliases) const { 544 Aliases = GCCRegAliases; 545 NumAliases = llvm::array_lengthof(GCCRegAliases); 546} 547} // end anonymous namespace. 548 549namespace { 550class PPC32TargetInfo : public PPCTargetInfo { 551public: 552 PPC32TargetInfo(const std::string& triple) : PPCTargetInfo(triple) { 553 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 554 "i64:64:64-f32:32:32-f64:64:64-v128:128:128"; 555 } 556}; 557} // end anonymous namespace. 558 559namespace { 560class PPC64TargetInfo : public PPCTargetInfo { 561public: 562 PPC64TargetInfo(const std::string& triple) : PPCTargetInfo(triple) { 563 LongWidth = LongAlign = PointerWidth = PointerAlign = 64; 564 IntMaxType = SignedLong; 565 UIntMaxType = UnsignedLong; 566 Int64Type = SignedLong; 567 DescriptionString = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 568 "i64:64:64-f32:32:32-f64:64:64-v128:128:128"; 569 } 570}; 571} // end anonymous namespace. 572 573namespace { 574// Namespace for x86 abstract base class 575const Builtin::Info BuiltinInfo[] = { 576#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false }, 577#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false }, 578#include "clang/Basic/BuiltinsX86.def" 579}; 580 581const char *GCCRegNames[] = { 582 "ax", "dx", "cx", "bx", "si", "di", "bp", "sp", 583 "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)", 584 "argp", "flags", "fspr", "dirflag", "frame", 585 "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7", 586 "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7", 587 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 588 "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15" 589}; 590 591const TargetInfo::GCCRegAlias GCCRegAliases[] = { 592 { { "al", "ah", "eax", "rax" }, "ax" }, 593 { { "bl", "bh", "ebx", "rbx" }, "bx" }, 594 { { "cl", "ch", "ecx", "rcx" }, "cx" }, 595 { { "dl", "dh", "edx", "rdx" }, "dx" }, 596 { { "esi", "rsi" }, "si" }, 597 { { "edi", "rdi" }, "di" }, 598 { { "esp", "rsp" }, "sp" }, 599 { { "ebp", "rbp" }, "bp" }, 600}; 601 602// X86 target abstract base class; x86-32 and x86-64 are very close, so 603// most of the implementation can be shared. 604class X86TargetInfo : public TargetInfo { 605 enum X86SSEEnum { 606 NoMMXSSE, MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42 607 } SSELevel; 608public: 609 X86TargetInfo(const std::string& triple) 610 : TargetInfo(triple), SSELevel(NoMMXSSE) { 611 LongDoubleFormat = &llvm::APFloat::x87DoubleExtended; 612 } 613 virtual void getTargetBuiltins(const Builtin::Info *&Records, 614 unsigned &NumRecords) const { 615 Records = BuiltinInfo; 616 NumRecords = clang::X86::LastTSBuiltin-Builtin::FirstTSBuiltin; 617 } 618 virtual void getGCCRegNames(const char * const *&Names, 619 unsigned &NumNames) const { 620 Names = GCCRegNames; 621 NumNames = llvm::array_lengthof(GCCRegNames); 622 } 623 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 624 unsigned &NumAliases) const { 625 Aliases = GCCRegAliases; 626 NumAliases = llvm::array_lengthof(GCCRegAliases); 627 } 628 virtual bool validateAsmConstraint(const char *&Name, 629 TargetInfo::ConstraintInfo &info) const; 630 virtual std::string convertConstraint(const char Constraint) const; 631 virtual const char *getClobbers() const { 632 return "~{dirflag},~{fpsr},~{flags}"; 633 } 634 virtual void getTargetDefines(const LangOptions &Opts, 635 std::vector<char> &Defines) const; 636 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features, 637 const std::string &Name, 638 bool Enabled) const; 639 virtual void getDefaultFeatures(const std::string &CPU, 640 llvm::StringMap<bool> &Features) const; 641 virtual void HandleTargetFeatures(const llvm::StringMap<bool> &Features); 642}; 643 644void X86TargetInfo::getDefaultFeatures(const std::string &CPU, 645 llvm::StringMap<bool> &Features) const { 646 // FIXME: This should not be here. 647 Features["3dnow"] = false; 648 Features["3dnowa"] = false; 649 Features["mmx"] = false; 650 Features["sse"] = false; 651 Features["sse2"] = false; 652 Features["sse3"] = false; 653 Features["ssse3"] = false; 654 Features["sse41"] = false; 655 Features["sse42"] = false; 656 657 // LLVM does not currently recognize this. 658 // Features["sse4a"] = false; 659 660 // FIXME: This *really* should not be here. 661 662 // X86_64 always has SSE2. 663 if (PointerWidth == 64) 664 Features["sse2"] = Features["sse"] = Features["mmx"] = true; 665 666 if (CPU == "generic" || CPU == "i386" || CPU == "i486" || CPU == "i586" || 667 CPU == "pentium" || CPU == "i686" || CPU == "pentiumpro") 668 ; 669 else if (CPU == "pentium-mmx" || CPU == "pentium2") 670 setFeatureEnabled(Features, "mmx", true); 671 else if (CPU == "pentium3") 672 setFeatureEnabled(Features, "sse", true); 673 else if (CPU == "pentium-m" || CPU == "pentium4" || CPU == "x86-64") 674 setFeatureEnabled(Features, "sse2", true); 675 else if (CPU == "yonah" || CPU == "prescott" || CPU == "nocona") 676 setFeatureEnabled(Features, "sse3", true); 677 else if (CPU == "core2") 678 setFeatureEnabled(Features, "ssse3", true); 679 else if (CPU == "penryn") { 680 setFeatureEnabled(Features, "sse4", true); 681 Features["sse42"] = false; 682 } else if (CPU == "atom") 683 setFeatureEnabled(Features, "sse3", true); 684 else if (CPU == "corei7") 685 setFeatureEnabled(Features, "sse4", true); 686 else if (CPU == "k6" || CPU == "winchip-c6") 687 setFeatureEnabled(Features, "mmx", true); 688 else if (CPU == "k6-2" || CPU == "k6-3" || CPU == "athlon" || 689 CPU == "athlon-tbird" || CPU == "winchip2" || CPU == "c3") { 690 setFeatureEnabled(Features, "mmx", true); 691 setFeatureEnabled(Features, "3dnow", true); 692 } else if (CPU == "athlon-4" || CPU == "athlon-xp" || CPU == "athlon-mp") { 693 setFeatureEnabled(Features, "sse", true); 694 setFeatureEnabled(Features, "3dnowa", true); 695 } else if (CPU == "k8" || CPU == "opteron" || CPU == "athlon64" || 696 CPU == "athlon-fx") { 697 setFeatureEnabled(Features, "sse2", true); 698 setFeatureEnabled(Features, "3dnowa", true); 699 } else if (CPU == "c3-2") 700 setFeatureEnabled(Features, "sse", true); 701} 702 703bool X86TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features, 704 const std::string &Name, 705 bool Enabled) const { 706 // FIXME: This *really* should not be here. 707 if (!Features.count(Name) && Name != "sse4") 708 return false; 709 710 if (Enabled) { 711 if (Name == "mmx") 712 Features["mmx"] = true; 713 else if (Name == "sse") 714 Features["mmx"] = Features["sse"] = true; 715 else if (Name == "sse2") 716 Features["mmx"] = Features["sse"] = Features["sse2"] = true; 717 else if (Name == "sse3") 718 Features["mmx"] = Features["sse"] = Features["sse2"] = 719 Features["sse3"] = true; 720 else if (Name == "ssse3") 721 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] = 722 Features["ssse3"] = true; 723 else if (Name == "sse4") 724 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] = 725 Features["ssse3"] = Features["sse41"] = Features["sse42"] = true; 726 else if (Name == "3dnow") 727 Features["3dnowa"] = true; 728 else if (Name == "3dnowa") 729 Features["3dnow"] = Features["3dnowa"] = true; 730 } else { 731 if (Name == "mmx") 732 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] = 733 Features["ssse3"] = Features["sse41"] = Features["sse42"] = false; 734 else if (Name == "sse") 735 Features["sse"] = Features["sse2"] = Features["sse3"] = 736 Features["ssse3"] = Features["sse41"] = Features["sse42"] = false; 737 else if (Name == "sse2") 738 Features["sse2"] = Features["sse3"] = Features["ssse3"] = 739 Features["sse41"] = Features["sse42"] = false; 740 else if (Name == "sse3") 741 Features["sse3"] = Features["ssse3"] = Features["sse41"] = 742 Features["sse42"] = false; 743 else if (Name == "ssse3") 744 Features["ssse3"] = Features["sse41"] = Features["sse42"] = false; 745 else if (Name == "sse4") 746 Features["sse41"] = Features["sse42"] = false; 747 else if (Name == "3dnow") 748 Features["3dnow"] = Features["3dnowa"] = false; 749 else if (Name == "3dnowa") 750 Features["3dnowa"] = false; 751 } 752 753 return true; 754} 755 756/// HandleTargetOptions - Perform initialization based on the user 757/// configured set of features. 758void X86TargetInfo::HandleTargetFeatures(const llvm::StringMap<bool>&Features) { 759 if (Features.lookup("sse42")) 760 SSELevel = SSE42; 761 else if (Features.lookup("sse41")) 762 SSELevel = SSE41; 763 else if (Features.lookup("ssse3")) 764 SSELevel = SSSE3; 765 else if (Features.lookup("sse3")) 766 SSELevel = SSE3; 767 else if (Features.lookup("sse2")) 768 SSELevel = SSE2; 769 else if (Features.lookup("sse")) 770 SSELevel = SSE1; 771 else if (Features.lookup("mmx")) 772 SSELevel = MMX; 773} 774 775/// X86TargetInfo::getTargetDefines - Return a set of the X86-specific #defines 776/// that are not tied to a specific subtarget. 777void X86TargetInfo::getTargetDefines(const LangOptions &Opts, 778 std::vector<char> &Defs) const { 779 // Target identification. 780 if (PointerWidth == 64) { 781 Define(Defs, "_LP64"); 782 Define(Defs, "__LP64__"); 783 Define(Defs, "__amd64__"); 784 Define(Defs, "__amd64"); 785 Define(Defs, "__x86_64"); 786 Define(Defs, "__x86_64__"); 787 } else { 788 DefineStd(Defs, "i386", Opts); 789 } 790 791 // Target properties. 792 Define(Defs, "__LITTLE_ENDIAN__"); 793 794 // Subtarget options. 795 Define(Defs, "__nocona"); 796 Define(Defs, "__nocona__"); 797 Define(Defs, "__tune_nocona__"); 798 Define(Defs, "__REGISTER_PREFIX__", ""); 799 800 // Define __NO_MATH_INLINES on linux/x86 so that we don't get inline 801 // functions in glibc header files that use FP Stack inline asm which the 802 // backend can't deal with (PR879). 803 Define(Defs, "__NO_MATH_INLINES"); 804 805 // Each case falls through to the previous one here. 806 switch (SSELevel) { 807 case SSE42: 808 Define(Defs, "__SSE4_2__"); 809 case SSE41: 810 Define(Defs, "__SSE4_1__"); 811 case SSSE3: 812 Define(Defs, "__SSSE3__"); 813 case SSE3: 814 Define(Defs, "__SSE3__"); 815 case SSE2: 816 Define(Defs, "__SSE2__"); 817 Define(Defs, "__SSE2_MATH__"); // -mfp-math=sse always implied. 818 case SSE1: 819 Define(Defs, "__SSE__"); 820 Define(Defs, "__SSE_MATH__"); // -mfp-math=sse always implied. 821 case MMX: 822 Define(Defs, "__MMX__"); 823 case NoMMXSSE: 824 break; 825 } 826} 827 828 829bool 830X86TargetInfo::validateAsmConstraint(const char *&Name, 831 TargetInfo::ConstraintInfo &Info) const { 832 switch (*Name) { 833 default: return false; 834 case 'a': // eax. 835 case 'b': // ebx. 836 case 'c': // ecx. 837 case 'd': // edx. 838 case 'S': // esi. 839 case 'D': // edi. 840 case 'A': // edx:eax. 841 case 't': // top of floating point stack. 842 case 'u': // second from top of floating point stack. 843 case 'q': // Any register accessible as [r]l: a, b, c, and d. 844 case 'y': // Any MMX register. 845 case 'x': // Any SSE register. 846 case 'Q': // Any register accessible as [r]h: a, b, c, and d. 847 case 'e': // 32-bit signed integer constant for use with zero-extending 848 // x86_64 instructions. 849 case 'Z': // 32-bit unsigned integer constant for use with zero-extending 850 // x86_64 instructions. 851 case 'N': // unsigned 8-bit integer constant for use with in and out 852 // instructions. 853 case 'R': // "legacy" registers: ax, bx, cx, dx, di, si, sp, bp. 854 Info.setAllowsRegister(); 855 return true; 856 } 857} 858 859std::string 860X86TargetInfo::convertConstraint(const char Constraint) const { 861 switch (Constraint) { 862 case 'a': return std::string("{ax}"); 863 case 'b': return std::string("{bx}"); 864 case 'c': return std::string("{cx}"); 865 case 'd': return std::string("{dx}"); 866 case 'S': return std::string("{si}"); 867 case 'D': return std::string("{di}"); 868 case 't': // top of floating point stack. 869 return std::string("{st}"); 870 case 'u': // second from top of floating point stack. 871 return std::string("{st(1)}"); // second from top of floating point stack. 872 default: 873 return std::string(1, Constraint); 874 } 875} 876} // end anonymous namespace 877 878namespace { 879// X86-32 generic target 880class X86_32TargetInfo : public X86TargetInfo { 881public: 882 X86_32TargetInfo(const std::string& triple) : X86TargetInfo(triple) { 883 DoubleAlign = LongLongAlign = 32; 884 LongDoubleWidth = 96; 885 LongDoubleAlign = 32; 886 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 887 "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-" 888 "a0:0:64-f80:32:32"; 889 SizeType = UnsignedInt; 890 PtrDiffType = SignedInt; 891 IntPtrType = SignedInt; 892 RegParmMax = 3; 893 } 894 virtual const char *getVAListDeclaration() const { 895 return "typedef char* __builtin_va_list;"; 896 } 897 898 int getEHDataRegisterNumber(unsigned RegNo) const { 899 if (RegNo == 0) return 0; 900 if (RegNo == 1) return 2; 901 return -1; 902 } 903}; 904} // end anonymous namespace 905 906namespace { 907class OpenBSDI386TargetInfo : public OpenBSDTargetInfo<X86_32TargetInfo> { 908public: 909 OpenBSDI386TargetInfo(const std::string& triple) : 910 OpenBSDTargetInfo<X86_32TargetInfo>(triple) { 911 SizeType = UnsignedLong; 912 IntPtrType = SignedLong; 913 PtrDiffType = SignedLong; 914 } 915}; 916} // end anonymous namespace 917 918namespace { 919class DarwinI386TargetInfo : public DarwinTargetInfo<X86_32TargetInfo> { 920public: 921 DarwinI386TargetInfo(const std::string& triple) : 922 DarwinTargetInfo<X86_32TargetInfo>(triple) { 923 LongDoubleWidth = 128; 924 LongDoubleAlign = 128; 925 SizeType = UnsignedLong; 926 IntPtrType = SignedLong; 927 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 928 "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-" 929 "a0:0:64-f80:128:128"; 930 } 931 932}; 933} // end anonymous namespace 934 935namespace { 936// x86-32 Windows target 937class WindowsX86_32TargetInfo : public X86_32TargetInfo { 938public: 939 WindowsX86_32TargetInfo(const std::string& triple) 940 : X86_32TargetInfo(triple) { 941 TLSSupported = false; 942 WCharType = UnsignedShort; 943 WCharWidth = WCharAlign = 16; 944 DoubleAlign = LongLongAlign = 64; 945 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 946 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-" 947 "a0:0:64-f80:32:32"; 948 } 949 virtual void getTargetDefines(const LangOptions &Opts, 950 std::vector<char> &Defines) const { 951 X86_32TargetInfo::getTargetDefines(Opts, Defines); 952 // This list is based off of the the list of things MingW defines 953 Define(Defines, "_WIN32"); 954 DefineStd(Defines, "WIN32", Opts); 955 DefineStd(Defines, "WINNT", Opts); 956 Define(Defines, "_X86_"); 957 } 958}; 959} // end anonymous namespace 960 961namespace { 962 963/// GetWindowsVisualStudioLanguageOptions - Set the default language options for Windows. 964static void GetWindowsVisualStudioLanguageOptions(LangOptions &Opts) { 965 Opts.Microsoft = true; 966} 967 968// x86-32 Windows Visual Studio target 969class VisualStudioWindowsX86_32TargetInfo : public WindowsX86_32TargetInfo { 970public: 971 VisualStudioWindowsX86_32TargetInfo(const std::string& triple) 972 : WindowsX86_32TargetInfo(triple) { 973 } 974 virtual void getTargetDefines(const LangOptions &Opts, 975 std::vector<char> &Defines) const { 976 WindowsX86_32TargetInfo::getTargetDefines(Opts, Defines); 977 // The value of the following reflects processor type. 978 // 300=386, 400=486, 500=Pentium, 600=Blend (default) 979 // We lost the original triple, so we use the default. 980 Define(Defines, "_M_IX86", "600"); 981 } 982 virtual void getDefaultLangOptions(LangOptions &Opts) { 983 WindowsX86_32TargetInfo::getDefaultLangOptions(Opts); 984 GetWindowsVisualStudioLanguageOptions(Opts); 985 } 986}; 987} // end anonymous namespace 988 989namespace { 990// x86-32 MinGW target 991class MinGWX86_32TargetInfo : public WindowsX86_32TargetInfo { 992public: 993 MinGWX86_32TargetInfo(const std::string& triple) 994 : WindowsX86_32TargetInfo(triple) { 995 } 996 virtual void getTargetDefines(const LangOptions &Opts, 997 std::vector<char> &Defines) const { 998 WindowsX86_32TargetInfo::getTargetDefines(Opts, Defines); 999 Define(Defines, "__MSVCRT__"); 1000 Define(Defines, "__MINGW32__"); 1001 Define(Defines, "__declspec", "__declspec"); 1002 } 1003}; 1004} // end anonymous namespace 1005 1006namespace { 1007// x86-32 Cygwin target 1008class CygwinX86_32TargetInfo : public X86_32TargetInfo { 1009public: 1010 CygwinX86_32TargetInfo(const std::string& triple) 1011 : X86_32TargetInfo(triple) { 1012 TLSSupported = false; 1013 WCharType = UnsignedShort; 1014 WCharWidth = WCharAlign = 16; 1015 DoubleAlign = LongLongAlign = 64; 1016 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 1017 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-" 1018 "a0:0:64-f80:32:32"; 1019 } 1020 virtual void getTargetDefines(const LangOptions &Opts, 1021 std::vector<char> &Defines) const { 1022 X86_32TargetInfo::getTargetDefines(Opts, Defines); 1023 Define(Defines, "__CYGWIN__"); 1024 Define(Defines, "__CYGWIN32__"); 1025 DefineStd(Defines, "unix", Opts); 1026 } 1027}; 1028} // end anonymous namespace 1029 1030namespace { 1031// x86-64 generic target 1032class X86_64TargetInfo : public X86TargetInfo { 1033public: 1034 X86_64TargetInfo(const std::string &triple) : X86TargetInfo(triple) { 1035 LongWidth = LongAlign = PointerWidth = PointerAlign = 64; 1036 LongDoubleWidth = 128; 1037 LongDoubleAlign = 128; 1038 IntMaxType = SignedLong; 1039 UIntMaxType = UnsignedLong; 1040 Int64Type = SignedLong; 1041 RegParmMax = 6; 1042 1043 DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 1044 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-" 1045 "a0:0:64-s0:64:64-f80:128:128"; 1046 } 1047 virtual const char *getVAListDeclaration() const { 1048 return "typedef struct __va_list_tag {" 1049 " unsigned gp_offset;" 1050 " unsigned fp_offset;" 1051 " void* overflow_arg_area;" 1052 " void* reg_save_area;" 1053 "} __va_list_tag;" 1054 "typedef __va_list_tag __builtin_va_list[1];"; 1055 } 1056 1057 int getEHDataRegisterNumber(unsigned RegNo) const { 1058 if (RegNo == 0) return 0; 1059 if (RegNo == 1) return 1; 1060 return -1; 1061 } 1062}; 1063} // end anonymous namespace 1064 1065namespace { 1066// x86-64 Windows target 1067class WindowsX86_64TargetInfo : public X86_64TargetInfo { 1068public: 1069 WindowsX86_64TargetInfo(const std::string& triple) 1070 : X86_64TargetInfo(triple) { 1071 TLSSupported = false; 1072 WCharType = UnsignedShort; 1073 WCharWidth = WCharAlign = 16; 1074 LongWidth = LongAlign = 32; 1075 DoubleAlign = LongLongAlign = 64; 1076 } 1077 virtual void getTargetDefines(const LangOptions &Opts, 1078 std::vector<char> &Defines) const { 1079 X86_64TargetInfo::getTargetDefines(Opts, Defines); 1080 Define(Defines, "_WIN64"); 1081 DefineStd(Defines, "WIN64", Opts); 1082 } 1083}; 1084} // end anonymous namespace 1085 1086namespace { 1087// x86-64 Windows Visual Studio target 1088class VisualStudioWindowsX86_64TargetInfo : public WindowsX86_64TargetInfo { 1089public: 1090 VisualStudioWindowsX86_64TargetInfo(const std::string& triple) 1091 : WindowsX86_64TargetInfo(triple) { 1092 } 1093 virtual void getTargetDefines(const LangOptions &Opts, 1094 std::vector<char> &Defines) const { 1095 WindowsX86_64TargetInfo::getTargetDefines(Opts, Defines); 1096 Define(Defines, "_M_X64"); 1097 } 1098 virtual const char *getVAListDeclaration() const { 1099 return "typedef char* va_list;"; 1100 } 1101}; 1102} // end anonymous namespace 1103 1104namespace { 1105// x86-64 MinGW target 1106class MinGWX86_64TargetInfo : public WindowsX86_64TargetInfo { 1107public: 1108 MinGWX86_64TargetInfo(const std::string& triple) 1109 : WindowsX86_64TargetInfo(triple) { 1110 } 1111 virtual void getTargetDefines(const LangOptions &Opts, 1112 std::vector<char> &Defines) const { 1113 WindowsX86_64TargetInfo::getTargetDefines(Opts, Defines); 1114 Define(Defines, "__MSVCRT__"); 1115 Define(Defines, "__MINGW64__"); 1116 Define(Defines, "__declspec"); 1117 } 1118}; 1119} // end anonymous namespace 1120 1121namespace { 1122class DarwinX86_64TargetInfo : public DarwinTargetInfo<X86_64TargetInfo> { 1123public: 1124 DarwinX86_64TargetInfo(const std::string& triple) 1125 : DarwinTargetInfo<X86_64TargetInfo>(triple) { 1126 Int64Type = SignedLongLong; 1127 } 1128}; 1129} // end anonymous namespace 1130 1131namespace { 1132class OpenBSDX86_64TargetInfo : public OpenBSDTargetInfo<X86_64TargetInfo> { 1133public: 1134 OpenBSDX86_64TargetInfo(const std::string& triple) 1135 : OpenBSDTargetInfo<X86_64TargetInfo>(triple) { 1136 IntMaxType = SignedLongLong; 1137 UIntMaxType = UnsignedLongLong; 1138 Int64Type = SignedLongLong; 1139 } 1140}; 1141} // end anonymous namespace 1142 1143namespace { 1144class ARMTargetInfo : public TargetInfo { 1145 enum { 1146 Armv4t, 1147 Armv5, 1148 Armv6, 1149 Armv7a, 1150 XScale 1151 } ArmArch; 1152 1153 static const TargetInfo::GCCRegAlias GCCRegAliases[]; 1154 static const char * const GCCRegNames[]; 1155 1156 std::string ABI; 1157 bool IsThumb; 1158 1159public: 1160 ARMTargetInfo(const std::string &TripleStr) 1161 : TargetInfo(TripleStr), ABI("aapcs-linux"), IsThumb(false) 1162 { 1163 llvm::Triple Triple(TripleStr); 1164 1165 SizeType = UnsignedInt; 1166 PtrDiffType = SignedInt; 1167 1168 // FIXME: This shouldn't be done this way, we should use features to 1169 // indicate the arch. See lib/Driver/Tools.cpp. 1170 llvm::StringRef Version(""), Arch = Triple.getArchName(); 1171 if (Arch.startswith("arm")) 1172 Version = Arch.substr(3); 1173 else if (Arch.startswith("thumb")) 1174 Version = Arch.substr(5); 1175 if (Version == "v7") 1176 ArmArch = Armv7a; 1177 else if (Version.empty() || Version == "v6" || Version == "v6t2") 1178 ArmArch = Armv6; 1179 else if (Version == "v5") 1180 ArmArch = Armv5; 1181 else if (Version == "v4t") 1182 ArmArch = Armv4t; 1183 else if (Arch == "xscale" || Arch == "thumbv5e") 1184 ArmArch = XScale; 1185 else 1186 ArmArch = Armv6; 1187 1188 if (Arch.startswith("thumb")) 1189 IsThumb = true; 1190 1191 if (IsThumb) { 1192 DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-" 1193 "i64:64:64-f32:32:32-f64:64:64-" 1194 "v64:64:64-v128:128:128-a0:0:32"); 1195 } else { 1196 DescriptionString = ("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 1197 "i64:64:64-f32:32:32-f64:64:64-" 1198 "v64:64:64-v128:128:128-a0:0:64"); 1199 } 1200 } 1201 virtual const char *getABI() const { return ABI.c_str(); } 1202 virtual bool setABI(const std::string &Name) { 1203 ABI = Name; 1204 1205 // The defaults (above) are for AAPCS, check if we need to change them. 1206 // 1207 // FIXME: We need support for -meabi... we could just mangle it into the 1208 // name. 1209 if (Name == "apcs-gnu") { 1210 DoubleAlign = LongLongAlign = 32; 1211 SizeType = UnsignedLong; 1212 1213 if (IsThumb) { 1214 DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-" 1215 "i64:32:32-f32:32:32-f64:32:32-" 1216 "v64:64:64-v128:128:128-a0:0:32"); 1217 } else { 1218 DescriptionString = ("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 1219 "i64:32:32-f32:32:32-f64:32:32-" 1220 "v64:64:64-v128:128:128-a0:0:64"); 1221 } 1222 1223 // FIXME: Override "preferred align" for double and long long. 1224 } else if (Name == "aapcs") { 1225 // FIXME: Enumerated types are variable width in straight AAPCS. 1226 } else if (Name == "aapcs-linux") { 1227 ; 1228 } else 1229 return false; 1230 1231 return true; 1232 } 1233 virtual void getTargetDefines(const LangOptions &Opts, 1234 std::vector<char> &Defs) const { 1235 // Target identification. 1236 Define(Defs, "__arm"); 1237 Define(Defs, "__arm__"); 1238 1239 // Target properties. 1240 Define(Defs, "__LITTLE_ENDIAN__"); 1241 1242 // Subtarget options. 1243 // 1244 // FIXME: Neither THUMB_INTERWORK nor SOFTFP is not being set correctly 1245 // here. 1246 if (ArmArch == Armv7a) { 1247 Define(Defs, "__ARM_ARCH_7A__"); 1248 Define(Defs, "__THUMB_INTERWORK__"); 1249 } else if (ArmArch == Armv6) { 1250 Define(Defs, "__ARM_ARCH_6K__"); 1251 Define(Defs, "__THUMB_INTERWORK__"); 1252 } else if (ArmArch == Armv5) { 1253 Define(Defs, "__ARM_ARCH_5TEJ__"); 1254 Define(Defs, "__THUMB_INTERWORK__"); 1255 Define(Defs, "__SOFTFP__"); 1256 } else if (ArmArch == Armv4t) { 1257 Define(Defs, "__ARM_ARCH_4T__"); 1258 Define(Defs, "__SOFTFP__"); 1259 } else if (ArmArch == XScale) { 1260 Define(Defs, "__ARM_ARCH_5TE__"); 1261 Define(Defs, "__XSCALE__"); 1262 Define(Defs, "__SOFTFP__"); 1263 } 1264 1265 Define(Defs, "__ARMEL__"); 1266 1267 if (IsThumb) { 1268 Define(Defs, "__THUMBEL__"); 1269 Define(Defs, "__thumb__"); 1270 if (ArmArch == Armv7a) 1271 Define(Defs, "__thumb2__"); 1272 } 1273 1274 // Note, this is always on in gcc, even though it doesn't make sense. 1275 Define(Defs, "__APCS_32__"); 1276 // FIXME: This should be conditional on VFP instruction support. 1277 Define(Defs, "__VFP_FP__"); 1278 1279 Define(Defs, "__USING_SJLJ_EXCEPTIONS__"); 1280 } 1281 virtual void getTargetBuiltins(const Builtin::Info *&Records, 1282 unsigned &NumRecords) const { 1283 // FIXME: Implement. 1284 Records = 0; 1285 NumRecords = 0; 1286 } 1287 virtual const char *getVAListDeclaration() const { 1288 return "typedef char* __builtin_va_list;"; 1289 } 1290 virtual void getGCCRegNames(const char * const *&Names, 1291 unsigned &NumNames) const; 1292 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 1293 unsigned &NumAliases) const; 1294 virtual bool validateAsmConstraint(const char *&Name, 1295 TargetInfo::ConstraintInfo &Info) const { 1296 // FIXME: Check if this is complete 1297 switch (*Name) { 1298 default: 1299 case 'l': // r0-r7 1300 case 'h': // r8-r15 1301 case 'w': // VFP Floating point register single precision 1302 case 'P': // VFP Floating point register double precision 1303 Info.setAllowsRegister(); 1304 return true; 1305 } 1306 return false; 1307 } 1308 virtual const char *getClobbers() const { 1309 // FIXME: Is this really right? 1310 return ""; 1311 } 1312}; 1313 1314const char * const ARMTargetInfo::GCCRegNames[] = { 1315 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 1316 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" 1317}; 1318 1319void ARMTargetInfo::getGCCRegNames(const char * const *&Names, 1320 unsigned &NumNames) const { 1321 Names = GCCRegNames; 1322 NumNames = llvm::array_lengthof(GCCRegNames); 1323} 1324 1325const TargetInfo::GCCRegAlias ARMTargetInfo::GCCRegAliases[] = { 1326 1327 { { "a1" }, "r0" }, 1328 { { "a2" }, "r1" }, 1329 { { "a3" }, "r2" }, 1330 { { "a4" }, "r3" }, 1331 { { "v1" }, "r4" }, 1332 { { "v2" }, "r5" }, 1333 { { "v3" }, "r6" }, 1334 { { "v4" }, "r7" }, 1335 { { "v5" }, "r8" }, 1336 { { "v6", "rfp" }, "r9" }, 1337 { { "sl" }, "r10" }, 1338 { { "fp" }, "r11" }, 1339 { { "ip" }, "r12" }, 1340 { { "sp" }, "r13" }, 1341 { { "lr" }, "r14" }, 1342 { { "pc" }, "r15" }, 1343}; 1344 1345void ARMTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, 1346 unsigned &NumAliases) const { 1347 Aliases = GCCRegAliases; 1348 NumAliases = llvm::array_lengthof(GCCRegAliases); 1349} 1350} // end anonymous namespace. 1351 1352 1353namespace { 1354class DarwinARMTargetInfo : 1355 public DarwinTargetInfo<ARMTargetInfo> { 1356protected: 1357 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 1358 std::vector<char> &Defines) const { 1359 getDarwinDefines(Defines, Opts); 1360 getDarwinIPhoneOSDefines(Defines, Triple); 1361 } 1362 1363public: 1364 DarwinARMTargetInfo(const std::string& triple) 1365 : DarwinTargetInfo<ARMTargetInfo>(triple) {} 1366}; 1367} // end anonymous namespace. 1368 1369namespace { 1370class SparcV8TargetInfo : public TargetInfo { 1371 static const TargetInfo::GCCRegAlias GCCRegAliases[]; 1372 static const char * const GCCRegNames[]; 1373public: 1374 SparcV8TargetInfo(const std::string& triple) : TargetInfo(triple) { 1375 // FIXME: Support Sparc quad-precision long double? 1376 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 1377 "i64:64:64-f32:32:32-f64:64:64-v64:64:64"; 1378 } 1379 virtual void getTargetDefines(const LangOptions &Opts, 1380 std::vector<char> &Defines) const { 1381 DefineStd(Defines, "sparc", Opts); 1382 Define(Defines, "__sparcv8"); 1383 Define(Defines, "__REGISTER_PREFIX__", ""); 1384 } 1385 virtual void getTargetBuiltins(const Builtin::Info *&Records, 1386 unsigned &NumRecords) const { 1387 // FIXME: Implement! 1388 } 1389 virtual const char *getVAListDeclaration() const { 1390 return "typedef void* __builtin_va_list;"; 1391 } 1392 virtual void getGCCRegNames(const char * const *&Names, 1393 unsigned &NumNames) const; 1394 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 1395 unsigned &NumAliases) const; 1396 virtual bool validateAsmConstraint(const char *&Name, 1397 TargetInfo::ConstraintInfo &info) const { 1398 // FIXME: Implement! 1399 return false; 1400 } 1401 virtual const char *getClobbers() const { 1402 // FIXME: Implement! 1403 return ""; 1404 } 1405}; 1406 1407const char * const SparcV8TargetInfo::GCCRegNames[] = { 1408 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 1409 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 1410 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", 1411 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" 1412}; 1413 1414void SparcV8TargetInfo::getGCCRegNames(const char * const *&Names, 1415 unsigned &NumNames) const { 1416 Names = GCCRegNames; 1417 NumNames = llvm::array_lengthof(GCCRegNames); 1418} 1419 1420const TargetInfo::GCCRegAlias SparcV8TargetInfo::GCCRegAliases[] = { 1421 { { "g0" }, "r0" }, 1422 { { "g1" }, "r1" }, 1423 { { "g2" }, "r2" }, 1424 { { "g3" }, "r3" }, 1425 { { "g4" }, "r4" }, 1426 { { "g5" }, "r5" }, 1427 { { "g6" }, "r6" }, 1428 { { "g7" }, "r7" }, 1429 { { "o0" }, "r8" }, 1430 { { "o1" }, "r9" }, 1431 { { "o2" }, "r10" }, 1432 { { "o3" }, "r11" }, 1433 { { "o4" }, "r12" }, 1434 { { "o5" }, "r13" }, 1435 { { "o6", "sp" }, "r14" }, 1436 { { "o7" }, "r15" }, 1437 { { "l0" }, "r16" }, 1438 { { "l1" }, "r17" }, 1439 { { "l2" }, "r18" }, 1440 { { "l3" }, "r19" }, 1441 { { "l4" }, "r20" }, 1442 { { "l5" }, "r21" }, 1443 { { "l6" }, "r22" }, 1444 { { "l7" }, "r23" }, 1445 { { "i0" }, "r24" }, 1446 { { "i1" }, "r25" }, 1447 { { "i2" }, "r26" }, 1448 { { "i3" }, "r27" }, 1449 { { "i4" }, "r28" }, 1450 { { "i5" }, "r29" }, 1451 { { "i6", "fp" }, "r30" }, 1452 { { "i7" }, "r31" }, 1453}; 1454 1455void SparcV8TargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, 1456 unsigned &NumAliases) const { 1457 Aliases = GCCRegAliases; 1458 NumAliases = llvm::array_lengthof(GCCRegAliases); 1459} 1460} // end anonymous namespace. 1461 1462namespace { 1463class SolarisSparcV8TargetInfo : public SolarisTargetInfo<SparcV8TargetInfo> { 1464public: 1465 SolarisSparcV8TargetInfo(const std::string& triple) : 1466 SolarisTargetInfo<SparcV8TargetInfo>(triple) { 1467 SizeType = UnsignedInt; 1468 PtrDiffType = SignedInt; 1469 } 1470}; 1471} // end anonymous namespace. 1472 1473namespace { 1474 class PIC16TargetInfo : public TargetInfo{ 1475 public: 1476 PIC16TargetInfo(const std::string& triple) : TargetInfo(triple) { 1477 TLSSupported = false; 1478 IntWidth = 16; 1479 LongWidth = LongLongWidth = 32; 1480 IntMaxTWidth = 32; 1481 PointerWidth = 16; 1482 IntAlign = 8; 1483 LongAlign = LongLongAlign = 8; 1484 PointerAlign = 8; 1485 SizeType = UnsignedInt; 1486 IntMaxType = SignedLong; 1487 UIntMaxType = UnsignedLong; 1488 IntPtrType = SignedShort; 1489 PtrDiffType = SignedInt; 1490 FloatWidth = 32; 1491 FloatAlign = 32; 1492 DoubleWidth = 32; 1493 DoubleAlign = 32; 1494 LongDoubleWidth = 32; 1495 LongDoubleAlign = 32; 1496 FloatFormat = &llvm::APFloat::IEEEsingle; 1497 DoubleFormat = &llvm::APFloat::IEEEsingle; 1498 LongDoubleFormat = &llvm::APFloat::IEEEsingle; 1499 DescriptionString = "e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8-f32:32:32"; 1500 1501 } 1502 virtual uint64_t getPointerWidthV(unsigned AddrSpace) const { return 16; } 1503 virtual uint64_t getPointerAlignV(unsigned AddrSpace) const { return 8; } 1504 virtual void getTargetDefines(const LangOptions &Opts, 1505 std::vector<char> &Defines) const { 1506 Define(Defines, "__pic16"); 1507 Define(Defines, "rom", "__attribute__((address_space(1)))"); 1508 Define(Defines, "ram", "__attribute__((address_space(0)))"); 1509 Define(Defines, "_section(SectName)", 1510 "__attribute__((section(SectName)))"); 1511 Define(Defines, "_address(Addr)", 1512 "__attribute__((section(\"Address=\"#Addr)))"); 1513 Define(Defines, "_CONFIG(conf)", "asm(\"CONFIG \"#conf)"); 1514 Define(Defines, "_interrupt", 1515 "__attribute__((section(\"interrupt=0x4\"))) \ 1516 __attribute__((used))"); 1517 } 1518 virtual void getTargetBuiltins(const Builtin::Info *&Records, 1519 unsigned &NumRecords) const {} 1520 virtual const char *getVAListDeclaration() const { 1521 return ""; 1522 } 1523 virtual const char *getClobbers() const { 1524 return ""; 1525 } 1526 virtual void getGCCRegNames(const char * const *&Names, 1527 unsigned &NumNames) const {} 1528 virtual bool validateAsmConstraint(const char *&Name, 1529 TargetInfo::ConstraintInfo &info) const { 1530 return true; 1531 } 1532 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 1533 unsigned &NumAliases) const {} 1534 virtual bool useGlobalsForAutomaticVariables() const {return true;} 1535 }; 1536} 1537 1538namespace { 1539 class MSP430TargetInfo : public TargetInfo { 1540 static const char * const GCCRegNames[]; 1541 public: 1542 MSP430TargetInfo(const std::string& triple) : TargetInfo(triple) { 1543 TLSSupported = false; 1544 IntWidth = 16; 1545 LongWidth = LongLongWidth = 32; 1546 IntMaxTWidth = 32; 1547 PointerWidth = 16; 1548 IntAlign = 8; 1549 LongAlign = LongLongAlign = 8; 1550 PointerAlign = 8; 1551 SizeType = UnsignedInt; 1552 IntMaxType = SignedLong; 1553 UIntMaxType = UnsignedLong; 1554 IntPtrType = SignedShort; 1555 PtrDiffType = SignedInt; 1556 DescriptionString = "e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8"; 1557 } 1558 virtual void getTargetDefines(const LangOptions &Opts, 1559 std::vector<char> &Defines) const { 1560 Define(Defines, "MSP430"); 1561 Define(Defines, "__MSP430__"); 1562 // FIXME: defines for different 'flavours' of MCU 1563 } 1564 virtual void getTargetBuiltins(const Builtin::Info *&Records, 1565 unsigned &NumRecords) const { 1566 // FIXME: Implement. 1567 Records = 0; 1568 NumRecords = 0; 1569 } 1570 virtual void getGCCRegNames(const char * const *&Names, 1571 unsigned &NumNames) const; 1572 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 1573 unsigned &NumAliases) const { 1574 // No aliases. 1575 Aliases = 0; 1576 NumAliases = 0; 1577 } 1578 virtual bool validateAsmConstraint(const char *&Name, 1579 TargetInfo::ConstraintInfo &info) const { 1580 // FIXME: implement 1581 return true; 1582 } 1583 virtual const char *getClobbers() const { 1584 // FIXME: Is this really right? 1585 return ""; 1586 } 1587 virtual const char *getVAListDeclaration() const { 1588 // FIXME: implement 1589 return "typedef char* __builtin_va_list;"; 1590 } 1591 }; 1592 1593 const char * const MSP430TargetInfo::GCCRegNames[] = { 1594 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 1595 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" 1596 }; 1597 1598 void MSP430TargetInfo::getGCCRegNames(const char * const *&Names, 1599 unsigned &NumNames) const { 1600 Names = GCCRegNames; 1601 NumNames = llvm::array_lengthof(GCCRegNames); 1602 } 1603} 1604 1605 1606namespace { 1607 class SystemZTargetInfo : public TargetInfo { 1608 static const char * const GCCRegNames[]; 1609 public: 1610 SystemZTargetInfo(const std::string& triple) : TargetInfo(triple) { 1611 TLSSupported = false; 1612 IntWidth = IntAlign = 32; 1613 LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64; 1614 PointerWidth = PointerAlign = 64; 1615 DescriptionString = "E-p:64:64:64-i8:8:16-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f128:128:128-a0:16:16"; 1616 } 1617 virtual void getTargetDefines(const LangOptions &Opts, 1618 std::vector<char> &Defines) const { 1619 Define(Defines, "__s390__"); 1620 Define(Defines, "__s390x__"); 1621 } 1622 virtual void getTargetBuiltins(const Builtin::Info *&Records, 1623 unsigned &NumRecords) const { 1624 // FIXME: Implement. 1625 Records = 0; 1626 NumRecords = 0; 1627 } 1628 1629 virtual void getDefaultLangOptions(LangOptions &Opts) { 1630 TargetInfo::getDefaultLangOptions(Opts); 1631 Opts.CharIsSigned = false; 1632 } 1633 1634 virtual void getGCCRegNames(const char * const *&Names, 1635 unsigned &NumNames) const; 1636 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 1637 unsigned &NumAliases) const { 1638 // No aliases. 1639 Aliases = 0; 1640 NumAliases = 0; 1641 } 1642 virtual bool validateAsmConstraint(const char *&Name, 1643 TargetInfo::ConstraintInfo &info) const { 1644 // FIXME: implement 1645 return true; 1646 } 1647 virtual const char *getClobbers() const { 1648 // FIXME: Is this really right? 1649 return ""; 1650 } 1651 virtual const char *getVAListDeclaration() const { 1652 // FIXME: implement 1653 return "typedef char* __builtin_va_list;"; 1654 } 1655 }; 1656 1657 const char * const SystemZTargetInfo::GCCRegNames[] = { 1658 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 1659 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" 1660 }; 1661 1662 void SystemZTargetInfo::getGCCRegNames(const char * const *&Names, 1663 unsigned &NumNames) const { 1664 Names = GCCRegNames; 1665 NumNames = llvm::array_lengthof(GCCRegNames); 1666 } 1667} 1668 1669namespace { 1670 class BlackfinTargetInfo : public TargetInfo { 1671 static const char * const GCCRegNames[]; 1672 public: 1673 BlackfinTargetInfo(const std::string& triple) : TargetInfo(triple) { 1674 TLSSupported = false; 1675 DoubleAlign = 32; 1676 LongLongAlign = 32; 1677 LongDoubleAlign = 32; 1678 DescriptionString = "e-p:32:32-i64:32-f64:32"; 1679 } 1680 1681 virtual void getTargetDefines(const LangOptions &Opts, 1682 std::vector<char> &Defines) const { 1683 DefineStd(Defines, "bfin", Opts); 1684 DefineStd(Defines, "BFIN", Opts); 1685 Define(Defines, "__ADSPBLACKFIN__"); 1686 // FIXME: This one is really dependent on -mcpu 1687 Define(Defines, "__ADSPLPBLACKFIN__"); 1688 // FIXME: Add cpu-dependent defines and __SILICON_REVISION__ 1689 } 1690 1691 virtual void getTargetBuiltins(const Builtin::Info *&Records, 1692 unsigned &NumRecords) const { 1693 // FIXME: Implement. 1694 Records = 0; 1695 NumRecords = 0; 1696 } 1697 1698 virtual void getGCCRegNames(const char * const *&Names, 1699 unsigned &NumNames) const; 1700 1701 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 1702 unsigned &NumAliases) const { 1703 // No aliases. 1704 Aliases = 0; 1705 NumAliases = 0; 1706 } 1707 1708 virtual bool validateAsmConstraint(const char *&Name, 1709 TargetInfo::ConstraintInfo &Info) const { 1710 if (strchr("adzDWeABbvfcCtukxywZY", Name[0])) { 1711 Info.setAllowsRegister(); 1712 return true; 1713 } 1714 return false; 1715 } 1716 1717 virtual const char *getClobbers() const { 1718 return ""; 1719 } 1720 1721 virtual const char *getVAListDeclaration() const { 1722 return "typedef char* __builtin_va_list;"; 1723 } 1724 }; 1725 1726 const char * const BlackfinTargetInfo::GCCRegNames[] = { 1727 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 1728 "p0", "p1", "p2", "p3", "p4", "p5", "sp", "fp", 1729 "i0", "i1", "i2", "i3", "b0", "b1", "b2", "b3", 1730 "l0", "l1", "l2", "l3", "m0", "m1", "m2", "m3", 1731 "a0", "a1", "cc", 1732 "rets", "reti", "retx", "retn", "rete", "astat", "seqstat", "usp", 1733 "argp", "lt0", "lt1", "lc0", "lc1", "lb0", "lb1" 1734 }; 1735 1736 void BlackfinTargetInfo::getGCCRegNames(const char * const *&Names, 1737 unsigned &NumNames) const { 1738 Names = GCCRegNames; 1739 NumNames = llvm::array_lengthof(GCCRegNames); 1740 } 1741} 1742 1743namespace { 1744 1745 // LLVM and Clang cannot be used directly to output native binaries for 1746 // target, but is used to compile C code to llvm bitcode with correct 1747 // type and alignment information. 1748 // 1749 // TCE uses the llvm bitcode as input and uses it for generating customized 1750 // target processor and program binary. TCE co-design environment is 1751 // publicly available in http://tce.cs.tut.fi 1752 1753 class TCETargetInfo : public TargetInfo{ 1754 public: 1755 TCETargetInfo(const std::string& triple) : TargetInfo(triple) { 1756 TLSSupported = false; 1757 IntWidth = 32; 1758 LongWidth = LongLongWidth = 32; 1759 IntMaxTWidth = 32; 1760 PointerWidth = 32; 1761 IntAlign = 32; 1762 LongAlign = LongLongAlign = 32; 1763 PointerAlign = 32; 1764 SizeType = UnsignedInt; 1765 IntMaxType = SignedLong; 1766 UIntMaxType = UnsignedLong; 1767 IntPtrType = SignedInt; 1768 PtrDiffType = SignedInt; 1769 FloatWidth = 32; 1770 FloatAlign = 32; 1771 DoubleWidth = 32; 1772 DoubleAlign = 32; 1773 LongDoubleWidth = 32; 1774 LongDoubleAlign = 32; 1775 FloatFormat = &llvm::APFloat::IEEEsingle; 1776 DoubleFormat = &llvm::APFloat::IEEEsingle; 1777 LongDoubleFormat = &llvm::APFloat::IEEEsingle; 1778 DescriptionString = "E-p:32:32:32-a0:32:32" 1779 "-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64" 1780 "-f32:32:32-f64:32:64"; 1781 } 1782 1783 virtual void getTargetDefines(const LangOptions &Opts, 1784 std::vector<char> &Defines) const { 1785 DefineStd(Defines, "tce", Opts); 1786 Define(Defines, "__TCE__"); 1787 Define(Defines, "__TCE_V1__"); 1788 } 1789 virtual void getTargetBuiltins(const Builtin::Info *&Records, 1790 unsigned &NumRecords) const {} 1791 virtual const char *getClobbers() const { 1792 return ""; 1793 } 1794 virtual const char *getVAListDeclaration() const { 1795 return "typedef void* __builtin_va_list;"; 1796 } 1797 virtual void getGCCRegNames(const char * const *&Names, 1798 unsigned &NumNames) const {} 1799 virtual bool validateAsmConstraint(const char *&Name, 1800 TargetInfo::ConstraintInfo &info) const { 1801 return true; 1802 } 1803 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 1804 unsigned &NumAliases) const {} 1805 }; 1806} 1807 1808//===----------------------------------------------------------------------===// 1809// Driver code 1810//===----------------------------------------------------------------------===// 1811 1812/// CreateTargetInfo - Return the target info object for the specified target 1813/// triple. 1814TargetInfo* TargetInfo::CreateTargetInfo(const std::string &T) { 1815 llvm::Triple Triple(T); 1816 llvm::Triple::OSType os = Triple.getOS(); 1817 1818 switch (Triple.getArch()) { 1819 default: 1820 return NULL; 1821 1822 case llvm::Triple::arm: 1823 case llvm::Triple::thumb: 1824 switch (os) { 1825 case llvm::Triple::Darwin: 1826 return new DarwinARMTargetInfo(T); 1827 case llvm::Triple::FreeBSD: 1828 return new FreeBSDTargetInfo<ARMTargetInfo>(T); 1829 default: 1830 return new ARMTargetInfo(T); 1831 } 1832 1833 case llvm::Triple::bfin: 1834 return new BlackfinTargetInfo(T); 1835 1836 case llvm::Triple::msp430: 1837 return new MSP430TargetInfo(T); 1838 1839 case llvm::Triple::pic16: 1840 return new PIC16TargetInfo(T); 1841 1842 case llvm::Triple::ppc: 1843 if (os == llvm::Triple::Darwin) 1844 return new DarwinTargetInfo<PPCTargetInfo>(T); 1845 return new PPC32TargetInfo(T); 1846 1847 case llvm::Triple::ppc64: 1848 if (os == llvm::Triple::Darwin) 1849 return new DarwinTargetInfo<PPC64TargetInfo>(T); 1850 return new PPC64TargetInfo(T); 1851 1852 case llvm::Triple::sparc: 1853 if (os == llvm::Triple::Solaris) 1854 return new SolarisSparcV8TargetInfo(T); 1855 return new SparcV8TargetInfo(T); 1856 1857 case llvm::Triple::systemz: 1858 return new SystemZTargetInfo(T); 1859 1860 case llvm::Triple::tce: 1861 return new TCETargetInfo(T); 1862 1863 case llvm::Triple::x86: 1864 switch (os) { 1865 case llvm::Triple::Darwin: 1866 return new DarwinI386TargetInfo(T); 1867 case llvm::Triple::Linux: 1868 return new LinuxTargetInfo<X86_32TargetInfo>(T); 1869 case llvm::Triple::DragonFly: 1870 return new DragonFlyBSDTargetInfo<X86_32TargetInfo>(T); 1871 case llvm::Triple::NetBSD: 1872 return new NetBSDTargetInfo<X86_32TargetInfo>(T); 1873 case llvm::Triple::OpenBSD: 1874 return new OpenBSDI386TargetInfo(T); 1875 case llvm::Triple::FreeBSD: 1876 return new FreeBSDTargetInfo<X86_32TargetInfo>(T); 1877 case llvm::Triple::Solaris: 1878 return new SolarisTargetInfo<X86_32TargetInfo>(T); 1879 case llvm::Triple::Cygwin: 1880 return new CygwinX86_32TargetInfo(T); 1881 case llvm::Triple::MinGW32: 1882 return new MinGWX86_32TargetInfo(T); 1883 case llvm::Triple::Win32: 1884 return new VisualStudioWindowsX86_32TargetInfo(T); 1885 default: 1886 return new X86_32TargetInfo(T); 1887 } 1888 1889 case llvm::Triple::x86_64: 1890 switch (os) { 1891 case llvm::Triple::Darwin: 1892 return new DarwinX86_64TargetInfo(T); 1893 case llvm::Triple::Linux: 1894 return new LinuxTargetInfo<X86_64TargetInfo>(T); 1895 case llvm::Triple::NetBSD: 1896 return new NetBSDTargetInfo<X86_64TargetInfo>(T); 1897 case llvm::Triple::OpenBSD: 1898 return new OpenBSDX86_64TargetInfo(T); 1899 case llvm::Triple::FreeBSD: 1900 return new FreeBSDTargetInfo<X86_64TargetInfo>(T); 1901 case llvm::Triple::Solaris: 1902 return new SolarisTargetInfo<X86_64TargetInfo>(T); 1903 case llvm::Triple::MinGW64: 1904 return new MinGWX86_64TargetInfo(T); 1905 case llvm::Triple::Win32: // This is what Triple.h supports now. 1906 return new VisualStudioWindowsX86_64TargetInfo(T); 1907 default: 1908 return new X86_64TargetInfo(T); 1909 } 1910 } 1911} 1912