Skip to content

Commit

Permalink
Reinstate "Nuke the old JIT."
Browse files Browse the repository at this point in the history
Approved by Jim Grosbach, Lang Hames, Rafael Espindola.

This reinstates commits r215111, 215115, 215116, 215117, 215136.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216982 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
echristo committed Sep 2, 2014
1 parent 4437658 commit d5dd8ce
Show file tree
Hide file tree
Showing 258 changed files with 184 additions and 12,590 deletions.
7 changes: 1 addition & 6 deletions Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -1669,18 +1669,13 @@ $(ObjDir)/%GenAsmMatcher.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
$(TARGET:%=$(ObjDir)/%GenMCCodeEmitter.inc.tmp): \
$(ObjDir)/%GenMCCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
$(Echo) "Building $(<F) MC code emitter with tblgen"
$(Verb) $(LLVMTableGen) -gen-emitter -mc-emitter -o $(call SYSPATH, $@) $<
$(Verb) $(LLVMTableGen) -gen-emitter -o $(call SYSPATH, $@) $<

$(TARGET:%=$(ObjDir)/%GenMCPseudoLowering.inc.tmp): \
$(ObjDir)/%GenMCPseudoLowering.inc.tmp: %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
$(Echo) "Building $(<F) MC Pseudo instruction expander with tblgen"
$(Verb) $(LLVMTableGen) -gen-pseudo-lowering -o $(call SYSPATH, $@) $<

