decompiler
1.0.0
|
Class for merging low-level Varnodes into high-level HighVariables. More...
#include <merge.hh>
Public Member Functions | |
Merge (Funcdata &fd) | |
Construct given a specific function. | |
bool | intersection (HighVariable *a, HighVariable *b) |
Test the intersection of two HighVariables and cache the result. More... | |
bool | inflateTest (Varnode *a, HighVariable *high) |
Test if we can inflate the Cover of the given Varnode without incurring intersections. More... | |
void | inflate (Varnode *a, HighVariable *high) |
Inflate the Cover of a given Varnode with a HighVariable. More... | |
bool | mergeTest (HighVariable *high, vector< HighVariable * > &tmplist) |
Test for intersections between a given HighVariable and a list of other HighVariables. More... | |
void | mergeOpcode (OpCode opc) |
Try to force merges of input to output for all p-code ops of a given type. More... | |
void | mergeByDatatype (VarnodeLocSet::const_iterator startiter, VarnodeLocSet::const_iterator enditer) |
Try to merge all HighVariables in the given range that have the same data-type. More... | |
void | mergeAddrTied (void) |
Force the merge of address tried Varnodes. More... | |
void | mergeMarker (void) |
Force the merge of input and output Varnodes to MULTIEQUAL and INDIRECT ops. More... | |
void | mergeAdjacent (void) |
Speculatively merge Varnodes that are input/output to the same p-code op. More... | |
void | mergeMultiEntry (void) |
Merge together Varnodes mapped to SymbolEntrys from the same Symbol. More... | |
bool | hideShadows (HighVariable *high) |
Hide shadow Varnodes related to the given HighVariable by consolidating COPY chains. More... | |
void | processCopyTrims (void) |
Try to reduce/eliminate COPYs produced by the merge trimming process. More... | |
void | markInternalCopies (void) |
Mark redundant/internal COPY PcodeOps. More... | |
Private Member Functions | |
bool | updateHigh (HighVariable *a) |
Make sure given HighVariable's Cover is up-to-date. More... | |
void | purgeHigh (HighVariable *high) |
Remove cached intersection tests for a given HighVariable. More... | |
bool | blockIntersection (HighVariable *a, HighVariable *b, int4 blk) |
Test if two HighVariables intersect on a given BlockBasic. More... | |
void | collectCovering (vector< Varnode * > &vlist, HighVariable *high, PcodeOp *op) |
Collect all instances of the given HighVariable whose Cover intersects a p-code op. More... | |
bool | collectCorrectable (const vector< Varnode * > &vlist, list< PcodeOp * > &oplist, vector< int4 > &slotlist, PcodeOp *op) |
Check for for p-code op intersections that are correctable. More... | |
PcodeOp * | allocateCopyTrim (Varnode *inVn, Datatype *ct, const Address &addr) |
Allocate COPY PcodeOp designed to trim an overextended Cover. More... | |
void | snipReads (Varnode *vn, list< PcodeOp * > &markedop) |
Snip off set of read p-code ops for a given Varnode. More... | |
void | snipIndirect (PcodeOp *indop) |
Snip instances of the input of an INDIRECT op that interfere with its output. More... | |
void | eliminateIntersect (Varnode *vn, const vector< BlockVarnode > &blocksort) |
Eliminate intersections of given Varnode with other Varnodes in a list. More... | |
void | unifyAddress (VarnodeLocSet::const_iterator startiter, VarnodeLocSet::const_iterator enditer) |
Make sure all Varnodes with the same storage address and size can be merged. More... | |
void | trimOpOutput (PcodeOp *op) |
Trim the output HighVariable of the given PcodeOp so that its Cover is tiny. More... | |
void | trimOpInput (PcodeOp *op, int4 slot) |
Trim the input HighVariable of the given PcodeOp so that its Cover is tiny. More... | |
void | mergeRangeMust (VarnodeLocSet::const_iterator startiter, VarnodeLocSet::const_iterator enditer) |
Force the merge of a ranges of Varnodes with the same size and storage address. More... | |
void | mergeOp (PcodeOp *op) |
Force the merge of all input and output Varnodes for the given PcodeOp. More... | |
void | mergeIndirect (PcodeOp *indop) |
Force the merge of all input and output Varnodes to a given INDIRECT op. More... | |
void | mergeLinear (vector< HighVariable * > &highvec) |
Speculatively merge all HighVariables in the given list as well as possible. More... | |
bool | merge (HighVariable *high1, HighVariable *high2, bool isspeculative) |
Perform low-level details of merging two HighVariables if possible. More... | |
bool | checkCopyPair (HighVariable *high, PcodeOp *domOp, PcodeOp *subOp) |
Check if the given PcodeOp COPYs are redundant. More... | |
void | buildDominantCopy (HighVariable *high, vector< PcodeOp * > ©, int4 pos, int4 size) |
Try to replace a set of COPYs from the same Varnode with a single dominant COPY. More... | |
void | markRedundantCopies (HighVariable *high, vector< PcodeOp * > ©, int4 pos, int4 size) |
Search for and mark redundant COPY ops into the given high as non-printing. More... | |
void | processHighDominantCopy (HighVariable *high) |
Try to replace COPYs into the given HighVariable with a single dominant COPY. More... | |
void | processHighRedundantCopy (HighVariable *high) |
Mark COPY ops into the given HighVariable that are redundant. More... | |
Static Private Member Functions | |
static bool | mergeTestRequired (HighVariable *high_out, HighVariable *high_in) |
Required tests to merge HighVariables that are not Cover related. More... | |
static bool | mergeTestAdjacent (HighVariable *high_out, HighVariable *high_in) |
Adjacency tests for merging Varnodes that are input or output to the same p-code op. More... | |
static bool | mergeTestSpeculative (HighVariable *high_out, HighVariable *high_in) |
Speculative tests for merging HighVariables that are not Cover related. More... | |
static bool | mergeTestBasic (Varnode *vn) |
A test if the given Varnode can ever be merged. More... | |
static void | findSingleCopy (HighVariable *high, vector< Varnode * > &singlelist) |
Find instance Varnodes that copied to from outside the given HighVariable. More... | |
static bool | compareHighByBlock (const HighVariable *a, const HighVariable *b) |
Compare HighVariables by the blocks they cover. More... | |
static bool | compareCopyByInVarnode (PcodeOp *op1, PcodeOp *op2) |
Compare COPY ops first by Varnode input, then by block containing the op. More... | |
static bool | shadowedVarnode (const Varnode *vn) |
Determine if given Varnode is shadowed by another Varnode in the same HighVariable. More... | |
static void | findAllIntoCopies (HighVariable *high, vector< PcodeOp * > ©Ins, bool filterTemps) |
Find all the COPY ops into the given HighVariable. More... | |
Private Attributes | |
Funcdata & | data |
The function containing the Varnodes to be merged. | |
map< HighEdge, bool > | highedgemap |
A cache of intersection tests, sorted by HighVariable pair. | |
vector< PcodeOp * > | copyTrims |
COPY ops inserted to facilitate merges. | |
Class for merging low-level Varnodes into high-level HighVariables.
As a node in Single Static Assignment (SSA) form, a Varnode has at most one defining operation. To get a suitable notion of a single high-level variable (HighVariable) that may be reassigned at multiple places in a single function, individual Varnode objects can be merged into a HighVariable object. Varnode objects may be merged in this way if there is no pairwise intersection between each Varnode's Cover, the ranges of code where the Varnode holds its value.
For a given function, this class attempts to merge Varnodes using various strategies and keeps track of Cover intersections to facilitate the process. Merge strategies break up into two general categories: forced merges, and speculative merges. Forced merges must happen, and extra Varnodes may be added to split up problematic covers to enforce it. Forced merges include:
Speculative merges are attempted to reduce the overall number of variables defined by a function, but any given merge attempt is abandoned if there are Cover intersections. No modification is made to the data-flow to force the merge. Speculative merges include:
Allocate COPY PcodeOp designed to trim an overextended Cover.
A COPY is allocated with the given input and data-type. A unique space output is created.
inVn | is the given input Varnode for the new COPY |
ct | is the data-type to assign to the new unique output |
addr | is the address associated with the new COPY |
References CPUI_COPY, and Varnode::getSize().
|
private |
Test if two HighVariables intersect on a given BlockBasic.
Intersections are checked only on the specified block.
a | is the first HighVariable |
b | is the second HighVariable |
blk | is the index of the BlockBasic on which to test intersection |
References Varnode::copyShadow(), Varnode::getCover(), HighVariable::getInstance(), Cover::intersectByBlock(), HighVariable::numInstances(), BlockVarnode::vn, and HighVariable::wholecover.
|
private |
Try to replace a set of COPYs from the same Varnode with a single dominant COPY.
All the COPY outputs must be instances of the same HighVariable (not the same Varnode). Either an existing COPY dominates all the others, or a new dominating COPY is constructed. The read locations of all other COPY outputs are replaced with the output of the dominating COPY, if it does not cause intersections in the HighVariable's Cover. Because of intersections, replacement may fail or partially succeed. Replacement only happens with COPY outputs that are temporary registers. The cover of the HighVariable may be extended because of a new COPY output instance.
high | is the HighVariable being copied to |
copy | is the list of COPY ops into the HighVariable |
pos | is the index of the first COPY from the specific input Varnode |
size | is the number of COPYs (in sequence) from the same specific Varnode |
References Cover::addDefPoint(), Cover::addRefPoint(), Varnode::beginDescend(), PcodeOp::clearMark(), PcodeOp::code(), Varnode::copyShadow(), CPUI_COPY, Varnode::endDescend(), FlowBlock::findCommonBlock(), Varnode::getCover(), Varnode::getDef(), Varnode::getHigh(), PcodeOp::getIn(), HighVariable::getInstance(), PcodeOp::getOut(), Varnode::getSize(), BlockBasic::getStop(), Varnode::getType(), Cover::intersect(), PcodeOp::isMark(), Varnode::isWritten(), HighVariable::merge(), Cover::merge(), HighVariable::numInstances(), HighVariable::remove(), PcodeOp::setMark(), and BlockVarnode::vn.
|
private |
Check if the given PcodeOp COPYs are redundant.
Both the given COPYs assign to the same HighVariable. One is redundant if there is no other assignment to the HighVariable between the first COPY and the second COPY. The first COPY must come from a block with a smaller or equal index to the second COPY. If the indices are equal, the first COPY must come before the second within the block.
high | is the HighVariable being assigned to |
domOp | is the first COPY |
subOp | is the second COPY |
References Cover::addDefPoint(), Cover::addRefPoint(), PcodeOp::code(), Cover::contain(), CPUI_COPY, FlowBlock::dominates(), Varnode::getDef(), PcodeOp::getIn(), HighVariable::getInstance(), PcodeOp::getOut(), PcodeOp::getParent(), Varnode::isWritten(), HighVariable::numInstances(), and BlockVarnode::vn.
|
private |
Check for for p-code op intersections that are correctable.
Given a list of Varnodes that intersect a specific PcodeOp, check that each intersection is on the boundary, and if so, pass back the read op(s) that cause the intersection.
vlist | is the given list of intersecting Varnodes |
oplist | will hold the boundary intersecting read ops |
slotlist | will hold the corresponding input slots of the instance |
op | is the specific intersecting PcodeOp |
References Varnode::beginDescend(), CoverBlock::boundary(), Varnode::endDescend(), Varnode::getCover(), Cover::getCoverBlock(), FlowBlock::getIndex(), PcodeOp::getParent(), PcodeOp::getSlot(), CoverBlock::getUIndex(), and BlockVarnode::vn.
|
private |
Collect all instances of the given HighVariable whose Cover intersects a p-code op.
Efficiently test if each instance Varnodes contains the specific p-code op in its Cover and return a list of the instances that do.
vlist | will hold the resulting list of intersecting instances |
high | is the given HighVariable |
op | is the specific PcodeOp to test intersection with |
References CoverBlock::contain(), Varnode::getCover(), Cover::getCoverBlock(), FlowBlock::getIndex(), HighVariable::getInstance(), PcodeOp::getParent(), HighVariable::numInstances(), and BlockVarnode::vn.
Compare COPY ops first by Varnode input, then by block containing the op.
A sort designed to group COPY ops from the same Varnode together. Then within a group, COPYs are sorted by their containing basic block (so that dominating ops come first).
References Varnode::getCreateIndex(), PcodeOp::getIn(), FlowBlock::getIndex(), SeqNum::getOrder(), PcodeOp::getParent(), and PcodeOp::getSeqNum().
|
inlinestaticprivate |
Compare HighVariables by the blocks they cover.
This comparator sorts, based on:
a | is the first HighVariable to compare |
b | is the second HighVariable |
References Cover::compareTo(), PcodeOp::getAddr(), Varnode::getAddr(), Varnode::getDef(), HighVariable::getInstance(), and HighVariable::wholecover.
|
private |
Eliminate intersections of given Varnode with other Varnodes in a list.
Both the given Varnode and those in the list are assumed to be at the same storage address. For any intersection, identify the PcodeOp reading the given Varnode which causes the intersection and snip the read by inserting additional COPY ops.
vn | is the given Varnode |
blocksort | is the list of other Varnodes sorted by their defining basic block |
References Cover::addDefPoint(), Cover::addRefPoint(), Cover::begin(), Varnode::beginDescend(), PcodeOp::code(), Cover::containVarnodeDef(), Varnode::copyShadow(), CPUI_INDIRECT, Cover::end(), Varnode::endDescend(), BlockVarnode::findFront(), Varnode::getAddr(), Varnode::getDef(), PcodeOp::getIn(), BlockVarnode::getIndex(), PcodeOp::getOpFromConst(), SeqNum::getOrder(), PcodeOp::getSeqNum(), Varnode::isAddrForce(), and Varnode::isWritten().
|
staticprivate |
Find all the COPY ops into the given HighVariable.
Collect all the COPYs whose output is the given HighVariable but the input is from a different HighVariable. Returned COPYs are sorted first by the input Varnode then by block order.
high | is the given HighVariable |
copyIns | will hold the list of COPYs |
filterTemps | is true if COPYs must have a temporary output |
References PcodeOp::code(), CPUI_COPY, Varnode::getDef(), Varnode::getHigh(), PcodeOp::getIn(), HighVariable::getInstance(), PcodeOp::getOut(), Varnode::getSpace(), AddrSpace::getType(), IPTR_INTERNAL, Varnode::isWritten(), HighVariable::numInstances(), and BlockVarnode::vn.
|
staticprivate |
Find instance Varnodes that copied to from outside the given HighVariable.
Find all Varnodes in the HighVariable which are defined by a COPY from another Varnode which is not part of the same HighVariable.
high | is the given HighVariable |
singlelist | will hold the resulting list of copied instances |
References PcodeOp::code(), CPUI_COPY, Varnode::getDef(), Varnode::getHigh(), PcodeOp::getIn(), HighVariable::getInstance(), Varnode::isWritten(), HighVariable::numInstances(), and BlockVarnode::vn.
bool Merge::hideShadows | ( | HighVariable * | high | ) |
Hide shadow Varnodes related to the given HighVariable by consolidating COPY chains.
If two Varnodes are copied from the same common ancestor then they will always contain the same value and can be considered shadows of the same variable. If the paths from the ancestor to the two Varnodes aren't properly nested, the two Varnodes will still look like distinct variables. This routine searches for this situation, relative to a single HighVariable, and alters data-flow so that copying from ancestor to first Varnode to second Varnode becomes a single path. Both Varnodes then ultimately become instances of the same HighVariable.
high | is the given HighVariable to search near |
References Cover::containVarnodeDef(), Varnode::copyShadow(), Varnode::getCover(), and Varnode::getDef().
Referenced by ActionHideShadow::apply().
void Merge::inflate | ( | Varnode * | a, |
HighVariable * | high | ||
) |
Inflate the Cover of a given Varnode with a HighVariable.
An expression involving a HighVariable can be propagated to all the read sites of the output Varnode of the expression if the Varnode Cover can be inflated to include the Cover of the HighVariable, even though the Varnode is not part of the HighVariable. This routine performs the inflation, assuming an intersection test is already performed.
a | is the given Varnode to inflate |
high | is the HighVariable to inflate with |
References Varnode::cover, HighVariable::coverDirty(), Varnode::getHigh(), HighVariable::getInstance(), Cover::merge(), and HighVariable::numInstances().
Referenced by ActionMarkImplied::apply().
bool Merge::inflateTest | ( | Varnode * | a, |
HighVariable * | high | ||
) |
Test if we can inflate the Cover of the given Varnode without incurring intersections.
This routine tests whether an expression involving a HighVariable can be propagated to all the read sites of the output Varnode of the expression. This is possible only if the Varnode Cover can be inflated to include the Cover of the HighVariable, even though the Varnode is not part of the HighVariable.
a | is the given Varnode to inflate |
high | is the HighVariable being propagated |
References Varnode::copyShadow(), Varnode::getCover(), Varnode::getHigh(), HighVariable::getInstance(), Cover::intersect(), HighVariable::numInstances(), and HighVariable::wholecover.
Referenced by ActionMarkImplied::checkImpliedCover().
bool Merge::intersection | ( | HighVariable * | a, |
HighVariable * | b | ||
) |
Test the intersection of two HighVariables and cache the result.
If the Covers of the two variables intersect, this routine returns true. To avoid expensive computation on the Cover objects themselves, the test result associated with the pair of HighVariables is cached.
a | is the first HighVariable |
b | is the second HighVariable |
References Cover::intersectList(), and HighVariable::wholecover.
void Merge::markInternalCopies | ( | void | ) |
Mark redundant/internal COPY PcodeOps.
Run through all COPY, SUBPIECE, and PIECE operations (PcodeOps that copy data) and characterize those that are internal (copy data between storage locations representing the same variable) or redundant (perform the same copy as an earlier operation). These, as a result, are not printed in the final source code representation.
References HighVariable::clearCopyIns(), PcodeOp::code(), CPUI_COPY, CPUI_PIECE, CPUI_SUBPIECE, Varnode::getHigh(), PcodeOp::getIn(), Varnode::getOffset(), PcodeOp::getOut(), Varnode::getSize(), HighVariable::getTiedVarnode(), HighVariable::hasCopyIn1(), HighVariable::hasCopyIn2(), Varnode::hasNoDescend(), HighVariable::isAddrTied(), Varnode::overlap(), HighVariable::setCopyIn1(), and HighVariable::setCopyIn2().
Referenced by ActionCopyMarker::apply().
|
private |
Search for and mark redundant COPY ops into the given high as non-printing.
Trimming during the merge process can insert multiple COPYs from the same source. In some cases, one or more COPYs may be redundant and shouldn't be printed. This method searches for redundancy among COPY ops that assign to the given HighVariable.
high | is the given HighVariable |
copy | is the list of COPYs coming from the same source HighVariable |
pos | is the starting index of a set of COPYs coming from the same Varnode |
size | is the number of Varnodes in the set coming from the same Varnode |
References PcodeOp::isDead().
|
private |
Perform low-level details of merging two HighVariables if possible.
This routine only fails (returning false) if there is a Cover intersection between the two variables. Otherwise, all the Varnode instances from the second HighVariable are merged into the first and its Cover is updated. The cached intersection tests are also updated to reflect the merge.
high1 | is the first HighVariable being merged |
high2 | is the second |
isspeculative | is true if the desired merge is speculative |
References HighVariable::merge(), HighVariable::setMark(), and HighVariable::updateCover().
void Merge::mergeAddrTied | ( | void | ) |
Force the merge of address tried Varnodes.
For each set of address tied Varnodes with the same size and storage address, merge them into a single HighVariable. The merges are forced, so any Cover intersections must be resolved by altering data-flow, which involves inserting additional COPY ops and unique Varnodes.
References Varnode::written.
Referenced by ActionMergeRequired::apply().
void Merge::mergeAdjacent | ( | void | ) |
Speculatively merge Varnodes that are input/output to the same p-code op.
If a single p-code op has an input and output HighVariable that share the same data-type, attempt to merge them. Each merge is speculative and is skipped if it would introduce Cover intersections.
References Varnode::getDef(), Varnode::getHigh(), PcodeOp::getIn(), PcodeOp::getOut(), Varnode::getSize(), PcodeOp::inputTypeLocal(), PcodeOp::isCall(), Varnode::isInput(), PcodeOp::numInput(), and PcodeOp::outputTypeLocal().
Referenced by ActionMergeAdjacent::apply().
void Merge::mergeByDatatype | ( | VarnodeLocSet::const_iterator | startiter, |
VarnodeLocSet::const_iterator | enditer | ||
) |
Try to merge all HighVariables in the given range that have the same data-type.
HighVariables that have an instance within the given Varnode range are sorted into groups based on their data-type. Then an attempt is made to merge all the HighVariables within a group. If a particular merge causes Cover intersection, it is skipped.
startiter | is the start of the given range of Varnodes |
enditer | is the end of the given range |
References HighVariable::getType(), Varnode::isFree(), HighVariable::isMark(), HighVariable::setMark(), and BlockVarnode::vn.
Referenced by ActionMergeType::apply().
|
private |
Force the merge of all input and output Varnodes to a given INDIRECT op.
Merging INDIRECTs take a little care if their output is address forced because by convention the value must be present at the address BEFORE the indirect effect operation takes place.
indop | is the given INDIRECT |
References PcodeOp::getAddr(), Varnode::getHigh(), PcodeOp::getIn(), PcodeOp::getOut(), Varnode::getType(), and Varnode::isAddrForce().
|
private |
Speculatively merge all HighVariables in the given list as well as possible.
The variables are first sorted by the index of the earliest block in their range. Then proceeding in order, an attempt is made to merge each variable with the first. The attempt fails if the speculative test doesn't pass or if there are Cover intersections, in which case that particular merge is skipped.
void Merge::mergeMarker | ( | void | ) |
Force the merge of input and output Varnodes to MULTIEQUAL and INDIRECT ops.
Run through all MULTIEQUAL and INDIRECT ops in the function. Force the merge of each input Varnode with the output Varnode, doing data-flow modification if necessary to resolve Cover intersections.
References PcodeOp::code(), CPUI_INDIRECT, PcodeOp::isIndirectCreation(), and PcodeOp::isMarker().
Referenced by ActionMergeRequired::apply().
void Merge::mergeMultiEntry | ( | void | ) |
Merge together Varnodes mapped to SymbolEntrys from the same Symbol.
Symbols that have more than one SymbolEntry may attach to more than one Varnode. These Varnodes need to be merged to properly represent a single variable.
References Symbol::getMapEntry(), Symbol::getName(), Datatype::getSize(), SymbolEntry::getSize(), Symbol::getType(), Symbol::numEntries(), Symbol::setMergeProblems(), and HighVariable::setUnmerged().
Referenced by ActionMergeMultiEntry::apply().
|
private |
Force the merge of all input and output Varnodes for the given PcodeOp.
Data-flow for specific input and output Varnodes are snipped until everything can be merged.
op | is the given PcodeOp |
References PcodeOp::code(), CPUI_INDIRECT, Varnode::getHigh(), PcodeOp::getIn(), PcodeOp::getOut(), PcodeOp::getSeqNum(), and PcodeOp::numInput().
void Merge::mergeOpcode | ( | OpCode | opc | ) |
Try to force merges of input to output for all p-code ops of a given type.
For a given opcode, run through all ops in the function in block/address order and try to merge each input HighVariable with the output HighVariable. If this would introduce Cover intersections, the merge is skipped. This is generally used to try to merge the input and output of COPY ops if possible.
opc | is the op-code type to merge |
References BlockBasic::beginOp(), PcodeOp::code(), BlockBasic::endOp(), Varnode::getHigh(), PcodeOp::getIn(), PcodeOp::getOut(), and PcodeOp::numInput().
Referenced by ActionMergeCopy::apply().
|
private |
Force the merge of a ranges of Varnodes with the same size and storage address.
The list of Varnodes to be merged is provided as a range in the main location sorted container. Any Cover intersection is assumed to already be snipped, so any problems with merging cause an exception to be thrown.
startiter | is the beginning of the range of Varnodes with the same storage address |
enditer | is the end of the range |
References Varnode::getHigh(), Varnode::isSpacebase(), and BlockVarnode::vn.
bool Merge::mergeTest | ( | HighVariable * | high, |
vector< HighVariable * > & | tmplist | ||
) |
Test for intersections between a given HighVariable and a list of other HighVariables.
If there is any Cover intersection between the given HighVariable and one in the list, this routine returns false. Otherwise, the given HighVariable is added to the end of the list and true is returned.
high | is the given HighVariable |
tmplist | is the list of HighVariables to test against |
References Varnode::getHigh(), HighVariable::hasCopyIn1(), HighVariable::hasCover(), Varnode::hasCover(), HighVariable::setCopyIn1(), and BlockVarnode::vn.
|
staticprivate |
Adjacency tests for merging Varnodes that are input or output to the same p-code op.
All the required tests (mergeTestRequired()) are performed, and then some additional tests are performed. This does not perform any Cover tests.
high_out | is the output HighVariable to test |
high_in | is the input HighVariable to test |
References HighVariable::getInputVarnode(), HighVariable::getSymbol(), HighVariable::getType(), Varnode::isIllegalInput(), Varnode::isIndirectOnly(), HighVariable::isInput(), Symbol::isIsolated(), HighVariable::isNameLock(), and BlockVarnode::vn.
|
staticprivate |
A test if the given Varnode can ever be merged.
Some Varnodes (constants, annotations, implied, spacebase) are never merged with another Varnode.
vn | is the Varnode to test |
References Varnode::hasCover(), Varnode::isImplied(), and Varnode::isSpacebase().
|
staticprivate |
Required tests to merge HighVariables that are not Cover related.
This is designed to short circuit merge tests, when we know properties of the two HighVariables preclude merging. For example, you can't merge HighVariables if:
high_out | is the first HighVariable to test |
high_in | is the second HighVariable to test |
References Varnode::getAddr(), HighVariable::getSymbol(), HighVariable::getSymbolOffset(), HighVariable::getTiedVarnode(), HighVariable::getType(), HighVariable::isAddrTied(), HighVariable::isExtraOut(), HighVariable::isInput(), HighVariable::isPersist(), and HighVariable::isTypeLock().
|
staticprivate |
Speculative tests for merging HighVariables that are not Cover related.
This does all the required and adjacency merge tests and then performs additional tests required for speculative merges.
high_out | is the first HighVariable to test |
high_in | is the second HighVariable to test |
References HighVariable::isAddrTied(), HighVariable::isInput(), and HighVariable::isPersist().
void Merge::processCopyTrims | ( | void | ) |
Try to reduce/eliminate COPYs produced by the merge trimming process.
In order to force merging of certain Varnodes, extra COPY operations may be inserted to reduce their Cover ranges, and multiple COPYs from the same Varnode can be created this way. This method collects sets of COPYs generated in this way that have the same input Varnode and then tries to replace the COPYs with fewer or a single COPY.
References HighVariable::clearCopyIns(), HighVariable::hasCopyIn1(), HighVariable::hasCopyIn2(), HighVariable::setCopyIn1(), and HighVariable::setCopyIn2().
Referenced by ActionDominantCopy::apply().
|
private |
Try to replace COPYs into the given HighVariable with a single dominant COPY.
Find groups of COPYs into the given HighVariable that come from a single source Varnode, then try to replace them with a COPY.
high | is the given HighVariable |
|
private |
Mark COPY ops into the given HighVariable that are redundant.
A COPY is redundant if another COPY performs the same action and has dominant control flow. The redundant COPY is not removed but is marked so that it doesn't print in the final source output.
high | is the given HighVariable |
|
private |
Remove cached intersection tests for a given HighVariable.
All tests for pairs where either the first or second HighVariable matches the given one are removed.
high | is the given HighVariable to purge |
|
staticprivate |
Determine if given Varnode is shadowed by another Varnode in the same HighVariable.
vn | is the Varnode to check for shadowing |
References Varnode::getCover(), Varnode::getHigh(), HighVariable::getInstance(), Cover::intersect(), and HighVariable::numInstances().
|
private |
Snip instances of the input of an INDIRECT op that interfere with its output.
Examine the input and output HighVariable for the given INDIRECT op. Varnode instances of the input that intersect the output Cover are snipped by creating a new COPY op from the input to a new temporary and then replacing the Varnode reads with the temporary.
indop | is the given INDIRECT op |
References PcodeOp::getAddr(), Varnode::getAddr(), Varnode::getHigh(), PcodeOp::getIn(), PcodeOp::getOpFromConst(), PcodeOp::getOut(), and Varnode::getType().
Snip off set of read p-code ops for a given Varnode.
The data-flow for the given Varnode is truncated by creating a COPY p-code from the Varnode into a new temporary Varnode, then replacing the Varnode reads for a specific set of p-code ops with the temporary.
References PcodeOp::code(), CPUI_INDIRECT, PcodeOp::getAddr(), Varnode::getAddr(), Varnode::getDef(), PcodeOp::getIn(), PcodeOp::getOpFromConst(), PcodeOp::getOut(), PcodeOp::getParent(), BlockBasic::getStart(), Varnode::getType(), Varnode::isInput(), PcodeOp::numInput(), and BlockVarnode::vn.
|
private |
Trim the input HighVariable of the given PcodeOp so that its Cover is tiny.
The given PcodeOp is assumed to force merging so that input and output Covers shouldn't intersect. A new COPY is inserted right before the given PcodeOp with a new unique output that replaces the specified input, disassociating it from the other original inputs and output.
References PcodeOp::code(), CPUI_MULTIEQUAL, PcodeOp::getAddr(), PcodeOp::getIn(), FlowBlock::getIn(), PcodeOp::getOut(), PcodeOp::getParent(), BlockBasic::getStop(), Varnode::getType(), and BlockVarnode::vn.
|
private |
Trim the output HighVariable of the given PcodeOp so that its Cover is tiny.
The given PcodeOp is assumed to force merging so that input and output Covers shouldn't intersect. The original PcodeOp output is moved so that it becomes the output of a new COPY, disassociating the original output Varnode from the inputs.
op | is the given PcodeOp |
References PcodeOp::code(), CPUI_COPY, CPUI_INDIRECT, PcodeOp::getAddr(), Varnode::getAddr(), PcodeOp::getIn(), PcodeOp::getOpFromConst(), PcodeOp::getOut(), Varnode::getSize(), Varnode::getType(), and BlockVarnode::vn.
|
private |
Make sure all Varnodes with the same storage address and size can be merged.
The list of Varnodes to be merged is provided as a range in the main location sorted container. Any discovered intersection is snipped by splitting data-flow for one of the Varnodes into two or more flows, which involves insert new COPY ops and temporaries.
startiter | is the beginning of the range of Varnodes with the same storage address |
enditer | is the end of the range |
References BlockVarnode::vn.
|
private |
Make sure given HighVariable's Cover is up-to-date.
As manipulations are made, Cover information gets out of date. A dirty flag is used to indicate a particular HighVariable Cover is out-of-date. This routine checks the dirty flag and updates the Cover information if it is set.
a | is the HighVariable to update |
References HighVariable::coverdirty, HighVariable::getInstance(), HighVariable::highflags, HighVariable::numInstances(), HighVariable::updateCover(), and Varnode::updateCover().