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