org.jikesrvm.compilers.opt
Class ExpressionFolding

java.lang.Object
  extended by org.jikesrvm.compilers.opt.ir.IRTools
      extended by org.jikesrvm.compilers.opt.ExpressionFolding

public class ExpressionFolding
extends IRTools

This class simplifies expressions globally, if in SSA form, or locally within a basic block if not.


Field Summary
private static boolean FOLD_2CONVERSION
          Fold xxx_2xxx where the precision is increased then decreased achieving a nop effect
private static boolean FOLD_ADDS
          Fold binary ADD operations
private static boolean FOLD_ANDS
          Fold binary AND operations
private static boolean FOLD_CHECKS
          Fold ZeroCheck where we're testing whether a value is 0 or not
private static boolean FOLD_CMPS
          Fold binary CMP operations
private static boolean FOLD_CONDMOVES
          Fold COND_MOVE operations
private static boolean FOLD_CONSTANTS_TO_LHS
          Fold operations that create a constant on the LHS?
private static boolean FOLD_DIVS
          Fold binary divide operations
private static boolean FOLD_DOUBLES
          Fold operations on doubles
private static boolean FOLD_FLOATS
          Fold operations on floats
private static boolean FOLD_IFCMPS
          Fold IFCMP operations
private static boolean FOLD_INTS
          Fold operations on ints
private static boolean FOLD_LONGS
          Fold operations on longs
private static boolean FOLD_MULTS
          Fold binary multiply operations
private static boolean FOLD_NEGS
          Fold unary NEG operations
private static boolean FOLD_NOTS
          Fold unary NOT operations
private static boolean FOLD_ORS
          Fold binary OR operations
private static boolean FOLD_OVER_UNINTERRUPTIBLE
          Fold across uninterruptible regions
private static boolean FOLD_REFS
          Fold operations on word like things
private static boolean FOLD_SHIFTLS
          Fold binary shift left operations
private static boolean FOLD_SHIFTRS
          Fold binary shift right operations
private static boolean FOLD_SUBS
          Fold binary SUB operations
private static boolean FOLD_XORS
          Fold binary XOR operations
private static boolean RESTRICT_TO_DEAD_EXPRESSIONS
          Only fold operations when the result of the 1st operation becomes dead after folding TODO: doesn't apply to local folding
private static boolean VERBOSE
          Print out debug information
 
Constructor Summary
ExpressionFolding()
           
 
Method Summary
private static Address getAddressValue(Operand op)
           
private static RegisterOperand getDefFromCandidate(Instruction s, boolean first)
          Get the register that's defined by the candidate instruction
private static double getDoubleValue(Operand op)
           
private static float getFloatValue(Operand op)
           
private static int getIntValue(Operand op)
           
private static long getLongValue(Operand op)
           
private static RegisterOperand getUseFromCandidate(Instruction s)
          Get the register that's used by the candidate instruction
private static Register isCandidateExpression(Instruction s, boolean ssa)
          Does instruction s compute a register r = candidate expression?
static void perform(IR ir)
          Perform the transformation.
static boolean performLocal(IR ir)
          Perform expression folding on individual basic blocks
private static void pruneCandidates(HashSet<Register> candidates)
          Prune the candidate set; restrict candidates to only allow transformations that result in dead code to be eliminated
private static Instruction transform(Instruction s, Instruction def)
          Perform the transformation on the instruction
 
Methods inherited from class org.jikesrvm.compilers.opt.ir.IRTools
A, AC, AC, CPOS, CR, D, DC, defDoublesAsUse, definedIn, F, FC, getCondMoveOp, getDefaultOperand, getLoadOp, getLoadOp, getMoveOp, getStoreOp, getStoreOp, I, IC, insertInstructionsAfter, L, LC, makeBlockOnEdge, mayBeVolatileFieldLoad, moveInstruction, moveIntoRegister, moveIntoRegister, nonPEIGC, TG, usedIn, useDoublesAsDef
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESTRICT_TO_DEAD_EXPRESSIONS

private static final boolean RESTRICT_TO_DEAD_EXPRESSIONS
Only fold operations when the result of the 1st operation becomes dead after folding TODO: doesn't apply to local folding

See Also:
Constant Field Values

FOLD_OVER_UNINTERRUPTIBLE

private static final boolean FOLD_OVER_UNINTERRUPTIBLE
Fold across uninterruptible regions

See Also:
Constant Field Values

FOLD_INTS

private static final boolean FOLD_INTS
Fold operations on ints

See Also:
Constant Field Values

FOLD_REFS

private static final boolean FOLD_REFS
Fold operations on word like things

See Also:
Constant Field Values

FOLD_LONGS

private static final boolean FOLD_LONGS
Fold operations on longs

See Also:
Constant Field Values

FOLD_FLOATS

private static final boolean FOLD_FLOATS
Fold operations on floats

