retdec
if_to_switch_optimizer.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_LLVMIR2HLL_OPTIMIZER_OPTIMIZERS_IF_TO_SWITCH_OPTIMIZER_H
8 #define RETDEC_LLVMIR2HLL_OPTIMIZER_OPTIMIZERS_IF_TO_SWITCH_OPTIMIZER_H
9 
11 
12 namespace retdec {
13 namespace llvmir2hll {
14 
15 class ValueAnalysis;
16 
64 class IfToSwitchOptimizer final: public FuncOptimizer {
65 public:
67 
68  virtual std::string getId() const override { return "IfToSwitch"; }
69 
70 private:
74  virtual void visit(ShPtr<IfStmt> stmt) override;
75 
79  eqOpExpr);
81  controlExpr);
82 
83 private:
86 };
87 
88 } // namespace llvmir2hll
89 } // namespace retdec
90 
91 #endif
A base class of all function optimizers.
Definition: func_optimizer.h:44
Optimizes if statements to switch statements.
Definition: if_to_switch_optimizer.h:64
virtual std::string getId() const override
Returns the ID of the optimizer.
Definition: if_to_switch_optimizer.h:68
void appendBreakStmtIfNeeded(ShPtr< Statement > stmt)
Append BreakStmt after stmt when stmt is not a ContinueStmt or ReturnStmt or GotoStmt.
Definition: if_to_switch_optimizer.cpp:172
ShPtr< ValueAnalysis > va
Analysis of values.
Definition: if_to_switch_optimizer.h:85
virtual void visit(ShPtr< GlobalVarDef > varDef) override
Definition: ordered_all_visitor.cpp:95
ShPtr< Expression > getNextOpIfSecondOneIsConstInt(ShPtr< EqOpExpr > eqOpExpr)
Check if one of the operands is a ConstInt. If so, then return the next one operand.
Definition: if_to_switch_optimizer.cpp:188
ShPtr< Expression > getControlExprIfConvertibleToSwitch(ShPtr< IfStmt > ifStmt)
Analyze if IfStmt can be optimized to SwitchStmt and if yes, return control expression.
Definition: if_to_switch_optimizer.cpp:57
void convertIfStmtToSwitchStmt(ShPtr< IfStmt > ifStmt, ShPtr< Expression > controlExpr)
Optimize ifStmt to SwitchStmt.
Definition: if_to_switch_optimizer.cpp:124
IfToSwitchOptimizer(ShPtr< Module > module, ShPtr< ValueAnalysis > va)
Constructs a new optimizer.
Definition: if_to_switch_optimizer.cpp:33
ShPtr< Module > module
The module that is being optimized.
Definition: optimizer.h:79
virtual void visit(ShPtr< GlobalVarDef > varDef) override
Definition: ordered_all_visitor.cpp:95
A base class of all function optimizers.
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