Commit 8d7d24ad authored by Marius Wachtler's avatar Marius Wachtler

misc fixes to get the bjit further

- fix instruction encoding of: add imm, mem
- fix Py_REF_DEBUG when increfing multiple times at once
- add missing bjit annotations
parent ede3f121
...@@ -116,26 +116,28 @@ void Assembler::emitArith(Immediate imm, Indirect mem, int opcode) { ...@@ -116,26 +116,28 @@ void Assembler::emitArith(Immediate imm, Indirect mem, int opcode) {
mem_idx -= 8; mem_idx -= 8;
} }
// TODO: needs testing, then remove this trap
trap();
emitRex(rex); emitRex(rex);
bool needssib = (mem_idx == 0b100); bool needssib = (mem_idx == 0b100);
assert(!needssib && "untested"); assert(!needssib && "untested");
int mode = getModeFromOffset(mem.offset, mem_idx); int mode = getModeFromOffset(mem.offset, mem_idx);
assert(mode != 0b10 && "not yet supported");
if (-0x80 <= amount && amount < 0x80) { if (-0x80 <= amount && amount < 0x80) {
emitByte(0x83); emitByte(0x83);
if (needssib) if (needssib)
emitSIB(0b00, 0b100, mem_idx); emitSIB(0b00, 0b100, mem_idx);
emitModRM(mode, opcode, mem_idx); emitModRM(mode, opcode, mem_idx);
if (mode == 0b01)
emitByte(mem.offset);
emitByte(amount); emitByte(amount);
} else { } else {
emitByte(0x81); emitByte(0x81);
if (needssib) if (needssib)
emitSIB(0b00, 0b100, mem_idx); emitSIB(0b00, 0b100, mem_idx);
emitModRM(mode, opcode, mem_idx); emitModRM(mode, opcode, mem_idx);
if (mode == 0b01)
emitByte(mem.offset);
emitInt(amount, 4); emitInt(amount, 4);
} }
} }
......
...@@ -542,6 +542,7 @@ void Rewriter::_incref(RewriterVar* var, int num_refs) { ...@@ -542,6 +542,7 @@ void Rewriter::_incref(RewriterVar* var, int num_refs) {
// llvm::ArrayRef<RewriterVar*>()); // llvm::ArrayRef<RewriterVar*>());
#ifdef Py_REF_DEBUG #ifdef Py_REF_DEBUG
// assembler->trap(); // assembler->trap();
for (int i = 0; i < num_refs; ++i)
assembler->incq(assembler::Immediate(&_Py_RefTotal)); assembler->incq(assembler::Immediate(&_Py_RefTotal));
#endif #endif
auto reg = var->getInReg(); auto reg = var->getInReg();
......
...@@ -1798,7 +1798,8 @@ void ASTInterpreterJitInterface::pendingCallsCheckHelper() { ...@@ -1798,7 +1798,8 @@ void ASTInterpreterJitInterface::pendingCallsCheckHelper() {
#endif #endif
} }
void ASTInterpreterJitInterface::setExcInfoHelper(void* _interpreter, Box* type, Box* value, Box* traceback) { void ASTInterpreterJitInterface::setExcInfoHelper(void* _interpreter, STOLEN(Box*) type, STOLEN(Box*) value,
STOLEN(Box*) traceback) {
ASTInterpreter* interpreter = (ASTInterpreter*)_interpreter; ASTInterpreter* interpreter = (ASTInterpreter*)_interpreter;
setFrameExcInfo(interpreter->getFrameInfo(), type, value, traceback); setFrameExcInfo(interpreter->getFrameInfo(), type, value, traceback);
} }
......
...@@ -49,7 +49,7 @@ struct ASTInterpreterJitInterface { ...@@ -49,7 +49,7 @@ struct ASTInterpreterJitInterface {
static Box* derefHelper(void* interp, InternedString s); static Box* derefHelper(void* interp, InternedString s);
static Box* landingpadHelper(void* interp); static Box* landingpadHelper(void* interp);
static void pendingCallsCheckHelper(); static void pendingCallsCheckHelper();
static void setExcInfoHelper(void* interp, Box* type, Box* value, Box* traceback); static void setExcInfoHelper(void* interp, STOLEN(Box*) type, STOLEN(Box*) value, STOLEN(Box*) traceback);
static void setLocalClosureHelper(void* interp, long vreg, InternedString id, Box* v); static void setLocalClosureHelper(void* interp, long vreg, InternedString id, Box* v);
static void uncacheExcInfoHelper(void* interp); static void uncacheExcInfoHelper(void* interp);
static void raise0Helper(void* interp) __attribute__((noreturn)); static void raise0Helper(void* interp) __attribute__((noreturn));
......
...@@ -539,6 +539,9 @@ void JitFragmentWriter::emitRaise0() { ...@@ -539,6 +539,9 @@ void JitFragmentWriter::emitRaise0() {
void JitFragmentWriter::emitRaise3(RewriterVar* arg0, RewriterVar* arg1, RewriterVar* arg2) { void JitFragmentWriter::emitRaise3(RewriterVar* arg0, RewriterVar* arg1, RewriterVar* arg2) {
call(false, (void*)raise3, arg0, arg1, arg2); call(false, (void*)raise3, arg0, arg1, arg2);
arg0->refConsumed();
arg1->refConsumed();
arg2->refConsumed();
} }
void JitFragmentWriter::emitEndBlock() { void JitFragmentWriter::emitEndBlock() {
...@@ -570,6 +573,9 @@ void JitFragmentWriter::emitSetCurrentInst(AST_stmt* node) { ...@@ -570,6 +573,9 @@ void JitFragmentWriter::emitSetCurrentInst(AST_stmt* node) {
void JitFragmentWriter::emitSetExcInfo(RewriterVar* type, RewriterVar* value, RewriterVar* traceback) { void JitFragmentWriter::emitSetExcInfo(RewriterVar* type, RewriterVar* value, RewriterVar* traceback) {
call(false, (void*)ASTInterpreterJitInterface::setExcInfoHelper, getInterp(), type, value, traceback); call(false, (void*)ASTInterpreterJitInterface::setExcInfoHelper, getInterp(), type, value, traceback);
type->refConsumed();
value->refConsumed();
traceback->refConsumed();
} }
void JitFragmentWriter::emitSetGlobal(Box* global, BoxedString* s, STOLEN(RewriterVar*) v) { void JitFragmentWriter::emitSetGlobal(Box* global, BoxedString* s, STOLEN(RewriterVar*) v) {
...@@ -887,7 +893,6 @@ Box* JitFragmentWriter::runtimeCallHelper(Box* obj, ArgPassSpec argspec, TypeRec ...@@ -887,7 +893,6 @@ Box* JitFragmentWriter::runtimeCallHelper(Box* obj, ArgPassSpec argspec, TypeRec
void JitFragmentWriter::_emitGetLocal(RewriterVar* val_var, const char* name) { void JitFragmentWriter::_emitGetLocal(RewriterVar* val_var, const char* name) {
assembler::Register var_reg = val_var->getInReg(); assembler::Register var_reg = val_var->getInReg();
assembler->test(var_reg, var_reg); assembler->test(var_reg, var_reg);
val_var->bumpUse();
{ {
assembler::ForwardJump jnz(*assembler, assembler::COND_NOT_ZERO); assembler::ForwardJump jnz(*assembler, assembler::COND_NOT_ZERO);
...@@ -897,6 +902,7 @@ void JitFragmentWriter::_emitGetLocal(RewriterVar* val_var, const char* name) { ...@@ -897,6 +902,7 @@ void JitFragmentWriter::_emitGetLocal(RewriterVar* val_var, const char* name) {
} }
_incref(val_var); _incref(val_var);
val_var->bumpUse();
} }
void JitFragmentWriter::_emitJump(CFGBlock* b, RewriterVar* block_next, ExitInfo& exit_info) { void JitFragmentWriter::_emitJump(CFGBlock* b, RewriterVar* block_next, ExitInfo& exit_info) {
......
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