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:
parent
fc0d35cf06
commit
69d848ca78
@ -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();
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
{
|
||||
#endif
|
||||
if ((pHli.type == HIGH_LEVEL) && ( pHli.valid() )) //TODO: use filtering range here.
|
||||
{
|
||||
std::string line = hli->hl()->write1HlIcode(pProc, numLoc);
|
||||
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());
|
||||
}
|
||||
|
||||
@ -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 */
|
||||
|
||||
|
||||
@ -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 = ");
|
||||
|
||||
@ -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);
|
||||
@ -231,9 +231,9 @@ static uint8_t pattMainMedium[] =
|
||||
0xFF, 0x36, WILD, WILD, /* Push argv */
|
||||
0xFF, 0x36, WILD, WILD, /* Push argc */
|
||||
0x9A, WILD, WILD, WILD, WILD /* call far _main */
|
||||
/* 0x50 /* push ax */
|
||||
/* 0x0E, /* push cs NB not tested Borland */
|
||||
/* 0xE8 /* call _exit */
|
||||
/* 0x50 /* push ax */
|
||||
/* 0x0E, /* push cs NB not tested Borland */
|
||||
/* 0xE8 /* call _exit */
|
||||
};
|
||||
/* Num bytes from start pattern to the relative offset of main() */
|
||||
#define OFFMAINMEDIUM 13
|
||||
@ -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
|
||||
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
137
src/dataflow.cpp
137
src/dataflow.cpp
@ -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,25 +128,27 @@ 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->rend(); defAt++)
|
||||
{
|
||||
/* Find definition within the same basic block */
|
||||
defAt=useAt;
|
||||
++defAt;
|
||||
for (; defAt != pBB->rend2(); defAt++)
|
||||
def = defAt->ll()->flagDU.d;
|
||||
if ((use & def) != use)
|
||||
continue;
|
||||
notSup = false;
|
||||
if ((useAtOp >= iJB) && (useAtOp <= iJNS))
|
||||
{
|
||||
def = defAt->ll()->flagDU.d;
|
||||
if ((use & def) != use)
|
||||
continue;
|
||||
notSup = FALSE;
|
||||
if ((useAtOp >= iJB) && (useAtOp <= iJNS))
|
||||
iICODE befDefAt = (++riICODE(defAt)).base();
|
||||
switch (defAt->ll()->getOpcode())
|
||||
{
|
||||
iICODE befDefAt = (++riICODE(defAt)).base();
|
||||
switch (defAt->ll()->getOpcode())
|
||||
{
|
||||
case iCMP:
|
||||
rhs = srcIdent (*defAt->ll(), this, befDefAt,*useAt, eUSE);
|
||||
lhs = dstIdent (*defAt->ll(), this, befDefAt,*useAt, eUSE);
|
||||
@ -172,57 +174,58 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
else if (useAtOp == iJCXZ)
|
||||
if (! notSup)
|
||||
{
|
||||
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);
|
||||
assert(lhs);
|
||||
assert(rhs);
|
||||
_expr = COND_EXPR::boolOp (lhs, rhs,condOpJCond[useAtOp-iJB]);
|
||||
useAt->setJCond(_expr);
|
||||
}
|
||||
// else if (useAt->getOpcode() == iRCL)
|
||||
// {
|
||||
// }
|
||||
else
|
||||
{
|
||||
ICODE &a(*defAt);
|
||||
ICODE &b(*useAt);
|
||||
reportError (NOT_DEF_USE,a.ll()->getOpcode(),b.ll()->getOpcode());
|
||||
flg |= PROC_ASM; /* generate asm */
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* Check for extended basic block */
|
||||
if ((pBB->size() == 1) &&(useAtOp >= iJB) && (useAtOp <= iJNS))
|
||||
else if (useAtOp == iJCXZ)
|
||||
{
|
||||
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);
|
||||
}
|
||||
lhs = COND_EXPR::idReg (rCX, 0, &localId);
|
||||
useAt->setRegDU (rCX, eUSE);
|
||||
rhs = COND_EXPR::idKte (0, 2);
|
||||
_expr = COND_EXPR::boolOp (lhs, rhs, EQUAL);
|
||||
useAt->setJCond(_expr);
|
||||
}
|
||||
/* Error - definition not found for use of a cond code */
|
||||
else if (defAt == pBB->rend2())
|
||||
// else if (useAt->getOpcode() == iRCL)
|
||||
// {
|
||||
// }
|
||||
else
|
||||
{
|
||||
reportError(DEF_NOT_FOUND,useAtOp);
|
||||
//fatalError (DEF_NOT_FOUND, Icode.getOpcode(useAt-1));
|
||||
ICODE &a(*defAt);
|
||||
ICODE &b(*useAt);
|
||||
reportError (NOT_DEF_USE,a.ll()->getOpcode(),b.ll()->getOpcode());
|
||||
flg |= PROC_ASM; /* generate asm */
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
_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->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 */
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
342
src/hlicode.cpp
342
src/hlicode.cpp
@ -14,14 +14,14 @@ using namespace std;
|
||||
|
||||
/* Masks off bits set by duReg[] */
|
||||
std::bitset<32> maskDuReg[] = { 0x00,
|
||||
0xFEEFFE, 0xFDDFFD, 0xFBB00B, 0xF77007, /* uint16_t regs */
|
||||
0xFFFFEF, 0xFFFFDF, 0xFFFFBF, 0xFFFF7F,
|
||||
0xFFFEFF, 0xFFFDFF, 0xFFFBFF, 0xFFF7FF, /* seg regs */
|
||||
0xFFEFFF, 0xFFDFFF, 0xFFBFFF, 0xFF7FFF, /* uint8_t regs */
|
||||
0xFEFFFF, 0xFDFFFF, 0xFBFFFF, 0xF7FFFF,
|
||||
0xEFFFFF, /* tmp reg */
|
||||
0xFFFFB7, 0xFFFF77, 0xFFFF9F, 0xFFFF5F, /* index regs */
|
||||
0xFFFFBF, 0xFFFF7F, 0xFFFFDF, 0xFFFFF7 };
|
||||
0xFEEFFE, 0xFDDFFD, 0xFBB00B, 0xF77007, /* uint16_t regs */
|
||||
0xFFFFEF, 0xFFFFDF, 0xFFFFBF, 0xFFFF7F,
|
||||
0xFFFEFF, 0xFFFDFF, 0xFFFBFF, 0xFFF7FF, /* seg regs */
|
||||
0xFFEFFF, 0xFFDFFF, 0xFFBFFF, 0xFF7FFF, /* uint8_t regs */
|
||||
0xFEFFFF, 0xFDFFFF, 0xFBFFFF, 0xF7FFFF,
|
||||
0xEFFFFF, /* tmp reg */
|
||||
0xFFFFB7, 0xFFFF77, 0xFFFF9F, 0xFFFF5F, /* index regs */
|
||||
0xFFFFBF, 0xFFFF7F, 0xFFFFDF, 0xFFFFF7 };
|
||||
|
||||
static char buf[lineSize]; /* Line buffer for hl icode output */
|
||||
|
||||
@ -141,138 +141,138 @@ HLTYPE LLInst::toHighLevel(COND_EXPR *lhs,COND_EXPR *rhs,Function *func)
|
||||
|
||||
switch (getOpcode())
|
||||
{
|
||||
case iADD:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, ADD);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
case iADD:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, ADD);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
|
||||
case iAND:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, AND);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
case iAND:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, AND);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
|
||||
case iCALL:
|
||||
case iCALLF:
|
||||
//TODO: this is noop pIcode->checkHlCall();
|
||||
res=createCall();
|
||||
break;
|
||||
case iCALL:
|
||||
case iCALLF:
|
||||
//TODO: this is noop pIcode->checkHlCall();
|
||||
res=createCall();
|
||||
break;
|
||||
|
||||
case iDEC:
|
||||
rhs = COND_EXPR::idKte (1, 2);
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, SUB);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
case iDEC:
|
||||
rhs = COND_EXPR::idKte (1, 2);
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, SUB);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
|
||||
case iDIV:
|
||||
case iIDIV:/* should be signed div */
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, DIV);
|
||||
if ( ll->testFlags(B) )
|
||||
{
|
||||
lhs = COND_EXPR::idReg (rAL, 0, &localId);
|
||||
pIcode->setRegDU( rAL, eDEF);
|
||||
}
|
||||
else
|
||||
{
|
||||
lhs = COND_EXPR::idReg (rAX, 0, &localId);
|
||||
pIcode->setRegDU( rAX, eDEF);
|
||||
}
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
case iDIV:
|
||||
case iIDIV:/* should be signed div */
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, DIV);
|
||||
if ( ll->testFlags(B) )
|
||||
{
|
||||
lhs = COND_EXPR::idReg (rAL, 0, &localId);
|
||||
pIcode->setRegDU( rAL, eDEF);
|
||||
}
|
||||
else
|
||||
{
|
||||
lhs = COND_EXPR::idReg (rAX, 0, &localId);
|
||||
pIcode->setRegDU( rAX, eDEF);
|
||||
}
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
|
||||
case iIMUL:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, MUL);
|
||||
lhs = COND_EXPR::id (*pIcode, LHS_OP, func, i, *pIcode, NONE);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
case iIMUL:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, MUL);
|
||||
lhs = COND_EXPR::id (*pIcode, LHS_OP, func, i, *pIcode, NONE);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
|
||||
case iINC:
|
||||
rhs = COND_EXPR::idKte (1, 2);
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, ADD);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
case iINC:
|
||||
rhs = COND_EXPR::idKte (1, 2);
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, ADD);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
|
||||
case iLEA:
|
||||
rhs = COND_EXPR::unary (ADDRESSOF, rhs);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
case iLEA:
|
||||
rhs = COND_EXPR::unary (ADDRESSOF, rhs);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
|
||||
case iMOD:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, MOD);
|
||||
if ( ll->testFlags(B) )
|
||||
{
|
||||
lhs = COND_EXPR::idReg (rAH, 0, &localId);
|
||||
pIcode->setRegDU( rAH, eDEF);
|
||||
}
|
||||
else
|
||||
{
|
||||
lhs = COND_EXPR::idReg (rDX, 0, &localId);
|
||||
pIcode->setRegDU( rDX, eDEF);
|
||||
}
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
case iMOD:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, MOD);
|
||||
if ( ll->testFlags(B) )
|
||||
{
|
||||
lhs = COND_EXPR::idReg (rAH, 0, &localId);
|
||||
pIcode->setRegDU( rAH, eDEF);
|
||||
}
|
||||
else
|
||||
{
|
||||
lhs = COND_EXPR::idReg (rDX, 0, &localId);
|
||||
pIcode->setRegDU( rDX, eDEF);
|
||||
}
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
|
||||
case iMOV: res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
case iMOV: res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
|
||||
case iMUL:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, MUL);
|
||||
lhs = COND_EXPR::id (*pIcode, LHS_OP, this, i, *pIcode, NONE);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
case iMUL:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, MUL);
|
||||
lhs = COND_EXPR::id (*pIcode, LHS_OP, this, i, *pIcode, NONE);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
|
||||
case iNEG:
|
||||
rhs = COND_EXPR::unary (NEGATION, lhs);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
case iNEG:
|
||||
rhs = COND_EXPR::unary (NEGATION, lhs);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
|
||||
case iNOT:
|
||||
rhs = COND_EXPR::boolOp (NULL, rhs, NOT);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
case iNOT:
|
||||
rhs = COND_EXPR::boolOp (NULL, rhs, NOT);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
|
||||
case iOR:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, OR);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
case iOR:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, OR);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
|
||||
case iPOP: res.set(HLI_POP, lhs);
|
||||
break;
|
||||
case iPOP: res.set(HLI_POP, lhs);
|
||||
break;
|
||||
|
||||
case iPUSH: res.set(HLI_PUSH, lhs);
|
||||
break;
|
||||
case iPUSH: res.set(HLI_PUSH, lhs);
|
||||
break;
|
||||
|
||||
case iRET:
|
||||
case iRETF:
|
||||
res.set(HLI_RET, NULL);
|
||||
break;
|
||||
case iRET:
|
||||
case iRETF:
|
||||
res.set(HLI_RET, NULL);
|
||||
break;
|
||||
|
||||
case iSHL:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, SHL);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
case iSHL:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, SHL);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
|
||||
case iSAR: /* signed */
|
||||
case iSHR:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, SHR); /* unsigned*/
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
case iSAR: /* signed */
|
||||
case iSHR:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, SHR); /* unsigned*/
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
|
||||
case iSIGNEX:
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
case iSIGNEX:
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
|
||||
case iSUB:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, SUB);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
case iSUB:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, SUB);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
|
||||
case iXCHG:
|
||||
break;
|
||||
case iXCHG:
|
||||
break;
|
||||
|
||||
case iXOR:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, XOR);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
case iXOR:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, XOR);
|
||||
res.setAsgn(lhs, rhs);
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@ -296,17 +296,17 @@ void Function::highLevelGen()
|
||||
pIcode->invalidate();
|
||||
if ((pIcode->type != LOW_LEVEL) or not pIcode->valid() )
|
||||
continue;
|
||||
flg = ll->getFlag();
|
||||
if ((flg & IM_OPS) != IM_OPS) /* not processing IM_OPS yet */
|
||||
if ((flg & NO_OPS) != NO_OPS) /* if there are opers */
|
||||
{
|
||||
if ( not ll->testFlags(NO_SRC) ) /* if there is src op */
|
||||
flg = ll->getFlag();
|
||||
if ((flg & IM_OPS) != IM_OPS) /* not processing IM_OPS yet */
|
||||
if ((flg & NO_OPS) != NO_OPS) /* if there are opers */
|
||||
{
|
||||
if ( not ll->testFlags(NO_SRC) ) /* if there is src op */
|
||||
rhs = COND_EXPR::id (*pIcode->ll(), SRC, this, i, *pIcode, NONE);
|
||||
lhs = COND_EXPR::id (*pIcode->ll(), DST, this, i, *pIcode, NONE);
|
||||
}
|
||||
|
||||
switch (ll->getOpcode())
|
||||
{
|
||||
switch (ll->getOpcode())
|
||||
{
|
||||
case iADD:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, ADD);
|
||||
pIcode->setAsgn(lhs, rhs);
|
||||
@ -319,8 +319,8 @@ void Function::highLevelGen()
|
||||
|
||||
case iCALL:
|
||||
case iCALLF:
|
||||
pIcode->type = HIGH_LEVEL;
|
||||
pIcode->hl( ll->createCall() );
|
||||
pIcode->type = HIGH_LEVEL;
|
||||
pIcode->hl( ll->createCall() );
|
||||
break;
|
||||
|
||||
case iDEC:
|
||||
@ -347,7 +347,7 @@ void Function::highLevelGen()
|
||||
|
||||
case iIMUL:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, MUL);
|
||||
lhs = COND_EXPR::id (*ll, LHS_OP, this, i, *pIcode, NONE);
|
||||
lhs = COND_EXPR::id (*ll, LHS_OP, this, i, *pIcode, NONE);
|
||||
pIcode->setAsgn(lhs, rhs);
|
||||
break;
|
||||
|
||||
@ -382,11 +382,12 @@ void Function::highLevelGen()
|
||||
|
||||
case iMUL:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, MUL);
|
||||
lhs = COND_EXPR::id (*ll, LHS_OP, this, i, *pIcode, NONE);
|
||||
lhs = COND_EXPR::id (*ll, LHS_OP, this, i, *pIcode, NONE);
|
||||
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;
|
||||
|
||||
@ -424,8 +425,8 @@ void Function::highLevelGen()
|
||||
case iSIGNEX: pIcode->setAsgn(lhs, rhs);
|
||||
break;
|
||||
|
||||
case iSUB:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, SUB);
|
||||
case iSUB:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, SUB);
|
||||
pIcode->setAsgn(lhs, rhs);
|
||||
break;
|
||||
|
||||
@ -436,7 +437,7 @@ void Function::highLevelGen()
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, XOR);
|
||||
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,
|
||||
@ -456,22 +457,22 @@ COND_EXPR *COND_EXPR::inverse ()
|
||||
{
|
||||
switch ( op() )
|
||||
{
|
||||
case LESS_EQUAL: case LESS: case EQUAL:
|
||||
case NOT_EQUAL: case GREATER: case GREATER_EQUAL:
|
||||
res = this->clone();
|
||||
res->boolExpr.op = invCondOp[op()];
|
||||
return res;
|
||||
case LESS_EQUAL: case LESS: case EQUAL:
|
||||
case NOT_EQUAL: case GREATER: case GREATER_EQUAL:
|
||||
res = this->clone();
|
||||
res->boolExpr.op = invCondOp[op()];
|
||||
return res;
|
||||
|
||||
case AND: case OR: case XOR: case NOT: case ADD:
|
||||
case SUB: case MUL: case DIV: case SHR: case SHL: case MOD:
|
||||
return COND_EXPR::unary (NEGATION, this->clone());
|
||||
case AND: case OR: case XOR: case NOT: case ADD:
|
||||
case SUB: case MUL: case DIV: case SHR: case SHL: case MOD:
|
||||
return COND_EXPR::unary (NEGATION, this->clone());
|
||||
|
||||
case DBL_AND: case DBL_OR:
|
||||
res = this->clone();
|
||||
res->boolExpr.op = invCondOp[op()];
|
||||
res->boolExpr.lhs=lhs()->inverse ();
|
||||
res->boolExpr.rhs=rhs()->inverse ();
|
||||
return res;
|
||||
case DBL_AND: case DBL_OR:
|
||||
res = this->clone();
|
||||
res->boolExpr.op = invCondOp[op()];
|
||||
res->boolExpr.lhs=lhs()->inverse ();
|
||||
res->boolExpr.rhs=rhs()->inverse ();
|
||||
return res;
|
||||
} /* eos */
|
||||
|
||||
}
|
||||
@ -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));
|
||||
@ -565,25 +566,25 @@ string HLTYPE::write1HlIcode (Function * pProc, int *numLoc)
|
||||
HlTypeSupport *p = get();
|
||||
switch (opcode)
|
||||
{
|
||||
case HLI_ASSIGN:
|
||||
return p->writeOut(pProc,numLoc);
|
||||
case HLI_CALL:
|
||||
return p->writeOut(pProc,numLoc);
|
||||
case HLI_RET:
|
||||
e = p->writeOut(pProc,numLoc);
|
||||
if (! e.empty())
|
||||
ostr << "return (" << e << ");\n";
|
||||
break;
|
||||
case HLI_POP:
|
||||
ostr << "HLI_POP ";
|
||||
ostr << p->writeOut(pProc,numLoc);
|
||||
ostr << "\n";
|
||||
break;
|
||||
case HLI_PUSH:
|
||||
ostr << "HLI_PUSH ";
|
||||
ostr << p->writeOut(pProc,numLoc);
|
||||
ostr << "\n";
|
||||
break;
|
||||
case HLI_ASSIGN:
|
||||
return p->writeOut(pProc,numLoc);
|
||||
case HLI_CALL:
|
||||
return p->writeOut(pProc,numLoc);
|
||||
case HLI_RET:
|
||||
e = p->writeOut(pProc,numLoc);
|
||||
if (! e.empty())
|
||||
ostr << "return (" << e << ");\n";
|
||||
break;
|
||||
case HLI_POP:
|
||||
ostr << "HLI_POP ";
|
||||
ostr << p->writeOut(pProc,numLoc);
|
||||
ostr << "\n";
|
||||
break;
|
||||
case HLI_PUSH:
|
||||
ostr << "HLI_PUSH ";
|
||||
ostr << p->writeOut(pProc,numLoc);
|
||||
ostr << "\n";
|
||||
break;
|
||||
}
|
||||
return ostr.str();
|
||||
}
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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
|
||||
m_icodes[idx]->invalidate();
|
||||
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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user