decompiler  1.0.0
Classes | Functions
funcdata.hh File Reference

Utilities for processing data structures associated with a single function. More...

#include "architecture.hh"
#include "override.hh"
#include "heritage.hh"
#include "merge.hh"
#include "dynamic.hh"

Classes

class  Funcdata
 Container for data structures associated with a single function. More...
 
class  PcodeEmitFd
 A p-code emitter for building PcodeOp objects. More...
 
class  AncestorRealistic
 Helper class for determining if Varnodes can trace their value from a legitimate source. More...
 
class  AncestorRealistic::State
 Node in a depth first traversal of ancestors. More...
 

Functions

int4 opFlipInPlaceTest (PcodeOp *op, vector< PcodeOp * > &fliplist)
 Trace a boolean value to a set of PcodeOps that can be changed to flip the boolean value. More...
 
void opFlipInPlaceExecute (Funcdata &data, vector< PcodeOp * > &fliplist)
 Perform op-code flips (in-place) to change a boolean value. More...
 
PcodeOpearliestUseInBlock (Varnode *vn, BlockBasic *bl)
 Get the earliest use/read of a Varnode in a specified basic block. More...
 
PcodeOpcseFindInBlock (PcodeOp *op, Varnode *vn, BlockBasic *bl, PcodeOp *earliest)
 Find a duplicate calculation of a given PcodeOp reading a specific Varnode. More...
 
PcodeOpcseElimination (Funcdata &data, PcodeOp *op1, PcodeOp *op2)
 Perform a Common Subexpression Elimination step. More...
 
void cseEliminateList (Funcdata &data, vector< pair< uintm, PcodeOp * > > &list, vector< Varnode * > &outlist)
 Perform Common Subexpression Elimination on a list of Varnode descendants. More...
 

Detailed Description

Utilities for processing data structures associated with a single function.

Function Documentation

void cseEliminateList ( Funcdata data,
vector< pair< uintm, PcodeOp * > > &  list,
vector< Varnode * > &  outlist 
)

Perform Common Subexpression Elimination on a list of Varnode descendants.

The list consists of PcodeOp descendants of a single Varnode paired with a hash value. The hash serves as a primary test for duplicate calculations; if it doesn't match the PcodeOps aren't common subexpressions. This method searches for hash matches then does secondary testing and eliminates any redundancy it finds.

Parameters
datais the function being modified
listis the list of (hash, PcodeOp) pairs
outlistwill hold Varnodes produced by duplicate calculations

References cseElimination(), PcodeOp::getOut(), PcodeOp::isCseMatch(), PcodeOp::isDead(), and Funcdata::isHeritaged().

Referenced by RuleSelectCse::applyOp(), and AncestorRealistic::mark().

PcodeOp* cseElimination ( Funcdata data,
PcodeOp op1,
PcodeOp op2 
)

Perform a Common Subexpression Elimination step.

Assuming the two given PcodeOps perform the identical operation on identical operands (depth 1 functional equivalence) eliminate the redundancy. Return the remaining (dominating) PcodeOp. If neither op dominates the other, both are eliminated, and a new PcodeOp is built at a commonly accessible point.

Parameters
datais the function being modified
op1is the first of the given PcodeOps
op2is the second given PcodeOp
Returns
the dominating PcodeOp

References PcodeOp::code(), FlowBlock::findCommonBlock(), Varnode::getAddr(), PcodeOp::getIn(), Varnode::getOffset(), SeqNum::getOrder(), PcodeOp::getOut(), PcodeOp::getParent(), PcodeOp::getSeqNum(), Varnode::getSize(), BlockBasic::getStop(), Varnode::isConstant(), Funcdata::newConstant(), Funcdata::newOp(), Funcdata::newVarnodeOut(), PcodeOp::numInput(), Funcdata::opDestroy(), Funcdata::opInsertEnd(), Funcdata::opSetInput(), Funcdata::opSetOpcode(), and Funcdata::totalReplace().

