retdec
def_use_analysis.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_LLVMIR2HLL_ANALYSIS_DEF_USE_ANALYSIS_H
8 #define RETDEC_LLVMIR2HLL_ANALYSIS_DEF_USE_ANALYSIS_H
9 
10 #include <functional>
11 #include <map>
12 #include <set>
13 #include <vector>
14 
18 
19 namespace retdec {
20 namespace llvmir2hll {
21 
22 class CFGBuilder;
23 class Function;
24 class Module;
25 class ValueAnalysis;
26 class VarUsesVisitor;
27 class Variable;
28 
35 class DefUseChains {
36 public:
38  using StmtVarPair = std::pair<ShPtr<Statement>, ShPtr<Variable>>;
39 
41  using StmtVarPairSet = std::set<StmtVarPair>;
42 
44  using NodePairMap = std::map<ShPtr<CFG::Node>, StmtVarPairSet>;
45 
47  // Implementation note: we have to use std::vector instead of std::map to
48  // make the chain deterministic.
49  using DefUseChain = std::vector<std::pair<StmtVarPair, StmtSet>>;
50 
51 public:
52  void debugPrint();
53 
54 public:
57 
60 
63  std::function<bool (ShPtr<Variable>)> shouldBeIncluded;
64 
68 
75 
82 
89 
96 };
97 
113 public:
115  ShPtr<Function> func,
116  ShPtr<CFG> cfg = nullptr,
117  std::function<bool (ShPtr<Variable>)> shouldBeIncluded =
118  [](auto) { return true; }
119  );
120 
123 
124 private:
127 
130  ShPtr<CFG::Node> node);
133  ShPtr<CFG::Node> node);
136  ShPtr<CFG::Node> node);
138  ShPtr<CFG::Node> node, CFG::stmt_iterator varDefStmtIter,
139  ShPtr<Variable> defVar);
141 
142 private:
145 
148 
151 
154 };
155 
156 } // namespace llvmir2hll
157 } // namespace retdec
158 
159 #endif
A representation of a control-flow graph (CFG).
StmtVector::const_iterator stmt_iterator
Statements iterator.
Definition: cfg.h:49
An analysis providing def-use chains.
Definition: def_use_analysis.h:112
ShPtr< VarUsesVisitor > vuv
Visitor for obtaining uses of variables.
Definition: def_use_analysis.h:150
ShPtr< Module > module
Module that is being analyzed.
Definition: def_use_analysis.h:144
bool computeInAndOutForNode(ShPtr< DefUseChains > ducs, ShPtr< CFG::Node > node)
Computes the IN[node] and OUT[node] set for the given node node.
Definition: def_use_analysis.cpp:319
DefUseAnalysis(ShPtr< Module > module, ShPtr< ValueAnalysis > va, ShPtr< VarUsesVisitor > vuv=nullptr)
Constructs a new analysis.
Definition: def_use_analysis.cpp:87
void computeGenAndKill(ShPtr< DefUseChains > ducs)
Computes the GEN[B] and KILL[B] sets for each CFG node B.
Definition: def_use_analysis.cpp:154
ShPtr< Variable > getDefVarInStmt(ShPtr< Statement > stmt)
Returns the variable that is defined in stmt (if any).
Definition: def_use_analysis.cpp:459
void computeInAndOut(ShPtr< DefUseChains > ducs)
Computes the IN[B] and OUT[B] sets for each CFG node B.
Definition: def_use_analysis.cpp:238
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.
Definition: def_use_analysis.cpp:384
ShPtr< CFGBuilder > cfgBuilder
The used builder of CFGs.
Definition: def_use_analysis.h:153
void computeDefUseChains(ShPtr< DefUseChains > ducs)
Computes the DU[s, x] set for each statement s that defines a variable x.
Definition: def_use_analysis.cpp:367
ShPtr< ValueAnalysis > va
Analysis of used values.
Definition: def_use_analysis.h:147
void computeGenAndKillForNode(ShPtr< DefUseChains > ducs, ShPtr< CFG::Node > node)
Computes the GEN[B] and KILL[B] sets for the given CFG node node B.
Definition: def_use_analysis.cpp:168
ShPtr< DefUseChains > 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.
Definition: def_use_analysis.cpp:108
static ShPtr< DefUseAnalysis > create(ShPtr< Module > module, ShPtr< ValueAnalysis > va, ShPtr< VarUsesVisitor > vuv=nullptr)
Creates a new analysis.
Definition: def_use_analysis.cpp:142
void computeDefUseChainForStmt(ShPtr< DefUseChains > ducs, ShPtr< CFG::Node > node, CFG::stmt_iterator varDefStmtIter, ShPtr< Variable > defVar)
Computes the DU[*varDefStmtIter, defVar] set.
Definition: def_use_analysis.cpp:405
Def-use chains.
Definition: def_use_analysis.h:35
NodePairMap in
Definition: def_use_analysis.h:88
ShPtr< Function > func
Function for which the chains have been computed.
Definition: def_use_analysis.h:56
DefUseChain du
Definition: def_use_analysis.h:67
NodePairMap gen
Definition: def_use_analysis.h:81
NodePairMap out
Definition: def_use_analysis.h:95
std::function< bool(ShPtr< Variable >)> shouldBeIncluded
Definition: def_use_analysis.h:63
NodePairMap kill
Definition: def_use_analysis.h:74
std::vector< std::pair< StmtVarPair, StmtSet > > DefUseChain
A def-use chain (see [ItC]).
Definition: def_use_analysis.h:49
std::pair< ShPtr< Statement >, ShPtr< Variable > > StmtVarPair
(statement, variable) pair
Definition: def_use_analysis.h:38
ShPtr< CFG > cfg
CFG of func.
Definition: def_use_analysis.h:59
void debugPrint()
Emits all the live variables info to standard error.
Definition: def_use_analysis.cpp:39
std::map< ShPtr< CFG::Node >, StmtVarPairSet > NodePairMap
Mapping of a CFG node into a set of (statement, variable) pairs.
Definition: def_use_analysis.h:44
std::set< StmtVarPair > StmtVarPairSet
Set of (statement, variable) pairs.
Definition: def_use_analysis.h:41
A mixin to make classes non-copyable.
Definition: non_copyable.h:27
A library providing API for working with back-end IR.
std::shared_ptr< T > ShPtr
An alias for a shared pointer.
Definition: smart_ptr.h:18
Definition: archive_wrapper.h:19
A mixin to make classes non-copyable.
Declarations, aliases, macros, etc. for the use of smart pointers.