aboutsummaryrefslogtreecommitdiffstats
path: root/lib
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 /lib
parenta89b7ea9d6819606eea3ba945913127a212b836f (diff)
downloadexternal_llvm-9adc0abad3c3ed40a268ccbcee0c74cb9e1359fe.zip
external_llvm-9adc0abad3c3ed40a268ccbcee0c74cb9e1359fe.tar.gz
external_llvm-9adc0abad3c3ed40a268ccbcee0c74cb9e1359fe.tar.bz2
Move EVER MORE stuff over to LLVMContext.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75703 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-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
37 files changed, 264 insertions, 278 deletions
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp
index 0c17f14..7c68f89 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 080575d..1c8156a 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 e4d3c5e..b15355a 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 4ef43fd..5fa8dce 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 6ec3a62..455adc4 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 01f3cc7..9343b96 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 13fa758..77ec9c6 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 9043b89..3dce50b 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 baa8a47..58ff71b 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 53ce753..37ba0ef 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 8023f45..a102021 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 9c544e3..8374090 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 ebb8ce5..bf71497 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 0f4d0f4..19f1a5b 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 6f8386e..caf91c8 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 5114bc7..7f653279 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 75a0415..7f1c3cb 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 398f78a..13fe94a 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 b55dea2..d3e609d 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 dfdf5b6..8f5d50d 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 6c32050..ce976c8 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 94b37a2..7771bc4 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 36b4464..ad76ba4 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 f42827c..4160ee7 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 f3536c1..86e03c4 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 52dd06a..aa49b24 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 4116c66..50d6063 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 ac95d25..289f08c 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 83db90d..d999f9d 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 684b0963..5f72210 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 be02560..46e27c8 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 b8dd754..6cf043b 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 0e50cd1..30b1caa 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 2e13ed3..8ba1439 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 33c8f67..5c7c288 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 8ce40a9..6c3a36f 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 7e43692..90230f0 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);
}