Coverage Report

Created: 2019-07-24 05:18

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