org.jikesrvm.compilers.opt.ir
Class IRTools

java.lang.Object
  extended by org.jikesrvm.compilers.opt.ir.IRTools
Direct Known Subclasses:
CallingConvention, ComplexLIR2MIRExpansion, ConvertToLowLevelIR, ExpressionFolding, FinalMIRExpansion, GenericPhysicalRegisterTools, GenericStackManager, Simplifier

public abstract class IRTools
extends Object

This abstract class contains a bunch of useful static methods for performing operations on IR.


Constructor Summary
IRTools()
           
 
Method Summary
static RegisterOperand A(Register reg)
          Create an integer register operand for a given register.
static AddressConstantOperand AC(Address value)
          Create an address constant operand with a given value.
static AddressConstantOperand AC(Offset value)
           
static Instruction CPOS(Instruction src, Instruction dst)
          Copy the position information from the source instruction to the destination instruction, returning the source instruction.
static RegisterOperand CR(Register reg)
          Create a condition register operand for a given register.
static RegisterOperand D(Register reg)
          Create a double register operand for a given register.
static DoubleConstantOperand DC(double value)
          Create a long constant operand with a given value.
static boolean defDoublesAsUse(Operand d, Instruction s)
          Is the operand d, which is a def in instruction s, also a def in instruction s?
static boolean definedIn(Register r, Instruction s)
          Does instruction s define register r?
static RegisterOperand F(Register reg)
          Create a float register operand for a given register.
static FloatConstantOperand FC(float value)
          Create a long constant operand with a given value.
static Operator getCondMoveOp(TypeReference type)
          Returns the correct operator for a conditional move with the given data type.
static Operand getDefaultOperand(TypeReference type)
          Returns a constant operand with a default value for a given type
static Operator getLoadOp(FieldReference field, boolean isStatic)
          Returns the correct operator for loading from the given field
static Operator getLoadOp(TypeReference type, boolean isStatic)
          Returns the correct operator for loading a value of the given type
static Operator getMoveOp(TypeReference type)
          Returns the correct operator for moving the given data type.
static Operator getStoreOp(FieldReference field, boolean isStatic)
          Returns the correct operator for storing to the given field.
static Operator getStoreOp(TypeReference type, boolean isStatic)
          Returns the correct operator for storing a value of the given type
static RegisterOperand I(Register reg)
          Create an integer register operand for a given register.
static IntConstantOperand IC(int value)
          Create an integer constant operand with a given value.
static void insertInstructionsAfter(Instruction after, BasicBlock temp)
          Inserts the instructions in the given basic block after the given instruction.
static RegisterOperand L(Register reg)
          Create a long register operand for a given register.
static LongConstantOperand LC(long value)
          Create a long constant operand with a given value.
static BasicBlock makeBlockOnEdge(BasicBlock in, BasicBlock out, IR ir)
          Make an empty basic block on an edge in the control flow graph, and fix up the control flow graph and IR instructions accordingly.
static boolean mayBeVolatileFieldLoad(Instruction s)
          Might this instruction be a load from a field that is declared to be volatile?
static void moveInstruction(Instruction from, Instruction to)
          Moves the 'from' instruction to immediately before the 'to' instruction.
static RegisterOperand moveIntoRegister(ArchitectureSpecificOpt.RegisterPool pool, Instruction s, Operand op)
          Generates an instruction to move the given operand into a register, and inserts it before the given instruction.
static RegisterOperand moveIntoRegister(TypeReference type, Operator move_op, ArchitectureSpecificOpt.RegisterPool pool, Instruction s, Operand op)
          Generates an instruction to move the given operand into a register, and inserts it before the given instruction.
static Instruction nonPEIGC(Instruction instr)
          Mark the parameter as nonGC and nonPEI and return it.
static TrueGuardOperand TG()
          Create a new TrueGuardOperand.
static boolean usedIn(Register r, Instruction s)
          Does instruction s use register r?
static boolean useDoublesAsDef(Operand u, Instruction s)
          Is the operand u, which is a use in instruction s, also a def in instruction s?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IRTools

public IRTools()
Method Detail

A

public static RegisterOperand A(Register reg)
Create an integer register operand for a given register. To be used in passthrough expressions like
    ... Load.create(INT_LOAD, I(r2), A(r1), IC(4)) ...
 

