summaryrefslogtreecommitdiff
path: root/lib/VMCore
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-08-13 21:58:54 +0000
committerOwen Anderson <resistor@mac.com>2009-08-13 21:58:54 +0000
commit1d0be15f89cb5056e20e2d24faa8d6afb1573bca (patch)
tree2cdabe223bfce83bd12e10dd557147a2f68c9bf8 /lib/VMCore
parentd163e8b14c8aa5bbbb129e3f0dffdbe7213a3c72 (diff)
downloadllvm-1d0be15f89cb5056e20e2d24faa8d6afb1573bca.tar.gz
llvm-1d0be15f89cb5056e20e2d24faa8d6afb1573bca.tar.bz2
llvm-1d0be15f89cb5056e20e2d24faa8d6afb1573bca.tar.xz
Push LLVMContexts through the IntegerType APIs.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78948 91177308-0d34-0410-b5e6-96231b3b80d8
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) {
+ return (LLVMTypeRef) Type::getX86_FP80Ty(getGlobalContext());
+}
+LLVMTypeRef LLVMFP128Type(void) {
+ return (LLVMTypeRef) Type::getFP128Ty(getGlobalContext());
+}
+LLVMTypeRef LLVMPPCFP128Type(void) {
+ return (LLVMTypeRef) Type::getPPC_FP128Ty(getGlobalContext());
+}
/*--.. Operations on function types ........................................--*/
@@ -265,8 +285,12 @@ unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy) {
/*--.. Operations on other types ...........................................--*/
-LLVMTypeRef LLVMVoidType(void) { return (LLVMTypeRef) Type::VoidTy; }
-LLVMTypeRef LLVMLabelType(void) { return (LLVMTypeRef) Type::LabelTy; }
+LLVMTypeRef LLVMVoidType(void) {
+ return (LLVMTypeRef) Type::getVoidTy(getGlobalContext());
+}
+LLVMTypeRef LLVMLabelType(void) {
+ return (LLVMTypeRef) Type::getLabelTy(getGlobalContext());
+}
LLVMTypeRef LLVMOpaqueType(void) {
return wrap(OpaqueType::get());
@@ -364,15 +388,15 @@ LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
static const fltSemantics &SemanticsForType(Type *Ty) {
assert(Ty->isFloatingPoint() && "Type is not floating point!");
- if (Ty == Type::FloatTy)
+ if (Ty == Type::getFloatTy(getGlobalContext()))
return APFloat::IEEEsingle;
- if (Ty == Type::DoubleTy)
+ if (Ty == Type::getDoubleTy(getGlobalContext()))
return APFloat::IEEEdouble;
- if (Ty == Type::X86_FP80Ty)
+ if (Ty == Type::getX86_FP80Ty(getGlobalContext()))
return APFloat::x87DoubleExtended;
- if (Ty == Type::FP128Ty)
+ if (Ty == Type::getFP128Ty(getGlobalContext()))
return APFloat::IEEEquad;
- if (Ty == Type::PPC_FP128Ty)
+ if (Ty == Type::getPPC_FP128Ty(getGlobalContext()))
return APFloat::PPCDoubleDouble;
return APFloat::Bogus;
}
@@ -396,7 +420,7 @@ LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
int DontNullTerminate) {
/* Inverted the sense of AddNull because ', 0)' is a
better mnemonic for null termination than ', 1)'. */
- return wrap(ConstantArray::get(std::string(Str, Length),
+ return wrap(ConstantArray::get(getGlobalContext(), std::string(Str, Length),
DontNullTerminate == 0));
}
@@ -1113,13 +1137,15 @@ LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB) {
}
LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef FnRef, const char *Name) {
- return wrap(BasicBlock::Create(Name, unwrap<Function>(FnRef)));
+ return wrap(BasicBlock::Create(getGlobalContext(), Name,
+ unwrap<Function>(FnRef)));
}
LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBBRef,
const char *Name) {
BasicBlock *InsertBeforeBB = unwrap(InsertBeforeBBRef);
- return wrap(BasicBlock::Create(Name, InsertBeforeBB->getParent(),
+ return wrap(BasicBlock::Create(getGlobalContext(), Name,
+ InsertBeforeBB->getParent(),
InsertBeforeBB));
}
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index 481300500c..8ad885c4c2 100644
--- a/lib/VMCore/Function.cpp
+++ b/lib/VMCore/Function.cpp
@@ -182,7 +182,7 @@ void Function::BuildLazyArguments() const {
// Create the arguments vector, all arguments start out unnamed.
const FunctionType *FT = getFunctionType();
for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
- assert(FT->getParamType(i) != Type::VoidTy &&
+ assert(FT->getParamType(i) != Type::getVoidTy(FT->getContext()) &&
"Cannot have void typed arguments!");
ArgumentList.push_back(new Argument(FT->getParamType(i)));
}
diff --git a/lib/VMCore/InlineAsm.cpp b/lib/VMCore/InlineAsm.cpp
index 485092e6ff..fbd6b90f93 100644
--- a/lib/VMCore/InlineAsm.cpp
+++ b/lib/VMCore/InlineAsm.cpp
@@ -213,7 +213,7 @@ bool InlineAsm::Verify(const FunctionType *Ty, const StringRef &ConstStr) {
switch (NumOutputs) {
case 0:
- if (Ty->getReturnType() != Type::VoidTy) return false;
+ if (Ty->getReturnType() != Type::getVoidTy(Ty->getContext())) return false;
break;
case 1:
if (isa<StructType>(Ty->getReturnType())) return false;
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index 902d806f23..bbea62bded 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -126,7 +126,7 @@ const char *SelectInst::areInvalidOperands(Value *Op0, Value *Op1, Value *Op2) {
if (const VectorType *VT = dyn_cast<VectorType>(Op0->getType())) {
// Vector select.
- if (VT->getElementType() != Type::Int1Ty)
+ if (VT->getElementType() != Type::getInt1Ty(Op0->getContext()))
return "vector select condition element type must be i1";
const VectorType *ET = dyn_cast<VectorType>(Op1->getType());
if (ET == 0)
@@ -134,7 +134,7 @@ const char *SelectInst::areInvalidOperands(Value *Op0, Value *Op1, Value *Op2) {
if (ET->getNumElements() != VT->getNumElements())
return "vector select requires selected vectors to have "
"the same vector length as select condition";
- } else if (Op0->getType() != Type::Int1Ty) {
+ } else if (Op0->getType() != Type::getInt1Ty(Op0->getContext())) {
return "select condition must be i1 or <n x i1>";
}
return 0;
@@ -502,7 +502,7 @@ void InvokeInst::removeAttribute(unsigned i, Attributes attr) {
//===----------------------------------------------------------------------===//
ReturnInst::ReturnInst(const ReturnInst &RI)
- : TerminatorInst(Type::VoidTy, Instruction::Ret,
+ : TerminatorInst(Type::getVoidTy(RI.getContext()), Instruction::Ret,
OperandTraits<ReturnInst>::op_end(this) -
RI.getNumOperands(),
RI.getNumOperands()) {
@@ -510,22 +510,22 @@ ReturnInst::ReturnInst(const ReturnInst &RI)
Op<0>() = RI.Op<0>();
}
-ReturnInst::ReturnInst(Value *retVal, Instruction *InsertBefore)
- : TerminatorInst(Type::VoidTy, Instruction::Ret,
+ReturnInst::ReturnInst(LLVMContext &C, Value *retVal, Instruction *InsertBefore)
+ : TerminatorInst(Type::getVoidTy(C), Instruction::Ret,
OperandTraits<ReturnInst>::op_end(this) - !!retVal, !!retVal,
InsertBefore) {
if (retVal)
Op<0>() = retVal;
}
-ReturnInst::ReturnInst(Value *retVal, BasicBlock *InsertAtEnd)
- : TerminatorInst(Type::VoidTy, Instruction::Ret,
+ReturnInst::ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd)
+ : TerminatorInst(Type::getVoidTy(C), Instruction::Ret,
OperandTraits<ReturnInst>::op_end(this) - !!retVal, !!retVal,
InsertAtEnd) {
if (retVal)
Op<0>() = retVal;
}
-ReturnInst::ReturnInst(BasicBlock *InsertAtEnd)
- : TerminatorInst(Type::VoidTy, Instruction::Ret,
+ReturnInst::ReturnInst(LLVMContext &Context, BasicBlock *InsertAtEnd)
+ : TerminatorInst(Type::getVoidTy(Context), Instruction::Ret,
OperandTraits<ReturnInst>::op_end(this), 0, InsertAtEnd) {
}
@@ -551,11 +551,13 @@ ReturnInst::~ReturnInst() {
// UnwindInst Implementation
//===----------------------------------------------------------------------===//
-UnwindInst::UnwindInst(Instruction *InsertBefore)
- : TerminatorInst(Type::VoidTy, Instruction::Unwind, 0, 0, InsertBefore) {
+UnwindInst::UnwindInst(LLVMContext &Context, Instruction *InsertBefore)
+ : TerminatorInst(Type::getVoidTy(Context), Instruction::Unwind,
+ 0, 0, InsertBefore) {
}
-UnwindInst::UnwindInst(BasicBlock *InsertAtEnd)
- : TerminatorInst(Type::VoidTy, Instruction::Unwind, 0, 0, InsertAtEnd) {
+UnwindInst::UnwindInst(LLVMContext &Context, BasicBlock *InsertAtEnd)
+ : TerminatorInst(Type::getVoidTy(Context), Instruction::Unwind,
+ 0, 0, InsertAtEnd) {
}
@@ -576,11 +578,14 @@ BasicBlock *UnwindInst::getSuccessorV(unsigned idx) const {
// UnreachableInst Implementation
//===----------------------------------------------------------------------===//
-UnreachableInst::UnreachableInst(Instruction *InsertBefore)
- : TerminatorInst(Type::VoidTy, Instruction::Unreachable, 0, 0, InsertBefore) {
+UnreachableInst::UnreachableInst(LLVMContext &Context,
+ Instruction *InsertBefore)
+ : TerminatorInst(Type::getVoidTy(Context), Instruction::Unreachable,
+ 0, 0, InsertBefore) {
}
-UnreachableInst::UnreachableInst(BasicBlock *InsertAtEnd)
- : TerminatorInst(Type::VoidTy, Instruction::Unreachable, 0, 0, InsertAtEnd) {
+UnreachableInst::UnreachableInst(LLVMContext &Context, BasicBlock *InsertAtEnd)
+ : TerminatorInst(Type::getVoidTy(Context), Instruction::Unreachable,
+ 0, 0, InsertAtEnd) {
}
unsigned UnreachableInst::getNumSuccessorsV() const {
@@ -602,12 +607,12 @@ BasicBlock *UnreachableInst::getSuccessorV(unsigned idx) const {
void BranchInst::AssertOK() {
if (isConditional())
- assert(getCondition()->getType() == Type::Int1Ty &&
+ assert(getCondition()->getType() == Type::getInt1Ty(getContext()) &&
"May only branch on boolean predicates!");
}
BranchInst::BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore)
- : TerminatorInst(Type::VoidTy, Instruction::Br,
+ : TerminatorInst(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
OperandTraits<BranchInst>::op_end(this) - 1,
1, InsertBefore) {
assert(IfTrue != 0 && "Branch destination may not be null!");
@@ -615,7 +620,7 @@ BranchInst::BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore)
}
BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
Instruction *InsertBefore)
- : TerminatorInst(Type::VoidTy, Instruction::Br,
+ : TerminatorInst(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
OperandTraits<BranchInst>::op_end(this) - 3,
3, InsertBefore) {
Op<-1>() = IfTrue;
@@ -627,7 +632,7 @@ BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
}
BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
- : TerminatorInst(Type::VoidTy, Instruction::Br,
+ : TerminatorInst(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
OperandTraits<BranchInst>::op_end(this) - 1,
1, InsertAtEnd) {
assert(IfTrue != 0 && "Branch destination may not be null!");
@@ -636,7 +641,7 @@ BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
BasicBlock *InsertAtEnd)
- : TerminatorInst(Type::VoidTy, Instruction::Br,
+ : TerminatorInst(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
OperandTraits<BranchInst>::op_end(this) - 3,
3, InsertAtEnd) {
Op<-1>() = IfTrue;
@@ -649,7 +654,7 @@ BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
BranchInst::BranchInst(const BranchInst &BI) :
- TerminatorInst(Type::VoidTy, Instruction::Br,
+ TerminatorInst(Type::getVoidTy(BI.getContext()), Instruction::Br,
OperandTraits<BranchInst>::op_end(this) - BI.getNumOperands(),
BI.getNumOperands()) {
Op<-1>() = BI.Op<-1>();
@@ -702,11 +707,11 @@ void BranchInst::setSuccessorV(unsigned idx, BasicBlock *B) {
static Value *getAISize(LLVMContext &Context, Value *Amt) {
if (!Amt)
- Amt = ConstantInt::get(Type::Int32Ty, 1);
+ Amt = ConstantInt::get(Type::getInt32Ty(Context), 1);
else {
assert(!isa<BasicBlock>(Amt) &&
"Passed basic block into allocation size parameter! Use other ctor");
- assert(Amt->getType() == Type::Int32Ty &&
+ assert(Amt->getType() == Type::getInt32Ty(Context) &&
"Malloc/Allocation array size is not a 32-bit integer!");
}
return Amt;
@@ -718,7 +723,7 @@ AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
: UnaryInstruction(PointerType::getUnqual(Ty), iTy,
getAISize(Ty->getContext(), ArraySize), InsertBefore) {
setAlignment(Align);
- assert(Ty != Type::VoidTy && "Cannot allocate void!");
+ assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!");
setName(Name);
}
@@ -728,7 +733,7 @@ AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
: UnaryInstruction(PointerType::getUnqual(Ty), iTy,
getAISize(Ty->getContext(), ArraySize), InsertAtEnd) {
setAlignment(Align);
- assert(Ty != Type::VoidTy && "Cannot allocate void!");
+ assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!");
setName(Name);
}
@@ -786,12 +791,14 @@ void FreeInst::AssertOK() {
}
FreeInst::FreeInst(Value *Ptr, Instruction *InsertBefore)
- : UnaryInstruction(Type::VoidTy, Free, Ptr, InsertBefore) {
+ : UnaryInstruction(Type::getVoidTy(Ptr->getContext()),
+ Free, Ptr, InsertBefore) {
AssertOK();
}
FreeInst::FreeInst(Value *Ptr, BasicBlock *InsertAtEnd)
- : UnaryInstruction(Type::VoidTy, Free, Ptr, InsertAtEnd) {
+ : UnaryInstruction(Type::getVoidTy(Ptr->getContext()),
+ Free, Ptr, InsertAtEnd) {
AssertOK();
}
@@ -923,7 +930,7 @@ void StoreInst::AssertOK() {
StoreInst::StoreInst(Value *val, Value *addr, Instruction *InsertBefore)
- : Instruction(Type::VoidTy, Store,
+ : Instruction(Type::getVoidTy(val->getContext()), Store,
OperandTraits<StoreInst>::op_begin(this),
OperandTraits<StoreInst>::operands(this),
InsertBefore) {
@@ -935,7 +942,7 @@ StoreInst::StoreInst(Value *val, Value *addr, Instruction *InsertBefore)
}
StoreInst::StoreInst(Value *val, Value *addr, BasicBlock *InsertAtEnd)
- : Instruction(Type::VoidTy, Store,
+ : Instruction(Type::getVoidTy(val->getContext()), Store,
OperandTraits<StoreInst>::op_begin(this),
OperandTraits<StoreInst>::operands(this),
InsertAtEnd) {
@@ -948,7 +955,7 @@ StoreInst::StoreInst(Value *val, Value *addr, BasicBlock *InsertAtEnd)
StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
Instruction *InsertBefore)
- : Instruction(Type::VoidTy, Store,
+ : Instruction(Type::getVoidTy(val->getContext()), Store,
OperandTraits<StoreInst>::op_begin(this),
OperandTraits<StoreInst>::operands(this),
InsertBefore) {
@@ -961,7 +968,7 @@ StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
unsigned Align, Instruction *InsertBefore)
- : Instruction(Type::VoidTy, Store,
+ : Instruction(Type::getVoidTy(val->getContext()), Store,
OperandTraits<StoreInst>::op_begin(this),
OperandTraits<StoreInst>::operands(this),
InsertBefore) {
@@ -974,7 +981,7 @@ StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
unsigned Align, BasicBlock *InsertAtEnd)
- : Instruction(Type::VoidTy, Store,
+ : Instruction(Type::getVoidTy(val->getContext()), Store,
OperandTraits<StoreInst>::op_begin(this),
OperandTraits<StoreInst>::operands(this),
InsertAtEnd) {
@@ -987,7 +994,7 @@ StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
BasicBlock *InsertAtEnd)
- : Instruction(Type::VoidTy, Store,
+ : Instruction(Type::getVoidTy(val->getContext()), Store,
OperandTraits<StoreInst>::op_begin(this),
OperandTraits<StoreInst>::operands(this),
InsertAtEnd) {
@@ -1193,7 +1200,8 @@ ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
bool ExtractElementInst::isValidOperands(const Value *Val, const Value *Index) {
- if (!isa<VectorType>(Val->getType()) || Index->getType() != Type::Int32Ty)
+ if (!isa<VectorType>(Val->getType()) ||
+ Index->getType() != Type::getInt32Ty(Val->getContext()))
return false;
return true;
}
@@ -1247,7 +1255,7 @@ bool InsertElementInst::isValidOperands(const Value *Vec, const Value *Elt,
if (Elt->getType() != cast<VectorType>(Vec->getType())->getElementType())
return false;// Second operand of insertelement must be vector element type.
- if (Index->getType() != Type::Int32Ty)
+ if (Index->getType() != Type::getInt32Ty(Vec->getContext()))
return false; // Third operand of insertelement must be i32.
return true;
}
@@ -1306,7 +1314,7 @@ bool ShuffleVectorInst::isValidOperands(const Value *V1, const Value *V2,
const VectorType *MaskTy = dyn_cast<VectorType>(Mask->getType());
if (!isa<Constant>(Mask) || MaskTy == 0 ||
- MaskTy->getElementType() != Type::Int32Ty)
+ MaskTy->getElementType() != Type::getInt32Ty(V1->getContext()))
return false;
return true;
}
@@ -2758,7 +2766,8 @@ void SwitchInst::init(Value *Value, BasicBlock *Default, unsigned NumCases) {
/// constructor can also autoinsert before another instruction.
SwitchInst::SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
Instruction *InsertBefore)
- : TerminatorInst(Type::VoidTy, Instruction::Switch, 0, 0, InsertBefore) {
+ : TerminatorInst(Type::getVoidTy(Value->getContext()), Instruction::Switch,
+ 0, 0, InsertBefore) {
init(Value, Default, NumCases);
}
@@ -2768,12 +2777,13 @@ SwitchInst::SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
/// constructor also autoinserts at the end of the specified BasicBlock.
SwitchInst::SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
BasicBlock *InsertAtEnd)
- : TerminatorInst(Type::VoidTy, Instruction::Switch, 0, 0, InsertAtEnd) {
+ : TerminatorInst(Type::getVoidTy(Value->getContext()), Instruction::Switch,
+ 0, 0, InsertAtEnd) {
init(Value, Default, NumCases);
}
SwitchInst::SwitchInst(const SwitchInst &SI)
- : TerminatorInst(Type::VoidTy, Instruction::Switch,
+ : TerminatorInst(Type::getVoidTy(SI.getContext()), Instruction::Switch,
allocHungoffUses(SI.getNumOperands()), SI.getNumOperands()) {
Use *OL = OperandList, *InOL = SI.OperandList;
for (unsigned i = 0, E = SI.getNumOperands(); i != E; i+=2) {
@@ -3006,10 +3016,10 @@ InvokeInst *InvokeInst::clone(LLVMContext&) const {
return new(getNumOperands()) InvokeInst(*this);
}
-UnwindInst *UnwindInst::clone(LLVMContext&) const {
- return new UnwindInst();
+UnwindInst *UnwindInst::clone(LLVMContext &C) const {
+ return new UnwindInst(C);
}
-UnreachableInst *UnreachableInst::clone(LLVMContext&) const {
- return new UnreachableInst();
+UnreachableInst *UnreachableInst::clone(LLVMContext &C) const {
+ return new UnreachableInst(C);
}
diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp
index 4762a10555..208e1bcedc 100644
--- a/lib/VMCore/Metadata.cpp
+++ b/lib/VMCore/Metadata.cpp
@@ -55,7 +55,7 @@ MDString *MDString::get(LLVMContext &Context, const StringRef &Str) {
StringMapEntry<MDString *> &Entry =
pImpl->MDStringCache.GetOrCreateValue(Str);
MDString *&S = Entry.getValue();
- if (!S) S = new MDString(Entry.getKeyData(),
+ if (!S) S = new MDString(Context, Entry.getKeyData(),
Entry.getKeyLength());
return S;
@@ -64,8 +64,8 @@ MDString *MDString::get(LLVMContext &Context, const StringRef &Str) {
//===----------------------------------------------------------------------===//
//MDNode implementation
//
-MDNode::MDNode(Value*const* Vals, unsigned NumVals)
- : MetadataBase(Type::MetadataTy, Value::MDNodeVal) {
+MDNode::MDNode(LLVMContext &C, Value*const* Vals, unsigned NumVals)
+ : MetadataBase(Type::getMetadataTy(C), Value::MDNodeVal) {
NumOperands = 0;
resizeOperands(NumVals);
for (unsigned i = 0; i != NumVals; ++i) {
@@ -83,7 +83,7 @@ MDNode *MDNode::get(LLVMContext &Context, Value*const* Vals, unsigned NumVals) {
for (unsigned i = 0; i < NumVals; ++i)
V.push_back(Vals[i]);
- return pImpl->MDNodes.getOrCreate(Type::MetadataTy, V);
+ return pImpl->MDNodes.getOrCreate(Type::getMetadataTy(Context), V);
}
/// dropAllReferences - Remove all uses and clear node vector.
@@ -108,9 +108,10 @@ MDNode::~MDNode() {
//===----------------------------------------------------------------------===//
//NamedMDNode implementation
//
-NamedMDNode::NamedMDNode(const Twine &N, MetadataBase*const* MDs,
+NamedMDNode::NamedMDNode(LLVMContext &C, const Twine &N,
+ MetadataBase*const* MDs,
unsigned NumMDs, Module *ParentModule)
- : MetadataBase(Type::MetadataTy, Value::NamedMDNodeVal), Parent(0) {
+ : MetadataBase(Type::getMetadataTy(C), Value::NamedMDNodeVal), Parent(0) {
setName(N);
NumOperands = 0;
resizeOperands(NumMDs);
@@ -129,7 +130,8 @@ NamedMDNode *NamedMDNode::Create(const NamedMDNode *NMD, Module *M) {
SmallVector<MetadataBase *, 4> Elems;
for (unsigned i = 0, e = NMD->getNumElements(); i != e; ++i)
Elems.push_back(NMD->getElement(i));
- return new NamedMDNode(NMD->getName().data(), Elems.data(), Elems.size(), M);
+ return new NamedMDNode(NMD->getContext(), NMD->getName().data(),
+ Elems.data(), Elems.size(), M);
}
/// eraseFromParent - Drop all references and remove the node from parent
diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp
index e06e79a026..add2449107 100644
--- a/lib/VMCore/Module.cpp
+++ b/lib/VMCore/Module.cpp
@@ -31,14 +31,15 @@ using namespace llvm;
//
GlobalVariable *ilist_traits<GlobalVariable>::createSentinel() {
- GlobalVariable *Ret = new GlobalVariable(getGlobalContext(), Type::Int32Ty,
+ GlobalVariable *Ret = new GlobalVariable(getGlobalContext(),
+ Type::getInt32Ty(getGlobalContext()),
false, GlobalValue::ExternalLinkage);
// This should not be garbage monitored.
LeakDetector::removeGarbageObject(Ret);
return Ret;
}
GlobalAlias *ilist_traits<GlobalAlias>::createSentinel() {
- GlobalAlias *Ret = new GlobalAlias(Type::Int32Ty,
+ GlobalAlias *Ret = new GlobalAlias(Type::getInt32Ty(getGlobalContext()),
GlobalValue::ExternalLinkage);
// This should not be garbage monitored.
LeakDetector::removeGarbageObject(Ret);
@@ -303,7 +304,7 @@ NamedMDNode *Module::getOrInsertNamedMetadata(const StringRef &Name) {
NamedMDNode *NMD =
dyn_cast_or_null<NamedMDNode>(getValueSymbolTable().lookup(Name));
if (!NMD)
- NMD = NamedMDNode::Create(Name, NULL, 0, this);
+ NMD = NamedMDNode::Create(getContext(), Name, NULL, 0, this);
return NMD;
}
diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp
index ac55096ac8..3072e838b5 100644
--- a/lib/VMCore/Type.cpp
+++ b/lib/VMCore/Type.cpp
@@ -103,26 +103,26 @@ void Type::destroy() const {
delete this;
}
-const Type *Type::getPrimitiveType(TypeID IDNumber) {
+const Type *Type::getPrimitiveType(LLVMContext &C, TypeID IDNumber) {
switch (IDNumber) {
- case VoidTyID : return VoidTy;
- case FloatTyID : return FloatTy;
- case DoubleTyID : return DoubleTy;
- case X86_FP80TyID : return X86_FP80Ty;
- case FP128TyID : return FP128Ty;
- case PPC_FP128TyID : return PPC_FP128Ty;
- case LabelTyID : return LabelTy;
- case MetadataTyID : return MetadataTy;
+ case VoidTyID : return getVoidTy(C);
+ case FloatTyID : return getFloatTy(C);
+ case DoubleTyID : return getDoubleTy(C);
+ case X86_FP80TyID : return getX86_FP80Ty(C);
+ case FP128TyID : return getFP128Ty(C);
+ case PPC_FP128TyID : return getPPC_FP128Ty(C);
+ case LabelTyID : return getLabelTy(C);
+ case MetadataTyID : return getMetadataTy(C);
default:
return 0;
}
}
-const Type *Type::getVAArgsPromotedType() const {
+const Type *Type::getVAArgsPromotedType(LLVMContext &C) const {
if (ID == IntegerTyID && getSubclassData() < 32)
- return Type::Int32Ty;
+ return Type::getInt32Ty(C);
else if (ID == FloatTyID)
- return Type::DoubleTy;
+ return Type::getDoubleTy(C);
else
return this;
}
@@ -288,7 +288,7 @@ std::string Type::getDescription() const {
bool StructType::indexValid(const Value *V) const {
// Structure indexes require 32-bit integer constants.
- if (V->getType() == Type::Int32Ty)
+ if (V->getType() == Type::getInt32Ty(V->getContext()))
if (const ConstantInt *CU = dyn_cast<ConstantInt>(V))
return indexValid(CU->getZExtValue());
return false;
@@ -315,25 +315,76 @@ const Type *StructType::getTypeAtIndex(unsigned Idx) const {
// Primitive 'Type' data
//===----------------------------------------------------------------------===//
-const Type *Type::VoidTy = new Type(Type::VoidTyID);
-const Type *Type::FloatTy = new Type(Type::FloatTyID);
-const Type *Type::DoubleTy = new Type(Type::DoubleTyID);
-const Type *Type::X86_FP80Ty = new Type(Type::X86_FP80TyID);
-const Type *Type::FP128Ty = new Type(Type::FP128TyID);
-const Type *Type::PPC_FP128Ty = new Type(Type::PPC_FP128TyID);
-const Type *Type::LabelTy = new Type(Type::LabelTyID);
-const Type *Type::MetadataTy = new Type(Type::MetadataTyID);
-
namespace {
struct BuiltinIntegerType : public IntegerType {
explicit BuiltinIntegerType(unsigned W) : IntegerType(W) {}
};
}
-const IntegerType *Type::Int1Ty = new BuiltinIntegerType(1);
-const IntegerType *Type::Int8Ty = new BuiltinIntegerType(8);
-const IntegerType *Type::Int16Ty = new BuiltinIntegerType(16);
-const IntegerType *Type::Int32Ty = new BuiltinIntegerType(32);
-const IntegerType *Type::Int64Ty = new BuiltinIntegerType(64);
+
+const Type *Type::getVoidTy(LLVMContext &C) {
+ static const Type *VoidTy = new Type(Type::VoidTyID);
+ return VoidTy;
+}
+
+const Type *Type::getLabelTy(LLVMContext &C) {
+ static const Type *LabelTy = new Type(Type::LabelTyID);
+ return LabelTy;
+}
+
+const Type *Type::getFloatTy(LLVMContext &C) {
+ static const Type *FloatTy = new Type(Type::FloatTyID);
+ return FloatTy;
+}
+
+const Type *Type::getDoubleTy(LLVMContext &C) {
+ static const Type *DoubleTy = new Type(Type::DoubleTyID);
+ return DoubleTy;
+}
+
+const Type *Type::getMetadataTy(LLVMContext &C) {
+ static const Type *MetadataTy = new Type(Type::MetadataTyID);
+ return MetadataTy;
+}
+
+const Type *Type::getX86_FP80Ty(LLVMContext &C) {
+ static const Type *X86_FP80Ty = new Type(Type::X86_FP80TyID);
+ return X86_FP80Ty;
+}
+
+const Type *Type::getFP128Ty(LLVMContext &C) {
+ static const Type *FP128Ty = new Type(Type::FP128TyID);
+ return FP128Ty;
+}
+
+const Type *Type::getPPC_FP128Ty(LLVMContext &C) {
+ static const Type *PPC_FP128Ty = new Type(Type::PPC_FP128TyID);
+ return PPC_FP128Ty;
+}
+
+const IntegerType *Type::getInt1Ty(LLVMContext &C) {
+ static const IntegerType *Int1Ty = new BuiltinIntegerType(1);
+ return Int1Ty;
+}
+
+const IntegerType *Type::getInt8Ty(LLVMContext &C) {
+ static const IntegerType *Int8Ty = new BuiltinIntegerType(8);
+ return Int8Ty;
+}
+
+const IntegerType *Type::getInt16Ty(LLVMContext &C) {
+ static const IntegerType *Int16Ty = new BuiltinIntegerType(16);
+ return Int16Ty;
+}
+
+const IntegerType *Type::getInt32Ty(LLVMContext &C) {
+ static const IntegerType *Int32Ty = new BuiltinIntegerType(32);
+ return Int32Ty;
+}
+
+const IntegerType *Type::getInt64Ty(LLVMContext &C) {
+ static const IntegerType *Int64Ty = new BuiltinIntegerType(64);
+ return Int64Ty;
+}
//===----------------------------------------------------------------------===//
// Derived Type Constructors
@@ -344,10 +395,11 @@ const IntegerType *Type::Int64Ty = new BuiltinIntegerType(64);
bool FunctionType::isValidReturnType(const Type *RetTy) {
if (RetTy->isFirstClassType()) {
if (const PointerType *PTy = dyn_cast<PointerType>(RetTy))
- return PTy->getElementType() != Type::MetadataTy;
+ return PTy->getElementType() != Type::getMetadataTy(RetTy->getContext());
return true;
}
- if (RetTy == Type::VoidTy || RetTy == Type::MetadataTy ||
+ if (RetTy == Type::getVoidTy(RetTy->getContext()) ||
+ RetTy == Type::getMetadataTy(RetTy->getContext()) ||
isa<OpaqueType>(RetTy))
return true;
@@ -368,7 +420,8 @@ bool FunctionType::isValidReturnType(const Type *RetTy) {
bool FunctionType::isValidArgumentType(const Type *ArgTy) {
if ((!ArgTy->isFirstClassType() && !isa<OpaqueType>(ArgTy)) ||
(isa<PointerType>(ArgTy) &&
- cast<PointerType>(ArgTy)->getElementType() == Type::MetadataTy))
+ cast<PointerType>(ArgTy)->getElementType() ==
+ Type::getMetadataTy(ArgTy->getContext())))
return false;
return true;
@@ -488,7 +541,7 @@ void DerivedType::dropAllTypeUses() {
// pick so long as it doesn't point back to this type. We choose something
// concrete to avoid overhead for adding to AbstracTypeUser lists and stuff.
for (unsigned i = 1, e = NumContainedTys; i != e; ++i)
- ContainedTys[i] = Type::Int32Ty;
+ ContainedTys[i] = Type::getInt32Ty(getContext());
}
}
@@ -705,17 +758,17 @@ static bool TypeHasCycleThroughItself(const Type *Ty) {
static ManagedStatic<TypeMap<IntegerValType, IntegerType> > IntegerTypes;
-const IntegerType *IntegerType::get(unsigned NumBits) {
+const IntegerType *IntegerType::get(LLVMContext &C, unsigned NumBits) {
assert(NumBits >= MIN_INT_BITS && "bitwidth too small");
assert(NumBits <= MAX_INT_BITS && "bitwidth too large");
// Check for the built-in integer types
switch (NumBits) {
- case 1: return cast<IntegerType>(Type::Int1Ty);
- case 8: return cast<IntegerType>(Type::Int8Ty);
- case 16: return cast<IntegerType>(Type::Int16Ty);
- case 32: return cast<IntegerType>(Type::Int32Ty);
- case 64: return cast<IntegerType>(Type::Int64Ty);
+ case 1: return cast<IntegerType>(Type::getInt1Ty(C));
+ case 8: return cast<IntegerType>(Type::getInt8Ty(C));
+ case 16: return cast<IntegerType>(Type::getInt16Ty(C));
+ case 32: return cast<IntegerType>(Type::getInt32Ty(C));
+ case 64: return cast<IntegerType>(Type::getInt64Ty(C));
default:
break;
}
@@ -806,12 +859,13 @@ ArrayType *ArrayType::get(const Type *ElementType, uint64_t NumElements) {
}
bool ArrayType::isValidElementType(const Type *ElemTy) {
- if (ElemTy == Type::VoidTy || ElemTy == Type::LabelTy ||
- ElemTy == Type::MetadataTy)
+ if (ElemTy == Type::getVoidTy(ElemTy->getContext()) ||
+ ElemTy == Type::getLabelTy(ElemTy->getContext()) ||
+ ElemTy == Type::getMetadataTy(ElemTy->getContext()))
return false;
if (const PointerType *PTy = dyn_cast<PointerType>(ElemTy))
- if (PTy->getElementType() == Type::MetadataTy)
+ if (PTy->getElementType() == Type::getMetadataTy(ElemTy->getContext()))
return false;
return true;
@@ -885,12 +939,13 @@ StructType *StructType::get(LLVMContext &Context, const Type *type, ...) {
}
bool StructType::isValidElementType(const Type *ElemTy) {
- if (ElemTy == Type::VoidTy || ElemTy == Type::LabelTy ||
- ElemTy == Type::MetadataTy)
+ if (ElemTy == Type::getVoidTy(ElemTy->getContext()) ||
+ ElemTy == Type::getLabelTy(ElemTy->getContext()) ||
+ ElemTy == Type::getMetadataTy(ElemTy->getContext()))
return false;
if (const PointerType *PTy = dyn_cast<PointerType>(ElemTy))
- if (PTy->getElementType() == Type::MetadataTy)
+ if (PTy->getElementType() == Type::getMetadataTy(ElemTy->getContext()))
return false;
return true;
@@ -903,7 +958,7 @@ bool StructType::isValidElementType(const Type *ElemTy) {
PointerType *PointerType::get(const Type *ValueType, unsigned AddressSpace) {
assert(ValueType && "Can't get a pointer to <null> type!");
- assert(ValueType != Type::VoidTy &&
+ assert(ValueType != Type::getVoidTy(ValueType->getContext()) &&
"Pointer to void is not valid, use i8* instead!");
assert(isValidElementType(ValueType) && "Invalid type for pointer element!");
PointerValType PVT(ValueType, AddressSpace);
@@ -930,11 +985,12 @@ PointerType *Type::getPointerTo(unsigned addrs) const {
}
bool PointerType::isValidElementType(const Type *ElemTy) {
- if (ElemTy == Type::VoidTy || ElemTy == Type::LabelTy)
+ if (ElemTy == Type::getVoidTy(ElemTy->getContext()) ||
+ ElemTy == Type::getLabelTy(ElemTy->getContext()))
return false;
if (const PointerType *PTy = dyn_cast<PointerType>(ElemTy))
- if (PTy->getElementType() == Type::MetadataTy)
+ if (PTy->getElementType() == Type::getMetadataTy(ElemTy->getContext()))
return false;
return true;
diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp
index 104f0377e8..2bdb5b8a79 100644
--- a/lib/VMCore/Value.cpp
+++ b/lib/VMCore/Value.cpp
@@ -47,11 +47,13 @@ Value::Value(const Type *ty, unsigned scid)
SubclassData(0), VTy(checkType(ty)),
UseList(0), Name(0) {
if (isa<CallInst>(this) || isa<InvokeInst>(this))
- assert((VTy->isFirstClassType() || VTy == Type::VoidTy ||
+ assert((VTy->isFirstClassType() ||
+ VTy == Type::getVoidTy(ty->getContext()) ||
isa<OpaqueType>(ty) || VTy->getTypeID() == Type::StructTyID) &&
"invalid CallInst type!");
else if (!isa<Constant>(this) && !isa<BasicBlock>(this))
- assert((VTy->isFirstClassType() || VTy == Type::VoidTy ||
+ assert((VTy->isFirstClassType() ||
+ VTy == Type::getVoidTy(ty->getContext()) ||
isa<OpaqueType>(ty)) &&
"Cannot create non-first-class values except for constants!");
}
@@ -178,7 +180,8 @@ void Value::setName(const Twine &NewName) {
if (getName() == StringRef(NameStr, NameLen))
return;
- assert(getType() != Type::VoidTy && "Cannot assign a name to void values!");
+ assert(getType() != Type::getVoidTy(getContext()) &&
+ "Cannot assign a name to void values!");
// Get the symbol table to update for this object.
ValueSymbolTable *ST;
diff --git a/lib/VMCore/ValueTypes.cpp b/lib/VMCore/ValueTypes.cpp
index 8a046fd682..b10b3c1200 100644
--- a/lib/VMCore/ValueTypes.cpp
+++ b/lib/VMCore/ValueTypes.cpp
@@ -21,7 +21,7 @@ using namespace llvm;
EVT EVT::getExtendedIntegerVT(LLVMContext &Context, unsigned BitWidth) {
EVT VT;
- VT.LLVMTy = IntegerType::get(BitWidth);
+ VT.LLVMTy = IntegerType::get(Context, BitWidth);
assert(VT.isExtended() && "Type is not extended!");
return VT;
}
@@ -137,38 +137,38 @@ const Type *EVT::getTypeForEVT(LLVMContext &Context) const {
default:
assert(isExtended() && "Type is not extended!");
return LLVMTy;
- case MVT::isVoid: return Type::VoidTy;
- case MVT::i1: return Type::Int1Ty;
- case MVT::i8: return Type::Int8Ty;
- case MVT::i16: return Type::Int16Ty;
- case MVT::i32: return Type::Int32Ty;
- case MVT::i64: return Type::Int64Ty;
- case MVT::i128: return IntegerType::get(128);
- case MVT::f32: return Type::FloatTy;
- case MVT::f64: return Type::DoubleTy;
- case MVT::f80: return Type::X86_FP80Ty;
- case MVT::f128: return Type::FP128Ty;
- case MVT::ppcf128: return Type::PPC_FP128Ty;
- case MVT::v2i8: return VectorType::get(Type::Int8Ty, 2);
- case MVT::v4i8: return VectorType::get(Type::Int8Ty, 4);
- case MVT::v8i8: return VectorType::get(Type::Int8Ty, 8);
- case MVT::v16i8: return VectorType::get(Type::Int8Ty, 16);
- case MVT::v32i8: return VectorType::get(Type::Int8Ty, 32);
- case MVT::v2i16: return VectorType::get(Type::Int16Ty, 2);
- case MVT::v4i16: return VectorType::get(Type::Int16Ty, 4);
- case MVT::v8i16: return VectorType::get(Type::Int16Ty, 8);
- case MVT::v16i16: return VectorType::get(Type::Int16Ty, 16);
- case MVT::v2i32: return VectorType::get(Type::Int32Ty, 2);
- case MVT::v4i32: return VectorType::get(Type::Int32Ty, 4);
- case MVT::v8i32: return VectorType::get(Type::Int32Ty, 8);
- case MVT::v1i64: return VectorType::get(Type::Int64Ty, 1);
- case MVT::v2i64: return VectorType::get(Type::Int64Ty, 2);
- case MVT::v4i64: return VectorType::get(Type::Int64Ty, 4);
- case MVT::v2f32: return VectorType::get(Type::FloatTy, 2);
- case MVT::v4f32: return VectorType::get(Type::FloatTy, 4);
- case MVT::v8f32: return VectorType::get(Type::FloatTy, 8);
- case MVT::v2f64: return VectorType::get(Type::DoubleTy, 2);
- case MVT::v4f64: return VectorType::get(Type::DoubleTy, 4);
+ case MVT::isVoid: return Type::getVoidTy(Context);
+ case MVT::i1: return Type::getInt1Ty(Context);
+ case MVT::i8: return Type::getInt8Ty(Context);
+ case MVT::i16: return Type::getInt16Ty(Context);
+ case MVT::i32: return Type::getInt32Ty(Context);
+ case MVT::i64: return Type::getInt64Ty(Context);
+ case MVT::i128: return IntegerType::get(Context, 128);
+ case MVT::f32: return Type::getFloatTy(Context);
+ case MVT::f64: return Type::getDoubleTy(Context);
+ case MVT::f80: return Type::getX86_FP80Ty(Context);
+ case MVT::f128: return Type::getFP128Ty(Context);
+ case MVT::ppcf128: return Type::getPPC_FP128Ty(Context);
+ case MVT::v2i8: return VectorType::get(Type::getInt8Ty(Context), 2);
+ case MVT::v4i8: return VectorType::get(Type::getInt8Ty(Context), 4);
+ case MVT::v8i8: return VectorType::get(Type::getInt8Ty(Context), 8);
+ case MVT::v16i8: return VectorType::get(Type::getInt8Ty(Context), 16);
+ case MVT::v32i8: return VectorType::get(Type::getInt8Ty(Context), 32);
+ case MVT::v2i16: return VectorType::get(Type::getInt16Ty(Context), 2);
+ case MVT::v4i16: return VectorType::get(Type::getInt16Ty(Context), 4);
+ case MVT::v8i16: return VectorType::get(Type::getInt16Ty(Context), 8);
+ case MVT::v16i16: return VectorType::get(Type::getInt16Ty(Context), 16);
+ case MVT::v2i32: return VectorType::get(Type::getInt32Ty(Context), 2);
+ case MVT::v4i32: return VectorType::get(Type::getInt32Ty(Context), 4);
+ case MVT::v8i32: return VectorType::get(Type::getInt32Ty(Context), 8);
+ case MVT::v1i64: return VectorType::get(Type::getInt64Ty(Context), 1);
+ case MVT::v2i64: return VectorType::get(Type::getInt64Ty(Context), 2);
+ case MVT::v4i64: return VectorType::get(Type::getInt64Ty(Context), 4);
+ case MVT::v2f32: return VectorType::get(Type::getFloatTy(Context), 2);
+ case MVT::v4f32: return VectorType::get(Type::getFloatTy(Context), 4);
+ case MVT::v8f32: return VectorType::get(Type::getFloatTy(Context), 8);
+ case MVT::v2f64: return VectorType::get(Type::getDoubleTy(Context), 2);
+ case MVT::v4f64: return VectorType::get(Type::getDoubleTy(Context), 4);
}
}
diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp
index 70370b8c0f..d53cf0eb04 100644
--- a/lib/VMCore/Verifier.cpp
+++ b/lib/VMCore/Verifier.cpp
@@ -558,11 +558,12 @@ void Verifier::visitFunction(Function &F) {
"# formal arguments must match # of arguments for function type!",
&F, FT);
Assert1(F.getReturnType()->isFirstClassType() ||
- F.getReturnType() == Type::VoidTy ||
+ F.getReturnType() == Type::getVoidTy(F.getContext()) ||
isa<StructType>(F.getReturnType()),
"Functions cannot return aggregate values!", &F);
- Assert1(!F.hasStructRetAttr() || F.getReturnType() == Type::VoidTy,
+ Assert1(!F.hasStructRetAttr() ||
+ F.getReturnType() == Type::getVoidTy(F.getContext()),
"Invalid struct return type!", &F);
const AttrListPtr &Attrs = F.getAttributes();
@@ -590,7 +591,7 @@ void Verifier::visitFunction(Function &F) {
bool isLLVMdotName = F.getName().size() >= 5 &&
F.getName().substr(0, 5) == "llvm.";
if (!isLLVMdotName)
- Assert1(F.getReturnType() != Type::MetadataTy,
+ Assert1(F.getReturnType() != Type::getMetadataTy(F.getContext()),
"Function may not return metadata unless it's an intrinsic", &F);
// Check that the argument values match the function type for this function...
@@ -603,7 +604,7 @@ void Verifier::visitFunction(Function &F) {
Assert1(I->getType()->isFirstClassType(),
"Function arguments must have first-class types!", I);
if (!isLLVMdotName)
- Assert2(I->getType() != Type::MetadataTy,
+ Assert2(I->getType() != Type::getMetadataTy(F.getContext()),
"Function takes metadata but isn't an intrinsic", I, &F);
}
@@ -688,7 +689,7 @@ void Verifier::visitTerminatorInst(TerminatorInst &I) {
void Verifier::visitReturnInst(ReturnInst &RI) {
Function *F = RI.getParent()->getParent();
unsigned N = RI.getNumOperands();
- if (F->getReturnType() == Type::VoidTy)
+ if (F->getReturnType() == Type::getVoidTy(RI.getContext()))
Assert2(N == 0,
"Found return instr that returns non-void in Function of void "
"return type!", &RI, F->getReturnType());
@@ -1048,12 +1049,12 @@ void Verifier::VerifyCallSite(CallSite CS) {
// Verify that there's no metadata unless it's a direct call to an intrinsic.
if (!CS.getCalledFunction() || CS.getCalledFunction()->getName().size() < 5 ||
CS.getCalledFunction()->getName().substr(0, 5) != "llvm.") {
- Assert1(FTy->getReturnType() != Type::MetadataTy,
+ Assert1(FTy->getReturnType() != Type::getMetadataTy(I->getContext()),
"Only intrinsics may return metadata", I);
for (FunctionType::param_iterator PI = FTy->param_begin(),
PE = FTy->param_end(); PI != PE; ++PI)
- Assert1(PI->get() != Type::MetadataTy, "Function has metadata parameter "
- "but isn't an intrinsic", I);
+ Assert1(PI->get() != Type::getMetadataTy(I->getContext()),
+ "Function has metadata parameter but isn't an intrinsic", I);
}
visitInstruction(*I);
@@ -1218,7 +1219,8 @@ void Verifier::visitLoadInst(LoadInst &LI) {
cast<PointerType>(LI.getOperand(0)->getType())->getElementType();
Assert2(ElTy == LI.getType(),
"Load result type does not match pointer operand type!", &LI, ElTy);
- Assert1(ElTy != Type::MetadataTy, "Can't load metadata!", &LI);
+ Assert1(ElTy != Type::getMetadataTy(LI.getContext()),
+ "Can't load metadata!", &LI);
visitInstruction(LI);
}
@@ -1227,7 +1229,8 @@ void Verifier::visitStoreInst(StoreInst &SI) {
cast<PointerType>(SI.getOperand(1)->getType())->getElementType();
Assert2(ElTy == SI.getOperand(0)->getType(),
"Stored value type does not match pointer operand type!", &SI, ElTy);
- Assert1(ElTy != Type::MetadataTy, "Can't store metadata!", &SI);
+ Assert1(ElTy != Type::getMetadataTy(SI.getContext()),
+ "Can't store metadata!", &SI);
visitInstruction(SI);
}
@@ -1278,24 +1281,25 @@ void Verifier::visitInstruction(Instruction &I) {
// Check that void typed values don't have names
- Assert1(I.getType() != Type::VoidTy || !I.hasName(),
+ Assert1(I.getType() != Type::getVoidTy(I.getContext()) || !I.hasName(),
"Instruction has a name, but provides a void value!", &I);
// Check that the return value of the instruction is either void or a legal
// value type.
- Assert1(I.getType() == Type::VoidTy || I.getType()->isFirstClassType()
+ Assert1(I.getType() == Type::getVoidTy(I.getContext()) ||
+ I.getType()->isFirstClassType()
|| ((isa<CallInst>(I) || isa<InvokeInst>(I))
&& isa<StructType>(I.getType())),
"Instruction returns a non-scalar type!", &I);
// Check that the instruction doesn't produce metadata or metadata*. Calls
// all already checked against the callee type.
- Assert1(I.getType() != Type::MetadataTy ||
+ Assert1(I.getType() != Type::getMetadataTy(I.getContext()) ||
isa<CallInst>(I) || isa<InvokeInst>(I),
"Invalid use of metadata!", &I);
if (const PointerType *PTy = dyn_cast<PointerType>(I.getType()))
- Assert1(PTy->getElementType() != Type::MetadataTy,
+ Assert1(PTy->getElementType() != Type::getMetadataTy(I.getContext()),
"Instructions may not produce pointer to metadata.", &I);
@@ -1322,7 +1326,7 @@ void Verifier::visitInstruction(Instruction &I) {
if (const PointerType *PTy =
dyn_cast<PointerType>(I.getOperand(i)->getType()))
- Assert1(PTy->getElementType() != Type::MetadataTy,
+ Assert1(PTy->getElementType() != Type::getMetadataTy(I.getContext()),
"Invalid use of metadata pointer.", &I);
if (Function *F = dyn_cast<Function>(I.getOperand(i))) {