retdec
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
retdec::llvmir2hll::DefUseAnalysis Class Reference

An analysis providing def-use chains. More...

#include <def_use_analysis.h>

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

Public Member Functions

ShPtr< DefUseChainsgetDefUseChains (ShPtr< Function > func, ShPtr< CFG > cfg=nullptr, std::function< bool(ShPtr< Variable >)> shouldBeIncluded=[](auto) { return true;})
 Returns def-use chains for the given function. More...
 

Static Public Member Functions

static ShPtr< DefUseAnalysiscreate (ShPtr< Module > module, ShPtr< ValueAnalysis > va, ShPtr< VarUsesVisitor > vuv=nullptr)
 Creates a new analysis. More...
 

Private Member Functions

 DefUseAnalysis (ShPtr< Module > module, ShPtr< ValueAnalysis > va, ShPtr< VarUsesVisitor > vuv=nullptr)
 Constructs a new analysis. More...
 
void computeGenAndKill (ShPtr< DefUseChains > ducs)
 Computes the GEN[B] and KILL[B] sets for each CFG node B. More...
 
void computeGenAndKillForNode (ShPtr< DefUseChains > ducs, ShPtr< CFG::Node > node)
 Computes the GEN[B] and KILL[B] sets for the given CFG node node B. More...
 
void computeInAndOut (ShPtr< DefUseChains > ducs)
 Computes the IN[B] and OUT[B] sets for each CFG node B. More...
 
bool computeInAndOutForNode (ShPtr< DefUseChains > ducs, ShPtr< CFG::Node > node)
 Computes the IN[node] and OUT[node] set for the given node node. More...
 
void computeDefUseChains (ShPtr< DefUseChains > ducs)
 Computes the DU[s, x] set for each statement s that defines a variable x. More...
 
void computeDefUseChainForNode (ShPtr< DefUseChains > ducs, ShPtr< CFG::Node > node)
 Computes the DU[s, x] set for each statement s in node that defines a variable x. More...
 
void computeDefUseChainForStmt (ShPtr< DefUseChains > ducs, ShPtr< CFG::Node > node, CFG::stmt_iterator varDefStmtIter, ShPtr< Variable > defVar)
 Computes the DU[*varDefStmtIter, defVar] set. More...
 
ShPtr< VariablegetDefVarInStmt (ShPtr< Statement > stmt)
 Returns the variable that is defined in stmt (if any). More...
 
- Private Member Functions inherited from retdec::utils::NonCopyable
 NonCopyable (const NonCopyable &)=delete
 
NonCopyableoperator= (const NonCopyable &)=delete
 
 NonCopyable ()=default
 
 ~NonCopyable ()=default
 

Private Attributes

ShPtr< Modulemodule
 Module that is being analyzed. More...
 
ShPtr< ValueAnalysisva
 Analysis of used values. More...
 
ShPtr< VarUsesVisitorvuv
 Visitor for obtaining uses of variables. More...
 
ShPtr< CFGBuildercfgBuilder
 The used builder of CFGs. More...
 

Detailed Description

An analysis providing def-use chains.

The analysis and its implementation is based on the following book:

For some basic information about def-use chains, see http://en.wikipedia.org/wiki/Use-define_chain.

Use create() to create instances. Instances of this class have reference object semantics.

Constructor & Destructor Documentation

◆ DefUseAnalysis()

retdec::llvmir2hll::DefUseAnalysis::DefUseAnalysis ( ShPtr< Module module,
ShPtr< ValueAnalysis va,
ShPtr< VarUsesVisitor vuv = nullptr 
)
private

Constructs a new analysis.

See create() for the description of the parameters.

Member Function Documentation

◆ computeDefUseChainForNode()

void retdec::llvmir2hll::DefUseAnalysis::computeDefUseChainForNode ( ShPtr< DefUseChains ducs,
ShPtr< CFG::Node node 
)
private

Computes the DU[s, x] set for each statement s in node that defines a variable x.

This function should be run only from computeDefUseChains(), and it modifies ducs.

◆ computeDefUseChainForStmt()

