Class AbstractDExpressionOptimizer

All Implemented Interfaces:
IPlugin, IDOptimizer

public abstract class AbstractDExpressionOptimizer extends AbstractDOptimizer
Skeleton for a top-down, recursive, IDExpression optimizer. Expressions are provided in depth-first, pre-order way: parent expressions are provided before their constituting children.

By default, IDInstructions are not candidates for optimization (although they can be).

  • Field Details

    • skipStatementProcessing

      protected boolean skipStatementProcessing
      Optimize only the constituents of statements, not the statements themselves.
      Default value: true.
    • skipLeftSideOfAssignment

      protected boolean skipLeftSideOfAssignment
      Do not process left-side of statement.
      Default value: false.
    • currentStatement

      protected IDInstruction currentStatement
      This field holds a reference to the top-level parent statement of the expression currently being optimized.
    • portSourceType

      protected boolean portSourceType
      Copy the type of an expression to the replacement expression (via IDExpression.setType) over to the replacement expression.
      Default value: false.
  • Constructor Details

    • AbstractDExpressionOptimizer

      public AbstractDExpressionOptimizer()
      Create a standard expression optimizer.
    • AbstractDExpressionOptimizer

      public AbstractDExpressionOptimizer(DOptimizerType type)
      Create an expression optimizer.
      Parameters:
      type - optimizer type, or null to use DOptimizerType.NORMAL
    • AbstractDExpressionOptimizer

      public AbstractDExpressionOptimizer(DOptimizerType type, String name)
      Create an expression optimizer.
      Parameters:
      type - optimizer type, or null to use DOptimizerType.NORMAL
      name - optional optimizer name
  • Method Details

    • perform

      public int perform()
      Description copied from class: AbstractDOptimizer
      An optimizer must implement this method. This method is called by a master optimizer to perform the optimization on the selected target.

      Note that the optimizer is responsible for returning a legal method context, e.g.: the method IR instructions must be consistent with the CFG; the CFG must adhere to certain rules (see cleanGraph); if the data flow analysis is no longer valid, it should be invalidated (see resetDFA); etc.

      Specified by:
      perform in class AbstractDOptimizer
      Returns:
      the number of optimizations performed, 0 if none
    • performOnExpression

      public IDExpression performOnExpression(IDExpression exp, IDMethodContext ctx)
      Run this optimizer on a standalone expression.
      Parameters:
      exp - expression to optimize
      ctx - method context
      Returns:
      replacement expression, or null if the input expression was not optimized
    • optimizeExpression

      protected abstract DOR optimizeExpression(IDExpression e)
      Attempt to optimize expressions. Sub-expressions may be examined. The implementor should not attempt to modify parent or cousins expressions.
      Parameters:
      e - IR expression
      Returns:
      the new (optimized) expression as well as DFA update hints, or null if the expression could not be optimized
    • doSubstitution

      protected IDExpression doSubstitution(IDExpression e, SubstitutionDefinition... substitutions)
      Attempt to apply the first matching SubstitutionDefinition on an IDExpression expression.
      Parameters:
      e - the target IR expression to be matched and modified
      substitutions - a list of candidate substitutions
      Returns:
      null if no substitution was performed, else the new expression