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 LangOptions &Opts, MacroBuilder &Builder) {
101  Builder.defineMacro("__MSVCRT__");
102  Builder.defineMacro("__MINGW32__");
103  addCygMingDefines(Opts, Builder);
104 }
105 
106 //===----------------------------------------------------------------------===//
107 // Driver code
108 //===----------------------------------------------------------------------===//
109 
110 TargetInfo *AllocateTarget(const llvm::Triple &Triple,
111  const TargetOptions &Opts) {
112  llvm::Triple::OSType os = Triple.getOS();
113 
114  switch (Triple.getArch()) {
115  default:
116  return nullptr;
117 
118  case llvm::Triple::xcore:
119  return new XCoreTargetInfo(Triple, Opts);
120 
121  case llvm::Triple::hexagon:
122  return new HexagonTargetInfo(Triple, Opts);
123 
124  case llvm::Triple::lanai:
125  return new LanaiTargetInfo(Triple, Opts);
126 
127  case llvm::Triple::aarch64:
128  if (Triple.isOSDarwin())
129  return new DarwinAArch64TargetInfo(Triple, Opts);
130 
131  switch (os) {
132  case llvm::Triple::CloudABI:
133  return new CloudABITargetInfo<AArch64leTargetInfo>(Triple, Opts);
134  case llvm::Triple::FreeBSD:
135  return new FreeBSDTargetInfo<AArch64leTargetInfo>(Triple, Opts);
136  case llvm::Triple::Fuchsia:
137  return new FuchsiaTargetInfo<AArch64leTargetInfo>(Triple, Opts);
138  case llvm::Triple::Linux:
139  return new LinuxTargetInfo<AArch64leTargetInfo>(Triple, Opts);
140  case llvm::Triple::NetBSD:
141  return new NetBSDTargetInfo<AArch64leTargetInfo>(Triple, Opts);
142  case llvm::Triple::OpenBSD:
143  return new OpenBSDTargetInfo<AArch64leTargetInfo>(Triple, Opts);
144  case llvm::Triple::Win32:
145  switch (Triple.getEnvironment()) {
146  case llvm::Triple::GNU:
147  return new MinGWARM64TargetInfo(Triple, Opts);
148  case llvm::Triple::MSVC:
149  default: // Assume MSVC for unknown environments
150  return new MicrosoftARM64TargetInfo(Triple, Opts);
151  }
152  default:
153  return new AArch64leTargetInfo(Triple, Opts);
154  }
155 
156  case llvm::Triple::aarch64_be:
157  switch (os) {
158  case llvm::Triple::FreeBSD:
159  return new FreeBSDTargetInfo<AArch64beTargetInfo>(Triple, Opts);
160  case llvm::Triple::Fuchsia:
161  return new FuchsiaTargetInfo<AArch64beTargetInfo>(Triple, Opts);
162  case llvm::Triple::Linux:
163  return new LinuxTargetInfo<AArch64beTargetInfo>(Triple, Opts);
164  case llvm::Triple::NetBSD:
165  return new NetBSDTargetInfo<AArch64beTargetInfo>(Triple, Opts);
166  default:
167  return new AArch64beTargetInfo(Triple, Opts);
168  }
169 
170  case llvm::Triple::arm:
171  case llvm::Triple::thumb:
172  if (Triple.isOSBinFormatMachO())
173  return new DarwinARMTargetInfo(Triple, Opts);
174 
175  switch (os) {
176  case llvm::Triple::CloudABI:
177  return new CloudABITargetInfo<ARMleTargetInfo>(Triple, Opts);
178  case llvm::Triple::Linux:
179  return new LinuxTargetInfo<ARMleTargetInfo>(Triple, Opts);
180  case llvm::Triple::FreeBSD:
181  return new FreeBSDTargetInfo<ARMleTargetInfo>(Triple, Opts);
182  case llvm::Triple::NetBSD:
183  return new NetBSDTargetInfo<ARMleTargetInfo>(Triple, Opts);
184  case llvm::Triple::OpenBSD:
185  return new OpenBSDTargetInfo<ARMleTargetInfo>(Triple, Opts);
186  case llvm::Triple::RTEMS:
187  return new RTEMSTargetInfo<ARMleTargetInfo>(Triple, Opts);
188  case llvm::Triple::NaCl:
189  return new NaClTargetInfo<ARMleTargetInfo>(Triple, Opts);
190  case llvm::Triple::Win32:
191  switch (Triple.getEnvironment()) {
192  case llvm::Triple::Cygnus:
193  return new CygwinARMTargetInfo(Triple, Opts);
194  case llvm::Triple::GNU:
195  return new MinGWARMTargetInfo(Triple, Opts);
196  case llvm::Triple::Itanium:
197  return new ItaniumWindowsARMleTargetInfo(Triple, Opts);
198  case llvm::Triple::MSVC:
199  default: // Assume MSVC for unknown environments
200  return new MicrosoftARMleTargetInfo(Triple, Opts);
201  }
202  default:
203  return new ARMleTargetInfo(Triple, Opts);
204  }
205 
206  case llvm::Triple::armeb:
207  case llvm::Triple::thumbeb:
208  if (Triple.isOSDarwin())
209  return new DarwinARMTargetInfo(Triple, Opts);
210 
211  switch (os) {
212  case llvm::Triple::Linux:
213  return new LinuxTargetInfo<ARMbeTargetInfo>(Triple, Opts);
214  case llvm::Triple::FreeBSD:
215  return new FreeBSDTargetInfo<ARMbeTargetInfo>(Triple, Opts);
216  case llvm::Triple::NetBSD:
217  return new NetBSDTargetInfo<ARMbeTargetInfo>(Triple, Opts);
218  case llvm::Triple::OpenBSD:
219  return new OpenBSDTargetInfo<ARMbeTargetInfo>(Triple, Opts);
220  case llvm::Triple::RTEMS:
221  return new RTEMSTargetInfo<ARMbeTargetInfo>(Triple, Opts);
222  case llvm::Triple::NaCl:
223  return new NaClTargetInfo<ARMbeTargetInfo>(Triple, Opts);
224  default:
225  return new ARMbeTargetInfo(Triple, Opts);
226  }
227 
228  case llvm::Triple::avr:
229  return new AVRTargetInfo(Triple, Opts);
230  case llvm::Triple::bpfeb:
231  case llvm::Triple::bpfel:
232  return new BPFTargetInfo(Triple, Opts);
233 
234  case llvm::Triple::msp430:
235  return new MSP430TargetInfo(Triple, Opts);
236 
237  case llvm::Triple::nios2:
238  return new LinuxTargetInfo<Nios2TargetInfo>(Triple, Opts);
239 
240  case llvm::Triple::mips:
241  switch (os) {
242  case llvm::Triple::Linux:
243  return new LinuxTargetInfo<MipsTargetInfo>(Triple, Opts);
244  case llvm::Triple::RTEMS:
245  return new RTEMSTargetInfo<MipsTargetInfo>(Triple, Opts);
246  case llvm::Triple::FreeBSD:
247  return new FreeBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
248  case llvm::Triple::NetBSD:
249  return new NetBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
250  default:
251  return new MipsTargetInfo(Triple, Opts);
252  }
253 
254  case llvm::Triple::mipsel:
255  switch (os) {
256  case llvm::Triple::Linux:
257  return new LinuxTargetInfo<MipsTargetInfo>(Triple, Opts);
258  case llvm::Triple::RTEMS:
259  return new RTEMSTargetInfo<MipsTargetInfo>(Triple, Opts);
260  case llvm::Triple::FreeBSD:
261  return new FreeBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
262  case llvm::Triple::NetBSD:
263  return new NetBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
264  case llvm::Triple::NaCl:
265  return new NaClTargetInfo<NaClMips32TargetInfo>(Triple, Opts);
266  default:
267  return new MipsTargetInfo(Triple, Opts);
268  }
269 
270  case llvm::Triple::mips64:
271  switch (os) {
272  case llvm::Triple::Linux:
273  return new LinuxTargetInfo<MipsTargetInfo>(Triple, Opts);
274  case llvm::Triple::RTEMS:
275  return new RTEMSTargetInfo<MipsTargetInfo>(Triple, Opts);
276  case llvm::Triple::FreeBSD:
277  return new FreeBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
278  case llvm::Triple::NetBSD:
279  return new NetBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
280  case llvm::Triple::OpenBSD:
281  return new OpenBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
282  default:
283  return new MipsTargetInfo(Triple, Opts);
284  }
285 
286  case llvm::Triple::mips64el:
287  switch (os) {
288  case llvm::Triple::Linux:
289  return new LinuxTargetInfo<MipsTargetInfo>(Triple, Opts);
290  case llvm::Triple::RTEMS:
291  return new RTEMSTargetInfo<MipsTargetInfo>(Triple, Opts);
292  case llvm::Triple::FreeBSD:
293  return new FreeBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
294  case llvm::Triple::NetBSD:
295  return new NetBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
296  case llvm::Triple::OpenBSD:
297  return new OpenBSDTargetInfo<MipsTargetInfo>(Triple, Opts);
298  default:
299  return new MipsTargetInfo(Triple, Opts);
300  }
301 
302  case llvm::Triple::le32:
303  switch (os) {
304  case llvm::Triple::NaCl:
305  return new NaClTargetInfo<PNaClTargetInfo>(Triple, Opts);
306  default:
307  return nullptr;
308  }
309 
310  case llvm::Triple::le64:
311  return new Le64TargetInfo(Triple, Opts);
312 
313  case llvm::Triple::ppc:
314  if (Triple.isOSDarwin())
315  return new DarwinPPC32TargetInfo(Triple, Opts);
316  switch (os) {
317  case llvm::Triple::Linux:
318  return new LinuxTargetInfo<PPC32TargetInfo>(Triple, Opts);
319  case llvm::Triple::FreeBSD:
320  return new FreeBSDTargetInfo<PPC32TargetInfo>(Triple, Opts);
321  case llvm::Triple::NetBSD:
322  return new NetBSDTargetInfo<PPC32TargetInfo>(Triple, Opts);
323  case llvm::Triple::OpenBSD:
324  return new OpenBSDTargetInfo<PPC32TargetInfo>(Triple, Opts);
325  case llvm::Triple::RTEMS:
326  return new RTEMSTargetInfo<PPC32TargetInfo>(Triple, Opts);
327  default:
328  return new PPC32TargetInfo(Triple, Opts);
329  }
330 
331  case llvm::Triple::ppc64:
332  if (Triple.isOSDarwin())
333  return new DarwinPPC64TargetInfo(Triple, Opts);
334  switch (os) {
335  case llvm::Triple::Linux:
336  return new LinuxTargetInfo<PPC64TargetInfo>(Triple, Opts);
337  case llvm::Triple::Lv2:
338  return new PS3PPUTargetInfo<PPC64TargetInfo>(Triple, Opts);
339  case llvm::Triple::FreeBSD:
340  return new FreeBSDTargetInfo<PPC64TargetInfo>(Triple, Opts);
341  case llvm::Triple::NetBSD:
342  return new NetBSDTargetInfo<PPC64TargetInfo>(Triple, Opts);
343  default:
344  return new PPC64TargetInfo(Triple, Opts);
345  }
346 
347  case llvm::Triple::ppc64le:
348  switch (os) {
349  case llvm::Triple::Linux:
350  return new LinuxTargetInfo<PPC64TargetInfo>(Triple, Opts);
351  case llvm::Triple::NetBSD:
352  return new NetBSDTargetInfo<PPC64TargetInfo>(Triple, Opts);
353  default:
354  return new PPC64TargetInfo(Triple, Opts);
355  }
356 
357  case llvm::Triple::nvptx:
358  return new NVPTXTargetInfo(Triple, Opts, /*TargetPointerWidth=*/32);
359  case llvm::Triple::nvptx64:
360  return new NVPTXTargetInfo(Triple, Opts, /*TargetPointerWidth=*/64);
361 
362  case llvm::Triple::amdgcn:
363  case llvm::Triple::r600:
364  return new AMDGPUTargetInfo(Triple, Opts);
365 
366  case llvm::Triple::sparc:
367  switch (os) {
368  case llvm::Triple::Linux:
369  return new LinuxTargetInfo<SparcV8TargetInfo>(Triple, Opts);
370  case llvm::Triple::Solaris:
371  return new SolarisTargetInfo<SparcV8TargetInfo>(Triple, Opts);
372  case llvm::Triple::NetBSD:
373  return new NetBSDTargetInfo<SparcV8TargetInfo>(Triple, Opts);
374  case llvm::Triple::OpenBSD:
375  return new OpenBSDTargetInfo<SparcV8TargetInfo>(Triple, Opts);
376  case llvm::Triple::RTEMS:
377  return new RTEMSTargetInfo<SparcV8TargetInfo>(Triple, Opts);
378  default:
379  return new SparcV8TargetInfo(Triple, Opts);
380  }
381 
382  // The 'sparcel' architecture copies all the above cases except for Solaris.
383  case llvm::Triple::sparcel:
384  switch (os) {
385  case llvm::Triple::Linux:
386  return new LinuxTargetInfo<SparcV8elTargetInfo>(Triple, Opts);
387  case llvm::Triple::NetBSD:
388  return new NetBSDTargetInfo<SparcV8elTargetInfo>(Triple, Opts);
389  case llvm::Triple::OpenBSD:
390  return new OpenBSDTargetInfo<SparcV8elTargetInfo>(Triple, Opts);
391  case llvm::Triple::RTEMS:
392  return new RTEMSTargetInfo<SparcV8elTargetInfo>(Triple, Opts);
393  default:
394  return new SparcV8elTargetInfo(Triple, Opts);
395  }
396 
397  case llvm::Triple::sparcv9:
398  switch (os) {
399  case llvm::Triple::Linux:
400  return new LinuxTargetInfo<SparcV9TargetInfo>(Triple, Opts);
401  case llvm::Triple::Solaris:
402  return new SolarisTargetInfo<SparcV9TargetInfo>(Triple, Opts);
403  case llvm::Triple::NetBSD:
404  return new NetBSDTargetInfo<SparcV9TargetInfo>(Triple, Opts);
405  case llvm::Triple::OpenBSD:
406  return new OpenBSDTargetInfo<SparcV9TargetInfo>(Triple, Opts);
407  case llvm::Triple::FreeBSD:
408  return new FreeBSDTargetInfo<SparcV9TargetInfo>(Triple, Opts);
409  default:
410  return new SparcV9TargetInfo(Triple, Opts);
411  }
412 
413  case llvm::Triple::systemz:
414  switch (os) {
415  case llvm::Triple::Linux:
416  return new LinuxTargetInfo<SystemZTargetInfo>(Triple, Opts);
417  default:
418  return new SystemZTargetInfo(Triple, Opts);
419  }
420 
421  case llvm::Triple::tce:
422  return new TCETargetInfo(Triple, Opts);
423 
424  case llvm::Triple::tcele:
425  return new TCELETargetInfo(Triple, Opts);
426 
427  case llvm::Triple::x86:
428  if (Triple.isOSDarwin())
429  return new DarwinI386TargetInfo(Triple, Opts);
430 
431  switch (os) {
432  case llvm::Triple::Ananas:
433  return new AnanasTargetInfo<X86_32TargetInfo>(Triple, Opts);
434  case llvm::Triple::CloudABI:
435  return new CloudABITargetInfo<X86_32TargetInfo>(Triple, Opts);
436  case llvm::Triple::Linux: {
437  switch (Triple.getEnvironment()) {
438  default:
439  return new LinuxTargetInfo<X86_32TargetInfo>(Triple, Opts);
440  case llvm::Triple::Android:
441  return new AndroidX86_32TargetInfo(Triple, Opts);
442  }
443  }
444  case llvm::Triple::DragonFly:
445  return new DragonFlyBSDTargetInfo<X86_32TargetInfo>(Triple, Opts);
446  case llvm::Triple::NetBSD:
447  return new NetBSDI386TargetInfo(Triple, Opts);
448  case llvm::Triple::OpenBSD:
449  return new OpenBSDI386TargetInfo(Triple, Opts);
450  case llvm::Triple::FreeBSD:
451  return new FreeBSDTargetInfo<X86_32TargetInfo>(Triple, Opts);
452  case llvm::Triple::KFreeBSD:
453  return new KFreeBSDTargetInfo<X86_32TargetInfo>(Triple, Opts);
454  case llvm::Triple::Minix:
455  return new MinixTargetInfo<X86_32TargetInfo>(Triple, Opts);
456  case llvm::Triple::Solaris:
457  return new SolarisTargetInfo<X86_32TargetInfo>(Triple, Opts);
458  case llvm::Triple::Win32: {
459  switch (Triple.getEnvironment()) {
460  case llvm::Triple::Cygnus:
461  return new CygwinX86_32TargetInfo(Triple, Opts);
462  case llvm::Triple::GNU:
463  return new MinGWX86_32TargetInfo(Triple, Opts);
464  case llvm::Triple::Itanium:
465  case llvm::Triple::MSVC:
466  default: // Assume MSVC for unknown environments
467  return new MicrosoftX86_32TargetInfo(Triple, Opts);
468  }
469  }
470  case llvm::Triple::Haiku:
471  return new HaikuX86_32TargetInfo(Triple, Opts);
472  case llvm::Triple::RTEMS:
473  return new RTEMSX86_32TargetInfo(Triple, Opts);
474  case llvm::Triple::NaCl:
475  return new NaClTargetInfo<X86_32TargetInfo>(Triple, Opts);
476  case llvm::Triple::ELFIAMCU:
477  return new MCUX86_32TargetInfo(Triple, Opts);
478  default:
479  return new X86_32TargetInfo(Triple, Opts);
480  }
481 
482  case llvm::Triple::x86_64:
483  if (Triple.isOSDarwin() || Triple.isOSBinFormatMachO())
484  return new DarwinX86_64TargetInfo(Triple, Opts);
485 
486  switch (os) {
487  case llvm::Triple::Ananas:
488  return new AnanasTargetInfo<X86_64TargetInfo>(Triple, Opts);
489  case llvm::Triple::CloudABI:
490  return new CloudABITargetInfo<X86_64TargetInfo>(Triple, Opts);
491  case llvm::Triple::Linux: {
492  switch (Triple.getEnvironment()) {
493  default:
494  return new LinuxTargetInfo<X86_64TargetInfo>(Triple, Opts);
495  case llvm::Triple::Android:
496  return new AndroidX86_64TargetInfo(Triple, Opts);
497  }
498  }
499  case llvm::Triple::DragonFly:
500  return new DragonFlyBSDTargetInfo<X86_64TargetInfo>(Triple, Opts);
501  case llvm::Triple::NetBSD:
502  return new NetBSDTargetInfo<X86_64TargetInfo>(Triple, Opts);
503  case llvm::Triple::OpenBSD:
504  return new OpenBSDX86_64TargetInfo(Triple, Opts);
505  case llvm::Triple::FreeBSD:
506  return new FreeBSDTargetInfo<X86_64TargetInfo>(Triple, Opts);
507  case llvm::Triple::Fuchsia:
508  return new FuchsiaTargetInfo<X86_64TargetInfo>(Triple, Opts);
509  case llvm::Triple::KFreeBSD:
510  return new KFreeBSDTargetInfo<X86_64TargetInfo>(Triple, Opts);
511  case llvm::Triple::Solaris:
512  return new SolarisTargetInfo<X86_64TargetInfo>(Triple, Opts);
513  case llvm::Triple::Win32: {
514  switch (Triple.getEnvironment()) {
515  case llvm::Triple::Cygnus:
516  return new CygwinX86_64TargetInfo(Triple, Opts);
517  case llvm::Triple::GNU:
518  return new MinGWX86_64TargetInfo(Triple, Opts);
519  case llvm::Triple::MSVC:
520  default: // Assume MSVC for unknown environments
521  return new MicrosoftX86_64TargetInfo(Triple, Opts);
522  }
523  }
524  case llvm::Triple::Haiku:
525  return new HaikuTargetInfo<X86_64TargetInfo>(Triple, Opts);
526  case llvm::Triple::NaCl:
527  return new NaClTargetInfo<X86_64TargetInfo>(Triple, Opts);
528  case llvm::Triple::PS4:
529  return new PS4OSTargetInfo<X86_64TargetInfo>(Triple, Opts);
530  default:
531  return new X86_64TargetInfo(Triple, Opts);
532  }
533 
534  case llvm::Triple::spir: {
535  if (Triple.getOS() != llvm::Triple::UnknownOS ||
536  Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
537  return nullptr;
538  return new SPIR32TargetInfo(Triple, Opts);
539  }
540  case llvm::Triple::spir64: {
541  if (Triple.getOS() != llvm::Triple::UnknownOS ||
542  Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
543  return nullptr;
544  return new SPIR64TargetInfo(Triple, Opts);
545  }
546  case llvm::Triple::wasm32:
547  if (Triple.getSubArch() != llvm::Triple::NoSubArch ||
548  Triple.getVendor() != llvm::Triple::UnknownVendor ||
549  Triple.getOS() != llvm::Triple::UnknownOS ||
550  Triple.getEnvironment() != llvm::Triple::UnknownEnvironment ||
551  !(Triple.isOSBinFormatELF() || Triple.isOSBinFormatWasm()))
552  return nullptr;
553  return new WebAssemblyOSTargetInfo<WebAssembly32TargetInfo>(Triple, Opts);
554  case llvm::Triple::wasm64:
555  if (Triple.getSubArch() != llvm::Triple::NoSubArch ||
556  Triple.getVendor() != llvm::Triple::UnknownVendor ||
557  Triple.getOS() != llvm::Triple::UnknownOS ||
558  Triple.getEnvironment() != llvm::Triple::UnknownEnvironment ||
559  !(Triple.isOSBinFormatELF() || Triple.isOSBinFormatWasm()))
560  return nullptr;
561  return new WebAssemblyOSTargetInfo<WebAssembly64TargetInfo>(Triple, Opts);
562 
563  case llvm::Triple::renderscript32:
564  return new LinuxTargetInfo<RenderScript32TargetInfo>(Triple, Opts);
565  case llvm::Triple::renderscript64:
566  return new LinuxTargetInfo<RenderScript64TargetInfo>(Triple, Opts);
567  }
568 }
569 } // namespace targets
570 } // namespace clang
571 
572 using namespace clang::targets;
573 /// CreateTargetInfo - Return the target info object for the specified target
574 /// options.
575 TargetInfo *
577  const std::shared_ptr<TargetOptions> &Opts) {
578  llvm::Triple Triple(Opts->Triple);
579 
580  // Construct the target
581  std::unique_ptr<TargetInfo> Target(AllocateTarget(Triple, *Opts));
582  if (!Target) {
583  Diags.Report(diag::err_target_unknown_triple) << Triple.str();
584  return nullptr;
585  }
586  Target->TargetOpts = Opts;
587 
588  // Set the target CPU if specified.
589  if (!Opts->CPU.empty() && !Target->setCPU(Opts->CPU)) {
590  Diags.Report(diag::err_target_unknown_cpu) << Opts->CPU;
591  return nullptr;
592  }
593 
594  // Set the target ABI if specified.
595  if (!Opts->ABI.empty() && !Target->setABI(Opts->ABI)) {
596  Diags.Report(diag::err_target_unknown_abi) << Opts->ABI;
597  return nullptr;
598  }
599 
600  // Set the fp math unit.
601  if (!Opts->FPMath.empty() && !Target->setFPMath(Opts->FPMath)) {
602  Diags.Report(diag::err_target_unknown_fpmath) << Opts->FPMath;
603  return nullptr;
604  }
605 
606  // Compute the default target features, we need the target to handle this
607  // because features may have dependencies on one another.
608  llvm::StringMap<bool> Features;
609  if (!Target->initFeatureMap(Features, Diags, Opts->CPU,
610  Opts->FeaturesAsWritten))
611  return nullptr;
612 
613  // Add the features to the compile options.
614  Opts->Features.clear();
615  for (const auto &F : Features)
616  Opts->Features.push_back((F.getValue() ? "+" : "-") + F.getKey().str());
617 
618  if (!Target->handleTargetFeatures(Opts->Features, Diags))
619  return nullptr;
620 
621  Target->setSupportedOpenCLOpts();
622  Target->setOpenCLExtensionOpts();
623  Target->setMaxAtomicWidth();
624 
625  if (!Target->validateTarget(Diags))
626  return nullptr;
627 
628  return Target.release();
629 }
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:1205
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.
Exposes information about the current target.
Definition: TargetInfo.h:55
static TargetInfo * CreateTargetInfo(DiagnosticsEngine &Diags, const std::shared_ptr< TargetOptions > &Opts)
Construct a target for the given options.
Definition: Targets.cpp:576
TargetInfo * AllocateTarget(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: Targets.cpp:110
void addCygMingDefines(const LangOptions &Opts, MacroBuilder &Builder)
Definition: Targets.cpp:76
Dataflow Directional Tag Classes.
void addMinGWDefines(const LangOptions &Opts, MacroBuilder &Builder)
Definition: Targets.cpp:100
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