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