Coverage Report

Created: 2022-07-16 07:03

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