Commit a47832d6 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge remote-tracking branch 'public/refcounting' into refcounting

parents a38d319c 97842832
...@@ -66,7 +66,7 @@ extern "C" Box* executeInnerAndSetupFrame(ASTInterpreter& interpreter, CFGBlock* ...@@ -66,7 +66,7 @@ extern "C" Box* executeInnerAndSetupFrame(ASTInterpreter& interpreter, CFGBlock*
*/ */
class ASTInterpreter { class ASTInterpreter {
public: public:
ASTInterpreter(FunctionMetadata* md, Box** vregs); ASTInterpreter(FunctionMetadata* md, Box** vregs, int num_vregs);
void initArguments(BoxedClosure* closure, BoxedGenerator* generator, Box* arg1, Box* arg2, Box* arg3, Box** args); void initArguments(BoxedClosure* closure, BoxedGenerator* generator, Box* arg1, Box* arg2, Box* arg3, Box** args);
...@@ -154,14 +154,6 @@ private: ...@@ -154,14 +154,6 @@ private:
public: public:
~ASTInterpreter() { ~ASTInterpreter() {
Py_XDECREF(frame_info.boxedLocals); Py_XDECREF(frame_info.boxedLocals);
int nvregs = getMD()->calculateNumVRegs();
int nvregs_user_visible = getMD()->calculateNumUserVisibleVRegs();
// skip the user visible ones because they will get decrefed in deinitFrame
for (int i = nvregs_user_visible; i < nvregs; i++) {
Py_XDECREF(vregs[i]);
}
Py_DECREF(frame_info.globals); Py_DECREF(frame_info.globals);
Py_XDECREF(this->created_closure); Py_XDECREF(this->created_closure);
} }
...@@ -241,7 +233,7 @@ void ASTInterpreter::setGlobals(Box* globals) { ...@@ -241,7 +233,7 @@ void ASTInterpreter::setGlobals(Box* globals) {
this->frame_info.globals = incref(globals); this->frame_info.globals = incref(globals);
} }
ASTInterpreter::ASTInterpreter(FunctionMetadata* md, Box** vregs) ASTInterpreter::ASTInterpreter(FunctionMetadata* md, Box** vregs, int num_vregs)
: current_block(0), : current_block(0),
frame_info(ExcInfo(NULL, NULL, NULL)), frame_info(ExcInfo(NULL, NULL, NULL)),
edgecount(0), edgecount(0),
...@@ -258,6 +250,7 @@ ASTInterpreter::ASTInterpreter(FunctionMetadata* md, Box** vregs) ...@@ -258,6 +250,7 @@ ASTInterpreter::ASTInterpreter(FunctionMetadata* md, Box** vregs)
scope_info = source_info->getScopeInfo(); scope_info = source_info->getScopeInfo();
frame_info.vregs = vregs; frame_info.vregs = vregs;
frame_info.md = md; frame_info.md = md;
frame_info.num_vregs = num_vregs;
assert(scope_info); assert(scope_info);
} }
...@@ -571,6 +564,7 @@ Value ASTInterpreter::getNone() { ...@@ -571,6 +564,7 @@ Value ASTInterpreter::getNone() {
Value ASTInterpreter::visit_unaryop(AST_UnaryOp* node) { Value ASTInterpreter::visit_unaryop(AST_UnaryOp* node) {
Value operand = visit_expr(node->operand); Value operand = visit_expr(node->operand);
AUTO_DECREF(operand.o);
if (node->op_type == AST_TYPE::Not) if (node->op_type == AST_TYPE::Not)
return Value(boxBool(!nonzero(operand.o)), jit ? jit->emitNotNonzero(operand) : NULL); return Value(boxBool(!nonzero(operand.o)), jit ? jit->emitNotNonzero(operand) : NULL);
else else
...@@ -733,7 +727,8 @@ Box* ASTInterpreter::doOSR(AST_Jump* node) { ...@@ -733,7 +727,8 @@ Box* ASTInterpreter::doOSR(AST_Jump* node) {
} }
for (auto&& dead : dead_symbols) { for (auto&& dead : dead_symbols) {
assert(getSymVRegMap().count(dead)); assert(getSymVRegMap().count(dead));
vregs[getSymVRegMap()[dead]] = NULL; int vreg_num = getSymVRegMap()[dead];
Py_CLEAR(vregs[vreg_num]);
} }
const OSREntryDescriptor* found_entry = nullptr; const OSREntryDescriptor* found_entry = nullptr;
...@@ -757,12 +752,13 @@ Box* ASTInterpreter::doOSR(AST_Jump* node) { ...@@ -757,12 +752,13 @@ Box* ASTInterpreter::doOSR(AST_Jump* node) {
if (phis->isPotentiallyUndefinedAfter(name, current_block)) { if (phis->isPotentiallyUndefinedAfter(name, current_block)) {
bool is_defined = val != NULL; bool is_defined = val != NULL;
assert(is_defined && "check refcounting");
// TODO only mangle once // TODO only mangle once
sorted_symbol_table[getIsDefinedName(name, source_info->getInternedStrings())] = (Box*)is_defined; sorted_symbol_table[getIsDefinedName(name, source_info->getInternedStrings())] = (Box*)is_defined;
sorted_symbol_table[name] = is_defined ? val : VAL_UNDEFINED; sorted_symbol_table[name] = is_defined ? incref(val) : VAL_UNDEFINED;
} else { } else {
ASSERT(val != NULL, "%s", name.c_str()); ASSERT(val != NULL, "%s", name.c_str());
Box* v = sorted_symbol_table[name] = val; sorted_symbol_table[name] = incref(val);
} }
} }
...@@ -1912,7 +1908,7 @@ Box* astInterpretFunction(FunctionMetadata* md, Box* closure, Box* generator, Bo ...@@ -1912,7 +1908,7 @@ Box* astInterpretFunction(FunctionMetadata* md, Box* closure, Box* generator, Bo
} }
++md->times_interpreted; ++md->times_interpreted;
ASTInterpreter interpreter(md, vregs); ASTInterpreter interpreter(md, vregs, num_vregs);
ScopeInfo* scope_info = md->source->getScopeInfo(); ScopeInfo* scope_info = md->source->getScopeInfo();
...@@ -1953,7 +1949,7 @@ Box* astInterpretFunctionEval(FunctionMetadata* md, Box* globals, Box* boxedLoca ...@@ -1953,7 +1949,7 @@ Box* astInterpretFunctionEval(FunctionMetadata* md, Box* globals, Box* boxedLoca
memset(vregs, 0, sizeof(Box*) * num_vregs); memset(vregs, 0, sizeof(Box*) * num_vregs);
} }
ASTInterpreter interpreter(md, vregs); ASTInterpreter interpreter(md, vregs, num_vregs);
interpreter.initArguments(NULL, NULL, NULL, NULL, NULL, NULL); interpreter.initArguments(NULL, NULL, NULL, NULL, NULL, NULL);
interpreter.setBoxedLocals(boxedLocals); interpreter.setBoxedLocals(boxedLocals);
...@@ -1988,7 +1984,7 @@ extern "C" Box* astInterpretDeoptFromASM(FunctionMetadata* md, AST_expr* after_e ...@@ -1988,7 +1984,7 @@ extern "C" Box* astInterpretDeoptFromASM(FunctionMetadata* md, AST_expr* after_e
memset(vregs, 0, sizeof(Box*) * num_vregs); memset(vregs, 0, sizeof(Box*) * num_vregs);
} }
ASTInterpreter interpreter(md, vregs); ASTInterpreter interpreter(md, vregs, num_vregs);
if (source_info->scoping->areGlobalsFromModule()) if (source_info->scoping->areGlobalsFromModule())
interpreter.setGlobals(source_info->parent_module); interpreter.setGlobals(source_info->parent_module);
......
...@@ -585,7 +585,7 @@ void JitFragmentWriter::emitSetLocal(InternedString s, int vreg, bool set_closur ...@@ -585,7 +585,7 @@ void JitFragmentWriter::emitSetLocal(InternedString s, int vreg, bool set_closur
v); v);
v->refConsumed(); v->refConsumed();
} else { } else {
RewriterVar* prev = vregs_array->getAttr(8 * vreg); RewriterVar* prev = vregs_array->getAttr(8 * vreg)->setNullable(true);
vregs_array->setAttr(8 * vreg, v); vregs_array->setAttr(8 * vreg, v);
v->refConsumed(); v->refConsumed();
......
...@@ -459,7 +459,9 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc ...@@ -459,7 +459,9 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc
if (p.second == phi_type) { if (p.second == phi_type) {
// good to go // good to go
v = from_arg; v = from_arg;
irstate->getRefcounts()->setType(v, RefType::BORROWED);
} else if (p.second->canConvertTo(phi_type)) { } else if (p.second->canConvertTo(phi_type)) {
assert(0 && "check refcounting");
// not sure if/when this happens, but if there's a type mismatch but one we know // not sure if/when this happens, but if there's a type mismatch but one we know
// can be handled (such as casting from a subclass to a superclass), handle it: // can be handled (such as casting from a subclass to a superclass), handle it:
ConcreteCompilerVariable* converted = var->makeConverted(*unbox_emitter, phi_type); ConcreteCompilerVariable* converted = var->makeConverted(*unbox_emitter, phi_type);
...@@ -601,7 +603,6 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc ...@@ -601,7 +603,6 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc
// TODO might be more efficient to do post-call safepoints? // TODO might be more efficient to do post-call safepoints?
generator->doSafePoint(block->body[0]); generator->doSafePoint(block->body[0]);
} else if (entry_descriptor && block == entry_descriptor->backedge->target) { } else if (entry_descriptor && block == entry_descriptor->backedge->target) {
assert(0 && "check refcounting");
assert(block->predecessors.size() > 1); assert(block->predecessors.size() > 1);
assert(osr_entry_block); assert(osr_entry_block);
assert(phis); assert(phis);
...@@ -619,11 +620,9 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc ...@@ -619,11 +620,9 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc
// printf("For %s, given %s, analyzed for %s\n", p.first.c_str(), p.second->debugName().c_str(), // printf("For %s, given %s, analyzed for %s\n", p.first.c_str(), p.second->debugName().c_str(),
// analyzed_type->debugName().c_str()); // analyzed_type->debugName().c_str());
assert(0 && "check refcounting");
llvm::PHINode* phi = emitter->getBuilder()->CreatePHI(analyzed_type->llvmType(), llvm::PHINode* phi = emitter->getBuilder()->CreatePHI(analyzed_type->llvmType(),
block->predecessors.size() + 1, p.first.s()); block->predecessors.size() + 1, p.first.s());
if (analyzed_type->getBoxType() == analyzed_type) { if (analyzed_type->getBoxType() == analyzed_type) {
assert(0 && "check refcounting");
irstate->getRefcounts()->setType(phi, RefType::OWNED); irstate->getRefcounts()->setType(phi, RefType::OWNED);
} }
ConcreteCompilerVariable* var = new ConcreteCompilerVariable(analyzed_type, phi); ConcreteCompilerVariable* var = new ConcreteCompilerVariable(analyzed_type, phi);
...@@ -877,7 +876,6 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc ...@@ -877,7 +876,6 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc
} }
if (this_is_osr_entry) { if (this_is_osr_entry) {
assert(0 && "check refcounting");
ConcreteCompilerVariable* v = (*osr_syms)[it->first]; ConcreteCompilerVariable* v = (*osr_syms)[it->first];
assert(v); assert(v);
......
...@@ -225,13 +225,12 @@ void IRGenState::setupFrameInfoVar(llvm::Value* passed_closure, llvm::Value* pas ...@@ -225,13 +225,12 @@ void IRGenState::setupFrameInfoVar(llvm::Value* passed_closure, llvm::Value* pas
assert(!passed_globals); assert(!passed_globals);
// The OSR case // The OSR case
assert(0 && "check refcounting");
this->frame_info = frame_info_arg; this->frame_info = frame_info_arg;
// use vrags array from the interpreter // use vrags array from the interpreter
vregs = builder.CreateLoad(getVRegsGep(builder, frame_info_arg)); vregs = builder.CreateLoad(getVRegsGep(builder, frame_info_arg));
this->globals = builder.CreateLoad(getGlobalsGep(builder, frame_info_arg)); this->globals = builder.CreateLoad(getGlobalsGep(builder, frame_info_arg));
getRefcounts()->setType(this->globals, RefType::BORROWED);
if (getScopeInfo()->usesNameLookup()) { if (getScopeInfo()->usesNameLookup()) {
// load frame_info.boxedLocals // load frame_info.boxedLocals
......
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