LLOperand no longer inherits from llvm::MCOperand, it contains one

instead.
Added BB accessors to ICODE and typedef'd BB to MachineBasicBlock
Removed an unused method in ICODE, and a parameter in isLong23
This commit is contained in:
Artur K 2012-03-17 22:38:54 +01:00
parent 467ff56356
commit dc8e7156a8
4 changed files with 40 additions and 27 deletions

View File

@ -13,9 +13,12 @@
#include <llvm/MC/MCInst.h> #include <llvm/MC/MCInst.h>
#include <llvm/MC/MCAsmInfo.h> #include <llvm/MC/MCAsmInfo.h>
#include <llvm/Value.h> #include <llvm/Value.h>
#include <llvm/Instruction.h>
#include <boost/range.hpp> #include <boost/range.hpp>
#include "libdis.h"
#include "Enums.h" #include "Enums.h"
#include "state.h" // State depends on INDEXBASE, but later need STATE #include "state.h" // State depends on INDEXBASE, but later need STATE
//enum condId; //enum condId;
struct LOCAL_ID; struct LOCAL_ID;
@ -163,11 +166,12 @@ public:
void setAsgn(COND_EXPR *lhs, COND_EXPR *rhs); void setAsgn(COND_EXPR *lhs, COND_EXPR *rhs);
} ; } ;
/* LOW_LEVEL icode operand record */ /* LOW_LEVEL icode operand record */
struct LLOperand : public llvm::MCOperand struct LLOperand
{ {
llvm::MCOperand llvm_op;
eReg seg; /* CS, DS, ES, SS */ eReg seg; /* CS, DS, ES, SS */
int16_t segValue; /* Value of segment seg during analysis */
eReg segOver; /* CS, DS, ES, SS if segment override */ eReg segOver; /* CS, DS, ES, SS if segment override */
int16_t segValue; /* Value of segment seg during analysis */
eReg regi; /* 0 < regs < INDEXBASE <= index modes */ eReg regi; /* 0 < regs < INDEXBASE <= index modes */
int16_t off; /* memory address offset */ int16_t off; /* memory address offset */
uint32_t opz; /* idx of immed src op */ uint32_t opz; /* idx of immed src op */
@ -219,7 +223,6 @@ public:
} }
flg &= ~flag; flg &= ~flag;
} }
uint32_t getFlag() const {return flg;} uint32_t getFlag() const {return flg;}
//llIcode getOpcode() const { return opcode; } //llIcode getOpcode() const { return opcode; }
@ -283,11 +286,15 @@ public:
/* Icode definition: LOW_LEVEL and HIGH_LEVEL */ /* Icode definition: LOW_LEVEL and HIGH_LEVEL */
struct ICODE struct ICODE
{ {
// use llvm names at least
typedef BB MachineBasicBlock;
protected: protected:
LLInst m_ll; LLInst m_ll;
HLTYPE m_hl; HLTYPE m_hl;
MachineBasicBlock * Parent; /* BB to which this icode belongs */
bool invalid; /* Has no HIGH_LEVEL equivalent */ bool invalid; /* Has no HIGH_LEVEL equivalent */
public: public:
x86_insn_t insn;
template<int FLAG> template<int FLAG>
struct FlagFilter struct FlagFilter
{ {
@ -306,6 +313,8 @@ public:
bool operator()(ICODE *ic) {return (ic->type==HIGH_LEVEL)&&(ic->valid());} bool operator()(ICODE *ic) {return (ic->type==HIGH_LEVEL)&&(ic->valid());}
bool operator()(ICODE &ic) {return (ic.type==HIGH_LEVEL)&&ic.valid();} bool operator()(ICODE &ic) {return (ic.type==HIGH_LEVEL)&&ic.valid();}
}; };
static TypeFilter<HIGH_LEVEL> select_high_level;
static TypeAndValidFilter<HIGH_LEVEL> select_valid_high_level;
/* Def/Use of registers and stack variables */ /* Def/Use of registers and stack variables */
struct DU_ICODE struct DU_ICODE
{ {
@ -366,7 +375,6 @@ public:
} }
}; };
icodeType type; /* Icode type */ icodeType type; /* Icode type */
BB *inBB; /* BB to which this icode belongs */
DU_ICODE du; /* Def/use regs/vars */ DU_ICODE du; /* Def/use regs/vars */
DU1 du1; /* du chain 1 */ DU1 du1; /* du chain 1 */
int loc_ip; // used by CICodeRec to number ICODEs int loc_ip; // used by CICodeRec to number ICODEs
@ -396,6 +404,7 @@ public:
void emitGotoLabel(int indLevel); void emitGotoLabel(int indLevel);
void copyDU(const ICODE &duIcode, operDu _du, operDu duDu); void copyDU(const ICODE &duIcode, operDu _du, operDu duDu);
bool valid() {return not invalid;} bool valid() {return not invalid;}
void setParent(MachineBasicBlock *P) { Parent = P; }
public: public:
bool removeDefRegi(eReg regi, int thisDefIdx, LOCAL_ID *locId); bool removeDefRegi(eReg regi, int thisDefIdx, LOCAL_ID *locId);
void checkHlCall(); void checkHlCall();
@ -403,14 +412,24 @@ public:
{ {
return hl()->call.newStkArg(exp,opcode,pproc); return hl()->call.newStkArg(exp,opcode,pproc);
} }
ICODE() : m_ll(this),type(NOT_SCANNED),inBB(0),loc_ip(0),invalid(false) ICODE() : m_ll(this),type(NOT_SCANNED),Parent(0),loc_ip(0),invalid(false)
{ {
} }
public:
const MachineBasicBlock* getParent() const { return Parent; }
MachineBasicBlock* getParent() { return Parent; }
//unsigned getNumOperands() const { return (unsigned)Operands.size(); }
}; };
/** Map n low level instructions to m high level instructions
*/
struct MappingLLtoML struct MappingLLtoML
{ {
std::list<std::shared_ptr<LLInst> > m_low_level; typedef llvm::iplist<llvm::Instruction> InstListType;
std::list<std::shared_ptr<HLTYPE> > m_middle_level; typedef boost::iterator_range<iICODE> rSourceRange;
typedef boost::iterator_range<InstListType::iterator> rTargetRange;
rSourceRange m_low_level;
rTargetRange m_middle_level;
}; };
// This is the icode array object. // This is the icode array object.
class CIcodeRec : public std::list<ICODE> class CIcodeRec : public std::list<ICODE>

