Coverage Report

Created: 2018-09-19 08:35

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/CodeGen/ValueTypes.h
Line
Count
Source (jump to first uncovered line)
1
//===- CodeGen/ValueTypes.h - Low-Level Target independ. types --*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// This file defines the set of low-level target independent types which various
11
// values in the code generator are.  This allows the target specific behavior
12
// of instructions to be described to target independent passes.
13
//
14
//===----------------------------------------------------------------------===//
15
16
#ifndef LLVM_CODEGEN_VALUETYPES_H
17
#define LLVM_CODEGEN_VALUETYPES_H
18
19
#include "llvm/Support/Compiler.h"
20
#include "llvm/Support/MachineValueType.h"
21
#include "llvm/Support/MathExtras.h"
22
#include <cassert>
23
#include <cstdint>
24
#include <string>
25
26
namespace llvm {
27
28
  class LLVMContext;
29
  class Type;
30
31
  /// Extended Value Type. Capable of holding value types which are not native
32
  /// for any processor (such as the i12345 type), as well as the types an MVT
33
  /// can represent.
34
0
  struct EVT {
Unexecuted instantiation: llvm::EVT::operator=(llvm::EVT const&)
Unexecuted instantiation: llvm::EVT::operator=(llvm::EVT&&)
35
  private:
36
    MVT V = MVT::INVALID_SIMPLE_VALUE_TYPE;
37
    Type *LLVMTy = nullptr;
38
39
  public:
40
14.1M
    constexpr EVT() = default;
41
768M
    constexpr EVT(MVT::SimpleValueType SVT) : V(SVT) {}
42
1.22G
    constexpr EVT(MVT S) : V(S) {}
43
44
465M
    bool operator==(EVT VT) const {
45
465M
      return !(*this != VT);
46
465M
    }
47
672M
    bool operator!=(EVT VT) const {
48
672M
      if (V.SimpleTy != VT.V.SimpleTy)
49
471M
        return true;
50
200M
      if (V.SimpleTy == MVT::INVALID_SIMPLE_VALUE_TYPE)
51
38.1k
        return LLVMTy != VT.LLVMTy;
52
200M
      return false;
53
200M
    }
54
55
    /// Returns the EVT that represents a floating-point type with the given
56
    /// number of bits. There are two floating-point types with 128 bits - this
57
    /// returns f128 rather than ppcf128.
58
604
    static EVT getFloatingPointVT(unsigned BitWidth) {
59
604
      return MVT::getFloatingPointVT(BitWidth);
60
604
    }
61
62
    /// Returns the EVT that represents an integer with the given number of
63
    /// bits.
64
42.4M
    static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth) {
65
42.4M
      MVT M = MVT::getIntegerVT(BitWidth);
66
42.4M
      if (M.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE)
67
41.7M
        return M;
68
642k
      return getExtendedIntegerVT(Context, BitWidth);
69
642k
    }
70
71
    /// Returns the EVT that represents a vector NumElements in length, where
72
    /// each element is of type VT.
73
    static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements,
74
7.98M
                           bool IsScalable = false) {
75
7.98M
      MVT M = MVT::getVectorVT(VT.V, NumElements, IsScalable);
76
7.98M
      if (M.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE)
77
7.68M
        return M;
78
296k
79
296k
      assert(!IsScalable && "We don't support extended scalable types yet");
80
296k
      return getExtendedVectorVT(Context, VT, NumElements);
81
296k
    }
82
83
    /// Returns the EVT that represents a vector EC.Min elements in length,
84
    /// where each element is of type VT.
85
155k
    static EVT getVectorVT(LLVMContext &Context, EVT VT, MVT::ElementCount EC) {
86
155k
      MVT M = MVT::getVectorVT(VT.V, EC);
87
155k
      if (M.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE)
88
147k
        return M;
89
8.07k
      assert (!EC.Scalable && "We don't support extended scalable types yet");
90
8.07k
      return getExtendedVectorVT(Context, VT, EC.Min);
91
8.07k
    }
92
93
    /// Return a vector with the same number of elements as this vector, but
94
    /// with the element type converted to an integer type with the same
95
    /// bitwidth.
