Coverage Report

Created: 2020-09-19 12:23

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