LLVM API Documentation

Constants.h
Go to the documentation of this file.
00001 //===-- llvm/Constants.h - Constant class subclass definitions --*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 /// @file
00011 /// This file contains the declarations for the subclasses of Constant,
00012 /// which represent the different flavors of constant values that live in LLVM.
00013 /// Note that Constants are immutable (once created they never change) and are
00014 /// fully shared by structural equivalence.  This means that two structurally
00015 /// equivalent constants will always have the same address.  Constant's are
00016 /// created on demand as needed and never deleted: thus clients don't have to
00017 /// worry about the lifetime of the objects.
00018 //
00019 //===----------------------------------------------------------------------===//
00020 
00021 #ifndef LLVM_IR_CONSTANTS_H
00022 #define LLVM_IR_CONSTANTS_H
00023 
00024 #include "llvm/ADT/APFloat.h"
00025 #include "llvm/ADT/APInt.h"
00026 #include "llvm/ADT/ArrayRef.h"
00027 #include "llvm/IR/Constant.h"
00028 #include "llvm/IR/DerivedTypes.h"
00029 #include "llvm/IR/OperandTraits.h"
00030 
00031 namespace llvm {
00032 
00033 class ArrayType;
00034 class IntegerType;
00035 class StructType;
00036 class PointerType;
00037 class VectorType;
00038 class SequentialType;
00039 
00040 struct ConstantExprKeyType;
00041 template <class ConstantClass> struct ConstantAggrKeyType;
00042 
00043 //===----------------------------------------------------------------------===//
00044 /// This is the shared class of boolean and integer constants. This class
00045 /// represents both boolean and integral constants.
00046 /// @brief Class for constant integers.
00047 class ConstantInt : public Constant {
00048   void anchor() override;
00049   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
00050   ConstantInt(const ConstantInt &) LLVM_DELETED_FUNCTION;
00051   ConstantInt(IntegerType *Ty, const APInt& V);
00052   APInt Val;
00053 protected:
00054   // allocate space for exactly zero operands
00055   void *operator new(size_t s) {
00056     return User::operator new(s, 0);
00057   }
00058 public:
00059   static ConstantInt *getTrue(LLVMContext &Context);
00060   static ConstantInt *getFalse(LLVMContext &Context);
00061   static Constant *getTrue(Type *Ty);
00062   static Constant *getFalse(Type *Ty);
00063 
00064   /// If Ty is a vector type, return a Constant with a splat of the given
00065   /// value. Otherwise return a ConstantInt for the given value.
00066   static Constant *get(Type *Ty, uint64_t V, bool isSigned = false);
00067 
00068   /// Return a ConstantInt with the specified integer value for the specified
00069   /// type. If the type is wider than 64 bits, the value will be zero-extended
00070   /// to fit the type, unless isSigned is true, in which case the value will
00071   /// be interpreted as a 64-bit signed integer and sign-extended to fit
00072   /// the type.
00073   /// @brief Get a ConstantInt for a specific value.
00074   static ConstantInt *get(IntegerType *Ty, uint64_t V,
00075                           bool isSigned = false);
00076 
00077   /// Return a ConstantInt with the specified value for the specified type. The
00078   /// value V will be canonicalized to a an unsigned APInt. Accessing it with
00079   /// either getSExtValue() or getZExtValue() will yield a correctly sized and
00080   /// signed value for the type Ty.
00081   /// @brief Get a ConstantInt for a specific signed value.
00082   static ConstantInt *getSigned(IntegerType *Ty, int64_t V);
00083   static Constant *getSigned(Type *Ty, int64_t V);
00084 
00085   /// Return a ConstantInt with the specified value and an implied Type. The
00086   /// type is the integer type that corresponds to the bit width of the value.
00087   static ConstantInt *get(LLVMContext &Context, const APInt &V);
00088 
00089   /// Return a ConstantInt constructed from the string strStart with the given
00090   /// radix.
00091   static ConstantInt *get(IntegerType *Ty, StringRef Str,
00092                           uint8_t radix);
00093 
00094   /// If Ty is a vector type, return a Constant with a splat of the given
00095   /// value. Otherwise return a ConstantInt for the given value.
00096   static Constant *get(Type* Ty, const APInt& V);
00097 
00098   /// Return the constant as an APInt value reference. This allows clients to
00099   /// obtain a copy of the value, with all its precision in tact.
00100   /// @brief Return the constant's value.
00101   inline const APInt &getValue() const {
00102     return Val;
00103   }
00104 
00105   /// getBitWidth - Return the bitwidth of this constant.
00106   unsigned getBitWidth() const { return Val.getBitWidth(); }
00107 
00108   /// Return the constant as a 64-bit unsigned integer value after it
00109   /// has been zero extended as appropriate for the type of this constant. Note
00110   /// that this method can assert if the value does not fit in 64 bits.
00111   /// @brief Return the zero extended value.
00112   inline uint64_t getZExtValue() const {
00113     return Val.getZExtValue();
00114   }
00115 
00116   /// Return the constant as a 64-bit integer value after it has been sign
00117   /// extended as appropriate for the type of this constant. Note that
00118   /// this method can assert if the value does not fit in 64 bits.
00119   /// @brief Return the sign extended value.
00120   inline int64_t getSExtValue() const {
00121     return Val.getSExtValue();
00122   }
00123 
00124   /// A helper method that can be used to determine if the constant contained
00125   /// within is equal to a constant.  This only works for very small values,
00126   /// because this is all that can be represented with all types.
00127   /// @brief Determine if this constant's value is same as an unsigned char.
00128   bool equalsInt(uint64_t V) const {
00129     return Val == V;
00130   }
00131 
00132   /// getType - Specialize the getType() method to always return an IntegerType,
00133   /// which reduces the amount of casting needed in parts of the compiler.
00134   ///
00135   inline IntegerType *getType() const {
00136     return cast<IntegerType>(Value::getType());
00137   }
00138 
00139   /// This static method returns true if the type Ty is big enough to
00140   /// represent the value V. This can be used to avoid having the get method
00141   /// assert when V is larger than Ty can represent. Note that there are two
00142   /// versions of this method, one for unsigned and one for signed integers.
00143   /// Although ConstantInt canonicalizes everything to an unsigned integer,
00144   /// the signed version avoids callers having to convert a signed quantity
00145   /// to the appropriate unsigned type before calling the method.
00146   /// @returns true if V is a valid value for type Ty
00147   /// @brief Determine if the value is in range for the given type.
00148   static bool isValueValidForType(Type *Ty, uint64_t V);
00149   static bool isValueValidForType(Type *Ty, int64_t V);
00150 
00151   bool isNegative() const { return Val.isNegative(); }
00152 
00153   /// This is just a convenience method to make client code smaller for a
00154   /// common code. It also correctly performs the comparison without the
00155   /// potential for an assertion from getZExtValue().
00156   bool isZero() const {
00157     return Val == 0;
00158   }
00159 
00160   /// This is just a convenience method to make client code smaller for a
00161   /// common case. It also correctly performs the comparison without the
00162   /// potential for an assertion from getZExtValue().
00163   /// @brief Determine if the value is one.
00164   bool isOne() const {
00165     return Val == 1;
00166   }
00167 
00168   /// This function will return true iff every bit in this constant is set
00169   /// to true.
00170   /// @returns true iff this constant's bits are all set to true.
00171   /// @brief Determine if the value is all ones.
00172   bool isMinusOne() const {
00173     return Val.isAllOnesValue();
00174   }
00175 
00176   /// This function will return true iff this constant represents the largest
00177   /// value that may be represented by the constant's type.
00178   /// @returns true iff this is the largest value that may be represented
00179   /// by this type.
00180   /// @brief Determine if the value is maximal.
00181   bool isMaxValue(bool isSigned) const {
00182     if (isSigned)
00183       return Val.isMaxSignedValue();
00184     else
00185       return Val.isMaxValue();
00186   }
00187 
00188   /// This function will return true iff this constant represents the smallest
00189   /// value that may be represented by this constant's type.
00190   /// @returns true if this is the smallest value that may be represented by
00191   /// this type.
00192   /// @brief Determine if the value is minimal.
00193   bool isMinValue(bool isSigned) const {
00194     if (isSigned)
00195       return Val.isMinSignedValue();
00196     else
00197       return Val.isMinValue();
00198   }
00199 
00200   /// This function will return true iff this constant represents a value with
00201   /// active bits bigger than 64 bits or a value greater than the given uint64_t
00202   /// value.
00203   /// @returns true iff this constant is greater or equal to the given number.
00204   /// @brief Determine if the value is greater or equal to the given number.
00205   bool uge(uint64_t Num) const {
00206     return Val.getActiveBits() > 64 || Val.getZExtValue() >= Num;
00207   }
00208 
00209   /// getLimitedValue - If the value is smaller than the specified limit,
00210   /// return it, otherwise return the limit value.  This causes the value
00211   /// to saturate to the limit.
00212   /// @returns the min of the value of the constant and the specified value
00213   /// @brief Get the constant's value with a saturation limit
00214   uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const {
00215     return Val.getLimitedValue(Limit);
00216   }
00217 
00218   /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
00219   static bool classof(const Value *V) {
00220     return V->getValueID() == ConstantIntVal;
00221   }
00222 };
00223 
00224 
00225 //===----------------------------------------------------------------------===//
00226 /// ConstantFP - Floating Point Values [float, double]
00227 ///
00228 class ConstantFP : public Constant {
00229   APFloat Val;
00230   void anchor() override;
00231   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
00232   ConstantFP(const ConstantFP &) LLVM_DELETED_FUNCTION;
00233   friend class LLVMContextImpl;
00234 protected:
00235   ConstantFP(Type *Ty, const APFloat& V);
00236 protected:
00237   // allocate space for exactly zero operands
00238   void *operator new(size_t s) {
00239     return User::operator new(s, 0);
00240   }
00241 public:
00242   /// Floating point negation must be implemented with f(x) = -0.0 - x. This
00243   /// method returns the negative zero constant for floating point or vector
00244   /// floating point types; for all other types, it returns the null value.
00245   static Constant *getZeroValueForNegation(Type *Ty);
00246 
00247   /// get() - This returns a ConstantFP, or a vector containing a splat of a
00248   /// ConstantFP, for the specified value in the specified type.  This should
00249   /// only be used for simple constant values like 2.0/1.0 etc, that are
00250   /// known-valid both as host double and as the target format.
00251   static Constant *get(Type* Ty, double V);
00252   static Constant *get(Type* Ty, StringRef Str);
00253   static ConstantFP *get(LLVMContext &Context, const APFloat &V);
00254   static Constant *getNegativeZero(Type *Ty);
00255   static Constant *getInfinity(Type *Ty, bool Negative = false);
00256 
00257   /// isValueValidForType - return true if Ty is big enough to represent V.
00258   static bool isValueValidForType(Type *Ty, const APFloat &V);
00259   inline const APFloat &getValueAPF() const { return Val; }
00260 
00261   /// isZero - Return true if the value is positive or negative zero.
00262   bool isZero() const { return Val.isZero(); }
00263 
00264   /// isNegative - Return true if the sign bit is set.
00265   bool isNegative() const { return Val.isNegative(); }
00266 
00267   /// isInfinity - Return true if the value is infinity
00268   bool isInfinity() const { return Val.isInfinity(); }
00269 
00270   /// isNaN - Return true if the value is a NaN.
00271   bool isNaN() const { return Val.isNaN(); }
00272 
00273   /// isExactlyValue - We don't rely on operator== working on double values, as
00274   /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
00275   /// As such, this method can be used to do an exact bit-for-bit comparison of
00276   /// two floating point values.  The version with a double operand is retained
00277   /// because it's so convenient to write isExactlyValue(2.0), but please use
00278   /// it only for simple constants.
00279   bool isExactlyValue(const APFloat &V) const;
00280 
00281   bool isExactlyValue(double V) const {
00282     bool ignored;
00283     APFloat FV(V);
00284     FV.convert(Val.getSemantics(), APFloat::rmNearestTiesToEven, &ignored);
00285     return isExactlyValue(FV);
00286   }
00287   /// Methods for support type inquiry through isa, cast, and dyn_cast:
00288   static bool classof(const Value *V) {
00289     return V->getValueID() == ConstantFPVal;
00290   }
00291 };
00292 
00293 //===----------------------------------------------------------------------===//
00294 /// ConstantAggregateZero - All zero aggregate value
00295 ///
00296 class ConstantAggregateZero : public Constant {
00297   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
00298   ConstantAggregateZero(const ConstantAggregateZero &) LLVM_DELETED_FUNCTION;
00299 protected:
00300   explicit ConstantAggregateZero(Type *ty)
00301     : Constant(ty, ConstantAggregateZeroVal, nullptr, 0) {}
00302 protected:
00303   // allocate space for exactly zero operands
00304   void *operator new(size_t s) {
00305     return User::operator new(s, 0);
00306   }
00307 public:
00308   static ConstantAggregateZero *get(Type *Ty);
00309 
00310   void destroyConstant() override;
00311 
00312   /// getSequentialElement - If this CAZ has array or vector type, return a zero
00313   /// with the right element type.
00314   Constant *getSequentialElement() const;
00315 
00316   /// getStructElement - If this CAZ has struct type, return a zero with the
00317   /// right element type for the specified element.
00318   Constant *getStructElement(unsigned Elt) const;
00319 
00320   /// getElementValue - Return a zero of the right value for the specified GEP
00321   /// index.
00322   Constant *getElementValue(Constant *C) const;
00323 
00324   /// getElementValue - Return a zero of the right value for the specified GEP
00325   /// index.
00326   Constant *getElementValue(unsigned Idx) const;
00327 
00328   /// Methods for support type inquiry through isa, cast, and dyn_cast:
00329   ///
00330   static bool classof(const Value *V) {
00331     return V->getValueID() == ConstantAggregateZeroVal;
00332   }
00333 };
00334 
00335 
00336 //===----------------------------------------------------------------------===//
00337 /// ConstantArray - Constant Array Declarations
00338 ///
00339 class ConstantArray : public Constant {
00340   friend struct ConstantAggrKeyType<ConstantArray>;
00341   ConstantArray(const ConstantArray &) LLVM_DELETED_FUNCTION;
00342 protected:
00343   ConstantArray(ArrayType *T, ArrayRef<Constant *> Val);
00344 public:
00345   // ConstantArray accessors
00346   static Constant *get(ArrayType *T, ArrayRef<Constant*> V);
00347 
00348 private:
00349   static Constant *getImpl(ArrayType *T, ArrayRef<Constant *> V);
00350 
00351 public:
00352   /// Transparently provide more efficient getOperand methods.
00353   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
00354 
00355   /// getType - Specialize the getType() method to always return an ArrayType,
00356   /// which reduces the amount of casting needed in parts of the compiler.
00357   ///
00358   inline ArrayType *getType() const {
00359     return cast<ArrayType>(Value::getType());
00360   }
00361 
00362   void destroyConstant() override;
00363   void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) override;
00364 
00365   /// Methods for support type inquiry through isa, cast, and dyn_cast:
00366   static bool classof(const Value *V) {
00367     return V->getValueID() == ConstantArrayVal;
00368   }
00369 };
00370 
00371 template <>
00372 struct OperandTraits<ConstantArray> :
00373   public VariadicOperandTraits<ConstantArray> {
00374 };
00375 
00376 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantArray, Constant)
00377 
00378 //===----------------------------------------------------------------------===//
00379 // ConstantStruct - Constant Struct Declarations
00380 //
00381 class ConstantStruct : public Constant {
00382   friend struct ConstantAggrKeyType<ConstantStruct>;
00383   ConstantStruct(const ConstantStruct &) LLVM_DELETED_FUNCTION;
00384 protected:
00385   ConstantStruct(StructType *T, ArrayRef<Constant *> Val);
00386 public:
00387   // ConstantStruct accessors
00388   static Constant *get(StructType *T, ArrayRef<Constant*> V);
00389   static Constant *get(StructType *T, ...) LLVM_END_WITH_NULL;
00390 
00391   /// getAnon - Return an anonymous struct that has the specified
00392   /// elements.  If the struct is possibly empty, then you must specify a
00393   /// context.
00394   static Constant *getAnon(ArrayRef<Constant*> V, bool Packed = false) {
00395     return get(getTypeForElements(V, Packed), V);
00396   }
00397   static Constant *getAnon(LLVMContext &Ctx,
00398                            ArrayRef<Constant*> V, bool Packed = false) {
00399     return get(getTypeForElements(Ctx, V, Packed), V);
00400   }
00401 
00402   /// getTypeForElements - Return an anonymous struct type to use for a constant
00403   /// with the specified set of elements.  The list must not be empty.
00404   static StructType *getTypeForElements(ArrayRef<Constant*> V,
00405                                         bool Packed = false);
00406   /// getTypeForElements - This version of the method allows an empty list.
00407   static StructType *getTypeForElements(LLVMContext &Ctx,
00408                                         ArrayRef<Constant*> V,
00409                                         bool Packed = false);
00410 
00411   /// Transparently provide more efficient getOperand methods.
00412   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
00413 
00414   /// getType() specialization - Reduce amount of casting...
00415   ///
00416   inline StructType *getType() const {
00417     return cast<StructType>(Value::getType());
00418   }
00419 
00420   void destroyConstant() override;
00421   void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) override;
00422 
00423   /// Methods for support type inquiry through isa, cast, and dyn_cast:
00424   static bool classof(const Value *V) {
00425     return V->getValueID() == ConstantStructVal;
00426   }
00427 };
00428 
00429 template <>
00430 struct OperandTraits<ConstantStruct> :
00431   public VariadicOperandTraits<ConstantStruct> {
00432 };
00433 
00434 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantStruct, Constant)
00435 
00436 
00437 //===----------------------------------------------------------------------===//
00438 /// ConstantVector - Constant Vector Declarations
00439 ///
00440 class ConstantVector : public Constant {
00441   friend struct ConstantAggrKeyType<ConstantVector>;
00442   ConstantVector(const ConstantVector &) LLVM_DELETED_FUNCTION;
00443 protected:
00444   ConstantVector(VectorType *T, ArrayRef<Constant *> Val);
00445 public:
00446   // ConstantVector accessors
00447   static Constant *get(ArrayRef<Constant*> V);
00448 
00449 private:
00450   static Constant *getImpl(ArrayRef<Constant *> V);
00451 
00452 public:
00453   /// getSplat - Return a ConstantVector with the specified constant in each
00454   /// element.
00455   static Constant *getSplat(unsigned NumElts, Constant *Elt);
00456 
00457   /// Transparently provide more efficient getOperand methods.
00458   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
00459 
00460   /// getType - Specialize the getType() method to always return a VectorType,
00461   /// which reduces the amount of casting needed in parts of the compiler.
00462   ///
00463   inline VectorType *getType() const {
00464     return cast<VectorType>(Value::getType());
00465   }
00466 
00467   /// getSplatValue - If this is a splat constant, meaning that all of the
00468   /// elements have the same value, return that value. Otherwise return NULL.
00469   Constant *getSplatValue() const;
00470 
00471   void destroyConstant() override;
00472   void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) override;
00473 
00474   /// Methods for support type inquiry through isa, cast, and dyn_cast:
00475   static bool classof(const Value *V) {
00476     return V->getValueID() == ConstantVectorVal;
00477   }
00478 };
00479 
00480 template <>
00481 struct OperandTraits<ConstantVector> :
00482   public VariadicOperandTraits<ConstantVector> {
00483 };
00484 
00485 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantVector, Constant)
00486 
00487 //===----------------------------------------------------------------------===//
00488 /// ConstantPointerNull - a constant pointer value that points to null
00489 ///
00490 class ConstantPointerNull : public Constant {
00491   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
00492   ConstantPointerNull(const ConstantPointerNull &) LLVM_DELETED_FUNCTION;
00493 protected:
00494   explicit ConstantPointerNull(PointerType *T)
00495     : Constant(T,
00496                Value::ConstantPointerNullVal, nullptr, 0) {}
00497 
00498 protected:
00499   // allocate space for exactly zero operands
00500   void *operator new(size_t s) {
00501     return User::operator new(s, 0);
00502   }
00503 public:
00504   /// get() - Static factory methods - Return objects of the specified value
00505   static ConstantPointerNull *get(PointerType *T);
00506 
00507   void destroyConstant() override;
00508 
00509   /// getType - Specialize the getType() method to always return an PointerType,
00510   /// which reduces the amount of casting needed in parts of the compiler.
00511   ///
00512   inline PointerType *getType() const {
00513     return cast<PointerType>(Value::getType());
00514   }
00515 
00516   /// Methods for support type inquiry through isa, cast, and dyn_cast:
00517   static bool classof(const Value *V) {
00518     return V->getValueID() == ConstantPointerNullVal;
00519   }
00520 };
00521 
00522 //===----------------------------------------------------------------------===//
00523 /// ConstantDataSequential - A vector or array constant whose element type is a
00524 /// simple 1/2/4/8-byte integer or float/double, and whose elements are just
00525 /// simple data values (i.e. ConstantInt/ConstantFP).  This Constant node has no
00526 /// operands because it stores all of the elements of the constant as densely
00527 /// packed data, instead of as Value*'s.
00528 ///
00529 /// This is the common base class of ConstantDataArray and ConstantDataVector.
00530 ///
00531 class ConstantDataSequential : public Constant {
00532   friend class LLVMContextImpl;
00533   /// DataElements - A pointer to the bytes underlying this constant (which is
00534   /// owned by the uniquing StringMap).
00535   const char *DataElements;
00536 
00537   /// Next - This forms a link list of ConstantDataSequential nodes that have
00538   /// the same value but different type.  For example, 0,0,0,1 could be a 4
00539   /// element array of i8, or a 1-element array of i32.  They'll both end up in
00540   /// the same StringMap bucket, linked up.
00541   ConstantDataSequential *Next;
00542   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
00543   ConstantDataSequential(const ConstantDataSequential &) LLVM_DELETED_FUNCTION;
00544 protected:
00545   explicit ConstantDataSequential(Type *ty, ValueTy VT, const char *Data)
00546     : Constant(ty, VT, nullptr, 0), DataElements(Data), Next(nullptr) {}
00547   ~ConstantDataSequential() { delete Next; }
00548 
00549   static Constant *getImpl(StringRef Bytes, Type *Ty);
00550 
00551 protected:
00552   // allocate space for exactly zero operands.
00553   void *operator new(size_t s) {
00554     return User::operator new(s, 0);
00555   }
00556 public:
00557 
00558   /// isElementTypeCompatible - Return true if a ConstantDataSequential can be
00559   /// formed with a vector or array of the specified element type.
00560   /// ConstantDataArray only works with normal float and int types that are
00561   /// stored densely in memory, not with things like i42 or x86_f80.
00562   static bool isElementTypeCompatible(const Type *Ty);
00563 
00564   /// getElementAsInteger - If this is a sequential container of integers (of
00565   /// any size), return the specified element in the low bits of a uint64_t.
00566   uint64_t getElementAsInteger(unsigned i) const;
00567 
00568   /// getElementAsAPFloat - If this is a sequential container of floating point
00569   /// type, return the specified element as an APFloat.
00570   APFloat getElementAsAPFloat(unsigned i) const;
00571 
00572   /// getElementAsFloat - If this is an sequential container of floats, return
00573   /// the specified element as a float.
00574   float getElementAsFloat(unsigned i) const;
00575 
00576   /// getElementAsDouble - If this is an sequential container of doubles, return
00577   /// the specified element as a double.
00578   double getElementAsDouble(unsigned i) const;
00579 
00580   /// getElementAsConstant - Return a Constant for a specified index's element.
00581   /// Note that this has to compute a new constant to return, so it isn't as
00582   /// efficient as getElementAsInteger/Float/Double.
00583   Constant *getElementAsConstant(unsigned i) const;
00584 
00585   /// getType - Specialize the getType() method to always return a
00586   /// SequentialType, which reduces the amount of casting needed in parts of the
00587   /// compiler.
00588   inline SequentialType *getType() const {
00589     return cast<SequentialType>(Value::getType());
00590   }
00591 
00592   /// getElementType - Return the element type of the array/vector.
00593   Type *getElementType() const;
00594 
00595   /// getNumElements - Return the number of elements in the array or vector.
00596   unsigned getNumElements() const;
00597 
00598   /// getElementByteSize - Return the size (in bytes) of each element in the
00599   /// array/vector.  The size of the elements is known to be a multiple of one
00600   /// byte.
00601   uint64_t getElementByteSize() const;
00602 
00603 
00604   /// isString - This method returns true if this is an array of i8.
00605   bool isString() const;
00606 
00607   /// isCString - This method returns true if the array "isString", ends with a
00608   /// nul byte, and does not contains any other nul bytes.
00609   bool isCString() const;
00610 
00611   /// getAsString - If this array is isString(), then this method returns the
00612   /// array as a StringRef.  Otherwise, it asserts out.
00613   ///
00614   StringRef getAsString() const {
00615     assert(isString() && "Not a string");
00616     return getRawDataValues();
00617   }
00618 
00619   /// getAsCString - If this array is isCString(), then this method returns the
00620   /// array (without the trailing null byte) as a StringRef. Otherwise, it
00621   /// asserts out.
00622   ///
00623   StringRef getAsCString() const {
00624     assert(isCString() && "Isn't a C string");
00625     StringRef Str = getAsString();
00626     return Str.substr(0, Str.size()-1);
00627   }
00628 
00629   /// getRawDataValues - Return the raw, underlying, bytes of this data.  Note
00630   /// that this is an extremely tricky thing to work with, as it exposes the
00631   /// host endianness of the data elements.
00632   StringRef getRawDataValues() const;
00633 
00634   void destroyConstant() override;
00635 
00636   /// Methods for support type inquiry through isa, cast, and dyn_cast:
00637   ///
00638   static bool classof(const Value *V) {
00639     return V->getValueID() == ConstantDataArrayVal ||
00640            V->getValueID() == ConstantDataVectorVal;
00641   }
00642 private:
00643   const char *getElementPointer(unsigned Elt) const;
00644 };
00645 
00646 //===----------------------------------------------------------------------===//
00647 /// ConstantDataArray - An array constant whose element type is a simple
00648 /// 1/2/4/8-byte integer or float/double, and whose elements are just simple
00649 /// data values (i.e. ConstantInt/ConstantFP).  This Constant node has no
00650 /// operands because it stores all of the elements of the constant as densely
00651 /// packed data, instead of as Value*'s.
00652 class ConstantDataArray : public ConstantDataSequential {
00653   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
00654   ConstantDataArray(const ConstantDataArray &) LLVM_DELETED_FUNCTION;
00655   void anchor() override;
00656   friend class ConstantDataSequential;
00657   explicit ConstantDataArray(Type *ty, const char *Data)
00658     : ConstantDataSequential(ty, ConstantDataArrayVal, Data) {}
00659 protected:
00660   // allocate space for exactly zero operands.
00661   void *operator new(size_t s) {
00662     return User::operator new(s, 0);
00663   }
00664 public:
00665 
00666   /// get() constructors - Return a constant with array type with an element
00667   /// count and element type matching the ArrayRef passed in.  Note that this
00668   /// can return a ConstantAggregateZero object.
00669   static Constant *get(LLVMContext &Context, ArrayRef<uint8_t> Elts);
00670   static Constant *get(LLVMContext &Context, ArrayRef<uint16_t> Elts);
00671   static Constant *get(LLVMContext &Context, ArrayRef<uint32_t> Elts);
00672   static Constant *get(LLVMContext &Context, ArrayRef<uint64_t> Elts);
00673   static Constant *get(LLVMContext &Context, ArrayRef<float> Elts);
00674   static Constant *get(LLVMContext &Context, ArrayRef<double> Elts);
00675 
00676   /// getString - This method constructs a CDS and initializes it with a text
00677   /// string. The default behavior (AddNull==true) causes a null terminator to
00678   /// be placed at the end of the array (increasing the length of the string by
00679   /// one more than the StringRef would normally indicate.  Pass AddNull=false
00680   /// to disable this behavior.
00681   static Constant *getString(LLVMContext &Context, StringRef Initializer,
00682                              bool AddNull = true);
00683 
00684   /// getType - Specialize the getType() method to always return an ArrayType,
00685   /// which reduces the amount of casting needed in parts of the compiler.
00686   ///
00687   inline ArrayType *getType() const {
00688     return cast<ArrayType>(Value::getType());
00689   }
00690 
00691   /// Methods for support type inquiry through isa, cast, and dyn_cast:
00692   ///
00693   static bool classof(const Value *V) {
00694     return V->getValueID() == ConstantDataArrayVal;
00695   }
00696 };
00697 
00698 //===----------------------------------------------------------------------===//
00699 /// ConstantDataVector - A vector constant whose element type is a simple
00700 /// 1/2/4/8-byte integer or float/double, and whose elements are just simple
00701 /// data values (i.e. ConstantInt/ConstantFP).  This Constant node has no
00702 /// operands because it stores all of the elements of the constant as densely
00703 /// packed data, instead of as Value*'s.
00704 class ConstantDataVector : public ConstantDataSequential {
00705   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
00706   ConstantDataVector(const ConstantDataVector &) LLVM_DELETED_FUNCTION;
00707   void anchor() override;
00708   friend class ConstantDataSequential;
00709   explicit ConstantDataVector(Type *ty, const char *Data)
00710   : ConstantDataSequential(ty, ConstantDataVectorVal, Data) {}
00711 protected:
00712   // allocate space for exactly zero operands.
00713   void *operator new(size_t s) {
00714     return User::operator new(s, 0);
00715   }
00716 public:
00717 
00718   /// get() constructors - Return a constant with vector type with an element
00719   /// count and element type matching the ArrayRef passed in.  Note that this
00720   /// can return a ConstantAggregateZero object.
00721   static Constant *get(LLVMContext &Context, ArrayRef<uint8_t> Elts);
00722   static Constant *get(LLVMContext &Context, ArrayRef<uint16_t> Elts);
00723   static Constant *get(LLVMContext &Context, ArrayRef<uint32_t> Elts);
00724   static Constant *get(LLVMContext &Context, ArrayRef<uint64_t> Elts);
00725   static Constant *get(LLVMContext &Context, ArrayRef<float> Elts);
00726   static Constant *get(LLVMContext &Context, ArrayRef<double> Elts);
00727 
00728   /// getSplat - Return a ConstantVector with the specified constant in each
00729   /// element.  The specified constant has to be a of a compatible type (i8/i16/
00730   /// i32/i64/float/double) and must be a ConstantFP or ConstantInt.
00731   static Constant *getSplat(unsigned NumElts, Constant *Elt);
00732 
00733   /// getSplatValue - If this is a splat constant, meaning that all of the
00734   /// elements have the same value, return that value. Otherwise return NULL.
00735   Constant *getSplatValue() const;
00736 
00737   /// getType - Specialize the getType() method to always return a VectorType,
00738   /// which reduces the amount of casting needed in parts of the compiler.
00739   ///
00740   inline VectorType *getType() const {
00741     return cast<VectorType>(Value::getType());
00742   }
00743 
00744   /// Methods for support type inquiry through isa, cast, and dyn_cast:
00745   ///
00746   static bool classof(const Value *V) {
00747     return V->getValueID() == ConstantDataVectorVal;
00748   }
00749 };
00750 
00751 
00752 
00753 /// BlockAddress - The address of a basic block.
00754 ///
00755 class BlockAddress : public Constant {
00756   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
00757   void *operator new(size_t s) { return User::operator new(s, 2); }
00758   BlockAddress(Function *F, BasicBlock *BB);
00759 public:
00760   /// get - Return a BlockAddress for the specified function and basic block.
00761   static BlockAddress *get(Function *F, BasicBlock *BB);
00762 
00763   /// get - Return a BlockAddress for the specified basic block.  The basic
00764   /// block must be embedded into a function.
00765   static BlockAddress *get(BasicBlock *BB);
00766 
00767   /// \brief Lookup an existing \c BlockAddress constant for the given
00768   /// BasicBlock.
00769   ///
00770   /// \returns 0 if \c !BB->hasAddressTaken(), otherwise the \c BlockAddress.
00771   static BlockAddress *lookup(const BasicBlock *BB);
00772 
00773   /// Transparently provide more efficient getOperand methods.
00774   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
00775 
00776   Function *getFunction() const { return (Function*)Op<0>().get(); }
00777   BasicBlock *getBasicBlock() const { return (BasicBlock*)Op<1>().get(); }
00778 
00779   void destroyConstant() override;
00780   void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) override;
00781 
00782   /// Methods for support type inquiry through isa, cast, and dyn_cast:
00783   static inline bool classof(const Value *V) {
00784     return V->getValueID() == BlockAddressVal;
00785   }
00786 };
00787 
00788 template <>
00789 struct OperandTraits<BlockAddress> :
00790   public FixedNumOperandTraits<BlockAddress, 2> {
00791 };
00792 
00793 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BlockAddress, Value)
00794 
00795 
00796 //===----------------------------------------------------------------------===//
00797 /// ConstantExpr - a constant value that is initialized with an expression using
00798 /// other constant values.
00799 ///
00800 /// This class uses the standard Instruction opcodes to define the various
00801 /// constant expressions.  The Opcode field for the ConstantExpr class is
00802 /// maintained in the Value::SubclassData field.
00803 class ConstantExpr : public Constant {
00804   friend struct ConstantExprKeyType;
00805 
00806 protected:
00807   ConstantExpr(Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
00808     : Constant(ty, ConstantExprVal, Ops, NumOps) {
00809     // Operation type (an Instruction opcode) is stored as the SubclassData.
00810     setValueSubclassData(Opcode);
00811   }
00812 
00813 public:
00814   // Static methods to construct a ConstantExpr of different kinds.  Note that
00815   // these methods may return a object that is not an instance of the
00816   // ConstantExpr class, because they will attempt to fold the constant
00817   // expression into something simpler if possible.
00818 
00819   /// getAlignOf constant expr - computes the alignment of a type in a target
00820   /// independent way (Note: the return type is an i64).
00821   static Constant *getAlignOf(Type *Ty);
00822 
00823   /// getSizeOf constant expr - computes the (alloc) size of a type (in
00824   /// address-units, not bits) in a target independent way (Note: the return
00825   /// type is an i64).
00826   ///
00827   static Constant *getSizeOf(Type *Ty);
00828 
00829   /// getOffsetOf constant expr - computes the offset of a struct field in a
00830   /// target independent way (Note: the return type is an i64).
00831   ///
00832   static Constant *getOffsetOf(StructType *STy, unsigned FieldNo);
00833 
00834   /// getOffsetOf constant expr - This is a generalized form of getOffsetOf,
00835   /// which supports any aggregate type, and any Constant index.
00836   ///
00837   static Constant *getOffsetOf(Type *Ty, Constant *FieldNo);
00838 
00839   static Constant *getNeg(Constant *C, bool HasNUW = false, bool HasNSW =false);
00840   static Constant *getFNeg(Constant *C);
00841   static Constant *getNot(Constant *C);
00842   static Constant *getAdd(Constant *C1, Constant *C2,
00843                           bool HasNUW = false, bool HasNSW = false);
00844   static Constant *getFAdd(Constant *C1, Constant *C2);
00845   static Constant *getSub(Constant *C1, Constant *C2,
00846                           bool HasNUW = false, bool HasNSW = false);
00847   static Constant *getFSub(Constant *C1, Constant *C2);
00848   static Constant *getMul(Constant *C1, Constant *C2,
00849                           bool HasNUW = false, bool HasNSW = false);
00850   static Constant *getFMul(Constant *C1, Constant *C2);
00851   static Constant *getUDiv(Constant *C1, Constant *C2, bool isExact = false);
00852   static Constant *getSDiv(Constant *C1, Constant *C2, bool isExact = false);
00853   static Constant *getFDiv(Constant *C1, Constant *C2);
00854   static Constant *getURem(Constant *C1, Constant *C2);
00855   static Constant *getSRem(Constant *C1, Constant *C2);
00856   static Constant *getFRem(Constant *C1, Constant *C2);
00857   static Constant *getAnd(Constant *C1, Constant *C2);
00858   static Constant *getOr(Constant *C1, Constant *C2);
00859   static Constant *getXor(Constant *C1, Constant *C2);
00860   static Constant *getShl(Constant *C1, Constant *C2,
00861                           bool HasNUW = false, bool HasNSW = false);
00862   static Constant *getLShr(Constant *C1, Constant *C2, bool isExact = false);
00863   static Constant *getAShr(Constant *C1, Constant *C2, bool isExact = false);
00864   static Constant *getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced = false);
00865   static Constant *getSExt(Constant *C, Type *Ty, bool OnlyIfReduced = false);
00866   static Constant *getZExt(Constant *C, Type *Ty, bool OnlyIfReduced = false);
00867   static Constant *getFPTrunc(Constant *C, Type *Ty,
00868                               bool OnlyIfReduced = false);
00869   static Constant *getFPExtend(Constant *C, Type *Ty,
00870                                bool OnlyIfReduced = false);
00871   static Constant *getUIToFP(Constant *C, Type *Ty, bool OnlyIfReduced = false);
00872   static Constant *getSIToFP(Constant *C, Type *Ty, bool OnlyIfReduced = false);
00873   static Constant *getFPToUI(Constant *C, Type *Ty, bool OnlyIfReduced = false);
00874   static Constant *getFPToSI(Constant *C, Type *Ty, bool OnlyIfReduced = false);
00875   static Constant *getPtrToInt(Constant *C, Type *Ty,
00876                                bool OnlyIfReduced = false);
00877   static Constant *getIntToPtr(Constant *C, Type *Ty,
00878                                bool OnlyIfReduced = false);
00879   static Constant *getBitCast(Constant *C, Type *Ty,
00880                               bool OnlyIfReduced = false);
00881   static Constant *getAddrSpaceCast(Constant *C, Type *Ty,
00882                                     bool OnlyIfReduced = false);
00883 
00884   static Constant *getNSWNeg(Constant *C) { return getNeg(C, false, true); }
00885   static Constant *getNUWNeg(Constant *C) { return getNeg(C, true, false); }
00886   static Constant *getNSWAdd(Constant *C1, Constant *C2) {
00887     return getAdd(C1, C2, false, true);
00888   }
00889   static Constant *getNUWAdd(Constant *C1, Constant *C2) {
00890     return getAdd(C1, C2, true, false);
00891   }
00892   static Constant *getNSWSub(Constant *C1, Constant *C2) {
00893     return getSub(C1, C2, false, true);
00894   }
00895   static Constant *getNUWSub(Constant *C1, Constant *C2) {
00896     return getSub(C1, C2, true, false);
00897   }
00898   static Constant *getNSWMul(Constant *C1, Constant *C2) {
00899     return getMul(C1, C2, false, true);
00900   }
00901   static Constant *getNUWMul(Constant *C1, Constant *C2) {
00902     return getMul(C1, C2, true, false);
00903   }
00904   static Constant *getNSWShl(Constant *C1, Constant *C2) {
00905     return getShl(C1, C2, false, true);
00906   }
00907   static Constant *getNUWShl(Constant *C1, Constant *C2) {
00908     return getShl(C1, C2, true, false);
00909   }
00910   static Constant *getExactSDiv(Constant *C1, Constant *C2) {
00911     return getSDiv(C1, C2, true);
00912   }
00913   static Constant *getExactUDiv(Constant *C1, Constant *C2) {
00914     return getUDiv(C1, C2, true);
00915   }
00916   static Constant *getExactAShr(Constant *C1, Constant *C2) {
00917     return getAShr(C1, C2, true);
00918   }
00919   static Constant *getExactLShr(Constant *C1, Constant *C2) {
00920     return getLShr(C1, C2, true);
00921   }
00922 
00923   /// getBinOpIdentity - Return the identity for the given binary operation,
00924   /// i.e. a constant C such that X op C = X and C op X = X for every X.  It
00925   /// returns null if the operator doesn't have an identity.
00926   static Constant *getBinOpIdentity(unsigned Opcode, Type *Ty);
00927 
00928   /// getBinOpAbsorber - Return the absorbing element for the given binary
00929   /// operation, i.e. a constant C such that X op C = C and C op X = C for
00930   /// every X.  For example, this returns zero for integer multiplication.
00931   /// It returns null if the operator doesn't have an absorbing element.
00932   static Constant *getBinOpAbsorber(unsigned Opcode, Type *Ty);
00933 
00934   /// Transparently provide more efficient getOperand methods.
00935   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
00936 
00937   /// \brief Convenience function for getting a Cast operation.
00938   ///
00939   /// \param ops The opcode for the conversion
00940   /// \param C  The constant to be converted
00941   /// \param Ty The type to which the constant is converted
00942   /// \param OnlyIfReduced see \a getWithOperands() docs.
00943   static Constant *getCast(unsigned ops, Constant *C, Type *Ty,
00944                            bool OnlyIfReduced = false);
00945 
00946   // @brief Create a ZExt or BitCast cast constant expression
00947   static Constant *getZExtOrBitCast(
00948     Constant *C,   ///< The constant to zext or bitcast
00949     Type *Ty ///< The type to zext or bitcast C to
00950   );
00951 
00952   // @brief Create a SExt or BitCast cast constant expression
00953   static Constant *getSExtOrBitCast(
00954     Constant *C,   ///< The constant to sext or bitcast
00955     Type *Ty ///< The type to sext or bitcast C to
00956   );
00957 
00958   // @brief Create a Trunc or BitCast cast constant expression
00959   static Constant *getTruncOrBitCast(
00960     Constant *C,   ///< The constant to trunc or bitcast
00961     Type *Ty ///< The type to trunc or bitcast C to
00962   );
00963 
00964   /// @brief Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant
00965   /// expression.
00966   static Constant *getPointerCast(
00967     Constant *C,   ///< The pointer value to be casted (operand 0)
00968     Type *Ty ///< The type to which cast should be made
00969   );
00970 
00971   /// @brief Create a BitCast or AddrSpaceCast for a pointer type depending on
00972   /// the address space.
00973   static Constant *getPointerBitCastOrAddrSpaceCast(
00974     Constant *C,   ///< The constant to addrspacecast or bitcast
00975     Type *Ty ///< The type to bitcast or addrspacecast C to
00976   );
00977 
00978   /// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts
00979   static Constant *getIntegerCast(
00980     Constant *C,    ///< The integer constant to be casted
00981     Type *Ty, ///< The integer type to cast to
00982     bool isSigned   ///< Whether C should be treated as signed or not
00983   );
00984 
00985   /// @brief Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
00986   static Constant *getFPCast(
00987     Constant *C,    ///< The integer constant to be casted
00988     Type *Ty ///< The integer type to cast to
00989   );
00990 
00991   /// @brief Return true if this is a convert constant expression
00992   bool isCast() const;
00993 
00994   /// @brief Return true if this is a compare constant expression
00995   bool isCompare() const;
00996 
00997   /// @brief Return true if this is an insertvalue or extractvalue expression,
00998   /// and the getIndices() method may be used.
00999   bool hasIndices() const;
01000 
01001   /// @brief Return true if this is a getelementptr expression and all
01002   /// the index operands are compile-time known integers within the
01003   /// corresponding notional static array extents. Note that this is
01004   /// not equivalant to, a subset of, or a superset of the "inbounds"
01005   /// property.
01006   bool isGEPWithNoNotionalOverIndexing() const;
01007 
01008   /// Select constant expr
01009   ///
01010   /// \param OnlyIfReducedTy see \a getWithOperands() docs.
01011   static Constant *getSelect(Constant *C, Constant *V1, Constant *V2,
01012                              Type *OnlyIfReducedTy = nullptr);
01013 
01014   /// get - Return a binary or shift operator constant expression,
01015   /// folding if possible.
01016   ///
01017   /// \param OnlyIfReducedTy see \a getWithOperands() docs.
01018   static Constant *get(unsigned Opcode, Constant *C1, Constant *C2,
01019                        unsigned Flags = 0, Type *OnlyIfReducedTy = nullptr);
01020 
01021   /// \brief Return an ICmp or FCmp comparison operator constant expression.
01022   ///
01023   /// \param OnlyIfReduced see \a getWithOperands() docs.
01024   static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2,
01025                               bool OnlyIfReduced = false);
01026 
01027   /// get* - Return some common constants without having to
01028   /// specify the full Instruction::OPCODE identifier.
01029   ///
01030   static Constant *getICmp(unsigned short pred, Constant *LHS, Constant *RHS,
01031                            bool OnlyIfReduced = false);
01032   static Constant *getFCmp(unsigned short pred, Constant *LHS, Constant *RHS,
01033                            bool OnlyIfReduced = false);
01034 
01035   /// Getelementptr form.  Value* is only accepted for convenience;
01036   /// all elements must be Constant's.
01037   ///
01038   /// \param OnlyIfReducedTy see \a getWithOperands() docs.
01039   static Constant *getGetElementPtr(Constant *C, ArrayRef<Constant *> IdxList,
01040                                     bool InBounds = false,
01041                                     Type *OnlyIfReducedTy = nullptr) {
01042     return getGetElementPtr(
01043         C, makeArrayRef((Value * const *)IdxList.data(), IdxList.size()),
01044         InBounds, OnlyIfReducedTy);
01045   }
01046   static Constant *getGetElementPtr(Constant *C, Constant *Idx,
01047                                     bool InBounds = false,
01048                                     Type *OnlyIfReducedTy = nullptr) {
01049     // This form of the function only exists to avoid ambiguous overload
01050     // warnings about whether to convert Idx to ArrayRef<Constant *> or
01051     // ArrayRef<Value *>.
01052     return getGetElementPtr(C, cast<Value>(Idx), InBounds, OnlyIfReducedTy);
01053   }
01054   static Constant *getGetElementPtr(Constant *C, ArrayRef<Value *> IdxList,
01055                                     bool InBounds = false,
01056                                     Type *OnlyIfReducedTy = nullptr);
01057 
01058   /// Create an "inbounds" getelementptr. See the documentation for the
01059   /// "inbounds" flag in LangRef.html for details.
01060   static Constant *getInBoundsGetElementPtr(Constant *C,
01061                                             ArrayRef<Constant *> IdxList) {
01062     return getGetElementPtr(C, IdxList, true);
01063   }
01064   static Constant *getInBoundsGetElementPtr(Constant *C,
01065                                             Constant *Idx) {
01066     // This form of the function only exists to avoid ambiguous overload
01067     // warnings about whether to convert Idx to ArrayRef<Constant *> or
01068     // ArrayRef<Value *>.
01069     return getGetElementPtr(C, Idx, true);
01070   }
01071   static Constant *getInBoundsGetElementPtr(Constant *C,
01072                                             ArrayRef<Value *> IdxList) {
01073     return getGetElementPtr(C, IdxList, true);
01074   }
01075 
01076   static Constant *getExtractElement(Constant *Vec, Constant *Idx,
01077                                      Type *OnlyIfReducedTy = nullptr);
01078   static Constant *getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx,
01079                                     Type *OnlyIfReducedTy = nullptr);
01080   static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask,
01081                                     Type *OnlyIfReducedTy = nullptr);
01082   static Constant *getExtractValue(Constant *Agg, ArrayRef<unsigned> Idxs,
01083                                    Type *OnlyIfReducedTy = nullptr);
01084   static Constant *getInsertValue(Constant *Agg, Constant *Val,
01085                                   ArrayRef<unsigned> Idxs,
01086                                   Type *OnlyIfReducedTy = nullptr);
01087 
01088   /// getOpcode - Return the opcode at the root of this constant expression
01089   unsigned getOpcode() const { return getSubclassDataFromValue(); }
01090 
01091   /// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is
01092   /// not an ICMP or FCMP constant expression.
01093   unsigned getPredicate() const;
01094 
01095   /// getIndices - Assert that this is an insertvalue or exactvalue
01096   /// expression and return the list of indices.
01097   ArrayRef<unsigned> getIndices() const;
01098 
01099   /// getOpcodeName - Return a string representation for an opcode.
01100   const char *getOpcodeName() const;
01101 
01102   /// getWithOperandReplaced - Return a constant expression identical to this
01103   /// one, but with the specified operand set to the specified value.
01104   Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
01105 
01106   /// getWithOperands - This returns the current constant expression with the
01107   /// operands replaced with the specified values.  The specified array must
01108   /// have the same number of operands as our current one.
01109   Constant *getWithOperands(ArrayRef<Constant*> Ops) const {
01110     return getWithOperands(Ops, getType());
01111   }
01112 
01113   /// \brief Get the current expression with the operands replaced.
01114   ///
01115   /// Return the current constant expression with the operands replaced with \c
01116   /// Ops and the type with \c Ty.  The new operands must have the same number
01117   /// as the current ones.
01118   ///
01119   /// If \c OnlyIfReduced is \c true, nullptr will be returned unless something
01120   /// gets constant-folded, the type changes, or the expression is otherwise
01121   /// canonicalized.  This parameter should almost always be \c false.
01122   Constant *getWithOperands(ArrayRef<Constant *> Ops, Type *Ty,
01123                             bool OnlyIfReduced = false) const;
01124 
01125   /// getAsInstruction - Returns an Instruction which implements the same operation
01126   /// as this ConstantExpr. The instruction is not linked to any basic block.
01127   ///
01128   /// A better approach to this could be to have a constructor for Instruction
01129   /// which would take a ConstantExpr parameter, but that would have spread
01130   /// implementation details of ConstantExpr outside of Constants.cpp, which
01131   /// would make it harder to remove ConstantExprs altogether.
01132   Instruction *getAsInstruction();
01133 
01134   void destroyConstant() override;
01135   void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) override;
01136 
01137   /// Methods for support type inquiry through isa, cast, and dyn_cast:
01138   static inline bool classof(const Value *V) {
01139     return V->getValueID() == ConstantExprVal;
01140   }
01141 
01142 private:
01143   // Shadow Value::setValueSubclassData with a private forwarding method so that
01144   // subclasses cannot accidentally use it.
01145   void setValueSubclassData(unsigned short D) {
01146     Value::setValueSubclassData(D);
01147   }
01148 };
01149 
01150 template <>
01151 struct OperandTraits<ConstantExpr> :
01152   public VariadicOperandTraits<ConstantExpr, 1> {
01153 };
01154 
01155 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantExpr, Constant)
01156 
01157 //===----------------------------------------------------------------------===//
01158 /// UndefValue - 'undef' values are things that do not have specified contents.
01159 /// These are used for a variety of purposes, including global variable
01160 /// initializers and operands to instructions.  'undef' values can occur with
01161 /// any first-class type.
01162 ///
01163 /// Undef values aren't exactly constants; if they have multiple uses, they
01164 /// can appear to have different bit patterns at each use. See
01165 /// LangRef.html#undefvalues for details.
01166 ///
01167 class UndefValue : public Constant {
01168   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
01169   UndefValue(const UndefValue &) LLVM_DELETED_FUNCTION;
01170 protected:
01171   explicit UndefValue(Type *T) : Constant(T, UndefValueVal, nullptr, 0) {}
01172 protected:
01173   // allocate space for exactly zero operands
01174   void *operator new(size_t s) {
01175     return User::operator new(s, 0);
01176   }
01177 public:
01178   /// get() - Static factory methods - Return an 'undef' object of the specified
01179   /// type.
01180   ///
01181   static UndefValue *get(Type *T);
01182 
01183   /// getSequentialElement - If this Undef has array or vector type, return a
01184   /// undef with the right element type.
01185   UndefValue *getSequentialElement() const;
01186 
01187   /// getStructElement - If this undef has struct type, return a undef with the
01188   /// right element type for the specified element.
01189   UndefValue *getStructElement(unsigned Elt) const;
01190 
01191   /// getElementValue - Return an undef of the right value for the specified GEP
01192   /// index.
01193   UndefValue *getElementValue(Constant *C) const;
01194 
01195   /// getElementValue - Return an undef of the right value for the specified GEP
01196   /// index.
01197   UndefValue *getElementValue(unsigned Idx) const;
01198 
01199   void destroyConstant() override;
01200 
01201   /// Methods for support type inquiry through isa, cast, and dyn_cast:
01202   static bool classof(const Value *V) {
01203     return V->getValueID() == UndefValueVal;
01204   }
01205 };
01206 
01207 } // End llvm namespace
01208 
01209 #endif