scale.backend
Class Instruction

java.lang.Object
  extended by scale.backend.Instruction
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
Branch, ConstantInstruction, FltOpInstruction, IntOpInstruction, IntOpLitInstruction, Marker, MemoryInstruction, MipsInstruction, PPCInstruction, SparcInstruction, TripsInstruction, X86Instruction

public abstract class Instruction
extends java.lang.Object
implements java.lang.Cloneable

This is the abstract class for all machine instructions including Markers.

$Id: Instruction.java,v 1.57 2007-10-17 23:21:34 bmaher Exp $

Copyright 2008 by the Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.

Flags

Various flags are used to mark instructions:
END_INST
This instruction is the last in a sequence. In particular, an instruction that ends a sequence can be used as a place to insert spill stores. Most instructions do not end a sequence. There may be several starts between every end.
START_INST
This instruction starts a sequence of instructions. In particular, an instruction that starts a sequence can be used as a place to insert spill loads. Most instructions can start a sequence. However, if there is a sequence of instructions that can not be split by a spill load, all but the first must be marked as not starting a sequence. There may be several starts between every end.
NULLIFIED_INST
This instruction is no longer used.
MANDATORY_INST
This instruction should never be eliminated. An example of a mandatory instruction would be a load of a "volatile" variable. Another example would be an instruction with no outputs such as a status setting instruction or a nop inserted for timing purposes.
SPILL_INST
This instruction was inserted as part of a spill sequence.


Constructor Summary
protected Instruction()
           
 
Method Summary
abstract  void assembler(Assembler asm, Emit emit)
          Insert the assembler representation of the instruction into the output stream.
 boolean canBeDeleted(RegisterSet registers)
          Return true if the instruction can be deleted without changing the program's semantics.
 java.lang.Object clone()
          Clone the instruction.
 Instruction copy()
          Make a copy of this instruction.
 boolean defs(int register, RegisterSet registers)
          Return true if the instruction sets the register.
 int ehash()
          Return a hash code that can be used to determine equivalence.
 int getBBID()
          Get the basic block number of the instruction.
 int getCopyDest()
          Return the source register of a copy instruction.
 int getCopySrc()
          Return the source register of a copy instruction.
 int getDestRegister()
          Return the destination register or -1 if none.
 int getExecutionCycles()
          Return the number of cycles that this instruction requires.
 int getFunctionalUnit()
          Return the number of the functional unit required to execute this instruction.
 int getLoopNumber()
          Return the loop number of the instruction.
 Instruction getNext()
          Return the next lexical instruction.
abstract  int getOpcode()
          Return the numeric opcode of the instruction.
 int getPredicate(int i)
          Return the specified predicate.
 int[] getPredicates()
          Return the predicates for the instruction.
 int[] getSrcRegisters()
          Return the source registers or null if none.
 int getTag()
          Get the tag value.
abstract  boolean independent(Instruction inst, RegisterSet registers)
          Return true if this instruction is independent of the specified instruction.
abstract  int instructionSize()
          Return the number of bytes required for the instruction.
 boolean isBranch()
          Return true if this is a branch instruction.
 boolean isCopy()
          Return true if the instruction copies a value from one register to another without modification.
 boolean isLabel()
          Return true if this is a LabelMarker.
 boolean isLoad()
          Return true if this is a load-from-memory instruction.
 boolean isMandatory()
          Return true if this instruction is mandatory.
 boolean isMarker()
          Return true if this is a Marker.
 boolean isPhi()
          Return true if this is a phi instruction.
 boolean isPredicated()
          Return true if the instruction is predicated.
 boolean isPredicatedOnTrue()
          Returns true if the instruction is predicated on true.
 boolean isPrefetch()
          Return true if this is a prefetch instruction.
 boolean isSpillInstruction()
          Return true if this instruction was inserted as part of a spill load or spill store sequence.
 boolean isSpillLoadPoint()
          Return true if this instruction is the first in a sequence of instructions.
 boolean isSpillStorePoint()
          Return true if this instruction is the last in a sequence of instructions.
 boolean isStore()
          Return true if this is a store-into-memory instruction.
 void markSpillInstruction()
          Mark this instruction as part of a spill load or spill store sequence.
 boolean mods(int register, RegisterSet registers)
          Return true if the instruction clobbers the register.
 boolean nullified()
          Return true if the instruction is nullified.
 void nullify(RegisterSet rs)
          Mark the instruction so that it is not used.
 int numPredicates()
          Return the number of predicates.
abstract  void remapDestRegister(int oldReg, int newReg)
          Map the registers defined in the instruction as destinations to the specified register.
abstract  void remapRegisters(int[] map)
          Map the virtual registers referenced in the instruction to the specified real registers.
abstract  void remapSrcRegister(int oldReg, int newReg)
          Map the registers used in the instruction as sources to the specified register.
 void removePredicates()
          Remove the predicates from this instruction.
 void setBBID(int bbid)
          Set the basic block number of the instruction.
