retdec
Public Member Functions | Private Member Functions | Private Attributes | List of all members
retdec::llvmir2hll::OptimizerManager Class Referencefinal

A manager managing optimizations. More...

#include <optimizer_manager.h>

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

Public Member Functions

 OptimizerManager (const StringSet &enabledOpts, const StringSet &disabledOpts, ShPtr< HLLWriter > hllWriter, ShPtr< ValueAnalysis > va, ShPtr< CallInfoObtainer > cio, ShPtr< ArithmExprEvaluator > arithmExprEvaluator, bool enableAggressiveOpts, bool enableDebug=false)
 Constructs a new optimizer manager. More...
 
void optimize (ShPtr< Module > m)
 Runs the optimizations over m. More...
 

Private Member Functions

void printOptimization (const std::string &optName) const
 Prints debug information about the currently run optimization with optId. More...
 
bool optShouldBeRun (const std::string &optName) const
 Returns true if the optimization with optId should be run, false otherwise. More...
 
void runOptimizerProvidedItShouldBeRun (ShPtr< Optimizer > optimizer)
 Runs the given optimizer provided that it should be run. More...
 
bool shouldSecondCopyPropagationBeRun () const
 Returns true if a second pass of CopyPropagation should be run, false otherwise. More...
 
template<typename Optimization , typename... Args>
void run (ShPtr< Module > m, Args &&... args)
 Runs the given optimization (specified in the template parameter) over m with the given arguments. More...
 
- Private Member Functions inherited from retdec::utils::NonCopyable
 NonCopyable (const NonCopyable &)=delete
 
NonCopyableoperator= (const NonCopyable &)=delete
 
 NonCopyable ()=default
 
 ~NonCopyable ()=default
 

Private Attributes

const StringSet enabledOpts
 No other optimization than these will be run. More...
 
const StringSet disabledOpts
 Optimizations that won't be run. More...
 
ShPtr< HLLWriterhllWriter
 Used HLL writer. More...
 
ShPtr< ValueAnalysisva
 Used value analysis. More...
 
ShPtr< CallInfoObtainercio
 Used call info obtainer. More...
 
ShPtr< ArithmExprEvaluatorarithmExprEvaluator
 Used evaluator of arithmetical expressions. More...
 
bool enableAggressiveOpts
 Enable aggressive optimizations? More...
 
bool enableDebug
 Enable emission of debug messages? More...
 
bool recoverFromOutOfMemory
 Should we recover from out-of-memory errors during optimizations? More...
 
StringSet backendRunOpts
 List of our optimizations that were run. More...
 

Detailed Description

A manager managing optimizations.

Instances of this class have reference object semantics. This class is not meant to be subclassed.

Constructor & Destructor Documentation

◆ OptimizerManager()

retdec::llvmir2hll::OptimizerManager::OptimizerManager ( const StringSet enabledOpts,
const StringSet disabledOpts,
ShPtr< HLLWriter hllWriter,
ShPtr< ValueAnalysis va,
ShPtr< CallInfoObtainer cio,
ShPtr< ArithmExprEvaluator arithmExprEvaluator,
bool  enableAggressiveOpts,
bool  enableDebug = false 
)

Constructs a new optimizer manager.

Parameters
[in]enabledOptsNames of optimizations. No other optimizations than these will be run.
[in]disabledOptsNames of optimizations. These optimizations will not be run.
[in]hllWriterHLL writer.
[in]vaValue analysis.
[in]cioCall info obtainer.
[in]arithmExprEvaluatorUsed evaluator of arithmetical expressions.
[in]enableAggressiveOptsEnables aggressive optimizations.
[in]enableDebugEnables emission of debug messages.

To perform the actual optimizations, call optimize(). To get a list of available optimizations and their names, see our wiki. The names are class names of optimizers (like CopyPropagationOptimizer). You may or may not include the "Optimizer" suffix.

If enabledOpts is empty, all optimizations are run. If disabledOpts is empty, also all optimizations are run. If an optimization is in both enabledOpts and disabledOpts, it is not run.

Aggressive optimizations are run only if enableAggressiveOpts is true, or they are specified in enabledOpts.

hllWriter, va, and cio are needed in some optimizations, so they have to be provided.

Preconditions
  • hllWriter, va, cio, and arithmExprEvaluator are non-null

Member Function Documentation

◆ optimize()

void retdec::llvmir2hll::OptimizerManager::optimize ( ShPtr< Module m)

Runs the optimizations over m.

◆ optShouldBeRun()

bool retdec::llvmir2hll::OptimizerManager::optShouldBeRun ( const std::string &  optName) const
private

Returns true if the optimization with optId should be run, false otherwise.

◆ printOptimization()

void retdec::llvmir2hll::OptimizerManager::printOptimization ( const std::string &  optId) const
private

Prints debug information about the currently run optimization with optId.

If enableDebug is false, this function does nothing.

◆ run()

template<typename Optimization , typename... Args>
void retdec::llvmir2hll::OptimizerManager::run ( ShPtr< Module m,
Args &&...  args 
)
private

Runs the given optimization (specified in the template parameter) over m with the given arguments.

Template Parameters
OptimizationOptimization to be performed.
Parameters
[in]mModule to be optimized.
[in]argsArguments to be passed to the optimization.

If the optimization is in disabledOpts, it is not run. If enabledOpts is non-empty and it doesn't contain the optimization, it is also not run.

If enableDebug is true, debug messages are emitted.

◆ runOptimizerProvidedItShouldBeRun()

void retdec::llvmir2hll::OptimizerManager::runOptimizerProvidedItShouldBeRun ( ShPtr< Optimizer optimizer)
private

Runs the given optimizer provided that it should be run.

◆ shouldSecondCopyPropagationBeRun()

bool retdec::llvmir2hll::OptimizerManager::shouldSecondCopyPropagationBeRun ( ) const
private

Returns true if a second pass of CopyPropagation should be run, false otherwise.

Member Data Documentation

◆ arithmExprEvaluator

ShPtr<ArithmExprEvaluator> retdec::llvmir2hll::OptimizerManager::arithmExprEvaluator
private

Used evaluator of arithmetical expressions.

◆ backendRunOpts

StringSet retdec::llvmir2hll::OptimizerManager::backendRunOpts
private

List of our optimizations that were run.

◆ cio

ShPtr<CallInfoObtainer> retdec::llvmir2hll::OptimizerManager::cio
private

Used call info obtainer.

◆ disabledOpts

const StringSet retdec::llvmir2hll::OptimizerManager::disabledOpts
private

Optimizations that won't be run.

◆ enableAggressiveOpts

bool retdec::llvmir2hll::OptimizerManager::enableAggressiveOpts
private

Enable aggressive optimizations?

◆ enableDebug

bool retdec::llvmir2hll::OptimizerManager::enableDebug
private

Enable emission of debug messages?

◆ enabledOpts

const StringSet retdec::llvmir2hll::OptimizerManager::enabledOpts
private

No other optimization than these will be run.

◆ hllWriter

ShPtr<HLLWriter> retdec::llvmir2hll::OptimizerManager::hllWriter
private

Used HLL writer.

◆ recoverFromOutOfMemory

bool retdec::llvmir2hll::OptimizerManager::recoverFromOutOfMemory
private

Should we recover from out-of-memory errors during optimizations?

◆ va

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

Used value analysis.


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