extracted FunctionCfg as it's own class
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#include <string>
|
||||
#include <llvm/ADT/ilist.h>
|
||||
#include <llvm/ADT/ilist_node.h>
|
||||
#include <boost/range.hpp>
|
||||
#include <boost/range/iterator_range.hpp>
|
||||
#include "icode.h"
|
||||
#include "types.h"
|
||||
#include "graph.h"
|
||||
@@ -27,10 +27,9 @@ struct TYPEADR_TYPE
|
||||
TYPEADR_TYPE(interval *v) : ip(0),BBptr(nullptr),intPtr(v)
|
||||
{}
|
||||
};
|
||||
|
||||
struct BB : public llvm::ilist_node<BB>
|
||||
{
|
||||
|
||||
friend struct Function;
|
||||
private:
|
||||
BB(const BB&);
|
||||
BB() : nodeType(0),traversed(DFS_NONE),
|
||||
@@ -46,6 +45,7 @@ private:
|
||||
//friend class SymbolTableListTraits<BB, Function>;
|
||||
typedef boost::iterator_range<iICODE> rCODE;
|
||||
rCODE instructions;
|
||||
rCODE &my_range() {return instructions;}
|
||||
|
||||
public:
|
||||
struct ValidFunctor
|
||||
@@ -77,29 +77,25 @@ public:
|
||||
interval *inInterval; /* Node's interval */
|
||||
|
||||
/* For derived sequence construction */
|
||||
interval *correspInt; /* Corresponding interval in
|
||||
* derived graph Gi-1 */
|
||||
|
||||
/* For live register analysis
|
||||
* LiveIn(b) = LiveUse(b) U (LiveOut(b) - Def(b)) */
|
||||
std::bitset<32> liveUse; /* LiveUse(b) */
|
||||
std::bitset<32> def; /* Def(b) */
|
||||
std::bitset<32> liveIn; /* LiveIn(b) */
|
||||
std::bitset<32> liveOut; /* LiveOut(b) */
|
||||
interval *correspInt; //!< Corresponding interval in derived graph Gi-1
|
||||
// For live register analysis
|
||||
// LiveIn(b) = LiveUse(b) U (LiveOut(b) - Def(b))
|
||||
LivenessSet liveUse; /* LiveUse(b) */
|
||||
LivenessSet def; /* Def(b) */
|
||||
LivenessSet liveIn; /* LiveIn(b) */
|
||||
LivenessSet liveOut; /* LiveOut(b) */
|
||||
|
||||
/* For structuring analysis */
|
||||
int dfsFirstNum; /* DFS #: first visit of node */
|
||||
int dfsLastNum; /* DFS #: last visit of node */
|
||||
int immedDom; /* Immediate dominator (dfsLast
|
||||
* index) */
|
||||
int immedDom; /* Immediate dominator (dfsLast index) */
|
||||
int ifFollow; /* node that ends the if */
|
||||
int loopType; /* Type of loop (if any) */
|
||||
int latchNode; /* latching node of the loop */
|
||||
size_t numBackEdges; /* # of back edges */
|
||||
int loopHead; /* most nested loop head to which this node belongs (dfsLast) */
|
||||
int loopFollow; /* node that follows the loop */
|
||||
int caseHead; /* most nested case to which this
|
||||
node belongs (dfsLast) */
|
||||
int caseHead; /* most nested case to which this node belongs (dfsLast) */
|
||||
int caseTail; /* tail node for the case */
|
||||
|
||||
int index; /* Index, used in several ways */
|
||||
@@ -134,7 +130,7 @@ public:
|
||||
void RemoveUnusedDefs(eReg regi, int defRegIdx, iICODE picode);
|
||||
private:
|
||||
bool FindUseBeforeDef(eReg regi, int defRegIdx, iICODE start_at);
|
||||
void ProcessUseDefForFunc(eReg regi, int defRegIdx, iICODE picode);
|
||||
void ProcessUseDefForFunc(eReg regi, int defRegIdx, ICODE &picode);
|
||||
bool isEndOfPath(int latch_node_idx) const;
|
||||
Function *Parent;
|
||||
|
||||
|
||||
@@ -86,7 +86,26 @@ struct JumpTable
|
||||
size_t entrySize() { return 2;}
|
||||
void pruneEntries(uint16_t cs);
|
||||
};
|
||||
|
||||
class FunctionCfg
|
||||
{
|
||||
std::list<BB*> m_listBB; /* Ptr. to BB list/CFG */
|
||||
public:
|
||||
typedef std::list<BB*>::iterator iterator;
|
||||
iterator begin() {
|
||||
return m_listBB.begin();
|
||||
}
|
||||
iterator end() {
|
||||
return m_listBB.end();
|
||||
}
|
||||
BB * &front() { return m_listBB.front();}
|
||||
void nodeSplitting()
|
||||
{
|
||||
/* Converts the irreducible graph G into an equivalent reducible one, by
|
||||
* means of node splitting. */
|
||||
fprintf(stderr,"Attempt to perform node splitting: NOT IMPLEMENTED\n");
|
||||
}
|
||||
void push_back(BB *v) { m_listBB.push_back(v);}
|
||||
};
|
||||
struct Function : public llvm::ilist_node<Function>
|
||||
{
|
||||
typedef llvm::iplist<BB> BasicBlockListType;
|
||||
@@ -109,6 +128,7 @@ public:
|
||||
|
||||
/* Icodes and control flow graph */
|
||||
CIcodeRec Icode; /* Object with ICODE records */
|
||||
FunctionCfg m_actual_cfg;
|
||||
std::list<BB*> m_cfg; /* Ptr. to BB list/CFG */
|
||||
std::vector<BB*> m_dfsLast;
|
||||
std::list<BB*> heldBBs;
|
||||
@@ -118,9 +138,9 @@ public:
|
||||
bool hasCase; /* Procedure has a case node */
|
||||
|
||||
/* For interprocedural live analysis */
|
||||
std::bitset<32> liveIn; /* Registers used before defined */
|
||||
std::bitset<32> liveOut; /* Registers that may be used in successors */
|
||||
bool liveAnal; /* Procedure has been analysed already */
|
||||
LivenessSet liveIn; /* Registers used before defined */
|
||||
LivenessSet liveOut; /* Registers that may be used in successors */
|
||||
bool liveAnal; /* Procedure has been analysed already */
|
||||
|
||||
Function(void */*ty*/=0) : procEntry(0),depth(0),flg(0),cbParam(0),m_cfg(0),m_dfsLast(0),numBBs(0),
|
||||
hasCase(false),liveIn(0),liveOut(0),liveAnal(0)//,next(0),prev(0)
|
||||
@@ -140,7 +160,7 @@ public:
|
||||
void writeProcComments();
|
||||
void lowLevelAnalysis();
|
||||
void bindIcodeOff();
|
||||
void dataFlow(std::bitset<32> &liveOut);
|
||||
void dataFlow(LivenessSet &liveOut);
|
||||
void compressCFG();
|
||||
void highLevelGen();
|
||||
void structure(derSeq *derivedG);
|
||||
@@ -166,7 +186,7 @@ public:
|
||||
void displayStats();
|
||||
void processHliCall(COND_EXPR *exp, iICODE picode);
|
||||
|
||||
void preprocessReturnDU(std::bitset<32> &_liveOut);
|
||||
void preprocessReturnDU(LivenessSet &_liveOut);
|
||||
protected:
|
||||
void extractJumpTableRange(ICODE& pIcode, STATE *pstate, JumpTable &table);
|
||||
bool followAllTableEntries(JumpTable &table, uint32_t cs, ICODE &pIcode, CALL_GRAPH *pcallGraph, STATE *pstate);
|
||||
@@ -190,7 +210,7 @@ protected:
|
||||
void findExps();
|
||||
void genDU1();
|
||||
void elimCondCodes();
|
||||
void liveRegAnalysis(std::bitset<32> &in_liveOut);
|
||||
void liveRegAnalysis(LivenessSet &in_liveOut);
|
||||
void findIdioms();
|
||||
void propLong();
|
||||
void genLiveKtes();
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
#pragma once
|
||||
#include <cstring>
|
||||
#include <list>
|
||||
#include <boost/range/iterator_range.hpp>
|
||||
#include "Enums.h"
|
||||
#include <boost/range.hpp>
|
||||
static const int operandSize=20;
|
||||
/* The following definitions and types define the Conditional Expression
|
||||
* attributed syntax tree, as defined by the following EBNF:
|
||||
|
||||
@@ -62,10 +62,10 @@ typedef struct { /* Command line option flags */
|
||||
extern OPTION option; /* Command line options */
|
||||
|
||||
#include "BinaryImage.h"
|
||||
extern std::bitset<32> duReg[30]; /* def/use bits for registers */
|
||||
extern LivenessSet duReg[30]; /* def/use bits for registers */
|
||||
|
||||
//extern uint32_t duReg[30]; /* def/use bits for registers */
|
||||
extern std::bitset<32> maskDuReg[30]; /* masks off du bits for regs */
|
||||
extern LivenessSet maskDuReg[30]; /* masks off du bits for regs */
|
||||
|
||||
/* Registers used by icode instructions */
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
/****************************************************************************
|
||||
* dcc project disassembler header
|
||||
* (C) Mike van Emmerik
|
||||
****************************************************************************/
|
||||
/*
|
||||
***************************************************************************
|
||||
dcc project disassembler header
|
||||
(C) Mike van Emmerik
|
||||
***************************************************************************
|
||||
*/
|
||||
#pragma once
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include "bundle.h"
|
||||
@@ -32,24 +33,6 @@ public:
|
||||
|
||||
#define EXT 0x100 /* "Extended" flag */
|
||||
|
||||
#ifdef __MSDOS__
|
||||
#define KEY_DOWN EXT+'P'
|
||||
#define KEY_LEFT EXT+'K'
|
||||
#define KEY_UP EXT+'H'
|
||||
#define KEY_RIGHT EXT+'M'
|
||||
#define KEY_NPAGE EXT+'Q'
|
||||
#define KEY_PPAGE EXT+'I'
|
||||
#endif
|
||||
|
||||
#ifdef _CONSOLE
|
||||
#define KEY_DOWN 0x50 /* Same as keypad scancodes */
|
||||
#define KEY_LEFT 0x4B
|
||||
#define KEY_UP 0x48
|
||||
#define KEY_RIGHT 0x4D
|
||||
#define KEY_NPAGE 0x51
|
||||
#define KEY_PPAGE 0x49
|
||||
#endif
|
||||
|
||||
#ifdef __UNIX__
|
||||
#define KEY_DOWN EXT+'B'
|
||||
#define KEY_LEFT EXT+'D'
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
/***************************************************************************
|
||||
/*
|
||||
|
||||
=**************************************************************************
|
||||
* File : dosdcc.h
|
||||
* Purpose : include file for files decompiled by dcc.
|
||||
* Copyright (c) Cristina Cifuentes - QUT - 1992
|
||||
**************************************************************************/
|
||||
*************************************************************************
|
||||
*/
|
||||
|
||||
/* Type definitions for intel 80x86 architecture */
|
||||
typedef unsigned int uint16_t; /* 16 bits */
|
||||
@@ -18,7 +21,7 @@ typedef struct {
|
||||
uint16_t lowBitWord : 1;
|
||||
uint16_t filler1 : 6;
|
||||
uint16_t highBitByte : 1;
|
||||
/* high uint8_t */
|
||||
/* high uint8_t */
|
||||
uint16_t lowBitByte : 1;
|
||||
uint16_t filler2 : 6;
|
||||
uint16_t highBitWord : 1;
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
/*****************************************************************************
|
||||
/*
|
||||
****************************************************************************
|
||||
* CFG, BB and interval related definitions
|
||||
* (C) Cristina Cifuentes
|
||||
****************************************************************************/
|
||||
* ( C ) Cristina Cifuentes
|
||||
****************************************************************************
|
||||
*/
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
struct Function;
|
||||
/* Types of basic block nodes */
|
||||
/* Real basic blocks: type defined according to their out-edges */
|
||||
@@ -55,6 +58,7 @@ enum eNodeHeaderType
|
||||
#define ELSE 1 /* else edge */
|
||||
|
||||
/* Basic Block (BB) flags */
|
||||
|
||||
#define INVALID_BB 0x0001 /* BB is not valid any more */
|
||||
#define IS_LATCH_NODE 0x0002 /* BB is the latching node of a loop */
|
||||
|
||||
@@ -64,8 +68,8 @@ typedef std::list<BB *> queue;
|
||||
|
||||
struct interval
|
||||
{
|
||||
uint8_t numInt; /* # of the interval */
|
||||
uint8_t numOutEdges; /* Number of out edges */
|
||||
uint8_t numInt; /* # of the interval */
|
||||
uint8_t numOutEdges; /* Number of out edges */
|
||||
queue nodes; /* Nodes of the interval*/
|
||||
queue::iterator currNode; /* Current node */
|
||||
interval *next; /* Next interval */
|
||||
@@ -76,6 +80,7 @@ struct interval
|
||||
currNode=nodes.end();
|
||||
next=0;
|
||||
}
|
||||
void appendNodeInt(queue &pqH, BB *node);
|
||||
};
|
||||
|
||||
|
||||
@@ -83,6 +88,7 @@ struct interval
|
||||
struct derSeq_Entry
|
||||
{
|
||||
BB * Gi; /* Graph pointer */
|
||||
std::list<interval *> m_intervals;
|
||||
interval * Ii; /* Interval list of Gi */
|
||||
derSeq_Entry() : Gi(0),Ii(0)
|
||||
{
|
||||
|
||||
@@ -9,12 +9,9 @@
|
||||
#include <bitset>
|
||||
#include <llvm/ADT/ilist.h>
|
||||
#include <llvm/ADT/ilist_node.h>
|
||||
#include <llvm/CodeGen/MachineInstr.h>
|
||||
#include <llvm/MC/MCInst.h>
|
||||
#include <llvm/MC/MCAsmInfo.h>
|
||||
#include <llvm/Value.h>
|
||||
#include <llvm/Instruction.h>
|
||||
#include <boost/range.hpp>
|
||||
#include <boost/range/iterator_range.hpp>
|
||||
#include "libdis.h"
|
||||
#include "Enums.h"
|
||||
#include "state.h" // State depends on INDEXBASE, but later need STATE
|
||||
@@ -32,7 +29,45 @@ typedef std::list<ICODE>::iterator iICODE;
|
||||
typedef std::list<ICODE>::reverse_iterator riICODE;
|
||||
typedef boost::iterator_range<iICODE> rCODE;
|
||||
|
||||
extern std::bitset<32> duReg[30];
|
||||
struct LivenessSet : public std::bitset<32>
|
||||
{
|
||||
LivenessSet(int val=0) : std::bitset<32>(val) {}
|
||||
LivenessSet(const LivenessSet &other)
|
||||
{
|
||||
(std::bitset<32> &)*this = (std::bitset<32> &)other;
|
||||
}
|
||||
LivenessSet(const std::bitset<32> &other)
|
||||
{
|
||||
(std::bitset<32> &)*this = other;
|
||||
}
|
||||
// LivenessSet(LivenessSet &&other) : LivenessSet()
|
||||
// {
|
||||
// swap(*this,other);
|
||||
// }
|
||||
LivenessSet &operator=(LivenessSet other)
|
||||
{
|
||||
swap(*this,other);
|
||||
return *this;
|
||||
}
|
||||
friend void swap(LivenessSet& first, LivenessSet& second) // nothrow
|
||||
{
|
||||
// enable ADL (not necessary in our case, but good practice)
|
||||
using std::swap;
|
||||
|
||||
// by swapping the members of two classes,
|
||||
// the two classes are effectively swapped
|
||||
swap((std::bitset<32> &)first, (std::bitset<32> &)second);
|
||||
}
|
||||
|
||||
LivenessSet &setReg(int r);
|
||||
LivenessSet &addReg(int r);
|
||||
bool testReg(int r)
|
||||
{
|
||||
return test(r-rAX);
|
||||
}
|
||||
};
|
||||
|
||||
extern LivenessSet duReg[30];
|
||||
/* uint8_t and uint16_t registers */
|
||||
|
||||
/* Def/use of flags - low 4 bits represent flags */
|
||||
@@ -350,14 +385,13 @@ public:
|
||||
use.reset();
|
||||
lastDefRegi.reset();
|
||||
}
|
||||
std::bitset<32> def; // For Registers: position in bitset is reg index
|
||||
std::bitset<32> use; // For Registers: position in uint32_t is reg index
|
||||
std::bitset<32> lastDefRegi;// Bit set if last def of this register in BB
|
||||
LivenessSet def; // For Registers: position in bitset is reg index
|
||||
LivenessSet use; // For Registers: position in uint32_t is reg index
|
||||
LivenessSet lastDefRegi;// Bit set if last def of this register in BB
|
||||
void addDefinedAndUsed(eReg r)
|
||||
{
|
||||
def |= duReg[r];
|
||||
use |= duReg[r];
|
||||
|
||||
def.addReg(r);
|
||||
use.addReg(r);
|
||||
}
|
||||
};
|
||||
struct DU1
|
||||
|
||||
@@ -73,7 +73,7 @@ public:
|
||||
ostr << regName(eReg(j))<<" ";
|
||||
}
|
||||
}
|
||||
static eReg subRegH(eReg reg); //TODO: move these into machine_x86
|
||||
static eReg subRegH(eReg reg);
|
||||
static eReg subRegL(eReg reg);
|
||||
|
||||
static bool isMemOff(eReg r);
|
||||
|
||||
@@ -3,10 +3,7 @@
|
||||
hashing functions
|
||||
* (C) Mike van Emmerik
|
||||
*/
|
||||
|
||||
//#define bool unsigned char
|
||||
#define uint8_t unsigned char
|
||||
#define uint16_t unsigned short
|
||||
#include <stdint.h>
|
||||
|
||||
/* Prototypes */
|
||||
void hashCleanup(void); /* Frees memory allocated by hashParams() */
|
||||
|
||||
Reference in New Issue
Block a user