diff options
67 files changed, 960 insertions, 1254 deletions
diff --git a/examples/BrainF/BrainF.cpp b/examples/BrainF/BrainF.cpp index 4969a55a66..97a9b0579e 100644 --- a/examples/BrainF/BrainF.cpp +++ b/examples/BrainF/BrainF.cpp @@ -77,16 +77,16 @@ void BrainF::header(LLVMContext& C) { builder = new IRBuilder<>(BasicBlock::Create(label, brainf_func)); //%arr = malloc i8, i32 %d - ConstantInt *val_mem = C.getConstantInt(APInt(32, memtotal)); + ConstantInt *val_mem = ConstantInt::get(C, APInt(32, memtotal)); ptr_arr = builder->CreateMalloc(IntegerType::Int8Ty, val_mem, "arr"); //call void @llvm.memset.i32(i8 *%arr, i8 0, i32 %d, i32 1) { Value *memset_params[] = { ptr_arr, - C.getConstantInt(APInt(8, 0)), + ConstantInt::get(C, APInt(8, 0)), val_mem, - C.getConstantInt(APInt(32, 1)) + ConstantInt::get(C, APInt(32, 1)) }; CallInst *memset_call = builder-> @@ -97,12 +97,12 @@ void BrainF::header(LLVMContext& C) { //%arrmax = getelementptr i8 *%arr, i32 %d if (comflag & flag_arraybounds) { ptr_arrmax = builder-> - CreateGEP(ptr_arr, C.getConstantInt(APInt(32, memtotal)), "arrmax"); + CreateGEP(ptr_arr, ConstantInt::get(C, APInt(32, memtotal)), "arrmax"); } //%head.%d = getelementptr i8 *%arr, i32 %d curhead = builder->CreateGEP(ptr_arr, - C.getConstantInt(APInt(32, memtotal/2)), + ConstantInt::get(C, APInt(32, memtotal/2)), headreg); @@ -229,7 +229,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb, { //%head.%d = getelementptr i8 *%head.%d, i32 %d curhead = builder-> - CreateGEP(curhead, C.getConstantInt(APInt(32, curvalue)), + CreateGEP(curhead, ConstantInt::get(C, APInt(32, curvalue)), headreg); //Error block for array out of bounds @@ -264,7 +264,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb, //%tape.%d = add i8 %tape.%d, %d Value *tape_1 = builder-> - CreateAdd(tape_0, C.getConstantInt(APInt(8, curvalue)), tapereg); + CreateAdd(tape_0, ConstantInt::get(C, APInt(8, curvalue)), tapereg); //store i8 %tape.%d, i8 *%head.%d\n" builder->CreateStore(tape_1, curhead); @@ -429,7 +429,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb, //%test.%d = icmp eq i8 %tape.%d, 0 ICmpInst *test_0 = new ICmpInst(*testbb, ICmpInst::ICMP_EQ, tape_0, - C.getConstantInt(APInt(8, 0)), testreg); + ConstantInt::get(C, APInt(8, 0)), testreg); //br i1 %test.%d, label %main.%d, label %main.%d BasicBlock *bb_0 = BasicBlock::Create(label, brainf_func); diff --git a/examples/BrainF/BrainFDriver.cpp b/examples/BrainF/BrainFDriver.cpp index fba79cfbd5..8c62ae2900 100644 --- a/examples/BrainF/BrainFDriver.cpp +++ b/examples/BrainF/BrainFDriver.cpp @@ -80,7 +80,7 @@ void addMainFunction(Module *mod) { } //ret i32 0 - ReturnInst::Create(getGlobalContext().getConstantInt(APInt(32, 0)), bb); + ReturnInst::Create(ConstantInt::get(getGlobalContext(), APInt(32, 0)), bb); } int main(int argc, char **argv) { diff --git a/examples/Fibonacci/fibonacci.cpp b/examples/Fibonacci/fibonacci.cpp index c5c8f0de89..48efd5a1cc 100644 --- a/examples/Fibonacci/fibonacci.cpp +++ b/examples/Fibonacci/fibonacci.cpp @@ -47,8 +47,8 @@ static Function *CreateFibFunction(Module *M, LLVMContext &Context) { BasicBlock *BB = BasicBlock::Create("EntryBlock", FibF); // Get pointers to the constants. - Value *One = Context.getConstantInt(Type::Int32Ty, 1); - Value *Two = Context.getConstantInt(Type::Int32Ty, 2); + Value *One = ConstantInt::get(Type::Int32Ty, 1); + Value *Two = ConstantInt::get(Type::Int32Ty, 2); // Get pointer to the integer argument of the add1 function... Argument *ArgX = FibF->arg_begin(); // Get the arg. diff --git a/examples/HowToUseJIT/HowToUseJIT.cpp b/examples/HowToUseJIT/HowToUseJIT.cpp index 8a788491fd..7a99ed4473 100644 --- a/examples/HowToUseJIT/HowToUseJIT.cpp +++ b/examples/HowToUseJIT/HowToUseJIT.cpp @@ -69,7 +69,7 @@ int main() { BasicBlock *BB = BasicBlock::Create("EntryBlock", Add1F); // Get pointers to the constant `1'. - Value *One = Context.getConstantInt(Type::Int32Ty, 1); + Value *One = ConstantInt::get(Type::Int32Ty, 1); // Get pointers to the integer argument of the add1 function... assert(Add1F->arg_begin() != Add1F->arg_end()); // Make sure there's an arg @@ -94,7 +94,7 @@ int main() { BB = BasicBlock::Create("EntryBlock", FooF); // Get pointers to the constant `10'. - Value *Ten = Context.getConstantInt(Type::Int32Ty, 10); + Value *Ten = ConstantInt::get(Type::Int32Ty, 10); // Pass Ten to the call call: CallInst *Add1CallRes = CallInst::Create(Add1F, Ten, "add1", BB); diff --git a/examples/ModuleMaker/ModuleMaker.cpp b/examples/ModuleMaker/ModuleMaker.cpp index 537ee341dc..1baa8c98ef 100644 --- a/examples/ModuleMaker/ModuleMaker.cpp +++ b/examples/ModuleMaker/ModuleMaker.cpp @@ -42,8 +42,8 @@ int main() { BasicBlock *BB = BasicBlock::Create("EntryBlock", F); // Get pointers to the constant integers... - Value *Two = Context.getConstantInt(Type::Int32Ty, 2); - Value *Three = Context.getConstantInt(Type::Int32Ty, 3); + Value *Two = ConstantInt::get(Type::Int32Ty, 2); + Value *Three = ConstantInt::get(Type::Int32Ty, 3); // Create the add instruction... does not insert... Instruction *Add = BinaryOperator::Create(Instruction::Add, Two, Three, diff --git a/examples/ParallelJIT/ParallelJIT.cpp b/examples/ParallelJIT/ParallelJIT.cpp index 464bd22e8f..83e2640636 100644 --- a/examples/ParallelJIT/ParallelJIT.cpp +++ b/examples/ParallelJIT/ParallelJIT.cpp @@ -44,7 +44,7 @@ static Function* createAdd1(Module *M) { BasicBlock *BB = BasicBlock::Create("EntryBlock", Add1F); // Get pointers to the constant `1'. - Value *One = M->getContext().getConstantInt(Type::Int32Ty, 1); + Value *One = ConstantInt::get(Type::Int32Ty, 1); // Get pointers to the integer argument of the add1 function... assert(Add1F->arg_begin() != Add1F->arg_end()); // Make sure there's an arg @@ -72,8 +72,8 @@ static Function *CreateFibFunction(Module *M) { BasicBlock *BB = BasicBlock::Create("EntryBlock", FibF); // Get pointers to the constants. - Value *One = M->getContext().getConstantInt(Type::Int32Ty, 1); - Value *Two = M->getContext().getConstantInt(Type::Int32Ty, 2); + Value *One = ConstantInt::get(Type::Int32Ty, 1); + Value *Two = ConstantInt::get(Type::Int32Ty, 2); // Get pointer to the integer argument of the add1 function... Argument *ArgX = FibF->arg_begin(); // Get the arg. diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h index f9fd636e3a..d59621a453 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 a2fa569ce5..73d88984c1 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 835a28622f..ac134ec303 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); } diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp index 49d771a42d..ed78c7ea46 100644 --- a/lib/Analysis/BasicAliasAnalysis.cpp +++ b/lib/Analysis/BasicAliasAnalysis.cpp @@ -780,10 +780,10 @@ BasicAliasAnalysis::CheckGEPInstructions( // if (const ArrayType *AT = dyn_cast<ArrayType>(BasePtr1Ty)) GEP1Ops[i] = - Context.getConstantInt(Type::Int64Ty,AT->getNumElements()-1); + ConstantInt::get(Type::Int64Ty,AT->getNumElements()-1); else if (const VectorType *VT = dyn_cast<VectorType>(BasePtr1Ty)) GEP1Ops[i] = - Context.getConstantInt(Type::Int64Ty,VT->getNumElements()-1); + ConstantInt::get(Type::Int64Ty,VT->getNumElements()-1); } } diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index d60b4f6800..7ac8b97768 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -113,7 +113,7 @@ static Constant *SymbolicallyEvaluateBinop(unsigned Opc, Constant *Op0, if (IsConstantOffsetFromGlobal(Op1, GV2, Offs2, *TD) && GV1 == GV2) { // (&GV+C1) - (&GV+C2) -> C1-C2, pointer arithmetic cannot overflow. - return Context.getConstantInt(Op0->getType(), Offs1-Offs2); + return ConstantInt::get(Op0->getType(), Offs1-Offs2); } } @@ -151,7 +151,7 @@ static Constant *SymbolicallyEvaluateGEP(Constant* const* Ops, unsigned NumOps, uint64_t Offset = TD->getIndexedOffset(Ptr->getType(), (Value**)Ops+1, NumOps-1); - Constant *C = Context.getConstantInt(TD->getIntPtrType(), Offset+BasePtr); + Constant *C = ConstantInt::get(TD->getIntPtrType(), Offset+BasePtr); return Context.getConstantExprIntToPtr(C, ResultTy); } @@ -232,7 +232,7 @@ static Constant *FoldBitCast(Constant *C, const Type *DestTy, // Shift it to the right place, depending on endianness. Src = Context.getConstantExprShl(Src, - Context.getConstantInt(Src->getType(), ShiftAmt)); + ConstantInt::get(Src->getType(), ShiftAmt)); ShiftAmt += isLittleEndian ? SrcBitSize : -SrcBitSize; // Mix it in. @@ -255,7 +255,7 @@ static Constant *FoldBitCast(Constant *C, const Type *DestTy, // Shift the piece of the value into the right place, depending on // endianness. Constant *Elt = Context.getConstantExprLShr(Src, - Context.getConstantInt(Src->getType(), ShiftAmt)); + ConstantInt::get(Src->getType(), ShiftAmt)); ShiftAmt += isLittleEndian ? DstBitSize : -DstBitSize; // Truncate and remember this piece. @@ -376,7 +376,7 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy, unsigned InWidth = Input->getType()->getScalarSizeInBits(); if (TD->getPointerSizeInBits() < InWidth) { Constant *Mask = - Context.getConstantInt(APInt::getLowBitsSet(InWidth, + ConstantInt::get(Context, APInt::getLowBitsSet(InWidth, TD->getPointerSizeInBits())); Input = Context.getConstantExprAnd(Input, Mask); } @@ -420,7 +420,7 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy, AT->getNumElements()))) { Constant *Index[] = { Context.getNullValue(CE->getType()), - Context.getConstantInt(ElemIdx) + ConstantInt::get(Context, ElemIdx) }; return Context.getConstantExprGetElementPtr(GV, &Index[0], 2); @@ -801,13 +801,13 @@ llvm::ConstantFoldCall(Function *F, } } else if (ConstantInt *Op = dyn_cast<ConstantInt>(Operands[0])) { if (Len > 11 && !memcmp(Str, "llvm.bswap", 10)) - return Context.getConstantInt(Op->getValue().byteSwap()); + return ConstantInt::get(Context, Op->getValue().byteSwap()); else if (Len > 11 && !memcmp(Str, "llvm.ctpop", 10)) - return Context.getConstantInt(Ty, Op->getValue().countPopulation()); + return ConstantInt::get(Ty, Op->getValue().countPopulation()); else if (Len > 10 && !memcmp(Str, "llvm.cttz", 9)) - return Context.getConstantInt(Ty, Op->getValue().countTrailingZeros()); + return ConstantInt::get(Ty, Op->getValue().countTrailingZeros()); else if (Len > 10 && !memcmp(Str, "llvm.ctlz", 9)) - return Context.getConstantInt(Ty, Op->getValue().countLeadingZeros()); + return ConstantInt::get(Ty, Op->getValue().countLeadingZeros()); } } else if (NumOperands == 2) { if (ConstantFP *Op1 = dyn_cast<ConstantFP>(Operands[0])) { diff --git a/lib/Analysis/DebugInfo.cpp b/lib/Analysis/DebugInfo.cpp index f1ad08aefa..aded6d8eee 100644 --- a/lib/Analysis/DebugInfo.cpp +++ b/lib/Analysis/DebugInfo.cpp @@ -482,7 +482,7 @@ Constant *DIFactory::getCastToEmpty(DIDescriptor D) { Constant *DIFactory::GetTagConstant(unsigned TAG) { assert((TAG & LLVMDebugVersionMask) == 0 && "Tag too large for debug encoding!"); - return VMContext.getConstantInt(Type::Int32Ty, TAG | LLVMDebugVersion); + return ConstantInt::get(Type::Int32Ty, TAG | LLVMDebugVersion); } Constant *DIFactory::GetStringConstant(const std::string &String) { @@ -541,8 +541,8 |