retdec
while_true_to_for_loop_optimizer.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_LLVMIR2HLL_OPTIMIZER_OPTIMIZERS_WHILE_TRUE_TO_FOR_LOOP_OPTIMIZER_H
8 #define RETDEC_LLVMIR2HLL_OPTIMIZER_OPTIMIZERS_WHILE_TRUE_TO_FOR_LOOP_OPTIMIZER_H
9 
13 
14 namespace retdec {
15 namespace llvmir2hll {
16 
17 class ArithmExprEvaluator;
18 class BinaryOpExpr;
19 class ValueAnalysis;
20 
47 public:
50 
51  virtual std::string getId() const override { return "WhileTrueToForLoop"; }
52 
53 private:
54  virtual void doOptimization() override;
55 
59  virtual void visit(ShPtr<WhileLoopStmt> stmt) override;
61 
63  ShPtr<IndVarInfo> indVarInfo) const;
65  ShPtr<IndVarInfo> indVarInfo) const;
67  ShPtr<IndVarInfo> indVarInfo,
68  ShPtr<Expression> startValue, ShPtr<Expression> step) const;
70 
72  ShPtr<BinaryOpExpr> expr);
73  static bool isNonNegative(ShPtr<Expression> expr);
74  static bool isPositive(ShPtr<Expression> expr);
75 
76 private:
79 
82 };
83 
84 } // namespace llvmir2hll
85 } // namespace retdec
86 
87 #endif
A base class of all function optimizers.
Definition: func_optimizer.h:44
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
Optimizes while loops into for loops.
Definition: while_true_to_for_loop_optimizer.h:46
ShPtr< Expression > computeEndCondOfForLoop(ShPtr< IndVarInfo > indVarInfo, ShPtr< Expression > startValue, ShPtr< Expression > step) const
Returns the end condition of the resulting for loop.
Definition: while_true_to_for_loop_optimizer.cpp:199
ShPtr< ValueAnalysis > va
Analysis of values.
Definition: while_true_to_for_loop_optimizer.h:78
ShPtr< Expression > computeStepOfForLoop(ShPtr< IndVarInfo > indVarInfo) const
Returns the step of the resulting for loop.
Definition: while_true_to_for_loop_optimizer.cpp:433
static ShPtr< BinaryOpExpr > exchangeCompOpAndOperands(ShPtr< BinaryOpExpr > expr)
Exchanges the operation and operands in the given binary comparison expression.
Definition: while_true_to_for_loop_optimizer.cpp:487
ShPtr< ConstInt > evaluate(ShPtr< Expression > expr) const
Tries to evaluate the given arithmetical expression and returns the resulting value.
Definition: while_true_to_for_loop_optimizer.cpp:472
virtual void visit(ShPtr< GlobalVarDef > varDef) override
Definition: ordered_all_visitor.cpp:95
WhileTrueToForLoopOptimizer(ShPtr< Module > module, ShPtr< ValueAnalysis > va, ShPtr< ArithmExprEvaluator > arithmExprEvaluator)
Constructs a new optimizer.
Definition: while_true_to_for_loop_optimizer.cpp:45
virtual void doOptimization() override
Performs the optimization on all functions in the module.
Definition: while_true_to_for_loop_optimizer.cpp:53
static bool isPositive(ShPtr< Expression > expr)
Returns true if the given expression represents a positive value, false otherwise.
Definition: while_true_to_for_loop_optimizer.cpp:545
ShPtr< ArithmExprEvaluator > arithmExprEvaluator
Evaluator of expressions.
Definition: while_true_to_for_loop_optimizer.h:81
ShPtr< Expression > computeStartValueOfForLoop(ShPtr< IndVarInfo > indVarInfo) const
Returns the start value of the resulting for loop.
Definition: while_true_to_for_loop_optimizer.cpp:186
static bool isNonNegative(ShPtr< Expression > expr)
Returns true if the given expression represents a non-negative value, false otherwise.
Definition: while_true_to_for_loop_optimizer.cpp:526
virtual std::string getId() const override
Returns the ID of the optimizer.
Definition: while_true_to_for_loop_optimizer.h:51
A base class of all function optimizers.
Utilities for 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
Declarations, aliases, macros, etc. for the use of smart pointers.