summaryrefslogtreecommitdiffstats
path: root/llvm/examples/Kaleidoscope/Orc
diff options
context:
space:
mode:
authorMehdi Amini <mehdi.amini@apple.com>2016-04-14 21:59:01 +0000
committerMehdi Amini <mehdi.amini@apple.com>2016-04-14 21:59:01 +0000
commit03b42e41bf4bdd9ab05ea4c6905bae5d19971960 (patch)
treed4249845a564b11af673299653e7c4e876d8c4f2 /llvm/examples/Kaleidoscope/Orc
parent3d1c1deb04efe0022f11ebc18bb43d7341ba0c75 (diff)
downloadbcm5719-llvm-03b42e41bf4bdd9ab05ea4c6905bae5d19971960.tar.gz
bcm5719-llvm-03b42e41bf4bdd9ab05ea4c6905bae5d19971960.zip
Remove every uses of getGlobalContext() in LLVM (but the C API)
At the same time, fixes InstructionsTest::CastInst unittest: yes you can leave the IR in an invalid state and exit when you don't destroy the context (like the global one), no longer now. This is the first part of http://reviews.llvm.org/D19094 From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 266379
Diffstat (limited to 'llvm/examples/Kaleidoscope/Orc')
-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
4 files changed, 88 insertions, 80 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) {
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