Coverage Report

Created: 2021-08-24 07:12

/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
30.9k
               const LangOptions &Opts) {
58
30.9k
  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
30.9k
  if (Opts.GNUMode)
63
16.5k
    Builder.defineMacro(MacroName);
64
65
  // Define __unix.
66
30.9k
  Builder.defineMacro("__" + MacroName);
67
68
  // Define __unix__.
69
30.9k
  Builder.defineMacro("__" + MacroName + "__");
70
30.9k
}
71
72
34.8k
void defineCPUMacros(MacroBuilder &Builder, StringRef CPUName, bool Tuning) {
73
34.8k
  Builder.defineMacro("__" + CPUName);
74
34.8k
  Builder.defineMacro("__" + CPUName + "__");
75
34.8k
  if (Tuning)
76
34.7k
    Builder.defineMacro("__tune_" + CPUName + "__");
77
34.8k
}
78
79
182
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
182
  if (Opts.MicrosoftExt)
84
41
    Builder.defineMacro("__declspec", "__declspec");
85
141
  else
86
141
    Builder.defineMacro("__declspec(a)", "__attribute__((a))");
87
88
182
  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
141
    const char *CCs[] = {"cdecl", "stdcall", "fastcall", "thiscall", "pascal"};
93
705
    for (const char *CC : CCs) {
94
705
      std::string GCCSpelling = "__attribute__((__";
95
705
      GCCSpelling += CC;
96
705
      GCCSpelling += "__))";
97
705
      Builder.defineMacro(Twine("_") + CC, GCCSpelling);
98
705
      Builder.defineMacro(Twine("__") + CC, GCCSpelling);
99
705
    }
100
141
  }
101
182
}
102
103
//===----------------------------------------------------------------------===//
104
// Driver code
105
//===----------------------------------------------------------------------===//
106
107
TargetInfo *AllocateTarget(const llvm::Triple &Triple,
108
105k
                           const TargetOptions &Opts) {
109
105k
  llvm::Triple::OSType os = Triple.getOS();
110
111
105k
  switch (Triple.getArch()) {
112
295
  default:
113
295
    return nullptr;
114
115
4
  case llvm::Triple::arc:
116
4
    return new ARCTargetInfo(Triple, Opts);
117
118
14
  case llvm::Triple::xcore:
119
14
    return new XCoreTargetInfo(Triple, Opts);
120
121
74
  case llvm::Triple::hexagon:
122
74
    if (os == llvm::Triple::Linux &&
123
74
        
Triple.getEnvironment() == llvm::Triple::Musl5
)
124
3
      return new LinuxTargetInfo<HexagonTargetInfo>(Triple, Opts);
125
71
    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.27k
  case llvm::Triple::aarch64:
136
3.27k
    if (Triple.isOSDarwin())
137
156
      return new DarwinAArch64TargetInfo(Triple, Opts);
138
139
3.11k
    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
45
    case llvm::Triple::Win32:
153
45
      switch (Triple.getEnvironment()) {
154
3
      case llvm::Triple::GNU:
155
3
        return new MinGWARM64TargetInfo(Triple, Opts);
156
41
      case llvm::Triple::MSVC:
157
42
      default: // Assume MSVC for unknown environments
158
42
        return new MicrosoftARM64TargetInfo(Triple, Opts);
159
45
      }
160
242
    default:
161
242
      return new AArch64leTargetInfo(Triple, Opts);
162
3.11k
    }
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
650
  case llvm::Triple::arm:
179
1.21k
  case llvm::Triple::thumb:
180
1.21k
    if (Triple.isOSBinFormatMachO())
181
213
      return new DarwinARMTargetInfo(Triple, Opts);
182
183
1.00k
    switch (os) {
184
3
    case llvm::Triple::CloudABI:
185
3
      return new CloudABITargetInfo<ARMleTargetInfo>(Triple, Opts);
186
273
    case llvm::Triple::Linux:
187
273
      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
96
    case llvm::Triple::Win32:
199
96
      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
79
      case llvm::Triple::MSVC:
207
81
      default: // Assume MSVC for unknown environments
208
81
        return new MicrosoftARMleTargetInfo(Triple, Opts);
209
96
      }
210
608
    default:
211
608
      return new ARMleTargetInfo(Triple, Opts);
212
1.00k
    }
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
35
  case llvm::Triple::bpfel:
