public class ExpressionFolding extends IRTools
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
ExpressionFolding() |
Modifier and Type | Method and Description |
---|---|
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
|
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, offsetOperand, TG, usedIn, useDoublesAsDef
private static final boolean RESTRICT_TO_DEAD_EXPRESSIONS
private static final boolean FOLD_OVER_UNINTERRUPTIBLE
private static final boolean FOLD_INTS
private static final boolean FOLD_REFS
private static final boolean FOLD_LONGS
private static final boolean FOLD_FLOATS
private static final boolean FOLD_DOUBLES
private static final boolean FOLD_SUBS
private static final boolean FOLD_ADDS
private static final boolean FOLD_MULTS
private static final boolean FOLD_DIVS
private static final boolean FOLD_SHIFTLS
private static final boolean FOLD_SHIFTRS
private static final boolean FOLD_CMPS
private static final boolean FOLD_XORS
private static final boolean FOLD_ORS
private static final boolean FOLD_ANDS
private static final boolean FOLD_NEGS
private static final boolean FOLD_NOTS
private static final boolean FOLD_CONSTANTS_TO_LHS
private static final boolean FOLD_IFCMPS
private static final boolean FOLD_CONDMOVES
private static final boolean FOLD_2CONVERSION
private static final boolean FOLD_CHECKS
private static final boolean VERBOSE
public ExpressionFolding()
public static boolean performLocal(IR ir)
ir
- the IR that contains the blocksprivate static RegisterOperand getUseFromCandidate(Instruction s)
s
- the instructionnull
if this isn't a candidateprivate static RegisterOperand getDefFromCandidate(Instruction s, boolean first)
first
- is this the first instruction?s
- the instructionnull
if this isn't a candidatepublic static void perform(IR ir)
x = a op1 c1 y = x op2 c2where 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
ir
- the governing IRprivate static void pruneCandidates(HashSet<Register> candidates)
candidates
- the candidates to pruneprivate static Instruction transform(Instruction s, Instruction def)
s
- the instruction to transform of the form y = x op c1def
- the definition of x, the defining instruction is of the form x = a
op c2private static Register isCandidateExpression(Instruction s, boolean ssa)
s
- the instructionssa
- are we in SSA form?null
private static int getIntValue(Operand op)
private static long getLongValue(Operand op)
private static float getFloatValue(Operand op)
private static double getDoubleValue(Operand op)
private static Address getAddressValue(Operand op)