Commit d817b297 authored by Marius Wachtler's avatar Marius Wachtler Committed by GitHub

Merge pull request #1317 from undingen/delete_llvm_mod

delete the llvm module after code generation
parents fca39ba9 d8f237b3
......@@ -637,7 +637,8 @@ _call(IREmitter& emitter, const OpInfo& info, llvm::Value* func, ExceptionStyle
// Don't use the IRBuilder since we want to specifically put this in the entry block so it only gets called
// once.
// TODO we could take this further and use the same alloca for all function calls?
llvm::Instruction* insertion_point = emitter.currentFunction()->func->getEntryBlock().getFirstInsertionPt();
llvm::Instruction* insertion_point
= emitter.getBuilder()->GetInsertBlock()->getParent()->getEntryBlock().getFirstInsertionPt();
arg_array = new llvm::AllocaInst(g.llvm_value_type_ptr, n_varargs, "arg_scratch", insertion_point);
for (int i = 3; i < args.size(); i++) {
......@@ -1928,7 +1929,7 @@ public:
llvm::FunctionType* ft = llvm::FunctionType::get(cf->spec->rtn_type->llvmType(), arg_types, false);
llvm::Value* linked_function;
if (cf->func) // for JITed functions we need to make the desination address relocatable.
if (cf->md->source) // for JITed functions we need to make the desination address relocatable.
linked_function = embedRelocatablePtr(cf->code, ft->getPointerTo());
else
linked_function = embedConstantPtr(cf->code, ft->getPointerTo());
......
......@@ -1023,9 +1023,11 @@ static std::string getUniqueFunctionName(std::string nameprefix, EffortLevel eff
return os.str();
}
CompiledFunction* doCompile(FunctionMetadata* md, SourceInfo* source, ParamNames* param_names,
const OSREntryDescriptor* entry_descriptor, EffortLevel effort,
ExceptionStyle exception_style, FunctionSpecialization* spec, llvm::StringRef nameprefix) {
std::pair<CompiledFunction*, llvm::Function*> doCompile(FunctionMetadata* md, SourceInfo* source,
ParamNames* param_names,
const OSREntryDescriptor* entry_descriptor, EffortLevel effort,
ExceptionStyle exception_style, FunctionSpecialization* spec,
llvm::StringRef nameprefix) {
Timer _t("in doCompile");
Timer _t2;
long irgen_us = 0;
......@@ -1096,8 +1098,6 @@ CompiledFunction* doCompile(FunctionMetadata* md, SourceInfo* source, ParamNames
llvm::Function* f = llvm::Function::Create(ft, llvm::Function::ExternalLinkage, name, g.cur_module);
cf->func = f;
// g.func_registry.registerFunction(f, g.cur_module);
llvm::MDNode* dbg_funcinfo = setupDebugInfo(source, f, nameprefix);
......@@ -1138,7 +1138,7 @@ CompiledFunction* doCompile(FunctionMetadata* md, SourceInfo* source, ParamNames
RefcountTracker refcounter;
IRGenState irstate(md, cf, source, std::move(phis), param_names, getGCBuilder(), dbg_funcinfo, &refcounter);
IRGenState irstate(md, cf, f, source, std::move(phis), param_names, getGCBuilder(), dbg_funcinfo, &refcounter);
emitBBs(&irstate, types, entry_descriptor, blocks);
assert(!llvm::verifyFunction(*f, &llvm::errs()));
......@@ -1187,7 +1187,7 @@ CompiledFunction* doCompile(FunctionMetadata* md, SourceInfo* source, ParamNames
g.cur_module = NULL;
return cf;
return std::make_pair(cf, f);
}
......
......@@ -137,9 +137,9 @@ extern const std::string PASSED_GENERATOR_NAME;
InternedString getIsDefinedName(InternedString name, InternedStringPool& interned_strings);
bool isIsDefinedName(llvm::StringRef name);
CompiledFunction* doCompile(FunctionMetadata* md, SourceInfo* source, ParamNames* param_names,
const OSREntryDescriptor* entry_descriptor, EffortLevel effort,
ExceptionStyle exception_style, FunctionSpecialization* spec, llvm::StringRef nameprefix);
std::pair<CompiledFunction*, llvm::Function*>
doCompile(FunctionMetadata* md, SourceInfo* source, ParamNames* param_names, const OSREntryDescriptor* entry_descriptor,
EffortLevel effort, ExceptionStyle exception_style, FunctionSpecialization* spec, llvm::StringRef nameprefix);
// A common pattern is to branch based off whether a variable is defined but only if it is
// potentially-undefined. If it is potentially-undefined, we have to generate control-flow
......
......@@ -157,23 +157,25 @@ LivenessAnalysis* SourceInfo::getLiveness() {
return liveness_info.get();
}
static void compileIR(CompiledFunction* cf, EffortLevel effort) {
static void compileIR(CompiledFunction* cf, llvm::Function* func, EffortLevel effort) {
assert(cf);
assert(cf->func);
assert(func);
void* compiled = NULL;
cf->code = NULL;
{
Timer _t("to jit the IR");
llvm::Module* module = func->getParent();
#if LLVMREV < 215967
g.engine->addModule(cf->func->getParent());
g.engine->addModule(module);
#else
g.engine->addModule(std::unique_ptr<llvm::Module>(cf->func->getParent()));
g.engine->addModule(std::unique_ptr<llvm::Module>(module));
#endif
g.cur_cf = cf;
void* compiled = (void*)g.engine->getFunctionAddress(cf->func->getName());
void* compiled = (void*)g.engine->getFunctionAddress(func->getName());
g.cur_cf = NULL;
assert(compiled);
ASSERT(compiled == cf->code, "cf->code should have gotten filled in");
......@@ -185,9 +187,12 @@ static void compileIR(CompiledFunction* cf, EffortLevel effort) {
num_jits.log();
if (VERBOSITY() >= 1 && us > 100000) {
printf("Took %.1fs to compile %s\n", us * 0.000001, cf->func->getName().data());
printf("Has %ld basic blocks\n", cf->func->getBasicBlockList().size());
printf("Took %.1fs to compile %s\n", us * 0.000001, func->getName().data());
printf("Has %ld basic blocks\n", func->getBasicBlockList().size());
}
g.engine->removeModule(module);
delete module;
}
if (VERBOSITY("irgen") >= 2) {
......@@ -275,9 +280,11 @@ CompiledFunction* compileFunction(FunctionMetadata* f, FunctionSpecialization* s
}
CompiledFunction* cf
CompiledFunction* cf = NULL;
llvm::Function* func = NULL;
std::tie(cf, func)
= doCompile(f, source, &f->param_names, entry_descriptor, effort, exception_style, spec, name->s());
compileIR(cf, effort);
compileIR(cf, func, effort);
f->addVersion(cf);
......@@ -684,7 +691,6 @@ std::unordered_set<CompiledFunction*> all_compiled_functions;
CompiledFunction::CompiledFunction(FunctionMetadata* md, FunctionSpecialization* spec, void* code, EffortLevel effort,
ExceptionStyle exception_style, const OSREntryDescriptor* entry_descriptor)
: md(md),
func(NULL),
effort(effort),
exception_style(exception_style),
spec(spec),
......
......@@ -44,11 +44,12 @@ extern "C" void dumpLLVM(void* _v) {
v->dump();
}
IRGenState::IRGenState(FunctionMetadata* md, CompiledFunction* cf, SourceInfo* source_info,
IRGenState::IRGenState(FunctionMetadata* md, CompiledFunction* cf, llvm::Function* func, SourceInfo* source_info,
std::unique_ptr<PhiAnalysis> phis, ParamNames* param_names, GCBuilder* gc,
llvm::MDNode* func_dbg_info, RefcountTracker* refcount_tracker)
: md(md),
cf(cf),
func(func),
source_info(source_info),
phis(std::move(phis)),
param_names(param_names),
......@@ -61,7 +62,7 @@ IRGenState::IRGenState(FunctionMetadata* md, CompiledFunction* cf, SourceInfo* s
vregs(NULL),
stmt(NULL),
scratch_size(0) {
assert(cf->func);
assert(func);
assert(cf->md->source.get() == source_info); // I guess this is duplicate now
}
......
......@@ -63,6 +63,7 @@ private:
// to md at the end of irgen.
FunctionMetadata* md;
CompiledFunction* cf;
llvm::Function* func;
SourceInfo* source_info;
std::unique_ptr<PhiAnalysis> phis;
ParamNames* param_names;
......@@ -82,8 +83,9 @@ private:
int scratch_size;
public:
IRGenState(FunctionMetadata* md, CompiledFunction* cf, SourceInfo* source_info, std::unique_ptr<PhiAnalysis> phis,
ParamNames* param_names, GCBuilder* gc, llvm::MDNode* func_dbg_info, RefcountTracker* refcount_tracker);
IRGenState(FunctionMetadata* md, CompiledFunction* cf, llvm::Function* func, SourceInfo* source_info,
std::unique_ptr<PhiAnalysis> phis, ParamNames* param_names, GCBuilder* gc, llvm::MDNode* func_dbg_info,
RefcountTracker* refcount_tracker);
~IRGenState();
CFG* getCFG() { return getSourceInfo()->cfg; }
......@@ -93,7 +95,7 @@ public:
ExceptionStyle getExceptionStyle() { return cf->exception_style; }
llvm::Function* getLLVMFunction() { return cf->func; }
llvm::Function* getLLVMFunction() { return func; }
EffortLevel getEffortLevel() { return cf->effort; }
......
......@@ -335,7 +335,6 @@ struct CompiledFunction {
private:
public:
FunctionMetadata* md;
llvm::Function* func; // the llvm IR object
// Some compilation settings:
EffortLevel effort;
......
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