summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-07-14 23:09:55 +0000
committerOwen Anderson <resistor@mac.com>2009-07-14 23:09:55 +0000
commit9adc0abad3c3ed40a268ccbcee0c74cb9e1359fe (patch)
treef15d2aa3fea09947494a5d0bb36583dbe3be000a
parenta89b7ea9d6819606eea3ba945913127a212b836f (diff)
downloadllvm-9adc0abad3c3ed40a268ccbcee0c74cb9e1359fe.tar.gz
llvm-9adc0abad3c3ed40a268ccbcee0c74cb9e1359fe.tar.bz2
llvm-9adc0abad3c3ed40a268ccbcee0c74cb9e1359fe.tar.xz
Move EVER MORE stuff over to LLVMContext.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75703 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--examples/BrainF/BrainF.cpp33
-rw-r--r--examples/BrainF/BrainF.h3
-rw-r--r--examples/Fibonacci/fibonacci.cpp8
-rw-r--r--examples/HowToUseJIT/HowToUseJIT.cpp4
-rw-r--r--examples/ModuleMaker/ModuleMaker.cpp7
-rw-r--r--examples/ParallelJIT/ParallelJIT.cpp6
-rw-r--r--include/llvm/Constants.h37
-rw-r--r--include/llvm/Instructions.h104
-rw-r--r--include/llvm/LLVMContext.h28
-rw-r--r--include/llvm/Support/IRBuilder.h4
-rw-r--r--include/llvm/Transforms/Utils/Local.h7
-rw-r--r--lib/Analysis/ScalarEvolution.cpp9
-rw-r--r--lib/AsmParser/LLParser.cpp4
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp6
-rw-r--r--lib/CodeGen/DwarfEHPrepare.cpp3
-rw-r--r--lib/CodeGen/IntrinsicLowering.cpp83
-rw-r--r--lib/CodeGen/SelectionDAG/LegalizeDAG.cpp3
-rw-r--r--lib/CodeGen/ShadowStackGC.cpp56
-rw-r--r--lib/CodeGen/StackProtector.cpp2
-rw-r--r--lib/ExecutionEngine/JIT/JIT.cpp18
-rw-r--r--lib/Target/ARM/ARMBaseRegisterInfo.cpp5
-rw-r--r--lib/Target/ARM/ARMISelDAGToDAG.cpp4
-rw-r--r--lib/Target/ARM/Thumb1RegisterInfo.cpp5
-rw-r--r--lib/Target/ARM/Thumb2RegisterInfo.cpp5
-rw-r--r--lib/Target/Alpha/AlphaISelDAGToDAG.cpp3
-rw-r--r--lib/Target/CBackend/CBackend.cpp2
-rw-r--r--lib/Target/XCore/XCoreISelDAGToDAG.cpp4
-rw-r--r--lib/Transforms/IPO/ArgumentPromotion.cpp2
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp9
-rw-r--r--lib/Transforms/IPO/IndMemRemoval.cpp8
-rw-r--r--lib/Transforms/IPO/LowerSetJmp.cpp4
-rw-r--r--lib/Transforms/IPO/RaiseAllocations.cpp3
-rw-r--r--lib/Transforms/IPO/StructRetPromotion.cpp2
-rw-r--r--lib/Transforms/Instrumentation/RSProfiling.cpp2
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp28
-rw-r--r--lib/Transforms/Scalar/JumpThreading.cpp2
-rw-r--r--lib/Transforms/Scalar/LICM.cpp5
-rw-r--r--lib/Transforms/Scalar/PredicateSimplifier.cpp2
-rw-r--r--lib/Transforms/Scalar/Reg2Mem.cpp4
-rw-r--r--lib/Transforms/Scalar/ScalarReplAggregates.cpp11
-rw-r--r--lib/Transforms/Scalar/TailDuplication.cpp2
-rw-r--r--lib/Transforms/Utils/CodeExtractor.cpp5
-rw-r--r--lib/Transforms/Utils/DemoteRegToStack.cpp16
-rw-r--r--lib/Transforms/Utils/InlineFunction.cpp5
-rw-r--r--lib/Transforms/Utils/LowerInvoke.cpp24
-rw-r--r--lib/VMCore/Constants.cpp53
-rw-r--r--lib/VMCore/Instructions.cpp94
-rw-r--r--lib/VMCore/LLVMContext.cpp49
-rw-r--r--tools/bugpoint/ExtractFunction.cpp9
-rw-r--r--tools/bugpoint/Miscompilation.cpp20
-rw-r--r--unittests/ExecutionEngine/JIT/JITTest.cpp6
-rw-r--r--unittests/Support/ValueHandleTest.cpp5
-rw-r--r--unittests/VMCore/MetadataTest.cpp34
53 files changed, 422 insertions, 435 deletions
diff --git a/examples/BrainF/BrainF.cpp b/examples/BrainF/BrainF.cpp
index 38914688ec..4969a55a66 100644
--- a/examples/BrainF/BrainF.cpp
+++ b/examples/BrainF/BrainF.cpp
@@ -43,7 +43,7 @@ Module *BrainF::parse(std::istream *in1, int mem, CompileFlags cf,
comflag = cf;
header(Context);
- readloop(0, 0, 0);
+ readloop(0, 0, 0, Context);
delete builder;
return module;
}
@@ -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 = ConstantInt::get(APInt(32, memtotal));
+ ConstantInt *val_mem = C.getConstantInt(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,
- ConstantInt::get(APInt(8, 0)),
+ C.getConstantInt(APInt(8, 0)),
val_mem,
- ConstantInt::get(APInt(32, 1))
+ C.getConstantInt(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, ConstantInt::get(APInt(32, memtotal)), "arrmax");
+ CreateGEP(ptr_arr, C.getConstantInt(APInt(32, memtotal)), "arrmax");
}
//%head.%d = getelementptr i8 *%arr, i32 %d
curhead = builder->CreateGEP(ptr_arr,
- ConstantInt::get(APInt(32, memtotal/2)),
+ C.getConstantInt(APInt(32, memtotal/2)),
headreg);
@@ -124,8 +124,8 @@ void BrainF::header(LLVMContext& C) {
if (comflag & flag_arraybounds)
{
//@aberrormsg = internal constant [%d x i8] c"\00"
- Constant *msg_0 = ConstantArray::
- get("Error: The head has left the tape.", true);
+ Constant *msg_0 =
+ C.getConstantArray("Error: The head has left the tape.", true);
GlobalVariable *aberrormsg = new GlobalVariable(
*module,
@@ -138,7 +138,7 @@ void BrainF::header(LLVMContext& C) {
//declare i32 @puts(i8 *)
Function *puts_func = cast<Function>(module->
getOrInsertFunction("puts", IntegerType::Int32Ty,
- PointerType::getUnqual(IntegerType::Int8Ty), NULL));
+ C.getPointerTypeUnqual(IntegerType::Int8Ty), NULL));
//brainf.aberror:
aberrorbb = BasicBlock::Create(label, brainf_func);
@@ -172,7 +172,8 @@ void BrainF::header(LLVMContext& C) {
}
}
-void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) {
+void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb,
+ LLVMContext &C) {
Symbol cursym = SYM_NONE;
int curvalue = 0;
Symbol nextsym = SYM_NONE;
@@ -228,7 +229,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) {
{
//%head.%d = getelementptr i8 *%head.%d, i32 %d
curhead = builder->
- CreateGEP(curhead, ConstantInt::get(APInt(32, curvalue)),
+ CreateGEP(curhead, C.getConstantInt(APInt(32, curvalue)),
headreg);
//Error block for array out of bounds
@@ -263,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, ConstantInt::get(APInt(8, curvalue)), tapereg);
+ CreateAdd(tape_0, C.getConstantInt(APInt(8, curvalue)), tapereg);
//store i8 %tape.%d, i8 *%head.%d\n"
builder->CreateStore(tape_1, curhead);
@@ -283,13 +284,13 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) {
// Make part of PHI instruction now, wait until end of loop to finish
PHINode *phi_0 =
- PHINode::Create(PointerType::getUnqual(IntegerType::Int8Ty),
+ PHINode::Create(C.getPointerTypeUnqual(IntegerType::Int8Ty),
headreg, testbb);
phi_0->reserveOperandSpace(2);
phi_0->addIncoming(curhead, bb_0);
curhead = phi_0;
- readloop(phi_0, bb_1, testbb);
+ readloop(phi_0, bb_1, testbb, C);
}
break;
@@ -428,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,
- ConstantInt::get(APInt(8, 0)), testreg);
+ C.getConstantInt(APInt(8, 0)), testreg);
//br i1 %test.%d, label %main.%d, label %main.%d
BasicBlock *bb_0 = BasicBlock::Create(label, brainf_func);
@@ -439,7 +440,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) {
//%head.%d = phi i8 *[%head.%d, %main.%d]
PHINode *phi_1 = builder->
- CreatePHI(PointerType::getUnqual(IntegerType::Int8Ty), headreg);
+ CreatePHI(C.getPointerTypeUnqual(IntegerType::Int8Ty), headreg);
phi_1->reserveOperandSpace(1);
phi_1->addIncoming(head_0, testbb);
curhead = phi_1;
diff --git a/examples/BrainF/BrainF.h b/examples/BrainF/BrainF.h
index 053ddaa587..add0687d54 100644
--- a/examples/BrainF/BrainF.h
+++ b/examples/BrainF/BrainF.h
@@ -70,7 +70,8 @@ class BrainF {
/// The main loop for parsing. It calls itself recursively
/// to handle the depth of nesting of "[]".
- void readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb);
+ void readloop(PHINode *phi, BasicBlock *oldbb,
+ BasicBlock *testbb, LLVMContext &Context);
/// Constants during parsing
int memtotal;
diff --git a/examples/Fibonacci/fibonacci.cpp b/examples/Fibonacci/fibonacci.cpp
index 89f3ef2d75..d637d4dea1 100644
--- a/examples/Fibonacci/fibonacci.cpp
+++ b/examples/Fibonacci/fibonacci.cpp
@@ -36,7 +36,7 @@
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
-static Function *CreateFibFunction(Module *M) {
+static Function *CreateFibFunction(Module *M, LLVMContext &Context) {
// Create the fib function and insert it into module M. This function is said
// to return an int and take an int parameter.
Function *FibF =
@@ -47,8 +47,8 @@ static Function *CreateFibFunction(Module *M) {
BasicBlock *BB = BasicBlock::Create("EntryBlock", FibF);
// Get pointers to the constants.
- Value *One = ConstantInt::get(Type::Int32Ty, 1);
- Value *Two = ConstantInt::get(Type::Int32Ty, 2);
+ Value *One = Context.getConstantInt(Type::Int32Ty, 1);
+ Value *Two = Context.getConstantInt(Type::Int32Ty, 2);
// Get pointer to the integer argument of the add1 function...
Argument *ArgX = FibF->arg_begin(); // Get the arg.
@@ -97,7 +97,7 @@ int main(int argc, char **argv) {
Module *M = new Module("test", Context);
// We are about to create the "fib" function:
- Function *FibF = CreateFibFunction(M);
+ Function *FibF = CreateFibFunction(M, Context);
// Now we going to create JIT
ExistingModuleProvider *MP = new ExistingModuleProvider(M);
diff --git a/examples/HowToUseJIT/HowToUseJIT.cpp b/examples/HowToUseJIT/HowToUseJIT.cpp
index 6734547916..6d43cb47ce 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 = ConstantInt::get(Type::Int32Ty, 1);
+ Value *One = Context.getConstantInt(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 = ConstantInt::get(Type::Int32Ty, 10);
+ Value *Ten = Context.getConstantInt(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 59a86d031d..537ee341dc 100644
--- a/examples/ModuleMaker/ModuleMaker.cpp
+++ b/examples/ModuleMaker/ModuleMaker.cpp
@@ -30,7 +30,8 @@ int main() {
Module *M = new Module("test", Context);
// Create the main function: first create the type 'int ()'
- FunctionType *FT = FunctionType::get(Type::Int32Ty, /*not vararg*/false);
+ FunctionType *FT =
+ Context.getFunctionType(Type::Int32Ty, /*not vararg*/false);
// By passing a module as the last parameter to the Function constructor,
// it automatically gets appended to the Module.
@@ -41,8 +42,8 @@ int main() {
BasicBlock *BB = BasicBlock::Create("EntryBlock", F);
// Get pointers to the constant integers...
- Value *Two = ConstantInt::get(Type::Int32Ty, 2);
- Value *Three = ConstantInt::get(Type::Int32Ty, 3);
+ Value *Two = Context.getConstantInt(Type::Int32Ty, 2);
+ Value *Three = Context.getConstantInt(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 e80dc4986a..d82a6be81d 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 = ConstantInt::get(Type::Int32Ty, 1);
+ Value *One = M->getContext().getConstantInt(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 = ConstantInt::get(Type::Int32Ty, 1);
- Value *Two = ConstantInt::get(Type::Int32Ty, 2);
+ Value *One = M->getContext().getConstantInt(Type::Int32Ty, 1);
+ Value *Two = M->getContext().getConstantInt(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 448a87e770..27e225bc37 100644
--- a/include/llvm/Constants.h
+++ b/include/llvm/Constants.h
@@ -102,39 +102,10 @@ public:
return CreateTrueFalseVals(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);
-
- /// 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 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) {
- return get(Ty, V, true);
- }
- static Constant *getSigned(const Type *Ty, int64_t V) {
- return get(Ty, V, true);
- }
-
/// 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(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);
-
/// getType - Specialize the getType() method to always return an IntegerType,
/// which reduces the amount of casting needed in parts of the compiler.
///
@@ -348,14 +319,6 @@ public:
return get(T, std::vector<Constant*>(Vals, Vals+NumVals));
}
- /// 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);
-
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h
index 5bd3066ef9..b20ac18f41 100644
--- a/include/llvm/Instructions.h
+++ b/include/llvm/Instructions.h
@@ -29,6 +29,7 @@ namespace llvm {
class ConstantInt;
class ConstantRange;
class APInt;
+class LLVMContext;
//===----------------------------------------------------------------------===//
// AllocationInst Class
@@ -39,10 +40,14 @@ class APInt;
///
class AllocationInst : public UnaryInstruction {
protected:
- AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
- const std::string &Name = "", Instruction *InsertBefore = 0);
- AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
- const std::string &Name, BasicBlock *InsertAtEnd);
+ LLVMContext &Context;
+
+ AllocationInst(LLVMContext &Context, const Type *Ty, Value *ArraySize,
+ unsigned iTy, unsigned Align, const std::string &Name = "",
+ Instruction *InsertBefore = 0);
+ AllocationInst(LLVMContext &Context, const Type *Ty, Value *ArraySize,
+ unsigned iTy, unsigned Align, const std::string &Name,
+ BasicBlock *InsertAtEnd);
public:
// Out of line virtual method, so the vtable, etc. has a home.
virtual ~AllocationInst();
@@ -98,28 +103,33 @@ public:
class MallocInst : public AllocationInst {
MallocInst(const MallocInst &MI);
public:
- explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
+ explicit MallocInst(LLVMContext &Context,
+ const Type *Ty, Value *ArraySize = 0,
const std::string &NameStr = "",
Instruction *InsertBefore = 0)
- : AllocationInst(Ty, ArraySize, Malloc, 0, NameStr, InsertBefore) {}
- MallocInst(const Type *Ty, Value *ArraySize, const std::string &NameStr,
- BasicBlock *InsertAtEnd)
- : AllocationInst(Ty, ArraySize, Malloc, 0, NameStr, InsertAtEnd) {}
+ : AllocationInst(Context, Ty, ArraySize, Malloc,
+ 0, NameStr, InsertBefore) {}
+ MallocInst(LLVMContext &Context, const Type *Ty, Value *ArraySize,
+ const std::string &NameStr, BasicBlock *InsertAtEnd)
+ : AllocationInst(Context, Ty, ArraySize, Malloc, 0, NameStr, InsertAtEnd) {}
- MallocInst(const Type *Ty, const std::string &NameStr,
+ MallocInst(LLVMContext &Context, const Type *Ty, const std::string &NameStr,
Instruction *InsertBefore = 0)
- : AllocationInst(Ty, 0, Malloc, 0, NameStr, InsertBefore) {}
- MallocInst(const Type *Ty, const std::string &NameStr,
+ : AllocationInst(Context, Ty, 0, Malloc, 0, NameStr, InsertBefore) {}
+ MallocInst(LLVMContext &Context, const Type *Ty, const std::string &NameStr,
BasicBlock *InsertAtEnd)
- : AllocationInst(Ty, 0, Malloc, 0, NameStr, InsertAtEnd) {}
+ : AllocationInst(Context, Ty, 0, Malloc, 0, NameStr, InsertAtEnd) {}
- MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
- const std::string &NameStr, BasicBlock *InsertAtEnd)
- : AllocationInst(Ty, ArraySize, Malloc, Align, NameStr, InsertAtEnd) {}
- MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
- const std::string &NameStr = "",
- Instruction *InsertBefore = 0)
- : AllocationInst(Ty, ArraySize, Malloc, Align, NameStr, InsertBefore) {}
+ MallocInst(LLVMContext &Context, const Type *Ty, Value *ArraySize,
+ unsigned Align, const std::string &NameStr,
+ BasicBlock *InsertAtEnd)
+ : AllocationInst(Context, Ty, ArraySize, Malloc,
+ Align, NameStr, InsertAtEnd) {}
+ MallocInst(LLVMContext &Context, const Type *Ty, Value *ArraySize,
+ unsigned Align, const std::string &NameStr = "",
+ Instruction *InsertBefore = 0)
+ : AllocationInst(Context, Ty, ArraySize,
+ Malloc, Align, NameStr, InsertBefore) {}
virtual MallocInst *clone(LLVMContext &Context) const;
@@ -143,27 +153,34 @@ public:
class AllocaInst : public AllocationInst {
AllocaInst(const AllocaInst &);
public:
- explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
+ explicit AllocaInst(LLVMContext &Context, const Type *Ty,
+ Value *ArraySize = 0,
const std::string &NameStr = "",
Instruction *InsertBefore = 0)
- : AllocationInst(Ty, ArraySize, Alloca, 0, NameStr, InsertBefore) {}
- AllocaInst(const Type *Ty, Value *ArraySize, const std::string &NameStr,
+ : AllocationInst(Context, Ty, ArraySize, Alloca,
+ 0, NameStr, InsertBefore) {}
+ AllocaInst(LLVMContext &Context, const Type *Ty,
+ Value *ArraySize, const std::string &NameStr,
BasicBlock *InsertAtEnd)
- : AllocationInst(Ty, ArraySize, Alloca, 0, NameStr, InsertAtEnd) {}
+ : AllocationInst(Context, Ty, ArraySize, Alloca, 0, NameStr, InsertAtEnd) {}
- AllocaInst(const Type *Ty, const std::string &NameStr,
+ AllocaInst(LLVMContext &Context, const Type *Ty, const std::string &NameStr,
Instruction *InsertBefore = 0)
- : AllocationInst(Ty, 0, Alloca, 0, NameStr, InsertBefore) {}
- AllocaInst(const Type *Ty, const std::string &NameStr,
+ : AllocationInst(Context, Ty, 0, Alloca, 0, NameStr, InsertBefore) {}
+ AllocaInst(LLVMContext &Context, const Type *Ty, const std::string &NameStr,
BasicBlock *InsertAtEnd)
- : AllocationInst(Ty, 0, Alloca, 0, NameStr, InsertAtEnd) {}
+ : AllocationInst(Context, Ty, 0, Alloca, 0, NameStr, InsertAtEnd) {}
- AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
- const std::string &NameStr = "", Instruction *InsertBefore = 0)
- : AllocationInst(Ty, ArraySize, Alloca, Align, NameStr, InsertBefore) {}
- AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
- const std::string &NameStr, BasicBlock *InsertAtEnd)
- : AllocationInst(Ty, ArraySize, Alloca, Align, NameStr, InsertAtEnd) {}
+ AllocaInst(LLVMContext &Context, const Type *Ty, Value *ArraySize,
+ unsigned Align, const std::string &NameStr = "",
+ Instruction *InsertBefore = 0)
+ : AllocationInst(Context, Ty, ArraySize, Alloca,
+ Align, NameStr, InsertBefore) {}
+ AllocaInst(LLVMContext &Context, const Type *Ty, Value *ArraySize,
+ unsigned Align, const std::string &NameStr,
+ BasicBlock *InsertAtEnd)
+ : AllocationInst(Context, Ty, ArraySize, Alloca,
+ Align, NameStr, InsertAtEnd) {}
virtual AllocaInst *clone(LLVMContext &Context) const;
@@ -1266,12 +1283,8 @@ public:
}
ExtractElementInst(Value *Vec, Value *Idx, const std::string &NameStr = "",
Instruction *InsertBefore = 0);
- ExtractElementInst(Value *Vec, unsigned Idx, const std::string &NameStr = "",
- Instruction *InsertBefore = 0);
ExtractElementInst(Value *Vec, Value *Idx, const std::string &NameStr,
BasicBlock *InsertAtEnd);
- ExtractElementInst(Value *Vec, unsigned Idx, const std::string &NameStr,
- BasicBlock *InsertAtEnd);
/// isValidOperands - Return true if an extractelement instruction can be
/// formed with the specified operands.
@@ -1310,13 +1323,8 @@ class InsertElementInst : public Instruction {
InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
const std::string &NameStr = "",
Instruction *InsertBefore = 0);
- InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
- const std::string &NameStr = "",
- Instruction *InsertBefore = 0);
InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
const std::string &NameStr, BasicBlock *InsertAtEnd);
- InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
- const std::string &NameStr, BasicBlock *InsertAtEnd);
public:
static InsertElementInst *Create(const InsertElementInst &IE) {
return new(IE.getNumOperands()) InsertElementInst(IE);
@@ -1326,21 +1334,11 @@ public:
Instruction *InsertBefore = 0) {
return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
}
- static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
- const std::string &NameStr = "",
- Instruction *InsertBefore = 0) {
- return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
- }
static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
const std::string &NameStr,
BasicBlock *InsertAtEnd) {
return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
}
- static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
- const std::string &NameStr,
- BasicBlock *InsertAtEnd) {
- return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
- }
/// isValidOperands - Return true if an insertelement instruction can be
/// formed with the specified operands.
diff --git a/include/llvm/LLVMContext.h b/include/llvm/LLVMContext.h
index e71183855a..552e7992c6 100644
--- a/include/llvm/LLVMContext.h
+++ b/include/llvm/LLVMContext.h
@@ -70,12 +70,33 @@ public:
// ConstantInt accessors
ConstantInt* getConstantIntTrue();
ConstantInt* getConstantIntFalse();
+
+ /// 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);
+
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
@@ -97,6 +118,13 @@ public:
const std::vector<Constant*>& V);
Constant* getConstantArray(const ArrayType* T, Constant* const* Vals,
unsigned NumVals);
+
+ /// 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.
Constant* getConstantArray(const std::string& Initializer,
bool AddNull = true);
diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h
index 2ef13a789f..cd0e1826b0 100644
--- a/include/llvm/Support/IRBuilder.h
+++ b/include/llvm/Support/IRBuilder.h
@@ -330,11 +330,11 @@ public:
MallocInst *CreateMalloc(const Type *Ty, Value *ArraySize = 0,
const char *Name = "") {
- return Insert(new MallocInst(Ty, ArraySize), Name);
+ return Insert(new MallocInst(Context, Ty, ArraySize), Name);
}
AllocaInst *CreateAlloca(const Type *Ty, Value *ArraySize = 0,
const char *Name = "") {
- return Insert(new AllocaInst(Ty, ArraySize), Name);
+ return Insert(new AllocaInst(Context, Ty, ArraySize), Name);
}
FreeInst *CreateFree(Value *Ptr) {
return Insert(new FreeInst(Ptr));
diff --git a/include/llvm/Transforms/Utils/Local.h b/include/llvm/Transforms/Utils/Local.h
index dd423fa3b1..35f2a69f47 100644
--- a/include/llvm/Transforms/Utils/Local.h
+++ b/include/llvm/Transforms/Utils/Local.h
@@ -27,6 +27,7 @@ class PHINode;
class AllocaInst;
class ConstantExpr;
class TargetData;
+class LLVMContext;
struct DbgInfoIntrinsic;
template<typename T> class SmallVectorImpl;
@@ -107,13 +108,15 @@ bool FoldBranchToCommonDest(BranchInst *BI);
/// invalidating the SSA information for the value. It returns the pointer to
/// the alloca inserted to create a stack slot for X.
///
-AllocaInst *DemoteRegToStack(Instruction &X, bool VolatileLoads = false,
+AllocaInst *DemoteRegToStack(LLVMContext &Context, Instruction &X,
+ bool VolatileLoads = false,
Instruction *AllocaPoint = 0);
/// DemotePHIToStack - This function takes a virtual register computed by a phi
/// node and replaces it with a slot in the stack frame, allocated via alloca.
/// The phi node is deleted and it returns the pointer to the alloca inserted.
-AllocaInst *DemotePHIToStack(PHINode *P, Instruction *AllocaPoint = 0);
+AllocaInst *DemotePHIToStack(LLVMContext &Context, PHINode *P,
+ Instruction *AllocaPoint = 0);
/// OnlyUsedByDbgIntrinsics - Return true if the instruction I is only used
/// by DbgIntrinsics. If DbgInUses is specified then the vector is filled
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp
index 0c17f14892..7c68f8920e 100644
--- a/lib/Analysis/ScalarEvolution.cpp
+++ b/lib/Analysis/ScalarEvolution.cpp
@@ -196,7 +196,8 @@ const SCEV *ScalarEvolution::getConstant(const APInt& Val) {
const SCEV *
ScalarEvolution::getConstant(const Type *Ty, uint64_t V, bool isSigned) {
- return getConstant(ConstantInt::get(cast<IntegerType>(Ty), V, isSigned));
+ return getConstant(
+ Context->getConstantInt(cast<IntegerType>(Ty), V, isSigned));
}
const Type *SCEVConstant::getType() const { return V->getType(); }
@@ -2115,7 +2116,7 @@ const SCEV *ScalarEvolution::getSCEV(Value *V) {
/// specified signed integer value and return a SCEV for the constant.
const SCEV *ScalarEvolution::getIntegerSCEV(int Val, const Type *Ty) {
const IntegerType *ITy = cast<IntegerType>(getEffectiveSCEVType(Ty));
- return getConstant(ConstantInt::get(ITy, Val));
+ return getConstant(Context->getConstantInt(ITy, Val));
}
/// getNegativeSCEV - Return a SCEV corresponding to -V = -1*V
@@ -3537,8 +3538,8 @@ ScalarEvolution::ComputeLoadConstantCompareBackedgeTakenCount(
unsigned MaxSteps = MaxBruteForceIterations;
for (unsigned IterationNum = 0; IterationNum != MaxSteps; ++IterationNum) {
- ConstantInt *ItCst =
- ConstantInt::get(cast<IntegerType>(IdxExpr->getType()), IterationNum);
+ ConstantInt *ItCst = Context->getConstantInt(
+ cast<IntegerType>(IdxExpr->getType()), IterationNum);
ConstantInt *Val = EvaluateConstantChrecAtConstant(IdxExpr, ItCst, *this);
// Form the GEP offset.
diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp
index 080575df84..1c8156adcf 100644
--- a/lib/AsmParser/LLParser.cpp
+++ b/lib/AsmParser/LLParser.cpp
@@ -3182,9 +3182,9 @@ bool LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS,
return Error(SizeLoc, "element count must be i32");
if (Opc == Instruction::Malloc)
- Inst = new MallocInst(Ty, Size, Alignment);
+ Inst = new MallocInst(Context, Ty, Size, Alignment);
else
- Inst = new AllocaInst(Ty, Size, Alignment);
+ Inst = new AllocaInst(Context, Ty, Size, Alignment);
return false;
}
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index e4d3c5e1ad..b15355a8ca 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1817,7 +1817,8 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
Value *Size = getFnValueByID(Record[1], Type::Int32Ty);
unsigned Align = Record[2];
if (!Ty || !Size) return Error("Invalid MALLOC record");
- I = new MallocInst(Ty->getElementType(), Size, (1 << Align) >> 1);
+ I = new MallocInst(Context, Ty->getElementType(), Size,
+ (1 << Align) >> 1);
break;
}
case bitc::FUNC_CODE_INST_FREE: { // FREE: [op, opty]
@@ -1837,7 +1838,8 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
Value *Size = getFnValueByID(Record[1], Type::Int32Ty);
unsigned Align = Record[2];
if (!Ty || !Size) return Error("Invalid ALLOCA record");
- I = new AllocaInst(Ty->getElementType(), Size, (1 << Align) >> 1);
+ I = new AllocaInst(Context, Ty->getElementType(), Size,
+ (1 << Align) >> 1);
break;
}
case bitc::FUNC_CODE_INST_LOAD: { // LOAD: [opty, op, align, vol]
diff --git a/lib/CodeGen/DwarfEHPrepare.cpp b/lib/CodeGen/DwarfEHPrepare.cpp
index 4ef43fde50..5fa8dcea34 100644
--- a/lib/CodeGen/DwarfEHPrepare.cpp
+++ b/lib/CodeGen/DwarfEHPrepare.cpp
@@ -354,7 +354,8 @@ Instruction *DwarfEHPrepare::CreateValueLoad(BasicBlock *BB) {
// Create the temporary if we didn't already.
if (!ExceptionValueVar) {
- ExceptionValueVar = new AllocaInst(PointerType::getUnqual(Type::Int8Ty),
+ ExceptionValueVar = new AllocaInst(*Context,
+ PointerType::getUnqual(Type::Int8Ty),
"eh.value", F->begin()->begin());
++NumStackTempsIntroduced;
}
diff --git a/lib/CodeGen/IntrinsicLowering.cpp b/lib/CodeGen/IntrinsicLowering.cpp
index 6ec3a629fb..455adc44a1 100644
--- a/lib/CodeGen/IntrinsicLowering.cpp
+++ b/lib/CodeGen/IntrinsicLowering.cpp
@@ -149,7 +149,7 @@ void IntrinsicLowering::AddPrototypes(Module &M) {
/// LowerBSWAP - Emit the code to lower bswap of V before the specified
/// instruction IP.
-static Value *LowerBSWAP(Value *V, Instruction *IP) {
+static Value *LowerBSWAP(LLVMContext &Context, Value *V, Instruction *IP) {
assert(V->getType()->isInteger() && "Can't bswap a non-integer type!");
unsigned BitSize = V->getType()->getPrimitiveSizeInBits();
@@ -159,25 +159,27 @@ static Value *LowerBSWAP(Value *V, Instruction *IP) {
switch(BitSize) {
default: llvm_unreachable("Unhandled type size of value to byteswap!");
case 16: {
- Value *Tmp1 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8),
+ Value *Tmp1 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 8),
"bswap.2");
- Value *Tmp2 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8),
+ Value *Tmp2 = Builder.CreateLShr(V, Context.getConstantInt(V->getType(), 8),
"bswap.1");
V = Builder.CreateOr(Tmp1, Tmp2, "bswap.i16");
break;
}
case 32: {
- Value *Tmp4 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 24),
+ Value *Tmp4 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 24),
"bswap.4");
- Value *Tmp3 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8),
+ Value *Tmp3 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 8),
"bswap.3");
- Value *Tmp2 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8),
+ Value *Tmp2 = Builder.CreateLShr(V, Context.getConstantInt(V->getType(), 8),
"bswap.2");
- Value *Tmp1 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 24),
+ Value *Tmp1 = Builder.CreateLShr(V,Context.getConstantInt(V->getType(), 24),
"bswap.1");
- Tmp3 = Builder.CreateAnd(Tmp3, ConstantInt::get(Type::Int32Ty, 0xFF0000),
+ Tmp3 = Builder.CreateAnd(Tmp3,
+ Context.getConstantInt(Type::Int32Ty, 0xFF0000),
"bswap.and3");
- Tmp2 = Builder.CreateAnd(Tmp2, ConstantInt::get(Type::Int32Ty, 0xFF00),
+ Tmp2 = Builder.CreateAnd(Tmp2,
+ Context.getConstantInt(Type::Int32Ty, 0xFF00),
"bswap.and2");
Tmp4 = Builder.CreateOr(Tmp4, Tmp3, "bswap.or1");
Tmp2 = Builder.CreateOr(Tmp2, Tmp1, "bswap.or2");
@@ -185,41 +187,44 @@ static Value *LowerBSWAP(Value *V, Instruction *IP) {
break;
}
case 64: {
- Value *Tmp8 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 56),
+ Value *Tmp8 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 56),
"bswap.8");
- Value *Tmp7 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 40),
+ Value *Tmp7 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 40),
"bswap.7");
- Value *Tmp6 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 24),
+ Value *Tmp6 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 24),
"bswap.6");
- Value *Tmp5 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8),
+ Value *Tmp5 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 8),
"bswap.5");
- Value* Tmp4 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8),
+ Value* Tmp4 = Builder.CreateLShr(V, Context.getConstantInt(V->getType(), 8),
"bswap.4");
- Value* Tmp3 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 24),
+ Value* Tmp3 = Builder.CreateLShr(V,
+ Context.getConstantInt(V->getType(), 24),
"bswap.3");
- Value* Tmp2 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 40),
+ Value* Tmp2 = Builder.CreateLShr(V,
+ Context.getConstantInt(V->getType(), 40),
"bswap.2");
- Value* Tmp1 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 56),
+ Value* Tmp1 = Builder.CreateLShr(V,
+ Context.getConstantInt(V->getType(), 56),
"bswap.1");
Tmp7 = Builder.CreateAnd(Tmp7,
- ConstantInt::get(Type::Int64Ty,
+ Context.getConstantInt(Type::Int64Ty,
0xFF000000000000ULL),
"bswap.and7");
Tmp6 = Builder.CreateAnd(Tmp6,
- ConstantInt::get(Type::Int64Ty,
+ Context.getConstantInt(Type::Int64Ty,
0xFF0000000000ULL),
"bswap.and6");
Tmp5 = Builder.CreateAnd(Tmp5,
- ConstantInt::get(Type::Int64Ty, 0xFF00000000ULL),
+ Context.getConstantInt(Type::Int64Ty, 0xFF00000000ULL),
"bswap.and5");
Tmp4 = Builder.CreateAnd(Tmp4,
- ConstantInt::get(Type::Int64Ty, 0xFF000000ULL),
+ Context.getConstantInt(Type::Int64Ty, 0xFF000000ULL),
"bswap.and4");
Tmp3 = Builder.CreateAnd(Tmp3,
- ConstantInt::get(Type::Int64Ty, 0xFF0000ULL),
+ Context.getConstantInt(Type::Int64Ty, 0xFF0000ULL),
"bswap.and3");
Tmp2 = Builder.CreateAnd(Tmp2,
- ConstantInt::get(Type::Int64Ty, 0xFF00ULL),
+ Context.getConstantInt(Type::Int64Ty, 0xFF00ULL),
"bswap.and2");
Tmp8 = Builder.CreateOr(Tmp8, Tmp7, "bswap.or1");
Tmp6 = Builder.CreateOr(Tmp6, Tmp5, "bswap.or2");
@@ -236,7 +241,7 @@ static Value *LowerBSWAP(Value *V, Instruction *IP) {
/// LowerCTPOP - Emit the code to lower ctpop of V before the specified
/// instruction IP.
-static Value *LowerCTPOP(Value *V, Instruction *IP) {
+static Value *LowerCTPOP(LLVMContext &Context, Value *V, Instruction *IP) {
assert(V->getType()->isInteger() && "Can't ctpop a non-integer type!");
static const uint64_t MaskValues[6] = {
@@ -249,23 +254,23 @@ static Value *LowerCTPOP(Value *V, Instruction *IP) {
unsigned BitSize = V->getType()->getPrimitiveSizeInBits();
unsigned WordSize = (BitSize + 63) / 64;
- Value *Count = ConstantInt::get(V->getType(), 0);
+ Value *Count = Context.getConstantInt(V->getType(), 0);
for (unsigned n = 0; n < WordSize; ++n) {
Value *PartValue = V;
for (unsigned i = 1, ct = 0; i < (BitSize>64 ? 64 : BitSize);
i <<= 1, ++ct) {
- Value *MaskCst = ConstantInt::get(V->getType(), MaskValues[ct]);
+ Value *MaskCst = Context.getConstantInt(V->getType(), MaskValues[ct]);
Value *LHS = Builder.CreateAnd(PartValue, MaskCst, "cppop.and1");
Value *VShift = Builder.CreateLShr(PartValue,
- ConstantInt::get(V->getType(), i),
+ Context.getConstantInt(V->getType(), i),
"ctpop.sh");
Value *RHS = Builder.CreateAnd(VShift, MaskCst, "cppop.and2");
PartValue = Builder.CreateAdd(LHS, RHS, "ctpop.step");
}
Count = Builder.CreateAdd(PartValue, Count, "ctpop.part");
if (BitSize > 64) {
- V = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 64),
+ V = Builder.CreateLShr(V, Context.getConstantInt(V->getType(), 64),
"ctpop.part.sh");
BitSize -= 64;
}
@@ -276,19 +281,19 @@ static Value *LowerCTPOP(Value *V, Instruction *IP) {
/// LowerCTLZ - Emit the code to lower ctlz of V before the specified
/// instruction IP.
-static Value *LowerCTLZ(Value *V, Instruction *IP) {
+static Value *LowerCTLZ(LLVMContext &Context, Value *V, Instruction *IP) {
IRBuilder<> Builder(IP->getParent(), IP);
unsigned BitSize = V->getType()->getPrimitiveSizeInBits();
for (unsigned i = 1; i < BitSize; i <<= 1) {
- Value *ShVal = ConstantInt::get(V->getType(), i);
+ Value *ShVal = Context.getConstantInt(V->getType(), i);
ShVal = Builder.CreateLShr(V, ShVal, "ctlz.sh");
V = Builder.CreateOr(V, ShVal, "ctlz.step");
}
V = Builder.CreateNot(V);
- return LowerCTPOP(V, IP);
+ return LowerCTPOP(Context, V, IP);
}
static void ReplaceFPIntrinsicWithCall(CallInst *CI, const char *Fname,
@@ -357,15 +362,15 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
break;
}
case Intrinsic::ctpop:
- CI->replaceAllUsesWith(LowerCTPOP(CI->getOperand(1), CI));
+ CI->replaceAllUsesWith(LowerCTPOP(*Context, CI->getOperand(1), CI));
break;
case Intrinsic::bswap:
- CI->replaceAllUsesWith(LowerBSWAP(CI->getOperand(1), CI));
+ CI->replaceAllUsesWith(LowerBSWAP(*Context, CI->getOperand(1), CI));
break;
case Intrinsic::ctlz:
- CI->replaceAllUsesWith(LowerCTLZ(CI->getOperand(1), CI));
+ CI->replaceAllUsesWith(LowerCTLZ(*Context, CI->getOperand(1), CI));
break;
case Intrinsic::cttz: {
@@ -373,9 +378,9 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
Value *Src = CI->getOperand(1);
Value *NotSrc = Builder.CreateNot(Src);
NotSrc->setName(Src->getName() + ".not");
- Value *SrcM1 = ConstantInt::get(Src->getType(), 1);
+ Value *SrcM1 = Context->getConstantInt(Src->getType(), 1);
SrcM1 = Builder.CreateSub(Src, SrcM1);
- Src = LowerCTPOP(Builder.CreateAnd(NotSrc, SrcM1), CI);
+ Src = LowerCTPOP(*Context, Builder.CreateAnd(NotSrc, SrcM1), CI);
CI->replaceAllUsesWith(Src);
break;
}
@@ -409,7 +414,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
case Intrinsic::readcyclecounter: {
cerr << "WARNING: this target does not support the llvm.readcyclecoun"
<< "ter intrinsic. It is being lowered to a constant 0\n";
- CI->replaceAllUsesWith(ConstantInt::get(Type::Int64Ty, 0));
+ CI->replaceAllUsesWith(Context->getConstantInt(Type::Int64Ty, 0));
break;
}
@@ -429,7 +434,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
case Intrinsic::eh_typeid_for_i32:
case Intrinsic::eh_typeid_for_i64:
// Return something different to eh_selector.
- CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 1));
+ CI->replaceAllUsesWith(Context->getConstantInt(CI->getType(), 1));
break;
case Intrinsic::var_annotation:
@@ -501,7 +506,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
case Intrinsic::flt_rounds:
// Lower to "round to the nearest"
if (CI->getType() != Type::VoidTy)
- CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 1));
+ CI->replaceAllUsesWith(Context->getConstantInt(CI->getType(), 1));
break;
}
diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
index 01f3cc7af1..9343b965c4 100644
--- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -30,6 +30,7 @@
#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
#include "llvm/GlobalVariable.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
@@ -2035,7 +2036,7 @@ SDValue SelectionDAGLegalize::ExpandLegalINT_TO_FP(bool isSigned,
case MVT::i64: FF = 0x5F800000ULL; break; // 2^64 (as a float)
}
if (TLI.isLittleEndian()) FF <<= 32;
- Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF);
+ Constant *FudgeFactor = DAG.getContext()->getConstantInt(Type::Int64Ty, FF);
SDValue CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy());
unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlignment();
diff --git a/lib/CodeGen/ShadowStackGC.cpp b/lib/CodeGen/ShadowStackGC.cpp
index 13fa758c24..77ec9c6131 100644
--- a/lib/CodeGen/ShadowStackGC.cpp
+++ b/lib/CodeGen/ShadowStackGC.cpp
@@ -62,9 +62,11 @@ namespace {
Constant *GetFrameMap(Function &F);
const Type* GetConcreteStackEntryType(Function &F);
void CollectRoots(Function &F);
- static GetElementPtrInst *CreateGEP(IRBuilder<> &B, Value *BasePtr,
+ static GetElementPtrInst *CreateGEP(LLVMContext *Context,
+ IRBuilder<> &B, Value *BasePtr,
int Idx1, const char *Name);
- static GetElementPtrInst *CreateGEP(IRBuilder<> &B, Value *BasePtr,
+ static GetElementPtrInst *CreateGEP(LLVMContext *Context,
+ IRBuilder<> &B, Value *BasePtr,
int Idx1, int Idx2, const char *Name);
};
@@ -186,6 +188,7 @@ ShadowStackGC::ShadowStackGC() : Head(0), StackEntryTy(0) {
Constant *ShadowStackGC::GetFrameMap(Function &F) {
// doInitialization creates the abstract type of this value.
+ LLVMContext *Context = F.getContext();
Type *VoidPtr = PointerType::getUnqual(Type::Int8Ty);
@@ -200,17 +203,17 @@ Constant *ShadowStackGC::GetFrameMap(Function &F) {
}
Constant *BaseElts[] = {
- ConstantInt::get(Type::Int32Ty, Roots.size(), false),
- ConstantInt::get(Type::Int32Ty, NumMeta, false),
+ Context->getConstantInt(Type::Int32Ty, Roots.size(), false),
+ Context->getConstantInt(Type::Int32Ty, NumMeta, false),
};
Constant *DescriptorElts[] = {
- ConstantStruct::get(BaseElts, 2),
- ConstantArray::get(ArrayType::get(VoidPtr, NumMeta),
+ Context->getConstantStruct(BaseElts, 2),
+ Context->getConstantArray(Context->getArrayType(VoidPtr, NumMeta),
Metadata.begin(), NumMeta)
};
- Constant *FrameMap = ConstantStruct::get(DescriptorElts, 2);
+ Constant *FrameMap = Context->getConstantStruct(DescriptorElts, 2);
std::string TypeName("gc_map.");
TypeName += utostr(NumMeta);
@@ -233,9 +236,9 @@ Constant *ShadowStackGC::GetFrameMap(Function &F) {
GlobalVariable::InternalLinkage,
FrameMap, "__gc_" + F.getName());
- Constant *GEPIndices[2] = { ConstantInt::get(Type::Int32Ty, 0),
- ConstantInt::get(Type::Int32Ty, 0) };
- return ConstantExpr::getGetElementPtr(GV, GEPIndices, 2);
+ Constant *GEPIndices[2] = { Context->getConstantInt(Type::Int32Ty, 0),
+ Context->getConstantInt(Type::Int32Ty, 0) };
+ return Context->getConstantExprGetElementPtr(GV, GEPIndices, 2);
}
const Type* ShadowStackGC::GetConcreteStackEntryType(Function &F) {
@@ -337,11 +340,11 @@ void ShadowStackGC::CollectRoots(Function &F) {
}
GetElementPtrInst *
-ShadowStackGC::CreateGEP(IRBuilder<> &B, Value *BasePtr,
+ShadowStackGC::CreateGEP(LLVMContext *Context, IRBuilder<> &B, Value *BasePtr,
int Idx, int Idx2, const char *Name) {
- Value *Indices[] = { ConstantInt::get(Type::Int32Ty, 0),
- ConstantInt::get(Type::Int32Ty, Idx),
- ConstantInt::get(Type::Int32Ty, Idx2) };
+ Value *Indices[] = { Context->getConstantInt(Type::Int32Ty, 0),
+ Context->getConstantInt(Type::Int32Ty, Idx),
+ Context->getConstantInt(Type::Int32Ty, Idx2) };
Value* Val = B.CreateGEP(BasePtr, Indices, Indices + 3, Name);
assert(isa<GetElementPtrInst>(Val) && "Unexpected folded constant");
@@ -350,10 +353,10 @@ ShadowStackGC::CreateGEP(IRBuilder<> &B, Value *BasePtr,
}
GetElementPtrInst *
-ShadowStackGC::CreateGEP(IRBuilder<> &B, Value *BasePtr,
+ShadowStackGC::CreateGEP(LLVMContext *Context, IRBuilder<> &B, Value *BasePtr,
int Idx, const char *Name) {
- Value *Indices[] = { ConstantInt::get(Type::Int32Ty, 0),
- ConstantInt::get(Type::Int32Ty, Idx) };
+ Value *Indices[] = { Context->getConstantInt(Type::Int32Ty, 0),
+ Context->getConstantInt(Type::Int32Ty, Idx) };
Value *Val = B.CreateGEP(BasePtr, Indices, Indices + 2, Name);
assert(isa<GetElementPtrInst>(Val) && "Unexpected folded constant");
@@ -363,6 +366,8 @@ ShadowStackGC::CreateGEP(IRBuilder<> &B, Value *BasePtr,
/// runOnFunction - Insert code to maintain the shadow stack.
bool ShadowStackGC::performCustomLowering(Function &F) {
+ LLVMContext *Context = F.getContext();
+
// Find calls to llvm.gcroot.
CollectRoots(F);
@@ -387,13 +392,14 @@ bool ShadowStackGC::performCustomLowering(Function &F) {
// Initialize the map pointer and load the current head of the shadow stack.
Instruction *CurrentHead = AtEntry.CreateLoad(Head, "gc_currhead");
- Instruction *EntryMapPtr = CreateGEP(AtEntry, StackEntry,0,1,"gc_frame.map");
+ Instruction *EntryMapPtr = CreateGEP(Context, AtEntry, StackEntry,
+ 0,1,"gc_frame.map");
AtEntry.CreateStore(FrameMap, EntryMapPtr);
// After all the allocas...
for (unsigned I = 0, E = Roots.size(); I != E; ++I) {
// For each root, find the corresponding slot in the aggregate...
- Value *SlotPtr = CreateGEP(AtEntry, StackEntry, 1 + I, "gc_root");
+ Value *SlotPtr = CreateGEP(Context, AtEntry, StackEntry, 1 + I, "gc_root");
// And use it in lieu of the alloca.
AllocaInst *OriginalAlloca = Roots[I].second;
@@ -409,17 +415,19 @@ bool ShadowStackGC::performCustomLowering(Function &F) {
AtEntry.SetInsertPoint(IP->getParent(), IP);
// Push the entry onto the shadow stack.
- Instruction *EntryNextPtr = CreateGEP(AtEntry,StackEntry,0,0,"gc_frame.next");
- Instruction *NewHeadVal = CreateGEP(AtEntry,StackEntry, 0, "gc_newhead");
- AtEntry.CreateStore(CurrentHead, EntryNextPtr);
- AtEntry.CreateStore(NewHeadVal, Head);
+ Instruction *EntryNextPtr = CreateGEP(Context, AtEntry,
+ StackEntry,0,0,"gc_frame.next");
+ Instruction *NewHeadVal = CreateGEP(Context, AtEntry,
+ StackEntry, 0, "gc_newhead");
+ AtEntry.CreateStore(CurrentHead, EntryNextPtr);
+ AtEntry.CreateStore(NewHeadVal, Head);
// For each instruction that escapes...
EscapeEnumerator EE(F, "gc_cleanup");
while (IRBuilder<> *AtExit = EE.Next()) {
// Pop the entry from the shadow stack. Don't reuse CurrentHead from
// AtEntry, since that would make the value live for the entire function.
- Instruction *EntryNextPtr2 = CreateGEP(*AtExit, StackEntry, 0, 0,
+ Instruction *EntryNextPtr2 = CreateGEP(Context, *AtExit, StackEntry, 0, 0,
"gc_frame.next");
Value *SavedHead = AtExit->CreateLoad(EntryNextPtr2, "gc_savedhead");
AtExit->CreateStore(SavedHead, Head);
diff --git a/lib/CodeGen/StackProtector.cpp b/lib/CodeGen/StackProtector.cpp
index 9043b89e35..3dce50b1a8 100644
--- a/lib/CodeGen/StackProtector.cpp
+++ b/lib/CodeGen/StackProtector.cpp
@@ -154,7 +154,7 @@ bool StackProtector::InsertStackProtectors() {
BasicBlock &Entry = F->getEntryBlock();
Instruction *InsPt = &Entry.front();
- AI = new AllocaInst(PtrTy, "StackGuardSlot", InsPt);
+ AI = new AllocaInst(*Context, PtrTy, "StackGuardSlot", InsPt);
LoadInst *LI = new LoadInst(StackGuardVar, "StackGuard", false, InsPt);
Value *Args[] = { LI, AI };
diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp
index baa8a47452..58ff71b846 100644
--- a/lib/ExecutionEngine/JIT/JIT.cpp
+++ b/lib/ExecutionEngine/JIT/JIT.cpp
@@ -351,6 +351,7 @@ void JIT::deleteModuleProvider(ModuleProvider *MP, std::string *E) {
GenericValue JIT::runFunction(Function *F,
const std::vector<GenericValue> &ArgValues) {
assert(F && "Function *F was null at entry to run()");
+ LLVMContext *Context = F->getContext();
void *FPtr = getPointerToFunction(F);
assert(FPtr && "Pointer to fn's code was null after getPointerToFunction");
@@ -452,7 +453,7 @@ GenericValue JIT::runFunction(Function *F,
// arguments. Make this function and return.
// First, create the function.
- FunctionType *STy=FunctionType::get(RetTy, false);
+ FunctionType *STy=Context->getFunctionType(RetTy, false);
Function *Stub = Function::Create(STy, Function::InternalLinkage, "",
F->getParent());
@@ -469,26 +470,27 @@ GenericValue JIT::runFunction(Function *F,
switch (ArgTy->getTypeID()) {
default: llvm_unreachable("Unknown argument type for function call!");
case Type::IntegerTyID:
- C = ConstantInt::get(AV.IntVal);
+ C = Context->getConstantInt(AV.IntVal);
break;
case Type::FloatTyID:
- C = ConstantFP::get(APFloat(AV.FloatVal));
+ C = Context->getConstantFP(APFloat(AV.FloatVal));
break;
case Type::DoubleTyID:
- C = ConstantFP::get(APFloat(AV.DoubleVal));
+ C = Context->getConstantFP(APFloat(AV.DoubleVal));
break;
case Type::PPC_FP128TyID:
case Type::X86_FP80TyID:
case Type::FP128TyID:
- C = ConstantFP::get(APFloat(AV.IntVal));
+ C = Context->getConstantFP(APFloat(AV.IntVal));
break;
case Type::PointerTyID:
void *ArgPtr = GVTOP(AV);
if (sizeof(void*) == 4)
- C = ConstantInt::get(Type::Int32Ty, (int)(intptr_t)ArgPtr);
+ C = Context->getConstantInt(Type::Int32Ty, (int)(intptr_t)ArgPtr);
else
- C = ConstantInt::get(Type::Int64Ty, (intptr_t)ArgPtr);
- C = ConstantExpr::getIntToPtr(C, ArgTy); // Cast the integer to pointer
+ C = Context->getConstantInt(Type::Int64Ty, (intptr_t)ArgPtr);
+ // Cast the integer to pointer
+ C = Context->getConstantExprIntToPtr(C, ArgTy);
break;
}
Args.push_back(C);
diff --git a/lib/Target/ARM/ARMBaseRegisterInfo.cpp b/lib/Target/ARM/ARMBaseRegisterInfo.cpp
index 53ce753412..37ba0efae7 100644
--- a/lib/Target/ARM/ARMBaseRegisterInfo.cpp
+++ b/lib/Target/ARM/ARMBaseRegisterInfo.cpp
@@ -20,6 +20,8 @@
#include "ARMSubtarget.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
+#include "llvm/Function.h"
+#include "llvm/LLVMContext.h"
#include "llvm/CodeGen/MachineConstantPool.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
@@ -890,7 +892,8 @@ emitLoadConstPool(MachineBasicBlock &MBB,
unsigned PredReg) const {
MachineFunction &MF = *MBB.getParent();
MachineConstantPool *ConstantPool = MF.getConstantPool();
- Constant *C = ConstantInt::get(Type::Int32Ty, Val);
+ Constant *C =
+ MF.getFunction()->getContext()->getConstantInt(Type::Int32Ty, Val);
unsigned Idx = ConstantPool->getConstantPoolIndex(C, 4);
BuildMI(MBB, MBBI, dl, TII.get(ARM::LDRcp), DestReg)
diff --git a/lib/Target/ARM/ARMISelDAGToDAG.cpp b/lib/Target/ARM/ARMISelDAGToDAG.cpp
index 8023f45c1e..a102021e42 100644
--- a/lib/Target/ARM/ARMISelDAGToDAG.cpp
+++ b/lib/Target/ARM/ARMISelDAGToDAG.cpp
@@ -21,6 +21,7 @@
#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
#include "llvm/Intrinsics.h"
+#include "llvm/LLVMContext.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
@@ -865,7 +866,8 @@ SDNode *ARMDAGToDAGISel::Select(SDValue Op) {
!ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
if (UseCP) {
SDValue CPIdx =
- CurDAG->getTargetConstantPool(ConstantInt::get(Type::Int32Ty, Val),
+ CurDAG->getTargetConstantPool(
+ CurDAG->getContext()->getConstantInt(Type::Int32Ty, Val),
TLI.getPointerTy());
SDNode *ResNode;
diff --git a/lib/Target/ARM/Thumb1RegisterInfo.cpp b/lib/Target/ARM/Thumb1RegisterInfo.cpp
index 9c544e337a..8374090bd3 100644
--- a/lib/Target/ARM/Thumb1RegisterInfo.cpp
+++ b/lib/Target/ARM/Thumb1RegisterInfo.cpp
@@ -20,6 +20,8 @@
#include "Thumb1RegisterInfo.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
+#include "llvm/Function.h"
+#include "llvm/LLVMContext.h"
#include "llvm/CodeGen/MachineConstantPool.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
@@ -65,7 +67,8 @@ void Thumb1RegisterInfo::emitLoadConstPool(MachineBasicBlock &MBB,
unsigned PredReg) const {
MachineFunction &MF = *MBB.getParent();
MachineConstantPool *ConstantPool = MF.getConstantPool();
- Constant *C = ConstantInt::get(Type::Int32Ty, Val);
+ Constant *C =
+ MF.getFunction()->getContext()->getConstantInt(Type::Int32Ty, Val);
unsigned Idx = ConstantPool->getConstantPoolIndex(C, 4);
BuildMI(MBB, MBBI, dl, TII.get(ARM::tLDRcp), DestReg)
diff --git a/lib/Target/ARM/Thumb2RegisterInfo.cpp b/lib/Target/ARM/Thumb2RegisterInfo.cpp
index ebb8ce5f70..bf7149722e 100644
--- a/lib/Target/ARM/Thumb2RegisterInfo.cpp
+++ b/lib/Target/ARM/Thumb2RegisterInfo.cpp
@@ -20,6 +20,8 @@
#include "Thumb2RegisterInfo.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
+#include "llvm/Function.h"
+#include "llvm/LLVMContext.h"
#include "llvm/CodeGen/MachineConstantPool.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
@@ -49,7 +51,8 @@ void Thumb2RegisterInfo::emitLoadConstPool(MachineBasicBlock &MBB,
unsigned PredReg) const {
MachineFunction &MF = *MBB.getParent();
MachineConstantPool *ConstantPool = MF.getConstantPool();
- Constant *C = ConstantInt::get(Type::Int32Ty, Val);
+ Constant *C =
+ MF.getFunction()->getContext()->getConstantInt(Type::Int32Ty, Val);
unsigned Idx = ConstantPool->getConstantPoolIndex(C, 4);
BuildMI(MBB, MBBI, dl, TII.get(ARM::t2LDRpci), DestReg)
diff --git a/lib/Target/Alpha/AlphaISelDAGToDAG.cpp b/lib/Target/Alpha/AlphaISelDAGToDAG.cpp
index 0f4d0f42ca..19f1a5b5b8 100644
--- a/lib/Target/Alpha/AlphaISelDAGToDAG.cpp
+++ b/lib/Target/Alpha/AlphaISelDAGToDAG.cpp
@@ -26,6 +26,7 @@
#include "llvm/DerivedTypes.h"
#include "llvm/GlobalValue.h"
#include "llvm/Intrinsics.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
@@ -304,7 +305,7 @@ SDNode *AlphaDAGToDAGISel::Select(SDValue Op) {
// val32 >= IMM_LOW + IMM_LOW * IMM_MULT) //always true
break; //(zext (LDAH (LDA)))
//Else use the constant pool
- ConstantInt *C = ConstantInt::get(Type::Int64Ty, uval);
+ ConstantInt *C = CurDAG->getContext()->getConstantInt(Type::Int64Ty, uval);
SDValue CPI = CurDAG->getTargetConstantPool(C, MVT::i64);
SDNode *Tmp = CurDAG->getTargetNode(Alpha::LDAHr, dl, MVT::i64, CPI,
SDValue(getGlobalBaseReg(), 0));
diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp
index 6f8386e96c..caf91c882e 100644
--- a/lib/Target/CBackend/CBackend.cpp
+++ b/lib/Target/CBackend/CBackend.cpp
@@ -3503,7 +3503,7 @@ void CWriter::visitStoreInst(StoreInst &I) {
if (!ITy->isPowerOf2ByteWidth())
// We have a bit width that doesn't match an even power-of-2 byte
// size. Consequently we must & the value with the type's bit mask
- BitMask = ConstantInt::get(ITy, ITy->getBitMask());
+ BitMask = Context->getConstantInt(ITy, ITy->getBitMask());
if (BitMask)
Out << "((";
writeOperand(Operand);
diff --git a/lib/Target/XCore/XCoreISelDAGToDAG.cpp b/lib/Target/XCore/XCoreISelDAGToDAG.cpp
index 5114bc7532..7f6532790c 100644
--- a/lib/Target/XCore/XCoreISelDAGToDAG.cpp
+++ b/lib/Target/XCore/XCoreISelDAGToDAG.cpp
@@ -19,6 +19,7 @@
#include "llvm/Intrinsics.h"
#include "llvm/CallingConv.h"
#include "llvm/Constants.h"
+#include "llvm/LLVMContext.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
@@ -173,7 +174,8 @@ SDNode *XCoreDAGToDAGISel::Select(SDValue Op) {
else if (! Predicate_immU16(N)) {
unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
SDValue CPIdx =
- CurDAG->getTargetConstantPool(ConstantInt::get(Type::Int32Ty, Val),
+ CurDAG->getTargetConstantPool(
+ CurDAG->getContext()->getConstantInt(Type::Int32Ty, Val),
TLI.getPointerTy());
return CurDAG->getTargetNode(XCore::LDWCP_lru6, dl, MVT::i32,
MVT::Other, CPIdx,
diff --git a/lib/Transforms/IPO/ArgumentPromotion.cpp b/lib/Transforms/IPO/ArgumentPromotion.cpp
index 75a0415fad..7f1c3cb216 100644
--- a/lib/Transforms/IPO/ArgumentPromotion.cpp
+++ b/lib/Transforms/IPO/ArgumentPromotion.cpp
@@ -755,7 +755,7 @@ Function *ArgPromotion::DoPromotion(Function *F,
// Just add all the struct element types.
const Type *AgTy = cast<PointerType>(I->getType())->getElementType();
- Value *TheAlloca = new AllocaInst(AgTy, 0, "", InsertPt);
+ Value *TheAlloca = new AllocaInst(*Context, AgTy, 0, "", InsertPt);
const StructType *STy = cast<StructType>(AgTy);
Value *Idxs[2] = { Context->getConstantInt(Type::Int32Ty, 0), 0 };
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp
index 398f78a098..13fe94af31 100644
--- a/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/lib/Transforms/IPO/GlobalOpt.cpp
@@ -828,7 +828,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
Type *NewTy = Context->getArrayType(MI->getAllocatedType(),
NElements->getZExtValue());
MallocInst *NewMI =
- new MallocInst(NewTy, Context->getNullValue(Type::Int32Ty),
+ new MallocInst(*Context, NewTy, Context->getNullValue(Type::Int32Ty),
MI->getAlignment(), MI->getName(), MI);
Value* Indices[2];
Indices[0] = Indices[1] = Context->getNullValue(Type::Int32Ty);
@@ -1291,7 +1291,7 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI,
GV->isThreadLocal());
FieldGlobals.push_back(NGV);
- MallocInst *NMI = new MallocInst(FieldTy, MI->getArraySize(),
+ MallocInst *NMI = new MallocInst(*Context, FieldTy, MI->getArraySize(),
MI->getName() + ".f" + utostr(FieldNo),MI);
FieldMallocs.push_back(NMI);
new StoreInst(NMI, NGV, MI);
@@ -1507,7 +1507,7 @@ static bool TryToOptimizeStoreOfMallocToGlobal(GlobalVariable *GV,
// structs. malloc [100 x struct],1 -> malloc struct, 100
if (const ArrayType *AT = dyn_cast<ArrayType>(MI->getAllocatedType())) {
MallocInst *NewMI =
- new MallocInst(AllocSTy,
+ new MallocInst(*Context, AllocSTy,
Context->getConstantInt(Type::Int32Ty, AT->getNumElements()),
"", MI);
NewMI->takeName(MI);
@@ -1703,7 +1703,8 @@ bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV,
Instruction* FirstI = GS.AccessingFunction->getEntryBlock().begin();
const Type* ElemTy = GV->getType()->getElementType();
// FIXME: Pass Global's alignment when globals have alignment
- AllocaInst* Alloca = new AllocaInst(ElemTy, NULL, GV->getName(), FirstI);
+ AllocaInst* Alloca = new AllocaInst(*Context, ElemTy, NULL,
+ GV->getName(), FirstI);
if (!isa<UndefValue>(GV->getInitializer()))
new StoreInst(GV->getInitializer(), Alloca, FirstI);
diff --git a/lib/Transforms/IPO/IndMemRemoval.cpp b/lib/Transforms/IPO/IndMemRemoval.cpp
index b55dea2c75..d3e609dd82 100644
--- a/lib/Transforms/IPO/IndMemRemoval.cpp
+++ b/lib/Transforms/IPO/IndMemRemoval.cpp
@@ -1,4 +1,4 @@
-//===-- IndMemRemoval.cpp - Remove indirect allocations and frees ----------===//
+//===-- IndMemRemoval.cpp - Remove indirect allocations and frees ---------===//
//
// The LLVM Compiler Infrastructure
//
@@ -10,8 +10,8 @@
// This pass finds places where memory allocation functions may escape into
// indirect land. Some transforms are much easier (aka possible) only if free
// or malloc are not called indirectly.
-// Thus find places where the address of memory functions are taken and construct
-// bounce functions with direct calls of those functions.
+// Thus find places where the address of memory functions are taken and
+// construct bounce functions with direct calls of those functions.
//
//===----------------------------------------------------------------------===//
@@ -73,7 +73,7 @@ bool IndMemRemPass::runOnModule(Module &M) {
BasicBlock* bb = BasicBlock::Create("entry",FN);
Instruction* c = CastInst::CreateIntegerCast(
FN->arg_begin(), Type::Int32Ty, false, "c", bb);
- Instruction* a = new MallocInst(Type::Int8Ty, c, "m", bb);
+ Instruction* a = new MallocInst(*Context, Type::Int8Ty, c, "m", bb);
ReturnInst::Create(a, bb);
++NumBounce;
NumBounceSites += F->getNumUses();
diff --git a/lib/Transforms/IPO/LowerSetJmp.cpp b/lib/Transforms/IPO/LowerSetJmp.cpp
index dfdf5b6f2d..8f5d50d3b6 100644
--- a/lib/Transforms/IPO/LowerSetJmp.cpp
+++ b/lib/Transforms/IPO/LowerSetJmp.cpp
@@ -311,7 +311,7 @@ AllocaInst* LowerSetJmp::GetSetJmpMap(Function* Func)
// Fill in the alloca and call to initialize the SJ map.
const Type *SBPTy = Context->getPointerTypeUnqual(Type::Int8Ty);
- AllocaInst* Map = new AllocaInst(SBPTy, 0, "SJMap", Inst);
+ AllocaInst* Map = new AllocaInst(*Context, SBPTy, 0, "SJMap", Inst);
CallInst::Create(InitSJMap, Map, "", Inst);
return SJMap[Func] = Map;
}
@@ -408,7 +408,7 @@ void LowerSetJmp::TransformSetJmpCall(CallInst* Inst)
UI != E; ++UI)
if (cast<Instruction>(*UI)->getParent() != ABlock ||
InstrsAfterCall.count(cast<Instruction>(*UI))) {
- DemoteRegToStack(*II);
+ DemoteRegToStack(*Context, *II);
break;
}
InstrsAfterCall.clear();
diff --git a/lib/Transforms/IPO/RaiseAllocations.cpp b/lib/Transforms/IPO/RaiseAllocations.cpp
index 6c32050909..ce976c8d69 100644
--- a/lib/Transforms/IPO/RaiseAllocations.cpp
+++ b/lib/Transforms/IPO/RaiseAllocations.cpp
@@ -169,7 +169,8 @@ bool RaiseAllocations::runOnModule(Module &M) {
CastInst::CreateIntegerCast(Source, Type::Int32Ty, false/*ZExt*/,
"MallocAmtCast", I);
- MallocInst *MI = new MallocInst(Type::Int8Ty, Source, "", I);
+ MallocInst *MI = new MallocInst(*Context, Type::Int8Ty,
+ Source, "", I);
MI->takeName(I);
I->replaceAllUsesWith(MI);
diff --git a/lib/Transforms/IPO/StructRetPromotion.cpp b/lib/Transforms/IPO/StructRetPromotion.cpp
index 94b37a2191..7771bc4b74 100644
--- a/lib/Transforms/IPO/StructRetPromotion.cpp
+++ b/lib/Transforms/IPO/StructRetPromotion.cpp
@@ -110,7 +110,7 @@ bool SRETPromotion::PromoteReturn(CallGraphNode *CGN) {
DOUT << "SretPromotion: sret argument will be promoted\n";
NumSRET++;
// [1] Replace use of sret parameter
- AllocaInst *TheAlloca = new AllocaInst (STy, NULL, "mrv",
+ AllocaInst *TheAlloca = new AllocaInst (*Context, STy, NULL, "mrv",
F->getEntryBlock().begin());
Value *NFirstArg = F->arg_begin();
NFirstArg->replaceAllUsesWith(TheAlloca);
diff --git a/lib/Transforms/Instrumentation/RSProfiling.cpp b/lib/Transforms/Instrumentation/RSProfiling.cpp
index 36b4464311..ad76ba4480 100644
--- a/lib/Transforms/Instrumentation/RSProfiling.cpp
+++ b/lib/Transforms/Instrumentation/RSProfiling.cpp
@@ -248,7 +248,7 @@ void GlobalRandomCounterOpt::PrepFunction(Function* F) {
//make a local temporary to cache the global
BasicBlock& bb = F->getEntryBlock();
BasicBlock::iterator InsertPt = bb.begin();
- AI = new AllocaInst(T, 0, "localcounter", InsertPt);
+ AI = new AllocaInst(*F->getContext(), T, 0, "localcounter", InsertPt);
LoadInst* l = new LoadInst(Counter, "counterload", InsertPt);
new StoreInst(l, AI, InsertPt);
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index f42827cbbd..4160ee7dc1 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -1756,8 +1756,10 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
Value *LHS = II->getOperand(1);
Value *RHS = II->getOperand(2);
// Extract the element as scalars.
- LHS = InsertNewInstBefore(new ExtractElementInst(LHS, 0U,"tmp"), *II);
- RHS = InsertNewInstBefore(new ExtractElementInst(RHS, 0U,"tmp"), *II);
+ LHS = InsertNewInstBefore(new ExtractElementInst(LHS,
+ Context->getConstantInt(Type::Int32Ty, 0U, false), "tmp"), *II);
+ RHS = InsertNewInstBefore(new ExtractElementInst(RHS,
+ Context->getConstantInt(Type::Int32Ty, 0U, false), "tmp"), *II);
switch (II->getIntrinsicID()) {
default: llvm_unreachable("Case stmts out of sync!");
@@ -1775,7 +1777,8 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
Instruction *New =
InsertElementInst::Create(
- Context->getUndef(II->getType()), TmpV, 0U, II->getName());
+ Context->getUndef(II->getType()), TmpV,
+ Context->getConstantInt(Type::Int32Ty, 0U, false), II->getName());
InsertNewInstBefore(New, *II);
AddSoonDeadInstToWorklist(*II, 0);
return New;
@@ -7888,9 +7891,9 @@ Instruction *InstCombiner::PromoteCastOfAllocation(BitCastInst &CI,
AllocationInst *New;
if (isa<MallocInst>(AI))
- New = new MallocInst(CastElTy, Amt, AI.getAlignment());
+ New = new MallocInst(*Context, CastElTy, Amt, AI.getAlignment());
else
- New = new AllocaInst(CastElTy, Amt, AI.getAlignment());
+ New = new AllocaInst(*Context, CastElTy, Amt, AI.getAlignment());
InsertNewInstBefore(New, AI);
New->takeName(&AI);
@@ -9974,14 +9977,16 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
if (ExtractedElts[Idx] == 0) {
Instruction *Elt =
- new ExtractElementInst(Idx < 16 ? Op0 : Op1, Idx&15, "tmp");
+ new ExtractElementInst(Idx < 16 ? Op0 : Op1,
+ Context->getConstantInt(Type::Int32Ty, Idx&15, false), "tmp");
InsertNewInstBefore(Elt, CI);
ExtractedElts[Idx] = Elt;
}
// Insert this value into the result vector.
Result = InsertElementInst::Create(Result, ExtractedElts[Idx],
- i, "tmp");
+ Context->getConstantInt(Type::Int32Ty, i, false),
+ "tmp");
InsertNewInstBefore(cast<Instruction>(Result), CI);
}
return CastInst::Create(Instruction::BitCast, Result, CI.getType());
@@ -11363,10 +11368,12 @@ Instruction *InstCombiner::visitAllocationInst(AllocationInst &AI) {
// Create and insert the replacement instruction...
if (isa<MallocInst>(AI))
- New = new MallocInst(NewTy, 0, AI.getAlignment(), AI.getName());
+ New = new MallocInst(*Context, NewTy, 0,
+ AI.getAlignment(), AI.getName());
else {
assert(isa<AllocaInst>(AI) && "Unknown type of allocation inst!");
- New = new AllocaInst(NewTy, 0, AI.getAlignment(), AI.getName());
+ New = new AllocaInst(*Context, NewTy, 0,
+ AI.getAlignment(), AI.getName());
}
InsertNewInstBefore(New, AI);
@@ -12475,7 +12482,8 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
} else {
return ReplaceInstUsesWith(EI, Context->getUndef(EI.getType()));
}
- return new ExtractElementInst(Src, SrcIdx);
+ return new ExtractElementInst(Src,
+ Context->getConstantInt(Type::Int32Ty, SrcIdx, false));
}
}
}
diff --git a/lib/Transforms/Scalar/JumpThreading.cpp b/lib/Transforms/Scalar/JumpThreading.cpp
index f3536c10c5..86e03c47f6 100644
--- a/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/lib/Transforms/Scalar/JumpThreading.cpp
@@ -912,7 +912,7 @@ bool JumpThreading::ThreadEdge(BasicBlock *BB, BasicBlock *PredBB,
// We found a use of I outside of BB. Create a new stack slot to
// break this inter-block usage pattern.
- DemoteRegToStack(*I);
+ DemoteRegToStack(*Context, *I);
}
// We are going to have to map operands from the original BB block to the new
diff --git a/lib/Transforms/Scalar/LICM.cpp b/lib/Transforms/Scalar/LICM.cpp
index 52dd06affe..aa49b24aba 100644
--- a/lib/Transforms/Scalar/LICM.cpp
+++ b/lib/Transforms/Scalar/LICM.cpp
@@ -508,7 +508,7 @@ void LICM::sink(Instruction &I) {
AllocaInst *AI = 0;
if (I.getType() != Type::VoidTy) {
- AI = new AllocaInst(I.getType(), 0, I.getName(),
+ AI = new AllocaInst(*Context, I.getType(), 0, I.getName(),
I.getParent()->getParent()->getEntryBlock().begin());
CurAST->add(AI);
}
@@ -853,7 +853,8 @@ void LICM::FindPromotableValuesInLoop(
continue;
const Type *Ty = cast<PointerType>(V->getType())->getElementType();
- AllocaInst *AI = new AllocaInst(Ty, 0, V->getName()+".tmp", FnStart);
+ AllocaInst *AI = new AllocaInst(*Context, Ty, 0,
+ V->getName()+".tmp", FnStart);
PromotedValues.push_back(std::make_pair(AI, V));
// Update the AST and alias analysis.
diff --git a/lib/Transforms/Scalar/PredicateSimplifier.cpp b/lib/Transforms/Scalar/PredicateSimplifier.cpp
index 4116c66dba..50d606311a 100644
--- a/lib/Transforms/Scalar/PredicateSimplifier.cpp
+++ b/lib/Transforms/Scalar/PredicateSimplifier.cpp
@@ -1891,7 +1891,7 @@ namespace {
assert(!Ty->isFPOrFPVector() && "Float in work queue!");
Constant *Zero = Context->getNullValue(Ty);
- Constant *One = ConstantInt::get(Ty, 1);
+ Constant *One = Context->getConstantInt(Ty, 1);
ConstantInt *AllOnes = cast<ConstantInt>(Context->getAllOnesValue(Ty));
switch (Opcode) {
diff --git a/lib/Transforms/Scalar/Reg2Mem.cpp b/lib/Transforms/Scalar/Reg2Mem.cpp
index ac95d25b7f..289f08c947 100644
--- a/lib/Transforms/Scalar/Reg2Mem.cpp
+++ b/lib/Transforms/Scalar/Reg2Mem.cpp
@@ -89,7 +89,7 @@ namespace {
NumRegsDemoted += worklist.size();
for (std::list<Instruction*>::iterator ilb = worklist.begin(),
ile = worklist.end(); ilb != ile; ++ilb)
- DemoteRegToStack(**ilb, false, AllocaInsertionPoint);
+ DemoteRegToStack(*Context, **ilb, false, AllocaInsertionPoint);
worklist.clear();
@@ -105,7 +105,7 @@ namespace {
NumPhisDemoted += worklist.size();
for (std::list<Instruction*>::iterator ilb = worklist.begin(),
ile = worklist.end(); ilb != ile; ++ilb)
- DemotePHIToStack(cast<PHINode>(*ilb), AllocaInsertionPoint);
+ DemotePHIToStack(*Context, cast<PHINode>(*ilb), AllocaInsertionPoint);
return true;
}
diff --git a/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/lib/Transforms/Scalar/ScalarReplAggregates.cpp
index 83db90da76..d999f9d8a9 100644
--- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp
+++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp
@@ -302,14 +302,16 @@ bool SROA::performScalarRepl(Function &F) {
DOUT << "CONVERT TO VECTOR: " << *AI << " TYPE = " << *VectorTy <<"\n";
// Create and insert the vector alloca.
- NewAI = new AllocaInst(VectorTy, 0, "", AI->getParent()->begin());
+ NewAI = new AllocaInst(*Context, VectorTy, 0, "",
+ AI->getParent()->begin());
ConvertUsesToScalar(AI, NewAI, 0);
} else {
DOUT << "CONVERT TO SCALAR INTEGER: " << *AI << "\n";
// Create and insert the integer alloca.
const Type *NewTy = Context->getIntegerType(AllocaSize*8);
- NewAI = new AllocaInst(NewTy, 0, "", AI->getParent()->begin());
+ NewAI = new AllocaInst(*Context, NewTy, 0, "",
+ AI->getParent()->begin());
ConvertUsesToScalar(AI, NewAI, 0);
}
NewAI->takeName(AI);
@@ -334,7 +336,8 @@ void SROA::DoScalarReplacement(AllocationInst *AI,
if (const StructType *ST = dyn_cast<StructType>(AI->getAllocatedType())) {
ElementAllocas.reserve(ST->getNumContainedTypes());
for (unsigned i = 0, e = ST->getNumContainedTypes(); i != e; ++i) {
- AllocaInst *NA = new AllocaInst(ST->getContainedType(i), 0,
+ AllocaInst *NA = new AllocaInst(*Context,
+ ST->getContainedType(i), 0,
AI->getAlignment(),
AI->getName() + "." + utostr(i), AI);
ElementAllocas.push_back(NA);
@@ -345,7 +348,7 @@ void SROA::DoScalarReplacement(AllocationInst *AI,
ElementAllocas.reserve(AT->getNumElements());
const Type *ElTy = AT->getElementType();
for (unsigned i = 0, e = AT->getNumElements(); i != e; ++i) {
- AllocaInst *NA = new AllocaInst(ElTy, 0, AI->getAlignment(),
+ AllocaInst *NA = new AllocaInst(*Context, ElTy, 0, AI->getAlignment(),
AI->getName() + "." + utostr(i), AI);
ElementAllocas.push_back(NA);
WorkList.push_back(NA); // Add to worklist for recursive processing
diff --git a/lib/Transforms/Scalar/TailDuplication.cpp b/lib/Transforms/Scalar/TailDuplication.cpp
index 684b096345..5f7221051c 100644
--- a/lib/Transforms/Scalar/TailDuplication.cpp
+++ b/lib/Transforms/Scalar/TailDuplication.cpp
@@ -285,7 +285,7 @@ void TailDup::eliminateUnconditionalBranch(BranchInst *Branch) {
if (I->isUsedOutsideOfBlock(DestBlock)) {
// We found a use outside of the tail. Create a new stack slot to
// break this inter-block usage pattern.
- DemoteRegToStack(*I);
+ DemoteRegToStack(*Context, *I);
}
// We are going to have to map operands from the original block B to the new
diff --git a/lib/Transforms/Utils/CodeExtractor.cpp b/lib/Transforms/Utils/CodeExtractor.cpp
index be02560de0..46e27c8c27 100644
--- a/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/lib/Transforms/Utils/CodeExtractor.cpp
@@ -372,7 +372,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
StructValues.push_back(*i);
} else {
AllocaInst *alloca =
- new AllocaInst((*i)->getType(), 0, (*i)->getName()+".loc",
+ new AllocaInst(*codeReplacer->getContext(),
+ (*i)->getType(), 0, (*i)->getName()+".loc",
codeReplacer->getParent()->begin()->begin());
ReloadOutputs.push_back(alloca);
params.push_back(alloca);
@@ -389,7 +390,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
// Allocate a struct at the beginning of this function
Type *StructArgTy = Context->getStructType(ArgTypes);
Struct =
- new AllocaInst(StructArgTy, 0, "structArg",
+ new AllocaInst(*codeReplacer->getContext(), StructArgTy, 0, "structArg",
codeReplacer->getParent()->begin()->begin());
params.push_back(Struct);
diff --git a/lib/Transforms/Utils/DemoteRegToStack.cpp b/lib/Transforms/Utils/DemoteRegToStack.cpp
index b8dd754133..6cf043b6a1 100644
--- a/lib/Transforms/Utils/DemoteRegToStack.cpp
+++ b/lib/Transforms/Utils/DemoteRegToStack.cpp
@@ -29,7 +29,8 @@ using namespace llvm;
/// invalidating the SSA information for the value. It returns the pointer to
/// the alloca inserted to create a stack slot for I.
///
-AllocaInst* llvm::DemoteRegToStack(Instruction &I, bool VolatileLoads,
+AllocaInst* llvm::DemoteRegToStack(LLVMContext &Context,
+ Instruction &I, bool VolatileLoads,
Instruction *AllocaPoint) {
if (I.use_empty()) {
I.eraseFromParent();
@@ -39,10 +40,11 @@ AllocaInst* llvm::DemoteRegToStack(Instruction &I, bool VolatileLoads,
// Create a stack slot to hold the value.
AllocaInst *Slot;
if (AllocaPoint) {
- Slot = new AllocaInst(I.getType(), 0, I.getName()+".reg2mem", AllocaPoint);
+ Slot = new AllocaInst(Context, I.getType(), 0,
+ I.getName()+".reg2mem", AllocaPoint);
} else {
Function *F = I.getParent()->getParent();
- Slot = new AllocaInst(I.getType(), 0, I.getName()+".reg2mem",
+ Slot = new AllocaInst(Context, I.getType(), 0, I.getName()+".reg2mem",
F->getEntryBlock().begin());
}
@@ -107,7 +109,8 @@ AllocaInst* llvm::DemoteRegToStack(Instruction &I, bool VolatileLoads,
/// DemotePHIToStack - This function takes a virtual register computed by a phi
/// node and replaces it with a slot in the stack frame, allocated via alloca.
/// The phi node is deleted and it returns the pointer to the alloca inserted.
-AllocaInst* llvm::DemotePHIToStack(PHINode *P, Instruction *AllocaPoint) {
+AllocaInst* llvm::DemotePHIToStack(LLVMContext &Context, PHINode *P,
+ Instruction *AllocaPoint) {
if (P->use_empty()) {
P->eraseFromParent();
return 0;
@@ -116,10 +119,11 @@ AllocaInst* llvm::DemotePHIToStack(PHINode *P, Instruction *AllocaPoint) {
// Create a stack slot to hold the value.
AllocaInst *Slot;
if (AllocaPoint) {
- Slot = new AllocaInst(P->getType(), 0, P->getName()+".reg2mem", AllocaPoint);
+ Slot = new AllocaInst(Context, P->getType(), 0,
+ P->getName()+".reg2mem", AllocaPoint);
} else {
Function *F = P->getParent()->getParent();
- Slot = new AllocaInst(P->getType(), 0, P->getName()+".reg2mem",
+ Slot = new AllocaInst(Context, P->getType(), 0, P->getName()+".reg2mem",
F->getEntryBlock().begin());
}
diff --git a/lib/Transforms/Utils/InlineFunction.cpp b/lib/Transforms/Utils/InlineFunction.cpp
index 0e50cd11de..30b1caaa4c 100644
--- a/lib/Transforms/Utils/InlineFunction.cpp
+++ b/lib/Transforms/Utils/InlineFunction.cpp
@@ -309,8 +309,9 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
// Create the alloca. If we have TargetData, use nice alignment.
unsigned Align = 1;
if (TD) Align = TD->getPrefTypeAlignment(AggTy);
- Value *NewAlloca = new AllocaInst(AggTy, 0, Align, I->getName(),
- Caller->begin()->begin());
+ Value *NewAlloca = new AllocaInst(*Context, AggTy, 0, Align,
+ I->getName(),
+ &*Caller->begin()->begin());
// Emit a memcpy.
const Type *Tys[] = { Type::Int64Ty };
Function *MemCpyFn = Intrinsic::getDeclaration(Caller->getParent(),
diff --git a/lib/Transforms/Utils/LowerInvoke.cpp b/lib/Transforms/Utils/LowerInvoke.cpp
index 2e13ed3bd8..8ba14392ec 100644
--- a/lib/Transforms/Utils/LowerInvoke.cpp
+++ b/lib/Transforms/Utils/LowerInvoke.cpp
@@ -266,7 +266,7 @@ bool LowerInvoke::insertCheapEHSupport(Function &F) {
void LowerInvoke::rewriteExpensiveInvoke(InvokeInst *II, unsigned InvokeNo,
AllocaInst *InvokeNum,
SwitchInst *CatchSwitch) {
- ConstantInt *InvokeNoC = ConstantInt::get(Type::Int32Ty, InvokeNo);
+ ConstantInt *InvokeNoC = Context->getConstantInt(Type::Int32Ty, InvokeNo);
// If the unwind edge has phi nodes, split the edge.
if (isa<PHINode>(II->getUnwindDest()->begin())) {
@@ -417,7 +417,7 @@ splitLiveRangesLiveAcrossInvokes(std::vector<InvokeInst*> &Invokes) {
// If we decided we need a spill, do it.
if (NeedsSpill) {
++NumSpilled;
- DemoteRegToStack(*Inst, true);
+ DemoteRegToStack(*Context, *Inst, true);
}
}
}
@@ -470,13 +470,15 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
// alloca because the value needs to be live across invokes.
unsigned Align = TLI ? TLI->getJumpBufAlignment() : 0;
AllocaInst *JmpBuf =
- new AllocaInst(JBLinkTy, 0, Align, "jblink", F.begin()->begin());
+ new AllocaInst(*Context, JBLinkTy, 0, Align,
+ "jblink", F.begin()->begin());
std::vector<Value*> Idx;
Idx.push_back(Context->getNullValue(Type::Int32Ty));
- Idx.push_back(ConstantInt::get(Type::Int32Ty, 1));
+ Idx.push_back(Context->getConstantInt(Type::Int32Ty, 1));
OldJmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx.begin(), Idx.end(),
- "OldBuf", EntryBB->getTerminator());
+ "OldBuf",
+ EntryBB->getTerminator());
// Copy the JBListHead to the alloca.
Value *OldBuf = new LoadInst(JBListHead, "oldjmpbufptr", true,
@@ -492,9 +494,9 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
// Create an alloca which keeps track of which invoke is currently
// executing. For normal calls it contains zero.
- AllocaInst *InvokeNum = new AllocaInst(Type::Int32Ty, 0, "invokenum",
- EntryBB->begin());
- new StoreInst(ConstantInt::get(Type::Int32Ty, 0), InvokeNum, true,
+ AllocaInst *InvokeNum = new AllocaInst(*Context, Type::Int32Ty, 0,
+ "invokenum",EntryBB->begin());
+ new StoreInst(Context->getConstantInt(Type::Int32Ty, 0), InvokeNum, true,
EntryBB->getTerminator());
// Insert a load in the Catch block, and a switch on its value. By default,
@@ -513,7 +515,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
BasicBlock *ContBlock = EntryBB->splitBasicBlock(EntryBB->getTerminator(),
"setjmp.cont");
- Idx[1] = ConstantInt::get(Type::Int32Ty, 0);
+ Idx[1] = Context->getConstantInt(Type::Int32Ty, 0);
Value *JmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx.begin(), Idx.end(),
"TheJmpBuf",
EntryBB->getTerminator());
@@ -567,12 +569,12 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
// Get a pointer to the jmpbuf and longjmp.
std::vector<Value*> Idx;
Idx.push_back(Context->getNullValue(Type::Int32Ty));
- Idx.push_back(ConstantInt::get(Type::Int32Ty, 0));
+ Idx.push_back(Context->getConstantInt(Type::Int32Ty, 0));
Idx[0] = GetElementPtrInst::Create(BufPtr, Idx.begin(), Idx.end(), "JmpBuf",
UnwindBlock);
Idx[0] = new BitCastInst(Idx[0], PointerType::getUnqual(Type::Int8Ty),
"tmp", UnwindBlock);
- Idx[1] = ConstantInt::get(Type::Int32Ty, 1);
+ Idx[1] = Context->getConstantInt(Type::Int32Ty, 1);
CallInst::Create(LongJmpFn, Idx.begin(), Idx.end(), "", UnwindBlock);
new UnreachableInst(UnwindBlock);
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 33c8f675f8..5c7c288ce9 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -181,8 +181,8 @@ static ManagedCleanup<llvm::CleanupTrueFalse> TrueFalseCleanup;
ConstantInt *ConstantInt::CreateTrueFalseVals(bool WhichOne) {
assert(TheTrueVal == 0 && TheFalseVal == 0);
- TheTrueVal = get(Type::Int1Ty, 1);
- TheFalseVal = get(Type::Int1Ty, 0);
+ TheTrueVal = getGlobalContext().getConstantInt(Type::Int1Ty, 1);
+ TheFalseVal = getGlobalContext().getConstantInt(Type::Int1Ty, 0);
// Ensure that llvm_shutdown nulls out TheTrueVal/TheFalseVal.
TrueFalseCleanup.Register();
@@ -223,22 +223,6 @@ typedef DenseMap<DenseMapAPIntKeyInfo::KeyTy, ConstantInt*,
DenseMapAPIntKeyInfo> IntMapTy;
static ManagedStatic<IntMapTy> IntConstants;
-ConstantInt *ConstantInt::get(const IntegerType *Ty,
- uint64_t V, bool isSigned) {
- return get(APInt(Ty->getBitWidth(), V, isSigned));
-}
-
-Constant *ConstantInt::get(const Type *Ty, uint64_t V, bool isSigned) {
- Constant *C = get(cast<IntegerType>(Ty->getScalarType()), V, isSigned);
-
- // For vectors, broadcast the value.
- if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
- return
- ConstantVector::get(std::vector<Constant *>(VTy->getNumElements(), C));
-
- return C;
-}
-
// Get a ConstantInt from an APInt. Note that the value stored in the DenseMap
// as the key, is a DenseMapAPIntKeyInfo::KeyTy which has provided the
// operator== and operator!= to ensure that the DenseMap doesn't attempt to
@@ -267,19 +251,6 @@ ConstantInt *ConstantInt::get(const APInt& V) {
}
}
-Constant *ConstantInt::get(const Type *Ty, const APInt &V) {
- ConstantInt *C = ConstantInt::get(V);
- assert(C->getType() == Ty->getScalarType() &&
- "ConstantInt type doesn't match the type implied by its value!");
-
- // For vectors, broadcast the value.
- if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
- return
- ConstantVector::get(std::vector<Constant *>(VTy->getNumElements(), C));
-
- return C;
-}
-
//===----------------------------------------------------------------------===//
// ConstantFP
//===----------------------------------------------------------------------===//
@@ -1307,26 +1278,6 @@ void ConstantArray::destroyConstant() {
destroyConstantImpl();
}
-/// ConstantArray::get(const string&) - Return an array that is initialized to
-/// contain the specified string. If length is zero then a null terminator is
-/// added to the specified string so that it may be used in a natural way.
-/// Otherwise, the length parameter specifies how much of the string to use
-/// and it won't be null terminated.
-///
-Constant *ConstantArray::get(const std::string &Str, bool AddNull) {
- std::vector<Constant*> ElementVals;
- for (unsigned i = 0; i < Str.length(); ++i)
- ElementVals.push_back(ConstantInt::get(Type::Int8Ty, Str[i]));
-
- // Add a null terminator to the string...
- if (AddNull) {
- ElementVals.push_back(ConstantInt::get(Type::Int8Ty, 0));
- }
-
- ArrayType *ATy = ArrayType::get(Type::Int8Ty, ElementVals.size());
- return ConstantArray::get(ATy, ElementVals);
-}
-
/// isString - This method returns true if the array is an array of i8, and
/// if the elements of the array are all ConstantInt's.
bool ConstantArray::isString() const {
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index 8ce40a95b1..6c3a36fe4f 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -700,9 +700,9 @@ void BranchInst::setSuccessorV(unsigned idx, BasicBlock *B) {
// AllocationInst Implementation
//===----------------------------------------------------------------------===//
-static Value *getAISize(Value *Amt) {
+static Value *getAISize(LLVMContext &Context, Value *Amt) {
if (!Amt)
- Amt = ConstantInt::get(Type::Int32Ty, 1);
+ Amt = Context.getConstantInt(Type::Int32Ty, 1);
else {
assert(!isa<BasicBlock>(Amt) &&
"Passed basic block into allocation size parameter! Use other ctor");
@@ -712,21 +712,25 @@ static Value *getAISize(Value *Amt) {
return Amt;
}
-AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
+AllocationInst::AllocationInst(LLVMContext &C,
+ const Type *Ty, Value *ArraySize, unsigned iTy,
unsigned Align, const std::string &Name,
Instruction *InsertBefore)
- : UnaryInstruction(PointerType::getUnqual(Ty), iTy, getAISize(ArraySize),
- InsertBefore) {
+ : UnaryInstruction(PointerType::getUnqual(Ty), iTy,
+ getAISize(Context, ArraySize), InsertBefore),
+ Context(C) {
setAlignment(Align);
assert(Ty != Type::VoidTy && "Cannot allocate void!");
setName(Name);
}
-AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
+AllocationInst::AllocationInst(LLVMContext &C,
+ const Type *Ty, Value *ArraySize, unsigned iTy,
unsigned Align, const std::string &Name,
BasicBlock *InsertAtEnd)
- : UnaryInstruction(PointerType::getUnqual(Ty), iTy, getAISize(ArraySize),
- InsertAtEnd) {
+ : UnaryInstruction(PointerType::getUnqual(Ty), iTy,
+ getAISize(Context, ArraySize), InsertAtEnd),
+ Context(C) {
setAlignment(Align);
assert(Ty != Type::VoidTy && "Cannot allocate void!");
setName(Name);
@@ -753,8 +757,9 @@ const Type *AllocationInst::getAllocatedType() const {
}
AllocaInst::AllocaInst(const AllocaInst &AI)
- : AllocationInst(AI.getType()->getElementType(), (Value*)AI.getOperand(0),
- Instruction::Alloca, AI.getAlignment()) {
+ : AllocationInst(AI.Context, AI.getType()->getElementType(),
+ (Value*)AI.getOperand(0), Instruction::Alloca,
+ AI.getAlignment()) {
}
/// isStaticAlloca - Return true if this alloca is in the entry block of the
@@ -770,8 +775,9 @@ bool AllocaInst::isStaticAlloca() const {
}
MallocInst::MallocInst(const MallocInst &MI)
- : AllocationInst(MI.getType()->getElementType(), (Value*)MI.getOperand(0),
- Instruction::Malloc, MI.getAlignment()) {
+ : AllocationInst(MI.Context, MI.getType()->getElementType(),
+ (Value*)MI.getOperand(0), Instruction::Malloc,
+ MI.getAlignment()) {
}
//===----------------------------------------------------------------------===//
@@ -1173,22 +1179,6 @@ ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
setName(Name);
}
-ExtractElementInst::ExtractElementInst(Value *Val, unsigned IndexV,
- const std::string &Name,
- Instruction *InsertBef)
- : Instruction(cast<VectorType>(Val->getType())->getElementType(),
- ExtractElement,
- OperandTraits<ExtractElementInst>::op_begin(this),
- 2, InsertBef) {
- Constant *Index = ConstantInt::get(Type::Int32Ty, IndexV);
- assert(isValidOperands(Val, Index) &&
- "Invalid extractelement instruction operands!");
- Op<0>() = Val;
- Op<1>() = Index;
- setName(Name);
-}
-
-
ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
const std::string &Name,
BasicBlock *InsertAE)
@@ -1204,22 +1194,6 @@ ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
setName(Name);
}
-ExtractElementInst::ExtractElementInst(Value *Val, unsigned IndexV,
- const std::string &Name,
- BasicBlock *InsertAE)
- : Instruction(cast<VectorType>(Val->getType())->getElementType(),
- ExtractElement,
- OperandTraits<ExtractElementInst>::op_begin(this),
- 2, InsertAE) {
- Constant *Index = ConstantInt::get(Type::Int32Ty, IndexV);
- assert(isValidOperands(Val, Index) &&
- "Invalid extractelement instruction operands!");
-
- Op<0>() = Val;
- Op<1>() = Index;
- setName(Name);
-}
-
bool ExtractElementInst::isValidOperands(const Value *Val, const Value *Index) {
if (!isa<VectorType>(Val->getType()) || Index->getType() != Type::Int32Ty)
@@ -1253,22 +1227,6 @@ InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
setName(Name);
}
-InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, unsigned IndexV,
- const std::string &Name,
- Instruction *InsertBef)
- : Instruction(Vec->getType(), InsertElement,
- OperandTraits<InsertElementInst>::op_begin(this),
- 3, InsertBef) {
- Constant *Index = ConstantInt::get(Type::Int32Ty, IndexV);
- assert(isValidOperands(Vec, Elt, Index) &&
- "Invalid insertelement instruction operands!");
- Op<0>() = Vec;
- Op<1>() = Elt;
- Op<2>() = Index;
- setName(Name);
-}
-
-
InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
const std::string &Name,
BasicBlock *InsertAE)
@@ -1284,22 +1242,6 @@ InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
setName(Name);
}
-InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, unsigned IndexV,
- const std::string &Name,
- BasicBlock *InsertAE)
-: Instruction(Vec->getType(), InsertElement,
- OperandTraits<InsertElementInst>::op_begin(this),
- 3, InsertAE) {
- Constant *Index = ConstantInt::get(Type::Int32Ty, IndexV);
- assert(isValidOperands(Vec, Elt, Index) &&
- "Invalid insertelement instruction operands!");
-
- Op<0>() = Vec;
- Op<1>() = Elt;
- Op<2>() = Index;
- setName(Name);
-}
-
bool InsertElementInst::isValidOperands(const Value *Vec, const Value *Elt,
const Value *Index) {
if (!isa<VectorType>(Vec->getType()))
diff --git a/lib/VMCore/LLVMContext.cpp b/lib/VMCore/LLVMContext.cpp
index 7e436921e1..90230f0420 100644
--- a/lib/VMCore/LLVMContext.cpp
+++ b/lib/VMCore/LLVMContext.cpp
@@ -90,18 +90,30 @@ ConstantInt* LLVMContext::getConstantIntFalse() {
Constant* LLVMContext::getConstantInt(const Type* Ty, uint64_t V,
bool isSigned) {
- return ConstantInt::get(Ty, V, isSigned);
+ Constant *C = getConstantInt(cast<IntegerType>(Ty->getScalarType()),
+ V, isSigned);
+
+ // For vectors, broadcast the value.
+ if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
+ return
+ getConstantVector(std::vector<Constant *>(VTy->getNumElements(), C));
+
+ return C;
}
ConstantInt* LLVMContext::getConstantInt(const IntegerType* Ty, uint64_t V,
bool isSigned) {
- return ConstantInt::get(Ty, V, isSigned);
+ return getConstantInt(APInt(Ty->getBitWidth(), V, isSigned));
}
ConstantInt* LLVMContext::getConstantIntSigned(const IntegerType* Ty,
int64_t V) {
- return ConstantInt::getSigned(Ty, V);
+ return getConstantInt(Ty, V, true);
+}
+
+Constant *LLVMContext::getConstantIntSigned(const Type *Ty, int64_t V) {
+ return getConstantInt(Ty, V, true);
}
ConstantInt* LLVMContext::getConstantInt(const APInt& V) {
@@ -109,7 +121,16 @@ ConstantInt* LLVMContext::getConstantInt(const APInt& V) {
}
Constant* LLVMContext::getConstantInt(const Type* Ty, const APInt& V) {
- return ConstantInt::get(Ty, V);
+ ConstantInt *C = getConstantInt(V);
+ assert(C->getType() == Ty->getScalarType() &&
+ "ConstantInt type doesn't match the type implied by its value!");
+
+ // For vectors, broadcast the value.
+ if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
+ return
+ ConstantVector::get(std::vector<Constant *>(VTy->getNumElements(), C));
+
+ return C;
}
// ConstantPointerNull accessors.
@@ -153,9 +174,25 @@ Constant* LLVMContext::getConstantArray(const ArrayType* T,
return ConstantArray::get(T, Vals, NumVals);
}
-Constant* LLVMContext::getConstantArray(const std::string& Initializer,
+/// ConstantArray::get(const string&) - Return an array that is initialized to
+/// contain the specified string. If length is zero then a null terminator is
+/// added to the specified string so that it may be used in a natural way.
+/// Otherwise, the length parameter specifies how much of the string to use
+/// and it won't be null terminated.
+///
+Constant* LLVMContext::getConstantArray(const std::string& Str,
bool AddNull) {
- return ConstantArray::get(Initializer, AddNull);
+ std::vector<Constant*> ElementVals;
+ for (unsigned i = 0; i < Str.length(); ++i)
+ ElementVals.push_back(getConstantInt(Type::Int8Ty, Str[i]));
+
+ // Add a null terminator to the string...
+ if (AddNull) {
+ ElementVals.push_back(getConstantInt(Type::Int8Ty, 0));
+ }
+
+ ArrayType *ATy = getArrayType(Type::Int8Ty, ElementVals.size());
+ return getConstantArray(ATy, ElementVals);
}
diff --git a/tools/bugpoint/ExtractFunction.cpp b/tools/bugpoint/ExtractFunction.cpp
index bb35d4fab4..3df130771f 100644
--- a/tools/bugpoint/ExtractFunction.cpp
+++ b/tools/bugpoint/ExtractFunction.cpp
@@ -74,7 +74,7 @@ Module *BugDriver::deleteInstructionFromProgram(const Instruction *I,
// If this instruction produces a value, replace any users with null values
if (isa<StructType>(TheInst->getType()))
- TheInst->replaceAllUsesWith(UndefValue::get(TheInst->getType()));
+ TheInst->replaceAllUsesWith(Context.getUndef(TheInst->getType()));
else if (TheInst->getType() != Type::VoidTy)
TheInst->replaceAllUsesWith(Context.getNullValue(TheInst->getType()));
@@ -183,14 +183,15 @@ void llvm::DeleteFunctionBody(Function *F) {
/// as a constant array.
static Constant *GetTorInit(std::vector<std::pair<Function*, int> > &TorList) {
assert(!TorList.empty() && "Don't create empty tor list!");
+ LLVMContext &Context = *TorList[0].first->getContext();
std::vector<Constant*> ArrayElts;
for (unsigned i = 0, e = TorList.size(); i != e; ++i) {
std::vector<Constant*> Elts;
- Elts.push_back(ConstantInt::get(Type::Int32Ty, TorList[i].second));
+ Elts.push_back(Context.getConstantInt(Type::Int32Ty, TorList[i].second));
Elts.push_back(TorList[i].first);
- ArrayElts.push_back(ConstantStruct::get(Elts));
+ ArrayElts.push_back(Context.getConstantStruct(Elts));
}
- return ConstantArray::get(ArrayType::get(ArrayElts[0]->getType(),
+ return Context.getConstantArray(Context.getArrayType(ArrayElts[0]->getType(),
ArrayElts.size()),
ArrayElts);
}
diff --git a/tools/bugpoint/Miscompilation.cpp b/tools/bugpoint/Miscompilation.cpp
index a3a1e29b9f..4a25615285 100644
--- a/tools/bugpoint/Miscompilation.cpp
+++ b/tools/bugpoint/Miscompilation.cpp
@@ -67,7 +67,7 @@ ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
BD.EmitProgressBitcode("pass-error", false);
exit(BD.debugOptimizerCrash());
}
-
+
// Check to see if the finished program matches the reference output...
if (BD.diffProgram(BitcodeResult, "", true /*delete bitcode*/)) {
std::cout << " nope.\n";
@@ -640,6 +640,8 @@ bool BugDriver::debugMiscompilation() {
///
static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
Module *Safe) {
+ LLVMContext &Context = BD.getContext();
+
// Clean up the modules, removing extra cruft that we don't need anymore...
Test = BD.performFinalCleanups(Test);
@@ -689,8 +691,8 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
// Prototype: void *getPointerToNamedFunction(const char* Name)
Constant *resolverFunc =
Safe->getOrInsertFunction("getPointerToNamedFunction",
- PointerType::getUnqual(Type::Int8Ty),
- PointerType::getUnqual(Type::Int8Ty), (Type *)0);
+ Context.getPointerTypeUnqual(Type::Int8Ty),
+ Context.getPointerTypeUnqual(Type::Int8Ty), (Type *)0);
// Use the function we just added to get addresses of functions we need.
for (Module::iterator F = Safe->begin(), E = Safe->end(); F != E; ++F) {
@@ -701,7 +703,7 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
// Don't forward functions which are external in the test module too.
if (TestFn && !TestFn->isDeclaration()) {
// 1. Add a string constant with its name to the global file
- Constant *InitArray = ConstantArray::get(F->getName());
+ Constant *InitArray = Context.getConstantArray(F->getName());
GlobalVariable *funcName =
new GlobalVariable(*Safe, InitArray->getType(), true /*isConstant*/,
GlobalValue::InternalLinkage, InitArray,
@@ -711,9 +713,9 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
// sbyte* so it matches the signature of the resolver function.
// GetElementPtr *funcName, ulong 0, ulong 0
- std::vector<Constant*> GEPargs(2,
- BD.getContext().getNullValue(Type::Int32Ty));
- Value *GEP = ConstantExpr::getGetElementPtr(funcName, &GEPargs[0], 2);
+ std::vector<Constant*> GEPargs(2, Context.getNullValue(Type::Int32Ty));
+ Value *GEP =
+ Context.getConstantExprGetElementPtr(funcName, &GEPargs[0], 2);
std::vector<Value*> ResolverArgs;
ResolverArgs.push_back(GEP);
@@ -721,7 +723,7 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
// function that dynamically resolves the calls to F via our JIT API
if (!F->use_empty()) {
// Create a new global to hold the cached function pointer.
- Constant *NullPtr = ConstantPointerNull::get(F->getType());
+ Constant *NullPtr = Context.getConstantPointerNull(F->getType());
GlobalVariable *Cache =
new GlobalVariable(*F->getParent(), F->getType(),
false, GlobalValue::InternalLinkage,
@@ -753,7 +755,7 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
// Cast the result from the resolver to correctly-typed function.
CastInst *CastedResolver =
new BitCastInst(Resolver,
- PointerType::getUnqual(F->getFunctionType()),
+ Context.getPointerTypeUnqual(F->getFunctionType()),
"resolverCast", LookupBB);
// Save the value in our cache.
diff --git a/unittests/ExecutionEngine/JIT/JITTest.cpp b/unittests/ExecutionEngine/JIT/JITTest.cpp
index fce756b042..211b6adf47 100644
--- a/unittests/ExecutionEngine/JIT/JITTest.cpp
+++ b/unittests/ExecutionEngine/JIT/JITTest.cpp
@@ -30,14 +30,16 @@ namespace {
Function *makeReturnGlobal(std::string Name, GlobalVariable *G, Module *M) {
std::vector<const Type*> params;
- const FunctionType *FTy = FunctionType::get(G->getType()->getElementType(),
+ const FunctionType *FTy =
+ getGlobalContext().getFunctionType(G->getType()->getElementType(),
params, false);
Function *F = Function::Create(FTy, GlobalValue::ExternalLinkage, Name, M);
BasicBlock *Entry = BasicBlock::Create("entry", F);
IRBuilder<> builder(Entry);
Value *Load = builder.CreateLoad(G);
const Type *GTy = G->getType()->getElementType();
- Value *Add = builder.CreateAdd(Load, ConstantInt::get(GTy, 1LL));
+ Value *Add = builder.CreateAdd(Load,
+ getGlobalContext().getConstantInt(GTy, 1LL));
builder.CreateStore(Add, G);
builder.CreateRet(Add);
return F;
diff --git a/unittests/Support/ValueHandleTest.cpp b/unittests/Support/ValueHandleTest.cpp
index 7a709427c9..17d8f18290 100644
--- a/unittests/Support/ValueHandleTest.cpp
+++ b/unittests/Support/ValueHandleTest.cpp
@@ -25,8 +25,9 @@ protected:
Constant *ConstantV;
std::auto_ptr<BitCastInst> BitcastV;
- ValueHandle() : ConstantV(ConstantInt::get(Type::Int32Ty, 0)),
- BitcastV(new BitCastInst(ConstantV, Type::Int32Ty)) {
+ ValueHandle() :
+ ConstantV(getGlobalContext().getConstantInt(Type::Int32Ty, 0)),
+ BitcastV(new BitCastInst(ConstantV, Type::Int32Ty)) {
}
};
diff --git a/unittests/VMCore/MetadataTest.cpp b/unittests/VMCore/MetadataTest.cpp
index fcc9c6435a..c92bb139b4 100644
--- a/unittests/VMCore/MetadataTest.cpp
+++ b/unittests/VMCore/MetadataTest.cpp
@@ -23,9 +23,9 @@ namespace {
// MDString objects, even with the same string pointer and nulls in the string.
TEST(MDStringTest, CreateDifferent) {
char x[3] = { 'f', 0, 'A' };
- MDString *s1 = MDString::get(&x[0], &x[3]);
+ MDString *s1 = getGlobalContext().getMDString(&x[0], &x[3]);
x[2] = 'B';
- MDString *s2 = MDString::get(&x[0], &x[3]);
+ MDString *s2 = getGlobalContext().getMDString(&x[0], &x[3]);
EXPECT_NE(s1, s2);
}
@@ -35,8 +35,8 @@ TEST(MDStringTest, CreateSame) {
char x[4] = { 'a', 'b', 'c', 'X' };
char y[4] = { 'a', 'b', 'c', 'Y' };
- MDString *s1 = MDString::get(&x[0], &x[3]);
- MDString *s2 = MDString::get(&y[0], &y[3]);
+ MDString *s1 = getGlobalContext().getMDString(&x[0], &x[3]);
+ MDString *s2 = getGlobalContext().getMDString(&y[0], &y[3]);
EXPECT_EQ(s1, s2);
}
@@ -44,7 +44,7 @@ TEST(MDStringTest, CreateSame) {
TEST(MDStringTest, PrintingSimple) {
char *str = new char[13];
strncpy(str, "testing 1 2 3", 13);
- MDString *s = MDString::get(str, str+13);
+ MDString *s = getGlobalContext().getMDString(str, str+13);
strncpy(str, "aaaaaaaaaaaaa", 13);
delete[] str;
@@ -56,7 +56,7 @@ TEST(MDStringTest, PrintingSimple) {
// Test printing of MDString with non-printable characters.
TEST(MDStringTest, PrintingComplex) {
char str[5] = {0, '\n', '"', '\\', -1};
- MDString *s = MDString::get(str+0, str+5);
+ MDString *s = getGlobalContext().getMDString(str+0, str+5);
std::ostringstream oss;
s->print(oss);
EXPECT_STREQ("metadata !\"\\00\\0A\\22\\5C\\FF\"", oss.str().c_str());
@@ -67,19 +67,19 @@ TEST(MDNodeTest, Simple) {
char x[3] = { 'a', 'b', 'c' };
char y[3] = { '1', '2', '3' };
- MDString *s1 = MDString::get(&x[0], &x[3]);
- MDString *s2 = MDString::get(&y[0], &y[3]);
- ConstantInt *CI = ConstantInt::get(APInt(8, 0));
+ MDString *s1 = getGlobalContext().getMDString(&x[0], &x[3]);
+ MDString *s2 = getGlobalContext().getMDString(&y[0], &y[3]);
+ ConstantInt *CI = getGlobalContext().getConstantInt(APInt(8, 0));
std::vector<Value *> V;
V.push_back(s1);
V.push_back(CI);
V.push_back(s2);
- MDNode *n1 = MDNode::get(&V[0], 3);
+ MDNode *n1 = getGlobalContext().getMDNode(&V[0], 3);
Value *const c1 = n1;
- MDNode *n2 = MDNode::get(&c1, 1);
- MDNode *n3 = MDNode::get(&V[0], 3);
+ MDNode *n2 = getGlobalContext().getMDNode(&c1, 1);
+ MDNode *n3 = getGlobalContext().getMDNode(&V[0], 3);
EXPECT_NE(n1, n2);
EXPECT_EQ(n1, n3);
@@ -102,15 +102,15 @@ TEST(MDNodeTest, Simple) {
}
TEST(MDNodeTest, RAUW) {
- Constant *C = ConstantInt::get(Type::Int32Ty, 1);
+ Constant *C = getGlobalContext().getConstantInt(Type::Int32Ty, 1);
Instruction *I = new BitCastInst(C, Type::Int32Ty);
Value *const V1 = I;
- MDNode *n1 = MDNode::get(&V1, 1);
+ MDNode *n1 = getGlobalContext().getMDNode(&V1, 1);
WeakVH wn1 = n1;
Value *const V2 = C;
- MDNode *n2 = MDNode::get(&V2, 1);
+ MDNode *n2 = getGlobalContext().getMDNode(&V2, 1);
WeakVH wn2 = n2;
EXPECT_NE(wn1, wn2);
@@ -121,11 +121,11 @@ TEST(MDNodeTest, RAUW) {
}
TEST(MDNodeTest, Delete) {
- Constant *C = ConstantInt::get(Type::Int32Ty, 1);
+ Constant *C = getGlobalContext().getConstantInt(Type::Int32Ty, 1);
Instruction *I = new BitCastInst(C, Type::Int32Ty);
Value *const V = I;
- MDNode *n = MDNode::get(&V, 1);
+ MDNode *n = getGlobalContext().getMDNode(&V, 1);
WeakVH wvh = n;
EXPECT_EQ(n, wvh);