96
101k
    EVT changeVectorElementTypeToInteger() const {
97
101k
      if (!isSimple()) {
98
270
        assert (!isScalableVector() &&
99
270
                "We don't support extended scalable types yet");
100
270
        return changeExtendedVectorElementTypeToInteger();
101
270
      }
102
101k
      MVT EltTy = getSimpleVT().getVectorElementType();
103
101k
      unsigned BitWidth = EltTy.getSizeInBits();
104
101k
      MVT IntTy = MVT::getIntegerVT(BitWidth);
105
101k
      MVT VecTy = MVT::getVectorVT(IntTy, getVectorNumElements(),
106
101k
                                   isScalableVector());
107
101k
      assert(VecTy.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE &&
108
101k
             "Simple vector VT not representable by simple integer vector VT!");
109
101k
      return VecTy;
110
101k
    }
111
112
    /// Return the type converted to an equivalently sized integer or vector
113
    /// with integer element type. Similar to changeVectorElementTypeToInteger,
114
    /// but also handles scalars.
115
2.41k
    EVT changeTypeToInteger() {
116
2.41k
      if (isVector())
117
254
        return changeVectorElementTypeToInteger();
118
2.16k
119
2.16k
      if (isSimple())
120
2.16k
        return MVT::getIntegerVT(getSizeInBits());
121
0
122
0
      return changeExtendedTypeToInteger();
123
0
    }
124
125
    /// Test if the given EVT is simple (as opposed to being extended).
126
2.19G
    bool isSimple() const {
127
2.19G
      return V.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE;
128
2.19G
    }
129
130
    /// Test if the given EVT is extended (as opposed to being simple).
131
259M
    bool isExtended() const {
132
259M
      return !isSimple();
133
259M
    }
134
135
    /// Return true if this is a FP or a vector FP type.
136
3.96M
    bool isFloatingPoint() const {
137
3.96M
      return isSimple() ? 
V.isFloatingPoint()3.95M
:
isExtendedFloatingPoint()7.17k
;
138
3.96M
    }
139
140
    /// Return true if this is an integer or a vector integer type.
141
36.6M
    bool isInteger() const {
142
36.6M
      return isSimple() ? 
V.isInteger()36.5M
:
isExtendedInteger()74.9k
;
143
36.6M
    }
144
145
    /// Return true if this is an integer, but not a vector.
146
5.96M
    bool isScalarInteger() const {
147
5.96M
      return isSimple() ? 
V.isScalarInteger()5.95M
:
isExtendedScalarInteger()5.65k
;
148
5.96M
    }
149
150
    /// Return true if this is a vector value type.
151
370M
    bool isVector() const {
152
370M
      return isSimple() ? 
V.isVector()369M
:
isExtendedVector()1.02M
;
153
370M
    }
154
155
    /// Return true if this is a vector type where the runtime
156
    /// length is machine dependent
157
106k
    bool isScalableVector() const {
158
106k
      // FIXME: We don't support extended scalable types yet, because the
159
106k
      // matching IR type doesn't exist. Once it has been added, this can
160
106k
      // be changed to call isExtendedScalableVector.
161
106k
      if (!isSimple())
162
5.20k
        return false;
163
101k
      return V.isScalableVector();
164
101k
    }
165
166
    /// Return true if this is a 16-bit vector type.
167
    bool is16BitVector() const {
168
      return isSimple() ? V.is16BitVector() : isExtended16BitVector();
169
    }
170
171
    /// Return true if this is a 32-bit vector type.
172
    bool is32BitVector() const {
173
      return isSimple() ? V.is32BitVector() : isExtended32BitVector();
174
    }
175
176
    /// Return true if this is a 64-bit vector type.
177
14.6k
    bool is64BitVector() const {
178
14.6k
      return isSimple() ? V.is64BitVector() : 
isExtended64BitVector()0
;
179
14.6k
    }
180
181
    /// Return true if this is a 128-bit vector type.
182
1.21M
    bool is128BitVector() const {
183
1.21M
      return isSimple() ? 
V.is128BitVector()1.21M
:
isExtended128BitVector()548
;
184
1.21M
    }
