# Class: com.pnfsoftware.jeb.core.units.code.android.ir.AbstractDOptimizer

Base class for `dexdec` \(DEX decompiler\) IR optimizer plugins. Those plugins can access and modify the intermediate representation of a method being decompiled. They can be used to implement a wide range of optimizations, from trivial code clean\-up to the most complex deobfuscation passes. Internally, `dexdec` uses IR optimizers to perform dead\-code removal, variable substitutions, immediate propagation, restructuring, constant folding, arithmetic operation simplifications, deobfuscations such as control\-flow unflattening, etc. 

 Optimizers are usually managed by [master optimizers](IDMasterOptimizer) \(also called `orchestrators`\). Third\-party optimizer plugins can be automatically registered when creating an orchestrator. Refer to [createMasterOptimizer](IDGlobalContext#createMasterOptimizer(IDMethodContext)). 

 Life\-cycle information:
 \- plugins are reused \(i.e. the [#perform()](#perform()) method is called multiple times\)
 \- thread\-safety:
 \-\- Python script plugins must be thread\-safe: a plugin instance may be executed by multiple threads concurrently
 \-\- Java plugins \(including Java script plugins\) are not required to be thread\-safe: a plugin instance will not be executed by multiple threads concurrently

## Constructor: AbstractDOptimizer

Description: Create a [standard](DOptimizerType#NORMAL) optimizer.

## Constructor: AbstractDOptimizer
- parameter: `type`, type: `com.pnfsoftware.jeb.core.units.code.android.ir.DOptimizerType`

Description: Create an optimizer.
parameter: type: optimizer type, or null to use [DOptimizerType#NORMAL](DOptimizerType#NORMAL)

## Constructor: AbstractDOptimizer
- parameter: `type`, type: `com.pnfsoftware.jeb.core.units.code.android.ir.DOptimizerType`
- parameter: `name`, type: `java.lang.String`

Description: Create an optimizer.
parameter: type: optimizer type, or null to use [DOptimizerType#NORMAL](DOptimizerType#NORMAL)
parameter: name: optional optimizer name

## Field: cfg
Type: `com.pnfsoftware.jeb.core.units.code.android.controlflow.CFG<com.pnfsoftware.jeb.core.units.code.android.ir.IDInstruction>`
Description: Target method's IR CFG, set up for convenience \(see [IDMethodContext#getCfg()](IDMethodContext#getCfg())\)

## Field: ctx
Type: `com.pnfsoftware.jeb.core.units.code.android.ir.IDMethodContext`
Description: Target method's IR context

## Field: ctxlist
Type: `java.util.List<com.pnfsoftware.jeb.core.units.code.android.ir.IDMethodContext>`
Description: If the optimizer is a regular method optimizer \(an optimizer targeting a single method\), this field is null.
 If the optimizer is a class optimizer, [#ctx](#ctx) and [#cfg](#cfg) will be initially set to null, and this field contains the list of IR method contexts available to the optimizer.

## Field: decomp
Type: `com.pnfsoftware.jeb.core.units.code.android.IDexDecompilerUnit`
Description: Managing dex decompiler.

## Field: dex
Type: `com.pnfsoftware.jeb.core.units.code.android.IDexUnit`
Description: Underlying dex code.

## Field: dfa
Type: `com.pnfsoftware.jeb.core.units.code.IDFA<com.pnfsoftware.jeb.core.units.code.android.ir.IDInstruction>`
Description: The data flow analysis object is initially UNINITIALIZED. To initialize one, call [#analyzeChains(boolean)](#analyzeChains(boolean)).

## Field: g
Type: `com.pnfsoftware.jeb.core.units.code.android.ir.IDGlobalContext`
Description: IR global context.

## Field: of
Type: `com.pnfsoftware.jeb.core.units.code.java.IJavaOperatorFactory`
Description: IR/AST operation factory reference \(for convenience\).

## Field: tf
Type: `com.pnfsoftware.jeb.core.units.code.java.IJavaTypeFactory`
Description: IR/AST type factory reference \(for convenience\).

## Static Field: logger
Type: `com.pnfsoftware.jeb.util.logging.ILogger`
Description: Public logger accessible by the implementing optimizer. Writing to the logger should be favored over writing directly to `stdout`.

## Protected Method: addTag
- parameter: `tag`, type: `java.lang.String`

Description: Add an optimizer tag.
parameter: tag: tag to add

## Protected Method: analyzeChains
- parameter: `redo`, type: `boolean`
- return type: `com.pnfsoftware.jeb.core.units.code.IDFA<com.pnfsoftware.jeb.core.units.code.android.ir.IDInstruction>`

Description: Retrieve and set the [#dfa](#dfa) field, a data flow analysis object for [#cfg](#cfg).
parameter: redo: if true, a new object will be generated; otherwise, a previously generated DFA            object may be returned
return: the DFA, also available as a protected field [#dfa](#dfa)

## Protected Method: analyzeChains
- return type: `com.pnfsoftware.jeb.core.units.code.IDFA<com.pnfsoftware.jeb.core.units.code.android.ir.IDInstruction>`

Description: Retrieve and set the [#dfa](#dfa) field, a data flow analysis object for [#cfg](#cfg).
return: the DFA, also available as a protected field [#dfa](#dfa)

## Method: assignLocalFields
- parameter: `_ctx`, type: `com.pnfsoftware.jeb.core.units.code.android.ir.IDMethodContext`

Description: This convenience method can be used to assign the object's attributes \(e.g. `g`, `ctx`, `cfg`, etc.\) from the values of the provided IR context.
parameter: _ctx: an IR context

## Protected Method: checkInterrupted

Description: Verify if an interruption request was made by the managing decompiler. This method may be called when potentially length computations are performed in a loop.

## Protected Method: cleanGraph
- return type: `int`

Description: Perform clean\-up after a change in CFG structure. This method will remove unreachable blocks and simplify conditional jumps and switches.
return: the number of clean\-up operations performed

## Protected Method: cleanGraph
- parameter: `doRemoveUnreachableBlocks`, type: `boolean`
- parameter: `doSimplifyJCondsAndSwitches`, type: `boolean`
- return type: `int`

Description: Perform clean\-up after a change in CFG structure. Convenience method.
parameter: doRemoveUnreachableBlocks: if true, will call            [DUtil#removeUnreachableBlocks(IDMethodContext)](DUtil#removeUnreachableBlocks(IDMethodContext))
parameter: doSimplifyJCondsAndSwitches: if true, will call            [DUtil#simplifyJCondsAndSwitches(IDMethodContext)](DUtil#simplifyJCondsAndSwitches(IDMethodContext))
return: the number of clean\-up operations performed

## Protected Method: debugDump


## Protected Method: debugVerify


## Method: getName
- return type: `java.lang.String`


## Method: getPluginInformation
- return type: `com.pnfsoftware.jeb.core.EditablePluginInformation`


## Method: getPriority
- return type: `double`


## Method: getTags
- return type: `java.util.Set<java.lang.String>`


## Method: getType
- return type: `com.pnfsoftware.jeb.core.units.code.android.ir.DOptimizerType`


## Protected Method: invalidateChains

Description: Invalidate the DFA of [#cfg](#cfg). The [#dfa](#dfa) field is also reset to `null`.

## Method: isCollectionOptimizer
- return type: `boolean`


## Method: isEnabled
- return type: `boolean`


## Method: perform
- parameter: `ctx`, type: `com.pnfsoftware.jeb.core.units.code.android.ir.IDMethodContext`
- return type: `int`


## Method: perform
- return type: `int`

Description: An optimizer must implement this method. This method is called by a master optimizer to perform the optimization on the [selected](#assignLocalFields(IDMethodContext)) 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](#cleanGraph())\); if the data flow analysis is no longer valid, it should be invalidated \(see [resetDFA](CFG#invalidateDataFlowAnalysis())\); etc.
return: the number of optimizations performed, 0 if none

## Method: performOnCollection
- parameter: `ctxlist`, type: `java.util.List<com.pnfsoftware.jeb.core.units.code.android.ir.IDMethodContext>`
- parameter: `pmcntmap`, type: `java.util.Map<com.pnfsoftware.jeb.core.units.code.android.ir.IDMethodContext,java.lang.Integer>`
- return type: `int`


## Protected Method: removeTag
- parameter: `tag`, type: `java.lang.String`

Description: Remove an optimizer tag.
parameter: tag: tag to remove

## Method: resetLocalFields

Description: Reset this object's attributes. Same as [assignLocalFields\(null\)](#assignLocalFields(IDMethodContext)).

## Method: setEnabled
- parameter: `enabled`, type: `boolean`

Description: Enable or disable this optimizer. This flag is checked by a [master optimizer](IDMasterOptimizer).
parameter: enabled: true to enable this optimizer

## Protected Method: setName
- parameter: `name`, type: `java.lang.String`

Description: Set the optimizer name. To be used by the constructor.
parameter: name: if null, a name will be auto\-generated

## Protected Method: setPriority
- parameter: `priority`, type: `double`

Description: Set the optimizer priority. To be used by the constructor.
parameter: priority: the new priority \(high means higher priority\). When optimizers are managed            and run by an orchestrator, the optimizers with a higher priority are run before            those having a lower priority. The default priority is 0.

## Protected Method: setType
- parameter: `type`, type: `com.pnfsoftware.jeb.core.units.code.android.ir.DOptimizerType`

Description: Set the optimizer type. To be used by the constructor.
parameter: type: if null, a [standard](DOptimizerType#NORMAL) optimizer is assumed

