removed dependence on numeric offset in checkLongEq and it's family

This commit is contained in:
Artur K 2012-02-29 23:30:31 +01:00
parent 0ad46c3986
commit 5d42fb0624
7 changed files with 65 additions and 55 deletions

View File

@ -56,6 +56,7 @@ public:
static COND_EXPR *idParam(int off, const STKFRAME *argSymtab);
static COND_EXPR *unary(condNodeType t, COND_EXPR *sub_expr);
static COND_EXPR *idLong(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, int off);
static COND_EXPR *idLong(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, iICODE atOffset);
static COND_EXPR *idFunc(Function *pproc, STKFRAME *args);
static COND_EXPR *idID(const ID *retVal, LOCAL_ID *locsym, iICODE ix_);
static COND_EXPR *id(const ICODE &pIcode, opLoc sd, Function *pProc, iICODE ix_, ICODE &duIcode, operDu du);

View File

@ -174,6 +174,6 @@ char *writeJcondInv (HLTYPE, Function *, int *);
int power2 (int);
/* Exported funcions from locident.c */
boolT checkLongEq (LONG_STKID_TYPE, iICODE, int, Function *, Assignment &asgn, int);
boolT checkLongRegEq (LONGID_TYPE, iICODE, int, Function *, COND_EXPR *&, COND_EXPR *&, int);
boolT checkLongEq (LONG_STKID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE atOffset);
boolT checkLongRegEq (LONGID_TYPE, iICODE, int, Function *, COND_EXPR *&, COND_EXPR *&, iICODE);
uint8_t otherLongRegi (uint8_t, int, LOCAL_ID *);

View File

@ -118,6 +118,7 @@ public:
int newIntIdx(int16_t seg, int16_t off, uint8_t regi, int ix, hlType t);
int newLongReg(hlType t, uint8_t regH, uint8_t regL, iICODE ix_);
int newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, int off);
int newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, iICODE atOffset);
void newIdent(hlType t, frameType f);
void flagByteWordId(int off);
void propLongId(uint8_t regL, uint8_t regH, const char *name);

View File

@ -254,14 +254,18 @@ COND_EXPR *COND_EXPR::idLongIdx (int idx)
/* Returns an identifier conditional expression node of type LONG_VAR */
COND_EXPR *COND_EXPR::idLong(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, int off)
{
iICODE atOffset=pIcode;
advance(atOffset,off);
return idLong(localId,sd,pIcode,f,ix,du,atOffset);
}
COND_EXPR *COND_EXPR::idLong(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, iICODE atOffset)
{
int idx;
COND_EXPR *newExp = new COND_EXPR(IDENTIFIER);
/* Check for long constant and save it as a constant expression */
if ((sd == SRC) && pIcode->ll()->testFlags(I)) /* constant */
{
iICODE atOffset=pIcode;
advance(atOffset,off);
newExp->expr.ident.idType = CONSTANT;
if (f == HIGH_FIRST)
newExp->expr.ident.idNode.kte.kte = (pIcode->ll()->src.op() << 16) +
@ -274,7 +278,7 @@ COND_EXPR *COND_EXPR::idLong(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst
/* Save it as a long expression (reg, stack or glob) */
else
{
idx = localId->newLong(sd, pIcode, f, ix, du, off);
idx = localId->newLong(sd, pIcode, f, ix, du, atOffset);
newExp->expr.ident.idType = LONG_VAR;
newExp->expr.ident.idNode.longIdx = idx;
}

View File

@ -952,9 +952,7 @@ void Function::findExps()
switch (ticode->hl()->opcode)
{
case HLI_ASSIGN:
exp = COND_EXPR::idFunc (
picode->hl()->call.proc,
picode->hl()->call.args);
exp = COND_EXPR::idFunc ( picode->hl()->call.proc, picode->hl()->call.args);
ticode->hl()->asgn.lhs =
COND_EXPR::idLong(&localId, DST, ticode,HIGH_FIRST, picode, eDEF, 1);
ticode->hl()->asgn.rhs = exp;

View File

@ -264,12 +264,12 @@ int LOCAL_ID::newLongStk(hlType t, int offH, int offL)
/* Returns the index to an appropriate long identifier.
* Note: long constants should be checked first and stored as a long integer
* number in an expression record. */
int LOCAL_ID::newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix,operDu du, int off)
int LOCAL_ID::newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix,operDu du, iICODE atOffset)
{
int idx;
LLOperand *pmH, *pmL;
iICODE atOffset(pIcode);
advance(atOffset,off);
// iICODE atOffset(pIcode);
// advance(atOffset,off);
if (f == LOW_FIRST)
{
@ -323,12 +323,11 @@ int LOCAL_ID::newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix,operDu du, i
* idx : idx into icode array
* pProc : ptr to current procedure record
* rhs, lhs : return expressions if successful. */
boolT checkLongEq (LONG_STKID_TYPE longId, iICODE pIcode, int i,
Function * pProc, Assignment &asgn, int off)
boolT checkLongEq (LONG_STKID_TYPE longId, iICODE pIcode, int i, Function * pProc, Assignment &asgn, iICODE atOffset)
{
LLOperand *pmHdst, *pmLdst, *pmHsrc, *pmLsrc; /* pointers to LOW_LEVEL icodes */
iICODE atOffset(pIcode);
advance(atOffset,off);
// iICODE atOffset(pIcode);
// advance(atOffset,off);
pmHdst = &pIcode->ll()->dst;
pmLdst = &atOffset->ll()->dst;
@ -341,13 +340,13 @@ boolT checkLongEq (LONG_STKID_TYPE longId, iICODE pIcode, int i,
if ( not pIcode->ll()->testFlags(NO_SRC) )
{
asgn.rhs = COND_EXPR::idLong (&pProc->localId, SRC, pIcode, HIGH_FIRST, pIcode, eUSE, off);
asgn.rhs = COND_EXPR::idLong (&pProc->localId, SRC, pIcode, HIGH_FIRST, pIcode, eUSE, atOffset);
}
return true;
}
else if ((longId.offH == pmHsrc->off) && (longId.offL == pmLsrc->off))
{
asgn.lhs = COND_EXPR::idLong (&pProc->localId, DST, pIcode, HIGH_FIRST, pIcode,eDEF, off);
asgn.lhs = COND_EXPR::idLong (&pProc->localId, DST, pIcode, HIGH_FIRST, pIcode,eDEF, atOffset);
asgn.rhs = COND_EXPR::idLongIdx (i);
return true;
}
@ -365,11 +364,11 @@ boolT checkLongEq (LONG_STKID_TYPE longId, iICODE pIcode, int i,
* pProc : ptr to current procedure record
* rhs, lhs : return expressions if successful. */
boolT checkLongRegEq (LONGID_TYPE longId, iICODE pIcode, int i,
Function * pProc, COND_EXPR *&rhs, COND_EXPR *&lhs, int off)
Function * pProc, COND_EXPR *&rhs, COND_EXPR *&lhs, iICODE atOffset)
{
LLOperand *pmHdst, *pmLdst, *pmHsrc, *pmLsrc; /* pointers to LOW_LEVEL icodes */
iICODE atOffset(pIcode);
advance(atOffset,off);
// iICODE atOffset(pIcode);
// advance(atOffset,off);
pmHdst = &pIcode->ll()->dst;
pmLdst = &atOffset->ll()->dst;
@ -381,13 +380,13 @@ boolT checkLongRegEq (LONGID_TYPE longId, iICODE pIcode, int i,
lhs = COND_EXPR::idLongIdx (i);
if ( not pIcode->ll()->testFlags(NO_SRC) )
{
rhs = COND_EXPR::idLong (&pProc->localId, SRC, pIcode, HIGH_FIRST, pIcode, eUSE, off);
rhs = COND_EXPR::idLong (&pProc->localId, SRC, pIcode, HIGH_FIRST, pIcode, eUSE, atOffset);
}
return true;
}
else if ((longId.h == pmHsrc->regi) && (longId.l == pmLsrc->regi))
{
lhs = COND_EXPR::idLong (&pProc->localId, DST, pIcode, HIGH_FIRST, pIcode, eDEF, off);
lhs = COND_EXPR::idLong (&pProc->localId, DST, pIcode, HIGH_FIRST, pIcode, eDEF, atOffset);
rhs = COND_EXPR::idLongIdx (i);
return true;
}

View File

@ -22,7 +22,7 @@ static boolT isJCond (llIcode opcode)
/* Returns whether the conditions for a 2-3 long variable are satisfied */
static boolT isLong23 (iICODE iter, BB * pbb, int *off, int *arc)
static bool isLong23 (iICODE iter, BB * pbb, iICODE &off, int *arc)
{
BB * t, * e, * obb2;
@ -37,7 +37,7 @@ static boolT isLong23 (iICODE iter, BB * pbb, int *off, int *arc)
obb2 = t->edges[THEN].BBptr;
if ((obb2->size() == 2) && (obb2->nodeType == TWO_BRANCH) && (obb2->front().ll()->opcode == iCMP))
{
*off = std::distance(iter,obb2->begin2());
off = obb2->begin2();//std::distance(iter,obb2->begin2());
*arc = THEN;
return true;
}
@ -49,7 +49,7 @@ static boolT isLong23 (iICODE iter, BB * pbb, int *off, int *arc)
obb2 = e->edges[THEN].BBptr;
if ((obb2->size() == 2) && (obb2->nodeType == TWO_BRANCH) && (obb2->front().ll()->opcode == iCMP))
{
*off = std::distance(iter,obb2->begin2());//obb2->front().loc_ip - i;
off = obb2->begin2();//std::distance(iter,obb2->begin2());//obb2->front().loc_ip - i;
*arc = ELSE;
return true;
}
@ -59,8 +59,9 @@ static boolT isLong23 (iICODE iter, BB * pbb, int *off, int *arc)
/* Returns whether the conditions for a 2-2 long variable are satisfied */
static boolT isLong22 (iICODE pIcode, iICODE pEnd, int *off)
static boolT isLong22 (iICODE pIcode, iICODE pEnd, iICODE &off)
{
iICODE initial_icode=pIcode;
if(distance(pIcode,pEnd)<4)
return false;
// preincrement because pIcode is not checked here
@ -69,20 +70,20 @@ static boolT isLong22 (iICODE pIcode, iICODE pEnd, int *off)
(isJCond (icodes[0]->ll()->opcode)) &&
(isJCond (icodes[2]->ll()->opcode)))
{
*off = 2;
off = initial_icode;
advance(off,2);
return true;
}
return false;
}
/** Creates a long conditional <=, >=, <, or > at (pIcode+1).
* Removes excess nodes from the graph by flagging them, and updates
* the new edges for the remaining nodes.
* @return number of ICODEs to skip
*/
static int longJCond23 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode, int arc, int off)
static int longJCond23 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode, int arc, iICODE atOffset)
{
BB * pbb, * obb1, * obb2, * tbb;
int skipped_insn=0;
@ -138,9 +139,8 @@ static int longJCond23 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode, int arc,
/* Update icode index */
skipped_insn = 2;
}
iICODE atOffset(pIcode),atOffset1(pIcode),next1(++iICODE(pIcode));
advance(atOffset,off);
advance(atOffset1,off+1);
iICODE atOffset1(atOffset),next1(++iICODE(pIcode));
advance(atOffset1,1);
/* Create new HLI_JCOND and condition */
lhs = COND_EXPR::boolOp (lhs, rhs, condOpJCond[atOffset1->ll()->opcode-iJB]);
next1->setJCond(lhs);
@ -233,7 +233,7 @@ void Function::propLongStk (int i, const ID &pLocId)
Assignment asgn;
//COND_EXPR *lhs, *rhs; /* Pointers to left and right hand expression */
iICODE next1, pEnd;
iICODE l23;
/* Check all icodes for offHi:offLo */
pEnd = Icode.end();
int stat_size=Icode.size();
@ -251,7 +251,7 @@ void Function::propLongStk (int i, const ID &pLocId)
switch (pIcode->ll()->opcode)
{
case iMOV:
if (checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, 1) == TRUE)
if (checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, next1) == TRUE)
{
pIcode->setAsgn(asgn.lhs, asgn.rhs);
next1->invalidate();
@ -259,7 +259,7 @@ void Function::propLongStk (int i, const ID &pLocId)
break;
case iAND: case iOR: case iXOR:
if (checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, 1) == TRUE)
if (checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, next1) == TRUE)
{
switch (pIcode->ll()->opcode)
{
@ -273,29 +273,35 @@ void Function::propLongStk (int i, const ID &pLocId)
break;
case iPUSH:
if (checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, 1) == TRUE)
if (checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, next1) == TRUE)
{
pIcode->setUnary( HLI_PUSH, asgn.lhs);
next1->invalidate();
}
break;
default:
printf("Wild ass checkLongEq");
// if (checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, next1) == TRUE)
// {
// printf("Wild ass checkLongEq success on opcode %d\n",pIcode->ll()->opcode);
// }
} /*eos*/
}
/* Check long conditional (i.e. 2 CMPs and 3 branches */
else if ((pIcode->ll()->opcode == iCMP) && (isLong23 (pIcode, pIcode->inBB, &off, &arc)))
else if ((pIcode->ll()->opcode == iCMP) && (isLong23 (pIcode, pIcode->inBB, l23, &arc)))
{
if ( checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, off) )
if ( checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, l23) )
{
advance(pIcode,longJCond23 (asgn.rhs, asgn.lhs, pIcode, arc, off));
advance(pIcode,longJCond23 (asgn.rhs, asgn.lhs, pIcode, arc, l23));
}
}
/* Check for long conditional equality or inequality. This requires
* 2 CMPs and 2 branches */
else if ((pIcode->ll()->opcode == iCMP) && isLong22 (pIcode, pEnd, &off))
else if ((pIcode->ll()->opcode == iCMP) && isLong22 (pIcode, pEnd, l23))
{
if ( checkLongEq (pLocId.id.longStkId, pIcode, i, this,asgn, off) )
if ( checkLongEq (pLocId.id.longStkId, pIcode, i, this,asgn, l23) )
{
advance(pIcode,longJCond22 (asgn.rhs, asgn.lhs, pIcode,pEnd));
}
@ -312,41 +318,41 @@ int Function::findBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE be
for (; not forced_finish and rev!=Icode.rend();rev++) //idx = pLocId_idx - 1; idx > 0 ; idx--
{
pIcode = (++riICODE(rev)).base();//forward iterator from rev
iICODE next1((++iICODE(pIcode))); // next instruction
ICODE &icode(*pIcode);
ICODE &next1(*(++iICODE(pIcode))); // next instruction
if ((icode.type == HIGH_LEVEL) || (icode.invalid == TRUE))
continue;
if (icode.ll()->opcode != next1.ll()->opcode)
if (icode.ll()->opcode != next1->ll()->opcode)
continue;
switch (icode.ll()->opcode)
{
case iMOV:
pmH = &icode.ll()->dst;
pmL = &next1.ll()->dst;
pmL = &next1->ll()->dst;
if ((pLocId.id.longId.h == pmH->regi) && (pLocId.id.longId.l == pmL->regi))
{
localId.id_arr[loc_ident_idx].idx.push_back(pIcode);//idx-1//insert
icode.setRegDU( pmL->regi, eDEF);
asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
asgn.rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode, HIGH_FIRST, pIcode, eUSE, 1);
asgn.rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode, HIGH_FIRST, pIcode, eUSE, next1);
icode.setAsgn(asgn.lhs, asgn.rhs);
next1.invalidate();
next1->invalidate();
forced_finish=true; /* to exit the loop */
}
break;
case iPOP:
pmH = &next1.ll()->dst;
pmH = &next1->ll()->dst;
pmL = &icode.ll()->dst;
if ((pLocId.id.longId.h == pmH->regi) && (pLocId.id.longId.l == pmL->regi))
{
asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
icode.setRegDU( pmH->regi, eDEF);
icode.setUnary(HLI_POP, asgn.lhs);
next1.invalidate();
next1->invalidate();
asgn.lhs=0;
forced_finish=true; /* to exit the loop */
}
@ -356,7 +362,7 @@ int Function::findBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE be
case iAND: case iOR: case iXOR:
pmL = &icode.ll()->dst;
pmH = &next1.ll()->dst;
pmH = &next1->ll()->dst;
if ((pLocId.id.longId.h == pmH->regi) && (pLocId.id.longId.l == pmL->regi))
{
asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
@ -373,7 +379,7 @@ int Function::findBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE be
break;
} /* eos */
icode.setAsgn(asgn.lhs, asgn.rhs);
next1.invalidate();
next1->invalidate();
forced_finish=true; /* to exit the loop */
}
break;
@ -385,6 +391,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
{
bool forced_finish=false;
auto pEnd=Icode.end();
iICODE long_loc;
Assignment asgn;
for (auto pIcode=beg; not forced_finish; ++pIcode)
{
@ -458,20 +465,20 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
} /* eos */
/* Check long conditional (i.e. 2 CMPs and 3 branches */
else if ((pIcode->ll()->opcode == iCMP) && (isLong23 (pIcode, pIcode->inBB, &off, &arc)))
else if ((pIcode->ll()->opcode == iCMP) && (isLong23 (pIcode, pIcode->inBB, long_loc, &arc)))
{
if (checkLongRegEq (pLocId.id.longId, pIcode, loc_ident_idx, this, asgn.rhs, asgn.lhs, off) == TRUE)
if (checkLongRegEq (pLocId.id.longId, pIcode, loc_ident_idx, this, asgn.rhs, asgn.lhs, long_loc))
{
// reduce the advance by 1 here (loop increases) ?
advance(pIcode,longJCond23 (asgn.rhs, asgn.lhs, pIcode, arc, off));
advance(pIcode,longJCond23 (asgn.rhs, asgn.lhs, pIcode, arc, long_loc));
}
}
/* Check for long conditional equality or inequality. This requires
* 2 CMPs and 2 branches */
else if (pIcode->ll()->match(iCMP) && (isLong22 (pIcode, pEnd, &off)))
else if (pIcode->ll()->match(iCMP) && (isLong22 (pIcode, pEnd, long_loc)))
{
if (checkLongRegEq (pLocId.id.longId, pIcode, loc_ident_idx, this, asgn.rhs, asgn.lhs, off) == TRUE)
if (checkLongRegEq (pLocId.id.longId, pIcode, loc_ident_idx, this, asgn.rhs, asgn.lhs, long_loc) )
{
advance(pIcode,longJCond22 (asgn.rhs, asgn.lhs, pIcode,pEnd) - 1);
}