Commit 97426460 authored by Marius Wachtler's avatar Marius Wachtler

rewriter: improve decref and xdecref

problem was that the bumped the variable to late which caused an extra spill
parent 5edb8980
...@@ -510,17 +510,11 @@ void RewriterVar::incref() { ...@@ -510,17 +510,11 @@ void RewriterVar::incref() {
} }
void RewriterVar::decref() { void RewriterVar::decref() {
rewriter->addAction([=]() { rewriter->addAction([=]() { rewriter->_decref(this, { this }); }, { this }, ActionType::MUTATION);
rewriter->_decref(this);
this->bumpUse();
}, { this }, ActionType::MUTATION);
} }
void RewriterVar::xdecref() { void RewriterVar::xdecref() {
rewriter->addAction([=]() { rewriter->addAction([=]() { rewriter->_xdecref(this, { this }); }, { this }, ActionType::MUTATION);
rewriter->_xdecref(this);
this->bumpUse();
}, { this }, ActionType::MUTATION);
} }
void Rewriter::_incref(RewriterVar* var, int num_refs) { void Rewriter::_incref(RewriterVar* var, int num_refs) {
...@@ -565,17 +559,17 @@ void Rewriter::_incref(RewriterVar* var, int num_refs) { ...@@ -565,17 +559,17 @@ void Rewriter::_incref(RewriterVar* var, int num_refs) {
// (ie the caller should call bumpUse) // (ie the caller should call bumpUse)
} }
void Rewriter::_decref(RewriterVar* var) { void Rewriter::_decref(RewriterVar* var, llvm::ArrayRef<RewriterVar*> vars_to_bump) {
assert(!var->nullable); assert(!var->nullable);
// assembler->trap(); // assembler->trap();
// this->_call(NULL, true, false /* can't throw */, (void*)Helper::decref, { var }); // this->_call(NULL, true, false /* can't throw */, (void*)Helper::decref, { var }, {}, vars_to_bump);
#ifdef Py_REF_DEBUG #ifdef Py_REF_DEBUG
// assembler->trap(); // assembler->trap();
assembler->decq(assembler::Immediate(&_Py_RefTotal)); assembler->decq(assembler::Immediate(&_Py_RefTotal));
#endif #endif
_setupCall(true, { var }, {}, assembler::RAX); _setupCall(true, { var }, {}, assembler::RAX, vars_to_bump);
#ifdef Py_REF_DEBUG #ifdef Py_REF_DEBUG
...@@ -603,13 +597,16 @@ void Rewriter::_decref(RewriterVar* var) { ...@@ -603,13 +597,16 @@ void Rewriter::_decref(RewriterVar* var) {
// Doesn't call bumpUse, since this function is designed to be callable from other emitting functions. // Doesn't call bumpUse, since this function is designed to be callable from other emitting functions.
// (ie the caller should call bumpUse) // (ie the caller should call bumpUse)
for (auto&& use : vars_to_bump) {
use->bumpUseLateIfNecessary();
}
} }
void Rewriter::_xdecref(RewriterVar* var) { void Rewriter::_xdecref(RewriterVar* var, llvm::ArrayRef<RewriterVar*> vars_to_bump) {
assert(var->nullable); assert(var->nullable);
// assembler->trap(); // assembler->trap();
this->_call(NULL, true, false /* can't throw */, (void*)Helper::xdecref, { var }); this->_call(NULL, true, false /* can't throw */, (void*)Helper::xdecref, { var }, {}, vars_to_bump);
// Doesn't call bumpUse, since this function is designed to be callable from other emitting functions. // Doesn't call bumpUse, since this function is designed to be callable from other emitting functions.
// (ie the caller should call bumpUse) // (ie the caller should call bumpUse)
......
...@@ -565,8 +565,8 @@ protected: ...@@ -565,8 +565,8 @@ protected:
// These do not call bumpUse on their arguments: // These do not call bumpUse on their arguments:
void _incref(RewriterVar* var, int num_refs = 1); void _incref(RewriterVar* var, int num_refs = 1);
void _decref(RewriterVar* var); void _decref(RewriterVar* var, llvm::ArrayRef<RewriterVar*> vars_to_bump = {});
void _xdecref(RewriterVar* var); void _xdecref(RewriterVar* var, llvm::ArrayRef<RewriterVar*> vars_to_bump = {});
void assertConsistent() { void assertConsistent() {
#ifndef NDEBUG #ifndef NDEBUG
......
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