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

A CFG traversal for computing OptimFuncInfos. More...

#include <optim_func_info_cfg_traversal.h>

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

Static Public Member Functions

static ShPtr< OptimFuncInfogetOptimFuncInfo (ShPtr< Module > module, ShPtr< OptimCallInfoObtainer > cio, ShPtr< ValueAnalysis > va, ShPtr< CFG > cfg)
 Computes OptimFuncInfo for the function specified by its CFG. More...
 

Private Types

using VarToVarMap = std::map< ShPtr< Variable >, ShPtr< Variable > >
 A mapping of a variable into another variable. More...
 

Private Member Functions

 OptimFuncInfoCFGTraversal (ShPtr< Module > module, ShPtr< OptimCallInfoObtainer > cio, ShPtr< ValueAnalysis > va, ShPtr< CFG > cfg)
 Constructs a new traverser. More...
 
ShPtr< OptimFuncInfoperformComputation ()
 Computes the FuncInfo and returns it. More...
 
void precomputeAlwaysModifiedVarsBeforeRead ()
 Precomputes funcInfo->isAlwaysModifiedBeforeRead for traversedFunc. More...
 
void updateFuncInfo (ShPtr< Statement > stmt)
 Updates funcInfo by the information obtained from the given statement. More...
 
bool checkExitNodesPredecessor (ShPtr< CFG::Node > node)
 Checks the selected predecessor of the exit node of cfg. 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< Modulemodule
 Module which contains the function specified by its CFG. More...
 
VarSet globalVars
 
ShPtr< CGcg
 Call graph of the module. More...
 
ShPtr< OptimCallInfoObtainercio
 The used call info obtainer. More...
 
ShPtr< ValueAnalysisva
 Analysis of values. More...
 
ShPtr< CFGcfg
 The CFG that is being traversed. More...
 
ShPtr< FunctiontraversedFunc
 The function whose CFG is being traversed. More...
 
ShPtr< CG::CalledFuncscalledFuncs
 Called functions from traversedFunc. More...
 
ShPtr< OptimFuncInfofuncInfo
 The currently computed FuncInfo. More...
 
VarToVarMap storedGlobalVars
 

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 for computing OptimFuncInfos.

This class is meant to be used in OptimCallInfoObtainer.

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

Member Typedef Documentation

◆ VarToVarMap

A mapping of a variable into another variable.

Constructor & Destructor Documentation

◆ OptimFuncInfoCFGTraversal()

retdec::llvmir2hll::OptimFuncInfoCFGTraversal::OptimFuncInfoCFGTraversal ( ShPtr< Module module,
ShPtr< OptimCallInfoObtainer cio,
ShPtr< ValueAnalysis va,
ShPtr< CFG cfg 
)
private

Constructs a new traverser.

See getOptimFuncInfo() for the description of parameters.

Member Function Documentation

◆ checkExitNodesPredecessor()

bool retdec::llvmir2hll::OptimFuncInfoCFGTraversal::checkExitNodesPredecessor ( ShPtr< CFG::Node node)
private

Checks the selected predecessor of the exit node of cfg.

Returns
true if the next exit node's predecessor should be checked, false otherwise. If false is returned, it means that no variables from storedGlobalVars can be marked as 'never modified'.

This function checks that every variable from storedGlobalVars is retrieved its original value before the node exits.

◆ combineRetVals()

bool retdec::llvmir2hll::OptimFuncInfoCFGTraversal::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::OptimFuncInfoCFGTraversal::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.

◆ getOptimFuncInfo()

ShPtr< OptimFuncInfo > retdec::llvmir2hll::OptimFuncInfoCFGTraversal::getOptimFuncInfo ( ShPtr< Module module,
ShPtr< OptimCallInfoObtainer cio,
ShPtr< ValueAnalysis va,
ShPtr< CFG cfg 
)
static

Computes OptimFuncInfo for the function specified by its CFG.

Parameters
[in]moduleModule which contains the function specified by its CFG.
[in]cioThe used call info obtainer.
[in]vaThe used analysis of values.
[in]cfgCFG that should be traversed.
Preconditions
  • module, cio, va, and cfg are non-null
  • cio has been initialized
  • va is in a valid state

This function leaves va in a valid state.

◆ performComputation()

ShPtr< OptimFuncInfo > retdec::llvmir2hll::OptimFuncInfoCFGTraversal::performComputation ( )
private

Computes the FuncInfo and returns it.

◆ precomputeAlwaysModifiedVarsBeforeRead()

void retdec::llvmir2hll::OptimFuncInfoCFGTraversal::precomputeAlwaysModifiedVarsBeforeRead ( )
private

Precomputes funcInfo->isAlwaysModifiedBeforeRead for traversedFunc.

◆ updateFuncInfo()

void retdec::llvmir2hll::OptimFuncInfoCFGTraversal::updateFuncInfo ( ShPtr< Statement stmt)
private

Updates funcInfo by the information obtained from the given statement.

◆ visitStmt()

bool retdec::llvmir2hll::OptimFuncInfoCFGTraversal::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

◆ calledFuncs

ShPtr<CG::CalledFuncs> retdec::llvmir2hll::OptimFuncInfoCFGTraversal::calledFuncs
private

Called functions from traversedFunc.

◆ cfg

ShPtr<CFG> retdec::llvmir2hll::OptimFuncInfoCFGTraversal::cfg
private

The CFG that is being traversed.

◆ cg

ShPtr<CG> retdec::llvmir2hll::OptimFuncInfoCFGTraversal::cg
private

Call graph of the module.

◆ cio

ShPtr<OptimCallInfoObtainer> retdec::llvmir2hll::OptimFuncInfoCFGTraversal::cio
private

The used call info obtainer.

◆ funcInfo

ShPtr<OptimFuncInfo> retdec::llvmir2hll::OptimFuncInfoCFGTraversal::funcInfo
private

The currently computed FuncInfo.

◆ globalVars

VarSet retdec::llvmir2hll::OptimFuncInfoCFGTraversal::globalVars
private

Global variables in module. This is here to speedup the traversal. By using this set, we do not have to ask module every time we need such information.

◆ module

ShPtr<Module> retdec::llvmir2hll::OptimFuncInfoCFGTraversal::module
private

Module which contains the function specified by its CFG.

◆ storedGlobalVars

VarToVarMap retdec::llvmir2hll::OptimFuncInfoCFGTraversal::storedGlobalVars
private

Global variables that (1) are read into local variables at the beginning of the function's body and (2) the local variables are just read, not modified.

◆ traversedFunc

ShPtr<Function> retdec::llvmir2hll::OptimFuncInfoCFGTraversal::traversedFunc
private

The function whose CFG is being traversed.

◆ va

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

Analysis of values.


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