diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Constants.h | 29 | ||||
-rw-r--r-- | include/llvm/LLVMContext.h | 32 | ||||
-rw-r--r-- | include/llvm/Support/IRBuilder.h | 14 |
3 files changed, 38 insertions, 37 deletions
diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h index f9fd636..d59621a 100644 --- a/include/llvm/Constants.h +++ b/include/llvm/Constants.h @@ -57,6 +57,35 @@ protected: return User::operator new(s, 0); } public: + /// If Ty is a vector type, return a Constant with a splat of the given + /// value. Otherwise return a ConstantInt for the given value. + static Constant* get(const Type* Ty, uint64_t V, bool isSigned = false); + + /// Return a ConstantInt with the specified integer value for the specified + /// type. If the type is wider than 64 bits, the value will be zero-extended + /// to fit the type, unless isSigned is true, in which case the value will + /// be interpreted as a 64-bit signed integer and sign-extended to fit + /// the type. + /// @brief Get a ConstantInt for a specific value. + static ConstantInt* get(const IntegerType* Ty, uint64_t V, + bool isSigned = false); + + /// Return a ConstantInt with the specified value for the specified type. The + /// value V will be canonicalized to a an unsigned APInt. Accessing it with + /// either getSExtValue() or getZExtValue() will yield a correctly sized and + /// signed value for the type Ty. + /// @brief Get a ConstantInt for a specific signed value. + static ConstantInt* getSigned(const IntegerType* Ty, int64_t V); + static Constant *getSigned(const Type *Ty, int64_t V); + + /// Return a ConstantInt with the specified value and an implied Type. The + /// type is the integer type that corresponds to the bit width of the value. + static ConstantInt* get(LLVMContext &Context, const APInt& V); + + /// If Ty is a vector type, return a Constant with a splat of the given + /// value. Otherwise return a ConstantInt for the given value. + static Constant* get(const Type* Ty, const APInt& V); + /// Return the constant as an APInt value reference. This allows clients to /// obtain a copy of the value, with all its precision in tact. /// @brief Return the constant's value. diff --git a/include/llvm/LLVMContext.h b/include/llvm/LLVMContext.h index a2fa569..73d8898 100644 --- a/include/llvm/LLVMContext.h +++ b/include/llvm/LLVMContext.h @@ -53,6 +53,8 @@ class Use; /// to have one context per thread. class LLVMContext { LLVMContextImpl* pImpl; + + friend class ConstantInt; public: LLVMContext(); ~LLVMContext(); @@ -72,36 +74,6 @@ public: ConstantInt* getTrue(); ConstantInt* getFalse(); - /// If Ty is a vector type, return a Constant with a splat of the given - /// value. Otherwise return a ConstantInt for the given value. - Constant* getConstantInt(const Type* Ty, uint64_t V, - bool isSigned = false); - - /// Return a ConstantInt with the specified integer value for the specified - /// type. If the type is wider than 64 bits, the value will be zero-extended - /// to fit the type, unless isSigned is true, in which case the value will - /// be interpreted as a 64-bit signed integer and sign-extended to fit - /// the type. - /// @brief Get a ConstantInt for a specific value. - ConstantInt* getConstantInt(const IntegerType* Ty, uint64_t V, - bool isSigned = false); - - /// Return a ConstantInt with the specified value for the specified type. The - /// value V will be canonicalized to a an unsigned APInt. Accessing it with - /// either getSExtValue() or getZExtValue() will yield a correctly sized and - /// signed value for the type Ty. - /// @brief Get a ConstantInt for a specific signed value. - ConstantInt* getConstantIntSigned(const IntegerType* Ty, int64_t V); - Constant *getConstantIntSigned(const Type *Ty, int64_t V); - - /// Return a ConstantInt with the specified value and an implied Type. The - /// type is the integer type that corresponds to the bit width of the value. - ConstantInt* getConstantInt(const APInt& V); - - /// If Ty is a vector type, return a Constant with a splat of the given - /// value. Otherwise return a ConstantInt for the given value. - Constant* getConstantInt(const Type* Ty, const APInt& V); - // ConstantPointerNull accessors ConstantPointerNull* getConstantPointerNull(const PointerType* T); diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h index 835a286..ac134ec 100644 --- a/include/llvm/Support/IRBuilder.h +++ b/include/llvm/Support/IRBuilder.h @@ -370,7 +370,7 @@ public: return Insert(GetElementPtrInst::Create(Ptr, Idx), Name); } Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const char *Name = "") { - Value *Idx = Context.getConstantInt(Type::Int32Ty, Idx0); + Value *Idx = ConstantInt::get(Type::Int32Ty, Idx0); if (Constant *PC = dyn_cast<Constant>(Ptr)) return Folder.CreateGetElementPtr(PC, &Idx, 1); @@ -380,8 +380,8 @@ public: Value *CreateConstGEP2_32(Value *Ptr, unsigned Idx0, unsigned Idx1, const char *Name = "") { Value *Idxs[] = { - Context.getConstantInt(Type::Int32Ty, Idx0), - Context.getConstantInt(Type::Int32Ty, Idx1) + ConstantInt::get(Type::Int32Ty, Idx0), + ConstantInt::get(Type::Int32Ty, Idx1) }; if (Constant *PC = dyn_cast<Constant>(Ptr)) @@ -390,7 +390,7 @@ public: return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2), Name); } Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const char *Name = "") { - Value *Idx = Context.getConstantInt(Type::Int64Ty, Idx0); + Value *Idx = ConstantInt::get(Type::Int64Ty, Idx0); if (Constant *PC = dyn_cast<Constant>(Ptr)) return Folder.CreateGetElementPtr(PC, &Idx, 1); @@ -400,8 +400,8 @@ public: Value *CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1, const char *Name = "") { Value *Idxs[] = { - Context.getConstantInt(Type::Int64Ty, Idx0), - Context.getConstantInt(Type::Int64Ty, Idx1) + ConstantInt::get(Type::Int64Ty, Idx0), + ConstantInt::get(Type::Int64Ty, Idx1) }; if (Constant *PC = dyn_cast<Constant>(Ptr)) @@ -428,7 +428,7 @@ public: } Value *CreateGlobalStringPtr(const char *Str = "", const char *Name = "") { Value *gv = CreateGlobalString(Str, Name); - Value *zero = Context.getConstantInt(Type::Int32Ty, 0); + Value *zero = ConstantInt::get(Type::Int32Ty, 0); Value *Args[] = { zero, zero }; return CreateGEP(gv, Args, Args+2, Name); } |