clang  7.0.0svn
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/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/Nios2.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/Triple.h"
42 
43 using namespace clang;
44 
45 namespace clang {
46 namespace targets {
47 //===----------------------------------------------------------------------===//
48 // Common code shared among targets.
49 //===----------------------------------------------------------------------===//
50 
51 /// DefineStd - Define a macro name and standard variants. For example if
52 /// MacroName is "unix", then this will define "__unix", "__unix__", and "unix"
53 /// when in GNU mode.
54 void DefineStd(MacroBuilder &Builder, StringRef MacroName,
55  const LangOptions &Opts) {
56  assert(MacroName[0] != '_' && "Identifier should be in the user's namespace");
57 
58  // If in GNU mode (e.g. -std=gnu99 but not -std=c99) define the raw identifier
59  // in the user's namespace.
60  if (Opts.GNUMode)
61  Builder.defineMacro(MacroName);
62 
63  // Define __unix.
64  Builder.defineMacro("__" + MacroName);
65 
66  // Define __unix__.
67  Builder.defineMacro("__" + MacroName + "__");
68 }
69 
70 void defineCPUMacros(MacroBuilder &Builder, StringRef CPUName, bool Tuning) {
71  Builder.defineMacro("__" + CPUName);
72  Builder.defineMacro("__" + CPUName + "__");
73  if (Tuning)
74  Builder.defineMacro("__tune_" + CPUName + "__");
75 }
76 
77 void addCygMingDefines(const LangOptions &Opts, MacroBuilder &Builder) {
78  // Mingw and cygwin define __declspec(a) to __attribute__((a)). Clang
79  // supports __declspec natively under -fms-extensions, but we define a no-op
80  // __declspec macro anyway for pre-processor compatibility.
81  if (Opts.MicrosoftExt)
82  Builder.defineMacro("__declspec", "__declspec");
83  else
84  Builder.defineMacro("__declspec(a)", "__attribute__((a))");
85 
86  if (!Opts.MicrosoftExt) {
87  // Provide macros for all the calling convention keywords. Provide both
88  // single and double underscore prefixed variants. These are available on
89  // x64 as well as x86, even though they have no effect.
90  const char *CCs[] = {"cdecl", "stdcall", "fastcall", "thiscall", "pascal"};
91  for (const char *CC : CCs) {
92  std::string GCCSpelling = "__attribute__((__";
93  GCCSpelling += CC;
94  GCCSpelling += "__))";
95  Builder.defineMacro(Twine("_") + CC, GCCSpelling);
96  Builder.defineMacro(Twine("__") + CC, GCCSpelling);
97  }
98  }
99 }
100 
101 void addMinGWDefines(const llvm::Triple &Triple, const LangOptions &Opts,
102  MacroBuilder &Builder) {
103  DefineStd(Builder, "WIN32", Opts);
104  DefineStd(Builder, "WINNT", Opts);
105  if (Triple.isArch64Bit()) {
106  DefineStd(Builder, "WIN64", Opts);
107  Builder.defineMacro("__MINGW64__");
108  }
109  Builder.defineMacro("__MSVCRT__");
110  Builder.defineMacro("__MINGW32__");
111  addCygMingDefines(Opts, Builder);
112 }
113 
114 //===----------------------------------------------------------------------===//
115 // Driver code
116 //===----------------------------------------------------------------------===//
117 
118 TargetInfo *AllocateTarget(const llvm::Triple &Triple,
119  const TargetOptions &Opts) {
120  llvm::Triple::OSType os = Triple.getOS();
121 
122  switch (Triple.getArch()) {
123  default:
124  return nullptr;
125 
126  case llvm::Triple::xcore:
127  return new XCoreTargetInfo(Triple, Opts);
128 
129  case llvm::Triple::hexagon:
130  return new HexagonTargetInfo(Triple, Opts);
131 
132  case llvm::Triple::lanai:
133  return new LanaiTargetInfo(Triple, Opts);
134 
135  case llvm::Triple::aarch64:
136  if (Triple.isOSDarwin())
137  return new DarwinAArch64TargetInfo(Triple, Opts);
138 
139  switch (os) {
140  case llvm::Triple::CloudABI:
141  return new CloudABITargetInfo<AArch64leTargetInfo>(Triple, Opts);
142  case llvm::Triple::FreeBSD:
143  return new FreeBSDTargetInfo<AArch64leTargetInfo>(Triple, Opts);
144  case llvm::Triple::Fuchsia:
145  return new FuchsiaTargetInfo<AArch64leTargetInfo>(Triple, Opts);
146  case llvm::Triple::Linux:
147  return new LinuxTargetInfo<AArch64leTargetInfo>(Triple, Opts);
148  case llvm::Triple::NetBSD:
149  return new NetBSDTargetInfo<AArch64leTargetInfo>(Triple, Opts);
150  case llvm::Triple::OpenBSD:
151  return new OpenBSDTargetInfo<AArch64leTargetInfo>(Triple, Opts);
152  case llvm::Triple::Win32:
153  switch (Triple.getEnvironment()) {
154  case llvm::Triple::GNU:
155  return new MinGWARM64TargetInfo(Triple, Opts);
156  case llvm::Triple::MSVC:
157  default: // Assume MSVC for unknown environments
158  return new MicrosoftARM64TargetInfo(Triple, Opts);
159  }
160  default:
161  return new AArch64leTargetInfo(Triple, Opts);
162  }
163 
164  case llvm::Triple::aarch64_be:
165  switch (os) {
166  case llvm::Triple::FreeBSD:
167  return new FreeBSDTargetInfo<AArch64beTargetInfo>(Triple, Opts);
168  case llvm::Triple::Fuchsia:
169  return new FuchsiaTargetInfo<AArch64beTargetInfo>(Triple, Opts);
170  case llvm::Triple::Linux:
171  return new LinuxTargetInfo<AArch64beTargetInfo>(Triple, Opts);
172  case llvm::Triple::NetBSD:
173  return new NetBSDTargetInfo<AArch64beTargetInfo>(Triple, Opts);
174  default:
175  return new AArch64beTargetInfo(Triple, Opts);
176  }
177 
178  case llvm::Triple::arm:
179  case llvm::Triple::thumb:
180  if (Triple.isOSBinFormatMachO())
181  return new DarwinARMTargetInfo(Triple, Opts);
182 
183  switch (os) {
184  case llvm::Triple::CloudABI:
185  return new CloudABITargetInfo<ARMleTargetInfo>(Triple, Opts);
186  case llvm::Triple::Linux:
187  return new LinuxTargetInfo<ARMleTargetInfo>(Triple, Opts);
188  case llvm::Triple::FreeBSD:
189  return new FreeBSDTargetInfo<ARMleTargetInfo>(Triple, Opts);
190  case llvm::Triple::NetBSD:
191  return new NetBSDTargetInfo<ARMleTargetInfo>(Triple, Opts);
192  case llvm::Triple::OpenBSD:
193  return new OpenBSDTargetInfo<ARMleTargetInfo>(Triple, Opts);
194  case llvm::Triple::RTEMS:
195  return new RTEMSTargetInfo<ARMleTargetInfo>(Triple, Opts);
196  case llvm::Triple::NaCl:
197  return new NaClTargetInfo<ARMleTargetInfo>(Triple, Opts);
198  case llvm::Triple::Win32:
199  switch (Triple.getEnvironment()) {
200  case llvm::Triple::Cygnus:
201  return new CygwinARMTargetInfo(Triple, Opts);
202  case llvm::Triple::GNU:
203  return new MinGWARMTargetInfo(Triple, Opts);
204  case llvm::Triple::Itanium:
205  return new ItaniumWindowsARMleTargetInfo(Triple, Opts);
206  case llvm::Triple::MSVC:
207  default: // Assume MSVC for unknown environments
208  return new MicrosoftARMleTargetInfo(Triple, Opts);
209  }
210  default:
211  return new ARMleTargetInfo(Triple, Opts);
212  }
213 
214  case llvm::Triple::armeb:
215  case llvm::Triple::thumbeb:
216  if (Triple.isOSDarwin())
217  return new DarwinARMTargetInfo(Triple, Opts);
218 
219  switch (os) {
220  case llvm::Triple::Linux:
221  return new LinuxTargetInfo<ARMbeTargetInfo>(Triple, Opts);
222  case llvm::Triple::FreeBSD:
223  return new FreeBSDTargetInfo<ARMbeTargetInfo>(Triple, Opts);
224  case llvm::Triple::NetBSD:
225  return new NetBSDTargetInfo<ARMbeTargetInfo>(Triple, Opts);
226  case llvm::Triple::OpenBSD:
227  return new OpenBSDTargetInfo<ARMbeTargetInfo>(Triple, Opts);
228  case llvm::Triple::RTEMS:
229  return new RTEMSTargetInfo<ARMbeTargetInfo>(Triple, Opts);
230  case llvm::Triple::NaCl:
231  return new NaClTargetInfo<ARMbeTargetInfo>(Triple, Opts);
232  default:
233  return new ARMbeTargetInfo(Triple, Opts);
234  }
235 
236  case llvm::Triple::avr:
237  return new AVRTargetInfo(Triple, Opts);
238  case llvm::Triple::bpfeb:
239  case llvm::Triple::bpfel:
240  return new BPFTargetInfo(Triple, Opts);
241 
242  case llvm::Triple::msp430:
243  return new MSP430TargetInfo(Triple, Opts);
244 
245  case llvm::Triple::nios2:
246  return new LinuxTargetInfo<Nios2TargetInfo>(Triple, Opts);
247 
248  case llvm::Triple::mips:
249  switch (os) {
250  case llvm::Triple::Linux:
251  return new LinuxTargetInfo<MipsTargetInfo>(Triple, Opts);
252  case llvm::Triple::RTEMS:
253  return new RTEMSTargetInfo<MipsTargetInfo>(Triple, Opts);
254  case llvm::Triple::FreeBSD:
255  return new FreeBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
256  case llvm::Triple::NetBSD:
257  return new NetBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
258  default:
259  return new MipsTargetInfo(Triple, Opts);
260  }
261 
262  case llvm::Triple::mipsel:
263  switch (os) {
264  case llvm::Triple::Linux:
265  return new LinuxTargetInfo<MipsTargetInfo>(Triple, Opts);
266  case llvm::Triple::RTEMS:
267  return new RTEMSTargetInfo<MipsTargetInfo>(Triple, Opts);
268  case llvm::Triple::FreeBSD:
269  return new FreeBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
270  case llvm::Triple::NetBSD:
271  return new NetBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
272  case llvm::Triple::NaCl:
273  return new NaClTargetInfo<NaClMips32TargetInfo>(Triple, Opts);
274  default:
275  return new MipsTargetInfo(Triple, Opts);
276  }
277 
278  case llvm::Triple::mips64:
279  switch (os) {
280  case llvm::Triple::Linux:
281  return new LinuxTargetInfo<MipsTargetInfo>(Triple, Opts);
282  case llvm::Triple::RTEMS:
283  return new RTEMSTargetInfo<MipsTargetInfo>(Triple, Opts);
284  case llvm::Triple::FreeBSD:
285  return new FreeBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
286  case llvm::Triple::NetBSD:
287  return new NetBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
288  case llvm::Triple::OpenBSD:
289  return new OpenBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
290  default:
291  return new MipsTargetInfo(Triple, Opts);
292  }
293 
294  case llvm::Triple::mips64el:
295  switch (os) {
296  case llvm::Triple::Linux:
297  return new LinuxTargetInfo<MipsTargetInfo>(Triple, Opts);
298  case llvm::Triple::RTEMS:
299  return new RTEMSTargetInfo<MipsTargetInfo>(Triple, Opts);
300  case llvm::Triple::FreeBSD:
301  return new FreeBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
302  case llvm::Triple::NetBSD:
303  return new NetBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
304  case llvm::Triple::OpenBSD:
305  return new OpenBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
306  default:
307  return new MipsTargetInfo(Triple, Opts);
308  }
309 
310  case llvm::Triple::le32:
311  switch (os) {
312  case llvm::Triple::NaCl:
313  return new NaClTargetInfo<PNaClTargetInfo>(Triple, Opts);
314  default:
315  return nullptr;
316  }
317 
318  case llvm::Triple::le64:
319  return new Le64TargetInfo(Triple, Opts);
320 
321  case llvm::Triple::ppc:
322  if (Triple.isOSDarwin())
323  return new DarwinPPC32TargetInfo(Triple, Opts);
324  switch (os) {
325  case llvm::Triple::Linux:
326  return new LinuxTargetInfo<PPC32TargetInfo>(Triple, Opts);
327  case llvm::Triple::FreeBSD:
328  return new FreeBSDTargetInfo<PPC32TargetInfo>(Triple, Opts);
329  case llvm::Triple::NetBSD:
330  return new NetBSDTargetInfo<PPC32TargetInfo>(Triple, Opts);
331  case llvm::Triple::OpenBSD:
332  return new OpenBSDTargetInfo<PPC32TargetInfo>(Triple, Opts);
333  case llvm::Triple::RTEMS:
334  return new RTEMSTargetInfo<PPC32TargetInfo>(Triple, Opts);
335  default:
336  return new PPC32TargetInfo(Triple, Opts);
337  }
338 
339  case llvm::Triple::ppc64:
340  if (Triple.isOSDarwin())
341  return new DarwinPPC64TargetInfo(Triple, Opts);
342  switch (os) {
343  case llvm::Triple::Linux:
344  return new LinuxTargetInfo<PPC64TargetInfo>(Triple, Opts);
345  case llvm::Triple::Lv2:
346  return new PS3PPUTargetInfo<PPC64TargetInfo>(Triple, Opts);
347  case llvm::Triple::FreeBSD:
348  return new FreeBSDTargetInfo<PPC64TargetInfo>(Triple, Opts);
349  case llvm::Triple::NetBSD:
350  return new NetBSDTargetInfo<PPC64TargetInfo>(Triple, Opts);
351  default:
352  return new PPC64TargetInfo(Triple, Opts);
353  }
354 
355  case llvm::Triple::ppc64le:
356  switch (os) {
357  case llvm::Triple::Linux:
358  return new LinuxTargetInfo<PPC64TargetInfo>(Triple, Opts);
359  case llvm::Triple::NetBSD:
360  return new NetBSDTargetInfo<PPC64TargetInfo>(Triple, Opts);
361  default:
362  return new PPC64TargetInfo(Triple, Opts);
363  }
364 
365  case llvm::Triple::nvptx:
366  return new NVPTXTargetInfo(Triple, Opts, /*TargetPointerWidth=*/32);
367  case llvm::Triple::nvptx64:
368  return new NVPTXTargetInfo(Triple, Opts, /*TargetPointerWidth=*/64);
369 
370  case llvm::Triple::amdgcn:
371  case llvm::Triple::r600:
372  return new AMDGPUTargetInfo(Triple, Opts);
373 
374  case llvm::Triple::riscv32:
375  return new RISCV32TargetInfo(Triple, Opts);
376  case llvm::Triple::riscv64:
377  return new RISCV64TargetInfo(Triple, Opts);
378 
379  case llvm::Triple::sparc:
380  switch (os) {
381  case llvm::Triple::Linux:
382  return new LinuxTargetInfo<SparcV8TargetInfo>(Triple, Opts);
383  case llvm::Triple::Solaris:
384  return new SolarisTargetInfo<SparcV8TargetInfo>(Triple, Opts);
385  case llvm::Triple::NetBSD:
386  return new NetBSDTargetInfo<SparcV8TargetInfo>(Triple, Opts);
387  case llvm::Triple::OpenBSD:
388  return new OpenBSDTargetInfo<SparcV8TargetInfo>(Triple, Opts);
389  case llvm::Triple::RTEMS:
390  return new RTEMSTargetInfo<SparcV8TargetInfo>(Triple, Opts);
391  default:
392  return new SparcV8TargetInfo(Triple, Opts);
393  }
394 
395  // The 'sparcel' architecture copies all the above cases except for Solaris.
396  case llvm::Triple::sparcel:
397  switch (os) {
398  case llvm::Triple::Linux:
399  return new LinuxTargetInfo<SparcV8elTargetInfo>(Triple, Opts);
400  case llvm::Triple::NetBSD:
401  return new NetBSDTargetInfo<SparcV8elTargetInfo>(Triple, Opts);
402  case llvm::Triple::OpenBSD:
403  return new OpenBSDTargetInfo<SparcV8elTargetInfo>(Triple, Opts);
404  case llvm::Triple::RTEMS:
405  return new RTEMSTargetInfo<SparcV8elTargetInfo>(Triple, Opts);
406  default:
407  return new SparcV8elTargetInfo(Triple, Opts);
408  }
409 
410  case llvm::Triple::sparcv9:
411  switch (os) {
412  case llvm::Triple::Linux:
413  return new LinuxTargetInfo<SparcV9TargetInfo>(Triple, Opts);
414  case llvm::Triple::Solaris:
415  return new SolarisTargetInfo<SparcV9TargetInfo>(Triple, Opts);
416  case llvm::Triple::NetBSD:
417  return new NetBSDTargetInfo<SparcV9TargetInfo>(Triple, Opts);
418  case llvm::Triple::OpenBSD:
419  return new OpenBSDTargetInfo<SparcV9TargetInfo>(Triple, Opts);
420  case llvm::Triple::FreeBSD:
421  return new FreeBSDTargetInfo<SparcV9TargetInfo>(Triple, Opts);
422  default:
423  return new SparcV9TargetInfo(Triple, Opts);
424  }
425 
426  case llvm::Triple::systemz:
427  switch (os) {
428  case llvm::Triple::Linux:
429  return new LinuxTargetInfo<SystemZTargetInfo>(Triple, Opts);
430  default:
431  return new SystemZTargetInfo(Triple, Opts);
432  }
433 
434  case llvm::Triple::tce:
435  return new TCETargetInfo(Triple, Opts);
436 
437  case llvm::Triple::tcele:
438  return new TCELETargetInfo(Triple, Opts);
439 
440  case llvm::Triple::x86:
441  if (Triple.isOSDarwin())
442  return new DarwinI386TargetInfo(Triple, Opts);
443 
444  switch (os) {
445  case llvm::Triple::Ananas:
446  return new AnanasTargetInfo<X86_32TargetInfo>(Triple, Opts);
447  case llvm::Triple::CloudABI:
448  return new CloudABITargetInfo<X86_32TargetInfo>(Triple, Opts);
449  case llvm::Triple::Linux: {
450  switch (Triple.getEnvironment()) {
451  default:
452  return new LinuxTargetInfo<X86_32TargetInfo>(Triple, Opts);
453  case llvm::Triple::Android:
454  return new AndroidX86_32TargetInfo(Triple, Opts);
455  }
456  }
457  case llvm::Triple::DragonFly:
458  return new DragonFlyBSDTargetInfo<X86_32TargetInfo>(Triple, Opts);
459  case llvm::Triple::NetBSD:
460  return new NetBSDI386TargetInfo(Triple, Opts);
461  case llvm::Triple::OpenBSD:
462  return new OpenBSDI386TargetInfo(Triple, Opts);
463  case llvm::Triple::FreeBSD:
464  return new FreeBSDTargetInfo<X86_32TargetInfo>(Triple, Opts);
465  case llvm::Triple::KFreeBSD:
466  return new KFreeBSDTargetInfo<X86_32TargetInfo>(Triple, Opts);
467  case llvm::Triple::Minix:
468  return new MinixTargetInfo<X86_32TargetInfo>(Triple, Opts);
469  case llvm::Triple::Solaris:
470  return new SolarisTargetInfo<X86_32TargetInfo>(Triple, Opts);
471  case llvm::Triple::Win32: {
472  switch (Triple.getEnvironment()) {
473  case llvm::Triple::Cygnus:
474  return new CygwinX86_32TargetInfo(Triple, Opts);
475  case llvm::Triple::GNU:
476  return new MinGWX86_32TargetInfo(Triple, Opts);
477  case llvm::Triple::Itanium:
478  case llvm::Triple::MSVC:
479  default: // Assume MSVC for unknown environments
480  return new MicrosoftX86_32TargetInfo(Triple, Opts);
481  }
482  }
483  case llvm::Triple::Haiku:
484  return new HaikuX86_32TargetInfo(Triple, Opts);
485  case llvm::Triple::RTEMS:
486  return new RTEMSX86_32TargetInfo(Triple, Opts);
487  case llvm::Triple::NaCl:
488  return new NaClTargetInfo<X86_32TargetInfo>(Triple, Opts);
489  case llvm::Triple::ELFIAMCU:
490  return new MCUX86_32TargetInfo(Triple, Opts);
491  default:
492  return new X86_32TargetInfo(Triple, Opts);
493  }
494 
495  case llvm::Triple::x86_64:
496  if (Triple.isOSDarwin() || Triple.isOSBinFormatMachO())
497  return new DarwinX86_64TargetInfo(Triple, Opts);
498 
499  switch (os) {
500  case llvm::Triple::Ananas:
501  return new AnanasTargetInfo<X86_64TargetInfo>(Triple, Opts);
502  case llvm::Triple::CloudABI:
503  return new CloudABITargetInfo<X86_64TargetInfo>(Triple, Opts);
504  case llvm::Triple::Linux: {
505  switch (Triple.getEnvironment()) {
506  default:
507  return new LinuxTargetInfo<X86_64TargetInfo>(Triple, Opts);
508  case llvm::Triple::Android:
509  return new AndroidX86_64TargetInfo(Triple, Opts);
510  }
511  }
512  case llvm::Triple::DragonFly:
513  return new DragonFlyBSDTargetInfo<X86_64TargetInfo>(Triple, Opts);
514  case llvm::Triple::NetBSD:
515  return new NetBSDTargetInfo<X86_64TargetInfo>(Triple, Opts);
516  case llvm::Triple::OpenBSD:
517  return new OpenBSDX86_64TargetInfo(Triple, Opts);
518  case llvm::Triple::FreeBSD:
519  return new FreeBSDTargetInfo<X86_64TargetInfo>(Triple, Opts);
520  case llvm::Triple::Fuchsia:
521  return new FuchsiaTargetInfo<X86_64TargetInfo>(Triple, Opts);
522  case llvm::Triple::KFreeBSD:
523  return new KFreeBSDTargetInfo<X86_64TargetInfo>(Triple, Opts);
524  case llvm::Triple::Solaris:
525  return new SolarisTargetInfo<X86_64TargetInfo>(Triple, Opts);
526  case llvm::Triple::Win32: {
527  switch (Triple.getEnvironment()) {
528  case llvm::Triple::Cygnus:
529  return new CygwinX86_64TargetInfo(Triple, Opts);
530  case llvm::Triple::GNU:
531  return new MinGWX86_64TargetInfo(Triple, Opts);
532  case llvm::Triple::MSVC:
533  default: // Assume MSVC for unknown environments
534  return new MicrosoftX86_64TargetInfo(Triple, Opts);
535  }
536  }
537  case llvm::Triple::Haiku:
538  return new HaikuTargetInfo<X86_64TargetInfo>(Triple, Opts);
539  case llvm::Triple::NaCl:
540  return new NaClTargetInfo<X86_64TargetInfo>(Triple, Opts);
541  case llvm::Triple::PS4:
542  return new PS4OSTargetInfo<X86_64TargetInfo>(Triple, Opts);
543  default:
544  return new X86_64TargetInfo(Triple, Opts);
545  }
546 
547  case llvm::Triple::spir: {
548  if (Triple.getOS() != llvm::Triple::UnknownOS ||
549  Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
550  return nullptr;
551  return new SPIR32TargetInfo(Triple, Opts);
552  }
553  case llvm::Triple::spir64: {
554  if (Triple.getOS() != llvm::Triple::UnknownOS ||
555  Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
556  return nullptr;
557  return new SPIR64TargetInfo(Triple, Opts);
558  }
559  case llvm::Triple::wasm32:
560  if (Triple.getSubArch() != llvm::Triple::NoSubArch ||
561  Triple.getVendor() != llvm::Triple::UnknownVendor ||
562  Triple.getOS() != llvm::Triple::UnknownOS ||
563  Triple.getEnvironment() != llvm::Triple::UnknownEnvironment ||
564  !(Triple.isOSBinFormatELF() || Triple.isOSBinFormatWasm()))
565  return nullptr;
566  return new WebAssemblyOSTargetInfo<WebAssembly32TargetInfo>(Triple, Opts);
567  case llvm::Triple::wasm64:
568  if (Triple.getSubArch() != llvm::Triple::NoSubArch ||
569  Triple.getVendor() != llvm::Triple::UnknownVendor ||
570  Triple.getOS() != llvm::Triple::UnknownOS ||
571  Triple.getEnvironment() != llvm::Triple::UnknownEnvironment ||
572  !(Triple.isOSBinFormatELF() || Triple.isOSBinFormatWasm()))
573  return nullptr;
574  return new WebAssemblyOSTargetInfo<WebAssembly64TargetInfo>(Triple, Opts);
575 
576  case llvm::Triple::renderscript32:
577  return new LinuxTargetInfo<RenderScript32TargetInfo>(Triple, Opts);
578  case llvm::Triple::renderscript64:
579  return new LinuxTargetInfo<RenderScript64TargetInfo>(Triple, Opts);
580  }
581 }
582 } // namespace targets
583 } // namespace clang
584 
585 using namespace clang::targets;
586 /// CreateTargetInfo - Return the target info object for the specified target
587 /// options.
588 TargetInfo *
590  const std::shared_ptr<TargetOptions> &Opts) {
591  llvm::Triple Triple(Opts->Triple);
592 
593  // Construct the target
594  std::unique_ptr<TargetInfo> Target(AllocateTarget(Triple, *Opts));
595  if (!Target) {
596  Diags.Report(diag::err_target_unknown_triple) << Triple.str();
597  return nullptr;
598  }
599  Target->TargetOpts = Opts;
600 
601  // Set the target CPU if specified.
602  if (!Opts->CPU.empty() && !Target->setCPU(Opts->CPU)) {
603  Diags.Report(diag::err_target_unknown_cpu) << Opts->CPU;
604  return nullptr;
605  }
606 
607  // Set the target ABI if specified.
608  if (!Opts->ABI.empty() && !Target->setABI(Opts->ABI)) {
609  Diags.Report(diag::err_target_unknown_abi) << Opts->ABI;
610  return nullptr;
611  }
612 
613  // Set the fp math unit.
614  if (!Opts->FPMath.empty() && !Target->setFPMath(Opts->FPMath)) {
615  Diags.Report(diag::err_target_unknown_fpmath) << Opts->FPMath;
616  return nullptr;
617  }
618 
619  // Compute the default target features, we need the target to handle this
620  // because features may have dependencies on one another.
621  llvm::StringMap<bool> Features;
622  if (!Target->initFeatureMap(Features, Diags, Opts->CPU,
623  Opts->FeaturesAsWritten))
624  return nullptr;
625 
626  // Add the features to the compile options.
627  Opts->Features.clear();
628  for (const auto &F : Features)
629  Opts->Features.push_back((F.getValue() ? "+" : "-") + F.getKey().str());
630 
631  if (!Target->handleTargetFeatures(Opts->Features, Diags))
632  return nullptr;
633 
634  Target->setSupportedOpenCLOpts();
635  Target->setOpenCLExtensionOpts();
636  Target->setMaxAtomicWidth();
637 
638  if (!Target->validateTarget(Diags))
639  return nullptr;
640 
641  return Target.release();
642 }
void DefineStd(MacroBuilder &Builder, StringRef MacroName, const LangOptions &Opts)
DefineStd - Define a macro name and standard variants.
Definition: Targets.cpp:54
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1207
Options for controlling the target.
Definition: TargetOptions.h:26
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:147
Defines the Diagnostic-related interfaces.
void addMinGWDefines(const llvm::Triple &Triple, const LangOptions &Opts, MacroBuilder &Builder)
Definition: Targets.cpp:101
Exposes information about the current target.
Definition: TargetInfo.h:54
static TargetInfo * CreateTargetInfo(DiagnosticsEngine &Diags, const std::shared_ptr< TargetOptions > &Opts)
Construct a target for the given options.
Definition: Targets.cpp:589
TargetInfo * AllocateTarget(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: Targets.cpp:118
void addCygMingDefines(const LangOptions &Opts, MacroBuilder &Builder)
Definition: Targets.cpp:77
Dataflow Directional Tag Classes.
void defineCPUMacros(MacroBuilder &Builder, StringRef CPUName, bool Tuning)
Definition: Targets.cpp:70
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