Parameters:
reg - the given register
Returns:
integer register operand

I

public static RegisterOperand I(Register reg)
Create an integer register operand for a given register. To be used in passthrough expressions like
    ... Load.create(INT_LOAD, I(r2), A(r1), IC(4)) ...
 

Parameters:
reg - the given register
Returns:
integer register operand

F

public static RegisterOperand F(Register reg)
Create a float register operand for a given register. To be used in passthrough expressions like
    ... Load.create(FLOAT_LOAD, F(r2), A(r1), IC(4)) ...
 

Parameters:
reg - the given register
Returns:
float register operand

D

public static RegisterOperand D(Register reg)
Create a double register operand for a given register. To be used in passthrough expressions like
    ... Load.create(DOUBLE_LOAD, D(r2), A(r1), IC(4)) ...
 

Parameters:
reg - the given register
Returns:
double register operand

L

public static RegisterOperand L(Register reg)
Create a long register operand for a given register. To be used in passthrough expressions like
    ... Binary.create(LONG_LOAD, L(r2), A(r1), IC(4)) ...
 

Parameters:
reg - the given register
Returns:
long register operand

CR

public static RegisterOperand CR(Register reg)
Create a condition register operand for a given register. To be used in passthrough expressions like
    ... Binary.create(INT_CMP, CR(c2), I(r1), IC(4)) ...
 

Parameters:
reg - the given register
Returns:
condition register operand

AC

