Basic block is purer range now, it does not hold start and length members, it can be used in range based fors now

This commit is contained in:
Artur K 2012-03-08 00:20:13 +01:00
parent fc0d35cf06
commit 69d848ca78
17 changed files with 403 additions and 400 deletions

View File

@ -27,7 +27,7 @@ struct BB : public llvm::ilist_node<BB>
{
private:
BB(const BB&);
BB() : start(0),length(0),nodeType(0),traversed(0),
BB() : nodeType(0),traversed(0),
numHlIcodes(0),flg(0),
inEdges(0),
edges(0),beenOnH(0),inEdgeCount(0),reachingInt(0),
@ -38,19 +38,13 @@ private:
}
//friend class SymbolTableListTraits<BB, Function>;
//int numInEdges; /* Number of in edges */
int start; /* First instruction offset */
int length; /* No. of instructions this BB */
iICODE range_start;
iICODE range_end;
public:
int begin();
iICODE begin2();
iICODE end2();
int end();
int rbegin();
int rend();
riICODE rbegin2();
riICODE rend2();
iICODE begin();
iICODE end();
riICODE rbegin();
riICODE rend();
ICODE &front();
ICODE &back();
size_t size();

View File

@ -87,10 +87,10 @@ public:
static bool insertSubTreeLongReg(COND_EXPR *exp, COND_EXPR **tree, int longIdx);
static bool insertSubTreeReg(COND_EXPR *&tree, COND_EXPR *_expr, eReg regi, LOCAL_ID *locsym);
public:
virtual COND_EXPR *clone();
virtual COND_EXPR *clone() const;
void release();
void changeBoolOp(condOp newOp);
COND_EXPR(COND_EXPR &other)
COND_EXPR(const COND_EXPR &other)
{
type=other.type;
expr=other.expr;
@ -104,7 +104,7 @@ public:
}
virtual ~COND_EXPR() {}
public:
virtual COND_EXPR *inverse(); // return new COND_EXPR that is invarse of this
virtual COND_EXPR *inverse() const; // return new COND_EXPR that is invarse of this
virtual bool xClear(iICODE f, iICODE t, iICODE lastBBinst, Function *pproc);
virtual COND_EXPR *insertSubTreeReg(COND_EXPR *_expr, eReg regi, LOCAL_ID *locsym);
virtual COND_EXPR *insertSubTreeLongReg(COND_EXPR *_expr, int longIdx);

View File

@ -167,7 +167,7 @@ hlType expType (const COND_EXPR *, Function *);
/* Exported functions from hlicode.c */
std::string writeCall (Function *, STKFRAME *, Function *, int *);
char *writeJcond (HLTYPE, Function *, int *);
char *writeJcond (const HLTYPE &, Function *, int *);
char *writeJcondInv (HLTYPE, Function *, int *);
int power2 (int);

View File

