diff options
author | Owen Anderson <resistor@mac.com> | 2009-07-31 20:28:14 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2009-07-31 20:28:14 +0000 |
commit | a7235ea7245028a0723e8ab7fd011386b3900777 (patch) | |
tree | 4d702ea3baaaeaeaeb5cf194e266a0911882c613 /lib/VMCore | |
parent | 2a29899d74476e2a14069af7231ab76d8322a157 (diff) | |
download | external_llvm-a7235ea7245028a0723e8ab7fd011386b3900777.zip external_llvm-a7235ea7245028a0723e8ab7fd011386b3900777.tar.gz external_llvm-a7235ea7245028a0723e8ab7fd011386b3900777.tar.bz2 |
Move a few more APIs back to 2.5 forms. The only remaining ones left to change back are
metadata related, which I'm waiting on to avoid conflicting with Devang.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77721 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/ConstantFold.cpp | 116 | ||||
-rw-r--r-- | lib/VMCore/Constants.cpp | 58 | ||||
-rw-r--r-- | lib/VMCore/Core.cpp | 4 | ||||
-rw-r--r-- | lib/VMCore/Instructions.cpp | 8 | ||||
-rw-r--r-- | lib/VMCore/LLVMContext.cpp | 43 |
5 files changed, 112 insertions, 117 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 8b56ed3..081c780 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -103,13 +103,13 @@ static Constant *FoldBitCast(LLVMContext &Context, if (const PointerType *DPTy = dyn_cast<PointerType>(DestTy)) if (PTy->getAddressSpace() == DPTy->getAddressSpace()) { SmallVector<Value*, 8> IdxList; - IdxList.push_back(Context.getNullValue(Type::Int32Ty)); + IdxList.push_back(Constant::getNullValue(Type::Int32Ty)); const Type *ElTy = PTy->getElementType(); while (ElTy != DPTy->getElementType()) { if (const StructType *STy = dyn_cast<StructType>(ElTy)) { if (STy->getNumElements() == 0) break; ElTy = STy->getElementType(0); - IdxList.push_back(Context.getNullValue(Type::Int32Ty)); + IdxList.push_back(Constant::getNullValue(Type::Int32Ty)); } else if (const SequentialType *STy = dyn_cast<SequentialType>(ElTy)) { if (isa<PointerType>(ElTy)) break; // Can't index into pointers! @@ -134,7 +134,7 @@ static Constant *FoldBitCast(LLVMContext &Context, SrcTy = NULL; // First, check for null. Undef is already handled. if (isa<ConstantAggregateZero>(V)) - return Context.getNullValue(DestTy); + return Constant::getNullValue(DestTy); if (ConstantVector *CV = dyn_cast<ConstantVector>(V)) return BitCastConstantVector(Context, CV, DestPTy); @@ -186,7 +186,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context, // [us]itofp(undef) = 0, because the result value is bounded. if (opc == Instruction::ZExt || opc == Instruction::SExt || opc == Instruction::UIToFP || opc == Instruction::SIToFP) - return Context.getNullValue(DestTy); + return Constant::getNullValue(DestTy); return UndefValue::get(DestTy); } // No compile-time operations on this type yet. @@ -337,7 +337,7 @@ Constant *llvm::ConstantFoldExtractElementInstruction(LLVMContext &Context, if (isa<UndefValue>(Val)) // ee(undef, x) -> undef return UndefValue::get(cast<VectorType>(Val->getType())->getElementType()); if (Val->isNullValue()) // ee(zero, x) -> zero - return Context.getNullValue( + return Constant::getNullValue( cast<VectorType>(Val->getType())->getElementType()); if (const ConstantVector *CVal = dyn_cast<ConstantVector>(Val)) { @@ -389,7 +389,7 @@ Constant *llvm::ConstantFoldInsertElementInstruction(LLVMContext &Context, Ops.reserve(numOps); for (unsigned i = 0; i < numOps; ++i) { const Constant *Op = - (idxVal == i) ? Elt : Context.getNullValue(Elt->getType()); + (idxVal == i) ? Elt : Constant::getNullValue(Elt->getType()); Ops.push_back(const_cast<Constant*>(Op)); } return ConstantVector::get(Ops); @@ -418,7 +418,7 @@ static Constant *GetVectorElement(LLVMContext &Context, const Constant *C, const Type *EltTy = cast<VectorType>(C->getType())->getElementType(); if (isa<ConstantAggregateZero>(C)) - return Context.getNullValue(EltTy); + return Constant::getNullValue(EltTy); if (isa<UndefValue>(C)) return UndefValue::get(EltTy); return 0; @@ -477,7 +477,7 @@ Constant *llvm::ConstantFoldExtractValueInstruction(LLVMContext &Context, if (isa<ConstantAggregateZero>(Agg)) // ev(0, x) -> 0 return - Context.getNullValue(ExtractValueInst::getIndexedType(Agg->getType(), + Constant::getNullValue(ExtractValueInst::getIndexedType(Agg->getType(), Idxs, Idxs + NumIdx)); @@ -542,9 +542,9 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context, const Constant *Op = (*Idxs == i) ? ConstantFoldInsertValueInstruction(Context, - Context.getNullValue(MemberTy), + Constant::getNullValue(MemberTy), Val, Idxs+1, NumIdx-1) : - Context.getNullValue(MemberTy); + Constant::getNullValue(MemberTy); Ops[i] = const_cast<Constant*>(Op); } if (isa<StructType>(AggTy)) @@ -590,29 +590,29 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context, if (isa<UndefValue>(C1) && isa<UndefValue>(C2)) // Handle undef ^ undef -> 0 special case. This is a common // idiom (misuse). - return Context.getNullValue(C1->getType()); + return Constant::getNullValue(C1->getType()); // Fallthrough case Instruction::Add: case Instruction::Sub: return UndefValue::get(C1->getType()); case Instruction::Mul: case Instruction::And: - return Context.getNullValue(C1->getType()); + return Constant::getNullValue(C1->getType()); case Instruction::UDiv: case Instruction::SDiv: case Instruction::URem: case Instruction::SRem: if (!isa<UndefValue>(C2)) // undef / X -> 0 - return Context.getNullValue(C1->getType()); + return Constant::getNullValue(C1->getType()); return const_cast<Constant*>(C2); // X / undef -> undef case Instruction::Or: // X | undef -> -1 if (const VectorType *PTy = dyn_cast<VectorType>(C1->getType())) - return Context.getAllOnesValue(PTy); - return Context.getAllOnesValue(C1->getType()); + return Constant::getAllOnesValue(PTy); + return Constant::getAllOnesValue(C1->getType()); case Instruction::LShr: if (isa<UndefValue>(C2) && isa<UndefValue>(C1)) return const_cast<Constant*>(C1); // undef lshr undef -> undef - return Context.getNullValue(C1->getType()); // X lshr undef -> 0 + return Constant::getNullValue(C1->getType()); // X lshr undef -> 0 // undef lshr X -> 0 case Instruction::AShr: if (!isa<UndefValue>(C2)) @@ -623,7 +623,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context, return const_cast<Constant*>(C1); // X ashr undef --> X case Instruction::Shl: // undef << X -> 0 or X << undef -> 0 - return Context.getNullValue(C1->getType()); + return Constant::getNullValue(C1->getType()); } } @@ -651,7 +651,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context, case Instruction::URem: case Instruction::SRem: if (CI2->equalsInt(1)) - return Context.getNullValue(CI2->getType()); // X % 1 == 0 + return Constant::getNullValue(CI2->getType()); // X % 1 == 0 if (CI2->equalsInt(0)) return UndefValue::get(CI2->getType()); // X % 0 == undef break; @@ -688,7 +688,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context, // If checking bits we know are clear, return zero. if ((CI2->getValue() & BitsNotSet) == CI2->getValue()) - return Context.getNullValue(CI2->getType()); + return Constant::getNullValue(CI2->getType()); } } } @@ -824,144 +824,144 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context, break; case Instruction::Add: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getAdd(const_cast<Constant*>(C1), const_cast<Constant*>(C2))); } return ConstantVector::get(Res); case Instruction::FAdd: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getFAdd(const_cast<Constant*>(C1), const_cast<Constant*>(C2))); } return ConstantVector::get(Res); case Instruction::Sub: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getSub(const_cast<Constant*>(C1), const_cast<Constant*>(C2))); } return ConstantVector::get(Res); case Instruction::FSub: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getFSub(const_cast<Constant*>(C1), const_cast<Constant*>(C2))); } return ConstantVector::get(Res); case Instruction::Mul: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getMul(const_cast<Constant*>(C1), const_cast<Constant*>(C2))); } return ConstantVector::get(Res); case Instruction::FMul: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getFMul(const_cast<Constant*>(C1), const_cast<Constant*>(C2))); } return ConstantVector::get(Res); case Instruction::UDiv: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getUDiv(const_cast<Constant*>(C1), const_cast<Constant*>(C2))); } return ConstantVector::get(Res); case Instruction::SDiv: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getSDiv(const_cast<Constant*>(C1), const_cast<Constant*>(C2))); } return ConstantVector::get(Res); case Instruction::FDiv: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getFDiv(const_cast<Constant*>(C1), const_cast<Constant*>(C2))); } return ConstantVector::get(Res); case Instruction::URem: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getURem(const_cast<Constant*>(C1), const_cast<Constant*>(C2))); } return ConstantVector::get(Res); case Instruction::SRem: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getSRem(const_cast<Constant*>(C1), const_cast<Constant*>(C2))); } return ConstantVector::get(Res); case Instruction::FRem: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getFRem(const_cast<Constant*>(C1), const_cast<Constant*>(C2))); } return ConstantVector::get(Res); case Instruction::And: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getAnd(const_cast<Constant*>(C1), const_cast<Constant*>(C2))); } return ConstantVector::get(Res); case Instruction::Or: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getOr(const_cast<Constant*>(C1), const_cast<Constant*>(C2))); } return ConstantVector::get(Res); case Instruction::Xor: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getXor(const_cast<Constant*>(C1), const_cast<Constant*>(C2))); } return ConstantVector::get(Res); case Instruction::LShr: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getLShr(const_cast<Constant*>(C1), const_cast<Constant*>(C2))); } return ConstantVector::get(Res); case Instruction::AShr: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getAShr(const_cast<Constant*>(C1), const_cast<Constant*>(C2))); } return ConstantVector::get(Res); case Instruction::Shl: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getShl(const_cast<Constant*>(C1), const_cast<Constant*>(C2))); } @@ -1236,7 +1236,7 @@ static ICmpInst::Predicate evaluateICmpRelation(LLVMContext &Context, if (CE1->getOpcode() == Instruction::ZExt) isSigned = false; if (CE1->getOpcode() == Instruction::SExt) isSigned = true; return evaluateICmpRelation(Context, CE1Op0, - Context.getNullValue(CE1Op0->getType()), + Constant::getNullValue(CE1Op0->getType()), sgnd); } @@ -1379,10 +1379,10 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context, // Fold FCMP_FALSE/FCMP_TRUE unconditionally. if (pred == FCmpInst::FCMP_FALSE) - return Context.getNullValue(ResultTy); + return Constant::getNullValue(ResultTy); if (pred == FCmpInst::FCMP_TRUE) - return Context.getAllOnesValue(ResultTy); + return Constant::getAllOnesValue(ResultTy); // Handle some degenerate cases first if (isa<UndefValue>(C1) || isa<UndefValue>(C2)) diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index af3892a..4f0c411 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -43,6 +43,48 @@ using namespace llvm; // Becomes a no-op when multithreading is disabled. ManagedStatic<sys::SmartRWMutex<true> > ConstantsLock; +// Constructor to create a '0' constant of arbitrary type... +static const uint64_t zero[2] = {0, 0}; +Constant* Constant::getNullValue(const Type* Ty) { + switch (Ty->getTypeID()) { + case Type::IntegerTyID: + return ConstantInt::get(Ty, 0); + case Type::FloatTyID: + return ConstantFP::get(Ty->getContext(), APFloat(APInt(32, 0))); + case Type::DoubleTyID: + return ConstantFP::get(Ty->getContext(), APFloat(APInt(64, 0))); + case Type::X86_FP80TyID: + return ConstantFP::get(Ty->getContext(), APFloat(APInt(80, 2, zero))); + case Type::FP128TyID: + return ConstantFP::get(Ty->getContext(), + APFloat(APInt(128, 2, zero), true)); + case Type::PPC_FP128TyID: + return ConstantFP::get(Ty->getContext(), APFloat(APInt(128, 2, zero))); + case Type::PointerTyID: + return ConstantPointerNull::get(cast<PointerType>(Ty)); + case Type::StructTyID: + case Type::ArrayTyID: + case Type::VectorTyID: + return ConstantAggregateZero::get(Ty); + default: + // Function, Label, or Opaque type? + assert(!"Cannot create a null constant of that type!"); + return 0; + } +} + +Constant* Constant::getAllOnesValue(const Type* Ty) { + if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty)) + return ConstantInt::get(Ty->getContext(), + APInt::getAllOnesValue(ITy->getBitWidth())); + + std::vector<Constant*> Elts; + const VectorType* VTy = cast<VectorType>(Ty); + Elts.resize(VTy->getNumElements(), getAllOnesValue(VTy->getElementType())); + assert(Elts[0] && "Not a vector integer type!"); + return cast<ConstantVector>(ConstantVector::get(Elts)); +} + void Constant::destroyConstantImpl() { // When a Constant is destroyed, there may be lingering // references to the constant by other constants in the constant pool. These @@ -148,7 +190,7 @@ void Constant::getVectorElements(LLVMContext &Context, const VectorType *VT = cast<VectorType>(getType()); if (isa<ConstantAggregateZero>(this)) { Elts.assign(VT->getNumElements(), - Context.getNullValue(VT->getElementType())); + Constant::getNullValue(VT->getElementType())); return; } @@ -296,14 +338,13 @@ Constant* ConstantFP::get(const Type* Ty, double V) { ConstantFP* ConstantFP::getNegativeZero(const Type* Ty) { LLVMContext &Context = Ty->getContext(); - APFloat apf = cast <ConstantFP>(Context.getNullValue(Ty))->getValueAPF(); + APFloat apf = cast <ConstantFP>(Constant::getNullValue(Ty))->getValueAPF(); apf.changeSign(); return get(Context, apf); } Constant* ConstantFP::getZeroValueForNegation(const Type* Ty) { - LLVMContext &Context = Ty->getContext(); if (const VectorType *PTy = dyn_cast<VectorType>(Ty)) if (PTy->getElementType()->isFloatingPoint()) { std::vector<Constant*> zeros(PTy->getNumElements(), @@ -314,7 +355,7 @@ Constant* ConstantFP::getZeroValueForNegation(const Type* Ty) { if (Ty->isFloatingPoint()) return getNegativeZero(Ty); - return Context.getNullValue(Ty); + return Constant::getNullValue(Ty); } @@ -1751,18 +1792,16 @@ 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. - LLVMContext &Context = Ty->getContext(); Constant *GEPIdx = ConstantInt::get(Type::Int32Ty, 1); Constant *GEP = getGetElementPtr( - Context.getNullValue(PointerType::getUnqual(Ty)), &GEPIdx, 1); + Constant::getNullValue(PointerType::getUnqual(Ty)), &GEPIdx, 1); return getCast(Instruction::PtrToInt, GEP, Type::Int64Ty); } Constant* ConstantExpr::getAlignOf(const Type* Ty) { - LLVMContext &Context = Ty->getContext(); // alignof is implemented as: (i64) gep ({i8,Ty}*)null, 0, 1 const Type *AligningTy = StructType::get(Type::Int8Ty, Ty, NULL); - Constant *NullPtr = Context.getNullValue(AligningTy->getPointerTo()); + Constant *NullPtr = Constant::getNullValue(AligningTy->getPointerTo()); Constant *Zero = ConstantInt::get(Type::Int32Ty, 0); Constant *One = ConstantInt::get(Type::Int32Ty, 1); Constant *Indices[2] = { Zero, One }; @@ -2029,8 +2068,7 @@ Constant* ConstantExpr::getFNeg(Constant* C) { Constant* ConstantExpr::getNot(Constant* C) { assert(C->getType()->isIntOrIntVector() && "Cannot NOT a nonintegral value!"); - LLVMContext &Context = C->getType()->getContext(); - return get(Instruction::Xor, C, Context.getAllOnesValue(C->getType())); + return get(Instruction::Xor, C, Constant::getAllOnesValue(C->getType())); } Constant* ConstantExpr::getAdd(Constant* C1, Constant* C2) { diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp index be71d37..8998350 100644 --- a/lib/VMCore/Core.cpp +++ b/lib/VMCore/Core.cpp @@ -327,11 +327,11 @@ LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DEFINE_VALUE_CAST) /*--.. Operations on constants of any type .................................--*/ LLVMValueRef LLVMConstNull(LLVMTypeRef Ty) { - return wrap(getGlobalContext().getNullValue(unwrap(Ty))); + return wrap(Constant::getNullValue(unwrap(Ty))); } LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty) { - return wrap(getGlobalContext().getAllOnesValue(unwrap(Ty))); + return wrap(Constant::getAllOnesValue(unwrap(Ty))); } LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty) { diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index 3689146..e7983e0 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -1613,11 +1613,11 @@ BinaryOperator *BinaryOperator::CreateNot(LLVMContext &Context, Instruction *InsertBefore) { Constant *C; if (const VectorType *PTy = dyn_cast<VectorType>(Op->getType())) { - C = Context.getAllOnesValue(PTy->getElementType()); + C = Constant::getAllOnesValue(PTy->getElementType()); C = ConstantVector::get( std::vector<Constant*>(PTy->getNumElements(), C)); } else { - C = Context.getAllOnesValue(Op->getType()); + C = Constant::getAllOnesValue(Op->getType()); } return new BinaryOperator(Instruction::Xor, Op, C, @@ -1630,11 +1630,11 @@ BinaryOperator *BinaryOperator::CreateNot(LLVMContext &Context, Constant *AllOnes; if (const VectorType *PTy = dyn_cast<VectorType>(Op->getType())) { // Create a vector of all ones values. - Constant *Elt = Context.getAllOnesValue(PTy->getElementType()); + Constant *Elt = Constant::getAllOnesValue(PTy->getElementType()); AllOnes = ConstantVector::get( std::vector<Constant*>(PTy->getNumElements(), Elt)); } else { - AllOnes = Context.getAllOnesValue(Op->getType()); + AllOnes = Constant::getAllOnesValue(Op->getType()); } return new BinaryOperator(Instruction::Xor, Op, AllOnes, diff --git a/lib/VMCore/LLVMContext.cpp b/lib/VMCore/LLVMContext.cpp index 7dcfcf4..107905f 100644 --- a/lib/VMCore/LLVMContext.cpp +++ b/lib/VMCore/LLVMContext.cpp @@ -32,49 +32,6 @@ LLVMContext& llvm::getGlobalContext() { LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl(*this)) { } LLVMContext::~LLVMContext() { delete pImpl; } -// Constant accessors - -// Constructor to create a '0' constant of arbitrary type... -static const uint64_t zero[2] = {0, 0}; -Constant* LLVMContext::getNullValue(const Type* Ty) { - switch (Ty->getTypeID()) { - case Type::IntegerTyID: - return ConstantInt::get(Ty, 0); - case Type::FloatTyID: - return ConstantFP::get(Ty->getContext(), APFloat(APInt(32, 0))); - case Type::DoubleTyID: - return ConstantFP::get(Ty->getContext(), APFloat(APInt(64, 0))); - case Type::X86_FP80TyID: - return ConstantFP::get(Ty->getContext(), APFloat(APInt(80, 2, zero))); - case Type::FP128TyID: - return ConstantFP::get(Ty->getContext(), - APFloat(APInt(128, 2, zero), true)); - case Type::PPC_FP128TyID: - return ConstantFP::get(Ty->getContext(), APFloat(APInt(128, 2, zero))); - case Type::PointerTyID: - return ConstantPointerNull::get(cast<PointerType>(Ty)); - case Type::StructTyID: - case Type::ArrayTyID: - case Type::VectorTyID: - return ConstantAggregateZero::get(Ty); - default: - // Function, Label, or Opaque type? - assert(!"Cannot create a null constant of that type!"); - return 0; - } -} - -Constant* LLVMContext::getAllOnesValue(const Type* Ty) { - if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty)) - return ConstantInt::get(*this, APInt::getAllOnesValue(ITy->getBitWidth())); - - std::vector<Constant*> Elts; - const VectorType* VTy = cast<VectorType>(Ty); - Elts.resize(VTy->getNumElements(), getAllOnesValue(VTy->getElementType())); - assert(Elts[0] && "Not a vector integer type!"); - return cast<ConstantVector>(ConstantVector::get(Elts)); -} - // MDNode accessors MDNode* LLVMContext::getMDNode(Value* const* Vals, unsigned NumVals) { return pImpl->getMDNode(Vals, NumVals); |