Commit 4e7e480c authored by Kevin Modzelewski's avatar Kevin Modzelewski

Fix: have the AST interpreter reuse OSR entries

Before it was recompiling the OSR-entry function every
time it would take an osr exit.
parent bd3cfab0
......@@ -385,7 +385,15 @@ Value ASTInterpreter::visit_jump(AST_Jump* node) {
if (edgecount > OSR_THRESHOLD) {
eraseDeadSymbols();
OSRExit exit(compiled_func, OSREntryDescriptor::create(compiled_func, node));
const OSREntryDescriptor* found_entry = nullptr;
for (auto& p : compiled_func->clfunc->osr_versions) {
if (p.first->cf != compiled_func)
continue;
if (p.first->backedge != node)
continue;
found_entry = p.first;
}
std::map<std::string, Box*> sorted_symbol_table;
......@@ -414,18 +422,29 @@ Value ASTInterpreter::visit_jump(AST_Jump* node) {
if (created_closure)
sorted_symbol_table[CREATED_CLOSURE_NAME] = created_closure;
if (found_entry == nullptr) {
OSREntryDescriptor* entry = OSREntryDescriptor::create(compiled_func, node);
for (auto& it : sorted_symbol_table) {
if (isIsDefinedName(it.first))
entry->args[it.first] = BOOL;
else if (it.first == PASSED_GENERATOR_NAME)
entry->args[it.first] = GENERATOR;
else if (it.first == PASSED_CLOSURE_NAME || it.first == CREATED_CLOSURE_NAME)
entry->args[it.first] = CLOSURE;
else {
assert(it.first[0] != '!');
entry->args[it.first] = UNKNOWN;
}
}
found_entry = entry;
}
OSRExit exit(compiled_func, found_entry);
std::vector<Box*> arg_array;
for (auto& it : sorted_symbol_table) {
if (isIsDefinedName(it.first))
exit.entry->args[it.first] = BOOL;
else if (it.first == PASSED_GENERATOR_NAME)
exit.entry->args[it.first] = GENERATOR;
else if (it.first == PASSED_CLOSURE_NAME || it.first == CREATED_CLOSURE_NAME)
exit.entry->args[it.first] = CLOSURE;
else {
assert(it.first[0] != '!');
exit.entry->args[it.first] = UNKNOWN;
}
arg_array.push_back(it.second);
}
......
......@@ -281,6 +281,7 @@ void initCodegen() {
#endif
//"--print-after-all",
//"--print-machineinstrs",
//"--optimize-regalloc=false", // use the "fast" register allocator
};
int num_llvm_args = sizeof(llvm_args) / sizeof(llvm_args[0]);
llvm::cl::ParseCommandLineOptions(num_llvm_args, llvm_args, "<you should never see this>\n");
......
......@@ -1877,8 +1877,8 @@ private:
// Emitting the actual OSR:
emitter.getBuilder()->SetInsertPoint(onramp);
OSRExit* exit
= new OSRExit(irstate->getCurFunction(), OSREntryDescriptor::create(irstate->getCurFunction(), osr_key));
OSREntryDescriptor* entry = OSREntryDescriptor::create(irstate->getCurFunction(), osr_key);
OSRExit* exit = new OSRExit(irstate->getCurFunction(), entry);
llvm::Value* partial_func = emitter.getBuilder()->CreateCall(g.funcs.compilePartialFunc,
embedConstantPtr(exit, g.i8->getPointerTo()));
......@@ -1966,7 +1966,7 @@ private:
emitter.getBuilder()->CreateStore(val, ptr);
}
ConcreteCompilerType*& t = exit->entry->args[p.first];
ConcreteCompilerType*& t = entry->args[p.first];
if (t == NULL)
t = var->getType();
else
......
......@@ -45,9 +45,9 @@ class OSRExit {
private:
public:
CompiledFunction* const parent_cf;
OSREntryDescriptor* entry;
const OSREntryDescriptor* entry;
OSRExit(CompiledFunction* parent_cf, OSREntryDescriptor* entry) : parent_cf(parent_cf), entry(entry) {}
OSRExit(CompiledFunction* parent_cf, const OSREntryDescriptor* entry) : parent_cf(parent_cf), entry(entry) {}
};
}
......
import sys
def tally(fn):
counts = {}
for l in open(fn):
samples = int(l.split()[3])
func = l.split()[-1]
counts[func] = samples
return counts
def main():
fn1, fn2 = sys.argv[1:3]
counts1 = tally(fn1)
counts2 = tally(fn2)
total1 = sum(counts1.values())
total2 = sum(counts2.values())
names = list(set(counts1.keys()) | set(counts2.keys()))
diff_thresh = (total1 + total2) / 2 / 100
names.sort(key=lambda n: counts1.get(n, 0) + counts2.get(n, 0), reverse=True)
for n in names:
c1 = counts1.get(n, 0)
c2 = counts2.get(n, 0)
if abs(c1 - c2) >= diff_thresh:
print n, counts1.get(n, 0), counts2.get(n, 0)
if __name__ == "__main__":
main()
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