retdec
optim_call_info_obtainer.h
Go to the documentation of this file.
1 
8 #ifndef RETDEC_LLVMIR2HLL_OBTAINER_CALL_INFO_OBTAINERS_OPTIM_CALL_INFO_OBTAINER_H
9 #define RETDEC_LLVMIR2HLL_OBTAINER_CALL_INFO_OBTAINERS_OPTIM_CALL_INFO_OBTAINER_H
10 
11 #include <map>
12 #include <string>
13 
16 
17 namespace retdec {
18 namespace llvmir2hll {
19 
27 class OptimCallInfo: public CallInfo {
28  friend class OptimCallInfoObtainer;
30 
31 public:
33 
34  void debugPrint();
35 
36  virtual bool isNeverRead(ShPtr<Variable> var) const override;
37  virtual bool mayBeRead(ShPtr<Variable> var) const override;
38  virtual bool isAlwaysRead(ShPtr<Variable> var) const override;
39 
40  virtual bool isNeverModified(ShPtr<Variable> var) const override;
41  virtual bool mayBeModified(ShPtr<Variable> var) const override;
42  virtual bool isAlwaysModified(ShPtr<Variable> var) const override;
43 
44  virtual bool valueIsNeverChanged(ShPtr<Variable> var) const override;
45  virtual bool isAlwaysModifiedBeforeRead(ShPtr<Variable> var) const override;
46 
47 private:
50 
53 
56 
59 
62 
65 
68 
71 };
72 
80 class OptimFuncInfo: public FuncInfo {
81  friend class OptimCallInfoObtainer;
83 
84 public:
86 
87  void debugPrint();
88 
89  virtual bool isNeverRead(ShPtr<Variable> var) const override;
90  virtual bool mayBeRead(ShPtr<Variable> var) const override;
91  virtual bool isAlwaysRead(ShPtr<Variable> var) const override;
92 
93  virtual bool isNeverModified(ShPtr<Variable> var) const override;
94  virtual bool mayBeModified(ShPtr<Variable> var) const override;
95  virtual bool isAlwaysModified(ShPtr<Variable> var) const override;
96 
97  virtual bool valueIsNeverChanged(ShPtr<Variable> var) const override;
98  virtual bool isAlwaysModifiedBeforeRead(ShPtr<Variable> var) const override;
99 
100 private:
103 
106 
109 
112 
115 
118 
121 
124 };
125 
143 
144 public:
146 
147  virtual void init(ShPtr<CG> cg, ShPtr<ValueAnalysis> va) override;
148  virtual std::string getId() const override;
150  ShPtr<Function> caller) override;
151  virtual ShPtr<FuncInfo> getFuncInfo(ShPtr<Function> func) override;
152 
153 private:
155  using FuncInfoMap = std::map<ShPtr<Function>, ShPtr<OptimFuncInfo>>;
156 
158  using CallInfoMap = std::map<ShPtr<CallExpr>, ShPtr<OptimCallInfo>>;
159 
160 private:
162 
163  void computeAllFuncInfos();
164  void computeFuncInfo(ShPtr<Function> func);
165  void computeFuncInfos(const FuncSet &funcs);
166  VarSet skipLocalVars(const VarSet &vars);
170  ShPtr<Function> caller);
171 
172  static bool areDifferent(ShPtr<OptimFuncInfo> fi1,
174  static bool hasChanged(const FuncInfoMap &oldInfo,
175  const FuncInfoMap &newInfo);
176 
177 private:
180 
183 
186 };
187 
188 } // namespace llvmir2hll
189 } // namespace retdec
190 
191 #endif
A base class of all obtainers of information about functions and function calls.
A base class of all obtainers of information about functions and function calls.
Definition: call_info_obtainer.h:218
ShPtr< ValueAnalysis > va
Analysis of values.
Definition: call_info_obtainer.h:319
ShPtr< CG > cg
Call graph of the current module.
Definition: call_info_obtainer.h:316
Base class for all classes storing information about a function call.
Definition: call_info_obtainer.h:34
ShPtr< CallExpr > call
Function call for which this piece of information is computed.
Definition: call_info_obtainer.h:111
Base class for all classes storing information about a function.
Definition: call_info_obtainer.h:119
ShPtr< Function > func
Function for which this piece of information is computed.
Definition: call_info_obtainer.h:197
Obtainer of information about functions and function calls that assumes it has access to complete inf...
Definition: optim_call_info_obtainer.h:141
ShPtr< OptimFuncInfo > computeFuncInfoDefinition(ShPtr< Function > func)
Computes and returns a function info for the given function definition.
Definition: optim_call_info_obtainer.cpp:278
OptimCallInfoObtainer()
Constructs a new obtainer.
Definition: optim_call_info_obtainer.cpp:182
void computeFuncInfos(const FuncSet &funcs)
Computes funcInfoMap[f] for every function f from funcs using the currently known information.
Definition: optim_call_info_obtainer.cpp:227
FuncInfoMap funcInfoMap
Mapping of a function into its info.
Definition: optim_call_info_obtainer.h:179
virtual ShPtr< FuncInfo > getFuncInfo(ShPtr< Function > func) override
Computes and returns information about the given function.
Definition: optim_call_info_obtainer.cpp:412
static bool areDifferent(ShPtr< OptimFuncInfo > fi1, ShPtr< OptimFuncInfo > fi2)
Returns true if fi1 differs from fi2, false otherwise.
Definition: optim_call_info_obtainer.cpp:423
static ShPtr< CallInfoObtainer > create()
Creates a new obtainer.
Definition: optim_call_info_obtainer.cpp:360
void computeAllFuncInfos()
Computes funcInfoMap for each function in the module.
Definition: optim_call_info_obtainer.cpp:189
CallInfoMap callInfoMap
Mapping of a call into its info.
Definition: optim_call_info_obtainer.h:182
ShPtr< OptimFuncInfo > computeFuncInfoDeclaration(ShPtr< Function > func)
Computes and returns a function info for the given function declaration.
Definition: optim_call_info_obtainer.cpp:258
virtual void init(ShPtr< CG > cg, ShPtr< ValueAnalysis > va) override
Initializes the obtainer.
Definition: optim_call_info_obtainer.cpp:364
VarSet globalVars
Global variables in the module, including functions.
Definition: optim_call_info_obtainer.h:185
virtual ShPtr< CallInfo > getCallInfo(ShPtr< CallExpr > call, ShPtr< Function > caller) override
Computes and returns information about the given function call which occurs in caller.
Definition: optim_call_info_obtainer.cpp:394
void computeFuncInfo(ShPtr< Function > func)
Computes funcInfoMap[func] for func from the currently known information.
Definition: optim_call_info_obtainer.cpp:213
virtual std::string getId() const override
Returns the ID of the obtainer.
Definition: optim_call_info_obtainer.cpp:390
std::map< ShPtr< CallExpr >, ShPtr< OptimCallInfo > > CallInfoMap
Mapping of a function call into its info.
Definition: optim_call_info_obtainer.h:158
ShPtr< OptimCallInfo > computeCallInfo(ShPtr< CallExpr > call, ShPtr< Function > caller)
Computes and returns information about the given function call which occurs in caller.
Definition: optim_call_info_obtainer.cpp:291
VarSet skipLocalVars(const VarSet &vars)
Returns the set of variables that are in both vars and globalVars.
Definition: optim_call_info_obtainer.cpp:247
static bool hasChanged(const FuncInfoMap &oldInfo, const FuncInfoMap &newInfo)
Returns true if the FuncInfos in newInfo for functions that are also in oldInfo have changed,...
Definition: optim_call_info_obtainer.cpp:440
std::map< ShPtr< Function >, ShPtr< OptimFuncInfo > > FuncInfoMap
Mapping of a function into its info.
Definition: optim_call_info_obtainer.h:155
Optimistic information about a function call.
Definition: optim_call_info_obtainer.h:27
VarSet mayBeReadVars
Variables that may be read in this function call.
Definition: optim_call_info_obtainer.h:52
virtual bool isAlwaysModifiedBeforeRead(ShPtr< Variable > var) const override
Returns true if the given variable is modified prior to being read in the call, false otherwise.
Definition: optim_call_info_obtainer.cpp:100
VarSet mayBeModifiedVars
Variables that may be modified in this function call.
Definition: optim_call_info_obtainer.h:61
VarSet alwaysReadVars
Variables that are always read in this function call.
Definition: optim_call_info_obtainer.h:55
virtual bool isNeverRead(ShPtr< Variable > var) const override
Returns true if var is never read in the call, false otherwise.
Definition: optim_call_info_obtainer.cpp:72
virtual bool isAlwaysModified(ShPtr< Variable > var) const override
Returns true if the value of var is always changed in the call, false otherwise.
Definition: optim_call_info_obtainer.cpp:92
virtual bool mayBeModified(ShPtr< Variable > var) const override
Returns true if the value of var may be changed in the call, false otherwise.
Definition: optim_call_info_obtainer.cpp:88
OptimCallInfo(ShPtr< CallExpr > call)
Constructs a new optimistic piece of information about the given function call.
Definition: optim_call_info_obtainer.cpp:35
VarSet alwaysModifiedVars
Variables that are always modified in this function call.
Definition: optim_call_info_obtainer.h:64
virtual bool valueIsNeverChanged(ShPtr< Variable > var) const override
Returns true if the value of var is never changed in the call, false otherwise.
Definition: optim_call_info_obtainer.cpp:96
VarSet neverModifiedVars
Variables that are never modified in this function call.
Definition: optim_call_info_obtainer.h:58
virtual bool isNeverModified(ShPtr< Variable > var) const override
Returns true if there is no assign into var in the call, false otherwise.
Definition: optim_call_info_obtainer.cpp:84
virtual bool isAlwaysRead(ShPtr< Variable > var) const override
Returns true if var is always read in the call, false otherwise.
Definition: optim_call_info_obtainer.cpp:80
VarSet neverReadVars
Variables that are never read in this function call.
Definition: optim_call_info_obtainer.h:49
virtual bool mayBeRead(ShPtr< Variable > var) const override
Returns true if var may be read in the call, false otherwise.
Definition: optim_call_info_obtainer.cpp:76
VarSet varsAlwaysModifiedBeforeRead
Variables which are always modified before read in this function call.
Definition: optim_call_info_obtainer.h:70
VarSet varsWithNeverChangedValue
Variables whose value is never changed in this function call.
Definition: optim_call_info_obtainer.h:67
void debugPrint()
Emits the info to standard error.
Definition: optim_call_info_obtainer.cpp:42
A CFG traversal for computing OptimFuncInfos.
Definition: optim_func_info_cfg_traversal.h:34
Optimistic information about a function.
Definition: optim_call_info_obtainer.h:80
void debugPrint()
Emits the info to standard error.
Definition: optim_call_info_obtainer.cpp:115
virtual bool isAlwaysModifiedBeforeRead(ShPtr< Variable > var) const override
Returns true if the given variable is modified prior to being read in the function,...
Definition: optim_call_info_obtainer.cpp:173
VarSet alwaysModifiedVars
Variables that are always modified in this function.
Definition: optim_call_info_obtainer.h:117
virtual bool isNeverRead(ShPtr< Variable > var) const override
Returns true if var is never read in the function, false otherwise.
Definition: optim_call_info_obtainer.cpp:145
VarSet mayBeReadVars
Variables that may be read in this function.
Definition: optim_call_info_obtainer.h:105
virtual bool valueIsNeverChanged(ShPtr< Variable > var) const override
Returns true if the value of var is never changed in the call, false otherwise.
Definition: optim_call_info_obtainer.cpp:169
virtual bool isAlwaysModified(ShPtr< Variable > var) const override
Returns true if the value of var is always changed in the function, false otherwise.
Definition: optim_call_info_obtainer.cpp:165
VarSet neverModifiedVars
Variables that are never modified in this function.
Definition: optim_call_info_obtainer.h:111
VarSet mayBeModifiedVars
Variables that may be modified in this function.
Definition: optim_call_info_obtainer.h:114
VarSet varsAlwaysModifiedBeforeRead
Variables which are always modified before read in this function.
Definition: optim_call_info_obtainer.h:123
virtual bool isAlwaysRead(ShPtr< Variable > var) const override
Returns true if var is always read in the function, false otherwise.
Definition: optim_call_info_obtainer.cpp:153
VarSet varsWithNeverChangedValue
Variables whose value is never changed in this function.
Definition: optim_call_info_obtainer.h:120
VarSet neverReadVars
Variables that are never read in this function.
Definition: optim_call_info_obtainer.h:102
virtual bool mayBeModified(ShPtr< Variable > var) const override
Returns true if the value of var may be changed in the function, false otherwise.
Definition: optim_call_info_obtainer.cpp:161
virtual bool mayBeRead(ShPtr< Variable > var) const override
Returns true if var may be read in the function, false otherwise.
Definition: optim_call_info_obtainer.cpp:149
virtual bool isNeverModified(ShPtr< Variable > var) const override
Returns true if there is no assign into var in the function, false otherwise.
Definition: optim_call_info_obtainer.cpp:157
VarSet alwaysReadVars
Variables that are always read in this function.
Definition: optim_call_info_obtainer.h:108
OptimFuncInfo(ShPtr< Function > func)
Constructs a new optimistic piece of information about the given function.
Definition: optim_call_info_obtainer.cpp:108
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
std::set< ShPtr< Variable > > VarSet
Set of variables.
Definition: types.h:57
std::set< ShPtr< Function > > FuncSet
Set of functions.
Definition: types.h:78
Definition: archive_wrapper.h:19
Declarations, aliases, macros, etc. for the use of smart pointers.