Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/Mips/MCTargetDesc/MipsABIFlagsSection.h
Line
Count
Source (jump to first uncovered line)
1
//===- MipsABIFlagsSection.h - Mips ELF ABI Flags Section -------*- 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
#ifndef LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSABIFLAGSSECTION_H
10
#define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSABIFLAGSSECTION_H
11
12
#include "llvm/ADT/StringRef.h"
13
#include "llvm/Support/ErrorHandling.h"
14
#include "llvm/Support/MipsABIFlags.h"
15
#include <cstdint>
16
17
namespace llvm {
18
19
class MCStreamer;
20
21
struct MipsABIFlagsSection {
22
  // Internal representation of the fp_abi related values used in .module.
23
  enum class FpABIKind { ANY, XX, S32, S64, SOFT };
24
25
  // Version of flags structure.
26
  uint16_t Version = 0;
27
  // The level of the ISA: 1-5, 32, 64.
28
  uint8_t ISALevel = 0;
29
  // The revision of ISA: 0 for MIPS V and below, 1-n otherwise.
30
  uint8_t ISARevision = 0;
31
  // The size of general purpose registers.
32
  Mips::AFL_REG GPRSize = Mips::AFL_REG_NONE;
33
  // The size of co-processor 1 registers.
34
  Mips::AFL_REG CPR1Size = Mips::AFL_REG_NONE;
35
  // The size of co-processor 2 registers.
36
  Mips::AFL_REG CPR2Size = Mips::AFL_REG_NONE;
37
  // Processor-specific extension.
38
  Mips::AFL_EXT ISAExtension = Mips::AFL_EXT_NONE;
39
  // Mask of ASEs used.
40
  uint32_t ASESet = 0;
41
42
  bool OddSPReg = false;
43
44
  bool Is32BitABI = false;
45
46
protected:
47
  // The floating-point ABI.
48
  FpABIKind FpABI = FpABIKind::ANY;
49
50
public:
51
3.19k
  MipsABIFlagsSection() = default;
52
53
542
  uint16_t getVersionValue() { return (uint16_t)Version; }
54
542
  uint8_t getISALevelValue() { return (uint8_t)ISALevel; }
55
542
  uint8_t getISARevisionValue() { return (uint8_t)ISARevision; }
56
542
  uint8_t getGPRSizeValue() { return (uint8_t)GPRSize; }
57
  uint8_t getCPR1SizeValue();
58
542
  uint8_t getCPR2SizeValue() { return (uint8_t)CPR2Size; }
59
  uint8_t getFpABIValue();
60
542
  uint32_t getISAExtensionValue() { return (uint32_t)ISAExtension; }
61
542
  uint32_t getASESetValue() { return (uint32_t)ASESet; }
62
63
542
  uint32_t getFlags1Value() {
64
542
    uint32_t Value = 0;
65
542
66
542
    if (OddSPReg)
67
540
      Value |= (uint32_t)Mips::AFL_FLAGS1_ODDSPREG;
68
542
69
542
    return Value;
70
542
  }
71
72
542
  uint32_t getFlags2Value() { return 0; }
73
74
485
  FpABIKind getFpABI() { return FpABI; }
75
0
  void setFpABI(FpABIKind Value, bool IsABI32Bit) {
76
0
    FpABI = Value;
77
0
    Is32BitABI = IsABI32Bit;
78
0
  }
79
80
  StringRef getFpABIString(FpABIKind Value);
81
82
  template <class PredicateLibrary>
83
6.55k
  void setISALevelAndRevisionFromPredicates(const PredicateLibrary &P) {
84
6.55k
    if (P.hasMips64()) {
85
1.08k
      ISALevel = 64;
86
1.08k
      if (P.hasMips64r6())
87
154
        ISARevision = 6;
88
926
      else if (P.hasMips64r5())
89
65
        ISARevision = 5;
90
861
      else if (P.hasMips64r3())
91
50
        ISARevision = 3;
92
811
      else if (P.hasMips64r2())
93
236
        ISARevision = 2;
94
575
      else
95
575
        ISARevision = 1;
96
5.47k
    } else if (P.hasMips32()) {
97
5.25k
      ISALevel = 32;
98
5.25k
      if (P.hasMips32r6())
99
1.37k
        ISARevision = 6;
100
3.87k
      else if (P.hasMips32r5())
101
92
        ISARevision = 5;
102
3.78k
      else if (P.hasMips32r3())
103
408
        ISARevision = 3;
104
3.37k
      else if (P.hasMips32r2())
105
1.15k
        ISARevision = 2;
106
2.22k
      else
107
2.22k
        ISARevision = 1;
108
5.25k
    } else {
109
217
      ISARevision = 0;
110
217
      if (P.hasMips5())
111
14
        ISALevel = 5;
112
203
      else if (P.hasMips4())
113
90
        ISALevel = 4;
114
113
      else if (P.hasMips3())
115
48
        ISALevel = 3;
116
65
      else if (P.hasMips2())
117
40
        ISALevel = 2;
118
25
      else if (P.hasMips1())
119
25
        ISALevel = 1;
120
25
      else
121
25
        
llvm_unreachable0
("Unknown ISA level!");
122
217
    }
123
6.55k
  }
void llvm::MipsABIFlagsSection::setISALevelAndRevisionFromPredicates<llvm::MipsSubtarget>(llvm::MipsSubtarget const&)
Line
Count
Source
83
2.91k
  void setISALevelAndRevisionFromPredicates(const PredicateLibrary &P) {
84
2.91k
    if (P.hasMips64()) {
85
575
      ISALevel = 64;
86
575
      if (P.hasMips64r6())
87
94
        ISARevision = 6;
88
481
      else if (P.hasMips64r5())
89
35
        ISARevision = 5;
90
446
      else if (P.hasMips64r3())
91
25
        ISARevision = 3;
92
421
      else if (P.hasMips64r2())
93
140
        ISARevision = 2;
94
281
      else
95
281
        ISARevision = 1;
96
2.33k
    } else if (P.hasMips32()) {
97
2.21k
      ISALevel = 32;
98
2.21k
      if (P.hasMips32r6())
99
550
        ISARevision = 6;
100
1.66k
      else if (P.hasMips32r5())
101
40
        ISARevision = 5;
102
1.62k
      else if (P.hasMips32r3())
103
368
        ISARevision = 3;
104
1.25k
      else if (P.hasMips32r2())
105
502
        ISARevision = 2;
106
753
      else
107
753
        ISARevision = 1;
108
2.21k
    } else {
109
122
      ISARevision = 0;
110
122
      if (P.hasMips5())
111
0
        ISALevel = 5;
112
122
      else if (P.hasMips4())
113
71
        ISALevel = 4;
114
51
      else if (P.hasMips3())
115
28
        ISALevel = 3;
116
23
      else if (P.hasMips2())
117
23
        ISALevel = 2;
118
0
      else if (P.hasMips1())
119
0
        ISALevel = 1;
120
0
      else
121
0
        llvm_unreachable("Unknown ISA level!");
122
122
    }
123
2.91k
  }
MipsAsmParser.cpp:void llvm::MipsABIFlagsSection::setISALevelAndRevisionFromPredicates<(anonymous namespace)::MipsAsmParser>((anonymous namespace)::MipsAsmParser const&)
Line
Count
Source
83
3.64k
  void setISALevelAndRevisionFromPredicates(const PredicateLibrary &P) {
84
3.64k
    if (P.hasMips64()) {
85
505
      ISALevel = 64;
86
505
      if (P.hasMips64r6())
87
60
        ISARevision = 6;
88
445
      else if (P.hasMips64r5())
89
30
        ISARevision = 5;
90
415
      else if (P.hasMips64r3())
91
25
        ISARevision = 3;
92
390
      else if (P.hasMips64r2())
93
96
        ISARevision = 2;
94
294
      else
95
294
        ISARevision = 1;
96
3.13k
    } else if (P.hasMips32()) {
97
3.04k
      ISALevel = 32;
98
3.04k
      if (P.hasMips32r6())
99
828
        ISARevision = 6;
100
2.21k
      else if (P.hasMips32r5())
101
52
        ISARevision = 5;
102
2.16k
      else if (P.hasMips32r3())
103
40
        ISARevision = 3;
104
2.12k
      else if (P.hasMips32r2())
105
654
        ISARevision = 2;
106
1.47k
      else
107
1.47k
        ISARevision = 1;
108
3.04k
    } else {
109
95
      ISARevision = 0;
110
95
      if (P.hasMips5())
111
14
        ISALevel = 5;
112
81
      else if (P.hasMips4())
113
19
        ISALevel = 4;
114
62
      else if (P.hasMips3())
115
20
        ISALevel = 3;
116
42
      else if (P.hasMips2())
117
17
        ISALevel = 2;
118
25
      else if (P.hasMips1())
119
25
        ISALevel = 1;
120
25
      else
121
25
        
llvm_unreachable0
("Unknown ISA level!");
122
95
    }
123
3.64k
  }
124
125
  template <class PredicateLibrary>
126
6.55k
  void setGPRSizeFromPredicates(const PredicateLibrary &P) {
127
6.55k
    GPRSize = P.isGP64bit() ? 
Mips::AFL_REG_641.23k
:
Mips::AFL_REG_325.31k
;
128
6.55k
  }
void llvm::MipsABIFlagsSection::setGPRSizeFromPredicates<llvm::MipsSubtarget>(llvm::MipsSubtarget const&)
Line
Count
Source
126
2.91k
  void setGPRSizeFromPredicates(const PredicateLibrary &P) {
127
2.91k
    GPRSize = P.isGP64bit() ? 
Mips::AFL_REG_64674
:
Mips::AFL_REG_322.23k
;
128
2.91k
  }
MipsAsmParser.cpp:void llvm::MipsABIFlagsSection::setGPRSizeFromPredicates<(anonymous namespace)::MipsAsmParser>((anonymous namespace)::MipsAsmParser const&)
Line
Count
Source
126
3.64k
  void setGPRSizeFromPredicates(const PredicateLibrary &P) {
127
3.64k
    GPRSize = P.isGP64bit() ? 
Mips::AFL_REG_64564
:
Mips::AFL_REG_323.08k
;
128
3.64k
  }
129
130
  template <class PredicateLibrary>
131
6.55k
  void setCPR1SizeFromPredicates(const PredicateLibrary &P) {
132
6.55k
    if (P.useSoftFloat())
133
124
      CPR1Size = Mips::AFL_REG_NONE;
134
6.43k
    else if (P.hasMSA())
135
253
      CPR1Size = Mips::AFL_REG_128;
136
6.17k
    else
137
6.17k
      CPR1Size = P.isFP64bit() ? 
Mips::AFL_REG_642.64k
:
Mips::AFL_REG_323.53k
;
138
6.55k
  }
void llvm::MipsABIFlagsSection::setCPR1SizeFromPredicates<llvm::MipsSubtarget>(llvm::MipsSubtarget const&)
Line
Count
Source
131
2.91k
  void setCPR1SizeFromPredicates(const PredicateLibrary &P) {
132
2.91k
    if (P.useSoftFloat())
133
75
      CPR1Size = Mips::AFL_REG_NONE;
134
2.83k
    else if (P.hasMSA())
135
190
      CPR1Size = Mips::AFL_REG_128;
136
2.64k
    else
137
2.64k
      CPR1Size = P.isFP64bit() ? 
Mips::AFL_REG_641.21k
:
Mips::AFL_REG_321.42k
;
138
2.91k
  }
MipsAsmParser.cpp:void llvm::MipsABIFlagsSection::setCPR1SizeFromPredicates<(anonymous namespace)::MipsAsmParser>((anonymous namespace)::MipsAsmParser const&)
Line
Count
Source
131
3.64k
  void setCPR1SizeFromPredicates(const PredicateLibrary &P) {
132
3.64k
    if (P.useSoftFloat())
133
49
      CPR1Size = Mips::AFL_REG_NONE;
134
3.59k
    else if (P.hasMSA())
135
63
      CPR1Size = Mips::AFL_REG_128;
136
3.53k
    else
137
3.53k
      CPR1Size = P.isFP64bit() ? 
Mips::AFL_REG_641.42k
:
Mips::AFL_REG_322.10k
;
138
3.64k
  }
139
140
  template <class PredicateLibrary>
141
6.55k
  void setISAExtensionFromPredicates(const PredicateLibrary &P) {
142
6.55k
    if (P.hasCnMips())
143
14
      ISAExtension = Mips::AFL_EXT_OCTEON;
144
6.54k
    else
145
6.54k
      ISAExtension = Mips::AFL_EXT_NONE;
146
6.55k
  }
void llvm::MipsABIFlagsSection::setISAExtensionFromPredicates<llvm::MipsSubtarget>(llvm::MipsSubtarget const&)
Line
Count
Source
141
2.91k
  void setISAExtensionFromPredicates(const PredicateLibrary &P) {
142
2.91k
    if (P.hasCnMips())
143
4
      ISAExtension = Mips::AFL_EXT_OCTEON;
144
2.90k
    else
145
2.90k
      ISAExtension = Mips::AFL_EXT_NONE;
146
2.91k
  }
MipsAsmParser.cpp:void llvm::MipsABIFlagsSection::setISAExtensionFromPredicates<(anonymous namespace)::MipsAsmParser>((anonymous namespace)::MipsAsmParser const&)
Line
Count
Source
141
3.64k
  void setISAExtensionFromPredicates(const PredicateLibrary &P) {
142
3.64k
    if (P.hasCnMips())
143
10
      ISAExtension = Mips::AFL_EXT_OCTEON;
144
3.63k
    else
145
3.63k
      ISAExtension = Mips::AFL_EXT_NONE;
146
3.64k
  }
147
148
  template <class PredicateLibrary>
149
6.55k
  void setASESetFromPredicates(const PredicateLibrary &P) {
150
6.55k
    ASESet = 0;
151
6.55k
    if (P.hasDSP())
152
296
      ASESet |= Mips::AFL_ASE_DSP;
153
6.55k
    if (P.hasDSPR2())
154
154
      ASESet |= Mips::AFL_ASE_DSPR2;
155
6.55k
    if (P.hasMSA())
156
253
      ASESet |= Mips::AFL_ASE_MSA;
157
6.55k
    if (P.inMicroMipsMode())
158
3.31k
      ASESet |= Mips::AFL_ASE_MICROMIPS;
159
6.55k
    if (P.inMips16Mode())
160
216
      ASESet |= Mips::AFL_ASE_MIPS16;
161
6.55k
    if (P.hasMT())
162
10
      ASESet |= Mips::AFL_ASE_MT;
163
6.55k
    if (P.hasCRC())
164
16
      ASESet |= Mips::AFL_ASE_CRC;
165
6.55k
    if (P.hasVirt())
166
34
      ASESet |= Mips::AFL_ASE_VIRT;
167
6.55k
    if (P.hasGINV())
168
20
      ASESet |= Mips::AFL_ASE_GINV;
169
6.55k
  }
void llvm::MipsABIFlagsSection::setASESetFromPredicates<llvm::MipsSubtarget>(llvm::MipsSubtarget const&)
Line
Count
Source
149
2.91k
  void setASESetFromPredicates(const PredicateLibrary &P) {
150
2.91k
    ASESet = 0;
151
2.91k
    if (P.hasDSP())
152
27
      ASESet |= Mips::AFL_ASE_DSP;
153
2.91k
    if (P.hasDSPR2())
154
6
      ASESet |= Mips::AFL_ASE_DSPR2;
155
2.91k
    if (P.hasMSA())
156
190
      ASESet |= Mips::AFL_ASE_MSA;
157
2.91k
    if (P.inMicroMipsMode())
158
1.08k
      ASESet |= Mips::AFL_ASE_MICROMIPS;
159
2.91k
    if (P.inMips16Mode())
160
174
      ASESet |= Mips::AFL_ASE_MIPS16;
161
2.91k
    if (P.hasMT())
162
0
      ASESet |= Mips::AFL_ASE_MT;
163
2.91k
    if (P.hasCRC())
164
4
      ASESet |= Mips::AFL_ASE_CRC;
165
2.91k
    if (P.hasVirt())
166
4
      ASESet |= Mips::AFL_ASE_VIRT;
167
2.91k
    if (P.hasGINV())
168
4
      ASESet |= Mips::AFL_ASE_GINV;
169
2.91k
  }
MipsAsmParser.cpp:void llvm::MipsABIFlagsSection::setASESetFromPredicates<(anonymous namespace)::MipsAsmParser>((anonymous namespace)::MipsAsmParser const&)
Line
Count
Source
149
3.64k
  void setASESetFromPredicates(const PredicateLibrary &P) {
150
3.64k
    ASESet = 0;
151
3.64k
    if (P.hasDSP())
152
269
      ASESet |= Mips::AFL_ASE_DSP;
153
3.64k
    if (P.hasDSPR2())
154
148
      ASESet |= Mips::AFL_ASE_DSPR2;
155
3.64k
    if (P.hasMSA())
156
63
      ASESet |= Mips::AFL_ASE_MSA;
157
3.64k
    if (P.inMicroMipsMode())
158
2.22k
      ASESet |= Mips::AFL_ASE_MICROMIPS;
159
3.64k
    if (P.inMips16Mode())
160
42
      ASESet |= Mips::AFL_ASE_MIPS16;
161
3.64k
    if (P.hasMT())
162
10
      ASESet |= Mips::AFL_ASE_MT;
163
3.64k
    if (P.hasCRC())
164
12
      ASESet |= Mips::AFL_ASE_CRC;
165
3.64k
    if (P.hasVirt())
166
30
      ASESet |= Mips::AFL_ASE_VIRT;
167
3.64k
    if (P.hasGINV())
168
16
      ASESet |= Mips::AFL_ASE_GINV;
169
3.64k
  }
170
171
  template <class PredicateLibrary>
172
6.55k
  void setFpAbiFromPredicates(const PredicateLibrary &P) {
173
6.55k
    Is32BitABI = P.isABI_O32();
174
6.55k
175
6.55k
    FpABI = FpABIKind::ANY;
176
6.55k
    if (P.useSoftFloat())
177
124
      FpABI = FpABIKind::SOFT;
178
6.43k
    else if (P.isABI_N32() || 
P.isABI_N64()6.22k
)
179
1.17k
      FpABI = FpABIKind::S64;
180
5.25k
    else if (P.isABI_O32()) {
181
5.25k
      if (P.isABI_FPXX())
182
32
        FpABI = FpABIKind::XX;
183
5.22k
      else if (P.isFP64bit())
184
1.67k
        FpABI = FpABIKind::S64;
185
3.54k
      else
186
3.54k
        FpABI = FpABIKind::S32;
187
5.25k
    }
188
6.55k
  }
void llvm::MipsABIFlagsSection::setFpAbiFromPredicates<llvm::MipsSubtarget>(llvm::MipsSubtarget const&)
Line
Count
Source
172
2.91k
  void setFpAbiFromPredicates(const PredicateLibrary &P) {
173
2.91k
    Is32BitABI = P.isABI_O32();
174
2.91k
175
2.91k
    FpABI = FpABIKind::ANY;
176
2.91k
    if (P.useSoftFloat())
177
75
      FpABI = FpABIKind::SOFT;
178
2.83k
    else if (P.isABI_N32() || 
P.isABI_N64()2.75k
)
179
646
      FpABI = FpABIKind::S64;
180
2.18k
    else if (P.isABI_O32()) {
181
2.18k
      if (P.isABI_FPXX())
182
12
        FpABI = FpABIKind::XX;
183
2.17k
      else if (P.isFP64bit())
184
760
        FpABI = FpABIKind::S64;
185
1.41k
      else
186
1.41k
        FpABI = FpABIKind::S32;
187
2.18k
    }
188
2.91k
  }
MipsAsmParser.cpp:void llvm::MipsABIFlagsSection::setFpAbiFromPredicates<(anonymous namespace)::MipsAsmParser>((anonymous namespace)::MipsAsmParser const&)
Line
Count
Source
172
3.64k
  void setFpAbiFromPredicates(const PredicateLibrary &P) {
173
3.64k
    Is32BitABI = P.isABI_O32();
174
3.64k
175
3.64k
    FpABI = FpABIKind::ANY;
176
3.64k
    if (P.useSoftFloat())
177
49
      FpABI = FpABIKind::SOFT;
178
3.59k
    else if (P.isABI_N32() || 
P.isABI_N64()3.47k
)
179
528
      FpABI = FpABIKind::S64;
180
3.06k
    else if (P.isABI_O32()) {
181
3.06k
      if (P.isABI_FPXX())
182
20
        FpABI = FpABIKind::XX;
183
3.04k
      else if (P.isFP64bit())
184
916
        FpABI = FpABIKind::S64;
185
2.13k
      else
186
2.13k
        FpABI = FpABIKind::S32;
187
3.06k
    }
188
3.64k
  }
189
190
  template <class PredicateLibrary>
191
6.55k
  void setAllFromPredicates(const PredicateLibrary &P) {
192
6.55k
    setISALevelAndRevisionFromPredicates(P);
193
6.55k
    setGPRSizeFromPredicates(P);
194
6.55k
    setCPR1SizeFromPredicates(P);
195
6.55k
    setISAExtensionFromPredicates(P);
196
6.55k
    setASESetFromPredicates(P);
197
6.55k
    setFpAbiFromPredicates(P);
198
6.55k
    OddSPReg = P.useOddSPReg();
199
6.55k
  }
void llvm::MipsABIFlagsSection::setAllFromPredicates<llvm::MipsSubtarget>(llvm::MipsSubtarget const&)
Line
Count
Source
191
2.91k
  void setAllFromPredicates(const PredicateLibrary &P) {
192
2.91k
    setISALevelAndRevisionFromPredicates(P);
193
2.91k
    setGPRSizeFromPredicates(P);
194
2.91k
    setCPR1SizeFromPredicates(P);
195
2.91k
    setISAExtensionFromPredicates(P);
196
2.91k
    setASESetFromPredicates(P);
197
2.91k
    setFpAbiFromPredicates(P);
198
2.91k
    OddSPReg = P.useOddSPReg();
199
2.91k
  }
MipsAsmParser.cpp:void llvm::MipsABIFlagsSection::setAllFromPredicates<(anonymous namespace)::MipsAsmParser>((anonymous namespace)::MipsAsmParser const&)
Line
Count
Source
191
3.64k
  void setAllFromPredicates(const PredicateLibrary &P) {
192
3.64k
    setISALevelAndRevisionFromPredicates(P);
193
3.64k
    setGPRSizeFromPredicates(P);
194
3.64k
    setCPR1SizeFromPredicates(P);
195
3.64k
    setISAExtensionFromPredicates(P);
196
3.64k
    setASESetFromPredicates(P);
197
3.64k
    setFpAbiFromPredicates(P);
198
3.64k
    OddSPReg = P.useOddSPReg();
199
3.64k
  }
200
};
201
202
MCStreamer &operator<<(MCStreamer &OS, MipsABIFlagsSection &ABIFlagsSection);
203
204
} // end namespace llvm
205
206
#endif // LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSABIFLAGSSECTION_H