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