IR: Reduce RAUW traffic in ConstantExpr
[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   /// Transparently provide more efficient getOperand methods.
346   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
347
348   /// getType - Specialize the getType() method to always return an ArrayType,
349   /// which reduces the amount of casting needed in parts of the compiler.
350   ///
351   inline ArrayType *getType() const {
352     return cast<ArrayType>(Value::getType());
353   }
354
355   void destroyConstant() override;
356   void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) override;
357
358   /// Methods for support type inquiry through isa, cast, and dyn_cast:
359   static bool classof(const Value *V) {
360     return V->getValueID() == ConstantArrayVal;
361   }
362 };
363
364 template <>
365 struct OperandTraits<ConstantArray> :
366   public VariadicOperandTraits<ConstantArray> {
367 };
368
369 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantArray, Constant)
370
371 //===----------------------------------------------------------------------===//
372 // ConstantStruct - Constant Struct Declarations
373 //
374 class ConstantStruct : public Constant {
375   friend struct ConstantAggrKeyType<ConstantStruct>;
376   ConstantStruct(const ConstantStruct &) LLVM_DELETED_FUNCTION;
377 protected:
378   ConstantStruct(StructType *T, ArrayRef<Constant *> Val);
379 public:
380   // ConstantStruct accessors
381   static Constant *get(StructType *T, ArrayRef<Constant*> V);
382   static Constant *get(StructType *T, ...) END_WITH_NULL;
383
384   /// getAnon - Return an anonymous struct that has the specified
385   /// elements.  If the struct is possibly empty, then you must specify a
386   /// context.
387   static Constant *getAnon(ArrayRef<Constant*> V, bool Packed = false) {
388     return get(getTypeForElements(V, Packed), V);
389   }
390   static Constant *getAnon(LLVMContext &Ctx,
391                            ArrayRef<Constant*> V, bool Packed = false) {
392     return get(getTypeForElements(Ctx, V, Packed), V);
393   }
394
395   /// getTypeForElements - Return an anonymous struct type to use for a constant
396   /// with the specified set of elements.  The list must not be empty.
397   static StructType *getTypeForElements(ArrayRef<Constant*> V,
398                                         bool Packed = false);
399   /// getTypeForElements - This version of the method allows an empty list.
400   static StructType *getTypeForElements(LLVMContext &Ctx,
401                                         ArrayRef<Constant*> V,
402                                         bool Packed = false);
403
404   /// Transparently provide more efficient getOperand methods.
405   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
406
407   /// getType() specialization - Reduce amount of casting...
408   ///
409   inline StructType *getType() const {
410     return cast<StructType>(Value::getType());
411   }
412
413   void destroyConstant() override;
414   void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) override;
415
416   /// Methods for support type inquiry through isa, cast, and dyn_cast:
417   static bool classof(const Value *V) {
418     return V->getValueID() == ConstantStructVal;
419   }
420 };
421
422 template <>
423 struct OperandTraits<ConstantStruct> :
424   public VariadicOperandTraits<ConstantStruct> {
425 };
426
427 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantStruct, Constant)
428
429
430 //===----------------------------------------------------------------------===//
431 /// ConstantVector - Constant Vector Declarations
432 ///
433 class ConstantVector : public Constant {
434   friend struct ConstantAggrKeyType<ConstantVector>;
435   ConstantVector(const ConstantVector &) LLVM_DELETED_FUNCTION;
436 protected:
437   ConstantVector(VectorType *T, ArrayRef<Constant *> Val);
438 public:
439   // ConstantVector accessors
440   static Constant *get(ArrayRef<Constant*> V);
441
442   /// getSplat - Return a ConstantVector with the specified constant in each
443   /// element.
444   static Constant *getSplat(unsigned NumElts, Constant *Elt);
445
446   /// Transparently provide more efficient getOperand methods.
447   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
448
449   /// getType - Specialize the getType() method to always return a VectorType,
450   /// which reduces the amount of casting needed in parts of the compiler.
451   ///
452   inline VectorType *getType() const {
453     return cast<VectorType>(Value::getType());
454   }
455
456   /// getSplatValue - If this is a splat constant, meaning that all of the
457   /// elements have the same value, return that value. Otherwise return NULL.
458   Constant *getSplatValue() const;
459
460   void destroyConstant() override;
461   void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) override;
462
463   /// Methods for support type inquiry through isa, cast, and dyn_cast:
464   static bool classof(const Value *V) {
465     return V->getValueID() == ConstantVectorVal;
466   }
467 };
468
469 template <>
470 struct OperandTraits<ConstantVector> :
471   public VariadicOperandTraits<ConstantVector> {
472 };
473
474 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantVector, Constant)
475
476 //===----------------------------------------------------------------------===//
477 /// ConstantPointerNull - a constant pointer value that points to null
478 ///
479 class ConstantPointerNull : public Constant {
480   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
481   ConstantPointerNull(const ConstantPointerNull &) LLVM_DELETED_FUNCTION;
482 protected:
483   explicit ConstantPointerNull(PointerType *T)
484     : Constant(T,
485                Value::ConstantPointerNullVal, nullptr, 0) {}
486
487 protected:
488   // allocate space for exactly zero operands
489   void *operator new(size_t s) {
490     return User::operator new(s, 0);
491   }
492 public:
493   /// get() - Static factory methods - Return objects of the specified value
494   static ConstantPointerNull *get(PointerType *T);
495
496   void destroyConstant() override;
497
498   /// getType - Specialize the getType() method to always return an PointerType,
499   /// which reduces the amount of casting needed in parts of the compiler.
500   ///
501   inline PointerType *getType() const {
502     return cast<PointerType>(Value::getType());
503   }
504
505   /// Methods for support type inquiry through isa, cast, and dyn_cast:
506   static bool classof(const Value *V) {
507     return V->getValueID() == ConstantPointerNullVal;
508   }
509 };
510
511 //===----------------------------------------------------------------------===//
512 /// ConstantDataSequential - A vector or array constant whose element type is a
513 /// simple 1/2/4/8-byte integer or float/double, and whose elements are just
514 /// simple data values (i.e. ConstantInt/ConstantFP).  This Constant node has no
515 /// operands because it stores all of the elements of the constant as densely
516 /// packed data, instead of as Value*'s.
517 ///
518 /// This is the common base class of ConstantDataArray and ConstantDataVector.
519 ///
520 class ConstantDataSequential : public Constant {
521   friend class LLVMContextImpl;
522   /// DataElements - A pointer to the bytes underlying this constant (which is
523   /// owned by the uniquing StringMap).
524   const char *DataElements;
525
526   /// Next - This forms a link list of ConstantDataSequential nodes that have
527   /// the same value but different type.  For example, 0,0,0,1 could be a 4
528   /// element array of i8, or a 1-element array of i32.  They'll both end up in
529   /// the same StringMap bucket, linked up.
530   ConstantDataSequential *Next;
531   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
532   ConstantDataSequential(const ConstantDataSequential &) LLVM_DELETED_FUNCTION;
533 protected:
534   explicit ConstantDataSequential(Type *ty, ValueTy VT, const char *Data)
535     : Constant(ty, VT, nullptr, 0), DataElements(Data), Next(nullptr) {}
536   ~ConstantDataSequential() { delete Next; }
537
538   static Constant *getImpl(StringRef Bytes, Type *Ty);
539
540 protected:
541   // allocate space for exactly zero operands.
542   void *operator new(size_t s) {
543     return User::operator new(s, 0);
544   }
545 public:
546
547   /// isElementTypeCompatible - Return true if a ConstantDataSequential can be
548   /// formed with a vector or array of the specified element type.
549   /// ConstantDataArray only works with normal float and int types that are
550   /// stored densely in memory, not with things like i42 or x86_f80.
551   static bool isElementTypeCompatible(const Type *Ty);
552
553   /// getElementAsInteger - If this is a sequential container of integers (of
554   /// any size), return the specified element in the low bits of a uint64_t.
555   uint64_t getElementAsInteger(unsigned i) const;
556
557   /// getElementAsAPFloat - If this is a sequential container of floating point
558   /// type, return the specified element as an APFloat.
559   APFloat getElementAsAPFloat(unsigned i) const;
560
561   /// getElementAsFloat - If this is an sequential container of floats, return
562   /// the specified element as a float.
563   float getElementAsFloat(unsigned i) const;
564
565   /// getElementAsDouble - If this is an sequential container of doubles, return
566   /// the specified element as a double.
567   double getElementAsDouble(unsigned i) const;
568
569   /// getElementAsConstant - Return a Constant for a specified index's element.
570   /// Note that this has to compute a new constant to return, so it isn't as
571   /// efficient as getElementAsInteger/Float/Double.
572   Constant *getElementAsConstant(unsigned i) const;
573
574   /// getType - Specialize the getType() method to always return a
575   /// SequentialType, which reduces the amount of casting needed in parts of the
576   /// compiler.
577   inline SequentialType *getType() const {
578     return cast<SequentialType>(Value::getType());
579   }
580
581   /// getElementType - Return the element type of the array/vector.
582   Type *getElementType() const;
583
584   /// getNumElements - Return the number of elements in the array or vector.
585   unsigned getNumElements() const;
586
587   /// getElementByteSize - Return the size (in bytes) of each element in the
588   /// array/vector.  The size of the elements is known to be a multiple of one
589   /// byte.
590   uint64_t getElementByteSize() const;
591
592
593   /// isString - This method returns true if this is an array of i8.
594   bool isString() const;
595
596   /// isCString - This method returns true if the array "isString", ends with a
597   /// nul byte, and does not contains any other nul bytes.
598   bool isCString() const;
599
600   /// getAsString - If this array is isString(), then this method returns the
601   /// array as a StringRef.  Otherwise, it asserts out.
602   ///
603   StringRef getAsString() const {
604     assert(isString() && "Not a string");
605     return getRawDataValues();
606   }
607
608   /// getAsCString - If this array is isCString(), then this method returns the
609   /// array (without the trailing null byte) as a StringRef. Otherwise, it
610   /// asserts out.
611   ///
612   StringRef getAsCString() const {
613     assert(isCString() && "Isn't a C string");
614     StringRef Str = getAsString();
615     return Str.substr(0, Str.size()-1);
616   }
617
618   /// getRawDataValues - Return the raw, underlying, bytes of this data.  Note
619   /// that this is an extremely tricky thing to work with, as it exposes the
620   /// host endianness of the data elements.
621   StringRef getRawDataValues() const;
622
623   void destroyConstant() override;
624
625   /// Methods for support type inquiry through isa, cast, and dyn_cast:
626   ///
627   static bool classof(const Value *V) {
628     return V->getValueID() == ConstantDataArrayVal ||
629            V->getValueID() == ConstantDataVectorVal;
630   }
631 private:
632   const char *getElementPointer(unsigned Elt) const;
633 };
634
635 //===----------------------------------------------------------------------===//
636 /// ConstantDataArray - An array constant whose element type is a simple
637 /// 1/2/4/8-byte integer or float/double, and whose elements are just simple
638 /// data values (i.e. ConstantInt/ConstantFP).  This Constant node has no
639 /// operands because it stores all of the elements of the constant as densely
640 /// packed data, instead of as Value*'s.
641 class ConstantDataArray : public ConstantDataSequential {
642   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
643   ConstantDataArray(const ConstantDataArray &) LLVM_DELETED_FUNCTION;
644   void anchor() override;
645   friend class ConstantDataSequential;
646   explicit ConstantDataArray(Type *ty, const char *Data)
647     : ConstantDataSequential(ty, ConstantDataArrayVal, Data) {}
648 protected:
649   // allocate space for exactly zero operands.
650   void *operator new(size_t s) {
651     return User::operator new(s, 0);
652   }
653 public:
654
655   /// get() constructors - Return a constant with array type with an element
656   /// count and element type matching the ArrayRef passed in.  Note that this
657   /// can return a ConstantAggregateZero object.
658   static Constant *get(LLVMContext &Context, ArrayRef<uint8_t> Elts);
659   static Constant *get(LLVMContext &Context, ArrayRef<uint16_t> Elts);
660   static Constant *get(LLVMContext &Context, ArrayRef<uint32_t> Elts);
661   static Constant *get(LLVMContext &Context, ArrayRef<uint64_t> Elts);
662   static Constant *get(LLVMContext &Context, ArrayRef<float> Elts);
663   static Constant *get(LLVMContext &Context, ArrayRef<double> Elts);
664
665   /// getString - This method constructs a CDS and initializes it with a text
666   /// string. The default behavior (AddNull==true) causes a null terminator to
667   /// be placed at the end of the array (increasing the length of the string by
668   /// one more than the StringRef would normally indicate.  Pass AddNull=false
669   /// to disable this behavior.
670   static Constant *getString(LLVMContext &Context, StringRef Initializer,
671                              bool AddNull = true);
672
673   /// getType - Specialize the getType() method to always return an ArrayType,
674   /// which reduces the amount of casting needed in parts of the compiler.
675   ///
676   inline ArrayType *getType() const {
677     return cast<ArrayType>(Value::getType());
678   }
679
680   /// Methods for support type inquiry through isa, cast, and dyn_cast:
681   ///
682   static bool classof(const Value *V) {
683     return V->getValueID() == ConstantDataArrayVal;
684   }
685 };
686
687 //===----------------------------------------------------------------------===//
688 /// ConstantDataVector - A vector constant whose element type is a simple
689 /// 1/2/4/8-byte integer or float/double, and whose elements are just simple
690 /// data values (i.e. ConstantInt/ConstantFP).  This Constant node has no
691 /// operands because it stores all of the elements of the constant as densely
692 /// packed data, instead of as Value*'s.
693 class ConstantDataVector : public ConstantDataSequential {
694   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
695   ConstantDataVector(const ConstantDataVector &) LLVM_DELETED_FUNCTION;
696   void anchor() override;
697   friend class ConstantDataSequential;
698   explicit ConstantDataVector(Type *ty, const char *Data)
699   : ConstantDataSequential(ty, ConstantDataVectorVal, Data) {}
700 protected:
701   // allocate space for exactly zero operands.
702   void *operator new(size_t s) {
703     return User::operator new(s, 0);
704   }
705 public:
706
707   /// get() constructors - Return a constant with vector type with an element
708   /// count and element type matching the ArrayRef passed in.  Note that this
709   /// can return a ConstantAggregateZero object.
710   static Constant *get(LLVMContext &Context, ArrayRef<uint8_t> Elts);
711   static Constant *get(LLVMContext &Context, ArrayRef<uint16_t> Elts);
712   static Constant *get(LLVMContext &Context, ArrayRef<uint32_t> Elts);
713   static Constant *get(LLVMContext &Context, ArrayRef<uint64_t> Elts);
714   static Constant *get(LLVMContext &Context, ArrayRef<float> Elts);
715   static Constant *get(LLVMContext &Context, ArrayRef<double> Elts);
716
717   /// getSplat - Return a ConstantVector with the specified constant in each
718   /// element.  The specified constant has to be a of a compatible type (i8/i16/
719   /// i32/i64/float/double) and must be a ConstantFP or ConstantInt.
720   static Constant *getSplat(unsigned NumElts, Constant *Elt);
721
722   /// getSplatValue - If this is a splat constant, meaning that all of the
723   /// elements have the same value, return that value. Otherwise return NULL.
724   Constant *getSplatValue() const;
725
726   /// getType - Specialize the getType() method to always return a VectorType,
727   /// which reduces the amount of casting needed in parts of the compiler.
728   ///
729   inline VectorType *getType() const {
730     return cast<VectorType>(Value::getType());
731   }
732
733   /// Methods for support type inquiry through isa, cast, and dyn_cast:
734   ///
735   static bool classof(const Value *V) {
736     return V->getValueID() == ConstantDataVectorVal;
737   }
738 };
739
740
741
742 /// BlockAddress - The address of a basic block.
743 ///
744 class BlockAddress : public Constant {
745   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
746   void *operator new(size_t s) { return User::operator new(s, 2); }
747   BlockAddress(Function *F, BasicBlock *BB);
748 public:
749   /// get - Return a BlockAddress for the specified function and basic block.
750   static BlockAddress *get(Function *F, BasicBlock *BB);
751
752   /// get - Return a BlockAddress for the specified basic block.  The basic
753   /// block must be embedded into a function.
754   static BlockAddress *get(BasicBlock *BB);
755
756   /// \brief Lookup an existing \c BlockAddress constant for the given
757   /// BasicBlock.
758   ///
759   /// \returns 0 if \c !BB->hasAddressTaken(), otherwise the \c BlockAddress.
760   static BlockAddress *lookup(const BasicBlock *BB);
761
762   /// Transparently provide more efficient getOperand methods.
763   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
764
765   Function *getFunction() const { return (Function*)Op<0>().get(); }
766   BasicBlock *getBasicBlock() const { return (BasicBlock*)Op<1>().get(); }
767
768   void destroyConstant() override;
769   void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) override;
770
771   /// Methods for support type inquiry through isa, cast, and dyn_cast:
772   static inline bool classof(const Value *V) {
773     return V->getValueID() == BlockAddressVal;
774   }
775 };
776
777 template <>
778 struct OperandTraits<BlockAddress> :
779   public FixedNumOperandTraits<BlockAddress, 2> {
780 };
781
782 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BlockAddress, Value)
783
784
785 //===----------------------------------------------------------------------===//
786 /// ConstantExpr - a constant value that is initialized with an expression using
787 /// other constant values.
788 ///
789 /// This class uses the standard Instruction opcodes to define the various
790 /// constant expressions.  The Opcode field for the ConstantExpr class is
791 /// maintained in the Value::SubclassData field.
792 class ConstantExpr : public Constant {
793   friend struct ConstantExprKeyType;
794
795 protected:
796   ConstantExpr(Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
797     : Constant(ty, ConstantExprVal, Ops, NumOps) {
798     // Operation type (an Instruction opcode) is stored as the SubclassData.
799     setValueSubclassData(Opcode);
800   }
801
802 public:
803   // Static methods to construct a ConstantExpr of different kinds.  Note that
804   // these methods may return a object that is not an instance of the
805   // ConstantExpr class, because they will attempt to fold the constant
806   // expression into something simpler if possible.
807
808   /// getAlignOf constant expr - computes the alignment of a type in a target
809   /// independent way (Note: the return type is an i64).
810   static Constant *getAlignOf(Type *Ty);
811
812   /// getSizeOf constant expr - computes the (alloc) size of a type (in
813   /// address-units, not bits) in a target independent way (Note: the return
814   /// type is an i64).
815   ///
816   static Constant *getSizeOf(Type *Ty);
817
818   /// getOffsetOf constant expr - computes the offset of a struct field in a
819   /// target independent way (Note: the return type is an i64).
820   ///
821   static Constant *getOffsetOf(StructType *STy, unsigned FieldNo);
822
823   /// getOffsetOf constant expr - This is a generalized form of getOffsetOf,
824   /// which supports any aggregate type, and any Constant index.
825   ///
826   static Constant *getOffsetOf(Type *Ty, Constant *FieldNo);
827
828   static Constant *getNeg(Constant *C, bool HasNUW = false, bool HasNSW =false);
829   static Constant *getFNeg(Constant *C);
830   static Constant *getNot(Constant *C);
831   static Constant *getAdd(Constant *C1, Constant *C2,
832                           bool HasNUW = false, bool HasNSW = false);
833   static Constant *getFAdd(Constant *C1, Constant *C2);
834   static Constant *getSub(Constant *C1, Constant *C2,
835                           bool HasNUW = false, bool HasNSW = false);
836   static Constant *getFSub(Constant *C1, Constant *C2);
837   static Constant *getMul(Constant *C1, Constant *C2,
838                           bool HasNUW = false, bool HasNSW = false);
839   static Constant *getFMul(Constant *C1, Constant *C2);
840   static Constant *getUDiv(Constant *C1, Constant *C2, bool isExact = false);
841   static Constant *getSDiv(Constant *C1, Constant *C2, bool isExact = false);
842   static Constant *getFDiv(Constant *C1, Constant *C2);
843   static Constant *getURem(Constant *C1, Constant *C2);
844   static Constant *getSRem(Constant *C1, Constant *C2);
845   static Constant *getFRem(Constant *C1, Constant *C2);
846   static Constant *getAnd(Constant *C1, Constant *C2);
847   static Constant *getOr(Constant *C1, Constant *C2);
848   static Constant *getXor(Constant *C1, Constant *C2);
849   static Constant *getShl(Constant *C1, Constant *C2,
850                           bool HasNUW = false, bool HasNSW = false);
851   static Constant *getLShr(Constant *C1, Constant *C2, bool isExact = false);
852   static Constant *getAShr(Constant *C1, Constant *C2, bool isExact = false);
853   static Constant *getTrunc   (Constant *C, Type *Ty);
854   static Constant *getSExt    (Constant *C, Type *Ty);
855   static Constant *getZExt    (Constant *C, Type *Ty);
856   static Constant *getFPTrunc (Constant *C, Type *Ty);
857   static Constant *getFPExtend(Constant *C, Type *Ty);
858   static Constant *getUIToFP  (Constant *C, Type *Ty);
859   static Constant *getSIToFP  (Constant *C, Type *Ty);
860   static Constant *getFPToUI  (Constant *C, Type *Ty);
861   static Constant *getFPToSI  (Constant *C, Type *Ty);
862   static Constant *getPtrToInt(Constant *C, Type *Ty);
863   static Constant *getIntToPtr(Constant *C, Type *Ty);
864   static Constant *getBitCast (Constant *C, Type *Ty);
865   static Constant *getAddrSpaceCast(Constant *C, Type *Ty);
866
867   static Constant *getNSWNeg(Constant *C) { return getNeg(C, false, true); }
868   static Constant *getNUWNeg(Constant *C) { return getNeg(C, true, false); }
869   static Constant *getNSWAdd(Constant *C1, Constant *C2) {
870     return getAdd(C1, C2, false, true);
871   }
872   static Constant *getNUWAdd(Constant *C1, Constant *C2) {
873     return getAdd(C1, C2, true, false);
874   }
875   static Constant *getNSWSub(Constant *C1, Constant *C2) {
876     return getSub(C1, C2, false, true);
877   }
878   static Constant *getNUWSub(Constant *C1, Constant *C2) {
879     return getSub(C1, C2, true, false);
880   }
881   static Constant *getNSWMul(Constant *C1, Constant *C2) {
882     return getMul(C1, C2, false, true);
883   }
884   static Constant *getNUWMul(Constant *C1, Constant *C2) {
885     return getMul(C1, C2, true, false);
886   }
887   static Constant *getNSWShl(Constant *C1, Constant *C2) {
888     return getShl(C1, C2, false, true);
889   }
890   static Constant *getNUWShl(Constant *C1, Constant *C2) {
891     return getShl(C1, C2, true, false);
892   }
893   static Constant *getExactSDiv(Constant *C1, Constant *C2) {
894     return getSDiv(C1, C2, true);
895   }
896   static Constant *getExactUDiv(Constant *C1, Constant *C2) {
897     return getUDiv(C1, C2, true);
898   }
899   static Constant *getExactAShr(Constant *C1, Constant *C2) {
900     return getAShr(C1, C2, true);
901   }
902   static Constant *getExactLShr(Constant *C1, Constant *C2) {
903     return getLShr(C1, C2, true);
904   }
905
906   /// getBinOpIdentity - Return the identity for the given binary operation,
907   /// i.e. a constant C such that X op C = X and C op X = X for every X.  It
908   /// returns null if the operator doesn't have an identity.
909   static Constant *getBinOpIdentity(unsigned Opcode, Type *Ty);
910
911   /// getBinOpAbsorber - Return the absorbing element for the given binary
912   /// operation, i.e. a constant C such that X op C = C and C op X = C for
913   /// every X.  For example, this returns zero for integer multiplication.
914   /// It returns null if the operator doesn't have an absorbing element.
915   static Constant *getBinOpAbsorber(unsigned Opcode, Type *Ty);
916
917   /// Transparently provide more efficient getOperand methods.
918   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
919
920   // @brief Convenience function for getting one of the casting operations
921   // using a CastOps opcode.
922   static Constant *getCast(
923     unsigned ops,  ///< The opcode for the conversion
924     Constant *C,   ///< The constant to be converted
925     Type *Ty ///< The type to which the constant is converted
926   );
927
928   // @brief Create a ZExt or BitCast cast constant expression
929   static Constant *getZExtOrBitCast(
930     Constant *C,   ///< The constant to zext or bitcast
931     Type *Ty ///< The type to zext or bitcast C to
932   );
933
934   // @brief Create a SExt or BitCast cast constant expression
935   static Constant *getSExtOrBitCast(
936     Constant *C,   ///< The constant to sext or bitcast
937     Type *Ty ///< The type to sext or bitcast C to
938   );
939
940   // @brief Create a Trunc or BitCast cast constant expression
941   static Constant *getTruncOrBitCast(
942     Constant *C,   ///< The constant to trunc or bitcast
943     Type *Ty ///< The type to trunc or bitcast C to
944   );
945
946   /// @brief Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant
947   /// expression.
948   static Constant *getPointerCast(
949     Constant *C,   ///< The pointer value to be casted (operand 0)
950     Type *Ty ///< The type to which cast should be made
951   );
952
953   /// @brief Create a BitCast or AddrSpaceCast for a pointer type depending on
954   /// the address space.
955   static Constant *getPointerBitCastOrAddrSpaceCast(
956     Constant *C,   ///< The constant to addrspacecast or bitcast
957     Type *Ty ///< The type to bitcast or addrspacecast C to
958   );
959
960   /// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts
961   static Constant *getIntegerCast(
962     Constant *C,    ///< The integer constant to be casted
963     Type *Ty, ///< The integer type to cast to
964     bool isSigned   ///< Whether C should be treated as signed or not
965   );
966
967   /// @brief Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
968   static Constant *getFPCast(
969     Constant *C,    ///< The integer constant to be casted
970     Type *Ty ///< The integer type to cast to
971   );
972
973   /// @brief Return true if this is a convert constant expression
974   bool isCast() const;
975
976   /// @brief Return true if this is a compare constant expression
977   bool isCompare() const;
978
979   /// @brief Return true if this is an insertvalue or extractvalue expression,
980   /// and the getIndices() method may be used.
981   bool hasIndices() const;
982
983   /// @brief Return true if this is a getelementptr expression and all
984   /// the index operands are compile-time known integers within the
985   /// corresponding notional static array extents. Note that this is
986   /// not equivalant to, a subset of, or a superset of the "inbounds"
987   /// property.
988   bool isGEPWithNoNotionalOverIndexing() const;
989
990   /// Select constant expr
991   ///
992   static Constant *getSelect(Constant *C, Constant *V1, Constant *V2);
993
994   /// get - Return a binary or shift operator constant expression,
995   /// folding if possible.
996   ///
997   static Constant *get(unsigned Opcode, Constant *C1, Constant *C2,
998                        unsigned Flags = 0);
999
1000   /// @brief Return an ICmp or FCmp comparison operator constant expression.
1001   static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2);
1002
1003   /// get* - Return some common constants without having to
1004   /// specify the full Instruction::OPCODE identifier.
1005   ///
1006   static Constant *getICmp(unsigned short pred, Constant *LHS, Constant *RHS);
1007   static Constant *getFCmp(unsigned short pred, Constant *LHS, Constant *RHS);
1008
1009   /// Getelementptr form.  Value* is only accepted for convenience;
1010   /// all elements must be Constant's.
1011   ///
1012   static Constant *getGetElementPtr(Constant *C,
1013                                     ArrayRef<Constant *> IdxList,
1014                                     bool InBounds = false) {
1015     return getGetElementPtr(C, makeArrayRef((Value * const *)IdxList.data(),
1016                                             IdxList.size()),
1017                             InBounds);
1018   }
1019   static Constant *getGetElementPtr(Constant *C,
1020                                     Constant *Idx,
1021                                     bool InBounds = false) {
1022     // This form of the function only exists to avoid ambiguous overload
1023     // warnings about whether to convert Idx to ArrayRef<Constant *> or
1024     // ArrayRef<Value *>.
1025     return getGetElementPtr(C, cast<Value>(Idx), InBounds);
1026   }
1027   static Constant *getGetElementPtr(Constant *C,
1028                                     ArrayRef<Value *> IdxList,
1029                                     bool InBounds = false);
1030
1031   /// Create an "inbounds" getelementptr. See the documentation for the
1032   /// "inbounds" flag in LangRef.html for details.
1033   static Constant *getInBoundsGetElementPtr(Constant *C,
1034                                             ArrayRef<Constant *> IdxList) {
1035     return getGetElementPtr(C, IdxList, true);
1036   }
1037   static Constant *getInBoundsGetElementPtr(Constant *C,
1038                                             Constant *Idx) {
1039     // This form of the function only exists to avoid ambiguous overload
1040     // warnings about whether to convert Idx to ArrayRef<Constant *> or
1041     // ArrayRef<Value *>.
1042     return getGetElementPtr(C, Idx, true);
1043   }
1044   static Constant *getInBoundsGetElementPtr(Constant *C,
1045                                             ArrayRef<Value *> IdxList) {
1046     return getGetElementPtr(C, IdxList, true);
1047   }
1048
1049   static Constant *getExtractElement(Constant *Vec, Constant *Idx);
1050   static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
1051   static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
1052   static Constant *getExtractValue(Constant *Agg, ArrayRef<unsigned> Idxs);
1053   static Constant *getInsertValue(Constant *Agg, Constant *Val,
1054                                   ArrayRef<unsigned> Idxs);
1055
1056   /// getOpcode - Return the opcode at the root of this constant expression
1057   unsigned getOpcode() const { return getSubclassDataFromValue(); }
1058
1059   /// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is
1060   /// not an ICMP or FCMP constant expression.
1061   unsigned getPredicate() const;
1062
1063   /// getIndices - Assert that this is an insertvalue or exactvalue
1064   /// expression and return the list of indices.
1065   ArrayRef<unsigned> getIndices() const;
1066
1067   /// getOpcodeName - Return a string representation for an opcode.
1068   const char *getOpcodeName() const;
1069
1070   /// getWithOperandReplaced - Return a constant expression identical to this
1071   /// one, but with the specified operand set to the specified value.
1072   Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
1073
1074   /// getWithOperands - This returns the current constant expression with the
1075   /// operands replaced with the specified values.  The specified array must
1076   /// have the same number of operands as our current one.
1077   Constant *getWithOperands(ArrayRef<Constant*> Ops) const {
1078     return getWithOperands(Ops, getType());
1079   }
1080
1081   /// getWithOperands - This returns the current constant expression with the
1082   /// operands replaced with the specified values and with the specified result
1083   /// type.  The specified array must have the same number of operands as our
1084   /// current one.
1085   Constant *getWithOperands(ArrayRef<Constant*> Ops, Type *Ty) const;
1086
1087   /// getAsInstruction - Returns an Instruction which implements the same operation
1088   /// as this ConstantExpr. The instruction is not linked to any basic block.
1089   ///
1090   /// A better approach to this could be to have a constructor for Instruction
1091   /// which would take a ConstantExpr parameter, but that would have spread
1092   /// implementation details of ConstantExpr outside of Constants.cpp, which
1093   /// would make it harder to remove ConstantExprs altogether.
1094   Instruction *getAsInstruction();
1095
1096   void destroyConstant() override;
1097   void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) override;
1098
1099   /// Methods for support type inquiry through isa, cast, and dyn_cast:
1100   static inline bool classof(const Value *V) {
1101     return V->getValueID() == ConstantExprVal;
1102   }
1103
1104 private:
1105   // Shadow Value::setValueSubclassData with a private forwarding method so that
1106   // subclasses cannot accidentally use it.
1107   void setValueSubclassData(unsigned short D) {
1108     Value::setValueSubclassData(D);
1109   }
1110
1111   /// \brief Check whether this can become its replacement.
1112   ///
1113   /// For use during \a replaceUsesOfWithOnConstant(), check whether we know
1114   /// how to turn this into \a Replacement, thereby reducing RAUW traffic.
1115   bool canBecomeReplacement(const Constant *Replacement) const;
1116 };
1117
1118 template <>
1119 struct OperandTraits<ConstantExpr> :
1120   public VariadicOperandTraits<ConstantExpr, 1> {
1121 };
1122
1123 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantExpr, Constant)
1124
1125 //===----------------------------------------------------------------------===//
1126 /// UndefValue - 'undef' values are things that do not have specified contents.
1127 /// These are used for a variety of purposes, including global variable
1128 /// initializers and operands to instructions.  'undef' values can occur with
1129 /// any first-class type.
1130 ///
1131 /// Undef values aren't exactly constants; if they have multiple uses, they
1132 /// can appear to have different bit patterns at each use. See
1133 /// LangRef.html#undefvalues for details.
1134 ///
1135 class UndefValue : public Constant {
1136   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
1137   UndefValue(const UndefValue &) LLVM_DELETED_FUNCTION;
1138 protected:
1139   explicit UndefValue(Type *T) : Constant(T, UndefValueVal, nullptr, 0) {}
1140 protected:
1141   // allocate space for exactly zero operands
1142   void *operator new(size_t s) {
1143     return User::operator new(s, 0);
1144   }
1145 public:
1146   /// get() - Static factory methods - Return an 'undef' object of the specified
1147   /// type.
1148   ///
1149   static UndefValue *get(Type *T);
1150
1151   /// getSequentialElement - If this Undef has array or vector type, return a
1152   /// undef with the right element type.
1153   UndefValue *getSequentialElement() const;
1154
1155   /// getStructElement - If this undef has struct type, return a undef with the
1156   /// right element type for the specified element.
1157   UndefValue *getStructElement(unsigned Elt) const;
1158
1159   /// getElementValue - Return an undef of the right value for the specified GEP
1160   /// index.
1161   UndefValue *getElementValue(Constant *C) const;
1162
1163   /// getElementValue - Return an undef of the right value for the specified GEP
1164   /// index.
1165   UndefValue *getElementValue(unsigned Idx) const;
1166
1167   void destroyConstant() override;
1168
1169   /// Methods for support type inquiry through isa, cast, and dyn_cast:
1170   static bool classof(const Value *V) {
1171     return V->getValueID() == UndefValueVal;
1172   }
1173 };
1174
1175 } // End llvm namespace
1176
1177 #endif