scale.backend.x86
Class X86Instruction

java.lang.Object
  extended by scale.backend.Instruction
      extended by scale.backend.x86.X86Instruction
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
X86DInstruction, X86RInstruction

public class X86Instruction
extends Instruction

This is the base class for all X86 instructions except branches.

$Id$

Copyright 2008 by James H. Burrill
All Rights Reserved.


Field Summary
protected  int opcode
          The instruction opcode.
protected  byte setCC
          flags that specify the condition codes set by the instruction
protected  byte useCC
          flags that specify the condition codes used by the instruction
 
Constructor Summary
X86Instruction(int opcode)
           
 
Method Summary
 java.lang.String assembleDisp(Assembler asm, Displacement disp, int ftn)
          Generate a String representation of a Displacement that can be used by the assembly code generater.
 void assembler(Assembler asm, Emit emit)
          Insert the assembler representation of the instruction into the output stream.
static void buildAddress(java.lang.StringBuffer buf, int baseReg, int indexReg, Displacement disp, int scale)
           
 boolean canBeDeleted(RegisterSet registers)
          Return true if the instruction can be deleted without changing program semantics.
protected  boolean checkForm(int opcode)
          Return true if the specified form is valid for this instruction opcode.
 boolean defs(int register, RegisterSet registers)
          Return true if the instruction sets the register.
 Displacement getDisplacement()
           
 Displacement getDisplacement2()
           
 int getOpcode()
          Return the numeric opcode of the instruction.
 int getOperandSize()
          Return 1, 2, 4, or 8 depending on the size of the operand, in bytes, specified for the instruction.
 char getOperandSizeLabel()
          Return 'b', 'w', 'l', or 'x' depending on the size of the operand specified for the instruction.
 int getReg()
           
 int getReg2()
           
 int getReg3()
           
 int getScale()
          Return 1, 2, 4, or 8 depending on the scale factor specified for the instruction.
 boolean independent(Instruction inst, RegisterSet registers)
          Return true if this instruction is independent of the specified instruction.
protected  boolean independentCC(X86Instruction inst)
          Return true if this instruction's CC use is independent of the specified instruction.
 int instructionSize()
          Return the number of bytes required for this instruction.
 boolean isReversed()
          Return true if the instruction modifies memory.
 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 setDisplacement(Displacement disp)
           
 void setDisplacement2(Displacement disp)
           
