scale.backend.trips2
Class TripsBranch

java.lang.Object
  extended by scale.backend.Instruction
      extended by scale.backend.Branch
          extended by scale.backend.trips2.TripsBranch
All Implemented Interfaces:
java.lang.Cloneable

public final class TripsBranch
extends Branch

This class represents Trips branch instructions.

$Id: TripsBranch.java,v 1.43 2007-10-31 23:47:51 bmaher Exp $

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

The TripsInstruction class represents operations in both operand and target form. When in operand form, ithe operation is considered a PSEUDO-op. If a PSEUDO operation is represented, the ra, rb, and rc fields represent an input virtual register.

For operations in target form (non-PSEUDO operations), the ra, rb, and rc fields represent the targets of the operation and specifies either an instruction ID, immediate value, or a register depending on the instruction format.

The opcode encodes the instruction format:

BitsUsedescription
0..190should be zero
20..23formatThe format of the Trips instruction
24..31opcodeThe opcode of the Trips instruction

If there is only one output required from an instruction, the B1 or T1 form is used regardless of the register number or the immediate value size.

Each instruction is labeled with an integer ID which is unique within the basic block in which the instruction resides.

When the instruction is a Trips instruction containing an immediate value, the immediate value is coded as follows:

BitsUsedescription
0..27valuean index into a table of displacements
28..31ftnthe function to apply to the value
Allowed values for the function are


Field Summary
protected  SymbolDisplacement disp
          The target symbol displacement for a CALLO instruction.
protected  int numPredicates
          The number of registers the instruction is predicated on.
protected  boolean predicatedOnTrue
          The condition on which to predicate.
protected  int[] predicates
          The registers the instruction is predicated on.
protected  int rb
          The rb register.
 
Constructor Summary
TripsBranch(int opcode, int numTargets)
          Create a new Trips SCALL instruction.
TripsBranch(int opcode, int rb, int numTargets)
          Create a new Trips branch instruction in the B:1 format.
TripsBranch(int opcode, int numTargets, int rp, boolean predicatedOnTrue)
          Create a new Trips SCALL Instruction.
TripsBranch(int opcode, int rb, int numTargets, int rp, boolean predicatedOnTrue)
          Create a new Trips branch instruction in the B:1 format.
TripsBranch(int opcode, Label lab, int numTargets)
          Create a new Trips branch instruction in the B:0 format (except SCALL).
TripsBranch(int opcode, Label lab, int numTargets, int rp, boolean predicatedOnTrue)
          Create a new Trips branch instruction in the B:0 format (except SCALL).
TripsBranch(int opcode, Label lab, int numTargets, int rp, boolean predicatedOnTrue, double brpred)
          Create a new Trips branch with specified taken probability.
TripsBranch(int opcode, SymbolDisplacement disp, int numTargets)
          Create a new Trips CALLO Instruction.
TripsBranch(int opcode, SymbolDisplacement disp, int numTargets, int rp, boolean predicatedOnTrue)
          Create a new Trips CALLO Instruction.
 
Method Summary
 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 program semantics.
static int created()
          Return the number of instances of this class created.
 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 getBranchId()
          Return the branch id.
 int getCopyDest()
          Return the source register of a copy instruction.
 int getCopySrc()
          Return the source register of a copy instruction.
 int getFormat()
          Return the instruction format.
 int getLoopNumber()
          Return the loop number of the instruction.
 int getOpcode()
          Return the instruction opcode.
 int getPredicate(int i)
          Return the i-th predicate for the instruction.
 int[] getPredicates()
          Return the predicates for the instruction.
 int getRb()
          Return the rb field.
 int[] getSrcRegisters()
          This routine returns the source registers for an instruction.
 Label getTarget()
          Return the target of the branch.
 boolean independent(Instruction inst, RegisterSet registers)
          Return true if this instruction is independent of the specified instruction.
 int instructionSize()
          Return the number of bytes required for the TripsBranch.
 boolean isCopy()
          Return true if the instruction copies a value from one register to another without modification.
 boolean isPredicated()
          Returns true if the instruction in predicated
 boolean isPredicatedOnTrue()
          Returns true if the instruction is predicated on true.
 boolean mods(int register, RegisterSet registers)
          Return true if the instruction clobbers the register.
 int numPredicates()
          Return the number of predicates for the instruction.
 void remapDestRegister(int oldReg, int newReg)
          Map the registers defined in the instruction as destinations to the specified register.
 void remapRegisters(int[] map)
          Map the virtual registers referenced in the instruction to the specified real registers.
 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.
 void setBranchId(int branchId)
          Set the branch id.
