Coverage Report

Created: 2019-02-21 13:17

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