clang  8.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/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::xcore:
128  return new XCoreTargetInfo(Triple, Opts);
129 
130  case llvm::Triple::hexagon:
131  return new HexagonTargetInfo(Triple, Opts);
132 
133  case llvm::Triple::lanai:
134  return new LanaiTargetInfo(Triple, Opts);
135 
136  case llvm::Triple::aarch64:
137  if (Triple.isOSDarwin())
138  return new DarwinAArch64TargetInfo(Triple, Opts);
139 
140  switch (os) {
141  case llvm::Triple::CloudABI:
142  return new CloudABITargetInfo<AArch64leTargetInfo>(Triple, Opts);
143  case llvm::Triple::FreeBSD:
144  return new FreeBSDTargetInfo<AArch64leTargetInfo>(Triple, Opts);
145  case llvm::Triple::Fuchsia:
146  return new FuchsiaTargetInfo<AArch64leTargetInfo>(Triple, Opts);
147  case llvm::Triple::Linux:
148  return new LinuxTargetInfo<AArch64leTargetInfo>(Triple, Opts);
149  case llvm::Triple::NetBSD:
150  return new NetBSDTargetInfo<AArch64leTargetInfo>(Triple, Opts);
151  case llvm::Triple::OpenBSD:
152  return new OpenBSDTargetInfo<AArch64leTargetInfo>(Triple, Opts);
153  case llvm::Triple::Win32:
154  switch (Triple.getEnvironment()) {
155  case llvm::Triple::GNU:
156  return new MinGWARM64TargetInfo(Triple, Opts);
157  case llvm::Triple::MSVC:
158  default: // Assume MSVC for unknown environments
159  return new MicrosoftARM64TargetInfo(Triple, Opts);
160  }
161  default:
162  return new AArch64leTargetInfo(Triple, Opts);
163  }
164 
165  case llvm::Triple::aarch64_be:
166  switch (os) {
167  case llvm::Triple::FreeBSD:
168  return new FreeBSDTargetInfo<AArch64beTargetInfo>(Triple, Opts);
169  case llvm::Triple::Fuchsia:
170  return new FuchsiaTargetInfo<AArch64beTargetInfo>(Triple, Opts);
171  case llvm::Triple::Linux:
172  return new LinuxTargetInfo<AArch64beTargetInfo>(Triple, Opts);
173  case llvm::Triple::NetBSD:
174  return new NetBSDTargetInfo<AArch64beTargetInfo>(Triple, Opts);
175  default:
176  return new AArch64beTargetInfo(Triple, Opts);
177  }
178 
179  case llvm::Triple::arm:
180  case llvm::Triple::thumb:
181  if (Triple.isOSBinFormatMachO())
182  return new DarwinARMTargetInfo(Triple, Opts);
183 
184  switch (os) {
185  case llvm::Triple::CloudABI:
186  return new CloudABITargetInfo<ARMleTargetInfo>(Triple, Opts);
187  case llvm::Triple::Linux:
188  return new LinuxTargetInfo<ARMleTargetInfo>(Triple, Opts);
189  case llvm::Triple::FreeBSD:
190  return new FreeBSDTargetInfo<ARMleTargetInfo>(Triple, Opts);
191  case llvm::Triple::NetBSD:
192  return new NetBSDTargetInfo<ARMleTargetInfo>(Triple, Opts);
193  case llvm::Triple::OpenBSD:
194  return new OpenBSDTargetInfo<ARMleTargetInfo>(Triple, Opts);
195  case llvm::Triple::RTEMS:
196  return new RTEMSTargetInfo<ARMleTargetInfo>(Triple, Opts);
197  case llvm::Triple::NaCl:
198  return new NaClTargetInfo<ARMleTargetInfo>(Triple, Opts);
199  case llvm::Triple::Win32:
200  switch (Triple.getEnvironment()) {
201  case llvm::Triple::Cygnus:
202  return new CygwinARMTargetInfo(Triple, Opts);
203  case llvm::Triple::GNU:
204  return new MinGWARMTargetInfo(Triple, Opts);
205  case llvm::Triple::Itanium:
206  return new ItaniumWindowsARMleTargetInfo(Triple, Opts);
207  case llvm::Triple::MSVC:
208  default: // Assume MSVC for unknown environments
209  return new MicrosoftARMleTargetInfo(Triple, Opts);
210  }
211  default:
212  return new ARMleTargetInfo(Triple, Opts);
213  }
214 
215  case llvm::Triple::armeb:
216  case llvm::Triple::thumbeb:
217  if (Triple.isOSDarwin())
218  return new DarwinARMTargetInfo(Triple, Opts);
219 
220  switch (os) {
221  case llvm::Triple::Linux:
222  return new LinuxTargetInfo<ARMbeTargetInfo>(Triple, Opts);
223  case llvm::Triple::FreeBSD:
224  return new FreeBSDTargetInfo<ARMbeTargetInfo>(Triple, Opts);
225  case llvm::Triple::NetBSD:
226  return new NetBSDTargetInfo<ARMbeTargetInfo>(Triple, Opts);
227  case llvm::Triple::OpenBSD:
228  return new OpenBSDTargetInfo<ARMbeTargetInfo>(Triple, Opts);
229  case llvm::Triple::RTEMS:
230  return new RTEMSTargetInfo<ARMbeTargetInfo>(Triple, Opts);
231  case llvm::Triple::NaCl:
232  return new NaClTargetInfo<ARMbeTargetInfo>(Triple, Opts);
233  default:
234  return new ARMbeTargetInfo(Triple, Opts);
235  }
236 
237  case llvm::Triple::avr:
238  return new AVRTargetInfo(Triple, Opts);
239  case llvm::Triple::bpfeb:
240  case llvm::Triple::bpfel:
241  return new BPFTargetInfo(Triple, Opts);
242 
243  case llvm::Triple::msp430:
244  return new MSP430TargetInfo(Triple, Opts);
245 
246  case llvm::Triple::nios2:
247  return new LinuxTargetInfo<Nios2TargetInfo>(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  default:
499  return new X86_32TargetInfo(Triple, Opts);
500  }
501 
502  case llvm::Triple::x86_64:
503  if (Triple.isOSDarwin() || Triple.isOSBinFormatMachO())
504  return new DarwinX86_64TargetInfo(Triple, Opts);
505 
506  switch (os) {
507  case llvm::Triple::Ananas:
508  return new AnanasTargetInfo<X86_64TargetInfo>(Triple, Opts);
509  case llvm::Triple::CloudABI:
510  return new CloudABITargetInfo<X86_64TargetInfo>(Triple, Opts);
511  case llvm::Triple::Linux: {
512  switch (Triple.getEnvironment()) {
513  default:
514  return new LinuxTargetInfo<X86_64TargetInfo>(Triple, Opts);
515  case llvm::Triple::Android:
516  return new AndroidX86_64TargetInfo(Triple, Opts);
517  }
518  }
519  case llvm::Triple::DragonFly:
520  return new DragonFlyBSDTargetInfo<X86_64TargetInfo>(Triple, Opts);
521  case llvm::Triple::NetBSD:
522  return new NetBSDTargetInfo<X86_64TargetInfo>(Triple, Opts);
523  case llvm::Triple::OpenBSD:
524  return new OpenBSDX86_64TargetInfo(Triple, Opts);
525  case llvm::Triple::FreeBSD:
526  return new FreeBSDTargetInfo<X86_64TargetInfo>(Triple, Opts);
527  case llvm::Triple::Fuchsia:
528  return new FuchsiaTargetInfo<X86_64TargetInfo>(Triple, Opts);
529  case llvm::Triple::KFreeBSD:
530  return new KFreeBSDTargetInfo<X86_64TargetInfo>(Triple, Opts);
531  case llvm::Triple::Solaris:
532  return new SolarisTargetInfo<X86_64TargetInfo>(Triple, Opts);
533  case llvm::Triple::Win32: {
534  switch (Triple.getEnvironment()) {
535  case llvm::Triple::Cygnus:
536  return new CygwinX86_64TargetInfo(Triple, Opts);
537  case llvm::Triple::GNU:
538  return new MinGWX86_64TargetInfo(Triple, Opts);
539  case llvm::Triple::MSVC:
540  default: // Assume MSVC for unknown environments
541  return new MicrosoftX86_64TargetInfo(Triple, Opts);
542  }
543  }
544  case llvm::Triple::Haiku:
545  return new HaikuTargetInfo<X86_64TargetInfo>(Triple, Opts);
546  case llvm::Triple::NaCl:
547  return new NaClTargetInfo<X86_64TargetInfo>(Triple, Opts);
548  case llvm::Triple::PS4:
549  return new PS4OSTargetInfo<X86_64TargetInfo>(Triple, Opts);
550  default:
551  return new X86_64TargetInfo(Triple, Opts);
552  }
553 
554  case llvm::Triple::spir: {
555  if (Triple.getOS() != llvm::Triple::UnknownOS ||
556  Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
557  return nullptr;
558  return new SPIR32TargetInfo(Triple, Opts);
559  }
560  case llvm::Triple::spir64: {
561  if (Triple.getOS() != llvm::Triple::UnknownOS ||
562  Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
563  return nullptr;
564  return new SPIR64TargetInfo(Triple, Opts);
565  }
566  case llvm::Triple::wasm32:
567  if (Triple.getSubArch() != llvm::Triple::NoSubArch ||
568  Triple.getVendor() != llvm::Triple::UnknownVendor ||
569  Triple.getOS() != llvm::Triple::UnknownOS ||
570  Triple.getEnvironment() != llvm::Triple::UnknownEnvironment ||
571  !(Triple.isOSBinFormatELF() || Triple.isOSBinFormatWasm()))
572  return nullptr;
573  return new WebAssemblyOSTargetInfo<WebAssembly32TargetInfo>(Triple, Opts);
574  case llvm::Triple::wasm64:
575  if (Triple.getSubArch() != llvm::Triple::NoSubArch ||
576  Triple.getVendor() != llvm::Triple::UnknownVendor ||
577  Triple.getOS() != llvm::Triple::UnknownOS ||
578  Triple.getEnvironment() != llvm::Triple::UnknownEnvironment ||
579  !(Triple.isOSBinFormatELF() || Triple.isOSBinFormatWasm()))
580  return nullptr;
581  return new WebAssemblyOSTargetInfo<WebAssembly64TargetInfo>(Triple, Opts);
582 
583  case llvm::Triple::renderscript32:
584  return new LinuxTargetInfo<RenderScript32TargetInfo>(Triple, Opts);
585  case llvm::Triple::renderscript64:
586  return new LinuxTargetInfo<RenderScript64TargetInfo>(Triple, Opts);
587  }
588 }
589 } // namespace targets
590 } // namespace clang
591 
592 using namespace clang::targets;
593 /// CreateTargetInfo - Return the target info object for the specified target
594 /// options.
595 TargetInfo *
597  const std::shared_ptr<TargetOptions> &Opts) {
598  llvm::Triple Triple(Opts->Triple);
599 
600  // Construct the target
601  std::unique_ptr<TargetInfo> Target(AllocateTarget(Triple, *Opts));
602  if (!Target) {
603  Diags.Report(diag::err_target_unknown_triple) << Triple.str();
604  return nullptr;
605  }
606  Target->TargetOpts = Opts;
607 
608  // Set the target CPU if specified.
609  if (!Opts->CPU.empty() && !Target->setCPU(Opts->CPU)) {
610  Diags.Report(diag::err_target_unknown_cpu) << Opts->CPU;
611  SmallVector<StringRef, 32> ValidList;
612  Target->fillValidCPUList(ValidList);
613  if (!ValidList.empty())
614  Diags.Report(diag::note_valid_options) << llvm::join(ValidList, ", ");
615  return nullptr;
616  }
617 
618  // Set the target ABI if specified.
619  if (!Opts->ABI.empty() && !Target->setABI(Opts->ABI)) {
620  Diags.Report(diag::err_target_unknown_abi) << Opts->ABI;
621  return nullptr;
622  }
623 
624  // Set the fp math unit.
625  if (!Opts->FPMath.empty() && !Target->setFPMath(Opts->FPMath)) {
626  Diags.Report(diag::err_target_unknown_fpmath) << Opts->FPMath;
627  return nullptr;
628  }
629 
630  // Compute the default target features, we need the target to handle this
631  // because features may have dependencies on one another.
632  llvm::StringMap<bool> Features;
633  if (!Target->initFeatureMap(Features, Diags, Opts->CPU,
634  Opts->FeaturesAsWritten))
635  return nullptr;
636 
637  // Add the features to the compile options.
638  Opts->Features.clear();
639  for (const auto &F : Features)
640  Opts->Features.push_back((F.getValue() ? "+" : "-") + F.getKey().str());
641  // Sort here, so we handle the features in a predictable order. (This matters
642  // when we're dealing with features that overlap.)
643  llvm::sort(Opts->Features);
644 
645  if (!Target->handleTargetFeatures(Opts->Features, Diags))
646  return nullptr;
647 
648  Target->setSupportedOpenCLOpts();
649  Target->setOpenCLExtensionOpts();
650  Target->setMaxAtomicWidth();
651 
652  if (!Target->validateTarget(Diags))
653  return nullptr;
654 
655  Target->CheckFixedPointBits();
656 
657  return Target.release();
658 }
void DefineStd(MacroBuilder &Builder, StringRef MacroName, const LangOptions &Opts)
DefineStd - Define a macro name and standard variants.
Definition: Targets.cpp:55
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1294
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:50
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
Defines the Diagnostic-related interfaces.
void addMinGWDefines(const llvm::Triple &Triple, const LangOptions &Opts, MacroBuilder &Builder)
Definition: Targets.cpp:102
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:596
TargetInfo * AllocateTarget(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: Targets.cpp:119
void addCygMingDefines(const LangOptions &Opts, MacroBuilder &Builder)
Definition: Targets.cpp:78
Dataflow Directional Tag Classes.
void defineCPUMacros(MacroBuilder &Builder, StringRef CPUName, bool Tuning)
Definition: Targets.cpp:71
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