protected  void setLoopNumber(int loopNumber)
          Set the loop number of the 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)
          Set the predicates for the instruction.
 void setPredicates(int[] predicates, boolean predicatedOnTrue)
          Set the predicates for the instruction.
 void specifyRegisterUsage(RegisterAllocator rs, int index, int strength)
          Specify the registers used by this instruction.
 java.lang.String toString()
          Return a string representation of the instruction.
 boolean uses(int register, RegisterSet registers)
          Return true if the instruction uses the register.
 
Methods inherited from class scale.backend.Branch
additionalRegsKilled, additionalRegsSet, additionalRegsUsed, addTarget, copy, getBranchProbability, getExecutionCycles, getRegsKilled, getTarget, isBranch, isCall, markAsCall, nullify, numTargets, setBranchProbability, uses
 
Methods inherited from class scale.backend.Instruction
clone, getDestRegister, getFunctionalUnit, getNext, getTag, isLabel, isLoad, isMandatory, isMarker, isPhi, isPrefetch, isSpillInstruction, isSpillLoadPoint, isSpillStorePoint, isStore, markSpillInstruction, nullified, setMandatory, setNext, setsSpecialReg, setTag, specifyNotSpillLoadPoint, specifySpillStorePoint
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

rb

protected int rb
The rb register.


disp

protected SymbolDisplacement disp
The target symbol displacement for a CALLO instruction.


predicates

protected int[] predicates
The registers the instruction is predicated on.


numPredicates

protected int numPredicates
The number of registers the instruction is predicated on.


predicatedOnTrue

protected boolean predicatedOnTrue
The condition on which to predicate.

Constructor Detail

TripsBranch

public TripsBranch(int opcode,
                   int rb,
                   int numTargets,
                   int rp,
                   boolean predicatedOnTrue)
Create a new Trips branch instruction in the B:1 format.

Parameters:
opcode - specifies the pseudo-operation
rb - specifies the right argument register
numTargets - specifies the number of targets of the branch
rp - specifies the register to predicate on (-1 if unused)
predicatedOnTrue - specifies the condition to predicate on (ignored if rp is -1)

TripsBranch

public TripsBranch(int opcode,
                   int rb,
                   int numTargets)
Create a new Trips branch instruction in the B:1 format.

Parameters:
opcode - specifies the pseudo-operation
rb - specifies the right argument register
numTargets - specifies the number of targets of the branch

TripsBranch

public TripsBranch(int opcode,
                   Label lab,
                   int numTargets,
                   int rp,
                   boolean predicatedOnTrue)
Create a new Trips branch instruction in the B:0 format (except SCALL).

Parameters:
opcode - specifies the pseudo-operation
lab - specifies the target label (ignored if instruction opcode = SCALL)
numTargets - specifies the number of targets of the branch
rp - specifies the register to predicate on (-1 if unused)
predicatedOnTrue - specifies the condition to predicate on (ignored if rp is -1)

TripsBranch

public TripsBranch(int opcode,
                   Label lab,
                   int numTargets,
                   int rp,
                   boolean predicatedOnTrue,
                   double brpred)
Create a new Trips branch with specified taken probability.

Parameters:
opcode - specifies the pseudo-operation
lab - specifies the target label (ignored if instruction opcode = SCALL)
numTargets - specifies the number of targets of the branch
rp - specifies the register to predicate on (-1 if unused)
predicatedOnTrue - specifies the condition to predicate on (ignored if rp is -1)
brpred - is the probability that this branch is taken

TripsBranch

public TripsBranch(int opcode,
                   Label lab,
                   int numTargets)
Create a new Trips branch instruction in the B:0 format (except SCALL).

Parameters:
opcode - specifies the pseudo-operation
lab - specifies the target label (ignored if instruction opcode = SCALL)
numTargets - specifies the number of targets of the branch

TripsBranch

public TripsBranch(int opcode,
                   SymbolDisplacement disp,
                   int numTargets,
                   int rp,
                   boolean predicatedOnTrue)
Create a new Trips CALLO Instruction.

Parameters:
opcode - specifies the pseudo-operation
disp - specifies the target symbol displacement (ignored if instruction opcode = SCALL)
numTargets - specifies the number of targets of the branch
rp - specifies the register to predicate on (-1 if unused)
predicatedOnTrue - specifies the condition to predicate on (ignored if rp is -1)

