aboutsummaryrefslogtreecommitdiff
path: root/lib/VMCore
diff options
context:
space:
mode:
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/AsmWriter.cpp16
-rw-r--r--lib/VMCore/AutoUpgrade.cpp41
-rw-r--r--lib/VMCore/BasicBlock.cpp7
-rw-r--r--lib/VMCore/ConstantFold.cpp92
-rw-r--r--lib/VMCore/Constants.cpp71
-rw-r--r--lib/VMCore/ConstantsContext.h2
-rw-r--r--lib/VMCore/Core.cpp68
-rw-r--r--lib/VMCore/Function.cpp2
-rw-r--r--lib/VMCore/InlineAsm.cpp2
-rw-r--r--lib/VMCore/Instructions.cpp100
-rw-r--r--lib/VMCore/Metadata.cpp16
-rw-r--r--lib/VMCore/Module.cpp7
-rw-r--r--lib/VMCore/Type.cpp148
-rw-r--r--lib/VMCore/Value.cpp9
-rw-r--r--lib/VMCore/ValueTypes.cpp66
-rw-r--r--lib/VMCore/Verifier.cpp34
16 files changed, 397 insertions, 284 deletions
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp
index b6d98b8573..8270f1723f 100644
--- a/lib/VMCore/AsmWriter.cpp
+++ b/lib/VMCore/AsmWriter.cpp
@@ -685,7 +685,8 @@ void SlotTracker::processFunction() {
CreateFunctionSlot(BB);
for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E;
++I) {
- if (I->getType() != Type::VoidTy && !I->hasName())
+ if (I->getType() != Type::getVoidTy(TheFunction->getContext()) &&
+ !I->hasName())
CreateFunctionSlot(I);
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
if (MDNode *N = dyn_cast<MDNode>(I->getOperand(i)))
@@ -767,7 +768,8 @@ int SlotTracker::getLocalSlot(const Value *V) {
/// CreateModuleSlot - Insert the specified GlobalValue* into the slot table.
void SlotTracker::CreateModuleSlot(const GlobalValue *V) {
assert(V && "Can't insert a null Value into SlotTracker!");
- assert(V->getType() != Type::VoidTy && "Doesn't need a slot!");
+ assert(V->getType() != Type::getVoidTy(V->getContext()) &&
+ "Doesn't need a slot!");
assert(!V->hasName() && "Doesn't need a slot!");
unsigned DestSlot = mNext++;
@@ -783,8 +785,8 @@ void SlotTracker::CreateModuleSlot(const GlobalValue *V) {
/// CreateSlot - Create a new slot for the specified value if it has no name.
void SlotTracker::CreateFunctionSlot(const Value *V) {
- assert(V->getType() != Type::VoidTy && !V->hasName() &&
- "Doesn't need a slot!");
+ assert(V->getType() != Type::getVoidTy(TheFunction->getContext()) &&
+ !V->hasName() && "Doesn't need a slot!");
unsigned DestSlot = fNext++;
fMap[V] = DestSlot;
@@ -909,7 +911,7 @@ static void WriteOptimizationInfo(raw_ostream &Out, const User *U) {
static void WriteConstantInt(raw_ostream &Out, const Constant *CV,
TypePrinting &TypePrinter, SlotTracker *Machine) {
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
- if (CI->getType() == Type::Int1Ty) {
+ if (CI->getType() == Type::getInt1Ty(CV->getContext())) {
Out << (CI->getZExtValue() ? "true" : "false");
return;
}
@@ -1725,7 +1727,7 @@ void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {
/// which slot it occupies.
///
void AssemblyWriter::printInfoComment(const Value &V) {
- if (V.getType() != Type::VoidTy) {
+ if (V.getType() != Type::getVoidTy(V.getContext())) {
Out.PadToColumn(50);
Out << "; <";
TypePrinter.print(V.getType(), Out);
@@ -1744,7 +1746,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
if (I.hasName()) {
PrintLLVMName(Out, &I);
Out << " = ";
- } else if (I.getType() != Type::VoidTy) {
+ } else if (I.getType() != Type::getVoidTy(I.getContext())) {
// Print out the def slot taken.
int SlotNum = Machine.getLocalSlot(&I);
if (SlotNum == -1)
diff --git a/lib/VMCore/AutoUpgrade.cpp b/lib/VMCore/AutoUpgrade.cpp
index 7f6c7e167e..e4c0d1afc4 100644
--- a/lib/VMCore/AutoUpgrade.cpp
+++ b/lib/VMCore/AutoUpgrade.cpp
@@ -165,7 +165,7 @@ static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
Name.compare(13,4,"psrl", 4) == 0) && Name[17] != 'i') {
const llvm::Type *VT =
- VectorType::get(IntegerType::get(64), 1);
+ VectorType::get(IntegerType::get(FTy->getContext(), 64), 1);
// We don't have to do anything if the parameter already has
// the correct type.
@@ -230,6 +230,7 @@ bool llvm::UpgradeIntrinsicFunction(Function *F, Function *&NewFn) {
// order to seamlessly integrate with existing context.
void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
Function *F = CI->getCalledFunction();
+ LLVMContext &C = CI->getContext();
assert(F && "CallInst has no function associated with it.");
@@ -265,23 +266,23 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
if (isLoadH || isLoadL) {
Value *Op1 = UndefValue::get(Op0->getType());
Value *Addr = new BitCastInst(CI->getOperand(2),
- PointerType::getUnqual(Type::DoubleTy),
+ PointerType::getUnqual(Type::getDoubleTy(C)),
"upgraded.", CI);
Value *Load = new LoadInst(Addr, "upgraded.", false, 8, CI);
- Value *Idx = ConstantInt::get(Type::Int32Ty, 0);
+ Value *Idx = ConstantInt::get(Type::getInt32Ty(C), 0);
Op1 = InsertElementInst::Create(Op1, Load, Idx, "upgraded.", CI);
if (isLoadH) {
- Idxs.push_back(ConstantInt::get(Type::Int32Ty, 0));
- Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2));
+ Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 0));
+ Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 2));
} else {
- Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2));
- Idxs.push_back(ConstantInt::get(Type::Int32Ty, 1));
+ Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 2));
+ Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 1));
}
Value *Mask = ConstantVector::get(Idxs);
SI = new ShuffleVectorInst(Op0, Op1, Mask, "upgraded.", CI);
} else if (isMovL) {
- Constant *Zero = ConstantInt::get(Type::Int32Ty, 0);
+ Constant *Zero = ConstantInt::get(Type::getInt32Ty(C), 0);
Idxs.push_back(Zero);
Idxs.push_back(Zero);
Idxs.push_back(Zero);
@@ -289,32 +290,32 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
Value *ZeroV = ConstantVector::get(Idxs);
Idxs.clear();
- Idxs.push_back(ConstantInt::get(Type::Int32Ty, 4));
- Idxs.push_back(ConstantInt::get(Type::Int32Ty, 5));
- Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2));
- Idxs.push_back(ConstantInt::get(Type::Int32Ty, 3));
+ Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 4));
+ Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 5));
+ Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 2));
+ Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 3));
Value *Mask = ConstantVector::get(Idxs);
SI = new ShuffleVectorInst(ZeroV, Op0, Mask, "upgraded.", CI);
} else if (isMovSD ||
isUnpckhPD || isUnpcklPD || isPunpckhQPD || isPunpcklQPD) {
Value *Op1 = CI->getOperand(2);
if (isMovSD) {
- Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2));
- Idxs.push_back(ConstantInt::get(Type::Int32Ty, 1));
+ Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 2));
+ Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 1));
} else if (isUnpckhPD || isPunpckhQPD) {
- Idxs.push_back(ConstantInt::get(Type::Int32Ty, 1));
- Idxs.push_back(ConstantInt::get(Type::Int32Ty, 3));
+ Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 1));
+ Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 3));
} else {
- Idxs.push_back(ConstantInt::get(Type::Int32Ty, 0));
- Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2));
+ Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 0));
+ Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 2));
}
Value *Mask = ConstantVector::get(Idxs);
SI = new ShuffleVectorInst(Op0, Op1, Mask, "upgraded.", CI);
} else if (isShufPD) {
Value *Op1 = CI->getOperand(2);
unsigned MaskVal = cast<ConstantInt>(CI->getOperand(3))->getZExtValue();
- Idxs.push_back(ConstantInt::get(Type::Int32Ty, MaskVal & 1));
- Idxs.push_back(ConstantInt::get(Type::Int32Ty,
+ Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), MaskVal & 1));
+ Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C),
((MaskVal >> 1) & 1)+2));
Value *Mask = ConstantVector::get(Idxs);
SI = new ShuffleVectorInst(Op0, Op1, Mask, "upgraded.", CI);
diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp
index 5741cbc3db..50cf84c3fe 100644
--- a/lib/VMCore/BasicBlock.cpp
+++ b/lib/VMCore/BasicBlock.cpp
@@ -38,9 +38,9 @@ LLVMContext &BasicBlock::getContext() const {
template class SymbolTableListTraits<Instruction, BasicBlock>;
-BasicBlock::BasicBlock(const Twine &Name, Function *NewParent,
+BasicBlock::BasicBlock(LLVMContext &C, const Twine &Name, Function *NewParent,
BasicBlock *InsertBefore)
- : Value(Type::LabelTy, Value::BasicBlockVal), Parent(0) {
+ : Value(Type::getLabelTy(C), Value::BasicBlockVal), Parent(0) {
// Make sure that we get added to a function
LeakDetector::addGarbageObject(this);
@@ -246,7 +246,8 @@ BasicBlock *BasicBlock::splitBasicBlock(iterator I, const Twine &BBName) {
BasicBlock *InsertBefore = next(Function::iterator(this))
.getNodePtrUnchecked();
- BasicBlock *New = BasicBlock::Create(BBName, getParent(), InsertBefore);
+ BasicBlock *New = BasicBlock::Create(getContext(), BBName,
+ getParent(), InsertBefore);
// Move all of the specified instructions from the original basic block into
// the new basic block.
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp
index e30f144658..eda336a580 100644
--- a/lib/VMCore/ConstantFold.cpp
+++ b/lib/VMCore/ConstantFold.cpp
@@ -88,7 +88,7 @@ foldConstantCastPair(
// Let CastInst::isEliminableCastPair do the heavy lifting.
return CastInst::isEliminableCastPair(firstOp, secondOp, SrcTy, MidTy, DstTy,
- Type::Int64Ty);
+ Type::getInt64Ty(DstTy->getContext()));
}
static Constant *FoldBitCast(LLVMContext &Context,
@@ -103,7 +103,7 @@ static Constant *FoldBitCast(LLVMContext &Context,
if (const PointerType *DPTy = dyn_cast<PointerType>(DestTy))
if (PTy->getAddressSpace() == DPTy->getAddressSpace()) {
SmallVector<Value*, 8> IdxList;
- Value *Zero = Constant::getNullValue(Type::Int32Ty);
+ Value *Zero = Constant::getNullValue(Type::getInt32Ty(Context));
IdxList.push_back(Zero);
const Type *ElTy = PTy->getElementType();
while (ElTy != DPTy->getElementType()) {
@@ -164,7 +164,7 @@ static Constant *FoldBitCast(LLVMContext &Context,
if (DestTy->isFloatingPoint())
return ConstantFP::get(Context, APFloat(CI->getValue(),
- DestTy != Type::PPC_FP128Ty));
+ DestTy != Type::getPPC_FP128Ty(Context)));
// Otherwise, can't fold this (vector?)
return 0;
@@ -192,7 +192,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context,
return UndefValue::get(DestTy);
}
// No compile-time operations on this type yet.
- if (V->getType() == Type::PPC_FP128Ty || DestTy == Type::PPC_FP128Ty)
+ if (V->getType() == Type::getPPC_FP128Ty(Context) || DestTy == Type::getPPC_FP128Ty(Context))
return 0;
// If the cast operand is a constant expression, there's a few things we can
@@ -241,10 +241,10 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context,
if (const ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
bool ignored;
APFloat Val = FPC->getValueAPF();
- Val.convert(DestTy == Type::FloatTy ? APFloat::IEEEsingle :
- DestTy == Type::DoubleTy ? APFloat::IEEEdouble :
- DestTy == Type::X86_FP80Ty ? APFloat::x87DoubleExtended :
- DestTy == Type::FP128Ty ? APFloat::IEEEquad :
+ Val.convert(DestTy == Type::getFloatTy(Context) ? APFloat::IEEEsingle :
+ DestTy == Type::getDoubleTy(Context) ? APFloat::IEEEdouble :
+ DestTy == Type::getX86_FP80Ty(Context) ? APFloat::x87DoubleExtended :
+ DestTy == Type::getFP128Ty(Context) ? APFloat::IEEEquad :
APFloat::Bogus,
APFloat::rmNearestTiesToEven, &ignored);
return ConstantFP::get(Context, Val);
@@ -582,7 +582,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
const Constant *C1,
const Constant *C2) {
// No compile-time operations on this type yet.
- if (C1->getType() == Type::PPC_FP128Ty)
+ if (C1->getType() == Type::getPPC_FP128Ty(Context))
return 0;
// Handle UndefValue up front
@@ -1045,11 +1045,11 @@ static int IdxCompare(LLVMContext &Context, Constant *C1, Constant *C2,
// Ok, we have two differing integer indices. Sign extend them to be the same
// type. Long is always big enough, so we use it.
- if (C1->getType() != Type::Int64Ty)
- C1 = ConstantExpr::getSExt(C1, Type::Int64Ty);
+ if (C1->getType() != Type::getInt64Ty(Context))
+ C1 = ConstantExpr::getSExt(C1, Type::getInt64Ty(Context));
- if (C2->getType() != Type::Int64Ty)
- C2 = ConstantExpr::getSExt(C2, Type::Int64Ty);
+ if (C2->getType() != Type::getInt64Ty(Context))
+ C2 = ConstantExpr::getSExt(C2, Type::getInt64Ty(Context));
if (C1 == C2) return 0; // They are equal
@@ -1085,7 +1085,7 @@ static FCmpInst::Predicate evaluateFCmpRelation(LLVMContext &Context,
"Cannot compare values of different types!");
// No compile-time operations on this type yet.
- if (V1->getType() == Type::PPC_FP128Ty)
+ if (V1->getType() == Type::getPPC_FP128Ty(Context))
return FCmpInst::BAD_FCMP_PREDICATE;
// Handle degenerate case quickly
@@ -1375,9 +1375,9 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
const Constant *C2) {
const Type *ResultTy;
if (const VectorType *VT = dyn_cast<VectorType>(C1->getType()))
- ResultTy = VectorType::get(Type::Int1Ty, VT->getNumElements());
+ ResultTy = VectorType::get(Type::getInt1Ty(Context), VT->getNumElements());
else
- ResultTy = Type::Int1Ty;
+ ResultTy = Type::getInt1Ty(Context);
// Fold FCMP_FALSE/FCMP_TRUE unconditionally.
if (pred == FCmpInst::FCMP_FALSE)
@@ -1391,7 +1391,7 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
return UndefValue::get(ResultTy);
// No compile-time operations on this type yet.
- if (C1->getType() == Type::PPC_FP128Ty)
+ if (C1->getType() == Type::getPPC_FP128Ty(Context))
return 0;
// icmp eq/ne(null,GV) -> false/true
@@ -1422,25 +1422,25 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
switch (pred) {
default: llvm_unreachable("Invalid ICmp Predicate"); return 0;
case ICmpInst::ICMP_EQ:
- return ConstantInt::get(Type::Int1Ty, V1 == V2);
+ return ConstantInt::get(Type::getInt1Ty(Context), V1 == V2);
case ICmpInst::ICMP_NE:
- return ConstantInt::get(Type::Int1Ty, V1 != V2);
+ return ConstantInt::get(Type::getInt1Ty(Context), V1 != V2);
case ICmpInst::ICMP_SLT:
- return ConstantInt::get(Type::Int1Ty, V1.slt(V2));
+ return ConstantInt::get(Type::getInt1Ty(Context), V1.slt(V2));
case ICmpInst::ICMP_SGT:
- return ConstantInt::get(Type::Int1Ty, V1.sgt(V2));
+ return ConstantInt::get(Type::getInt1Ty(Context), V1.sgt(V2));
case ICmpInst::ICMP_SLE:
- return ConstantInt::get(Type::Int1Ty, V1.sle(V2));
+ return ConstantInt::get(Type::getInt1Ty(Context), V1.sle(V2));
case ICmpInst::ICMP_SGE:
- return ConstantInt::get(Type::Int1Ty, V1.sge(V2));
+ return ConstantInt::get(Type::getInt1Ty(Context), V1.sge(V2));
case ICmpInst::ICMP_ULT:
- return ConstantInt::get(Type::Int1Ty, V1.ult(V2));
+ return ConstantInt::get(Type::getInt1Ty(Context), V1.ult(V2));
case ICmpInst::ICMP_UGT:
- return ConstantInt::get(Type::Int1Ty, V1.ugt(V2));
+ return ConstantInt::get(Type::getInt1Ty(Context), V1.ugt(V2));
case ICmpInst::ICMP_ULE:
- return ConstantInt::get(Type::Int1Ty, V1.ule(V2));
+ return ConstantInt::get(Type::getInt1Ty(Context), V1.ule(V2));
case ICmpInst::ICMP_UGE:
- return ConstantInt::get(Type::Int1Ty, V1.uge(V2));
+ return ConstantInt::get(Type::getInt1Ty(Context), V1.uge(V2));
}
} else if (isa<ConstantFP>(C1) && isa<ConstantFP>(C2)) {
APFloat C1V = cast<ConstantFP>(C1)->getValueAPF();
@@ -1451,38 +1451,38 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
case FCmpInst::FCMP_FALSE: return ConstantInt::getFalse(Context);
case FCmpInst::FCMP_TRUE: return ConstantInt::getTrue(Context);
case FCmpInst::FCMP_UNO:
- return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpUnordered);
+ return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpUnordered);
case FCmpInst::FCMP_ORD:
- return ConstantInt::get(Type::Int1Ty, R!=APFloat::cmpUnordered);
+ return ConstantInt::get(Type::getInt1Ty(Context), R!=APFloat::cmpUnordered);
case FCmpInst::FCMP_UEQ:
- return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpUnordered ||
+ return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpUnordered ||
R==APFloat::cmpEqual);
case FCmpInst::FCMP_OEQ:
- return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpEqual);
+ return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpEqual);
case FCmpInst::FCMP_UNE:
- return ConstantInt::get(Type::Int1Ty, R!=APFloat::cmpEqual);
+ return ConstantInt::get(Type::getInt1Ty(Context), R!=APFloat::cmpEqual);
case FCmpInst::FCMP_ONE:
- return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpLessThan ||
+ return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpLessThan ||
R==APFloat::cmpGreaterThan);
case FCmpInst::FCMP_ULT:
- return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpUnordered ||
+ return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpUnordered ||
R==APFloat::cmpLessThan);
case FCmpInst::FCMP_OLT:
- return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpLessThan);
+ return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpLessThan);
case FCmpInst::FCMP_UGT:
- return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpUnordered ||
+ return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpUnordered ||
R==APFloat::cmpGreaterThan);
case FCmpInst::FCMP_OGT:
- return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpGreaterThan);
+ return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpGreaterThan);
case FCmpInst::FCMP_ULE:
- return ConstantInt::get(Type::Int1Ty, R!=APFloat::cmpGreaterThan);
+ return ConstantInt::get(Type::getInt1Ty(Context), R!=APFloat::cmpGreaterThan);
case FCmpInst::FCMP_OLE:
- return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpLessThan ||
+ return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpLessThan ||
R==APFloat::cmpEqual);
case FCmpInst::FCMP_UGE:
- return ConstantInt::get(Type::Int1Ty, R!=APFloat::cmpLessThan);
+ return ConstantInt::get(Type::getInt1Ty(Context), R!=APFloat::cmpLessThan);
case FCmpInst::FCMP_OGE:
- return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpGreaterThan ||
+ return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpGreaterThan ||
R==APFloat::cmpEqual);
}
} else if (isa<VectorType>(C1->getType())) {
@@ -1557,7 +1557,7 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
// If we evaluated the result, return it now.
if (Result != -1)
- return ConstantInt::get(Type::Int1Ty, Result);
+ return ConstantInt::get(Type::getInt1Ty(Context), Result);
} else {
// Evaluate the relation between the two constants, per the predicate.
@@ -1634,7 +1634,7 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
// If we evaluated the result, return it now.
if (Result != -1)
- return ConstantInt::get(Type::Int1Ty, Result);
+ return ConstantInt::get(Type::getInt1Ty(Context), Result);
if (!isa<ConstantExpr>(C1) && isa<ConstantExpr>(C2)) {
// If C2 is a constant expr and C1 isn't, flip them around and fold the
@@ -1726,9 +1726,9 @@ Constant *llvm::ConstantFoldGetElementPtr(LLVMContext &Context,
const Type *IdxTy = Combined->getType();
if (IdxTy != Idx0->getType()) {
Constant *C1 =
- ConstantExpr::getSExtOrBitCast(Idx0, Type::Int64Ty);
+ ConstantExpr::getSExtOrBitCast(Idx0, Type::getInt64Ty(Context));
Constant *C2 = ConstantExpr::getSExtOrBitCast(Combined,
- Type::Int64Ty);
+ Type::getInt64Ty(Context));
Combined = ConstantExpr::get(Instruction::Add, C1, C2);
} else {
Combined =
@@ -1765,7 +1765,7 @@ Constant *llvm::ConstantFoldGetElementPtr(LLVMContext &Context,
// This happens with pointers to member functions in C++.
if (CE->getOpcode() == Instruction::IntToPtr && NumIdx == 1 &&
isa<ConstantInt>(CE->getOperand(0)) && isa<ConstantInt>(Idxs[0]) &&
- cast<PointerType>(CE->getType())->getElementType() == Type::Int8Ty) {
+ cast<PointerType>(CE->getType())->getElementType() == Type::getInt8Ty(Context)) {
Constant *Base = CE->getOperand(0);
Constant *Offset = Idxs[0];
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 0bff5786b8..647bc1225a 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -233,7 +233,8 @@ ConstantInt* ConstantInt::getTrue(LLVMContext &Context) {
if (pImpl->TheTrueVal)
return pImpl->TheTrueVal;
else
- return (pImpl->TheTrueVal = ConstantInt::get(IntegerType::get(1), 1));
+ return (pImpl->TheTrueVal =
+ ConstantInt::get(IntegerType::get(Context, 1), 1));
}
ConstantInt* ConstantInt::getFalse(LLVMContext &Context) {
@@ -242,7 +243,8 @@ ConstantInt* ConstantInt::getFalse(LLVMContext &Context) {
if (pImpl->TheFalseVal)
return pImpl->TheFalseVal;
else
- return (pImpl->TheFalseVal = ConstantInt::get(IntegerType::get(1), 0));
+ return (pImpl->TheFalseVal =
+ ConstantInt::get(IntegerType::get(Context, 1), 0));
}
@@ -253,7 +255,7 @@ ConstantInt* ConstantInt::getFalse(LLVMContext &Context) {
// invariant which generates an assertion.
ConstantInt *ConstantInt::get(LLVMContext &Context, const APInt& V) {
// Get the corresponding integer type for the bit width of the value.
- const IntegerType *ITy = IntegerType::get(V.getBitWidth());
+ const IntegerType *ITy = IntegerType::get(Context, V.getBitWidth());
// get an existing value or the insertion position
DenseMapAPIntKeyInfo::KeyTy Key(V, ITy);
@@ -317,16 +319,16 @@ Constant* ConstantInt::get(const Type* Ty, const APInt& V) {
//===----------------------------------------------------------------------===//
static const fltSemantics *TypeToFloatSemantics(const Type *Ty) {
- if (Ty == Type::FloatTy)
+ if (Ty == Type::getFloatTy(Ty->getContext()))
return &APFloat::IEEEsingle;
- if (Ty == Type::DoubleTy)
+ if (Ty == Type::getDoubleTy(Ty->getContext()))
return &APFloat::IEEEdouble;
- if (Ty == Type::X86_FP80Ty)
+ if (Ty == Type::getX86_FP80Ty(Ty->getContext()))
return &APFloat::x87DoubleExtended;
- else if (Ty == Type::FP128Ty)
+ else if (Ty == Type::getFP128Ty(Ty->getContext()))
return &APFloat::IEEEquad;
- assert(Ty == Type::PPC_FP128Ty && "Unknown FP format");
+ assert(Ty == Type::getPPC_FP128Ty(Ty->getContext()) && "Unknown FP format");
return &APFloat::PPCDoubleDouble;
}
@@ -389,17 +391,17 @@ ConstantFP* ConstantFP::get(LLVMContext &Context, const APFloat& V) {
if (!NewSlot) {
const Type *Ty;
if (&V.getSemantics() == &APFloat::IEEEsingle)
- Ty = Type::FloatTy;
+ Ty = Type::getFloatTy(Context);
else if (&V.getSemantics() == &APFloat::IEEEdouble)
- Ty = Type::DoubleTy;
+ Ty = Type::getDoubleTy(Context);
else if (&V.getSemantics() == &APFloat::x87DoubleExtended)
- Ty = Type::X86_FP80Ty;
+ Ty = Type::getX86_FP80Ty(Context);
else if (&V.getSemantics() == &APFloat::IEEEquad)
- Ty = Type::FP128Ty;
+ Ty = Type::getFP128Ty(Context);
else {
assert(&V.getSemantics() == &APFloat::PPCDoubleDouble &&
"Unknown FP format");
- Ty = Type::PPC_FP128Ty;
+ Ty = Type::getPPC_FP128Ty(Context);
}
NewSlot = new ConstantFP(Ty, V);
}
@@ -481,17 +483,18 @@ Constant* ConstantArray::get(const ArrayType* T, Constant* const* Vals,
/// Otherwise, the length parameter specifies how much of the string to use
/// and it won't be null terminated.
///
-Constant* ConstantArray::get(const StringRef &Str, bool AddNull) {
+Constant* ConstantArray::get(LLVMContext &Context, const StringRef &Str,
+ bool AddNull) {
std::vector<Constant*> ElementVals;
for (unsigned i = 0; i < Str.size(); ++i)
- ElementVals.push_back(ConstantInt::get(Type::Int8Ty, Str[i]));
+ ElementVals.push_back(ConstantInt::get(Type::getInt8Ty(Context), Str[i]));
// Add a null terminator to the string...
if (AddNull) {
- ElementVals.push_back(ConstantInt::get(Type::Int8Ty, 0));
+ ElementVals.push_back(ConstantInt::get(Type::getInt8Ty(Context), 0));
}
- ArrayType *ATy = ArrayType::get(Type::Int8Ty, ElementVals.size());
+ ArrayType *ATy = ArrayType::get(Type::getInt8Ty(Context), ElementVals.size());
return get(ATy, ElementVals);
}
@@ -769,7 +772,7 @@ getWithOperands(Constant* const *Ops, unsigned NumOps) const {
bool ConstantInt::isValueValidForType(const Type *Ty, uint64_t Val) {
unsigned NumBits = cast<IntegerType>(Ty)->getBitWidth(); // assert okay
- if (Ty == Type::Int1Ty)
+ if (Ty == Type::getInt1Ty(Ty->getContext()))
return Val == 0 || Val == 1;
if (NumBits >= 64)
return true; // always true, has to fit in largest type
@@ -779,7 +782,7 @@ bool ConstantInt::isValueValidForType(const Type *Ty, uint64_t Val) {
bool ConstantInt::isValueValidForType(const Type *Ty, int64_t Val) {
unsigned NumBits = cast<IntegerType>(Ty)->getBitWidth(); // assert okay
- if (Ty == Type::Int1Ty)
+ if (Ty == Type::getInt1Ty(Ty->getContext()))
return Val == 0 || Val == 1 || Val == -1;
if (NumBits >= 64)
return true; // always true, has to fit in largest type
@@ -859,7 +862,7 @@ void ConstantArray::destroyConstant() {
/// if the elements of the array are all ConstantInt's.
bool ConstantArray::isString() const {
// Check the element type for i8...
- if (getType()->getElementType() != Type::Int8Ty)
+ if (getType()->getElementType() != Type::getInt8Ty(getContext()))
return false;
// Check the elements to make sure they are all integers, not constant
// expressions.
@@ -874,7 +877,7 @@ bool ConstantArray::isString() const {
/// null bytes except its terminator.
bool ConstantArray::isCString() const {
// Check the element type for i8...
- if (getType()->getElementType() != Type::Int8Ty)
+ if (getType()->getElementType() != Type::getInt8Ty(getContext()))
return false;
// Last element must be a null.
@@ -1262,7 +1265,7 @@ Constant *ConstantExpr::getTy(const Type *ReqTy, unsigned Opcode,
assert(C1->getType() == C2->getType() &&
"Operand types in binary constant expression should match");
- if (ReqTy == C1->getType() || ReqTy == Type::Int1Ty)
+ if (ReqTy == C1->getType() || ReqTy == Type::getInt1Ty(ReqTy->getContext()))
if (Constant *FC = ConstantFoldBinaryInstruction(ReqTy->getContext(),
Opcode, C1, C2))
return FC; // Fold a few common cases...
@@ -1367,23 +1370,25 @@ Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) {
Constant* ConstantExpr::getSizeOf(const Type* Ty) {
// sizeof is implemented as: (i64) gep (Ty*)null, 1
// Note that a non-inbounds gep is used, as null isn't within any object.
- Constant *GEPIdx = ConstantInt::get(Type::Int32Ty, 1);
+ Constant *GEPIdx = ConstantInt::get(Type::getInt32Ty(Ty->getContext()), 1);
Constant *GEP = getGetElementPtr(
Constant::getNullValue(PointerType::getUnqual(Ty)), &GEPIdx, 1);
- return getCast(Instruction::PtrToInt, GEP, Type::Int64Ty);
+ return getCast(Instruction::PtrToInt, GEP,
+ Type::getInt64Ty(Ty->getContext()));
}
Constant* ConstantExpr::getAlignOf(const Type* Ty) {
// alignof is implemented as: (i64) gep ({i8,Ty}*)null, 0, 1
// Note that a non-inbounds gep is used, as null isn't within any object.
const Type *AligningTy = StructType::get(Ty->getContext(),
- Type::Int8Ty, Ty, NULL);
+ Type::getInt8Ty(Ty->getContext()), Ty, NULL);
Constant *NullPtr = Constant::getNullValue(AligningTy->getPointerTo());
- Constant *Zero = ConstantInt::get(Type::Int32Ty, 0);
- Constant *One = ConstantInt::get(Type::Int32Ty, 1);
+ Constant *Zero = ConstantInt::get(Type::getInt32Ty(Ty->getContext()), 0);
+ Constant *One = ConstantInt::get(Type::getInt32Ty(Ty->getContext()), 1);
Constant *Indices[2] = { Zero, One };
Constant *GEP = getGetElementPtr(NullPtr, Indices, 2);
- return getCast(Instruction::PtrToInt, GEP, Type::Int32Ty);
+ return getCast(Instruction::PtrToInt, GEP,
+ Type::getInt32Ty(Ty->getContext()));
}
@@ -1493,7 +1498,8 @@ ConstantExpr::getICmp(unsigned short pred, Constant* LHS, Constant* RHS) {
LLVMContextImpl *pImpl = LHS->getType()->getContext().pImpl;
// Implicitly locked.
- return pImpl->ExprConstants.getOrCreate(Type::Int1Ty, Key);
+ return
+ pImpl->ExprConstants.getOrCreate(Type::getInt1Ty(LHS->getContext()), Key);
}
Constant *
@@ -1515,7 +1521,8 @@ ConstantExpr::getFCmp(unsigned short pred, Constant* LHS, Constant* RHS) {
LLVMContextImpl *pImpl = LHS->getType()->getContext().pImpl;
// Implicitly locked.
- return pImpl->ExprConstants.getOrCreate(Type::Int1Ty, Key);
+ return
+ pImpl->ExprConstants.getOrCreate(Type::getInt1Ty(LHS->getContext()), Key);
}
Constant *ConstantExpr::getExtractElementTy(const Type *ReqTy, Constant *Val,
@@ -1537,7 +1544,7 @@ Constant *ConstantExpr::getExtractElementTy(const Type *ReqTy, Constant *Val,
Constant *ConstantExpr::getExtractElement(Constant *Val, Constant *Idx) {
assert(isa<VectorType>(Val->getType()) &&
"Tried to create extractelement operation on non-vector type!");
- assert(Idx->getType() == Type::Int32Ty &&
+ assert(Idx->getType() == Type::getInt32Ty(Val->getContext()) &&
"Extractelement index must be i32 type!");
return getExtractElementTy(cast<VectorType>(Val->getType())->getElementType(),
Val, Idx);
@@ -1566,7 +1573,7 @@ Constant *ConstantExpr::getInsertElement(Constant *Val, Constant *Elt,
"Tried to create insertelement operation on non-vector type!");
assert(Elt->getType() == cast<VectorType>(Val->getType())->getElementType()
&& "Insertelement types must match!");
- assert(Idx->getType() == Type::Int32Ty &&
+ assert(Idx->getType() == Type::getInt32Ty(Val->getContext()) &&
"Insertelement index must be i32 type!");
return getInsertElementTy(Val->getType(), Val, Elt, Idx);
}
diff --git a/lib/VMCore/ConstantsContext.h b/lib/VMCore/ConstantsContext.h
index f1d4b25e1b..be75f11e19 100644
--- a/lib/VMCore/ConstantsContext.h
+++ b/lib/VMCore/ConstantsContext.h
@@ -446,7 +446,7 @@ struct ConstantCreator<ConstantAggregateZero, Type, ValType> {
template<>
struct ConstantCreator<MDNode, Type, std::vector<Value*> > {
static MDNode *create(const Type* Ty, const std::vector<Value*> &V) {
- return new MDNode(&V[0], V.size());
+ return new MDNode(Ty->getContext(), &V[0], V.size());
}
};
diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp
index 88160e1629..b2715d9d21 100644
--- a/lib/VMCore/Core.cpp
+++ b/lib/VMCore/Core.cpp
@@ -153,14 +153,24 @@ LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty) {
/*--.. Operations on integer types .........................................--*/
-LLVMTypeRef LLVMInt1Type(void) { return (LLVMTypeRef) Type::Int1Ty; }
-LLVMTypeRef LLVMInt8Type(void) { return (LLVMTypeRef) Type::Int8Ty; }
-LLVMTypeRef LLVMInt16Type(void) { return (LLVMTypeRef) Type::Int16Ty; }
-LLVMTypeRef LLVMInt32Type(void) { return (LLVMTypeRef) Type::Int32Ty; }
-LLVMTypeRef LLVMInt64Type(void) { return (LLVMTypeRef) Type::Int64Ty; }
+LLVMTypeRef LLVMInt1Type(void) {
+ return (LLVMTypeRef) Type::getInt1Ty(getGlobalContext());
+}
+LLVMTypeRef LLVMInt8Type(void) {
+ return (LLVMTypeRef) Type::getInt8Ty(getGlobalContext());
+}
+LLVMTypeRef LLVMInt16Type(void) {
+ return (LLVMTypeRef) Type::getInt16Ty(getGlobalContext());
+}
+LLVMTypeRef LLVMInt32Type(void) {
+ return (LLVMTypeRef) Type::getInt32Ty(getGlobalContext());
+}
+LLVMTypeRef LLVMInt64Type(void) {
+ return (LLVMTypeRef) Type::getInt64Ty(getGlobalContext());
+}
LLVMTypeRef LLVMIntType(unsigned NumBits) {
- return wrap(IntegerType::get(NumBits));
+ return wrap(IntegerType::get(getGlobalContext(), NumBits));
}
unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy) {
@@ -169,11 +179,21 @@ unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy) {
/*--.. Operations on real types ............................................--*/
-LLVMTypeRef LLVMFloatType(void) { return (LLVMTypeRef) Type::FloatTy; }
-LLVMTypeRef LLVMDoubleType(void) { return (LLVMTypeRef) Type::DoubleTy; }
-LLVMTypeRef LLVMX86FP80Type(void) { return (LLVMTypeRef) Type::X86_FP80Ty; }
-LLVMTypeRef LLVMFP128Type(void) { return (LLVMTypeRef) Type::FP128Ty; }
-LLVMTypeRef LLVMPPCFP128Type(void) { return (LLVMTypeRef) Type::PPC_FP128Ty; }
+LLVMTypeRef LLVMFloatType(void) {
+ return (LLVMTypeRef) Type::getFloatTy(getGlobalContext());
+}
+LLVMTypeRef LLVMDoubleType(void) {
+ return (LLVMTypeRef) Type::getDoubleTy(getGlobalContext());
+}
+LLVMTypeRef LLVMX86FP80Type(void) {
+ retu