More ranges
This commit is contained in:
parent
4dd97b0709
commit
b85106498e
@ -8,7 +8,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
|
#include <boost/range.hpp>
|
||||||
static const int operandSize=20;
|
static const int operandSize=20;
|
||||||
/* The following definitions and types define the Conditional Expression
|
/* The following definitions and types define the Conditional Expression
|
||||||
* attributed syntax tree, as defined by the following EBNF:
|
* attributed syntax tree, as defined by the following EBNF:
|
||||||
@ -30,6 +30,7 @@ struct ICODE;
|
|||||||
struct LLInst;
|
struct LLInst;
|
||||||
struct ID;
|
struct ID;
|
||||||
typedef std::list<ICODE>::iterator iICODE;
|
typedef std::list<ICODE>::iterator iICODE;
|
||||||
|
typedef boost::iterator_range<iICODE> rICODE;
|
||||||
#include "IdentType.h"
|
#include "IdentType.h"
|
||||||
|
|
||||||
/* Expression data type */
|
/* Expression data type */
|
||||||
@ -105,7 +106,7 @@ public:
|
|||||||
virtual ~COND_EXPR() {}
|
virtual ~COND_EXPR() {}
|
||||||
public:
|
public:
|
||||||
virtual COND_EXPR *inverse() const; // 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, const LOCAL_ID &locId);
|
virtual bool xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &locId);
|
||||||
virtual COND_EXPR *insertSubTreeReg(COND_EXPR *_expr, eReg regi, const LOCAL_ID *locsym);
|
virtual COND_EXPR *insertSubTreeReg(COND_EXPR *_expr, eReg regi, const LOCAL_ID *locsym);
|
||||||
virtual COND_EXPR *insertSubTreeLongReg(COND_EXPR *_expr, int longIdx);
|
virtual COND_EXPR *insertSubTreeLongReg(COND_EXPR *_expr, int longIdx);
|
||||||
virtual hlType expType(Function *pproc) const;
|
virtual hlType expType(Function *pproc) const;
|
||||||
@ -124,7 +125,7 @@ struct BinaryOperator : public COND_EXPR
|
|||||||
static BinaryOperator *CreateAdd(COND_EXPR *l,COND_EXPR *r);
|
static BinaryOperator *CreateAdd(COND_EXPR *l,COND_EXPR *r);
|
||||||
virtual COND_EXPR *inverse();
|
virtual COND_EXPR *inverse();
|
||||||
virtual COND_EXPR *clone();
|
virtual COND_EXPR *clone();
|
||||||
virtual bool xClear(iICODE f, iICODE t, iICODE lastBBinst, const LOCAL_ID &locs);
|
virtual bool xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &locs);
|
||||||
virtual COND_EXPR *insertSubTreeReg(COND_EXPR *_expr, eReg regi, LOCAL_ID *locsym);
|
virtual COND_EXPR *insertSubTreeReg(COND_EXPR *_expr, eReg regi, LOCAL_ID *locsym);
|
||||||
virtual COND_EXPR *insertSubTreeLongReg(COND_EXPR *_expr, int longIdx);
|
virtual COND_EXPR *insertSubTreeLongReg(COND_EXPR *_expr, int longIdx);
|
||||||
|
|
||||||
@ -158,7 +159,7 @@ struct UnaryOperator : public COND_EXPR
|
|||||||
COND_EXPR *unaryExp;
|
COND_EXPR *unaryExp;
|
||||||
virtual COND_EXPR *inverse();
|
virtual COND_EXPR *inverse();
|
||||||
virtual COND_EXPR *clone();
|
virtual COND_EXPR *clone();
|
||||||
virtual bool xClear(iICODE f, iICODE t, iICODE lastBBinst, const LOCAL_ID &locs);
|
virtual bool xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &locs);
|
||||||
static UnaryOperator *Create(condNodeType t, COND_EXPR *sub_expr)
|
static UnaryOperator *Create(condNodeType t, COND_EXPR *sub_expr)
|
||||||
{
|
{
|
||||||
UnaryOperator *newExp = new UnaryOperator();
|
UnaryOperator *newExp = new UnaryOperator();
|
||||||
|
|||||||
@ -300,6 +300,12 @@ public:
|
|||||||
bool operator()(ICODE *ic) {return ic->type==HIGH_LEVEL;}
|
bool operator()(ICODE *ic) {return ic->type==HIGH_LEVEL;}
|
||||||
bool operator()(ICODE &ic) {return ic.type==HIGH_LEVEL;}
|
bool operator()(ICODE &ic) {return ic.type==HIGH_LEVEL;}
|
||||||
};
|
};
|
||||||
|
template<int TYPE>
|
||||||
|
struct TypeAndValidFilter
|
||||||
|
{
|
||||||
|
bool operator()(ICODE *ic) {return (ic->type==HIGH_LEVEL)&&(ic->valid());}
|
||||||
|
bool operator()(ICODE &ic) {return (ic.type==HIGH_LEVEL)&&ic.valid();}
|
||||||
|
};
|
||||||
/* Def/Use of registers and stack variables */
|
/* Def/Use of registers and stack variables */
|
||||||
struct DU_ICODE
|
struct DU_ICODE
|
||||||
{
|
{
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
using namespace boost;
|
using namespace boost;
|
||||||
|
using namespace boost::adaptors;
|
||||||
struct ExpStack
|
struct ExpStack
|
||||||
{
|
{
|
||||||
typedef std::list<COND_EXPR *> EXP_STK;
|
typedef std::list<COND_EXPR *> EXP_STK;
|
||||||
@ -398,7 +399,6 @@ void Function::liveRegAnalysis (std::bitset<32> &in_liveOut)
|
|||||||
|
|
||||||
void BB::genDU1()
|
void BB::genDU1()
|
||||||
{
|
{
|
||||||
using namespace boost::adaptors;
|
|
||||||
eReg regi; /* Register that was defined */
|
eReg regi; /* Register that was defined */
|
||||||
int k, defRegIdx, useIdx;
|
int k, defRegIdx, useIdx;
|
||||||
iICODE picode, ticode,lastInst;
|
iICODE picode, ticode,lastInst;
|
||||||
@ -603,7 +603,7 @@ static void forwardSubsLong (int longIdx, COND_EXPR *_exp, iICODE picode, iICODE
|
|||||||
|
|
||||||
/* Returns whether the elements of the expression rhs are all x-clear from
|
/* Returns whether the elements of the expression rhs are all x-clear from
|
||||||
* instruction f up to instruction t. */
|
* instruction f up to instruction t. */
|
||||||
bool COND_EXPR::xClear (iICODE f, iICODE t, iICODE lastBBinst, const LOCAL_ID & locId)
|
bool COND_EXPR::xClear (rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID & locId)
|
||||||
{
|
{
|
||||||
iICODE i;
|
iICODE i;
|
||||||
boolT res;
|
boolT res;
|
||||||
@ -615,13 +615,12 @@ bool COND_EXPR::xClear (iICODE f, iICODE t, iICODE lastBBinst, const LOCAL_ID &
|
|||||||
if (expr.ident.idType == REGISTER)
|
if (expr.ident.idType == REGISTER)
|
||||||
{
|
{
|
||||||
regi= locId.id_arr[expr.ident.idNode.regiIdx].id.regi;
|
regi= locId.id_arr[expr.ident.idNode.regiIdx].id.regi;
|
||||||
for (i = ++iICODE(f); (i != lastBBinst) && (i!=t); i++)
|
range_to_check.advance_begin(1);
|
||||||
if ((i->type == HIGH_LEVEL) && ( i->valid() ))
|
auto all_valid_and_high_level_after_start = range_to_check | filtered(ICODE::TypeAndValidFilter<HIGH_LEVEL>());
|
||||||
{
|
for (ICODE &i : all_valid_and_high_level_after_start)
|
||||||
if ((i->du.def & duReg[regi]).any())
|
if ((i.du.def & duReg[regi]).any())
|
||||||
return false;
|
return false;
|
||||||
}
|
if (all_valid_and_high_level_after_start.end().base() != lastBBinst)
|
||||||
if (i != lastBBinst)
|
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -635,38 +634,38 @@ bool COND_EXPR::xClear (iICODE f, iICODE t, iICODE lastBBinst, const LOCAL_ID &
|
|||||||
case BOOLEAN_OP:
|
case BOOLEAN_OP:
|
||||||
if(0==rhs())
|
if(0==rhs())
|
||||||
return false;
|
return false;
|
||||||
res = rhs()->xClear ( f, t, lastBBinst, locId);
|
res = rhs()->xClear ( range_to_check, lastBBinst, locId);
|
||||||
if (res == false)
|
if (res == false)
|
||||||
return false;
|
return false;
|
||||||
if(0==lhs())
|
if(0==lhs())
|
||||||
return false;
|
return false;
|
||||||
return lhs()->xClear ( f, t, lastBBinst, locId);
|
return lhs()->xClear ( range_to_check, lastBBinst, locId);
|
||||||
|
|
||||||
case NEGATION:
|
case NEGATION:
|
||||||
case ADDRESSOF:
|
case ADDRESSOF:
|
||||||
case DEREFERENCE:
|
case DEREFERENCE:
|
||||||
if(0==expr.unaryExp)
|
if(0==expr.unaryExp)
|
||||||
return false;
|
return false;
|
||||||
return expr.unaryExp->xClear ( f, t, lastBBinst, locId);
|
return expr.unaryExp->xClear ( range_to_check, lastBBinst, locId);
|
||||||
} /* eos */
|
} /* eos */
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool UnaryOperator::xClear(iICODE f, iICODE t, iICODE lastBBinst, const LOCAL_ID &locs)
|
bool UnaryOperator::xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &locs)
|
||||||
{
|
{
|
||||||
if(0==unaryExp)
|
if(0==unaryExp)
|
||||||
return false;
|
return false;
|
||||||
return unaryExp->xClear ( f, t, lastBBinst, locs);
|
return unaryExp->xClear ( range_to_check, lastBBinst, locs);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BinaryOperator::xClear(iICODE f, iICODE t, iICODE lastBBinst, const LOCAL_ID &locs)
|
bool BinaryOperator::xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &locs)
|
||||||
{
|
{
|
||||||
if(0==m_rhs)
|
if(0==m_rhs)
|
||||||
return false;
|
return false;
|
||||||
if ( ! m_rhs->xClear (f, t, lastBBinst, locs) )
|
if ( ! m_rhs->xClear (range_to_check, lastBBinst, locs) )
|
||||||
return false;
|
return false;
|
||||||
if(0==m_lhs)
|
if(0==m_lhs)
|
||||||
return false;
|
return false;
|
||||||
return m_lhs->xClear (f, t, lastBBinst, locs);
|
return m_lhs->xClear (range_to_check, lastBBinst, locs);
|
||||||
}
|
}
|
||||||
/* Checks the type of the formal argument as against to the actual argument,
|
/* Checks the type of the formal argument as against to the actual argument,
|
||||||
* whenever possible, and then places the actual argument on the procedure's
|
* whenever possible, and then places the actual argument on the procedure's
|
||||||
@ -840,10 +839,11 @@ int BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
|||||||
uint8_t regi;
|
uint8_t regi;
|
||||||
numHlIcodes = 0;
|
numHlIcodes = 0;
|
||||||
// register(s) to be forward substituted */
|
// register(s) to be forward substituted */
|
||||||
for (iICODE picode = begin(); picode != end(); picode++)
|
auto valid_and_highlevel = instructions | filtered(ICODE::TypeAndValidFilter<HIGH_LEVEL>());
|
||||||
|
for (auto picode = valid_and_highlevel.begin(); picode != valid_and_highlevel.end(); picode++)
|
||||||
{
|
{
|
||||||
if ((picode->type != HIGH_LEVEL) || ( ! picode->valid() ))
|
// if ((picode->type != HIGH_LEVEL) || ( ! picode->valid() ))
|
||||||
continue;
|
// continue;
|
||||||
HLTYPE &_icHl(*picode->hl());
|
HLTYPE &_icHl(*picode->hl());
|
||||||
numHlIcodes++;
|
numHlIcodes++;
|
||||||
if (picode->du1.numRegsDef == 1) /* uint8_t/uint16_t regs */
|
if (picode->du1.numRegsDef == 1) /* uint8_t/uint16_t regs */
|
||||||
@ -870,11 +870,10 @@ int BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
|||||||
(ticode->hl()->opcode != HLI_RET)))
|
(ticode->hl()->opcode != HLI_RET)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (_icHl.asgn.rhs->xClear (picode,
|
if (_icHl.asgn.rhs->xClear (make_iterator_range(picode.base(),picode->du1.idx[0].uses[0]),
|
||||||
picode->du1.idx[0].uses[0],
|
|
||||||
end(), locals))
|
end(), locals))
|
||||||
{
|
{
|
||||||
locals.processTargetIcode(picode, numHlIcodes, ticode,false);
|
locals.processTargetIcode(picode.base(), numHlIcodes, ticode,false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -889,7 +888,7 @@ int BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
|||||||
_exp = g_exp_stk.pop(); /* pop last exp pushed */
|
_exp = g_exp_stk.pop(); /* pop last exp pushed */
|
||||||
switch (ticode->hl()->opcode) {
|
switch (ticode->hl()->opcode) {
|
||||||
case HLI_ASSIGN:
|
case HLI_ASSIGN:
|
||||||
locals.forwardSubs(_icHl.expr(), _exp, picode, ticode, numHlIcodes);
|
locals.forwardSubs(_icHl.expr(), _exp, picode.base(), ticode, numHlIcodes);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HLI_JCOND: case HLI_PUSH: case HLI_RET:
|
case HLI_JCOND: case HLI_PUSH: case HLI_RET:
|
||||||
@ -946,7 +945,7 @@ int BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
|||||||
else /* cannot substitute function */
|
else /* cannot substitute function */
|
||||||
{
|
{
|
||||||
//picode->loc_ip
|
//picode->loc_ip
|
||||||
lhs = COND_EXPR::idID(_retVal,&locals,picode);
|
lhs = COND_EXPR::idID(_retVal,&locals,picode.base());
|
||||||
picode->setAsgn(lhs, _exp);
|
picode->setAsgn(lhs, _exp);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -975,7 +974,7 @@ int BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
|||||||
((ticode->hl()->opcode != HLI_CALL) &&
|
((ticode->hl()->opcode != HLI_CALL) &&
|
||||||
(ticode->hl()->opcode != HLI_RET)))
|
(ticode->hl()->opcode != HLI_RET)))
|
||||||
continue;
|
continue;
|
||||||
locals.processTargetIcode(picode, numHlIcodes, ticode,true);
|
locals.processTargetIcode(picode.base(), numHlIcodes, ticode,true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -992,7 +991,7 @@ int BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
|||||||
switch (ticode->hl()->opcode) {
|
switch (ticode->hl()->opcode) {
|
||||||
case HLI_ASSIGN:
|
case HLI_ASSIGN:
|
||||||
forwardSubsLong (_icHl.expr()->expr.ident.idNode.longIdx,
|
forwardSubsLong (_icHl.expr()->expr.ident.idNode.longIdx,
|
||||||
_exp, picode, ticode, &numHlIcodes);
|
_exp, picode.base(), ticode, &numHlIcodes);
|
||||||
break;
|
break;
|
||||||
case HLI_JCOND: case HLI_PUSH:
|
case HLI_JCOND: case HLI_PUSH:
|
||||||
res = COND_EXPR::insertSubTreeLongReg (_exp,
|
res = COND_EXPR::insertSubTreeLongReg (_exp,
|
||||||
@ -1017,7 +1016,7 @@ int BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
|||||||
case HLI_ASSIGN:
|
case HLI_ASSIGN:
|
||||||
_exp = _icHl.call.toId();
|
_exp = _icHl.call.toId();
|
||||||
ticode->hl()->asgn.lhs =
|
ticode->hl()->asgn.lhs =
|
||||||
COND_EXPR::idLong(&locals, DST, ticode,HIGH_FIRST, picode, eDEF, ++iICODE(ticode));
|
COND_EXPR::idLong(&locals, DST, ticode,HIGH_FIRST, picode.base(), eDEF, ++iICODE(ticode));
|
||||||
ticode->hl()->asgn.rhs = _exp;
|
ticode->hl()->asgn.rhs = _exp;
|
||||||
picode->invalidate();
|
picode->invalidate();
|
||||||
numHlIcodes--;
|
numHlIcodes--;
|
||||||
@ -1035,7 +1034,7 @@ int BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
|||||||
res = COND_EXPR::insertSubTreeLongReg (_exp,
|
res = COND_EXPR::insertSubTreeLongReg (_exp,
|
||||||
&ticode->hl()->exp.v,
|
&ticode->hl()->exp.v,
|
||||||
locals.newLongReg ( _retVal->type, _retVal->id.longId.h,
|
locals.newLongReg ( _retVal->type, _retVal->id.longId.h,
|
||||||
_retVal->id.longId.l, picode));
|
_retVal->id.longId.l, picode.base()));
|
||||||
if (res) /* was substituted */
|
if (res) /* was substituted */
|
||||||
{
|
{
|
||||||
picode->invalidate();
|
picode->invalidate();
|
||||||
@ -1043,7 +1042,7 @@ int BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
|||||||
}
|
}
|
||||||
else /* cannot substitute function */
|
else /* cannot substitute function */
|
||||||
{
|
{
|
||||||
lhs = locals.createId(_retVal,picode);
|
lhs = locals.createId(_retVal,picode.base());
|
||||||
picode->setAsgn(lhs, _exp);
|
picode->setAsgn(lhs, _exp);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1056,7 +1055,7 @@ int BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
|||||||
* expression stack */
|
* expression stack */
|
||||||
else if (_icHl.opcode == HLI_PUSH)
|
else if (_icHl.opcode == HLI_PUSH)
|
||||||
{
|
{
|
||||||
g_exp_stk.processExpPush(numHlIcodes, picode);
|
g_exp_stk.processExpPush(numHlIcodes, picode.base());
|
||||||
}
|
}
|
||||||
else if(picode->du1.numRegsDef!=0)
|
else if(picode->du1.numRegsDef!=0)
|
||||||
printf("Num def %d\n",picode->du1.numRegsDef);
|
printf("Num def %d\n",picode->du1.numRegsDef);
|
||||||
@ -1068,7 +1067,7 @@ int BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
|||||||
{
|
{
|
||||||
if ( not _icHl.call.proc->hasRegArgs())
|
if ( not _icHl.call.proc->hasRegArgs())
|
||||||
{
|
{
|
||||||
fnc->processHliCall(_exp, picode);
|
fnc->processHliCall(_exp, picode.base());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we could not substitute the result of a function,
|
/* If we could not substitute the result of a function,
|
||||||
@ -1076,7 +1075,7 @@ int BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
|||||||
if ( not _icHl.call.proc->isLibrary() and (not picode->du1.used(0)) and (picode->du1.numRegsDef > 0))
|
if ( not _icHl.call.proc->isLibrary() and (not picode->du1.used(0)) and (picode->du1.numRegsDef > 0))
|
||||||
{
|
{
|
||||||
_exp = COND_EXPR::idFunc (_icHl.call.proc, _icHl.call.args);
|
_exp = COND_EXPR::idFunc (_icHl.call.proc, _icHl.call.args);
|
||||||
lhs = COND_EXPR::idID (&_icHl.call.proc->retVal, &locals, picode);
|
lhs = COND_EXPR::idID (&_icHl.call.proc->retVal, &locals, picode.base());
|
||||||
picode->setAsgn(lhs, _exp);
|
picode->setAsgn(lhs, _exp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user