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