240
35
    return new BPFTargetInfo(Triple, Opts);
241
242
18
  case llvm::Triple::msp430:
243
18
    return new MSP430TargetInfo(Triple, Opts);
244
245
86
  case llvm::Triple::mips:
246
86
    switch (os) {
247
37
    case llvm::Triple::Linux:
248
37
      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
45
    default:
256
45
      return new MipsTargetInfo(Triple, Opts);
257
86
    }
258
259
39
  case llvm::Triple::mipsel:
260
39
    switch (os) {
261
33
    case llvm::Triple::Linux:
262
33
      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
39
    }
274
275
92
  case llvm::Triple::mips64:
276
92
    switch (os) {
277
62
    case llvm::Triple::Linux:
278
62
      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
92
    }
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
265
  case llvm::Triple::ppc:
329
265
    if (Triple.isOSDarwin())
330
6
      return new DarwinPPC32TargetInfo(Triple, Opts);
331
259
    switch (os) {
332
35
    case llvm::Triple::Linux:
333
35
      return new LinuxTargetInfo<PPC32TargetInfo>(Triple, Opts);
334
3
    case llvm::Triple::FreeBSD:
335
3
      return new FreeBSDTargetInfo<PPC32TargetInfo>(Triple, Opts);
336
3
    case llvm::Triple::NetBSD:
337
3
      return new NetBSDTargetInfo<PPC32TargetInfo>(Triple, Opts);
338
8
    case llvm::Triple::OpenBSD:
339
8
      return new OpenBSDTargetInfo<PPC32TargetInfo>(Triple, Opts);
340
0
    case llvm::Triple::RTEMS:
341
0
      return new RTEMSTargetInfo<PPC32TargetInfo>(Triple, Opts);
342
144
    case llvm::Triple::AIX:
343
144
      return new AIXPPC32TargetInfo(Triple, Opts);
344
66
    default:
345
66
      return new PPC32TargetInfo(Triple, Opts);
346
259
    }
347
348
11
  case llvm::Triple::ppcle:
349
11
    switch (os) {
350
3
    case llvm::Triple::Linux:
351
3
      return new LinuxTargetInfo<PPC32TargetInfo>(Triple, Opts);
352
1
    case llvm::Triple::FreeBSD:
353
1
      return new FreeBSDTargetInfo<PPC32TargetInfo>(Triple, Opts);
354
7
    default:
355
7
      return new PPC32TargetInfo(Triple, Opts);
356
11
    }
357
358
339
  case llvm::Triple::ppc64:
359
339
    if (Triple.isOSDarwin())
360
1
      return new DarwinPPC64TargetInfo(Triple, Opts);
361
338
    switch (os) {
362
100
    case llvm::Triple::Linux:
363
100
      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
3
    case llvm::Triple::NetBSD:
369
3
      return new NetBSDTargetInfo<PPC64TargetInfo>(Triple, Opts);
370
2
    case llvm::Triple::OpenBSD:
371
2
      return new OpenBSDTargetInfo<PPC64TargetInfo>(Triple, Opts);
372
118
    case llvm::Triple::AIX:
373
118
      return new AIXPPC64TargetInfo(Triple, Opts);
374
109
    default:
375
109
      return new PPC64TargetInfo(Triple, Opts);
376
338
    }
377
378
3.76k
  case llvm::Triple::ppc64le:
379
3.76k
    switch (os) {
380
218
    case llvm::Triple::Linux:
381
218
      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.54k
    default:
389
3.54k
      return new PPC64TargetInfo(Triple, Opts);
390
3.76k
    }
391
392
178
  case llvm::Triple::nvptx:
393
178
    return new NVPTXTargetInfo(Triple, Opts, /*TargetPointerWidth=*/32);
394
235
  case llvm::Triple::nvptx64:
395
235
    return new NVPTXTargetInfo(Triple, Opts, /*TargetPointerWidth=*/64);
396
397
395
  case llvm::Triple::amdgcn:
398
466
  case llvm::Triple::r600:
399
466
    return new AMDGPUTargetInfo(Triple, Opts);
400
401
97
  case llvm::Triple::riscv32:
402
    // TODO: add cases for NetBSD, RTEMS once tested.
403
97
    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