@ -78,6 +78,8 @@ struct AssignType : public HlTypeSupport
return true;
}
std::string writeOut(Function *pProc, int *numLoc);
AssignType() : lhs(0),rhs(0)
{}
};
struct ExpType : public HlTypeSupport
{
@ -120,6 +122,7 @@ public:
exp.v=e;
}
COND_EXPR * expr() { return exp.v;}
const COND_EXPR * const expr() const { return exp.v;}
void set(hlIcode i,COND_EXPR *e)
{
if(i!=HLI_RET)
@ -337,7 +340,7 @@ public:
void setRegDU(eReg regi, operDu du_in);
void invalidate();
void newCallHl();
void writeDU(int idx);
void writeDU();
condId idType(opLoc sd);
// HLL setting functions
// set this icode to be an assign

View File

@ -20,12 +20,23 @@ BB *BB::Create(int start, int ip, uint8_t nodeType, int numOutEdges, Function *p
pnewBB = new BB;
pnewBB->nodeType = nodeType; /* Initialise */
pnewBB->start = start;
pnewBB->length = ip - start + 1;
pnewBB->immedDom = NO_DOM;
pnewBB->loopHead = pnewBB->caseHead = pnewBB->caseTail =
pnewBB->latchNode= pnewBB->loopFollow = NO_NODE;
pnewBB->range_start = parent->Icode.begin();
pnewBB->range_end = parent->Icode.begin();
if(start!=-1)
{
advance(pnewBB->range_start,start);
advance(pnewBB->range_end,ip+1);
}
else
{
pnewBB->range_end = parent->Icode.end();
pnewBB->range_end = parent->Icode.end();
}
// pnewBB->range_start = parent->Icode.begin();
if (numOutEdges)
pnewBB->edges.resize(numOutEdges);
@ -55,10 +66,10 @@ static const char *const s_loopType[] = {"noLoop", "while", "repeat", "loop", "f
void BB::display()
{
printf("\nnode type = %s, ", s_nodeType[nodeType]);
printf("start = %ld, length = %ld, #out edges = %ld\n", start, length, edges.size());
printf("start = %ld, length = %ld, #out edges = %ld\n", begin()->loc_ip, size(), edges.size());
for (int i = 0; i < edges.size(); i++)
printf(" outEdge[%2d] = %ld\n",i, edges[i].BBptr->start);
printf(" outEdge[%2d] = %ld\n",i, edges[i].BBptr->begin()->loc_ip);
}
/*****************************************************************************
* displayDfs - Displays the CFG using a depth first traversal
@ -71,7 +82,7 @@ void BB::displayDfs()
printf("node type = %s, ", s_nodeType[nodeType]);
printf("start = %ld, length = %ld, #in-edges = %ld, #out-edges = %ld\n",
start, length, inEdges.size(), edges.size());
begin()->loc_ip, size(), inEdges.size(), edges.size());
printf("dfsFirst = %ld, dfsLast = %ld, immed dom = %ld\n",
dfsFirstNum, dfsLastNum,
immedDom == MAX ? -1 : immedDom);
@ -88,16 +99,33 @@ void BB::displayDfs()
if (nodeType == INTERVAL_NODE)
printf("corresponding interval = %ld\n", correspInt->numInt);
else
for (i = 0; i < inEdges.size(); i++)
printf (" inEdge[%ld] = %ld\n", i, inEdges[i]->begin());
{
#ifdef _lint
for(auto iter=inEdges.begin(); iter!=inEdges.end(); ++iter)
{
BB *node(*iter);
#else
for(BB *node : inEdges)
{
#endif
printf (" inEdge[%ld] = %ld\n", i, node->begin()->loc_ip);
}
}
/* Display out edges information */
for (i = 0; i < edges.size(); i++)
#ifdef _lint
for(auto iter=edges.begin(); iter!=edges.end(); ++iter)
{
TYPEADR_TYPE &edg(*iter);
#else
for(TYPEADR_TYPE &edg : edges)
{
#endif
if (nodeType == INTERVAL_NODE)
printf(" outEdge[%ld] = %ld\n", i,
edges[i].BBptr->correspInt->numInt);
printf(" outEdge[%ld] = %ld\n", i, edg.BBptr->correspInt->numInt);
else
printf(" outEdge[%d] = %ld\n", i, edges[i].BBptr->begin());
printf(" outEdge[%d] = %ld\n", i, edg.BBptr->begin()->loc_ip);
}
printf("----\n");
/* Recursive call on successors of current node */
@ -344,71 +372,62 @@ void BB::writeBB(int lev, Function * pProc, int *numLoc)
//for (i = start, last = i + length; i < last; i++)
/* Generate code for each hlicode that is not a HLI_JCOND */
int idx=start;
for(iICODE hli=begin2(); hli!=end2(); ++hli)
//for();
#ifdef _lint
for(iICODE hli=begin(); hli!=end(); ++hli)
{
if ((hli->type == HIGH_LEVEL) && (hli->invalid == FALSE))
ICODE &pHli(*hli);
#else
for(ICODE &pHli : *this)
{
std::string line = hli->hl()->write1HlIcode(pProc, numLoc);
#endif
if ((pHli.type == HIGH_LEVEL) && ( pHli.valid() )) //TODO: use filtering range here.
{
std::string line = pHli.hl()->write1HlIcode(pProc, numLoc);
if (!line.empty())
{
cCode.appendCode( "%s%s", indent(lev), line.c_str());
stats.numHLIcode++;
}
if (option.verbose)
hli->writeDU(idx);
pHli.writeDU();
}
idx++;
}
}
int BB::begin()
//int BB::beginIdx()
//{
// return start;
//}
iICODE BB::begin()
{
return start;
return range_start;
}
iICODE BB::begin2()
iICODE BB::end()
{
iICODE result(Parent->Icode.begin());
advance(result,start);
return result;
}
iICODE BB::end2()
{
iICODE result(Parent->Icode.begin());
advance(result,start+length);
return result;
}
int BB::rbegin()
{
return start+length-1;
}
int BB::end()
{
return start+length;
return range_end;
}
ICODE &BB::back()
{
return *rbegin2();
return *rbegin();
}
size_t BB::size()
{
return length;
return distance(range_start,range_end);
}
ICODE &BB::front()
{
return *begin2();
return *begin();
}
riICODE BB::rbegin2()
riICODE BB::rbegin()
{
riICODE res(end2());
assert(res->loc_ip==rbegin());
return res;
return riICODE(end());
}
riICODE BB::rend2()
riICODE BB::rend()
{
return riICODE(begin2());
return riICODE(begin());
}

View File

@ -797,7 +797,7 @@ string walkCondExpr (const COND_EXPR* expr, Function * pProc, int* numLoc)
/* Makes a copy of the given expression. Allocates newExp storage for each
* node. Returns the copy. */
//lint -sem(COND_EXPR::clone, @p!=0)
COND_EXPR *COND_EXPR::clone()
COND_EXPR *COND_EXPR::clone() const
{
COND_EXPR* newExp=0; /* Expression node copy */

View File

@ -309,7 +309,7 @@ void Function::codeGen (std::ostream &fs)
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());
printf (" Start = %d, end = %d\n", pBB->begin()->loc_ip, pBB->begin()->loc_ip+pBB->size());
printf (" LiveUse = ");
writeBitVector (pBB->liveUse);
printf ("\n Def = ");

View File

@ -48,7 +48,7 @@ int numKeys; /* Number of hash table entries (keys) */
int numVert; /* Number of vertices in the graph (also size of g[]) */
unsigned PatLen; /* Size of the keys (pattern length) */
unsigned SymLen; /* Max size of the symbols, including null */
FILE *f; /* File being read */
static FILE *g_file; /* File being read */
static char sSigName[100]; /* Full path name of .sig file */
static uint16_t *T1base, *T2base; /* Pointers to start of T1, T2 */
@ -61,9 +61,9 @@ static int numArg; /* Number of param names actually stored
#define DCCLIBS "dcclibs.dat" /* Name of the prototypes data file */
/* prototypes */
void grab(int n, FILE *f);
uint16_t readFileShort(FILE *f);
void readFileSection(uint16_t* p, int len, FILE *f);
void grab(int n, FILE *_file);
uint16_t readFileShort(FILE *g_file);
void readFileSection(uint16_t* p, int len, FILE *g_file);
void cleanup(void);
void checkStartup(STATE *state);
void readProtoFile(void);
@ -300,7 +300,7 @@ void SetupLibCheck(void)
uint16_t w, len;
int i;
if ((f = fopen(sSigName, "rb")) == NULL)
if ((g_file = fopen(sSigName, "rb")) == NULL)
{
printf("Warning: cannot open signature file %s\n", sSigName);
return;
@ -311,16 +311,16 @@ void SetupLibCheck(void)
prog.bSigs = FALSE; /* False unless everything goes right */
/* Read the parameters */
grab(4, f);
grab(4, g_file);
if (memcmp("dccs", buf, 4) != 0)
{
printf("Not a dcc signature file!\n");
exit(3);
}
numKeys = readFileShort(f);
numVert = readFileShort(f);
PatLen = readFileShort(f);
SymLen = readFileShort(f);
numKeys = readFileShort(g_file);
numVert = readFileShort(g_file);
PatLen = readFileShort(g_file);
SymLen = readFileShort(g_file);
if ((PatLen != PATLEN) || (SymLen != SYMLEN))
{
printf("Sorry! Compiled for sym and pattern lengths of %d and %d\n",
@ -342,50 +342,50 @@ void SetupLibCheck(void)
g = g_pattern_hasher.readG();
/* Read T1 and T2 tables */
grab(2, f);
grab(2, g_file);
if (memcmp("T1", buf, 2) != 0)
{
printf("Expected 'T1'\n");
exit(3);
}
len = (uint16_t) (PatLen * 256 * sizeof(uint16_t));
w = readFileShort(f);
w = readFileShort(g_file);
if (w != len)
{
printf("Problem with size of T1: file %d, calc %d\n", w, len);
exit(4);
}
readFileSection(T1base, len, f);
readFileSection(T1base, len, g_file);
grab(2, f);
grab(2, g_file);
if (memcmp("T2", buf, 2) != 0)
{
printf("Expected 'T2'\n");
exit(3);
}
w = readFileShort(f);
w = readFileShort(g_file);
if (w != len)
{
printf("Problem with size of T2: file %d, calc %d\n", w, len);
exit(4);
}
readFileSection(T2base, len, f);
readFileSection(T2base, len, g_file);
/* Now read the function g[] */
grab(2, f);
grab(2, g_file);
if (memcmp("gg", buf, 2) != 0)
{
printf("Expected 'gg'\n");
exit(3);
}
len = (uint16_t)(numVert * sizeof(uint16_t));
w = readFileShort(f);
w = readFileShort(g_file);
if (w != len)
{
printf("Problem with size of g[]: file %d, calc %d\n", w, len);
exit(4);
}
readFileSection(g, len, f);
readFileSection(g, len, g_file);
/* This is now the hash table */
@ -396,13 +396,13 @@ void SetupLibCheck(void)
printf("Could not allocate hash table\n");
exit(1);
}
grab(2, f);
grab(2, g_file);
if (memcmp("ht", buf, 2) != 0)
{
printf("Expected 'ht'\n");
exit(3);
}
w = readFileShort(f);
w = readFileShort(g_file);
if (w != numKeys * (SymLen + PatLen + sizeof(uint16_t)))
{
printf("Problem with size of hash table: file %d, calc %d\n", w, len);
@ -412,13 +412,13 @@ void SetupLibCheck(void)
for (i=0; i < numKeys; i++)
{
if (fread(&ht[i], 1, SymLen + PatLen, f) != SymLen + PatLen)
if (fread(&ht[i], 1, SymLen + PatLen, g_file) != SymLen + PatLen)
{
printf("Could not read signature\n");
exit(11);
}
}
fclose(f);
fclose(g_file);
prog.bSigs = TRUE;
}
@ -528,9 +528,9 @@ bool LibCheck(Function & pProc)
void grab(int n, FILE *f)
void grab(int n, FILE *_file)
{
if (fread(buf, 1, n, f) != (unsigned)n)
if (fread(buf, 1, n, _file) != (unsigned)n)
{
printf("Could not grab\n");
exit(11);
@ -982,36 +982,4 @@ searchPList(char *name)
}
}
#if DEBUG_HEAP
void
checkHeap(char *msg)
/* HEAPCHK.C: This program checks the heap for
* consistency and prints an appropriate message.
*/
{
int heapstatus;
printf("%s\n", msg);
/* Check heap status */
heapstatus = _heapchk();
switch( heapstatus )
{
case _HEAPOK:
printf(" OK - heap is fine\n" );
break;
case _HEAPEMPTY:
printf(" OK - heap is empty\n" );
break;
case _HEAPBADBEGIN:
printf( "ERROR - bad start of heap\n" );
break;
case _HEAPBADNODE:
printf( "ERROR - bad node in heap\n" );
break;
}
}
#endif

View File

@ -8,11 +8,7 @@
#include "dcc.h"
#include <stdio.h>
#include <string.h>
#if __BORLAND__
#include <alloc.h>
#else
#include <malloc.h>
#endif
//typedef struct list {
// int nodeIdx;
@ -69,7 +65,7 @@ static int commonDom (int currImmDom, int predImmDom, Function * pProc)
void Function::findImmedDom ()
{
BB * currNode;
int currIdx, j, predIdx;
int currIdx, predIdx;
for (currIdx = 0; currIdx < numBBs; currIdx++)
{
@ -525,11 +521,11 @@ void Function::structIfs ()
* into one block with the appropriate condition */
void Function::compoundCond()
{
int i, j, k, numOutEdges;
BB * pbb, * t, * e, * obb,* pred;
int i; //j, k, numOutEdges
BB * pbb, * t, * e, * obb;//,* pred;
ICODE * picode, * ticode;
COND_EXPR *exp;
TYPEADR_TYPE *edges;
//COND_EXPR *exp;
//TYPEADR_TYPE *edges;
boolT change;
change = TRUE;

View File

@ -116,7 +116,7 @@ void Function::elimCondCodes ()
boolT notSup; /* Use/def combination not supported */
COND_EXPR *rhs; /* Source operand */
COND_EXPR *lhs; /* Destination operand */
COND_EXPR *exp; /* Boolean expression */
COND_EXPR *_expr; /* Boolean expression */
BB * pBB; /* Pointer to BBs in dfs last ordering */
riICODE useAt; /* Instruction that used flag */
riICODE defAt; /* Instruction that defined flag */
@ -128,20 +128,22 @@ void Function::elimCondCodes ()
// auto v(pBB | boost::adaptors::reversed);
// for (const ICODE &useAt : v)
// {}
for (useAt = pBB->rbegin2(); useAt != pBB->rend2(); useAt++)
assert(distance(pBB->rbegin(),pBB->rend())==pBB->size());
for (useAt = pBB->rbegin(); useAt != pBB->rend(); useAt++)
{
llIcode useAtOp = useAt->ll()->getOpcode();
if ((useAt->type == LOW_LEVEL) && (useAt->valid()) && (use = useAt->ll()->flagDU.u))
{
use = useAt->ll()->flagDU.u;
if ((useAt->type != LOW_LEVEL) || ( ! useAt->valid() ) || ( 0 == use ))
continue;
/* Find definition within the same basic block */
defAt=useAt;
++defAt;
for (; defAt != pBB->rend2(); defAt++)
for (; defAt != pBB->rend(); defAt++)
{
def = defAt->ll()->flagDU.d;
if ((use & def) != use)
continue;
notSup = FALSE;
notSup = false;
if ((useAtOp >= iJB) && (useAtOp <= iJNS))
{
iICODE befDefAt = (++riICODE(defAt)).base();
@ -172,15 +174,17 @@ void Function::elimCondCodes ()
break;
default:
notSup = TRUE;
notSup = true;
std::cout << hex<<defAt->loc_ip;
reportError (JX_NOT_DEF, defAt->ll()->getOpcode());
flg |= PROC_ASM; /* generate asm */
}
if (! notSup)
{
exp = COND_EXPR::boolOp (lhs, rhs,condOpJCond[useAtOp-iJB]);
useAt->setJCond(exp);
assert(lhs);
assert(rhs);
_expr = COND_EXPR::boolOp (lhs, rhs,condOpJCond[useAtOp-iJB]);
useAt->setJCond(_expr);
}
}
@ -189,8 +193,8 @@ void Function::elimCondCodes ()
lhs = COND_EXPR::idReg (rCX, 0, &localId);
useAt->setRegDU (rCX, eUSE);
rhs = COND_EXPR::idKte (0, 2);
exp = COND_EXPR::boolOp (lhs, rhs, EQUAL);
useAt->setJCond(exp);
_expr = COND_EXPR::boolOp (lhs, rhs, EQUAL);
useAt->setJCond(_expr);
}
// else if (useAt->getOpcode() == iRCL)
// {
@ -208,24 +212,23 @@ void Function::elimCondCodes ()
/* Check for extended basic block */
if ((pBB->size() == 1) &&(useAtOp >= iJB) && (useAtOp <= iJNS))
{
ICODE & prev(pBB->back()); /* For extended basic blocks - previous icode inst */
if (prev.hl()->opcode == HLI_JCOND)
ICODE & _prev(pBB->back()); /* For extended basic blocks - previous icode inst */
if (_prev.hl()->opcode == HLI_JCOND)
{
exp = prev.hl()->expr()->clone();
exp->changeBoolOp (condOpJCond[useAtOp-iJB]);
useAt->copyDU(prev, eUSE, eUSE);
useAt->setJCond(exp);
_expr = _prev.hl()->expr()->clone();
_expr->changeBoolOp (condOpJCond[useAtOp-iJB]);
useAt->copyDU(_prev, eUSE, eUSE);
useAt->setJCond(_expr);
}
}
/* Error - definition not found for use of a cond code */
else if (defAt == pBB->rend2())
else if (defAt == pBB->rend())
{
reportError(DEF_NOT_FOUND,useAtOp);
//fatalError (DEF_NOT_FOUND, Icode.getOpcode(useAt-1));
}
}
}
}
}
@ -248,7 +251,7 @@ void Function::genLiveKtes ()
pbb = m_dfsLast[i];
if (pbb->flg & INVALID_BB)
continue; // skip invalid BBs
for (auto j = pbb->begin2(); j != pbb->end2(); j++)
for (auto j = pbb->begin(); j != pbb->end(); j++)
{
if ((j->type == HIGH_LEVEL) && (j->invalid == FALSE))
{
@ -267,7 +270,6 @@ void Function::genLiveKtes ()
* Propagates register usage information to the procedure call. */
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 */
@ -306,11 +308,11 @@ void Function::liveRegAnalysis (std::bitset<32> &in_liveOut)
/* Get return expression of function */
if (flg & PROC_IS_FUNC)
{
auto picode = pbb->rbegin2(); /* icode of function return */
auto picode = pbb->rbegin(); /* icode of function return */
if (picode->hl()->opcode == HLI_RET)
{
//pbb->back().loc_ip
picode->hl()->expr(COND_EXPR::idID (&retVal, &localId, (++pbb->rbegin2()).base()));
picode->hl()->expr(COND_EXPR::idID (&retVal, &localId, (++pbb->rbegin()).base()));
picode->du.use = in_liveOut;
}
}
@ -362,7 +364,8 @@ void Function::liveRegAnalysis (std::bitset<32> &in_liveOut)
ticode.du1.numRegsDef = 1;
break;
default:
fprintf(stderr,"Function::liveRegAnalysis : Unknown return type %d\n",pcallee->retVal.type);
ticode.du1.numRegsDef = 0;
fprintf(stderr,"Function::liveRegAnalysis : Unknown return type %d, assume 0\n",pcallee->retVal.type);
} /*eos*/
/* Propagate def/use results to calling icode */
@ -411,8 +414,8 @@ void BB::genDU1()
* Note that register variables should not be considered registers.
*/
assert(0!=Parent);
lastInst = this->end2();
for (picode = this->begin2(); picode != lastInst; picode++)
lastInst = this->end();
for (picode = this->begin(); picode != lastInst; picode++)
{
if (picode->type != HIGH_LEVEL)
continue;
@ -470,7 +473,7 @@ void BB::genDU1()
(picode->hl()->call.proc->flg & PROC_IS_FUNC))
{
tbb = this->edges[0].BBptr;
for (ticode = tbb->begin2(); ticode != tbb->end2(); ticode++)
for (ticode = tbb->begin(); ticode != tbb->end(); ticode++)
{
if (ticode->type != HIGH_LEVEL)
continue;
@ -511,7 +514,7 @@ void BB::genDU1()
/* Backpatch any uses of this instruction, within
* the same BB, if the instruction was invalidated */
for (auto ticode = riICODE(picode); ticode != this->rend2(); ticode++)
for (auto ticode = riICODE(picode); ticode != this->rend(); ticode++)
{
ticode->du1.remove(0,picode);
}
@ -835,9 +838,9 @@ void Function::findExps()
pbb = m_dfsLast[i];
if (pbb->flg & INVALID_BB)
continue;
lastInst = pbb->end2();
lastInst = pbb->end();
numHlIcodes = 0;
for (picode = pbb->begin2(); picode != lastInst; picode++)
for (picode = pbb->begin(); picode != lastInst; picode++)
{
if ((picode->type == HIGH_LEVEL) && (picode->invalid == FALSE))
{
@ -918,7 +921,7 @@ void Function::findExps()
res = COND_EXPR::insertSubTreeReg (ti_hl->asgn.rhs,exp, retVal->id.regi, &localId);
if (! res)
COND_EXPR::insertSubTreeReg (ti_hl->asgn.lhs, exp,retVal->id.regi, &localId);
/*** TODO: HERE missing: 2 regs ****/
//TODO: HERE missing: 2 regs
picode->invalidate();
numHlIcodes--;
break;
@ -1131,7 +1134,7 @@ void Function::dataFlow(std::bitset<32> &liveOut)
}
/* Data flow analysis */
liveAnal = TRUE;
liveAnal = true;
elimCondCodes();
genLiveKtes();
liveRegAnalysis (liveOut); /* calls dataFlow() recursively */

View File

@ -152,7 +152,7 @@ CondJumps:
return ;
}
auto iter2=std::find_if(heldBBs.begin(),heldBBs.end(),
[ip](BB *psBB)->bool {return psBB->begin()==ip;});
[ip](BB *psBB)->bool {return psBB->begin()->loc_ip==ip;});
if(iter2==heldBBs.end())
fatalError(NO_BB, ip, name.c_str());
psBB = *iter2;
@ -223,23 +223,33 @@ void Function::compressCFG()
/* First pass over BB list removes redundant jumps of the form
* (Un)Conditional -> Unconditional jump */
#ifdef _lint
auto iter=m_cfg.begin();
for (;iter!=m_cfg.end(); ++iter)
{
pBB = *iter;
BB *pBB(*iter);
#else
for (BB *pBB : m_cfg)
{
#endif
if(pBB->inEdges.empty() || (pBB->nodeType != ONE_BRANCH && pBB->nodeType != TWO_BRANCH))
continue;
for (i = 0; i < pBB->edges.size(); i++)
#ifdef _lint
for (auto iter2=pBB->edges().begin(); iter2!=pBB->edges().end(); ++iter2)
{
ip = pBB->rbegin();
pNxt = pBB->edges[i].BBptr->rmJMP(ip, pBB->edges[i].BBptr);
TYPEADR_TYPE &edgeRef(*iter);
#else
for (TYPEADR_TYPE &edgeRef : pBB->edges)
{
#endif
ip = pBB->rbegin()->loc_ip;
pNxt = edgeRef.BBptr->rmJMP(ip, edgeRef.BBptr);
if (not pBB->edges.empty()) /* Might have been clobbered */
{
pBB->edges[i].BBptr = pNxt;
edgeRef.BBptr = pNxt;
assert(pBB->back().loc_ip==ip);
pBB->back().ll()->SetImmediateOp((uint32_t)pNxt->begin());
//Icode[ip].SetImmediateOp((uint32_t)pNxt->begin());
pBB->back().ll()->SetImmediateOp((uint32_t)pNxt->begin()->loc_ip);
}
}
}
@ -353,15 +363,15 @@ void BB::mergeFallThrough( CIcodeRec &Icode)
assert(Parent==pChild->Parent);
if(back().loc_ip>pChild->front().loc_ip) // back edege
break;
auto iter=std::find_if(this->end2(),pChild->begin2(),[](ICODE &c)
auto iter=std::find_if(this->end(),pChild->begin(),[](ICODE &c)
{return not c.ll()->testFlags(NO_CODE);});
if (iter != pChild->begin2())
if (iter != pChild->begin())
break;
back().ll()->setFlags(NO_CODE);
back().invalidate();
nodeType = FALL_NODE;
length--;
range_end--;
}
/* If there's no other edges into child can merge */
@ -369,7 +379,7 @@ void BB::mergeFallThrough( CIcodeRec &Icode)
break;
nodeType = pChild->nodeType;
length = (pChild->start - start) + pChild->length ;
range_end = pChild->range_end;
pChild->front().ll()->clrFlags(TARGET);
edges.swap(pChild->edges);

View File

@ -386,7 +386,8 @@ void Function::highLevelGen()
pIcode->setAsgn(lhs, rhs);
break;
case iNEG: rhs = COND_EXPR::unary (NEGATION, lhs);
case iNEG:
rhs = COND_EXPR::unary (NEGATION, lhs);
pIcode->setAsgn(lhs, rhs);
break;
@ -445,7 +446,7 @@ void Function::highLevelGen()
/* Modifies the given conditional operator to its inverse. This is used
* in if..then[..else] statements, to reflect the condition that takes the
* then part. */
COND_EXPR *COND_EXPR::inverse ()
COND_EXPR *COND_EXPR::inverse () const
{
static condOp invCondOp[] = {GREATER, GREATER_EQUAL, NOT_EQUAL, EQUAL,
LESS_EQUAL, LESS, DUMMY,DUMMY,DUMMY,DUMMY,
@ -503,7 +504,7 @@ std::string writeCall (Function * tproc, STKFRAME * args, Function * pproc, int
/* Displays the output of a HLI_JCOND icode. */
char *writeJcond (HLTYPE h, Function * pProc, int *numLoc)
char *writeJcond (const HLTYPE &h, Function * pProc, int *numLoc)
{
assert(h.expr());
memset (buf, ' ', sizeof(buf));
@ -600,8 +601,9 @@ int power2 (int i)
/* Writes the registers/stack variables that are used and defined by this
* instruction. */
void ICODE::writeDU(int idx)
void ICODE::writeDU()
{
int my_idx = loc_ip;
{
ostringstream ostr;
for (int i = 0; i < (INDEXBASE-1); i++)
@ -633,7 +635,7 @@ void ICODE::writeDU(int idx)
{
if (du1.used(i))
{
printf ("%d: du1[%d][] = ", idx, i);
printf ("%d: du1[%d][] = ", my_idx, i);
#ifdef _lint
for (auto ik=du1.idx[i].uses.begin(); ik!=du1.idx[i].uses.end(); ++ik)
{

View File

@ -95,7 +95,7 @@ void Function::findIdioms()
case iPUSH:
{
/* Idiom 1 */
// todo add other push idioms.
//TODO: add other push idioms.
advance(pIcode,i01(pIcode));
break;
}

View File

@ -132,12 +132,17 @@ bool Idiom4::match(iICODE pIcode)
if (pIcode->ll()->testFlags(I) )
{
m_param_count = (int16_t)pIcode->ll()->src.op();
return true;
}
return false;
}
int Idiom4::action()
{
for(size_t idx=0; idx<m_icodes.size()-1; ++idx) // don't invalidate last entry
if( ! m_icodes.empty()) // if not an empty RET[F] N
{
for(size_t idx=0; idx<m_icodes.size()-1; ++idx) // invalidate all but the RET
m_icodes[idx]->invalidate();
}
if(m_param_count)
{
m_func->cbParam = (int16_t)m_param_count;

View File

@ -127,7 +127,7 @@ bool Idiom10::match(iICODE pIcode)
int Idiom10::action()
{
m_icodes[0]->ll()->set(iCMP,I);
m_icodes[0]->ll()->src.SetImmediateOp(0); // todo check if proc should be zeroed too
m_icodes[0]->ll()->src.SetImmediateOp(0); //TODO: check if proc should be zeroed too
m_icodes[0]->du.def = 0;
m_icodes[0]->du1.numRegsDef = 0;
return 2;

View File

@ -37,7 +37,7 @@ static bool isLong23 (iICODE iter, BB * pbb, iICODE &off, int *arc)
obb2 = t->edges[THEN].BBptr;
if ((obb2->size() == 2) && (obb2->nodeType == TWO_BRANCH) && (obb2->front().ll()->getOpcode() == iCMP))
{
off = obb2->begin2();//std::distance(iter,obb2->begin2());
off = obb2->begin();//std::distance(iter,obb2->begin2());
*arc = THEN;
return true;
}
@ -49,7 +49,7 @@ static bool isLong23 (iICODE iter, BB * pbb, iICODE &off, int *arc)
obb2 = e->edges[THEN].BBptr;
if ((obb2->size() == 2) && (obb2->nodeType == TWO_BRANCH) && (obb2->front().ll()->getOpcode() == iCMP))
{
off = obb2->begin2();//std::distance(iter,obb2->begin2());//obb2->front().loc_ip - i;
off = obb2->begin();//std::distance(iter,obb2->begin2());//obb2->front().loc_ip - i;
*arc = ELSE;
return true;
}
@ -155,7 +155,7 @@ static int longJCond23 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode, int arc,
pIcode->invalidate();
obb1->front().invalidate();
// invalidate 2 first instructions of BB 2
iICODE ibb2 = obb2->begin2();
iICODE ibb2 = obb2->begin();
(ibb2++)->invalidate();
(ibb2++)->invalidate();
return skipped_insn;

View File

@ -35,6 +35,7 @@ static BB *firstOfQueue (queue &Q)
/* Appends pointer to node at the end of the queue Q if node is not present
* in this queue. Returns the queue node just appended. */
//lint -sem(appendQueue,custodial(1))
queue::iterator appendQueue (queue &Q, BB *node)
{
auto iter=std::find(Q.begin(),Q.end(),node);
@ -173,19 +174,21 @@ void derSeq_Entry::findIntervals (Function *c)
/* Displays the intervals of the graph Gi. */
static void displayIntervals (interval *pI)
{
queue::iterator nodePtr;
while (pI)
{
nodePtr = pI->nodes.begin();
printf (" Interval #: %ld\t#OutEdges: %ld\n", pI->numInt, pI->numOutEdges);
while (nodePtr!=pI->nodes.end())
#ifdef _lint
for(auto iter=pI->nodes.begin(); iter!=pI->nodes.end(); ++iter)
{
if ((*nodePtr)->correspInt == NULL) /* real BBs */
printf (" Node: %ld\n", (*nodePtr)->begin());
BB *node(*iter);
#else
for(BB *node : pI->nodes)
{
#endif
if (node->correspInt == NULL) /* real BBs */
printf (" Node: %ld\n", node->begin()->loc_ip);
else // BBs represent intervals
printf (" Node (corresp int): %d\n", (*nodePtr)->correspInt->numInt);
++nodePtr;
printf (" Node (corresp int): %d\n", node->correspInt->numInt);
}
pI = pI->next;
}