View File

@ -20,6 +20,7 @@
// TODO: why ? // TODO: why ?
struct COND_EXPR; struct COND_EXPR;
struct ICODE; struct ICODE;
struct LLInst;
typedef std::list<ICODE>::iterator iICODE; typedef std::list<ICODE>::iterator iICODE;
struct IDX_ARRAY : public std::vector<iICODE> struct IDX_ARRAY : public std::vector<iICODE>
{ {
@ -49,11 +50,12 @@ typedef struct
int offH; /* high offset from BP */ int offH; /* high offset from BP */
int offL; /* low offset from BP */ int offL; /* low offset from BP */
} LONG_STKID_TYPE; } LONG_STKID_TYPE;
typedef struct struct LONGID_TYPE
{ /* For TYPE_LONG_(UN)SIGN registers */ { /* For TYPE_LONG_(UN)SIGN registers */
eReg h; /* high register */ eReg h; /* high register */
eReg l; /* low register */ eReg l; /* low register */
} LONGID_TYPE; bool srcDstRegMatch(iICODE a,iICODE b) const;
};
/* ID, LOCAL_ID */ /* ID, LOCAL_ID */

View File

@ -12,7 +12,8 @@
#define ICODE_DELTA 25 // Amount to allocate for new chunk #define ICODE_DELTA 25 // Amount to allocate for new chunk
ICODE::TypeFilter<HIGH_LEVEL> ICODE::select_high_level;
ICODE::TypeAndValidFilter<HIGH_LEVEL> ICODE::select_valid_high_level;
CIcodeRec::CIcodeRec() CIcodeRec::CIcodeRec()
{ {
} }
@ -27,20 +28,11 @@ ICODE * CIcodeRec::addIcode(ICODE *pIcode)
return &back(); return &back();
} }
void CIcodeRec::SetInBB(int start, int _end, BB *pnewBB)
{
for(ICODE &icode : *this)
{
if((icode.loc_ip>=start) and (icode.loc_ip<=_end))
icode.inBB = pnewBB;
}
}
void CIcodeRec::SetInBB(rCODE &rang, BB *pnewBB) void CIcodeRec::SetInBB(rCODE &rang, BB *pnewBB)
{ {
for(ICODE &ic : rang) for(ICODE &ic : rang)
{ {
ic.inBB = pnewBB; ic.setParent(pnewBB);
} }
} }

