X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FConstants.h;h=cce4d49d1fbaf7fea9c330d1a7fb456c9fc2395e;hb=f8a01a966120a041fe96300271573a8bf5a3e668;hp=91e82ccb8d3161f60a931ef7252c4c4e66c3a3a1;hpb=9769ab22265b313171d201b5928688524a01bd87;p=oota-llvm.git diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h index 91e82ccb8d3..cce4d49d1fb 100644 --- a/include/llvm/Constants.h +++ b/include/llvm/Constants.h @@ -22,7 +22,6 @@ #include "llvm/Constant.h" #include "llvm/Type.h" -#include "llvm/Support/DataTypes.h" namespace llvm { @@ -47,14 +46,28 @@ protected: int64_t Signed; uint64_t Unsigned; } Val; - ConstantIntegral(const Type *Ty, uint64_t V); + ConstantIntegral(const Type *Ty, ValueTy VT, uint64_t V); public: /// getRawValue - return the underlying value of this constant as a 64-bit /// unsigned integer value. /// inline uint64_t getRawValue() const { return Val.Unsigned; } + + /// getZExtValue - Return the constant zero extended as appropriate for this + /// type. + inline uint64_t getZExtValue() const { + unsigned Size = getType()->getPrimitiveSizeInBits(); + return Val.Unsigned & (~uint64_t(0UL) >> (64-Size)); + } + /// getSExtValue - Return the constant sign extended as appropriate for this + /// type. + inline int64_t getSExtValue() const { + unsigned Size = getType()->getPrimitiveSizeInBits(); + return (Val.Signed << (64-Size)) >> (64-Size); + } + /// isNullValue - Return true if this is the value that would be returned by /// getNullValue. /// @@ -84,8 +97,9 @@ public: /// Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const ConstantIntegral *) { return true; } static bool classof(const Value *V) { - return V->getValueType() == SimpleConstantVal && - V->getType()->isIntegral(); + return V->getValueType() == ConstantBoolVal || + V->getValueType() == ConstantSIntVal || + V->getValueType() == ConstantUIntVal; } }; @@ -120,7 +134,7 @@ public: /// Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const ConstantBool *) { return true; } static bool classof(const Value *V) { - return (V == True) | (V == False); + return V->getValueType() == ConstantBoolVal; } }; @@ -132,7 +146,7 @@ public: class ConstantInt : public ConstantIntegral { protected: ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT - ConstantInt(const Type *Ty, uint64_t V); + ConstantInt(const Type *Ty, ValueTy VT, uint64_t V); public: /// equalsInt - Provide a helper method that can be used to determine if the /// constant contained within is equal to a constant. This only works for @@ -159,8 +173,8 @@ public: /// Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const ConstantInt *) { return true; } static bool classof(const Value *V) { - return V->getValueType() == SimpleConstantVal && - V->getType()->isInteger(); + return V->getValueType() == ConstantSIntVal || + V->getValueType() == ConstantUIntVal; } }; @@ -213,8 +227,7 @@ public: /// static inline bool classof(const ConstantSInt *) { return true; } static bool classof(const Value *V) { - return V->getValueType() == SimpleConstantVal && - V->getType()->isSigned(); + return V->getValueType() == ConstantSIntVal; } }; @@ -249,8 +262,7 @@ public: /// Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const ConstantUInt *) { return true; } static bool classof(const Value *V) { - return V->getValueType() == SimpleConstantVal && - V->getType()->isUnsigned(); + return V->getValueType() == ConstantUIntVal; } }; @@ -276,38 +288,18 @@ public: /// isNullValue - Return true if this is the value that would be returned by /// getNullValue. Don't depend on == for doubles to tell us it's zero, it /// considers -0.0 to be null as well as 0.0. :( - virtual bool isNullValue() const { - union { - double V; - uint64_t I; - } T; - T.V = Val; - return T.I == 0; - } + virtual bool isNullValue() const; /// isExactlyValue - We don't rely on operator== working on double values, as /// it returns true for things that are clearly not equal, like -0.0 and 0.0. /// As such, this method can be used to do an exact bit-for-bit comparison of /// two floating point values. - bool isExactlyValue(double V) const { - union { - double V; - uint64_t I; - } T1; - T1.V = Val; - union { - double V; - uint64_t I; - } T2; - T2.V = V; - return T1.I == T2.I; - } + bool isExactlyValue(double V) const; /// Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const ConstantFP *) { return true; } static bool classof(const Value *V) { - return V->getValueType() == SimpleConstantVal && - V->getType()->isFloatingPoint(); + return V->getValueType() == ConstantFPVal; } }; @@ -330,8 +322,6 @@ public: virtual bool isNullValue() const { return true; } virtual void destroyConstant(); - virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, - bool DisableChecking = false); /// Methods for support type inquiry through isa, cast, and dyn_cast: /// @@ -355,7 +345,14 @@ protected: public: /// get() - Static factory methods - Return objects of the specified value static Constant *get(const ArrayType *T, const std::vector &); - static Constant *get(const std::string &Initializer); + + /// This method constructs a ConstantArray and initializes it with a text + /// string. The default behavior (AddNull==true) causes a null terminator to + /// be placed at the end of the array. This effectively increases the length + /// of the array by one (you've been warned). However, in some situations + /// this is not desired so if AddNull==false then the string is copied without + /// null termination. + static Constant *get(const std::string &Initializer, bool AddNull = true); /// getType - Specialize the getType() method to always return an ArrayType, /// which reduces the amount of casting needed in parts of the compiler. @@ -379,14 +376,12 @@ public: virtual bool isNullValue() const { return false; } virtual void destroyConstant(); - virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, - bool DisableChecking = false); + virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); /// Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const ConstantArray *) { return true; } static bool classof(const Value *V) { - return V->getValueType() == SimpleConstantVal && - V->getType()->getTypeID() == Type::ArrayTyID; + return V->getValueType() == ConstantArrayVal; } }; @@ -421,14 +416,12 @@ public: } virtual void destroyConstant(); - virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, - bool DisableChecking = false); + virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); /// Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const ConstantStruct *) { return true; } static bool classof(const Value *V) { - return V->getValueType() == SimpleConstantVal && - V->getType()->getTypeID() == Type::StructTyID; + return V->getValueType() == ConstantStructVal; } }; @@ -460,14 +453,12 @@ public: virtual bool isNullValue() const { return false; } virtual void destroyConstant(); - virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, - bool DisableChecking = false); + virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); /// Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const ConstantPacked *) { return true; } static bool classof(const Value *V) { - return V->getValueType() == SimpleConstantVal && - V->getType()->getTypeID() == Type::PackedTyID; + return V->getValueType() == ConstantPackedVal; } }; @@ -480,7 +471,7 @@ class ConstantPointerNull : public Constant { protected: ConstantPointerNull(const PointerType *T) : Constant(reinterpret_cast(T), - Value::SimpleConstantVal, 0, 0) {} + Value::ConstantPointerNullVal, 0, 0) {} public: @@ -503,8 +494,7 @@ public: /// Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const ConstantPointerNull *) { return true; } static bool classof(const Value *V) { - return V->getValueType() == SimpleConstantVal && - isa(V->getType()); + return V->getValueType() == ConstantPointerNullVal; } }; @@ -537,6 +527,12 @@ protected: Constant *C1, Constant *C2, Constant *C3); static Constant *getGetElementPtrTy(const Type *Ty, Constant *C, const std::vector &IdxList); + static Constant *getExtractElementTy(const Type *Ty, Constant *Val, + Constant *Idx); + static Constant *getInsertElementTy(const Type *Ty, Constant *Val, + Constant *Elt, Constant *Idx); + static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1, + Constant *V2, Constant *Mask); public: // Static methods to construct a ConstantExpr of different kinds. Note that @@ -604,6 +600,10 @@ public: static Constant *getGetElementPtr(Constant *C, const std::vector &IdxList); + static Constant *getExtractElement(Constant *Vec, Constant *Idx); + static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx); + static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask); + /// isNullValue - Return true if this is the value that would be returned by /// getNullValue. virtual bool isNullValue() const { return false; } @@ -615,8 +615,7 @@ public: const char *getOpcodeName() const; virtual void destroyConstant(); - virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, - bool DisableChecking = false); + virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); /// Override methods to provide more type information... inline Constant *getOperand(unsigned i) {