185
186
    /// Return true if this is a 256-bit vector type.
187
2.84M
    bool is256BitVector() const {
188
2.84M
      return isSimple() ? 
V.is256BitVector()2.84M
:
isExtended256BitVector()2.97k
;
189
2.84M
    }
190
191
    /// Return true if this is a 512-bit vector type.
192
1.14M
    bool is512BitVector() const {
193
1.14M
      return isSimple() ? 
V.is512BitVector()1.14M
:
isExtended512BitVector()448
;
194
1.14M
    }
195
196
    /// Return true if this is a 1024-bit vector type.
197
    bool is1024BitVector() const {
198
      return isSimple() ? V.is1024BitVector() : isExtended1024BitVector();
199
    }
200
201
    /// Return true if this is a 2048-bit vector type.
202
    bool is2048BitVector() const {
203
      return isSimple() ? V.is2048BitVector() : isExtended2048BitVector();
204
    }
205
206
    /// Return true if this is an overloaded type for TableGen.
207
    bool isOverloaded() const {
208
      return (V==MVT::iAny || V==MVT::fAny || V==MVT::vAny || V==MVT::iPTRAny);
209
    }
210
211
    /// Return true if the bit size is a multiple of 8.
212
245k
    bool isByteSized() const {
213
245k
      return (getSizeInBits() & 7) == 0;
214
245k
    }
215
216
    /// Return true if the size is a power-of-two number of bytes.
217
162k
    bool isRound() const {
218
162k
      unsigned BitSize = getSizeInBits();
219
162k
      return BitSize >= 8 && 
!(BitSize & (BitSize - 1))138k
;
220
162k
    }
221
222
    /// Return true if this has the same number of bits as VT.
223
11.2M
    bool bitsEq(EVT VT) const {
224
11.2M
      if (EVT::operator==(VT)) 
return true5.77M
;
225
5.51M
      return getSizeInBits() == VT.getSizeInBits();
226
5.51M
    }
227
228
    /// Return true if this has more bits than VT.
229
1.38M
    bool bitsGT(EVT VT) const {
230
1.38M
      if (EVT::operator==(VT)) 
return false1.08M
;
231
297k
      return getSizeInBits() > VT.getSizeInBits();
232
297k
    }
233
234
    /// Return true if this has no less bits than VT.
235
89.2k
    bool bitsGE(EVT VT) const {
236
89.2k
      if (EVT::operator==(VT)) 
return true54.9k
;
237
34.2k
      return getSizeInBits() >= VT.getSizeInBits();
238
34.2k
    }
239
240
    /// Return true if this has less bits than VT.
241
9.64M
    bool bitsLT(EVT VT) const {
242
9.64M
      if (EVT::operator==(VT)) 
return false6.49M
;
243
3.15M
      return getSizeInBits() < VT.getSizeInBits();
244
3.15M
    }
245
246
    /// Return true if this has no more bits than VT.
247
562k
    bool bitsLE(EVT VT) const {
248
562k
      if (EVT::operator==(VT)) 
return true55.3k
;
249
506k
      return getSizeInBits() <= VT.getSizeInBits();
250
506k
    }
251
252
    /// Return the SimpleValueType held in the specified simple EVT.
253
1.06G
    MVT getSimpleVT() const {
254
1.06G
      assert(isSimple() && "Expected a SimpleValueType!");
255
1.06G
      return V;
256
1.06G
    }
257
258
    /// If this is a vector type, return the element type, otherwise return
259
    /// this.
260
152M
    EVT getScalarType() const {
261
152M
      return isVector() ? 
getVectorElementType()14.8M
:
*this137M
;
262
152M
    }
263
264
    /// Given a vector type, return the type of each element.
265
18.8M
    EVT getVectorElementType() const {
266
18.8M
      assert(isVector() && "Invalid vector type!");
267
18.8M
      if (isSimple())
268
18.5M
        return V.getVectorElementType();
269
307k
      return getExtendedVectorElementType();
270
307k
    }
271
272
    /// Given a vector type, return the number of elements it contains.
