1 //===--- Targets.cpp - Implement target feature support -------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file implements construction of a TargetInfo object from a 10 // target triple. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "Targets.h" 15 16 #include "Targets/AArch64.h" 17 #include "Targets/AMDGPU.h" 18 #include "Targets/ARC.h" 19 #include "Targets/ARM.h" 20 #include "Targets/AVR.h" 21 #include "Targets/BPF.h" 22 #include "Targets/Hexagon.h" 23 #include "Targets/Lanai.h" 24 #include "Targets/Le64.h" 25 #include "Targets/MSP430.h" 26 #include "Targets/Mips.h" 27 #include "Targets/NVPTX.h" 28 #include "Targets/OSTargets.h" 29 #include "Targets/PNaCl.h" 30 #include "Targets/PPC.h" 31 #include "Targets/RISCV.h" 32 #include "Targets/SPIR.h" 33 #include "Targets/Sparc.h" 34 #include "Targets/SystemZ.h" 35 #include "Targets/TCE.h" 36 #include "Targets/VE.h" 37 #include "Targets/WebAssembly.h" 38 #include "Targets/X86.h" 39 #include "Targets/XCore.h" 40 #include "clang/Basic/Diagnostic.h" 41 #include "llvm/ADT/StringExtras.h" 42 #include "llvm/ADT/Triple.h" 43 44 using namespace clang; 45 46 namespace clang { 47 namespace targets { 48 //===----------------------------------------------------------------------===// 49 // Common code shared among targets. 50 //===----------------------------------------------------------------------===// 51 52 /// DefineStd - Define a macro name and standard variants. For example if 53 /// MacroName is "unix", then this will define "__unix", "__unix__", and "unix" 54 /// when in GNU mode. 55 void DefineStd(MacroBuilder &Builder, StringRef MacroName, 56 const LangOptions &Opts) { 57 assert(MacroName[0] != '_' && "Identifier should be in the user's namespace"); 58 59 // If in GNU mode (e.g. -std=gnu99 but not -std=c99) define the raw identifier 60 // in the user's namespace. 61 if (Opts.GNUMode) 62 Builder.defineMacro(MacroName); 63 64 // Define __unix. 65 Builder.defineMacro("__" + MacroName); 66 67 // Define __unix__. 68 Builder.defineMacro("__" + MacroName + "__"); 69 } 70 71 void defineCPUMacros(MacroBuilder &Builder, StringRef CPUName, bool Tuning) { 72 Builder.defineMacro("__" + CPUName); 73 Builder.defineMacro("__" + CPUName + "__"); 74 if (Tuning) 75 Builder.defineMacro("__tune_" + CPUName + "__"); 76 } 77 78 void addCygMingDefines(const LangOptions &Opts, MacroBuilder &Builder) { 79 // Mingw and cygwin define __declspec(a) to __attribute__((a)). Clang 80 // supports __declspec natively under -fms-extensions, but we define a no-op 81 // __declspec macro anyway for pre-processor compatibility. 82 if (Opts.MicrosoftExt) 83 Builder.defineMacro("__declspec", "__declspec"); 84 else 85 Builder.defineMacro("__declspec(a)", "__attribute__((a))"); 86 87 if (!Opts.MicrosoftExt) { 88 // Provide macros for all the calling convention keywords. Provide both 89 // single and double underscore prefixed variants. These are available on 90 // x64 as well as x86, even though they have no effect. 91 const char *CCs[] = {"cdecl", "stdcall", "fastcall", "thiscall", "pascal"}; 92 for (const char *CC : CCs) { 93 std::string GCCSpelling = "__attribute__((__"; 94 GCCSpelling += CC; 95 GCCSpelling += "__))"; 96 Builder.defineMacro(Twine("_") + CC, GCCSpelling); 97 Builder.defineMacro(Twine("__") + CC, GCCSpelling); 98 } 99 } 100 } 101 102 //===----------------------------------------------------------------------===// 103 // Driver code 104 //===----------------------------------------------------------------------===// 105 106 TargetInfo *AllocateTarget(const llvm::Triple &Triple, 107 const TargetOptions &Opts) { 108 llvm::Triple::OSType os = Triple.getOS(); 109 110 switch (Triple.getArch()) { 111 default: 112 return nullptr; 113 114 case llvm::Triple::arc: 115 return new ARCTargetInfo(Triple, Opts); 116 117 case llvm::Triple::xcore: 118 return new XCoreTargetInfo(Triple, Opts); 119 120 case llvm::Triple::hexagon: 121 if (os == llvm::Triple::Linux && 122 Triple.getEnvironment() == llvm::Triple::Musl) 123 return new LinuxTargetInfo<HexagonTargetInfo>(Triple, Opts); 124 return new HexagonTargetInfo(Triple, Opts); 125 126 case llvm::Triple::lanai: 127 return new LanaiTargetInfo(Triple, Opts); 128 129 case llvm::Triple::aarch64_32: 130 if (Triple.isOSDarwin()) 131 return new DarwinAArch64TargetInfo(Triple, Opts); 132 133 return nullptr; 134 case llvm::Triple::aarch64: 135 if (Triple.isOSDarwin()) 136 return new DarwinAArch64TargetInfo(Triple, Opts); 137 138 switch (os) { 139 case llvm::Triple::CloudABI: 140 return new CloudABITargetInfo<AArch64leTargetInfo>(Triple, Opts); 141 case llvm::Triple::FreeBSD: 142 return new FreeBSDTargetInfo<AArch64leTargetInfo>(Triple, Opts); 143 case llvm::Triple::Fuchsia: 144 return new FuchsiaTargetInfo<AArch64leTargetInfo>(Triple, Opts); 145 case llvm::Triple::Linux: 146 return new LinuxTargetInfo<AArch64leTargetInfo>(Triple, Opts); 147 case llvm::Triple::NetBSD: 148 return new NetBSDTargetInfo<AArch64leTargetInfo>(Triple, Opts); 149 case llvm::Triple::OpenBSD: 150 return new OpenBSDTargetInfo<AArch64leTargetInfo>(Triple, Opts); 151 case llvm::Triple::Win32: 152 switch (Triple.getEnvironment()) { 153 case llvm::Triple::GNU: 154 return new MinGWARM64TargetInfo(Triple, Opts); 155 case llvm::Triple::MSVC: 156 default: // Assume MSVC for unknown environments 157 return new MicrosoftARM64TargetInfo(Triple, Opts); 158 } 159 default: 160 return new AArch64leTargetInfo(Triple, Opts); 161 } 162 163 case llvm::Triple::aarch64_be: 164 switch (os) { 165 case llvm::Triple::FreeBSD: 166 return new FreeBSDTargetInfo<AArch64beTargetInfo>(Triple, Opts); 167 case llvm::Triple::Fuchsia: 168 return new FuchsiaTargetInfo<AArch64beTargetInfo>(Triple, Opts); 169 case llvm::Triple::Linux: 170 return new LinuxTargetInfo<AArch64beTargetInfo>(Triple, Opts); 171 case llvm::Triple::NetBSD: 172 return new NetBSDTargetInfo<AArch64beTargetInfo>(Triple, Opts); 173 default: 174 return new AArch64beTargetInfo(Triple, Opts); 175 } 176 177 case llvm::Triple::arm: 178 case llvm::Triple::thumb: 179 if (Triple.isOSBinFormatMachO()) 180 return new DarwinARMTargetInfo(Triple, Opts); 181 182 switch (os) { 183 case llvm::Triple::CloudABI: 184 return new CloudABITargetInfo<ARMleTargetInfo>(Triple, Opts); 185 case llvm::Triple::Linux: 186 return new LinuxTargetInfo<ARMleTargetInfo>(Triple, Opts); 187 case llvm::Triple::FreeBSD: 188 return new FreeBSDTargetInfo<ARMleTargetInfo>(Triple, Opts); 189 case llvm::Triple::NetBSD: 190 return new NetBSDTargetInfo<ARMleTargetInfo>(Triple, Opts); 191 case llvm::Triple::OpenBSD: 192 return new OpenBSDTargetInfo<ARMleTargetInfo>(Triple, Opts); 193 case llvm::Triple::RTEMS: 194 return new RTEMSTargetInfo<ARMleTargetInfo>(Triple, Opts); 195 case llvm::Triple::NaCl: 196 return new NaClTargetInfo<ARMleTargetInfo>(Triple, Opts); 197 case llvm::Triple::Win32: 198 switch (Triple.getEnvironment()) { 199 case llvm::Triple::Cygnus: 200 return new CygwinARMTargetInfo(Triple, Opts); 201 case llvm::Triple::GNU: 202 return new MinGWARMTargetInfo(Triple, Opts); 203 case llvm::Triple::Itanium: 204 return new ItaniumWindowsARMleTargetInfo(Triple, Opts); 205 case llvm::Triple::MSVC: 206 default: // Assume MSVC for unknown environments 207 return new MicrosoftARMleTargetInfo(Triple, Opts); 208 } 209 default: 210 return new ARMleTargetInfo(Triple, Opts); 211 } 212 213 case llvm::Triple::armeb: 214 case llvm::Triple::thumbeb: 215 if (Triple.isOSDarwin()) 216 return new DarwinARMTargetInfo(Triple, Opts); 217 218 switch (os) { 219 case llvm::Triple::Linux: 220 return new LinuxTargetInfo<ARMbeTargetInfo>(Triple, Opts); 221 case llvm::Triple::FreeBSD: 222 return new FreeBSDTargetInfo<ARMbeTargetInfo>(Triple, Opts); 223 case llvm::Triple::NetBSD: 224 return new NetBSDTargetInfo<ARMbeTargetInfo>(Triple, Opts); 225 case llvm::Triple::OpenBSD: 226 return new OpenBSDTargetInfo<ARMbeTargetInfo>(Triple, Opts); 227 case llvm::Triple::RTEMS: 228 return new RTEMSTargetInfo<ARMbeTargetInfo>(Triple, Opts); 229 case llvm::Triple::NaCl: 230 return new NaClTargetInfo<ARMbeTargetInfo>(Triple, Opts); 231 default: 232 return new ARMbeTargetInfo(Triple, Opts); 233 } 234 235 case llvm::Triple::avr: 236 return new AVRTargetInfo(Triple, Opts); 237 case llvm::Triple::bpfeb: 238 case llvm::Triple::bpfel: 239 return new BPFTargetInfo(Triple, Opts); 240 241 case llvm::Triple::msp430: 242 return new MSP430TargetInfo(Triple, Opts); 243 244 case llvm::Triple::mips: 245 switch (os) { 246 case llvm::Triple::Linux: 247 return new LinuxTargetInfo<MipsTargetInfo>(Triple, Opts); 248 case llvm::Triple::RTEMS: 249 return new RTEMSTargetInfo<MipsTargetInfo>(Triple, Opts); 250 case llvm::Triple::FreeBSD: 251 return new FreeBSDTargetInfo<MipsTargetInfo>(Triple, Opts); 252 case llvm::Triple::NetBSD: 253 return new NetBSDTargetInfo<MipsTargetInfo>(Triple, Opts); 254 default: 255 return new MipsTargetInfo(Triple, Opts); 256 } 257 258 case llvm::Triple::mipsel: 259 switch (os) { 260 case llvm::Triple::Linux: 261 return new LinuxTargetInfo<MipsTargetInfo>(Triple, Opts); 262 case llvm::Triple::RTEMS: 263 return new RTEMSTargetInfo<MipsTargetInfo>(Triple, Opts); 264 case llvm::Triple::FreeBSD: 265 return new FreeBSDTargetInfo<MipsTargetInfo>(Triple, Opts); 266 case llvm::Triple::NetBSD: 267 return new NetBSDTargetInfo<MipsTargetInfo>(Triple, Opts); 268 case llvm::Triple::NaCl: 269 return new NaClTargetInfo<NaClMips32TargetInfo>(Triple, Opts); 270 default: 271 return new MipsTargetInfo(Triple, Opts); 272 } 273 274 case llvm::Triple::mips64: 275 switch (os) { 276 case llvm::Triple::Linux: 277 return new LinuxTargetInfo<MipsTargetInfo>(Triple, Opts); 278 case llvm::Triple::RTEMS: 279 return new RTEMSTargetInfo<MipsTargetInfo>(Triple, Opts); 280 case llvm::Triple::FreeBSD: 281 return new FreeBSDTargetInfo<MipsTargetInfo>(Triple, Opts); 282 case llvm::Triple::NetBSD: 283 return new NetBSDTargetInfo<MipsTargetInfo>(Triple, Opts); 284 case llvm::Triple::OpenBSD: 285 return new OpenBSDTargetInfo<MipsTargetInfo>(Triple, Opts); 286 default: 287 return new MipsTargetInfo(Triple, Opts); 288 } 289 290 case llvm::Triple::mips64el: 291 switch (os) { 292 case llvm::Triple::Linux: 293 return new LinuxTargetInfo<MipsTargetInfo>(Triple, Opts); 294 case llvm::Triple::RTEMS: 295 return new RTEMSTargetInfo<MipsTargetInfo>(Triple, Opts); 296 case llvm::Triple::FreeBSD: 297 return new FreeBSDTargetInfo<MipsTargetInfo>(Triple, Opts); 298 case llvm::Triple::NetBSD: 299 return new NetBSDTargetInfo<MipsTargetInfo>(Triple, Opts); 300 case llvm::Triple::OpenBSD: 301 return new OpenBSDTargetInfo<MipsTargetInfo>(Triple, Opts); 302 default: 303 return new MipsTargetInfo(Triple, Opts); 304 } 305 306 case llvm::Triple::le32: 307 switch (os) { 308 case llvm::Triple::NaCl: 309 return new NaClTargetInfo<PNaClTargetInfo>(Triple, Opts); 310 default: 311 return nullptr; 312 } 313 314 case llvm::Triple::le64: 315 return new Le64TargetInfo(Triple, Opts); 316 317 case llvm::Triple::ppc: 318 if (Triple.isOSDarwin()) 319 return new DarwinPPC32TargetInfo(Triple, Opts); 320 switch (os) { 321 case llvm::Triple::Linux: 322 return new LinuxTargetInfo<PPC32TargetInfo>(Triple, Opts); 323 case llvm::Triple::FreeBSD: 324 return new FreeBSDTargetInfo<PPC32TargetInfo>(Triple, Opts); 325 case llvm::Triple::NetBSD: 326 return new NetBSDTargetInfo<PPC32TargetInfo>(Triple, Opts); 327 case llvm::Triple::OpenBSD: 328 return new OpenBSDTargetInfo<PPC32TargetInfo>(Triple, Opts); 329 case llvm::Triple::RTEMS: 330 return new RTEMSTargetInfo<PPC32TargetInfo>(Triple, Opts); 331 case llvm::Triple::AIX: 332 return new AIXPPC32TargetInfo(Triple, Opts); 333 default: 334 return new PPC32TargetInfo(Triple, Opts); 335 } 336 337 case llvm::Triple::ppc64: 338 if (Triple.isOSDarwin()) 339 return new DarwinPPC64TargetInfo(Triple, Opts); 340 switch (os) { 341 case llvm::Triple::Linux: 342 return new LinuxTargetInfo<PPC64TargetInfo>(Triple, Opts); 343 case llvm::Triple::Lv2: 344 return new PS3PPUTargetInfo<PPC64TargetInfo>(Triple, Opts); 345 case llvm::Triple::FreeBSD: 346 return new FreeBSDTargetInfo<PPC64TargetInfo>(Triple, Opts); 347 case llvm::Triple::NetBSD: 348 return new NetBSDTargetInfo<PPC64TargetInfo>(Triple, Opts); 349 case llvm::Triple::OpenBSD: 350 return new OpenBSDTargetInfo<PPC64TargetInfo>(Triple, Opts); 351 case llvm::Triple::AIX: 352 return new AIXPPC64TargetInfo(Triple, Opts); 353 default: 354 return new PPC64TargetInfo(Triple, Opts); 355 } 356 357 case llvm::Triple::ppc64le: 358 switch (os) { 359 case llvm::Triple::Linux: 360 return new LinuxTargetInfo<PPC64TargetInfo>(Triple, Opts); 361 case llvm::Triple::FreeBSD: 362 return new FreeBSDTargetInfo<PPC64TargetInfo>(Triple, Opts); 363 case llvm::Triple::NetBSD: 364 return new NetBSDTargetInfo<PPC64TargetInfo>(Triple, Opts); 365 case llvm::Triple::OpenBSD: 366 return new OpenBSDTargetInfo<PPC64TargetInfo>(Triple, Opts); 367 default: 368 return new PPC64TargetInfo(Triple, Opts); 369 } 370 371 case llvm::Triple::nvptx: 372 return new NVPTXTargetInfo(Triple, Opts, /*TargetPointerWidth=*/32); 373 case llvm::Triple::nvptx64: 374 return new NVPTXTargetInfo(Triple, Opts, /*TargetPointerWidth=*/64); 375 376 case llvm::Triple::amdgcn: 377 case llvm::Triple::r600: 378 return new AMDGPUTargetInfo(Triple, Opts); 379 380 case llvm::Triple::riscv32: 381 // TODO: add cases for NetBSD, RTEMS once tested. 382 switch (os) { 383 case llvm::Triple::FreeBSD: 384 return new FreeBSDTargetInfo<RISCV32TargetInfo>(Triple, Opts); 385 case llvm::Triple::Linux: 386 return new LinuxTargetInfo<RISCV32TargetInfo>(Triple, Opts); 387 default: 388 return new RISCV32TargetInfo(Triple, Opts); 389 } 390 391 case llvm::Triple::riscv64: 392 // TODO: add cases for NetBSD, RTEMS once tested. 393 switch (os) { 394 case llvm::Triple::FreeBSD: 395 return new FreeBSDTargetInfo<RISCV64TargetInfo>(Triple, Opts); 396 case llvm::Triple::OpenBSD: 397 return new OpenBSDTargetInfo<RISCV64TargetInfo>(Triple, Opts); 398 case llvm::Triple::Fuchsia: 399 return new FuchsiaTargetInfo<RISCV64TargetInfo>(Triple, Opts); 400 case llvm::Triple::Linux: 401 return new LinuxTargetInfo<RISCV64TargetInfo>(Triple, Opts); 402 default: 403 return new RISCV64TargetInfo(Triple, Opts); 404 } 405 406 case llvm::Triple::sparc: 407 switch (os) { 408 case llvm::Triple::Linux: 409 return new LinuxTargetInfo<SparcV8TargetInfo>(Triple, Opts); 410 case llvm::Triple::Solaris: 411 return new SolarisTargetInfo<SparcV8TargetInfo>(Triple, Opts); 412 case llvm::Triple::NetBSD: 413 return new NetBSDTargetInfo<SparcV8TargetInfo>(Triple, Opts); 414 case llvm::Triple::OpenBSD: 415 return new OpenBSDTargetInfo<SparcV8TargetInfo>(Triple, Opts); 416 case llvm::Triple::RTEMS: 417 return new RTEMSTargetInfo<SparcV8TargetInfo>(Triple, Opts); 418 default: 419 return new SparcV8TargetInfo(Triple, Opts); 420 } 421 422 // The 'sparcel' architecture copies all the above cases except for Solaris. 423 case llvm::Triple::sparcel: 424 switch (os) { 425 case llvm::Triple::Linux: 426 return new LinuxTargetInfo<SparcV8elTargetInfo>(Triple, Opts); 427 case llvm::Triple::NetBSD: 428 return new NetBSDTargetInfo<SparcV8elTargetInfo>(Triple, Opts); 429 case llvm::Triple::OpenBSD: 430 return new OpenBSDTargetInfo<SparcV8elTargetInfo>(Triple, Opts); 431 case llvm::Triple::RTEMS: 432 return new RTEMSTargetInfo<SparcV8elTargetInfo>(Triple, Opts); 433 default: 434 return new SparcV8elTargetInfo(Triple, Opts); 435 } 436 437 case llvm::Triple::sparcv9: 438 switch (os) { 439 case llvm::Triple::Linux: 440 return new LinuxTargetInfo<SparcV9TargetInfo>(Triple, Opts); 441 case llvm::Triple::Solaris: 442 return new SolarisTargetInfo<SparcV9TargetInfo>(Triple, Opts); 443 case llvm::Triple::NetBSD: 444 return new NetBSDTargetInfo<SparcV9TargetInfo>(Triple, Opts); 445 case llvm::Triple::OpenBSD: 446 return new OpenBSDTargetInfo<SparcV9TargetInfo>(Triple, Opts); 447 case llvm::Triple::FreeBSD: 448 return new FreeBSDTargetInfo<SparcV9TargetInfo>(Triple, Opts); 449 default: 450 return new SparcV9TargetInfo(Triple, Opts); 451 } 452 453 case llvm::Triple::systemz: 454 switch (os) { 455 case llvm::Triple::Linux: 456 return new LinuxTargetInfo<SystemZTargetInfo>(Triple, Opts); 457 default: 458 return new SystemZTargetInfo(Triple, Opts); 459 } 460 461 case llvm::Triple::tce: 462 return new TCETargetInfo(Triple, Opts); 463 464 case llvm::Triple::tcele: 465 return new TCELETargetInfo(Triple, Opts); 466 467 case llvm::Triple::x86: 468 if (Triple.isOSDarwin()) 469 return new DarwinI386TargetInfo(Triple, Opts); 470 471 switch (os) { 472 case llvm::Triple::Ananas: 473 return new AnanasTargetInfo<X86_32TargetInfo>(Triple, Opts); 474 case llvm::Triple::CloudABI: 475 return new CloudABITargetInfo<X86_32TargetInfo>(Triple, Opts); 476 case llvm::Triple::Linux: { 477 switch (Triple.getEnvironment()) { 478 default: 479 return new LinuxTargetInfo<X86_32TargetInfo>(Triple, Opts); 480 case llvm::Triple::Android: 481 return new AndroidX86_32TargetInfo(Triple, Opts); 482 } 483 } 484 case llvm::Triple::DragonFly: 485 return new DragonFlyBSDTargetInfo<X86_32TargetInfo>(Triple, Opts); 486 case llvm::Triple::NetBSD: 487 return new NetBSDI386TargetInfo(Triple, Opts); 488 case llvm::Triple::OpenBSD: 489 return new OpenBSDI386TargetInfo(Triple, Opts); 490 case llvm::Triple::FreeBSD: 491 return new FreeBSDTargetInfo<X86_32TargetInfo>(Triple, Opts); 492 case llvm::Triple::Fuchsia: 493 return new FuchsiaTargetInfo<X86_32TargetInfo>(Triple, Opts); 494 case llvm::Triple::KFreeBSD: 495 return new KFreeBSDTargetInfo<X86_32TargetInfo>(Triple, Opts); 496 case llvm::Triple::Minix: 497 return new MinixTargetInfo<X86_32TargetInfo>(Triple, Opts); 498 case llvm::Triple::Solaris: 499 return new SolarisTargetInfo<X86_32TargetInfo>(Triple, Opts); 500 case llvm::Triple::Win32: { 501 switch (Triple.getEnvironment()) { 502 case llvm::Triple::Cygnus: 503 return new CygwinX86_32TargetInfo(Triple, Opts); 504 case llvm::Triple::GNU: 505 return new MinGWX86_32TargetInfo(Triple, Opts); 506 case llvm::Triple::Itanium: 507 case llvm::Triple::MSVC: 508 default: // Assume MSVC for unknown environments 509 return new MicrosoftX86_32TargetInfo(Triple, Opts); 510 } 511 } 512 case llvm::Triple::Haiku: 513 return new HaikuX86_32TargetInfo(Triple, Opts); 514 case llvm::Triple::RTEMS: 515 return new RTEMSX86_32TargetInfo(Triple, Opts); 516 case llvm::Triple::NaCl: 517 return new NaClTargetInfo<X86_32TargetInfo>(Triple, Opts); 518 case llvm::Triple::ELFIAMCU: 519 return new MCUX86_32TargetInfo(Triple, Opts); 520 case llvm::Triple::Hurd: 521 return new HurdTargetInfo<X86_32TargetInfo>(Triple, Opts); 522 default: 523 return new X86_32TargetInfo(Triple, Opts); 524 } 525 526 case llvm::Triple::x86_64: 527 if (Triple.isOSDarwin() || Triple.isOSBinFormatMachO()) 528 return new DarwinX86_64TargetInfo(Triple, Opts); 529 530 switch (os) { 531 case llvm::Triple::Ananas: 532 return new AnanasTargetInfo<X86_64TargetInfo>(Triple, Opts); 533 case llvm::Triple::CloudABI: 534 return new CloudABITargetInfo<X86_64TargetInfo>(Triple, Opts); 535 case llvm::Triple::Linux: { 536 switch (Triple.getEnvironment()) { 537 default: 538 return new LinuxTargetInfo<X86_64TargetInfo>(Triple, Opts); 539 case llvm::Triple::Android: 540 return new AndroidX86_64TargetInfo(Triple, Opts); 541 } 542 } 543 case llvm::Triple::DragonFly: 544 return new DragonFlyBSDTargetInfo<X86_64TargetInfo>(Triple, Opts); 545 case llvm::Triple::NetBSD: 546 return new NetBSDTargetInfo<X86_64TargetInfo>(Triple, Opts); 547 case llvm::Triple::OpenBSD: 548 return new OpenBSDX86_64TargetInfo(Triple, Opts); 549 case llvm::Triple::FreeBSD: 550 return new FreeBSDTargetInfo<X86_64TargetInfo>(Triple, Opts); 551 case llvm::Triple::Fuchsia: 552 return new FuchsiaTargetInfo<X86_64TargetInfo>(Triple, Opts); 553 case llvm::Triple::KFreeBSD: 554 return new KFreeBSDTargetInfo<X86_64TargetInfo>(Triple, Opts); 555 case llvm::Triple::Solaris: 556 return new SolarisTargetInfo<X86_64TargetInfo>(Triple, Opts); 557 case llvm::Triple::Win32: { 558 switch (Triple.getEnvironment()) { 559 case llvm::Triple::Cygnus: 560 return new CygwinX86_64TargetInfo(Triple, Opts); 561 case llvm::Triple::GNU: 562 return new MinGWX86_64TargetInfo(Triple, Opts); 563 case llvm::Triple::MSVC: 564 default: // Assume MSVC for unknown environments 565 return new MicrosoftX86_64TargetInfo(Triple, Opts); 566 } 567 } 568 case llvm::Triple::Haiku: 569 return new HaikuTargetInfo<X86_64TargetInfo>(Triple, Opts); 570 case llvm::Triple::NaCl: 571 return new NaClTargetInfo<X86_64TargetInfo>(Triple, Opts); 572 case llvm::Triple::PS4: 573 return new PS4OSTargetInfo<X86_64TargetInfo>(Triple, Opts); 574 default: 575 return new X86_64TargetInfo(Triple, Opts); 576 } 577 578 case llvm::Triple::spir: { 579 if (Triple.getOS() != llvm::Triple::UnknownOS || 580 Triple.getEnvironment() != llvm::Triple::UnknownEnvironment) 581 return nullptr; 582 return new SPIR32TargetInfo(Triple, Opts); 583 } 584 case llvm::Triple::spir64: { 585 if (Triple.getOS() != llvm::Triple::UnknownOS || 586 Triple.getEnvironment() != llvm::Triple::UnknownEnvironment) 587 return nullptr; 588 return new SPIR64TargetInfo(Triple, Opts); 589 } 590 case llvm::Triple::wasm32: 591 if (Triple.getSubArch() != llvm::Triple::NoSubArch || 592 Triple.getVendor() != llvm::Triple::UnknownVendor || 593 !Triple.isOSBinFormatWasm()) 594 return nullptr; 595 switch (Triple.getOS()) { 596 case llvm::Triple::WASI: 597 return new WASITargetInfo<WebAssembly32TargetInfo>(Triple, Opts); 598 case llvm::Triple::Emscripten: 599 return new EmscriptenTargetInfo<WebAssembly32TargetInfo>(Triple, Opts); 600 case llvm::Triple::UnknownOS: 601 return new WebAssemblyOSTargetInfo<WebAssembly32TargetInfo>(Triple, Opts); 602 default: 603 return nullptr; 604 } 605 case llvm::Triple::wasm64: 606 if (Triple.getSubArch() != llvm::Triple::NoSubArch || 607 Triple.getVendor() != llvm::Triple::UnknownVendor || 608 !Triple.isOSBinFormatWasm()) 609 return nullptr; 610 switch (Triple.getOS()) { 611 case llvm::Triple::WASI: 612 return new WASITargetInfo<WebAssembly64TargetInfo>(Triple, Opts); 613 case llvm::Triple::Emscripten: 614 return new EmscriptenTargetInfo<WebAssembly64TargetInfo>(Triple, Opts); 615 case llvm::Triple::UnknownOS: 616 return new WebAssemblyOSTargetInfo<WebAssembly64TargetInfo>(Triple, Opts); 617 default: 618 return nullptr; 619 } 620 621 case llvm::Triple::renderscript32: 622 return new LinuxTargetInfo<RenderScript32TargetInfo>(Triple, Opts); 623 case llvm::Triple::renderscript64: 624 return new LinuxTargetInfo<RenderScript64TargetInfo>(Triple, Opts); 625 626 case llvm::Triple::ve: 627 return new LinuxTargetInfo<VETargetInfo>(Triple, Opts); 628 } 629 } 630 } // namespace targets 631 } // namespace clang 632 633 using namespace clang::targets; 634 /// CreateTargetInfo - Return the target info object for the specified target 635 /// options. 636 TargetInfo * 637 TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags, 638 const std::shared_ptr<TargetOptions> &Opts) { 639 llvm::Triple Triple(Opts->Triple); 640 641 // Construct the target 642 std::unique_ptr<TargetInfo> Target(AllocateTarget(Triple, *Opts)); 643 if (!Target) { 644 Diags.Report(diag::err_target_unknown_triple) << Triple.str(); 645 return nullptr; 646 } 647 Target->TargetOpts = Opts; 648 649 // Set the target CPU if specified. 650 if (!Opts->CPU.empty() && !Target->setCPU(Opts->CPU)) { 651 Diags.Report(diag::err_target_unknown_cpu) << Opts->CPU; 652 SmallVector<StringRef, 32> ValidList; 653 Target->fillValidCPUList(ValidList); 654 if (!ValidList.empty()) 655 Diags.Report(diag::note_valid_options) << llvm::join(ValidList, ", "); 656 return nullptr; 657 } 658 659 // Set the target ABI if specified. 660 if (!Opts->ABI.empty() && !Target->setABI(Opts->ABI)) { 661 Diags.Report(diag::err_target_unknown_abi) << Opts->ABI; 662 return nullptr; 663 } 664 665 // Set the fp math unit. 666 if (!Opts->FPMath.empty() && !Target->setFPMath(Opts->FPMath)) { 667 Diags.Report(diag::err_target_unknown_fpmath) << Opts->FPMath; 668 return nullptr; 669 } 670 671 // Compute the default target features, we need the target to handle this 672 // because features may have dependencies on one another. 673 if (!Target->initFeatureMap(Opts->FeatureMap, Diags, Opts->CPU, 674 Opts->FeaturesAsWritten)) 675 return nullptr; 676 677 // Add the features to the compile options. 678 Opts->Features.clear(); 679 for (const auto &F : Opts->FeatureMap) 680 Opts->Features.push_back((F.getValue() ? "+" : "-") + F.getKey().str()); 681 // Sort here, so we handle the features in a predictable order. (This matters 682 // when we're dealing with features that overlap.) 683 llvm::sort(Opts->Features); 684 685 if (!Target->handleTargetFeatures(Opts->Features, Diags)) 686 return nullptr; 687 688 Target->setSupportedOpenCLOpts(); 689 Target->setOpenCLExtensionOpts(); 690 Target->setMaxAtomicWidth(); 691 692 if (!Target->validateTarget(Diags)) 693 return nullptr; 694 695 Target->CheckFixedPointBits(); 696 697 return Target.release(); 698 } 699