Coverage Report

Created: 2020-02-25 14:32

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