2015-01-20 03:00:42 +00:00
|
|
|
#ifndef JIT_COMPILER_HPP
|
|
|
|
#define JIT_COMPILER_HPP
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
|
|
#include "llvm/Linker/Linker.h"
|
|
|
|
#include "llvm/PassManager.h"
|
|
|
|
#include "llvm/Analysis/CallGraphSCCPass.h"
|
2015-06-19 01:17:07 +01:00
|
|
|
#include "llvm/Analysis/Passes.h"
|
2015-01-20 03:00:42 +00:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2015-06-19 01:17:07 +01:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2015-01-20 03:00:42 +00:00
|
|
|
#include "llvm/ADT/StringSet.h"
|
|
|
|
#include "llvm/ADT/Triple.h"
|
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2015-06-19 01:17:07 +01:00
|
|
|
#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineJumpTableInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineLoopInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineRegionInfo.h"
|
|
|
|
#include "llvm/ExecutionEngine/ExecutionEngine.h"
|
|
|
|
#include "llvm/ExecutionEngine/MCJIT.h"
|
2015-01-20 03:00:42 +00:00
|
|
|
#include "llvm/ExecutionEngine/Interpreter.h"
|
|
|
|
#include "llvm/ExecutionEngine/GenericValue.h"
|
|
|
|
#include "llvm/ExecutionEngine/JITEventListener.h"
|
2015-06-19 01:17:07 +01:00
|
|
|
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
|
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/DataLayout.h"
|
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
|
|
|
#include "llvm/IR/Instructions.h"
|
|
|
|
#include "llvm/IR/IRBuilder.h"
|
|
|
|
#include "llvm/IR/IRPrintingPasses.h"
|
|
|
|
#include "llvm/IR/LegacyPassManager.h"
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
|
|
|
#include "llvm/IR/TypeBuilder.h"
|
|
|
|
#include "llvm/IR/Verifier.h"
|
2015-01-20 03:00:42 +00:00
|
|
|
#include "llvm/IRReader/IRReader.h"
|
|
|
|
#include "llvm/Support/Host.h"
|
|
|
|
#include "llvm/Support/Path.h"
|
|
|
|
#include "llvm/Support/TargetSelect.h"
|
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
|
|
|
#include "llvm/Support/raw_os_ostream.h"
|
|
|
|
//#include "llvm/Support/PathV1.h"
|
|
|
|
#include "llvm/Support/ToolOutputFile.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetOptions.h"
|
|
|
|
#include "llvm/Target/TargetLibraryInfo.h"
|
|
|
|
#include "llvm/Analysis/Passes.h"
|
|
|
|
#include "llvm/Analysis/IVUsers.h"
|
|
|
|
#include "llvm/Analysis/Lint.h"
|
|
|
|
#include "llvm/Analysis/LoopPass.h"
|
|
|
|
#include "llvm/Analysis/RegionPass.h"
|
|
|
|
#include "llvm/Analysis/CFGPrinter.h"
|
|
|
|
#include "llvm/Analysis/DomPrinter.h"
|
|
|
|
#include "llvm/Analysis/BranchProbabilityInfo.h"
|
|
|
|
#include "llvm/Analysis/RegionPrinter.h"
|
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2015-09-25 10:57:26 +01:00
|
|
|
//#include "llvm/Support/SYSTEM_ERROR_INTERNAL.h"
|
2015-01-20 03:00:42 +00:00
|
|
|
#include "llvm/Support/Process.h"
|
|
|
|
#include "llvm/Bitcode/ReaderWriter.h"
|
|
|
|
#include "llvm/Transforms/IPO.h"
|
|
|
|
#include "llvm/Transforms/Scalar.h"
|
|
|
|
#include "llvm/Transforms/Vectorize.h"
|
|
|
|
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
|
|
|
#include "llvm/Transforms/Utils/Cloning.h"
|
|
|
|
#include "llvm/Transforms/ObjCARC.h"
|
|
|
|
#include "llvm/Support/FileSystem.h"
|
2015-06-19 01:17:07 +01:00
|
|
|
#include "llvm/Pass.h"
|
2015-01-20 03:00:42 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include "JIT.hpp"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
extern short global;
|
|
|
|
extern Environment ExpEnv;
|
|
|
|
extern NativeContext *NativeArea;
|
|
|
|
|
|
|
|
class JIT_Compiler {
|
2015-01-26 04:02:46 +00:00
|
|
|
private:
|
|
|
|
/* main method of JIT Compiler: compiles by clang, analyzes, optimizs and generates code accordingly the user choices */
|
|
|
|
void* compile_all(LLVMContext* &Context, yamop* p);
|
2015-01-20 03:00:42 +00:00
|
|
|
|
2015-01-26 04:02:46 +00:00
|
|
|
/* aid method to 'compile_all': adds register allocator pass to be used.
|
|
|
|
WARNING: don't use! For some reasons llvm crashes when I use it */
|
|
|
|
void set_regalloc_pass(PassManager &PM);
|
2015-01-20 03:00:42 +00:00
|
|
|
|
2015-01-26 04:02:46 +00:00
|
|
|
/* aid method to 'compile_all': optimizes module by individual transform passes or transform level */
|
|
|
|
void optimize_module(llvm::Module* &M);
|
2015-01-20 03:00:42 +00:00
|
|
|
|
2015-01-26 04:02:46 +00:00
|
|
|
/* aid method to 'compile_all': analyzes module by individual analysis passes */
|
|
|
|
void analyze_module(llvm::Module* &M);
|
|
|
|
public:
|
|
|
|
/* method invoked by wrapper 'call_JIT_Compiler' */
|
|
|
|
void* compile(yamop*);
|
|
|
|
};
|
|
|
|
|
2015-02-06 18:11:52 +00:00
|
|
|
extern "C" void* call_JIT_Compiler(JIT_Compiler* jc, yamop* p);
|
2015-01-20 03:00:42 +00:00
|
|
|
|
2015-02-06 18:11:52 +00:00
|
|
|
extern "C" void shutdown_llvm();
|
2015-01-20 03:00:42 +00:00
|
|
|
|
2015-01-26 04:02:46 +00:00
|
|
|
#else
|
|
|
|
|
2015-02-06 18:11:52 +00:00
|
|
|
typedef struct jit_compiler JIT_Compiler;
|
2015-01-26 04:02:46 +00:00
|
|
|
|
2015-02-06 18:11:52 +00:00
|
|
|
EXTERN void* (*Yap_JitCall)(JIT_Compiler* jc, yamop* p);
|
2015-01-26 04:02:46 +00:00
|
|
|
|
2015-02-06 18:11:52 +00:00
|
|
|
INLINE_ONLY inline EXTERN void* call_JIT_Compiler(JIT_Compiler* jc, yamop* p);
|
2015-01-26 04:02:46 +00:00
|
|
|
|
2015-02-06 18:11:52 +00:00
|
|
|
INLINE_ONLY inline EXTERN void* call_JIT_Compiler(JIT_Compiler* jc, yamop* p) {
|
|
|
|
return Yap_JitCall (jc,p); }
|
2015-01-26 04:02:46 +00:00
|
|
|
|
|
|
|
INLINE_ONLY inline EXTERN void shutdown_llvm(void ) ;
|
|
|
|
|
|
|
|
EXTERN void (* Yap_llvmShutdown)(void ) ;
|
|
|
|
|
|
|
|
INLINE_ONLY inline EXTERN void shutdown_llvm(void ) { Yap_llvmShutdown (); }
|
|
|
|
|
2015-02-06 18:11:52 +00:00
|
|
|
#endif
|
2015-01-20 03:00:42 +00:00
|
|
|
|
|
|
|
#endif
|