Coverage Report

Created: 2022-01-18 06:27

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