All Implemented Interfaces:
IPlugin, IEOptimizer, IOptimizer<IERoutineContext>
Direct Known Subclasses:
AbstractEBlockOptimizer, AbstractEExpressionOptimizer, AbstractEPatternOptimizer, AbstractEStatementOptimizer

public abstract class AbstractEOptimizer extends AbstractOptimizer<IERoutineContext> implements IEOptimizer
Base class for IR optimizers.

The no-arg constructor is for standard optimizers, with DFA updates handled internally.

  • Field Details

  • Constructor Details

  • Method Details

    • getMasterOptimizer

      public IEMasterOptimizer getMasterOptimizer()
      Description copied from interface: IOptimizer
      Retrieve the optional master optimizer that manages this optimizer.
      Specified by:
      getMasterOptimizer in interface IOptimizer<IERoutineContext>
      Overrides:
      getMasterOptimizer in class AbstractOptimizer<IERoutineContext>
      Returns:
      optional reference
    • getMasterOptimizerSafe

      protected IEMasterOptimizer getMasterOptimizerSafe()
      Safely retrieve a master optimizer. If getMasterOptimizer() provides one, it is returned. Else, an empty immutable generic MO is provided.
      Returns:
      never null
    • getDataChainsUpdatePolicy

      public DataChainsUpdatePolicy getDataChainsUpdatePolicy()
      Description copied from interface: IEOptimizer
      Get the data chains update policy after the optimization was performed.
      Specified by:
      getDataChainsUpdatePolicy in interface IEOptimizer
      Returns:
    • setDataChainsUpdatePolicy

      protected void setDataChainsUpdatePolicy(DataChainsUpdatePolicy dataChainsUpdatePolicy)
      This method should rarely be called; data-chains update policy is set up in the constructor, and should not change under normal circumstances.
      Parameters:
      dataChainsUpdatePolicy - null means DFA is handled internally, by the optimizer
    • performOnExpression

      public IEGeneric performOnExpression(IEGeneric exp, IERoutineContext ectx)
      The default implementation does nothing and returns null.
      Specified by:
      performOnExpression in interface IEOptimizer
      Parameters:
      exp - IR expression to optimize
      ectx - helper routine context
      Returns:
      non-null if the expression was optimized; null otherwise
    • performOnTarget

      public final int performOnTarget(IERoutineContext ctx)
      Same as perform(true). Data chains will be updated according to the optimizer's DFA policy.

      The above means that data chains after running this method may be modified, but must be in a consistent state with the CFG.

      Specified by:
      performOnTarget in interface IOptimizer<IERoutineContext>
      Returns:
      the number of optimizations performed; if negative, an error has occurred and the optimizing process should be aborted
    • perform

      protected abstract int perform()
      Perform the optimization pass. The caller may request that data chains not be updated, whenever possible. (They may be updated internally by the optimizer, which has the final say as to how and when DFA calculations should be run.)

      The above means that data chains after running this method may or may not have been modified, and may or may not be in a consistent state with the optimized CFG.

      Returns:
      the result of a call to one of postPerform(...) or a negative number indicating an error has occurred and the optimizing process should be aborted
    • postPerform

      protected final int postPerform(int totalOptimizationCount)
      Optimizers having DataChainsUpdatePolicy.UPDATE_IF_OPTIMIZED policy should return using this method.
      Parameters:
      totalOptimizationCount - count of optimizations
      Returns:
      the count of optimizations
    • postPerform

      protected final int postPerform(int totalOptimizationCount, boolean requestDFA)
      Optimizers having DataChainsUpdatePolicy.UPDATE_IF_OPTIMIZED or DataChainsUpdatePolicy.UPDATE_IF_REQUIRED policy should return using this method.
      Parameters:
      totalOptimizationCount - count of optimizations
      Returns:
      the count of optimizations
    • deleteUnreachableTrampoline

      protected boolean deleteUnreachableTrampoline(BasicBlock<IEStatement> b)
    • cleanCfg

      protected int cleanCfg()
    • verifyCfg

      protected void verifyCfg()
      Verify the CFG. Convenience method calling EUtil.verify(CFG).
    • dumpCfg

      protected void dumpCfg(String filename)
      Dump the CFG. Convenience method calling EUtil.dump(CFG, String).
      Parameters:
      filename - filename (the file will be created in the temp folder)