diff options
Diffstat (limited to 'examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp')
-rw-r--r-- | examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp b/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp index ebaff49e89b2..0a58169e5ea9 100644 --- a/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp +++ b/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp @@ -746,8 +746,8 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction, const std::string &VarName) { IRBuilder<> TmpB(&TheFunction->getEntryBlock(), TheFunction->getEntryBlock().begin()); - return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), nullptr, - VarName.c_str()); + return TmpB.CreateAlloca(Type::getDoubleTy(TheFunction->getContext()), + nullptr, VarName.c_str()); } Value *NumberExprAST::IRGen(IRGenContext &C) const { @@ -806,8 +806,8 @@ Value *BinaryExprAST::IRGen(IRGenContext &C) const { case '<': L = C.getBuilder().CreateFCmpULT(L, R, "cmptmp"); // Convert bool 0/1 to double 0.0 or 1.0 - return C.getBuilder().CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()), - "booltmp"); + return C.getBuilder().CreateUIToFP(L, Type::getDoubleTy(C.getLLVMContext()), + "booltmp"); default: break; } @@ -884,8 +884,8 @@ Value *IfExprAST::IRGen(IRGenContext &C) const { // Emit merge block. TheFunction->getBasicBlockList().push_back(MergeBB); C.getBuilder().SetInsertPoint(MergeBB); - PHINode *PN = C.getBuilder().CreatePHI(Type::getDoubleTy(getGlobalContext()), 2, - "iftmp"); + PHINode *PN = C.getBuilder().CreatePHI(Type::getDoubleTy(C.getLLVMContext()), + 2, "iftmp"); PN->addIncoming(ThenV, ThenBB); PN->addIncoming(ElseV, ElseBB); @@ -927,7 +927,8 @@ Value *ForExprAST::IRGen(IRGenContext &C) const { // Make the new basic block for the loop header, inserting after current // block. - BasicBlock *LoopBB = BasicBlock::Create(getGlobalContext(), "loop", TheFunction); + BasicBlock *LoopBB = + BasicBlock::Create(C.getLLVMContext(), "loop", TheFunction); // Insert an explicit fall through from the current block to the LoopBB. C.getBuilder().CreateBr(LoopBB); @@ -953,7 +954,7 @@ Value *ForExprAST::IRGen(IRGenContext &C) const { if (!StepVal) return nullptr; } else { // If not specified, use 1.0. - StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0)); + StepVal = ConstantFP::get(C.getLLVMContext(), APFloat(1.0)); } // Compute the end condition. @@ -967,12 +968,12 @@ Value *ForExprAST::IRGen(IRGenContext &C) const { C.getBuilder().CreateStore(NextVar, Alloca); // Convert condition to a bool by comparing equal to 0.0. - EndCond = C.getBuilder().CreateFCmpONE(EndCond, - ConstantFP::get(getGlobalContext(), APFloat(0.0)), - "loopcond"); + EndCond = C.getBuilder().CreateFCmpONE( + EndCond, ConstantFP::get(C.getLLVMContext(), APFloat(0.0)), "loopcond"); // Create the "after loop" block and insert it. - BasicBlock *AfterBB = BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction); + BasicBlock *AfterBB = + BasicBlock::Create(C.getLLVMContext(), "afterloop", TheFunction); // Insert the conditional branch into the end of LoopEndBB. C.getBuilder().CreateCondBr(EndCond, LoopBB, AfterBB); @@ -987,7 +988,7 @@ Value *ForExprAST::IRGen(IRGenContext &C) const { C.NamedValues.erase(VarName); // for expr always returns 0.0. - return Constant::getNullValue(Type::getDoubleTy(getGlobalContext())); + return Constant::getNullValue(Type::getDoubleTy(C.getLLVMContext())); } Value *VarExprAST::IRGen(IRGenContext &C) const { @@ -1010,7 +1011,7 @@ Value *VarExprAST::IRGen(IRGenContext &C) const { InitVal = Init->IRGen(C); if (!InitVal) return nullptr; } else // If not specified, use 0.0. - InitVal = ConstantFP::get(getGlobalContext(), APFloat(0.0)); + InitVal = ConstantFP::get(C.getLLVMContext(), APFloat(0.0)); AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName); C.getBuilder().CreateStore(InitVal, Alloca); @@ -1039,10 +1040,10 @@ Function *PrototypeAST::IRGen(IRGenContext &C) const { std::string FnName = MakeLegalFunctionName(Name); // Make the function type: double(double,double) etc. - std::vector<Type*> Doubles(Args.size(), - Type::getDoubleTy(getGlobalContext())); - FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()), - Doubles, false); + std::vector<Type *> Doubles(Args.size(), + Type::getDoubleTy(C.getLLVMContext())); + FunctionType *FT = + FunctionType::get(Type::getDoubleTy(C.getLLVMContext()), Doubles, false); Function *F = Function::Create(FT, Function::ExternalLinkage, FnName, &C.getM()); @@ -1103,7 +1104,7 @@ Function *FunctionAST::IRGen(IRGenContext &C) const { BinopPrecedence[Proto->getOperatorName()] = Proto->Precedence; // Create a new basic block to start insertion into. - BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction); + BasicBlock *BB = BasicBlock::Create(C.getLLVMContext(), "entry", TheFunction); C.getBuilder().SetInsertPoint(BB); // Add all arguments to the symbol table and create their allocas. @@ -1296,7 +1297,8 @@ static void HandleTopLevelExpression(SessionContext &S, KaleidoscopeJIT &J) { /// top ::= definition | external | expression | ';' static void MainLoop() { - SessionContext S(getGlobalContext()); + LLVMContext TheContext; + SessionContext S(TheContext); KaleidoscopeJIT J(S); while (1) { |