56
    default:
409
56
      return new RISCV32TargetInfo(Triple, Opts);
410
97
    }
411
412
406
  case llvm::Triple::riscv64:
413
    // TODO: add cases for NetBSD, RTEMS once tested.
414
406
    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
33
    case llvm::Triple::Linux:
422
33
      return new LinuxTargetInfo<RISCV64TargetInfo>(Triple, Opts);
423
369
    default:
424
369
      return new RISCV64TargetInfo(Triple, Opts);
425
406
    }
426
427
28
  case llvm::Triple::sparc:
428
28
    switch (os) {
429
2
    case llvm::Triple::Linux:
430
2
      return new LinuxTargetInfo<SparcV8TargetInfo>(Triple, Opts);
431
4
    case llvm::Triple::Solaris:
432
4
      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
18
    default:
438
18
      return new SparcV8TargetInfo(Triple, Opts);
439
28
    }
440
441
  // The 'sparcel' architecture copies all the above cases except for Solaris.
442
16
  case llvm::Triple::sparcel:
443
16
    switch (os) {
444
1
    case llvm::Triple::Linux:
445
1
      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
15
    default:
451
15
      return new SparcV8elTargetInfo(Triple, Opts);
452
16
    }
453
454
29
  case llvm::Triple::sparcv9:
455
29
    switch (os) {
456
7
    case llvm::Triple::Linux:
457
7
      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
2
    case llvm::Triple::OpenBSD:
463
2
      return new OpenBSDTargetInfo<SparcV9TargetInfo>(Triple, Opts);
464
0
    case llvm::Triple::FreeBSD:
465
0
      return new FreeBSDTargetInfo<SparcV9TargetInfo>(Triple, Opts);
466
10
    default:
467
10
      return new SparcV9TargetInfo(Triple, Opts);
468
29
    }
469
470
143
  case llvm::Triple::systemz:
471
143
    switch (os) {
472
97
    case llvm::Triple::Linux:
473
97
      return new LinuxTargetInfo<SystemZTargetInfo>(Triple, Opts);
474
16
    case llvm::Triple::ZOS:
475
16
      return new ZOSTargetInfo<SystemZTargetInfo>(Triple, Opts);
476
30
    default:
477
30
      return new SystemZTargetInfo(Triple, Opts);
478
143
    }
479
480
5
  case llvm::Triple::tce:
481
5
    return new TCETargetInfo(Triple, Opts);
482
483
1
  case llvm::Triple::tcele:
484
1
    return new TCELETargetInfo(Triple, Opts);
485
486
14.2k
  case llvm::Triple::x86:
487
14.2k
    if (Triple.isOSDarwin())
488
380
      return new DarwinI386TargetInfo(Triple, Opts);
489
490
13.8k
    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
497
    case llvm::Triple::Linux: {
496
497
      switch (Triple.getEnvironment()) {
497
493
      default:
498
493
        return new LinuxTargetInfo<X86_32TargetInfo>(Triple, Opts);
499
4
      case llvm::Triple::Android:
500
4
        return new AndroidX86_32TargetInfo(Triple, Opts);
501
497
      }
502
497
    }
503
1
    case llvm::Triple::DragonFly:
504
1
      return new DragonFlyBSDTargetInfo<X86_32TargetInfo>(Triple, Opts);
505
4
    case llvm::Triple::NetBSD:
506
4
      return new NetBSDI386TargetInfo(Triple, Opts);
507
4
    case llvm::Triple::OpenBSD:
508
4
      return new OpenBSDI386TargetInfo(Triple, Opts);
509
3
    case llvm::Triple::FreeBSD:
510
3
      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
658
    case llvm::Triple::Win32: {
520
658
      switch (Triple.getEnvironment()) {
521
11
      case llvm::Triple::Cygnus:
522
11
        return new CygwinX86_32TargetInfo(Triple, Opts);
523
110
      case llvm::Triple::GNU:
524
110
        return new MinGWX86_32TargetInfo(Triple, Opts);
525
22
      case llvm::Triple::Itanium:
526
537
      case llvm::Triple::MSVC:
527
537
      default: // Assume MSVC for unknown environments
528
537
        return new MicrosoftX86_32TargetInfo(Triple, Opts);
529
658
      }
530
658
    }
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
12.7k
    default:
