Commit f1d4b01f authored by Kevin Modzelewski's avatar Kevin Modzelewski

Ok some basic cases working, but exceptions are hard

parent e320ebee
...@@ -2843,8 +2843,9 @@ public: ...@@ -2843,8 +2843,9 @@ public:
irstate->getRefcounts()->refConsumed(exc_traceback, call_inst); irstate->getRefcounts()->refConsumed(exc_traceback, call_inst);
builder->CreateRet(getNullPtr(g.llvm_value_type_ptr)); builder->CreateRet(getNullPtr(g.llvm_value_type_ptr));
} else { } else {
auto call_inst = emitter.createCall3(UnwindInfo(unw_info.current_stmt, NO_CXX_INTERCEPTION), //auto call_inst = emitter.createCall3(UnwindInfo(unw_info.current_stmt, NO_CXX_INTERCEPTION),
g.funcs.rawThrow, exc_type, exc_value, exc_traceback); //g.funcs.rawThrow, exc_type, exc_value, exc_traceback);
auto call_inst = emitter.getBuilder()->CreateCall3(g.funcs.rawThrow, exc_type, exc_value, exc_traceback);
irstate->getRefcounts()->refConsumed(exc_type, call_inst); irstate->getRefcounts()->refConsumed(exc_type, call_inst);
irstate->getRefcounts()->refConsumed(exc_value, call_inst); irstate->getRefcounts()->refConsumed(exc_value, call_inst);
irstate->getRefcounts()->refConsumed(exc_traceback, call_inst); irstate->getRefcounts()->refConsumed(exc_traceback, call_inst);
......
...@@ -111,8 +111,9 @@ void addDecrefs(llvm::Value* v, int num_refs, llvm::Instruction* decref_pt) { ...@@ -111,8 +111,9 @@ void addDecrefs(llvm::Value* v, int num_refs, llvm::Instruction* decref_pt) {
new llvm::StoreInst(new_refcount, refcount_ptr, decref_pt); new llvm::StoreInst(new_refcount, refcount_ptr, decref_pt);
llvm::BasicBlock* cur_block = decref_pt->getParent(); llvm::BasicBlock* cur_block = decref_pt->getParent();
llvm::BasicBlock* dealloc_block = llvm::BasicBlock::Create(g.context, "dealloc", decref_pt->getParent()->getParent());
llvm::BasicBlock* continue_block = cur_block->splitBasicBlock(decref_pt); llvm::BasicBlock* continue_block = cur_block->splitBasicBlock(decref_pt);
llvm::BasicBlock* dealloc_block
= llvm::BasicBlock::Create(g.context, "dealloc", decref_pt->getParent()->getParent(), continue_block);
assert(llvm::isa<llvm::BranchInst>(cur_block->getTerminator())); assert(llvm::isa<llvm::BranchInst>(cur_block->getTerminator()));
cur_block->getTerminator()->eraseFromParent(); cur_block->getTerminator()->eraseFromParent();
...@@ -273,46 +274,51 @@ void RefcountTracker::addRefcounts(IRGenState* irstate) { ...@@ -273,46 +274,51 @@ void RefcountTracker::addRefcounts(IRGenState* irstate) {
assert(rt->vars.count(v)); assert(rt->vars.count(v));
auto refstate = rt->vars[v]; auto refstate = rt->vars[v];
if (refstate.reftype == RefType::BORROWED) { int min_refs = 1000000000;
int min_refs = 1000000000; for (auto SBB : successors) {
for (auto SBB : successors) { auto it = states[SBB].refs.find(v);
auto it = states[SBB].refs.find(v); if (it != states[SBB].refs.end()) {
if (it != states[SBB].refs.end()) { min_refs = std::min(it->second, min_refs);
min_refs = std::min(it->second, min_refs); } else
} else min_refs = 0;
min_refs = 0; }
}
for (auto SBB : successors) { if (refstate.reftype == RefType::OWNED)
auto it = states[SBB].refs.find(v); min_refs = std::max(1, min_refs);
int this_refs = 0;
if (it != states[SBB].refs.end()) {
this_refs = it->second;
}
if (this_refs > min_refs) {
addIncrefs(v, this_refs - min_refs, findIncrefPt(SBB));
//llvm::outs() << *incref_pt << '\n';
//llvm::outs() << "Need to incref " << *v << " at beginning of " << SBB->getName() << "\n";
}
}
if (min_refs) for (auto SBB : successors) {
state.refs[v] = min_refs; auto it = states[SBB].refs.find(v);
else int this_refs = 0;
assert(state.refs.count(v) == 0); if (it != states[SBB].refs.end()) {
} else { this_refs = it->second;
llvm::outs() << *v << " goes to multiple successors\n"; }
if (this_refs > min_refs) {
for (auto SBB : successors) { addIncrefs(v, this_refs - min_refs, findIncrefPt(SBB));
auto it = states[SBB].refs.find(v); //llvm::outs() << *incref_pt << '\n';
if (it != states[SBB].refs.end()) { //llvm::outs() << "Need to incref " << *v << " at beginning of " << SBB->getName() << "\n";
llvm::outs() << SBB->getName() << ": " << it->second << '\n'; } else if (this_refs < min_refs) {
} else assert(refstate.reftype == RefType::OWNED);
llvm::outs() << SBB->getName() << ": " << 0 << '\n'; addDecrefs(v, min_refs - this_refs, findIncrefPt(SBB));
} }
}
if (min_refs)
state.refs[v] = min_refs;
else
assert(state.refs.count(v) == 0);
assert(0 && "finish implementing"); #if 0
llvm::outs() << *v << " goes to multiple successors\n";
for (auto SBB : successors) {
auto it = states[SBB].refs.find(v);
if (it != states[SBB].refs.end()) {
llvm::outs() << SBB->getName() << ": " << it->second << '\n';
} else
llvm::outs() << SBB->getName() << ": " << 0 << '\n';
} }
#endif
} }
} }
......
...@@ -4281,6 +4281,12 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe ...@@ -4281,6 +4281,12 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe
throw e; throw e;
} }
if (num_output_args < 1)
arg1 = NULL;
if (num_output_args < 2)
arg2 = NULL;
if (num_output_args < 3)
arg3 = NULL;
AUTO_XDECREF(arg1); AUTO_XDECREF(arg1);
AUTO_XDECREF(arg2); AUTO_XDECREF(arg2);
AUTO_XDECREF(arg3); AUTO_XDECREF(arg3);
......
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