decompiler  1.0.0
Public Member Functions | Static Private Member Functions | List of all members
ActionDeadCode Class Reference

Dead code removal. Eliminate dead p-code ops. More...

#include <coreaction.hh>

Inheritance diagram for ActionDeadCode:
Action

Public Member Functions

 ActionDeadCode (const string &g)
 Constructor.
 
virtual Actionclone (const ActionGroupList &grouplist) const
 Clone the Action. More...
 
virtual int4 apply (Funcdata &data)
 Make a single attempt to apply this Action. More...
 
- Public Member Functions inherited from Action
 Action (uint4 f, const string &nm, const string &g)
 Base constructor for an Action. More...
 
virtual ~Action (void)
 Destructor.
 
virtual void printStatistics (ostream &s) const
 Dump statistics to stream. More...
 
int4 perform (Funcdata &data)
 Perform this action (if necessary) More...
 
bool setBreakPoint (uint4 tp, const string &specify)
 Set a breakpoint on this action. More...
 
bool setWarning (bool val, const string &specify)
 Set a warning on this action. More...
 
bool disableRule (const string &specify)
 Disable a specific Rule within this. More...
 
bool enableRule (const string &specify)
 Enable a specific Rule within this. More...
 
const string & getName (void) const
 Get the Action's name.
 
const string & getGroup (void) const
 Get the Action's group.
 
uint4 getStatus (void) const
 Get the current status of this Action.
 
uint4 getNumTests (void)
 Get the number of times apply() was invoked.
 
uint4 getNumApply (void)
 
virtual void reset (Funcdata &data)
 Reset the Action for a new function. More...
 
virtual void resetStats (void)
 Reset all the counts to zero. More...
 
virtual int4 print (ostream &s, int4 num, int4 depth) const
 Print a description of this Action to stream. More...
 
virtual void printState (ostream &s) const
 Print status to stream. More...
 
virtual void saveXml (ostream &s) const
 Save specifics of this action to stream.
 
virtual void restoreXml (const Element *el, Funcdata *fd)
 Load specifics of action from XML.
 
virtual ActiongetSubAction (const string &specify)
 Retrieve a specific sub-action by name. More...
 
virtual RulegetSubRule (const string &specify)
 Retrieve a specific sub-rule by name. More...
 

Static Private Member Functions

static void pushConsumed (uintb val, Varnode *vn, vector< Varnode * > &worklist)
 
static void propagateConsumed (vector< Varnode * > &worklist)
 Propagate the consumed value for one Varnode. More...
 
static bool neverConsumed (Varnode *vn, Funcdata &data)
 Deal with unconsumed Varnodes. More...
 

Additional Inherited Members

- Public Types inherited from Action
enum  ruleflags {
  rule_repeatapply = 4, rule_onceperfunc = 8, rule_oneactperfunc = 16, rule_debug = 32,
  rule_warnings_on = 64, rule_warnings_given = 128
}
 Boolean behavior properties governing this particular Action. More...
 
enum  statusflags {
  status_start =1, status_breakstarthit =2, status_repeat =4, status_mid =8,
  status_end =16, status_actionbreak =32
}
 Boolean properties describing the status of an action. More...
 
enum  breakflags { break_start = 1, tmpbreak_start = 2, break_action = 4, tmpbreak_action = 8 }
 Break points associated with an Action. More...
 
- Protected Member Functions inherited from Action
void issueWarning (Architecture *glb)
 Warn that this Action has applied. More...
 
bool checkStartBreak (void)
 Check start breakpoint. More...
 
bool checkActionBreak (void)
 Check action breakpoint. More...
 
void turnOnWarnings (void)
 Enable warnings for this Action.
 
void turnOffWarnings (void)
 Disable warnings for this Action.
 
- Protected Attributes inherited from Action
int4 lcount
 Changes not including last call to apply()
 
int4 count
 Number of changes made by this action so far.
 
uint4 status
 Current status.
 
uint4 breakpoint
 Breakpoint properties.
 
uint4 flags
 Behavior properties.
 
uint4 count_tests
 Number of times apply() has been called.
 
uint4 count_apply
 Number of times apply() made changes.
 
string name
 Name of the action.
 
string basegroup
 Base group this action belongs to.
 

Detailed Description

Dead code removal. Eliminate dead p-code ops.

This is a very fine grained algorithm, it detects usage of individual bits within the Varnode, not just use of the Varnode itself. Each Varnode has a consumed word, which indicates if a bit in the Varnode is being used, and it has two flags layed out as follows:

The algorithm works by back propagating the consumed value up from the output of the op to its inputs, starting with a set of seed Varnodes which are marked as completely used (function inputs, branch conditions, ...) For each propagation the particular op being passed through can transform the "bit usage" vector of the output to obtain the input.

Member Function Documentation

◆ apply()

int4 ActionDeadCode::apply ( Funcdata data)
virtual

◆ clone()

virtual Action* ActionDeadCode::clone ( const ActionGroupList grouplist) const
inlinevirtual

Clone the Action.

If this Action is a member of one of the groups in the grouplist, this returns a clone of the Action, otherwise NULL is returned.

Parameters
grouplistis the list of groups being cloned
Returns
the cloned Action or NULL

Implements Action.

References ActionDeadCode(), ActionGroupList::contains(), and Action::getGroup().

◆ neverConsumed()

bool ActionDeadCode::neverConsumed ( Varnode vn,
Funcdata data 
)
staticprivate

Deal with unconsumed Varnodes.

For a Varnode, none of whose bits are consumed, eliminate the PcodeOp defining it and replace Varnode inputs to ops that officially read it with zero constants.

Parameters
vnis the Varnode
datais the function being analyzed
Returns
true if the Varnode was eliminated

References Varnode::beginDescend(), Varnode::endDescend(), Varnode::getDef(), Varnode::getSize(), PcodeOp::getSlot(), PcodeOp::isCall(), Funcdata::newConstant(), Funcdata::opDestroy(), Funcdata::opSetInput(), and Funcdata::opUnsetOutput().

◆ propagateConsumed()

void ActionDeadCode::propagateConsumed ( vector< Varnode * > &  worklist)
staticprivate

◆ pushConsumed()

void ActionDeadCode::pushConsumed ( uintb  val,
Varnode vn,
vector< Varnode * > &  worklist 
)
inlinestaticprivate

Given a new consume value to push to a Varnode, determine if this changes the Varnodes consume value and whether to push the Varnode onto the work-list.

Parameters
valis the new consume value
vnis the Varnode to push to
worklistis the current work-list

References calc_mask(), Varnode::getConsume(), Varnode::getSize(), Varnode::isConsumeList(), Varnode::isConsumeVacuous(), Varnode::isWritten(), Varnode::setConsume(), Varnode::setConsumeList(), and Varnode::setConsumeVacuous().


The documentation for this class was generated from the following files: