liveIn/Out def/use changed to use bitset<32>
This commit is contained in:
parent
15deb26f2b
commit
74c5966579
@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
lcov -z -d bld/CMakeFiles/dcc_original.dir/src
|
||||
./regression_tester.rb bld/dcc_original -a2 -m -s -c -V
|
||||
./regression_tester.rb bld/dcc_original -a2 -m -s -c -V 2>stderr >stdout
|
||||
lcov -c -d bld/CMakeFiles/dcc_original.dir/src -o cover1.info
|
||||
lcov -e cover1.info *dcc_* -o cover2.info
|
||||
genhtml -o coverage -f --demangle-cpp cover2.info
|
||||
|
||||
@ -75,10 +75,10 @@ public:
|
||||
|
||||
/* For live register analysis
|
||||
* LiveIn(b) = LiveUse(b) U (LiveOut(b) - Def(b)) */
|
||||
dword liveUse; /* LiveUse(b) */
|
||||
dword def; /* Def(b) */
|
||||
dword liveIn; /* LiveIn(b) */
|
||||
dword liveOut; /* LiveOut(b) */
|
||||
std::bitset<32> liveUse; /* LiveUse(b) */
|
||||
std::bitset<32> def; /* Def(b) */
|
||||
std::bitset<32> liveIn; /* LiveIn(b) */
|
||||
std::bitset<32> liveOut; /* LiveOut(b) */
|
||||
|
||||
/* For structuring analysis */
|
||||
Int dfsFirstNum; /* DFS #: first visit of node */
|
||||
@ -97,8 +97,8 @@ public:
|
||||
Int caseTail; /* tail node for the case */
|
||||
|
||||
Int index; /* Index, used in several ways */
|
||||
static BB *Create(void *ctx=0,const std::string &s="",Function *parent=0,BB *insertBefore=0);
|
||||
static BB *Create(Int start, Int ip, byte nodeType, Int numOutEdges, Function * parent);
|
||||
static BB * Create(void *ctx=0,const std::string &s="",Function *parent=0,BB *insertBefore=0);
|
||||
static BB * Create(Int start, Int ip, byte nodeType, Int numOutEdges, Function * parent);
|
||||
void writeCode(Int indLevel, Function *pProc, Int *numLoc, Int latchNode, Int ifFollow);
|
||||
void mergeFallThrough(CIcodeRec &Icode);
|
||||
void dfsNumbering(std::vector<BB *> &dfsLast, Int *first, Int *last);
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <llvm/ADT/ilist.h>
|
||||
#include <llvm/ADT/ilist_node.h>
|
||||
#include <bitset>
|
||||
#include "BasicBlock.h"
|
||||
#include "types.h"
|
||||
#include "ast.h"
|
||||
@ -68,8 +69,8 @@ public:
|
||||
|
||||
/* Icodes and control flow graph */
|
||||
CIcodeRec Icode; /* Object with ICODE records */
|
||||
std::vector<BB*> cfg; /* Ptr. to BB list/CFG */
|
||||
std::vector<BB*> dfsLast;
|
||||
std::vector<BB*> m_cfg; /* Ptr. to BB list/CFG */
|
||||
std::vector<BB*> m_dfsLast;
|
||||
std::vector<BB*> heldBBs;
|
||||
//BB * *dfsLast; /* Array of pointers to BBs in dfsLast
|
||||
// * (reverse postorder) order */
|
||||
@ -77,11 +78,11 @@ public:
|
||||
boolT hasCase; /* Procedure has a case node */
|
||||
|
||||
/* For interprocedural live analysis */
|
||||
dword liveIn; /* Registers used before defined */
|
||||
dword liveOut; /* Registers that may be used in successors */
|
||||
boolT liveAnal; /* Procedure has been analysed already */
|
||||
std::bitset<32> liveIn; /* Registers used before defined */
|
||||
std::bitset<32> liveOut; /* Registers that may be used in successors */
|
||||
bool liveAnal; /* Procedure has been analysed already */
|
||||
|
||||
Function(void *ty=0) : procEntry(0),depth(0),flg(0),cbParam(0),cfg(0),dfsLast(0),numBBs(0),
|
||||
Function(void *ty=0) : procEntry(0),depth(0),flg(0),cbParam(0),m_cfg(0),m_dfsLast(0),numBBs(0),
|
||||
hasCase(false),liveIn(0),liveOut(0),liveAnal(0)//,next(0),prev(0)
|
||||
{
|
||||
}
|
||||
@ -96,7 +97,7 @@ public:
|
||||
void writeProcComments();
|
||||
void lowLevelAnalysis();
|
||||
void bindIcodeOff();
|
||||
void dataFlow(dword liveOut);
|
||||
void dataFlow(std::bitset<32> &liveOut);
|
||||
void compressCFG();
|
||||
void highLevelGen();
|
||||
void structure(derSeq *derivedG);
|
||||
@ -120,17 +121,17 @@ public:
|
||||
void newRegArg(ICODE *picode, ICODE *ticode);
|
||||
protected:
|
||||
// TODO: replace those with friend visitor ?
|
||||
void propLongReg(Int loc_ident_idx, const ID *pLocId);
|
||||
void propLongStk(Int i, ID *pLocId);
|
||||
void propLongGlb(Int i, ID *pLocId);
|
||||
void propLongReg(Int loc_ident_idx, const ID &pLocId);
|
||||
void propLongStk(Int i, const ID &pLocId);
|
||||
void propLongGlb(Int i, const ID &pLocId);
|
||||
|
||||
int checkBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE iter, Assignment &assign);
|
||||
int checkForwardLongDefs(int loc_ident_idx, const ID &pLocId, iICODE beg, Assignment &asgn);
|
||||
int findBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE iter);
|
||||
int findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE beg);
|
||||
void structCases();
|
||||
void findExps();
|
||||
void genDU1();
|
||||
void elimCondCodes();
|
||||
void liveRegAnalysis(dword in_liveOut);
|
||||
void liveRegAnalysis(std::bitset<32> &in_liveOut);
|
||||
void findIdioms();
|
||||
void propLong();
|
||||
void genLiveKtes();
|
||||
|
||||
@ -31,12 +31,12 @@ struct STKFRAME
|
||||
{
|
||||
std::vector<STKSYM> sym;
|
||||
//STKSYM * sym; /* Symbols */
|
||||
int16 minOff; /* Initial offset in stack frame*/
|
||||
int16 m_minOff; /* Initial offset in stack frame*/
|
||||
int16 maxOff; /* Maximum offset in stack frame*/
|
||||
Int cb; /* Number of bytes in arguments */
|
||||
Int numArgs; /* No. of arguments in the table*/
|
||||
void adjustForArgType(Int numArg_, hlType actType_);
|
||||
STKFRAME() : sym(0),minOff(0),maxOff(0),cb(0),numArgs(0)
|
||||
STKFRAME() : sym(0),m_minOff(0),maxOff(0),cb(0),numArgs(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ struct PROG /* Loaded program image parameters */
|
||||
};
|
||||
|
||||
extern PROG prog; /* Loaded program image parameters */
|
||||
extern dword duReg[30]; /* def/use bits for registers */
|
||||
extern std::bitset<32> duReg[30]; /* def/use bits for registers */
|
||||
|
||||
//extern dword duReg[30]; /* def/use bits for registers */
|
||||
extern dword maskDuReg[30]; /* masks off du bits for regs */
|
||||
@ -204,7 +204,7 @@ Int power2 (Int);
|
||||
void inverseCondOp (COND_EXPR **);
|
||||
|
||||
/* Exported funcions from locident.c */
|
||||
boolT checkLongEq (LONG_STKID_TYPE, iICODE, Int, Function *, COND_EXPR **, COND_EXPR **, Int);
|
||||
boolT checkLongEq (LONG_STKID_TYPE, iICODE, Int, Function *, Assignment &asgn, Int);
|
||||
boolT checkLongRegEq (LONGID_TYPE, iICODE, Int, Function *, COND_EXPR *&, COND_EXPR *&, Int);
|
||||
byte otherLongRegi (byte, Int, LOCAL_ID *);
|
||||
void insertIdx (IDX_ARRAY *, Int);
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <bitset>
|
||||
#include <llvm/MC/MCInst.h>
|
||||
#include <llvm/MC/MCAsmInfo.h>
|
||||
#include "Enums.h"
|
||||
@ -245,9 +246,12 @@ struct DU
|
||||
/* Def/Use of registers and stack variables */
|
||||
struct DU_ICODE
|
||||
{
|
||||
dword def; /* For Registers: position in dword is reg index*/
|
||||
dword lastDefRegi;/* Bit set if last def of this register in BB */
|
||||
dword use; /* For Registers: position in dword is reg index*/
|
||||
std::bitset<32> def; // For Registers: position in bitset is reg index
|
||||
//dword def; // For Registers: position in dword is reg index
|
||||
//dword def; // For Registers: position in dword is reg index
|
||||
//dword lastDefRegi; // Bit set if last def of this register in BB
|
||||
std::bitset<32> use; // For Registers: position in dword is reg index
|
||||
std::bitset<32> lastDefRegi;
|
||||
};
|
||||
|
||||
|
||||
@ -322,7 +326,7 @@ struct ICODE
|
||||
Int idx[MAX_REGS_DEF][MAX_USES]; /* inst that uses this def */
|
||||
};
|
||||
icodeType type; /* Icode type */
|
||||
boolT invalid; /* Has no HIGH_LEVEL equivalent */
|
||||
bool invalid; /* Has no HIGH_LEVEL equivalent */
|
||||
BB *inBB; /* BB to which this icode belongs */
|
||||
DU_ICODE du; /* Def/use regs/vars */
|
||||
DU1 du1; /* du chain 1 */
|
||||
|
||||
@ -109,6 +109,16 @@ struct ID
|
||||
type=t;
|
||||
loc=f;
|
||||
}
|
||||
bool isSigned() const { return (type==TYPE_BYTE_SIGN)||(type==TYPE_WORD_SIGN)||(type==TYPE_LONG_SIGN);}
|
||||
uint16_t typeBitsize() const
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case TYPE_WORD_SIGN: case TYPE_WORD_UNSIGN:
|
||||
return 16;
|
||||
}
|
||||
return ~0;
|
||||
}
|
||||
};
|
||||
|
||||
struct LOCAL_ID
|
||||
|
||||
@ -15,7 +15,7 @@ BB *BB::Create(void *ctx, const string &s, Function *parent, BB *insertBefore)
|
||||
|
||||
BB *BB::Create(Int start, Int ip, byte nodeType, Int numOutEdges, Function *parent)
|
||||
{
|
||||
parent->cfg;
|
||||
parent->m_cfg;
|
||||
BB* pnewBB;
|
||||
|
||||
pnewBB = new BB;
|
||||
@ -36,7 +36,7 @@ BB *BB::Create(Int start, Int ip, byte nodeType, Int numOutEdges, Function *pare
|
||||
if (start >= 0)
|
||||
parent->Icode.SetInBB(start, ip, pnewBB);
|
||||
parent->heldBBs.push_back(pnewBB);
|
||||
parent->cfg.push_back(pnewBB);
|
||||
parent->m_cfg.push_back(pnewBB);
|
||||
pnewBB->Parent = parent;
|
||||
}
|
||||
if (start != -1) /* Only for code BB's */
|
||||
@ -126,7 +126,7 @@ void BB::writeCode (Int indLevel, Function * pProc , Int *numLoc,Int latchNode,
|
||||
repCond; /* Repeat condition for while() */
|
||||
|
||||
/* Check if this basic block should be analysed */
|
||||
if ((_ifFollow != UN_INIT) && (this == pProc->dfsLast[_ifFollow]))
|
||||
if ((_ifFollow != UN_INIT) && (this == pProc->m_dfsLast[_ifFollow]))
|
||||
return;
|
||||
|
||||
if (traversed == DFS_ALPHA)
|
||||
@ -139,7 +139,7 @@ void BB::writeCode (Int indLevel, Function * pProc , Int *numLoc,Int latchNode,
|
||||
_loopType = loopType;
|
||||
if (_loopType)
|
||||
{
|
||||
latch = pProc->dfsLast[this->latchNode];
|
||||
latch = pProc->m_dfsLast[this->latchNode];
|
||||
switch (_loopType)
|
||||
{
|
||||
case WHILE_TYPE:
|
||||
@ -236,7 +236,7 @@ void BB::writeCode (Int indLevel, Function * pProc , Int *numLoc,Int latchNode,
|
||||
/* Recurse on the loop follow */
|
||||
if (loopFollow != MAX)
|
||||
{
|
||||
succ = pProc->dfsLast[loopFollow];
|
||||
succ = pProc->m_dfsLast[loopFollow];
|
||||
if (succ->traversed != DFS_ALPHA)
|
||||
succ->writeCode (indLevel, pProc, numLoc, latchNode, _ifFollow);
|
||||
else /* has been traversed so we need a goto */
|
||||
@ -297,7 +297,7 @@ void BB::writeCode (Int indLevel, Function * pProc , Int *numLoc,Int latchNode,
|
||||
cCode.appendCode( "%s}\n", indent(--indLevel));
|
||||
|
||||
/* Continue with the follow */
|
||||
succ = pProc->dfsLast[follow];
|
||||
succ = pProc->m_dfsLast[follow];
|
||||
if (succ->traversed != DFS_ALPHA)
|
||||
succ->writeCode (indLevel, pProc, numLoc, latchNode,_ifFollow);
|
||||
}
|
||||
|
||||
@ -259,8 +259,6 @@ 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)
|
||||
{
|
||||
//assert(pIcode==ix);
|
||||
//printf("**************** Not EQUAL ***************** \n");
|
||||
Int idx;
|
||||
COND_EXPR *newExp = new COND_EXPR(IDENTIFIER);
|
||||
|
||||
|
||||
@ -196,7 +196,8 @@ static void writeHeader (std::ostream &ios, char *fileName)
|
||||
|
||||
/* Writes the registers that are set in the bitvector */
|
||||
static void writeBitVector (dword regi)
|
||||
{ Int j;
|
||||
{
|
||||
Int j;
|
||||
|
||||
for (j = 0; j < INDEXBASE; j++)
|
||||
{
|
||||
@ -204,6 +205,15 @@ static void writeBitVector (dword regi)
|
||||
printf ("%s ", allRegs[j]);
|
||||
}
|
||||
}
|
||||
static void writeBitVector (const std::bitset<32> ®i)
|
||||
{ Int j;
|
||||
|
||||
for (j = 0; j < INDEXBASE; j++)
|
||||
{
|
||||
if (regi.test(j))
|
||||
printf ("%s ", allRegs[j]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -298,7 +308,7 @@ void Function::codeGen (std::ostream &fs)
|
||||
if (flg & PROC_ASM) /* generate assembler */
|
||||
disassem (3, this);
|
||||
else /* generate C */
|
||||
cfg.front()->writeCode (1, this, &numLoc, MAX, UN_INIT);
|
||||
m_cfg.front()->writeCode (1, this, &numLoc, MAX, UN_INIT);
|
||||
|
||||
cCode.appendCode( "}\n\n");
|
||||
writeBundle (fs, cCode);
|
||||
@ -308,7 +318,7 @@ void Function::codeGen (std::ostream &fs)
|
||||
if (option.verbose)
|
||||
for (i = 0; i < numBBs; i++)
|
||||
{
|
||||
pBB = dfsLast[i];
|
||||
pBB = m_dfsLast[i];
|
||||
if (pBB->flg & INVALID_BB) continue; /* skip invalid BBs */
|
||||
printf ("BB %d\n", i);
|
||||
printf (" Start = %d, end = %d\n", pBB->begin(), pBB->end());
|
||||
|
||||
@ -54,9 +54,9 @@ static Int commonDom (Int currImmDom, Int predImmDom, Function * pProc)
|
||||
(currImmDom != predImmDom))
|
||||
{
|
||||
if (currImmDom < predImmDom)
|
||||
predImmDom = pProc->dfsLast[predImmDom]->immedDom;
|
||||
predImmDom = pProc->m_dfsLast[predImmDom]->immedDom;
|
||||
else
|
||||
currImmDom = pProc->dfsLast[currImmDom]->immedDom;
|
||||
currImmDom = pProc->m_dfsLast[currImmDom]->immedDom;
|
||||
}
|
||||
return (currImmDom);
|
||||
}
|
||||
@ -73,7 +73,7 @@ void Function::findImmedDom ()
|
||||
|
||||
for (currIdx = 0; currIdx < numBBs; currIdx++)
|
||||
{
|
||||
currNode = dfsLast[currIdx];
|
||||
currNode = m_dfsLast[currIdx];
|
||||
if (currNode->flg & INVALID_BB) /* Do not process invalid BBs */
|
||||
continue;
|
||||
for (BB * inedge : currNode->inEdges)
|
||||
@ -125,9 +125,9 @@ static void findEndlessFollow (Function * pProc, nodeList &loopNodes, BB * head)
|
||||
nodeList::iterator p = loopNodes.begin();
|
||||
for( ;p != loopNodes.end();++p)
|
||||
{
|
||||
for (j = 0; j < pProc->dfsLast[*p]->edges.size(); j++)
|
||||
for (j = 0; j < pProc->m_dfsLast[*p]->edges.size(); j++)
|
||||
{
|
||||
succ = pProc->dfsLast[*p]->edges[j].BBptr->dfsLastNum;
|
||||
succ = pProc->m_dfsLast[*p]->edges[j].BBptr->dfsLastNum;
|
||||
if ((! inList(loopNodes, succ)) && (succ < head->loopFollow))
|
||||
head->loopFollow = succ;
|
||||
}
|
||||
@ -152,15 +152,15 @@ static void findNodesInLoop(BB * latchNode,BB * head,Function * pProc,queue &int
|
||||
insertList (loopNodes, headDfsNum);
|
||||
for (i = headDfsNum + 1; i < latchNode->dfsLastNum; i++)
|
||||
{
|
||||
if (pProc->dfsLast[i]->flg & INVALID_BB) /* skip invalid BBs */
|
||||
if (pProc->m_dfsLast[i]->flg & INVALID_BB) /* skip invalid BBs */
|
||||
continue;
|
||||
|
||||
immedDom = pProc->dfsLast[i]->immedDom;
|
||||
if (inList (loopNodes, immedDom) && inInt(pProc->dfsLast[i], intNodes))
|
||||
immedDom = pProc->m_dfsLast[i]->immedDom;
|
||||
if (inList (loopNodes, immedDom) && inInt(pProc->m_dfsLast[i], intNodes))
|
||||
{
|
||||
insertList (loopNodes, i);
|
||||
if (pProc->dfsLast[i]->loopHead == NO_NODE)/*not in other loop*/
|
||||
pProc->dfsLast[i]->loopHead = headDfsNum;
|
||||
if (pProc->m_dfsLast[i]->loopHead == NO_NODE)/*not in other loop*/
|
||||
pProc->m_dfsLast[i]->loopHead = headDfsNum;
|
||||
}
|
||||
}
|
||||
latchNode->loopHead = headDfsNum;
|
||||
@ -233,10 +233,10 @@ static void findNodesInLoop(BB * latchNode,BB * head,Function * pProc,queue &int
|
||||
findEndlessFollow (pProc, loopNodes, head);
|
||||
break;
|
||||
}
|
||||
pbb = pProc->dfsLast[pbb->immedDom];
|
||||
pbb = pProc->m_dfsLast[pbb->immedDom];
|
||||
}
|
||||
if (pbb->dfsLastNum > head->dfsLastNum)
|
||||
pProc->dfsLast[head->loopFollow]->loopHead = NO_NODE; /*****/
|
||||
pProc->m_dfsLast[head->loopFollow]->loopHead = NO_NODE; /*****/
|
||||
head->back().SetLlFlag(JX_LOOP);
|
||||
}
|
||||
else
|
||||
@ -342,7 +342,7 @@ static boolT successor (Int s, Int h, Function * pProc)
|
||||
Int i;
|
||||
BB * header;
|
||||
|
||||
header = pProc->dfsLast[h];
|
||||
header = pProc->m_dfsLast[h];
|
||||
for (i = 0; i < header->edges.size(); i++)
|
||||
if (header->edges[i].BBptr->dfsLastNum == s)
|
||||
return true;
|
||||
@ -382,27 +382,27 @@ void Function::structCases()
|
||||
/* Linear scan of the nodes in reverse dfsLast order, searching for
|
||||
* case nodes */
|
||||
for (i = numBBs - 1; i >= 0; i--)
|
||||
if (dfsLast[i]->nodeType == MULTI_BRANCH)
|
||||
if (m_dfsLast[i]->nodeType == MULTI_BRANCH)
|
||||
{
|
||||
caseHeader = dfsLast[i];
|
||||
caseHeader = m_dfsLast[i];
|
||||
|
||||
/* Find descendant node which has as immediate predecessor
|
||||
* the current header node, and is not a successor. */
|
||||
for (j = i + 2; j < numBBs; j++)
|
||||
{
|
||||
if ((!successor(j, i, this)) &&
|
||||
(dfsLast[j]->immedDom == i))
|
||||
(m_dfsLast[j]->immedDom == i))
|
||||
if (exitNode == NO_NODE)
|
||||
exitNode = j;
|
||||
else if (dfsLast[exitNode]->inEdges.size() < dfsLast[j]->inEdges.size())
|
||||
else if (m_dfsLast[exitNode]->inEdges.size() < m_dfsLast[j]->inEdges.size())
|
||||
exitNode = j;
|
||||
}
|
||||
dfsLast[i]->caseTail = exitNode;
|
||||
m_dfsLast[i]->caseTail = exitNode;
|
||||
|
||||
/* Tag nodes that belong to the case by recording the
|
||||
* header field with caseHeader. */
|
||||
insertList (caseNodes, i);
|
||||
dfsLast[i]->caseHead = i;
|
||||
m_dfsLast[i]->caseHead = i;
|
||||
for(TYPEADR_TYPE &pb : caseHeader->edges)
|
||||
{
|
||||
tagNodesInCase(pb.BBptr, caseNodes, i, exitNode);
|
||||
@ -410,7 +410,7 @@ void Function::structCases()
|
||||
//for (j = 0; j < caseHeader->edges[j]; j++)
|
||||
// tagNodesInCase (caseHeader->edges[j].BBptr, caseNodes, i, exitNode);
|
||||
if (exitNode != NO_NODE)
|
||||
dfsLast[exitNode]->caseHead = i;
|
||||
m_dfsLast[exitNode]->caseHead = i;
|
||||
}
|
||||
}
|
||||
|
||||
@ -424,7 +424,7 @@ static void flagNodes (nodeList &l, Int f, Function * pProc)
|
||||
p = l.begin();
|
||||
while (p!=l.end())
|
||||
{
|
||||
pProc->dfsLast[*p]->ifFollow = f;
|
||||
pProc->m_dfsLast[*p]->ifFollow = f;
|
||||
p = l.erase(p);
|
||||
}
|
||||
}
|
||||
@ -446,7 +446,7 @@ void Function::structIfs ()
|
||||
/* Linear scan of nodes in reverse dfsLast order */
|
||||
for (curr = numBBs - 1; curr >= 0; curr--)
|
||||
{
|
||||
currNode = dfsLast[curr];
|
||||
currNode = m_dfsLast[curr];
|
||||
if (currNode->flg & INVALID_BB) /* Do not process invalid BBs */
|
||||
continue;
|
||||
|
||||
@ -458,10 +458,10 @@ void Function::structIfs ()
|
||||
/* Find all nodes that have this node as immediate dominator */
|
||||
for (desc = curr+1; desc < numBBs; desc++)
|
||||
{
|
||||
if (dfsLast[desc]->immedDom == curr)
|
||||
if (m_dfsLast[desc]->immedDom == curr)
|
||||
{
|
||||
insertList (domDesc, desc);
|
||||
pbb = dfsLast[desc];
|
||||
pbb = m_dfsLast[desc];
|
||||
if ((pbb->inEdges.size() - pbb->numBackEdges) >= followInEdges)
|
||||
{
|
||||
follow = desc;
|
||||
@ -507,7 +507,7 @@ void Function::compoundCond()
|
||||
* compound condition is analysed first */
|
||||
for (i = 0; i < this->numBBs; i++)
|
||||
{
|
||||
pbb = this->dfsLast[i];
|
||||
pbb = this->m_dfsLast[i];
|
||||
if (pbb->flg & INVALID_BB)
|
||||
continue;
|
||||
|
||||
@ -547,11 +547,11 @@ void Function::compoundCond()
|
||||
t->flg |= INVALID_BB;
|
||||
|
||||
if (pbb->flg & IS_LATCH_NODE)
|
||||
this->dfsLast[t->dfsLastNum] = pbb;
|
||||
this->m_dfsLast[t->dfsLastNum] = pbb;
|
||||
else
|
||||
i--; /* to repeat this analysis */
|
||||
|
||||
change = TRUE;
|
||||
change = true;
|
||||
}
|
||||
|
||||
/* Check (!X && Y) case */
|
||||
@ -585,7 +585,7 @@ void Function::compoundCond()
|
||||
t->flg |= INVALID_BB;
|
||||
|
||||
if (pbb->flg & IS_LATCH_NODE)
|
||||
this->dfsLast[t->dfsLastNum] = pbb;
|
||||
this->m_dfsLast[t->dfsLastNum] = pbb;
|
||||
else
|
||||
i--; /* to repeat this analysis */
|
||||
|
||||
@ -620,7 +620,7 @@ void Function::compoundCond()
|
||||
e->flg |= INVALID_BB;
|
||||
|
||||
if (pbb->flg & IS_LATCH_NODE)
|
||||
this->dfsLast[e->dfsLastNum] = pbb;
|
||||
this->m_dfsLast[e->dfsLastNum] = pbb;
|
||||
else
|
||||
i--; /* to repeat this analysis */
|
||||
|
||||
@ -657,7 +657,7 @@ void Function::compoundCond()
|
||||
e->flg |= INVALID_BB;
|
||||
|
||||
if (pbb->flg & IS_LATCH_NODE)
|
||||
this->dfsLast[e->dfsLastNum] = pbb;
|
||||
this->m_dfsLast[e->dfsLastNum] = pbb;
|
||||
else
|
||||
i--; /* to repeat this analysis */
|
||||
|
||||
|
||||
320
src/dataflow.cpp
320
src/dataflow.cpp
@ -83,18 +83,14 @@ Int STKFRAME::getLocVar(Int off)
|
||||
/* Returns a string with the source operand of Icode */
|
||||
static COND_EXPR *srcIdent (const ICODE &Icode, Function * pProc, iICODE i, ICODE & duIcode, operDu du)
|
||||
{
|
||||
COND_EXPR *n;
|
||||
|
||||
if (Icode.ic.ll.flg & I) /* immediate operand */
|
||||
{
|
||||
if (Icode.ic.ll.flg & B)
|
||||
n = COND_EXPR::idKte (Icode.ic.ll.src.op(), 1);
|
||||
else
|
||||
n = COND_EXPR::idKte (Icode.ic.ll.src.op(), 2);
|
||||
return COND_EXPR::idKte (Icode.ic.ll.src.op(), 1);
|
||||
return COND_EXPR::idKte (Icode.ic.ll.src.op(), 2);
|
||||
}
|
||||
else
|
||||
n = COND_EXPR::id (Icode, SRC, pProc, i, duIcode, du);
|
||||
return (n);
|
||||
// otherwise
|
||||
return COND_EXPR::id (Icode, SRC, pProc, i, duIcode, du);
|
||||
}
|
||||
|
||||
|
||||
@ -125,7 +121,7 @@ void Function::elimCondCodes ()
|
||||
riICODE defAt; /* Instruction that defined flag */
|
||||
for (i = 0; i < numBBs; i++)
|
||||
{
|
||||
pBB = dfsLast[i];
|
||||
pBB = m_dfsLast[i];
|
||||
if (pBB->flg & INVALID_BB)
|
||||
continue; /* Do not process invalid BBs */
|
||||
|
||||
@ -225,7 +221,7 @@ void Function::elimCondCodes ()
|
||||
}
|
||||
|
||||
|
||||
/* Generates the LiveUse() and Def() sets for each basic block in the graph.
|
||||
/** Generates the LiveUse() and Def() sets for each basic block in the graph.
|
||||
* Note: these sets are constant and could have been constructed during
|
||||
* the construction of the graph, but since the code hasn't been
|
||||
* analyzed yet for idioms, the procedure preamble misleads the
|
||||
@ -235,14 +231,15 @@ void Function::genLiveKtes ()
|
||||
{
|
||||
Int i;
|
||||
BB * pbb;
|
||||
dword liveUse, def;
|
||||
bitset<32> liveUse, def;
|
||||
|
||||
for (i = 0; i < numBBs; i++)
|
||||
{
|
||||
liveUse = def = 0;
|
||||
pbb = dfsLast[i];
|
||||
liveUse.reset();
|
||||
def.reset();
|
||||
pbb = m_dfsLast[i];
|
||||
if (pbb->flg & INVALID_BB)
|
||||
continue; /* skip invalid BBs */
|
||||
continue; // skip invalid BBs
|
||||
for (auto j = pbb->begin2(); j != pbb->end2(); j++)
|
||||
{
|
||||
if ((j->type == HIGH_LEVEL) && (j->invalid == FALSE))
|
||||
@ -260,14 +257,14 @@ void Function::genLiveKtes ()
|
||||
/* Generates the liveIn() and liveOut() sets for each basic block via an
|
||||
* iterative approach.
|
||||
* Propagates register usage information to the procedure call. */
|
||||
void Function::liveRegAnalysis (dword in_liveOut)
|
||||
void Function::liveRegAnalysis (std::bitset<32> &in_liveOut)
|
||||
{
|
||||
Int i, j;
|
||||
BB * pbb=0; /* pointer to current basic block */
|
||||
Function * pcallee; /* invoked subroutine */
|
||||
ICODE *ticode /* icode that invokes a subroutine */
|
||||
//ICODE *ticode /* icode that invokes a subroutine */
|
||||
;
|
||||
dword prevLiveOut, /* previous live out */
|
||||
std::bitset<32> prevLiveOut, /* previous live out */
|
||||
prevLiveIn; /* previous live in */
|
||||
boolT change; /* is there change in the live sets?*/
|
||||
|
||||
@ -281,7 +278,7 @@ void Function::liveRegAnalysis (dword in_liveOut)
|
||||
change = FALSE;
|
||||
for (i = numBBs; i > 0; i--)
|
||||
{
|
||||
pbb = dfsLast[i-1];
|
||||
pbb = m_dfsLast[i-1];
|
||||
if (pbb->flg & INVALID_BB) /* Do not process invalid BBs */
|
||||
continue;
|
||||
|
||||
@ -310,8 +307,8 @@ void Function::liveRegAnalysis (dword in_liveOut)
|
||||
}
|
||||
else /* Check successors */
|
||||
{
|
||||
for (j = 0; j < pbb->edges.size(); j++)
|
||||
pbb->liveOut |= pbb->edges[j].BBptr->liveIn;
|
||||
for(TYPEADR_TYPE &e : pbb->edges)
|
||||
pbb->liveOut |= e.BBptr->liveIn;
|
||||
|
||||
/* propagate to invoked procedure */
|
||||
if (pbb->nodeType == CALL_NODE)
|
||||
@ -328,8 +325,9 @@ void Function::liveRegAnalysis (dword in_liveOut)
|
||||
}
|
||||
else /* library routine */
|
||||
{
|
||||
if ((pcallee->flg & PROC_IS_FUNC) && /* returns a value */
|
||||
(pcallee->liveOut & pbb->edges[0].BBptr->liveIn))
|
||||
if ( (pcallee->flg & PROC_IS_FUNC) && /* returns a value */
|
||||
(pcallee->liveOut & pbb->edges[0].BBptr->liveIn).any()
|
||||
)
|
||||
pbb->liveOut = pcallee->liveOut;
|
||||
else
|
||||
pbb->liveOut = 0;
|
||||
@ -345,6 +343,8 @@ void Function::liveRegAnalysis (dword in_liveOut)
|
||||
case TYPE_BYTE_SIGN: case TYPE_BYTE_UNSIGN:
|
||||
ticode.du1.numRegsDef = 1;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"Function::liveRegAnalysis : Unknow return type\n");
|
||||
} /*eos*/
|
||||
|
||||
/* Propagate def/use results to calling icode */
|
||||
@ -388,15 +388,16 @@ void Function::genDU1 ()
|
||||
Int i, k, defRegIdx, useIdx;
|
||||
iICODE picode, ticode,lastInst;/* Current and target bb */
|
||||
BB * pbb, *tbb; /* Current and target basic block */
|
||||
boolT res;
|
||||
COND_EXPR *exp, *lhs;
|
||||
bool res;
|
||||
//COND_EXPR *exp, *lhs;
|
||||
|
||||
/* Traverse tree in dfsLast order */
|
||||
assert(dfsLast.size()==numBBs);
|
||||
assert(m_dfsLast.size()==numBBs);
|
||||
for (i = 0; i < numBBs; i++)
|
||||
{
|
||||
pbb = dfsLast[i];
|
||||
if (pbb->flg & INVALID_BB) continue;
|
||||
pbb = m_dfsLast[i];
|
||||
if (pbb->flg & INVALID_BB)
|
||||
continue;
|
||||
|
||||
/* Process each register definition of a HIGH_LEVEL icode instruction.
|
||||
* Note that register variables should not be considered registers.
|
||||
@ -404,133 +405,131 @@ void Function::genDU1 ()
|
||||
lastInst = pbb->end2();
|
||||
for (picode = pbb->begin2(); picode != lastInst; picode++)
|
||||
{
|
||||
if (picode->type == HIGH_LEVEL)
|
||||
if (picode->type != HIGH_LEVEL)
|
||||
continue;
|
||||
regi = 0;
|
||||
defRegIdx = 0;
|
||||
for (k = 0; k < INDEXBASE; k++)
|
||||
{
|
||||
regi = 0;
|
||||
defRegIdx = 0;
|
||||
for (k = 0; k < INDEXBASE; k++)
|
||||
if (not picode->du.def.test(k))
|
||||
continue;
|
||||
regi = (byte)(k + 1); /* defined register */
|
||||
picode->du1.regi[defRegIdx] = regi;
|
||||
|
||||
/* Check remaining instructions of the BB for all uses
|
||||
* of register regi, before any definitions of the
|
||||
* register */
|
||||
if ((regi == rDI) && (flg & DI_REGVAR))
|
||||
continue;
|
||||
if ((regi == rSI) && (flg & SI_REGVAR))
|
||||
continue;
|
||||
if ((picode + 1) != lastInst) /* several instructions */
|
||||
{
|
||||
if ((picode->du.def & power2(k)) == 0)
|
||||
continue;
|
||||
regi = (byte)(k + 1); /* defined register */
|
||||
picode->du1.regi[defRegIdx] = regi;
|
||||
|
||||
/* Check remaining instructions of the BB for all uses
|
||||
* of register regi, before any definitions of the
|
||||
* register */
|
||||
if ((regi == rDI) && (flg & DI_REGVAR))
|
||||
continue;
|
||||
if ((regi == rSI) && (flg & SI_REGVAR))
|
||||
continue;
|
||||
if ((picode + 1) != lastInst) /* several instructions */
|
||||
useIdx = 0;
|
||||
for (auto ricode = picode + 1; ricode != lastInst; ricode++)
|
||||
{
|
||||
useIdx = 0;
|
||||
for (auto ricode = picode + 1; ricode != lastInst; ricode++)
|
||||
ticode=ricode;
|
||||
/* Only check uses of HIGH_LEVEL icodes */
|
||||
if (ricode->type == HIGH_LEVEL)
|
||||
{
|
||||
ticode=ricode;
|
||||
/* Only check uses of HIGH_LEVEL icodes */
|
||||
if (ricode->type == HIGH_LEVEL)
|
||||
{
|
||||
/* if used, get icode index */
|
||||
if (ricode->du.use & duReg[regi])
|
||||
picode->du1.idx[defRegIdx][useIdx++] = ricode->loc_ip;
|
||||
/* if used, get icode index */
|
||||
if ((ricode->du.use & duReg[regi]).any())
|
||||
picode->du1.idx[defRegIdx][useIdx++] = ricode->loc_ip;
|
||||
|
||||
/* if defined, stop finding uses for this reg */
|
||||
if (ricode->du.def & duReg[regi])
|
||||
break;
|
||||
}
|
||||
/* if defined, stop finding uses for this reg */
|
||||
if ((ricode->du.def & duReg[regi]).any())
|
||||
break;
|
||||
}
|
||||
|
||||
/* Check if last definition of this register */
|
||||
if ((! (ticode->du.def & duReg[regi])) && (pbb->liveOut & duReg[regi]))
|
||||
picode->du.lastDefRegi |= duReg[regi];
|
||||
}
|
||||
else /* only 1 instruction in this basic block */
|
||||
{
|
||||
/* Check if last definition of this register */
|
||||
if (pbb->liveOut & duReg[regi])
|
||||
picode->du.lastDefRegi |= duReg[regi];
|
||||
}
|
||||
|
||||
/* Find target icode for HLI_CALL icodes to procedures
|
||||
* that are functions. The target icode is in the
|
||||
* next basic block (unoptimized code) or somewhere else
|
||||
* on optimized code. */
|
||||
if ((picode->ic.hl.opcode == HLI_CALL) &&
|
||||
(picode->ic.hl.oper.call.proc->flg & PROC_IS_FUNC))
|
||||
/* Check if last definition of this register */
|
||||
if ((not (ticode->du.def & duReg[regi]).any()) and (pbb->liveOut & duReg[regi]).any())
|
||||
picode->du.lastDefRegi |= duReg[regi];
|
||||
}
|
||||
else /* only 1 instruction in this basic block */
|
||||
{
|
||||
/* Check if last definition of this register */
|
||||
if ((pbb->liveOut & duReg[regi]).any())
|
||||
picode->du.lastDefRegi |= duReg[regi];
|
||||
}
|
||||
|
||||
/* Find target icode for HLI_CALL icodes to procedures
|
||||
* that are functions. The target icode is in the
|
||||
* next basic block (unoptimized code) or somewhere else
|
||||
* on optimized code. */
|
||||
if ((picode->ic.hl.opcode == HLI_CALL) &&
|
||||
(picode->ic.hl.oper.call.proc->flg & PROC_IS_FUNC))
|
||||
{
|
||||
tbb = pbb->edges[0].BBptr;
|
||||
useIdx = 0;
|
||||
for (ticode = tbb->begin2(); ticode != tbb->end2(); ticode++)
|
||||
{
|
||||
tbb = pbb->edges[0].BBptr;
|
||||
useIdx = 0;
|
||||
for (ticode = tbb->begin2(); ticode != tbb->end2(); ticode++)
|
||||
{
|
||||
if (ticode->type == HIGH_LEVEL)
|
||||
if (ticode->type != HIGH_LEVEL)
|
||||
continue;
|
||||
/* if used, get icode index */
|
||||
if ((ticode->du.use & duReg[regi]).any())
|
||||
picode->du1.idx[defRegIdx][useIdx++] = ticode->loc_ip;
|
||||
|
||||
/* if defined, stop finding uses for this reg */
|
||||
if ((ticode->du.def & duReg[regi]).any())
|
||||
break;
|
||||
}
|
||||
|
||||
/* if not used in this basic block, check if the
|
||||
* register is live out, if so, make it the last
|
||||
* definition of this register */
|
||||
if ((picode->du1.idx[defRegIdx][useIdx] == 0) &&
|
||||
(tbb->liveOut & duReg[regi]).any())
|
||||
picode->du.lastDefRegi |= duReg[regi];
|
||||
}
|
||||
|
||||
/* If not used within this bb or in successors of this
|
||||
* bb (ie. not in liveOut), then register is useless,
|
||||
* thus remove it. Also check that this is not a return
|
||||
* from a library function (routines such as printf
|
||||
* return an integer, which is normally not taken into
|
||||
* account by the programmer). */
|
||||
if ((picode->invalid == FALSE) &&
|
||||
(picode->du1.idx[defRegIdx][0] == 0) &&
|
||||
(not (picode->du.lastDefRegi & duReg[regi]).any()) &&
|
||||
//(! ((picode->ic.hl.opcode != HLI_CALL) &&
|
||||
(not ((picode->ic.hl.opcode == HLI_CALL) &&
|
||||
(picode->ic.hl.oper.call.proc->flg & PROC_ISLIB))))
|
||||
{
|
||||
if (! (pbb->liveOut & duReg[regi]).any()) /* not liveOut */
|
||||
{
|
||||
res = picode->removeDefRegi (regi, defRegIdx+1,&localId);
|
||||
|
||||
/* Backpatch any uses of this instruction, within
|
||||
* the same BB, if the instruction was invalidated */
|
||||
if (res == TRUE)
|
||||
for (auto ticode = riICODE(picode); ticode != pbb->rend2(); ticode++)
|
||||
{
|
||||
/* if used, get icode index */
|
||||
if (ticode->du.use & duReg[regi])
|
||||
picode->du1.idx[defRegIdx][useIdx++] = ticode->loc_ip;
|
||||
|
||||
/* if defined, stop finding uses for this reg */
|
||||
if (ticode->du.def & duReg[regi])
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* if not used in this basic block, check if the
|
||||
* register is live out, if so, make it the last
|
||||
* definition of this register */
|
||||
if ((picode->du1.idx[defRegIdx][useIdx] == 0) &&
|
||||
(tbb->liveOut & duReg[regi]))
|
||||
picode->du.lastDefRegi |= duReg[regi];
|
||||
}
|
||||
|
||||
/* If not used within this bb or in successors of this
|
||||
* bb (ie. not in liveOut), then register is useless,
|
||||
* thus remove it. Also check that this is not a return
|
||||
* from a library function (routines such as printf
|
||||
* return an integer, which is normally not taken into
|
||||
* account by the programmer). */
|
||||
if ((picode->invalid == FALSE) &&
|
||||
(picode->du1.idx[defRegIdx][0] == 0) &&
|
||||
(! (picode->du.lastDefRegi & duReg[regi])) &&
|
||||
// (! ((picode->ic.hl.opcode != HLI_CALL) &&
|
||||
(! ((picode->ic.hl.opcode == HLI_CALL) &&
|
||||
(picode->ic.hl.oper.call.proc->flg & PROC_ISLIB))))
|
||||
{
|
||||
if (! (pbb->liveOut & duReg[regi])) /* not liveOut */
|
||||
{
|
||||
res = picode->removeDefRegi (regi, defRegIdx+1,&localId);
|
||||
|
||||
/* Backpatch any uses of this instruction, within
|
||||
* the same BB, if the instruction was invalidated */
|
||||
if (res == TRUE)
|
||||
for (auto ticode = riICODE(picode); ticode != pbb->rend2(); ticode++)
|
||||
for (int n = 0; n < MAX_USES; n++)
|
||||
{
|
||||
for (int n = 0; n < MAX_USES; n++)
|
||||
if (ticode->du1.idx[0][n] == picode->loc_ip)
|
||||
{
|
||||
if (ticode->du1.idx[0][n] == picode->loc_ip)
|
||||
if (n < MAX_USES - 1)
|
||||
{
|
||||
if (n < MAX_USES - 1)
|
||||
{
|
||||
memmove (&ticode->du1.idx[0][n],
|
||||
&ticode->du1.idx[0][n+1],
|
||||
(size_t)((MAX_USES - n - 1) * sizeof(Int)));
|
||||
n--;
|
||||
}
|
||||
ticode->du1.idx[0][MAX_USES - 1] = 0;
|
||||
memmove (&ticode->du1.idx[0][n],
|
||||
&ticode->du1.idx[0][n+1],
|
||||
(size_t)((MAX_USES - n - 1) * sizeof(Int)));
|
||||
n--;
|
||||
}
|
||||
ticode->du1.idx[0][MAX_USES - 1] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else /* liveOut */
|
||||
picode->du.lastDefRegi |= duReg[regi];
|
||||
}
|
||||
}
|
||||
defRegIdx++;
|
||||
|
||||
/* Check if all defined registers have been processed */
|
||||
if ((defRegIdx >= picode->du1.numRegsDef) ||
|
||||
(defRegIdx == MAX_REGS_DEF))
|
||||
break;
|
||||
else /* liveOut */
|
||||
picode->du.lastDefRegi |= duReg[regi];
|
||||
}
|
||||
defRegIdx++;
|
||||
|
||||
/* Check if all defined registers have been processed */
|
||||
if ((defRegIdx >= picode->du1.numRegsDef) ||
|
||||
(defRegIdx == MAX_REGS_DEF))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -541,7 +540,7 @@ void Function::genDU1 ()
|
||||
/* Substitutes the rhs (or lhs if rhs not possible) of ticode for the rhs
|
||||
* of picode. */
|
||||
static void forwardSubs (COND_EXPR *lhs, COND_EXPR *rhs, ICODE * picode,
|
||||
ICODE * ticode, LOCAL_ID *locsym, Int *numHlIcodes)
|
||||
ICODE * ticode, LOCAL_ID *locsym, Int &numHlIcodes)
|
||||
{
|
||||
boolT res;
|
||||
|
||||
@ -555,7 +554,7 @@ static void forwardSubs (COND_EXPR *lhs, COND_EXPR *rhs, ICODE * picode,
|
||||
if (res)
|
||||
{
|
||||
picode->invalidate();
|
||||
(*numHlIcodes)--;
|
||||
numHlIcodes--;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -566,7 +565,7 @@ static void forwardSubs (COND_EXPR *lhs, COND_EXPR *rhs, ICODE * picode,
|
||||
if (res)
|
||||
{
|
||||
picode->invalidate();
|
||||
(*numHlIcodes)--;
|
||||
numHlIcodes--;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -576,7 +575,8 @@ static void forwardSubs (COND_EXPR *lhs, COND_EXPR *rhs, ICODE * picode,
|
||||
* expression exp given */
|
||||
static void forwardSubsLong (Int longIdx, COND_EXPR *exp, ICODE * picode,
|
||||
ICODE * ticode, Int *numHlIcodes)
|
||||
{ boolT res;
|
||||
{
|
||||
bool res;
|
||||
|
||||
if (exp == NULL) /* In case expression popped is NULL */
|
||||
return;
|
||||
@ -613,16 +613,17 @@ static boolT xClear (COND_EXPR *rhs, iICODE f, Int t, iICODE lastBBinst, Functio
|
||||
if (rhs == NULL)
|
||||
return false;
|
||||
|
||||
switch (rhs->type) {
|
||||
switch (rhs->type)
|
||||
{
|
||||
case IDENTIFIER:
|
||||
if (rhs->expr.ident.idType == REGISTER)
|
||||
{
|
||||
picode = &pproc->Icode.front();
|
||||
regi= pproc->localId.id_arr[rhs->expr.ident.idNode.regiIdx].id.regi;
|
||||
for (i = (f + 1); (i != lastBBinst) && (i->loc_ip < t); i++)
|
||||
if ((i->type == HIGH_LEVEL) && (i->invalid == FALSE))
|
||||
if ((i->type == HIGH_LEVEL) && ( not i->invalid ))
|
||||
{
|
||||
if (i->du.def & duReg[regi])
|
||||
if ((i->du.def & duReg[regi]).any())
|
||||
return false;
|
||||
}
|
||||
if (i != lastBBinst)
|
||||
@ -688,7 +689,7 @@ static void processCArg (Function * pp, Function * pProc, ICODE * picode, Int nu
|
||||
*k += hlTypeSize (exp, pProc);
|
||||
}
|
||||
|
||||
/* Eliminates extraneous intermediate icode instructions when finding
|
||||
/** Eliminates extraneous intermediate icode instructions when finding
|
||||
* expressions. Generates new hlIcodes in the form of expression trees.
|
||||
* For HLI_CALL hlIcodes, places the arguments in the argument list. */
|
||||
void Function::findExps()
|
||||
@ -701,7 +702,7 @@ void Function::findExps()
|
||||
boolT res;
|
||||
COND_EXPR *exp, /* expression pointer - for HLI_POP and HLI_CALL */
|
||||
*lhs; /* exp ptr for return value of a HLI_CALL */
|
||||
STKFRAME * args; /* pointer to arguments - for HLI_CALL */
|
||||
//STKFRAME * args; /* pointer to arguments - for HLI_CALL */
|
||||
byte regi, regi2; /* register(s) to be forward substituted */
|
||||
ID *retVal; /* function return value */
|
||||
|
||||
@ -712,7 +713,7 @@ void Function::findExps()
|
||||
for (i = 0; i < numBBs; i++)
|
||||
{
|
||||
/* Process one BB */
|
||||
pbb = dfsLast[i];
|
||||
pbb = m_dfsLast[i];
|
||||
if (pbb->flg & INVALID_BB)
|
||||
continue;
|
||||
lastInst = pbb->end2();
|
||||
@ -735,12 +736,13 @@ void Function::findExps()
|
||||
regi = picode->du1.regi[0];
|
||||
|
||||
/* Check if we can forward substitute this register */
|
||||
switch (picode->ic.hl.opcode) {
|
||||
switch (picode->ic.hl.opcode)
|
||||
{
|
||||
case HLI_ASSIGN:
|
||||
/* Replace rhs of current icode into target
|
||||
* icode expression */
|
||||
ticode = Icode.begin()+picode->du1.idx[0][0];
|
||||
if ((picode->du.lastDefRegi & duReg[regi]) &&
|
||||
if ((picode->du.lastDefRegi & duReg[regi]).any() &&
|
||||
((ticode->ic.hl.opcode != HLI_CALL) &&
|
||||
(ticode->ic.hl.opcode != HLI_RET)))
|
||||
continue;
|
||||
@ -753,7 +755,7 @@ void Function::findExps()
|
||||
forwardSubs (picode->ic.hl.oper.asgn.lhs,
|
||||
picode->ic.hl.oper.asgn.rhs,
|
||||
&(*picode), &(*ticode), &localId,
|
||||
&numHlIcodes);
|
||||
numHlIcodes);
|
||||
break;
|
||||
|
||||
case HLI_JCOND: case HLI_PUSH: case HLI_RET:
|
||||
@ -780,7 +782,7 @@ void Function::findExps()
|
||||
|
||||
case HLI_POP:
|
||||
ticode = Icode.begin()+(picode->du1.idx[0][0]);
|
||||
if ((picode->du.lastDefRegi & duReg[regi]) &&
|
||||
if ((picode->du.lastDefRegi & duReg[regi]).any() &&
|
||||
((ticode->ic.hl.opcode != HLI_CALL) &&
|
||||
(ticode->ic.hl.opcode != HLI_RET)))
|
||||
continue;
|
||||
@ -790,7 +792,7 @@ void Function::findExps()
|
||||
case HLI_ASSIGN:
|
||||
forwardSubs (picode->ic.hl.oper.exp, exp,
|
||||
&(*picode), &(*ticode), &localId,
|
||||
&numHlIcodes);
|
||||
numHlIcodes);
|
||||
break;
|
||||
|
||||
case HLI_JCOND: case HLI_PUSH: case HLI_RET:
|
||||
@ -884,7 +886,7 @@ void Function::findExps()
|
||||
if (picode->du1.idx[0][0] == picode->du1.idx[1][0])
|
||||
{
|
||||
ticode = Icode.begin()+(picode->du1.idx[0][0]);
|
||||
if ((picode->du.lastDefRegi & duReg[regi]) &&
|
||||
if ((picode->du.lastDefRegi & duReg[regi]).any() &&
|
||||
((ticode->ic.hl.opcode != HLI_CALL) &&
|
||||
(ticode->ic.hl.opcode != HLI_RET)))
|
||||
continue;
|
||||
@ -921,7 +923,7 @@ void Function::findExps()
|
||||
if (picode->du1.idx[0][0] == picode->du1.idx[1][0])
|
||||
{
|
||||
ticode = Icode.begin()+(picode->du1.idx[0][0]);
|
||||
if ((picode->du.lastDefRegi & duReg[regi]) &&
|
||||
if ((picode->du.lastDefRegi & duReg[regi]).any() &&
|
||||
((ticode->ic.hl.opcode != HLI_CALL) &&
|
||||
(ticode->ic.hl.opcode != HLI_RET)))
|
||||
continue;
|
||||
@ -1080,10 +1082,10 @@ void Function::findExps()
|
||||
}
|
||||
|
||||
|
||||
/* Invokes procedures related with data flow analysis. Works on a procedure
|
||||
/** Invokes procedures related with data flow analysis. Works on a procedure
|
||||
* at a time basis.
|
||||
* Note: indirect recursion in liveRegAnalysis is possible. */
|
||||
void Function::dataFlow(dword liveOut)
|
||||
void Function::dataFlow(std::bitset<32> &liveOut)
|
||||
{
|
||||
boolT isAx, isBx, isCx, isDx;
|
||||
Int idx;
|
||||
@ -1098,10 +1100,10 @@ void Function::dataFlow(dword liveOut)
|
||||
if (liveOut != 0)
|
||||
{
|
||||
flg |= PROC_IS_FUNC;
|
||||
isAx = (boolT)(liveOut & power2(rAX - rAX));
|
||||
isBx = (boolT)(liveOut & power2(rBX - rAX));
|
||||
isCx = (boolT)(liveOut & power2(rCX - rAX));
|
||||
isDx = (boolT)(liveOut & power2(rDX - rAX));
|
||||
isAx = liveOut.test(rAX - rAX);
|
||||
isBx = liveOut.test(rBX - rAX);
|
||||
isCx = liveOut.test(rCX - rAX);
|
||||
isDx = liveOut.test(rDX - rAX);
|
||||
|
||||
if (isAx && isDx) /* long or pointer */
|
||||
{
|
||||
|
||||
@ -157,7 +157,7 @@ struct POSSTACK_ENTRY
|
||||
vector<POSSTACK_ENTRY> posStack; /* position stack */
|
||||
byte iPS; /* Index into the stack */
|
||||
|
||||
static char cbuf[256]; /* Has to be 256 for wgetstr() to work */
|
||||
//static char cbuf[256]; /* Has to be 256 for wgetstr() to work */
|
||||
|
||||
// These are "curses equivalent" functions. (Used to use curses for all this,
|
||||
// but it was too much of a distribution hassle
|
||||
|
||||
@ -8,11 +8,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef __BORLAND__
|
||||
#include <alloc.h>
|
||||
#else
|
||||
#include <malloc.h> /* For malloc, free, realloc */
|
||||
#endif
|
||||
|
||||
typedef struct { /* PSP structure */
|
||||
word int20h; /* interrupt 20h */
|
||||
|
||||
@ -203,8 +203,8 @@ void Function::compressCFG()
|
||||
|
||||
/* First pass over BB list removes redundant jumps of the form
|
||||
* (Un)Conditional -> Unconditional jump */
|
||||
std::vector<BB*>::iterator iter=cfg.begin();
|
||||
for (;iter!=cfg.end(); ++iter)
|
||||
auto iter=m_cfg.begin();
|
||||
for (;iter!=m_cfg.end(); ++iter)
|
||||
{
|
||||
pBB = *iter;
|
||||
if(pBB->inEdges.empty() || (pBB->nodeType != ONE_BRANCH && pBB->nodeType != TWO_BRANCH))
|
||||
@ -225,18 +225,18 @@ void Function::compressCFG()
|
||||
/* Next is a depth-first traversal merging any FALL_NODE or
|
||||
* ONE_BRANCH that fall through to a node with that as their only
|
||||
* in-edge. */
|
||||
this->cfg.front()->mergeFallThrough(Icode);
|
||||
m_cfg.front()->mergeFallThrough(Icode);
|
||||
|
||||
/* Remove redundant BBs created by the above compressions
|
||||
* and allocate in-edge arrays as required. */
|
||||
stats.numBBaft = stats.numBBbef;
|
||||
|
||||
for(auto iter=cfg.begin(); iter!=cfg.end(); ++iter)
|
||||
for(auto iter=m_cfg.begin(); iter!=m_cfg.end(); ++iter)
|
||||
{
|
||||
pBB = *iter;
|
||||
if (pBB->inEdges.empty())
|
||||
{
|
||||
if (iter == cfg.begin()) /* Init it misses out on */
|
||||
if (iter == m_cfg.begin()) /* Init it misses out on */
|
||||
pBB->index = UN_INIT;
|
||||
else
|
||||
{
|
||||
@ -252,11 +252,11 @@ void Function::compressCFG()
|
||||
|
||||
/* Allocate storage for dfsLast[] array */
|
||||
numBBs = stats.numBBaft;
|
||||
dfsLast.resize(numBBs,0); // = (BB **)allocMem(numBBs * sizeof(BB *))
|
||||
m_dfsLast.resize(numBBs,0); // = (BB **)allocMem(numBBs * sizeof(BB *))
|
||||
|
||||
/* Now do a dfs numbering traversal and fill in the inEdges[] array */
|
||||
last = numBBs - 1;
|
||||
cfg.front()->dfsNumbering(dfsLast, &first, &last);
|
||||
m_cfg.front()->dfsNumbering(m_dfsLast, &first, &last);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -99,34 +99,34 @@ boolT ICODE::removeDefRegi (byte regi, Int thisDefIdx, LOCAL_ID *locId)
|
||||
|
||||
numDefs = du1.numRegsDef;
|
||||
if (numDefs == thisDefIdx)
|
||||
{
|
||||
for ( ; numDefs > 0; numDefs--)
|
||||
{
|
||||
if ((du1.idx[numDefs-1][0] != 0)||(du.lastDefRegi))
|
||||
if ((du1.idx[numDefs-1][0] != 0)||(du.lastDefRegi.any()))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (numDefs == 0)
|
||||
{
|
||||
invalidate();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
switch (ic.hl.opcode)
|
||||
{
|
||||
switch (ic.hl.opcode) {
|
||||
case HLI_ASSIGN:
|
||||
removeRegFromLong (regi, locId,ic.hl.oper.asgn.lhs);
|
||||
du1.numRegsDef--;
|
||||
du.def &= maskDuReg[regi];
|
||||
break;
|
||||
case HLI_POP:
|
||||
case HLI_PUSH:
|
||||
removeRegFromLong (regi, locId, ic.hl.oper.exp);
|
||||
du1.numRegsDef--;
|
||||
du.def &= maskDuReg[regi];
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
case HLI_ASSIGN:
|
||||
removeRegFromLong (regi, locId,ic.hl.oper.asgn.lhs);
|
||||
du1.numRegsDef--;
|
||||
du.def &= maskDuReg[regi];
|
||||
break;
|
||||
case HLI_POP:
|
||||
case HLI_PUSH:
|
||||
removeRegFromLong (regi, locId, ic.hl.oper.exp);
|
||||
du1.numRegsDef--;
|
||||
du.def &= maskDuReg[regi];
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -452,7 +452,7 @@ void ICODE::writeDU(Int idx)
|
||||
buf[0] = '\0';
|
||||
for (i = 0; i < (INDEXBASE-1); i++)
|
||||
{
|
||||
if ((du.def & power2(i)) != 0)
|
||||
if (du.def[i])
|
||||
{
|
||||
strcat (buf, allRegs[i]);
|
||||
strcat (buf, " ");
|
||||
@ -465,7 +465,7 @@ void ICODE::writeDU(Int idx)
|
||||
buf[0] = '\0';
|
||||
for (i = 0; i < INDEXBASE; i++)
|
||||
{
|
||||
if ((du.use & power2(i)) != 0)
|
||||
if (du.use[i])
|
||||
{
|
||||
strcat (buf, allRegs[i]);
|
||||
strcat (buf, " ");
|
||||
|
||||
@ -137,7 +137,7 @@ static Int idiom1(iICODE pIcode, iICODE pEnd, Function * pProc)
|
||||
&& pIcode->ic.ll.opcode == iMOV && pIcode->ic.ll.dst.regi == rBP
|
||||
&& pIcode->ic.ll.src.regi == rSP)
|
||||
{
|
||||
pProc->args.minOff = 2;
|
||||
pProc->args.m_minOff = 2;
|
||||
pProc->flg |= PROC_IS_HLL;
|
||||
|
||||
/* Look for SUB SP, immed */
|
||||
@ -167,7 +167,7 @@ static Int idiom1(iICODE pIcode, iICODE pEnd, Function * pProc)
|
||||
pIcode->ic.ll.dst.regi == rBP &&
|
||||
pIcode->ic.ll.src.regi == rSP)
|
||||
{
|
||||
pProc->args.minOff = 2 + (n * 2);
|
||||
pProc->args.m_minOff = 2 + (n * 2);
|
||||
return (2 + n);
|
||||
}
|
||||
else return 0; // Cristina: check this please!
|
||||
@ -191,7 +191,7 @@ static Int idiom1x(cITER pIcode, cITER pEnd, Function * pProc)
|
||||
&& pIcode->ic.ll.opcode == iMOV && pIcode->ic.ll.dst.regi == rBP
|
||||
&& pIcode->ic.ll.src.regi == rSP)
|
||||
{
|
||||
pProc->args.minOff = 2;
|
||||
pProc->args.m_minOff = 2;
|
||||
pProc->flg |= PROC_IS_HLL;
|
||||
|
||||
/* Look for SUB SP, immed */
|
||||
@ -222,7 +222,7 @@ static Int idiom1x(cITER pIcode, cITER pEnd, Function * pProc)
|
||||
pIcode->ic.ll.dst.regi == rBP &&
|
||||
pIcode->ic.ll.src.regi == rSP)
|
||||
{
|
||||
pProc->args.minOff = 2 + (n * 2);
|
||||
pProc->args.m_minOff = 2 + (n * 2);
|
||||
return (2 + n);
|
||||
}
|
||||
else return 0; // Cristina: check this please!
|
||||
@ -1390,8 +1390,8 @@ void Function::findIdioms()
|
||||
/* Check if number of parameter bytes match their calling convention */
|
||||
if ((flg & PROC_HLL) && (!args.sym.empty()))
|
||||
{
|
||||
args.minOff += (flg & PROC_FAR ? 4 : 2);
|
||||
delta = args.maxOff - args.minOff;
|
||||
args.m_minOff += (flg & PROC_FAR ? 4 : 2);
|
||||
delta = args.maxOff - args.m_minOff;
|
||||
if (cbParam != delta)
|
||||
{
|
||||
cbParam = delta;
|
||||
|
||||
@ -32,9 +32,7 @@ Int LOCAL_ID::newByteWordReg(hlType t, byte regi)
|
||||
|
||||
/* Check for entry in the table */
|
||||
auto found=std::find_if(id_arr.begin(),id_arr.end(),[t,regi](ID &el)->bool {
|
||||
if ((el.type == t) && (el.id.regi == regi))
|
||||
return true;
|
||||
return false;
|
||||
return ((el.type == t) && (el.id.regi == regi));
|
||||
});
|
||||
if(found!=id_arr.end())
|
||||
return found-id_arr.begin();
|
||||
@ -56,8 +54,8 @@ void LOCAL_ID::flagByteWordId (Int off)
|
||||
{
|
||||
Int idx;
|
||||
auto found=std::find_if(id_arr.begin(),id_arr.end(),[off](ID &en)->bool {
|
||||
|
||||
if (((en.type == TYPE_WORD_SIGN) || (en.type == TYPE_BYTE_SIGN)) &&
|
||||
//if (((en.type == TYPE_WORD_SIGN) || (en.type == TYPE_BYTE_SIGN)) &&
|
||||
if ((en.isSigned()) &&
|
||||
(en.id.bwId.off == off) && (en.id.bwId.regOff == 0))
|
||||
return true;
|
||||
return false;
|
||||
@ -309,7 +307,7 @@ Int LOCAL_ID::newLong(opLoc sd, ICODE *pIcode, hlFirst f, iICODE ix,operDu du, I
|
||||
* pProc : ptr to current procedure record
|
||||
* rhs, lhs : return expressions if successful. */
|
||||
boolT checkLongEq (LONG_STKID_TYPE longId, iICODE pIcode, Int i,
|
||||
Function * pProc, COND_EXPR **rhs, COND_EXPR **lhs, Int off)
|
||||
Function * pProc, Assignment &asgn, Int off)
|
||||
{
|
||||
LLOperand *pmHdst, *pmLdst, *pmHsrc, *pmLsrc; /* pointers to LOW_LEVEL icodes */
|
||||
|
||||
@ -320,20 +318,18 @@ boolT checkLongEq (LONG_STKID_TYPE longId, iICODE pIcode, Int i,
|
||||
|
||||
if ((longId.offH == pmHdst->off) && (longId.offL == pmLdst->off))
|
||||
{
|
||||
*lhs = COND_EXPR::idLongIdx (i);
|
||||
asgn.lhs = COND_EXPR::idLongIdx (i);
|
||||
|
||||
if ((pIcode->ic.ll.flg & NO_SRC) != 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, idx, eUSE, off);
|
||||
asgn.rhs = COND_EXPR::idLong (&pProc->localId, SRC, pIcode, HIGH_FIRST, pIcode, eUSE, off);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if ((longId.offH == pmHsrc->off) && (longId.offL == pmLsrc->off))
|
||||
{
|
||||
*lhs = COND_EXPR::idLong (&pProc->localId, DST, pIcode, HIGH_FIRST, pIcode,eDEF, off);
|
||||
//*lhs = COND_EXPR::idLong (&pProc->localId, DST, pIcode, HIGH_FIRST, idx,eDEF, off);
|
||||
*rhs = COND_EXPR::idLongIdx (i);
|
||||
asgn.lhs = COND_EXPR::idLong (&pProc->localId, DST, pIcode, HIGH_FIRST, pIcode,eDEF, off);
|
||||
asgn.rhs = COND_EXPR::idLongIdx (i);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -410,25 +406,25 @@ void LOCAL_ID::propLongId (byte regL, byte regH, const char *name)
|
||||
Int i;
|
||||
ID *_id;
|
||||
|
||||
for (i = 0; i < id_arr.size(); i++)
|
||||
for (i = 0; i < id_arr.size(); i++)
|
||||
{
|
||||
_id = &id_arr[i];
|
||||
if (_id->typeBitsize()==16)
|
||||
{
|
||||
_id = &id_arr[i];
|
||||
if ((_id->type == TYPE_WORD_SIGN) || (_id->type == TYPE_WORD_UNSIGN))
|
||||
{
|
||||
if (_id->id.regi == regL)
|
||||
{
|
||||
strcpy (_id->name, name);
|
||||
strcpy (_id->macro, "LO");
|
||||
_id->hasMacro = TRUE;
|
||||
_id->illegal = TRUE;
|
||||
}
|
||||
else if (_id->id.regi == regH)
|
||||
{
|
||||
strcpy (_id->name, name);
|
||||
strcpy (_id->macro, "HI");
|
||||
_id->hasMacro = TRUE;
|
||||
_id->illegal = TRUE;
|
||||
}
|
||||
}
|
||||
if (_id->id.regi == regL)
|
||||
{
|
||||
strcpy (_id->name, name);
|
||||
strcpy (_id->macro, "LO");
|
||||
_id->hasMacro = TRUE;
|
||||
_id->illegal = TRUE;
|
||||
}
|
||||
else if (_id->id.regi == regH)
|
||||
{
|
||||
strcpy (_id->name, name);
|
||||
strcpy (_id->macro, "HI");
|
||||
_id->hasMacro = TRUE;
|
||||
_id->illegal = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -891,7 +891,7 @@ static void setBits(int16 type, dword start, dword len)
|
||||
}
|
||||
|
||||
/* DU bit definitions for each reg value - including index registers */
|
||||
dword duReg[] = { 0x00,
|
||||
std::bitset<32> duReg[] = { 0x00,
|
||||
0x11001, 0x22002, 0x44004, 0x88008, /* word regs */
|
||||
0x10, 0x20, 0x40, 0x80,
|
||||
0x100, 0x200, 0x400, 0x800, /* seg regs */
|
||||
|
||||
@ -15,8 +15,7 @@
|
||||
static char indentBuf[indSize] =
|
||||
" ";
|
||||
|
||||
static char *indent (Int indLevel)
|
||||
/* Indentation according to the depth of the statement */
|
||||
static char *indent (Int indLevel) // Indentation according to the depth of the statement
|
||||
{
|
||||
return (&indentBuf[indSize-(indLevel*3)-1]);
|
||||
}
|
||||
@ -104,7 +103,7 @@ void Function::newRegArg(ICODE *picode, ICODE *ticode)
|
||||
boolT regExist;
|
||||
condId type;
|
||||
Function * tproc;
|
||||
byte regL, regH; /* Registers involved in arguments */
|
||||
uint8_t regL, regH; /* Registers involved in arguments */
|
||||
|
||||
/* Flag ticode as having register arguments */
|
||||
tproc = ticode->ic.hl.oper.call.proc;
|
||||
@ -335,7 +334,7 @@ void STKFRAME::adjustForArgType(Int numArg_, hlType actType_)
|
||||
Int off, i;
|
||||
|
||||
/* Find stack offset for this argument */
|
||||
off = minOff;
|
||||
off = m_minOff;
|
||||
for (i = 0; i < numArg_; i++)
|
||||
off += sym[i].size;
|
||||
|
||||
|
||||
145
src/proplong.cpp
145
src/proplong.cpp
@ -256,10 +256,11 @@ static int longJCond22 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode)
|
||||
* Arguments: i : index into the local identifier table
|
||||
* pLocId: ptr to the long local identifier
|
||||
* pProc : ptr to current procedure's record. */
|
||||
void Function::propLongStk (Int i, ID *pLocId)
|
||||
void Function::propLongStk (Int i, const ID &pLocId)
|
||||
{
|
||||
Int idx, off, arc;
|
||||
COND_EXPR *lhs, *rhs; /* Pointers to left and right hand expression */
|
||||
Assignment asgn;
|
||||
//COND_EXPR *lhs, *rhs; /* Pointers to left and right hand expression */
|
||||
iICODE pIcode, pEnd;
|
||||
|
||||
/* Check all icodes for offHi:offLo */
|
||||
@ -275,39 +276,33 @@ void Function::propLongStk (Int i, ID *pLocId)
|
||||
switch (pIcode->ic.ll.opcode)
|
||||
{
|
||||
case iMOV:
|
||||
if (checkLongEq (pLocId->id.longStkId, pIcode, i, this,
|
||||
&rhs, &lhs, 1) == TRUE)
|
||||
if (checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, 1) == TRUE)
|
||||
{
|
||||
pIcode->setAsgn(lhs, rhs);
|
||||
pIcode->setAsgn(asgn.lhs, asgn.rhs);
|
||||
(pIcode+1)->invalidate();
|
||||
idx++;
|
||||
}
|
||||
break;
|
||||
|
||||
case iAND: case iOR: case iXOR:
|
||||
if (checkLongEq (pLocId->id.longStkId, pIcode, i, this,
|
||||
&rhs, &lhs, 1) == TRUE)
|
||||
if (checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, 1) == TRUE)
|
||||
{
|
||||
switch (pIcode->ic.ll.opcode)
|
||||
{
|
||||
case iAND: rhs = COND_EXPR::boolOp (lhs, rhs, AND);
|
||||
break;
|
||||
case iOR: rhs = COND_EXPR::boolOp (lhs, rhs, OR);
|
||||
break;
|
||||
case iXOR: rhs = COND_EXPR::boolOp (lhs, rhs, XOR);
|
||||
break;
|
||||
case iAND: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, AND); break;
|
||||
case iOR: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, OR); break;
|
||||
case iXOR: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, XOR); break;
|
||||
}
|
||||
pIcode->setAsgn(lhs, rhs);
|
||||
pIcode->setAsgn(asgn.lhs, asgn.rhs);
|
||||
(pIcode+1)->invalidate();
|
||||
idx++;
|
||||
}
|
||||
break;
|
||||
|
||||
case iPUSH:
|
||||
if (checkLongEq (pLocId->id.longStkId, pIcode, i, this,
|
||||
&rhs, &lhs, 1) == TRUE)
|
||||
if (checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, 1) == TRUE)
|
||||
{
|
||||
pIcode->setUnary( HLI_PUSH, lhs);
|
||||
pIcode->setUnary( HLI_PUSH, asgn.lhs);
|
||||
(pIcode+1)->invalidate();
|
||||
idx++;
|
||||
}
|
||||
@ -318,9 +313,9 @@ void Function::propLongStk (Int i, ID *pLocId)
|
||||
/* Check long conditional (i.e. 2 CMPs and 3 branches */
|
||||
else if ((pIcode->ic.ll.opcode == iCMP) && (isLong23 (idx, pIcode->inBB, &off, &arc)))
|
||||
{
|
||||
if ( checkLongEq (pLocId->id.longStkId, pIcode, i, this, &rhs, &lhs, off) )
|
||||
if ( checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, off) )
|
||||
{
|
||||
idx += longJCond23 (rhs, lhs, pIcode, arc, off); //
|
||||
idx += longJCond23 (asgn.rhs, asgn.lhs, pIcode, arc, off); //
|
||||
}
|
||||
}
|
||||
|
||||
@ -328,53 +323,59 @@ void Function::propLongStk (Int i, ID *pLocId)
|
||||
* 2 CMPs and 2 branches */
|
||||
else if ((pIcode->ic.ll.opcode == iCMP) && isLong22 (pIcode, pEnd, &off))
|
||||
{
|
||||
if ( checkLongEq (pLocId->id.longStkId, pIcode, i, this,&rhs, &lhs, off) )
|
||||
if ( checkLongEq (pLocId.id.longStkId, pIcode, i, this,asgn, off) )
|
||||
{
|
||||
idx += longJCond22 (rhs, lhs, pIcode); // maybe this should have -1 to offset loop autoincrement?
|
||||
idx += longJCond22 (asgn.rhs, asgn.lhs, pIcode); // maybe this should have -1 to offset loop autoincrement?
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int Function::checkBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE beg,Assignment &asgn)
|
||||
int Function::findBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE beg)
|
||||
{
|
||||
Assignment asgn;
|
||||
LLOperand * pmH,* pmL;
|
||||
iICODE pIcode;
|
||||
riICODE rev(beg);
|
||||
bool forced_finish=false;
|
||||
for (; not forced_finish and rev!=Icode.rend();rev++) //idx = pLocId_idx - 1; idx > 0 ; idx--
|
||||
{
|
||||
ICODE &icode(*rev);
|
||||
ICODE &next1(*(rev-1)); // prev reverse is actually next instruction
|
||||
pIcode = (rev+1).base();//Icode.begin()+(idx-1);
|
||||
if ((pIcode->type == HIGH_LEVEL) || (pIcode->invalid == TRUE))
|
||||
|
||||
|
||||
if ((icode.type == HIGH_LEVEL) || (icode.invalid == TRUE))
|
||||
continue;
|
||||
if (icode.ic.ll.opcode != next1.ic.ll.opcode)
|
||||
continue;
|
||||
|
||||
if (pIcode->ic.ll.opcode != (pIcode+1)->ic.ll.opcode)
|
||||
continue;
|
||||
switch (pIcode->ic.ll.opcode)
|
||||
switch (icode.ic.ll.opcode)
|
||||
{
|
||||
case iMOV:
|
||||
pmH = &pIcode->ic.ll.dst;
|
||||
pmL = &(pIcode+1)->ic.ll.dst;
|
||||
pmH = &icode.ic.ll.dst;
|
||||
pmL = &next1.ic.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);
|
||||
this->localId.id_arr[loc_ident_idx].idx.push_back(pIcode);//idx-1//insert
|
||||
pIcode->setRegDU( pmL->regi, eDEF);
|
||||
asgn.rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode, HIGH_FIRST, pIcode/*idx*/, eUSE, 1);
|
||||
pIcode->setAsgn(asgn.lhs, asgn.rhs);
|
||||
(pIcode+1)->invalidate();
|
||||
asgn.rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode, HIGH_FIRST, pIcode, eUSE, 1);
|
||||
icode.setAsgn(asgn.lhs, asgn.rhs);
|
||||
next1.invalidate();
|
||||
forced_finish=true; /* to exit the loop */
|
||||
}
|
||||
break;
|
||||
|
||||
case iPOP:
|
||||
pmH = &(pIcode+1)->ic.ll.dst;
|
||||
pmL = &pIcode->ic.ll.dst;
|
||||
pmH = &next1.ic.ll.dst;
|
||||
pmL = &icode.ic.ll.dst;
|
||||
if ((pLocId.id.longId.h == pmH->regi) && (pLocId.id.longId.l == pmL->regi))
|
||||
{
|
||||
asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
|
||||
pIcode->setRegDU( pmH->regi, eDEF);
|
||||
pIcode->setUnary(HLI_POP, asgn.lhs);
|
||||
(pIcode+1)->invalidate();
|
||||
icode.setRegDU( pmH->regi, eDEF);
|
||||
icode.setUnary(HLI_POP, asgn.lhs);
|
||||
next1.invalidate();
|
||||
asgn.lhs=0;
|
||||
forced_finish=true; /* to exit the loop */
|
||||
}
|
||||
break;
|
||||
@ -382,14 +383,15 @@ int Function::checkBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE b
|
||||
// /**** others missing ***/
|
||||
|
||||
case iAND: case iOR: case iXOR:
|
||||
pmL = &pIcode->ic.ll.dst;
|
||||
pmH = &(pIcode+1)->ic.ll.dst;
|
||||
pmL = &icode.ic.ll.dst;
|
||||
pmH = &next1.ic.ll.dst;
|
||||
if ((pLocId.id.longId.h == pmH->regi) && (pLocId.id.longId.l == pmL->regi))
|
||||
{
|
||||
asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
|
||||
pIcode->setRegDU( pmH->regi, USE_DEF);
|
||||
asgn.rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode, LOW_FIRST, pIcode/*idx*/, eUSE, 1);
|
||||
switch (pIcode->ic.ll.opcode) {
|
||||
icode.setRegDU( pmH->regi, USE_DEF);
|
||||
switch (icode.ic.ll.opcode)
|
||||
{
|
||||
case iAND: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, AND);
|
||||
break;
|
||||
case iOR:
|
||||
@ -398,8 +400,8 @@ int Function::checkBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE b
|
||||
case iXOR: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, XOR);
|
||||
break;
|
||||
} /* eos */
|
||||
pIcode->setAsgn(asgn.lhs, asgn.rhs);
|
||||
(pIcode+1)->invalidate();
|
||||
icode.setAsgn(asgn.lhs, asgn.rhs);
|
||||
next1.invalidate();
|
||||
forced_finish=true; /* to exit the loop */
|
||||
}
|
||||
break;
|
||||
@ -407,10 +409,11 @@ int Function::checkBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE b
|
||||
}
|
||||
return rev!=Icode.rend();
|
||||
}
|
||||
int Function::checkForwardLongDefs(int loc_ident_idx, const ID &pLocId, iICODE beg,Assignment &asgn)
|
||||
int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE beg)
|
||||
{
|
||||
bool forced_finish=false;
|
||||
auto pEnd=Icode.end();
|
||||
Assignment asgn;
|
||||
for (auto pIcode=beg; not forced_finish and ((pIcode+1)!=Icode.end()); ++pIcode)
|
||||
{
|
||||
iICODE next1(pIcode+1);
|
||||
@ -427,9 +430,11 @@ int Function::checkForwardLongDefs(int loc_ident_idx, const ID &pLocId, iICODE b
|
||||
if ((pLocId.id.longId.h == pIcode->ic.ll.src.regi) &&
|
||||
(pLocId.id.longId.l == next1->ic.ll.src.regi))
|
||||
{
|
||||
asgn.rhs = COND_EXPR::idLongIdx (loc_ident_idx);
|
||||
pIcode->setRegDU( next1->ic.ll.src.regi, eUSE);
|
||||
|
||||
asgn.rhs = COND_EXPR::idLongIdx (loc_ident_idx);
|
||||
asgn.lhs = COND_EXPR::idLong (&this->localId, DST, pIcode,HIGH_FIRST, pIcode, eDEF, 1);
|
||||
|
||||
pIcode->setAsgn(asgn.lhs, asgn.rhs);
|
||||
next1->invalidate();
|
||||
forced_finish =true; /* to exit the loop */
|
||||
@ -442,7 +447,7 @@ int Function::checkForwardLongDefs(int loc_ident_idx, const ID &pLocId, iICODE b
|
||||
{
|
||||
asgn.rhs = COND_EXPR::idLongIdx (loc_ident_idx);
|
||||
pIcode->setRegDU( next1->ic.ll.src.regi, eUSE);
|
||||
pIcode->setUnary(HLI_PUSH, asgn.lhs);
|
||||
pIcode->setUnary(HLI_PUSH, asgn.rhs);
|
||||
next1->invalidate();
|
||||
}
|
||||
forced_finish =true; /* to exit the loop */
|
||||
@ -481,8 +486,7 @@ int Function::checkForwardLongDefs(int loc_ident_idx, const ID &pLocId, iICODE b
|
||||
/* Check long conditional (i.e. 2 CMPs and 3 branches */
|
||||
else if ((pIcode->ic.ll.opcode == iCMP) && (isLong23 (pIcode, pIcode->inBB, &off, &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, off) == TRUE)
|
||||
{
|
||||
pIcode += longJCond23 (asgn.rhs, asgn.lhs, pIcode, arc, off);
|
||||
}
|
||||
@ -523,40 +527,37 @@ int Function::checkForwardLongDefs(int loc_ident_idx, const ID &pLocId, iICODE b
|
||||
} /* end for */
|
||||
}
|
||||
|
||||
/* Finds the definition of the long register pointed to by pLocId, and
|
||||
/** Finds the definition of the long register pointed to by pLocId, and
|
||||
* transforms that instruction into a HIGH_LEVEL icode instruction.
|
||||
* Arguments: i : index into the local identifier table
|
||||
* pLocId: ptr to the long local identifier
|
||||
* pProc : ptr to current procedure's record. */
|
||||
void Function::propLongReg (Int loc_ident_idx, const ID *pLocId)
|
||||
* @arg i index into the local identifier table
|
||||
* @arg pLocId ptr to the long local identifier
|
||||
*
|
||||
*/
|
||||
void Function::propLongReg (Int loc_ident_idx, const ID &pLocId)
|
||||
{
|
||||
Int idx;
|
||||
iICODE pEnd;
|
||||
|
||||
/* Process all definitions/uses of long registers at an icode position */
|
||||
pEnd = this->Icode.end();
|
||||
const IDX_ARRAY &lidx(pLocId->idx);
|
||||
// for (int pLocId_idx : pLocId->idx)
|
||||
// WARNING: this loop modifies the iterated-over container.
|
||||
for (int j = 0; j < pLocId->idx.size(); j++)
|
||||
size_t initial_size=pLocId.idx.size();
|
||||
for (int j = 0; j < pLocId.idx.size(); j++)
|
||||
{
|
||||
auto idx_iter=lidx.begin();
|
||||
auto idx_iter=pLocId.idx.begin();
|
||||
std::advance(idx_iter,j);
|
||||
//assert(*idx_iter==lidx.z[j]);
|
||||
int pLocId_idx=std::distance(Icode.begin(),*idx_iter);
|
||||
Assignment asgn;
|
||||
/* Check backwards for a definition of this long register */
|
||||
if (checkBackwarLongDefs(loc_ident_idx,*pLocId,*idx_iter,asgn))
|
||||
if (findBackwarLongDefs(loc_ident_idx,pLocId,*idx_iter))
|
||||
{
|
||||
//assert(initial_size==pLocId.idx.size());
|
||||
continue;
|
||||
}
|
||||
/* If no definition backwards, check forward for a use of this long reg */
|
||||
checkForwardLongDefs(loc_ident_idx,*pLocId,*idx_iter,asgn);
|
||||
findForwardLongUses(loc_ident_idx,pLocId,*idx_iter);
|
||||
//assert(initial_size==pLocId.idx.size());
|
||||
} /* end for */
|
||||
}
|
||||
|
||||
|
||||
/* Propagates the long global address across all LOW_LEVEL icodes.
|
||||
* Transforms some LOW_LEVEL icodes into HIGH_LEVEL */
|
||||
void Function::propLongGlb (Int i, ID *pLocId)
|
||||
void Function::propLongGlb (Int i, const ID &pLocId)
|
||||
{
|
||||
printf("WARN: Function::propLongGlb not implemented");
|
||||
}
|
||||
@ -567,14 +568,14 @@ void Function::propLongGlb (Int i, ID *pLocId)
|
||||
void Function::propLong()
|
||||
{
|
||||
Int i;
|
||||
ID *pLocId; /* Pointer to current local identifier */
|
||||
/* Pointer to current local identifier */
|
||||
|
||||
for (i = 0; i < localId.csym(); i++)
|
||||
{
|
||||
pLocId = &localId.id_arr[i];
|
||||
if ((pLocId->type==TYPE_LONG_SIGN) || (pLocId->type==TYPE_LONG_UNSIGN))
|
||||
const ID &pLocId(localId.id_arr[i]);
|
||||
if ((pLocId.type==TYPE_LONG_SIGN) || (pLocId.type==TYPE_LONG_UNSIGN))
|
||||
{
|
||||
switch (pLocId->loc)
|
||||
switch (pLocId.loc)
|
||||
{
|
||||
case STK_FRAME:
|
||||
propLongStk (i, pLocId);
|
||||
|
||||
@ -7,11 +7,7 @@
|
||||
#include <cassert>
|
||||
#include "dcc.h"
|
||||
#include <stdio.h>
|
||||
#ifdef __BORLAND__
|
||||
#include <alloc.h>
|
||||
#else
|
||||
#include <malloc.h> /* For free() */
|
||||
#endif
|
||||
#include <string.h>
|
||||
|
||||
static Int numInt; /* Number of intervals */
|
||||
@ -31,7 +27,7 @@ bool trivialGraph(BB *G)
|
||||
static BB *firstOfQueue (queue &Q)
|
||||
{
|
||||
assert(!Q.empty());
|
||||
BB *res=*Q.begin();
|
||||
BB *res=Q.front();
|
||||
Q.pop_front();
|
||||
return res;
|
||||
}
|
||||
@ -58,7 +54,7 @@ BB *interval::firstOfInt ()
|
||||
{
|
||||
auto pq = currNode;
|
||||
if (pq == nodes.end())
|
||||
return (NULL);
|
||||
return 0;
|
||||
++currNode;
|
||||
return *pq;
|
||||
}
|
||||
@ -169,7 +165,7 @@ void derSeq_Entry::findIntervals (Function *c)
|
||||
J = pI;
|
||||
}
|
||||
else /* first interval */
|
||||
first = FALSE;
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -187,7 +183,7 @@ static void displayIntervals (interval *pI)
|
||||
{
|
||||
if ((*nodePtr)->correspInt == NULL) /* real BBs */
|
||||
printf (" Node: %ld\n", (*nodePtr)->begin());
|
||||
else /* BBs represent intervals */
|
||||
else // BBs represent intervals
|
||||
printf (" Node (corresp int): %d\n", (*nodePtr)->correspInt->numInt);
|
||||
++nodePtr;
|
||||
}
|
||||
@ -234,8 +230,8 @@ void freeDerivedSeq(derSeq &derivedG)
|
||||
derSeq_Entry::~derSeq_Entry()
|
||||
{
|
||||
freeInterval (&Ii);
|
||||
// if(Gi && Gi->nodeType == INTERVAL_NODE)
|
||||
// freeCFG (Gi);
|
||||
// if(Gi && Gi->nodeType == INTERVAL_NODE)
|
||||
// freeCFG (Gi);
|
||||
}
|
||||
|
||||
/* Finds the next order graph of derivedGi->Gi according to its intervals
|
||||
@ -244,8 +240,8 @@ bool Function::nextOrderGraph (derSeq *derivedGi)
|
||||
{
|
||||
interval *Ii; /* Interval being processed */
|
||||
BB *BBnode, /* New basic block of intervals */
|
||||
*curr, /* BB being checked for out edges */
|
||||
*succ /* Successor node */
|
||||
*curr, /* BB being checked for out edges */
|
||||
*succ /* Successor node */
|
||||
;
|
||||
//queue *listIi; /* List of intervals */
|
||||
Int i, /* Index to outEdges array */
|
||||
@ -302,14 +298,14 @@ bool Function::nextOrderGraph (derSeq *derivedGi)
|
||||
BBnode = new_entry.Gi; /* BB of an interval */
|
||||
auto iter= std::find_if(bbs.begin(),bbs.end(),
|
||||
[&edge](BB *node)->bool { return edge.intPtr==node->correspInt;});
|
||||
if(iter==bbs.end())
|
||||
fatalError (INVALID_INT_BB);
|
||||
edge.BBptr = *iter;
|
||||
(*iter)->inEdges.push_back(0);
|
||||
(*iter)->inEdgeCount++;
|
||||
}
|
||||
if(iter==bbs.end())
|
||||
fatalError (INVALID_INT_BB);
|
||||
edge.BBptr = *iter;
|
||||
(*iter)->inEdges.push_back(0);
|
||||
(*iter)->inEdgeCount++;
|
||||
}
|
||||
return (boolT)(! sameGraph);
|
||||
}
|
||||
return (boolT)(! sameGraph);
|
||||
}
|
||||
|
||||
|
||||
@ -352,7 +348,7 @@ byte Function::findDerivedSeq (derSeq *derivedGi)
|
||||
* means of node splitting. */
|
||||
static void nodeSplitting (std::vector<BB *> &G)
|
||||
{
|
||||
printf("Attempt to perform node splitting: NOT IMPLEMENTED\n");
|
||||
fprintf(stderr,"Attempt to perform node splitting: NOT IMPLEMENTED\n");
|
||||
}
|
||||
|
||||
/* Displays the derived sequence and intervals of the graph G */
|
||||
@ -378,19 +374,19 @@ void derSeq::display()
|
||||
derSeq * Function::checkReducibility()
|
||||
{
|
||||
derSeq * der_seq;
|
||||
byte reducible; /* Reducible graph flag */
|
||||
byte reducible; /* Reducible graph flag */
|
||||
|
||||
numInt = 1; /* reinitialize no. of intervals*/
|
||||
stats.nOrder = 1; /* nOrder(cfg) = 1 */
|
||||
stats.nOrder = 1; /* nOrder(cfg) = 1 */
|
||||
der_seq = new derSeq;
|
||||
der_seq->resize(1);
|
||||
der_seq->back().Gi = cfg.front();
|
||||
der_seq->back().Gi = m_cfg.front();
|
||||
reducible = findDerivedSeq(der_seq);
|
||||
|
||||
if (! reducible)
|
||||
{
|
||||
flg |= GRAPH_IRRED;
|
||||
nodeSplitting (cfg);
|
||||
nodeSplitting (m_cfg);
|
||||
}
|
||||
return der_seq;
|
||||
}
|
||||
|
||||
11
src/udm.cpp
11
src/udm.cpp
@ -56,7 +56,7 @@ void Function::controlFlowAnalysis()
|
||||
if (option.verbose)
|
||||
{
|
||||
printf("\nDepth first traversal - Proc %s\n", name.c_str());
|
||||
cfg.front()->displayDfs();
|
||||
m_cfg.front()->displayDfs();
|
||||
}
|
||||
|
||||
/* Free storage occupied by this procedure */
|
||||
@ -74,9 +74,10 @@ void udm(void)
|
||||
}
|
||||
|
||||
/* Data flow analysis - eliminate condition codes, extraneous registers
|
||||
* and intermediate instructions. Find expressions by forward
|
||||
* substitution algorithm */
|
||||
pProcList.front().dataFlow (0);
|
||||
* and intermediate instructions. Find expressions by forward
|
||||
* substitution algorithm */
|
||||
std::bitset<32> live_regs;
|
||||
pProcList.front().dataFlow (live_regs);
|
||||
|
||||
/* Control flow analysis - structuring algorithm */
|
||||
for (auto iter = pProcList.rbegin(); iter!=pProcList.rend(); ++iter)
|
||||
@ -91,7 +92,7 @@ void udm(void)
|
||||
void Function::displayCFG()
|
||||
{
|
||||
printf("\nBasic Block List - Proc %s", name.c_str());
|
||||
for (BB *pBB : cfg)
|
||||
for (BB *pBB : m_cfg)
|
||||
{
|
||||
pBB->display();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user