public static AddressConstantOperand AC(Address value)
Create an address constant operand with a given value. To be used in passthrough expressions like
    ....create(...., AC(Address.zero()) ...
 

Parameters:
value - The address constant
Returns:
address constant operand

AC

public static AddressConstantOperand AC(Offset value)

IC

public static IntConstantOperand IC(int value)
Create an integer constant operand with a given value. To be used in passthrough expressions like
    ....create(...., IC(0) ...
 

Parameters:
value - The int constant
Returns:
integer constant operand

LC

public static LongConstantOperand LC(long value)
Create a long constant operand with a given value. To be used in passthrough expressions like
    ....create(...., LC(0L) ...
 

Parameters:
value - the long value
Returns:
long constant operand

FC

public static FloatConstantOperand FC(float value)
Create a long constant operand with a given value. To be used in passthrough expressions like
    ....create(...., FC(0L) ...
 

Parameters:
value - the float value
Returns:
float constant operand

DC

public static DoubleConstantOperand DC(double value)
Create a long constant operand with a given value. To be used in passthrough expressions like
    ....create(...., DC(0L) ...
 

Parameters:
value - the double value
Returns:
double constant operand

TG

public static TrueGuardOperand TG()
Create a new TrueGuardOperand. To be used in passthrough expressions like
    ....create(...., TG() ...
 

Returns:
true guard operand

CPOS

public static Instruction CPOS(Instruction src,
                               Instruction dst)
Copy the position information from the source instruction to the destination instruction, returning the source instruction. To be used in passthrough expressions like
    instr.insertBack(CPOS(instr, Load.create(...)));
 

Parameters:
src - the instruction to copy position information from
dst - the instruction to copy position information to
Returns:
dest

getDefaultOperand

public static Operand getDefaultOperand(TypeReference type)
Returns a constant operand with a default value for a given type

Parameters:
type - desired type
Returns:
a constant operand with the default value for type

getMoveOp

public static Operator getMoveOp(TypeReference type)
Returns the correct operator for moving the given data type.

Parameters:
type - desired type to move
Returns:
the Operator to use for moving a value of the given type

getCondMoveOp

public static Operator getCondMoveOp(TypeReference type)
Returns the correct operator for a conditional move with the given data type.

Parameters:
type - desired type to move
Returns:
the Operator to use for moving a value of the given type

getLoadOp

public static Operator getLoadOp(FieldReference field,
                                 boolean isStatic)
Returns the correct operator for loading from the given field

Parameters:
field - field to load from
isStatic - is the field static
Returns:
the Operator to use when loading the given field

getLoadOp

public static Operator getLoadOp(TypeReference type,
                                 boolean isStatic)
Returns the correct operator for loading a value of the given type

Parameters:
type - type of value to load
isStatic - is the field static
Returns:
the Operator to use when loading the given field

getStoreOp

public static Operator getStoreOp(FieldReference field,
                                  boolean isStatic)
Returns the correct operator for storing to the given field.

Parameters:
field - The field we're asking about
isStatic - is the field static
Returns:
the Operator to use when storing to the given field

getStoreOp

public static Operator getStoreOp(TypeReference type,
                                  boolean isStatic)
Returns the correct operator for storing a value of the given type

Parameters:
type - desired type to store
isStatic - is the field static
Returns:
the Operator to use when storing to the given field

moveIntoRegister

public static RegisterOperand moveIntoRegister(ArchitectureSpecificOpt.RegisterPool pool,
                                               Instruction s,
                                               Operand op)
Generates an instruction to move the given operand into a register, and inserts it before the given instruction.

Parameters:
pool - register pool to allocate from
s - instruction to insert before
op - operand to copy to a register
Returns:
register operand that we copied into

moveIntoRegister

public static RegisterOperand moveIntoRegister(TypeReference type,
                                               Operator move_op,
                                               ArchitectureSpecificOpt.RegisterPool pool,
                                               Instruction s,
                                               Operand op)
Generates an instruction to move the given operand into a register, and inserts it before the given instruction.

Parameters:
type - type to move
move_op - move operator to use
pool - register pool to allocate from
s - instruction to insert before
op - operand to copy to a register
Returns:
last use register operand that we copied into

moveInstruction

public static void moveInstruction(Instruction from,
                                   Instruction to)
Moves the 'from' instruction to immediately before the 'to' instruction.

Parameters:
from - instruction to move
to - instruction after where you want it moved

insertInstructionsAfter

public static void insertInstructionsAfter(Instruction after,
                                           BasicBlock temp)
Inserts the instructions in the given basic block after the given instruction.

Parameters:
after - instruction after where you want it inserted
temp - basic block which contains the instructions to be inserted.

makeBlockOnEdge

public static BasicBlock makeBlockOnEdge(BasicBlock in,
                                         BasicBlock out,
                                         IR ir)
Make an empty basic block on an edge in the control flow graph, and fix up the control flow graph and IR instructions accordingly. This routine will create the control struture
 in -> bb -> out.
 
Precondition : There is an edge in the control flow graph from * in -> out.

Parameters:
in - the source of the control flow edge
out - the sink of the control flow edge
ir - the governing IR
Returns:
the new basic block bb

useDoublesAsDef

public static boolean useDoublesAsDef(Operand u,
                                      Instruction s)
Is the operand u, which is a use in instruction s, also a def in instruction s? That is, is this operand defined as a DU operand in InstructionFormatList.dat.

TODO!!: This implementation is slow. Think about adding some IR support for this functionality; possibly add methods like enumeratePureDefs(), enumerateImpureUses(), etc ..., and restructure the caller to avoid having to call this function. Not going to put effort into this now, as the whole scratch register architecture has a questionable future.


defDoublesAsUse

public static boolean defDoublesAsUse(Operand d,
                                      Instruction s)
Is the operand d, which is a def in instruction s, also a def in instruction s? That is, is this operand defined as a DU operand in InstructionFormatList.dat.

TODO!!: This implementation is slow. Think about adding some IR support for this functionality; possibly add methods like enumeratePureDefs(), enumerateImpureUses(), etc ..., and restructure the caller to avoid having to call this function. Not going to put effort into this now, as the whole scratch register architecture has a questionable future.


definedIn

public static boolean definedIn(Register r,
                                Instruction s)
Does instruction s define register r?


usedIn

public static boolean usedIn(Register r,
                             Instruction s)
Does instruction s use register r?


nonPEIGC

public static Instruction nonPEIGC(Instruction instr)
Mark the parameter as nonGC and nonPEI and return it. To be used in passthrough expressions like
    instr.insertBack(notPEIGC(Load.create(...)));
 

Parameters:
instr - the given instruction
Returns:
the given instruction

mayBeVolatileFieldLoad

public static boolean mayBeVolatileFieldLoad(Instruction s)
Might this instruction be a load from a field that is declared to be volatile?

Parameters:
s - the insruction to check
Returns:
true if the instruction might be a load from a volatile field or false if it cannot be a load from a volatile field