542
12.7k
      return new X86_32TargetInfo(Triple, Opts);
543
13.8k
    }
544
545
79.7k
  case llvm::Triple::x86_64:
546
79.7k
    if (Triple.isOSDarwin() || 
Triple.isOSBinFormatMachO()12.6k
)
547
67.0k
      return new DarwinX86_64TargetInfo(Triple, Opts);
548
549
12.6k
    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.39k
    case llvm::Triple::Linux: {
555
3.39k
      switch (Triple.getEnvironment()) {
556
3.38k
      default:
557
3.38k
        return new LinuxTargetInfo<X86_64TargetInfo>(Triple, Opts);
558
5
      case llvm::Triple::Android:
559
5
        return new AndroidX86_64TargetInfo(Triple, Opts);
560
3.39k
      }
561
3.39k
    }
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
3
    case llvm::Triple::OpenBSD:
567
3
      return new OpenBSDX86_64TargetInfo(Triple, Opts);
568
38
    case llvm::Triple::FreeBSD:
569
38
      return new FreeBSDTargetInfo<X86_64TargetInfo>(Triple, Opts);
570
3
    case llvm::Triple::Fuchsia:
571
3
      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
7.77k
    case llvm::Triple::Win32: {
577
7.77k
      switch (Triple.getEnvironment()) {
578
3
      case llvm::Triple::Cygnus:
579
3
        return new CygwinX86_64TargetInfo(Triple, Opts);
580
51
      case llvm::Triple::GNU:
581
51
        return new MinGWX86_64TargetInfo(Triple, Opts);
582
7.70k
      case llvm::Triple::MSVC:
583
7.72k
      default: // Assume MSVC for unknown environments
584
7.72k
        return new MicrosoftX86_64TargetInfo(Triple, Opts);
585
7.77k
      }
586
7.77k
    }
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
36
    case llvm::Triple::PS4:
592
36
      return new PS4OSTargetInfo<X86_64TargetInfo>(Triple, Opts);
593
1.34k
    default:
594
1.34k
      return new X86_64TargetInfo(Triple, Opts);
595
12.6k
    }
