Assume most branches in bounds, and use branchpred for instruction estimation.

This commit is contained in:
Wilson Snyder 2018-07-15 22:35:44 -04:00
parent e37dce9d85
commit 78c16081a4
2 changed files with 16 additions and 13 deletions

View File

@ -179,18 +179,20 @@ private:
m_instrCount = 0;
iterateAndNextNull(nodep->ifsp());
uint32_t ifCount = m_instrCount;
if (nodep->branchPred() == AstBranchPred::BP_UNLIKELY) ifCount = 0;
UINFO(8, "elsesp:\n");
m_instrCount = 0;
iterateAndNextNull(nodep->elsesp());
uint32_t elseCount = m_instrCount;
if (nodep->branchPred() == AstBranchPred::BP_LIKELY) elseCount = 0;
if (ifCount < elseCount) {
m_instrCount = savedCount + elseCount;
if (nodep->ifsp()) nodep->ifsp()->user4(0); // Don't dump it
} else {
if (ifCount >= elseCount) {
m_instrCount = savedCount + ifCount;
if (nodep->elsesp()) nodep->elsesp()->user4(0); // Don't dump it
} else {
m_instrCount = savedCount + elseCount;
if (nodep->ifsp()) nodep->ifsp()->user4(0); // Don't dump it
}
}
virtual void visit(AstNodeCond* nodep) {

View File

@ -127,15 +127,16 @@ private:
AstNode* abovep = prep->backp(); // Grab above point before lose it w/ next replace
prep->replaceWith(new AstVarRef(fl, varp, true));
AstNode* newp = new AstIf(fl, condp,
(needDly
? static_cast<AstNode*>
(new AstAssignDly(fl, prep,
new AstVarRef(fl, varp, false)))
: static_cast<AstNode*>
(new AstAssign (fl, prep,
new AstVarRef(fl, varp, false)))),
NULL);
AstIf* newp = new AstIf(fl, condp,
(needDly
? static_cast<AstNode*>
(new AstAssignDly(fl, prep,
new AstVarRef(fl, varp, false)))
: static_cast<AstNode*>
(new AstAssign (fl, prep,
new AstVarRef(fl, varp, false)))),
NULL);
newp->branchPred(AstBranchPred::BP_LIKELY);
if (debug()>=9) newp->dumpTree(cout," _new: ");
abovep->addNextStmt(newp,abovep);
prep->user2p(newp); // Save so we may LogAnd it next time