Referenced by cseEliminateList(), and AncestorRealistic::mark().

PcodeOp* cseFindInBlock ( PcodeOp op,
Varnode vn,
BlockBasic bl,
PcodeOp earliest 
)

Find a duplicate calculation of a given PcodeOp reading a specific Varnode.

We only match 1 level of calculation. Additionally the duplicate must occur in the indicated basic block, earlier than a specified op.

Parameters
opis the given PcodeOp
vnis the specific Varnode that must be involved in the calculation
blis the indicated basic block
earliestis the specified op to be earlier than
Returns
the discovered duplicate PcodeOp or NULL

References Varnode::beginDescend(), Varnode::endDescend(), functionalEqualityLevel(), SeqNum::getOrder(), PcodeOp::getOut(), PcodeOp::getParent(), and PcodeOp::getSeqNum().

Referenced by RuleMultiCollapse::applyOp(), RulePushMulti::findSubstitute(), and AncestorRealistic::mark().

PcodeOp* earliestUseInBlock ( Varnode vn,
BlockBasic bl 
)

Get the earliest use/read of a Varnode in a specified basic block.

Parameters
vnis the Varnode to search for
blis the specified basic block in which to search
Returns
the earliest PcodeOp reading the Varnode or NULL

References Varnode::beginDescend(), Varnode::endDescend(), SeqNum::getOrder(), PcodeOp::getParent(), and PcodeOp::getSeqNum().

Referenced by RulePushMulti::applyOp(), RuleMultiCollapse::applyOp(), and AncestorRealistic::mark().

void opFlipInPlaceExecute ( Funcdata data,
vector< PcodeOp * > &  fliplist 
)

Perform op-code flips (in-place) to change a boolean value.

The precomputed list of PcodeOps have their op-codes modified to facilitate the flip.

Parameters
datais the function being modified
fliplistis the list of PcodeOps to modify

References PcodeOp::code(), CPUI_BOOL_AND, CPUI_BOOL_OR, CPUI_COPY, CPUI_INT_LESSEQUAL, CPUI_INT_SLESSEQUAL, CPUI_MAX, get_booleanflip(), PcodeOp::getIn(), PcodeOp::getOut(), PcodeOp::getSlot(), Varnode::loneDescend(), Funcdata::opDestroy(), Funcdata::opSetInput(), Funcdata::opSetOpcode(), Funcdata::opSwapInput(), and Funcdata::replaceLessequal().

Referenced by ActionNormalizeBranches::apply(), AncestorRealistic::mark(), and BlockIf::preferComplement().

int4 opFlipInPlaceTest ( PcodeOp op,
vector< PcodeOp * > &  fliplist 
)

Trace a boolean value to a set of PcodeOps that can be changed to flip the boolean value.

The boolean Varnode is either the output of the given PcodeOp or the first input if the PcodeOp is a CBRANCH. The list of ops that need flipping is returned in an array

Parameters
opis the given PcodeOp
fliplistis the array that will hold the ops to flip
Returns
0 if the change normalizes, 1 if the change is ambivalent, 2 if the change does not normalize

References PcodeOp::code(), CPUI_BOOL_AND, CPUI_BOOL_NEGATE, CPUI_BOOL_OR, CPUI_CBRANCH, CPUI_FLOAT_EQUAL, CPUI_FLOAT_NOTEQUAL, CPUI_INT_EQUAL, CPUI_INT_LESS, CPUI_INT_LESSEQUAL, CPUI_INT_NOTEQUAL, CPUI_INT_SLESS, CPUI_INT_SLESSEQUAL, Varnode::getDef(), PcodeOp::getIn(), Varnode::isConstant(), Varnode::isWritten(), and Varnode::loneDescend().

Referenced by ActionNormalizeBranches::apply(), BlockBasic::flipInPlaceTest(), and AncestorRealistic::mark().