protected  void setLoopNumber(int loopNumber)
          Set the loop number of the instruction.
 void setMandatory()
          Specify that this instruction should never be eliminated.
 void setNext(Instruction next)
          Set the next lexical instruction.
 void setPredicate(int rp)
          Set the predicate for the instruction.
 void setPredicate(int rp, boolean predicatedOnTrue)
          Set the predicate for the instruction.
 void setPredicatedOnTrue(boolean predicatedOnTrue)
          Set the condition for the predicate.
 void setPredicates(int[] predicates)
          Specify the predicates for the instruction.
 boolean setsSpecialReg()
          Return true if this instruction has a side effect of changing a special register.
 void setTag(int tag)
          Set the tag value.
 void specifyNotSpillLoadPoint()
          Specify that this instruction is not the first in a sequence of instructions.
abstract  void specifyRegisterUsage(RegisterAllocator rs, int index, int strength)
          Specify the registers used and defined by this instruction.
 void specifySpillStorePoint()
          Specify that this instruction is the last in a sequence of instructions and that a spill store can be inserted after it.
 boolean uses(int register, RegisterSet registers)
          Return true if the instruction uses the register.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Instruction

protected Instruction()
Method Detail

copy

public Instruction copy()
Make a copy of this instruction.

Returns:
the copy of the instruction

remapRegisters

public abstract void remapRegisters(int[] map)
Map the virtual registers referenced in the instruction to the specified real registers. The mapping is specified using an array that is indexed by the virtual register to return the real register.

Parameters:
map - maps from the virtual register to real register

remapSrcRegister

public abstract void remapSrcRegister(int oldReg,
                                      int newReg)
Map the registers used in the instruction as sources to the specified register. If the register is not used as a source register, no change is made.

Parameters:
oldReg - is the previous source register
newReg - is the new source register

remapDestRegister

public abstract void remapDestRegister(int oldReg,
                                       int newReg)
Map the registers defined in the instruction as destinations to the specified register. If the register is not used as a destination register, no change is made.

Parameters:
oldReg - is the previous destination register
newReg - is the new destination register

getOpcode

public abstract int getOpcode()
Return the numeric opcode of the instruction. This opcode may be an encoding of the actual instruction opcode.


getDestRegister

public int getDestRegister()
Return the destination register or -1 if none.


getSrcRegisters

public int[] getSrcRegisters()
Return the source registers or null if none.


nullify

public void nullify(RegisterSet rs)
Mark the instruction so that it is not used.


nullified

public final boolean nullified()
Return true if the instruction is nullified.


setMandatory

public final void setMandatory()
Specify that this instruction should never be eliminated. An example of a mandatory instruction would be a load of a "volatile" variable. Another example would be an instruction with no outputs such as a status setting instruction or a nop inserted for timing purposes.


isMandatory

public final boolean isMandatory()
Return true if this instruction is mandatory. An example of a mandatory instruction would be a load of a "volatile" variable. Another example would be an instruction with no outputs such as a status setting instruction or a nop inserted for timing purposes.


markSpillInstruction

public final void markSpillInstruction()
Mark this instruction as part of a spill load or spill store sequence.


isSpillInstruction

public boolean isSpillInstruction()
Return true if this instruction was inserted as part of a spill load or spill store sequence.


setTag

public final void setTag(int tag)
Set the tag value. The tag is used by various algorithmns.


getTag

public final int getTag()
Get the tag value. The tag is used by various algorithmns.


getExecutionCycles

public int getExecutionCycles()
Return the number of cycles that this instruction requires.


getFunctionalUnit

public int getFunctionalUnit()
Return the number of the functional unit required to execute this instruction.


specifySpillStorePoint

public final void specifySpillStorePoint()
Specify that this instruction is the last in a sequence of instructions and that a spill store can be inserted after it. Some sequences of instructions may define a register and then go on to modify that register. Sometimes these sequences utilize a branch. An example is the sequence generated for a divide on some architectures. If a spill store is needed for the result register, it is not valid to do the store before the sequence is complete. This flag is currently set when a ExprChord instance is translated or after the predicate of an if-then-else is evaluated.

See Also:
isSpillStorePoint(), specifyNotSpillLoadPoint(), isSpillLoadPoint()

isSpillStorePoint

public final boolean isSpillStorePoint()
Return true if this instruction is the last in a sequence of instructions. A sequence is defined to be the sequence of instructions that define a value. In particular, an instruction that ends a sequence can be used as a place to insert spill stores. Most instructions do not end a sequence. There may be several starts between every end. This flag is currently set when a ExprChord instance is translated.

See Also:
specifySpillStorePoint(), specifyNotSpillLoadPoint(), isSpillLoadPoint()

specifyNotSpillLoadPoint

