Coverage Report

Created: 2021-01-26 06:56

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