clang 8.0.0

Targets.cpp
Go to the documentation of this file.
1 //===--- Targets.cpp - Implement target feature support -------------------===//
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 "Targets.h"
16
17 #include "Targets/AArch64.h"
18 #include "Targets/AMDGPU.h"
19 #include "Targets/ARC.h"
20 #include "Targets/ARM.h"
21 #include "Targets/AVR.h"
22 #include "Targets/BPF.h"
23 #include "Targets/Hexagon.h"
24 #include "Targets/Lanai.h"
25 #include "Targets/Le64.h"
26 #include "Targets/MSP430.h"
27 #include "Targets/Mips.h"
28 #include "Targets/NVPTX.h"
29 #include "Targets/OSTargets.h"
30 #include "Targets/PNaCl.h"
31 #include "Targets/PPC.h"
32 #include "Targets/RISCV.h"
33 #include "Targets/SPIR.h"
34 #include "Targets/Sparc.h"
35 #include "Targets/SystemZ.h"
36 #include "Targets/TCE.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 void addMinGWDefines(const llvm::Triple &Triple, const LangOptions &Opts,
103 MacroBuilder &Builder) {
104 DefineStd(Builder, "WIN32", Opts);
105 DefineStd(Builder, "WINNT", Opts);
106 if (Triple.isArch64Bit()) {
107 DefineStd(Builder, "WIN64", Opts);
108 Builder.defineMacro("__MINGW64__");
109 }
110 Builder.defineMacro("__MSVCRT__");
111 Builder.defineMacro("__MINGW32__");
112 addCygMingDefines(Opts, Builder);
113 }
114
115 //===----------------------------------------------------------------------===//
116 // Driver code
117 //===----------------------------------------------------------------------===//
118
119 TargetInfo *AllocateTarget(const llvm::Triple &Triple,
120 const TargetOptions &Opts) {
121 llvm::Triple::OSType os = Triple.getOS();
122
123 switch (Triple.getArch()) {
124 default:
125 return nullptr;
126
127 case llvm::Triple::arc:
128 return new ARCTargetInfo(Triple, Opts);
129
130 case llvm::Triple::xcore:
131 return new XCoreTargetInfo(Triple, Opts);
132
133 case llvm::Triple::hexagon:
134 return new HexagonTargetInfo(Triple, Opts);
135
136 case llvm::Triple::lanai:
137 return new LanaiTargetInfo(Triple, Opts);
138
139 case llvm::Triple::aarch64:
140 if (Triple.isOSDarwin())
141 return new DarwinAArch64TargetInfo(Triple, Opts);
142
143 switch (os) {
144 case llvm::Triple::CloudABI:
145 return new CloudABITargetInfo<AArch64leTargetInfo>(Triple, Opts);
146 case llvm::Triple::FreeBSD:
147 return new FreeBSDTargetInfo<AArch64leTargetInfo>(Triple, Opts);
148 case llvm::Triple::Fuchsia:
149 return new FuchsiaTargetInfo<AArch64leTargetInfo>(Triple, Opts);
150 case llvm::Triple::Linux:
151 return new LinuxTargetInfo<AArch64leTargetInfo>(Triple, Opts);
152 case llvm::Triple::NetBSD:
153 return new NetBSDTargetInfo<AArch64leTargetInfo>(Triple, Opts);
154 case llvm::Triple::OpenBSD:
155 return new OpenBSDTargetInfo<AArch64leTargetInfo>(Triple, Opts);
156 case llvm::Triple::Win32:
157 switch (Triple.getEnvironment()) {
158 case llvm::Triple::GNU:
159 return new MinGWARM64TargetInfo(Triple, Opts);
160 case llvm::Triple::MSVC:
161 default: // Assume MSVC for unknown environments
162 return new MicrosoftARM64TargetInfo(Triple, Opts);
163 }
164 default:
165 return new AArch64leTargetInfo(Triple, Opts);
166 }
167
168 case llvm::Triple::aarch64_be:
169 switch (os) {
170 case llvm::Triple::FreeBSD:
171 return new FreeBSDTargetInfo<AArch64beTargetInfo>(Triple, Opts);
172 case llvm::Triple::Fuchsia:
173 return new FuchsiaTargetInfo<AArch64beTargetInfo>(Triple, Opts);
174 case llvm::Triple::Linux:
175 return new LinuxTargetInfo<AArch64beTargetInfo>(Triple, Opts);
176 case llvm::Triple::NetBSD:
177 return new NetBSDTargetInfo<AArch64beTargetInfo>(Triple, Opts);
178 default:
179 return new AArch64beTargetInfo(Triple, Opts);
180 }
181
182 case llvm::Triple::arm:
183 case llvm::Triple::thumb:
184 if (Triple.isOSBinFormatMachO())
185 return new DarwinARMTargetInfo(Triple, Opts);
186
187 switch (os) {
188 case llvm::Triple::CloudABI:
189 return new CloudABITargetInfo<ARMleTargetInfo>(Triple, Opts);
190 case llvm::Triple::Linux:
191 return new LinuxTargetInfo<ARMleTargetInfo>(Triple, Opts);
192 case llvm::Triple::FreeBSD:
193 return new FreeBSDTargetInfo<ARMleTargetInfo>(Triple, Opts);
194 case llvm::Triple::NetBSD:
195 return new NetBSDTargetInfo<ARMleTargetInfo>(Triple, Opts);
196 case llvm::Triple::OpenBSD:
197 return new OpenBSDTargetInfo<ARMleTargetInfo>(Triple, Opts);
198 case llvm::Triple::RTEMS:
199 return new RTEMSTargetInfo<ARMleTargetInfo>(Triple, Opts);
200 case llvm::Triple::NaCl:
201 return new NaClTargetInfo<ARMleTargetInfo>(Triple, Opts);
202 case llvm::Triple::Win32:
203 switch (Triple.getEnvironment()) {
204 case llvm::Triple::Cygnus:
205 return new CygwinARMTargetInfo(Triple, Opts);
206 case llvm::Triple::GNU:
207 return new MinGWARMTargetInfo(Triple, Opts);
208 case llvm::Triple::Itanium:
209 return new ItaniumWindowsARMleTargetInfo(Triple, Opts);
210 case llvm::Triple::MSVC:
211 default: // Assume MSVC for unknown environments
212 return new MicrosoftARMleTargetInfo(Triple, Opts);
213 }
214 default:
215 return new ARMleTargetInfo(Triple, Opts);
216 }
217
218 case llvm::Triple::armeb:
219 case llvm::Triple::thumbeb:
220 if (Triple.isOSDarwin())
221 return new DarwinARMTargetInfo(Triple, Opts);
222
223 switch (os) {
224 case llvm::Triple::Linux:
225 return new LinuxTargetInfo<ARMbeTargetInfo>(Triple, Opts);
226 case llvm::Triple::FreeBSD:
227 return new FreeBSDTargetInfo<ARMbeTargetInfo>(Triple, Opts);
228 case llvm::Triple::NetBSD:
229 return new NetBSDTargetInfo<ARMbeTargetInfo>(Triple, Opts);
230 case llvm::Triple::OpenBSD:
231 return new OpenBSDTargetInfo<ARMbeTargetInfo>(Triple, Opts);
232 case llvm::Triple::RTEMS:
233 return new RTEMSTargetInfo<ARMbeTargetInfo>(Triple, Opts);
234 case llvm::Triple::NaCl:
235 return new NaClTargetInfo<ARMbeTargetInfo>(Triple, Opts);
236 default:
237 return new ARMbeTargetInfo(Triple, Opts);
238 }
239
240 case llvm::Triple::avr:
241 return new AVRTargetInfo(Triple, Opts);
242 case llvm::Triple::bpfeb:
243 case llvm::Triple::bpfel:
244 return new BPFTargetInfo(Triple, Opts);
245
246 case llvm::Triple::msp430:
247 return new MSP430TargetInfo(Triple, Opts);
248
249 case llvm::Triple::mips:
250 switch (os) {
251 case llvm::Triple::Linux:
252 return new LinuxTargetInfo<MipsTargetInfo>(Triple, Opts);
253 case llvm::Triple::RTEMS:
254 return new RTEMSTargetInfo<MipsTargetInfo>(Triple, Opts);
255 case llvm::Triple::FreeBSD:
256 return new FreeBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
257 case llvm::Triple::NetBSD:
258 return new NetBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
259 default:
260 return new MipsTargetInfo(Triple, Opts);
261 }
262
263 case llvm::Triple::mipsel:
264 switch (os) {
265 case llvm::Triple::Linux:
266 return new LinuxTargetInfo<MipsTargetInfo>(Triple, Opts);
267 case llvm::Triple::RTEMS:
268 return new RTEMSTargetInfo<MipsTargetInfo>(Triple, Opts);
269 case llvm::Triple::FreeBSD:
270 return new FreeBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
271 case llvm::Triple::NetBSD:
272 return new NetBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
273 case llvm::Triple::NaCl:
274 return new NaClTargetInfo<NaClMips32TargetInfo>(Triple, Opts);
275 default:
276 return new MipsTargetInfo(Triple, Opts);
277 }
278
279 case llvm::Triple::mips64:
280 switch (os) {
281 case llvm::Triple::Linux:
282 return new LinuxTargetInfo<MipsTargetInfo>(Triple, Opts);
283 case llvm::Triple::RTEMS:
284 return new RTEMSTargetInfo<MipsTargetInfo>(Triple, Opts);
285 case llvm::Triple::FreeBSD:
286 return new FreeBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
287 case llvm::Triple::NetBSD:
288 return new NetBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
289 case llvm::Triple::OpenBSD:
290 return new OpenBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
291 default:
292 return new MipsTargetInfo(Triple, Opts);
293 }
294
295 case llvm::Triple::mips64el:
296 switch (os) {
297 case llvm::Triple::Linux:
298 return new LinuxTargetInfo<MipsTargetInfo>(Triple, Opts);
299 case llvm::Triple::RTEMS:
300 return new RTEMSTargetInfo<MipsTargetInfo>(Triple, Opts);
301 case llvm::Triple::FreeBSD:
302 return new FreeBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
303 case llvm::Triple::NetBSD:
304 return new NetBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
305 case llvm::Triple::OpenBSD:
306 return new OpenBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
307 default:
308 return new MipsTargetInfo(Triple, Opts);
309 }
310
311 case llvm::Triple::le32:
312 switch (os) {
313 case llvm::Triple::NaCl:
314 return new NaClTargetInfo<PNaClTargetInfo>(Triple, Opts);
315 default:
316 return nullptr;
317 }
318
319 case llvm::Triple::le64:
320 return new Le64TargetInfo(Triple, Opts);
321
322 case llvm::Triple::ppc:
323 if (Triple.isOSDarwin())
324 return new DarwinPPC32TargetInfo(Triple, Opts);
325 switch (os) {
326 case llvm::Triple::Linux:
327 return new LinuxTargetInfo<PPC32TargetInfo>(Triple, Opts);
328 case llvm::Triple::FreeBSD:
329 return new FreeBSDTargetInfo<PPC32TargetInfo>(Triple, Opts);
330 case llvm::Triple::NetBSD:
331 return new NetBSDTargetInfo<PPC32TargetInfo>(Triple, Opts);
332 case llvm::Triple::OpenBSD:
333 return new OpenBSDTargetInfo<PPC32TargetInfo>(Triple, Opts);
334 case llvm::Triple::RTEMS:
335 return new RTEMSTargetInfo<PPC32TargetInfo>(Triple, Opts);
336 default:
337 return new PPC32TargetInfo(Triple, Opts);
338 }
339
340 case llvm::Triple::ppc64:
341 if (Triple.isOSDarwin())
342 return new DarwinPPC64TargetInfo(Triple, Opts);
343 switch (os) {
344 case llvm::Triple::Linux:
345 return new LinuxTargetInfo<PPC64TargetInfo>(Triple, Opts);
346 case llvm::Triple::Lv2:
347 return new PS3PPUTargetInfo<PPC64TargetInfo>(Triple, Opts);
348 case llvm::Triple::FreeBSD:
349 return new FreeBSDTargetInfo<PPC64TargetInfo>(Triple, Opts);
350 case llvm::Triple::NetBSD:
351 return new NetBSDTargetInfo<PPC64TargetInfo>(Triple, Opts);
352 default:
353 return new PPC64TargetInfo(Triple, Opts);
354 }
355
356 case llvm::Triple::ppc64le:
357 switch (os) {
358 case llvm::Triple::Linux:
359 return new LinuxTargetInfo<PPC64TargetInfo>(Triple, Opts);
360 case llvm::Triple::NetBSD:
361 return new NetBSDTargetInfo<PPC64TargetInfo>(Triple, Opts);
362 default:
363 return new PPC64TargetInfo(Triple, Opts);
364 }
365
366 case llvm::Triple::nvptx:
367 return new NVPTXTargetInfo(Triple, Opts, /*TargetPointerWidth=*/32);
368 case llvm::Triple::nvptx64:
369 return new NVPTXTargetInfo(Triple, Opts, /*TargetPointerWidth=*/64);
370
371 case llvm::Triple::amdgcn:
372 case llvm::Triple::r600:
373 return new AMDGPUTargetInfo(Triple, Opts);
374
375 case llvm::Triple::riscv32:
376 // TODO: add cases for FreeBSD, NetBSD, RTEMS once tested.
377 if (os == llvm::Triple::Linux)
378 return new LinuxTargetInfo<RISCV32TargetInfo>(Triple, Opts);
379 return new RISCV32TargetInfo(Triple, Opts);
380 case llvm::Triple::riscv64:
381 // TODO: add cases for FreeBSD, NetBSD, RTEMS once tested.
382 if (os == llvm::Triple::Linux)
383 return new LinuxTargetInfo<RISCV64TargetInfo>(Triple, Opts);
384 return new RISCV64TargetInfo(Triple, Opts);
385
386 case llvm::Triple::sparc:
387 switch (os) {
388 case llvm::Triple::Linux:
389 return new LinuxTargetInfo<SparcV8TargetInfo>(Triple, Opts);
390 case llvm::Triple::Solaris:
391 return new SolarisTargetInfo<SparcV8TargetInfo>(Triple, Opts);
392 case llvm::Triple::NetBSD:
393 return new NetBSDTargetInfo<SparcV8TargetInfo>(Triple, Opts);
394 case llvm::Triple::OpenBSD:
395 return new OpenBSDTargetInfo<SparcV8TargetInfo>(Triple, Opts);
396 case llvm::Triple::RTEMS:
397 return new RTEMSTargetInfo<SparcV8TargetInfo>(Triple, Opts);
398 default:
399 return new SparcV8TargetInfo(Triple, Opts);
400 }
401
402 // The 'sparcel' architecture copies all the above cases except for Solaris.
403 case llvm::Triple::sparcel:
404 switch (os) {
405 case llvm::Triple::Linux:
406 return new LinuxTargetInfo<SparcV8elTargetInfo>(Triple, Opts);
407 case llvm::Triple::NetBSD:
408 return new NetBSDTargetInfo<SparcV8elTargetInfo>(Triple, Opts);
409 case llvm::Triple::OpenBSD:
410 return new OpenBSDTargetInfo<SparcV8elTargetInfo>(Triple, Opts);
411 case llvm::Triple::RTEMS:
412 return new RTEMSTargetInfo<SparcV8elTargetInfo>(Triple, Opts);
413 default:
414 return new SparcV8elTargetInfo(Triple, Opts);
415 }
416
417 case llvm::Triple::sparcv9:
418 switch (os) {
419 case llvm::Triple::Linux:
420 return new LinuxTargetInfo<SparcV9TargetInfo>(Triple, Opts);
421 case llvm::Triple::Solaris:
422 return new SolarisTargetInfo<SparcV9TargetInfo>(Triple, Opts);
423 case llvm::Triple::NetBSD:
424 return new NetBSDTargetInfo<SparcV9TargetInfo>(Triple, Opts);
425 case llvm::Triple::OpenBSD:
426 return new OpenBSDTargetInfo<SparcV9TargetInfo>(Triple, Opts);
427 case llvm::Triple::FreeBSD:
428 return new FreeBSDTargetInfo<SparcV9TargetInfo>(Triple, Opts);
429 default:
430 return new SparcV9TargetInfo(Triple, Opts);
431 }
432
433 case llvm::Triple::systemz:
434 switch (os) {
435 case llvm::Triple::Linux:
436 return new LinuxTargetInfo<SystemZTargetInfo>(Triple, Opts);
437 default:
438 return new SystemZTargetInfo(Triple, Opts);
439 }
440
441 case llvm::Triple::tce:
442 return new TCETargetInfo(Triple, Opts);
443
444 case llvm::Triple::tcele:
445 return new TCELETargetInfo(Triple, Opts);
446
447 case llvm::Triple::x86:
448 if (Triple.isOSDarwin())
449 return new DarwinI386TargetInfo(Triple, Opts);
450
451 switch (os) {
452 case llvm::Triple::Ananas:
453 return new AnanasTargetInfo<X86_32TargetInfo>(Triple, Opts);
454 case llvm::Triple::CloudABI:
455 return new CloudABITargetInfo<X86_32TargetInfo>(Triple, Opts);
456 case llvm::Triple::Linux: {
457 switch (Triple.getEnvironment()) {
458 default:
459 return new LinuxTargetInfo<X86_32TargetInfo>(Triple, Opts);
460 case llvm::Triple::Android:
461 return new AndroidX86_32TargetInfo(Triple, Opts);
462 }
463 }
464 case llvm::Triple::DragonFly:
465 return new DragonFlyBSDTargetInfo<X86_32TargetInfo>(Triple, Opts);
466 case llvm::Triple::NetBSD:
467 return new NetBSDI386TargetInfo(Triple, Opts);
468 case llvm::Triple::OpenBSD:
469 return new OpenBSDI386TargetInfo(Triple, Opts);
470 case llvm::Triple::FreeBSD:
471 return new FreeBSDTargetInfo<X86_32TargetInfo>(Triple, Opts);
472 case llvm::Triple::KFreeBSD:
473 return new KFreeBSDTargetInfo<X86_32TargetInfo>(Triple, Opts);
474 case llvm::Triple::Minix:
475 return new MinixTargetInfo<X86_32TargetInfo>(Triple, Opts);
476 case llvm::Triple::Solaris:
477 return new SolarisTargetInfo<X86_32TargetInfo>(Triple, Opts);
478 case llvm::Triple::Win32: {
479 switch (Triple.getEnvironment()) {
480 case llvm::Triple::Cygnus:
481 return new CygwinX86_32TargetInfo(Triple, Opts);
482 case llvm::Triple::GNU:
483 return new MinGWX86_32TargetInfo(Triple, Opts);
484 case llvm::Triple::Itanium:
485 case llvm::Triple::MSVC:
486 default: // Assume MSVC for unknown environments
487 return new MicrosoftX86_32TargetInfo(Triple, Opts);
488 }
489 }
490 case llvm::Triple::Haiku:
491 return new HaikuX86_32TargetInfo(Triple, Opts);
492 case llvm::Triple::RTEMS:
493 return new RTEMSX86_32TargetInfo(Triple, Opts);
494 case llvm::Triple::NaCl:
495 return new NaClTargetInfo<X86_32TargetInfo>(Triple, Opts);
496 case llvm::Triple::ELFIAMCU:
497 return new MCUX86_32TargetInfo(Triple, Opts);
498 case llvm::Triple::Hurd:
499 return new HurdTargetInfo<X86_32TargetInfo>(Triple, Opts);
500 default:
501 return new X86_32TargetInfo(Triple, Opts);
502 }
503
504 case llvm::Triple::x86_64:
505 if (Triple.isOSDarwin() || Triple.isOSBinFormatMachO())
506 return new DarwinX86_64TargetInfo(Triple, Opts);
507
508 switch (os) {
509 case llvm::Triple::Ananas:
510 return new AnanasTargetInfo<X86_64TargetInfo>(Triple, Opts);
511 case llvm::Triple::CloudABI:
512 return new CloudABITargetInfo<X86_64TargetInfo>(Triple, Opts);
513 case llvm::Triple::Linux: {
514 switch (Triple.getEnvironment()) {
515 default:
516 return new LinuxTargetInfo<X86_64TargetInfo>(Triple, Opts);
517 case llvm::Triple::Android:
518 return new AndroidX86_64TargetInfo(Triple, Opts);
519 }
520 }
521 case llvm::Triple::DragonFly:
522 return new DragonFlyBSDTargetInfo<X86_64TargetInfo>(Triple, Opts);
523 case llvm::Triple::NetBSD:
524 return new NetBSDTargetInfo<X86_64TargetInfo>(Triple, Opts);
525 case llvm::Triple::OpenBSD:
526 return new OpenBSDX86_64TargetInfo(Triple, Opts);
527 case llvm::Triple::FreeBSD:
528 return new FreeBSDTargetInfo<X86_64TargetInfo>(Triple, Opts);
529 case llvm::Triple::Fuchsia:
530 return new FuchsiaTargetInfo<X86_64TargetInfo>(Triple, Opts);
531 case llvm::Triple::KFreeBSD:
532 return new KFreeBSDTargetInfo<X86_64TargetInfo>(Triple, Opts);
533 case llvm::Triple::Solaris:
534 return new SolarisTargetInfo<X86_64TargetInfo>(Triple, Opts);
535 case llvm::Triple::Win32: {
536 switch (Triple.getEnvironment()) {
537 case llvm::Triple::Cygnus:
538 return new CygwinX86_64TargetInfo(Triple, Opts);
539 case llvm::Triple::GNU:
540 return new MinGWX86_64TargetInfo(Triple, Opts);
541 case llvm::Triple::MSVC:
542 default: // Assume MSVC for unknown environments
543 return new MicrosoftX86_64TargetInfo(Triple, Opts);
544 }
545 }
546 case llvm::Triple::Haiku:
547 return new HaikuTargetInfo<X86_64TargetInfo>(Triple, Opts);
548 case llvm::Triple::NaCl:
549 return new NaClTargetInfo<X86_64TargetInfo>(Triple, Opts);
550 case llvm::Triple::PS4:
551 return new PS4OSTargetInfo<X86_64TargetInfo>(Triple, Opts);
552 default:
553 return new X86_64TargetInfo(Triple, Opts);
554 }
555
556 case llvm::Triple::spir: {
557 if (Triple.getOS() != llvm::Triple::UnknownOS ||
558 Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
559 return nullptr;
560 return new SPIR32TargetInfo(Triple, Opts);
561 }
562 case llvm::Triple::spir64: {
563 if (Triple.getOS() != llvm::Triple::UnknownOS ||
564 Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
565 return nullptr;
566 return new SPIR64TargetInfo(Triple, Opts);
567 }
568 case llvm::Triple::wasm32:
569 if (Triple.getSubArch() != llvm::Triple::NoSubArch ||
570 Triple.getVendor() != llvm::Triple::UnknownVendor ||
571 !Triple.isOSBinFormatWasm())
572 return nullptr;
573 switch (Triple.getOS()) {
574 case llvm::Triple::WASI:
575 return new WASITargetInfo<WebAssembly32TargetInfo>(Triple, Opts);
576 case llvm::Triple::UnknownOS:
577 return new WebAssemblyOSTargetInfo<WebAssembly32TargetInfo>(Triple, Opts);
578 default:
579 return nullptr;
580 }
581 case llvm::Triple::wasm64:
582 if (Triple.getSubArch() != llvm::Triple::NoSubArch ||
583 Triple.getVendor() != llvm::Triple::UnknownVendor ||
584 !Triple.isOSBinFormatWasm())
585 return nullptr;
586 switch (Triple.getOS()) {
587 case llvm::Triple::WASI:
588 return new WASITargetInfo<WebAssembly64TargetInfo>(Triple, Opts);
589 case llvm::Triple::UnknownOS:
590 return new WebAssemblyOSTargetInfo<WebAssembly64TargetInfo>(Triple, Opts);
591 default:
592 return nullptr;
593 }
594
595 case llvm::Triple::renderscript32:
596 return new LinuxTargetInfo<RenderScript32TargetInfo>(Triple, Opts);
597 case llvm::Triple::renderscript64:
598 return new LinuxTargetInfo<RenderScript64TargetInfo>(Triple, Opts);
599 }
600 }
601 } // namespace targets
602 } // namespace clang
603
604 using namespace clang::targets;
605 /// CreateTargetInfo - Return the target info object for the specified target
606 /// options.
607 TargetInfo *
608 TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags,
609 const std::shared_ptr<TargetOptions> &Opts) {
610 llvm::Triple Triple(Opts->Triple);
611
612 // Construct the target
613 std::unique_ptr<TargetInfo> Target(AllocateTarget(Triple, *Opts));
614 if (!Target) {
615 Diags.Report(diag::err_target_unknown_triple) << Triple.str();
616 return nullptr;
617 }
618 Target->TargetOpts = Opts;
619
620 // Set the target CPU if specified.
621 if (!Opts->CPU.empty() && !Target->setCPU(Opts->CPU)) {
622 Diags.Report(diag::err_target_unknown_cpu) << Opts->CPU;
623 SmallVector<StringRef, 32> ValidList;
624 Target->fillValidCPUList(ValidList);
625 if (!ValidList.empty())
626 Diags.Report(diag::note_valid_options) << llvm::join(ValidList, ", ");
627 return nullptr;
628 }
629
630 // Set the target ABI if specified.
631 if (!Opts->ABI.empty() && !Target->setABI(Opts->ABI)) {
632 Diags.Report(diag::err_target_unknown_abi) << Opts->ABI;
633 return nullptr;
634 }
635
636 // Set the fp math unit.
637 if (!Opts->FPMath.empty() && !Target->setFPMath(Opts->FPMath)) {
638 Diags.Report(diag::err_target_unknown_fpmath) << Opts->FPMath;
639 return nullptr;
640 }
641
642 // Compute the default target features, we need the target to handle this
643 // because features may have dependencies on one another.
644 llvm::StringMap<bool> Features;
645 if (!Target->initFeatureMap(Features, Diags, Opts->CPU,
646 Opts->FeaturesAsWritten))
647 return nullptr;
648
649 // Add the features to the compile options.
650 Opts->Features.clear();
651 for (const auto &F : Features)
652 Opts->Features.push_back((F.getValue() ? "+" : "-") + F.getKey().str());
653 // Sort here, so we handle the features in a predictable order. (This matters
654 // when we're dealing with features that overlap.)
655 llvm::sort(Opts->Features);
656
657 if (!Target->handleTargetFeatures(Opts->Features, Diags))
658 return nullptr;
659
660 Target->setSupportedOpenCLOpts();
661 Target->setOpenCLExtensionOpts();
662 Target->setMaxAtomicWidth();
663
664 if (!Target->validateTarget(Diags))
665 return nullptr;
666
667 Target->CheckFixedPointBits();
668
669 return Target.release();
670 }
clang::targets::MinGWX86_32TargetInfo
Definition: X86.h:488
clang::targets::PPC64TargetInfo
Definition: PPC.h:351
clang::targets::MinGWARM64TargetInfo
Definition: AArch64.h:135
clang::targets::LinuxTargetInfo
Definition: OSTargets.h:341
clang::targets::NVPTXTargetInfo
Definition: NVPTX.h:39
clang::targets::DefineStd
void DefineStd(MacroBuilder &Builder, StringRef MacroName, const LangOptions &Opts)
DefineStd - Define a macro name and standard variants.
Definition: Targets.cpp:55
clang::targets::SPIR64TargetInfo
Definition: SPIR.h:117
TCE.h
clang::targets::MCUX86_32TargetInfo
Definition: X86.h:541
clang::targets::LanaiTargetInfo
Definition: Lanai.h:25
clang::targets
Definition: AArch64.h:22
clang::targets::DarwinPPC64TargetInfo
Definition: PPC.h:420
clang::targets::SparcV9TargetInfo
Definition: Sparc.h:192
clang::targets::ARCTargetInfo
Definition: ARC.h:25
clang::targets::CygwinARMTargetInfo
Definition: ARM.h:232
clang::DiagnosticsEngine::Report
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1295
clang::targets::MicrosoftX86_32TargetInfo
Definition: X86.h:466
clang::targets::AArch64beTargetInfo
Definition: AArch64.h:141
PNaCl.h
clang::targets::DarwinPPC32TargetInfo
Definition: PPC.h:403
clang::TargetOptions
Options for controlling the target.
Definition: TargetOptions.h:27
clang::targets::MicrosoftARM64TargetInfo
Definition: AArch64.h:120
clang::targets::MinixTargetInfo
Definition: OSTargets.h:317
clang::MultiVersionKind::Target
clang::targets::RTEMSTargetInfo
Definition: OSTargets.h:538
Le64.h
NVPTX.h
clang::targets::ARMbeTargetInfo
Definition: ARM.h:178
X86.h
clang::targets::XCoreTargetInfo
Definition: XCore.h:25
clang::targets::DarwinAArch64TargetInfo
Definition: AArch64.h:151
clang::targets::HurdTargetInfo
Definition: OSTargets.h:294
clang::targets::AndroidX86_32TargetInfo
Definition: X86.h:826
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
AMDGPU.h
clang::targets::SystemZTargetInfo
Definition: SystemZ.h:25
AVR.h
clang::targets::WebAssemblyOSTargetInfo
Definition: OSTargets.h:765
BPF.h
OSTargets.h
clang::DiagnosticsEngine
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
MSP430.h
Diagnostic.h
Defines the Diagnostic-related interfaces.
clang::targets::WASITargetInfo
Definition: OSTargets.h:789
clang::targets::DarwinI386TargetInfo
Definition: X86.h:419
ARM.h
clang::targets::PS3PPUTargetInfo
Definition: OSTargets.h:475
clang::targets::RISCV64TargetInfo
Definition: RISCV.h:93
clang::targets::PPC32TargetInfo
Definition: PPC.h:316
Hexagon.h
clang::targets::FreeBSDTargetInfo
Definition: OSTargets.h:182
clang::targets::TCELETargetInfo
Definition: TCE.h:105
clang::targets::DarwinARMTargetInfo
Definition: ARM.h:240
clang::targets::addMinGWDefines
void addMinGWDefines(const llvm::Triple &Triple, const LangOptions &Opts, MacroBuilder &Builder)
Definition: Targets.cpp:102
clang::targets::CloudABITargetInfo
Definition: OSTargets.h:41
clang::targets::DragonFlyBSDTargetInfo
Definition: OSTargets.h:149
clang::targets::OpenBSDX86_64TargetInfo
Definition: X86.h:815
SystemZ.h
clang::targets::MinGWX86_64TargetInfo
Definition: X86.h:755
clang::targets::MSP430TargetInfo
Definition: MSP430.h:25
clang::TargetInfo
Exposes information about the current target.
Definition: TargetInfo.h:54
clang::targets::TCETargetInfo
Definition: TCE.h:46
clang::targets::NetBSDI386TargetInfo
Definition: X86.h:391
clang::targets::HexagonTargetInfo
Definition: Hexagon.h:26
clang::targets::RISCV32TargetInfo
Definition: RISCV.h:74
clang::targets::SparcV8elTargetInfo
Definition: Sparc.h:183
clang::TargetInfo::CreateTargetInfo
static TargetInfo * CreateTargetInfo(DiagnosticsEngine &Diags, const std::shared_ptr< TargetOptions > &Opts)
Construct a target for the given options.
Definition: Targets.cpp:608
clang::targets::MicrosoftX86_64TargetInfo
Definition: X86.h:730
clang::targets::RTEMSX86_32TargetInfo
Definition: X86.h:567
clang::targets::SolarisTargetInfo
Definition: OSTargets.h:574
clang::targets::NaClTargetInfo
Definition: OSTargets.h:693
clang::targets::BPFTargetInfo
Definition: BPF.h:25
clang::targets::AllocateTarget
TargetInfo * AllocateTarget(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: Targets.cpp:119
WebAssembly.h
clang::targets::OpenBSDI386TargetInfo
Definition: X86.h:408
Sparc.h
clang::targets::ItaniumWindowsARMleTargetInfo
Definition: ARM.h:201
clang::targets::addCygMingDefines
void addCygMingDefines(const LangOptions &Opts, MacroBuilder &Builder)
Definition: Targets.cpp:78
clang::targets::OpenBSDTargetInfo
Definition: OSTargets.h:420
Lanai.h
clang::targets::AArch64leTargetInfo
Definition: AArch64.h:94
clang::targets::HaikuX86_32TargetInfo
Definition: X86.h:527
llvm::SmallVector
Definition: LLVM.h:36
clang::targets::MicrosoftARMleTargetInfo
Definition: ARM.h:212
clang::targets::SparcV8TargetInfo
Definition: Sparc.h:151
clang::targets::KFreeBSDTargetInfo
Definition: OSTargets.h:238
Targets.h
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::targets::ARMleTargetInfo
Definition: ARM.h:171
RISCV.h
clang::targets::AVRTargetInfo
Definition: AVR.h:26
clang::targets::AndroidX86_64TargetInfo
Definition: X86.h:838
clang::targets::SPIR32TargetInfo
Definition: SPIR.h:102
clang::targets::CygwinX86_32TargetInfo
Definition: X86.h:504
clang::targets::MipsTargetInfo
Definition: Mips.h:25
clang::targets::HaikuTargetInfo
Definition: OSTargets.h:261
AArch64.h
clang::targets::NetBSDTargetInfo
Definition: OSTargets.h:399
SPIR.h
clang::targets::AMDGPUTargetInfo
Definition: AMDGPU.h:27
Mips.h
clang::MacroBuilder
Definition: MacroBuilder.h:24
clang::targets::AnanasTargetInfo
Definition: OSTargets.h:61
clang::targets::FuchsiaTargetInfo
Definition: OSTargets.h:743
clang::targets::MinGWARMTargetInfo
Definition: ARM.h:223
clang::targets::X86_32TargetInfo
Definition: X86.h:330
XCore.h
clang::targets::Le64TargetInfo
Definition: Le64.h:25
clang::targets::X86_64TargetInfo
Definition: X86.h:585
clang::targets::defineCPUMacros
void defineCPUMacros(MacroBuilder &Builder, StringRef CPUName, bool Tuning)
Definition: Targets.cpp:71
PPC.h
clang::targets::PS4OSTargetInfo
Definition: OSTargets.h:502
clang::MacroBuilder::defineMacro
void defineMacro(const Twine &Name, const Twine &Value="1")
Append a #define line for macro of the form "\#define Name Value\n".
Definition: MacroBuilder.h:30
clang::targets::DarwinX86_64TargetInfo
Definition: X86.h:790
ARC.h
clang::targets::CygwinX86_64TargetInfo
Definition: X86.h:769