public final void specifyNotSpillLoadPoint()
Specify that this instruction is not the first in a sequence of instructions. A sequence is defined to be the sequence of instructions that define a value.

See Also:
specifySpillStorePoint(), isSpillStorePoint(), isSpillLoadPoint()

isSpillLoadPoint

public final boolean isSpillLoadPoint()
Return true if this instruction is the first in a sequence of instructions. A sequence is defined to be the sequence of instructions that define a value. In particular, an instruction that starts a sequence can be used as a place to insert spill loads. Most instructions can start a sequence. However, if there is a sequence of instructions that can not be split by a spill load, all but the first must be marked as not starting a sequence. There may be several starts between every end.

See Also:
specifySpillStorePoint(), isSpillStorePoint(), specifyNotSpillLoadPoint()

isLoad

public boolean isLoad()
Return true if this is a load-from-memory instruction.


isStore

public boolean isStore()
Return true if this is a store-into-memory instruction.


isBranch

public boolean isBranch()
Return true if this is a branch instruction.


isMarker

public boolean isMarker()
Return true if this is a Marker.

See Also:
Marker

isPrefetch

public boolean isPrefetch()
Return true if this is a prefetch instruction.


isLabel

public boolean isLabel()
Return true if this is a LabelMarker.


isPhi

public boolean isPhi()
Return true if this is a phi instruction.


setNext

public final void setNext(Instruction next)
Set the next lexical instruction.


getNext

public final Instruction getNext()
Return the next lexical instruction.


assembler

public abstract void assembler(Assembler asm,
                               Emit emit)
Insert the assembler representation of the instruction into the output stream.


instructionSize

public abstract int instructionSize()
Return the number of bytes required for the instruction.


specifyRegisterUsage

public abstract void specifyRegisterUsage(RegisterAllocator rs,
                                          int index,
                                          int strength)
Specify the registers used and defined by this instruction. Uses must be specified before definitions.

Parameters:
rs - is the register set in use
index - is an index associated with the instruction
strength - is the importance of the instruction
See Also:
RegisterAllocator.useRegister(int,int,int), RegisterAllocator.defRegister(int,int)

uses

public boolean uses(int register,
                    RegisterSet registers)
Return true if the instruction uses the register.


defs

public boolean defs(int register,
                    RegisterSet registers)
Return true if the instruction sets the register.


mods

public boolean mods(int register,
                    RegisterSet registers)
Return true if the instruction clobbers the register.


canBeDeleted

public boolean canBeDeleted(RegisterSet registers)
Return true if the instruction can be deleted without changing the program's semantics.


independent

public abstract boolean independent(Instruction inst,
                                    RegisterSet registers)
Return true if this instruction is independent of the specified instruction. If instructions are independent, than one instruction can be moved before or after the other instruction without changing the semantics of the program.

Parameters:
inst - is the specified instruction

setsSpecialReg

public boolean setsSpecialReg()
Return true if this instruction has a side effect of changing a special register. An example would be a condition code register for architectures that set the condition and tehn branch on it such as the Sparc.


isCopy

public boolean isCopy()
Return true if the instruction copies a value from one register to another without modification. Transfers between integer and floating point registers are not considered to be copy instructions.


isPredicated

public boolean isPredicated()
Return true if the instruction is predicated.


isPredicatedOnTrue

public boolean isPredicatedOnTrue()
Returns true if the instruction is predicated on true.


setPredicate

public void setPredicate(int rp)
Set the predicate for the instruction.


setPredicate

public void setPredicate(int rp,
                         boolean predicatedOnTrue)
Set the predicate for the instruction.


setPredicatedOnTrue

public void setPredicatedOnTrue(boolean predicatedOnTrue)
Set the condition for the predicate.


removePredicates

public void removePredicates()
Remove the predicates from this instruction.


getPredicates

public int[] getPredicates()
Return the predicates for the instruction.


numPredicates

public int numPredicates()
Return the number of predicates.


getPredicate

public int getPredicate(int i)
Return the specified predicate.


setPredicates

public void setPredicates(int[] predicates)
Specify the predicates for the instruction.


ehash

public int ehash()
Return a hash code that can be used to determine equivalence.


getCopySrc

public int getCopySrc()
Return the source register of a copy instruction.


getCopyDest

public int getCopyDest()
Return the source register of a copy instruction.


clone

public java.lang.Object clone()
Clone the instruction. Performs a shallow copy.

Overrides:
clone in class java.lang.Object

getLoopNumber

public int getLoopNumber()
Return the loop number of the instruction. This is Trips specific. For all other backends, it returns 0.


setLoopNumber

protected void setLoopNumber(int loopNumber)
Set the loop number of the instruction. This is Trips specific. For all other backends, it does nothing.


getBBID

public int getBBID()
Get the basic block number of the instruction. TRIPS-specific.


setBBID

public void setBBID(int bbid)
Set the basic block number of the instruction. TRIPS-specific.