scale.backend
Class Branch

java.lang.Object
  extended by scale.backend.Instruction
      extended by scale.backend.Branch
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
BranchInstruction, JmpInstruction, MipsBranch, PPCBranch, SparcBranch, TripsBranch, X86Branch

public abstract class Branch
extends Instruction

This is the abstract class for all machine branch instructions.

$Id: Branch.java,v 1.26 2007-10-04 19:57:48 burrill Exp $

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


Constructor Summary
protected Branch(int numTargets)
           
 
Method Summary
 void additionalRegsKilled(short[] regsKilled)
          Specify additional registers that may be killed by a subroutine call.
 void additionalRegsSet(short[] regsSet)
          Specify additional registers that may be set by a subroutine call.
 void additionalRegsUsed(short[] regsUsed)
          Specify additional registers that may be used by a subroutine call.
 void addTarget(Label lab, int targetNumber)
          Add a successor label for this branch.
 Instruction copy()
          Make a copy of this instruction.
 boolean defs(int register, RegisterSet registers)
          Return true if the instruction defines the register.
 double getBranchProbability()
          Return the probability that this branch is taken.
 int getExecutionCycles()
          Return the number of cycles that this instruction requires.
 short[] getRegsKilled()
          Specify additional registers that may be killed by a subroutine call.
 Label getTarget(int targetNumber)
          Return the place branched to.
 boolean independent(Instruction inst, RegisterSet registers)
          Return true if this instruction is independent of the specified instruction.
 boolean isBranch()
          Return true if this is a branch instruction.
 boolean isCall()
          Return true if this branch is a call to a subroutine.
 void markAsCall()
          Specify that this branch is a call to a subroutine.
 boolean mods(int register, RegisterSet registers)
          Return true if the instruction clobbers the register.
 void nullify(RegisterSet rs)
          Mark the instruction as no longer needed.
 int numTargets()
          Return the number of successors of this branch.
 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 setBranchProbability(double brProb)
          Set the probability that this branch is taken.
 void specifyRegisterUsage(RegisterAllocator rs, int index, int strength)
          Specify the registers used by this instruction.
 java.lang.String toString()
           
 short[] uses()
          Returns array of registers used.
 boolean uses(int register, RegisterSet registers)
          Return true if the instruction uses the register.
 
Methods inherited from class scale.backend.Instruction
assembler, canBeDeleted, clone, ehash, getBBID, getCopyDest, getCopySrc, getDestRegister, getFunctionalUnit, getLoopNumber, getNext, getOpcode, getPredicate, getPredicates, getSrcRegisters, getTag, instructionSize, isCopy, isLabel, isLoad, isMandatory, isMarker, isPhi, isPredicated, isPredicatedOnTrue, isPrefetch, isSpillInstruction, isSpillLoadPoint, isSpillStorePoint, isStore, markSpillInstruction, nullified, numPredicates, removePredicates, setBBID, setLoopNumber, setMandatory, setNext, setPredicate, setPredicate, setPredicatedOnTrue, setPredicates, setsSpecialReg, setTag, specifyNotSpillLoadPoint, specifySpillStorePoint
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Branch

protected Branch(int numTargets)
Parameters:
numTargets - is the number of successors of this instruction. For routine calls, it does not include the routine called.
Method Detail

addTarget

public final void addTarget(Label lab,
                            int targetNumber)
Add a successor label for this branch. Generally, the branch target should be target number 0.


additionalRegsUsed

public final void additionalRegsUsed(short[] regsUsed)
Specify additional registers that may be used by a subroutine call.


additionalRegsKilled

public final void additionalRegsKilled(short[] regsKilled)
Specify additional registers that may be killed by a subroutine call.


getRegsKilled

public final short[] getRegsKilled()
Specify additional registers that may be killed by a subroutine call.


additionalRegsSet

public final void additionalRegsSet(short[] regsSet)
Specify additional registers that may be set by a subroutine call.


nullify

public void nullify(RegisterSet rs)
Mark the instruction as no longer needed.

Overrides:
nullify in class Instruction

isBranch

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

Overrides:
isBranch in class Instruction

markAsCall

public final void markAsCall()
Specify that this branch is a call to a subroutine.


isCall

public final boolean isCall()
Return true if this branch is a call to a subroutine.


getBranchProbability

public final double getBranchProbability()
Return the probability that this branch is taken.


setBranchProbability

public final void setBranchProbability(double brProb)
Set the probability that this branch is taken.


getTarget

public final Label getTarget(int targetNumber)
Return the place branched to.


numTargets

public final int numTargets()
Return the number of successors of this branch.


getExecutionCycles

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

Overrides:
getExecutionCycles in class Instruction

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.

Specified by:
independent in class Instruction
Parameters:
inst - is the specified instruction

specifyRegisterUsage

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

Specified by:
specifyRegisterUsage in class Instruction
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)

defs

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

Overrides:
defs in class Instruction

uses

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

Overrides:
uses in class Instruction

uses

public short[] uses()
Returns array of registers used.


mods

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

Overrides:
mods in class Instruction

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.

Specified by:
remapRegisters in class Instruction
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.

Specified by:
remapSrcRegister in class Instruction
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.

Specified by:
remapDestRegister in class Instruction
Parameters:
oldReg - is the previous destination register
newReg - is the new destination register

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

copy

public Instruction copy()
Description copied from class: Instruction
Make a copy of this instruction.

Overrides:
copy in class Instruction
Returns:
the copy of the instruction