protected  void setOpcode(int opcode)
           
 void setOperandSize(int size)
          Set the operand size specified for the instruction.
 void setReg(int reg)
           
 void setReg2(int reg2)
           
 void setReg3(int reg3)
           
 void setScale(int scale)
          ((X86Assembler) Set the scale factor specified for the instruction.
 boolean setsCC(int cc)
          Return true if the instruction sets the CC flag specified.
 void setSetCC(int cc)
          Specify the CC set by this instruction.
 boolean setsSpecialReg()
          Return true if this instruction has a side effect of changing a special register.
 void setUseCC(int cc)
          Specify the CCs used by this instruction.
 void specifyRegisterUsage(RegisterAllocator rs, int index, int strength)
          Specify the registers used and defined by this instruction.
 java.lang.String toString()
           
 boolean uses(int register, RegisterSet registers)
          Return true if the instruction uses the register.
 boolean usesCC(int cc)
          Return true if the instruction uses the CC flag specified.
 
Methods inherited from class scale.backend.Instruction
clone, copy, ehash, getBBID, getCopyDest, getCopySrc, getDestRegister, getExecutionCycles, getFunctionalUnit, getLoopNumber, getNext, getPredicate, getPredicates, getSrcRegisters, getTag, isBranch, isCopy, isLabel, isLoad, isMandatory, isMarker, isPhi, isPredicated, isPredicatedOnTrue, isPrefetch, isSpillInstruction, isSpillLoadPoint, isSpillStorePoint, isStore, markSpillInstruction, mods, nullified, nullify, numPredicates, removePredicates, setBBID, setLoopNumber, setMandatory, setNext, setPredicate, setPredicate, setPredicatedOnTrue, setPredicates, setTag, specifyNotSpillLoadPoint, specifySpillStorePoint
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

opcode

protected int opcode
The instruction opcode.


setCC

protected byte setCC
flags that specify the condition codes set by the instruction


useCC

protected byte useCC
flags that specify the condition codes used by the instruction

Constructor Detail

X86Instruction

public X86Instruction(int opcode)
Parameters:
opcode - is the instruction's opcode
Method Detail

checkForm

protected boolean checkForm(int opcode)
Return true if the specified form is valid for this instruction opcode.


getOpcode

public final int getOpcode()
Description copied from class: Instruction
Return the numeric opcode of the instruction. This opcode may be an encoding of the actual instruction opcode.

Specified by:
getOpcode in class Instruction

setOpcode

protected final void setOpcode(int opcode)

isReversed

public final boolean isReversed()
Return true if the instruction modifies memory.


getDisplacement

public Displacement getDisplacement()

setDisplacement

public void setDisplacement(Displacement disp)

getDisplacement2

public Displacement getDisplacement2()

setDisplacement2

public void setDisplacement2(Displacement disp)

getReg

public int getReg()

setReg

public void setReg(int reg)

getReg2

public int getReg2()

setReg2

public void setReg2(int reg2)

getReg3

public int getReg3()

setReg3

public void setReg3(int reg3)

uses

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

Overrides:
uses in class Instruction

defs

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

Overrides:
defs in class Instruction

instructionSize

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

Specified by:
instructionSize in class Instruction

setSetCC

public final void setSetCC(int cc)
Specify the CC set by this instruction.


setUseCC

public final void setUseCC(int cc)
Specify the CCs used by this instruction.


setsCC

public final boolean setsCC(int cc)
Return true if the instruction sets the CC flag specified.

Parameters:
cc - specifies the CC

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

Overrides:
setsSpecialReg in class Instruction

usesCC

public final boolean usesCC(int cc)
Return true if the instruction uses the CC flag specified.

Parameters:
cc - specifies the CC

independentCC

protected final boolean independentCC(X86Instruction inst)
Return true if this instruction's CC use 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

specifyRegisterUsage

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

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)

remapRegisters

public void remapRegisters(int[] map)
Description copied from class: Instruction
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

canBeDeleted

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

Overrides:
canBeDeleted in class Instruction

independent

public boolean independent(Instruction inst,
                           RegisterSet registers)
Description copied from class: Instruction
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

remapDestRegister

public void remapDestRegister(int oldReg,
                              int newReg)
Description copied from class: Instruction
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

remapSrcRegister

public void remapSrcRegister(int oldReg,
                             int newReg)
Description copied from class: Instruction
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

assembleDisp

public java.lang.String assembleDisp(Assembler asm,
                                     Displacement disp,
                                     int ftn)
Generate a String representation of a Displacement that can be used by the assembly code generater.


getScale

public int getScale()
Return 1, 2, 4, or 8 depending on the scale factor specified for the instruction.


setScale

public void setScale(int scale)
((X86Assembler) Set the scale factor specified for the instruction. The value must be 1, 2, 4, or 8.


getOperandSize

public int getOperandSize()
Return 1, 2, 4, or 8 depending on the size of the operand, in bytes, specified for the instruction.


getOperandSizeLabel

public char getOperandSizeLabel()
Return 'b', 'w', 'l', or 'x' depending on the size of the operand specified for the instruction.


setOperandSize

public void setOperandSize(int size)
Set the operand size specified for the instruction. The value must be 1, 2, 4, or 8.


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()
Overrides:
toString in class java.lang.Object

buildAddress

public static void buildAddress(java.lang.StringBuffer buf,
                                int baseReg,
                                int indexReg,
                                Displacement disp,
                                int scale)