273
17.8M
    unsigned getVectorNumElements() const {
274
17.8M
      assert(isVector() && "Invalid vector type!");
275
17.8M
      if (isSimple())
276
17.3M
        return V.getVectorNumElements();
277
582k
      return getExtendedVectorNumElements();
278
582k
    }
279
280
    // Given a (possibly scalable) vector type, return the ElementCount
281
155k
    MVT::ElementCount getVectorElementCount() const {
282
155k
      assert((isVector()) && "Invalid vector type!");
283
155k
      if (isSimple())
284
148k
        return V.getVectorElementCount();
285
7.09k
286
7.09k
      assert(!isScalableVector() &&
287
7.09k
             "We don't support extended scalable types yet");
288
7.09k
      return {getExtendedVectorNumElements(), false};
289
7.09k
    }
290
291
    /// Return the size of the specified value type in bits.
292
228M
    unsigned getSizeInBits() const {
293
228M
      if (isSimple())
294
226M
        return V.getSizeInBits();
295
2.32M
      return getExtendedSizeInBits();
296
2.32M
    }
297
298
15.0M
    unsigned getScalarSizeInBits() const {
299
15.0M
      return getScalarType().getSizeInBits();
300
15.0M
    }
301
302
    /// Return the number of bytes overwritten by a store of the specified value
303
    /// type.
304
49.3M
    unsigned getStoreSize() const {
305
49.3M
      return (getSizeInBits() + 7) / 8;
306
49.3M
    }
307
308
    /// Return the number of bits overwritten by a store of the specified value
309
    /// type.
310
932k
    unsigned getStoreSizeInBits() const {
311
932k
      return getStoreSize() * 8;
312
932k
    }
313
314
    /// Rounds the bit-width of the given integer EVT up to the nearest power of
315
    /// two (and at least to eight), and returns the integer EVT with that
316
    /// number of bits.
317
324k
    EVT getRoundIntegerType(LLVMContext &Context) const {
318
324k
      assert(isInteger() && !isVector() && "Invalid integer type!");
319
324k
      unsigned BitWidth = getSizeInBits();
320
324k
      if (BitWidth <= 8)
321
35.2k
        return EVT(MVT::i8);
322
289k
      return getIntegerVT(Context, 1 << Log2_32_Ceil(BitWidth));
323
289k
    }
324
325
    /// Finds the smallest simple value type that is greater than or equal to
326
    /// half the width of this EVT. If no simple value type can be found, an
327
    /// extended integer value type of half the size (rounded up) is returned.
328
1.67k
    EVT getHalfSizedIntegerVT(LLVMContext &Context) const {
329
1.67k
      assert(isInteger() && !isVector() && "Invalid integer type!");
330
1.67k
      unsigned EVTSize = getSizeInBits();
331
1.67k
      for (unsigned IntVT = MVT::FIRST_INTEGER_VALUETYPE;
332
5.43k
          IntVT <= MVT::LAST_INTEGER_VALUETYPE; 
++IntVT3.76k
) {
333
5.43k
        EVT HalfVT = EVT((MVT::SimpleValueType)IntVT);
334
5.43k
        if (HalfVT.getSizeInBits() * 2 >= EVTSize)
335
1.67k
          return HalfVT;
336
5.43k
      }
337
1.67k
      
return getIntegerVT(Context, (EVTSize + 1) / 2)0
;
338
1.67k
    }
339
340
    /// Return a VT for an integer vector type with the size of the
341
    /// elements doubled. The typed returned may be an extended type.
342
5.70k
    EVT widenIntegerVectorElementType(LLVMContext &Context) const {
343
5.70k
      EVT EltVT = getVectorElementType();
344
5.70k
      EltVT = EVT::getIntegerVT(Context, 2 * EltVT.getSizeInBits());
345
5.70k
      return EVT::getVectorVT(Context, EltVT, getVectorElementCount());
346
5.70k
    }
347
348
    // Return a VT for a vector type with the same element type but
349
    // half the number of elements. The type returned may be an
350
    // extended type.
351
149k
    EVT getHalfNumVectorElementsVT(LLVMContext &Context) const {
352
149k
      EVT EltVT = getVectorElementType();
353
149k
      auto EltCnt = getVectorElementCount();
354
149k
      assert(!(EltCnt.Min & 1) && "Splitting vector, but not in half!");
355
149k
      return EVT::getVectorVT(Context, EltVT, EltCnt / 2);
356
149k
    }
