LLVM  mainline
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) = delete;
00050   ConstantInt(const ConstantInt &) = delete;
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) = delete;
00232   ConstantFP(const ConstantFP &) = delete;
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) = delete;
00298   ConstantAggregateZero(const ConstantAggregateZero &) = delete;
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   /// \brief Return the number of elements in the array, vector, or struct.
00329   unsigned getNumElements() const;
00330 
00331   /// Methods for support type inquiry through isa, cast, and dyn_cast:
00332   ///
00333   static bool classof(const Value *V) {
00334     return V->getValueID() == ConstantAggregateZeroVal;
00335   }
00336 };
00337 
00338 
00339 //===----------------------------------------------------------------------===//
00340 /// ConstantArray - Constant Array Declarations
00341 ///
00342 class ConstantArray : public Constant {
00343   friend struct ConstantAggrKeyType<ConstantArray>;
00344   ConstantArray(const ConstantArray &) = delete;
00345 protected:
00346   ConstantArray(ArrayType *T, ArrayRef<Constant *> Val);
00347 public:
00348   // ConstantArray accessors
00349   static Constant *get(ArrayType *T, ArrayRef<Constant*> V);
00350 
00351 private:
00352   static Constant *getImpl(ArrayType *T, ArrayRef<Constant *> V);
00353 
00354 public:
00355   /// Transparently provide more efficient getOperand methods.
00356   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
00357 
00358   /// getType - Specialize the getType() method to always return an ArrayType,
00359   /// which reduces the amount of casting needed in parts of the compiler.
00360   ///
00361   inline ArrayType *getType() const {
00362     return cast<ArrayType>(Value::getType());
00363   }
00364 
00365   void destroyConstant() override;
00366   void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) override;
00367 
00368   /// Methods for support type inquiry through isa, cast, and dyn_cast:
00369   static bool classof(const Value *V) {
00370     return V->getValueID() == ConstantArrayVal;
00371   }
00372 };
00373 
00374 template <>
00375 struct OperandTraits<ConstantArray> :
00376   public VariadicOperandTraits<ConstantArray> {
00377 };
00378 
00379 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantArray, Constant)
00380 
00381 //===----------------------------------------------------------------------===//
00382 // ConstantStruct - Constant Struct Declarations
00383 //
00384 class ConstantStruct : public Constant {
00385   friend struct ConstantAggrKeyType<ConstantStruct>;
00386   ConstantStruct(const ConstantStruct &) = delete;
00387 protected:
00388   ConstantStruct(StructType *T, ArrayRef<Constant *> Val);
00389 public:
00390   // ConstantStruct accessors
00391   static Constant *get(StructType *T, ArrayRef<Constant*> V);
00392   static Constant *get(StructType *T, ...) LLVM_END_WITH_NULL;
00393 
00394   /// getAnon - Return an anonymous struct that has the specified
00395   /// elements.  If the struct is possibly empty, then you must specify a
00396   /// context.
00397   static Constant *getAnon(ArrayRef<Constant*> V, bool Packed = false) {
00398     return get(getTypeForElements(V, Packed), V);
00399   }
00400   static Constant *getAnon(LLVMContext &Ctx,
00401                            ArrayRef<Constant*> V, bool Packed = false) {
00402     return get(getTypeForElements(Ctx, V, Packed), V);
00403   }
00404 
00405   /// getTypeForElements - Return an anonymous struct type to use for a constant
00406   /// with the specified set of elements.  The list must not be empty.
00407   static StructType *getTypeForElements(ArrayRef<Constant*> V,
00408                                         bool Packed = false);
00409   /// getTypeForElements - This version of the method allows an empty list.
00410   static StructType *getTypeForElements(LLVMContext &Ctx,
00411                                         ArrayRef<Constant*> V,
00412                                         bool Packed = false);
00413 
00414   /// Transparently provide more efficient getOperand methods.
00415   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
00416 
00417   /// getType() specialization - Reduce amount of casting...
00418   ///
00419   inline StructType *getType() const {
00420     return cast<StructType>(Value::getType());
00421   }
00422 
00423   void destroyConstant() override;
00424   void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) override;
00425 
00426   /// Methods for support type inquiry through isa, cast, and dyn_cast:
00427   static bool classof(const Value *V) {
00428     return V->getValueID() == ConstantStructVal;
00429   }
00430 };
00431 
00432 template <>
00433 struct OperandTraits<ConstantStruct> :
00434   public VariadicOperandTraits<ConstantStruct> {
00435 };
00436 
00437 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantStruct, Constant)
00438 
00439 
00440 //===----------------------------------------------------------------------===//
00441 /// ConstantVector - Constant Vector Declarations
00442 ///
00443 class ConstantVector : public Constant {
00444   friend struct ConstantAggrKeyType<ConstantVector>;
00445   ConstantVector(const ConstantVector &) = delete;
00446 protected:
00447   ConstantVector(VectorType *T, ArrayRef<Constant *> Val);
00448 public:
00449   // ConstantVector accessors
00450   static Constant *get(ArrayRef<Constant*> V);
00451 
00452 private:
00453   static Constant *getImpl(ArrayRef<Constant *> V);
00454 
00455 public:
00456   /// getSplat - Return a ConstantVector with the specified constant in each
00457   /// element.
00458   static Constant *getSplat(unsigned NumElts, Constant *Elt);
00459 
00460   /// Transparently provide more efficient getOperand methods.
00461   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
00462 
00463   /// getType - Specialize the getType() method to always return a VectorType,
00464   /// which reduces the amount of casting needed in parts of the compiler.
00465   ///
00466   inline VectorType *getType() const {
00467     return cast<VectorType>(Value::getType());
00468   }
00469 
00470   /// getSplatValue - If this is a splat constant, meaning that all of the
00471   /// elements have the same value, return that value. Otherwise return NULL.
00472   Constant *getSplatValue() const;
00473 
00474   void destroyConstant() override;
00475   void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) override;
00476 
00477   /// Methods for support type inquiry through isa, cast, and dyn_cast:
00478   static bool classof(const Value *V) {
00479     return V->getValueID() == ConstantVectorVal;
00480   }
00481 };
00482 
00483 template <>
00484 struct OperandTraits<ConstantVector> :
00485   public VariadicOperandTraits<ConstantVector> {
00486 };
00487 
00488 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantVector, Constant)
00489 
00490 //===----------------------------------------------------------------------===//
00491 /// ConstantPointerNull - a constant pointer value that points to null
00492 ///
00493 class ConstantPointerNull : public Constant {
00494   void *operator new(size_t, unsigned) = delete;
00495   ConstantPointerNull(const ConstantPointerNull &) = delete;
00496 protected:
00497   explicit ConstantPointerNull(PointerType *T)
00498     : Constant(T,
00499                Value::ConstantPointerNullVal, nullptr, 0) {}
00500 
00501 protected:
00502   // allocate space for exactly zero operands
00503   void *operator new(size_t s) {
00504     return User::operator new(s, 0);
00505   }
00506 public:
00507   /// get() - Static factory methods - Return objects of the specified value
00508   static ConstantPointerNull *get(PointerType *T);
00509 
00510   void destroyConstant() override;
00511 
00512   /// getType - Specialize the getType() method to always return an PointerType,
00513   /// which reduces the amount of casting needed in parts of the compiler.
00514   ///
00515   inline PointerType *getType() const {
00516     return cast<PointerType>(Value::getType());
00517   }
00518 
00519   /// Methods for support type inquiry through isa, cast, and dyn_cast:
00520   static bool classof(const Value *V) {
00521     return V->getValueID() == ConstantPointerNullVal;
00522   }
00523 };
00524 
00525 //===----------------------------------------------------------------------===//
00526 /// ConstantDataSequential - A vector or array constant whose element type is a
00527 /// simple 1/2/4/8-byte integer or float/double, and whose elements are just
00528 /// simple data values (i.e. ConstantInt/ConstantFP).  This Constant node has no
00529 /// operands because it stores all of the elements of the constant as densely
00530 /// packed data, instead of as Value*'s.
00531 ///
00532 /// This is the common base class of ConstantDataArray and ConstantDataVector.
00533 ///
00534 class ConstantDataSequential : public Constant {
00535   friend class LLVMContextImpl;
00536   /// DataElements - A pointer to the bytes underlying this constant (which is
00537   /// owned by the uniquing StringMap).
00538   const char *DataElements;
00539 
00540   /// Next - This forms a link list of ConstantDataSequential nodes that have
00541   /// the same value but different type.  For example, 0,0,0,1 could be a 4
00542   /// element array of i8, or a 1-element array of i32.  They'll both end up in
00543   /// the same StringMap bucket, linked up.
00544   ConstantDataSequential *Next;
00545   void *operator new(size_t, unsigned) = delete;
00546   ConstantDataSequential(const ConstantDataSequential &) = delete;
00547 protected:
00548   explicit ConstantDataSequential(Type *ty, ValueTy VT, const char *Data)
00549     : Constant(ty, VT, nullptr, 0), DataElements(Data), Next(nullptr) {}
00550   ~ConstantDataSequential() { delete Next; }
00551 
00552   static Constant *getImpl(StringRef Bytes, Type *Ty);
00553 
00554 protected:
00555   // allocate space for exactly zero operands.
00556   void *operator new(size_t s) {
00557     return User::operator new(s, 0);
00558   }
00559 public:
00560 
00561   /// isElementTypeCompatible - Return true if a ConstantDataSequential can be
00562   /// formed with a vector or array of the specified element type.
00563   /// ConstantDataArray only works with normal float and int types that are
00564   /// stored densely in memory, not with things like i42 or x86_f80.
00565   static bool isElementTypeCompatible(const Type *Ty);
00566 
00567   /// getElementAsInteger - If this is a sequential container of integers (of
00568   /// any size), return the specified element in the low bits of a uint64_t.
00569   uint64_t getElementAsInteger(unsigned i) const;
00570 
00571   /// getElementAsAPFloat - If this is a sequential container of floating point
00572   /// type, return the specified element as an APFloat.
00573   APFloat getElementAsAPFloat(unsigned i) const;
00574 
00575   /// getElementAsFloat - If this is an sequential container of floats, return
00576   /// the specified element as a float.
00577   float getElementAsFloat(unsigned i) const;
00578 
00579   /// getElementAsDouble - If this is an sequential container of doubles, return
00580   /// the specified element as a double.
00581   double getElementAsDouble(unsigned i) const;
00582 
00583   /// getElementAsConstant - Return a Constant for a specified index's element.
00584   /// Note that this has to compute a new constant to return, so it isn't as
00585   /// efficient as getElementAsInteger/Float/Double.
00586   Constant *getElementAsConstant(unsigned i) const;
00587 
00588   /// getType - Specialize the getType() method to always return a
00589   /// SequentialType, which reduces the amount of casting needed in parts of the
00590   /// compiler.
00591   inline SequentialType *getType() const {
00592     return cast<SequentialType>(Value::getType());
00593   }
00594 
00595   /// getElementType - Return the element type of the array/vector.
00596   Type *getElementType() const;
00597 
00598   /// getNumElements - Return the number of elements in the array or vector.
00599   unsigned getNumElements() const;
00600 
00601   /// getElementByteSize - Return the size (in bytes) of each element in the
00602   /// array/vector.  The size of the elements is known to be a multiple of one
00603   /// byte.
00604   uint64_t getElementByteSize() const;
00605 
00606 
00607   /// isString - This method returns true if this is an array of i8.
00608   bool isString() const;
00609 
00610   /// isCString - This method returns true if the array "isString", ends with a
00611   /// nul byte, and does not contains any other nul bytes.
00612   bool isCString() const;
00613 
00614   /// getAsString - If this array is isString(), then this method returns the
00615   /// array as a StringRef.  Otherwise, it asserts out.
00616   ///
00617   StringRef getAsString() const {
00618     assert(isString() && "Not a string");
00619     return getRawDataValues();
00620   }
00621 
00622   /// getAsCString - If this array is isCString(), then this method returns the
00623   /// array (without the trailing null byte) as a StringRef. Otherwise, it
00624   /// asserts out.
00625   ///
00626   StringRef getAsCString() const {
00627     assert(isCString() && "Isn't a C string");
00628     StringRef Str = getAsString();
00629     return Str.substr(0, Str.size()-1);
00630   }
00631 
00632   /// getRawDataValues - Return the raw, underlying, bytes of this data.  Note
00633   /// that this is an extremely tricky thing to work with, as it exposes the
00634   /// host endianness of the data elements.
00635   StringRef getRawDataValues() const;
00636 
00637   void destroyConstant() override;
00638 
00639   /// Methods for support type inquiry through isa, cast, and dyn_cast:
00640   ///
00641   static bool classof(const Value *V) {
00642     return V->getValueID() == ConstantDataArrayVal ||
00643            V->getValueID() == ConstantDataVectorVal;
00644   }
00645 private:
00646   const char *getElementPointer(unsigned Elt) const;
00647 };
00648 
00649 //===----------------------------------------------------------------------===//
00650 /// ConstantDataArray - An array constant whose element type is a simple
00651 /// 1/2/4/8-byte integer or float/double, and whose elements are just simple
00652 /// data values (i.e. ConstantInt/ConstantFP).  This Constant node has no
00653 /// operands because it stores all of the elements of the constant as densely
00654 /// packed data, instead of as Value*'s.
00655 class ConstantDataArray : public ConstantDataSequential {
00656   void *operator new(size_t, unsigned) = delete;
00657   ConstantDataArray(const ConstantDataArray &) = delete;
00658   void anchor() override;
00659   friend class ConstantDataSequential;
00660   explicit ConstantDataArray(Type *ty, const char *Data)
00661     : ConstantDataSequential(ty, ConstantDataArrayVal, Data) {}
00662 protected:
00663   // allocate space for exactly zero operands.
00664   void *operator new(size_t s) {
00665     return User::operator new(s, 0);
00666   }
00667 public:
00668 
00669   /// get() constructors - Return a constant with array type with an element
00670   /// count and element type matching the ArrayRef passed in.  Note that this
00671   /// can return a ConstantAggregateZero object.
00672   static Constant *get(LLVMContext &Context, ArrayRef<uint8_t> Elts);
00673   static Constant *get(LLVMContext &Context, ArrayRef<uint16_t> Elts);
00674   static Constant *get(LLVMContext &Context, ArrayRef<uint32_t> Elts);
00675   static Constant *get(LLVMContext &Context, ArrayRef<uint64_t> Elts);
00676   static Constant *get(LLVMContext &Context, ArrayRef<float> Elts);
00677   static Constant *get(LLVMContext &Context, ArrayRef<double> Elts);
00678 
00679   /// getFP() constructors - Return a constant with array type with an element
00680   /// count and element type of float with precision matching the number of
00681   /// bits in the ArrayRef passed in. (i.e. half for 16bits, float for 32bits,
00682   /// double for 64bits) Note that this can return a ConstantAggregateZero
00683   /// object.
00684   static Constant *getFP(LLVMContext &Context, ArrayRef<uint16_t> Elts);
00685   static Constant *getFP(LLVMContext &Context, ArrayRef<uint32_t> Elts);
00686   static Constant *getFP(LLVMContext &Context, ArrayRef<uint64_t> Elts);
00687 
00688   /// getString - This method constructs a CDS and initializes it with a text
00689   /// string. The default behavior (AddNull==true) causes a null terminator to
00690   /// be placed at the end of the array (increasing the length of the string by
00691   /// one more than the StringRef would normally indicate.  Pass AddNull=false
00692   /// to disable this behavior.
00693   static Constant *getString(LLVMContext &Context, StringRef Initializer,
00694                              bool AddNull = true);
00695 
00696   /// getType - Specialize the getType() method to always return an ArrayType,
00697   /// which reduces the amount of casting needed in parts of the compiler.
00698   ///
00699   inline ArrayType *getType() const {
00700     return cast<ArrayType>(Value::getType());
00701   }
00702 
00703   /// Methods for support type inquiry through isa, cast, and dyn_cast:
00704   ///
00705   static bool classof(const Value *V) {
00706     return V->getValueID() == ConstantDataArrayVal;
00707   }
00708 };
00709 
00710 //===----------------------------------------------------------------------===//
00711 /// ConstantDataVector - A vector constant whose element type is a simple
00712 /// 1/2/4/8-byte integer or float/double, and whose elements are just simple
00713 /// data values (i.e. ConstantInt/ConstantFP).  This Constant node has no
00714 /// operands because it stores all of the elements of the constant as densely
00715 /// packed data, instead of as Value*'s.
00716 class ConstantDataVector : public ConstantDataSequential {
00717   void *operator new(size_t, unsigned) = delete;
00718   ConstantDataVector(const ConstantDataVector &) = delete;
00719   void anchor() override;
00720   friend class ConstantDataSequential;
00721   explicit ConstantDataVector(Type *ty, const char *Data)
00722   : ConstantDataSequential(ty, ConstantDataVectorVal, Data) {}
00723 protected:
00724   // allocate space for exactly zero operands.
00725   void *operator new(size_t s) {
00726     return User::operator new(s, 0);
00727   }
00728 public:
00729 
00730   /// get() constructors - Return a constant with vector type with an element
00731   /// count and element type matching the ArrayRef passed in.  Note that this
00732   /// can return a ConstantAggregateZero object.
00733   static Constant *get(LLVMContext &Context, ArrayRef<uint8_t> Elts);
00734   static Constant *get(LLVMContext &Context, ArrayRef<uint16_t> Elts);
00735   static Constant *get(LLVMContext &Context, ArrayRef<uint32_t> Elts);
00736   static Constant *get(LLVMContext &Context, ArrayRef<uint64_t> Elts);
00737   static Constant *get(LLVMContext &Context, ArrayRef<float> Elts);
00738   static Constant *get(LLVMContext &Context, ArrayRef<double> Elts);
00739 
00740   /// getFP() constructors - Return a constant with vector type with an element
00741   /// count and element type of float with the precision matching the number of
00742   /// bits in the ArrayRef passed in.  (i.e. half for 16bits, float for 32bits,
00743   /// double for 64bits) Note that this can return a ConstantAggregateZero
00744   /// object.
00745   static Constant *getFP(LLVMContext &Context, ArrayRef<uint16_t> Elts);
00746   static Constant *getFP(LLVMContext &Context, ArrayRef<uint32_t> Elts);
00747   static Constant *getFP(LLVMContext &Context, ArrayRef<uint64_t> Elts);
00748 
00749   /// getSplat - Return a ConstantVector with the specified constant in each
00750   /// element.  The specified constant has to be a of a compatible type (i8/i16/
00751   /// i32/i64/float/double) and must be a ConstantFP or ConstantInt.
00752   static Constant *getSplat(unsigned NumElts, Constant *Elt);
00753 
00754   /// getSplatValue - If this is a splat constant, meaning that all of the
00755   /// elements have the same value, return that value. Otherwise return NULL.
00756   Constant *getSplatValue() const;
00757 
00758   /// getType - Specialize the getType() method to always return a VectorType,
00759   /// which reduces the amount of casting needed in parts of the compiler.
00760   ///
00761   inline VectorType *getType() const {
00762     return cast<VectorType>(Value::getType());
00763   }
00764 
00765   /// Methods for support type inquiry through isa, cast, and dyn_cast:
00766   ///
00767   static bool classof(const Value *V) {
00768     return V->getValueID() == ConstantDataVectorVal;
00769   }
00770 };
00771 
00772 
00773 
00774 /// BlockAddress - The address of a basic block.
00775 ///
00776 class BlockAddress : public Constant {
00777   void *operator new(size_t, unsigned) = delete;
00778   void *operator new(size_t s) { return User::operator new(s, 2); }
00779   BlockAddress(Function *F, BasicBlock *BB);
00780 public:
00781   /// get - Return a BlockAddress for the specified function and basic block.
00782   static BlockAddress *get(Function *F, BasicBlock *BB);
00783 
00784   /// get - Return a BlockAddress for the specified basic block.  The basic
00785   /// block must be embedded into a function.
00786   static BlockAddress *get(BasicBlock *BB);
00787 
00788   /// \brief Lookup an existing \c BlockAddress constant for the given
00789   /// BasicBlock.
00790   ///
00791   /// \returns 0 if \c !BB->hasAddressTaken(), otherwise the \c BlockAddress.
00792   static BlockAddress *lookup(const BasicBlock *BB);
00793 
00794   /// Transparently provide more efficient getOperand methods.
00795   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
00796 
00797   Function *getFunction() const { return (Function*)Op<0>().get(); }
00798   BasicBlock *getBasicBlock() const { return (BasicBlock*)Op<1>().get(); }
00799 
00800   void destroyConstant() override;
00801   void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) override;
00802 
00803   /// Methods for support type inquiry through isa, cast, and dyn_cast:
00804   static inline bool classof(const Value *V) {
00805     return V->getValueID() == BlockAddressVal;
00806   }
00807 };
00808 
00809 template <>
00810 struct OperandTraits<BlockAddress> :
00811   public FixedNumOperandTraits<BlockAddress, 2> {
00812 };
00813 
00814 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BlockAddress, Value)
00815 
00816 
00817 //===----------------------------------------------------------------------===//
00818 /// ConstantExpr - a constant value that is initialized with an expression using
00819 /// other constant values.
00820 ///
00821 /// This class uses the standard Instruction opcodes to define the various
00822 /// constant expressions.  The Opcode field for the ConstantExpr class is
00823 /// maintained in the Value::SubclassData field.
00824 class ConstantExpr : public Constant {
00825   friend struct ConstantExprKeyType;
00826 
00827 protected:
00828   ConstantExpr(Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
00829     : Constant(ty, ConstantExprVal, Ops, NumOps) {
00830     // Operation type (an Instruction opcode) is stored as the SubclassData.
00831     setValueSubclassData(Opcode);
00832   }
00833 
00834 public:
00835   // Static methods to construct a ConstantExpr of different kinds.  Note that
00836   // these methods may return a object that is not an instance of the
00837   // ConstantExpr class, because they will attempt to fold the constant
00838   // expression into something simpler if possible.
00839 
00840   /// getAlignOf constant expr - computes the alignment of a type in a target
00841   /// independent way (Note: the return type is an i64).
00842   static Constant *getAlignOf(Type *Ty);
00843 
00844   /// getSizeOf constant expr - computes the (alloc) size of a type (in
00845   /// address-units, not bits) in a target independent way (Note: the return
00846   /// type is an i64).
00847   ///
00848   static Constant *getSizeOf(Type *Ty);
00849 
00850   /// getOffsetOf constant expr - computes the offset of a struct field in a
00851   /// target independent way (Note: the return type is an i64).
00852   ///
00853   static Constant *getOffsetOf(StructType *STy, unsigned FieldNo);
00854 
00855   /// getOffsetOf constant expr - This is a generalized form of getOffsetOf,
00856   /// which supports any aggregate type, and any Constant index.
00857   ///
00858   static Constant *getOffsetOf(Type *Ty, Constant *FieldNo);
00859 
00860   static Constant *getNeg(Constant *C, bool HasNUW = false, bool HasNSW =false);
00861   static Constant *getFNeg(Constant *C);
00862   static Constant *getNot(Constant *C);
00863   static Constant *getAdd(Constant *C1, Constant *C2,
00864                           bool HasNUW = false, bool HasNSW = false);
00865   static Constant *getFAdd(Constant *C1, Constant *C2);
00866   static Constant *getSub(Constant *C1, Constant *C2,
00867                           bool HasNUW = false, bool HasNSW = false);
00868   static Constant *getFSub(Constant *C1, Constant *C2);
00869   static Constant *getMul(Constant *C1, Constant *C2,
00870                           bool HasNUW = false, bool HasNSW = false);
00871   static Constant *getFMul(Constant *C1, Constant *C2);
00872   static Constant *getUDiv(Constant *C1, Constant *C2, bool isExact = false);
00873   static Constant *getSDiv(Constant *C1, Constant *C2, bool isExact = false);
00874   static Constant *getFDiv(Constant *C1, Constant *C2);
00875   static Constant *getURem(Constant *C1, Constant *C2);
00876   static Constant *getSRem(Constant *C1, Constant *C2);
00877   static Constant *getFRem(Constant *C1, Constant *C2);
00878   static Constant *getAnd(Constant *C1, Constant *C2);
00879   static Constant *getOr(Constant *C1, Constant *C2);
00880   static Constant *getXor(Constant *C1, Constant *C2);
00881   static Constant *getShl(Constant *C1, Constant *C2,
00882                           bool HasNUW = false, bool HasNSW = false);
00883   static Constant *getLShr(Constant *C1, Constant *C2, bool isExact = false);
00884   static Constant *getAShr(Constant *C1, Constant *C2, bool isExact = false);
00885   static Constant *getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced = false);
00886   static Constant *getSExt(Constant *C, Type *Ty, bool OnlyIfReduced = false);
00887   static Constant *getZExt(Constant *C, Type *Ty, bool OnlyIfReduced = false);
00888   static Constant *getFPTrunc(Constant *C, Type *Ty,
00889                               bool OnlyIfReduced = false);
00890   static Constant *getFPExtend(Constant *C, Type *Ty,
00891                                bool OnlyIfReduced = false);
00892   static Constant *getUIToFP(Constant *C, Type *Ty, bool OnlyIfReduced = false);
00893   static Constant *getSIToFP(Constant *C, Type *Ty, bool OnlyIfReduced = false);
00894   static Constant *getFPToUI(Constant *C, Type *Ty, bool OnlyIfReduced = false);
00895   static Constant *getFPToSI(Constant *C, Type *Ty, bool OnlyIfReduced = false);
00896   static Constant *getPtrToInt(Constant *C, Type *Ty,
00897                                bool OnlyIfReduced = false);
00898   static Constant *getIntToPtr(Constant *C, Type *Ty,
00899                                bool OnlyIfReduced = false);
00900   static Constant *getBitCast(Constant *C, Type *Ty,
00901                               bool OnlyIfReduced = false);
00902   static Constant *getAddrSpaceCast(Constant *C, Type *Ty,
00903                                     bool OnlyIfReduced = false);
00904 
00905   static Constant *getNSWNeg(Constant *C) { return getNeg(C, false, true); }
00906   static Constant *getNUWNeg(Constant *C) { return getNeg(C, true, false); }
00907   static Constant *getNSWAdd(Constant *C1, Constant *C2) {
00908     return getAdd(C1, C2, false, true);
00909   }
00910   static Constant *getNUWAdd(Constant *C1, Constant *C2) {
00911     return getAdd(C1, C2, true, false);
00912   }
00913   static Constant *getNSWSub(Constant *C1, Constant *C2) {
00914     return getSub(C1, C2, false, true);
00915   }
00916   static Constant *getNUWSub(Constant *C1, Constant *C2) {
00917     return getSub(C1, C2, true, false);
00918   }
00919   static Constant *getNSWMul(Constant *C1, Constant *C2) {
00920     return getMul(C1, C2, false, true);
00921   }
00922   static Constant *getNUWMul(Constant *C1, Constant *C2) {
00923     return getMul(C1, C2, true, false);
00924   }
00925   static Constant *getNSWShl(Constant *C1, Constant *C2) {
00926     return getShl(C1, C2, false, true);
00927   }
00928   static Constant *getNUWShl(Constant *C1, Constant *C2) {
00929     return getShl(C1, C2, true, false);
00930   }
00931   static Constant *getExactSDiv(Constant *C1, Constant *C2) {
00932     return getSDiv(C1, C2, true);
00933   }
00934   static Constant *getExactUDiv(Constant *C1, Constant *C2) {
00935     return getUDiv(C1, C2, true);
00936   }
00937   static Constant *getExactAShr(Constant *C1, Constant *C2) {
00938     return getAShr(C1, C2, true);
00939   }
00940   static Constant *getExactLShr(Constant *C1, Constant *C2) {
00941     return getLShr(C1, C2, true);
00942   }
00943 
00944   /// getBinOpIdentity - Return the identity for the given binary operation,
00945   /// i.e. a constant C such that X op C = X and C op X = X for every X.  It
00946   /// returns null if the operator doesn't have an identity.
00947   static Constant *getBinOpIdentity(unsigned Opcode, Type *Ty);
00948 
00949   /// getBinOpAbsorber - Return the absorbing element for the given binary
00950   /// operation, i.e. a constant C such that X op C = C and C op X = C for
00951   /// every X.  For example, this returns zero for integer multiplication.
00952   /// It returns null if the operator doesn't have an absorbing element.
00953   static Constant *getBinOpAbsorber(unsigned Opcode, Type *Ty);
00954 
00955   /// Transparently provide more efficient getOperand methods.
00956   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
00957 
00958   /// \brief Convenience function for getting a Cast operation.
00959   ///
00960   /// \param ops The opcode for the conversion
00961   /// \param C  The constant to be converted
00962   /// \param Ty The type to which the constant is converted
00963   /// \param OnlyIfReduced see \a getWithOperands() docs.
00964   static Constant *getCast(unsigned ops, Constant *C, Type *Ty,
00965                            bool OnlyIfReduced = false);
00966 
00967   // @brief Create a ZExt or BitCast cast constant expression
00968   static Constant *getZExtOrBitCast(
00969     Constant *C,   ///< The constant to zext or bitcast
00970     Type *Ty ///< The type to zext or bitcast C to
00971   );
00972 
00973   // @brief Create a SExt or BitCast cast constant expression
00974   static Constant *getSExtOrBitCast(
00975     Constant *C,   ///< The constant to sext or bitcast
00976     Type *Ty ///< The type to sext or bitcast C to
00977   );
00978 
00979   // @brief Create a Trunc or BitCast cast constant expression
00980   static Constant *getTruncOrBitCast(
00981     Constant *C,   ///< The constant to trunc or bitcast
00982     Type *Ty ///< The type to trunc or bitcast C to
00983   );
00984 
00985   /// @brief Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant
00986   /// expression.
00987   static Constant *getPointerCast(
00988     Constant *C,   ///< The pointer value to be casted (operand 0)
00989     Type *Ty ///< The type to which cast should be made
00990   );
00991 
00992   /// @brief Create a BitCast or AddrSpaceCast for a pointer type depending on
00993   /// the address space.
00994   static Constant *getPointerBitCastOrAddrSpaceCast(
00995     Constant *C,   ///< The constant to addrspacecast or bitcast
00996     Type *Ty ///< The type to bitcast or addrspacecast C to
00997   );
00998 
00999   /// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts
01000   static Constant *getIntegerCast(
01001     Constant *C,    ///< The integer constant to be casted
01002     Type *Ty, ///< The integer type to cast to
01003     bool isSigned   ///< Whether C should be treated as signed or not
01004   );
01005 
01006   /// @brief Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
01007   static Constant *getFPCast(
01008     Constant *C,    ///< The integer constant to be casted
01009     Type *Ty ///< The integer type to cast to
01010   );
01011 
01012   /// @brief Return true if this is a convert constant expression
01013   bool isCast() const;
01014 
01015   /// @brief Return true if this is a compare constant expression
01016   bool isCompare() const;
01017 
01018   /// @brief Return true if this is an insertvalue or extractvalue expression,
01019   /// and the getIndices() method may be used.
01020   bool hasIndices() const;
01021 
01022   /// @brief Return true if this is a getelementptr expression and all
01023   /// the index operands are compile-time known integers within the
01024   /// corresponding notional static array extents. Note that this is
01025   /// not equivalant to, a subset of, or a superset of the "inbounds"
01026   /// property.
01027   bool isGEPWithNoNotionalOverIndexing() const;
01028 
01029   /// Select constant expr
01030   ///
01031   /// \param OnlyIfReducedTy see \a getWithOperands() docs.
01032   static Constant *getSelect(Constant *C, Constant *V1, Constant *V2,
01033                              Type *OnlyIfReducedTy = nullptr);
01034 
01035   /// get - Return a binary or shift operator constant expression,
01036   /// folding if possible.
01037   ///
01038   /// \param OnlyIfReducedTy see \a getWithOperands() docs.
01039   static Constant *get(unsigned Opcode, Constant *C1, Constant *C2,
01040                        unsigned Flags = 0, Type *OnlyIfReducedTy = nullptr);
01041 
01042   /// \brief Return an ICmp or FCmp comparison operator constant expression.
01043   ///
01044   /// \param OnlyIfReduced see \a getWithOperands() docs.
01045   static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2,
01046                               bool OnlyIfReduced = false);
01047 
01048   /// get* - Return some common constants without having to
01049   /// specify the full Instruction::OPCODE identifier.
01050   ///
01051   static Constant *getICmp(unsigned short pred, Constant *LHS, Constant *RHS,
01052                            bool OnlyIfReduced = false);
01053   static Constant *getFCmp(unsigned short pred, Constant *LHS, Constant *RHS,
01054                            bool OnlyIfReduced = false);
01055 
01056   /// Getelementptr form.  Value* is only accepted for convenience;
01057   /// all elements must be Constant's.
01058   ///
01059   /// \param OnlyIfReducedTy see \a getWithOperands() docs.
01060   static Constant *getGetElementPtr(Constant *C, ArrayRef<Constant *> IdxList,
01061                                     bool InBounds = false,
01062                                     Type *OnlyIfReducedTy = nullptr) {
01063     return getGetElementPtr(
01064         C, makeArrayRef((Value * const *)IdxList.data(), IdxList.size()),
01065         InBounds, OnlyIfReducedTy);
01066   }
01067   static Constant *getGetElementPtr(Constant *C, Constant *Idx,
01068                                     bool InBounds = false,
01069                                     Type *OnlyIfReducedTy = nullptr) {
01070     // This form of the function only exists to avoid ambiguous overload
01071     // warnings about whether to convert Idx to ArrayRef<Constant *> or
01072     // ArrayRef<Value *>.
01073     return getGetElementPtr(C, cast<Value>(Idx), InBounds, OnlyIfReducedTy);
01074   }
01075   static Constant *getGetElementPtr(Constant *C, ArrayRef<Value *> IdxList,
01076                                     bool InBounds = false,
01077                                     Type *OnlyIfReducedTy = nullptr);
01078 
01079   /// Create an "inbounds" getelementptr. See the documentation for the
01080   /// "inbounds" flag in LangRef.html for details.
01081   static Constant *getInBoundsGetElementPtr(Constant *C,
01082                                             ArrayRef<Constant *> IdxList) {
01083     return getGetElementPtr(C, IdxList, true);
01084   }
01085   static Constant *getInBoundsGetElementPtr(Constant *C,
01086                                             Constant *Idx) {
01087     // This form of the function only exists to avoid ambiguous overload
01088     // warnings about whether to convert Idx to ArrayRef<Constant *> or
01089     // ArrayRef<Value *>.
01090     return getGetElementPtr(C, Idx, true);
01091   }
01092   static Constant *getInBoundsGetElementPtr(Constant *C,
01093                                             ArrayRef<Value *> IdxList) {
01094     return getGetElementPtr(C, IdxList, true);
01095   }
01096 
01097   static Constant *getExtractElement(Constant *Vec, Constant *Idx,
01098                                      Type *OnlyIfReducedTy = nullptr);
01099   static Constant *getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx,
01100                                     Type *OnlyIfReducedTy = nullptr);
01101   static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask,
01102                                     Type *OnlyIfReducedTy = nullptr);
01103   static Constant *getExtractValue(Constant *Agg, ArrayRef<unsigned> Idxs,
01104                                    Type *OnlyIfReducedTy = nullptr);
01105   static Constant *getInsertValue(Constant *Agg, Constant *Val,
01106                                   ArrayRef<unsigned> Idxs,
01107                                   Type *OnlyIfReducedTy = nullptr);
01108 
01109   /// getOpcode - Return the opcode at the root of this constant expression
01110   unsigned getOpcode() const { return getSubclassDataFromValue(); }
01111 
01112   /// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is
01113   /// not an ICMP or FCMP constant expression.
01114   unsigned getPredicate() const;
01115 
01116   /// getIndices - Assert that this is an insertvalue or exactvalue
01117   /// expression and return the list of indices.
01118   ArrayRef<unsigned> getIndices() const;
01119 
01120   /// getOpcodeName - Return a string representation for an opcode.
01121   const char *getOpcodeName() const;
01122 
01123   /// getWithOperandReplaced - Return a constant expression identical to this
01124   /// one, but with the specified operand set to the specified value.
01125   Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
01126 
01127   /// getWithOperands - This returns the current constant expression with the
01128   /// operands replaced with the specified values.  The specified array must
01129   /// have the same number of operands as our current one.
01130   Constant *getWithOperands(ArrayRef<Constant*> Ops) const {
01131     return getWithOperands(Ops, getType());
01132   }
01133 
01134   /// \brief Get the current expression with the operands replaced.
01135   ///
01136   /// Return the current constant expression with the operands replaced with \c
01137   /// Ops and the type with \c Ty.  The new operands must have the same number
01138   /// as the current ones.
01139   ///
01140   /// If \c OnlyIfReduced is \c true, nullptr will be returned unless something
01141   /// gets constant-folded, the type changes, or the expression is otherwise
01142   /// canonicalized.  This parameter should almost always be \c false.
01143   Constant *getWithOperands(ArrayRef<Constant *> Ops, Type *Ty,
01144                             bool OnlyIfReduced = false) const;
01145 
01146   /// getAsInstruction - Returns an Instruction which implements the same operation
01147   /// as this ConstantExpr. The instruction is not linked to any basic block.
01148   ///
01149   /// A better approach to this could be to have a constructor for Instruction
01150   /// which would take a ConstantExpr parameter, but that would have spread
01151   /// implementation details of ConstantExpr outside of Constants.cpp, which
01152   /// would make it harder to remove ConstantExprs altogether.
01153   Instruction *getAsInstruction();
01154 
01155   void destroyConstant() override;
01156   void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) override;
01157 
01158   /// Methods for support type inquiry through isa, cast, and dyn_cast:
01159   static inline bool classof(const Value *V) {
01160     return V->getValueID() == ConstantExprVal;
01161   }
01162 
01163 private:
01164   // Shadow Value::setValueSubclassData with a private forwarding method so that
01165   // subclasses cannot accidentally use it.
01166   void setValueSubclassData(unsigned short D) {
01167     Value::setValueSubclassData(D);
01168   }
01169 };
01170 
01171 template <>
01172 struct OperandTraits<ConstantExpr> :
01173   public VariadicOperandTraits<ConstantExpr, 1> {
01174 };
01175 
01176 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantExpr, Constant)
01177 
01178 //===----------------------------------------------------------------------===//
01179 /// UndefValue - 'undef' values are things that do not have specified contents.
01180 /// These are used for a variety of purposes, including global variable
01181 /// initializers and operands to instructions.  'undef' values can occur with
01182 /// any first-class type.
01183 ///
01184 /// Undef values aren't exactly constants; if they have multiple uses, they
01185 /// can appear to have different bit patterns at each use. See
01186 /// LangRef.html#undefvalues for details.
01187 ///
01188 class UndefValue : public Constant {
01189   void *operator new(size_t, unsigned) = delete;
01190   UndefValue(const UndefValue &) = delete;
01191 protected:
01192   explicit UndefValue(Type *T) : Constant(T, UndefValueVal, nullptr, 0) {}
01193 protected:
01194   // allocate space for exactly zero operands
01195   void *operator new(size_t s) {
01196     return User::operator new(s, 0);
01197   }
01198 public:
01199   /// get() - Static factory methods - Return an 'undef' object of the specified
01200   /// type.
01201   ///
01202   static UndefValue *get(Type *T);
01203 
01204   /// getSequentialElement - If this Undef has array or vector type, return a
01205   /// undef with the right element type.
01206   UndefValue *getSequentialElement() const;
01207 
01208   /// getStructElement - If this undef has struct type, return a undef with the
01209   /// right element type for the specified element.
01210   UndefValue *getStructElement(unsigned Elt) const;
01211 
01212   /// getElementValue - Return an undef of the right value for the specified GEP
01213   /// index.
01214   UndefValue *getElementValue(Constant *C) const;
01215 
01216   /// getElementValue - Return an undef of the right value for the specified GEP
01217   /// index.
01218   UndefValue *getElementValue(unsigned Idx) const;
01219 
01220   /// \brief Return the number of elements in the array, vector, or struct.
01221   unsigned getNumElements() const;
01222 
01223   void destroyConstant() override;
01224 
01225   /// Methods for support type inquiry through isa, cast, and dyn_cast:
01226   static bool classof(const Value *V) {
01227     return V->getValueID() == UndefValueVal;
01228   }
01229 };
01230 
01231 } // End llvm namespace
01232 
01233 #endif