See Also:
Constant Field Values

FOLD_DOUBLES

private static final boolean FOLD_DOUBLES
Fold operations on doubles

See Also:
Constant Field Values

FOLD_SUBS

private static final boolean FOLD_SUBS
Fold binary SUB operations

See Also:
Constant Field Values

FOLD_ADDS

private static final boolean FOLD_ADDS
Fold binary ADD operations

See Also:
Constant Field Values

FOLD_MULTS

private static final boolean FOLD_MULTS
Fold binary multiply operations

See Also:
Constant Field Values

FOLD_DIVS

private static final boolean FOLD_DIVS
Fold binary divide operations

See Also:
Constant Field Values

FOLD_SHIFTLS

private static final boolean FOLD_SHIFTLS
Fold binary shift left operations

See Also:
Constant Field Values

FOLD_SHIFTRS

private static final boolean FOLD_SHIFTRS
Fold binary shift right operations

See Also:
Constant Field Values

FOLD_CMPS

private static final boolean FOLD_CMPS
Fold binary CMP operations

See Also:
Constant Field Values

FOLD_XORS

private static final boolean FOLD_XORS
Fold binary XOR operations

See Also:
Constant Field Values

FOLD_ORS

private static final boolean FOLD_ORS
Fold binary OR operations

See Also:
Constant Field Values

FOLD_ANDS

private static final boolean FOLD_ANDS
Fold binary AND operations

See Also:
Constant Field Values

FOLD_NEGS

private static final boolean FOLD_NEGS
Fold unary NEG operations

See Also:
Constant Field Values

FOLD_NOTS

private static final boolean FOLD_NOTS
Fold unary NOT operations

See Also:
Constant Field Values

FOLD_CONSTANTS_TO_LHS

private static final boolean FOLD_CONSTANTS_TO_LHS
Fold operations that create a constant on the LHS? This may produce less optimal code on 2 address architectures where the constant would need loading into a register prior to the operation.

See Also:
Constant Field Values

FOLD_IFCMPS

private static final boolean FOLD_IFCMPS
Fold IFCMP operations

See Also:
Constant Field Values

FOLD_CONDMOVES

private static final boolean FOLD_CONDMOVES
Fold COND_MOVE operations

See Also:
Constant Field Values

FOLD_2CONVERSION

private static final boolean FOLD_2CONVERSION
Fold xxx_2xxx where the precision is increased then decreased achieving a nop effect

See Also:
Constant Field Values

FOLD_CHECKS

private static final boolean FOLD_CHECKS
Fold ZeroCheck where we're testing whether a value is 0 or not

See Also:
Constant Field Values

VERBOSE

private static final boolean VERBOSE
Print out debug information

See Also:
Constant Field Values
Constructor Detail

ExpressionFolding

public ExpressionFolding()
Method Detail

performLocal

public static boolean performLocal(IR ir)
Perform expression folding on individual basic blocks


getUseFromCandidate

private static RegisterOperand getUseFromCandidate(Instruction s)
Get the register that's used by the candidate instruction

Parameters:
s - the instruction
Returns:
register used by candidate or null if this isn't a candidate

getDefFromCandidate

private static RegisterOperand getDefFromCandidate(Instruction s,
                                                   boolean first)
Get the register that's defined by the candidate instruction

Parameters:
first - is this the first instruction?
s - the instruction
Returns:
register used by candidate or null if this isn't a candidate

perform

public static void perform(IR ir)
Perform the transformation. If we have, in SSA form,
    x = a op1 c1
    y = x op2 c2
 
where c1 and c2 are constants, replace the def of y by
 y = a op1 (c1 op3 c2)
 
Where op1, op2 and op3 are add, subtract, multiply, and, or, xor and compare. Repeatedly apply transformation until all expressions are folded.

PRECONDITIONS: SSA form, register lists computed

Parameters:
ir - the governing IR

pruneCandidates

private static void pruneCandidates(HashSet<Register> candidates)
Prune the candidate set; restrict candidates to only allow transformations that result in dead code to be eliminated


transform

private static Instruction transform(Instruction s,
                                     Instruction def)
Perform the transformation on the instruction

Parameters:
s - the instruction to transform of the form y = x op c1
def - the definition of x, the defining instruction is of the form x = a op c2
Returns:
the new instruction to replace s;

isCandidateExpression

private static Register isCandidateExpression(Instruction s,
                                              boolean ssa)
Does instruction s compute a register r = candidate expression?

Parameters:
s - the instruction
ssa - are we in SSA form?
Returns:
the computed register, or null

getIntValue

private static int getIntValue(Operand op)

getLongValue

private static long getLongValue(Operand op)

getFloatValue

private static float getFloatValue(Operand op)

getDoubleValue

private static double getDoubleValue(Operand op)

getAddressValue

private static Address getAddressValue(Operand op)