Commit 1bfb56e8 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Further distinguish OSR and non-osr compiles

A "FunctionSpecialization" object really makes no sense in the context of
an OSR compile, since the FunctionSpecialization talks about the types
of the input arguments, which no longer matter for OSR compiles.
Now, their type information comes (almost) entirely from the OSREntryDescriptor,
so in most places assert that we get exactly one or the other.
parent 0e60f0d3
......@@ -880,6 +880,8 @@ CompiledFunction* doCompile(SourceInfo* source, ParamNames* param_names, const O
Timer _t2;
long irgen_us = 0;
assert((entry_descriptor != NULL) + (spec != NULL) == 1);
if (VERBOSITY("irgen") >= 1)
source->cfg->print();
......@@ -896,12 +898,14 @@ CompiledFunction* doCompile(SourceInfo* source, ParamNames* param_names, const O
////
// Initializing the llvm-level structures:
int nargs = param_names->totalParameters();
ASSERT(nargs == spec->arg_types.size(), "%d %ld", nargs, spec->arg_types.size());
std::vector<llvm::Type*> llvm_arg_types;
if (entry_descriptor == NULL) {
assert(spec);
int nargs = param_names->totalParameters();
ASSERT(nargs == spec->arg_types.size(), "%d %ld", nargs, spec->arg_types.size());
if (source->getScopeInfo()->takesClosure())
llvm_arg_types.push_back(g.llvm_closure_type_ptr);
......@@ -929,13 +933,17 @@ CompiledFunction* doCompile(SourceInfo* source, ParamNames* param_names, const O
}
}
llvm::FunctionType* ft = llvm::FunctionType::get(spec->rtn_type->llvmType(), llvm_arg_types, false /*vararg*/);
CompiledFunction* cf
= new CompiledFunction(NULL, spec, (effort == EffortLevel::INTERPRETED), NULL, NULL, effort, entry_descriptor);
llvm::FunctionType* ft = llvm::FunctionType::get(cf->getReturnType()->llvmType(), llvm_arg_types, false /*vararg*/);
llvm::Function* f = llvm::Function::Create(ft, llvm::Function::ExternalLinkage, name, g.cur_module);
// g.func_registry.registerFunction(f, g.cur_module);
CompiledFunction* cf
= new CompiledFunction(f, spec, (effort == EffortLevel::INTERPRETED), NULL, NULL, effort, entry_descriptor);
cf->func = f;
// g.func_registry.registerFunction(f, g.cur_module);
llvm::MDNode* dbg_funcinfo = setupDebugInfo(source, f, nameprefix);
......
......@@ -166,9 +166,10 @@ static void compileIR(CompiledFunction* cf, EffortLevel effort) {
// should only be called after checking to see if the other versions would work.
// The codegen_lock needs to be held in W mode before calling this function:
CompiledFunction* compileFunction(CLFunction* f, FunctionSpecialization* spec, EffortLevel effort,
const OSREntryDescriptor* entry) {
const OSREntryDescriptor* entry_descriptor) {
Timer _t("for compileFunction()");
assert(spec);
assert((entry_descriptor != NULL) + (spec != NULL) == 1);
ASSERT(f->versions.size() < 20, "%ld", f->versions.size());
SourceInfo* source = f->source;
......@@ -180,21 +181,21 @@ CompiledFunction* compileFunction(CLFunction* f, FunctionSpecialization* spec, E
std::string s;
llvm::raw_string_ostream ss(s);
ss << "\033[34;1mJIT'ing " << name << " with signature (";
for (int i = 0; i < spec->arg_types.size(); i++) {
if (i > 0)
ss << ", ";
ss << spec->arg_types[i]->debugName();
// spec->arg_types[i]->llvmType()->print(ss);
if (spec) {
ss << "\033[34;1mJIT'ing " << name << " with signature (";
for (int i = 0; i < spec->arg_types.size(); i++) {
if (i > 0)
ss << ", ";
ss << spec->arg_types[i]->debugName();
// spec->arg_types[i]->llvmType()->print(ss);
}
ss << ") -> ";
ss << spec->rtn_type->debugName();
} else {
ss << "\nDoing OSR-entry partial compile of " << name << ", starting with backedge to block "
<< entry_descriptor->backedge->target->idx << '\n';
}
ss << ") -> ";
ss << spec->rtn_type->debugName();
// spec->rtn_type->llvmType()->print(ss);
ss << " at effort level " << (int)effort;
if (entry != NULL) {
ss << "\nDoing OSR-entry partial compile, starting with backedge to block " << entry->backedge->target->idx
<< '\n';
}
ss << "\033[0m";
printf("%s\n", ss.str().c_str());
}
......@@ -216,9 +217,10 @@ CompiledFunction* compileFunction(CLFunction* f, FunctionSpecialization* spec, E
CompiledFunction* cf = 0;
if (effort == EffortLevel::INTERPRETED) {
assert(!entry_descriptor);
cf = new CompiledFunction(0, spec, true, NULL, NULL, effort, 0);
} else {
cf = doCompile(source, &f->param_names, entry, effort, spec, name);
cf = doCompile(source, &f->param_names, entry_descriptor, effort, spec, name);
compileIR(cf, effort);
}
......@@ -327,6 +329,12 @@ void CompiledFunction::speculationFailed() {
}
}
ConcreteCompilerType* CompiledFunction::getReturnType() {
if (spec)
return spec->rtn_type;
return entry_descriptor->cf->getReturnType();
}
/// Reoptimizes the given function version at the new effort level.
/// The cf must be an active version in its parents CLFunction; the given
/// version will be replaced by the new version, which will be returned.
......@@ -385,8 +393,7 @@ CompiledFunction* compilePartialFuncInternal(OSRExit* exit) {
EffortLevel new_effort = EffortLevel::MAXIMAL;
if (exit->parent_cf->effort == EffortLevel::INTERPRETED)
new_effort = EffortLevel::MINIMAL;
CompiledFunction* compiled
= compileFunction(exit->parent_cf->clfunc, exit->parent_cf->spec, new_effort, exit->entry);
CompiledFunction* compiled = compileFunction(exit->parent_cf->clfunc, NULL, new_effort, exit->entry);
assert(compiled == new_cf);
stat_osr_compiles.log();
......
......@@ -83,10 +83,7 @@ public:
llvm::Value* getScratchSpace(int min_bytes);
llvm::Value* getFrameInfoVar();
ConcreteCompilerType* getReturnType() {
assert(cf->spec);
return cf->spec->rtn_type;
}
ConcreteCompilerType* getReturnType() { return cf->getReturnType(); }
SourceInfo* getSourceInfo() { return source_info; }
......
......@@ -203,7 +203,11 @@ public:
llvm::Value* llvm_code, EffortLevel effort, const OSREntryDescriptor* entry_descriptor)
: clfunc(NULL), func(func), spec(spec), entry_descriptor(entry_descriptor), is_interpreted(is_interpreted),
code(code), llvm_code(llvm_code), effort(effort), times_called(0), times_speculation_failed(0),
location_map(nullptr) {}
location_map(nullptr) {
assert((spec != NULL) + (entry_descriptor != NULL) == 1);
}
ConcreteCompilerType* getReturnType();
// TODO this will need to be implemented eventually; things to delete:
// - line_table if it exists
......@@ -297,16 +301,17 @@ public:
void addVersion(CompiledFunction* compiled) {
assert(compiled);
assert(compiled->spec);
assert(compiled->spec->arg_types.size() == num_args + (takes_varargs ? 1 : 0) + (takes_kwargs ? 1 : 0));
assert((compiled->spec != NULL) + (compiled->entry_descriptor != NULL) == 1);
assert(compiled->clfunc == NULL);
assert(compiled->is_interpreted == (compiled->code == NULL));
assert(compiled->is_interpreted == (compiled->llvm_code == NULL));
compiled->clfunc = this;
if (compiled->entry_descriptor == NULL)
if (compiled->entry_descriptor == NULL) {
assert(compiled->spec->arg_types.size() == num_args + (takes_varargs ? 1 : 0) + (takes_kwargs ? 1 : 0));
versions.push_back(compiled);
else
} else {
osr_versions[compiled->entry_descriptor] = compiled;
}
}
};
......
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