View File

@ -22,7 +22,7 @@ static boolT isJCond (llIcode opcode)
/* Returns whether the conditions for a 2-3 long variable are satisfied */ /* Returns whether the conditions for a 2-3 long variable are satisfied */
static bool isLong23 (iICODE iter, BB * pbb, iICODE &off, int *arc) static bool isLong23 (BB * pbb, iICODE &off, int *arc)
{ {
BB * t, * e, * obb2; BB * t, * e, * obb2;
@ -90,7 +90,7 @@ static int longJCond23 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode, int arc,
if (arc == THEN) if (arc == THEN)
{ {
/* Find intermediate basic blocks and target block */ /* Find intermediate basic blocks and target block */
pbb = pIcode->inBB; pbb = pIcode->getParent();
obb1 = pbb->edges[THEN].BBptr; obb1 = pbb->edges[THEN].BBptr;
obb2 = obb1->edges[THEN].BBptr; obb2 = obb1->edges[THEN].BBptr;
tbb = obb2->edges[THEN].BBptr; tbb = obb2->edges[THEN].BBptr;
@ -116,7 +116,7 @@ static int longJCond23 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode, int arc,
else /* ELSE arc */ else /* ELSE arc */
{ {
/* Find intermediate basic blocks and target block */ /* Find intermediate basic blocks and target block */
pbb = pIcode->inBB; pbb = pIcode->getParent();
obb1 = pbb->edges[ELSE].BBptr; obb1 = pbb->edges[ELSE].BBptr;
obb2 = obb1->edges[THEN].BBptr; obb2 = obb1->edges[THEN].BBptr;
tbb = obb2->edges[THEN].BBptr; tbb = obb2->edges[THEN].BBptr;
@ -183,7 +183,7 @@ static int longJCond22 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode,iICODE pEn
icodes[1]->du.use |= icodes[2]->du.use; icodes[1]->du.use |= icodes[2]->du.use;
/* Adjust outEdges[0] to the new target basic block */ /* Adjust outEdges[0] to the new target basic block */
pbb = icodes[0]->inBB; pbb = icodes[0]->getParent();
if (pbb->back().loc_ip == icodes[1]->loc_ip) if (pbb->back().loc_ip == icodes[1]->loc_ip)
{ {
/* Find intermediate and target basic blocks */ /* Find intermediate and target basic blocks */
@ -277,9 +277,9 @@ void Function::propLongStk (int i, const ID &pLocId)
} /*eos*/ } /*eos*/
} }
} }
//TODO: Simplify this!
/* Check long conditional (i.e. 2 CMPs and 3 branches */ /* Check long conditional (i.e. 2 CMPs and 3 branches */
else if ((pIcode->ll()->getOpcode() == iCMP) && (isLong23 (pIcode, pIcode->inBB, l23, &arc))) else if ((pIcode->ll()->getOpcode() == iCMP) && (isLong23 (pIcode->getParent(), l23, &arc)))
{ {
if ( checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, l23) ) if ( checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, l23) )
{ {
@ -455,7 +455,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
} /* eos */ } /* eos */
/* Check long conditional (i.e. 2 CMPs and 3 branches */ /* Check long conditional (i.e. 2 CMPs and 3 branches */
else if ((pIcode->ll()->getOpcode() == iCMP) && (isLong23 (pIcode, pIcode->inBB, long_loc, &arc))) else if ((pIcode->ll()->getOpcode() == iCMP) && (isLong23 (pIcode->getParent(), long_loc, &arc)))
{ {
if (checkLongRegEq (pLocId.id.longId, pIcode, loc_ident_idx, this, asgn, long_loc)) if (checkLongRegEq (pLocId.id.longId, pIcode, loc_ident_idx, this, asgn, long_loc))
{ {