$(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
$(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
$(Echo) "Building $(<F) code emitter with tblgen"
$(Verb) $(LLVMTableGen) -gen-emitter -o $(call SYSPATH, $@) $<

$(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
$(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
$(Echo) "Building $(<F) DAG instruction selector implementation with tblgen"
Expand Down
2 changes: 1 addition & 1 deletion bindings/ocaml/executionengine/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

LEVEL := ../../..
LIBRARYNAME := llvm_executionengine
UsedComponents := executionengine jit interpreter native
UsedComponents := executionengine mcjit interpreter native
UsedOcamlInterfaces := llvm llvm_target

include ../Makefile.ocaml
2 changes: 1 addition & 1 deletion bindings/ocaml/executionengine/executionengine_ocaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/* Force the LLVM interpreter and JIT to be linked in. */
void llvm_initialize(void) {
LLVMLinkInInterpreter();
LLVMLinkInJIT();
LLVMLinkInMCJIT();
}

/* unit -> bool */
Expand Down
3 changes: 1 addition & 2 deletions docs/TableGen/BackEnds.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ returns the (currently, 32-bit unsigned) value of the instruction.
**Output**: C++ code, implementing the target's CodeEmitter
class by overriding the virtual functions as ``<Target>CodeEmitter::function()``.

**Usage**: Used to include directly at the end of ``<Target>CodeEmitter.cpp``, and
with option `-mc-emitter` to be included in ``<Target>MCCodeEmitter.cpp``.
**Usage**: Used to include directly at the end of ``<Target>MCCodeEmitter.cpp``.

RegisterInfo
------------
Expand Down
2 changes: 1 addition & 1 deletion examples/BrainF/BrainFDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

#include "BrainF.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/GenericValue.h"
#include "llvm/ExecutionEngine/JIT.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/CommandLine.h"
Expand Down
1 change: 0 additions & 1 deletion examples/BrainF/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ set(LLVM_LINK_COMPONENTS
BitWriter
Core
ExecutionEngine
JIT
MC
Support
nativecodegen
Expand Down
2 changes: 0 additions & 2 deletions examples/ExceptionDemo/ExceptionDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1966,10 +1966,8 @@ int main(int argc, char *argv[]) {
// Build engine with JIT
llvm::EngineBuilder factory(std::move(Owner));
factory.setEngineKind(llvm::EngineKind::JIT);
factory.setAllocateGVsWithCode(false);
factory.setTargetOptions(Opts);
factory.setMCJITMemoryManager(MemMgr);
factory.setUseMCJIT(true);
llvm::ExecutionEngine *executionEngine = factory.create();

{
Expand Down
1 change: 0 additions & 1 deletion examples/Fibonacci/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ set(LLVM_LINK_COMPONENTS
Core
ExecutionEngine
Interpreter
JIT
MC
Support
nativecodegen
Expand Down
1 change: 0 additions & 1 deletion examples/Fibonacci/fibonacci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "llvm/IR/Verifier.h"
#include "llvm/ExecutionEngine/GenericValue.h"
#include "llvm/ExecutionEngine/Interpreter.h"
#include "llvm/ExecutionEngine/JIT.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Instructions.h"
Expand Down
1 change: 0 additions & 1 deletion examples/HowToUseJIT/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ set(LLVM_LINK_COMPONENTS
Core
ExecutionEngine
Interpreter
JIT
MC
Support
nativecodegen
Expand Down
2 changes: 0 additions & 2 deletions examples/HowToUseJIT/HowToUseJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

#include "llvm/ExecutionEngine/GenericValue.h"
#include "llvm/ExecutionEngine/Interpreter.h"
#include "llvm/ExecutionEngine/JIT.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/IRBuilder.h"
Expand Down Expand Up @@ -127,7 +126,6 @@ int main() {

// Import result of execution:
outs() << "Result: " << gv.IntVal << "\n";
EE->freeMachineCodeForFunction(FooF);
delete EE;
llvm_shutdown();
return 0;
Expand Down
1 change: 0 additions & 1 deletion examples/Kaleidoscope/Chapter4/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ set(LLVM_LINK_COMPONENTS
Core
ExecutionEngine
InstCombine
JIT
MC
ScalarOpts
Support
Expand Down
1 change: 0 additions & 1 deletion examples/Kaleidoscope/Chapter4/toy.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "llvm/Analysis/Passes.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JIT.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/IRBuilder.h"
Expand Down
1 change: 0 additions & 1 deletion examples/Kaleidoscope/Chapter5/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ set(LLVM_LINK_COMPONENTS
Core
ExecutionEngine
InstCombine
JIT
MC
ScalarOpts
Support
Expand Down
1 change: 0 additions & 1 deletion examples/Kaleidoscope/Chapter5/toy.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "llvm/Analysis/Passes.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JIT.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/IRBuilder.h"
Expand Down
1 change: 0 additions & 1 deletion examples/Kaleidoscope/Chapter6/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ set(LLVM_LINK_COMPONENTS
Core
ExecutionEngine
InstCombine
JIT
MC
ScalarOpts
Support
Expand Down
1 change: 0 additions & 1 deletion examples/Kaleidoscope/Chapter6/toy.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "llvm/Analysis/Passes.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JIT.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/IRBuilder.h"
Expand Down
1 change: 0 additions & 1 deletion examples/Kaleidoscope/Chapter7/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ set(LLVM_LINK_COMPONENTS
Core
ExecutionEngine
InstCombine
JIT
MC
ScalarOpts
Support
Expand Down
1 change: 0 additions & 1 deletion examples/Kaleidoscope/Chapter7/toy.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "llvm/Analysis/Passes.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JIT.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/IRBuilder.h"
Expand Down
1 change: 0 additions & 1 deletion examples/Kaleidoscope/MCJIT/cached/toy-jit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "llvm/Analysis/Passes.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JIT.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/IRBuilder.h"
Expand Down
1 change: 0 additions & 1 deletion examples/Kaleidoscope/MCJIT/cached/toy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,6 @@ ExecutionEngine *MCJITHelper::compileModule(Module *M) {
std::string ErrStr;
ExecutionEngine *NewEngine = EngineBuilder(M)
.setErrorStr(&ErrStr)
.setUseMCJIT(true)
.setMCJITMemoryManager(new HelpingMemoryManager(this))
.create();
if (!NewEngine) {
Expand Down
129 changes: 8 additions & 121 deletions examples/Kaleidoscope/MCJIT/complete/toy.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "llvm/Analysis/Passes.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JIT.h"
#include "llvm/ExecutionEngine/MCJIT.h"
#include "llvm/ExecutionEngine/ObjectCache.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
Expand Down Expand Up @@ -52,10 +51,6 @@ namespace {
cl::desc("Dump IR from modules to stderr on shutdown"),
cl::init(false));

cl::opt<bool> UseMCJIT(
"use-mcjit", cl::desc("Use the MCJIT execution engine"),
cl::init(true));

cl::opt<bool> EnableLazyCompilation(
"enable-lazy-compilation", cl::desc("Enable lazy compilation when using the MCJIT engine"),
cl::init(true));
Expand Down Expand Up @@ -792,96 +787,6 @@ class BaseHelper
virtual void dump();
};

//===----------------------------------------------------------------------===//
// Helper class for JIT execution engine
//===----------------------------------------------------------------------===//

class JITHelper : public BaseHelper {
public:
JITHelper(LLVMContext &Context) {
// Make the module, which holds all the code.
if (!InputIR.empty()) {
TheModule = parseInputIR(InputIR, Context);
} else {
TheModule = new Module("my cool jit", Context);
}

// Create the JIT. This takes ownership of the module.
std::string ErrStr;
TheExecutionEngine = EngineBuilder(TheModule).setErrorStr(&ErrStr).create();
if (!TheExecutionEngine) {
fprintf(stderr, "Could not create ExecutionEngine: %s\n", ErrStr.c_str());
exit(1);
}

TheFPM = new FunctionPassManager(TheModule);

// Set up the optimizer pipeline. Start with registering info about how the
// target lays out data structures.
TheFPM->add(new DataLayout(*TheExecutionEngine->getDataLayout()));
// Provide basic AliasAnalysis support for GVN.
TheFPM->add(createBasicAliasAnalysisPass());
// Promote allocas to registers.
TheFPM->add(createPromoteMemoryToRegisterPass());
// Do simple "peephole" optimizations and bit-twiddling optzns.
TheFPM->add(createInstructionCombiningPass());
// Reassociate expressions.
TheFPM->add(createReassociatePass());
// Eliminate Common SubExpressions.
TheFPM->add(createGVNPass());
// Simplify the control flow graph (deleting unreachable blocks, etc).
TheFPM->add(createCFGSimplificationPass());

TheFPM->doInitialization();
}

virtual ~JITHelper() {
if (TheFPM)
delete TheFPM;
if (TheExecutionEngine)
delete TheExecutionEngine;
}

virtual Function *getFunction(const std::string FnName) {
assert(TheModule);
return TheModule->getFunction(FnName);
}

virtual Module *getModuleForNewFunction() {
assert(TheModule);
return TheModule;
}

virtual void *getPointerToFunction(Function* F) {
assert(TheExecutionEngine);
return TheExecutionEngine->getPointerToFunction(F);
}

virtual void *getPointerToNamedFunction(const std::string &Name) {
return TheExecutionEngine->getPointerToNamedFunction(Name);
}

virtual void runFPM(Function &F) {
assert(TheFPM);
TheFPM->run(F);
}

virtual void closeCurrentModule() {
// This should never be called for JIT
assert(false);
}

virtual void dump() {
assert(TheModule);
TheModule->dump();
}

private:
Module *TheModule;
ExecutionEngine *TheExecutionEngine;
FunctionPassManager *TheFPM;
};

//===----------------------------------------------------------------------===//
// MCJIT helper class
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -1034,7 +939,6 @@ ExecutionEngine *MCJITHelper::compileModule(Module *M) {
std::string ErrStr;
ExecutionEngine *EE = EngineBuilder(M)
.setErrorStr(&ErrStr)
.setUseMCJIT(true)
.setMCJITMemoryManager(new HelpingMemoryManager(this))
.create();
if (!EE) {
Expand Down Expand Up @@ -1194,10 +1098,8 @@ Value *UnaryExprAST::Codegen() {
Value *OperandV = Operand->Codegen();
if (OperandV == 0) return 0;
Function *F;
if (UseMCJIT)
F = TheHelper->getFunction(MakeLegalFunctionName(std::string("unary")+Opcode));
else
F = TheHelper->getFunction(std::string("unary")+Opcode);
F = TheHelper->getFunction(
MakeLegalFunctionName(std::string("unary") + Opcode));
if (F == 0)
return ErrorV("Unknown unary operator");

Expand Down Expand Up @@ -1246,10 +1148,7 @@ Value *BinaryExprAST::Codegen() {
// If it wasn't a builtin binary operator, it must be a user defined one. Emit
// a call to it.
Function *F;
if (UseMCJIT)
F = TheHelper->getFunction(MakeLegalFunctionName(std::string("binary")+Op));
else
F = TheHelper->getFunction(std::string("binary")+Op);
F = TheHelper->getFunction(MakeLegalFunctionName(std::string("binary")+Op));
assert(F && "binary operator not found!");

Value *Ops[] = { L, R };
Expand Down Expand Up @@ -1482,10 +1381,7 @@ Function *PrototypeAST::Codegen() {
Doubles, false);

std::string FnName;
if (UseMCJIT)
FnName = MakeLegalFunctionName(Name);
else
FnName = Name;
FnName = MakeLegalFunctionName(Name);

Module* M = TheHelper->getModuleForNewFunction();
Function *F = Function::Create(FT, Function::ExternalLinkage, FnName, M);
Expand Down Expand Up @@ -1560,10 +1456,6 @@ Function *FunctionAST::Codegen() {
// Validate the generated code, checking for consistency.
verifyFunction(*TheFunction);

// Optimize the function.
if (!UseMCJIT)
TheHelper->runFPM(*TheFunction);

return TheFunction;
}

Expand All @@ -1581,7 +1473,7 @@ Function *FunctionAST::Codegen() {

static void HandleDefinition() {
if (FunctionAST *F = ParseDefinition()) {
if (UseMCJIT && EnableLazyCompilation)
if (EnableLazyCompilation)
TheHelper->closeCurrentModule();
Function *LF = F->Codegen();
if (LF && VerboseOutput) {
Expand Down Expand Up @@ -1671,10 +1563,8 @@ double printlf() {

int main(int argc, char **argv) {
InitializeNativeTarget();
if (UseMCJIT) {
InitializeNativeTargetAsmPrinter();
InitializeNativeTargetAsmParser();
}
InitializeNativeTargetAsmPrinter();
InitializeNativeTargetAsmParser();
LLVMContext &Context = getGlobalContext();

cl::ParseCommandLineOptions(argc, argv,
Expand All @@ -1690,10 +1580,7 @@ int main(int argc, char **argv) {
BinopPrecedence['*'] = 40; // highest.

// Make the Helper, which holds all the code.
if (UseMCJIT)
TheHelper = new MCJITHelper(Context);
else
TheHelper = new JITHelper(Context);
TheHelper = new MCJITHelper(Context);

// Prime the first token.
if (!SuppressPrompts)
Expand Down
Loading

0 comments on commit d5dd8ce

Please sign in to comment.