void retdec::llvmir2hll::DefUseAnalysis::computeDefUseChainForStmt ( ShPtr< DefUseChains ducs,
ShPtr< CFG::Node node,
CFG::stmt_iterator  varDefStmtIter,
ShPtr< Variable defVar 
)
private

Computes the DU[*varDefStmtIter, defVar] set.

Parameters
[in]ducsInformation about def-use chains.
[in]nodeCurrently processed basic block.
[in]varDefStmtIterIterator to the current statement in node.
[in]defVarVariable that is defined in *varDefStmtIter.

This function should be run only from computeDefUseChainForNode(), and it modifies ducs.

◆ computeDefUseChains()

void retdec::llvmir2hll::DefUseAnalysis::computeDefUseChains ( ShPtr< DefUseChains ducs)
private

Computes the DU[s, x] set for each statement s that defines a variable x.

computeGenAndKill() and computeInAndOut() have to be run before this function. This function modifies ducs.

◆ computeGenAndKill()

void retdec::llvmir2hll::DefUseAnalysis::computeGenAndKill ( ShPtr< DefUseChains ducs)
private

Computes the GEN[B] and KILL[B] sets for each CFG node B.

This function modifies ducs.

◆ computeGenAndKillForNode()

void retdec::llvmir2hll::DefUseAnalysis::computeGenAndKillForNode ( ShPtr< DefUseChains ducs,
ShPtr< CFG::Node node 
)
private

Computes the GEN[B] and KILL[B] sets for the given CFG node node B.

This function modifies ducs.

◆ computeInAndOut()

void retdec::llvmir2hll::DefUseAnalysis::computeInAndOut ( ShPtr< DefUseChains ducs)
private

Computes the IN[B] and OUT[B] sets for each CFG node B.

computeGenAndKill() has to be run before this function. This function modifies ducs.

◆ computeInAndOutForNode()

bool retdec::llvmir2hll::DefUseAnalysis::computeInAndOutForNode ( ShPtr< DefUseChains ducs,
ShPtr< CFG::Node node 
)
private

Computes the IN[node] and OUT[node] set for the given node node.

Returns
true if either of these two sets has been changed, false otherwise.

This function modifies ducs.

Preconditions
  • node is not the exit node of a CFG

◆ create()

ShPtr< DefUseAnalysis > retdec::llvmir2hll::DefUseAnalysis::create ( ShPtr< Module module,
ShPtr< ValueAnalysis va,
ShPtr< VarUsesVisitor vuv = nullptr 
)
static

Creates a new analysis.

Parameters
[in]moduleModule for which the analysis is created.
[in]vaThe used analysis of values.
[in]vuvThe used visitor for obtaining uses of variables.

If vuv is not provided, a new visitor is created.

Preconditions
  • va is in a valid state

All methods of this class leave va in a valid state.

◆ getDefUseChains()

ShPtr< DefUseChains > retdec::llvmir2hll::DefUseAnalysis::getDefUseChains ( ShPtr< Function func,
ShPtr< CFG cfg = nullptr,
std::function< bool(ShPtr< Variable >)>  shouldBeIncluded = [](auto) { return true; } 
)

Returns def-use chains for the given function.

Parameters
[in]funcFunction for which the analysis is computed.
[in]cfgOptional CFG for func.
[in]shouldBeIncludedA function that returns whether the given variable should be included in def-use chains.
Preconditions
  • if cfg is non-null, it has to be a CFG corresponding to func

◆ getDefVarInStmt()

ShPtr< Variable > retdec::llvmir2hll::DefUseAnalysis::getDefVarInStmt ( ShPtr< Statement stmt)
private

Returns the variable that is defined in stmt (if any).

"Defined" means that it is assigned a value (it doesn't necessary mean that stmt is a VarDefStmt).

If stmt doesn't define any variable, this function returns the null pointer.

Member Data Documentation

◆ cfgBuilder

ShPtr<CFGBuilder> retdec::llvmir2hll::DefUseAnalysis::cfgBuilder
private

The used builder of CFGs.

◆ module

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

Module that is being analyzed.

◆ va

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

Analysis of used values.

◆ vuv

ShPtr<VarUsesVisitor> retdec::llvmir2hll::DefUseAnalysis::vuv
private

Visitor for obtaining uses of variables.


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