Commit c2e7665b authored by Kevin Modzelewski's avatar Kevin Modzelewski

Nice, it's working

parent cedf6ac6
...@@ -632,6 +632,8 @@ Value ASTInterpreter::visit_branch(AST_Branch* node) { ...@@ -632,6 +632,8 @@ Value ASTInterpreter::visit_branch(AST_Branch* node) {
ASSERT(v.o == True || v.o == False, "Should have called NONZERO before this branch"); ASSERT(v.o == True || v.o == False, "Should have called NONZERO before this branch");
if (jit) { if (jit) {
jit->emitEndBlock();
// Special note: emitSideExit decrefs v for us. // Special note: emitSideExit decrefs v for us.
// TODO: since the value is always True or False, maybe could optimize by putting the decref // TODO: since the value is always True or False, maybe could optimize by putting the decref
// before the conditional instead of after. // before the conditional instead of after.
...@@ -665,6 +667,7 @@ Value ASTInterpreter::visit_jump(AST_Jump* node) { ...@@ -665,6 +667,7 @@ Value ASTInterpreter::visit_jump(AST_Jump* node) {
if (jit) { if (jit) {
if (backedge) if (backedge)
jit->emitOSRPoint(node); jit->emitOSRPoint(node);
jit->emitEndBlock();
jit->emitJump(node->target); jit->emitJump(node->target);
finishJITing(node->target); finishJITing(node->target);
...@@ -1036,6 +1039,7 @@ Value ASTInterpreter::visit_return(AST_Return* node) { ...@@ -1036,6 +1039,7 @@ Value ASTInterpreter::visit_return(AST_Return* node) {
Value s = node->value ? visit_expr(node->value) : getNone(); Value s = node->value ? visit_expr(node->value) : getNone();
if (jit) { if (jit) {
jit->emitEndBlock();
jit->emitReturn(s); jit->emitReturn(s);
finishJITing(); finishJITing();
} }
...@@ -1738,8 +1742,10 @@ Box* ASTInterpreterJitInterface::derefHelper(void* _interpreter, InternedString ...@@ -1738,8 +1742,10 @@ Box* ASTInterpreterJitInterface::derefHelper(void* _interpreter, InternedString
Box* ASTInterpreterJitInterface::doOSRHelper(void* _interpreter, AST_Jump* node) { Box* ASTInterpreterJitInterface::doOSRHelper(void* _interpreter, AST_Jump* node) {
ASTInterpreter* interpreter = (ASTInterpreter*)_interpreter; ASTInterpreter* interpreter = (ASTInterpreter*)_interpreter;
++interpreter->edgecount; ++interpreter->edgecount;
if (interpreter->edgecount >= OSR_THRESHOLD_BASELINE) if (interpreter->edgecount >= OSR_THRESHOLD_BASELINE) {
// XXX refcounting here?
return interpreter->doOSR(node); return interpreter->doOSR(node);
}
return NULL; return NULL;
} }
......
...@@ -482,16 +482,6 @@ void JitFragmentWriter::emitExec(RewriterVar* code, RewriterVar* globals, Rewrit ...@@ -482,16 +482,6 @@ void JitFragmentWriter::emitExec(RewriterVar* code, RewriterVar* globals, Rewrit
void JitFragmentWriter::emitJump(CFGBlock* b) { void JitFragmentWriter::emitJump(CFGBlock* b) {
if (LOG_BJIT_ASSEMBLY) comment("BJIT: emitJump() start"); if (LOG_BJIT_ASSEMBLY) comment("BJIT: emitJump() start");
for (auto v : local_syms) {
if (v.second) {
if (LOG_BJIT_ASSEMBLY) {
// XXX silly but we need to keep this alive
std::string s = std::string("BJIT: decvref(") + v.first.c_str() + ")";
comment(*new std::string(s));
}
v.second->decvref(); // xdecref?
}
}
RewriterVar* next = imm(b); RewriterVar* next = imm(b);
addAction([=]() { _emitJump(b, next, exit_info); }, { next }, ActionType::NORMAL); addAction([=]() { _emitJump(b, next, exit_info); }, { next }, ActionType::NORMAL);
...@@ -522,12 +512,20 @@ void JitFragmentWriter::emitRaise3(RewriterVar* arg0, RewriterVar* arg1, Rewrite ...@@ -522,12 +512,20 @@ void JitFragmentWriter::emitRaise3(RewriterVar* arg0, RewriterVar* arg1, Rewrite
call(false, (void*)raise3, arg0, arg1, arg2); call(false, (void*)raise3, arg0, arg1, arg2);
} }
void JitFragmentWriter::emitReturn(RewriterVar* v) { void JitFragmentWriter::emitEndBlock() {
for (auto v : local_syms) { for (auto v : local_syms) {
if (v.second) if (v.second) {
v.second->decvref(); if (LOG_BJIT_ASSEMBLY) {
// XXX silly but we need to keep this alive
std::string s = std::string("BJIT: decvref(") + v.first.c_str() + ")";
comment(*new std::string(s));
}
v.second->decvref(); // xdecref?
} }
}
}
void JitFragmentWriter::emitReturn(RewriterVar* v) {
v->stealRef(); v->stealRef();
addAction([=]() { _emitReturn(v); }, { v }, ActionType::NORMAL); addAction([=]() { _emitReturn(v); }, { v }, ActionType::NORMAL);
v->decvref(); v->decvref();
...@@ -603,10 +601,6 @@ void JitFragmentWriter::emitSideExit(STOLEN(RewriterVar*) v, Box* cmp_value, CFG ...@@ -603,10 +601,6 @@ void JitFragmentWriter::emitSideExit(STOLEN(RewriterVar*) v, Box* cmp_value, CFG
vars.push_back(v); vars.push_back(v);
vars.push_back(var); vars.push_back(var);
vars.push_back(next_block_var); vars.push_back(next_block_var);
for (auto v : local_syms) {
if (v.second)
vars.push_back(v.second);
}
addAction([=]() { _emitSideExit(v, var, next_block, next_block_var); }, { v, var, next_block_var }, addAction([=]() { _emitSideExit(v, var, next_block, next_block_var); }, { v, var, next_block_var },
ActionType::NORMAL); ActionType::NORMAL);
...@@ -701,10 +695,12 @@ int JitFragmentWriter::finishCompilation() { ...@@ -701,10 +695,12 @@ int JitFragmentWriter::finishCompilation() {
pp.release(); pp.release();
} }
#ifndef NDEBUG
if (LOG_BJIT_ASSEMBLY) { if (LOG_BJIT_ASSEMBLY) {
auto s = assembler->dump((uint8_t*)block->code/*, (uint8_t*)block->code + assembler->bytesWritten()*/); auto s = assembler->dump((uint8_t*)block->code/*, (uint8_t*)block->code + assembler->bytesWritten()*/);
printf("%s\n", s.c_str()); printf("%s\n", s.c_str());
} }
#endif
void* next_fragment_start = (uint8_t*)block->code + assembler->bytesWritten(); void* next_fragment_start = (uint8_t*)block->code + assembler->bytesWritten();
if (exit_info.num_bytes) if (exit_info.num_bytes)
...@@ -1030,19 +1026,12 @@ void JitFragmentWriter::_emitSideExit(STOLEN(RewriterVar*) var, RewriterVar* val ...@@ -1030,19 +1026,12 @@ void JitFragmentWriter::_emitSideExit(STOLEN(RewriterVar*) var, RewriterVar* val
assembler->cmp(var_reg, assembler::Immediate(val)); assembler->cmp(var_reg, assembler::Immediate(val));
} }
assert(0 && "the rewriter thinks this section is linear but it's not");
{ {
// TODO: Figure out if we need a large/small forward based on the number of local syms we will have to decref? // TODO: Figure out if we need a large/small forward based on the number of local syms we will have to decref?
assembler::LargeForwardJump jne(*assembler, assembler::COND_EQUAL); assembler::LargeForwardJump jne(*assembler, assembler::COND_EQUAL);
//assert(0 && "hmm I think this is the issue");
_decref(var); _decref(var);
for (auto v : local_syms) {
if (v.second)
_decref(v.second);
}
ExitInfo exit_info; ExitInfo exit_info;
_emitJump(next_block, next_block_var, exit_info); _emitJump(next_block, next_block_var, exit_info);
if (exit_info.num_bytes) { if (exit_info.num_bytes) {
...@@ -1055,7 +1044,6 @@ void JitFragmentWriter::_emitSideExit(STOLEN(RewriterVar*) var, RewriterVar* val ...@@ -1055,7 +1044,6 @@ void JitFragmentWriter::_emitSideExit(STOLEN(RewriterVar*) var, RewriterVar* val
if (LOG_BJIT_ASSEMBLY) assembler->comment("BJIT: decreffing emitSideExit var"); if (LOG_BJIT_ASSEMBLY) assembler->comment("BJIT: decreffing emitSideExit var");
//assert(0 && "hmm I think this is the issue");
_decref(var); _decref(var);
if (LOG_BJIT_ASSEMBLY) assembler->comment("BJIT: decreffing emitSideExit var end"); if (LOG_BJIT_ASSEMBLY) assembler->comment("BJIT: decreffing emitSideExit var end");
......
...@@ -268,6 +268,7 @@ public: ...@@ -268,6 +268,7 @@ public:
// emitSideExit steals a full ref from v, not just a vref // emitSideExit steals a full ref from v, not just a vref
void emitSideExit(STOLEN(RewriterVar*) v, Box* cmp_value, CFGBlock* next_block); void emitSideExit(STOLEN(RewriterVar*) v, Box* cmp_value, CFGBlock* next_block);
void emitUncacheExcInfo(); void emitUncacheExcInfo();
void emitEndBlock();
void abortCompilation(); void abortCompilation();
int finishCompilation(); int finishCompilation();
......
...@@ -25,7 +25,7 @@ int PYSTON_VERSION_MICRO = 0; ...@@ -25,7 +25,7 @@ int PYSTON_VERSION_MICRO = 0;
int MAX_OPT_ITERATIONS = 1; int MAX_OPT_ITERATIONS = 1;
bool LOG_IC_ASSEMBLY = false; bool LOG_IC_ASSEMBLY = false;
bool LOG_BJIT_ASSEMBLY = true; bool LOG_BJIT_ASSEMBLY = false;
bool CONTINUE_AFTER_FATAL = false; bool CONTINUE_AFTER_FATAL = false;
bool FORCE_INTERPRETER = true; bool FORCE_INTERPRETER = true;
......
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