Added JumpTable class, and simplified LongJCond23/22 by using Assignment

class as an parameter.
This commit is contained in:
Artur K 2012-03-17 23:42:46 +01:00
parent 7b63b45dd5
commit 71fc8bfef7
3 changed files with 45 additions and 10 deletions

View File

@ -77,6 +77,15 @@ struct Assignment
COND_EXPR *lhs;
COND_EXPR *rhs;
};
struct JumpTable
{
uint32_t start;
uint32_t finish;
bool valid() {return start<finish;}
size_t size() { return (finish-start)/2;}
size_t entrySize() { return 2;}
void pruneEntries(uint16_t cs);
};
struct Function : public llvm::ilist_node<Function>
{

View File

@ -5,3 +5,28 @@
//{
// return &m_type;
//}
/* Does some heuristic pruning. Looks for ptrs. into the table
* and for addresses that don't appear to point to valid code.
*/
void JumpTable::pruneEntries(uint16_t cs)
{
PROG *prg(Project::get()->binary());
for (uint32_t i = start; i < finish; i += 2)
{
uint32_t target = cs + LH(&prg->Image[i]);
if (target < finish && target >= start)
finish = target;
else if (target >= (uint32_t)prg->cbImage)
finish = i;
}
ICODE _Icode; // used as scan input
for (uint32_t i = start; i < finish; i += 2)
{
uint32_t target = cs + LH(&prg->Image[i]);
/* Be wary of 00 00 as code - it's probably data */
if (! (prg->Image[target] || prg->Image[target+1]) || scan(target, _Icode))
finish = i;
}
}

View File

@ -83,7 +83,7 @@ static boolT isLong22 (iICODE pIcode, iICODE pEnd, iICODE &off)
* @return number of ICODEs to skip
*/
static int longJCond23 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode, int arc, iICODE atOffset)
static int longJCond23 (Assignment &asgn, iICODE pIcode, int arc, iICODE atOffset)
{
BB * pbb, * obb1, * obb2, * tbb;
int skipped_insn=0;
@ -142,8 +142,8 @@ static int longJCond23 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode, int arc,
iICODE atOffset1(atOffset),next1(++iICODE(pIcode));
advance(atOffset1,1);
/* Create new HLI_JCOND and condition */
lhs = COND_EXPR::boolOp (lhs, rhs, condOpJCond[atOffset1->ll()->getOpcode()-iJB]);
next1->setJCond(lhs);
asgn.lhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, condOpJCond[atOffset1->ll()->getOpcode()-iJB]);
next1->setJCond(asgn.lhs);
next1->copyDU(*pIcode, eUSE, eUSE);
next1->du.use |= atOffset->du.use;
@ -167,7 +167,7 @@ static int longJCond23 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode, int arc,
* the new edges for the remaining nodes.
* @return number of ICODE's to skip
*/
static int longJCond22 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode,iICODE pEnd)
static int longJCond22 (Assignment &asgn, iICODE pIcode,iICODE pEnd)
{
BB * pbb, * obb1, * tbb;
@ -177,8 +177,8 @@ static int longJCond22 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode,iICODE pEn
iICODE icodes[] = { pIcode++,pIcode++,pIcode++,pIcode++ };
/* Form conditional expression */
lhs = COND_EXPR::boolOp (lhs, rhs, condOpJCond[icodes[3]->ll()->getOpcode() - iJB]);
icodes[1]->setJCond(lhs);
asgn.lhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, condOpJCond[icodes[3]->ll()->getOpcode() - iJB]);
icodes[1]->setJCond(asgn.lhs);
icodes[1]->copyDU (*icodes[0], eUSE, eUSE);
icodes[1]->du.use |= icodes[2]->du.use;
@ -283,7 +283,7 @@ void Function::propLongStk (int i, const ID &pLocId)
{
if ( checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, *l23->ll()) )
{
advance(pIcode,longJCond23 (asgn.rhs, asgn.lhs, pIcode, arc, l23));
advance(pIcode,longJCond23 (asgn, pIcode, arc, l23));
}
}
@ -293,7 +293,7 @@ void Function::propLongStk (int i, const ID &pLocId)
{
if ( checkLongEq (pLocId.id.longStkId, pIcode, i, this,asgn, *l23->ll()) )
{
advance(pIcode,longJCond22 (asgn.rhs, asgn.lhs, pIcode,pEnd));
advance(pIcode,longJCond22 (asgn, pIcode,pEnd));
}
}
}
@ -460,7 +460,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
if (checkLongRegEq (pLocId.id.longId, pIcode, loc_ident_idx, this, asgn, *long_loc->ll()))
{
// reduce the advance by 1 here (loop increases) ?
advance(pIcode,longJCond23 (asgn.rhs, asgn.lhs, pIcode, arc, long_loc));
advance(pIcode,longJCond23 (asgn, pIcode, arc, long_loc));
}
}
@ -470,7 +470,8 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
{
if (checkLongRegEq (pLocId.id.longId, pIcode, loc_ident_idx, this, asgn, *long_loc->ll()) )
{
advance(pIcode,longJCond22 (asgn.rhs, asgn.lhs, pIcode,pEnd) - 1);
// TODO: verify that removing -1 does not change anything !
advance(pIcode,longJCond22 (asgn, pIcode,pEnd));
}
}