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