retdec
Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
retdec::llvmir2hll::LhsRhsUsesCFGTraversal Class Referencefinal

A CFG traversal that for an assign statement S returns the uses of its left-hand side such that there are no modifications of variables used in S before them. More...

#include <lhs_rhs_uses_cfg_traversal.h>

Inheritance diagram for retdec::llvmir2hll::LhsRhsUsesCFGTraversal:
Inheritance graph
[legend]
Collaboration diagram for retdec::llvmir2hll::LhsRhsUsesCFGTraversal:
Collaboration graph
[legend]

Static Public Member Functions

static StmtSet getUses (ShPtr< Statement > stmt, ShPtr< CFG > cfg, ShPtr< ValueAnalysis > va, ShPtr< CallInfoObtainer > cio)
 Returns the uses of left-hand side of stmt such that there are no modifications of variables used in stmt before them. More...
 

Private Member Functions

 LhsRhsUsesCFGTraversal (ShPtr< Statement > stmt, ShPtr< Variable > origLhsVar, const VarSet &origRhsVars, ShPtr< CFG > cfg, ShPtr< ValueAnalysis > va, ShPtr< CallInfoObtainer > cio)
 Constructs a new traverser. More...
 
virtual bool visitStmt (ShPtr< Statement > stmt) override
 Visits the given statement stmt. More...
 
virtual bool getEndRetVal () const override
 Returns the value that should be returned when an end of the traversal is reached. More...
 
virtual bool combineRetVals (bool origRetVal, bool newRetVal) const override
 Computes a new return value from the original return value (origRetVal) and the new return value (newRetVal). More...
 

Private Attributes

ShPtr< StatementorigStmt
 Original statement. More...
 
ShPtr< VariableorigLhsVar
 The left-hand side of the original statement. More...
 
const VarSetorigRhsVars
 
ShPtr< ValueAnalysisva
 Analysis of values. More...
 
ShPtr< CallInfoObtainercio
 Obtainer of information about function calls. More...
 
StmtSet uses
 Uses of the variable defined in origStmt. More...
 

Additional Inherited Members

- Protected Member Functions inherited from retdec::llvmir2hll::CFGTraversal
 CFGTraversal (ShPtr< CFG > cfg, bool defaultCurrRetVal)
 Constructs a new traverser. More...
 
 ~CFGTraversal ()=default
 
bool getCurrRetVal () const
 Returns the value that should be returned as the result of visiting a statement. More...
 
bool performTraversal (ShPtr< Statement > startStmt)
 Performs a traversal of the current CFG, starting at startStmt. More...
 
bool performTraversalFromSuccessors (ShPtr< Statement > stmt)
 Performs a traversal of the current CFG, starting at the successor(s) of stmt. More...
 
bool performReverseTraversal (ShPtr< Statement > startStmt)
 Performs a reverse traversal of the current CFG, starting at startStmt. More...
 
bool performReverseTraversalFromPredecessors (ShPtr< Statement > stmt)
 Performs a reverse traversal of the current CFG, starting at the predecessor(s) of stmt. More...
 
- Protected Attributes inherited from retdec::llvmir2hll::CFGTraversal
ShPtr< CFGcfg
 CFG that is being traversed. More...
 
StmtUSet checkedStmts
 Statements that have been checked (to prevent looping). More...
 
bool currRetVal
 Current return value of visitStmt(). More...
 
bool stopTraversal
 Should the traversal be stopped? More...
 

Detailed Description

A CFG traversal that for an assign statement S returns the uses of its left-hand side such that there are no modifications of variables used in S before them.

This traverser is meant to be used in SimpleCopyPropagationOptimizer, see its description for more details.

Instances of this class have reference object semantics. This is a concrete traverser which should not be subclassed.

Constructor & Destructor Documentation

◆ LhsRhsUsesCFGTraversal()

retdec::llvmir2hll::LhsRhsUsesCFGTraversal::LhsRhsUsesCFGTraversal ( ShPtr< Statement stmt,
ShPtr< Variable origLhsVar,
const VarSet origRhsVars,
ShPtr< CFG cfg,
ShPtr< ValueAnalysis va,
ShPtr< CallInfoObtainer cio 
)
private

Constructs a new traverser.

See the description and implementation of getUses() for information on the parameters.

Member Function Documentation

◆ combineRetVals()

bool retdec::llvmir2hll::LhsRhsUsesCFGTraversal::combineRetVals ( bool  origRetVal,
bool  newRetVal 
) const
overrideprivatevirtual

Computes a new return value from the original return value (origRetVal) and the new return value (newRetVal).

Implements retdec::llvmir2hll::CFGTraversal.

◆ getEndRetVal()

bool retdec::llvmir2hll::LhsRhsUsesCFGTraversal::getEndRetVal ( ) const
overrideprivatevirtual

Returns the value that should be returned when an end of the traversal is reached.

For example, the end may mean the end node of the CFG or a statement that has already been traversed.

Implements retdec::llvmir2hll::CFGTraversal.

◆ getUses()

StmtSet retdec::llvmir2hll::LhsRhsUsesCFGTraversal::getUses ( ShPtr< Statement stmt,
ShPtr< CFG cfg,
ShPtr< ValueAnalysis va,
ShPtr< CallInfoObtainer cio 
)
static

Returns the uses of left-hand side of stmt such that there are no modifications of variables used in stmt before them.

Parameters
[in]stmtStatement from which we should start the search.
[in]cfgCFG that should be traversed.
[in]vaAnalysis of values.
[in]cioThe used call info obtainer.
Preconditions
  • stmt, cfg, va, and cio are non-null
  • cio has been initialized
  • va is in a valid state

This function returns the empty StmtSet if:

  • stmt is not of the form a = x where a is a variable and x is an expression containing only variables and arithmetical operations
  • stmt is not in cfg
  • the variables used in stmt can be used indirectly (by a pointer)
  • there are no suitable uses

This function leaves va in a valid state.

◆ visitStmt()

bool retdec::llvmir2hll::LhsRhsUsesCFGTraversal::visitStmt ( ShPtr< Statement stmt)
overrideprivatevirtual

Visits the given statement stmt.

return true if the traversing should continue, false otherwise.

Note: checkedStmts is modified in CFGTraversal, so it is not necessary for the implementation of this function to add stmt to checkedStmts.

If you want the traversal to end prematurely, set the stopTraversal variable to true. Otherwise, if you just return false, the traversal may still continue from other branches because of recursion.

Implements retdec::llvmir2hll::CFGTraversal.

Member Data Documentation

◆ cio

ShPtr<CallInfoObtainer> retdec::llvmir2hll::LhsRhsUsesCFGTraversal::cio
private

Obtainer of information about function calls.

◆ origLhsVar

ShPtr<Variable> retdec::llvmir2hll::LhsRhsUsesCFGTraversal::origLhsVar
private

The left-hand side of the original statement.

◆ origRhsVars

const VarSet& retdec::llvmir2hll::LhsRhsUsesCFGTraversal::origRhsVars
private

The set of variables used in the right-hand side of the original statement.

◆ origStmt

ShPtr<Statement> retdec::llvmir2hll::LhsRhsUsesCFGTraversal::origStmt
private

Original statement.

◆ uses

StmtSet retdec::llvmir2hll::LhsRhsUsesCFGTraversal::uses
private

Uses of the variable defined in origStmt.

◆ va

ShPtr<ValueAnalysis> retdec::llvmir2hll::LhsRhsUsesCFGTraversal::va
private

Analysis of values.


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