596
597
219
  case llvm::Triple::spir: {
598
219
    if (os != llvm::Triple::UnknownOS ||
599
219
        Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
600
0
      return nullptr;
601
219
    return new SPIR32TargetInfo(Triple, Opts);
602
219
  }
603
43
  case llvm::Triple::spir64: {
604
43
    if (os != llvm::Triple::UnknownOS ||
605
43
        Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
606
0
      return nullptr;
607
43
    return new SPIR64TargetInfo(Triple, Opts);
608
43
  }
609
64
  case llvm::Triple::wasm32:
610
64
    if (Triple.getSubArch() != llvm::Triple::NoSubArch ||
611
64
        Triple.getVendor() != llvm::Triple::UnknownVendor ||
612
64
        !Triple.isOSBinFormatWasm())
613
0
      return nullptr;
614
64
    switch (os) {
615
1
      case llvm::Triple::WASI:
616
1
        return new WASITargetInfo<WebAssembly32TargetInfo>(Triple, Opts);
617
4
      case llvm::Triple::Emscripten:
618
4
        return new EmscriptenTargetInfo<WebAssembly32TargetInfo>(Triple, Opts);
619
59
      case llvm::Triple::UnknownOS:
620
59
        return new WebAssemblyOSTargetInfo<WebAssembly32TargetInfo>(Triple, Opts);
621
0
      default:
622
0
        return nullptr;
623
64
    }
624
32
  case llvm::Triple::wasm64:
625
32
    if (Triple.getSubArch() != llvm::Triple::NoSubArch ||
626
32
        Triple.getVendor() != llvm::Triple::UnknownVendor ||
627
32
        !Triple.isOSBinFormatWasm())
628
0
      return nullptr;
629
32
    switch (os) {
630
1
      case llvm::Triple::WASI:
631
1
        return new WASITargetInfo<WebAssembly64TargetInfo>(Triple, Opts);
632
1
      case llvm::Triple::Emscripten:
633
1
        return new EmscriptenTargetInfo<WebAssembly64TargetInfo>(Triple, Opts);
634
30
      case llvm::Triple::UnknownOS:
635
30
        return new WebAssemblyOSTargetInfo<WebAssembly64TargetInfo>(Triple, Opts);
636
0
      default:
637
0
        return nullptr;
638
32
    }
639
640
1
  case llvm::Triple::renderscript32:
641
1
    return new LinuxTargetInfo<RenderScript32TargetInfo>(Triple, Opts);
642
1
  case llvm::Triple::renderscript64:
643
1
    return new LinuxTargetInfo<RenderScript64TargetInfo>(Triple, Opts);
644
645
3
  case llvm::Triple::ve:
646
3
    return new LinuxTargetInfo<VETargetInfo>(Triple, Opts);
647
105k
  }
648
105k
}
649
} // namespace targets
650
} // namespace clang
651
652
using namespace clang::targets;
653
/// CreateTargetInfo - Return the target info object for the specified target
654
/// options.
655
TargetInfo *
656
TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags,
657
105k
                             const std::shared_ptr<TargetOptions> &Opts) {
658
105k
  llvm::Triple Triple(Opts->Triple);
659
660
  // Construct the target
661
105k
  std::unique_ptr<TargetInfo> Target(AllocateTarget(Triple, *Opts));
662
105k
  if (!Target) {
663
5
    Diags.Report(diag::err_target_unknown_triple) << Triple.str();
664
5
    return nullptr;
665
5
  }
666
105k
  Target->TargetOpts = Opts;
667
668
  // Set the target CPU if specified.
669
105k
  if (!Opts->CPU.empty() && 
!Target->setCPU(Opts->CPU)36.6k
) {
670
59
    Diags.Report(diag::err_target_unknown_cpu) << Opts->CPU;
671
59
    SmallVector<StringRef, 32> ValidList;
672
59
    Target->fillValidCPUList(ValidList);
673
59
    if (!ValidList.empty())
674
59
      Diags.Report(diag::note_valid_options) << llvm::join(ValidList, ", ");
675
59
    return nullptr;
676
59
  }
677
678
  // Check the TuneCPU name if specified.
679
105k
  if (!Opts->TuneCPU.empty() &&
680
105k
      
!Target->isValidTuneCPUName(Opts->TuneCPU)34.3k
) {
681
8
    Diags.Report(diag::err_target_unknown_cpu) << Opts->TuneCPU;
682
8
    SmallVector<StringRef, 32> ValidList;
683
8
    Target->fillValidTuneCPUList(ValidList);
684
8
    if (!ValidList.empty())
685
8
      Diags.Report(diag::note_valid_options) << llvm::join(ValidList, ", ");
686
8
    return nullptr;
687
8
  }
688
689
  // Set the target ABI if specified.
690
105k
  if (!Opts->ABI.empty() && 
!Target->setABI(Opts->ABI)1.06k
) {
691
4
    Diags.Report(diag::err_target_unknown_abi) << Opts->ABI;
692
4
    return nullptr;
693
4
  }
694
695
  // Set the fp math unit.
696
105k
  if (!Opts->FPMath.empty() && 
!Target->setFPMath(Opts->FPMath)13
) {
697
1
    Diags.Report(diag::err_target_unknown_fpmath) << Opts->FPMath;
698
1
    return nullptr;
699
1
  }
700
701
  // Compute the default target features, we need the target to handle this
702
  // because features may have dependencies on one another.
703
105k
  if (!Target->initFeatureMap(Opts->FeatureMap, Diags, Opts->CPU,
704
105k
                              Opts->FeaturesAsWritten))
705
22
    return nullptr;
706
707
  // Add the features to the compile options.
708
105k
  Opts->Features.clear();
709
105k
  for (const auto &F : Opts->FeatureMap)
710
666k
    Opts->Features.push_back((F.getValue() ? 
"+"597k
:
"-"69.2k
) + F.getKey().str());
711
  // Sort here, so we handle the features in a predictable order. (This matters
712
  // when we're dealing with features that overlap.)
713
105k
  llvm::sort(Opts->Features);
714
715
105k
  if (!Target->handleTargetFeatures(Opts->Features, Diags))
716
5
    return nullptr;
717
718
105k
  Target->setSupportedOpenCLOpts();
719
105k
  Target->setCommandLineOpenCLOpts();
720
105k
  Target->setMaxAtomicWidth();
721
722
105k
  if (!Target->validateTarget(Diags))
723
6
    return nullptr;
724
725
105k
  Target->CheckFixedPointBits();
726
727
105k
  return Target.release();
728
105k
}
729
/// validateOpenCLTarget  - Check that OpenCL target has valid
730
/// options setting based on OpenCL version.
731
bool TargetInfo::validateOpenCLTarget(const LangOptions &Opts,
732
830
                                      DiagnosticsEngine &Diags) const {
733
830
  const llvm::StringMap<bool> &OpenCLFeaturesMap = getSupportedOpenCLOpts();
734
735
34.8k
  auto diagnoseNotSupportedCore = [&](llvm::StringRef Name, auto... OptArgs) {
736
34.8k
    if (OpenCLOptions::isOpenCLOptionCoreIn(Opts, OptArgs...) &&
737
34.8k
        
!hasFeatureEnabled(OpenCLFeaturesMap, Name)4.24k
)
738
144
      Diags.Report(diag::warn_opencl_unsupported_core_feature)
739
144
          << Name << Opts.OpenCLCPlusPlus
740
144
          << Opts.getOpenCLVersionTuple().getAsString();
741
34.8k
  };
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
735
4.15k
  auto diagnoseNotSupportedCore = [&](llvm::StringRef Name, auto... OptArgs) {
736
4.15k
    if (OpenCLOptions::isOpenCLOptionCoreIn(Opts, OptArgs...) &&
737
4.15k
        
!hasFeatureEnabled(OpenCLFeaturesMap, Name)3.96k
)
738
140
      Diags.Report(diag::warn_opencl_unsupported_core_feature)
739
140
          << Name << Opts.OpenCLCPlusPlus
740
140
          << Opts.getOpenCLVersionTuple().getAsString();
741
4.15k
  };
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
735
9.96k
  auto diagnoseNotSupportedCore = [&](llvm::StringRef Name, auto... OptArgs) {
736
9.96k
    if (OpenCLOptions::isOpenCLOptionCoreIn(Opts, OptArgs...) &&
737
9.96k
        
!hasFeatureEnabled(OpenCLFeaturesMap, Name)0
)
738
0
      Diags.Report(diag::warn_opencl_unsupported_core_feature)
739
0
          << Name << Opts.OpenCLCPlusPlus
740
0
          << Opts.getOpenCLVersionTuple().getAsString();
741
9.96k
  };
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
735
19.9k
  auto diagnoseNotSupportedCore = [&](llvm::StringRef Name, auto... OptArgs) {
736
19.9k
    if (OpenCLOptions::isOpenCLOptionCoreIn(Opts, OptArgs...) &&
737
19.9k
        
!hasFeatureEnabled(OpenCLFeaturesMap, Name)0
)
738
0
      Diags.Report(diag::warn_opencl_unsupported_core_feature)
739
0
          << Name << Opts.OpenCLCPlusPlus
740
0
          << Opts.getOpenCLVersionTuple().getAsString();
741
19.9k
  };
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
735
830
  auto diagnoseNotSupportedCore = [&](llvm::StringRef Name, auto... OptArgs) {
736
830
    if (OpenCLOptions::isOpenCLOptionCoreIn(Opts, OptArgs...) &&
737
830
        
!hasFeatureEnabled(OpenCLFeaturesMap, Name)282
)
738
4
      Diags.Report(diag::warn_opencl_unsupported_core_feature)
739
4
          << Name << Opts.OpenCLCPlusPlus
740
4
          << Opts.getOpenCLVersionTuple().getAsString();
741
830
  };
742
830
#define OPENCL_GENERIC_EXTENSION(Ext, ...)                                     \
743
34.8k
  diagnoseNotSupportedCore(#Ext, __VA_ARGS__);
744
830
#include "clang/Basic/OpenCLExtensions.def"
745
746
  // Validate that feature macros are set properly for OpenCL C 3.0.
747
  // In other cases assume that target is always valid.
748
830
  if (Opts.OpenCLCPlusPlus || 
Opts.OpenCLVersion < 300727
)
749
758
    return true;
750
751
72
  return OpenCLOptions::diagnoseUnsupportedFeatureDependencies(*this, Diags) &&
752
72
         
OpenCLOptions::diagnoseFeatureExtensionDifferences(*this, Diags)69
;
753
830
}