Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/Basic/Targets/Mips.h
Line
Count
Source (jump to first uncovered line)
1
//===--- Mips.h - Declare Mips target feature support -----------*- C++ -*-===//
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 declares Mips TargetInfo objects.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_MIPS_H
14
#define LLVM_CLANG_LIB_BASIC_TARGETS_MIPS_H
15
16
#include "clang/Basic/TargetInfo.h"
17
#include "clang/Basic/TargetOptions.h"
18
#include "llvm/ADT/Triple.h"
19
#include "llvm/Support/Compiler.h"
20
21
namespace clang {
22
namespace targets {
23
24
class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public TargetInfo {
25
247
  void setDataLayout() {
26
247
    StringRef Layout;
27
247
28
247
    if (ABI == "o32")
29
122
      Layout = "m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64";
30
125
    else if (ABI == "n32")
31
31
      Layout = "m:e-p:32:32-i8:8:32-i16:16:32-i64:64-n32:64-S128";
32
94
    else if (ABI == "n64")
33
94
      Layout = "m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128";
34
94
    else
35
94
      
llvm_unreachable0
("Invalid ABI");
36
247
37
247
    if (BigEndian)
38
163
      resetDataLayout(("E-" + Layout).str());
39
84
    else
40
84
      resetDataLayout(("e-" + Layout).str());
41
247
  }
42
43
  static const Builtin::Info BuiltinInfo[];
44
  std::string CPU;
45
  bool IsMips16;
46
  bool IsMicromips;
47
  bool IsNan2008;
48
  bool IsAbs2008;
49
  bool IsSingleFloat;
50
  bool IsNoABICalls;
51
  bool CanUseBSDABICalls;
52
  enum MipsFloatABI { HardFloat, SoftFloat } FloatABI;
53
  enum DspRevEnum { NoDSP, DSP1, DSP2 } DspRev;
54
  bool HasMSA;
55
  bool DisableMadd4;
56
  bool UseIndirectJumpHazard;
57
58
protected:
59
  enum FPModeEnum { FPXX, FP32, FP64 } FPMode;
60
  std::string ABI;
61
62
public:
63
  MipsTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
64
      : TargetInfo(Triple), IsMips16(false), IsMicromips(false),
65
        IsNan2008(false), IsAbs2008(false), IsSingleFloat(false),
66
        IsNoABICalls(false), CanUseBSDABICalls(false), FloatABI(HardFloat),
67
        DspRev(NoDSP), HasMSA(false), DisableMadd4(false),
68
251
        UseIndirectJumpHazard(false), FPMode(FPXX) {
69
251
    TheCXXABI.set(TargetCXXABI::GenericMIPS);
70
251
71
251
    if (Triple.isMIPS32())
72
125
      setABI("o32");
73
126
    else if (Triple.getEnvironment() == llvm::Triple::GNUABIN32)
74
13
      setABI("n32");
75
113
    else
76
113
      setABI("n64");
77
251
78
251
    CPU = ABI == "o32" ? 
"mips32r2"125
:
"mips64r2"126
;
79
251
80
251
    CanUseBSDABICalls = Triple.isOSFreeBSD() ||
81
251
                        
Triple.isOSOpenBSD()247
;
82
251
  }
clang::targets::MipsTargetInfo::MipsTargetInfo(llvm::Triple const&, clang::TargetOptions const&)
Line
Count
Source
68
70
        UseIndirectJumpHazard(false), FPMode(FPXX) {
69
70
    TheCXXABI.set(TargetCXXABI::GenericMIPS);
70
70
71
70
    if (Triple.isMIPS32())
72
47
      setABI("o32");
73
23
    else if (Triple.getEnvironment() == llvm::Triple::GNUABIN32)
74
0
      setABI("n32");
75
23
    else
76
23
      setABI("n64");
77
70
78
70
    CPU = ABI == "o32" ? 
"mips32r2"47
:
"mips64r2"23
;
79
70
80
70
    CanUseBSDABICalls = Triple.isOSFreeBSD() ||
81
70
                        Triple.isOSOpenBSD();
82
70
  }
clang::targets::MipsTargetInfo::MipsTargetInfo(llvm::Triple const&, clang::TargetOptions const&)
Line
Count
Source
68
181
        UseIndirectJumpHazard(false), FPMode(FPXX) {
69
181
    TheCXXABI.set(TargetCXXABI::GenericMIPS);
70
181
71
181
    if (Triple.isMIPS32())
72
78
      setABI("o32");
73
103
    else if (Triple.getEnvironment() == llvm::Triple::GNUABIN32)
74
13
      setABI("n32");
75
90
    else
76
90
      setABI("n64");
77
181
78
181
    CPU = ABI == "o32" ? 
"mips32r2"78
:
"mips64r2"103
;
79
181
80
181
    CanUseBSDABICalls = Triple.isOSFreeBSD() ||
81
181
                        
Triple.isOSOpenBSD()177
;
82
181
  }
83
84
494
  bool isIEEE754_2008Default() const {
85
494
    return CPU == "mips32r6" || 
CPU == "mips64r6"484
;
86
494
  }
87
88
247
  bool isFP64Default() const {
89
247
    return CPU == "mips32r6" || 
ABI == "n32"242
||
ABI == "n64"211
||
ABI == "64"117
;
90
247
  }
91
92
40
  bool isNan2008() const override { return IsNan2008; }
93
94
  bool processorSupportsGPR64() const;
95
96
0
  StringRef getABI() const override { return ABI; }
97
98
312
  bool setABI(const std::string &Name) override {
99
312
    if (Name == "o32") {
100
143
      setO32ABITypes();
101
143
      ABI = Name;
102
143
      return true;
103
143
    }
104
169
105
169
    if (Name == "n32") {
106
31
      setN32ABITypes();
107
31
      ABI = Name;
108
31
      return true;
109
31
    }
110
138
    if (Name == "n64") {
111
136
      setN64ABITypes();
112
136
      ABI = Name;
113
136
      return true;
114
136
    }
115
2
    return false;
116
2
  }
117
118
143
  void setO32ABITypes() {
119
143
    Int64Type = SignedLongLong;
120
143
    IntMaxType = Int64Type;
121
143
    LongDoubleFormat = &llvm::APFloat::IEEEdouble();
122
143
    LongDoubleWidth = LongDoubleAlign = 64;
123
143
    LongWidth = LongAlign = 32;
124
143
    MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32;
125
143
    PointerWidth = PointerAlign = 32;
126
143
    PtrDiffType = SignedInt;
127
143
    SizeType = UnsignedInt;
128
143
    SuitableAlign = 64;
129
143
  }
130
131
167
  void setN32N64ABITypes() {
132
167
    LongDoubleWidth = LongDoubleAlign = 128;
133
167
    LongDoubleFormat = &llvm::APFloat::IEEEquad();
134
167
    if (getTriple().isOSFreeBSD()) {
135
2
      LongDoubleWidth = LongDoubleAlign = 64;
136
2
      LongDoubleFormat = &llvm::APFloat::IEEEdouble();
137
2
    }
138
167
    MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
139
167
    SuitableAlign = 128;
140
167
  }
141
142
136
  void setN64ABITypes() {
143
136
    setN32N64ABITypes();
144
136
    if (getTriple().isOSOpenBSD()) {
145
3
      Int64Type = SignedLongLong;
146
133
    } else {
147
133
      Int64Type = SignedLong;
148
133
    }
149
136
    IntMaxType = Int64Type;
150
136
    LongWidth = LongAlign = 64;
151
136
    PointerWidth = PointerAlign = 64;
152
136
    PtrDiffType = SignedLong;
153
136
    SizeType = UnsignedLong;
154
136
  }
155
156
31
  void setN32ABITypes() {
157
31
    setN32N64ABITypes();
158
31
    Int64Type = SignedLongLong;
159
31
    IntMaxType = Int64Type;
160
31
    LongWidth = LongAlign = 32;
161
31
    PointerWidth = PointerAlign = 32;
162
31
    PtrDiffType = SignedInt;
163
31
    SizeType = UnsignedInt;
164
31
  }
165
166
  bool isValidCPUName(StringRef Name) const override;
167
  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
168
169
60
  bool setCPU(const std::string &Name) override {
170
60
    CPU = Name;
171
60
    return isValidCPUName(Name);
172
60
  }
173
174
556
  const std::string &getCPU() const { return CPU; }
175
  bool
176
  initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
177
                 StringRef CPU,
178
247
                 const std::vector<std::string> &FeaturesVec) const override {
179
247
    if (CPU.empty())
180
189
      CPU = getCPU();
181
247
    if (CPU == "octeon")
182
0
      Features["mips64r2"] = Features["cnmips"] = true;
183
247
    else
184
247
      Features[CPU] = true;
185
247
    return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
186
247
  }
187
188
  unsigned getISARev() const;
189
190
  void getTargetDefines(const LangOptions &Opts,
191
                        MacroBuilder &Builder) const override;
192
193
  ArrayRef<Builtin::Info> getTargetBuiltins() const override;
194
195
  bool hasFeature(StringRef Feature) const override;
196
197
177
  BuiltinVaListKind getBuiltinVaListKind() const override {
198
177
    return TargetInfo::VoidPtrBuiltinVaList;
199
177
  }
200
201
415
  ArrayRef<const char *> getGCCRegNames() const override {
202
415
    static const char *const GCCRegNames[] = {
203
415
        // CPU register names
204
415
        // Must match second column of GCCRegAliases
205
415
        "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9", "$10",
206
415
        "$11", "$12", "$13", "$14", "$15", "$16", "$17", "$18", "$19", "$20",
207
415
        "$21", "$22", "$23", "$24", "$25", "$26", "$27", "$28", "$29", "$30",
208
415
        "$31",
209
415
        // Floating point register names
210
415
        "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7", "$f8", "$f9",
211
415
        "$f10", "$f11", "$f12", "$f13", "$f14", "$f15", "$f16", "$f17", "$f18",
212
415
        "$f19", "$f20", "$f21", "$f22", "$f23", "$f24", "$f25", "$f26", "$f27",
213
415
        "$f28", "$f29", "$f30", "$f31",
214
415
        // Hi/lo and condition register names
215
415
        "hi", "lo", "", "$fcc0", "$fcc1", "$fcc2", "$fcc3", "$fcc4", "$fcc5",
216
415
        "$fcc6", "$fcc7", "$ac1hi", "$ac1lo", "$ac2hi", "$ac2lo", "$ac3hi",
217
415
        "$ac3lo",
218
415
        // MSA register names
219
415
        "$w0", "$w1", "$w2", "$w3", "$w4", "$w5", "$w6", "$w7", "$w8", "$w9",
220
415
        "$w10", "$w11", "$w12", "$w13", "$w14", "$w15", "$w16", "$w17", "$w18",
221
415
        "$w19", "$w20", "$w21", "$w22", "$w23", "$w24", "$w25", "$w26", "$w27",
222
415
        "$w28", "$w29", "$w30", "$w31",
223
415
        // MSA control register names
224
415
        "$msair", "$msacsr", "$msaaccess", "$msasave", "$msamodify",
225
415
        "$msarequest", "$msamap", "$msaunmap"
226
415
    };
227
415
    return llvm::makeArrayRef(GCCRegNames);
228
415
  }
229
230
  bool validateAsmConstraint(const char *&Name,
231
18
                             TargetInfo::ConstraintInfo &Info) const override {
232
18
    switch (*Name) {
233
18
    default:
234
0
      return false;
235
18
    case 'r': // CPU registers.
236
10
    case 'd': // Equivalent to "r" unless generating MIPS16 code.
237
10
    case 'y': // Equivalent to "r", backward compatibility only.
238
10
    case 'f': // floating-point registers.
239
10
    case 'c': // $25 for indirect jumps
240
10
    case 'l': // lo register
241
10
    case 'x': // hilo register pair
242
10
      Info.setAllowsRegister();
243
10
      return true;
244
10
    case 'I': // Signed 16-bit constant
245
2
    case 'J': // Integer 0
246
2
    case 'K': // Unsigned 16-bit constant
247
2
    case 'L': // Signed 32-bit constant, lower 16-bit zeros (for lui)
248
2
    case 'M': // Constants not loadable via lui, addiu, or ori
249
2
    case 'N': // Constant -1 to -65535
250
2
    case 'O': // A signed 15-bit constant
251
2
    case 'P': // A constant between 1 go 65535
252
2
      return true;
253
4
    case 'R': // An address that can be used in a non-macro load or store
254
4
      Info.setAllowsMemory();
255
4
      return true;
256
2
    case 'Z':
257
2
      if (Name[1] == 'C') { // An address usable by ll, and sc.
258
2
        Info.setAllowsMemory();
259
2
        Name++; // Skip over 'Z'.
260
2
        return true;
261
2
      }
262
0
      return false;
263
18
    }
264
18
  }
265
266
263
  std::string convertConstraint(const char *&Constraint) const override {
267
263
    std::string R;
268
263
    switch (*Constraint) {
269
263
    case 'Z': // Two-character constraint; add "^" hint for later parsing.
270
1
      if (Constraint[1] == 'C') {
271
1
        R = std::string("^") + std::string(Constraint, 2);
272
1
        Constraint++;
273
1
        return R;
274
1
      }
275
0
      break;
276
262
    }
277
262
    return TargetInfo::convertConstraint(Constraint);
278
262
  }
279
280
220
  const char *getClobbers() const override {
281
220
    // In GCC, $1 is not widely used in generated code (it's used only in a few
282
220
    // specific situations), so there is no real need for users to add it to
283
220
    // the clobbers list if they want to use it in their inline assembly code.
284
220
    //
285
220
    // In LLVM, $1 is treated as a normal GPR and is always allocatable during
286
220
    // code generation, so using it in inline assembly without adding it to the
287
220
    // clobbers list can cause conflicts between the inline assembly code and
288
220
    // the surrounding generated code.
289
220
    //
290
220
    // Another problem is that LLVM is allowed to choose $1 for inline assembly
291
220
    // operands, which will conflict with the ".set at" assembler option (which
292
220
    // we use only for inline assembly, in order to maintain compatibility with
293
220
    // GCC) and will also conflict with the user's usage of $1.
294
220
    //
295
220
    // The easiest way to avoid these conflicts and keep $1 as an allocatable
296
220
    // register for generated code is to automatically clobber $1 for all inline
297
220
    // assembly code.
298
220
    //
299
220
    // FIXME: We should automatically clobber $1 only for inline assembly code
300
220
    // which actually uses it. This would allow LLVM to use $1 for inline
301
220
    // assembly operands if the user's assembly code doesn't use it.
302
220
    return "~{$1}";
303
220
  }
304
305
  bool handleTargetFeatures(std::vector<std::string> &Features,
306
247
                            DiagnosticsEngine &Diags) override {
307
247
    IsMips16 = false;
308
247
    IsMicromips = false;
309
247
    IsNan2008 = isIEEE754_2008Default();
310
247
    IsAbs2008 = isIEEE754_2008Default();
311
247
    IsSingleFloat = false;
312
247
    FloatABI = HardFloat;
313
247
    DspRev = NoDSP;
314
247
    FPMode = isFP64Default() ? 
FP64130
:
FPXX117
;
315
247
316
329
    for (const auto &Feature : Features) {
317
329
      if (Feature == "+single-float")
318
4
        IsSingleFloat = true;
319
325
      else if (Feature == "+soft-float")
320
3
        FloatABI = SoftFloat;
321
322
      else if (Feature == "+mips16")
322
1
        IsMips16 = true;
323
321
      else if (Feature == "+micromips")
324
1
        IsMicromips = true;
325
320
      else if (Feature == "+dsp")
326
1
        DspRev = std::max(DspRev, DSP1);
327
319
      else if (Feature == "+dspr2")
328
1
        DspRev = std::max(DspRev, DSP2);
329
318
      else if (Feature == "+msa")
330
3
        HasMSA = true;
331
315
      else if (Feature == "+nomadd4")
332
3
        DisableMadd4 = true;
333
312
      else if (Feature == "+fp64")
334
5
        FPMode = FP64;
335
307
      else if (Feature == "-fp64")
336
3
        FPMode = FP32;
337
304
      else if (Feature == "+fpxx")
338
4
        FPMode = FPXX;
339
300
      else if (Feature == "+nan2008")
340
6
        IsNan2008 = true;
341
294
      else if (Feature == "-nan2008")
342
7
        IsNan2008 = false;
343
287
      else if (Feature == "+abs2008")
344
2
        IsAbs2008 = true;
345
285
      else if (Feature == "-abs2008")
346
2
        IsAbs2008 = false;
347
283
      else if (Feature == "+noabicalls")
348
0
        IsNoABICalls = true;
349
283
      else if (Feature == "+use-indirect-jump-hazard")
350
0
        UseIndirectJumpHazard = true;
351
329
    }
352
247
353
247
    setDataLayout();
354
247
355
247
    return true;
356
247
  }
357
358
4
  int getEHDataRegisterNumber(unsigned RegNo) const override {
359
4
    if (RegNo == 0)
360
2
      return 4;
361
2
    if (RegNo == 1)
362
2
      return 5;
363
0
    return -1;
364
0
  }
365
366
6
  bool isCLZForZeroUndef() const override { return false; }
367
368
312
  ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
369
312
    static const TargetInfo::GCCRegAlias O32RegAliases[] = {
370
312
        {{"at"}, "$1"},  {{"v0"}, "$2"},         {{"v1"}, "$3"},
371
312
        {{"a0"}, "$4"},  {{"a1"}, "$5"},         {{"a2"}, "$6"},
372
312
        {{"a3"}, "$7"},  {{"t0"}, "$8"},         {{"t1"}, "$9"},
373
312
        {{"t2"}, "$10"}, {{"t3"}, "$11"},        {{"t4"}, "$12"},
374
312
        {{"t5"}, "$13"}, {{"t6"}, "$14"},        {{"t7"}, "$15"},
375
312
        {{"s0"}, "$16"}, {{"s1"}, "$17"},        {{"s2"}, "$18"},
376
312
        {{"s3"}, "$19"}, {{"s4"}, "$20"},        {{"s5"}, "$21"},
377
312
        {{"s6"}, "$22"}, {{"s7"}, "$23"},        {{"t8"}, "$24"},
378
312
        {{"t9"}, "$25"}, {{"k0"}, "$26"},        {{"k1"}, "$27"},
379
312
        {{"gp"}, "$28"}, {{"sp", "$sp"}, "$29"}, {{"fp", "$fp"}, "$30"},
380
312
        {{"ra"}, "$31"}
381
312
    };
382
312
    static const TargetInfo::GCCRegAlias NewABIRegAliases[] = {
383
312
        {{"at"}, "$1"},  {{"v0"}, "$2"},         {{"v1"}, "$3"},
384
312
        {{"a0"}, "$4"},  {{"a1"}, "$5"},         {{"a2"}, "$6"},
385
312
        {{"a3"}, "$7"},  {{"a4"}, "$8"},         {{"a5"}, "$9"},
386
312
        {{"a6"}, "$10"}, {{"a7"}, "$11"},        {{"t0"}, "$12"},
387
312
        {{"t1"}, "$13"}, {{"t2"}, "$14"},        {{"t3"}, "$15"},
388
312
        {{"s0"}, "$16"}, {{"s1"}, "$17"},        {{"s2"}, "$18"},
389
312
        {{"s3"}, "$19"}, {{"s4"}, "$20"},        {{"s5"}, "$21"},
390
312
        {{"s6"}, "$22"}, {{"s7"}, "$23"},        {{"t8"}, "$24"},
391
312
        {{"t9"}, "$25"}, {{"k0"}, "$26"},        {{"k1"}, "$27"},
392
312
        {{"gp"}, "$28"}, {{"sp", "$sp"}, "$29"}, {{"fp", "$fp"}, "$30"},
393
312
        {{"ra"}, "$31"}
394
312
    };
395
312
    if (ABI == "o32")
396
312
      return llvm::makeArrayRef(O32RegAliases);
397
0
    return llvm::makeArrayRef(NewABIRegAliases);
398
0
  }
399
400
667
  bool hasInt128Type() const override {
401
667
    return (ABI == "n32" || 
ABI == "n64"576
) ||
getTargetOpts().ForceEnableInt128326
;
402
667
  }
403
404
  unsigned getUnwindWordWidth() const override;
405
406
  bool validateTarget(DiagnosticsEngine &Diags) const override;
407
};
408
} // namespace targets
409
} // namespace clang
410
411
#endif // LLVM_CLANG_LIB_BASIC_TARGETS_MIPS_H