summaryrefslogtreecommitdiffstats
path: root/llvm/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp')
-rw-r--r--llvm/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp42
1 files changed, 22 insertions, 20 deletions
diff --git a/llvm/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp b/llvm/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp
index 0371a3f76f6..2b90620a207 100644
--- a/llvm/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp
@@ -747,8 +747,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 {
@@ -807,8 +807,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;
}
@@ -885,8 +885,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);
@@ -928,7 +928,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);
@@ -954,7 +955,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.
@@ -968,12 +969,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);
@@ -988,7 +989,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 {
@@ -1011,7 +1012,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);
@@ -1040,10 +1041,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());
@@ -1104,7 +1105,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.
@@ -1366,7 +1367,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) {
OpenPOWER on IntegriCloud