mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
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
This commit is contained in:
parent
2dfb6d03c5
commit
ea195a382e
@ -434,7 +434,7 @@ val create_context : unit -> llcontext
|
|||||||
[llvm::LLVMContext::~LLVMContext]. *)
|
[llvm::LLVMContext::~LLVMContext]. *)
|
||||||
val dispose_context : llcontext -> unit
|
val dispose_context : llcontext -> unit
|
||||||
|
|
||||||
(** See the function [llvm::getGlobalContext]. *)
|
(** See the function [LLVMGetGlobalContext]. *)
|
||||||
val global_context : unit -> llcontext
|
val global_context : unit -> llcontext
|
||||||
|
|
||||||
(** [mdkind_id context name] returns the MDKind ID that corresponds to the
|
(** [mdkind_id context name] returns the MDKind ID that corresponds to the
|
||||||
|
@ -2419,11 +2419,6 @@ determine what context they belong to by looking at their own ``Type``. If you
|
|||||||
are adding new entities to LLVM IR, please try to maintain this interface
|
are adding new entities to LLVM IR, please try to maintain this interface
|
||||||
design.
|
design.
|
||||||
|
|
||||||
For clients that do *not* require the benefits of isolation, LLVM provides a
|
|
||||||
convenience API ``getGlobalContext()``. This returns a global, lazily
|
|
||||||
initialized ``LLVMContext`` that may be used in situations where isolation is
|
|
||||||
not a concern.
|
|
||||||
|
|
||||||
.. _jitthreading:
|
.. _jitthreading:
|
||||||
|
|
||||||
Threads and the JIT
|
Threads and the JIT
|
||||||
|
@ -38,6 +38,8 @@ Non-comprehensive list of changes in this release
|
|||||||
(other than GlobalValue). This is intended to be used in release builds by
|
(other than GlobalValue). This is intended to be used in release builds by
|
||||||
clients that are interested in saving CPU/memory as much as possible.
|
clients that are interested in saving CPU/memory as much as possible.
|
||||||
|
|
||||||
|
* There is no longer a "global context" available in LLVM, except for the C API.
|
||||||
|
|
||||||
* .. note about autoconf build having been removed.
|
* .. note about autoconf build having been removed.
|
||||||
|
|
||||||
* .. note about C API functions LLVMParseBitcode,
|
* .. note about C API functions LLVMParseBitcode,
|
||||||
|
@ -74,7 +74,7 @@ parser, which will be used to report errors found during code generation
|
|||||||
.. code-block:: c++
|
.. code-block:: c++
|
||||||
|
|
||||||
static std::unique_ptr<Module> *TheModule;
|
static std::unique_ptr<Module> *TheModule;
|
||||||
static IRBuilder<> Builder(getGlobalContext());
|
static IRBuilder<> Builder(LLVMContext);
|
||||||
static std::map<std::string, Value*> NamedValues;
|
static std::map<std::string, Value*> NamedValues;
|
||||||
|
|
||||||
Value *LogErrorV(const char *Str) {
|
Value *LogErrorV(const char *Str) {
|
||||||
@ -116,7 +116,7 @@ First we'll do numeric literals:
|
|||||||
.. code-block:: c++
|
.. code-block:: c++
|
||||||
|
|
||||||
Value *NumberExprAST::codegen() {
|
Value *NumberExprAST::codegen() {
|
||||||
return ConstantFP::get(getGlobalContext(), APFloat(Val));
|
return ConstantFP::get(LLVMContext, APFloat(Val));
|
||||||
}
|
}
|
||||||
|
|
||||||
In the LLVM IR, numeric constants are represented with the
|
In the LLVM IR, numeric constants are represented with the
|
||||||
@ -165,7 +165,7 @@ variables <LangImpl7.html#user-defined-local-variables>`_.
|
|||||||
case '<':
|
case '<':
|
||||||
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
|
return Builder.CreateUIToFP(L, Type::getDoubleTy(LLVMContext),
|
||||||
"booltmp");
|
"booltmp");
|
||||||
default:
|
default:
|
||||||
return LogErrorV("invalid binary operator");
|
return LogErrorV("invalid binary operator");
|
||||||
@ -264,9 +264,9 @@ with:
|
|||||||
Function *PrototypeAST::codegen() {
|
Function *PrototypeAST::codegen() {
|
||||||
// Make the function type: double(double,double) etc.
|
// Make the function type: double(double,double) etc.
|
||||||
std::vector<Type*> Doubles(Args.size(),
|
std::vector<Type*> Doubles(Args.size(),
|
||||||
Type::getDoubleTy(getGlobalContext()));
|
Type::getDoubleTy(LLVMContext));
|
||||||
FunctionType *FT =
|
FunctionType *FT =
|
||||||
FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);
|
FunctionType::get(Type::getDoubleTy(LLVMContext), Doubles, false);
|
||||||
|
|
||||||
Function *F =
|
Function *F =
|
||||||
Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
|
Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
|
||||||
@ -340,7 +340,7 @@ assert that the function is empty (i.e. has no body yet) before we start.
|
|||||||
.. code-block:: c++
|
.. code-block:: c++
|
||||||
|
|
||||||
// Create a new basic block to start insertion into.
|
// Create a new basic block to start insertion into.
|
||||||
BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
|
BasicBlock *BB = BasicBlock::Create(LLVMContext, "entry", TheFunction);
|
||||||
Builder.SetInsertPoint(BB);
|
Builder.SetInsertPoint(BB);
|
||||||
|
|
||||||
// Record the function arguments in the NamedValues map.
|
// Record the function arguments in the NamedValues map.
|
||||||
|
@ -131,7 +131,8 @@ for us:
|
|||||||
|
|
||||||
void InitializeModuleAndPassManager(void) {
|
void InitializeModuleAndPassManager(void) {
|
||||||
// Open a new module.
|
// Open a new module.
|
||||||
TheModule = llvm::make_unique<Module>("my cool jit", getGlobalContext());
|
Context LLVMContext;
|
||||||
|
TheModule = llvm::make_unique<Module>("my cool jit", LLVMContext);
|
||||||
TheModule->setDataLayout(TheJIT->getTargetMachine().createDataLayout());
|
TheModule->setDataLayout(TheJIT->getTargetMachine().createDataLayout());
|
||||||
|
|
||||||
// Create a new pass manager attached to it.
|
// Create a new pass manager attached to it.
|
||||||
|
@ -292,7 +292,7 @@ for ``IfExprAST``:
|
|||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
CondV = Builder.CreateFCmpONE(
|
CondV = Builder.CreateFCmpONE(
|
||||||
CondV, ConstantFP::get(getGlobalContext(), APFloat(0.0)), "ifcond");
|
CondV, ConstantFP::get(LLVMContext, APFloat(0.0)), "ifcond");
|
||||||
|
|
||||||
This code is straightforward and similar to what we saw before. We emit
|
This code is straightforward and similar to what we saw before. We emit
|
||||||
the expression for the condition, then compare that value to zero to get
|
the expression for the condition, then compare that value to zero to get
|
||||||
@ -305,9 +305,9 @@ a truth value as a 1-bit (bool) value.
|
|||||||
// Create blocks for the then and else cases. Insert the 'then' block at the
|
// Create blocks for the then and else cases. Insert the 'then' block at the
|
||||||
// end of the function.
|
// end of the function.
|
||||||
BasicBlock *ThenBB =
|
BasicBlock *ThenBB =
|
||||||
BasicBlock::Create(getGlobalContext(), "then", TheFunction);
|
BasicBlock::Create(LLVMContext, "then", TheFunction);
|
||||||
BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
|
BasicBlock *ElseBB = BasicBlock::Create(LLVMContext, "else");
|
||||||
BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
|
BasicBlock *MergeBB = BasicBlock::Create(LLVMContext, "ifcont");
|
||||||
|
|
||||||
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
|
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
|
||||||
|
|
||||||
@ -400,7 +400,7 @@ code:
|
|||||||
TheFunction->getBasicBlockList().push_back(MergeBB);
|
TheFunction->getBasicBlockList().push_back(MergeBB);
|
||||||
Builder.SetInsertPoint(MergeBB);
|
Builder.SetInsertPoint(MergeBB);
|
||||||
PHINode *PN =
|
PHINode *PN =
|
||||||
Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2, "iftmp");
|
Builder.CreatePHI(Type::getDoubleTy(LLVMContext), 2, "iftmp");
|
||||||
|
|
||||||
PN->addIncoming(ThenV, ThenBB);
|
PN->addIncoming(ThenV, ThenBB);
|
||||||
PN->addIncoming(ElseV, ElseBB);
|
PN->addIncoming(ElseV, ElseBB);
|
||||||
@ -625,7 +625,7 @@ expression).
|
|||||||
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
||||||
BasicBlock *PreheaderBB = Builder.GetInsertBlock();
|
BasicBlock *PreheaderBB = Builder.GetInsertBlock();
|
||||||
BasicBlock *LoopBB =
|
BasicBlock *LoopBB =
|
||||||
BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
|
BasicBlock::Create(LLVMContext, "loop", TheFunction);
|
||||||
|
|
||||||
// Insert an explicit fall through from the current block to the LoopBB.
|
// Insert an explicit fall through from the current block to the LoopBB.
|
||||||
Builder.CreateBr(LoopBB);
|
Builder.CreateBr(LoopBB);
|
||||||
@ -642,7 +642,7 @@ the two blocks.
|
|||||||
Builder.SetInsertPoint(LoopBB);
|
Builder.SetInsertPoint(LoopBB);
|
||||||
|
|
||||||
// Start the PHI node with an entry for Start.
|
// Start the PHI node with an entry for Start.
|
||||||
PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()),
|
PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(LLVMContext),
|
||||||
2, VarName.c_str());
|
2, VarName.c_str());
|
||||||
Variable->addIncoming(StartVal, PreheaderBB);
|
Variable->addIncoming(StartVal, PreheaderBB);
|
||||||
|
|
||||||
@ -693,7 +693,7 @@ table.
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
} else {
|
} else {
|
||||||
// If not specified, use 1.0.
|
// If not specified, use 1.0.
|
||||||
StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
|
StepVal = ConstantFP::get(LLVMContext, APFloat(1.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *NextVar = Builder.CreateFAdd(Variable, StepVal, "nextvar");
|
Value *NextVar = Builder.CreateFAdd(Variable, StepVal, "nextvar");
|
||||||
@ -712,7 +712,7 @@ iteration of the loop.
|
|||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
EndCond = Builder.CreateFCmpONE(
|
EndCond = Builder.CreateFCmpONE(
|
||||||
EndCond, ConstantFP::get(getGlobalContext(), APFloat(0.0)), "loopcond");
|
EndCond, ConstantFP::get(LLVMContext, APFloat(0.0)), "loopcond");
|
||||||
|
|
||||||
Finally, we evaluate the exit value of the loop, to determine whether
|
Finally, we evaluate the exit value of the loop, to determine whether
|
||||||
the loop should exit. This mirrors the condition evaluation for the
|
the loop should exit. This mirrors the condition evaluation for the
|
||||||
@ -723,7 +723,7 @@ if/then/else statement.
|
|||||||
// Create the "after loop" block and insert it.
|
// Create the "after loop" block and insert it.
|
||||||
BasicBlock *LoopEndBB = Builder.GetInsertBlock();
|
BasicBlock *LoopEndBB = Builder.GetInsertBlock();
|
||||||
BasicBlock *AfterBB =
|
BasicBlock *AfterBB =
|
||||||
BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
|
BasicBlock::Create(LLVMContext, "afterloop", TheFunction);
|
||||||
|
|
||||||
// Insert the conditional branch into the end of LoopEndBB.
|
// Insert the conditional branch into the end of LoopEndBB.
|
||||||
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
|
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
|
||||||
@ -751,7 +751,7 @@ insertion position to it.
|
|||||||
NamedValues.erase(VarName);
|
NamedValues.erase(VarName);
|
||||||
|
|
||||||
// for expr always returns 0.0.
|
// for expr always returns 0.0.
|
||||||
return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
|
return Constant::getNullValue(Type::getDoubleTy(LLVMContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
The final code handles various cleanups: now that we have the "NextVar"
|
The final code handles various cleanups: now that we have the "NextVar"
|
||||||
|
@ -251,7 +251,7 @@ default case for our existing binary operator node:
|
|||||||
case '<':
|
case '<':
|
||||||
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
|
return Builder.CreateUIToFP(L, Type::getDoubleTy(LLVMContext),
|
||||||
"booltmp");
|
"booltmp");
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -288,7 +288,7 @@ The final piece of code we are missing, is a bit of top-level magic:
|
|||||||
BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
|
BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
|
||||||
|
|
||||||
// Create a new basic block to start insertion into.
|
// Create a new basic block to start insertion into.
|
||||||
BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
|
BasicBlock *BB = BasicBlock::Create(LLVMContext, "entry", TheFunction);
|
||||||
Builder.SetInsertPoint(BB);
|
Builder.SetInsertPoint(BB);
|
||||||
|
|
||||||
if (Value *RetVal = Body->codegen()) {
|
if (Value *RetVal = Body->codegen()) {
|
||||||
|
@ -339,7 +339,7 @@ the function:
|
|||||||
const std::string &VarName) {
|
const std::string &VarName) {
|
||||||
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
||||||
TheFunction->getEntryBlock().begin());
|
TheFunction->getEntryBlock().begin());
|
||||||
return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), 0,
|
return TmpB.CreateAlloca(Type::getDoubleTy(LLVMContext), 0,
|
||||||
VarName.c_str());
|
VarName.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -812,7 +812,7 @@ previous value that we replace in OldBindings.
|
|||||||
if (!InitVal)
|
if (!InitVal)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
} else { // If not specified, use 0.0.
|
} else { // If not specified, use 0.0.
|
||||||
InitVal = ConstantFP::get(getGlobalContext(), APFloat(0.0));
|
InitVal = ConstantFP::get(LLVMContext, APFloat(0.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
|
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
|
||||||
|
@ -88,7 +88,7 @@ void addMainFunction(Module *mod) {
|
|||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
cl::ParseCommandLineOptions(argc, argv, " BrainF compiler\n");
|
cl::ParseCommandLineOptions(argc, argv, " BrainF compiler\n");
|
||||||
|
|
||||||
LLVMContext &Context = getGlobalContext();
|
LLVMContext Context;
|
||||||
|
|
||||||
if (InputFilename == "") {
|
if (InputFilename == "") {
|
||||||
errs() << "Error: You must specify the filename of the program to "
|
errs() << "Error: You must specify the filename of the program to "
|
||||||
|
@ -1951,12 +1951,12 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
llvm::InitializeNativeTarget();
|
llvm::InitializeNativeTarget();
|
||||||
llvm::InitializeNativeTargetAsmPrinter();
|
llvm::InitializeNativeTargetAsmPrinter();
|
||||||
llvm::LLVMContext &context = llvm::getGlobalContext();
|
llvm::LLVMContext Context;
|
||||||
llvm::IRBuilder<> theBuilder(context);
|
llvm::IRBuilder<> theBuilder(Context);
|
||||||
|
|
||||||
// Make the module, which holds all the code.
|
// Make the module, which holds all the code.
|
||||||
std::unique_ptr<llvm::Module> Owner =
|
std::unique_ptr<llvm::Module> Owner =
|
||||||
llvm::make_unique<llvm::Module>("my cool jit", context);
|
llvm::make_unique<llvm::Module>("my cool jit", Context);
|
||||||
llvm::Module *module = Owner.get();
|
llvm::Module *module = Owner.get();
|
||||||
|
|
||||||
std::unique_ptr<llvm::RTDyldMemoryManager> MemMgr(new llvm::SectionMemoryManager());
|
std::unique_ptr<llvm::RTDyldMemoryManager> MemMgr(new llvm::SectionMemoryManager());
|
||||||
|
@ -381,7 +381,8 @@ static std::unique_ptr<PrototypeAST> ParseExtern() {
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
static std::unique_ptr<Module> TheModule;
|
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::map<std::string, Value *> NamedValues;
|
||||||
|
|
||||||
Value *LogErrorV(const char *Str) {
|
Value *LogErrorV(const char *Str) {
|
||||||
@ -390,7 +391,7 @@ Value *LogErrorV(const char *Str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Value *NumberExprAST::codegen() {
|
Value *NumberExprAST::codegen() {
|
||||||
return ConstantFP::get(getGlobalContext(), APFloat(Val));
|
return ConstantFP::get(TheContext, APFloat(Val));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VariableExprAST::codegen() {
|
Value *VariableExprAST::codegen() {
|
||||||
@ -417,8 +418,7 @@ Value *BinaryExprAST::codegen() {
|
|||||||
case '<':
|
case '<':
|
||||||
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
|
return Builder.CreateUIToFP(L, Type::getDoubleTy(TheContext), "booltmp");
|
||||||
"booltmp");
|
|
||||||
default:
|
default:
|
||||||
return LogErrorV("invalid binary operator");
|
return LogErrorV("invalid binary operator");
|
||||||
}
|
}
|
||||||
@ -446,10 +446,9 @@ Value *CallExprAST::codegen() {
|
|||||||
|
|
||||||
Function *PrototypeAST::codegen() {
|
Function *PrototypeAST::codegen() {
|
||||||
// Make the function type: double(double,double) etc.
|
// Make the function type: double(double,double) etc.
|
||||||
std::vector<Type *> Doubles(Args.size(),
|
std::vector<Type *> Doubles(Args.size(), Type::getDoubleTy(TheContext));
|
||||||
Type::getDoubleTy(getGlobalContext()));
|
|
||||||
FunctionType *FT =
|
FunctionType *FT =
|
||||||
FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);
|
FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);
|
||||||
|
|
||||||
Function *F =
|
Function *F =
|
||||||
Function::Create(FT, Function::ExternalLinkage, Name, TheModule.get());
|
Function::Create(FT, Function::ExternalLinkage, Name, TheModule.get());
|
||||||
@ -473,7 +472,7 @@ Function *FunctionAST::codegen() {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
// Create a new basic block to start insertion into.
|
// 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);
|
Builder.SetInsertPoint(BB);
|
||||||
|
|
||||||
// Record the function arguments in the NamedValues map.
|
// Record the function arguments in the NamedValues map.
|
||||||
@ -577,7 +576,7 @@ int main() {
|
|||||||
getNextToken();
|
getNextToken();
|
||||||
|
|
||||||
// Make the module, which holds all the code.
|
// 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.
|
// Run the main "interpreter loop" now.
|
||||||
MainLoop();
|
MainLoop();
|
||||||
|
@ -388,7 +388,8 @@ static std::unique_ptr<PrototypeAST> ParseExtern() {
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
static std::unique_ptr<Module> TheModule;
|
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::map<std::string, Value *> NamedValues;
|
||||||
static std::unique_ptr<legacy::FunctionPassManager> TheFPM;
|
static std::unique_ptr<legacy::FunctionPassManager> TheFPM;
|
||||||
static std::unique_ptr<KaleidoscopeJIT> TheJIT;
|
static std::unique_ptr<KaleidoscopeJIT> TheJIT;
|
||||||
@ -415,7 +416,7 @@ Function *getFunction(std::string Name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Value *NumberExprAST::codegen() {
|
Value *NumberExprAST::codegen() {
|
||||||
return ConstantFP::get(getGlobalContext(), APFloat(Val));
|
return ConstantFP::get(TheContext, APFloat(Val));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VariableExprAST::codegen() {
|
Value *VariableExprAST::codegen() {
|
||||||
@ -442,8 +443,7 @@ Value *BinaryExprAST::codegen() {
|
|||||||
case '<':
|
case '<':
|
||||||
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
|
return Builder.CreateUIToFP(L, Type::getDoubleTy(TheContext), "booltmp");
|
||||||
"booltmp");
|
|
||||||
default:
|
default:
|
||||||
return LogErrorV("invalid binary operator");
|
return LogErrorV("invalid binary operator");
|
||||||
}
|
}
|
||||||
@ -471,10 +471,9 @@ Value *CallExprAST::codegen() {
|
|||||||
|
|
||||||
Function *PrototypeAST::codegen() {
|
Function *PrototypeAST::codegen() {
|
||||||
// Make the function type: double(double,double) etc.
|
// Make the function type: double(double,double) etc.
|
||||||
std::vector<Type *> Doubles(Args.size(),
|
std::vector<Type *> Doubles(Args.size(), Type::getDoubleTy(TheContext));
|
||||||
Type::getDoubleTy(getGlobalContext()));
|
|
||||||
FunctionType *FT =
|
FunctionType *FT =
|
||||||
FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);
|
FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);
|
||||||
|
|
||||||
Function *F =
|
Function *F =
|
||||||
Function::Create(FT, Function::ExternalLinkage, Name, TheModule.get());
|
Function::Create(FT, Function::ExternalLinkage, Name, TheModule.get());
|
||||||
@ -497,7 +496,7 @@ Function *FunctionAST::codegen() {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
// Create a new basic block to start insertion into.
|
// 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);
|
Builder.SetInsertPoint(BB);
|
||||||
|
|
||||||
// Record the function arguments in the NamedValues map.
|
// Record the function arguments in the NamedValues map.
|
||||||
@ -529,7 +528,7 @@ Function *FunctionAST::codegen() {
|
|||||||
|
|
||||||
static void InitializeModuleAndPassManager() {
|
static void InitializeModuleAndPassManager() {
|
||||||
// Open a new module.
|
// 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());
|
TheModule->setDataLayout(TheJIT->getTargetMachine().createDataLayout());
|
||||||
|
|
||||||
// Create a new pass manager attached to it.
|
// Create a new pass manager attached to it.
|
||||||
|
@ -512,7 +512,8 @@ static std::unique_ptr<PrototypeAST> ParseExtern() {
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
static std::unique_ptr<Module> TheModule;
|
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::map<std::string, Value *> NamedValues;
|
||||||
static std::unique_ptr<legacy::FunctionPassManager> TheFPM;
|
static std::unique_ptr<legacy::FunctionPassManager> TheFPM;
|
||||||
static std::unique_ptr<KaleidoscopeJIT> TheJIT;
|
static std::unique_ptr<KaleidoscopeJIT> TheJIT;
|
||||||
@ -539,7 +540,7 @@ Function *getFunction(std::string Name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Value *NumberExprAST::codegen() {
|
Value *NumberExprAST::codegen() {
|
||||||
return ConstantFP::get(getGlobalContext(), APFloat(Val));
|
return ConstantFP::get(TheContext, APFloat(Val));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VariableExprAST::codegen() {
|
Value *VariableExprAST::codegen() {
|
||||||
@ -566,8 +567,7 @@ Value *BinaryExprAST::codegen() {
|
|||||||
case '<':
|
case '<':
|
||||||
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
|
return Builder.CreateUIToFP(L, Type::getDoubleTy(TheContext), "booltmp");
|
||||||
"booltmp");
|
|
||||||
default:
|
default:
|
||||||
return LogErrorV("invalid binary operator");
|
return LogErrorV("invalid binary operator");
|
||||||
}
|
}
|
||||||
@ -600,16 +600,15 @@ Value *IfExprAST::codegen() {
|
|||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
CondV = Builder.CreateFCmpONE(
|
CondV = Builder.CreateFCmpONE(
|
||||||
CondV, ConstantFP::get(getGlobalContext(), APFloat(0.0)), "ifcond");
|
CondV, ConstantFP::get(TheContext, APFloat(0.0)), "ifcond");
|
||||||
|
|
||||||
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
||||||
|
|
||||||
// Create blocks for the then and else cases. Insert the 'then' block at the
|
// Create blocks for the then and else cases. Insert the 'then' block at the
|
||||||
// end of the function.
|
// end of the function.
|
||||||
BasicBlock *ThenBB =
|
BasicBlock *ThenBB = BasicBlock::Create(TheContext, "then", TheFunction);
|
||||||
BasicBlock::Create(getGlobalContext(), "then", TheFunction);
|
BasicBlock *ElseBB = BasicBlock::Create(TheContext, "else");
|
||||||
BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
|
BasicBlock *MergeBB = BasicBlock::Create(TheContext, "ifcont");
|
||||||
BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
|
|
||||||
|
|
||||||
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
|
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
|
||||||
|
|
||||||
@ -639,8 +638,7 @@ Value *IfExprAST::codegen() {
|
|||||||
// Emit merge block.
|
// Emit merge block.
|
||||||
TheFunction->getBasicBlockList().push_back(MergeBB);
|
TheFunction->getBasicBlockList().push_back(MergeBB);
|
||||||
Builder.SetInsertPoint(MergeBB);
|
Builder.SetInsertPoint(MergeBB);
|
||||||
PHINode *PN =
|
PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
|
||||||
Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2, "iftmp");
|
|
||||||
|
|
||||||
PN->addIncoming(ThenV, ThenBB);
|
PN->addIncoming(ThenV, ThenBB);
|
||||||
PN->addIncoming(ElseV, ElseBB);
|
PN->addIncoming(ElseV, ElseBB);
|
||||||
@ -672,8 +670,7 @@ Value *ForExprAST::codegen() {
|
|||||||
// block.
|
// block.
|
||||||
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
||||||
BasicBlock *PreheaderBB = Builder.GetInsertBlock();
|
BasicBlock *PreheaderBB = Builder.GetInsertBlock();
|
||||||
BasicBlock *LoopBB =
|
BasicBlock *LoopBB = BasicBlock::Create(TheContext, "loop", TheFunction);
|
||||||
BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
|
|
||||||
|
|
||||||
// Insert an explicit fall through from the current block to the LoopBB.
|
// Insert an explicit fall through from the current block to the LoopBB.
|
||||||
Builder.CreateBr(LoopBB);
|
Builder.CreateBr(LoopBB);
|
||||||
@ -682,8 +679,8 @@ Value *ForExprAST::codegen() {
|
|||||||
Builder.SetInsertPoint(LoopBB);
|
Builder.SetInsertPoint(LoopBB);
|
||||||
|
|
||||||
// Start the PHI node with an entry for Start.
|
// Start the PHI node with an entry for Start.
|
||||||
PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()),
|
PHINode *Variable =
|
||||||
2, VarName.c_str());
|
Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, VarName.c_str());
|
||||||
Variable->addIncoming(StartVal, PreheaderBB);
|
Variable->addIncoming(StartVal, PreheaderBB);
|
||||||
|
|
||||||
// Within the loop, the variable is defined equal to the PHI node. If it
|
// Within the loop, the variable is defined equal to the PHI node. If it
|
||||||
@ -705,7 +702,7 @@ Value *ForExprAST::codegen() {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
} else {
|
} else {
|
||||||
// If not specified, use 1.0.
|
// 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");
|
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.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
EndCond = Builder.CreateFCmpONE(
|
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.
|
// Create the "after loop" block and insert it.
|
||||||
BasicBlock *LoopEndBB = Builder.GetInsertBlock();
|
BasicBlock *LoopEndBB = Builder.GetInsertBlock();
|
||||||
BasicBlock *AfterBB =
|
BasicBlock *AfterBB =
|
||||||
BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
|
BasicBlock::Create(TheContext, "afterloop", TheFunction);
|
||||||
|
|
||||||
// Insert the conditional branch into the end of LoopEndBB.
|
// Insert the conditional branch into the end of LoopEndBB.
|
||||||
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
|
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
|
||||||
@ -740,15 +737,14 @@ Value *ForExprAST::codegen() {
|
|||||||
NamedValues.erase(VarName);
|
NamedValues.erase(VarName);
|
||||||
|
|
||||||
// for expr always returns 0.0.
|
// for expr always returns 0.0.
|
||||||
return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
|
return Constant::getNullValue(Type::getDoubleTy(TheContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
Function *PrototypeAST::codegen() {
|
Function *PrototypeAST::codegen() {
|
||||||
// Make the function type: double(double,double) etc.
|
// Make the function type: double(double,double) etc.
|
||||||
std::vector<Type *> Doubles(Args.size(),
|
std::vector<Type *> Doubles(Args.size(), Type::getDoubleTy(TheContext));
|
||||||
Type::getDoubleTy(getGlobalContext()));
|
|
||||||
FunctionType *FT =
|
FunctionType *FT =
|
||||||
FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);
|
FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);
|
||||||
|
|
||||||
Function *F =
|
Function *F =
|
||||||
Function::Create(FT, Function::ExternalLinkage, Name, TheModule.get());
|
Function::Create(FT, Function::ExternalLinkage, Name, TheModule.get());
|
||||||
@ -771,7 +767,7 @@ Function *FunctionAST::codegen() {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
// Create a new basic block to start insertion into.
|
// 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);
|
Builder.SetInsertPoint(BB);
|
||||||
|
|
||||||
// Record the function arguments in the NamedValues map.
|
// Record the function arguments in the NamedValues map.
|
||||||
@ -803,7 +799,7 @@ Function *FunctionAST::codegen() {
|
|||||||
|
|
||||||
static void InitializeModuleAndPassManager() {
|
static void InitializeModuleAndPassManager() {
|
||||||
// Open a new module.
|
// 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());
|
TheModule->setDataLayout(TheJIT->getTargetMachine().createDataLayout());
|
||||||
|
|
||||||
// Create a new pass manager attached to it.
|
// Create a new pass manager attached to it.
|
||||||
|
@ -603,7 +603,8 @@ static std::unique_ptr<PrototypeAST> ParseExtern() {
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
static std::unique_ptr<Module> TheModule;
|
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::map<std::string, Value *> NamedValues;
|
||||||
static std::unique_ptr<legacy::FunctionPassManager> TheFPM;
|
static std::unique_ptr<legacy::FunctionPassManager> TheFPM;
|
||||||
static std::unique_ptr<KaleidoscopeJIT> TheJIT;
|
static std::unique_ptr<KaleidoscopeJIT> TheJIT;
|
||||||
@ -630,7 +631,7 @@ Function *getFunction(std::string Name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Value *NumberExprAST::codegen() {
|
Value *NumberExprAST::codegen() {
|
||||||
return ConstantFP::get(getGlobalContext(), APFloat(Val));
|
return ConstantFP::get(TheContext, APFloat(Val));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VariableExprAST::codegen() {
|
Value *VariableExprAST::codegen() {
|
||||||
@ -669,8 +670,7 @@ Value *BinaryExprAST::codegen() {
|
|||||||
case '<':
|
case '<':
|
||||||
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
|
return Builder.CreateUIToFP(L, Type::getDoubleTy(TheContext), "booltmp");
|
||||||
"booltmp");
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -711,16 +711,15 @@ Value *IfExprAST::codegen() {
|
|||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
CondV = Builder.CreateFCmpONE(
|
CondV = Builder.CreateFCmpONE(
|
||||||
CondV, ConstantFP::get(getGlobalContext(), APFloat(0.0)), "ifcond");
|
CondV, ConstantFP::get(TheContext, APFloat(0.0)), "ifcond");
|
||||||
|
|
||||||
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
||||||
|
|
||||||
// Create blocks for the then and else cases. Insert the 'then' block at the
|
// Create blocks for the then and else cases. Insert the 'then' block at the
|
||||||
// end of the function.
|
// end of the function.
|
||||||
BasicBlock *ThenBB =
|
BasicBlock *ThenBB = BasicBlock::Create(TheContext, "then", TheFunction);
|
||||||
BasicBlock::Create(getGlobalContext(), "then", TheFunction);
|
BasicBlock *ElseBB = BasicBlock::Create(TheContext, "else");
|
||||||
BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
|
BasicBlock *MergeBB = BasicBlock::Create(TheContext, "ifcont");
|
||||||
BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
|
|
||||||
|
|
||||||
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
|
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
|
||||||
|
|
||||||
@ -750,8 +749,7 @@ Value *IfExprAST::codegen() {
|
|||||||
// Emit merge block.
|
// Emit merge block.
|
||||||
TheFunction->getBasicBlockList().push_back(MergeBB);
|
TheFunction->getBasicBlockList().push_back(MergeBB);
|
||||||
Builder.SetInsertPoint(MergeBB);
|
Builder.SetInsertPoint(MergeBB);
|
||||||
PHINode *PN =
|
PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
|
||||||
Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2, "iftmp");
|
|
||||||
|
|
||||||
PN->addIncoming(ThenV, ThenBB);
|
PN->addIncoming(ThenV, ThenBB);
|
||||||
PN->addIncoming(ElseV, ElseBB);
|
PN->addIncoming(ElseV, ElseBB);
|
||||||
@ -783,8 +781,7 @@ Value *ForExprAST::codegen() {
|
|||||||
// block.
|
// block.
|
||||||
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
||||||
BasicBlock *PreheaderBB = Builder.GetInsertBlock();
|
BasicBlock *PreheaderBB = Builder.GetInsertBlock();
|
||||||
BasicBlock *LoopBB =
|
BasicBlock *LoopBB = BasicBlock::Create(TheContext, "loop", TheFunction);
|
||||||
BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
|
|
||||||
|
|
||||||
// Insert an explicit fall through from the current block to the LoopBB.
|
// Insert an explicit fall through from the current block to the LoopBB.
|
||||||
Builder.CreateBr(LoopBB);
|
Builder.CreateBr(LoopBB);
|
||||||
@ -793,8 +790,8 @@ Value *ForExprAST::codegen() {
|
|||||||
Builder.SetInsertPoint(LoopBB);
|
Builder.SetInsertPoint(LoopBB);
|
||||||
|
|
||||||
// Start the PHI node with an entry for Start.
|
// Start the PHI node with an entry for Start.
|
||||||
PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()),
|
PHINode *Variable =
|
||||||
2, VarName.c_str());
|
Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, VarName.c_str());
|
||||||
Variable->addIncoming(StartVal, PreheaderBB);
|
Variable->addIncoming(StartVal, PreheaderBB);
|
||||||
|
|
||||||
// Within the loop, the variable is defined equal to the PHI node. If it
|
// Within the loop, the variable is defined equal to the PHI node. If it
|
||||||
@ -816,7 +813,7 @@ Value *ForExprAST::codegen() {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
} else {
|
} else {
|
||||||
// If not specified, use 1.0.
|
// 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");
|
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.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
EndCond = Builder.CreateFCmpONE(
|
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.
|
// Create the "after loop" block and insert it.
|
||||||
BasicBlock *LoopEndBB = Builder.GetInsertBlock();
|
BasicBlock *LoopEndBB = Builder.GetInsertBlock();
|
||||||
BasicBlock *AfterBB =
|
BasicBlock *AfterBB =
|
||||||
BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
|
BasicBlock::Create(TheContext, "afterloop", TheFunction);
|
||||||
|
|
||||||
// Insert the conditional branch into the end of LoopEndBB.
|
// Insert the conditional branch into the end of LoopEndBB.
|
||||||
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
|
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
|
||||||
@ -851,15 +848,14 @@ Value *ForExprAST::codegen() {
|
|||||||
NamedValues.erase(VarName);
|
NamedValues.erase(VarName);
|
||||||
|
|
||||||
// for expr always returns 0.0.
|
// for expr always returns 0.0.
|
||||||
return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
|
return Constant::getNullValue(Type::getDoubleTy(TheContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
Function *PrototypeAST::codegen() {
|
Function *PrototypeAST::codegen() {
|
||||||
// Make the function type: double(double,double) etc.
|
// Make the function type: double(double,double) etc.
|
||||||
std::vector<Type *> Doubles(Args.size(),
|
std::vector<Type *> Doubles(Args.size(), Type::getDoubleTy(TheContext));
|
||||||
Type::getDoubleTy(getGlobalContext()));
|
|
||||||
FunctionType *FT =
|
FunctionType *FT =
|
||||||
FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);
|
FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);
|
||||||
|
|
||||||
Function *F =
|
Function *F =
|
||||||
Function::Create(FT, Function::ExternalLinkage, Name, TheModule.get());
|
Function::Create(FT, Function::ExternalLinkage, Name, TheModule.get());
|
||||||
@ -886,7 +882,7 @@ Function *FunctionAST::codegen() {
|
|||||||
BinopPrecedence[P.getOperatorName()] = P.getBinaryPrecedence();
|
BinopPrecedence[P.getOperatorName()] = P.getBinaryPrecedence();
|
||||||
|
|
||||||
// Create a new basic block to start insertion into.
|
// 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);
|
Builder.SetInsertPoint(BB);
|
||||||
|
|
||||||
// Record the function arguments in the NamedValues map.
|
// Record the function arguments in the NamedValues map.
|
||||||
@ -921,7 +917,7 @@ Function *FunctionAST::codegen() {
|
|||||||
|
|
||||||
static void InitializeModuleAndPassManager() {
|
static void InitializeModuleAndPassManager() {
|
||||||
// Open a new module.
|
// 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());
|
TheModule->setDataLayout(TheJIT->getTargetMachine().createDataLayout());
|
||||||
|
|
||||||
// Create a new pass manager attached to it.
|
// Create a new pass manager attached to it.
|
||||||
|
@ -673,7 +673,8 @@ static std::unique_ptr<PrototypeAST> ParseExtern() {
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
static std::unique_ptr<Module> TheModule;
|
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::map<std::string, AllocaInst *> NamedValues;
|
||||||
static std::unique_ptr<legacy::FunctionPassManager> TheFPM;
|
static std::unique_ptr<legacy::FunctionPassManager> TheFPM;
|
||||||
static std::unique_ptr<KaleidoscopeJIT> TheJIT;
|
static std::unique_ptr<KaleidoscopeJIT> TheJIT;
|
||||||
@ -705,12 +706,12 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
|
|||||||
const std::string &VarName) {
|
const std::string &VarName) {
|
||||||
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
||||||
TheFunction->getEntryBlock().begin());
|
TheFunction->getEntryBlock().begin());
|
||||||
return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), nullptr,
|
return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), nullptr,
|
||||||
VarName.c_str());
|
VarName.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *NumberExprAST::codegen() {
|
Value *NumberExprAST::codegen() {
|
||||||
return ConstantFP::get(getGlobalContext(), APFloat(Val));
|
return ConstantFP::get(TheContext, APFloat(Val));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VariableExprAST::codegen() {
|
Value *VariableExprAST::codegen() {
|
||||||
@ -774,8 +775,7 @@ Value *BinaryExprAST::codegen() {
|
|||||||
case '<':
|
case '<':
|
||||||
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
|
return Builder.CreateUIToFP(L, Type::getDoubleTy(TheContext), "booltmp");
|
||||||
"booltmp");
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -816,16 +816,15 @@ Value *IfExprAST::codegen() {
|
|||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
CondV = Builder.CreateFCmpONE(
|
CondV = Builder.CreateFCmpONE(
|
||||||
CondV, ConstantFP::get(getGlobalContext(), APFloat(0.0)), "ifcond");
|
CondV, ConstantFP::get(TheContext, APFloat(0.0)), "ifcond");
|
||||||
|
|
||||||
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
||||||
|
|
||||||
// Create blocks for the then and else cases. Insert the 'then' block at the
|
// Create blocks for the then and else cases. Insert the 'then' block at the
|
||||||
// end of the function.
|
// end of the function.
|
||||||
BasicBlock *ThenBB =
|
BasicBlock *ThenBB = BasicBlock::Create(TheContext, "then", TheFunction);
|
||||||
BasicBlock::Create(getGlobalContext(), "then", TheFunction);
|
BasicBlock *ElseBB = BasicBlock::Create(TheContext, "else");
|
||||||
BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
|
BasicBlock *MergeBB = BasicBlock::Create(TheContext, "ifcont");
|
||||||
BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
|
|
||||||
|
|
||||||
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
|
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
|
||||||
|
|
||||||
@ -855,8 +854,7 @@ Value *IfExprAST::codegen() {
|
|||||||
// Emit merge block.
|
// Emit merge block.
|
||||||
TheFunction->getBasicBlockList().push_back(MergeBB);
|
TheFunction->getBasicBlockList().push_back(MergeBB);
|
||||||
Builder.SetInsertPoint(MergeBB);
|
Builder.SetInsertPoint(MergeBB);
|
||||||
PHINode *PN =
|
PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
|
||||||
Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2, "iftmp");
|
|
||||||
|
|
||||||
PN->addIncoming(ThenV, ThenBB);
|
PN->addIncoming(ThenV, ThenBB);
|
||||||
PN->addIncoming(ElseV, ElseBB);
|
PN->addIncoming(ElseV, ElseBB);
|
||||||
@ -898,8 +896,7 @@ Value *ForExprAST::codegen() {
|
|||||||
|
|
||||||
// Make the new basic block for the loop header, inserting after current
|
// Make the new basic block for the loop header, inserting after current
|
||||||
// block.
|
// block.
|
||||||
BasicBlock *LoopBB =
|
BasicBlock *LoopBB = BasicBlock::Create(TheContext, "loop", TheFunction);
|
||||||
BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
|
|
||||||
|
|
||||||
// Insert an explicit fall through from the current block to the LoopBB.
|
// Insert an explicit fall through from the current block to the LoopBB.
|
||||||
Builder.CreateBr(LoopBB);
|
Builder.CreateBr(LoopBB);
|
||||||
@ -926,7 +923,7 @@ Value *ForExprAST::codegen() {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
} else {
|
} else {
|
||||||
// If not specified, use 1.0.
|
// If not specified, use 1.0.
|
||||||
StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
|
StepVal = ConstantFP::get(TheContext, APFloat(1.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the end condition.
|
// Compute the end condition.
|
||||||
@ -942,11 +939,11 @@ Value *ForExprAST::codegen() {
|
|||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
EndCond = Builder.CreateFCmpONE(
|
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.
|
// Create the "after loop" block and insert it.
|
||||||
BasicBlock *AfterBB =
|
BasicBlock *AfterBB =
|
||||||
BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
|
BasicBlock::Create(TheContext, "afterloop", TheFunction);
|
||||||
|
|
||||||
// Insert the conditional branch into the end of LoopEndBB.
|
// Insert the conditional branch into the end of LoopEndBB.
|
||||||
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
|
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
|
||||||
@ -961,7 +958,7 @@ Value *ForExprAST::codegen() {
|
|||||||
NamedValues.erase(VarName);
|
NamedValues.erase(VarName);
|
||||||
|
|
||||||
// for expr always returns 0.0.
|
// for expr always returns 0.0.
|
||||||
return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
|
return Constant::getNullValue(Type::getDoubleTy(TheContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VarExprAST::codegen() {
|
Value *VarExprAST::codegen() {
|
||||||
@ -985,7 +982,7 @@ Value *VarExprAST::codegen() {
|
|||||||
if (!InitVal)
|
if (!InitVal)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
} else { // If not specified, use 0.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);
|
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
|
||||||
@ -1014,10 +1011,9 @@ Value *VarExprAST::codegen() {
|
|||||||
|
|
||||||
Function *PrototypeAST::codegen() {
|
Function *PrototypeAST::codegen() {
|
||||||
// Make the function type: double(double,double) etc.
|
// Make the function type: double(double,double) etc.
|
||||||
std::vector<Type *> Doubles(Args.size(),
|
std::vector<Type *> Doubles(Args.size(), Type::getDoubleTy(TheContext));
|
||||||
Type::getDoubleTy(getGlobalContext()));
|
|
||||||
FunctionType *FT =
|
FunctionType *FT =
|
||||||
FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);
|
FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);
|
||||||
|
|
||||||
Function *F =
|
Function *F =
|
||||||
Function::Create(FT, Function::ExternalLinkage, Name, TheModule.get());
|
Function::Create(FT, Function::ExternalLinkage, Name, TheModule.get());
|
||||||
@ -1044,7 +1040,7 @@ Function *FunctionAST::codegen() {
|
|||||||
BinopPrecedence[P.getOperatorName()] = P.getBinaryPrecedence();
|
BinopPrecedence[P.getOperatorName()] = P.getBinaryPrecedence();
|
||||||
|
|
||||||
// Create a new basic block to start insertion into.
|
// 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);
|
Builder.SetInsertPoint(BB);
|
||||||
|
|
||||||
// Record the function arguments in the NamedValues map.
|
// Record the function arguments in the NamedValues map.
|
||||||
@ -1087,7 +1083,7 @@ Function *FunctionAST::codegen() {
|
|||||||
|
|
||||||
static void InitializeModuleAndPassManager() {
|
static void InitializeModuleAndPassManager() {
|
||||||
// Open a new module.
|
// 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());
|
TheModule->setDataLayout(TheJIT->getTargetMachine().createDataLayout());
|
||||||
|
|
||||||
// Create a new pass manager attached to it.
|
// Create a new pass manager attached to it.
|
||||||
|
@ -87,7 +87,8 @@ namespace {
|
|||||||
class PrototypeAST;
|
class PrototypeAST;
|
||||||
class ExprAST;
|
class ExprAST;
|
||||||
}
|
}
|
||||||
static IRBuilder<> Builder(getGlobalContext());
|
static LLVMContext TheContext;
|
||||||
|
static IRBuilder<> Builder(TheContext);
|
||||||
struct DebugInfo {
|
struct DebugInfo {
|
||||||
DICompileUnit *TheCU;
|
DICompileUnit *TheCU;
|
||||||
DIType *DblTy;
|
DIType *DblTy;
|
||||||
@ -886,13 +887,13 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
|
|||||||
const std::string &VarName) {
|
const std::string &VarName) {
|
||||||
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
||||||
TheFunction->getEntryBlock().begin());
|
TheFunction->getEntryBlock().begin());
|
||||||
return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), nullptr,
|
return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), nullptr,
|
||||||
VarName.c_str());
|
VarName.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *NumberExprAST::codegen() {
|
Value *NumberExprAST::codegen() {
|
||||||
KSDbgInfo.emitLocation(this);
|
KSDbgInfo.emitLocation(this);
|
||||||
return ConstantFP::get(getGlobalContext(), APFloat(Val));
|
return ConstantFP::get(TheContext, APFloat(Val));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VariableExprAST::codegen() {
|
Value *VariableExprAST::codegen() {
|
||||||
@ -960,8 +961,7 @@ Value *BinaryExprAST::codegen() {
|
|||||||
case '<':
|
case '<':
|
||||||
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
|
return Builder.CreateUIToFP(L, Type::getDoubleTy(TheContext), "booltmp");
|
||||||
"booltmp");
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1006,16 +1006,15 @@ Value *IfExprAST::codegen() {
|
|||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
CondV = Builder.CreateFCmpONE(
|
CondV = Builder.CreateFCmpONE(
|
||||||
CondV, ConstantFP::get(getGlobalContext(), APFloat(0.0)), "ifcond");
|
CondV, ConstantFP::get(TheContext, APFloat(0.0)), "ifcond");
|
||||||
|
|
||||||
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
||||||
|
|
||||||
// Create blocks for the then and else cases. Insert the 'then' block at the
|
// Create blocks for the then and else cases. Insert the 'then' block at the
|
||||||
// end of the function.
|
// end of the function.
|
||||||
BasicBlock *ThenBB =
|
BasicBlock *ThenBB = BasicBlock::Create(TheContext, "then", TheFunction);
|
||||||
BasicBlock::Create(getGlobalContext(), "then", TheFunction);
|
BasicBlock *ElseBB = BasicBlock::Create(TheContext, "else");
|
||||||
BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
|
BasicBlock *MergeBB = BasicBlock::Create(TheContext, "ifcont");
|
||||||
BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
|
|
||||||
|
|
||||||
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
|
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
|
||||||
|
|
||||||
@ -1045,8 +1044,7 @@ Value *IfExprAST::codegen() {
|
|||||||
// Emit merge block.
|
// Emit merge block.
|
||||||
TheFunction->getBasicBlockList().push_back(MergeBB);
|
TheFunction->getBasicBlockList().push_back(MergeBB);
|
||||||
Builder.SetInsertPoint(MergeBB);
|
Builder.SetInsertPoint(MergeBB);
|
||||||
PHINode *PN =
|
PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
|
||||||
Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2, "iftmp");
|
|
||||||
|
|
||||||
PN->addIncoming(ThenV, ThenBB);
|
PN->addIncoming(ThenV, ThenBB);
|
||||||
PN->addIncoming(ElseV, ElseBB);
|
PN->addIncoming(ElseV, ElseBB);
|
||||||
@ -1090,8 +1088,7 @@ Value *ForExprAST::codegen() {
|
|||||||
|
|
||||||
// Make the new basic block for the loop header, inserting after current
|
// Make the new basic block for the loop header, inserting after current
|
||||||
// block.
|
// block.
|
||||||
BasicBlock *LoopBB =
|
BasicBlock *LoopBB = BasicBlock::Create(TheContext, "loop", TheFunction);
|
||||||
BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
|
|
||||||
|
|
||||||
// Insert an explicit fall through from the current block to the LoopBB.
|
// Insert an explicit fall through from the current block to the LoopBB.
|
||||||
Builder.CreateBr(LoopBB);
|
Builder.CreateBr(LoopBB);
|
||||||
@ -1118,7 +1115,7 @@ Value *ForExprAST::codegen() {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
} else {
|
} else {
|
||||||
// If not specified, use 1.0.
|
// If not specified, use 1.0.
|
||||||
StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
|
StepVal = ConstantFP::get(TheContext, APFloat(1.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the end condition.
|
// Compute the end condition.
|
||||||
@ -1134,11 +1131,11 @@ Value *ForExprAST::codegen() {
|
|||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
EndCond = Builder.CreateFCmpONE(
|
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.
|
// Create the "after loop" block and insert it.
|
||||||
BasicBlock *AfterBB =
|
BasicBlock *AfterBB =
|
||||||
BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
|
BasicBlock::Create(TheContext, "afterloop", TheFunction);
|
||||||
|
|
||||||
// Insert the conditional branch into the end of LoopEndBB.
|
// Insert the conditional branch into the end of LoopEndBB.
|
||||||
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
|
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
|
||||||
@ -1153,7 +1150,7 @@ Value *ForExprAST::codegen() {
|
|||||||
NamedValues.erase(VarName);
|
NamedValues.erase(VarName);
|
||||||
|
|
||||||
// for expr always returns 0.0.
|
// for expr always returns 0.0.
|
||||||
return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
|
return Constant::getNullValue(Type::getDoubleTy(TheContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VarExprAST::codegen() {
|
Value *VarExprAST::codegen() {
|
||||||
@ -1177,7 +1174,7 @@ Value *VarExprAST::codegen() {
|
|||||||
if (!InitVal)
|
if (!InitVal)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
} else { // If not specified, use 0.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);
|
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
|
||||||
@ -1208,10 +1205,9 @@ Value *VarExprAST::codegen() {
|
|||||||
|
|
||||||
Function *PrototypeAST::codegen() {
|
Function *PrototypeAST::codegen() {
|
||||||
// Make the function type: double(double,double) etc.
|
// Make the function type: double(double,double) etc.
|
||||||
std::vector<Type *> Doubles(Args.size(),
|
std::vector<Type *> Doubles(Args.size(), Type::getDoubleTy(TheContext));
|
||||||
Type::getDoubleTy(getGlobalContext()));
|
|
||||||
FunctionType *FT =
|
FunctionType *FT =
|
||||||
FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);
|
FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);
|
||||||
|
|
||||||
Function *F =
|
Function *F =
|
||||||
Function::Create(FT, Function::ExternalLinkage, Name, TheModule.get());
|
Function::Create(FT, Function::ExternalLinkage, Name, TheModule.get());
|
||||||
@ -1238,7 +1234,7 @@ Function *FunctionAST::codegen() {
|
|||||||
BinopPrecedence[P.getOperatorName()] = P.getBinaryPrecedence();
|
BinopPrecedence[P.getOperatorName()] = P.getBinaryPrecedence();
|
||||||
|
|
||||||
// Create a new basic block to start insertion into.
|
// 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);
|
Builder.SetInsertPoint(BB);
|
||||||
|
|
||||||
// Create a subprogram DIE for this function.
|
// Create a subprogram DIE for this function.
|
||||||
@ -1319,7 +1315,7 @@ Function *FunctionAST::codegen() {
|
|||||||
|
|
||||||
static void InitializeModule() {
|
static void InitializeModule() {
|
||||||
// Open a new module.
|
// 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());
|
TheModule->setDataLayout(TheJIT->getTargetMachine().createDataLayout());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -623,7 +623,8 @@ static PrototypeAST *ParseExtern() {
|
|||||||
|
|
||||||
static Module *TheModule;
|
static Module *TheModule;
|
||||||
static FunctionPassManager *TheFPM;
|
static FunctionPassManager *TheFPM;
|
||||||
static IRBuilder<> Builder(getGlobalContext());
|
static LLVMContext TheContext;
|
||||||
|
static IRBuilder<> Builder(TheContext);
|
||||||
static std::map<std::string, AllocaInst*> NamedValues;
|
static std::map<std::string, AllocaInst*> NamedValues;
|
||||||
|
|
||||||
Value *ErrorV(const char *Str) { Error(Str); return 0; }
|
Value *ErrorV(const char *Str) { Error(Str); return 0; }
|
||||||
@ -634,12 +635,11 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
|
|||||||
const std::string &VarName) {
|
const std::string &VarName) {
|
||||||
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
||||||
TheFunction->getEntryBlock().begin());
|
TheFunction->getEntryBlock().begin());
|
||||||
return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), 0,
|
return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), 0, VarName.c_str());
|
||||||
VarName.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *NumberExprAST::Codegen() {
|
Value *NumberExprAST::Codegen() {
|
||||||
return ConstantFP::get(getGlobalContext(), APFloat(Val));
|
return ConstantFP::get(TheContext, APFloat(Val));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VariableExprAST::Codegen() {
|
Value *VariableExprAST::Codegen() {
|
||||||
@ -699,8 +699,7 @@ Value *BinaryExprAST::Codegen() {
|
|||||||
case '<':
|
case '<':
|
||||||
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
|
return Builder.CreateUIToFP(L, Type::getDoubleTy(TheContext), "booltmp");
|
||||||
"booltmp");
|
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -740,18 +739,17 @@ Value *IfExprAST::Codegen() {
|
|||||||
if (CondV == 0) return 0;
|
if (CondV == 0) return 0;
|
||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
CondV = Builder.CreateFCmpONE(CondV,
|
CondV = Builder.CreateFCmpONE(
|
||||||
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
CondV, ConstantFP::get(TheContext, APFloat(0.0)), "ifcond");
|
||||||
"ifcond");
|
|
||||||
|
|
||||||
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
||||||
|
|
||||||
// Create blocks for the then and else cases. Insert the 'then' block at the
|
// Create blocks for the then and else cases. Insert the 'then' block at the
|
||||||
// end of the function.
|
// end of the function.
|
||||||
BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction);
|
BasicBlock *ThenBB = BasicBlock::Create(TheContext, "then", TheFunction);
|
||||||
BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
|
BasicBlock *ElseBB = BasicBlock::Create(TheContext, "else");
|
||||||
BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
|
BasicBlock *MergeBB = BasicBlock::Create(TheContext, "ifcont");
|
||||||
|
|
||||||
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
|
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
|
||||||
|
|
||||||
// Emit then value.
|
// Emit then value.
|
||||||
@ -778,9 +776,8 @@ Value *IfExprAST::Codegen() {
|
|||||||
// Emit merge block.
|
// Emit merge block.
|
||||||
TheFunction->getBasicBlockList().push_back(MergeBB);
|
TheFunction->getBasicBlockList().push_back(MergeBB);
|
||||||
Builder.SetInsertPoint(MergeBB);
|
Builder.SetInsertPoint(MergeBB);
|
||||||
PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
|
PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
|
||||||
"iftmp");
|
|
||||||
|
|
||||||
PN->addIncoming(ThenV, ThenBB);
|
PN->addIncoming(ThenV, ThenBB);
|
||||||
PN->addIncoming(ElseV, ElseBB);
|
PN->addIncoming(ElseV, ElseBB);
|
||||||
return PN;
|
return PN;
|
||||||
@ -821,8 +818,8 @@ Value *ForExprAST::Codegen() {
|
|||||||
|
|
||||||
// Make the new basic block for the loop header, inserting after current
|
// Make the new basic block for the loop header, inserting after current
|
||||||
// block.
|
// 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.
|
// Insert an explicit fall through from the current block to the LoopBB.
|
||||||
Builder.CreateBr(LoopBB);
|
Builder.CreateBr(LoopBB);
|
||||||
|
|
||||||
@ -847,7 +844,7 @@ Value *ForExprAST::Codegen() {
|
|||||||
if (StepVal == 0) return 0;
|
if (StepVal == 0) return 0;
|
||||||
} else {
|
} else {
|
||||||
// If not specified, use 1.0.
|
// If not specified, use 1.0.
|
||||||
StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
|
StepVal = ConstantFP::get(TheContext, APFloat(1.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the end condition.
|
// Compute the end condition.
|
||||||
@ -861,13 +858,13 @@ Value *ForExprAST::Codegen() {
|
|||||||
Builder.CreateStore(NextVar, Alloca);
|
Builder.CreateStore(NextVar, Alloca);
|
||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
EndCond = Builder.CreateFCmpONE(EndCond,
|
EndCond = Builder.CreateFCmpONE(
|
||||||
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
EndCond, ConstantFP::get(TheContext, APFloat(0.0)), "loopcond");
|
||||||
"loopcond");
|
|
||||||
|
|
||||||
// Create the "after loop" block and insert it.
|
// 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.
|
// Insert the conditional branch into the end of LoopEndBB.
|
||||||
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
|
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
|
||||||
|
|
||||||
@ -882,7 +879,7 @@ Value *ForExprAST::Codegen() {
|
|||||||
|
|
||||||
|
|
||||||
// for expr always returns 0.0.
|
// for expr always returns 0.0.
|
||||||
return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
|
return Constant::getNullValue(Type::getDoubleTy(TheContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VarExprAST::Codegen() {
|
Value *VarExprAST::Codegen() {
|
||||||
@ -905,7 +902,7 @@ Value *VarExprAST::Codegen() {
|
|||||||
InitVal = Init->Codegen();
|
InitVal = Init->Codegen();
|
||||||
if (InitVal == 0) return 0;
|
if (InitVal == 0) return 0;
|
||||||
} else { // If not specified, use 0.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);
|
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
|
||||||
@ -933,10 +930,9 @@ Value *VarExprAST::Codegen() {
|
|||||||
|
|
||||||
Function *PrototypeAST::Codegen() {
|
Function *PrototypeAST::Codegen() {
|
||||||
// Make the function type: double(double,double) etc.
|
// Make the function type: double(double,double) etc.
|
||||||
std::vector<Type*> Doubles(Args.size(),
|
std::vector<Type *> Doubles(Args.size(), Type::getDoubleTy(TheContext));
|
||||||
Type::getDoubleTy(getGlobalContext()));
|
FunctionType *FT =
|
||||||
FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()),
|
FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);
|
||||||
Doubles, false);
|
|
||||||
|
|
||||||
Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
|
Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
|
||||||
// If F conflicted, there was already something named 'Name'. If it has a
|
// 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();
|
BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
|
||||||
|
|
||||||
// Create a new basic block to start insertion into.
|
// 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);
|
Builder.SetInsertPoint(BB);
|
||||||
|
|
||||||
// Add all arguments to the symbol table and create their allocas.
|
// Add all arguments to the symbol table and create their allocas.
|
||||||
@ -1122,7 +1118,7 @@ double printlf() {
|
|||||||
|
|
||||||
Module* parseInputIR(std::string InputFile) {
|
Module* parseInputIR(std::string InputFile) {
|
||||||
SMDiagnostic Err;
|
SMDiagnostic Err;
|
||||||
Module *M = ParseIRFile(InputFile, Err, getGlobalContext());
|
Module *M = ParseIRFile(InputFile, Err, TheContext);
|
||||||
if (!M) {
|
if (!M) {
|
||||||
Err.print("IR parsing failed: ", errs());
|
Err.print("IR parsing failed: ", errs());
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1137,7 +1133,7 @@ Module* parseInputIR(std::string InputFile) {
|
|||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
InitializeNativeTarget();
|
InitializeNativeTarget();
|
||||||
LLVMContext &Context = getGlobalContext();
|
LLVMContext &Context = TheContext;
|
||||||
|
|
||||||
cl::ParseCommandLineOptions(argc, argv,
|
cl::ParseCommandLineOptions(argc, argv,
|
||||||
"Kaleidoscope example program\n");
|
"Kaleidoscope example program\n");
|
||||||
|
@ -994,7 +994,8 @@ void MCJITHelper::dump()
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
static MCJITHelper *TheHelper;
|
static MCJITHelper *TheHelper;
|
||||||
static IRBuilder<> Builder(getGlobalContext());
|
static LLVMContext TheContext;
|
||||||
|
static IRBuilder<> Builder(TheContext);
|
||||||
static std::map<std::string, AllocaInst*> NamedValues;
|
static std::map<std::string, AllocaInst*> NamedValues;
|
||||||
|
|
||||||
Value *ErrorV(const char *Str) { Error(Str); return 0; }
|
Value *ErrorV(const char *Str) { Error(Str); return 0; }
|
||||||
@ -1005,12 +1006,11 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
|
|||||||
const std::string &VarName) {
|
const std::string &VarName) {
|
||||||
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
||||||
TheFunction->getEntryBlock().begin());
|
TheFunction->getEntryBlock().begin());
|
||||||
return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), 0,
|
return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), 0, VarName.c_str());
|
||||||
VarName.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *NumberExprAST::Codegen() {
|
Value *NumberExprAST::Codegen() {
|
||||||
return ConstantFP::get(getGlobalContext(), APFloat(Val));
|
return ConstantFP::get(TheContext, APFloat(Val));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VariableExprAST::Codegen() {
|
Value *VariableExprAST::Codegen() {
|
||||||
@ -1066,8 +1066,7 @@ Value *BinaryExprAST::Codegen() {
|
|||||||
case '<':
|
case '<':
|
||||||
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
|
return Builder.CreateUIToFP(L, Type::getDoubleTy(TheContext), "booltmp");
|
||||||
"booltmp");
|
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1104,17 +1103,16 @@ Value *IfExprAST::Codegen() {
|
|||||||
if (CondV == 0) return 0;
|
if (CondV == 0) return 0;
|
||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
CondV = Builder.CreateFCmpONE(CondV,
|
CondV = Builder.CreateFCmpONE(
|
||||||
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
CondV, ConstantFP::get(TheContext, APFloat(0.0)), "ifcond");
|
||||||
"ifcond");
|
|
||||||
|
|
||||||
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
||||||
|
|
||||||
// Create blocks for the then and else cases. Insert the 'then' block at the
|
// Create blocks for the then and else cases. Insert the 'then' block at the
|
||||||
// end of the function.
|
// end of the function.
|
||||||
BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction);
|
BasicBlock *ThenBB = BasicBlock::Create(TheContext, "then", TheFunction);
|
||||||
BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
|
BasicBlock *ElseBB = BasicBlock::Create(TheContext, "else");
|
||||||
BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
|
BasicBlock *MergeBB = BasicBlock::Create(TheContext, "ifcont");
|
||||||
|
|
||||||
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
|
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
|
||||||
|
|
||||||
@ -1142,8 +1140,7 @@ Value *IfExprAST::Codegen() {
|
|||||||
// Emit merge block.
|
// Emit merge block.
|
||||||
TheFunction->getBasicBlockList().push_back(MergeBB);
|
TheFunction->getBasicBlockList().push_back(MergeBB);
|
||||||
Builder.SetInsertPoint(MergeBB);
|
Builder.SetInsertPoint(MergeBB);
|
||||||
PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
|
PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
|
||||||
"iftmp");
|
|
||||||
|
|
||||||
PN->addIncoming(ThenV, ThenBB);
|
PN->addIncoming(ThenV, ThenBB);
|
||||||
PN->addIncoming(ElseV, ElseBB);
|
PN->addIncoming(ElseV, ElseBB);
|
||||||
@ -1185,7 +1182,7 @@ Value *ForExprAST::Codegen() {
|
|||||||
|
|
||||||
// Make the new basic block for the loop header, inserting after current
|
// Make the new basic block for the loop header, inserting after current
|
||||||
// block.
|
// 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.
|
// Insert an explicit fall through from the current block to the LoopBB.
|
||||||
Builder.CreateBr(LoopBB);
|
Builder.CreateBr(LoopBB);
|
||||||
@ -1211,7 +1208,7 @@ Value *ForExprAST::Codegen() {
|
|||||||
if (StepVal == 0) return 0;
|
if (StepVal == 0) return 0;
|
||||||
} else {
|
} else {
|
||||||
// If not specified, use 1.0.
|
// If not specified, use 1.0.
|
||||||
StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
|
StepVal = ConstantFP::get(TheContext, APFloat(1.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the end condition.
|
// Compute the end condition.
|
||||||
@ -1225,12 +1222,12 @@ Value *ForExprAST::Codegen() {
|
|||||||
Builder.CreateStore(NextVar, Alloca);
|
Builder.CreateStore(NextVar, Alloca);
|
||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
EndCond = Builder.CreateFCmpONE(EndCond,
|
EndCond = Builder.CreateFCmpONE(
|
||||||
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
EndCond, ConstantFP::get(TheContext, APFloat(0.0)), "loopcond");
|
||||||
"loopcond");
|
|
||||||
|
|
||||||
// Create the "after loop" block and insert it.
|
// 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.
|
// Insert the conditional branch into the end of LoopEndBB.
|
||||||
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
|
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
|
||||||
@ -1246,7 +1243,7 @@ Value *ForExprAST::Codegen() {
|
|||||||
|
|
||||||
|
|
||||||
// for expr always returns 0.0.
|
// for expr always returns 0.0.
|
||||||
return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
|
return Constant::getNullValue(Type::getDoubleTy(TheContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VarExprAST::Codegen() {
|
Value *VarExprAST::Codegen() {
|
||||||
@ -1269,7 +1266,7 @@ Value *VarExprAST::Codegen() {
|
|||||||
InitVal = Init->Codegen();
|
InitVal = Init->Codegen();
|
||||||
if (InitVal == 0) return 0;
|
if (InitVal == 0) return 0;
|
||||||
} else { // If not specified, use 0.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);
|
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
|
||||||
@ -1297,10 +1294,9 @@ Value *VarExprAST::Codegen() {
|
|||||||
|
|
||||||
Function *PrototypeAST::Codegen() {
|
Function *PrototypeAST::Codegen() {
|
||||||
// Make the function type: double(double,double) etc.
|
// Make the function type: double(double,double) etc.
|
||||||
std::vector<Type*> Doubles(Args.size(),
|
std::vector<Type *> Doubles(Args.size(), Type::getDoubleTy(TheContext));
|
||||||
Type::getDoubleTy(getGlobalContext()));
|
FunctionType *FT =
|
||||||
FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()),
|
FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);
|
||||||
Doubles, false);
|
|
||||||
|
|
||||||
std::string FnName = MakeLegalFunctionName(Name);
|
std::string FnName = MakeLegalFunctionName(Name);
|
||||||
|
|
||||||
@ -1365,7 +1361,7 @@ Function *FunctionAST::Codegen() {
|
|||||||
BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
|
BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
|
||||||
|
|
||||||
// Create a new basic block to start insertion into.
|
// 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);
|
Builder.SetInsertPoint(BB);
|
||||||
|
|
||||||
// Add all arguments to the symbol table and create their allocas.
|
// Add all arguments to the symbol table and create their allocas.
|
||||||
@ -1490,7 +1486,7 @@ double printlf() {
|
|||||||
|
|
||||||
Module* parseInputIR(std::string InputFile) {
|
Module* parseInputIR(std::string InputFile) {
|
||||||
SMDiagnostic Err;
|
SMDiagnostic Err;
|
||||||
Module *M = ParseIRFile(InputFile, Err, getGlobalContext());
|
Module *M = ParseIRFile(InputFile, Err, TheContext);
|
||||||
if (!M) {
|
if (!M) {
|
||||||
Err.print("IR parsing failed: ", errs());
|
Err.print("IR parsing failed: ", errs());
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1512,7 +1508,7 @@ int main(int argc, char **argv) {
|
|||||||
InitializeNativeTarget();
|
InitializeNativeTarget();
|
||||||
InitializeNativeTargetAsmPrinter();
|
InitializeNativeTargetAsmPrinter();
|
||||||
InitializeNativeTargetAsmParser();
|
InitializeNativeTargetAsmParser();
|
||||||
LLVMContext &Context = getGlobalContext();
|
LLVMContext &Context = TheContext;
|
||||||
|
|
||||||
cl::ParseCommandLineOptions(argc, argv,
|
cl::ParseCommandLineOptions(argc, argv,
|
||||||
"Kaleidoscope example program\n");
|
"Kaleidoscope example program\n");
|
||||||
|
@ -1066,7 +1066,8 @@ void MCJITHelper::dump()
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
static BaseHelper *TheHelper;
|
static BaseHelper *TheHelper;
|
||||||
static IRBuilder<> Builder(getGlobalContext());
|
static LLVMContext TheContext;
|
||||||
|
static IRBuilder<> Builder(TheContext);
|
||||||
static std::map<std::string, AllocaInst*> NamedValues;
|
static std::map<std::string, AllocaInst*> NamedValues;
|
||||||
|
|
||||||
Value *ErrorV(const char *Str) { Error(Str); return 0; }
|
Value *ErrorV(const char *Str) { Error(Str); return 0; }
|
||||||
@ -1077,12 +1078,11 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
|
|||||||
const std::string &VarName) {
|
const std::string &VarName) {
|
||||||
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
||||||
TheFunction->getEntryBlock().begin());
|
TheFunction->getEntryBlock().begin());
|
||||||
return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), 0,
|
return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), 0, VarName.c_str());
|
||||||
VarName.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *NumberExprAST::Codegen() {
|
Value *NumberExprAST::Codegen() {
|
||||||
return ConstantFP::get(getGlobalContext(), APFloat(Val));
|
return ConstantFP::get(TheContext, APFloat(Val));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VariableExprAST::Codegen() {
|
Value *VariableExprAST::Codegen() {
|
||||||
@ -1140,8 +1140,7 @@ Value *BinaryExprAST::Codegen() {
|
|||||||
case '<':
|
case '<':
|
||||||
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
|
return Builder.CreateUIToFP(L, Type::getDoubleTy(TheContext), "booltmp");
|
||||||
"booltmp");
|
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1182,17 +1181,16 @@ Value *IfExprAST::Codegen() {
|
|||||||
if (CondV == 0) return 0;
|
if (CondV == 0) return 0;
|
||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
CondV = Builder.CreateFCmpONE(CondV,
|
CondV = Builder.CreateFCmpONE(
|
||||||
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
CondV, ConstantFP::get(TheContext, APFloat(0.0)), "ifcond");
|
||||||
"ifcond");
|
|
||||||
|
|
||||||
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
||||||
|
|
||||||
// Create blocks for the then and else cases. Insert the 'then' block at the
|
// Create blocks for the then and else cases. Insert the 'then' block at the
|
||||||
// end of the function.
|
// end of the function.
|
||||||
BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction);
|
BasicBlock *ThenBB = BasicBlock::Create(TheContext, "then", TheFunction);
|
||||||
BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
|
BasicBlock *ElseBB = BasicBlock::Create(TheContext, "else");
|
||||||
BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
|
BasicBlock *MergeBB = BasicBlock::Create(TheContext, "ifcont");
|
||||||
|
|
||||||
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
|
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
|
||||||
|
|
||||||
@ -1220,8 +1218,7 @@ Value *IfExprAST::Codegen() {
|
|||||||
// Emit merge block.
|
// Emit merge block.
|
||||||
TheFunction->getBasicBlockList().push_back(MergeBB);
|
TheFunction->getBasicBlockList().push_back(MergeBB);
|
||||||
Builder.SetInsertPoint(MergeBB);
|
Builder.SetInsertPoint(MergeBB);
|
||||||
PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
|
PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
|
||||||
"iftmp");
|
|
||||||
|
|
||||||
PN->addIncoming(ThenV, ThenBB);
|
PN->addIncoming(ThenV, ThenBB);
|
||||||
PN->addIncoming(ElseV, ElseBB);
|
PN->addIncoming(ElseV, ElseBB);
|
||||||
@ -1263,7 +1260,7 @@ Value *ForExprAST::Codegen() {
|
|||||||
|
|
||||||
// Make the new basic block for the loop header, inserting after current
|
// Make the new basic block for the loop header, inserting after current
|
||||||
// block.
|
// 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.
|
// Insert an explicit fall through from the current block to the LoopBB.
|
||||||
Builder.CreateBr(LoopBB);
|
Builder.CreateBr(LoopBB);
|
||||||
@ -1289,7 +1286,7 @@ Value *ForExprAST::Codegen() {
|
|||||||
if (StepVal == 0) return 0;
|
if (StepVal == 0) return 0;
|
||||||
} else {
|
} else {
|
||||||
// If not specified, use 1.0.
|
// If not specified, use 1.0.
|
||||||
StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
|
StepVal = ConstantFP::get(TheContext, APFloat(1.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the end condition.
|
// Compute the end condition.
|
||||||
@ -1303,12 +1300,12 @@ Value *ForExprAST::Codegen() {
|
|||||||
Builder.CreateStore(NextVar, Alloca);
|
Builder.CreateStore(NextVar, Alloca);
|
||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
EndCond = Builder.CreateFCmpONE(EndCond,
|
EndCond = Builder.CreateFCmpONE(
|
||||||
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
EndCond, ConstantFP::get(TheContext, APFloat(0.0)), "loopcond");
|
||||||
"loopcond");
|
|
||||||
|
|
||||||
// Create the "after loop" block and insert it.
|
// 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.
|
// Insert the conditional branch into the end of LoopEndBB.
|
||||||
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
|
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
|
||||||
@ -1324,7 +1321,7 @@ Value *ForExprAST::Codegen() {
|
|||||||
|
|
||||||
|
|
||||||
// for expr always returns 0.0.
|
// for expr always returns 0.0.
|
||||||
return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
|
return Constant::getNullValue(Type::getDoubleTy(TheContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VarExprAST::Codegen() {
|
Value *VarExprAST::Codegen() {
|
||||||
@ -1347,7 +1344,7 @@ Value *VarExprAST::Codegen() {
|
|||||||
InitVal = Init->Codegen();
|
InitVal = Init->Codegen();
|
||||||
if (InitVal == 0) return 0;
|
if (InitVal == 0) return 0;
|
||||||
} else { // If not specified, use 0.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);
|
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
|
||||||
@ -1375,10 +1372,9 @@ Value *VarExprAST::Codegen() {
|
|||||||
|
|
||||||
Function *PrototypeAST::Codegen() {
|
Function *PrototypeAST::Codegen() {
|
||||||
// Make the function type: double(double,double) etc.
|
// Make the function type: double(double,double) etc.
|
||||||
std::vector<Type*> Doubles(Args.size(),
|
std::vector<Type *> Doubles(Args.size(), Type::getDoubleTy(TheContext));
|
||||||
Type::getDoubleTy(getGlobalContext()));
|
FunctionType *FT =
|
||||||
FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()),
|
FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);
|
||||||
Doubles, false);
|
|
||||||
|
|
||||||
std::string FnName;
|
std::string FnName;
|
||||||
FnName = MakeLegalFunctionName(Name);
|
FnName = MakeLegalFunctionName(Name);
|
||||||
@ -1443,7 +1439,7 @@ Function *FunctionAST::Codegen() {
|
|||||||
BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
|
BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
|
||||||
|
|
||||||
// Create a new basic block to start insertion into.
|
// 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);
|
Builder.SetInsertPoint(BB);
|
||||||
|
|
||||||
// Add all arguments to the symbol table and create their allocas.
|
// Add all arguments to the symbol table and create their allocas.
|
||||||
@ -1565,7 +1561,7 @@ int main(int argc, char **argv) {
|
|||||||
InitializeNativeTarget();
|
InitializeNativeTarget();
|
||||||
InitializeNativeTargetAsmPrinter();
|
InitializeNativeTargetAsmPrinter();
|
||||||
InitializeNativeTargetAsmParser();
|
InitializeNativeTargetAsmParser();
|
||||||
LLVMContext &Context = getGlobalContext();
|
LLVMContext &Context = TheContext;
|
||||||
|
|
||||||
cl::ParseCommandLineOptions(argc, argv,
|
cl::ParseCommandLineOptions(argc, argv,
|
||||||
"Kaleidoscope example program\n");
|
"Kaleidoscope example program\n");
|
||||||
|
@ -852,7 +852,8 @@ void MCJITHelper::dump()
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
static MCJITHelper *TheHelper;
|
static MCJITHelper *TheHelper;
|
||||||
static IRBuilder<> Builder(getGlobalContext());
|
static LLVMContext TheContext;
|
||||||
|
static IRBuilder<> Builder(TheContext);
|
||||||
static std::map<std::string, AllocaInst*> NamedValues;
|
static std::map<std::string, AllocaInst*> NamedValues;
|
||||||
|
|
||||||
Value *ErrorV(const char *Str) { Error(Str); return 0; }
|
Value *ErrorV(const char *Str) { Error(Str); return 0; }
|
||||||
@ -863,12 +864,11 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
|
|||||||
const std::string &VarName) {
|
const std::string &VarName) {
|
||||||
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
||||||
TheFunction->getEntryBlock().begin());
|
TheFunction->getEntryBlock().begin());
|
||||||
return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), 0,
|
return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), 0, VarName.c_str());
|
||||||
VarName.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *NumberExprAST::Codegen() {
|
Value *NumberExprAST::Codegen() {
|
||||||
return ConstantFP::get(getGlobalContext(), APFloat(Val));
|
return ConstantFP::get(TheContext, APFloat(Val));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VariableExprAST::Codegen() {
|
Value *VariableExprAST::Codegen() {
|
||||||
@ -924,8 +924,7 @@ Value *BinaryExprAST::Codegen() {
|
|||||||
case '<':
|
case '<':
|
||||||
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
|
return Builder.CreateUIToFP(L, Type::getDoubleTy(TheContext), "booltmp");
|
||||||
"booltmp");
|
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -962,17 +961,16 @@ Value *IfExprAST::Codegen() {
|
|||||||
if (CondV == 0) return 0;
|
if (CondV == 0) return 0;
|
||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
CondV = Builder.CreateFCmpONE(CondV,
|
CondV = Builder.CreateFCmpONE(
|
||||||
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
CondV, ConstantFP::get(TheContext, APFloat(0.0)), "ifcond");
|
||||||
"ifcond");
|
|
||||||
|
|
||||||
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
||||||
|
|
||||||
// Create blocks for the then and else cases. Insert the 'then' block at the
|
// Create blocks for the then and else cases. Insert the 'then' block at the
|
||||||
// end of the function.
|
// end of the function.
|
||||||
BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction);
|
BasicBlock *ThenBB = BasicBlock::Create(TheContext, "then", TheFunction);
|
||||||
BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
|
BasicBlock *ElseBB = BasicBlock::Create(TheContext, "else");
|
||||||
BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
|
BasicBlock *MergeBB = BasicBlock::Create(TheContext, "ifcont");
|
||||||
|
|
||||||
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
|
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
|
||||||
|
|
||||||
@ -1000,8 +998,7 @@ Value *IfExprAST::Codegen() {
|
|||||||
// Emit merge block.
|
// Emit merge block.
|
||||||
TheFunction->getBasicBlockList().push_back(MergeBB);
|
TheFunction->getBasicBlockList().push_back(MergeBB);
|
||||||
Builder.SetInsertPoint(MergeBB);
|
Builder.SetInsertPoint(MergeBB);
|
||||||
PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
|
PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
|
||||||
"iftmp");
|
|
||||||
|
|
||||||
PN->addIncoming(ThenV, ThenBB);
|
PN->addIncoming(ThenV, ThenBB);
|
||||||
PN->addIncoming(ElseV, ElseBB);
|
PN->addIncoming(ElseV, ElseBB);
|
||||||
@ -1043,7 +1040,7 @@ Value *ForExprAST::Codegen() {
|
|||||||
|
|
||||||
// Make the new basic block for the loop header, inserting after current
|
// Make the new basic block for the loop header, inserting after current
|
||||||
// block.
|
// 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.
|
// Insert an explicit fall through from the current block to the LoopBB.
|
||||||
Builder.CreateBr(LoopBB);
|
Builder.CreateBr(LoopBB);
|
||||||
@ -1069,7 +1066,7 @@ Value *ForExprAST::Codegen() {
|
|||||||
if (StepVal == 0) return 0;
|
if (StepVal == 0) return 0;
|
||||||
} else {
|
} else {
|
||||||
// If not specified, use 1.0.
|
// If not specified, use 1.0.
|
||||||
StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
|
StepVal = ConstantFP::get(TheContext, APFloat(1.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the end condition.
|
// Compute the end condition.
|
||||||
@ -1083,12 +1080,12 @@ Value *ForExprAST::Codegen() {
|
|||||||
Builder.CreateStore(NextVar, Alloca);
|
Builder.CreateStore(NextVar, Alloca);
|
||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
EndCond = Builder.CreateFCmpONE(EndCond,
|
EndCond = Builder.CreateFCmpONE(
|
||||||
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
EndCond, ConstantFP::get(TheContext, APFloat(0.0)), "loopcond");
|
||||||
"loopcond");
|
|
||||||
|
|
||||||
// Create the "after loop" block and insert it.
|
// 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.
|
// Insert the conditional branch into the end of LoopEndBB.
|
||||||
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
|
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
|
||||||
@ -1104,7 +1101,7 @@ Value *ForExprAST::Codegen() {
|
|||||||
|
|
||||||
|
|
||||||
// for expr always returns 0.0.
|
// for expr always returns 0.0.
|
||||||
return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
|
return Constant::getNullValue(Type::getDoubleTy(TheContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VarExprAST::Codegen() {
|
Value *VarExprAST::Codegen() {
|
||||||
@ -1127,7 +1124,7 @@ Value *VarExprAST::Codegen() {
|
|||||||
InitVal = Init->Codegen();
|
InitVal = Init->Codegen();
|
||||||
if (InitVal == 0) return 0;
|
if (InitVal == 0) return 0;
|
||||||
} else { // If not specified, use 0.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);
|
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
|
||||||
@ -1155,10 +1152,9 @@ Value *VarExprAST::Codegen() {
|
|||||||
|
|
||||||
Function *PrototypeAST::Codegen() {
|
Function *PrototypeAST::Codegen() {
|
||||||
// Make the function type: double(double,double) etc.
|
// Make the function type: double(double,double) etc.
|
||||||
std::vector<Type*> Doubles(Args.size(),
|
std::vector<Type *> Doubles(Args.size(), Type::getDoubleTy(TheContext));
|
||||||
Type::getDoubleTy(getGlobalContext()));
|
FunctionType *FT =
|
||||||
FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()),
|
FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);
|
||||||
Doubles, false);
|
|
||||||
|
|
||||||
std::string FnName = MakeLegalFunctionName(Name);
|
std::string FnName = MakeLegalFunctionName(Name);
|
||||||
|
|
||||||
@ -1223,7 +1219,7 @@ Function *FunctionAST::Codegen() {
|
|||||||
BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
|
BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
|
||||||
|
|
||||||
// Create a new basic block to start insertion into.
|
// 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);
|
Builder.SetInsertPoint(BB);
|
||||||
|
|
||||||
// Add all arguments to the symbol table and create their allocas.
|
// Add all arguments to the symbol table and create their allocas.
|
||||||
@ -1349,7 +1345,7 @@ int main() {
|
|||||||
InitializeNativeTarget();
|
InitializeNativeTarget();
|
||||||
InitializeNativeTargetAsmPrinter();
|
InitializeNativeTargetAsmPrinter();
|
||||||
InitializeNativeTargetAsmParser();
|
InitializeNativeTargetAsmParser();
|
||||||
LLVMContext &Context = getGlobalContext();
|
LLVMContext &Context = TheContext;
|
||||||
|
|
||||||
// Install standard binary operators.
|
// Install standard binary operators.
|
||||||
// 1 is lowest precedence.
|
// 1 is lowest precedence.
|
||||||
|
@ -608,7 +608,8 @@ static PrototypeAST *ParseExtern() {
|
|||||||
|
|
||||||
static Module *TheModule;
|
static Module *TheModule;
|
||||||
static FunctionPassManager *TheFPM;
|
static FunctionPassManager *TheFPM;
|
||||||
static IRBuilder<> Builder(getGlobalContext());
|
static LLVMContext TheContext;
|
||||||
|
static IRBuilder<> Builder(TheContext);
|
||||||
static std::map<std::string, AllocaInst*> NamedValues;
|
static std::map<std::string, AllocaInst*> NamedValues;
|
||||||
|
|
||||||
Value *ErrorV(const char *Str) { Error(Str); return 0; }
|
Value *ErrorV(const char *Str) { Error(Str); return 0; }
|
||||||
@ -619,12 +620,11 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
|
|||||||
const std::string &VarName) {
|
const std::string &VarName) {
|
||||||
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
||||||
TheFunction->getEntryBlock().begin());
|
TheFunction->getEntryBlock().begin());
|
||||||
return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), 0,
|
return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), 0, VarName.c_str());
|
||||||
VarName.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *NumberExprAST::Codegen() {
|
Value *NumberExprAST::Codegen() {
|
||||||
return ConstantFP::get(getGlobalContext(), APFloat(Val));
|
return ConstantFP::get(TheContext, APFloat(Val));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VariableExprAST::Codegen() {
|
Value *VariableExprAST::Codegen() {
|
||||||
@ -681,8 +681,7 @@ Value *BinaryExprAST::Codegen() {
|
|||||||
case '<':
|
case '<':
|
||||||
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
|
return Builder.CreateUIToFP(L, Type::getDoubleTy(TheContext), "booltmp");
|
||||||
"booltmp");
|
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -722,18 +721,17 @@ Value *IfExprAST::Codegen() {
|
|||||||
if (CondV == 0) return 0;
|
if (CondV == 0) return 0;
|
||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
CondV = Builder.CreateFCmpONE(CondV,
|
CondV = Builder.CreateFCmpONE(
|
||||||
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
CondV, ConstantFP::get(TheContext, APFloat(0.0)), "ifcond");
|
||||||
"ifcond");
|
|
||||||
|
|
||||||
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
||||||
|
|
||||||
// Create blocks for the then and else cases. Insert the 'then' block at the
|
// Create blocks for the then and else cases. Insert the 'then' block at the
|
||||||
// end of the function.
|
// end of the function.
|
||||||
BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction);
|
BasicBlock *ThenBB = BasicBlock::Create(TheContext, "then", TheFunction);
|
||||||
BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
|
BasicBlock *ElseBB = BasicBlock::Create(TheContext, "else");
|
||||||
BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
|
BasicBlock *MergeBB = BasicBlock::Create(TheContext, "ifcont");
|
||||||
|
|
||||||
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
|
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
|
||||||
|
|
||||||
// Emit then value.
|
// Emit then value.
|
||||||
@ -760,9 +758,8 @@ Value *IfExprAST::Codegen() {
|
|||||||
// Emit merge block.
|
// Emit merge block.
|
||||||
TheFunction->getBasicBlockList().push_back(MergeBB);
|
TheFunction->getBasicBlockList().push_back(MergeBB);
|
||||||
Builder.SetInsertPoint(MergeBB);
|
Builder.SetInsertPoint(MergeBB);
|
||||||
PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
|
PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
|
||||||
"iftmp");
|
|
||||||
|
|
||||||
PN->addIncoming(ThenV, ThenBB);
|
PN->addIncoming(ThenV, ThenBB);
|
||||||
PN->addIncoming(ElseV, ElseBB);
|
PN->addIncoming(ElseV, ElseBB);
|
||||||
return PN;
|
return PN;
|
||||||
@ -803,8 +800,8 @@ Value *ForExprAST::Codegen() {
|
|||||||
|
|
||||||
// Make the new basic block for the loop header, inserting after current
|
// Make the new basic block for the loop header, inserting after current
|
||||||
// block.
|
// 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.
|
// Insert an explicit fall through from the current block to the LoopBB.
|
||||||
Builder.CreateBr(LoopBB);
|
Builder.CreateBr(LoopBB);
|
||||||
|
|
||||||
@ -829,7 +826,7 @@ Value *ForExprAST::Codegen() {
|
|||||||
if (StepVal == 0) return 0;
|
if (StepVal == 0) return 0;
|
||||||
} else {
|
} else {
|
||||||
// If not specified, use 1.0.
|
// If not specified, use 1.0.
|
||||||
StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
|
StepVal = ConstantFP::get(TheContext, APFloat(1.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the end condition.
|
// Compute the end condition.
|
||||||
@ -843,13 +840,13 @@ Value *ForExprAST::Codegen() {
|
|||||||
Builder.CreateStore(NextVar, Alloca);
|
Builder.CreateStore(NextVar, Alloca);
|
||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
EndCond = Builder.CreateFCmpONE(EndCond,
|
EndCond = Builder.CreateFCmpONE(
|
||||||
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
EndCond, ConstantFP::get(TheContext, APFloat(0.0)), "loopcond");
|
||||||
"loopcond");
|
|
||||||
|
|
||||||
// Create the "after loop" block and insert it.
|
// 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.
|
// Insert the conditional branch into the end of LoopEndBB.
|
||||||
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
|
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
|
||||||
|
|
||||||
@ -864,7 +861,7 @@ Value *ForExprAST::Codegen() {
|
|||||||
|
|
||||||
|
|
||||||
// for expr always returns 0.0.
|
// for expr always returns 0.0.
|
||||||
return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
|
return Constant::getNullValue(Type::getDoubleTy(TheContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VarExprAST::Codegen() {
|
Value *VarExprAST::Codegen() {
|
||||||
@ -887,7 +884,7 @@ Value *VarExprAST::Codegen() {
|
|||||||
InitVal = Init->Codegen();
|
InitVal = Init->Codegen();
|
||||||
if (InitVal == 0) return 0;
|
if (InitVal == 0) return 0;
|
||||||
} else { // If not specified, use 0.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);
|
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
|
||||||
@ -915,10 +912,9 @@ Value *VarExprAST::Codegen() {
|
|||||||
|
|
||||||
Function *PrototypeAST::Codegen() {
|
Function *PrototypeAST::Codegen() {
|
||||||
// Make the function type: double(double,double) etc.
|
// Make the function type: double(double,double) etc.
|
||||||
std::vector<Type*> Doubles(Args.size(),
|
std::vector<Type *> Doubles(Args.size(), Type::getDoubleTy(TheContext));
|
||||||
Type::getDoubleTy(getGlobalContext()));
|
FunctionType *FT =
|
||||||
FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()),
|
FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);
|
||||||
Doubles, false);
|
|
||||||
|
|
||||||
Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
|
Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
|
||||||
// If F conflicted, there was already something named 'Name'. If it has a
|
// 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();
|
BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
|
||||||
|
|
||||||
// Create a new basic block to start insertion into.
|
// 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);
|
Builder.SetInsertPoint(BB);
|
||||||
|
|
||||||
// Add all arguments to the symbol table and create their allocas.
|
// Add all arguments to the symbol table and create their allocas.
|
||||||
@ -1104,7 +1100,7 @@ double printlf() {
|
|||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
InitializeNativeTarget();
|
InitializeNativeTarget();
|
||||||
LLVMContext &Context = getGlobalContext();
|
LLVMContext &Context = TheContext;
|
||||||
|
|
||||||
// Install standard binary operators.
|
// Install standard binary operators.
|
||||||
// 1 is lowest precedence.
|
// 1 is lowest precedence.
|
||||||
|
@ -892,7 +892,8 @@ void MCJITHelper::dump()
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
static MCJITHelper *TheHelper;
|
static MCJITHelper *TheHelper;
|
||||||
static IRBuilder<> Builder(getGlobalContext());
|
static LLVMContext TheContext;
|
||||||
|
static IRBuilder<> Builder(TheContext);
|
||||||
static std::map<std::string, AllocaInst*> NamedValues;
|
static std::map<std::string, AllocaInst*> NamedValues;
|
||||||
|
|
||||||
Value *ErrorV(const char *Str) { Error(Str); return 0; }
|
Value *ErrorV(const char *Str) { Error(Str); return 0; }
|
||||||
@ -903,12 +904,11 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
|
|||||||
const std::string &VarName) {
|
const std::string &VarName) {
|
||||||
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
||||||
TheFunction->getEntryBlock().begin());
|
TheFunction->getEntryBlock().begin());
|
||||||
return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), 0,
|
return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), 0, VarName.c_str());
|
||||||
VarName.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *NumberExprAST::Codegen() {
|
Value *NumberExprAST::Codegen() {
|
||||||
return ConstantFP::get(getGlobalContext(), APFloat(Val));
|
return ConstantFP::get(TheContext, APFloat(Val));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VariableExprAST::Codegen() {
|
Value *VariableExprAST::Codegen() {
|
||||||
@ -964,8 +964,7 @@ Value *BinaryExprAST::Codegen() {
|
|||||||
case '<':
|
case '<':
|
||||||
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
|
return Builder.CreateUIToFP(L, Type::getDoubleTy(TheContext), "booltmp");
|
||||||
"booltmp");
|
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1002,17 +1001,16 @@ Value *IfExprAST::Codegen() {
|
|||||||
if (CondV == 0) return 0;
|
if (CondV == 0) return 0;
|
||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
CondV = Builder.CreateFCmpONE(CondV,
|
CondV = Builder.CreateFCmpONE(
|
||||||
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
CondV, ConstantFP::get(TheContext, APFloat(0.0)), "ifcond");
|
||||||
"ifcond");
|
|
||||||
|
|
||||||
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
||||||
|
|
||||||
// Create blocks for the then and else cases. Insert the 'then' block at the
|
// Create blocks for the then and else cases. Insert the 'then' block at the
|
||||||
// end of the function.
|
// end of the function.
|
||||||
BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction);
|
BasicBlock *ThenBB = BasicBlock::Create(TheContext, "then", TheFunction);
|
||||||
BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
|
BasicBlock *ElseBB = BasicBlock::Create(TheContext, "else");
|
||||||
BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
|
BasicBlock *MergeBB = BasicBlock::Create(TheContext, "ifcont");
|
||||||
|
|
||||||
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
|
Builder.CreateCondBr(CondV, ThenBB, ElseBB);
|
||||||
|
|
||||||
@ -1040,8 +1038,7 @@ Value *IfExprAST::Codegen() {
|
|||||||
// Emit merge block.
|
// Emit merge block.
|
||||||
TheFunction->getBasicBlockList().push_back(MergeBB);
|
TheFunction->getBasicBlockList().push_back(MergeBB);
|
||||||
Builder.SetInsertPoint(MergeBB);
|
Builder.SetInsertPoint(MergeBB);
|
||||||
PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
|
PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
|
||||||
"iftmp");
|
|
||||||
|
|
||||||
PN->addIncoming(ThenV, ThenBB);
|
PN->addIncoming(ThenV, ThenBB);
|
||||||
PN->addIncoming(ElseV, ElseBB);
|
PN->addIncoming(ElseV, ElseBB);
|
||||||
@ -1083,7 +1080,7 @@ Value *ForExprAST::Codegen() {
|
|||||||
|
|
||||||
// Make the new basic block for the loop header, inserting after current
|
// Make the new basic block for the loop header, inserting after current
|
||||||
// block.
|
// 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.
|
// Insert an explicit fall through from the current block to the LoopBB.
|
||||||
Builder.CreateBr(LoopBB);
|
Builder.CreateBr(LoopBB);
|
||||||
@ -1109,7 +1106,7 @@ Value *ForExprAST::Codegen() {
|
|||||||
if (StepVal == 0) return 0;
|
if (StepVal == 0) return 0;
|
||||||
} else {
|
} else {
|
||||||
// If not specified, use 1.0.
|
// If not specified, use 1.0.
|
||||||
StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
|
StepVal = ConstantFP::get(TheContext, APFloat(1.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the end condition.
|
// Compute the end condition.
|
||||||
@ -1123,12 +1120,12 @@ Value *ForExprAST::Codegen() {
|
|||||||
Builder.CreateStore(NextVar, Alloca);
|
Builder.CreateStore(NextVar, Alloca);
|
||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
EndCond = Builder.CreateFCmpONE(EndCond,
|
EndCond = Builder.CreateFCmpONE(
|
||||||
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
EndCond, ConstantFP::get(TheContext, APFloat(0.0)), "loopcond");
|
||||||
"loopcond");
|
|
||||||
|
|
||||||
// Create the "after loop" block and insert it.
|
// 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.
|
// Insert the conditional branch into the end of LoopEndBB.
|
||||||
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
|
Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
|
||||||
@ -1144,7 +1141,7 @@ Value *ForExprAST::Codegen() {
|
|||||||
|
|
||||||
|
|
||||||
// for expr always returns 0.0.
|
// for expr always returns 0.0.
|
||||||
return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
|
return Constant::getNullValue(Type::getDoubleTy(TheContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VarExprAST::Codegen() {
|
Value *VarExprAST::Codegen() {
|
||||||
@ -1167,7 +1164,7 @@ Value *VarExprAST::Codegen() {
|
|||||||
InitVal = Init->Codegen();
|
InitVal = Init->Codegen();
|
||||||
if (InitVal == 0) return 0;
|
if (InitVal == 0) return 0;
|
||||||
} else { // If not specified, use 0.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);
|
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
|
||||||
@ -1195,10 +1192,9 @@ Value *VarExprAST::Codegen() {
|
|||||||
|
|
||||||
Function *PrototypeAST::Codegen() {
|
Function *PrototypeAST::Codegen() {
|
||||||
// Make the function type: double(double,double) etc.
|
// Make the function type: double(double,double) etc.
|
||||||
std::vector<Type*> Doubles(Args.size(),
|
std::vector<Type *> Doubles(Args.size(), Type::getDoubleTy(TheContext));
|
||||||
Type::getDoubleTy(getGlobalContext()));
|
FunctionType *FT =
|
||||||
FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()),
|
FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);
|
||||||
Doubles, false);
|
|
||||||
|
|
||||||
std::string FnName = MakeLegalFunctionName(Name);
|
std::string FnName = MakeLegalFunctionName(Name);
|
||||||
|
|
||||||
@ -1263,7 +1259,7 @@ Function *FunctionAST::Codegen() {
|
|||||||
BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
|
BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
|
||||||
|
|
||||||
// Create a new basic block to start insertion into.
|
// 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);
|
Builder.SetInsertPoint(BB);
|
||||||
|
|
||||||
// Add all arguments to the symbol table and create their allocas.
|
// Add all arguments to the symbol table and create their allocas.
|
||||||
@ -1390,7 +1386,7 @@ int main() {
|
|||||||
InitializeNativeTarget();
|
InitializeNativeTarget();
|
||||||
InitializeNativeTargetAsmPrinter();
|
InitializeNativeTargetAsmPrinter();
|
||||||
InitializeNativeTargetAsmParser();
|
InitializeNativeTargetAsmParser();
|
||||||
LLVMContext &Context = getGlobalContext();
|
LLVMContext &Context = TheContext;
|
||||||
|
|
||||||
// Install standard binary operators.
|
// Install standard binary operators.
|
||||||
// 1 is lowest precedence.
|
// 1 is lowest precedence.
|
||||||
|
@ -747,8 +747,8 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
|
|||||||
const std::string &VarName) {
|
const std::string &VarName) {
|
||||||
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
||||||
TheFunction->getEntryBlock().begin());
|
TheFunction->getEntryBlock().begin());
|
||||||
return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), nullptr,
|
return TmpB.CreateAlloca(Type::getDoubleTy(TheFunction->getContext()),
|
||||||
VarName.c_str());
|
nullptr, VarName.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *NumberExprAST::IRGen(IRGenContext &C) const {
|
Value *NumberExprAST::IRGen(IRGenContext &C) const {
|
||||||
@ -807,8 +807,8 @@ Value *BinaryExprAST::IRGen(IRGenContext &C) const {
|
|||||||
case '<':
|
case '<':
|
||||||
L = C.getBuilder().CreateFCmpULT(L, R, "cmptmp");
|
L = C.getBuilder().CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return C.getBuilder().CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
|
return C.getBuilder().CreateUIToFP(L, Type::getDoubleTy(C.getLLVMContext()),
|
||||||
"booltmp");
|
"booltmp");
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -885,8 +885,8 @@ Value *IfExprAST::IRGen(IRGenContext &C) const {
|
|||||||
// Emit merge block.
|
// Emit merge block.
|
||||||
TheFunction->getBasicBlockList().push_back(MergeBB);
|
TheFunction->getBasicBlockList().push_back(MergeBB);
|
||||||
C.getBuilder().SetInsertPoint(MergeBB);
|
C.getBuilder().SetInsertPoint(MergeBB);
|
||||||
PHINode *PN = C.getBuilder().CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
|
PHINode *PN = C.getBuilder().CreatePHI(Type::getDoubleTy(C.getLLVMContext()),
|
||||||
"iftmp");
|
2, "iftmp");
|
||||||
|
|
||||||
PN->addIncoming(ThenV, ThenBB);
|
PN->addIncoming(ThenV, ThenBB);
|
||||||
PN->addIncoming(ElseV, ElseBB);
|
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
|
// Make the new basic block for the loop header, inserting after current
|
||||||
// block.
|
// 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.
|
// Insert an explicit fall through from the current block to the LoopBB.
|
||||||
C.getBuilder().CreateBr(LoopBB);
|
C.getBuilder().CreateBr(LoopBB);
|
||||||
@ -954,7 +955,7 @@ Value *ForExprAST::IRGen(IRGenContext &C) const {
|
|||||||
if (!StepVal) return nullptr;
|
if (!StepVal) return nullptr;
|
||||||
} else {
|
} else {
|
||||||
// If not specified, use 1.0.
|
// 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.
|
// Compute the end condition.
|
||||||
@ -968,12 +969,12 @@ Value *ForExprAST::IRGen(IRGenContext &C) const {
|
|||||||
C.getBuilder().CreateStore(NextVar, Alloca);
|
C.getBuilder().CreateStore(NextVar, Alloca);
|
||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
EndCond = C.getBuilder().CreateFCmpONE(EndCond,
|
EndCond = C.getBuilder().CreateFCmpONE(
|
||||||
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
EndCond, ConstantFP::get(C.getLLVMContext(), APFloat(0.0)), "loopcond");
|
||||||
"loopcond");
|
|
||||||
|
|
||||||
// Create the "after loop" block and insert it.
|
// 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.
|
// Insert the conditional branch into the end of LoopEndBB.
|
||||||
C.getBuilder().CreateCondBr(EndCond, LoopBB, AfterBB);
|
C.getBuilder().CreateCondBr(EndCond, LoopBB, AfterBB);
|
||||||
@ -988,7 +989,7 @@ Value *ForExprAST::IRGen(IRGenContext &C) const {
|
|||||||
C.NamedValues.erase(VarName);
|
C.NamedValues.erase(VarName);
|
||||||
|
|
||||||
// for expr always returns 0.0.
|
// 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 {
|
Value *VarExprAST::IRGen(IRGenContext &C) const {
|
||||||
@ -1011,7 +1012,7 @@ Value *VarExprAST::IRGen(IRGenContext &C) const {
|
|||||||
InitVal = Init->IRGen(C);
|
InitVal = Init->IRGen(C);
|
||||||
if (!InitVal) return nullptr;
|
if (!InitVal) return nullptr;
|
||||||
} else // If not specified, use 0.0.
|
} 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);
|
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
|
||||||
C.getBuilder().CreateStore(InitVal, Alloca);
|
C.getBuilder().CreateStore(InitVal, Alloca);
|
||||||
@ -1040,10 +1041,10 @@ Function *PrototypeAST::IRGen(IRGenContext &C) const {
|
|||||||
std::string FnName = MakeLegalFunctionName(Name);
|
std::string FnName = MakeLegalFunctionName(Name);
|
||||||
|
|
||||||
// Make the function type: double(double,double) etc.
|
// Make the function type: double(double,double) etc.
|
||||||
std::vector<Type*> Doubles(Args.size(),
|
std::vector<Type *> Doubles(Args.size(),
|
||||||
Type::getDoubleTy(getGlobalContext()));
|
Type::getDoubleTy(C.getLLVMContext()));
|
||||||
FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()),
|
FunctionType *FT =
|
||||||
Doubles, false);
|
FunctionType::get(Type::getDoubleTy(C.getLLVMContext()), Doubles, false);
|
||||||
Function *F = Function::Create(FT, Function::ExternalLinkage, FnName,
|
Function *F = Function::Create(FT, Function::ExternalLinkage, FnName,
|
||||||
&C.getM());
|
&C.getM());
|
||||||
|
|
||||||
@ -1104,7 +1105,7 @@ Function *FunctionAST::IRGen(IRGenContext &C) const {
|
|||||||
BinopPrecedence[Proto->getOperatorName()] = Proto->Precedence;
|
BinopPrecedence[Proto->getOperatorName()] = Proto->Precedence;
|
||||||
|
|
||||||
// Create a new basic block to start insertion into.
|
// 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);
|
C.getBuilder().SetInsertPoint(BB);
|
||||||
|
|
||||||
// Add all arguments to the symbol table and create their allocas.
|
// 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 | ';'
|
/// top ::= definition | external | expression | ';'
|
||||||
static void MainLoop() {
|
static void MainLoop() {
|
||||||
SessionContext S(getGlobalContext());
|
LLVMContext TheContext;
|
||||||
|
SessionContext S(TheContext);
|
||||||
KaleidoscopeJIT J(S);
|
KaleidoscopeJIT J(S);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -746,8 +746,8 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
|
|||||||
const std::string &VarName) {
|
const std::string &VarName) {
|
||||||
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
||||||
TheFunction->getEntryBlock().begin());
|
TheFunction->getEntryBlock().begin());
|
||||||
return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), nullptr,
|
return TmpB.CreateAlloca(Type::getDoubleTy(TheFunction->getContext()),
|
||||||
VarName.c_str());
|
nullptr, VarName.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *NumberExprAST::IRGen(IRGenContext &C) const {
|
Value *NumberExprAST::IRGen(IRGenContext &C) const {
|
||||||
@ -806,8 +806,8 @@ Value *BinaryExprAST::IRGen(IRGenContext &C) const {
|
|||||||
case '<':
|
case '<':
|
||||||
L = C.getBuilder().CreateFCmpULT(L, R, "cmptmp");
|
L = C.getBuilder().CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return C.getBuilder().CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
|
return C.getBuilder().CreateUIToFP(L, Type::getDoubleTy(C.getLLVMContext()),
|
||||||
"booltmp");
|
"booltmp");
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -884,8 +884,8 @@ Value *IfExprAST::IRGen(IRGenContext &C) const {
|
|||||||
// Emit merge block.
|
// Emit merge block.
|
||||||
TheFunction->getBasicBlockList().push_back(MergeBB);
|
TheFunction->getBasicBlockList().push_back(MergeBB);
|
||||||
C.getBuilder().SetInsertPoint(MergeBB);
|
C.getBuilder().SetInsertPoint(MergeBB);
|
||||||
PHINode *PN = C.getBuilder().CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
|
PHINode *PN = C.getBuilder().CreatePHI(Type::getDoubleTy(C.getLLVMContext()),
|
||||||
"iftmp");
|
2, "iftmp");
|
||||||
|
|
||||||
PN->addIncoming(ThenV, ThenBB);
|
PN->addIncoming(ThenV, ThenBB);
|
||||||
PN->addIncoming(ElseV, ElseBB);
|
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
|
// Make the new basic block for the loop header, inserting after current
|
||||||
// block.
|
// 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.
|
// Insert an explicit fall through from the current block to the LoopBB.
|
||||||
C.getBuilder().CreateBr(LoopBB);
|
C.getBuilder().CreateBr(LoopBB);
|
||||||
@ -953,7 +954,7 @@ Value *ForExprAST::IRGen(IRGenContext &C) const {
|
|||||||
if (!StepVal) return nullptr;
|
if (!StepVal) return nullptr;
|
||||||
} else {
|
} else {
|
||||||
// If not specified, use 1.0.
|
// 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.
|
// Compute the end condition.
|
||||||
@ -967,12 +968,12 @@ Value *ForExprAST::IRGen(IRGenContext &C) const {
|
|||||||
C.getBuilder().CreateStore(NextVar, Alloca);
|
C.getBuilder().CreateStore(NextVar, Alloca);
|
||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
EndCond = C.getBuilder().CreateFCmpONE(EndCond,
|
EndCond = C.getBuilder().CreateFCmpONE(
|
||||||
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
EndCond, ConstantFP::get(C.getLLVMContext(), APFloat(0.0)), "loopcond");
|
||||||
"loopcond");
|
|
||||||
|
|
||||||
// Create the "after loop" block and insert it.
|
// 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.
|
// Insert the conditional branch into the end of LoopEndBB.
|
||||||
C.getBuilder().CreateCondBr(EndCond, LoopBB, AfterBB);
|
C.getBuilder().CreateCondBr(EndCond, LoopBB, AfterBB);
|
||||||
@ -987,7 +988,7 @@ Value *ForExprAST::IRGen(IRGenContext &C) const {
|
|||||||
C.NamedValues.erase(VarName);
|
C.NamedValues.erase(VarName);
|
||||||
|
|
||||||
// for expr always returns 0.0.
|
// 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 {
|
Value *VarExprAST::IRGen(IRGenContext &C) const {
|
||||||
@ -1010,7 +1011,7 @@ Value *VarExprAST::IRGen(IRGenContext &C) const {
|
|||||||
InitVal = Init->IRGen(C);
|
InitVal = Init->IRGen(C);
|
||||||
if (!InitVal) return nullptr;
|
if (!InitVal) return nullptr;
|
||||||
} else // If not specified, use 0.0.
|
} 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);
|
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
|
||||||
C.getBuilder().CreateStore(InitVal, Alloca);
|
C.getBuilder().CreateStore(InitVal, Alloca);
|
||||||
@ -1039,10 +1040,10 @@ Function *PrototypeAST::IRGen(IRGenContext &C) const {
|
|||||||
std::string FnName = MakeLegalFunctionName(Name);
|
std::string FnName = MakeLegalFunctionName(Name);
|
||||||
|
|
||||||
// Make the function type: double(double,double) etc.
|
// Make the function type: double(double,double) etc.
|
||||||
std::vector<Type*> Doubles(Args.size(),
|
std::vector<Type *> Doubles(Args.size(),
|
||||||
Type::getDoubleTy(getGlobalContext()));
|
Type::getDoubleTy(C.getLLVMContext()));
|
||||||
FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()),
|
FunctionType *FT =
|
||||||
Doubles, false);
|
FunctionType::get(Type::getDoubleTy(C.getLLVMContext()), Doubles, false);
|
||||||
Function *F = Function::Create(FT, Function::ExternalLinkage, FnName,
|
Function *F = Function::Create(FT, Function::ExternalLinkage, FnName,
|
||||||
&C.getM());
|
&C.getM());
|
||||||
|
|
||||||
@ -1103,7 +1104,7 @@ Function *FunctionAST::IRGen(IRGenContext &C) const {
|
|||||||
BinopPrecedence[Proto->getOperatorName()] = Proto->Precedence;
|
BinopPrecedence[Proto->getOperatorName()] = Proto->Precedence;
|
||||||
|
|
||||||
// Create a new basic block to start insertion into.
|
// 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);
|
C.getBuilder().SetInsertPoint(BB);
|
||||||
|
|
||||||
// Add all arguments to the symbol table and create their allocas.
|
// 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 | ';'
|
/// top ::= definition | external | expression | ';'
|
||||||
static void MainLoop() {
|
static void MainLoop() {
|
||||||
SessionContext S(getGlobalContext());
|
LLVMContext TheContext;
|
||||||
|
SessionContext S(TheContext);
|
||||||
KaleidoscopeJIT J(S);
|
KaleidoscopeJIT J(S);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -746,8 +746,8 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
|
|||||||
const std::string &VarName) {
|
const std::string &VarName) {
|
||||||
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
||||||
TheFunction->getEntryBlock().begin());
|
TheFunction->getEntryBlock().begin());
|
||||||
return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), nullptr,
|
return TmpB.CreateAlloca(Type::getDoubleTy(TheFunction->getContext()),
|
||||||
VarName.c_str());
|
nullptr, VarName.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *NumberExprAST::IRGen(IRGenContext &C) const {
|
Value *NumberExprAST::IRGen(IRGenContext &C) const {
|
||||||
@ -806,8 +806,8 @@ Value *BinaryExprAST::IRGen(IRGenContext &C) const {
|
|||||||
case '<':
|
case '<':
|
||||||
L = C.getBuilder().CreateFCmpULT(L, R, "cmptmp");
|
L = C.getBuilder().CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return C.getBuilder().CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
|
return C.getBuilder().CreateUIToFP(L, Type::getDoubleTy(C.getLLVMContext()),
|
||||||
"booltmp");
|
"booltmp");
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -884,8 +884,8 @@ Value *IfExprAST::IRGen(IRGenContext &C) const {
|
|||||||
// Emit merge block.
|
// Emit merge block.
|
||||||
TheFunction->getBasicBlockList().push_back(MergeBB);
|
TheFunction->getBasicBlockList().push_back(MergeBB);
|
||||||
C.getBuilder().SetInsertPoint(MergeBB);
|
C.getBuilder().SetInsertPoint(MergeBB);
|
||||||
PHINode *PN = C.getBuilder().CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
|
PHINode *PN = C.getBuilder().CreatePHI(Type::getDoubleTy(C.getLLVMContext()),
|
||||||
"iftmp");
|
2, "iftmp");
|
||||||
|
|
||||||
PN->addIncoming(ThenV, ThenBB);
|
PN->addIncoming(ThenV, ThenBB);
|
||||||
PN->addIncoming(ElseV, ElseBB);
|
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
|
// Make the new basic block for the loop header, inserting after current
|
||||||
// block.
|
// 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.
|
// Insert an explicit fall through from the current block to the LoopBB.
|
||||||
C.getBuilder().CreateBr(LoopBB);
|
C.getBuilder().CreateBr(LoopBB);
|
||||||
@ -953,7 +954,7 @@ Value *ForExprAST::IRGen(IRGenContext &C) const {
|
|||||||
if (!StepVal) return nullptr;
|
if (!StepVal) return nullptr;
|
||||||
} else {
|
} else {
|
||||||
// If not specified, use 1.0.
|
// 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.
|
// Compute the end condition.
|
||||||
@ -967,12 +968,12 @@ Value *ForExprAST::IRGen(IRGenContext &C) const {
|
|||||||
C.getBuilder().CreateStore(NextVar, Alloca);
|
C.getBuilder().CreateStore(NextVar, Alloca);
|
||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
EndCond = C.getBuilder().CreateFCmpONE(EndCond,
|
EndCond = C.getBuilder().CreateFCmpONE(
|
||||||
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
EndCond, ConstantFP::get(C.getLLVMContext(), APFloat(0.0)), "loopcond");
|
||||||
"loopcond");
|
|
||||||
|
|
||||||
// Create the "after loop" block and insert it.
|
// 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.
|
// Insert the conditional branch into the end of LoopEndBB.
|
||||||
C.getBuilder().CreateCondBr(EndCond, LoopBB, AfterBB);
|
C.getBuilder().CreateCondBr(EndCond, LoopBB, AfterBB);
|
||||||
@ -987,7 +988,7 @@ Value *ForExprAST::IRGen(IRGenContext &C) const {
|
|||||||
C.NamedValues.erase(VarName);
|
C.NamedValues.erase(VarName);
|
||||||
|
|
||||||
// for expr always returns 0.0.
|
// 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 {
|
Value *VarExprAST::IRGen(IRGenContext &C) const {
|
||||||
@ -1010,7 +1011,7 @@ Value *VarExprAST::IRGen(IRGenContext &C) const {
|
|||||||
InitVal = Init->IRGen(C);
|
InitVal = Init->IRGen(C);
|
||||||
if (!InitVal) return nullptr;
|
if (!InitVal) return nullptr;
|
||||||
} else // If not specified, use 0.0.
|
} 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);
|
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
|
||||||
C.getBuilder().CreateStore(InitVal, Alloca);
|
C.getBuilder().CreateStore(InitVal, Alloca);
|
||||||
@ -1039,10 +1040,10 @@ Function *PrototypeAST::IRGen(IRGenContext &C) const {
|
|||||||
std::string FnName = MakeLegalFunctionName(Name);
|
std::string FnName = MakeLegalFunctionName(Name);
|
||||||
|
|
||||||
// Make the function type: double(double,double) etc.
|
// Make the function type: double(double,double) etc.
|
||||||
std::vector<Type*> Doubles(Args.size(),
|
std::vector<Type *> Doubles(Args.size(),
|
||||||
Type::getDoubleTy(getGlobalContext()));
|
Type::getDoubleTy(C.getLLVMContext()));
|
||||||
FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()),
|
FunctionType *FT =
|
||||||
Doubles, false);
|
FunctionType::get(Type::getDoubleTy(C.getLLVMContext()), Doubles, false);
|
||||||
Function *F = Function::Create(FT, Function::ExternalLinkage, FnName,
|
Function *F = Function::Create(FT, Function::ExternalLinkage, FnName,
|
||||||
&C.getM());
|
&C.getM());
|
||||||
|
|
||||||
@ -1103,7 +1104,7 @@ Function *FunctionAST::IRGen(IRGenContext &C) const {
|
|||||||
BinopPrecedence[Proto->getOperatorName()] = Proto->Precedence;
|
BinopPrecedence[Proto->getOperatorName()] = Proto->Precedence;
|
||||||
|
|
||||||
// Create a new basic block to start insertion into.
|
// 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);
|
C.getBuilder().SetInsertPoint(BB);
|
||||||
|
|
||||||
// Add all arguments to the symbol table and create their allocas.
|
// 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 | ';'
|
/// top ::= definition | external | expression | ';'
|
||||||
static void MainLoop() {
|
static void MainLoop() {
|
||||||
SessionContext S(getGlobalContext());
|
LLVMContext TheContext;
|
||||||
|
SessionContext S(TheContext);
|
||||||
KaleidoscopeJIT J(S);
|
KaleidoscopeJIT J(S);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -746,8 +746,8 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
|
|||||||
const std::string &VarName) {
|
const std::string &VarName) {
|
||||||
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
|
||||||
TheFunction->getEntryBlock().begin());
|
TheFunction->getEntryBlock().begin());
|
||||||
return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), nullptr,
|
return TmpB.CreateAlloca(Type::getDoubleTy(TheFunction->getContext()),
|
||||||
VarName.c_str());
|
nullptr, VarName.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *NumberExprAST::IRGen(IRGenContext &C) const {
|
Value *NumberExprAST::IRGen(IRGenContext &C) const {
|
||||||
@ -806,8 +806,8 @@ Value *BinaryExprAST::IRGen(IRGenContext &C) const {
|
|||||||
case '<':
|
case '<':
|
||||||
L = C.getBuilder().CreateFCmpULT(L, R, "cmptmp");
|
L = C.getBuilder().CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return C.getBuilder().CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
|
return C.getBuilder().CreateUIToFP(L, Type::getDoubleTy(C.getLLVMContext()),
|
||||||
"booltmp");
|
"booltmp");
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -884,8 +884,8 @@ Value *IfExprAST::IRGen(IRGenContext &C) const {
|
|||||||
// Emit merge block.
|
// Emit merge block.
|
||||||
TheFunction->getBasicBlockList().push_back(MergeBB);
|
TheFunction->getBasicBlockList().push_back(MergeBB);
|
||||||
C.getBuilder().SetInsertPoint(MergeBB);
|
C.getBuilder().SetInsertPoint(MergeBB);
|
||||||
PHINode *PN = C.getBuilder().CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
|
PHINode *PN = C.getBuilder().CreatePHI(Type::getDoubleTy(C.getLLVMContext()),
|
||||||
"iftmp");
|
2, "iftmp");
|
||||||
|
|
||||||
PN->addIncoming(ThenV, ThenBB);
|
PN->addIncoming(ThenV, ThenBB);
|
||||||
PN->addIncoming(ElseV, ElseBB);
|
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
|
// Make the new basic block for the loop header, inserting after current
|
||||||
// block.
|
// 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.
|
// Insert an explicit fall through from the current block to the LoopBB.
|
||||||
C.getBuilder().CreateBr(LoopBB);
|
C.getBuilder().CreateBr(LoopBB);
|
||||||
@ -953,7 +954,7 @@ Value *ForExprAST::IRGen(IRGenContext &C) const {
|
|||||||
if (!StepVal) return nullptr;
|
if (!StepVal) return nullptr;
|
||||||
} else {
|
} else {
|
||||||
// If not specified, use 1.0.
|
// 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.
|
// Compute the end condition.
|
||||||
@ -967,12 +968,12 @@ Value *ForExprAST::IRGen(IRGenContext &C) const {
|
|||||||
C.getBuilder().CreateStore(NextVar, Alloca);
|
C.getBuilder().CreateStore(NextVar, Alloca);
|
||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
EndCond = C.getBuilder().CreateFCmpONE(EndCond,
|
EndCond = C.getBuilder().CreateFCmpONE(
|
||||||
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
EndCond, ConstantFP::get(C.getLLVMContext(), APFloat(0.0)), "loopcond");
|
||||||
"loopcond");
|
|
||||||
|
|
||||||
// Create the "after loop" block and insert it.
|
// 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.
|
// Insert the conditional branch into the end of LoopEndBB.
|
||||||
C.getBuilder().CreateCondBr(EndCond, LoopBB, AfterBB);
|
C.getBuilder().CreateCondBr(EndCond, LoopBB, AfterBB);
|
||||||
@ -987,7 +988,7 @@ Value *ForExprAST::IRGen(IRGenContext &C) const {
|
|||||||
C.NamedValues.erase(VarName);
|
C.NamedValues.erase(VarName);
|
||||||
|
|
||||||
// for expr always returns 0.0.
|
// 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 {
|
Value *VarExprAST::IRGen(IRGenContext &C) const {
|
||||||
@ -1010,7 +1011,7 @@ Value *VarExprAST::IRGen(IRGenContext &C) const {
|
|||||||
InitVal = Init->IRGen(C);
|
InitVal = Init->IRGen(C);
|
||||||
if (!InitVal) return nullptr;
|
if (!InitVal) return nullptr;
|
||||||
} else // If not specified, use 0.0.
|
} 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);
|
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
|
||||||
C.getBuilder().CreateStore(InitVal, Alloca);
|
C.getBuilder().CreateStore(InitVal, Alloca);
|
||||||
@ -1039,10 +1040,10 @@ Function *PrototypeAST::IRGen(IRGenContext &C) const {
|
|||||||
std::string FnName = MakeLegalFunctionName(Name);
|
std::string FnName = MakeLegalFunctionName(Name);
|
||||||
|
|
||||||
// Make the function type: double(double,double) etc.
|
// Make the function type: double(double,double) etc.
|
||||||
std::vector<Type*> Doubles(Args.size(),
|
std::vector<Type *> Doubles(Args.size(),
|
||||||
Type::getDoubleTy(getGlobalContext()));
|
Type::getDoubleTy(C.getLLVMContext()));
|
||||||
FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()),
|
FunctionType *FT =
|
||||||
Doubles, false);
|
FunctionType::get(Type::getDoubleTy(C.getLLVMContext()), Doubles, false);
|
||||||
Function *F = Function::Create(FT, Function::ExternalLinkage, FnName,
|
Function *F = Function::Create(FT, Function::ExternalLinkage, FnName,
|
||||||
&C.getM());
|
&C.getM());
|
||||||
|
|
||||||
@ -1103,7 +1104,7 @@ Function *FunctionAST::IRGen(IRGenContext &C) const {
|
|||||||
BinopPrecedence[Proto->getOperatorName()] = Proto->Precedence;
|
BinopPrecedence[Proto->getOperatorName()] = Proto->Precedence;
|
||||||
|
|
||||||
// Create a new basic block to start insertion into.
|
// 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);
|
C.getBuilder().SetInsertPoint(BB);
|
||||||
|
|
||||||
// Add all arguments to the symbol table and create their allocas.
|
// 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 | ';'
|
/// top ::= definition | external | expression | ';'
|
||||||
static void MainLoop() {
|
static void MainLoop() {
|
||||||
SessionContext S(getGlobalContext());
|
LLVMContext TheContext;
|
||||||
|
SessionContext S(TheContext);
|
||||||
KaleidoscopeJIT J(S);
|
KaleidoscopeJIT J(S);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -43,8 +43,9 @@ namespace {
|
|||||||
// to know that getenv() never returns -1, this will do the job.
|
// to know that getenv() never returns -1, this will do the job.
|
||||||
if (std::getenv("bar") != (char*) -1)
|
if (std::getenv("bar") != (char*) -1)
|
||||||
return;
|
return;
|
||||||
(void)new llvm::Module("", llvm::getGlobalContext());
|
llvm::LLVMContext Context;
|
||||||
(void)new llvm::UnreachableInst(llvm::getGlobalContext());
|
(void)new llvm::Module("", Context);
|
||||||
|
(void)new llvm::UnreachableInst(Context);
|
||||||
(void) llvm::createVerifierPass();
|
(void) llvm::createVerifierPass();
|
||||||
}
|
}
|
||||||
} ForceVMCoreLinking;
|
} ForceVMCoreLinking;
|
||||||
|
@ -25,14 +25,13 @@ using namespace llvm;
|
|||||||
Optionally returns a human-readable error message via OutMessage. */
|
Optionally returns a human-readable error message via OutMessage. */
|
||||||
LLVMBool LLVMParseBitcode(LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutModule,
|
LLVMBool LLVMParseBitcode(LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutModule,
|
||||||
char **OutMessage) {
|
char **OutMessage) {
|
||||||
return LLVMParseBitcodeInContext(wrap(&getGlobalContext()), MemBuf, OutModule,
|
return LLVMParseBitcodeInContext(LLVMGetGlobalContext(), MemBuf, OutModule,
|
||||||
OutMessage);
|
OutMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
LLVMBool LLVMParseBitcode2(LLVMMemoryBufferRef MemBuf,
|
LLVMBool LLVMParseBitcode2(LLVMMemoryBufferRef MemBuf,
|
||||||
LLVMModuleRef *OutModule) {
|
LLVMModuleRef *OutModule) {
|
||||||
return LLVMParseBitcodeInContext2(wrap(&getGlobalContext()), MemBuf,
|
return LLVMParseBitcodeInContext2(LLVMGetGlobalContext(), MemBuf, OutModule);
|
||||||
OutModule);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void diagnosticHandler(const DiagnosticInfo &DI, void *C) {
|
static void diagnosticHandler(const DiagnosticInfo &DI, void *C) {
|
||||||
|
@ -1947,6 +1947,7 @@ void CppWriter::printProgram(const std::string& fname,
|
|||||||
Out << "#include <llvm/Support/MathExtras.h>\n";
|
Out << "#include <llvm/Support/MathExtras.h>\n";
|
||||||
Out << "#include <algorithm>\n";
|
Out << "#include <algorithm>\n";
|
||||||
Out << "using namespace llvm;\n\n";
|
Out << "using namespace llvm;\n\n";
|
||||||
|
Out << "static LLVMContext TheContext;\n\n";
|
||||||
Out << "Module* " << fname << "();\n\n";
|
Out << "Module* " << fname << "();\n\n";
|
||||||
Out << "int main(int argc, char**argv) {\n";
|
Out << "int main(int argc, char**argv) {\n";
|
||||||
Out << " Module* Mod = " << fname << "();\n";
|
Out << " Module* Mod = " << fname << "();\n";
|
||||||
@ -1965,7 +1966,7 @@ void CppWriter::printModule(const std::string& fname,
|
|||||||
nl(Out,1) << "// Module Construction";
|
nl(Out,1) << "// Module Construction";
|
||||||
nl(Out) << "Module* mod = new Module(\"";
|
nl(Out) << "Module* mod = new Module(\"";
|
||||||
printEscapedString(mName);
|
printEscapedString(mName);
|
||||||
Out << "\", getGlobalContext());";
|
Out << "\", TheContext);";
|
||||||
if (!TheModule->getTargetTriple().empty()) {
|
if (!TheModule->getTargetTriple().empty()) {
|
||||||
nl(Out) << "mod->setDataLayout(\"" << TheModule->getDataLayoutStr()
|
nl(Out) << "mod->setDataLayout(\"" << TheModule->getDataLayoutStr()
|
||||||
<< "\");";
|
<< "\");";
|
||||||
|
@ -24,6 +24,9 @@
|
|||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
|
// Avoid including "llvm-c/Core.h" for compile time, fwd-declare this instead.
|
||||||
|
extern "C" LLVMContextRef LLVMGetGlobalContext(void);
|
||||||
|
|
||||||
inline TargetLibraryInfoImpl *unwrap(LLVMTargetLibraryInfoRef P) {
|
inline TargetLibraryInfoImpl *unwrap(LLVMTargetLibraryInfoRef P) {
|
||||||
return reinterpret_cast<TargetLibraryInfoImpl*>(P);
|
return reinterpret_cast<TargetLibraryInfoImpl*>(P);
|
||||||
}
|
}
|
||||||
@ -81,11 +84,11 @@ unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD) {
|
LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD) {
|
||||||
return wrap(unwrap(TD)->getIntPtrType(getGlobalContext()));
|
return wrap(unwrap(TD)->getIntPtrType(*unwrap(LLVMGetGlobalContext())));
|
||||||
}
|
}
|
||||||
|
|
||||||
LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS) {
|
LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS) {
|
||||||
return wrap(unwrap(TD)->getIntPtrType(getGlobalContext(), AS));
|
return wrap(unwrap(TD)->getIntPtrType(*unwrap(LLVMGetGlobalContext()), AS));
|
||||||
}
|
}
|
||||||
|
|
||||||
LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C, LLVMTargetDataRef TD) {
|
LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C, LLVMTargetDataRef TD) {
|
||||||
|
@ -143,7 +143,7 @@ int main(int argc, char **argv) {
|
|||||||
sys::SetInterruptFunction(BugpointInterruptFunction);
|
sys::SetInterruptFunction(BugpointInterruptFunction);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
LLVMContext& Context = getGlobalContext();
|
LLVMContext Context;
|
||||||
// If we have an override, set it and then track the triple we want Modules
|
// If we have an override, set it and then track the triple we want Modules
|
||||||
// to use.
|
// to use.
|
||||||
if (!OverrideTriple.empty()) {
|
if (!OverrideTriple.empty()) {
|
||||||
|
@ -187,7 +187,7 @@ int main(int argc, char **argv) {
|
|||||||
// Enable debug stream buffering.
|
// Enable debug stream buffering.
|
||||||
EnableDebugBuffering = true;
|
EnableDebugBuffering = true;
|
||||||
|
|
||||||
LLVMContext &Context = getGlobalContext();
|
LLVMContext Context;
|
||||||
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
||||||
|
|
||||||
// Initialize targets first, so that --version shows registered targets.
|
// Initialize targets first, so that --version shows registered targets.
|
||||||
|
@ -385,7 +385,7 @@ int main(int argc, char **argv, char * const *envp) {
|
|||||||
sys::PrintStackTraceOnErrorSignal();
|
sys::PrintStackTraceOnErrorSignal();
|
||||||
PrettyStackTraceProgram X(argc, argv);
|
PrettyStackTraceProgram X(argc, argv);
|
||||||
|
|
||||||
LLVMContext &Context = getGlobalContext();
|
LLVMContext Context;
|
||||||
atexit(do_shutdown); // Call llvm_shutdown() on exit.
|
atexit(do_shutdown); // Call llvm_shutdown() on exit.
|
||||||
|
|
||||||
// If we have a native target, initialize it to ensure it is linked in and
|
// If we have a native target, initialize it to ensure it is linked in and
|
||||||
|
@ -53,7 +53,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
|||||||
// parsed is always null terminated.
|
// parsed is always null terminated.
|
||||||
std::unique_ptr<MemoryBuffer> MemBuf = MemoryBuffer::getMemBufferCopy(Input);
|
std::unique_ptr<MemoryBuffer> MemBuf = MemoryBuffer::getMemBufferCopy(Input);
|
||||||
SMDiagnostic Err;
|
SMDiagnostic Err;
|
||||||
LLVMContext &Context = getGlobalContext();
|
LLVMContext Context;
|
||||||
std::unique_ptr<Module> M;
|
std::unique_ptr<Module> M;
|
||||||
|
|
||||||
if (setjmp(JmpBuf))
|
if (setjmp(JmpBuf))
|
||||||
|
@ -91,7 +91,7 @@ int main(int argc, char **argv) {
|
|||||||
// Print a stack trace if we signal out.
|
// Print a stack trace if we signal out.
|
||||||
sys::PrintStackTraceOnErrorSignal();
|
sys::PrintStackTraceOnErrorSignal();
|
||||||
PrettyStackTraceProgram X(argc, argv);
|
PrettyStackTraceProgram X(argc, argv);
|
||||||
LLVMContext &Context = getGlobalContext();
|
LLVMContext Context;
|
||||||
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
||||||
cl::ParseCommandLineOptions(argc, argv, "llvm .ll -> .bc assembler\n");
|
cl::ParseCommandLineOptions(argc, argv, "llvm .ll -> .bc assembler\n");
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ int main(int argc, char **argv) {
|
|||||||
sys::PrintStackTraceOnErrorSignal();
|
sys::PrintStackTraceOnErrorSignal();
|
||||||
PrettyStackTraceProgram X(argc, argv);
|
PrettyStackTraceProgram X(argc, argv);
|
||||||
|
|
||||||
LLVMContext &Context = getGlobalContext();
|
LLVMContext Context;
|
||||||
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
||||||
|
|
||||||
Context.setDiagnosticHandler(diagnosticHandler, argv[0]);
|
Context.setDiagnosticHandler(diagnosticHandler, argv[0]);
|
||||||
|
@ -105,7 +105,7 @@ int main(int argc, char **argv) {
|
|||||||
sys::PrintStackTraceOnErrorSignal();
|
sys::PrintStackTraceOnErrorSignal();
|
||||||
PrettyStackTraceProgram X(argc, argv);
|
PrettyStackTraceProgram X(argc, argv);
|
||||||
|
|
||||||
LLVMContext &Context = getGlobalContext();
|
LLVMContext Context;
|
||||||
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
||||||
cl::ParseCommandLineOptions(argc, argv, "llvm extractor\n");
|
cl::ParseCommandLineOptions(argc, argv, "llvm extractor\n");
|
||||||
|
|
||||||
|
@ -105,8 +105,6 @@ unsigned int GetNewMethodID(void) {
|
|||||||
class JitEventListenerTest {
|
class JitEventListenerTest {
|
||||||
protected:
|
protected:
|
||||||
void InitEE(const std::string &IRFile) {
|
void InitEE(const std::string &IRFile) {
|
||||||
LLVMContext &Context = getGlobalContext();
|
|
||||||
|
|
||||||
// If we have a native target, initialize it to ensure it is linked in and
|
// If we have a native target, initialize it to ensure it is linked in and
|
||||||
// usable by the JIT.
|
// usable by the JIT.
|
||||||
InitializeNativeTarget();
|
InitializeNativeTarget();
|
||||||
|
@ -331,7 +331,7 @@ int main(int argc, char **argv) {
|
|||||||
sys::PrintStackTraceOnErrorSignal();
|
sys::PrintStackTraceOnErrorSignal();
|
||||||
PrettyStackTraceProgram X(argc, argv);
|
PrettyStackTraceProgram X(argc, argv);
|
||||||
|
|
||||||
LLVMContext &Context = getGlobalContext();
|
LLVMContext Context;
|
||||||
Context.setDiagnosticHandler(diagnosticHandlerWithContext, nullptr, true);
|
Context.setDiagnosticHandler(diagnosticHandlerWithContext, nullptr, true);
|
||||||
|
|
||||||
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
||||||
|
@ -1020,7 +1020,7 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
|
|||||||
if (error(BufferOrErr.getError(), Filename))
|
if (error(BufferOrErr.getError(), Filename))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
LLVMContext &Context = getGlobalContext();
|
LLVMContext Context;
|
||||||
Expected<std::unique_ptr<Binary>> BinaryOrErr = createBinary(
|
Expected<std::unique_ptr<Binary>> BinaryOrErr = createBinary(
|
||||||
BufferOrErr.get()->getMemBufferRef(), NoLLVMBitcode ? nullptr : &Context);
|
BufferOrErr.get()->getMemBufferRef(), NoLLVMBitcode ? nullptr : &Context);
|
||||||
if (!BinaryOrErr) {
|
if (!BinaryOrErr) {
|
||||||
|
@ -164,9 +164,9 @@ static void mergeSampleProfile(const WeightedFileVector &Inputs,
|
|||||||
auto Writer = std::move(WriterOrErr.get());
|
auto Writer = std::move(WriterOrErr.get());
|
||||||
StringMap<FunctionSamples> ProfileMap;
|
StringMap<FunctionSamples> ProfileMap;
|
||||||
SmallVector<std::unique_ptr<sampleprof::SampleProfileReader>, 5> Readers;
|
SmallVector<std::unique_ptr<sampleprof::SampleProfileReader>, 5> Readers;
|
||||||
|
LLVMContext Context;
|
||||||
for (const auto &Input : Inputs) {
|
for (const auto &Input : Inputs) {
|
||||||
auto ReaderOrErr =
|
auto ReaderOrErr = SampleProfileReader::create(Input.Filename, Context);
|
||||||
SampleProfileReader::create(Input.Filename, getGlobalContext());
|
|
||||||
if (std::error_code EC = ReaderOrErr.getError())
|
if (std::error_code EC = ReaderOrErr.getError())
|
||||||
exitWithErrorCode(EC, Input.Filename);
|
exitWithErrorCode(EC, Input.Filename);
|
||||||
|
|
||||||
@ -365,7 +365,8 @@ static int showSampleProfile(std::string Filename, bool ShowCounts,
|
|||||||
bool ShowAllFunctions, std::string ShowFunction,
|
bool ShowAllFunctions, std::string ShowFunction,
|
||||||
raw_fd_ostream &OS) {
|
raw_fd_ostream &OS) {
|
||||||
using namespace sampleprof;
|
using namespace sampleprof;
|
||||||
auto ReaderOrErr = SampleProfileReader::create(Filename, getGlobalContext());
|
LLVMContext Context;
|
||||||
|
auto ReaderOrErr = SampleProfileReader::create(Filename, Context);
|
||||||
if (std::error_code EC = ReaderOrErr.getError())
|
if (std::error_code EC = ReaderOrErr.getError())
|
||||||
exitWithErrorCode(EC, Filename);
|
exitWithErrorCode(EC, Filename);
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ static cl::opt<bool>
|
|||||||
cl::desc("Split without externalizing locals"));
|
cl::desc("Split without externalizing locals"));
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
LLVMContext &Context = getGlobalContext();
|
LLVMContext Context;
|
||||||
SMDiagnostic Err;
|
SMDiagnostic Err;
|
||||||
cl::ParseCommandLineOptions(argc, argv, "LLVM module splitter\n");
|
cl::ParseCommandLineOptions(argc, argv, "LLVM module splitter\n");
|
||||||
|
|
||||||
|
@ -43,6 +43,8 @@ static cl::opt<std::string>
|
|||||||
OutputFilename("o", cl::desc("Override output filename"),
|
OutputFilename("o", cl::desc("Override output filename"),
|
||||||
cl::value_desc("filename"));
|
cl::value_desc("filename"));
|
||||||
|
|
||||||
|
static LLVMContext Context;
|
||||||
|
|
||||||
namespace cl {
|
namespace cl {
|
||||||
template <> class parser<Type*> final : public basic_parser<Type*> {
|
template <> class parser<Type*> final : public basic_parser<Type*> {
|
||||||
public:
|
public:
|
||||||
@ -50,7 +52,6 @@ public:
|
|||||||
|
|
||||||
// Parse options as IR types. Return true on error.
|
// Parse options as IR types. Return true on error.
|
||||||
bool parse(Option &O, StringRef, StringRef Arg, Type *&Value) {
|
bool parse(Option &O, StringRef, StringRef Arg, Type *&Value) {
|
||||||
auto &Context = getGlobalContext();
|
|
||||||
if (Arg == "half") Value = Type::getHalfTy(Context);
|
if (Arg == "half") Value = Type::getHalfTy(Context);
|
||||||
else if (Arg == "fp128") Value = Type::getFP128Ty(Context);
|
else if (Arg == "fp128") Value = Type::getFP128Ty(Context);
|
||||||
else if (Arg == "x86_fp80") Value = Type::getX86_FP80Ty(Context);
|
else if (Arg == "x86_fp80") Value = Type::getX86_FP80Ty(Context);
|
||||||
@ -687,7 +688,7 @@ int main(int argc, char **argv) {
|
|||||||
cl::ParseCommandLineOptions(argc, argv, "llvm codegen stress-tester\n");
|
cl::ParseCommandLineOptions(argc, argv, "llvm codegen stress-tester\n");
|
||||||
llvm_shutdown_obj Y;
|
llvm_shutdown_obj Y;
|
||||||
|
|
||||||
auto M = make_unique<Module>("/tmp/autogen.bc", getGlobalContext());
|
auto M = make_unique<Module>("/tmp/autogen.bc", Context);
|
||||||
Function *F = GenEmptyFunction(M.get());
|
Function *F = GenEmptyFunction(M.get());
|
||||||
|
|
||||||
// Pick an initial seed value
|
// Pick an initial seed value
|
||||||
|
@ -101,7 +101,8 @@ static void lto_initialize() {
|
|||||||
InitializeAllAsmPrinters();
|
InitializeAllAsmPrinters();
|
||||||
InitializeAllDisassemblers();
|
InitializeAllDisassemblers();
|
||||||
|
|
||||||
LTOContext = &getGlobalContext();
|
static LLVMContext Context;
|
||||||
|
LTOContext = &Context;
|
||||||
LTOContext->setDiagnosticHandler(diagnosticHandler, nullptr, true);
|
LTOContext->setDiagnosticHandler(diagnosticHandler, nullptr, true);
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
@ -316,7 +316,7 @@ int main(int argc, char **argv) {
|
|||||||
EnableDebugBuffering = true;
|
EnableDebugBuffering = true;
|
||||||
|
|
||||||
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
||||||
LLVMContext &Context = getGlobalContext();
|
LLVMContext Context;
|
||||||
|
|
||||||
InitializeAllTargets();
|
InitializeAllTargets();
|
||||||
InitializeAllTargetMCs();
|
InitializeAllTargetMCs();
|
||||||
|
@ -525,7 +525,7 @@ int main(int argc, char **argv) {
|
|||||||
EnableDebugBuffering = true;
|
EnableDebugBuffering = true;
|
||||||
|
|
||||||
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
||||||
LLVMContext &Context = getGlobalContext();
|
LLVMContext Context;
|
||||||
|
|
||||||
cl::ParseCommandLineOptions(argc, argv,
|
cl::ParseCommandLineOptions(argc, argv,
|
||||||
"llvm tool to verify use-list order\n");
|
"llvm tool to verify use-list order\n");
|
||||||
|
@ -207,14 +207,13 @@ TEST_F(AliasAnalysisTest, getModRefInfo) {
|
|||||||
|
|
||||||
class AAPassInfraTest : public testing::Test {
|
class AAPassInfraTest : public testing::Test {
|
||||||
protected:
|
protected:
|
||||||
LLVMContext &C;
|
LLVMContext C;
|
||||||
SMDiagnostic Err;
|
SMDiagnostic Err;
|
||||||
std::unique_ptr<Module> M;
|
std::unique_ptr<Module> M;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AAPassInfraTest()
|
AAPassInfraTest()
|
||||||
: C(getGlobalContext()),
|
: M(parseAssemblyString("define i32 @f(i32* %x, i32* %y) {\n"
|
||||||
M(parseAssemblyString("define i32 @f(i32* %x, i32* %y) {\n"
|
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" %lx = load i32, i32* %x\n"
|
" %lx = load i32, i32* %x\n"
|
||||||
" %ly = load i32, i32* %y\n"
|
" %ly = load i32, i32* %y\n"
|
||||||
|
@ -30,6 +30,7 @@ protected:
|
|||||||
std::unique_ptr<BranchProbabilityInfo> BPI;
|
std::unique_ptr<BranchProbabilityInfo> BPI;
|
||||||
std::unique_ptr<DominatorTree> DT;
|
std::unique_ptr<DominatorTree> DT;
|
||||||
std::unique_ptr<LoopInfo> LI;
|
std::unique_ptr<LoopInfo> LI;
|
||||||
|
LLVMContext C;
|
||||||
|
|
||||||
BlockFrequencyInfo buildBFI(Function &F) {
|
BlockFrequencyInfo buildBFI(Function &F) {
|
||||||
DT.reset(new DominatorTree(F));
|
DT.reset(new DominatorTree(F));
|
||||||
@ -50,7 +51,6 @@ protected:
|
|||||||
" %y2 = phi i32 [0, %bb1], [1, %bb2] \n"
|
" %y2 = phi i32 [0, %bb1], [1, %bb2] \n"
|
||||||
" ret i32 %y2\n"
|
" ret i32 %y2\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
LLVMContext &C = getGlobalContext();
|
|
||||||
SMDiagnostic Err;
|
SMDiagnostic Err;
|
||||||
return parseAssemblyString(ModuleStrig, Err, C);
|
return parseAssemblyString(ModuleStrig, Err, C);
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ class IsPotentiallyReachableTest : public testing::Test {
|
|||||||
protected:
|
protected:
|
||||||
void ParseAssembly(const char *Assembly) {
|
void ParseAssembly(const char *Assembly) {
|
||||||
SMDiagnostic Error;
|
SMDiagnostic Error;
|
||||||
M = parseAssemblyString(Assembly, Error, getGlobalContext());
|
M = parseAssemblyString(Assembly, Error, Context);
|
||||||
|
|
||||||
std::string errMsg;
|
std::string errMsg;
|
||||||
raw_string_ostream os(errMsg);
|
raw_string_ostream os(errMsg);
|
||||||
@ -112,6 +112,7 @@ protected:
|
|||||||
PM.run(*M);
|
PM.run(*M);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LLVMContext Context;
|
||||||
std::unique_ptr<Module> M;
|
std::unique_ptr<Module> M;
|
||||||
Instruction *A, *B;
|
Instruction *A, *B;
|
||||||
};
|
};
|
||||||
|
@ -209,51 +209,50 @@ struct TestFunctionPass {
|
|||||||
int &RunCount;
|
int &RunCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<Module> parseIR(const char *IR) {
|
std::unique_ptr<Module> parseIR(LLVMContext &C, const char *IR) {
|
||||||
LLVMContext &C = getGlobalContext();
|
|
||||||
SMDiagnostic Err;
|
SMDiagnostic Err;
|
||||||
return parseAssemblyString(IR, Err, C);
|
return parseAssemblyString(IR, Err, C);
|
||||||
}
|
}
|
||||||
|
|
||||||
class CGSCCPassManagerTest : public ::testing::Test {
|
class CGSCCPassManagerTest : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
|
LLVMContext Context;
|
||||||
std::unique_ptr<Module> M;
|
std::unique_ptr<Module> M;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CGSCCPassManagerTest()
|
CGSCCPassManagerTest()
|
||||||
: M(parseIR("define void @f() {\n"
|
: M(parseIR(Context, "define void @f() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @g()\n"
|
" call void @g()\n"
|
||||||
" call void @h1()\n"
|
" call void @h1()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @g() {\n"
|
"define void @g() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @g()\n"
|
" call void @g()\n"
|
||||||
" call void @x()\n"
|
" call void @x()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @h1() {\n"
|
"define void @h1() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @h2()\n"
|
" call void @h2()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @h2() {\n"
|
"define void @h2() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @h3()\n"
|
" call void @h3()\n"
|
||||||
" call void @x()\n"
|
" call void @x()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @h3() {\n"
|
"define void @h3() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @h1()\n"
|
" call void @h1()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @x() {\n"
|
"define void @x() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n")) {}
|
||||||
)) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(CGSCCPassManagerTest, Basic) {
|
TEST_F(CGSCCPassManagerTest, Basic) {
|
||||||
|
@ -44,14 +44,16 @@ template <typename Ty> void canSpecializeGraphTraitsIterators(Ty *G) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(CallGraphTest, GraphTraitsSpecialization) {
|
TEST(CallGraphTest, GraphTraitsSpecialization) {
|
||||||
Module M("", getGlobalContext());
|
LLVMContext Context;
|
||||||
|
Module M("", Context);
|
||||||
CallGraph CG(M);
|
CallGraph CG(M);
|
||||||
|
|
||||||
canSpecializeGraphTraitsIterators(&CG);
|
canSpecializeGraphTraitsIterators(&CG);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CallGraphTest, GraphTraitsConstSpecialization) {
|
TEST(CallGraphTest, GraphTraitsConstSpecialization) {
|
||||||
Module M("", getGlobalContext());
|
LLVMContext Context;
|
||||||
|
Module M("", Context);
|
||||||
CallGraph CG(M);
|
CallGraph CG(M);
|
||||||
|
|
||||||
canSpecializeGraphTraitsIterators(const_cast<const CallGraph *>(&CG));
|
canSpecializeGraphTraitsIterators(const_cast<const CallGraph *>(&CG));
|
||||||
|
@ -21,10 +21,10 @@ using namespace llvm;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::unique_ptr<Module> parseAssembly(const char *Assembly) {
|
std::unique_ptr<Module> parseAssembly(LLVMContext &Context,
|
||||||
|
const char *Assembly) {
|
||||||
SMDiagnostic Error;
|
SMDiagnostic Error;
|
||||||
std::unique_ptr<Module> M =
|
std::unique_ptr<Module> M = parseAssemblyString(Assembly, Error, Context);
|
||||||
parseAssemblyString(Assembly, Error, getGlobalContext());
|
|
||||||
|
|
||||||
std::string ErrMsg;
|
std::string ErrMsg;
|
||||||
raw_string_ostream OS(ErrMsg);
|
raw_string_ostream OS(ErrMsg);
|
||||||
@ -121,7 +121,8 @@ static const char DiamondOfTriangles[] =
|
|||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
TEST(LazyCallGraphTest, BasicGraphFormation) {
|
TEST(LazyCallGraphTest, BasicGraphFormation) {
|
||||||
std::unique_ptr<Module> M = parseAssembly(DiamondOfTriangles);
|
LLVMContext Context;
|
||||||
|
std::unique_ptr<Module> M = parseAssembly(Context, DiamondOfTriangles);
|
||||||
LazyCallGraph CG(*M);
|
LazyCallGraph CG(*M);
|
||||||
|
|
||||||
// The order of the entry nodes should be stable w.r.t. the source order of
|
// The order of the entry nodes should be stable w.r.t. the source order of
|
||||||
@ -280,21 +281,21 @@ static Function &lookupFunction(Module &M, StringRef Name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(LazyCallGraphTest, BasicGraphMutation) {
|
TEST(LazyCallGraphTest, BasicGraphMutation) {
|
||||||
std::unique_ptr<Module> M = parseAssembly(
|
LLVMContext Context;
|
||||||
"define void @a() {\n"
|
std::unique_ptr<Module> M = parseAssembly(Context, "define void @a() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @b()\n"
|
" call void @b()\n"
|
||||||
" call void @c()\n"
|
" call void @c()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @b() {\n"
|
"define void @b() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @c() {\n"
|
"define void @c() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
LazyCallGraph CG(*M);
|
LazyCallGraph CG(*M);
|
||||||
|
|
||||||
LazyCallGraph::Node &A = CG.get(lookupFunction(*M, "a"));
|
LazyCallGraph::Node &A = CG.get(lookupFunction(*M, "a"));
|
||||||
@ -328,7 +329,8 @@ TEST(LazyCallGraphTest, BasicGraphMutation) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(LazyCallGraphTest, InnerSCCFormation) {
|
TEST(LazyCallGraphTest, InnerSCCFormation) {
|
||||||
std::unique_ptr<Module> M = parseAssembly(DiamondOfTriangles);
|
LLVMContext Context;
|
||||||
|
std::unique_ptr<Module> M = parseAssembly(Context, DiamondOfTriangles);
|
||||||
LazyCallGraph CG(*M);
|
LazyCallGraph CG(*M);
|
||||||
|
|
||||||
// Now mutate the graph to connect every node into a single RefSCC to ensure
|
// Now mutate the graph to connect every node into a single RefSCC to ensure
|
||||||
@ -391,37 +393,37 @@ TEST(LazyCallGraphTest, InnerSCCFormation) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(LazyCallGraphTest, MultiArmSCC) {
|
TEST(LazyCallGraphTest, MultiArmSCC) {
|
||||||
|
LLVMContext Context;
|
||||||
// Two interlocking cycles. The really useful thing about this SCC is that it
|
// Two interlocking cycles. The really useful thing about this SCC is that it
|
||||||
// will require Tarjan's DFS to backtrack and finish processing all of the
|
// will require Tarjan's DFS to backtrack and finish processing all of the
|
||||||
// children of each node in the SCC. Since this involves call edges, both
|
// children of each node in the SCC. Since this involves call edges, both
|
||||||
// Tarjan implementations will have to successfully navigate the structure.
|
// Tarjan implementations will have to successfully navigate the structure.
|
||||||
std::unique_ptr<Module> M = parseAssembly(
|
std::unique_ptr<Module> M = parseAssembly(Context, "define void @f1() {\n"
|
||||||
"define void @f1() {\n"
|
"entry:\n"
|
||||||
"entry:\n"
|
" call void @f2()\n"
|
||||||
" call void @f2()\n"
|
" call void @f4()\n"
|
||||||
" call void @f4()\n"
|
" ret void\n"
|
||||||
" ret void\n"
|
"}\n"
|
||||||
"}\n"
|
"define void @f2() {\n"
|
||||||
"define void @f2() {\n"
|
"entry:\n"
|
||||||
"entry:\n"
|
" call void @f3()\n"
|
||||||
" call void @f3()\n"
|
" ret void\n"
|
||||||
" ret void\n"
|
"}\n"
|
||||||
"}\n"
|
"define void @f3() {\n"
|
||||||
"define void @f3() {\n"
|
"entry:\n"
|
||||||
"entry:\n"
|
" call void @f1()\n"
|
||||||
" call void @f1()\n"
|
" ret void\n"
|
||||||
" ret void\n"
|
"}\n"
|
||||||
"}\n"
|
"define void @f4() {\n"
|
||||||
"define void @f4() {\n"
|
"entry:\n"
|
||||||
"entry:\n"
|
" call void @f5()\n"
|
||||||
" call void @f5()\n"
|
" ret void\n"
|
||||||
" ret void\n"
|
"}\n"
|
||||||
"}\n"
|
"define void @f5() {\n"
|
||||||
"define void @f5() {\n"
|
"entry:\n"
|
||||||
"entry:\n"
|
" call void @f1()\n"
|
||||||
" call void @f1()\n"
|
" ret void\n"
|
||||||
" ret void\n"
|
"}\n");
|
||||||
"}\n");
|
|
||||||
LazyCallGraph CG(*M);
|
LazyCallGraph CG(*M);
|
||||||
|
|
||||||
// Force the graph to be fully expanded.
|
// Force the graph to be fully expanded.
|
||||||
@ -451,27 +453,27 @@ TEST(LazyCallGraphTest, MultiArmSCC) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(LazyCallGraphTest, OutgoingEdgeMutation) {
|
TEST(LazyCallGraphTest, OutgoingEdgeMutation) {
|
||||||
std::unique_ptr<Module> M = parseAssembly(
|
LLVMContext Context;
|
||||||
"define void @a() {\n"
|
std::unique_ptr<Module> M = parseAssembly(Context, "define void @a() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @b()\n"
|
" call void @b()\n"
|
||||||
" call void @c()\n"
|
" call void @c()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @b() {\n"
|
"define void @b() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @d()\n"
|
" call void @d()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @c() {\n"
|
"define void @c() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @d()\n"
|
" call void @d()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @d() {\n"
|
"define void @d() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
LazyCallGraph CG(*M);
|
LazyCallGraph CG(*M);
|
||||||
|
|
||||||
// Force the graph to be fully expanded.
|
// Force the graph to be fully expanded.
|
||||||
@ -575,6 +577,7 @@ TEST(LazyCallGraphTest, OutgoingEdgeMutation) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(LazyCallGraphTest, IncomingEdgeInsertion) {
|
TEST(LazyCallGraphTest, IncomingEdgeInsertion) {
|
||||||
|
LLVMContext Context;
|
||||||
// We want to ensure we can add edges even across complex diamond graphs, so
|
// We want to ensure we can add edges even across complex diamond graphs, so
|
||||||
// we use the diamond of triangles graph defined above. The ascii diagram is
|
// we use the diamond of triangles graph defined above. The ascii diagram is
|
||||||
// repeated here for easy reference.
|
// repeated here for easy reference.
|
||||||
@ -591,7 +594,7 @@ TEST(LazyCallGraphTest, IncomingEdgeInsertion) {
|
|||||||
// / \ |
|
// / \ |
|
||||||
// a3--a2 |
|
// a3--a2 |
|
||||||
//
|
//
|
||||||
std::unique_ptr<Module> M = parseAssembly(DiamondOfTriangles);
|
std::unique_ptr<Module> M = parseAssembly(Context, DiamondOfTriangles);
|
||||||
LazyCallGraph CG(*M);
|
LazyCallGraph CG(*M);
|
||||||
|
|
||||||
// Force the graph to be fully expanded.
|
// Force the graph to be fully expanded.
|
||||||
@ -668,9 +671,10 @@ TEST(LazyCallGraphTest, IncomingEdgeInsertion) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(LazyCallGraphTest, IncomingEdgeInsertionMidTraversal) {
|
TEST(LazyCallGraphTest, IncomingEdgeInsertionMidTraversal) {
|
||||||
|
LLVMContext Context;
|
||||||
// This is the same fundamental test as the previous, but we perform it
|
// This is the same fundamental test as the previous, but we perform it
|
||||||
// having only partially walked the RefSCCs of the graph.
|
// having only partially walked the RefSCCs of the graph.
|
||||||
std::unique_ptr<Module> M = parseAssembly(DiamondOfTriangles);
|
std::unique_ptr<Module> M = parseAssembly(Context, DiamondOfTriangles);
|
||||||
LazyCallGraph CG(*M);
|
LazyCallGraph CG(*M);
|
||||||
|
|
||||||
// Walk the RefSCCs until we find the one containing 'c1'.
|
// Walk the RefSCCs until we find the one containing 'c1'.
|
||||||
@ -744,22 +748,22 @@ TEST(LazyCallGraphTest, IncomingEdgeInsertionMidTraversal) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(LazyCallGraphTest, InternalEdgeMutation) {
|
TEST(LazyCallGraphTest, InternalEdgeMutation) {
|
||||||
std::unique_ptr<Module> M = parseAssembly(
|
LLVMContext Context;
|
||||||
"define void @a() {\n"
|
std::unique_ptr<Module> M = parseAssembly(Context, "define void @a() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @b()\n"
|
" call void @b()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @b() {\n"
|
"define void @b() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @c()\n"
|
" call void @c()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @c() {\n"
|
"define void @c() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @a()\n"
|
" call void @a()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
LazyCallGraph CG(*M);
|
LazyCallGraph CG(*M);
|
||||||
|
|
||||||
// Force the graph to be fully expanded.
|
// Force the graph to be fully expanded.
|
||||||
@ -824,29 +828,30 @@ TEST(LazyCallGraphTest, InternalEdgeMutation) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(LazyCallGraphTest, InternalEdgeRemoval) {
|
TEST(LazyCallGraphTest, InternalEdgeRemoval) {
|
||||||
|
LLVMContext Context;
|
||||||
// A nice fully connected (including self-edges) RefSCC.
|
// A nice fully connected (including self-edges) RefSCC.
|
||||||
std::unique_ptr<Module> M = parseAssembly(
|
std::unique_ptr<Module> M = parseAssembly(
|
||||||
"define void @a(i8** %ptr) {\n"
|
Context, "define void @a(i8** %ptr) {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" store i8* bitcast (void(i8**)* @a to i8*), i8** %ptr\n"
|
" store i8* bitcast (void(i8**)* @a to i8*), i8** %ptr\n"
|
||||||
" store i8* bitcast (void(i8**)* @b to i8*), i8** %ptr\n"
|
" store i8* bitcast (void(i8**)* @b to i8*), i8** %ptr\n"
|
||||||
" store i8* bitcast (void(i8**)* @c to i8*), i8** %ptr\n"
|
" store i8* bitcast (void(i8**)* @c to i8*), i8** %ptr\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @b(i8** %ptr) {\n"
|
"define void @b(i8** %ptr) {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" store i8* bitcast (void(i8**)* @a to i8*), i8** %ptr\n"
|
" store i8* bitcast (void(i8**)* @a to i8*), i8** %ptr\n"
|
||||||
" store i8* bitcast (void(i8**)* @b to i8*), i8** %ptr\n"
|
" store i8* bitcast (void(i8**)* @b to i8*), i8** %ptr\n"
|
||||||
" store i8* bitcast (void(i8**)* @c to i8*), i8** %ptr\n"
|
" store i8* bitcast (void(i8**)* @c to i8*), i8** %ptr\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @c(i8** %ptr) {\n"
|
"define void @c(i8** %ptr) {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" store i8* bitcast (void(i8**)* @a to i8*), i8** %ptr\n"
|
" store i8* bitcast (void(i8**)* @a to i8*), i8** %ptr\n"
|
||||||
" store i8* bitcast (void(i8**)* @b to i8*), i8** %ptr\n"
|
" store i8* bitcast (void(i8**)* @b to i8*), i8** %ptr\n"
|
||||||
" store i8* bitcast (void(i8**)* @c to i8*), i8** %ptr\n"
|
" store i8* bitcast (void(i8**)* @c to i8*), i8** %ptr\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
LazyCallGraph CG(*M);
|
LazyCallGraph CG(*M);
|
||||||
|
|
||||||
// Force the graph to be fully expanded.
|
// Force the graph to be fully expanded.
|
||||||
@ -882,29 +887,29 @@ TEST(LazyCallGraphTest, InternalEdgeRemoval) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(LazyCallGraphTest, InternalCallEdgeToRef) {
|
TEST(LazyCallGraphTest, InternalCallEdgeToRef) {
|
||||||
|
LLVMContext Context;
|
||||||
// A nice fully connected (including self-edges) SCC (and RefSCC)
|
// A nice fully connected (including self-edges) SCC (and RefSCC)
|
||||||
std::unique_ptr<Module> M = parseAssembly(
|
std::unique_ptr<Module> M = parseAssembly(Context, "define void @a() {\n"
|
||||||
"define void @a() {\n"
|
"entry:\n"
|
||||||
"entry:\n"
|
" call void @a()\n"
|
||||||
" call void @a()\n"
|
" call void @b()\n"
|
||||||
" call void @b()\n"
|
" call void @c()\n"
|
||||||
" call void @c()\n"
|
" ret void\n"
|
||||||
" ret void\n"
|
"}\n"
|
||||||
"}\n"
|
"define void @b() {\n"
|
||||||
"define void @b() {\n"
|
"entry:\n"
|
||||||
"entry:\n"
|
" call void @a()\n"
|
||||||
" call void @a()\n"
|
" call void @b()\n"
|
||||||
" call void @b()\n"
|
" call void @c()\n"
|
||||||
" call void @c()\n"
|
" ret void\n"
|
||||||
" ret void\n"
|
"}\n"
|
||||||
"}\n"
|
"define void @c() {\n"
|
||||||
"define void @c() {\n"
|
"entry:\n"
|
||||||
"entry:\n"
|
" call void @a()\n"
|
||||||
" call void @a()\n"
|
" call void @b()\n"
|
||||||
" call void @b()\n"
|
" call void @c()\n"
|
||||||
" call void @c()\n"
|
" ret void\n"
|
||||||
" ret void\n"
|
"}\n");
|
||||||
"}\n");
|
|
||||||
LazyCallGraph CG(*M);
|
LazyCallGraph CG(*M);
|
||||||
|
|
||||||
// Force the graph to be fully expanded.
|
// Force the graph to be fully expanded.
|
||||||
@ -964,33 +969,34 @@ TEST(LazyCallGraphTest, InternalCallEdgeToRef) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(LazyCallGraphTest, InternalRefEdgeToCall) {
|
TEST(LazyCallGraphTest, InternalRefEdgeToCall) {
|
||||||
|
LLVMContext Context;
|
||||||
// Basic tests for making a ref edge a call. This hits the basics of the
|
// Basic tests for making a ref edge a call. This hits the basics of the
|
||||||
// process only.
|
// process only.
|
||||||
std::unique_ptr<Module> M = parseAssembly(
|
std::unique_ptr<Module> M =
|
||||||
"define void @a() {\n"
|
parseAssembly(Context, "define void @a() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @b()\n"
|
" call void @b()\n"
|
||||||
" call void @c()\n"
|
" call void @c()\n"
|
||||||
" store void()* @d, void()** undef\n"
|
" store void()* @d, void()** undef\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @b() {\n"
|
"define void @b() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" store void()* @c, void()** undef\n"
|
" store void()* @c, void()** undef\n"
|
||||||
" call void @d()\n"
|
" call void @d()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @c() {\n"
|
"define void @c() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" store void()* @b, void()** undef\n"
|
" store void()* @b, void()** undef\n"
|
||||||
" call void @d()\n"
|
" call void @d()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @d() {\n"
|
"define void @d() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" store void()* @a, void()** undef\n"
|
" store void()* @a, void()** undef\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
LazyCallGraph CG(*M);
|
LazyCallGraph CG(*M);
|
||||||
|
|
||||||
// Force the graph to be fully expanded.
|
// Force the graph to be fully expanded.
|
||||||
@ -1049,59 +1055,60 @@ TEST(LazyCallGraphTest, InternalRefEdgeToCall) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(LazyCallGraphTest, InternalRefEdgeToCallNoCycleInterleaved) {
|
TEST(LazyCallGraphTest, InternalRefEdgeToCallNoCycleInterleaved) {
|
||||||
|
LLVMContext Context;
|
||||||
// Test for having a post-order prior to changing a ref edge to a call edge
|
// Test for having a post-order prior to changing a ref edge to a call edge
|
||||||
// with SCCs connecting to the source and connecting to the target, but not
|
// with SCCs connecting to the source and connecting to the target, but not
|
||||||
// connecting to both, interleaved between the source and target. This
|
// connecting to both, interleaved between the source and target. This
|
||||||
// ensures we correctly partition the range rather than simply moving one or
|
// ensures we correctly partition the range rather than simply moving one or
|
||||||
// the other.
|
// the other.
|
||||||
std::unique_ptr<Module> M = parseAssembly(
|
std::unique_ptr<Module> M =
|
||||||
"define void @a() {\n"
|
parseAssembly(Context, "define void @a() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @b1()\n"
|
" call void @b1()\n"
|
||||||
" call void @c1()\n"
|
" call void @c1()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @b1() {\n"
|
"define void @b1() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @c1()\n"
|
" call void @c1()\n"
|
||||||
" call void @b2()\n"
|
" call void @b2()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @c1() {\n"
|
"define void @c1() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @b2()\n"
|
" call void @b2()\n"
|
||||||
" call void @c2()\n"
|
" call void @c2()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @b2() {\n"
|
"define void @b2() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @c2()\n"
|
" call void @c2()\n"
|
||||||
" call void @b3()\n"
|
" call void @b3()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @c2() {\n"
|
"define void @c2() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @b3()\n"
|
" call void @b3()\n"
|
||||||
" call void @c3()\n"
|
" call void @c3()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @b3() {\n"
|
"define void @b3() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @c3()\n"
|
" call void @c3()\n"
|
||||||
" call void @d()\n"
|
" call void @d()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @c3() {\n"
|
"define void @c3() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" store void()* @b1, void()** undef\n"
|
" store void()* @b1, void()** undef\n"
|
||||||
" call void @d()\n"
|
" call void @d()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @d() {\n"
|
"define void @d() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" store void()* @a, void()** undef\n"
|
" store void()* @a, void()** undef\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
LazyCallGraph CG(*M);
|
LazyCallGraph CG(*M);
|
||||||
|
|
||||||
// Force the graph to be fully expanded.
|
// Force the graph to be fully expanded.
|
||||||
@ -1163,6 +1170,7 @@ TEST(LazyCallGraphTest, InternalRefEdgeToCallNoCycleInterleaved) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(LazyCallGraphTest, InternalRefEdgeToCallBothPartitionAndMerge) {
|
TEST(LazyCallGraphTest, InternalRefEdgeToCallBothPartitionAndMerge) {
|
||||||
|
LLVMContext Context;
|
||||||
// Test for having a postorder where between the source and target are all
|
// Test for having a postorder where between the source and target are all
|
||||||
// three kinds of other SCCs:
|
// three kinds of other SCCs:
|
||||||
// 1) One connected to the target only that have to be shifted below the
|
// 1) One connected to the target only that have to be shifted below the
|
||||||
@ -1190,47 +1198,47 @@ TEST(LazyCallGraphTest, InternalRefEdgeToCallBothPartitionAndMerge) {
|
|||||||
// G | G |
|
// G | G |
|
||||||
//
|
//
|
||||||
// And we form a cycle by connecting F to B.
|
// And we form a cycle by connecting F to B.
|
||||||
std::unique_ptr<Module> M = parseAssembly(
|
std::unique_ptr<Module> M =
|
||||||
"define void @a() {\n"
|
parseAssembly(Context, "define void @a() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @b()\n"
|
" call void @b()\n"
|
||||||
" call void @e()\n"
|
" call void @e()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @b() {\n"
|
"define void @b() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @c()\n"
|
" call void @c()\n"
|
||||||
" call void @d()\n"
|
" call void @d()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @c() {\n"
|
"define void @c() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @d()\n"
|
" call void @d()\n"
|
||||||
" call void @g()\n"
|
" call void @g()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @d() {\n"
|
"define void @d() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @e()\n"
|
" call void @e()\n"
|
||||||
" call void @f()\n"
|
" call void @f()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @e() {\n"
|
"define void @e() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @f()\n"
|
" call void @f()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @f() {\n"
|
"define void @f() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" store void()* @b, void()** undef\n"
|
" store void()* @b, void()** undef\n"
|
||||||
" call void @g()\n"
|
" call void @g()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @g() {\n"
|
"define void @g() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" store void()* @a, void()** undef\n"
|
" store void()* @a, void()** undef\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
LazyCallGraph CG(*M);
|
LazyCallGraph CG(*M);
|
||||||
|
|
||||||
// Force the graph to be fully expanded.
|
// Force the graph to be fully expanded.
|
||||||
|
@ -99,39 +99,39 @@ public:
|
|||||||
static StringRef name() { return "TestLoopInvalidatingPass"; }
|
static StringRef name() { return "TestLoopInvalidatingPass"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<Module> parseIR(const char *IR) {
|
std::unique_ptr<Module> parseIR(LLVMContext &C, const char *IR) {
|
||||||
LLVMContext &C = getGlobalContext();
|
|
||||||
SMDiagnostic Err;
|
SMDiagnostic Err;
|
||||||
return parseAssemblyString(IR, Err, C);
|
return parseAssemblyString(IR, Err, C);
|
||||||
}
|
}
|
||||||
|
|
||||||
class LoopPassManagerTest : public ::testing::Test {
|
class LoopPassManagerTest : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
|
LLVMContext Context;
|
||||||
std::unique_ptr<Module> M;
|
std::unique_ptr<Module> M;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LoopPassManagerTest()
|
LoopPassManagerTest()
|
||||||
: M(parseIR("define void @f() {\n"
|
: M(parseIR(Context, "define void @f() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" br label %loop.0\n"
|
" br label %loop.0\n"
|
||||||
"loop.0:\n"
|
"loop.0:\n"
|
||||||
" br i1 undef, label %loop.0.0, label %end\n"
|
" br i1 undef, label %loop.0.0, label %end\n"
|
||||||
"loop.0.0:\n"
|
"loop.0.0:\n"
|
||||||
" br i1 undef, label %loop.0.0, label %loop.0.1\n"
|
" br i1 undef, label %loop.0.0, label %loop.0.1\n"
|
||||||
"loop.0.1:\n"
|
"loop.0.1:\n"
|
||||||
" br i1 undef, label %loop.0.1, label %loop.0\n"
|
" br i1 undef, label %loop.0.1, label %loop.0\n"
|
||||||
"end:\n"
|
"end:\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"\n"
|
"\n"
|
||||||
"define void @g() {\n"
|
"define void @g() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" br label %loop.g.0\n"
|
" br label %loop.g.0\n"
|
||||||
"loop.g.0:\n"
|
"loop.g.0:\n"
|
||||||
" br i1 undef, label %loop.g.0, label %end\n"
|
" br i1 undef, label %loop.g.0, label %end\n"
|
||||||
"end:\n"
|
"end:\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n")) {}
|
"}\n")) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define EXPECT_N_ELEMENTS_EQ(N, EXPECTED, ACTUAL) \
|
#define EXPECT_N_ELEMENTS_EQ(N, EXPECTED, ACTUAL) \
|
||||||
|
@ -60,11 +60,11 @@ struct UnrollAnalyzerTest : public FunctionPass {
|
|||||||
|
|
||||||
char UnrollAnalyzerTest::ID = 0;
|
char UnrollAnalyzerTest::ID = 0;
|
||||||
|
|
||||||
std::unique_ptr<Module> makeLLVMModule(UnrollAnalyzerTest *P,
|
std::unique_ptr<Module> makeLLVMModule(LLVMContext &Context,
|
||||||
|
UnrollAnalyzerTest *P,
|
||||||
const char *ModuleStr) {
|
const char *ModuleStr) {
|
||||||
LLVMContext &C = getGlobalContext();
|
|
||||||
SMDiagnostic Err;
|
SMDiagnostic Err;
|
||||||
return parseAssemblyString(ModuleStr, Err, C);
|
return parseAssemblyString(ModuleStr, Err, Context);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(UnrollAnalyzerTest, BasicSimplifications) {
|
TEST(UnrollAnalyzerTest, BasicSimplifications) {
|
||||||
@ -86,7 +86,8 @@ TEST(UnrollAnalyzerTest, BasicSimplifications) {
|
|||||||
" ret i64 %x.lcssa\n"
|
" ret i64 %x.lcssa\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
UnrollAnalyzerTest *P = new UnrollAnalyzerTest();
|
UnrollAnalyzerTest *P = new UnrollAnalyzerTest();
|
||||||
std::unique_ptr<Module> M = makeLLVMModule(P, ModuleStr);
|
LLVMContext Context;
|
||||||
|
std::unique_ptr<Module> M = makeLLVMModule(Context, P, ModuleStr);
|
||||||
legacy::PassManager Passes;
|
legacy::PassManager Passes;
|
||||||
Passes.add(P);
|
Passes.add(P);
|
||||||
Passes.run(*M);
|
Passes.run(*M);
|
||||||
@ -148,7 +149,8 @@ TEST(UnrollAnalyzerTest, OuterLoopSimplification) {
|
|||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
UnrollAnalyzerTest *P = new UnrollAnalyzerTest();
|
UnrollAnalyzerTest *P = new UnrollAnalyzerTest();
|
||||||
std::unique_ptr<Module> M = makeLLVMModule(P, ModuleStr);
|
LLVMContext Context;
|
||||||
|
std::unique_ptr<Module> M = makeLLVMModule(Context, P, ModuleStr);
|
||||||
legacy::PassManager Passes;
|
legacy::PassManager Passes;
|
||||||
Passes.add(P);
|
Passes.add(P);
|
||||||
Passes.run(*M);
|
Passes.run(*M);
|
||||||
@ -188,7 +190,8 @@ TEST(UnrollAnalyzerTest, CmpSimplifications) {
|
|||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
UnrollAnalyzerTest *P = new UnrollAnalyzerTest();
|
UnrollAnalyzerTest *P = new UnrollAnalyzerTest();
|
||||||
std::unique_ptr<Module> M = makeLLVMModule(P, ModuleStr);
|
LLVMContext Context;
|
||||||
|
std::unique_ptr<Module> M = makeLLVMModule(Context, P, ModuleStr);
|
||||||
legacy::PassManager Passes;
|
legacy::PassManager Passes;
|
||||||
Passes.add(P);
|
Passes.add(P);
|
||||||
Passes.run(*M);
|
Passes.run(*M);
|
||||||
@ -234,7 +237,8 @@ TEST(UnrollAnalyzerTest, PtrCmpSimplifications) {
|
|||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
UnrollAnalyzerTest *P = new UnrollAnalyzerTest();
|
UnrollAnalyzerTest *P = new UnrollAnalyzerTest();
|
||||||
std::unique_ptr<Module> M = makeLLVMModule(P, ModuleStr);
|
LLVMContext Context;
|
||||||
|
std::unique_ptr<Module> M = makeLLVMModule(Context, P, ModuleStr);
|
||||||
legacy::PassManager Passes;
|
legacy::PassManager Passes;
|
||||||
Passes.add(P);
|
Passes.add(P);
|
||||||
Passes.run(*M);
|
Passes.run(*M);
|
||||||
@ -279,7 +283,8 @@ TEST(UnrollAnalyzerTest, CastSimplifications) {
|
|||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
UnrollAnalyzerTest *P = new UnrollAnalyzerTest();
|
UnrollAnalyzerTest *P = new UnrollAnalyzerTest();
|
||||||
std::unique_ptr<Module> M = makeLLVMModule(P, ModuleStr);
|
LLVMContext Context;
|
||||||
|
std::unique_ptr<Module> M = makeLLVMModule(Context, P, ModuleStr);
|
||||||
legacy::PassManager Passes;
|
legacy::PassManager Passes;
|
||||||
Passes.add(P);
|
Passes.add(P);
|
||||||
Passes.run(*M);
|
Passes.run(*M);
|
||||||
|
@ -25,7 +25,7 @@ class MatchSelectPatternTest : public testing::Test {
|
|||||||
protected:
|
protected:
|
||||||
void parseAssembly(const char *Assembly) {
|
void parseAssembly(const char *Assembly) {
|
||||||
SMDiagnostic Error;
|
SMDiagnostic Error;
|
||||||
M = parseAssemblyString(Assembly, Error, getGlobalContext());
|
M = parseAssemblyString(Assembly, Error, Context);
|
||||||
|
|
||||||
std::string errMsg;
|
std::string errMsg;
|
||||||
raw_string_ostream os(errMsg);
|
raw_string_ostream os(errMsg);
|
||||||
@ -59,6 +59,7 @@ protected:
|
|||||||
EXPECT_EQ(P.Ordered, R.Ordered);
|
EXPECT_EQ(P.Ordered, R.Ordered);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LLVMContext Context;
|
||||||
std::unique_ptr<Module> M;
|
std::unique_ptr<Module> M;
|
||||||
Instruction *A, *B;
|
Instruction *A, *B;
|
||||||
};
|
};
|
||||||
|
@ -21,7 +21,7 @@ using namespace llvm;
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
TEST(AsmParserTest, NullTerminatedInput) {
|
TEST(AsmParserTest, NullTerminatedInput) {
|
||||||
LLVMContext &Ctx = getGlobalContext();
|
LLVMContext Ctx;
|
||||||
StringRef Source = "; Empty module \n";
|
StringRef Source = "; Empty module \n";
|
||||||
SMDiagnostic Error;
|
SMDiagnostic Error;
|
||||||
auto Mod = parseAssemblyString(Source, Error, Ctx);
|
auto Mod = parseAssemblyString(Source, Error, Ctx);
|
||||||
@ -34,7 +34,7 @@ TEST(AsmParserTest, NullTerminatedInput) {
|
|||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
|
||||||
TEST(AsmParserTest, NonNullTerminatedInput) {
|
TEST(AsmParserTest, NonNullTerminatedInput) {
|
||||||
LLVMContext &Ctx = getGlobalContext();
|
LLVMContext Ctx;
|
||||||
StringRef Source = "; Empty module \n\1\2";
|
StringRef Source = "; Empty module \n\1\2";
|
||||||
SMDiagnostic Error;
|
SMDiagnostic Error;
|
||||||
std::unique_ptr<Module> Mod;
|
std::unique_ptr<Module> Mod;
|
||||||
@ -47,7 +47,7 @@ TEST(AsmParserTest, NonNullTerminatedInput) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
TEST(AsmParserTest, SlotMappingTest) {
|
TEST(AsmParserTest, SlotMappingTest) {
|
||||||
LLVMContext &Ctx = getGlobalContext();
|
LLVMContext Ctx;
|
||||||
StringRef Source = "@0 = global i32 0\n !0 = !{}\n !42 = !{i32 42}";
|
StringRef Source = "@0 = global i32 0\n !0 = !{}\n !42 = !{i32 42}";
|
||||||
SMDiagnostic Error;
|
SMDiagnostic Error;
|
||||||
SlotMapping Mapping;
|
SlotMapping Mapping;
|
||||||
@ -66,7 +66,7 @@ TEST(AsmParserTest, SlotMappingTest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(AsmParserTest, TypeAndConstantValueParsing) {
|
TEST(AsmParserTest, TypeAndConstantValueParsing) {
|
||||||
LLVMContext &Ctx = getGlobalContext();
|
LLVMContext Ctx;
|
||||||
SMDiagnostic Error;
|
SMDiagnostic Error;
|
||||||
StringRef Source = "define void @test() {\n entry:\n ret void\n}";
|
StringRef Source = "define void @test() {\n entry:\n ret void\n}";
|
||||||
auto Mod = parseAssemblyString(Source, Error, Ctx);
|
auto Mod = parseAssemblyString(Source, Error, Ctx);
|
||||||
@ -117,7 +117,7 @@ TEST(AsmParserTest, TypeAndConstantValueParsing) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(AsmParserTest, TypeAndConstantValueWithSlotMappingParsing) {
|
TEST(AsmParserTest, TypeAndConstantValueWithSlotMappingParsing) {
|
||||||
LLVMContext &Ctx = getGlobalContext();
|
LLVMContext Ctx;
|
||||||
SMDiagnostic Error;
|
SMDiagnostic Error;
|
||||||
StringRef Source =
|
StringRef Source =
|
||||||
"%st = type { i32, i32 }\n"
|
"%st = type { i32, i32 }\n"
|
||||||
@ -153,7 +153,7 @@ TEST(AsmParserTest, TypeAndConstantValueWithSlotMappingParsing) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(AsmParserTest, TypeWithSlotMappingParsing) {
|
TEST(AsmParserTest, TypeWithSlotMappingParsing) {
|
||||||
LLVMContext &Ctx = getGlobalContext();
|
LLVMContext Ctx;
|
||||||
SMDiagnostic Error;
|
SMDiagnostic Error;
|
||||||
StringRef Source =
|
StringRef Source =
|
||||||
"%st = type { i32, i32 }\n"
|
"%st = type { i32, i32 }\n"
|
||||||
@ -277,7 +277,7 @@ TEST(AsmParserTest, TypeWithSlotMappingParsing) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(AsmParserTest, TypeAtBeginningWithSlotMappingParsing) {
|
TEST(AsmParserTest, TypeAtBeginningWithSlotMappingParsing) {
|
||||||
LLVMContext &Ctx = getGlobalContext();
|
LLVMContext Ctx;
|
||||||
SMDiagnostic Error;
|
SMDiagnostic Error;
|
||||||
StringRef Source =
|
StringRef Source =
|
||||||
"%st = type { i32, i32 }\n"
|
"%st = type { i32, i32 }\n"
|
||||||
|
@ -29,10 +29,10 @@ using namespace llvm;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::unique_ptr<Module> parseAssembly(const char *Assembly) {
|
std::unique_ptr<Module> parseAssembly(LLVMContext &Context,
|
||||||
|
const char *Assembly) {
|
||||||
SMDiagnostic Error;
|
SMDiagnostic Error;
|
||||||
std::unique_ptr<Module> M =
|
std::unique_ptr<Module> M = parseAssemblyString(Assembly, Error, Context);
|
||||||
parseAssemblyString(Assembly, Error, getGlobalContext());
|
|
||||||
|
|
||||||
std::string ErrMsg;
|
std::string ErrMsg;
|
||||||
raw_string_ostream OS(ErrMsg);
|
raw_string_ostream OS(ErrMsg);
|
||||||
@ -54,7 +54,7 @@ static void writeModuleToBuffer(std::unique_ptr<Module> Mod,
|
|||||||
static std::unique_ptr<Module> getLazyModuleFromAssembly(LLVMContext &Context,
|
static std::unique_ptr<Module> getLazyModuleFromAssembly(LLVMContext &Context,
|
||||||
SmallString<1024> &Mem,
|
SmallString<1024> &Mem,
|
||||||
const char *Assembly) {
|
const char *Assembly) {
|
||||||
writeModuleToBuffer(parseAssembly(Assembly), Mem);
|
writeModuleToBuffer(parseAssembly(Context, Assembly), Mem);
|
||||||
std::unique_ptr<MemoryBuffer> Buffer =
|
std::unique_ptr<MemoryBuffer> Buffer =
|
||||||
MemoryBuffer::getMemBuffer(Mem.str(), "test", false);
|
MemoryBuffer::getMemBuffer(Mem.str(), "test", false);
|
||||||
ErrorOr<std::unique_ptr<Module>> ModuleOrErr =
|
ErrorOr<std::unique_ptr<Module>> ModuleOrErr =
|
||||||
@ -82,7 +82,7 @@ public:
|
|||||||
static std::unique_ptr<Module>
|
static std::unique_ptr<Module>
|
||||||
getStreamedModuleFromAssembly(LLVMContext &Context, SmallString<1024> &Mem,
|
getStreamedModuleFromAssembly(LLVMContext &Context, SmallString<1024> &Mem,
|
||||||
const char *Assembly) {
|
const char *Assembly) {
|
||||||
writeModuleToBuffer(parseAssembly(Assembly), Mem);
|
writeModuleToBuffer(parseAssembly(Context, Assembly), Mem);
|
||||||
std::unique_ptr<MemoryBuffer> Buffer =
|
std::unique_ptr<MemoryBuffer> Buffer =
|
||||||
MemoryBuffer::getMemBuffer(Mem.str(), "test", false);
|
MemoryBuffer::getMemBuffer(Mem.str(), "test", false);
|
||||||
auto Streamer = llvm::make_unique<BufferDataStreamer>(std::move(Buffer));
|
auto Streamer = llvm::make_unique<BufferDataStreamer>(std::move(Buffer));
|
||||||
|
@ -28,7 +28,7 @@ private:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
ExecutionEngineTest() {
|
ExecutionEngineTest() {
|
||||||
auto Owner = make_unique<Module>("<main>", getGlobalContext());
|
auto Owner = make_unique<Module>("<main>", Context);
|
||||||
M = Owner.get();
|
M = Owner.get();
|
||||||
Engine.reset(EngineBuilder(std::move(Owner)).setErrorStr(&Error).create());
|
Engine.reset(EngineBuilder(std::move(Owner)).setErrorStr(&Error).create());
|
||||||
}
|
}
|
||||||
@ -44,13 +44,13 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string Error;
|
std::string Error;
|
||||||
|
LLVMContext Context;
|
||||||
Module *M; // Owned by ExecutionEngine.
|
Module *M; // Owned by ExecutionEngine.
|
||||||
std::unique_ptr<ExecutionEngine> Engine;
|
std::unique_ptr<ExecutionEngine> Engine;
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(ExecutionEngineTest, ForwardGlobalMapping) {
|
TEST_F(ExecutionEngineTest, ForwardGlobalMapping) {
|
||||||
GlobalVariable *G1 =
|
GlobalVariable *G1 = NewExtGlobal(Type::getInt32Ty(Context), "Global1");
|
||||||
NewExtGlobal(Type::getInt32Ty(getGlobalContext()), "Global1");
|
|
||||||
int32_t Mem1 = 3;
|
int32_t Mem1 = 3;
|
||||||
Engine->addGlobalMapping(G1, &Mem1);
|
Engine->addGlobalMapping(G1, &Mem1);
|
||||||
EXPECT_EQ(&Mem1, Engine->getPointerToGlobalIfAvailable(G1));
|
EXPECT_EQ(&Mem1, Engine->getPointerToGlobalIfAvailable(G1));
|
||||||
@ -63,8 +63,7 @@ TEST_F(ExecutionEngineTest, ForwardGlobalMapping) {
|
|||||||
Engine->updateGlobalMapping(G1, &Mem2);
|
Engine->updateGlobalMapping(G1, &Mem2);
|
||||||
EXPECT_EQ(&Mem2, Engine->getPointerToGlobalIfAvailable(G1));
|
EXPECT_EQ(&Mem2, Engine->getPointerToGlobalIfAvailable(G1));
|
||||||
|
|
||||||
GlobalVariable *G2 =
|
GlobalVariable *G2 = NewExtGlobal(Type::getInt32Ty(Context), "Global1");
|
||||||
NewExtGlobal(Type::getInt32Ty(getGlobalContext()), "Global1");
|
|
||||||
EXPECT_EQ(nullptr, Engine->getPointerToGlobalIfAvailable(G2))
|
EXPECT_EQ(nullptr, Engine->getPointerToGlobalIfAvailable(G2))
|
||||||
<< "The NULL return shouldn't depend on having called"
|
<< "The NULL return shouldn't depend on having called"
|
||||||
<< " updateGlobalMapping(..., NULL)";
|
<< " updateGlobalMapping(..., NULL)";
|
||||||
@ -76,8 +75,7 @@ TEST_F(ExecutionEngineTest, ForwardGlobalMapping) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ExecutionEngineTest, ReverseGlobalMapping) {
|
TEST_F(ExecutionEngineTest, ReverseGlobalMapping) {
|
||||||
GlobalVariable *G1 =
|
GlobalVariable *G1 = NewExtGlobal(Type::getInt32Ty(Context), "Global1");
|
||||||
NewExtGlobal(Type::getInt32Ty(getGlobalContext()), "Global1");
|
|
||||||
|
|
||||||
int32_t Mem1 = 3;
|
int32_t Mem1 = 3;
|
||||||
Engine->addGlobalMapping(G1, &Mem1);
|
Engine->addGlobalMapping(G1, &Mem1);
|
||||||
@ -87,8 +85,7 @@ TEST_F(ExecutionEngineTest, ReverseGlobalMapping) {
|
|||||||
EXPECT_EQ(nullptr, Engine->getGlobalValueAtAddress(&Mem1));
|
EXPECT_EQ(nullptr, Engine->getGlobalValueAtAddress(&Mem1));
|
||||||
EXPECT_EQ(G1, Engine->getGlobalValueAtAddress(&Mem2));
|
EXPECT_EQ(G1, Engine->getGlobalValueAtAddress(&Mem2));
|
||||||
|
|
||||||
GlobalVariable *G2 =
|
GlobalVariable *G2 = NewExtGlobal(Type::getInt32Ty(Context), "Global2");
|
||||||
NewExtGlobal(Type::getInt32Ty(getGlobalContext()), "Global2");
|
|
||||||
Engine->updateGlobalMapping(G2, &Mem1);
|
Engine->updateGlobalMapping(G2, &Mem1);
|
||||||
EXPECT_EQ(G2, Engine->getGlobalValueAtAddress(&Mem1));
|
EXPECT_EQ(G2, Engine->getGlobalValueAtAddress(&Mem1));
|
||||||
EXPECT_EQ(G1, Engine->getGlobalValueAtAddress(&Mem2));
|
EXPECT_EQ(G1, Engine->getGlobalValueAtAddress(&Mem2));
|
||||||
@ -104,8 +101,7 @@ TEST_F(ExecutionEngineTest, ReverseGlobalMapping) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ExecutionEngineTest, ClearModuleMappings) {
|
TEST_F(ExecutionEngineTest, ClearModuleMappings) {
|
||||||
GlobalVariable *G1 =
|
GlobalVariable *G1 = NewExtGlobal(Type::getInt32Ty(Context), "Global1");
|
||||||
NewExtGlobal(Type::getInt32Ty(getGlobalContext()), "Global1");
|
|
||||||
|
|
||||||
int32_t Mem1 = 3;
|
int32_t Mem1 = 3;
|
||||||
Engine->addGlobalMapping(G1, &Mem1);
|
Engine->addGlobalMapping(G1, &Mem1);
|
||||||
@ -115,8 +111,7 @@ TEST_F(ExecutionEngineTest, ClearModuleMappings) {
|
|||||||
|
|
||||||
EXPECT_EQ(nullptr, Engine->getGlobalValueAtAddress(&Mem1));
|
EXPECT_EQ(nullptr, Engine->getGlobalValueAtAddress(&Mem1));
|
||||||
|
|
||||||
GlobalVariable *G2 =
|
GlobalVariable *G2 = NewExtGlobal(Type::getInt32Ty(Context), "Global2");
|
||||||
NewExtGlobal(Type::getInt32Ty(getGlobalContext()), "Global2");
|
|
||||||
// After clearing the module mappings, we can assign a new GV to the
|
// After clearing the module mappings, we can assign a new GV to the
|
||||||
// same address.
|
// same address.
|
||||||
Engine->addGlobalMapping(G2, &Mem1);
|
Engine->addGlobalMapping(G2, &Mem1);
|
||||||
@ -124,8 +119,7 @@ TEST_F(ExecutionEngineTest, ClearModuleMappings) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ExecutionEngineTest, DestructionRemovesGlobalMapping) {
|
TEST_F(ExecutionEngineTest, DestructionRemovesGlobalMapping) {
|
||||||
GlobalVariable *G1 =
|
GlobalVariable *G1 = NewExtGlobal(Type::getInt32Ty(Context), "Global1");
|
||||||
NewExtGlobal(Type::getInt32Ty(getGlobalContext()), "Global1");
|
|
||||||
int32_t Mem1 = 3;
|
int32_t Mem1 = 3;
|
||||||
Engine->addGlobalMapping(G1, &Mem1);
|
Engine->addGlobalMapping(G1, &Mem1);
|
||||||
// Make sure the reverse mapping is enabled.
|
// Make sure the reverse mapping is enabled.
|
||||||
|
@ -17,7 +17,8 @@ using namespace llvm;
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
TEST(IndirectionUtilsTest, MakeStub) {
|
TEST(IndirectionUtilsTest, MakeStub) {
|
||||||
ModuleBuilder MB(getGlobalContext(), "x86_64-apple-macosx10.10", "");
|
LLVMContext Context;
|
||||||
|
ModuleBuilder MB(Context, "x86_64-apple-macosx10.10", "");
|
||||||
Function *F = MB.createFunctionDecl<void(DummyStruct, DummyStruct)>("");
|
Function *F = MB.createFunctionDecl<void(DummyStruct, DummyStruct)>("");
|
||||||
SmallVector<AttributeSet, 4> Attrs;
|
SmallVector<AttributeSet, 4> Attrs;
|
||||||
Attrs.push_back(
|
Attrs.push_back(
|
||||||
|
@ -25,6 +25,7 @@ namespace {
|
|||||||
|
|
||||||
class ObjectLinkingLayerExecutionTest : public testing::Test,
|
class ObjectLinkingLayerExecutionTest : public testing::Test,
|
||||||
public OrcExecutionTest {
|
public OrcExecutionTest {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class SectionMemoryManagerWrapper : public SectionMemoryManager {
|
class SectionMemoryManagerWrapper : public SectionMemoryManager {
|
||||||
@ -64,9 +65,10 @@ TEST(ObjectLinkingLayerTest, TestSetProcessAllSections) {
|
|||||||
|
|
||||||
ObjectLinkingLayer<> ObjLayer;
|
ObjectLinkingLayer<> ObjLayer;
|
||||||
|
|
||||||
auto M = llvm::make_unique<Module>("", getGlobalContext());
|
LLVMContext Context;
|
||||||
|
auto M = llvm::make_unique<Module>("", Context);
|
||||||
M->setTargetTriple("x86_64-unknown-linux-gnu");
|
M->setTargetTriple("x86_64-unknown-linux-gnu");
|
||||||
Type *Int32Ty = IntegerType::get(getGlobalContext(), 32);
|
Type *Int32Ty = IntegerType::get(Context, 32);
|
||||||
GlobalVariable *GV =
|
GlobalVariable *GV =
|
||||||
new GlobalVariable(*M, Int32Ty, false, GlobalValue::ExternalLinkage,
|
new GlobalVariable(*M, Int32Ty, false, GlobalValue::ExternalLinkage,
|
||||||
ConstantInt::get(Int32Ty, 42), "foo");
|
ConstantInt::get(Int32Ty, 42), "foo");
|
||||||
@ -131,14 +133,13 @@ TEST_F(ObjectLinkingLayerExecutionTest, NoDuplicateFinalization) {
|
|||||||
// instance (for Module 1) which is unsafe, as it will prevent relocation of
|
// instance (for Module 1) which is unsafe, as it will prevent relocation of
|
||||||
// Module 2.
|
// Module 2.
|
||||||
|
|
||||||
ModuleBuilder MB1(getGlobalContext(), "", "dummy");
|
ModuleBuilder MB1(Context, "", "dummy");
|
||||||
{
|
{
|
||||||
MB1.getModule()->setDataLayout(TM->createDataLayout());
|
MB1.getModule()->setDataLayout(TM->createDataLayout());
|
||||||
Function *BarImpl = MB1.createFunctionDecl<int32_t(void)>("bar");
|
Function *BarImpl = MB1.createFunctionDecl<int32_t(void)>("bar");
|
||||||
BasicBlock *BarEntry = BasicBlock::Create(getGlobalContext(), "entry",
|
BasicBlock *BarEntry = BasicBlock::Create(Context, "entry", BarImpl);
|
||||||
BarImpl);
|
|
||||||
IRBuilder<> Builder(BarEntry);
|
IRBuilder<> Builder(BarEntry);
|
||||||
IntegerType *Int32Ty = IntegerType::get(getGlobalContext(), 32);
|
IntegerType *Int32Ty = IntegerType::get(Context, 32);
|
||||||
Value *FourtyTwo = ConstantInt::getSigned(Int32Ty, 42);
|
Value *FourtyTwo = ConstantInt::getSigned(Int32Ty, 42);
|
||||||
Builder.CreateRet(FourtyTwo);
|
Builder.CreateRet(FourtyTwo);
|
||||||
}
|
}
|
||||||
@ -147,13 +148,12 @@ TEST_F(ObjectLinkingLayerExecutionTest, NoDuplicateFinalization) {
|
|||||||
std::vector<object::ObjectFile*> Obj1Set;
|
std::vector<object::ObjectFile*> Obj1Set;
|
||||||
Obj1Set.push_back(Obj1.getBinary());
|
Obj1Set.push_back(Obj1.getBinary());
|
||||||
|
|
||||||
ModuleBuilder MB2(getGlobalContext(), "", "dummy");
|
ModuleBuilder MB2(Context, "", "dummy");
|
||||||
{
|
{
|
||||||
MB2.getModule()->setDataLayout(TM->createDataLayout());
|
MB2.getModule()->setDataLayout(TM->createDataLayout());
|
||||||
Function *BarDecl = MB2.createFunctionDecl<int32_t(void)>("bar");
|
Function *BarDecl = MB2.createFunctionDecl<int32_t(void)>("bar");
|
||||||
Function *FooImpl = MB2.createFunctionDecl<int32_t(void)>("foo");
|
Function *FooImpl = MB2.createFunctionDecl<int32_t(void)>("foo");
|
||||||
BasicBlock *FooEntry = BasicBlock::Create(getGlobalContext(), "entry",
|
BasicBlock *FooEntry = BasicBlock::Create(Context, "entry", FooImpl);
|
||||||
FooImpl);
|
|
||||||
IRBuilder<> Builder(FooEntry);
|
IRBuilder<> Builder(FooEntry);
|
||||||
Builder.CreateRet(Builder.CreateCall(BarDecl));
|
Builder.CreateRet(Builder.CreateCall(BarDecl));
|
||||||
}
|
}
|
||||||
@ -203,14 +203,13 @@ TEST_F(ObjectLinkingLayerExecutionTest, NoPrematureAllocation) {
|
|||||||
// RuntimeDyld::MemoryManager::needsToReserveAllocationSpace hook, which is
|
// RuntimeDyld::MemoryManager::needsToReserveAllocationSpace hook, which is
|
||||||
// called once per object before any sections are allocated.
|
// called once per object before any sections are allocated.
|
||||||
|
|
||||||
ModuleBuilder MB1(getGlobalContext(), "", "dummy");
|
ModuleBuilder MB1(Context, "", "dummy");
|
||||||
{
|
{
|
||||||
MB1.getModule()->setDataLayout(TM->createDataLayout());
|
MB1.getModule()->setDataLayout(TM->createDataLayout());
|
||||||
Function *BarImpl = MB1.createFunctionDecl<int32_t(void)>("foo");
|
Function *BarImpl = MB1.createFunctionDecl<int32_t(void)>("foo");
|
||||||
BasicBlock *BarEntry = BasicBlock::Create(getGlobalContext(), "entry",
|
BasicBlock *BarEntry = BasicBlock::Create(Context, "entry", BarImpl);
|
||||||
BarImpl);
|
|
||||||
IRBuilder<> Builder(BarEntry);
|
IRBuilder<> Builder(BarEntry);
|
||||||
IntegerType *Int32Ty = IntegerType::get(getGlobalContext(), 32);
|
IntegerType *Int32Ty = IntegerType::get(Context, 32);
|
||||||
Value *FourtyTwo = ConstantInt::getSigned(Int32Ty, 42);
|
Value *FourtyTwo = ConstantInt::getSigned(Int32Ty, 42);
|
||||||
Builder.CreateRet(FourtyTwo);
|
Builder.CreateRet(FourtyTwo);
|
||||||
}
|
}
|
||||||
@ -219,14 +218,13 @@ TEST_F(ObjectLinkingLayerExecutionTest, NoPrematureAllocation) {
|
|||||||
std::vector<object::ObjectFile*> Obj1Set;
|
std::vector<object::ObjectFile*> Obj1Set;
|
||||||
Obj1Set.push_back(Obj1.getBinary());
|
Obj1Set.push_back(Obj1.getBinary());
|
||||||
|
|
||||||
ModuleBuilder MB2(getGlobalContext(), "", "dummy");
|
ModuleBuilder MB2(Context, "", "dummy");
|
||||||
{
|
{
|
||||||
MB2.getModule()->setDataLayout(TM->createDataLayout());
|
MB2.getModule()->setDataLayout(TM->createDataLayout());
|
||||||
Function *BarImpl = MB2.createFunctionDecl<int32_t(void)>("bar");
|
Function *BarImpl = MB2.createFunctionDecl<int32_t(void)>("bar");
|
||||||
BasicBlock *BarEntry = BasicBlock::Create(getGlobalContext(), "entry",
|
BasicBlock *BarEntry = BasicBlock::Create(Context, "entry", BarImpl);
|
||||||
BarImpl);
|
|
||||||
IRBuilder<> Builder(BarEntry);
|
IRBuilder<> Builder(BarEntry);
|
||||||
IntegerType *Int32Ty = IntegerType::get(getGlobalContext(), 32);
|
IntegerType *Int32Ty = IntegerType::get(Context, 32);
|
||||||
Value *Seven = ConstantInt::getSigned(Int32Ty, 7);
|
Value *Seven = ConstantInt::getSigned(Int32Ty, 7);
|
||||||
Builder.CreateRet(Seven);
|
Builder.CreateRet(Seven);
|
||||||
}
|
}
|
||||||
|
@ -25,11 +25,11 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(TargetMachine, LLVMTargetMachineRef)
|
|||||||
class OrcCAPIExecutionTest : public testing::Test, public OrcExecutionTest {
|
class OrcCAPIExecutionTest : public testing::Test, public OrcExecutionTest {
|
||||||
protected:
|
protected:
|
||||||
std::unique_ptr<Module> createTestModule(const Triple &TT) {
|
std::unique_ptr<Module> createTestModule(const Triple &TT) {
|
||||||
ModuleBuilder MB(getGlobalContext(), TT.str(), "");
|
ModuleBuilder MB(Context, TT.str(), "");
|
||||||
Function *TestFunc = MB.createFunctionDecl<int()>("testFunc");
|
Function *TestFunc = MB.createFunctionDecl<int()>("testFunc");
|
||||||
Function *Main = MB.createFunctionDecl<int(int, char*[])>("main");
|
Function *Main = MB.createFunctionDecl<int(int, char*[])>("main");
|
||||||
|
|
||||||
Main->getBasicBlockList().push_back(BasicBlock::Create(getGlobalContext()));
|
Main->getBasicBlockList().push_back(BasicBlock::Create(Context));
|
||||||
IRBuilder<> B(&Main->back());
|
IRBuilder<> B(&Main->back());
|
||||||
Value* Result = B.CreateCall(TestFunc);
|
Value* Result = B.CreateCall(TestFunc);
|
||||||
B.CreateRet(Result);
|
B.CreateRet(Result);
|
||||||
|
@ -54,6 +54,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
LLVMContext Context;
|
||||||
std::unique_ptr<TargetMachine> TM;
|
std::unique_ptr<TargetMachine> TM;
|
||||||
private:
|
private:
|
||||||
static bool NativeTargetInitialized;
|
static bool NativeTargetInitialized;
|
||||||
|
@ -22,7 +22,8 @@ namespace llvm {
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
TEST(ConstantsTest, Integer_i1) {
|
TEST(ConstantsTest, Integer_i1) {
|
||||||
IntegerType* Int1 = IntegerType::get(getGlobalContext(), 1);
|
LLVMContext Context;
|
||||||
|
IntegerType *Int1 = IntegerType::get(Context, 1);
|
||||||
Constant* One = ConstantInt::get(Int1, 1, true);
|
Constant* One = ConstantInt::get(Int1, 1, true);
|
||||||
Constant* Zero = ConstantInt::get(Int1, 0);
|
Constant* Zero = ConstantInt::get(Int1, 0);
|
||||||
Constant* NegOne = ConstantInt::get(Int1, static_cast<uint64_t>(-1), true);
|
Constant* NegOne = ConstantInt::get(Int1, static_cast<uint64_t>(-1), true);
|
||||||
@ -103,7 +104,8 @@ TEST(ConstantsTest, Integer_i1) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(ConstantsTest, IntSigns) {
|
TEST(ConstantsTest, IntSigns) {
|
||||||
IntegerType* Int8Ty = Type::getInt8Ty(getGlobalContext());
|
LLVMContext Context;
|
||||||
|
IntegerType *Int8Ty = Type::getInt8Ty(Context);
|
||||||
EXPECT_EQ(100, ConstantInt::get(Int8Ty, 100, false)->getSExtValue());
|
EXPECT_EQ(100, ConstantInt::get(Int8Ty, 100, false)->getSExtValue());
|
||||||
EXPECT_EQ(100, ConstantInt::get(Int8Ty, 100, true)->getSExtValue());
|
EXPECT_EQ(100, ConstantInt::get(Int8Ty, 100, true)->getSExtValue());
|
||||||
EXPECT_EQ(100, ConstantInt::getSigned(Int8Ty, 100)->getSExtValue());
|
EXPECT_EQ(100, ConstantInt::getSigned(Int8Ty, 100)->getSExtValue());
|
||||||
@ -116,16 +118,17 @@ TEST(ConstantsTest, IntSigns) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(ConstantsTest, FP128Test) {
|
TEST(ConstantsTest, FP128Test) {
|
||||||
Type *FP128Ty = Type::getFP128Ty(getGlobalContext());
|
LLVMContext Context;
|
||||||
|
Type *FP128Ty = Type::getFP128Ty(Context);
|
||||||
|
|
||||||
IntegerType *Int128Ty = Type::getIntNTy(getGlobalContext(), 128);
|
IntegerType *Int128Ty = Type::getIntNTy(Context, 128);
|
||||||
Constant *Zero128 = Constant::getNullValue(Int128Ty);
|
Constant *Zero128 = Constant::getNullValue(Int128Ty);
|
||||||
Constant *X = ConstantExpr::getUIToFP(Zero128, FP128Ty);
|
Constant *X = ConstantExpr::getUIToFP(Zero128, FP128Ty);
|
||||||
EXPECT_TRUE(isa<ConstantFP>(X));
|
EXPECT_TRUE(isa<ConstantFP>(X));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ConstantsTest, PointerCast) {
|
TEST(ConstantsTest, PointerCast) {
|
||||||
LLVMContext &C(getGlobalContext());
|
LLVMContext C;
|
||||||
Type *Int8PtrTy = Type::getInt8PtrTy(C);
|
Type *Int8PtrTy = Type::getInt8PtrTy(C);
|
||||||
Type *Int32PtrTy = Type::getInt32PtrTy(C);
|
Type *Int32PtrTy = Type::getInt32PtrTy(C);
|
||||||
Type *Int64Ty = Type::getInt64Ty(C);
|
Type *Int64Ty = Type::getInt64Ty(C);
|
||||||
@ -165,14 +168,15 @@ TEST(ConstantsTest, PointerCast) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(ConstantsTest, AsInstructionsTest) {
|
TEST(ConstantsTest, AsInstructionsTest) {
|
||||||
std::unique_ptr<Module> M(new Module("MyModule", getGlobalContext()));
|
LLVMContext Context;
|
||||||
|
std::unique_ptr<Module> M(new Module("MyModule", Context));
|
||||||
|
|
||||||
Type *Int64Ty = Type::getInt64Ty(getGlobalContext());
|
Type *Int64Ty = Type::getInt64Ty(Context);
|
||||||
Type *Int32Ty = Type::getInt32Ty(getGlobalContext());
|
Type *Int32Ty = Type::getInt32Ty(Context);
|
||||||
Type *Int16Ty = Type::getInt16Ty(getGlobalContext());
|
Type *Int16Ty = Type::getInt16Ty(Context);
|
||||||
Type *Int1Ty = Type::getInt1Ty(getGlobalContext());
|
Type *Int1Ty = Type::getInt1Ty(Context);
|
||||||
Type *FloatTy = Type::getFloatTy(getGlobalContext());
|
Type *FloatTy = Type::getFloatTy(Context);
|
||||||
Type *DoubleTy = Type::getDoubleTy(getGlobalContext());
|
Type *DoubleTy = Type::getDoubleTy(Context);
|
||||||
|
|
||||||
Constant *Global = M->getOrInsertGlobal("dummy",
|
Constant *Global = M->getOrInsertGlobal("dummy",
|
||||||
PointerType::getUnqual(Int32Ty));
|
PointerType::getUnqual(Int32Ty));
|
||||||
@ -189,8 +193,7 @@ TEST(ConstantsTest, AsInstructionsTest) {
|
|||||||
|
|
||||||
Constant *One = ConstantInt::get(Int32Ty, 1);
|
Constant *One = ConstantInt::get(Int32Ty, 1);
|
||||||
Constant *Two = ConstantInt::get(Int64Ty, 2);
|
Constant *Two = ConstantInt::get(Int64Ty, 2);
|
||||||
Constant *Big = ConstantInt::get(getGlobalContext(),
|
Constant *Big = ConstantInt::get(Context, APInt{256, uint64_t(-1), true});
|
||||||
APInt{256, uint64_t(-1), true});
|
|
||||||
Constant *Elt = ConstantInt::get(Int16Ty, 2015);
|
Constant *Elt = ConstantInt::get(Int16Ty, 2015);
|
||||||
Constant *Undef16 = UndefValue::get(Int16Ty);
|
Constant *Undef16 = UndefValue::get(Int16Ty);
|
||||||
Constant *Undef64 = UndefValue::get(Int64Ty);
|
Constant *Undef64 = UndefValue::get(Int64Ty);
|
||||||
@ -278,9 +281,10 @@ TEST(ConstantsTest, AsInstructionsTest) {
|
|||||||
#ifdef GTEST_HAS_DEATH_TEST
|
#ifdef GTEST_HAS_DEATH_TEST
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
TEST(ConstantsTest, ReplaceWithConstantTest) {
|
TEST(ConstantsTest, ReplaceWithConstantTest) {
|
||||||
std::unique_ptr<Module> M(new Module("MyModule", getGlobalContext()));
|
LLVMContext Context;
|
||||||
|
std::unique_ptr<Module> M(new Module("MyModule", Context));
|
||||||
|
|
||||||
Type *Int32Ty = Type::getInt32Ty(getGlobalContext());
|
Type *Int32Ty = Type::getInt32Ty(Context);
|
||||||
Constant *One = ConstantInt::get(Int32Ty, 1);
|
Constant *One = ConstantInt::get(Int32Ty, 1);
|
||||||
|
|
||||||
Constant *Global =
|
Constant *Global =
|
||||||
|
@ -215,7 +215,7 @@ namespace llvm {
|
|||||||
};
|
};
|
||||||
char DPass::ID = 0;
|
char DPass::ID = 0;
|
||||||
|
|
||||||
std::unique_ptr<Module> makeLLVMModule(DPass *P) {
|
std::unique_ptr<Module> makeLLVMModule(LLVMContext &Context, DPass *P) {
|
||||||
const char *ModuleStrig =
|
const char *ModuleStrig =
|
||||||
"declare i32 @g()\n" \
|
"declare i32 @g()\n" \
|
||||||
"define void @f(i32 %x) personality i32 ()* @g {\n" \
|
"define void @f(i32 %x) personality i32 ()* @g {\n" \
|
||||||
@ -239,14 +239,14 @@ namespace llvm {
|
|||||||
" %y9 = phi i32 [0, %bb2], [%y4, %bb1]\n"
|
" %y9 = phi i32 [0, %bb2], [%y4, %bb1]\n"
|
||||||
" ret void\n" \
|
" ret void\n" \
|
||||||
"}\n";
|
"}\n";
|
||||||
LLVMContext &C = getGlobalContext();
|
|
||||||
SMDiagnostic Err;
|
SMDiagnostic Err;
|
||||||
return parseAssemblyString(ModuleStrig, Err, C);
|
return parseAssemblyString(ModuleStrig, Err, Context);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(DominatorTree, Unreachable) {
|
TEST(DominatorTree, Unreachable) {
|
||||||
DPass *P = new DPass();
|
DPass *P = new DPass();
|
||||||
std::unique_ptr<Module> M = makeLLVMModule(P);
|
LLVMContext Context;
|
||||||
|
std::unique_ptr<Module> M = makeLLVMModule(Context, P);
|
||||||
legacy::PassManager Passes;
|
legacy::PassManager Passes;
|
||||||
Passes.add(P);
|
Passes.add(P);
|
||||||
Passes.run(*M);
|
Passes.run(*M);
|
||||||
|
@ -27,7 +27,7 @@ namespace llvm {
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
TEST(InstructionsTest, ReturnInst) {
|
TEST(InstructionsTest, ReturnInst) {
|
||||||
LLVMContext &C(getGlobalContext());
|
LLVMContext C;
|
||||||
|
|
||||||
// test for PR6589
|
// test for PR6589
|
||||||
const ReturnInst* r0 = ReturnInst::Create(C);
|
const ReturnInst* r0 = ReturnInst::Create(C);
|
||||||
@ -103,7 +103,7 @@ TEST_F(ModuleWithFunctionTest, InvokeInst) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(InstructionsTest, BranchInst) {
|
TEST(InstructionsTest, BranchInst) {
|
||||||
LLVMContext &C(getGlobalContext());
|
LLVMContext C;
|
||||||
|
|
||||||
// Make a BasicBlocks
|
// Make a BasicBlocks
|
||||||
BasicBlock* bb0 = BasicBlock::Create(C);
|
BasicBlock* bb0 = BasicBlock::Create(C);
|
||||||
@ -169,7 +169,7 @@ TEST(InstructionsTest, BranchInst) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(InstructionsTest, CastInst) {
|
TEST(InstructionsTest, CastInst) {
|
||||||
LLVMContext &C(getGlobalContext());
|
LLVMContext C;
|
||||||
|
|
||||||
Type *Int8Ty = Type::getInt8Ty(C);
|
Type *Int8Ty = Type::getInt8Ty(C);
|
||||||
Type *Int16Ty = Type::getInt16Ty(C);
|
Type *Int16Ty = Type::getInt16Ty(C);
|
||||||
@ -281,14 +281,18 @@ TEST(InstructionsTest, CastInst) {
|
|||||||
// First form
|
// First form
|
||||||
BasicBlock *BB = BasicBlock::Create(C);
|
BasicBlock *BB = BasicBlock::Create(C);
|
||||||
Constant *NullV2I32Ptr = Constant::getNullValue(V2Int32PtrTy);
|
Constant *NullV2I32Ptr = Constant::getNullValue(V2Int32PtrTy);
|
||||||
CastInst::CreatePointerCast(NullV2I32Ptr, V2Int32Ty, "foo", BB);
|
auto Inst1 = CastInst::CreatePointerCast(NullV2I32Ptr, V2Int32Ty, "foo", BB);
|
||||||
|
|
||||||
// Second form
|
// Second form
|
||||||
CastInst::CreatePointerCast(NullV2I32Ptr, V2Int32Ty);
|
auto Inst2 = CastInst::CreatePointerCast(NullV2I32Ptr, V2Int32Ty);
|
||||||
|
|
||||||
|
delete Inst2;
|
||||||
|
Inst1->eraseFromParent();
|
||||||
|
delete BB;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(InstructionsTest, VectorGep) {
|
TEST(InstructionsTest, VectorGep) {
|
||||||
LLVMContext &C(getGlobalContext());
|
LLVMContext C;
|
||||||
|
|
||||||
// Type Definitions
|
// Type Definitions
|
||||||
Type *I8Ty = IntegerType::get(C, 8);
|
Type *I8Ty = IntegerType::get(C, 8);
|
||||||
@ -391,7 +395,7 @@ TEST(InstructionsTest, VectorGep) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(InstructionsTest, FPMathOperator) {
|
TEST(InstructionsTest, FPMathOperator) {
|
||||||
LLVMContext &Context = getGlobalContext();
|
LLVMContext Context;
|
||||||
IRBuilder<> Builder(Context);
|
IRBuilder<> Builder(Context);
|
||||||
MDBuilder MDHelper(Context);
|
MDBuilder MDHelper(Context);
|
||||||
Instruction *I = Builder.CreatePHI(Builder.getDoubleTy(), 0);
|
Instruction *I = Builder.CreatePHI(Builder.getDoubleTy(), 0);
|
||||||
@ -406,7 +410,7 @@ TEST(InstructionsTest, FPMathOperator) {
|
|||||||
|
|
||||||
|
|
||||||
TEST(InstructionsTest, isEliminableCastPair) {
|
TEST(InstructionsTest, isEliminableCastPair) {
|
||||||
LLVMContext &C(getGlobalContext());
|
LLVMContext C;
|
||||||
|
|
||||||
Type* Int16Ty = Type::getInt16Ty(C);
|
Type* Int16Ty = Type::getInt16Ty(C);
|
||||||
Type* Int32Ty = Type::getInt32Ty(C);
|
Type* Int32Ty = Type::getInt32Ty(C);
|
||||||
@ -486,7 +490,7 @@ TEST(InstructionsTest, isEliminableCastPair) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(InstructionsTest, CloneCall) {
|
TEST(InstructionsTest, CloneCall) {
|
||||||
LLVMContext &C(getGlobalContext());
|
LLVMContext C;
|
||||||
Type *Int32Ty = Type::getInt32Ty(C);
|
Type *Int32Ty = Type::getInt32Ty(C);
|
||||||
Type *ArgTys[] = {Int32Ty, Int32Ty, Int32Ty};
|
Type *ArgTys[] = {Int32Ty, Int32Ty, Int32Ty};
|
||||||
Type *FnTy = FunctionType::get(Int32Ty, ArgTys, /*isVarArg=*/false);
|
Type *FnTy = FunctionType::get(Int32Ty, ArgTys, /*isVarArg=*/false);
|
||||||
@ -519,7 +523,7 @@ TEST(InstructionsTest, CloneCall) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(InstructionsTest, AlterCallBundles) {
|
TEST(InstructionsTest, AlterCallBundles) {
|
||||||
LLVMContext &C(getGlobalContext());
|
LLVMContext C;
|
||||||
Type *Int32Ty = Type::getInt32Ty(C);
|
Type *Int32Ty = Type::getInt32Ty(C);
|
||||||
Type *FnTy = FunctionType::get(Int32Ty, Int32Ty, /*isVarArg=*/false);
|
Type *FnTy = FunctionType::get(Int32Ty, Int32Ty, /*isVarArg=*/false);
|
||||||
Value *Callee = Constant::getNullValue(FnTy->getPointerTo());
|
Value *Callee = Constant::getNullValue(FnTy->getPointerTo());
|
||||||
@ -546,7 +550,7 @@ TEST(InstructionsTest, AlterCallBundles) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(InstructionsTest, AlterInvokeBundles) {
|
TEST(InstructionsTest, AlterInvokeBundles) {
|
||||||
LLVMContext &C(getGlobalContext());
|
LLVMContext C;
|
||||||
Type *Int32Ty = Type::getInt32Ty(C);
|
Type *Int32Ty = Type::getInt32Ty(C);
|
||||||
Type *FnTy = FunctionType::get(Int32Ty, Int32Ty, /*isVarArg=*/false);
|
Type *FnTy = FunctionType::get(Int32Ty, Int32Ty, /*isVarArg=*/false);
|
||||||
Value *Callee = Constant::getNullValue(FnTy->getPointerTo());
|
Value *Callee = Constant::getNullValue(FnTy->getPointerTo());
|
||||||
|
@ -288,7 +288,8 @@ namespace llvm {
|
|||||||
char OnTheFlyTest::ID=0;
|
char OnTheFlyTest::ID=0;
|
||||||
|
|
||||||
TEST(PassManager, RunOnce) {
|
TEST(PassManager, RunOnce) {
|
||||||
Module M("test-once", getGlobalContext());
|
LLVMContext Context;
|
||||||
|
Module M("test-once", Context);
|
||||||
struct ModuleNDNM *mNDNM = new ModuleNDNM();
|
struct ModuleNDNM *mNDNM = new ModuleNDNM();
|
||||||
struct ModuleDNM *mDNM = new ModuleDNM();
|
struct ModuleDNM *mDNM = new ModuleDNM();
|
||||||
struct ModuleNDM *mNDM = new ModuleNDM();
|
struct ModuleNDM *mNDM = new ModuleNDM();
|
||||||
@ -311,7 +312,8 @@ namespace llvm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(PassManager, ReRun) {
|
TEST(PassManager, ReRun) {
|
||||||
Module M("test-rerun", getGlobalContext());
|
LLVMContext Context;
|
||||||
|
Module M("test-rerun", Context);
|
||||||
struct ModuleNDNM *mNDNM = new ModuleNDNM();
|
struct ModuleNDNM *mNDNM = new ModuleNDNM();
|
||||||
struct ModuleDNM *mDNM = new ModuleDNM();
|
struct ModuleDNM *mDNM = new ModuleDNM();
|
||||||
struct ModuleNDM *mNDM = new ModuleNDM();
|
struct ModuleNDM *mNDM = new ModuleNDM();
|
||||||
@ -334,11 +336,12 @@ namespace llvm {
|
|||||||
EXPECT_EQ(1, mDNM->run);
|
EXPECT_EQ(1, mDNM->run);
|
||||||
}
|
}
|
||||||
|
|
||||||
Module* makeLLVMModule();
|
Module *makeLLVMModule(LLVMContext &Context);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void MemoryTestHelper(int run) {
|
void MemoryTestHelper(int run) {
|
||||||
std::unique_ptr<Module> M(makeLLVMModule());
|
LLVMContext Context;
|
||||||
|
std::unique_ptr<Module> M(makeLLVMModule(Context));
|
||||||
T *P = new T();
|
T *P = new T();
|
||||||
legacy::PassManager Passes;
|
legacy::PassManager Passes;
|
||||||
Passes.add(P);
|
Passes.add(P);
|
||||||
@ -348,7 +351,8 @@ namespace llvm {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void MemoryTestHelper(int run, int N) {
|
void MemoryTestHelper(int run, int N) {
|
||||||
Module *M = makeLLVMModule();
|
LLVMContext Context;
|
||||||
|
Module *M = makeLLVMModule(Context);
|
||||||
T *P = new T();
|
T *P = new T();
|
||||||
legacy::PassManager Passes;
|
legacy::PassManager Passes;
|
||||||
Passes.add(P);
|
Passes.add(P);
|
||||||
@ -383,7 +387,8 @@ namespace llvm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(PassManager, MemoryOnTheFly) {
|
TEST(PassManager, MemoryOnTheFly) {
|
||||||
Module *M = makeLLVMModule();
|
LLVMContext Context;
|
||||||
|
Module *M = makeLLVMModule(Context);
|
||||||
{
|
{
|
||||||
SCOPED_TRACE("Running OnTheFlyTest");
|
SCOPED_TRACE("Running OnTheFlyTest");
|
||||||
struct OnTheFlyTest *O = new OnTheFlyTest();
|
struct OnTheFlyTest *O = new OnTheFlyTest();
|
||||||
@ -396,9 +401,9 @@ namespace llvm {
|
|||||||
delete M;
|
delete M;
|
||||||
}
|
}
|
||||||
|
|
||||||
Module* makeLLVMModule() {
|
Module *makeLLVMModule(LLVMContext &Context) {
|
||||||
// Module Construction
|
// Module Construction
|
||||||
Module* mod = new Module("test-mem", getGlobalContext());
|
Module *mod = new Module("test-mem", Context);
|
||||||
mod->setDataLayout("e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
|
mod->setDataLayout("e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
|
||||||
"i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
|
"i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
|
||||||
"a:0:64-s:64:64-f80:128:128");
|
"a:0:64-s:64:64-f80:128:128");
|
||||||
@ -406,18 +411,17 @@ namespace llvm {
|
|||||||
|
|
||||||
// Type Definitions
|
// Type Definitions
|
||||||
std::vector<Type*>FuncTy_0_args;
|
std::vector<Type*>FuncTy_0_args;
|
||||||
FunctionType* FuncTy_0 = FunctionType::get(
|
FunctionType *FuncTy_0 = FunctionType::get(
|
||||||
/*Result=*/IntegerType::get(getGlobalContext(), 32),
|
/*Result=*/IntegerType::get(Context, 32),
|
||||||
/*Params=*/FuncTy_0_args,
|
/*Params=*/FuncTy_0_args,
|
||||||
/*isVarArg=*/false);
|
/*isVarArg=*/false);
|
||||||
|
|
||||||
std::vector<Type*>FuncTy_2_args;
|
std::vector<Type*>FuncTy_2_args;
|
||||||
FuncTy_2_args.push_back(IntegerType::get(getGlobalContext(), 1));
|
FuncTy_2_args.push_back(IntegerType::get(Context, 1));
|
||||||
FunctionType* FuncTy_2 = FunctionType::get(
|
FunctionType *FuncTy_2 = FunctionType::get(
|
||||||
/*Result=*/Type::getVoidTy(getGlobalContext()),
|
/*Result=*/Type::getVoidTy(Context),
|
||||||
/*Params=*/FuncTy_2_args,
|
/*Params=*/FuncTy_2_args,
|
||||||
/*isVarArg=*/false);
|
/*isVarArg=*/false);
|
||||||
|
|
||||||
|
|
||||||
// Function Declarations
|
// Function Declarations
|
||||||
|
|
||||||
@ -465,7 +469,8 @@ namespace llvm {
|
|||||||
// Function: test1 (func_test1)
|
// Function: test1 (func_test1)
|
||||||
{
|
{
|
||||||
|
|
||||||
BasicBlock* label_entry = BasicBlock::Create(getGlobalContext(), "entry",func_test1,nullptr);
|
BasicBlock *label_entry =
|
||||||
|
BasicBlock::Create(Context, "entry", func_test1, nullptr);
|
||||||
|
|
||||||
// Block entry (label_entry)
|
// Block entry (label_entry)
|
||||||
CallInst* int32_3 = CallInst::Create(func_test2, "", label_entry);
|
CallInst* int32_3 = CallInst::Create(func_test2, "", label_entry);
|
||||||
@ -473,14 +478,14 @@ namespace llvm {
|
|||||||
int32_3->setTailCall(false);AttributeSet int32_3_PAL;
|
int32_3->setTailCall(false);AttributeSet int32_3_PAL;
|
||||||
int32_3->setAttributes(int32_3_PAL);
|
int32_3->setAttributes(int32_3_PAL);
|
||||||
|
|
||||||
ReturnInst::Create(getGlobalContext(), int32_3, label_entry);
|
ReturnInst::Create(Context, int32_3, label_entry);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function: test2 (func_test2)
|
// Function: test2 (func_test2)
|
||||||
{
|
{
|
||||||
|
|
||||||
BasicBlock* label_entry_5 = BasicBlock::Create(getGlobalContext(), "entry",func_test2,nullptr);
|
BasicBlock *label_entry_5 =
|
||||||
|
BasicBlock::Create(Context, "entry", func_test2, nullptr);
|
||||||
|
|
||||||
// Block entry (label_entry_5)
|
// Block entry (label_entry_5)
|
||||||
CallInst* int32_6 = CallInst::Create(func_test3, "", label_entry_5);
|
CallInst* int32_6 = CallInst::Create(func_test3, "", label_entry_5);
|
||||||
@ -488,14 +493,14 @@ namespace llvm {
|
|||||||
int32_6->setTailCall(false);AttributeSet int32_6_PAL;
|
int32_6->setTailCall(false);AttributeSet int32_6_PAL;
|
||||||
int32_6->setAttributes(int32_6_PAL);
|
int32_6->setAttributes(int32_6_PAL);
|
||||||
|
|
||||||
ReturnInst::Create(getGlobalContext(), int32_6, label_entry_5);
|
ReturnInst::Create(Context, int32_6, label_entry_5);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function: test3 (func_test3)
|
// Function: test3 (func_test3)
|
||||||
{
|
{
|
||||||
|
|
||||||
BasicBlock* label_entry_8 = BasicBlock::Create(getGlobalContext(), "entry",func_test3,nullptr);
|
BasicBlock *label_entry_8 =
|
||||||
|
BasicBlock::Create(Context, "entry", func_test3, nullptr);
|
||||||
|
|
||||||
// Block entry (label_entry_8)
|
// Block entry (label_entry_8)
|
||||||
CallInst* int32_9 = CallInst::Create(func_test1, "", label_entry_8);
|
CallInst* int32_9 = CallInst::Create(func_test1, "", label_entry_8);
|
||||||
@ -503,8 +508,7 @@ namespace llvm {
|
|||||||
int32_9->setTailCall(false);AttributeSet int32_9_PAL;
|
int32_9->setTailCall(false);AttributeSet int32_9_PAL;
|
||||||
int32_9->setAttributes(int32_9_PAL);
|
int32_9->setAttributes(int32_9_PAL);
|
||||||
|
|
||||||
ReturnInst::Create(getGlobalContext(), int32_9, label_entry_8);
|
ReturnInst::Create(Context, int32_9, label_entry_8);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function: test4 (func_test4)
|
// Function: test4 (func_test4)
|
||||||
@ -513,10 +517,14 @@ namespace llvm {
|
|||||||
Value *int1_f = &*args++;
|
Value *int1_f = &*args++;
|
||||||
int1_f->setName("f");
|
int1_f->setName("f");
|
||||||
|
|
||||||
BasicBlock* label_entry_11 = BasicBlock::Create(getGlobalContext(), "entry",func_test4,nullptr);
|
BasicBlock *label_entry_11 =
|
||||||
BasicBlock* label_bb = BasicBlock::Create(getGlobalContext(), "bb",func_test4,nullptr);
|
BasicBlock::Create(Context, "entry", func_test4, nullptr);
|
||||||
BasicBlock* label_bb1 = BasicBlock::Create(getGlobalContext(), "bb1",func_test4,nullptr);
|
BasicBlock *label_bb =
|
||||||
BasicBlock* label_return = BasicBlock::Create(getGlobalContext(), "return",func_test4,nullptr);
|
BasicBlock::Create(Context, "bb", func_test4, nullptr);
|
||||||
|
BasicBlock *label_bb1 =
|
||||||
|
BasicBlock::Create(Context, "bb1", func_test4, nullptr);
|
||||||
|
BasicBlock *label_return =
|
||||||
|
BasicBlock::Create(Context, "return", func_test4, nullptr);
|
||||||
|
|
||||||
// Block entry (label_entry_11)
|
// Block entry (label_entry_11)
|
||||||
BranchInst::Create(label_bb, label_entry_11);
|
BranchInst::Create(label_bb, label_entry_11);
|
||||||
@ -528,8 +536,7 @@ namespace llvm {
|
|||||||
BranchInst::Create(label_bb1, label_return, int1_f, label_bb1);
|
BranchInst::Create(label_bb1, label_return, int1_f, label_bb1);
|
||||||
|
|
||||||
// Block return (label_return)
|
// Block return (label_return)
|
||||||
ReturnInst::Create(getGlobalContext(), label_return);
|
ReturnInst::Create(Context, label_return);
|
||||||
|
|
||||||
}
|
}
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
|
@ -174,8 +174,8 @@ TEST_F(MDNodeTest, Simple) {
|
|||||||
|
|
||||||
MDString *s1 = MDString::get(Context, StringRef(&x[0], 3));
|
MDString *s1 = MDString::get(Context, StringRef(&x[0], 3));
|
||||||
MDString *s2 = MDString::get(Context, StringRef(&y[0], 3));
|
MDString *s2 = MDString::get(Context, StringRef(&y[0], 3));
|
||||||
ConstantAsMetadata *CI = ConstantAsMetadata::get(
|
ConstantAsMetadata *CI =
|
||||||
ConstantInt::get(getGlobalContext(), APInt(8, 0)));
|
ConstantAsMetadata::get(ConstantInt::get(Context, APInt(8, 0)));
|
||||||
|
|
||||||
std::vector<Metadata *> V;
|
std::vector<Metadata *> V;
|
||||||
V.push_back(s1);
|
V.push_back(s1);
|
||||||
@ -206,8 +206,8 @@ TEST_F(MDNodeTest, Simple) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MDNodeTest, Delete) {
|
TEST_F(MDNodeTest, Delete) {
|
||||||
Constant *C = ConstantInt::get(Type::getInt32Ty(getGlobalContext()), 1);
|
Constant *C = ConstantInt::get(Type::getInt32Ty(Context), 1);
|
||||||
Instruction *I = new BitCastInst(C, Type::getInt32Ty(getGlobalContext()));
|
Instruction *I = new BitCastInst(C, Type::getInt32Ty(Context));
|
||||||
|
|
||||||
Metadata *const V = LocalAsMetadata::get(I);
|
Metadata *const V = LocalAsMetadata::get(I);
|
||||||
MDNode *n = MDNode::get(Context, V);
|
MDNode *n = MDNode::get(Context, V);
|
||||||
@ -2062,8 +2062,8 @@ TEST_F(ValueAsMetadataTest, UpdatesOnRAUW) {
|
|||||||
|
|
||||||
TEST_F(ValueAsMetadataTest, TempTempReplacement) {
|
TEST_F(ValueAsMetadataTest, TempTempReplacement) {
|
||||||
// Create a constant.
|
// Create a constant.
|
||||||
ConstantAsMetadata *CI = ConstantAsMetadata::get(
|
ConstantAsMetadata *CI =
|
||||||
ConstantInt::get(getGlobalContext(), APInt(8, 0)));
|
ConstantAsMetadata::get(ConstantInt::get(Context, APInt(8, 0)));
|
||||||
|
|
||||||
auto Temp1 = MDTuple::getTemporary(Context, None);
|
auto Temp1 = MDTuple::getTemporary(Context, None);
|
||||||
auto Temp2 = MDTuple::getTemporary(Context, {CI});
|
auto Temp2 = MDTuple::getTemporary(Context, {CI});
|
||||||
@ -2079,8 +2079,8 @@ TEST_F(ValueAsMetadataTest, TempTempReplacement) {
|
|||||||
|
|
||||||
TEST_F(ValueAsMetadataTest, CollidingDoubleUpdates) {
|
TEST_F(ValueAsMetadataTest, CollidingDoubleUpdates) {
|
||||||
// Create a constant.
|
// Create a constant.
|
||||||
ConstantAsMetadata *CI = ConstantAsMetadata::get(
|
ConstantAsMetadata *CI =
|
||||||
ConstantInt::get(getGlobalContext(), APInt(8, 0)));
|
ConstantAsMetadata::get(ConstantInt::get(Context, APInt(8, 0)));
|
||||||
|
|
||||||
// Create a temporary to prevent nodes from resolving.
|
// Create a temporary to prevent nodes from resolving.
|
||||||
auto Temp = MDTuple::getTemporary(Context, None);
|
auto Temp = MDTuple::getTemporary(Context, None);
|
||||||
|
@ -153,30 +153,30 @@ struct TestInvalidationFunctionPass
|
|||||||
StringRef Name;
|
StringRef Name;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<Module> parseIR(const char *IR) {
|
std::unique_ptr<Module> parseIR(LLVMContext &Context, const char *IR) {
|
||||||
LLVMContext &C = getGlobalContext();
|
|
||||||
SMDiagnostic Err;
|
SMDiagnostic Err;
|
||||||
return parseAssemblyString(IR, Err, C);
|
return parseAssemblyString(IR, Err, Context);
|
||||||
}
|
}
|
||||||
|
|
||||||
class PassManagerTest : public ::testing::Test {
|
class PassManagerTest : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
|
LLVMContext Context;
|
||||||
std::unique_ptr<Module> M;
|
std::unique_ptr<Module> M;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PassManagerTest()
|
PassManagerTest()
|
||||||
: M(parseIR("define void @f() {\n"
|
: M(parseIR(Context, "define void @f() {\n"
|
||||||
"entry:\n"
|
"entry:\n"
|
||||||
" call void @g()\n"
|
" call void @g()\n"
|
||||||
" call void @h()\n"
|
" call void @h()\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @g() {\n"
|
"define void @g() {\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"define void @h() {\n"
|
"define void @h() {\n"
|
||||||
" ret void\n"
|
" ret void\n"
|
||||||
"}\n")) {}
|
"}\n")) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(PassManagerTest, BasicPreservedAnalyses) {
|
TEST_F(PassManagerTest, BasicPreservedAnalyses) {
|
||||||
|
@ -17,141 +17,175 @@ using namespace llvm;
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
TEST(TypeBuilderTest, Void) {
|
TEST(TypeBuilderTest, Void) {
|
||||||
EXPECT_EQ(Type::getVoidTy(getGlobalContext()), (TypeBuilder<void, true>::get(getGlobalContext())));
|
LLVMContext Context;
|
||||||
EXPECT_EQ(Type::getVoidTy(getGlobalContext()), (TypeBuilder<void, false>::get(getGlobalContext())));
|
EXPECT_EQ(Type::getVoidTy(Context), (TypeBuilder<void, true>::get(Context)));
|
||||||
|
EXPECT_EQ(Type::getVoidTy(Context), (TypeBuilder<void, false>::get(Context)));
|
||||||
// Special cases for C compatibility:
|
// Special cases for C compatibility:
|
||||||
EXPECT_EQ(Type::getInt8PtrTy(getGlobalContext()),
|
EXPECT_EQ(Type::getInt8PtrTy(Context),
|
||||||
(TypeBuilder<void*, false>::get(getGlobalContext())));
|
(TypeBuilder<void *, false>::get(Context)));
|
||||||
EXPECT_EQ(Type::getInt8PtrTy(getGlobalContext()),
|
EXPECT_EQ(Type::getInt8PtrTy(Context),
|
||||||
(TypeBuilder<const void*, false>::get(getGlobalContext())));
|
(TypeBuilder<const void *, false>::get(Context)));
|
||||||
EXPECT_EQ(Type::getInt8PtrTy(getGlobalContext()),
|
EXPECT_EQ(Type::getInt8PtrTy(Context),
|
||||||
(TypeBuilder<volatile void*, false>::get(getGlobalContext())));
|
(TypeBuilder<volatile void *, false>::get(Context)));
|
||||||
EXPECT_EQ(Type::getInt8PtrTy(getGlobalContext()),
|
EXPECT_EQ(Type::getInt8PtrTy(Context),
|
||||||
(TypeBuilder<const volatile void*, false>::get(
|
(TypeBuilder<const volatile void *, false>::get(Context)));
|
||||||
getGlobalContext())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TypeBuilderTest, HostIntegers) {
|
TEST(TypeBuilderTest, HostIntegers) {
|
||||||
EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), (TypeBuilder<int8_t, false>::get(getGlobalContext())));
|
LLVMContext Context;
|
||||||
EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), (TypeBuilder<uint8_t, false>::get(getGlobalContext())));
|
EXPECT_EQ(Type::getInt8Ty(Context),
|
||||||
EXPECT_EQ(Type::getInt16Ty(getGlobalContext()), (TypeBuilder<int16_t, false>::get(getGlobalContext())));
|
(TypeBuilder<int8_t, false>::get(Context)));
|
||||||
EXPECT_EQ(Type::getInt16Ty(getGlobalContext()), (TypeBuilder<uint16_t, false>::get(getGlobalContext())));
|
EXPECT_EQ(Type::getInt8Ty(Context),
|
||||||
EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), (TypeBuilder<int32_t, false>::get(getGlobalContext())));
|
(TypeBuilder<uint8_t, false>::get(Context)));
|
||||||
EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), (TypeBuilder<uint32_t, false>::get(getGlobalContext())));
|
EXPECT_EQ(Type::getInt16Ty(Context),
|
||||||
EXPECT_EQ(Type::getInt64Ty(getGlobalContext()), (TypeBuilder<int64_t, false>::get(getGlobalContext())));
|
(TypeBuilder<int16_t, false>::get(Context)));
|
||||||
EXPECT_EQ(Type::getInt64Ty(getGlobalContext()), (TypeBuilder<uint64_t, false>::get(getGlobalContext())));
|
EXPECT_EQ(Type::getInt16Ty(Context),
|
||||||
|
(TypeBuilder<uint16_t, false>::get(Context)));
|
||||||
|
EXPECT_EQ(Type::getInt32Ty(Context),
|
||||||
|
(TypeBuilder<int32_t, false>::get(Context)));
|
||||||
|
EXPECT_EQ(Type::getInt32Ty(Context),
|
||||||
|
(TypeBuilder<uint32_t, false>::get(Context)));
|
||||||
|
EXPECT_EQ(Type::getInt64Ty(Context),
|
||||||
|
(TypeBuilder<int64_t, false>::get(Context)));
|
||||||
|
EXPECT_EQ(Type::getInt64Ty(Context),
|
||||||
|
(TypeBuilder<uint64_t, false>::get(Context)));
|
||||||
|
|
||||||
EXPECT_EQ(IntegerType::get(getGlobalContext(), sizeof(size_t) * CHAR_BIT),
|
EXPECT_EQ(IntegerType::get(Context, sizeof(size_t) * CHAR_BIT),
|
||||||
(TypeBuilder<size_t, false>::get(getGlobalContext())));
|
(TypeBuilder<size_t, false>::get(Context)));
|
||||||
EXPECT_EQ(IntegerType::get(getGlobalContext(), sizeof(ptrdiff_t) * CHAR_BIT),
|
EXPECT_EQ(IntegerType::get(Context, sizeof(ptrdiff_t) * CHAR_BIT),
|
||||||
(TypeBuilder<ptrdiff_t, false>::get(getGlobalContext())));
|
(TypeBuilder<ptrdiff_t, false>::get(Context)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TypeBuilderTest, CrossCompilableIntegers) {
|
TEST(TypeBuilderTest, CrossCompilableIntegers) {
|
||||||
EXPECT_EQ(IntegerType::get(getGlobalContext(), 1), (TypeBuilder<types::i<1>, true>::get(getGlobalContext())));
|
LLVMContext Context;
|
||||||
EXPECT_EQ(IntegerType::get(getGlobalContext(), 1), (TypeBuilder<types::i<1>, false>::get(getGlobalContext())));
|
EXPECT_EQ(IntegerType::get(Context, 1),
|
||||||
EXPECT_EQ(IntegerType::get(getGlobalContext(), 72), (TypeBuilder<types::i<72>, true>::get(getGlobalContext())));
|
(TypeBuilder<types::i<1>, true>::get(Context)));
|
||||||
EXPECT_EQ(IntegerType::get(getGlobalContext(), 72), (TypeBuilder<types::i<72>, false>::get(getGlobalContext())));
|
EXPECT_EQ(IntegerType::get(Context, 1),
|
||||||
|
(TypeBuilder<types::i<1>, false>::get(Context)));
|
||||||
|
EXPECT_EQ(IntegerType::get(Context, 72),
|
||||||
|
(TypeBuilder<types::i<72>, true>::get(Context)));
|
||||||
|
EXPECT_EQ(IntegerType::get(Context, 72),
|
||||||
|
(TypeBuilder<types::i<72>, false>::get(Context)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TypeBuilderTest, Float) {
|
TEST(TypeBuilderTest, Float) {
|
||||||
EXPECT_EQ(Type::getFloatTy(getGlobalContext()), (TypeBuilder<float, false>::get(getGlobalContext())));
|
LLVMContext Context;
|
||||||
EXPECT_EQ(Type::getDoubleTy(getGlobalContext()), (TypeBuilder<double, false>::get(getGlobalContext())));
|
EXPECT_EQ(Type::getFloatTy(Context),
|
||||||
|
(TypeBuilder<float, false>::get(Context)));
|
||||||
|
EXPECT_EQ(Type::getDoubleTy(Context),
|
||||||
|
(TypeBuilder<double, false>::get(Context)));
|
||||||
// long double isn't supported yet.
|
// long double isn't supported yet.
|
||||||
EXPECT_EQ(Type::getFloatTy(getGlobalContext()), (TypeBuilder<types::ieee_float, true>::get(getGlobalContext())));
|
EXPECT_EQ(Type::getFloatTy(Context),
|
||||||
EXPECT_EQ(Type::getFloatTy(getGlobalContext()), (TypeBuilder<types::ieee_float, false>::get(getGlobalContext())));
|
(TypeBuilder<types::ieee_float, true>::get(Context)));
|
||||||
EXPECT_EQ(Type::getDoubleTy(getGlobalContext()), (TypeBuilder<types::ieee_double, true>::get(getGlobalContext())));
|
EXPECT_EQ(Type::getFloatTy(Context),
|
||||||
EXPECT_EQ(Type::getDoubleTy(getGlobalContext()), (TypeBuilder<types::ieee_double, false>::get(getGlobalContext())));
|
(TypeBuilder<types::ieee_float, false>::get(Context)));
|
||||||
EXPECT_EQ(Type::getX86_FP80Ty(getGlobalContext()), (TypeBuilder<types::x86_fp80, true>::get(getGlobalContext())));
|
EXPECT_EQ(Type::getDoubleTy(Context),
|
||||||
EXPECT_EQ(Type::getX86_FP80Ty(getGlobalContext()), (TypeBuilder<types::x86_fp80, false>::get(getGlobalContext())));
|
(TypeBuilder<types::ieee_double, true>::get(Context)));
|
||||||
EXPECT_EQ(Type::getFP128Ty(getGlobalContext()), (TypeBuilder<types::fp128, true>::get(getGlobalContext())));
|
EXPECT_EQ(Type::getDoubleTy(Context),
|
||||||
EXPECT_EQ(Type::getFP128Ty(getGlobalContext()), (TypeBuilder<types::fp128, false>::get(getGlobalContext())));
|
(TypeBuilder<types::ieee_double, false>::get(Context)));
|
||||||
EXPECT_EQ(Type::getPPC_FP128Ty(getGlobalContext()), (TypeBuilder<types::ppc_fp128, true>::get(getGlobalContext())));
|
EXPECT_EQ(Type::getX86_FP80Ty(Context),
|
||||||
EXPECT_EQ(Type::getPPC_FP128Ty(getGlobalContext()), (TypeBuilder<types::ppc_fp128, false>::get(getGlobalContext())));
|
(TypeBuilder<types::x86_fp80, true>::get(Context)));
|
||||||
|
EXPECT_EQ(Type::getX86_FP80Ty(Context),
|
||||||
|
(TypeBuilder<types::x86_fp80, false>::get(Context)));
|
||||||
|
EXPECT_EQ(Type::getFP128Ty(Context),
|
||||||
|
(TypeBuilder<types::fp128, true>::get(Context)));
|
||||||
|
EXPECT_EQ(Type::getFP128Ty(Context),
|
||||||
|
(TypeBuilder<types::fp128, false>::get(Context)));
|
||||||
|
EXPECT_EQ(Type::getPPC_FP128Ty(Context),
|
||||||
|
(TypeBuilder<types::ppc_fp128, true>::get(Context)));
|
||||||
|
EXPECT_EQ(Type::getPPC_FP128Ty(Context),
|
||||||
|
(TypeBuilder<types::ppc_fp128, false>::get(Context)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TypeBuilderTest, Derived) {
|
TEST(TypeBuilderTest, Derived) {
|
||||||
EXPECT_EQ(PointerType::getUnqual(Type::getInt8PtrTy(getGlobalContext())),
|
LLVMContext Context;
|
||||||
(TypeBuilder<int8_t**, false>::get(getGlobalContext())));
|
EXPECT_EQ(PointerType::getUnqual(Type::getInt8PtrTy(Context)),
|
||||||
EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 7),
|
(TypeBuilder<int8_t **, false>::get(Context)));
|
||||||
(TypeBuilder<int8_t[7], false>::get(getGlobalContext())));
|
EXPECT_EQ(ArrayType::get(Type::getInt8Ty(Context), 7),
|
||||||
EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 0),
|
(TypeBuilder<int8_t[7], false>::get(Context)));
|
||||||
(TypeBuilder<int8_t[], false>::get(getGlobalContext())));
|
EXPECT_EQ(ArrayType::get(Type::getInt8Ty(Context), 0),
|
||||||
|
(TypeBuilder<int8_t[], false>::get(Context)));
|
||||||
|
|
||||||
EXPECT_EQ(PointerType::getUnqual(Type::getInt8PtrTy(getGlobalContext())),
|
EXPECT_EQ(PointerType::getUnqual(Type::getInt8PtrTy(Context)),
|
||||||
(TypeBuilder<types::i<8>**, false>::get(getGlobalContext())));
|
(TypeBuilder<types::i<8> **, false>::get(Context)));
|
||||||
EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 7),
|
EXPECT_EQ(ArrayType::get(Type::getInt8Ty(Context), 7),
|
||||||
(TypeBuilder<types::i<8>[7], false>::get(getGlobalContext())));
|
(TypeBuilder<types::i<8>[7], false>::get(Context)));
|
||||||
EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 0),
|
EXPECT_EQ(ArrayType::get(Type::getInt8Ty(Context), 0),
|
||||||
(TypeBuilder<types::i<8>[], false>::get(getGlobalContext())));
|
(TypeBuilder<types::i<8>[], false>::get(Context)));
|
||||||
|
|
||||||
EXPECT_EQ(PointerType::getUnqual(Type::getInt8PtrTy(getGlobalContext())),
|
EXPECT_EQ(PointerType::getUnqual(Type::getInt8PtrTy(Context)),
|
||||||
(TypeBuilder<types::i<8>**, true>::get(getGlobalContext())));
|
(TypeBuilder<types::i<8> **, true>::get(Context)));
|
||||||
EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 7),
|
EXPECT_EQ(ArrayType::get(Type::getInt8Ty(Context), 7),
|
||||||
(TypeBuilder<types::i<8>[7], true>::get(getGlobalContext())));
|
(TypeBuilder<types::i<8>[7], true>::get(Context)));
|
||||||
EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 0),
|
EXPECT_EQ(ArrayType::get(Type::getInt8Ty(Context), 0),
|
||||||
(TypeBuilder<types::i<8>[], true>::get(getGlobalContext())));
|
(TypeBuilder<types::i<8>[], true>::get(Context)));
|
||||||
|
|
||||||
|
EXPECT_EQ(Type::getInt8Ty(Context),
|
||||||
|
(TypeBuilder<const int8_t, false>::get(Context)));
|
||||||
|
EXPECT_EQ(Type::getInt8Ty(Context),
|
||||||
|
(TypeBuilder<volatile int8_t, false>::get(Context)));
|
||||||
|
EXPECT_EQ(Type::getInt8Ty(Context),
|
||||||
|
(TypeBuilder<const volatile int8_t, false>::get(Context)));
|
||||||
|
|
||||||
EXPECT_EQ(Type::getInt8Ty(getGlobalContext()),
|
EXPECT_EQ(Type::getInt8Ty(Context),
|
||||||
(TypeBuilder<const int8_t, false>::get(getGlobalContext())));
|
(TypeBuilder<const types::i<8>, false>::get(Context)));
|
||||||
EXPECT_EQ(Type::getInt8Ty(getGlobalContext()),
|
EXPECT_EQ(Type::getInt8Ty(Context),
|
||||||
(TypeBuilder<volatile int8_t, false>::get(getGlobalContext())));
|
(TypeBuilder<volatile types::i<8>, false>::get(Context)));
|
||||||
EXPECT_EQ(Type::getInt8Ty(getGlobalContext()),
|
EXPECT_EQ(Type::getInt8Ty(Context),
|
||||||
(TypeBuilder<const volatile int8_t, false>::get(getGlobalContext())));
|
(TypeBuilder<const volatile types::i<8>, false>::get(Context)));
|
||||||
|
|
||||||
EXPECT_EQ(Type::getInt8Ty(getGlobalContext()),
|
EXPECT_EQ(Type::getInt8Ty(Context),
|
||||||
(TypeBuilder<const types::i<8>, false>::get(getGlobalContext())));
|
(TypeBuilder<const types::i<8>, true>::get(Context)));
|
||||||
EXPECT_EQ(Type::getInt8Ty(getGlobalContext()),
|
EXPECT_EQ(Type::getInt8Ty(Context),
|
||||||
(TypeBuilder<volatile types::i<8>, false>::get(getGlobalContext())));
|
(TypeBuilder<volatile types::i<8>, true>::get(Context)));
|
||||||
EXPECT_EQ(Type::getInt8Ty(getGlobalContext()),
|
EXPECT_EQ(Type::getInt8Ty(Context),
|
||||||
(TypeBuilder<const volatile types::i<8>, false>::get(getGlobalContext())));
|
(TypeBuilder<const volatile types::i<8>, true>::get(Context)));
|
||||||
|
|
||||||
EXPECT_EQ(Type::getInt8Ty(getGlobalContext()),
|
EXPECT_EQ(Type::getInt8PtrTy(Context),
|
||||||
(TypeBuilder<const types::i<8>, true>::get(getGlobalContext())));
|
(TypeBuilder<const volatile int8_t *const volatile, false>::get(
|
||||||
EXPECT_EQ(Type::getInt8Ty(getGlobalContext()),
|
Context)));
|
||||||
(TypeBuilder<volatile types::i<8>, true>::get(getGlobalContext())));
|
|
||||||
EXPECT_EQ(Type::getInt8Ty(getGlobalContext()),
|
|
||||||
(TypeBuilder<const volatile types::i<8>, true>::get(getGlobalContext())));
|
|
||||||
|
|
||||||
EXPECT_EQ(Type::getInt8PtrTy(getGlobalContext()),
|
|
||||||
(TypeBuilder<const volatile int8_t*const volatile, false>::get(getGlobalContext())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TypeBuilderTest, Functions) {
|
TEST(TypeBuilderTest, Functions) {
|
||||||
|
LLVMContext Context;
|
||||||
std::vector<Type*> params;
|
std::vector<Type*> params;
|
||||||
EXPECT_EQ(FunctionType::get(Type::getVoidTy(getGlobalContext()), params, false),
|
EXPECT_EQ(FunctionType::get(Type::getVoidTy(Context), params, false),
|
||||||
(TypeBuilder<void(), true>::get(getGlobalContext())));
|
(TypeBuilder<void(), true>::get(Context)));
|
||||||
EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true),
|
EXPECT_EQ(FunctionType::get(Type::getInt8Ty(Context), params, true),
|
||||||
(TypeBuilder<int8_t(...), false>::get(getGlobalContext())));
|
(TypeBuilder<int8_t(...), false>::get(Context)));
|
||||||
params.push_back(TypeBuilder<int32_t*, false>::get(getGlobalContext()));
|
params.push_back(TypeBuilder<int32_t *, false>::get(Context));
|
||||||
EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false),
|
EXPECT_EQ(FunctionType::get(Type::getInt8Ty(Context), params, false),
|
||||||
(TypeBuilder<int8_t(const int32_t*), false>::get(getGlobalContext())));
|
(TypeBuilder<int8_t(const int32_t *), false>::get(Context)));
|
||||||
EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true),
|
EXPECT_EQ(FunctionType::get(Type::getInt8Ty(Context), params, true),
|
||||||
(TypeBuilder<int8_t(const int32_t*, ...), false>::get(getGlobalContext())));
|
(TypeBuilder<int8_t(const int32_t *, ...), false>::get(Context)));
|
||||||
params.push_back(TypeBuilder<char*, false>::get(getGlobalContext()));
|
params.push_back(TypeBuilder<char *, false>::get(Context));
|
||||||
EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false),
|
EXPECT_EQ(FunctionType::get(Type::getInt8Ty(Context), params, false),
|
||||||
(TypeBuilder<int8_t(int32_t*, void*), false>::get(getGlobalContext())));
|
(TypeBuilder<int8_t(int32_t *, void *), false>::get(Context)));
|
||||||
EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true),
|
EXPECT_EQ(FunctionType::get(Type::getInt8Ty(Context), params, true),
|
||||||
(TypeBuilder<int8_t(int32_t*, char*, ...), false>::get(getGlobalContext())));
|
(TypeBuilder<int8_t(int32_t *, char *, ...), false>::get(Context)));
|
||||||
params.push_back(TypeBuilder<char, false>::get(getGlobalContext()));
|
params.push_back(TypeBuilder<char, false>::get(Context));
|
||||||
EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false),
|
EXPECT_EQ(
|
||||||
(TypeBuilder<int8_t(int32_t*, void*, char), false>::get(getGlobalContext())));
|
FunctionType::get(Type::getInt8Ty(Context), params, false),
|
||||||
EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true),
|
(TypeBuilder<int8_t(int32_t *, void *, char), false>::get(Context)));
|
||||||
(TypeBuilder<int8_t(int32_t*, char*, char, ...), false>::get(getGlobalContext())));
|
EXPECT_EQ(
|
||||||
params.push_back(TypeBuilder<char, false>::get(getGlobalContext()));
|
FunctionType::get(Type::getInt8Ty(Context), params, true),
|
||||||
EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false),
|
(TypeBuilder<int8_t(int32_t *, char *, char, ...), false>::get(Context)));
|
||||||
(TypeBuilder<int8_t(int32_t*, void*, char, char), false>::get(getGlobalContext())));
|
params.push_back(TypeBuilder<char, false>::get(Context));
|
||||||
EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true),
|
EXPECT_EQ(FunctionType::get(Type::getInt8Ty(Context), params, false),
|
||||||
(TypeBuilder<int8_t(int32_t*, char*, char, char, ...),
|
(TypeBuilder<int8_t(int32_t *, void *, char, char), false>::get(
|
||||||
false>::get(getGlobalContext())));
|
Context)));
|
||||||
params.push_back(TypeBuilder<char, false>::get(getGlobalContext()));
|
EXPECT_EQ(
|
||||||
EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false),
|
FunctionType::get(Type::getInt8Ty(Context), params, true),
|
||||||
(TypeBuilder<int8_t(int32_t*, void*, char, char, char),
|
(TypeBuilder<int8_t(int32_t *, char *, char, char, ...), false>::get(
|
||||||
false>::get(getGlobalContext())));
|
Context)));
|
||||||
EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true),
|
params.push_back(TypeBuilder<char, false>::get(Context));
|
||||||
(TypeBuilder<int8_t(int32_t*, char*, char, char, char, ...),
|
EXPECT_EQ(
|
||||||
false>::get(getGlobalContext())));
|
FunctionType::get(Type::getInt8Ty(Context), params, false),
|
||||||
|
(TypeBuilder<int8_t(int32_t *, void *, char, char, char), false>::get(
|
||||||
|
Context)));
|
||||||
|
EXPECT_EQ(FunctionType::get(Type::getInt8Ty(Context), params, true),
|
||||||
|
(TypeBuilder<int8_t(int32_t *, char *, char, char, char, ...),
|
||||||
|
false>::get(Context)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TypeBuilderTest, Context) {
|
TEST(TypeBuilderTest, Context) {
|
||||||
@ -230,24 +264,24 @@ public:
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
TEST(TypeBuilderTest, Extensions) {
|
TEST(TypeBuilderTest, Extensions) {
|
||||||
|
LLVMContext Context;
|
||||||
EXPECT_EQ(PointerType::getUnqual(StructType::get(
|
EXPECT_EQ(PointerType::getUnqual(StructType::get(
|
||||||
TypeBuilder<int, false>::get(getGlobalContext()),
|
TypeBuilder<int, false>::get(Context),
|
||||||
TypeBuilder<int*, false>::get(getGlobalContext()),
|
TypeBuilder<int *, false>::get(Context),
|
||||||
TypeBuilder<void*[], false>::get(getGlobalContext()),
|
TypeBuilder<void *[], false>::get(Context), (void *)nullptr)),
|
||||||
(void*)nullptr)),
|
(TypeBuilder<MyType *, false>::get(Context)));
|
||||||
(TypeBuilder<MyType*, false>::get(getGlobalContext())));
|
EXPECT_EQ(
|
||||||
EXPECT_EQ(PointerType::getUnqual(StructType::get(
|
PointerType::getUnqual(StructType::get(
|
||||||
TypeBuilder<types::i<32>, false>::get(getGlobalContext()),
|
TypeBuilder<types::i<32>, false>::get(Context),
|
||||||
TypeBuilder<types::i<32>*, false>::get(getGlobalContext()),
|
TypeBuilder<types::i<32> *, false>::get(Context),
|
||||||
TypeBuilder<types::i<8>*[], false>::get(getGlobalContext()),
|
TypeBuilder<types::i<8> *[], false>::get(Context), (void *)nullptr)),
|
||||||
(void*)nullptr)),
|
(TypeBuilder<MyPortableType *, false>::get(Context)));
|
||||||
(TypeBuilder<MyPortableType*, false>::get(getGlobalContext())));
|
EXPECT_EQ(
|
||||||
EXPECT_EQ(PointerType::getUnqual(StructType::get(
|
PointerType::getUnqual(StructType::get(
|
||||||
TypeBuilder<types::i<32>, false>::get(getGlobalContext()),
|
TypeBuilder<types::i<32>, false>::get(Context),
|
||||||
TypeBuilder<types::i<32>*, false>::get(getGlobalContext()),
|
TypeBuilder<types::i<32> *, false>::get(Context),
|
||||||
TypeBuilder<types::i<8>*[], false>::get(getGlobalContext()),
|
TypeBuilder<types::i<8> *[], false>::get(Context), (void *)nullptr)),
|
||||||
(void*)nullptr)),
|
(TypeBuilder<MyPortableType *, true>::get(Context)));
|
||||||
(TypeBuilder<MyPortableType*, true>::get(getGlobalContext())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
@ -94,9 +94,9 @@ TEST(UserTest, ValueOpIteration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(UserTest, PersonalityUser) {
|
TEST(UserTest, PersonalityUser) {
|
||||||
Module M("", getGlobalContext());
|
LLVMContext Context;
|
||||||
FunctionType *RetVoidTy =
|
Module M("", Context);
|
||||||
FunctionType::get(Type::getVoidTy(getGlobalContext()), false);
|
FunctionType *RetVoidTy = FunctionType::get(Type::getVoidTy(Context), false);
|
||||||
Function *PersonalityF = Function::Create(
|
Function *PersonalityF = Function::Create(
|
||||||
RetVoidTy, GlobalValue::ExternalLinkage, "PersonalityFn", &M);
|
RetVoidTy, GlobalValue::ExternalLinkage, "PersonalityFn", &M);
|
||||||
Function *TestF =
|
Function *TestF =
|
||||||
|
@ -20,13 +20,13 @@ namespace {
|
|||||||
|
|
||||||
class ValueHandle : public testing::Test {
|
class ValueHandle : public testing::Test {
|
||||||
protected:
|
protected:
|
||||||
|
LLVMContext Context;
|
||||||
Constant *ConstantV;
|
Constant *ConstantV;
|
||||||
std::unique_ptr<BitCastInst> BitcastV;
|
std::unique_ptr<BitCastInst> BitcastV;
|
||||||
|
|
||||||
ValueHandle() :
|
ValueHandle()
|
||||||
ConstantV(ConstantInt::get(Type::getInt32Ty(getGlobalContext()), 0)),
|
: ConstantV(ConstantInt::get(Type::getInt32Ty(Context), 0)),
|
||||||
BitcastV(new BitCastInst(ConstantV, Type::getInt32Ty(getGlobalContext()))) {
|
BitcastV(new BitCastInst(ConstantV, Type::getInt32Ty(Context))) {}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConcreteCallbackVH final : public CallbackVH {
|
class ConcreteCallbackVH final : public CallbackVH {
|
||||||
@ -42,8 +42,8 @@ TEST_F(ValueHandle, WeakVH_BasicOperation) {
|
|||||||
|
|
||||||
// Make sure I can call a method on the underlying Value. It
|
// Make sure I can call a method on the underlying Value. It
|
||||||
// doesn't matter which method.
|
// doesn't matter which method.
|
||||||
EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), WVH->getType());
|
EXPECT_EQ(Type::getInt32Ty(Context), WVH->getType());
|
||||||
EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), (*WVH).getType());
|
EXPECT_EQ(Type::getInt32Ty(Context), (*WVH).getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ValueHandle, WeakVH_Comparisons) {
|
TEST_F(ValueHandle, WeakVH_Comparisons) {
|
||||||
@ -197,8 +197,8 @@ TEST_F(ValueHandle, CallbackVH_BasicOperation) {
|
|||||||
|
|
||||||
// Make sure I can call a method on the underlying Value. It
|
// Make sure I can call a method on the underlying Value. It
|
||||||
// doesn't matter which method.
|
// doesn't matter which method.
|
||||||
EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), CVH->getType());
|
EXPECT_EQ(Type::getInt32Ty(Context), CVH->getType());
|
||||||
EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), (*CVH).getType());
|
EXPECT_EQ(Type::getInt32Ty(Context), (*CVH).getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ValueHandle, CallbackVH_Comparisons) {
|
TEST_F(ValueHandle, CallbackVH_Comparisons) {
|
||||||
@ -297,15 +297,17 @@ TEST_F(ValueHandle, CallbackVH_DeletionCanRAUW) {
|
|||||||
Value *AURWArgument;
|
Value *AURWArgument;
|
||||||
LLVMContext *Context;
|
LLVMContext *Context;
|
||||||
|
|
||||||
RecoveringVH() : DeletedCalls(0), AURWArgument(nullptr),
|
RecoveringVH(LLVMContext &TheContext)
|
||||||
Context(&getGlobalContext()) {}
|
: DeletedCalls(0), AURWArgument(nullptr), Context(&TheContext) {}
|
||||||
RecoveringVH(Value *V)
|
|
||||||
: CallbackVH(V), DeletedCalls(0), AURWArgument(nullptr),
|
RecoveringVH(LLVMContext &TheContext, Value *V)
|
||||||
Context(&getGlobalContext()) {}
|
: CallbackVH(V), DeletedCalls(0), AURWArgument(nullptr),
|
||||||
|
Context(&TheContext) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void deleted() override {
|
void deleted() override {
|
||||||
getValPtr()->replaceAllUsesWith(Constant::getNullValue(Type::getInt32Ty(getGlobalContext())));
|
getValPtr()->replaceAllUsesWith(
|
||||||
|
Constant::getNullValue(Type::getInt32Ty(*Context)));
|
||||||
setValPtr(nullptr);
|
setValPtr(nullptr);
|
||||||
}
|
}
|
||||||
void allUsesReplacedWith(Value *new_value) override {
|
void allUsesReplacedWith(Value *new_value) override {
|
||||||
@ -318,15 +320,15 @@ TEST_F(ValueHandle, CallbackVH_DeletionCanRAUW) {
|
|||||||
|
|
||||||
// Normally, if a value has uses, deleting it will crash. However, we can use
|
// Normally, if a value has uses, deleting it will crash. However, we can use
|
||||||
// a CallbackVH to remove the uses before the check for no uses.
|
// a CallbackVH to remove the uses before the check for no uses.
|
||||||
RecoveringVH RVH;
|
RecoveringVH RVH(Context);
|
||||||
RVH = BitcastV.get();
|
RVH = RecoveringVH(Context, BitcastV.get());
|
||||||
std::unique_ptr<BinaryOperator> BitcastUser(
|
std::unique_ptr<BinaryOperator> BitcastUser(BinaryOperator::CreateAdd(
|
||||||
BinaryOperator::CreateAdd(RVH,
|
RVH, Constant::getNullValue(Type::getInt32Ty(Context))));
|
||||||
Constant::getNullValue(Type::getInt32Ty(getGlobalContext()))));
|
|
||||||
EXPECT_EQ(BitcastV.get(), BitcastUser->getOperand(0));
|
EXPECT_EQ(BitcastV.get(), BitcastUser->getOperand(0));
|
||||||
BitcastV.reset(); // Would crash without the ValueHandler.
|
BitcastV.reset(); // Would crash without the ValueHandler.
|
||||||
EXPECT_EQ(Constant::getNullValue(Type::getInt32Ty(getGlobalContext())), RVH.AURWArgument);
|
EXPECT_EQ(Constant::getNullValue(Type::getInt32Ty(Context)),
|
||||||
EXPECT_EQ(Constant::getNullValue(Type::getInt32Ty(getGlobalContext())),
|
RVH.AURWArgument);
|
||||||
|
EXPECT_EQ(Constant::getNullValue(Type::getInt32Ty(Context)),
|
||||||
BitcastUser->getOperand(0));
|
BitcastUser->getOperand(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,15 +22,15 @@ namespace {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
class ValueMapTest : public testing::Test {
|
class ValueMapTest : public testing::Test {
|
||||||
protected:
|
protected:
|
||||||
|
LLVMContext Context;
|
||||||
Constant *ConstantV;
|
Constant *ConstantV;
|
||||||
std::unique_ptr<BitCastInst> BitcastV;
|
std::unique_ptr<BitCastInst> BitcastV;
|
||||||
std::unique_ptr<BinaryOperator> AddV;
|
std::unique_ptr<BinaryOperator> AddV;
|
||||||
|
|
||||||
ValueMapTest() :
|
ValueMapTest()
|
||||||
ConstantV(ConstantInt::get(Type::getInt32Ty(getGlobalContext()), 0)),
|
: ConstantV(ConstantInt::get(Type::getInt32Ty(Context), 0)),
|
||||||
BitcastV(new BitCastInst(ConstantV, Type::getInt32Ty(getGlobalContext()))),
|
BitcastV(new BitCastInst(ConstantV, Type::getInt32Ty(Context))),
|
||||||
AddV(BinaryOperator::CreateAdd(ConstantV, ConstantV)) {
|
AddV(BinaryOperator::CreateAdd(ConstantV, ConstantV)) {}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Run everything on Value*, a subtype to make sure that casting works as
|
// Run everything on Value*, a subtype to make sure that casting works as
|
||||||
|
@ -45,7 +45,7 @@ TEST(ValueTest, UsedInBasicBlock) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(GlobalTest, CreateAddressSpace) {
|
TEST(GlobalTest, CreateAddressSpace) {
|
||||||
LLVMContext &Ctx = getGlobalContext();
|
LLVMContext Ctx;
|
||||||
std::unique_ptr<Module> M(new Module("TestModule", Ctx));
|
std::unique_ptr<Module> M(new Module("TestModule", Ctx));
|
||||||
Type *Int8Ty = Type::getInt8Ty(Ctx);
|
Type *Int8Ty = Type::getInt8Ty(Ctx);
|
||||||
Type *Int32Ty = Type::getInt32Ty(Ctx);
|
Type *Int32Ty = Type::getInt32Ty(Ctx);
|
||||||
@ -92,7 +92,7 @@ TEST(GlobalTest, CreateAddressSpace) {
|
|||||||
#ifdef GTEST_HAS_DEATH_TEST
|
#ifdef GTEST_HAS_DEATH_TEST
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
TEST(GlobalTest, AlignDeath) {
|
TEST(GlobalTest, AlignDeath) {
|
||||||
LLVMContext &Ctx = getGlobalContext();
|
LLVMContext Ctx;
|
||||||
std::unique_ptr<Module> M(new Module("TestModule", Ctx));
|
std::unique_ptr<Module> M(new Module("TestModule", Ctx));
|
||||||
Type *Int32Ty = Type::getInt32Ty(Ctx);
|
Type *Int32Ty = Type::getInt32Ty(Ctx);
|
||||||
GlobalVariable *Var =
|
GlobalVariable *Var =
|
||||||
|
@ -23,7 +23,7 @@ namespace llvm {
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
TEST(VerifierTest, Branch_i1) {
|
TEST(VerifierTest, Branch_i1) {
|
||||||
LLVMContext &C = getGlobalContext();
|
LLVMContext C;
|
||||||
Module M("M", C);
|
Module M("M", C);
|
||||||
FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), /*isVarArg=*/false);
|
FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), /*isVarArg=*/false);
|
||||||
Function *F = cast<Function>(M.getOrInsertFunction("foo", FTy));
|
Function *F = cast<Function>(M.getOrInsertFunction("foo", FTy));
|
||||||
@ -46,7 +46,7 @@ TEST(VerifierTest, Branch_i1) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(VerifierTest, InvalidRetAttribute) {
|
TEST(VerifierTest, InvalidRetAttribute) {
|
||||||
LLVMContext &C = getGlobalContext();
|
LLVMContext C;
|
||||||
Module M("M", C);
|
Module M("M", C);
|
||||||
FunctionType *FTy = FunctionType::get(Type::getInt32Ty(C), /*isVarArg=*/false);
|
FunctionType *FTy = FunctionType::get(Type::getInt32Ty(C), /*isVarArg=*/false);
|
||||||
Function *F = cast<Function>(M.getOrInsertFunction("foo", FTy));
|
Function *F = cast<Function>(M.getOrInsertFunction("foo", FTy));
|
||||||
@ -62,7 +62,7 @@ TEST(VerifierTest, InvalidRetAttribute) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(VerifierTest, CrossModuleRef) {
|
TEST(VerifierTest, CrossModuleRef) {
|
||||||
LLVMContext &C = getGlobalContext();
|
LLVMContext C;
|
||||||
Module M1("M1", C);
|
Module M1("M1", C);
|
||||||
Module M2("M2", C);
|
Module M2("M2", C);
|
||||||
Module M3("M3", C);
|
Module M3("M3", C);
|
||||||
@ -121,7 +121,7 @@ TEST(VerifierTest, CrossModuleRef) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(VerifierTest, CrossModuleMetadataRef) {
|
TEST(VerifierTest, CrossModuleMetadataRef) {
|
||||||
LLVMContext &C = getGlobalContext();
|
LLVMContext C;
|
||||||
Module M1("M1", C);
|
Module M1("M1", C);
|
||||||
Module M2("M2", C);
|
Module M2("M2", C);
|
||||||
GlobalVariable *newGV =
|
GlobalVariable *newGV =
|
||||||
|
@ -19,16 +19,14 @@
|
|||||||
namespace llvm {
|
namespace llvm {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
Constant *char2constant(char c) {
|
|
||||||
return ConstantInt::get(Type::getInt8Ty(getGlobalContext()), c);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TEST(WaymarkTest, NativeArray) {
|
TEST(WaymarkTest, NativeArray) {
|
||||||
|
LLVMContext Context;
|
||||||
static uint8_t tail[22] = "s02s33s30y2y0s1x0syxS";
|
static uint8_t tail[22] = "s02s33s30y2y0s1x0syxS";
|
||||||
Value * values[22];
|
Value * values[22];
|
||||||
std::transform(tail, tail + 22, values, char2constant);
|
std::transform(tail, tail + 22, values, [&](char c) {
|
||||||
FunctionType *FT = FunctionType::get(Type::getVoidTy(getGlobalContext()), true);
|
return ConstantInt::get(Type::getInt8Ty(Context), c);
|
||||||
|
});
|
||||||
|
FunctionType *FT = FunctionType::get(Type::getVoidTy(Context), true);
|
||||||
std::unique_ptr<Function> F(
|
std::unique_ptr<Function> F(
|
||||||
Function::Create(FT, GlobalValue::ExternalLinkage));
|
Function::Create(FT, GlobalValue::ExternalLinkage));
|
||||||
const CallInst *A = CallInst::Create(F.get(), makeArrayRef(values));
|
const CallInst *A = CallInst::Create(F.get(), makeArrayRef(values));
|
||||||
|
@ -180,7 +180,8 @@ TEST_F(InstrProfTest, get_profile_summary) {
|
|||||||
VerifySummary(PS);
|
VerifySummary(PS);
|
||||||
|
|
||||||
// Test that conversion of summary to and from Metadata works.
|
// Test that conversion of summary to and from Metadata works.
|
||||||
Metadata *MD = PS.getMD(getGlobalContext());
|
LLVMContext Context;
|
||||||
|
Metadata *MD = PS.getMD(Context);
|
||||||
ASSERT_TRUE(MD);
|
ASSERT_TRUE(MD);
|
||||||
ProfileSummary *PSFromMD = ProfileSummary::getFromMD(MD);
|
ProfileSummary *PSFromMD = ProfileSummary::getFromMD(MD);
|
||||||
ASSERT_TRUE(PSFromMD);
|
ASSERT_TRUE(PSFromMD);
|
||||||
@ -190,7 +191,7 @@ TEST_F(InstrProfTest, get_profile_summary) {
|
|||||||
delete IPS;
|
delete IPS;
|
||||||
|
|
||||||
// Test that summary can be attached to and read back from module.
|
// Test that summary can be attached to and read back from module.
|
||||||
Module M("my_module", getGlobalContext());
|
Module M("my_module", Context);
|
||||||
M.setProfileSummary(MD);
|
M.setProfileSummary(MD);
|
||||||
MD = M.getProfileSummary();
|
MD = M.getProfileSummary();
|
||||||
ASSERT_TRUE(MD);
|
ASSERT_TRUE(MD);
|
||||||
|
@ -29,6 +29,7 @@ namespace {
|
|||||||
|
|
||||||
struct SampleProfTest : ::testing::Test {
|
struct SampleProfTest : ::testing::Test {
|
||||||
std::string Data;
|
std::string Data;
|
||||||
|
LLVMContext Context;
|
||||||
std::unique_ptr<raw_ostream> OS;
|
std::unique_ptr<raw_ostream> OS;
|
||||||
std::unique_ptr<SampleProfileWriter> Writer;
|
std::unique_ptr<SampleProfileWriter> Writer;
|
||||||
std::unique_ptr<SampleProfileReader> Reader;
|
std::unique_ptr<SampleProfileReader> Reader;
|
||||||
@ -43,7 +44,7 @@ struct SampleProfTest : ::testing::Test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void readProfile(std::unique_ptr<MemoryBuffer> &Profile) {
|
void readProfile(std::unique_ptr<MemoryBuffer> &Profile) {
|
||||||
auto ReaderOrErr = SampleProfileReader::create(Profile, getGlobalContext());
|
auto ReaderOrErr = SampleProfileReader::create(Profile, Context);
|
||||||
ASSERT_TRUE(NoError(ReaderOrErr.getError()));
|
ASSERT_TRUE(NoError(ReaderOrErr.getError()));
|
||||||
Reader = std::move(ReaderOrErr.get());
|
Reader = std::move(ReaderOrErr.get());
|
||||||
}
|
}
|
||||||
@ -127,7 +128,7 @@ struct SampleProfTest : ::testing::Test {
|
|||||||
VerifySummary(Summary);
|
VerifySummary(Summary);
|
||||||
|
|
||||||
// Test that conversion of summary to and from Metadata works.
|
// Test that conversion of summary to and from Metadata works.
|
||||||
Metadata *MD = Summary.getMD(getGlobalContext());
|
Metadata *MD = Summary.getMD(Context);
|
||||||
ASSERT_TRUE(MD);
|
ASSERT_TRUE(MD);
|
||||||
ProfileSummary *PS = ProfileSummary::getFromMD(MD);
|
ProfileSummary *PS = ProfileSummary::getFromMD(MD);
|
||||||
ASSERT_TRUE(PS);
|
ASSERT_TRUE(PS);
|
||||||
@ -137,7 +138,7 @@ struct SampleProfTest : ::testing::Test {
|
|||||||
delete SPS;
|
delete SPS;
|
||||||
|
|
||||||
// Test that summary can be attached to and read back from module.
|
// Test that summary can be attached to and read back from module.
|
||||||
Module M("my_module", getGlobalContext());
|
Module M("my_module", Context);
|
||||||
M.setProfileSummary(MD);
|
M.setProfileSummary(MD);
|
||||||
MD = M.getProfileSummary();
|
MD = M.getProfileSummary();
|
||||||
ASSERT_TRUE(MD);
|
ASSERT_TRUE(MD);
|
||||||
|
@ -21,7 +21,7 @@ namespace {
|
|||||||
|
|
||||||
|
|
||||||
TEST(IntegerDivision, SDiv) {
|
TEST(IntegerDivision, SDiv) {
|
||||||
LLVMContext &C(getGlobalContext());
|
LLVMContext C;
|
||||||
Module M("test division", C);
|
Module M("test division", C);
|
||||||
IRBuilder<> Builder(C);
|
IRBuilder<> Builder(C);
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ TEST(IntegerDivision, SDiv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(IntegerDivision, UDiv) {
|
TEST(IntegerDivision, UDiv) {
|
||||||
LLVMContext &C(getGlobalContext());
|
LLVMContext C;
|
||||||
Module M("test division", C);
|
Module M("test division", C);
|
||||||
IRBuilder<> Builder(C);
|
IRBuilder<> Builder(C);
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ TEST(IntegerDivision, UDiv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(IntegerDivision, SRem) {
|
TEST(IntegerDivision, SRem) {
|
||||||
LLVMContext &C(getGlobalContext());
|
LLVMContext C;
|
||||||
Module M("test remainder", C);
|
Module M("test remainder", C);
|
||||||
IRBuilder<> Builder(C);
|
IRBuilder<> Builder(C);
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ TEST(IntegerDivision, SRem) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(IntegerDivision, URem) {
|
TEST(IntegerDivision, URem) {
|
||||||
LLVMContext &C(getGlobalContext());
|
LLVMContext C;
|
||||||
Module M("test remainder", C);
|
Module M("test remainder", C);
|
||||||
IRBuilder<> Builder(C);
|
IRBuilder<> Builder(C);
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ TEST(IntegerDivision, URem) {
|
|||||||
|
|
||||||
|
|
||||||
TEST(IntegerDivision, SDiv64) {
|
TEST(IntegerDivision, SDiv64) {
|
||||||
LLVMContext &C(getGlobalContext());
|
LLVMContext C;
|
||||||
Module M("test division", C);
|
Module M("test division", C);
|
||||||
IRBuilder<> Builder(C);
|
IRBuilder<> Builder(C);
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ TEST(IntegerDivision, SDiv64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(IntegerDivision, UDiv64) {
|
TEST(IntegerDivision, UDiv64) {
|
||||||
LLVMContext &C(getGlobalContext());
|
LLVMContext C;
|
||||||
Module M("test division", C);
|
Module M("test division", C);
|
||||||
IRBuilder<> Builder(C);
|
IRBuilder<> Builder(C);
|
||||||
|
|
||||||
@ -202,7 +202,7 @@ TEST(IntegerDivision, UDiv64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(IntegerDivision, SRem64) {
|
TEST(IntegerDivision, SRem64) {
|
||||||
LLVMContext &C(getGlobalContext());
|
LLVMContext C;
|
||||||
Module M("test remainder", C);
|
Module M("test remainder", C);
|
||||||
IRBuilder<> Builder(C);
|
IRBuilder<> Builder(C);
|
||||||
|
|
||||||
@ -232,7 +232,7 @@ TEST(IntegerDivision, SRem64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(IntegerDivision, URem64) {
|
TEST(IntegerDivision, URem64) {
|
||||||
LLVMContext &C(getGlobalContext());
|
LLVMContext C;
|
||||||
Module M("test remainder", C);
|
Module M("test remainder", C);
|
||||||
IRBuilder<> Builder(C);
|
IRBuilder<> Builder(C);
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
TEST(Local, RecursivelyDeleteDeadPHINodes) {
|
TEST(Local, RecursivelyDeleteDeadPHINodes) {
|
||||||
LLVMContext &C(getGlobalContext());
|
LLVMContext C;
|
||||||
|
|
||||||
IRBuilder<> builder(C);
|
IRBuilder<> builder(C);
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ TEST(Local, RecursivelyDeleteDeadPHINodes) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(Local, RemoveDuplicatePHINodes) {
|
TEST(Local, RemoveDuplicatePHINodes) {
|
||||||
LLVMContext &C(getGlobalContext());
|
LLVMContext C;
|
||||||
IRBuilder<> B(C);
|
IRBuilder<> B(C);
|
||||||
|
|
||||||
std::unique_ptr<Function> F(
|
std::unique_ptr<Function> F(
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
TEST(MemorySSA, RemoveMemoryAccess) {
|
TEST(MemorySSA, RemoveMemoryAccess) {
|
||||||
LLVMContext &C(getGlobalContext());
|
LLVMContext C;
|
||||||
std::unique_ptr<Module> M(new Module("Remove memory access", C));
|
std::unique_ptr<Module> M(new Module("Remove memory access", C));
|
||||||
IRBuilder<> B(C);
|
IRBuilder<> B(C);
|
||||||
DataLayout DL("e-i64:64-f80:128-n8:16:32:64-S128");
|
DataLayout DL("e-i64:64-f80:128-n8:16:32:64-S128");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user