IR: Split up Constant{Array,Vector}::get(), NFC
[oota-llvm.git] / include / llvm / IR / Constants.h
1 //===-- llvm/Constants.h - Constant class subclass definitions --*- 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 /// @file
11 /// This file contains the declarations for the subclasses of Constant,
12 /// which represent the different flavors of constant values that live in LLVM.
13 /// Note that Constants are immutable (once created they never change) and are
14 /// fully shared by structural equivalence.  This means that two structurally
15 /// equivalent constants will always have the same address.  Constant's are
16 /// created on demand as needed and never deleted: thus clients don't have to
17 /// worry about the lifetime of the objects.
18 //
19 //===----------------------------------------------------------------------===//
20
21 #ifndef LLVM_IR_CONSTANTS_H
22 #define LLVM_IR_CONSTANTS_H
23
24 #include "llvm/ADT/APFloat.h"
25 #include "llvm/ADT/APInt.h"
26 #include "llvm/ADT/ArrayRef.h"
27 #include "llvm/IR/Constant.h"
28 #include "llvm/IR/DerivedTypes.h"
29 #include "llvm/IR/OperandTraits.h"
30
31 namespace llvm {
32
33 class ArrayType;
34 class IntegerType;
35 class StructType;
36 class PointerType;
37 class VectorType;
38 class SequentialType;
39
40 struct ConstantExprKeyType;
41 template <class ConstantClass> struct ConstantAggrKeyType;
42
43 //===----------------------------------------------------------------------===//
44 /// This is the shared class of boolean and integer constants. This class
45 /// represents both boolean and integral constants.
46 /// @brief Class for constant integers.
47 class ConstantInt : public Constant {
48   void anchor() override;
49   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
50   ConstantInt(const ConstantInt &) LLVM_DELETED_FUNCTION;
51   ConstantInt(IntegerType *Ty, const APInt& V);
52   APInt Val;
53 protected:
54   // allocate space for exactly zero operands
55   void *operator new(size_t s) {
56     return User::operator new(s, 0);
57   }
58 public:
59   static ConstantInt *getTrue(LLVMContext &Context);
60   static ConstantInt *getFalse(LLVMContext &Context);
61   static Constant *getTrue(Type *Ty);
62   static Constant *getFalse(Type *Ty);
63
64   /// If Ty is a vector type, return a Constant with a splat of the given
65   /// value. Otherwise return a ConstantInt for the given value.
66   static Constant *get(Type *Ty, uint64_t V, bool isSigned = false);
67
68   /// Return a ConstantInt with the specified integer value for the specified
69   /// type. If the type is wider than 64 bits, the value will be zero-extended
70   /// to fit the type, unless isSigned is true, in which case the value will
71   /// be interpreted as a 64-bit signed integer and sign-extended to fit
72   /// the type.
73   /// @brief Get a ConstantInt for a specific value.
74   static ConstantInt *get(IntegerType *Ty, uint64_t V,
75                           bool isSigned = false);
76
77   /// Return a ConstantInt with the specified value for the specified type. The
78   /// value V will be canonicalized to a an unsigned APInt. Accessing it with
79   /// either getSExtValue() or getZExtValue() will yield a correctly sized and
80   /// signed value for the type Ty.
81   /// @brief Get a ConstantInt for a specific signed value.
82   static ConstantInt *getSigned(IntegerType *Ty, int64_t V);
83   static Constant *getSigned(Type *Ty, int64_t V);
84
85   /// Return a ConstantInt with the specified value and an implied Type. The
86   /// type is the integer type that corresponds to the bit width of the value.
87   static ConstantInt *get(LLVMContext &Context, const APInt &V);
88
89   /// Return a ConstantInt constructed from the string strStart with the given
90   /// radix.
91   static ConstantInt *get(IntegerType *Ty, StringRef Str,
92                           uint8_t radix);
93
94   /// If Ty is a vector type, return a Constant with a splat of the given
95   /// value. Otherwise return a ConstantInt for the given value.
96   static Constant *get(Type* Ty, const APInt& V);
97
98   /// Return the constant as an APInt value reference. This allows clients to
99   /// obtain a copy of the value, with all its precision in tact.
100   /// @brief Return the constant's value.
101   inline const APInt &getValue() const {
102     return Val;
103   }
104
105   /// getBitWidth - Return the bitwidth of this constant.
106   unsigned getBitWidth() const { return Val.getBitWidth(); }
107
108   /// Return the constant as a 64-bit unsigned integer value after it
109   /// has been zero extended as appropriate for the type of this constant. Note
110   /// that this method can assert if the value does not fit in 64 bits.
111   /// @brief Return the zero extended value.
112   inline uint64_t getZExtValue() const {
113     return Val.getZExtValue();
114   }
115
116   /// Return the constant as a 64-bit integer value after it has been sign
117   /// extended as appropriate for the type of this constant. Note that
118   /// this method can assert if the value does not fit in 64 bits.
119   /// @brief Return the sign extended value.
120   inline int64_t getSExtValue() const {
121     return Val.getSExtValue();
122   }
123
124   /// A helper method that can be used to determine if the constant contained
125   /// within is equal to a constant.  This only works for very small values,
126   /// because this is all that can be represented with all types.
127   /// @brief Determine if this constant's value is same as an unsigned char.
128   bool equalsInt(uint64_t V) const {
129     return Val == V;
130   }
131
132   /// getType - Specialize the getType() method to always return an IntegerType,
133   /// which reduces the amount of casting needed in parts of the compiler.
134   ///
135   inline IntegerType *getType() const {
136     return cast<IntegerType>(Value::getType());
137   }
138
139   /// This static method returns true if the type Ty is big enough to
140   /// represent the value V. This can be used to avoid having the get method
141   /// assert when V is larger than Ty can represent. Note that there are two
142   /// versions of this method, one for unsigned and one for signed integers.
143   /// Although ConstantInt canonicalizes everything to an unsigned integer,
144   /// the signed version avoids callers having to convert a signed quantity
145   /// to the appropriate unsigned type before calling the method.
146   /// @returns true if V is a valid value for type Ty
147   /// @brief Determine if the value is in range for the given type.
148   static bool isValueValidForType(Type *Ty, uint64_t V);
149   static bool isValueValidForType(Type *Ty, int64_t V);
150
151   bool isNegative() const { return Val.isNegative(); }
152
153   /// This is just a convenience method to make client code smaller for a
154   /// common code. It also correctly performs the comparison without the
155   /// potential for an assertion from getZExtValue().
156   bool isZero() const {
157     return Val == 0;
158   }
159
160   /// This is just a convenience method to make client code smaller for a
161   /// common case. It also correctly performs the comparison without the
162   /// potential for an assertion from getZExtValue().
163   /// @brief Determine if the value is one.
164   bool isOne() const {
165     return Val == 1;
166   }
167
168   /// This function will return true iff every bit in this constant is set
169   /// to true.
170   /// @returns true iff this constant's bits are all set to true.
171   /// @brief Determine if the value is all ones.
172   bool isMinusOne() const {
173     return Val.isAllOnesValue();
174   }
175
176   /// This function will return true iff this constant represents the largest
177   /// value that may be represented by the constant's type.
178   /// @returns true iff this is the largest value that may be represented
179   /// by this type.
180   /// @brief Determine if the value is maximal.
181   bool isMaxValue(bool isSigned) const {
182     if (isSigned)
183       return Val.isMaxSignedValue();
184     else
185       return Val.isMaxValue();
186   }
187
188   /// This function will return true iff this constant represents the smallest
189   /// value that may be represented by this constant's type.
190   /// @returns true if this is the smallest value that may be represented by
191   /// this type.
192   /// @brief Determine if the value is minimal.
193   bool isMinValue(bool isSigned) const {
194     if (isSigned)
195       return Val.isMinSignedValue();
196     else
197       return Val.isMinValue();
198   }
199
200   /// This function will return true iff this constant represents a value with
201   /// active bits bigger than 64 bits or a value greater than the given uint64_t
202   /// value.
203   /// @returns true iff this constant is greater or equal to the given number.
204   /// @brief Determine if the value is greater or equal to the given number.
205   bool uge(uint64_t Num) const {
206     return Val.getActiveBits() > 64 || Val.getZExtValue() >= Num;
207   }
208
209   /// getLimitedValue - If the value is smaller than the specified limit,
210   /// return it, otherwise return the limit value.  This causes the value
211   /// to saturate to the limit.
212   /// @returns the min of the value of the constant and the specified value
213   /// @brief Get the constant's value with a saturation limit
214   uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const {
215     return Val.getLimitedValue(Limit);
216   }
217
218   /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
219   static bool classof(const Value *V) {
220     return V->getValueID() == ConstantIntVal;
221   }
222 };
223
224
225 //===----------------------------------------------------------------------===//
226 /// ConstantFP - Floating Point Values [float, double]
227 ///
228 class ConstantFP : public Constant {
229   APFloat Val;
230   void anchor() override;
231   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
232   ConstantFP(const ConstantFP &) LLVM_DELETED_FUNCTION;
233   friend class LLVMContextImpl;
234 protected:
235   ConstantFP(Type *Ty, const APFloat& V);
236 protected:
237   // allocate space for exactly zero operands
238   void *operator new(size_t s) {
239     return User::operator new(s, 0);
240   }
241 public:
242   /// Floating point negation must be implemented with f(x) = -0.0 - x. This
243   /// method returns the negative zero constant for floating point or vector
244   /// floating point types; for all other types, it returns the null value.
245   static Constant *getZeroValueForNegation(Type *Ty);
246
247   /// get() - This returns a ConstantFP, or a vector containing a splat of a
248   /// ConstantFP, for the specified value in the specified type.  This should
249   /// only be used for simple constant values like 2.0/1.0 etc, that are
250   /// known-valid both as host double and as the target format.
251   static Constant *get(Type* Ty, double V);
252   static Constant *get(Type* Ty, StringRef Str);
253   static ConstantFP *get(LLVMContext &Context, const APFloat &V);
254   static Constant *getNegativeZero(Type *Ty);
255   static Constant *getInfinity(Type *Ty, bool Negative = false);
256
257   /// isValueValidForType - return true if Ty is big enough to represent V.
258   static bool isValueValidForType(Type *Ty, const APFloat &V);
259   inline const APFloat &getValueAPF() const { return Val; }
260
261   /// isZero - Return true if the value is positive or negative zero.
262   bool isZero() const { return Val.isZero(); }
263
264   /// isNegative - Return true if the sign bit is set.
265   bool isNegative() const { return Val.isNegative(); }
266
267   /// isNaN - Return true if the value is a NaN.
268   bool isNaN() const { return Val.isNaN(); }
269
270   /// isExactlyValue - We don't rely on operator== working on double values, as
271   /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
272   /// As such, this method can be used to do an exact bit-for-bit comparison of
273   /// two floating point values.  The version with a double operand is retained
274   /// because it's so convenient to write isExactlyValue(2.0), but please use
275   /// it only for simple constants.
276   bool isExactlyValue(const APFloat &V) const;
277
278   bool isExactlyValue(double V) const {
279     bool ignored;
280     APFloat FV(V);
281     FV.convert(Val.getSemantics(), APFloat::rmNearestTiesToEven, &ignored);
282     return isExactlyValue(FV);
283   }
284   /// Methods for support type inquiry through isa, cast, and dyn_cast:
285   static bool classof(const Value *V) {
286     return V->getValueID() == ConstantFPVal;
287   }
288 };
289
290 //===----------------------------------------------------------------------===//
291 /// ConstantAggregateZero - All zero aggregate value
292 ///
293 class ConstantAggregateZero : public Constant {
294   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
295   ConstantAggregateZero(const ConstantAggregateZero &) LLVM_DELETED_FUNCTION;
296 protected:
297   explicit ConstantAggregateZero(Type *ty)
298     : Constant(ty, ConstantAggregateZeroVal, nullptr, 0) {}
299 protected:
300   // allocate space for exactly zero operands
301   void *operator new(size_t s) {
302     return User::operator new(s, 0);
303   }
304 public:
305   static ConstantAggregateZero *get(Type *Ty);
306
307   void destroyConstant() override;
308
309   /// getSequentialElement - If this CAZ has array or vector type, return a zero
310   /// with the right element type.
311   Constant *getSequentialElement() const;
312
313   /// getStructElement - If this CAZ has struct type, return a zero with the
314   /// right element type for the specified element.
315   Constant *getStructElement(unsigned Elt) const;
316
317   /// getElementValue - Return a zero of the right value for the specified GEP
318   /// index.
319   Constant *getElementValue(Constant *C) const;
320
321   /// getElementValue - Return a zero of the right value for the specified GEP
322   /// index.
323   Constant *getElementValue(unsigned Idx) const;
324
325   /// Methods for support type inquiry through isa, cast, and dyn_cast:
326   ///
327   static bool classof(const Value *V) {
328     return V->getValueID() == ConstantAggregateZeroVal;
329   }
330 };
331
332
333 //===----------------------------------------------------------------------===//
334 /// ConstantArray - Constant Array Declarations
335 ///
336 class ConstantArray : public Constant {
337   friend struct ConstantAggrKeyType<ConstantArray>;
338   ConstantArray(const ConstantArray &) LLVM_DELETED_FUNCTION;
339 protected:
340   ConstantArray(ArrayType *T, ArrayRef<Constant *> Val);
341 public:
342   // ConstantArray accessors
343   static Constant *get(ArrayType *T, ArrayRef<Constant*> V);
344
345 private:
346   static Constant *getImpl(ArrayType *T, ArrayRef<Constant *> V);
347
348 public:
349   /// Transparently provide more efficient getOperand methods.
350   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
351
352   /// getType - Specialize the getType() method to always return an ArrayType,
353   /// which reduces the amount of casting needed in parts of the compiler.
354   ///
355   inline ArrayType *getType() const {
356     return cast<ArrayType>(Value::getType());
357   }
358
359   void destroyConstant() override;
360   void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) override;
361
362   /// Methods for support type inquiry through isa, cast, and dyn_cast:
363   static bool classof(const Value *V) {
364     return V->getValueID() == ConstantArrayVal;
365   }
366 };
367
368 template <>
369 struct OperandTraits<ConstantArray> :
370   public VariadicOperandTraits<ConstantArray> {
371 };
372
373 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantArray, Constant)
374
375 //===----------------------------------------------------------------------===//
376 // ConstantStruct - Constant Struct Declarations
377 //
378 class ConstantStruct : public Constant {
379   friend struct ConstantAggrKeyType<ConstantStruct>;
380   ConstantStruct(const ConstantStruct &) LLVM_DELETED_FUNCTION;
381 protected:
382   ConstantStruct(StructType *T, ArrayRef<Constant *> Val);
383 public:
384   // ConstantStruct accessors
385   static Constant *get(StructType *T, ArrayRef<Constant*> V);
386   static Constant *get(StructType *T, ...) END_WITH_NULL;
387
388   /// getAnon - Return an anonymous struct that has the specified
389   /// elements.  If the struct is possibly empty, then you must specify a
390   /// context.
391   static Constant *getAnon(ArrayRef<Constant*> V, bool Packed = false) {
392     return get(getTypeForElements(V, Packed), V);
393   }
394   static Constant *getAnon(LLVMContext &Ctx,
395                            ArrayRef<Constant*> V, bool Packed = false) {
396     return get(getTypeForElements(Ctx, V, Packed), V);
397   }
398
399   /// getTypeForElements - Return an anonymous struct type to use for a constant
400   /// with the specified set of elements.  The list must not be empty.
401   static StructType *getTypeForElements(ArrayRef<Constant*> V,
402                                         bool Packed = false);
403   /// getTypeForElements - This version of the method allows an empty list.
404   static StructType *getTypeForElements(LLVMContext &Ctx,
405                                         ArrayRef<Constant*> V,
406                                         bool Packed = false);
407
408   /// Transparently provide more efficient getOperand methods.
409   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
410
411   /// getType() specialization - Reduce amount of casting...
412   ///
413   inline StructType *getType() const {
414     return cast<StructType>(Value::getType());
415   }
416
417   void destroyConstant() override;
418   void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) override;
419
420   /// Methods for support type inquiry through isa, cast, and dyn_cast:
421   static bool classof(const Value *V) {
422     return V->getValueID() == ConstantStructVal;
423   }
424 };
425
426 template <>
427 struct OperandTraits<ConstantStruct> :
428   public VariadicOperandTraits<ConstantStruct> {
429 };
430
431 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantStruct, Constant)
432
433
434 //===----------------------------------------------------------------------===//
435 /// ConstantVector - Constant Vector Declarations
436 ///
437 class ConstantVector : public Constant {
438   friend struct ConstantAggrKeyType<ConstantVector>;
439   ConstantVector(const ConstantVector &) LLVM_DELETED_FUNCTION;
440 protected:
441   ConstantVector(VectorType *T, ArrayRef<Constant *> Val);
442 public:
443   // ConstantVector accessors
444   static Constant *get(ArrayRef<Constant*> V);
445
446 private:
447   static Constant *getImpl(ArrayRef<Constant *> V);
448
449 public:
450   /// getSplat - Return a ConstantVector with the specified constant in each
451   /// element.
452   static Constant *getSplat(unsigned NumElts, Constant *Elt);
453
454   /// Transparently provide more efficient getOperand methods.
455   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
456
457   /// getType - Specialize the getType() method to always return a VectorType,
458   /// which reduces the amount of casting needed in parts of the compiler.
459   ///
460   inline VectorType *getType() const {
461     return cast<VectorType>(Value::getType());
462   }
463
464   /// getSplatValue - If this is a splat constant, meaning that all of the
465   /// elements have the same value, return that value. Otherwise return NULL.
466   Constant *getSplatValue() const;
467
468   void destroyConstant() override;
469   void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) override;
470
471   /// Methods for support type inquiry through isa, cast, and dyn_cast:
472   static bool classof(const Value *V) {
473     return V->getValueID() == ConstantVectorVal;
474   }
475 };
476
477 template <>
478 struct OperandTraits<ConstantVector> :
479   public VariadicOperandTraits<ConstantVector> {
480 };
481
482 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantVector, Constant)
483
484 //===----------------------------------------------------------------------===//
485 /// ConstantPointerNull - a constant pointer value that points to null
486 ///
487 class ConstantPointerNull : public Constant {
488   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
489   ConstantPointerNull(const ConstantPointerNull &) LLVM_DELETED_FUNCTION;
490 protected:
491   explicit ConstantPointerNull(PointerType *T)
492     : Constant(T,
493                Value::ConstantPointerNullVal, nullptr, 0) {}
494
495 protected:
496   // allocate space for exactly zero operands
497   void *operator new(size_t s) {
498     return User::operator new(s, 0);
499   }
500 public:
501   /// get() - Static factory methods - Return objects of the specified value
502   static ConstantPointerNull *get(PointerType *T);
503
504   void destroyConstant() override;
505
506   /// getType - Specialize the getType() method to always return an PointerType,
507   /// which reduces the amount of casting needed in parts of the compiler.
508   ///
509   inline PointerType *getType() const {
510     return cast<PointerType>(Value::getType());
511   }
512
513   /// Methods for support type inquiry through isa, cast, and dyn_cast:
514   static bool classof(const Value *V) {
515     return V->getValueID() == ConstantPointerNullVal;
516   }
517 };
518
519 //===----------------------------------------------------------------------===//
520 /// ConstantDataSequential - A vector or array constant whose element type is a
521 /// simple 1/2/4/8-byte integer or float/double, and whose elements are just
522 /// simple data values (i.e. ConstantInt/ConstantFP).  This Constant node has no
523 /// operands because it stores all of the elements of the constant as densely
524 /// packed data, instead of as Value*'s.
525 ///
526 /// This is the common base class of ConstantDataArray and ConstantDataVector.
527 ///
528 class ConstantDataSequential : public Constant {
529   friend class LLVMContextImpl;
530   /// DataElements - A pointer to the bytes underlying this constant (which is
531   /// owned by the uniquing StringMap).
532   const char *DataElements;
533
534   /// Next - This forms a link list of ConstantDataSequential nodes that have
535   /// the same value but different type.  For example, 0,0,0,1 could be a 4
536   /// element array of i8, or a 1-element array of i32.  They'll both end up in
537   /// the same StringMap bucket, linked up.
538   ConstantDataSequential *Next;
539   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
540   ConstantDataSequential(const ConstantDataSequential &) LLVM_DELETED_FUNCTION;
541 protected:
542   explicit ConstantDataSequential(Type *ty, ValueTy VT, const char *Data)
543     : Constant(ty, VT, nullptr, 0), DataElements(Data), Next(nullptr) {}
544   ~ConstantDataSequential() { delete Next; }
545
546   static Constant *getImpl(StringRef Bytes, Type *Ty);
547
548 protected:
549   // allocate space for exactly zero operands.
550   void *operator new(size_t s) {
551     return User::operator new(s, 0);
552   }
553 public:
554
555   /// isElementTypeCompatible - Return true if a ConstantDataSequential can be
556   /// formed with a vector or array of the specified element type.
557   /// ConstantDataArray only works with normal float and int types that are
558   /// stored densely in memory, not with things like i42 or x86_f80.
559   static bool isElementTypeCompatible(const Type *Ty);
560
561   /// getElementAsInteger - If this is a sequential container of integers (of
562   /// any size), return the specified element in the low bits of a uint64_t.
563   uint64_t getElementAsInteger(unsigned i) const;
564
565   /// getElementAsAPFloat - If this is a sequential container of floating point
566   /// type, return the specified element as an APFloat.
567   APFloat getElementAsAPFloat(unsigned i) const;
568
569   /// getElementAsFloat - If this is an sequential container of floats, return
570   /// the specified element as a float.
571   float getElementAsFloat(unsigned i) const;
572
573   /// getElementAsDouble - If this is an sequential container of doubles, return
574   /// the specified element as a double.
575   double getElementAsDouble(unsigned i) const;
576
577   /// getElementAsConstant - Return a Constant for a specified index's element.
578   /// Note that this has to compute a new constant to return, so it isn't as
579   /// efficient as getElementAsInteger/Float/Double.
580   Constant *getElementAsConstant(unsigned i) const;
581
582   /// getType - Specialize the getType() method to always return a
583   /// SequentialType, which reduces the amount of casting needed in parts of the
584   /// compiler.
585   inline SequentialType *getType() const {
586     return cast<SequentialType>(Value::getType());
587   }
588
589   /// getElementType - Return the element type of the array/vector.
590   Type *getElementType() const;
591
592   /// getNumElements - Return the number of elements in the array or vector.
593   unsigned getNumElements() const;
594
595   /// getElementByteSize - Return the size (in bytes) of each element in the
596   /// array/vector.  The size of the elements is known to be a multiple of one
597   /// byte.
598   uint64_t getElementByteSize() const;
599
600
601   /// isString - This method returns true if this is an array of i8.
602   bool isString() const;
603
604   /// isCString - This method returns true if the array "isString", ends with a
605   /// nul byte, and does not contains any other nul bytes.
606   bool isCString() const;
607
608   /// getAsString - If this array is isString(), then this method returns the
609   /// array as a StringRef.  Otherwise, it asserts out.
610   ///
611   StringRef getAsString() const {
612     assert(isString() && "Not a string");
613     return getRawDataValues();
614   }
615
616   /// getAsCString - If this array is isCString(), then this method returns the
617   /// array (without the trailing null byte) as a StringRef. Otherwise, it
618   /// asserts out.
619   ///
620   StringRef getAsCString() const {
621     assert(isCString() && "Isn't a C string");
622     StringRef Str = getAsString();
623     return Str.substr(0, Str.size()-1);
624   }
625
626   /// getRawDataValues - Return the raw, underlying, bytes of this data.  Note
627   /// that this is an extremely tricky thing to work with, as it exposes the
628   /// host endianness of the data elements.
629   StringRef getRawDataValues() const;
630
631   void destroyConstant() override;
632
633   /// Methods for support type inquiry through isa, cast, and dyn_cast:
634   ///
635   static bool classof(const Value *V) {
636     return V->getValueID() == ConstantDataArrayVal ||
637            V->getValueID() == ConstantDataVectorVal;
638   }
639 private:
640   const char *getElementPointer(unsigned Elt) const;
641 };
642
643 //===----------------------------------------------------------------------===//
644 /// ConstantDataArray - An array constant whose element type is a simple
645 /// 1/2/4/8-byte integer or float/double, and whose elements are just simple
646 /// data values (i.e. ConstantInt/ConstantFP).  This Constant node has no
647 /// operands because it stores all of the elements of the constant as densely
648 /// packed data, instead of as Value*'s.
649 class ConstantDataArray : public ConstantDataSequential {
650   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
651   ConstantDataArray(const ConstantDataArray &) LLVM_DELETED_FUNCTION;
652   void anchor() override;
653   friend class ConstantDataSequential;
654   explicit ConstantDataArray(Type *ty, const char *Data)
655     : ConstantDataSequential(ty, ConstantDataArrayVal, Data) {}
656 protected:
657   // allocate space for exactly zero operands.
658   void *operator new(size_t s) {
659     return User::operator new(s, 0);
660   }
661 public:
662
663   /// get() constructors - Return a constant with array type with an element
664   /// count and element type matching the ArrayRef passed in.  Note that this
665   /// can return a ConstantAggregateZero object.
666   static Constant *get(LLVMContext &Context, ArrayRef<uint8_t> Elts);
667   static Constant *get(LLVMContext &Context, ArrayRef<uint16_t> Elts);
668   static Constant *get(LLVMContext &Context, ArrayRef<uint32_t> Elts);
669   static Constant *get(LLVMContext &Context, ArrayRef<uint64_t> Elts);
670   static Constant *get(LLVMContext &Context, ArrayRef<float> Elts);
671   static Constant *get(LLVMContext &Context, ArrayRef<double> Elts);
672
673   /// getString - This method constructs a CDS and initializes it with a text
674   /// string. The default behavior (AddNull==true) causes a null terminator to
675   /// be placed at the end of the array (increasing the length of the string by
676   /// one more than the StringRef would normally indicate.  Pass AddNull=false
677   /// to disable this behavior.
678   static Constant *getString(LLVMContext &Context, StringRef Initializer,
679                              bool AddNull = true);
680
681   /// getType - Specialize the getType() method to always return an ArrayType,
682   /// which reduces the amount of casting needed in parts of the compiler.
683   ///
684   inline ArrayType *getType() const {
685     return cast<ArrayType>(Value::getType());
686   }
687
688   /// Methods for support type inquiry through isa, cast, and dyn_cast:
689   ///
690   static bool classof(const Value *V) {
691     return V->getValueID() == ConstantDataArrayVal;
692   }
693 };
694
695 //===----------------------------------------------------------------------===//
696 /// ConstantDataVector - A vector constant whose element type is a simple
697 /// 1/2/4/8-byte integer or float/double, and whose elements are just simple
698 /// data values (i.e. ConstantInt/ConstantFP).  This Constant node has no
699 /// operands because it stores all of the elements of the constant as densely
700 /// packed data, instead of as Value*'s.
701 class ConstantDataVector : public ConstantDataSequential {
702   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
703   ConstantDataVector(const ConstantDataVector &) LLVM_DELETED_FUNCTION;
704   void anchor() override;
705   friend class ConstantDataSequential;
706   explicit ConstantDataVector(Type *ty, const char *Data)
707   : ConstantDataSequential(ty, ConstantDataVectorVal, Data) {}
708 protected:
709   // allocate space for exactly zero operands.
710   void *operator new(size_t s) {
711     return User::operator new(s, 0);
712   }
713 public:
714
715   /// get() constructors - Return a constant with vector type with an element
716   /// count and element type matching the ArrayRef passed in.  Note that this
717   /// can return a ConstantAggregateZero object.
718   static Constant *get(LLVMContext &Context, ArrayRef<uint8_t> Elts);
719   static Constant *get(LLVMContext &Context, ArrayRef<uint16_t> Elts);
720   static Constant *get(LLVMContext &Context, ArrayRef<uint32_t> Elts);
721   static Constant *get(LLVMContext &Context, ArrayRef<uint64_t> Elts);
722   static Constant *get(LLVMContext &Context, ArrayRef<float> Elts);
723   static Constant *get(LLVMContext &Context, ArrayRef<double> Elts);
724
725   /// getSplat - Return a ConstantVector with the specified constant in each
726   /// element.  The specified constant has to be a of a compatible type (i8/i16/
727   /// i32/i64/float/double) and must be a ConstantFP or ConstantInt.
728   static Constant *getSplat(unsigned NumElts, Constant *Elt);
729
730   /// getSplatValue - If this is a splat constant, meaning that all of the
731   /// elements have the same value, return that value. Otherwise return NULL.
732   Constant *getSplatValue() const;
733
734   /// getType - Specialize the getType() method to always return a VectorType,
735   /// which reduces the amount of casting needed in parts of the compiler.
736   ///
737   inline VectorType *getType() const {
738     return cast<VectorType>(Value::getType());
739   }
740
741   /// Methods for support type inquiry through isa, cast, and dyn_cast:
742   ///
743   static bool classof(const Value *V) {
744     return V->getValueID() == ConstantDataVectorVal;
745   }
746 };
747
748
749
750 /// BlockAddress - The address of a basic block.
751 ///
752 class BlockAddress : public Constant {
753   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
754   void *operator new(size_t s) { return User::operator new(s, 2); }
755   BlockAddress(Function *F, BasicBlock *BB);
756 public:
757   /// get - Return a BlockAddress for the specified function and basic block.
758   static BlockAddress *get(Function *F, BasicBlock *BB);
759
760   /// get - Return a BlockAddress for the specified basic block.  The basic
761   /// block must be embedded into a function.
762   static BlockAddress *get(BasicBlock *BB);
763
764   /// \brief Lookup an existing \c BlockAddress constant for the given
765   /// BasicBlock.
766   ///
767   /// \returns 0 if \c !BB->hasAddressTaken(), otherwise the \c BlockAddress.
768   static BlockAddress *lookup(const BasicBlock *BB);
769
770   /// Transparently provide more efficient getOperand methods.
771   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
772
773   Function *getFunction() const { return (Function*)Op<0>().get(); }
774   BasicBlock *getBasicBlock() const { return (BasicBlock*)Op<1>().get(); }
775
776   void destroyConstant() override;
777   void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) override;
778
779   /// Methods for support type inquiry through isa, cast, and dyn_cast:
780   static inline bool classof(const Value *V) {
781     return V->getValueID() == BlockAddressVal;
782   }
783 };
784
785 template <>
786 struct OperandTraits<BlockAddress> :
787   public FixedNumOperandTraits<BlockAddress, 2> {
788 };
789
790 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BlockAddress, Value)
791
792
793 //===----------------------------------------------------------------------===//
794 /// ConstantExpr - a constant value that is initialized with an expression using
795 /// other constant values.
796 ///
797 /// This class uses the standard Instruction opcodes to define the various
798 /// constant expressions.  The Opcode field for the ConstantExpr class is
799 /// maintained in the Value::SubclassData field.
800 class ConstantExpr : public Constant {
801   friend struct ConstantExprKeyType;
802
803 protected:
804   ConstantExpr(Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
805     : Constant(ty, ConstantExprVal, Ops, NumOps) {
806     // Operation type (an Instruction opcode) is stored as the SubclassData.
807     setValueSubclassData(Opcode);
808   }
809
810 public:
811   // Static methods to construct a ConstantExpr of different kinds.  Note that
812   // these methods may return a object that is not an instance of the
813   // ConstantExpr class, because they will attempt to fold the constant
814   // expression into something simpler if possible.
815
816   /// getAlignOf constant expr - computes the alignment of a type in a target
817   /// independent way (Note: the return type is an i64).
818   static Constant *getAlignOf(Type *Ty);
819
820   /// getSizeOf constant expr - computes the (alloc) size of a type (in
821   /// address-units, not bits) in a target independent way (Note: the return
822   /// type is an i64).
823   ///
824   static Constant *getSizeOf(Type *Ty);
825
826   /// getOffsetOf constant expr - computes the offset of a struct field in a
827   /// target independent way (Note: the return type is an i64).
828   ///
829   static Constant *getOffsetOf(StructType *STy, unsigned FieldNo);
830
831   /// getOffsetOf constant expr - This is a generalized form of getOffsetOf,
832   /// which supports any aggregate type, and any Constant index.
833   ///
834   static Constant *getOffsetOf(Type *Ty, Constant *FieldNo);
835
836   static Constant *getNeg(Constant *C, bool HasNUW = false, bool HasNSW =false);
837   static Constant *getFNeg(Constant *C);
838   static Constant *getNot(Constant *C);
839   static Constant *getAdd(Constant *C1, Constant *C2,
840                           bool HasNUW = false, bool HasNSW = false);
841   static Constant *getFAdd(Constant *C1, Constant *C2);
842   static Constant *getSub(Constant *C1, Constant *C2,
843                           bool HasNUW = false, bool HasNSW = false);
844   static Constant *getFSub(Constant *C1, Constant *C2);
845   static Constant *getMul(Constant *C1, Constant *C2,
846                           bool HasNUW = false, bool HasNSW = false);
847   static Constant *getFMul(Constant *C1, Constant *C2);
848   static Constant *getUDiv(Constant *C1, Constant *C2, bool isExact = false);
849   static Constant *getSDiv(Constant *C1, Constant *C2, bool isExact = false);
850   static Constant *getFDiv(Constant *C1, Constant *C2);
851   static Constant *getURem(Constant *C1, Constant *C2);
852   static Constant *getSRem(Constant *C1, Constant *C2);
853   static Constant *getFRem(Constant *C1, Constant *C2);
854   static Constant *getAnd(Constant *C1, Constant *C2);
855   static Constant *getOr(Constant *C1, Constant *C2);
856   static Constant *getXor(Constant *C1, Constant *C2);
857   static Constant *getShl(Constant *C1, Constant *C2,
858                           bool HasNUW = false, bool HasNSW = false);
859   static Constant *getLShr(Constant *C1, Constant *C2, bool isExact = false);
860   static Constant *getAShr(Constant *C1, Constant *C2, bool isExact = false);
861   static Constant *getTrunc   (Constant *C, Type *Ty);
862   static Constant *getSExt    (Constant *C, Type *Ty);
863   static Constant *getZExt    (Constant *C, Type *Ty);
864   static Constant *getFPTrunc (Constant *C, Type *Ty);
865   static Constant *getFPExtend(Constant *C, Type *Ty);
866   static Constant *getUIToFP  (Constant *C, Type *Ty);
867   static Constant *getSIToFP  (Constant *C, Type *Ty);
868   static Constant *getFPToUI  (Constant *C, Type *Ty);
869   static Constant *getFPToSI  (Constant *C, Type *Ty);
870   static Constant *getPtrToInt(Constant *C, Type *Ty);
871   static Constant *getIntToPtr(Constant *C, Type *Ty);
872   static Constant *getBitCast (Constant *C, Type *Ty);
873   static Constant *getAddrSpaceCast(Constant *C, Type *Ty);
874
875   static Constant *getNSWNeg(Constant *C) { return getNeg(C, false, true); }
876   static Constant *getNUWNeg(Constant *C) { return getNeg(C, true, false); }
877   static Constant *getNSWAdd(Constant *C1, Constant *C2) {
878     return getAdd(C1, C2, false, true);
879   }
880   static Constant *getNUWAdd(Constant *C1, Constant *C2) {
881     return getAdd(C1, C2, true, false);
882   }
883   static Constant *getNSWSub(Constant *C1, Constant *C2) {
884     return getSub(C1, C2, false, true);
885   }
886   static Constant *getNUWSub(Constant *C1, Constant *C2) {
887     return getSub(C1, C2, true, false);
888   }
889   static Constant *getNSWMul(Constant *C1, Constant *C2) {
890     return getMul(C1, C2, false, true);
891   }
892   static Constant *getNUWMul(Constant *C1, Constant *C2) {
893     return getMul(C1, C2, true, false);
894   }
895   static Constant *getNSWShl(Constant *C1, Constant *C2) {
896     return getShl(C1, C2, false, true);
897   }
898   static Constant *getNUWShl(Constant *C1, Constant *C2) {
899     return getShl(C1, C2, true, false);
900   }
901   static Constant *getExactSDiv(Constant *C1, Constant *C2) {
902     return getSDiv(C1, C2, true);
903   }
904   static Constant *getExactUDiv(Constant *C1, Constant *C2) {
905     return getUDiv(C1, C2, true);
906   }
907   static Constant *getExactAShr(Constant *C1, Constant *C2) {
908     return getAShr(C1, C2, true);
909   }
910   static Constant *getExactLShr(Constant *C1, Constant *C2) {
911     return getLShr(C1, C2, true);
912   }
913
914   /// getBinOpIdentity - Return the identity for the given binary operation,
915   /// i.e. a constant C such that X op C = X and C op X = X for every X.  It
916   /// returns null if the operator doesn't have an identity.
917   static Constant *getBinOpIdentity(unsigned Opcode, Type *Ty);
918
919   /// getBinOpAbsorber - Return the absorbing element for the given binary
920   /// operation, i.e. a constant C such that X op C = C and C op X = C for
921   /// every X.  For example, this returns zero for integer multiplication.
922   /// It returns null if the operator doesn't have an absorbing element.
923   static Constant *getBinOpAbsorber(unsigned Opcode, Type *Ty);
924
925   /// Transparently provide more efficient getOperand methods.
926   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
927
928   // @brief Convenience function for getting one of the casting operations
929   // using a CastOps opcode.
930   static Constant *getCast(
931     unsigned ops,  ///< The opcode for the conversion
932     Constant *C,   ///< The constant to be converted
933     Type *Ty ///< The type to which the constant is converted
934   );
935
936   // @brief Create a ZExt or BitCast cast constant expression
937   static Constant *getZExtOrBitCast(
938     Constant *C,   ///< The constant to zext or bitcast
939     Type *Ty ///< The type to zext or bitcast C to
940   );
941
942   // @brief Create a SExt or BitCast cast constant expression
943   static Constant *getSExtOrBitCast(
944     Constant *C,   ///< The constant to sext or bitcast
945     Type *Ty ///< The type to sext or bitcast C to
946   );
947
948   // @brief Create a Trunc or BitCast cast constant expression
949   static Constant *getTruncOrBitCast(
950     Constant *C,   ///< The constant to trunc or bitcast
951     Type *Ty ///< The type to trunc or bitcast C to
952   );
953
954   /// @brief Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant
955   /// expression.
956   static Constant *getPointerCast(
957     Constant *C,   ///< The pointer value to be casted (operand 0)
958     Type *Ty ///< The type to which cast should be made
959   );
960
961   /// @brief Create a BitCast or AddrSpaceCast for a pointer type depending on
962   /// the address space.
963   static Constant *getPointerBitCastOrAddrSpaceCast(
964     Constant *C,   ///< The constant to addrspacecast or bitcast
965     Type *Ty ///< The type to bitcast or addrspacecast C to
966   );
967
968   /// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts
969   static Constant *getIntegerCast(
970     Constant *C,    ///< The integer constant to be casted
971     Type *Ty, ///< The integer type to cast to
972     bool isSigned   ///< Whether C should be treated as signed or not
973   );
974
975   /// @brief Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
976   static Constant *getFPCast(
977     Constant *C,    ///< The integer constant to be casted
978     Type *Ty ///< The integer type to cast to
979   );
980
981   /// @brief Return true if this is a convert constant expression
982   bool isCast() const;
983
984   /// @brief Return true if this is a compare constant expression
985   bool isCompare() const;
986
987   /// @brief Return true if this is an insertvalue or extractvalue expression,
988   /// and the getIndices() method may be used.
989   bool hasIndices() const;
990
991   /// @brief Return true if this is a getelementptr expression and all
992   /// the index operands are compile-time known integers within the
993   /// corresponding notional static array extents. Note that this is
994   /// not equivalant to, a subset of, or a superset of the "inbounds"
995   /// property.
996   bool isGEPWithNoNotionalOverIndexing() const;
997
998   /// Select constant expr
999   ///
1000   static Constant *getSelect(Constant *C, Constant *V1, Constant *V2);
1001
1002   /// get - Return a binary or shift operator constant expression,
1003   /// folding if possible.
1004   ///
1005   static Constant *get(unsigned Opcode, Constant *C1, Constant *C2,
1006                        unsigned Flags = 0);
1007
1008   /// @brief Return an ICmp or FCmp comparison operator constant expression.
1009   static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2);
1010
1011   /// get* - Return some common constants without having to
1012   /// specify the full Instruction::OPCODE identifier.
1013   ///
1014   static Constant *getICmp(unsigned short pred, Constant *LHS, Constant *RHS);
1015   static Constant *getFCmp(unsigned short pred, Constant *LHS, Constant *RHS);
1016
1017   /// Getelementptr form.  Value* is only accepted for convenience;
1018   /// all elements must be Constant's.
1019   ///
1020   static Constant *getGetElementPtr(Constant *C,
1021                                     ArrayRef<Constant *> IdxList,
1022                                     bool InBounds = false) {
1023     return getGetElementPtr(C, makeArrayRef((Value * const *)IdxList.data(),
1024                                             IdxList.size()),
1025                             InBounds);
1026   }
1027   static Constant *getGetElementPtr(Constant *C,
1028                                     Constant *Idx,
1029                                     bool InBounds = false) {
1030     // This form of the function only exists to avoid ambiguous overload
1031     // warnings about whether to convert Idx to ArrayRef<Constant *> or
1032     // ArrayRef<Value *>.
1033     return getGetElementPtr(C, cast<Value>(Idx), InBounds);
1034   }
1035   static Constant *getGetElementPtr(Constant *C,
1036                                     ArrayRef<Value *> IdxList,
1037                                     bool InBounds = false);
1038
1039   /// Create an "inbounds" getelementptr. See the documentation for the
1040   /// "inbounds" flag in LangRef.html for details.
1041   static Constant *getInBoundsGetElementPtr(Constant *C,
1042                                             ArrayRef<Constant *> IdxList) {
1043     return getGetElementPtr(C, IdxList, true);
1044   }
1045   static Constant *getInBoundsGetElementPtr(Constant *C,
1046                                             Constant *Idx) {
1047     // This form of the function only exists to avoid ambiguous overload
1048     // warnings about whether to convert Idx to ArrayRef<Constant *> or
1049     // ArrayRef<Value *>.
1050     return getGetElementPtr(C, Idx, true);
1051   }
1052   static Constant *getInBoundsGetElementPtr(Constant *C,
1053                                             ArrayRef<Value *> IdxList) {
1054     return getGetElementPtr(C, IdxList, true);
1055   }
1056
1057   static Constant *getExtractElement(Constant *Vec, Constant *Idx);
1058   static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
1059   static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
1060   static Constant *getExtractValue(Constant *Agg, ArrayRef<unsigned> Idxs);
1061   static Constant *getInsertValue(Constant *Agg, Constant *Val,
1062                                   ArrayRef<unsigned> Idxs);
1063
1064   /// getOpcode - Return the opcode at the root of this constant expression
1065   unsigned getOpcode() const { return getSubclassDataFromValue(); }
1066
1067   /// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is
1068   /// not an ICMP or FCMP constant expression.
1069   unsigned getPredicate() const;
1070
1071   /// getIndices - Assert that this is an insertvalue or exactvalue
1072   /// expression and return the list of indices.
1073   ArrayRef<unsigned> getIndices() const;
1074
1075   /// getOpcodeName - Return a string representation for an opcode.
1076   const char *getOpcodeName() const;
1077
1078   /// getWithOperandReplaced - Return a constant expression identical to this
1079   /// one, but with the specified operand set to the specified value.
1080   Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
1081
1082   /// getWithOperands - This returns the current constant expression with the
1083   /// operands replaced with the specified values.  The specified array must
1084   /// have the same number of operands as our current one.
1085   Constant *getWithOperands(ArrayRef<Constant*> Ops) const {
1086     return getWithOperands(Ops, getType());
1087   }
1088
1089   /// getWithOperands - This returns the current constant expression with the
1090   /// operands replaced with the specified values and with the specified result
1091   /// type.  The specified array must have the same number of operands as our
1092   /// current one.
1093   Constant *getWithOperands(ArrayRef<Constant*> Ops, Type *Ty) const;
1094
1095   /// getAsInstruction - Returns an Instruction which implements the same operation
1096   /// as this ConstantExpr. The instruction is not linked to any basic block.
1097   ///
1098   /// A better approach to this could be to have a constructor for Instruction
1099   /// which would take a ConstantExpr parameter, but that would have spread
1100   /// implementation details of ConstantExpr outside of Constants.cpp, which
1101   /// would make it harder to remove ConstantExprs altogether.
1102   Instruction *getAsInstruction();
1103
1104   void destroyConstant() override;
1105   void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) override;
1106
1107   /// Methods for support type inquiry through isa, cast, and dyn_cast:
1108   static inline bool classof(const Value *V) {
1109     return V->getValueID() == ConstantExprVal;
1110   }
1111
1112 private:
1113   // Shadow Value::setValueSubclassData with a private forwarding method so that
1114   // subclasses cannot accidentally use it.
1115   void setValueSubclassData(unsigned short D) {
1116     Value::setValueSubclassData(D);
1117   }
1118
1119   /// \brief Check whether this can become its replacement.
1120   ///
1121   /// For use during \a replaceUsesOfWithOnConstant(), check whether we know
1122   /// how to turn this into \a Replacement, thereby reducing RAUW traffic.
1123   bool canBecomeReplacement(const Constant *Replacement) const;
1124 };
1125
1126 template <>
1127 struct OperandTraits<ConstantExpr> :
1128   public VariadicOperandTraits<ConstantExpr, 1> {
1129 };
1130
1131 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantExpr, Constant)
1132
1133 //===----------------------------------------------------------------------===//
1134 /// UndefValue - 'undef' values are things that do not have specified contents.
1135 /// These are used for a variety of purposes, including global variable
1136 /// initializers and operands to instructions.  'undef' values can occur with
1137 /// any first-class type.
1138 ///
1139 /// Undef values aren't exactly constants; if they have multiple uses, they
1140 /// can appear to have different bit patterns at each use. See
1141 /// LangRef.html#undefvalues for details.
1142 ///
1143 class UndefValue : public Constant {
1144   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
1145   UndefValue(const UndefValue &) LLVM_DELETED_FUNCTION;
1146 protected:
1147   explicit UndefValue(Type *T) : Constant(T, UndefValueVal, nullptr, 0) {}
1148 protected:
1149   // allocate space for exactly zero operands
1150   void *operator new(size_t s) {
1151     return User::operator new(s, 0);
1152   }
1153 public:
1154   /// get() - Static factory methods - Return an 'undef' object of the specified
1155   /// type.
1156   ///
1157   static UndefValue *get(Type *T);
1158
1159   /// getSequentialElement - If this Undef has array or vector type, return a
1160   /// undef with the right element type.
1161   UndefValue *getSequentialElement() const;
1162
1163   /// getStructElement - If this undef has struct type, return a undef with the
1164   /// right element type for the specified element.
1165   UndefValue *getStructElement(unsigned Elt) const;
1166
1167   /// getElementValue - Return an undef of the right value for the specified GEP
1168   /// index.
1169   UndefValue *getElementValue(Constant *C) const;
1170
1171   /// getElementValue - Return an undef of the right value for the specified GEP
1172   /// index.
1173   UndefValue *getElementValue(unsigned Idx) const;
1174
1175   void destroyConstant() override;
1176
1177   /// Methods for support type inquiry through isa, cast, and dyn_cast:
1178   static bool classof(const Value *V) {
1179     return V->getValueID() == UndefValueVal;
1180   }
1181 };
1182
1183 } // End llvm namespace
1184
1185 #endif