Commit 758a9b32 authored by Marius Wachtler's avatar Marius Wachtler

Merge pull request #970 from undingen/cache_optimized

object cache: hash IR before running any opt passes
parents accd1839 1e62e500
...@@ -31,6 +31,8 @@ class TargetMachine; ...@@ -31,6 +31,8 @@ class TargetMachine;
namespace pyston { namespace pyston {
class PystonObjectCache;
class FunctionAddressRegistry { class FunctionAddressRegistry {
private: private:
struct FuncInfo { struct FuncInfo {
...@@ -62,6 +64,7 @@ struct GlobalState { ...@@ -62,6 +64,7 @@ struct GlobalState {
CompiledFunction* cur_cf; CompiledFunction* cur_cf;
llvm::TargetMachine* tm; llvm::TargetMachine* tm;
llvm::ExecutionEngine* engine; llvm::ExecutionEngine* engine;
PystonObjectCache* object_cache;
std::vector<llvm::JITEventListener*> jit_listeners; std::vector<llvm::JITEventListener*> jit_listeners;
......
This diff is collapsed.
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <stdint.h> #include <stdint.h>
#include "llvm/Analysis/Passes.h" #include "llvm/Analysis/Passes.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/IR/DIBuilder.h" #include "llvm/IR/DIBuilder.h"
#include "llvm/IR/Module.h" #include "llvm/IR/Module.h"
#include "llvm/IR/Verifier.h" #include "llvm/IR/Verifier.h"
...@@ -1120,8 +1121,18 @@ CompiledFunction* doCompile(CLFunction* clfunc, SourceInfo* source, ParamNames* ...@@ -1120,8 +1121,18 @@ CompiledFunction* doCompile(CLFunction* clfunc, SourceInfo* source, ParamNames*
static StatCounter us_irgen("us_compiling_irgen"); static StatCounter us_irgen("us_compiling_irgen");
us_irgen.log(irgen_us); us_irgen.log(irgen_us);
if (ENABLE_LLVMOPTS)
optimizeIR(f, effort); // Calculate the module hash before doing any optimizations.
// This has the advantage that we can skip running the opt passes when we have cached object file
// but the disadvantage that optimizations are not allowed to add new symbolic constants...
if (ENABLE_JIT_OBJECT_CACHE) {
g.object_cache->calculateModuleHash(g.cur_module, effort);
if (ENABLE_LLVMOPTS && !g.object_cache->haveCacheFileForHash())
optimizeIR(f, effort);
} else {
if (ENABLE_LLVMOPTS)
optimizeIR(f, effort);
}
g.cur_module = NULL; g.cur_module = NULL;
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#ifndef PYSTON_CODEGEN_IRGEN_H #ifndef PYSTON_CODEGEN_IRGEN_H
#define PYSTON_CODEGEN_IRGEN_H #define PYSTON_CODEGEN_IRGEN_H
#include "llvm/ADT/SmallString.h"
#include "llvm/ExecutionEngine/ObjectCache.h"
#include "llvm/IR/CallSite.h" #include "llvm/IR/CallSite.h"
#include "llvm/IR/Function.h" #include "llvm/IR/Function.h"
#include "llvm/IR/Intrinsics.h" #include "llvm/IR/Intrinsics.h"
...@@ -150,6 +152,35 @@ public: ...@@ -150,6 +152,35 @@ public:
ExceptionStyle preferredExceptionStyle() const { return unw_info.preferredExceptionStyle(); } ExceptionStyle preferredExceptionStyle() const { return unw_info.preferredExceptionStyle(); }
}; };
class PystonObjectCache : public llvm::ObjectCache {
private:
llvm::SmallString<128> cache_dir;
std::string module_identifier;
std::string hash_before_codegen;
public:
PystonObjectCache();
#if LLVMREV < 216002
virtual void notifyObjectCompiled(const llvm::Module* M, const llvm::MemoryBuffer* Obj);
#else
virtual void notifyObjectCompiled(const llvm::Module* M, llvm::MemoryBufferRef Obj);
#endif
#if LLVMREV < 215566
virtual llvm::MemoryBuffer* getObject(const llvm::Module* M);
#else
virtual std::unique_ptr<llvm::MemoryBuffer> getObject(const llvm::Module* M);
#endif
void cleanupCacheDirectory();
void calculateModuleHash(const llvm::Module* M, EffortLevel effort);
bool haveCacheFileForHash();
};
} }
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment