diff options
56 files changed, 350 insertions, 399 deletions
diff --git a/docs/tutorial/LangImpl5.html b/docs/tutorial/LangImpl5.html index 8d77d5ec89..9057cae384 100644 --- a/docs/tutorial/LangImpl5.html +++ b/docs/tutorial/LangImpl5.html @@ -856,7 +856,7 @@ the loop again and exiting the loop. Any future code is emitted in the NamedValues.erase(VarName); // for expr always returns 0.0. - return TheFunction->getContext().getNullValue(Type::DoubleTy); + return Constant::getNullValue(Type::DoubleTy); } </pre> </div> diff --git a/docs/tutorial/LangImpl6.html b/docs/tutorial/LangImpl6.html index 0f714b385a..d845eb86c1 100644 --- a/docs/tutorial/LangImpl6.html +++ b/docs/tutorial/LangImpl6.html @@ -1570,7 +1570,7 @@ Value *ForExprAST::Codegen() { // for expr always returns 0.0. - return TheFunction->getContext().getNullValue(Type::DoubleTy); + return Constant::getNullValue(Type::DoubleTy); } Function *PrototypeAST::Codegen() { diff --git a/docs/tutorial/LangImpl7.html b/docs/tutorial/LangImpl7.html index 844c48fff2..691bfacb60 100644 --- a/docs/tutorial/LangImpl7.html +++ b/docs/tutorial/LangImpl7.html @@ -1858,7 +1858,7 @@ Value *ForExprAST::Codegen() { // for expr always returns 0.0. - return TheFunction->getContext().getNullValue(Type::DoubleTy); + return Constant::getNullValue(Type::DoubleTy); } Value *VarExprAST::Codegen() { diff --git a/examples/BrainF/BrainF.cpp b/examples/BrainF/BrainF.cpp index e1615569d2..8651b6e918 100644 --- a/examples/BrainF/BrainF.cpp +++ b/examples/BrainF/BrainF.cpp @@ -145,7 +145,7 @@ void BrainF::header(LLVMContext& C) { //call i32 @puts(i8 *getelementptr([%d x i8] *@aberrormsg, i32 0, i32 0)) { - Constant *zero_32 = C.getNullValue(IntegerType::Int32Ty); + Constant *zero_32 = Constant::getNullValue(IntegerType::Int32Ty); Constant *gep_params[] = { zero_32, diff --git a/examples/Kaleidoscope/toy.cpp b/examples/Kaleidoscope/toy.cpp index 004c7b7c06..22b8285e92 100644 --- a/examples/Kaleidoscope/toy.cpp +++ b/examples/Kaleidoscope/toy.cpp @@ -856,7 +856,7 @@ Value *ForExprAST::Codegen() { // for expr always returns 0.0. - return TheFunction->getContext().getNullValue(Type::DoubleTy); + return Constant::getNullValue(Type::DoubleTy); } Value *VarExprAST::Codegen() { diff --git a/include/llvm/Constant.h b/include/llvm/Constant.h index 80c88b623f..3b3089748e 100644 --- a/include/llvm/Constant.h +++ b/include/llvm/Constant.h @@ -135,6 +135,13 @@ public: "implemented for all constants that have operands!"); assert(0 && "Constants that do not have operands cannot be using 'From'!"); } + + static Constant* getNullValue(const Type* Ty); + + /// @returns the value for an integer constant of the given type that has all + /// its bits set to true. + /// @brief Get the all ones value + static Constant* getAllOnesValue(const Type* Ty); }; } // End llvm namespace diff --git a/include/llvm/LLVMContext.h b/include/llvm/LLVMContext.h index 91312f73a8..9150e6160e 100644 --- a/include/llvm/LLVMContext.h +++ b/include/llvm/LLVMContext.h @@ -65,14 +65,6 @@ public: LLVMContext(); ~LLVMContext(); - // Constant accessors - Constant* getNullValue(const Type* Ty); - - /// @returns the value for an integer constant of the given type that has all - /// its bits set to true. - /// @brief Get the all ones value - Constant* getAllOnesValue(const Type* Ty); - // MDNode accessors MDNode* getMDNode(Value* const* Vals, unsigned NumVals); diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h index 223fe028e2..d0535c3604 100644 --- a/include/llvm/Support/IRBuilder.h +++ b/include/llvm/Support/IRBuilder.h @@ -705,13 +705,13 @@ public: /// CreateIsNull - Return an i1 value testing if \arg Arg is null. Value *CreateIsNull(Value *Arg, const char *Name = "") { - return CreateICmpEQ(Arg, Context.getNullValue(Arg->getType()), + return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()), Name); } /// CreateIsNotNull - Return an i1 value testing if \arg Arg is not null. Value *CreateIsNotNull(Value *Arg, const char *Name = "") { - return CreateICmpNE(Arg, Context.getNullValue(Arg->getType()), + return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()), Name); } diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp index 2badd266c2..a89505549f 100644 --- a/lib/Analysis/BasicAliasAnalysis.cpp +++ b/lib/Analysis/BasicAliasAnalysis.cpp @@ -308,8 +308,6 @@ BasicAliasAnalysis::getModRefInfo(CallSite CS1, CallSite CS2) { AliasAnalysis::AliasResult BasicAliasAnalysis::alias(const Value *V1, unsigned V1Size, const Value *V2, unsigned V2Size) { - LLVMContext &Context = V1->getType()->getContext(); - // Strip off any constant expression casts if they exist if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(V1)) if (CE->isCast() && isa<PointerType>(CE->getOperand(0)->getType())) @@ -394,13 +392,13 @@ BasicAliasAnalysis::alias(const Value *V1, unsigned V1Size, // the base pointers. while (isGEP(GEP1->getOperand(0)) && GEP1->getOperand(1) == - Context.getNullValue(GEP1->getOperand(1)->getType())) + Constant::getNullValue(GEP1->getOperand(1)->getType())) GEP1 = cast<User>(GEP1->getOperand(0)); const Value *BasePtr1 = GEP1->getOperand(0); while (isGEP(GEP2->getOperand(0)) && GEP2->getOperand(1) == - Context.getNullValue(GEP2->getOperand(1)->getType())) + Constant::getNullValue(GEP2->getOperand(1)->getType())) GEP2 = cast<User>(GEP2->getOperand(0)); const Value *BasePtr2 = GEP2->getOperand(0); @@ -480,7 +478,7 @@ BasicAliasAnalysis::alias(const Value *V1, unsigned V1Size, for (unsigned i = 0; i != GEPOperands.size(); ++i) if (!isa<ConstantInt>(GEPOperands[i])) GEPOperands[i] = - Context.getNullValue(GEPOperands[i]->getType()); + Constant::getNullValue(GEPOperands[i]->getType()); int64_t Offset = TD->getIndexedOffset(BasePtr->getType(), &GEPOperands[0], @@ -696,7 +694,7 @@ BasicAliasAnalysis::CheckGEPInstructions( // TargetData::getIndexedOffset. for (i = 0; i != MaxOperands; ++i) if (!isa<ConstantInt>(GEP1Ops[i])) - GEP1Ops[i] = Context.getNullValue(GEP1Ops[i]->getType()); + GEP1Ops[i] = Constant::getNullValue(GEP1Ops[i]->getType()); // Okay, now get the offset. This is the relative offset for the full // instruction. int64_t Offset1 = TD->getIndexedOffset(GEPPointerTy, GEP1Ops, @@ -740,7 +738,7 @@ BasicAliasAnalysis::CheckGEPInstructions( const Type *ZeroIdxTy = GEPPointerTy; for (unsigned i = 0; i != FirstConstantOper; ++i) { if (!isa<StructType>(ZeroIdxTy)) - GEP1Ops[i] = GEP2Ops[i] = Context.getNullValue(Type::Int32Ty); + GEP1Ops[i] = GEP2Ops[i] = Constant::getNullValue(Type::Int32Ty); if (const CompositeType *CT = dyn_cast<CompositeType>(ZeroIdxTy)) ZeroIdxTy = CT->getTypeAtIndex(GEP1Ops[i]); @@ -755,7 +753,7 @@ BasicAliasAnalysis::CheckGEPInstructions( // If they are equal, use a zero index... if (Op1 == Op2 && BasePtr1Ty == BasePtr2Ty) { if (!isa<ConstantInt>(Op1)) - GEP1Ops[i] = GEP2Ops[i] = Context.getNullValue(Op1->getType()); + GEP1Ops[i] = GEP2Ops[i] = Constant::getNullValue(Op1->getType()); // Otherwise, just keep the constants we have. } else { if (Op1) { @@ -800,7 +798,7 @@ BasicAliasAnalysis::CheckGEPInstructions( return MayAlias; // Be conservative with out-of-range accesses } } else { // Conservatively assume the minimum value for this index - GEP2Ops[i] = Context.getNullValue(Op2->getType()); + GEP2Ops[i] = Constant::getNullValue(Op2->getType()); } } } diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index 12ef0174e4..57e781615a 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -215,7 +215,7 @@ static Constant *FoldBitCast(Constant *C, const Type *DestTy, SmallVector<Constant*, 32> Result; if (NumDstElt < NumSrcElt) { // Handle: bitcast (<4 x i32> <i32 0, i32 1, i32 2, i32 3> to <2 x i64>) - Constant *Zero = Context.getNullValue(DstEltTy); + Constant *Zero = Constant::getNullValue(DstEltTy); unsigned Ratio = NumSrcElt/NumDstElt; unsigned SrcBitSize = SrcEltTy->getPrimitiveSizeInBits(); unsigned SrcElt = 0; @@ -419,7 +419,7 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy, if (ElemIdx.ult(APInt(ElemIdx.getBitWidth(), AT->getNumElements()))) { Constant *Index[] = { - Context.getNullValue(CE->getType()), + Constant::getNullValue(CE->getType()), ConstantInt::get(Context, ElemIdx) }; return @@ -486,7 +486,7 @@ Constant *llvm::ConstantFoldCompareInstOperands(unsigned Predicate, // proper extension or truncation. Constant *C = ConstantExpr::getIntegerCast(CE0->getOperand(0), IntPtrTy, false); - Constant *NewOps[] = { C, Context.getNullValue(C->getType()) }; + Constant *NewOps[] = { C, Constant::getNullValue(C->getType()) }; return ConstantFoldCompareInstOperands(Predicate, NewOps, 2, Context, TD); } @@ -496,7 +496,7 @@ Constant *llvm::ConstantFoldCompareInstOperands(unsigned Predicate, if (CE0->getOpcode() == Instruction::PtrToInt && CE0->getType() == IntPtrTy) { Constant *C = CE0->getOperand(0); - Constant *NewOps[] = { C, Context.getNullValue(C->getType()) }; + Constant *NewOps[] = { C, Constant::getNullValue(C->getType()) }; // FIXME! return ConstantFoldCompareInstOperands(Predicate, NewOps, 2, Context, TD); @@ -543,7 +543,7 @@ Constant *llvm::ConstantFoldCompareInstOperands(unsigned Predicate, Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C, ConstantExpr *CE, LLVMContext &Context) { - if (CE->getOperand(1) != Context.getNullValue(CE->getOperand(1)->getType())) + if (CE->getOperand(1) != Constant::getNullValue(CE->getOperand(1)->getType())) return 0; // Do not allow stepping over the value! // Loop over all of the operands, tracking down which value we are @@ -558,7 +558,7 @@ Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C, if (ConstantStruct *CS = dyn_cast<ConstantStruct>(C)) { C = CS->getOperand(El); } else if (isa<ConstantAggregateZero>(C)) { - C = Context.getNullValue(STy->getElementType(El)); + C = Constant::getNullValue(STy->getElementType(El)); } else if (isa<UndefValue>(C)) { C = UndefValue::get(STy->getElementType(El)); } else { @@ -571,7 +571,7 @@ Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C, if (ConstantArray *CA = dyn_cast<ConstantArray>(C)) C = CA->getOperand(CI->getZExtValue()); else if (isa<ConstantAggregateZero>(C)) - C = Context.getNullValue(ATy->getElementType()); + C = Constant::getNullValue(ATy->getElementType()); else if (isa<UndefValue>(C)) C = UndefValue::get(ATy->getElementType()); else @@ -582,7 +582,7 @@ Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C, if (ConstantVector *CP = dyn_cast<ConstantVector>(C)) C = CP->getOperand(CI->getZExtValue()); else if (isa<ConstantAggregateZero>(C)) - C = Context.getNullValue(PTy->getElementType()); + C = Constant::getNullValue(PTy->getElementType()); else if (isa<UndefValue>(C)) C = UndefValue::get(PTy->getElementType()); else @@ -741,7 +741,7 @@ llvm::ConstantFoldCall(Function *F, if (V >= -0.0) return ConstantFoldFP(sqrt, V, Ty, Context); else // Undefined - return Context.getNullValue(Ty); + return Constant::getNullValue(Ty); } break; case 's': diff --git a/lib/Analysis/DebugInfo.cpp b/lib/Analysis/DebugInfo.cpp index 5ecfdcdd44..1e2913477d 100644 --- a/lib/Analysis/DebugInfo.cpp +++ b/lib/Analysis/DebugInfo.cpp @@ -476,7 +476,7 @@ DIFactory::DIFactory(Module &m) /// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'. /// This is only valid when the descriptor is non-null. Constant *DIFactory::getCastToEmpty(DIDescriptor D) { - if (D.isNull()) return VMContext.getNullValue(EmptyStructPtr); + if (D.isNull()) return llvm::Constant::getNullValue(EmptyStructPtr); return ConstantExpr::getBitCast(D.getGV(), EmptyStructPtr); } @@ -576,7 +576,7 @@ DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID, unsigned RunTimeVer) { Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_compile_unit), - VMContext.getNullValue(EmptyStructPtr), + llvm::Constant::getNullValue(EmptyStructPtr), ConstantInt::get(Type::Int32Ty, LangID), GetStringConstant(Filename), GetStringConstant(Directory), @@ -737,7 +737,7 @@ DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context, Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_subprogram), - VMContext.getNullValue(EmptyStructPtr), + llvm::Constant::getNullValue(EmptyStructPtr), getCastToEmpty(Context), GetStringConstant(Name), GetStringConstant(DisplayName), @@ -769,7 +769,7 @@ DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name, bool isDefinition, llvm::GlobalVariable *Val) { Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_variable), - VMContext.getNullValue(EmptyStructPtr), + llvm::Constant::getNullValue(EmptyStructPtr), getCastToEmpty(Context), GetStringConstant(Name), GetStringConstant(DisplayName), diff --git a/lib/Analysis/IPA/Andersens.cpp b/lib/Analysis/IPA/Andersens.cpp index 84cde63f95..3c07d24bef 100644 --- a/lib/Analysis/IPA/Andersens.cpp +++ b/lib/Analysis/IPA/Andersens.cpp @@ -693,7 +693,7 @@ void Andersens::getMustAliases(Value *P, std::vector<Value*> &RetVals) { // If the object in the points-to set is the null object, then the null // pointer is a must alias. if (Pointee == &GraphNodes[NullObject]) - RetVals.push_back(P->getContext().getNullValue(P->getType())); + RetVals.push_back(Constant::getNullValue(P->getType())); } } AliasAnalysis::getMustAliases(P, RetVals); diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 8c4d191efb..03f3cd66ae 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -2100,7 +2100,7 @@ const SCEV *ScalarEvolution::getNegativeSCEV(const SCEV *V) { const Type *Ty = V->getType(); Ty = getEffectiveSCEVType(Ty); return getMulExpr(V, - getConstant(cast<ConstantInt>(getContext().getAllOnesValue(Ty)))); + getConstant(cast<ConstantInt>(Constant::getAllOnesValue(Ty)))); } /// getNotSCEV - Return a SCEV corresponding to ~V = -1-V @@ -2112,7 +2112,7 @@ const SCEV *ScalarEvolution::getNotSCEV(const SCEV *V) { const Type *Ty = V->getType(); Ty = getEffectiveSCEVType(Ty); const SCEV *AllOnes = - getConstant(cast<ConstantInt>(getContext().getAllOnesValue(Ty))); + getConstant(cast<ConstantInt>(Constant::getAllOnesValue(Ty))); return getMinusSCEV(AllOnes, V); } @@ -3479,10 +3479,10 @@ GetAddressedElementFromGlobal(LLVMContext &Context, GlobalVariable *GV, } else if (isa<ConstantAggregateZero>(Init)) { if (const StructType *STy = dyn_cast<StructType>(Init->getType())) { assert(Idx < STy->getNumElements() && "Bad struct index!"); - Init = Context.getNullValue(STy->getElementType(Idx)); + Init = Constant::getNullValue(STy->getElementType(Idx)); } else if (const ArrayType *ATy = dyn_cast<ArrayType>(Init->getType())) { if (Idx >= ATy->getNumElements()) return 0; // Bogus program - Init = Context.getNullValue(ATy->getElementType()); + Init = Constant::getNullValue(ATy->getElementType()); } else { llvm_unreachable("Unknown constant aggregate type!"); } diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp index b6c30fbc67..40bf0a1a02 100644 --- a/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/lib/Analysis/ScalarEvolutionExpander.cpp @@ -285,7 +285,7 @@ Value *SCEVExpander::expandAddToGEP(const SCEV *const *op_begin, Ops = NewOps; AnyNonZeroIndices |= !ScaledOps.empty(); Value *Scaled = ScaledOps.empty() ? - getContext().getNullValue(Ty) : + Constant::getNullValue(Ty) : expandCodeFor(SE.getAddExpr(ScaledOps), Ty); GepIndices.push_back(Scaled); @@ -401,7 +401,7 @@ Value *SCEVExpander::visitMulExpr(const SCEVMulExpr *S) { // -1 * ... ---> 0 - ... if (FirstOp == 1) - V = InsertBinop(Instruction::Sub, getContext().getNullValue(Ty), V); + V = InsertBinop(Instruction::Sub, Constant::getNullValue(Ty), V); return V; } @@ -523,7 +523,7 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) { BasicBlock *Preheader = L->getLoopPreheader(); PHINode *PN = PHINode::Create(Ty, "indvar", Header->begin()); InsertedValues.insert(PN); - PN->addIncoming(getContext().getNullValue(Ty), Preheader); + PN->addIncoming(Constant::getNullValue(Ty), Preheader); pred_iterator HPI = pred_begin(Header); assert(HPI != pred_end(Header) && "Loop with zero preds???"); diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp index 70f11f4f72..0ed0bbdc33 100644 --- a/lib/Analysis/ValueTracking.cpp +++ b/lib/Analysis/ValueTracking.cpp @@ -917,7 +917,7 @@ Value *llvm::FindInsertedValue(Value *V, const unsigned *idx_begin, idx_begin, idx_end)); else if (isa<ConstantAggregateZero>(V)) - return Context.getNullValue(ExtractValueInst::getIndexedType(PTy, + return Constant::getNullValue(ExtractValueInst::getIndexedType(PTy, idx_begin, idx_end)); else if (Constant *C = dyn_cast<Constant>(V)) { diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index 16dc32f55d..ac3570216d 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -2211,7 +2211,7 @@ bool LLParser::ConvertGlobalValIDToValue(const Type *Ty, ValID &ID, // FIXME: LabelTy should not be a first-class type. if (!Ty->isFirstClassType() || Ty == Type::LabelTy) return Error(ID.Loc, "invalid type for null constant"); - V = Context.getNullValue(Ty); + V = Constant::getNullValue(Ty); return false; case ValID::t_Constant: if (ID.ConstantVal->getType() != Ty) diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index a58e68f183..40920d87e9 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -898,7 +898,7 @@ bool BitcodeReader::ParseConstants() { CurTy = TypeList[Record[0]]; continue; // Skip the ValueList manipulation. case bitc::CST_CODE_NULL: // NULL - V = Context.getNullValue(CurTy); + V = Constant::getNullValue(CurTy); break; case bitc::CST_CODE_INTEGER: // INTEGER: [intval] if (!isa<IntegerType>(CurTy) || Record.empty()) @@ -993,7 +993,7 @@ bool BitcodeReader::ParseConstants() { std::vector<Constant*> Elts; for (unsigned i = 0; i != Size; ++i) Elts.push_back(ConstantInt::get(EltTy, Record[i])); - Elts.push_back(Context.getNullValue(EltTy)); + Elts.push_back(Constant::getNullValue(EltTy)); V = ConstantArray::get(ATy, Elts); break; } diff --git a/lib/CodeGen/IntrinsicLowering.cpp b/lib/CodeGen/IntrinsicLowering.cpp index 113eea0777..67e4e6f762 100644 --- a/lib/CodeGen/IntrinsicLowering.cpp +++ b/lib/CodeGen/IntrinsicLowering.cpp @@ -346,7 +346,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { } case |