357
358
    /// Returns true if the given vector is a power of 2.
359
112k
    bool isPow2VectorType() const {
360
112k
      unsigned NElts = getVectorNumElements();
361
112k
      return !(NElts & (NElts - 1));
362
112k
    }
363
364
    /// Widens the length of the given vector EVT up to the nearest power of 2
365
    /// and returns that type.
366
5.20k
    EVT getPow2VectorType(LLVMContext &Context) const {
367
5.20k
      if (!isPow2VectorType()) {
368
5.20k
        unsigned NElts = getVectorNumElements();
369
5.20k
        unsigned Pow2NElts = 1 <<  Log2_32_Ceil(NElts);
370
5.20k
        return EVT::getVectorVT(Context, getVectorElementType(), Pow2NElts,
371
5.20k
                                isScalableVector());
372
5.20k
      }
373
0
      else {
374
0
        return *this;
375
0
      }
376
5.20k
    }
377
378
    /// This function returns value type as a string, e.g. "i32".
379
    std::string getEVTString() const;
380
381
    /// This method returns an LLVM type corresponding to the specified EVT.
382
    /// For integer types, this returns an unsigned type. Note that this will
383
    /// abort for types that cannot be represented.
384
    Type *getTypeForEVT(LLVMContext &Context) const;
385
386
    /// Return the value type corresponding to the specified type.
387
    /// This returns all pointers as iPTR.  If HandleUnknown is true, unknown
388
    /// types are returned as Other, otherwise they are invalid.
389
    static EVT getEVT(Type *Ty, bool HandleUnknown = false);
390
391
50.9M
    intptr_t getRawBits() const {
392
50.9M
      if (isSimple())
393
50.8M
        return V.SimpleTy;
394
57.2k
      else
395
57.2k
        return (intptr_t)(LLVMTy);
396
50.9M
    }
397
398
    /// A meaningless but well-behaved order, useful for constructing
399
    /// containers.
400
    struct compareRawBits {
401
710k
      bool operator()(EVT L, EVT R) const {
402
710k
        if (L.V.SimpleTy == R.V.SimpleTy)
403
710k
          return L.LLVMTy < R.LLVMTy;
404
0
        else
405
0
          return L.V.SimpleTy < R.V.SimpleTy;
406
710k
      }
407
    };
408
409
  private:
410
    // Methods for handling the Extended-type case in functions above.
411
    // These are all out-of-line to prevent users of this header file
412
    // from having a dependency on Type.h.
413
    EVT changeExtendedTypeToInteger() const;
414
    EVT changeExtendedVectorElementTypeToInteger() const;
415
    static EVT getExtendedIntegerVT(LLVMContext &C, unsigned BitWidth);
416
    static EVT getExtendedVectorVT(LLVMContext &C, EVT VT,
417
                                   unsigned NumElements);
418
    bool isExtendedFloatingPoint() const LLVM_READONLY;
419
    bool isExtendedInteger() const LLVM_READONLY;
420
    bool isExtendedScalarInteger() const LLVM_READONLY;
421
    bool isExtendedVector() const LLVM_READONLY;
422
    bool isExtended16BitVector() const LLVM_READONLY;
423
    bool isExtended32BitVector() const LLVM_READONLY;
424
    bool isExtended64BitVector() const LLVM_READONLY;
425
    bool isExtended128BitVector() const LLVM_READONLY;
426
    bool isExtended256BitVector() const LLVM_READONLY;
427
    bool isExtended512BitVector() const LLVM_READONLY;
428
    bool isExtended1024BitVector() const LLVM_READONLY;
429
    bool isExtended2048BitVector() const LLVM_READONLY;
430
    EVT getExtendedVectorElementType() const;
431
    unsigned getExtendedVectorNumElements() const LLVM_READONLY;
432
    unsigned getExtendedSizeInBits() const LLVM_READONLY;
433
  };
434
435
} // end namespace llvm
436
437
#endif // LLVM_CODEGEN_VALUETYPES_H