summaryrefslogtreecommitdiffstats
path: root/llvm/examples/Kaleidoscope
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/examples/Kaleidoscope')
-rw-r--r--llvm/examples/Kaleidoscope/Chapter3/toy.cpp17
-rw-r--r--llvm/examples/Kaleidoscope/Chapter4/toy.cpp17
-rw-r--r--llvm/examples/Kaleidoscope/Chapter5/toy.cpp44
-rw-r--r--llvm/examples/Kaleidoscope/Chapter6/toy.cpp44
-rw-r--r--llvm/examples/Kaleidoscope/Chapter7/toy.cpp44
-rw-r--r--llvm/examples/Kaleidoscope/Chapter8/toy.cpp44
-rw-r--r--llvm/examples/Kaleidoscope/MCJIT/cached/toy-jit.cpp66
-rw-r--r--llvm/examples/Kaleidoscope/MCJIT/cached/toy.cpp54
-rw-r--r--llvm/examples/Kaleidoscope/MCJIT/complete/toy.cpp52
-rw-r--r--llvm/examples/Kaleidoscope/MCJIT/initial/toy.cpp52
-rw-r--r--llvm/examples/Kaleidoscope/MCJIT/lazy/toy-jit.cpp64
-rw-r--r--llvm/examples/Kaleidoscope/MCJIT/lazy/toy.cpp52
-rw-r--r--llvm/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp42
-rw-r--r--llvm/examples/Kaleidoscope/Orc/initial/toy.cpp42
-rw-r--r--llvm/examples/Kaleidoscope/Orc/lazy_codegen/toy.cpp42
-rw-r--r--llvm/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp42
16 files changed, 342 insertions, 376 deletions
diff --git a/llvm/examples/Kaleidoscope/Chapter3/toy.cpp b/llvm/examples/Kaleidoscope/Chapter3/toy.cpp
index 8c5252312a7..84113ccdc4c 100644
--- a/llvm/examples/Kaleidoscope/Chapter3/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Chapter3/toy.cpp
@@ -381,7 +381,8 @@ static std::unique_ptr<PrototypeAST> ParseExtern() {
//===----------------------------------------------------------------------===//
static std::unique_ptr<Module> TheModule;
-static IRBuilder<> Builder(getGlobalContext());
+static LLVMContext TheContext;
+static IRBuilder<> Builder(TheContext);
static std::map<std::string, Value *> NamedValues;
Value *LogErrorV(const char *Str) {
@@ -390,7 +391,7 @@ Value *LogErrorV(const char *Str) {
}
Value *NumberExprAST::codegen() {
- return ConstantFP::get(getGlobalContext(), APFloat(Val));
+ return ConstantFP::get(TheContext, APFloat(Val));
}
Value *VariableExprAST::codegen() {
@@ -417,8 +418,7 @@ Value *BinaryExprAST::codegen() {
case '<':
L = Builder.CreateFCmpULT(L, R, "cmptmp");
// Convert bool 0/1 to double 0.0 or 1.0
- return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
- "booltmp");
+ return Builder.CreateUIToFP(L, Type::getDoubleTy(TheContext), "booltmp");
default:
return LogErrorV("invalid binary operator");
}
@@ -446,10 +446,9 @@ Value *CallExprAST::codegen() {
Function *PrototypeAST::codegen() {
// Make the function type: double(double,double) etc.
- std::vector<Type *> Doubles(Args.size(),
- Type::getDoubleTy(getGlobalContext()));
+ std::vector<Type *> Doubles(Args.size(), Type::getDoubleTy(TheContext));
FunctionType *FT =
- FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);
+ FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);
Function *F =
Function::Create(FT, Function::ExternalLinkage, Name, TheModule.get());
@@ -473,7 +472,7 @@ Function *FunctionAST::codegen() {
return nullptr;
// Create a new basic block to start insertion into.
- BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
+ BasicBlock *BB = BasicBlock::Create(TheContext, "entry", TheFunction);
Builder.SetInsertPoint(BB);
// Record the function arguments in the NamedValues map.
@@ -577,7 +576,7 @@ int main() {
getNextToken();
// Make the module, which holds all the code.
- TheModule = llvm::make_unique<Module>("my cool jit", getGlobalContext());
+ TheModule = llvm::make_unique<Module>("my cool jit", TheContext);
// Run the main "interpreter loop" now.
MainLoop();
diff --git a/llvm/examples/Kaleidoscope/Chapter4/toy.cpp b/llvm/examples/Kaleidoscope/Chapter4/toy.cpp
index 4b5b1585a3d..f8d85ab56f0 100644
--- a/llvm/examples/Kaleidoscope/Chapter4/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Chapter4/toy.cpp
@@ -388,7 +388,8 @@ static std::unique_ptr<PrototypeAST> ParseExtern() {
//===----------------------------------------------------------------------===//
static std::unique_ptr<Module> TheModule;
-static IRBuilder<> Builder(getGlobalContext());
+static LLVMContext TheContext;
+static IRBuilder<> Builder(TheContext);
static std::map<std::string, Value *> NamedValues;
static std::unique_ptr<legacy::FunctionPassManager> TheFPM;
static std::unique_ptr<KaleidoscopeJIT> TheJIT;
@@ -415,7 +416,7 @@ Function *getFunction(std::string Name) {
}
Value *NumberExprAST::codegen() {
- return ConstantFP::get(getGlobalContext(), APFloat(Val));
+ return ConstantFP::get(TheContext, APFloat(Val));
}
Value *VariableExprAST::codegen() {
@@ -442,8 +443,7 @@ Value *BinaryExprAST::codegen() {
case '<':
L = Builder.CreateFCmpULT(L, R, "cmptmp");
// Convert bool 0/1 to double 0.0 or 1.0
- return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
- "booltmp");
+ return Builder.CreateUIToFP(L, Type::getDoubleTy(TheContext), "booltmp");
default:
return LogErrorV("invalid binary operator");
}
@@ -471,10 +471,9 @@ Value *CallExprAST::codegen() {
Function *PrototypeAST::codegen() {
// Make the function type: double(double,double) etc.
- std::vector<Type *> Doubles(Args.size(),
- Type::getDoubleTy(getGlobalContext()));
+ std::vector<Type *> Doubles(Args.size(), Type::getDoubleTy(TheContext));
FunctionType *FT =
- FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);
+ FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);
Function *F =
Function::Create(FT, Function::ExternalLinkage, Name, TheModule.get());
@@ -497,7 +496,7 @@ Function *FunctionAST::codegen() {
return nullptr;
// Create a new basic block to start insertion into.
- BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
+ BasicBlock *BB = BasicBlock::Create(TheContext, "entry", TheFunction);
Builder.SetInsertPoint(BB);
// Record the function arguments in the NamedValues map.
@@ -529,7 +528,7 @@ Function *FunctionAST::codegen() {
static void InitializeModuleAndPassManager() {
// Open a new module.
- TheModule = llvm::make_unique<Module>("my cool jit", getGlobalContext());
+ TheModule = llvm::make_unique<Module>("my cool jit", TheContext);
TheModule->setDataLayout(TheJIT->getTargetMachine().createDataLayout());
// Create a new pass manager attached to it.
diff --git a/llvm/examples/Kaleidoscope/Chapter5/toy.cpp b/llvm/examples/Kaleidoscope/Chapter5/toy.cpp
index d54c6696266..15646c44dc7 100644
--- a/llvm/examples/Kaleidoscope/Chapter5/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Chapter5/toy.cpp
@@ -512,7 +512,8 @@ static std::unique_ptr<PrototypeAST> ParseExtern() {
//===----------------------------------------------------------------------===//
static std::unique_ptr<Module> TheModule;
-static IRBuilder<> Builder(getGlobalContext());
+static LLVMContext TheContext;
+static IRBuilder<> Builder(TheContext);
static std::map<std::string, Value *> NamedValues;
static std::unique_ptr<legacy::FunctionPassManager> TheFPM;
static std::unique_ptr<KaleidoscopeJIT> TheJIT;
@@ -539,7 +540,7 @@ Function *getFunction(std::string Name) {
}
Value *NumberExprAST::codegen() {
- return ConstantFP::get(getGlobalContext(), APFloat(Val));
+ return ConstantFP::get(TheContext, APFloat(Val));
}
Value *VariableExprAST::codegen() {
@@ -566,8 +567,7 @@ Value *BinaryExprAST::codegen() {
case '<':
L = Builder.CreateFCmpULT(L, R, "cmptmp");
// Convert bool 0/1 to double 0.0 or 1.0
- return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
- "booltmp");
+ return Builder.CreateUIToFP(L, Type::getDoubleTy(TheContext), "booltmp");
default:
return LogErrorV("invalid binary operator");
}
@@ -600,16 +600,15 @@ Value *IfExprAST::codegen() {
// Convert condition to a bool by comparing equal to 0.0.
CondV = Builder.CreateFCmpONE(
- CondV, ConstantFP::get(getGlobalContext(), APFloat(0.0)), "ifcond");
+ CondV, ConstantFP::get(TheContext, APFloat(0.0)), "ifcond");
Function *TheFunction = Builder.GetInsertBlock()->getParent();
// Create blocks for the then and else cases. Insert the 'then' block at the
// end of the function.
- BasicBlock *ThenBB =
- BasicBlock::Create(getGlobalContext(), "then", TheFunction);
- BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
- BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
+ BasicBlock *ThenBB = BasicBlock::Create(TheContext, "then", TheFunction);
+ BasicBlock *ElseBB = BasicBlock::Create(TheContext, "else");
+ BasicBlock *MergeBB = BasicBlock::Create(TheContext, "ifcont");
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
@@ -639,8 +638,7 @@ Value *IfExprAST::codegen() {
// Emit merge block.
TheFunction->getBasicBlockList().push_back(MergeBB);
Builder.SetInsertPoint(MergeBB);
- PHINode *PN =
- Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2, "iftmp");
+ PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
PN->addIncoming(ThenV, ThenBB);
PN->addIncoming(ElseV, ElseBB);
@@ -672,8 +670,7 @@ Value *ForExprAST::codegen() {
// block.
Function *TheFunction = Builder.GetInsertBlock()->getParent();
BasicBlock *PreheaderBB = Builder.GetInsertBlock();
- BasicBlock *LoopBB =
- BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
+ BasicBlock *LoopBB = BasicBlock::Create(TheContext, "loop", TheFunction);
// Insert an explicit fall through from the current block to the LoopBB.
Builder.CreateBr(LoopBB);
@@ -682,8 +679,8 @@ Value *ForExprAST::codegen() {
Builder.SetInsertPoint(LoopBB);
// Start the PHI node with an entry for Start.
- PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()),
- 2, VarName.c_str());
+ PHINode *Variable =
+ Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, VarName.c_str());
Variable->addIncoming(StartVal, PreheaderBB);
// Within the loop, the variable is defined equal to the PHI node. If it
@@ -705,7 +702,7 @@ Value *ForExprAST::codegen() {
return nullptr;
} else {
// If not specified, use 1.0.
- StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
+ StepVal = ConstantFP::get(TheContext, APFloat(1.0));
}
Value *NextVar = Builder.CreateFAdd(Variable, StepVal, "nextvar");
@@ -717,12 +714,12 @@ Value *ForExprAST::codegen() {
// Convert condition to a bool by comparing equal to 0.0.
EndCond = Builder.CreateFCmpONE(
- EndCond, ConstantFP::get(getGlobalContext(), APFloat(0.0)), "loopcond");
+ EndCond, ConstantFP::get(TheContext, APFloat(0.0)), "loopcond");
// Create the "after loop" block and insert it.
BasicBlock *LoopEndBB = Builder.GetInsertBlock();
BasicBlock *AfterBB =
- BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
+ BasicBlock::Create(TheContext, "afterloop", TheFunction);
// Insert the conditional branch into the end of LoopEndBB.
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
@@ -740,15 +737,14 @@ Value *ForExprAST::codegen() {
NamedValues.erase(VarName);
// for expr always returns 0.0.
- return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
+ return Constant::getNullValue(Type::getDoubleTy(TheContext));
}
Function *PrototypeAST::codegen() {
// Make the function type: double(double,double) etc.
- std::vector<Type *> Doubles(Args.size(),
- Type::getDoubleTy(getGlobalContext()));
+ std::vector<Type *> Doubles(Args.size(), Type::getDoubleTy(TheContext));
FunctionType *FT =
- FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);
+ FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);
Function *F =
Function::Create(FT, Function::ExternalLinkage, Name, TheModule.get());
@@ -771,7 +767,7 @@ Function *FunctionAST::codegen() {
return nullptr;
// Create a new basic block to start insertion into.
- BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
+ BasicBlock *BB = BasicBlock::Create(TheContext, "entry", TheFunction);
Builder.SetInsertPoint(BB);
// Record the function arguments in the NamedValues map.
@@ -803,7 +799,7 @@ Function *FunctionAST::codegen() {
static void InitializeModuleAndPassManager() {
// Open a new module.
- TheModule = llvm::make_unique<Module>("my cool jit", getGlobalContext());
+ TheModule = llvm::make_unique<Module>("my cool jit", TheContext);
TheModule->setDataLayout(TheJIT->getTargetMachine().createDataLayout());
// Create a new pass manager attached to it.
diff --git a/llvm/examples/Kaleidoscope/Chapter6/toy.cpp b/llvm/examples/Kaleidoscope/Chapter6/toy.cpp
index 532a59a0c91..433ba7b82b8 100644
--- a/llvm/examples/Kaleidoscope/Chapter6/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Chapter6/toy.cpp
@@ -603,7 +603,8 @@ static std::unique_ptr<PrototypeAST> ParseExtern() {
//===----------------------------------------------------------------------===//
static std::unique_ptr<Module> TheModule;
-static IRBuilder<> Builder(getGlobalContext());
+static LLVMContext TheContext;
+static IRBuilder<> Builder(TheContext);
static std::map<std::string, Value *> NamedValues;
static std::unique_ptr<legacy::FunctionPassManager> TheFPM;
static std::unique_ptr<KaleidoscopeJIT> TheJIT;
@@ -630,7 +631,7 @@ Function *getFunction(std::string Name) {
}
Value *NumberExprAST::codegen() {
- return ConstantFP::get(getGlobalContext(), APFloat(Val));
+ return ConstantFP::get(TheContext, APFloat(Val));
}
Value *VariableExprAST::codegen() {
@@ -669,8 +670,7 @@ Value *BinaryExprAST::codegen() {
case '<':
L = Builder.CreateFCmpULT(L, R, "cmptmp");
// Convert bool 0/1 to double 0.0 or 1.0
- return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
- "booltmp");
+ return Builder.CreateUIToFP(L, Type::getDoubleTy(TheContext), "booltmp");
default:
break;
}
@@ -711,16 +711,15 @@ Value *IfExprAST::codegen() {
// Convert condition to a bool by comparing equal to 0.0.
CondV = Builder.CreateFCmpONE(
- CondV, ConstantFP::get(getGlobalContext(), APFloat(0.0)), "ifcond");
+ CondV, ConstantFP::get(TheContext, APFloat(0.0)), "ifcond");
Function *TheFunction = Builder.GetInsertBlock()->getParent();
// Create blocks for the then and else cases. Insert the 'then' block at the
// end of the function.
- BasicBlock *ThenBB =
- BasicBlock::Create(getGlobalContext(), "then", TheFunction);
- BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
- BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
+ BasicBlock *ThenBB = BasicBlock::Create(TheContext, "then", TheFunction);
+ BasicBlock *ElseBB = BasicBlock::Create(TheContext, "else");
+ BasicBlock *MergeBB = BasicBlock::Create(TheContext, "ifcont");
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
@@ -750,8 +749,7 @@ Value *IfExprAST::codegen() {
// Emit merge block.
TheFunction->getBasicBlockList().push_back(MergeBB);
Builder.SetInsertPoint(MergeBB);
- PHINode *PN =
- Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2, "iftmp");
+ PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
PN->addIncoming(ThenV, ThenBB);
PN->addIncoming(ElseV, ElseBB);
@@ -783,8 +781,7 @@ Value *ForExprAST::codegen() {
// block.
Function *TheFunction = Builder.GetInsertBlock()->getParent();
BasicBlock *PreheaderBB = Builder.GetInsertBlock();
- BasicBlock *LoopBB =
- BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
+ BasicBlock *LoopBB = BasicBlock::Create(TheContext, "loop", TheFunction);
// Insert an explicit fall through from the current block to the LoopBB.
Builder.CreateBr(LoopBB);
@@ -793,8 +790,8 @@ Value *ForExprAST::codegen() {
Builder.SetInsertPoint(LoopBB);
// Start the PHI node with an entry for Start.
- PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()),
- 2, VarName.c_str());
+ PHINode *Variable =
+ Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, VarName.c_str());
Variable->addIncoming(StartVal, PreheaderBB);
// Within the loop, the variable is defined equal to the PHI node. If it
@@ -816,7 +813,7 @@ Value *ForExprAST::codegen() {
return nullptr;
} else {
// If not specified, use 1.0.
- StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
+ StepVal = ConstantFP::get(TheContext, APFloat(1.0));
}
Value *NextVar = Builder.CreateFAdd(Variable, StepVal, "nextvar");
@@ -828,12 +825,12 @@ Value *ForExprAST::codegen() {
// Convert condition to a bool by comparing equal to 0.0.
EndCond = Builder.CreateFCmpONE(
- EndCond, ConstantFP::get(getGlobalContext(), APFloat(0.0)), "loopcond");
+ EndCond, ConstantFP::get(TheContext, APFloat(0.0)), "loopcond");
// Create the "after loop" block and insert it.
BasicBlock *LoopEndBB = Builder.GetInsertBlock();
BasicBlock *AfterBB =
- BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
+ BasicBlock::Create(TheContext, "afterloop", TheFunction);
// Insert the conditional branch into the end of LoopEndBB.
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
@@ -851,15 +848,14 @@ Value *ForExprAST::codegen() {
NamedValues.erase(VarName);
// for expr always returns 0.0.
- return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
+ return Constant::getNullValue(Type::getDoubleTy(TheContext));
}
Function *PrototypeAST::codegen() {
// Make the function type: double(double,double) etc.
- std::vector<Type *> Doubles(Args.size(),
- Type::getDoubleTy(getGlobalContext()));
+ std::vector<Type *> Doubles(Args.size(), Type::getDoubleTy(TheContext));
FunctionType *FT =
- FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);
+ FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);
Function *F =
Function::Create(FT, Function::ExternalLinkage, Name, TheModule.get());
@@ -886,7 +882,7 @@ Function *FunctionAST::codegen() {
BinopPrecedence[P.getOperatorName()] = P.getBinaryPrecedence();
// Create a new basic block to start insertion into.
- BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
+ BasicBlock *BB = BasicBlock::Create(TheContext, "entry", TheFunction);
Builder.SetInsertPoint(BB);
// Record the function arguments in the NamedValues map.
@@ -921,7 +917,7 @@ Function *FunctionAST::codegen() {
static void InitializeModuleAndPassManager() {
// Open a new module.
- TheModule = llvm::make_unique<Module>("my cool jit", getGlobalContext());
+ TheModule = llvm::make_unique<Module>("my cool jit", TheContext);
TheModule->setDataLayout(TheJIT->getTargetMachine().createDataLayout());
// Create a new pass manager attached to it.
diff --git a/llvm/examples/Kaleidoscope/Chapter7/toy.cpp b/llvm/examples/Kaleidoscope/Chapter7/toy.cpp
index 5cd062a1b5b..18401de5266 100644
--- a/llvm/examples/Kaleidoscope/Chapter7/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Chapter7/toy.cpp
@@ -673,7 +673,8 @@ static std::unique_ptr<PrototypeAST> ParseExtern() {
//===----------------------------------------------------------------------===//
static std::unique_ptr<Module> TheModule;
-static IRBuilder<> Builder(getGlobalContext());
+static LLVMContext TheContext;
+static IRBuilder<> Builder(TheContext);
static std::map<std::string, AllocaInst *> NamedValues;
static std::unique_ptr<legacy::FunctionPassManager> TheFPM;
static std::unique_ptr<KaleidoscopeJIT> TheJIT;
@@ -705,12 +706,12 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
const std::string &VarName) {
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
TheFunction->getEntryBlock().begin());
- return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), nullptr,
+ return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), nullptr,
VarName.c_str());
}
Value *NumberExprAST::codegen() {
- return ConstantFP::get(getGlobalContext(), APFloat(Val));
+ return ConstantFP::get(TheContext, APFloat(Val));
}
Value *VariableExprAST::codegen() {
@@ -774,8 +775,7 @@ Value *BinaryExprAST::codegen() {
case '<':
L = Builder.CreateFCmpULT(L, R, "cmptmp");
// Convert bool 0/1 to double 0.0 or 1.0
- return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
- "booltmp");
+ return Builder.CreateUIToFP(L, Type::getDoubleTy(TheContext), "booltmp");
default:
break;
}
@@ -816,16 +816,15 @@ Value *IfExprAST::codegen() {
// Convert condition to a bool by comparing equal to 0.0.
CondV = Builder.CreateFCmpONE(
- CondV, ConstantFP::get(getGlobalContext(), APFloat(0.0)), "ifcond");
+ CondV, ConstantFP::get(TheContext, APFloat(0.0)), "ifcond");
Function *TheFunction = Builder.GetInsertBlock()->getParent();
// Create blocks for the then and else cases. Insert the 'then' block at the
// end of the function.
- BasicBlock *ThenBB =
- BasicBlock::Create(getGlobalContext(), "then", TheFunction);
- BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
- BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
+ BasicBlock *ThenBB = BasicBlock::Create(TheContext, "then", TheFunction);
+ BasicBlock *ElseBB = BasicBlock::Create(TheContext, "else");
+ BasicBlock *MergeBB = BasicBlock::Create(TheContext, "ifcont");
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
@@ -855,8 +854,7 @@ Value *IfExprAST::codegen() {
// Emit merge block.
TheFunction->getBasicBlockList().push_back(MergeBB);
Builder.SetInsertPoint(MergeBB);
- PHINode *PN =
- Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2, "iftmp");
+ PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
PN->addIncoming(ThenV, ThenBB);
PN->addIncoming(ElseV, ElseBB);
@@ -898,8 +896,7 @@ Value *ForExprAST::codegen() {
// Make the new basic block for the loop header, inserting after current
// block.
- BasicBlock *LoopBB =
- BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
+ BasicBlock *LoopBB = BasicBlock::Create(TheContext, "loop", TheFunction);
// Insert an explicit fall through from the current block to the LoopBB.
Builder.CreateBr(LoopBB);
@@ -926,7 +923,7 @@ Value *ForExprAST::codegen() {
return nullptr;
} else {
// If not specified, use 1.0.
- StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
+ StepVal = ConstantFP::get(TheContext, APFloat(1.0));
}
// Compute the end condition.
@@ -942,11 +939,11 @@ Value *ForExprAST::codegen() {
// Convert condition to a bool by comparing equal to 0.0.
EndCond = Builder.CreateFCmpONE(
- EndCond, ConstantFP::get(getGlobalContext(), APFloat(0.0)), "loopcond");
+ EndCond, ConstantFP::get(TheContext, APFloat(0.0)), "loopcond");
// Create the "after loop" block and insert it.
BasicBlock *AfterBB =
- BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
+ BasicBlock::Create(TheContext, "afterloop", TheFunction);
// Insert the conditional branch into the end of LoopEndBB.
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
@@ -961,7 +958,7 @@ Value *ForExprAST::codegen() {
NamedValues.erase(VarName);
// for expr always returns 0.0.
- return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
+ return Constant::getNullValue(Type::getDoubleTy(TheContext));
}
Value *VarExprAST::codegen() {
@@ -985,7 +982,7 @@ Value *VarExprAST::codegen() {
if (!InitVal)
return nullptr;
} else { // If not specified, use 0.0.
- InitVal = ConstantFP::get(getGlobalContext(), APFloat(0.0));
+ InitVal = ConstantFP::get(TheContext, APFloat(0.0));
}
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
@@ -1014,10 +1011,9 @@ Value *VarExprAST::codegen() {
Function *PrototypeAST::codegen() {
// Make the function type: double(double,double) etc.
- std::vector<Type *> Doubles(Args.size(),
- Type::getDoubleTy(getGlobalContext()));
+ std::vector<Type *> Doubles(Args.size(), Type::getDoubleTy(TheContext));
FunctionType *FT =
- FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);
+ FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);
Function *F =
Function::Create(FT, Function::ExternalLinkage, Name, TheModule.get());
@@ -1044,7 +1040,7 @@ Function *FunctionAST::codegen() {
BinopPrecedence[P.getOperatorName()] = P.getBinaryPrecedence();
// Create a new basic block to start insertion into.
- BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
+ BasicBlock *BB = BasicBlock::Create(TheContext, "entry", TheFunction);
Builder.SetInsertPoint(BB);
// Record the function arguments in the NamedValues map.
@@ -1087,7 +1083,7 @@ Function *FunctionAST::codegen() {
static void InitializeModuleAndPassManager() {
// Open a new module.
- TheModule = llvm::make_unique<Module>("my cool jit", getGlobalContext());
+ TheModule = llvm::make_unique<Module>("my cool jit", TheContext);
TheModule->setDataLayout(TheJIT->getTargetMachine().createDataLayout());
// Create a new pass manager attached to it.
diff --git a/llvm/examples/Kaleidoscope/Chapter8/toy.cpp b/llvm/examples/Kaleidoscope/Chapter8/toy.cpp
index 31a83861a10..a482ccd7352 100644
--- a/llvm/examples/Kaleidoscope/Chapter8/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Chapter8/toy.cpp
@@ -87,7 +87,8 @@ namespace {
class PrototypeAST;
class ExprAST;
}
-static IRBuilder<> Builder(getGlobalContext());
+static LLVMContext TheContext;
+static IRBuilder<> Builder(TheContext);
struct DebugInfo {
DICompileUnit *TheCU;
DIType *DblTy;
@@ -886,13 +887,13 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
const std::string &VarName) {
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
TheFunction->getEntryBlock().begin());
- return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), nullptr,
+ return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), nullptr,
VarName.c_str());
}
Value *NumberExprAST::codegen() {
KSDbgInfo.emitLocation(this);
- return ConstantFP::get(getGlobalContext(), APFloat(Val));
+ return ConstantFP::get(TheContext, APFloat(Val));
}
Value *VariableExprAST::codegen() {
@@ -960,8 +961,7 @@ Value *BinaryExprAST::codegen() {
case '<':
L = Builder.CreateFCmpULT(L, R, "cmptmp");
// Convert bool 0/1 to double 0.0 or 1.0
- return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
- "booltmp");
+ return Builder.CreateUIToFP(L, Type::getDoubleTy(TheContext), "booltmp");
default:
break;
}
@@ -1006,16 +1006,15 @@ Value *IfExprAST::codegen() {
// Convert condition to a bool by comparing equal to 0.0.
CondV = Builder.CreateFCmpONE(
- CondV, ConstantFP::get(getGlobalContext(), APFloat(0.0)), "ifcond");
+ CondV, ConstantFP::get(TheContext, APFloat(0.0)), "ifcond");
Function *TheFunction = Builder.GetInsertBlock()->getParent();
// Create blocks for the then and else cases. Insert the 'then' block at the
// end of the function.
- BasicBlock *ThenBB =
- BasicBlock::Create(getGlobalContext(), "then", TheFunction);
- BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
- BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
+ BasicBlock *ThenBB = BasicBlock::Create(TheContext, "then", TheFunction);
+ BasicBlock *ElseBB = BasicBlock::Create(TheContext, "else");
+ BasicBlock *MergeBB = BasicBlock::Create(TheContext, "ifcont");
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
@@ -1045,8 +1044,7 @@ Value *IfExprAST::codegen() {
// Emit merge block.
TheFunction->getBasicBlockList().push_back(MergeBB);
Builder.SetInsertPoint(MergeBB);
- PHINode *PN =
- Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2, "iftmp");
+ PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
PN->addIncoming(ThenV, ThenBB);
PN->addIncoming(ElseV, ElseBB);
@@ -1090,8 +1088,7 @@ Value *ForExprAST::codegen() {
// Make the new basic block for the loop header, inserting after current
// block.
- BasicBlock *LoopBB =
- BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
+ BasicBlock *LoopBB = BasicBlock::Create(TheContext, "loop", TheFunction);
// Insert an explicit fall through from the current block to the LoopBB.
Builder.CreateBr(LoopBB);
@@ -1118,7 +1115,7 @@ Value *ForExprAST::codegen() {
return nullptr;
} else {
// If not specified, use 1.0.
- StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
+ StepVal = ConstantFP::get(TheContext, APFloat(1.0));
}
// Compute the end condition.
@@ -1134,11 +1131,11 @@ Value *ForExprAST::codegen() {
// Convert condition to a bool by comparing equal to 0.0.
EndCond = Builder.CreateFCmpONE(
- EndCond, ConstantFP::get(getGlobalContext(), APFloat(0.0)), "loopcond");
+ EndCond, ConstantFP::get(TheContext, APFloat(0.0)), "loopcond");
// Create the "after loop" block and insert it.
BasicBlock *AfterBB =
- BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
+ BasicBlock::Create(TheContext, "afterloop", TheFunction);
// Insert the conditional branch into the end of LoopEndBB.
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
@@ -1153,7 +1150,7 @@ Value *ForExprAST::codegen() {
NamedValues.erase(VarName);
// for expr always returns 0.0.
- return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
+ return Constant::getNullValue(Type::getDoubleTy(TheContext));
}
Value *VarExprAST::codegen() {
@@ -1177,7 +1174,7 @@ Value *VarExprAST::codegen() {
if (!InitVal)
return nullptr;
} else { // If not specified, use 0.0.
- InitVal = ConstantFP::get(getGlobalContext(), APFloat(0.0));
+ InitVal = ConstantFP::get(TheContext, APFloat(0.0));
}
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
@@ -1208,10 +1205,9 @@ Value *VarExprAST::codegen() {
Function *PrototypeAST::codegen() {
// Make the function type: double(double,double) etc.
- std::vector<Type *> Doubles(Args.size(),
- Type::getDoubleTy(getGlobalContext()));
+ std::vector<Type *> Doubles(Args.size(), Type::getDoubleTy(TheContext));
FunctionType *FT =
- FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);
+ FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);
Function *F =
Function::Create(FT, Function::ExternalLinkage, Name, TheModule.get());
@@ -1238,7 +1234,7 @@ Function *FunctionAST::codegen() {
BinopPrecedence[P.getOperatorName()] = P.getBinaryPrecedence();
// Create a new basic block to start insertion into.
- BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
+ BasicBlock *BB = BasicBlock::Create(TheContext, "entry", TheFunction);
Builder.SetInsertPoint(BB);
// Create a subprogram DIE for this function.
@@ -1319,7 +1315,7 @@ Function *FunctionAST::codegen() {
static void InitializeModule() {
// Open a new module.
- TheModule = llvm::make_unique<Module>("my cool jit", getGlobalContext());
+ TheModule = llvm::make_unique<Module>("my cool jit", TheContext);
TheModule->setDataLayout(TheJIT->getTargetMachine().createDataLayout());
}
diff --git a/llvm/examples/Kaleidoscope/MCJIT/cached/toy-jit.cpp b/llvm/examples/Kaleidoscope/MCJIT/cached/toy-jit.cpp
index 77b7f001095..3f3b133703b 100644
--- a/llvm/examples/Kaleidoscope/MCJIT/cached/toy-jit.cpp
+++ b/llvm/examples/Kaleidoscope/MCJIT/cached/toy-jit.cpp
@@ -623,7 +623,8 @@ static PrototypeAST *ParseExtern() {
static Module *TheModule;
static FunctionPassManager *TheFPM;
-static IRBuilder<> Builder(getGlobalContext());
+static LLVMContext TheContext;
+static IRBuilder<> Builder(TheContext);
static std::map<std::string, AllocaInst*> NamedValues;
Value *ErrorV(const char *Str) { Error(Str); return 0; }
@@ -634,12 +635,11 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
const std::string &VarName) {
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
TheFunction->getEntryBlock().begin());
- return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), 0,
- VarName.c_str());
+ return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), 0, VarName.c_str());
}
Value *NumberExprAST::Codegen() {
- return ConstantFP::get(getGlobalContext(), APFloat(Val));
+ return ConstantFP::get(TheContext, APFloat(Val));
}
Value *VariableExprAST::Codegen() {
@@ -699,8 +699,7 @@ Value *BinaryExprAST::Codegen() {
case '<':
L = Builder.CreateFCmpULT(L, R, "cmptmp");
// Convert bool 0/1 to double 0.0 or 1.0
- return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
- "booltmp");
+ return Builder.CreateUIToFP(L, Type::getDoubleTy(TheContext), "booltmp");
default: break;
}
@@ -740,18 +739,17 @@ Value *IfExprAST::Codegen() {
if (CondV == 0) return 0;
// Convert condition to a bool by comparing equal to 0.0.
- CondV = Builder.CreateFCmpONE(CondV,
- ConstantFP::get(getGlobalContext(), APFloat(0.0)),
- "ifcond");
-
+ CondV = Builder.CreateFCmpONE(
+ CondV, ConstantFP::get(TheContext, APFloat(0.0)), "ifcond");
+
Function *TheFunction = Builder.GetInsertBlock()->getParent();
// Create blocks for the then and else cases. Insert the 'then' block at the
// end of the function.
- BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction);
- BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
- BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
-
+ BasicBlock *ThenBB = BasicBlock::Create(TheContext, "then", TheFunction);
+ BasicBlock *ElseBB = BasicBlock::Create(TheContext, "else");
+ BasicBlock *MergeBB = BasicBlock::Create(TheContext, "ifcont");
+
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
// Emit then value.
@@ -778,9 +776,8 @@ Value *IfExprAST::Codegen() {
// Emit merge block.
TheFunction->getBasicBlockList().push_back(MergeBB);
Builder.SetInsertPoint(MergeBB);
- PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
- "iftmp");
-
+ PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
+
PN->addIncoming(ThenV, ThenBB);
PN->addIncoming(ElseV, ElseBB);
return PN;
@@ -821,8 +818,8 @@ Value *ForExprAST::Codegen() {
// Make the new basic block for the loop header, inserting after current
// block.
- BasicBlock *LoopBB = BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
-
+ BasicBlock *LoopBB = BasicBlock::Create(TheContext, "loop", TheFunction);
+
// Insert an explicit fall through from the current block to the LoopBB.
Builder.CreateBr(LoopBB);
@@ -847,7 +844,7 @@ Value *ForExprAST::Codegen() {
if (StepVal == 0) return 0;
} else {
// If not specified, use 1.0.
- StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
+ StepVal = ConstantFP::get(TheContext, APFloat(1.0));
}
// Compute the end condition.
@@ -861,13 +858,13 @@ Value *ForExprAST::Codegen() {
Builder.CreateStore(NextVar, Alloca);
// Convert condition to a bool by comparing equal to 0.0.
- EndCond = Builder.CreateFCmpONE(EndCond,
- ConstantFP::get(getGlobalContext(), APFloat(0.0)),
- "loopcond");
-
+ EndCond = Builder.CreateFCmpONE(
+ EndCond, ConstantFP::get(TheContext, APFloat(0.0)), "loopcond");
+
// Create the "after loop" block and insert it.
- BasicBlock *AfterBB = BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
-
+ BasicBlock *AfterBB =
+ BasicBlock::Create(TheContext, "afterloop", TheFunction);
+
// Insert the conditional branch into the end of LoopEndBB.
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
@@ -882,7 +879,7 @@ Value *ForExprAST::Codegen() {
// for expr always returns 0.0.
- return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
+ return Constant::getNullValue(Type::getDoubleTy(TheContext));
}
Value *VarExprAST::Codegen() {
@@ -905,7 +902,7 @@ Value *VarExprAST::Codegen() {
InitVal = Init->Codegen();
if (InitVal == 0) return 0;
} else { // If not specified, use 0.0.
- InitVal = ConstantFP::get(getGlobalContext(), APFloat(0.0));
+ InitVal = ConstantFP::get(TheContext, APFloat(0.0));
}
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
@@ -933,10 +930,9 @@ Value *VarExprAST::Codegen() {
Function *PrototypeAST::Codegen() {
// 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(TheContext));
+ FunctionType *FT =
+ FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);
Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
// If F conflicted, there was already something named 'Name'. If it has a
@@ -994,7 +990,7 @@ Function *FunctionAST::Codegen() {
BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
// Create a new basic block to start insertion into.
- BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
+ BasicBlock *BB = BasicBlock::Create(TheContext, "entry", TheFunction);
Builder.SetInsertPoint(BB);
// Add all arguments to the symbol table and create their allocas.
@@ -1122,7 +1118,7 @@ double printlf() {
Module* parseInputIR(std::string InputFile) {
SMDiagnostic Err;
- Module *M = ParseIRFile(InputFile, Err, getGlobalContext());
+ Module *M = ParseIRFile(InputFile, Err, TheContext);
if (!M) {
Err.print("IR parsing failed: ", errs());
return NULL;
@@ -1137,7 +1133,7 @@ Module* parseInputIR(std::string InputFile) {
int main(int argc, char **argv) {
InitializeNativeTarget();
- LLVMContext &Context = getGlobalContext();
+ LLVMContext &Context = TheContext;
cl::ParseCommandLineOptions(argc, argv,
"Kaleidoscope example program\n");
diff --git a/llvm/examples/Kaleidoscope/MCJIT/cached/toy.cpp b/llvm/examples/Kaleidoscope/MCJIT/cached/toy.cpp
index cc12abcc431..2b9c3da9218 100644
--- a/llvm/examples/Kaleidoscope/MCJIT/cached/toy.cpp
+++ b/llvm/examples/Kaleidoscope/MCJIT/cached/toy.cpp
@@ -994,7 +994,8 @@ void MCJITHelper::dump()
//===----------------------------------------------------------------------===//
static MCJITHelper *TheHelper;
-static IRBuilder<> Builder(getGlobalContext());
+static LLVMContext TheContext;
+static IRBuilder<> Builder(TheContext);
static std::map<std::string, AllocaInst*> NamedValues;
Value *ErrorV(const char *Str) { Error(Str); return 0; }
@@ -1005,12 +1006,11 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
const std::string &VarName) {
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
TheFunction->getEntryBlock().begin());
- return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), 0,
- VarName.c_str());
+ return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), 0, VarName.c_str());
}
Value *NumberExprAST::Codegen() {
- return ConstantFP::get(getGlobalContext(), APFloat(Val));
+ return ConstantFP::get(TheContext, APFloat(Val));
}
Value *VariableExprAST::Codegen() {
@@ -1066,8 +1066,7 @@ Value *BinaryExprAST::Codegen() {
case '<':
L = Builder.CreateFCmpULT(L, R, "cmptmp");
// Convert bool 0/1 to double 0.0 or 1.0
- return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
- "booltmp");
+ return Builder.CreateUIToFP(L, Type::getDoubleTy(TheContext), "booltmp");
default: break;
}
@@ -1104,17 +1103,16 @@ Value *IfExprAST::Codegen() {
if (CondV == 0) return 0;
// Convert condition to a bool by comparing equal to 0.0.
- CondV = Builder.CreateFCmpONE(CondV,
- ConstantFP::get(getGlobalContext(), APFloat(0.0)),
- "ifcond");
+ CondV = Builder.CreateFCmpONE(
+ CondV, ConstantFP::get(TheContext, APFloat(0.0)), "ifcond");
Function *TheFunction = Builder.GetInsertBlock()->getParent();
// Create blocks for the then and else cases. Insert the 'then' block at the
// end of the function.
- BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction);
- BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
- BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
+ BasicBlock *ThenBB = BasicBlock::Create(TheContext, "then", TheFunction);
+ BasicBlock *ElseBB = BasicBlock::Create(TheContext, "else");
+ BasicBlock *MergeBB = BasicBlock::Create(TheContext, "ifcont");
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
@@ -1142,8 +1140,7 @@ Value *IfExprAST::Codegen() {
// Emit merge block.
TheFunction->getBasicBlockList().push_back(MergeBB);
Builder.SetInsertPoint(MergeBB);
- PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
- "iftmp");
+ PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
PN->addIncoming(ThenV, ThenBB);
PN->addIncoming(ElseV, ElseBB);
@@ -1185,7 +1182,7 @@ Value *ForExprAST::Codegen() {
// Make the new basic block for the loop header, inserting after current
// block.
- BasicBlock *LoopBB = BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
+ BasicBlock *LoopBB = BasicBlock::Create(TheContext, "loop", TheFunction);
// Insert an explicit fall through from the current block to the LoopBB.
Builder.CreateBr(LoopBB);
@@ -1211,7 +1208,7 @@ Value *ForExprAST::Codegen() {
if (StepVal == 0) return 0;
} else {
// If not specified, use 1.0.
- StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
+ StepVal = ConstantFP::get(TheContext, APFloat(1.0));
}
// Compute the end condition.
@@ -1225,12 +1222,12 @@ Value *ForExprAST::Codegen() {
Builder.CreateStore(NextVar, Alloca);
// Convert condition to a bool by comparing equal to 0.0.
- EndCond = Builder.CreateFCmpONE(EndCond,
- ConstantFP::get(getGlobalContext(), APFloat(0.0)),
- "loopcond");
+ EndCond = Builder.CreateFCmpONE(
+ EndCond, ConstantFP::get(TheContext, APFloat(0.0)), "loopcond");
// Create the "after loop" block and insert it.
- BasicBlock *AfterBB = BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
+ BasicBlock *AfterBB =
+ BasicBlock::Create(TheContext, "afterloop", TheFunction);
// Insert the conditional branch into the end of LoopEndBB.
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
@@ -1246,7 +1243,7 @@ Value *ForExprAST::Codegen() {
// for expr always returns 0.0.
- return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
+ return Constant::getNullValue(Type::getDoubleTy(TheContext));
}
Value *VarExprAST::Codegen() {
@@ -1269,7 +1266,7 @@ Value *VarExprAST::Codegen() {
InitVal = Init->Codegen();
if (InitVal == 0) return 0;
} else { // If not specified, use 0.0.
- InitVal = ConstantFP::get(getGlobalContext(), APFloat(0.0));
+ InitVal = ConstantFP::get(TheContext, APFloat(0.0));
}
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
@@ -1297,10 +1294,9 @@ Value *VarExprAST::Codegen() {
Function *PrototypeAST::Codegen() {
// 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(TheContext));
+ FunctionType *FT =
+ FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);
std::string FnName = MakeLegalFunctionName(Name);
@@ -1365,7 +1361,7 @@ Function *FunctionAST::Codegen() {
BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
// Create a new basic block to start insertion into.
- BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
+ BasicBlock *BB = BasicBlock::Create(TheContext, "entry", TheFunction);
Builder.SetInsertPoint(BB);
// Add all arguments to the symbol table and create their allocas.
@@ -1490,7 +1486,7 @@ double printlf() {
Module* parseInputIR(std::string InputFile) {
SMDiagnostic Err;
- Module *M = ParseIRFile(InputFile, Err, getGlobalContext());
+ Module *M = ParseIRFile(InputFile, Err, TheContext);
if (!M) {
Err.print("IR parsing failed: ", errs());
return NULL;
@@ -1512,7 +1508,7 @@ int main(int argc, char **argv) {
InitializeNativeTarget();
InitializeNativeTargetAsmPrinter();
InitializeNativeTargetAsmParser();
- LLVMContext &Context = getGlobalContext();
+ LLVMContext &Context = TheContext;
cl::ParseCommandLineOptions(argc, argv,
"Kaleidoscope example program\n");
diff --git a/llvm/examples/Kaleidoscope/MCJIT/complete/toy.cpp b/llvm/examples/Kaleidoscope/MCJIT/complete/toy.cpp
index c78ec35fa0b..40a00693e8c 100644
--- a/llvm/examples/Kaleidoscope/MCJIT/complete/toy.cpp
+++ b/llvm/examples/Kaleidoscope/MCJIT/complete/toy.cpp
@@ -1066,7 +1066,8 @@ void MCJITHelper::dump()
//===----------------------------------------------------------------------===//
static BaseHelper *TheHelper;
-static IRBuilder<> Builder(getGlobalContext());
+static LLVMContext TheContext;
+static IRBuilder<> Builder(TheContext);
static std::map<std::string, AllocaInst*> NamedValues;
Value *ErrorV(const char *Str) { Error(Str); return 0; }
@@ -1077,12 +1078,11 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
const std::string &VarName) {
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
TheFunction->getEntryBlock().begin());
- return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), 0,
- VarName.c_str());
+ return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), 0, VarName.c_str());
}
Value *NumberExprAST::Codegen() {
- return ConstantFP::get(getGlobalContext(), APFloat(Val));
+ return ConstantFP::get(TheContext, APFloat(Val));
}
Value *VariableExprAST::Codegen() {
@@ -1140,8 +1140,7 @@ Value *BinaryExprAST::Codegen() {
case '<':
L = Builder.CreateFCmpULT(L, R, "cmptmp");
// Convert bool 0/1 to double 0.0 or 1.0
- return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
- "booltmp");
+ return Builder.CreateUIToFP(L, Type::getDoubleTy(TheContext), "booltmp");
default: break;
}
@@ -1182,17 +1181,16 @@ Value *IfExprAST::Codegen() {
if (CondV == 0) return 0;
// Convert condition to a bool by comparing equal to 0.0.
- CondV = Builder.CreateFCmpONE(CondV,
- ConstantFP::get(getGlobalContext(), APFloat(0.0)),
- "ifcond");
+ CondV = Builder.CreateFCmpONE(
+ CondV, ConstantFP::get(TheContext, APFloat(0.0)), "ifcond");
Function *TheFunction = Builder.GetInsertBlock()->getParent();
// Create blocks for the then and else cases. Insert the 'then' block at the
// end of the function.
- BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction);
- BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
- BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
+ BasicBlock *ThenBB = BasicBlock::Create(TheContext, "then", TheFunction);
+ BasicBlock *ElseBB = BasicBlock::Create(TheContext, "else");
+ BasicBlock *MergeBB = BasicBlock::Create(TheContext, "ifcont");
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
@@ -1220,8 +1218,7 @@ Value *IfExprAST::Codegen() {
// Emit merge block.
TheFunction->getBasicBlockList().push_back(MergeBB);
Builder.SetInsertPoint(MergeBB);
- PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
- "iftmp");
+ PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
PN->addIncoming(ThenV, ThenBB);
PN->addIncoming(ElseV, ElseBB);
@@ -1263,7 +1260,7 @@ Value *ForExprAST::Codegen() {
// Make the new basic block for the loop header, inserting after current
// block.
- BasicBlock *LoopBB = BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
+ BasicBlock *LoopBB = BasicBlock::Create(TheContext, "loop", TheFunction);
// Insert an explicit fall through from the current block to the LoopBB.
Builder.CreateBr(LoopBB);
@@ -1289,7 +1286,7 @@ Value *ForExprAST::Codegen() {
if (StepVal == 0) return 0;
} else {
// If not specified, use 1.0.
- StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
+ StepVal = ConstantFP::get(TheContext, APFloat(1.0));
}
// Compute the end condition.
@@ -1303,12 +1300,12 @@ Value *ForExprAST::Codegen() {
Builder.CreateStore(NextVar, Alloca);
// Convert condition to a bool by comparing equal to 0.0.
- EndCond = Builder.CreateFCmpONE(EndCond,
- ConstantFP::get(getGlobalContext(), APFloat(0.0)),
- "loopcond");
+ EndCond = Builder.CreateFCmpONE(
+ EndCond, ConstantFP::get(TheContext, APFloat(0.0)), "loopcond");
// Create the "after loop" block and insert it.
- BasicBlock *AfterBB = BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
+ BasicBlock *AfterBB =
+ BasicBlock::Create(TheContext, "afterloop", TheFunction);
// Insert the conditional branch into the end of LoopEndBB.
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
@@ -1324,7 +1321,7 @@ Value *ForExprAST::Codegen() {
// for expr always returns 0.0.
- return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
+ return Constant::getNullValue(Type::getDoubleTy(TheContext));
}
Value *VarExprAST::Codegen() {
@@ -1347,7 +1344,7 @@ Value *VarExprAST::Codegen() {
InitVal = Init->Codegen();
if (InitVal == 0) return 0;
} else { // If not specified, use 0.0.
- InitVal = ConstantFP::get(getGlobalContext(), APFloat(0.0));
+ InitVal = ConstantFP::get(TheContext, APFloat(0.0));
}
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
@@ -1375,10 +1372,9 @@ Value *VarExprAST::Codegen() {
Function *PrototypeAST::Codegen() {
// 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(TheContext));
+ FunctionType *FT =
+ FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);
std::string FnName;
FnName = MakeLegalFunctionName(Name);
@@ -1443,7 +1439,7 @@ Function *FunctionAST::Codegen() {
BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
// Create a new basic block to start insertion into.
- BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
+ BasicBlock *BB = BasicBlock::Create(TheContext, "entry", TheFunction);
Builder.SetInsertPoint(BB);
// Add all arguments to the symbol table and create their allocas.
@@ -1565,7 +1561,7 @@ int main(int argc, char **argv) {
InitializeNativeTarget();
InitializeNativeTargetAsmPrinter();
InitializeNativeTargetAsmParser();
- LLVMContext &Context = getGlobalContext();
+ LLVMContext &Context = TheContext;
cl::ParseCommandLineOptions(argc, argv,
"Kaleidoscope example program\n");
diff --git a/llvm/examples/Kaleidoscope/MCJIT/initial/toy.cpp b/llvm/examples/Kaleidoscope/MCJIT/initial/toy.cpp
index 9455946087d..1e476aef786 100644
--- a/llvm/examples/Kaleidoscope/MCJIT/initial/toy.cpp
+++ b/llvm/examples/Kaleidoscope/MCJIT/initial/toy.cpp
@@ -852,7 +852,8 @@ void MCJITHelper::dump()
//===----------------------------------------------------------------------===//
static MCJITHelper *TheHelper;
-static IRBuilder<> Builder(getGlobalContext());
+static LLVMContext TheContext;
+static IRBuilder<> Builder(TheContext);
static std::map<std::string, AllocaInst*> NamedValues;
Value *ErrorV(const char *Str) { Error(Str); return 0; }
@@ -863,12 +864,11 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
const std::string &VarName) {
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
TheFunction->getEntryBlock().begin());
- return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), 0,
- VarName.c_str());
+ return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), 0, VarName.c_str());
}
Value *NumberExprAST::Codegen() {
- return ConstantFP::get(getGlobalContext(), APFloat(Val));
+ return ConstantFP::get(TheContext, APFloat(Val));
}
Value *VariableExprAST::Codegen() {
@@ -924,8 +924,7 @@ Value *BinaryExprAST::Codegen() {
case '<':
L = Builder.CreateFCmpULT(L, R, "cmptmp");
// Convert bool 0/1 to double 0.0 or 1.0
- return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
- "booltmp");
+ return Builder.CreateUIToFP(L, Type::getDoubleTy(TheContext), "booltmp");
default: break;
}
@@ -962,17 +961,16 @@ Value *IfExprAST::Codegen() {
if (CondV == 0) return 0;
// Convert condition to a bool by comparing equal to 0.0.
- CondV = Builder.CreateFCmpONE(CondV,
- ConstantFP::get(getGlobalContext(), APFloat(0.0)),
- "ifcond");
+ CondV = Builder.CreateFCmpONE(
+ CondV, ConstantFP::get(TheContext, APFloat(0.0)), "ifcond");
Function *TheFunction = Builder.GetInsertBlock()->getParent();
// Create blocks for the then and else cases. Insert the 'then' block at the
// end of the function.
- BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction);
- BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
- BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
+ BasicBlock *ThenBB = BasicBlock::Create(TheContext, "then", TheFunction);
+ BasicBlock *ElseBB = BasicBlock::Create(TheContext, "else");
+ BasicBlock *MergeBB = BasicBlock::Create(TheContext, "ifcont");
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
@@ -1000,8 +998,7 @@ Value *IfExprAST::Codegen() {
// Emit merge block.
TheFunction->getBasicBlockList().push_back(MergeBB);
Builder.SetInsertPoint(MergeBB);
- PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
- "iftmp");
+ PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
PN->addIncoming(ThenV, ThenBB);
PN->addIncoming(ElseV, ElseBB);
@@ -1043,7 +1040,7 @@ Value *ForExprAST::Codegen() {
// Make the new basic block for the loop header, inserting after current
// block.
- BasicBlock *LoopBB = BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
+ BasicBlock *LoopBB = BasicBlock::Create(TheContext, "loop", TheFunction);
// Insert an explicit fall through from the current block to the LoopBB.
Builder.CreateBr(LoopBB);
@@ -1069,7 +1066,7 @@ Value *ForExprAST::Codegen() {
if (StepVal == 0) return 0;
} else {
// If not specified, use 1.0.
- StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
+ StepVal = ConstantFP::get(TheContext, APFloat(1.0));
}
// Compute the end condition.
@@ -1083,12 +1080,12 @@ Value *ForExprAST::Codegen() {
Builder.CreateStore(NextVar, Alloca);
// Convert condition to a bool by comparing equal to 0.0.
- EndCond = Builder.CreateFCmpONE(EndCond,
- ConstantFP::get(getGlobalContext(), APFloat(0.0)),
- "loopcond");
+ EndCond = Builder.CreateFCmpONE(
+ EndCond, ConstantFP::get(TheContext, APFloat(0.0)), "loopcond");
// Create the "after loop" block and insert it.
- BasicBlock *AfterBB = BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
+ BasicBlock *AfterBB =
+ BasicBlock::Create(TheContext, "afterloop", TheFunction);
// Insert the conditional branch into the end of LoopEndBB.
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
@@ -1104,7 +1101,7 @@ Value *ForExprAST::Codegen() {
// for expr always returns 0.0.
- return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
+ return Constant::getNullValue(Type::getDoubleTy(TheContext));
}
Value *VarExprAST::Codegen() {
@@ -1127,7 +1124,7 @@ Value *VarExprAST::Codegen() {
InitVal = Init->Codegen();
if (InitVal == 0) return 0;
} else { // If not specified, use 0.0.
- InitVal = ConstantFP::get(getGlobalContext(), APFloat(0.0));
+ InitVal = ConstantFP::get(TheContext, APFloat(0.0));
}
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
@@ -1155,10 +1152,9 @@ Value *VarExprAST::Codegen() {
Function *PrototypeAST::Codegen() {
// 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(TheContext));
+ FunctionType *FT =
+ FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);
std::string FnName = MakeLegalFunctionName(Name);
@@ -1223,7 +1219,7 @@ Function *FunctionAST::Codegen() {
BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
// Create a new basic block to start insertion into.
- BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
+ BasicBlock *BB = BasicBlock::Create(TheContext, "entry", TheFunction);
Builder.SetInsertPoint(BB);
// Add all arguments to the symbol table and create their allocas.
@@ -1349,7 +1345,7 @@ int main() {
InitializeNativeTarget();
InitializeNativeTargetAsmPrinter();
InitializeNativeTargetAsmParser();
- LLVMContext &Context = getGlobalContext();
+ LLVMContext &Context = TheContext;
// Install standard binary operators.
// 1 is lowest precedence.
diff --git a/llvm/examples/Kaleidoscope/MCJIT/lazy/toy-jit.cpp b/llvm/examples/Kaleidoscope/MCJIT/lazy/toy-jit.cpp
index 07adbd45014..f0c5ad5a46d 100644
--- a/llvm/examples/Kaleidoscope/MCJIT/lazy/toy-jit.cpp
+++ b/llvm/examples/Kaleidoscope/MCJIT/lazy/toy-jit.cpp
@@ -608,7 +608,8 @@ static PrototypeAST *ParseExtern() {
static Module *TheModule;
static FunctionPassManager *TheFPM;
-static IRBuilder<> Builder(getGlobalContext());
+static LLVMContext TheContext;
+static IRBuilder<> Builder(TheContext);
static std::map<std::string, AllocaInst*> NamedValues;
Value *ErrorV(const char *Str) { Error(Str); return 0; }
@@ -619,12 +620,11 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
const std::string &VarName) {
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
TheFunction->getEntryBlock().begin());
- return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), 0,
- VarName.c_str());
+ return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), 0, VarName.c_str());
}
Value *NumberExprAST::Codegen() {
- return ConstantFP::get(getGlobalContext(), APFloat(Val));
+ return ConstantFP::get(TheContext, APFloat(Val));
}
Value *VariableExprAST::Codegen() {
@@ -681,8 +681,7 @@ Value *BinaryExprAST::Codegen() {
case '<':
L = Builder.CreateFCmpULT(L, R, "cmptmp");
// Convert bool 0/1 to double 0.0 or 1.0
- return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
- "booltmp");
+ return Builder.CreateUIToFP(L, Type::getDoubleTy(TheContext), "booltmp");
default: break;
}
@@ -722,18 +721,17 @@ Value *IfExprAST::Codegen() {
if (CondV == 0) return 0;
// Convert condition to a bool by comparing equal to 0.0.
- CondV = Builder.CreateFCmpONE(CondV,
- ConstantFP::get(getGlobalContext(), APFloat(0.0)),
- "ifcond");
-
+ CondV = Builder.CreateFCmpONE(
+ CondV, ConstantFP::get(TheContext, APFloat(0.0)), "ifcond");
+
Function *TheFunction = Builder.GetInsertBlock()->getParent();
// Create blocks for the then and else cases. Insert the 'then' block at the
// end of the function.
- BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction);
- BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
- BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
-
+ BasicBlock *ThenBB = BasicBlock::Create(TheContext, "then", TheFunction);
+ BasicBlock *ElseBB = BasicBlock::Create(TheContext, "else");
+ BasicBlock *MergeBB = BasicBlock::Create(TheContext, "ifcont");
+
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
// Emit then value.
@@ -760,9 +758,8 @@ Value *IfExprAST::Codegen() {
// Emit merge block.
TheFunction->getBasicBlockList().push_back(MergeBB);
Builder.SetInsertPoint(MergeBB);
- PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
- "iftmp");
-
+ PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
+
PN->addIncoming(ThenV, ThenBB);
PN->addIncoming(ElseV, ElseBB);
return PN;
@@ -803,8 +800,8 @@ Value *ForExprAST::Codegen() {
// Make the new basic block for the loop header, inserting after current
// block.
- BasicBlock *LoopBB = BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
-
+ BasicBlock *LoopBB = BasicBlock::Create(TheContext, "loop", TheFunction);
+
// Insert an explicit fall through from the current block to the LoopBB.
Builder.CreateBr(LoopBB);
@@ -829,7 +826,7 @@ Value *ForExprAST::Codegen() {
if (StepVal == 0) return 0;
} else {
// If not specified, use 1.0.
- StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
+ StepVal = ConstantFP::get(TheContext, APFloat(1.0));
}
// Compute the end condition.
@@ -843,13 +840,13 @@ Value *ForExprAST::Codegen() {
Builder.CreateStore(NextVar, Alloca);
// Convert condition to a bool by comparing equal to 0.0.
- EndCond = Builder.CreateFCmpONE(EndCond,
- ConstantFP::get(getGlobalContext(), APFloat(0.0)),
- "loopcond");
-
+ EndCond = Builder.CreateFCmpONE(
+ EndCond, ConstantFP::get(TheContext, APFloat(0.0)), "loopcond");
+
// Create the "after loop" block and insert it.
- BasicBlock *AfterBB = BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
-
+ BasicBlock *AfterBB =
+ BasicBlock::Create(TheContext, "afterloop", TheFunction);
+
// Insert the conditional branch into the end of LoopEndBB.
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
@@ -864,7 +861,7 @@ Value *ForExprAST::Codegen() {
// for expr always returns 0.0.
- return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
+ return Constant::getNullValue(Type::getDoubleTy(TheContext));
}
Value *VarExprAST::Codegen() {
@@ -887,7 +884,7 @@ Value *VarExprAST::Codegen() {
InitVal = Init->Codegen();
if (InitVal == 0) return 0;
} else { // If not specified, use 0.0.
- InitVal = ConstantFP::get(getGlobalContext(), APFloat(0.0));
+ InitVal = ConstantFP::get(TheContext, APFloat(0.0));
}
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
@@ -915,10 +912,9 @@ Value *VarExprAST::Codegen() {
Function *PrototypeAST::Codegen() {
// 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(TheContext));
+ FunctionType *FT =
+ FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);
Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
// If F conflicted, there was already something named 'Name'. If it has a
@@ -976,7 +972,7 @@ Function *FunctionAST::Codegen() {
BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
// Create a new basic block to start insertion into.
- BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
+ BasicBlock *BB = BasicBlock::Create(TheContext, "entry", TheFunction);
Builder.SetInsertPoint(BB);
// Add all arguments to the symbol table and create their allocas.
@@ -1104,7 +1100,7 @@ double printlf() {
int main(int argc, char **argv) {
InitializeNativeTarget();
- LLVMContext &Context = getGlobalContext();
+ LLVMContext &Context = TheContext;
// Install standard binary operators.
// 1 is lowest precedence.
diff --git a/llvm/examples/Kaleidoscope/MCJIT/lazy/toy.cpp b/llvm/examples/Kaleidoscope/MCJIT/lazy/toy.cpp
index 14d758cfa79..37339b60b44 100644
--- a/llvm/examples/Kaleidoscope/MCJIT/lazy/toy.cpp
+++ b/llvm/examples/Kaleidoscope/MCJIT/lazy/toy.cpp
@@ -892,7 +892,8 @@ void MCJITHelper::dump()
//===----------------------------------------------------------------------===//
static MCJITHelper *TheHelper;
-static IRBuilder<> Builder(getGlobalContext());
+static LLVMContext TheContext;
+static IRBuilder<> Builder(TheContext);
static std::map<std::string, AllocaInst*> NamedValues;
Value *ErrorV(const char *Str) { Error(Str); return 0; }
@@ -903,12 +904,11 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
const std::string &VarName) {
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
TheFunction->getEntryBlock().begin());
- return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), 0,
- VarName.c_str());
+ return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), 0, VarName.c_str());
}
Value *NumberExprAST::Codegen() {
- return ConstantFP::get(getGlobalContext(), APFloat(Val));
+ return ConstantFP::get(TheContext, APFloat(Val));
}
Value *VariableExprAST::Codegen() {
@@ -964,8 +964,7 @@ Value *BinaryExprAST::Codegen() {
case '<':
L = Builder.CreateFCmpULT(L, R, "cmptmp");
// Convert bool 0/1 to double 0.0 or 1.0
- return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
- "booltmp");
+ return Builder.CreateUIToFP(L, Type::getDoubleTy(TheContext), "booltmp");
default: break;
}
@@ -1002,17 +1001,16 @@ Value *IfExprAST::Codegen() {
if (CondV == 0) return 0;
// Convert condition to a bool by comparing equal to 0.0.
- CondV = Builder.CreateFCmpONE(CondV,
- ConstantFP::get(getGlobalContext(), APFloat(0.0)),
- "ifcond");
+ CondV = Builder.CreateFCmpONE(
+ CondV, ConstantFP::get(TheContext, APFloat(0.0)), "ifcond");
Function *TheFunction = Builder.GetInsertBlock()->getParent();
// Create blocks for the then and else cases. Insert the 'then' block at the
// end of the function.
- BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction);
- BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
- BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
+ BasicBlock *ThenBB = BasicBlock::Create(TheContext, "then", TheFunction);
+ BasicBlock *ElseBB = BasicBlock::Create(TheContext, "else");
+ BasicBlock *MergeBB = BasicBlock::Create(TheContext, "ifcont");
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
@@ -1040,8 +1038,7 @@ Value *IfExprAST::Codegen() {
// Emit merge block.
TheFunction->getBasicBlockList().push_back(MergeBB);
Builder.SetInsertPoint(MergeBB);
- PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
- "iftmp");
+ PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
PN->addIncoming(ThenV, ThenBB);
PN->addIncoming(ElseV, ElseBB);
@@ -1083,7 +1080,7 @@ Value *ForExprAST::Codegen() {
// Make the new basic block for the loop header, inserting after current
// block.
- BasicBlock *LoopBB = BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
+ BasicBlock *LoopBB = BasicBlock::Create(TheContext, "loop", TheFunction);
// Insert an explicit fall through from the current block to the LoopBB.
Builder.CreateBr(LoopBB);
@@ -1109,7 +1106,7 @@ Value *ForExprAST::Codegen() {
if (StepVal == 0) return 0;
} else {
// If not specified, use 1.0.
- StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
+ StepVal = ConstantFP::get(TheContext, APFloat(1.0));
}
// Compute the end condition.
@@ -1123,12 +1120,12 @@ Value *ForExprAST::Codegen() {
Builder.CreateStore(NextVar, Alloca);
// Convert condition to a bool by comparing equal to 0.0.
- EndCond = Builder.CreateFCmpONE(EndCond,
- ConstantFP::get(getGlobalContext(), APFloat(0.0)),
- "loopcond");
+ EndCond = Builder.CreateFCmpONE(
+ EndCond, ConstantFP::get(TheContext, APFloat(0.0)), "loopcond");
// Create the "after loop" block and insert it.
- BasicBlock *AfterBB = BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
+ BasicBlock *AfterBB =
+ BasicBlock::Create(TheContext, "afterloop", TheFunction);
// Insert the conditional branch into the end of LoopEndBB.
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
@@ -1144,7 +1141,7 @@ Value *ForExprAST::Codegen() {
// for expr always returns 0.0.
- return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
+ return Constant::getNullValue(Type::getDoubleTy(TheContext));
}
Value *VarExprAST::Codegen() {
@@ -1167,7 +1164,7 @@ Value *VarExprAST::Codegen() {
InitVal = Init->Codegen();
if (InitVal == 0) return 0;
} else { // If not specified, use 0.0.
- InitVal = ConstantFP::get(getGlobalContext(), APFloat(0.0));
+ InitVal = ConstantFP::get(TheContext, APFloat(0.0));
}
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
@@ -1195,10 +1192,9 @@ Value *VarExprAST::Codegen() {
Function *PrototypeAST::Codegen() {
// 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(TheContext));
+ FunctionType *FT =
+ FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);
std::string FnName = MakeLegalFunctionName(Name);
@@ -1263,7 +1259,7 @@ Function *FunctionAST::Codegen() {
BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
// Create a new basic block to start insertion into.
- BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
+ BasicBlock *BB = BasicBlock::Create(TheContext, "entry", TheFunction);
Builder.SetInsertPoint(BB);
// Add all arguments to the symbol table and create their allocas.
@@ -1390,7 +1386,7 @@ int main() {
InitializeNativeTarget();
InitializeNativeTargetAsmPrinter();
InitializeNativeTargetAsmParser();
- LLVMContext &Context = getGlobalContext();
+ LLVMContext &Context = TheContext;
// Install standard binary operators.
// 1 is lowest precedence.
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) {
diff --git a/llvm/examples/Kaleidoscope/Orc/initial/toy.cpp b/llvm/examples/Kaleidoscope/Orc/initial/toy.cpp
index 2a6bb92246d..77c8db46ba9 100644
--- a/llvm/examples/Kaleidoscope/Orc/initial/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Orc/initial/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.
@@ -1261,7 +1262,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) {
diff --git a/llvm/examples/Kaleidoscope/Orc/lazy_codegen/toy.cpp b/llvm/examples/Kaleidoscope/Orc/lazy_codegen/toy.cpp
index 5205b406ed7..5ab8c4fa9c9 100644
--- a/llvm/examples/Kaleidoscope/Orc/lazy_codegen/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Orc/lazy_codegen/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.
@@ -1265,7 +1266,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) {
diff --git a/llvm/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp b/llvm/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp
index ebaff49e89b..0a58169e5ea 100644
--- a/llvm/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp
+++ b/llvm/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) {
OpenPOWER on IntegriCloud