TripsBranch

public TripsBranch(int opcode,
                   SymbolDisplacement disp,
                   int numTargets)
Create a new Trips CALLO Instruction.

Parameters:
opcode - specifies the pseudo-operation
disp - specifies the target symbol displacement (ignored if instruction opcode = SCALL)
numTargets - specifies the number of targets of the branch

TripsBranch

public TripsBranch(int opcode,
                   int numTargets,
                   int rp,
                   boolean predicatedOnTrue)
Create a new Trips SCALL Instruction.

Parameters:
opcode - specifies the pseudo-operation
numTargets - specifies the number of targets of the branch
rp - specifies the register to predicate on (-1 if unused)
predicatedOnTrue - specifies the condition to predicate on (ignored if rp is -1)

TripsBranch

public TripsBranch(int opcode,
                   int numTargets)
Create a new Trips SCALL instruction.

Parameters:
opcode - specifies the pseudo-operation
numTargets - specifies the number of targets of the branch
Method Detail

created

public static int created()
Return the number of instances of this class created.


remapRegisters

public 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.

Overrides:
remapRegisters in class Branch
Parameters:
map - maps from the virtual register to real register

remapSrcRegister

public 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.

Overrides:
remapSrcRegister in class Branch
Parameters:
oldReg - is the previous source register
newReg - is the new source register

remapDestRegister

public 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.

Overrides:
remapDestRegister in class Branch
Parameters:
oldReg - is the previous destination register
newReg - is the new destination register

getOpcode

public int getOpcode()
Return the instruction opcode.

Specified by:
getOpcode in class Instruction

getTarget

public Label getTarget()
Return the target of the branch.


getFormat

public int getFormat()
Return the instruction format.


getSrcRegisters

public int[] getSrcRegisters()
This routine returns the source registers for an instruction. Null is returned if there are no source registers.

Overrides:
getSrcRegisters in class Instruction

getRb

public int getRb()
Return the rb field.


numPredicates

public final int numPredicates()
Return the number of predicates for the instruction.

Overrides:
numPredicates in class Instruction

getPredicate

public final int getPredicate(int i)
Return the i-th predicate for the instruction.

Overrides:
getPredicate in class Instruction

getPredicates

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

Overrides:
getPredicates in class Instruction

setPredicate

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

Overrides:
setPredicate in class Instruction

setPredicate

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

Overrides:
setPredicate in class Instruction

setPredicates

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

Overrides:
setPredicates in class Instruction

setPredicates

public void setPredicates(int[] predicates,
                          boolean predicatedOnTrue)
Set the predicates for the instruction. This clears any previous predicates.


removePredicates

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

Overrides:
removePredicates in class Instruction

isPredicated

public boolean isPredicated()
Returns true if the instruction in predicated

Overrides:
isPredicated in class Instruction

isPredicatedOnTrue

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

Overrides:
isPredicatedOnTrue in class Instruction

setPredicatedOnTrue

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

Overrides:
setPredicatedOnTrue in class Instruction

specifyRegisterUsage

public void specifyRegisterUsage(RegisterAllocator rs,
                                 int index,
                                 int strength)
Specify the registers used by this instruction.

Overrides:
specifyRegisterUsage in class Branch
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.

Overrides:
uses in class Branch

defs

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

Overrides:
defs in class Branch

mods

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

Overrides:
mods in class Branch

independent

public 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.

Overrides:
independent in class Branch
Parameters:
inst - is the specified instruction

instructionSize

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

Specified by:
instructionSize in class Instruction

canBeDeleted

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

Overrides:
canBeDeleted in class Instruction

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.

Overrides:
isCopy in class Instruction

getCopySrc

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

Overrides:
getCopySrc in class Instruction

getCopyDest

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

Overrides:
getCopyDest in class Instruction

ehash

public int ehash()
Return a hash code that can be used to determine equivalence. The hash code does not include predicates or the destination register.

Overrides:
ehash in class Instruction

assembler

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

Specified by:
assembler in class Instruction

toString

public java.lang.String toString()
Return a string representation of the instruction.

Overrides:
toString in class Branch

getLoopNumber

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

Overrides:
getLoopNumber in class Instruction

setLoopNumber

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

Overrides:
setLoopNumber in class Instruction

getBBID

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

Overrides:
getBBID in class Instruction

setBBID

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

Overrides:
setBBID in class Instruction

getBranchId

public int getBranchId()
Return the branch id.


setBranchId

public void setBranchId(int branchId)
Set the branch id.