Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/CodeGen/ValueTypes.cpp
Line
Count
Source (jump to first uncovered line)
1
//===----------- ValueTypes.cpp - Implementation of EVT methods -----------===//
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
#include "llvm/CodeGen/ValueTypes.h"
10
#include "llvm/ADT/StringExtras.h"
11
#include "llvm/IR/DerivedTypes.h"
12
#include "llvm/IR/Type.h"
13
#include "llvm/Support/ErrorHandling.h"
14
using namespace llvm;
15
16
0
EVT EVT::changeExtendedTypeToInteger() const {
17
0
  LLVMContext &Context = LLVMTy->getContext();
18
0
  return getIntegerVT(Context, getSizeInBits());
19
0
}
20
21
203
EVT EVT::changeExtendedVectorElementTypeToInteger() const {
22
203
  LLVMContext &Context = LLVMTy->getContext();
23
203
  EVT IntTy = getIntegerVT(Context, getScalarSizeInBits());
24
203
  return getVectorVT(Context, IntTy, getVectorNumElements());
25
203
}
26
27
714k
EVT EVT::getExtendedIntegerVT(LLVMContext &Context, unsigned BitWidth) {
28
714k
  EVT VT;
29
714k
  VT.LLVMTy = IntegerType::get(Context, BitWidth);
30
714k
  assert(VT.isExtended() && "Type is not extended!");
31
714k
  return VT;
32
714k
}
33
34
EVT EVT::getExtendedVectorVT(LLVMContext &Context, EVT VT,
35
245k
                             unsigned NumElements) {
36
245k
  EVT ResultVT;
37
245k
  ResultVT.LLVMTy = VectorType::get(VT.getTypeForEVT(Context), NumElements);
38
245k
  assert(ResultVT.isExtended() && "Type is not extended!");
39
245k
  return ResultVT;
40
245k
}
41
42
19.3k
bool EVT::isExtendedFloatingPoint() const {
43
19.3k
  assert(isExtended() && "Type is not extended!");
44
19.3k
  return LLVMTy->isFPOrFPVectorTy();
45
19.3k
}
46
47
91.1k
bool EVT::isExtendedInteger() const {
48
91.1k
  assert(isExtended() && "Type is not extended!");
49
91.1k
  return LLVMTy->isIntOrIntVectorTy();
50
91.1k
}
51
52
5.54k
bool EVT::isExtendedScalarInteger() const {
53
5.54k
  assert(isExtended() && "Type is not extended!");
54
5.54k
  return LLVMTy->isIntegerTy();
55
5.54k
}
56
57
1.24M
bool EVT::isExtendedVector() const {
58
1.24M
  assert(isExtended() && "Type is not extended!");
59
1.24M
  return LLVMTy->isVectorTy();
60
1.24M
}
61
62
0
bool EVT::isExtended16BitVector() const {
63
0
  return isExtendedVector() && getExtendedSizeInBits() == 16;
64
0
}
65
66
0
bool EVT::isExtended32BitVector() const {
67
0
  return isExtendedVector() && getExtendedSizeInBits() == 32;
68
0
}
69
70
0
bool EVT::isExtended64BitVector() const {
71
0
  return isExtendedVector() && getExtendedSizeInBits() == 64;
72
0
}
73
74
568
bool EVT::isExtended128BitVector() const {
75
568
  return isExtendedVector() && 
getExtendedSizeInBits() == 128252
;
76
568
}
77
78
3.34k
bool EVT::isExtended256BitVector() const {
79
3.34k
  return isExtendedVector() && 
getExtendedSizeInBits() == 2561.09k
;
80
3.34k
}
81
82
538
bool EVT::isExtended512BitVector() const {
83
538
  return isExtendedVector() && 
getExtendedSizeInBits() == 512158
;
84
538
}
85
86
0
bool EVT::isExtended1024BitVector() const {
87
0
  return isExtendedVector() && getExtendedSizeInBits() == 1024;
88
0
}
89
90
0
bool EVT::isExtended2048BitVector() const {
91
0
  return isExtendedVector() && getExtendedSizeInBits() == 2048;
92
0
}
93
94
386k
EVT EVT::getExtendedVectorElementType() const {
95
386k
  assert(isExtended() && "Type is not extended!");
96
386k
  return EVT::getEVT(cast<VectorType>(LLVMTy)->getElementType());
97
386k
}
98
99
628k
unsigned EVT::getExtendedVectorNumElements() const {
100
628k
  assert(isExtended() && "Type is not extended!");
101
628k
  return cast<VectorType>(LLVMTy)->getNumElements();
102
628k
}
103
104
2.48M
unsigned EVT::getExtendedSizeInBits() const {
105
2.48M
  assert(isExtended() && "Type is not extended!");
106
2.48M
  if (IntegerType *ITy = dyn_cast<IntegerType>(LLVMTy))
107
2.31M
    return ITy->getBitWidth();
108
169k
  if (VectorType *VTy = dyn_cast<VectorType>(LLVMTy))
109
169k
    return VTy->getBitWidth();
110
0
  llvm_unreachable("Unrecognized extended type!");
111
0
}
112
113
/// getEVTString - This function returns value type as a string, e.g. "i32".
114
73
std::string EVT::getEVTString() const {
115
73
  switch (V.SimpleTy) {
116
73
  default:
117
0
    if (isVector())
118
0
      return "v" + utostr(getVectorNumElements()) +
119
0
             getVectorElementType().getEVTString();
120
0
    if (isInteger())
121
0
      return "i" + utostr(getSizeInBits());
122
0
    llvm_unreachable("Invalid EVT!");
123
0
  case MVT::i1:      return "i1";
124
0
  case MVT::i8:      return "i8";
125
0
  case MVT::i16:     return "i16";
126
23
  case MVT::i32:     return "i32";
127
43
  case MVT::i64:     return "i64";
128
0
  case MVT::i128:    return "i128";
129
0
  case MVT::f16:     return "f16";
130
4
  case MVT::f32:     return "f32";
131
0
  case MVT::f64:     return "f64";
132
0
  case MVT::f80:     return "f80";
133
0
  case MVT::f128:    return "f128";
134
0
  case MVT::ppcf128: return "ppcf128";
135
0
  case MVT::isVoid:  return "isVoid";
136
0
  case MVT::Other:   return "ch";
137
0
  case MVT::Glue:    return "glue";
138
0
  case MVT::x86mmx:  return "x86mmx";
139
0
  case MVT::v1i1:    return "v1i1";
140
0
  case MVT::v2i1:    return "v2i1";
141
0
  case MVT::v4i1:    return "v4i1";
142
0
  case MVT::v8i1:    return "v8i1";
143
0
  case MVT::v16i1:   return "v16i1";
144
0
  case MVT::v32i1:   return "v32i1";
145
0
  case MVT::v64i1:   return "v64i1";
146
0
  case MVT::v128i1:  return "v128i1";
147
0
  case MVT::v512i1:  return "v512i1";
148
0
  case MVT::v1024i1: return "v1024i1";
149
0
  case MVT::v1i8:    return "v1i8";
150
0
  case MVT::v2i8:    return "v2i8";
151
0
  case MVT::v4i8:    return "v4i8";
152
0
  case MVT::v8i8:    return "v8i8";
153
0
  case MVT::v16i8:   return "v16i8";
154
0
  case MVT::v32i8:   return "v32i8";
155
0
  case MVT::v64i8:   return "v64i8";
156
0
  case MVT::v128i8:  return "v128i8";
157
0
  case MVT::v256i8:  return "v256i8";
158
0
  case MVT::v1i16:   return "v1i16";
159
0
  case MVT::v2i16:   return "v2i16";
160
0
  case MVT::v4i16:   return "v4i16";
161
0
  case MVT::v8i16:   return "v8i16";
162
0
  case MVT::v16i16:  return "v16i16";
163
0
  case MVT::v32i16:  return "v32i16";
164
0
  case MVT::v64i16:  return "v64i16";
165
0
  case MVT::v128i16: return "v128i16";
166
0
  case MVT::v1i32:   return "v1i32";
167
3
  case MVT::v2i32:   return "v2i32";
168
0
  case MVT::v3i32:   return "v3i32";
169
0
  case MVT::v4i32:   return "v4i32";
170
0
  case MVT::v5i32:   return "v5i32";
171
0
  case MVT::v8i32:   return "v8i32";
172
0
  case MVT::v16i32:  return "v16i32";
173
0
  case MVT::v32i32:  return "v32i32";
174
0
  case MVT::v64i32:  return "v64i32";
175
0
  case MVT::v128i32: return "v128i32";
176
0
  case MVT::v256i32: return "v256i32";
177
0
  case MVT::v512i32: return "v512i32";
178
0
  case MVT::v1024i32:return "v1024i32";
179
0
  case MVT::v2048i32:return "v2048i32";
180
0
  case MVT::v1i64:   return "v1i64";
181
0
  case MVT::v2i64:   return "v2i64";
182
0
  case MVT::v4i64:   return "v4i64";
183
0
  case MVT::v8i64:   return "v8i64";
184
0
  case MVT::v16i64:  return "v16i64";
185
0
  case MVT::v32i64:  return "v32i64";
186
0
  case MVT::v1i128:  return "v1i128";
187
0
  case MVT::v1f32:   return "v1f32";
188
0
  case MVT::v2f32:   return "v2f32";
189
0
  case MVT::v2f16:   return "v2f16";
190
0
  case MVT::v4f16:   return "v4f16";
191
0
  case MVT::v8f16:   return "v8f16";
192
0
  case MVT::v3f32:   return "v3f32";
193
0
  case MVT::v4f32:   return "v4f32";
194
0
  case MVT::v5f32:   return "v5f32";
195
0
  case MVT::v8f32:   return "v8f32";
196
0
  case MVT::v16f32:  return "v16f32";
197
0
  case MVT::v32f32:  return "v32f32";
198
0
  case MVT::v64f32:  return "v64f32";
199
0
  case MVT::v128f32: return "v128f32";
200
0
  case MVT::v256f32: return "v256f32";
201
0
  case MVT::v512f32: return "v512f32";
202
0
  case MVT::v1024f32:return "v1024f32";
203
0
  case MVT::v2048f32:return "v2048f32";
204
0
  case MVT::v1f64:   return "v1f64";
205
0
  case MVT::v2f64:   return "v2f64";
206
0
  case MVT::v4f64:   return "v4f64";
207
0
  case MVT::v8f64:   return "v8f64";
208
0
  case MVT::Metadata:return "Metadata";
209
0
  case MVT::Untyped: return "Untyped";
210
0
  case MVT::exnref : return "exnref";
211
73
  }
212
73
}
213
214
/// getTypeForEVT - This method returns an LLVM type corresponding to the
215
/// specified EVT.  For integer types, this returns an unsigned type.  Note
216
/// that this will abort for types that cannot be represented.
217
12.0M
Type *EVT::getTypeForEVT(LLVMContext &Context) const {
218
12.0M
  switch (V.SimpleTy) {
219
12.0M
  default:
220
27.5k
    assert(isExtended() && "Type is not extended!");
221
27.5k
    return LLVMTy;
222
12.0M
  
case MVT::isVoid: return Type::getVoidTy(Context)392
;
223
12.0M
  
case MVT::i1: return Type::getInt1Ty(Context)67.8k
;
224
12.0M
  
case MVT::i8: return Type::getInt8Ty(Context)777k
;
225
12.0M
  
case MVT::i16: return Type::getInt16Ty(Context)190k
;
226
12.0M
  
case MVT::i32: return Type::getInt32Ty(Context)3.16M
;
227
12.0M
  
case MVT::i64: return Type::getInt64Ty(Context)5.83M
;
228
12.0M
  
case MVT::i128: return IntegerType::get(Context, 128)20.9k
;
229
12.0M
  
case MVT::f16: return Type::getHalfTy(Context)28.1k
;
230
12.0M
  
case MVT::f32: return Type::getFloatTy(Context)111k
;
231
12.0M
  
case MVT::f64: return Type::getDoubleTy(Context)227k
;
232
12.0M
  
case MVT::f80: return Type::getX86_FP80Ty(Context)9.92k
;
233
12.0M
  
case MVT::f128: return Type::getFP128Ty(Context)280k
;
234
12.0M
  
case MVT::ppcf128: return Type::getPPC_FP128Ty(Context)549
;
235
12.0M
  
case MVT::x86mmx: return Type::getX86_MMXTy(Context)3.86k
;
236
12.0M
  
case MVT::v1i1: return VectorType::get(Type::getInt1Ty(Context), 1)180
;
237
12.0M
  
case MVT::v2i1: return VectorType::get(Type::getInt1Ty(Context), 2)483
;
238
12.0M
  
case MVT::v4i1: return VectorType::get(Type::getInt1Ty(Context), 4)1.55k
;
239
12.0M
  
case MVT::v8i1: return VectorType::get(Type::getInt1Ty(Context), 8)907
;
240
12.0M
  
case MVT::v16i1: return VectorType::get(Type::getInt1Ty(Context), 16)2.69k
;
241
12.0M
  
case MVT::v32i1: return VectorType::get(Type::getInt1Ty(Context), 32)1.01k
;
242
12.0M
  
case MVT::v64i1: return VectorType::get(Type::getInt1Ty(Context), 64)642
;
243
12.0M
  
case MVT::v128i1: return VectorType::get(Type::getInt1Ty(Context), 128)8
;
244
12.0M
  
case MVT::v512i1: return VectorType::get(Type::getInt1Ty(Context), 512)568
;
245
12.0M
  
case MVT::v1024i1: return VectorType::get(Type::getInt1Ty(Context), 1024)8
;
246
12.0M
  
case MVT::v1i8: return VectorType::get(Type::getInt8Ty(Context), 1)358
;
247
12.0M
  
case MVT::v2i8: return VectorType::get(Type::getInt8Ty(Context), 2)2.12k
;
248
12.0M
  
case MVT::v4i8: return VectorType::get(Type::getInt8Ty(Context), 4)4.85k
;
249
12.0M
  
case MVT::v8i8: return VectorType::get(Type::getInt8Ty(Context), 8)7.46k
;
250
12.0M
  
case MVT::v16i8: return VectorType::get(Type::getInt8Ty(Context), 16)70.3k
;
251
12.0M
  
case MVT::v32i8: return VectorType::get(Type::getInt8Ty(Context), 32)29.6k
;
252
12.0M
  
case MVT::v64i8: return VectorType::get(Type::getInt8Ty(Context), 64)3.91k
;
253
12.0M
  
case MVT::v128i8: return VectorType::get(Type::getInt8Ty(Context), 128)1.04k
;
254
12.0M
  
case MVT::v256i8: return VectorType::get(Type::getInt8Ty(Context), 256)672
;
255
12.0M
  
case MVT::v1i16: return VectorType::get(Type::getInt16Ty(Context), 1)426
;
256
12.0M
  
case MVT::v2i16: return VectorType::get(Type::getInt16Ty(Context), 2)4.52k
;
257
12.0M
  
case MVT::v4i16: return VectorType::get(Type::getInt16Ty(Context), 4)10.7k
;
258
12.0M
  
case MVT::v8i16: return VectorType::get(Type::getInt16Ty(Context), 8)40.5k
;
259
12.0M
  
case MVT::v16i16: return VectorType::get(Type::getInt16Ty(Context), 16)14.6k
;
260
12.0M
  
case MVT::v32i16: return VectorType::get(Type::getInt16Ty(Context), 32)4.52k
;
261
12.0M
  
case MVT::v64i16: return VectorType::get(Type::getInt16Ty(Context), 64)344
;
262
12.0M
  
case MVT::v128i16: return VectorType::get(Type::getInt16Ty(Context), 128)1
;
263
12.0M
  
case MVT::v1i32: return VectorType::get(Type::getInt32Ty(Context), 1)1.38k
;
264
12.0M
  
case MVT::v2i32: return VectorType::get(Type::getInt32Ty(Context), 2)120k
;
265
12.0M
  
case MVT::v3i32: return VectorType::get(Type::getInt32Ty(Context), 3)1.83k
;
266
12.0M
  
case MVT::v4i32: return VectorType::get(Type::getInt32Ty(Context), 4)292k
;
267
12.0M
  
case MVT::v5i32: return VectorType::get(Type::getInt32Ty(Context), 5)139
;
268
12.0M
  
case MVT::v8i32: return VectorType::get(Type::getInt32Ty(Context), 8)30.7k
;
269
12.0M
  
case MVT::v16i32: return VectorType::get(Type::getInt32Ty(Context), 16)26.1k
;
270
12.0M
  
case MVT::v32i32: return VectorType::get(Type::getInt32Ty(Context), 32)1.97k
;
271
12.0M
  
case MVT::v64i32: return VectorType::get(Type::getInt32Ty(Context), 64)103
;
272
12.0M
  
case MVT::v128i32: return VectorType::get(Type::getInt32Ty(Context), 128)0
;
273
12.0M
  
case MVT::v256i32: return VectorType::get(Type::getInt32Ty(Context), 256)2
;
274
12.0M
  
case MVT::v512i32: return VectorType::get(Type::getInt32Ty(Context), 512)0
;
275
12.0M
  
case MVT::v1024i32:return VectorType::get(Type::getInt32Ty(Context), 1024)0
;
276
12.0M
  
case MVT::v2048i32:return VectorType::get(Type::getInt32Ty(Context), 2048)0
;
277
12.0M
  
case MVT::v1i64: return VectorType::get(Type::getInt64Ty(Context), 1)4.66k
;
278
12.0M
  
case MVT::v2i64: return VectorType::get(Type::getInt64Ty(Context), 2)454k
;
279
12.0M
  
case MVT::v4i64: return VectorType::get(Type::getInt64Ty(Context), 4)35.3k
;
280
12.0M
  
case MVT::v8i64: return VectorType::get(Type::getInt64Ty(Context), 8)11.6k
;
281
12.0M
  
case MVT::v16i64: return VectorType::get(Type::getInt64Ty(Context), 16)846
;
282
12.0M
  
case MVT::v32i64: return VectorType::get(Type::getInt64Ty(Context), 32)196
;
283
12.0M
  
case MVT::v1i128: return VectorType::get(Type::getInt128Ty(Context), 1)175
;
284
12.0M
  
case MVT::v2f16: return VectorType::get(Type::getHalfTy(Context), 2)3.31k
;
285
12.0M
  
case MVT::v4f16: return VectorType::get(Type::getHalfTy(Context), 4)1.33k
;
286
12.0M
  
case MVT::v8f16: return VectorType::get(Type::getHalfTy(Context), 8)958
;
287
12.0M
  
case MVT::v1f32: return VectorType::get(Type::getFloatTy(Context), 1)334
;
288
12.0M
  
case MVT::v2f32: return VectorType::get(Type::getFloatTy(Context), 2)3.18k
;
289
12.0M
  
case MVT::v3f32: return VectorType::get(Type::getFloatTy(Context), 3)271
;
290
12.0M
  
case MVT::v4f32: return VectorType::get(Type::getFloatTy(Context), 4)29.2k
;
291
12.0M
  
case MVT::v5f32: return VectorType::get(Type::getFloatTy(Context), 5)68
;
292
12.0M
  
case MVT::v8f32: return VectorType::get(Type::getFloatTy(Context), 8)10.4k
;
293
12.0M
  
case MVT::v16f32: return VectorType::get(Type::getFloatTy(Context), 16)6.26k
;
294
12.0M
  
case MVT::v32f32: return VectorType::get(Type::getFloatTy(Context), 32)185
;
295
12.0M
  
case MVT::v64f32: return VectorType::get(Type::getFloatTy(Context), 64)8
;
296
12.0M
  
case MVT::v128f32: return VectorType::get(Type::getFloatTy(Context), 128)192
;
297
12.0M
  
case MVT::v256f32: return VectorType::get(Type::getFloatTy(Context), 256)0
;
298
12.0M
  
case MVT::v512f32: return VectorType::get(Type::getFloatTy(Context), 512)0
;
299
12.0M
  
case MVT::v1024f32:return VectorType::get(Type::getFloatTy(Context), 1024)0
;
300
12.0M
  
case MVT::v2048f32:return VectorType::get(Type::getFloatTy(Context), 2048)0
;
301
12.0M
  
case MVT::v1f64: return VectorType::get(Type::getDoubleTy(Context), 1)432
;
302
12.0M
  
case MVT::v2f64: return VectorType::get(Type::getDoubleTy(Context), 2)40.1k
;
303
12.0M
  
case MVT::v4f64: return VectorType::get(Type::getDoubleTy(Context), 4)10.1k
;
304
12.0M
  
case MVT::v8f64: return VectorType::get(Type::getDoubleTy(Context), 8)5.02k
;
305
12.0M
  
case MVT::Metadata: return Type::getMetadataTy(Context)0
;
306
12.0M
 }
307
12.0M
}
308
309
/// Return the value type corresponding to the specified type.  This returns all
310
/// pointers as MVT::iPTR.  If HandleUnknown is true, unknown types are returned
311
/// as Other, otherwise they are invalid.
312
12.6M
MVT MVT::getVT(Type *Ty, bool HandleUnknown){
313
12.6M
  switch (Ty->getTypeID()) {
314
12.6M
  default:
315
13.6k
    if (HandleUnknown) return MVT(MVT::Other);
316
0
    llvm_unreachable("Unknown type!");
317
11.1k
  case Type::VoidTyID:
318
11.1k
    return MVT::isVoid;
319
9.00M
  case Type::IntegerTyID:
320
9.00M
    return getIntegerVT(cast<IntegerType>(Ty)->getBitWidth());
321
65.5k
  case Type::HalfTyID:      return MVT(MVT::f16);
322
1.70M
  case Type::FloatTyID:     return MVT(MVT::f32);
323
1.83M
  case Type::DoubleTyID:    return MVT(MVT::f64);
324
14.3k
  case Type::X86_FP80TyID:  return MVT(MVT::f80);
325
5.81k
  case Type::X86_MMXTyID:   return MVT(MVT::x86mmx);
326
21.7k
  case Type::FP128TyID:     return MVT(MVT::f128);
327
968
  case Type::PPC_FP128TyID: return MVT(MVT::ppcf128);
328
0
  case Type::PointerTyID:   return MVT(MVT::iPTR);
329
6.60k
  case Type::VectorTyID: {
330
6.60k
    VectorType *VTy = cast<VectorType>(Ty);
331
6.60k
    return getVectorVT(
332
6.60k
      getVT(VTy->getElementType(), false), VTy->getNumElements());
333
0
  }
334
12.6M
  }
335
12.6M
}
336
337
/// getEVT - Return the value type corresponding to the specified type.  This
338
/// returns all pointers as MVT::iPTR.  If HandleUnknown is true, unknown types
339
/// are returned as Other, otherwise they are invalid.
340
49.1M
EVT EVT::getEVT(Type *Ty, bool HandleUnknown){
341
49.1M
  switch (Ty->getTypeID()) {
342
49.1M
  default:
343
3.56M
    return MVT::getVT(Ty, HandleUnknown);
344
49.1M
  case Type::IntegerTyID:
345
45.5M
    return getIntegerVT(Ty->getContext(), cast<IntegerType>(Ty)->getBitWidth());
346
49.1M
  case Type::VectorTyID: {
347
5.00k
    VectorType *VTy = cast<VectorType>(Ty);
348
5.00k
    return getVectorVT(Ty->getContext(), getEVT(VTy->getElementType(), false),
349
5.00k
                       VTy->getNumElements());
350
49.1M
  }
351
49.1M
  }
352
49.1M
}