Commit 805b30c7 authored by Marius Wachtler's avatar Marius Wachtler

bjit: keep track which vregs are known to be non null

this transform some xdecrefs to decrefs
and removes some calls of assertNameDefinedHelper
parent 2023c928
......@@ -202,7 +202,8 @@ public:
template <typename Src, typename Dst> inline RewriterVar* getAttrCast(int offset, Location loc = Location::any());
bool isConstant() { return is_constant; }
bool isConstant() const { return is_constant; }
bool isContantNull() const { return isConstant() && constant_value == 0; }
protected:
void incref();
......
......@@ -412,8 +412,14 @@ RewriterVar* JitFragmentWriter::emitGetLocal(InternedString s, int vreg) {
assert(vreg >= 0);
// TODO Can we use BORROWED here? Not sure if there are cases when we can't rely on borrowing the ref
// from the vregs array. Safer like this.
RewriterVar* val_var = vregs_array->getAttr(vreg * 8)->setType(RefType::OWNED);
addAction([=]() { _emitGetLocal(val_var, s.c_str()); }, { val_var }, ActionType::NORMAL);
RewriterVar* val_var = vregs_array->getAttr(vreg * 8);
if (known_non_null_vregs.count(vreg) == 0) {
addAction([=]() { _emitGetLocal(val_var, s.c_str()); }, { val_var }, ActionType::NORMAL);
known_non_null_vregs.insert(vreg);
} else {
val_var->incref();
}
val_var->setType(RefType::OWNED);
if (LOG_BJIT_ASSEMBLY)
comment("BJIT: emitGetLocal end");
return val_var;
......@@ -696,10 +702,14 @@ void JitFragmentWriter::emitSetLocal(InternedString s, int vreg, bool set_closur
// The issue is that definedness analysis is somewhat expensive to compute, so we don't compute it
// for the bjit. We could try calculating it (which would require some re-plumbing), which might help
// but I suspect is not that big a deal as long as the llvm jit implements this kind of optimization.
bool prev_nullable = true;
bool prev_nullable = known_non_null_vregs.count(vreg) == 0;
assert(!block->cfg->getVRegInfo().isBlockLocalVReg(vreg));
vregs_array->replaceAttr(8 * vreg, v, prev_nullable);
if (v->isContantNull())
known_non_null_vregs.erase(vreg);
else
known_non_null_vregs.insert(vreg);
}
if (LOG_BJIT_ASSEMBLY)
comment("BJIT: emitSetLocal() end");
......
......@@ -207,6 +207,9 @@ private:
RewriterVar* interp;
RewriterVar* vregs_array;
llvm::DenseMap<InternedString, RewriterVar*> local_syms;
// keeps track which non block local vregs are known to have a non NULL value
// TODO: in the future we could reuse this information between different basic blocks
llvm::DenseSet<int> known_non_null_vregs;
std::unique_ptr<ICInfo> ic_info;
// Optional points to a CFGBlock and a patch location which should get patched to a direct jump if
......
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