Ghidra Decompiler Analysis Engine
|
Go to the documentation of this file.
20 #ifndef __CPUI_HERITAGE__
21 #define __CPUI_HERITAGE__
45 typedef map<Address,SizePass>::iterator
iterator;
47 map<Address,SizePass> themap;
52 void erase(
iterator iter) { themap.erase(iter); }
53 iterator begin(
void) {
return themap.begin(); }
54 iterator end(
void) {
return themap.end(); }
55 void clear(
void) { themap.clear(); }
65 vector<vector<FlowBlock *> > queue;
69 void reset(int4 maxdepth);
72 bool empty(
void)
const {
return (curdepth==-1); }
93 void set(
AddrSpace *spc,int4 dl,int4 dcdl) {
94 space=spc; delay=dl; deadcodedelay=dcdl; deadremoved=0; warningissued=
false; loadGuardSearch =
false; }
95 bool isHeritaged(
void)
const {
return (space != (
AddrSpace *)0); }
97 deadremoved = 0; deadcodedelay = delay; warningissued =
false; loadGuardSearch =
false; }
123 op = o; spc = s; pointerBase=off; minimumOffset=0; maximumOffset=s->
getHighest(); step=0; analysisState=0;
126 PcodeOp *getOp(
void)
const {
return op; }
127 uintb getMinimum(
void)
const {
return minimumOffset; }
128 uintb getMaximum(
void)
const {
return maximumOffset; }
129 int4 getStep(
void)
const {
return step; }
131 bool isRangeLocked(
void)
const {
return (analysisState == 2); }
132 bool isValid(
OpCode opc)
const {
return (!op->isDead() && op->code() == opc); }
172 enum heritage_flags {
181 nonconstant_index = 1,
187 list<PcodeOp *>::const_iterator iter;
193 StackNode(
Varnode *v,uintb o,uint4 trav) {
196 iter = v->beginDescend();
204 vector<vector<FlowBlock *> > domchild;
205 vector<vector<FlowBlock *> > augment;
212 vector<FlowBlock *> merge;
213 vector<HeritageInfo> infolist;
214 list<LoadGuard> loadGuard;
215 list<LoadGuard> storeGuard;
216 vector<PcodeOp *> loadCopyOps;
217 void clearInfoList(
void);
225 void splitJoinLevel(vector<Varnode *> &lastcombo,vector<Varnode *> &nextlev,
JoinRecord *joinrec);
230 void processJoins(
void);
232 void removeRevisitedMarkers(
const vector<Varnode *> &remove,
const Address &addr,int4 size);
233 int4 collect(
Address addr,int4 size,vector<Varnode *> &read,vector<Varnode *> &write,vector<Varnode *> &input,vector<Varnode *> &remove)
const;
234 bool callOpIndirectEffect(
const Address &addr,int4 size,
PcodeOp *op)
const;
238 void splitPieces(
const vector<Varnode *> &vnlist,
PcodeOp *insertop,
const Address &addr,int4 size,
Varnode *startvn);
239 void findAddressForces(vector<PcodeOp *> ©Sinks,vector<PcodeOp *> &forces);
240 void propagateCopyAway(
PcodeOp *op);
241 void handleNewLoadCopies(
void);
242 void analyzeNewLoadGuards(
void);
245 bool protectFreeStores(
AddrSpace *spc,vector<PcodeOp *> &freeStores);
246 bool discoverIndexedStackPointers(
AddrSpace *spc,vector<PcodeOp *> &freeStores,
bool checkFreeStores);
247 void reprocessFreeStores(
AddrSpace *spc,vector<PcodeOp *> &freeStores);
248 void guard(
const Address &addr,int4 size,vector<Varnode *> &read,vector<Varnode *> &write,vector<Varnode *> &inputvars);
249 void guardInput(
const Address &addr,int4 size,vector<Varnode *> &input);
251 void guardCalls(uint4 flags,
const Address &addr,int4 size,vector<Varnode *> &write);
252 void guardStores(
const Address &addr,int4 size,vector<Varnode *> &write);
253 void guardLoads(uint4 flags,
const Address &addr,int4 size,vector<Varnode *> &write);
254 void guardReturns(uint4 flags,
const Address &addr,int4 size,vector<Varnode *> &write);
255 static void buildRefinement(vector<int4> &refine,
const Address &addr,int4 size,
const vector<Varnode *> &vnlist);
256 void splitByRefinement(
Varnode *vn,
const Address &addr,
const vector<int4> &refine,vector<Varnode *> &split);
257 void refineRead(
Varnode *vn,
const Address &addr,
const vector<int4> &refine,vector<Varnode *> &newvn);
258 void refineWrite(
Varnode *vn,
const Address &addr,
const vector<int4> &refine,vector<Varnode *> &newvn);
259 void refineInput(
Varnode *vn,
const Address &addr,
const vector<int4> &refine,vector<Varnode *> &newvn);
260 void remove13Refinement(vector<int4> &refine);
261 bool refinement(
const Address &addr,int4 size,
const vector<Varnode *> &readvars,
const vector<Varnode *> &writevars,
const vector<Varnode *> &inputvars);
263 void calcMultiequals(
const vector<Varnode *> &write);
265 void bumpDeadcodeDelay(
Varnode *vn);
266 void placeMultiequals(
void);
271 int4 getPass(
void)
const {
return pass; }
285 void forceRestructure(
void) { maxdepth = -1; }
288 const list<LoadGuard> &getLoadGuards(
void)
const {
return loadGuard; }
289 const list<LoadGuard> &getStoreGuards(
void)
const {
return storeGuard; }
bool deadRemovalAllowed(AddrSpace *spc) const
Return true if it is safe to remove dead code.
Definition: heritage.cc:2469
bool isGuarded(const Address &addr) const
Does this guard apply to the given address.
Definition: heritage.cc:719
int4 findPass(const Address &addr) const
Look up if/how given address was heritaged.
Definition: heritage.cc:83
uintb getHighest(void) const
Get the highest byte-scaled address.
Definition: space.hh:341
A region where processor data is stored.
Definition: space.hh:73
Description of a control-flow block containing PcodeOps.
Definition: block.hh:60
A special form of ValueSet associated with the read point of a Varnode.
Definition: rangeutil.hh:176
bool deadRemovalAllowedSeen(AddrSpace *spc)
Check if dead code removal is safe and mark that removal has happened.
Definition: heritage.cc:2483
Classes related to basic blocks and control-flow structuring.
int4 pass
Pass when the range was heritaged.
Definition: heritage.hh:32
int4 getDeadCodeDelay(AddrSpace *spc) const
Get pass delay for heritaging the given space.
Definition: heritage.cc:2443
A record describing how logical values are split.
Definition: translate.hh:195
Manage the construction of Static Single Assignment (SSA) form.
Definition: heritage.hh:170
map< Address, SizePass >::iterator iterator
Iterator into the main map.
Definition: heritage.hh:45
void buildInfoList(void)
Initialize information for each space.
Definition: heritage.cc:2286
A class for analyzing parameters to a sub-function call.
Definition: fspec.hh:1449
void reset(int4 maxdepth)
Reset to an empty queue.
Definition: heritage.cc:97
A basic block for p-code operations.
Definition: block.hh:365
Priority queue for the phi-node (MULTIEQUAL) placement algorithm.
Definition: heritage.hh:64
Lowest level operation of the p-code language.
Definition: op.hh:58
int4 numHeritagePasses(AddrSpace *spc) const
Get the number times heritage was performed for the given address space.
Definition: heritage.cc:2419
Description of a LOAD operation that needs to be guarded.
Definition: heritage.hh:105
Information about heritage passes performed for a specific address space.
Definition: heritage.hh:85
A low-level variable or contiguous set of bytes described by an Address and a size.
Definition: varnode.hh:65
void heritage(void)
Perform one pass of heritage.
Definition: heritage.cc:2306
A low-level machine address for labelling bytes and data.
Definition: address.hh:46
Container for data structures associated with a single function.
Definition: funcdata.hh:45
void seenDeadCode(AddrSpace *spc)
Inform system of dead code removal in given space.
Definition: heritage.cc:2431
int4 getIndex(void) const
Get the integer identifier.
Definition: space.hh:319
void setDeadCodeDelay(AddrSpace *spc, int4 delay)
Set delay for a specific space.
Definition: heritage.cc:2455
void clear(void)
Reset all analysis of heritage.
Definition: heritage.cc:2495
FlowBlock * extract(void)
Retrieve the highest priority block.
Definition: heritage.cc:121
Heritage(Funcdata *data)
Constructor.
Definition: heritage.cc:135
OpCode
The op-code defining a specific p-code operation (PcodeOp)
Definition: opcodes.hh:35
int4 heritagePass(const Address &addr) const
Get the pass number when the given address was heritaged.
Definition: heritage.hh:277
const LoadGuard * getStoreGuard(PcodeOp *op) const
Get LoadGuard record associated with given PcodeOp.
Definition: heritage.cc:2402
Map object for keeping track of which address ranges have been heritaged.
Definition: heritage.hh:42
iterator find(const Address &addr)
Look up if/how given address was heritaged.
Definition: heritage.cc:69
int4 size
Size of the range (in bytes)
Definition: heritage.hh:31
map< Address, vector< Varnode * > > VariableStack
Definition: heritage.hh:27
iterator add(Address addr, int4 size, int4 pass, int4 &intersect)
Mark new address as heritaged.
Definition: heritage.cc:30
void insert(FlowBlock *bl, int4 depth)
Insert a block into the queue given its priority.
Definition: heritage.cc:109
Label for describing extent of address range that has been heritaged.
Definition: heritage.hh:30