scale.backend.x86
Class X86Generator

java.lang.Object
  extended by scale.backend.Generator
      extended by scale.backend.x86.X86Generator
All Implemented Interfaces:
Predicate

public class X86Generator
extends Generator

This class converts Scribble into X86 instructions.

$Id: X86Generator.java,v 1.1 2007-11-01 16:52:29 burrill Exp $

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

This class generates the instructions for the specific architecture. Most of the methods below generate a "not implemented error". These must be replaced with code that generates the proper instruction sequence. The other methods may need to be modified. Use the code generators from the other architectures to help you understand how to make changes for your architecture.

See Also:
Generator, AlphaGenerator, SparcGenerator, PPCGenerator

Field Summary
static int BSS
          Un-initialized large data area.
static int DATA
          Initialized large data area.
static int LIT4
          Initialized 4-byte data area.
static int LIT8
          Initialized 8-byte data area.
static int LITA
          Initialized address data area.
static int RCONST
          Read-only constants
static int RDATA
          Read-only data.
static int SBSS
          Un-initialized small data area.
static int SDATA
          Initialized small data area.
static int TEXT
          Instructions.
 
Fields inherited from class scale.backend.Generator
ADD, addrDisp, AND, annotateCode, ansic, ANSIC, branchPrediction, callsRoutine, cg, classTrace, codeMap, commutative, currentBeginMarker, currentRoutine, dataAreas, DEBUG, DIV, fieldAlignment, genDebugInfo, lastInstruction, lastLabel, LINENUM, lineNumbers, little, machine, MOD, MUL, naln, NALN, nextArea, nis, NIS, nph, NPH, operation, OR, predicatedOnTrue, predicateReg, readOnlyDataArea, registers, resultReg, resultRegAddressAlignment, resultRegAddressOffset, resultRegMode, resultRegSize, returnInst, scribble, SLL, SRA, SRL, stkPtrReg, SUB, successorCFGNode, trace, un, useMemory, usesAlloca, usesVaStart, XOR
 
Constructor Summary
X86Generator(CallGraph cg, Machine machine, int features)
           
 
Method Summary
protected  void addRegs(int laReg, int raReg, int dest)
          Generate an add of address registers laReg and raReg.
protected  int allocStackAddress(int adrReg, Type type)
          Allocate a location on the stack for storing a value of the specified size.
 void assemble(Emit emit, java.lang.String source, java.util.Enumeration<java.lang.String> comments)
          Generate assembly language.
protected  void assignDeclToMemory(java.lang.String name, VariableDecl vd)
          Assign the specified variable to a location in memory using the specified name.
protected  void assignDeclToRegister(VariableDecl vd)
          Assign the specified variable to a register.
protected  void assignDeclToStack(VariableDecl vd)
          Assign the specified variable to a location in the stack frame.
protected  void basicBlockEnd()
          Called after the last CFG node in a basic block is processed.
protected  void calcArrayElementAddress(ArrayIndexExpr aie, long offseta)
          Load the address of an array element into a register.
protected  short[] callArgs(Expr[] args, boolean retStruct)
          Load the arguments into registers for a routine call.
protected  int convertIntRegValue(int src, int srcSize, boolean srcSigned, int dest, int destSize, boolean destSigned)
          Generate instructions to convert an integer value in an integer register to an integer value of a different size.
 int dataType(int size, boolean flt)
          Return the data type as an integer.
protected  Displacement defStringValue(java.lang.String v, int size)
          Return the displacement for a string.
protected  void doBinaryOp(int which, Type ct, Expr la, Expr ra, int ir)
          Generate instructions to do a binary operation on two values.
protected  void doCompareOp(BinaryExpr c, CompareMode which)
          Generate instructions to do a comparison of two values.
protected  void doVaCopy(Expr dst, Expr src)
          Generate code for a va_copy().
protected  void endRoutineCode(int[] regMap)
          Called at the end of code generation for a routine.
protected  void genAcosFtn(int dest, int src, Type type)
          Generate the code for the acos() function.
protected  void genAlloca(Expr arg, int reg)
          Generate the code for the alloca() function.
protected  void genAsinFtn(int dest, int src, Type type)
          Generate the code for the asin() function.
protected  void genAtan2Ftn(int dest, int laReg, int raReg, Type rType)
          Generate the code for the Fortran ATAN2() intrinsic function.
protected  void genAtanFtn(int dest, int src, Type type)
          Generate the code for the atan() function.
protected  void genConjgFtn(int dest, int src, Type type)
          Generate the code for the conjg() function.
protected  void genCosFtn(int dest, int src, Type type)
          Generate the code for the cos() function.
protected  void genCoshFtn(int dest, int src, Type type)
          Generate the code for the cosh() function.
protected  void genDimFtn(int dest, int laReg, int raReg, Type rType)
          Generate the code for the Fortran DIM() intrinsic function.
protected  short[] genDoubleUse(int reg1, int reg2)
          Generate the array of registers that a call to a function requires.
 void generateProlog(ProcedureType pt)
          This method is responsible for generating instructions to move function arguments to the position assigned by the layoutParameters method.
 void generateScribble()
          Generate the machine instructions for a CFG.
 void generateUnconditionalBranch(Label lab)
          Generate an unconditional branch to the label specified.
protected  void genExpFtn(int dest, int src, Type type)
          Generate the code for the exp() function.
protected  void genFloorOfReal(int src, int srcSize, int dest, int destSize)
          Generate instructions to compute the floor of a real vaue in a real register to a real register.
protected  void genFrameAddressFtn(int dest, int src, Type type)
          Generate the code for the builtin_fram_address() function.
protected  Branch genFtnCall(java.lang.String name, short[] uses, short[] defs)
          Create a call to the routine with the specified name.
protected  void genIfRegister(CompareMode which, int treg, boolean signed, Label labt, Label labf)
          Generate a branch based on the value of an expression compared to zero.
protected  void genIfRelational(boolean rflag, MatchExpr predicate, Chord tc, Chord fc)
          Generate a branch based on a relational expression.
protected  void genIntToReal(int src, int srcSize, int dest, int destSize)
          Convert an integer value in an integer register to a real value in a real register.
protected  int genLoadDblImmediate(double value, int dest, int destSize)
          Generate instructions to load an immediate integer value into a register.
protected  long genLoadHighImmediate(long value, int base)
          Generate instructions to calculate a valid offset.
protected  int genLoadImmediate(long value, int dest)
          Generate instructions to load an immediate integer value into a register.
protected  void genLoadImmediate(long value, int base, int dest)
          Generate instructions to load an immediate integer value added to the value in a register into a register.
protected  void genLog10Ftn(int dest, int src, Type type)
          Generate the code for the log10() function.
protected  void genLogFtn(int dest, int src, Type type)
          Generate the code for the log() function.
protected  void genRealPart(int src, int srcSize, int dest, int destSize)
           
protected  int genRealToInt(int src, int srcSize, int dest, int destSize, boolean destSigned)
          Convert real value in a real register to an integer value in a real register.
protected  void genRealToIntRound(int src, int srcSize, int dest, int destSize)
          Convert real value in a real register to an integer value in a real register.
protected  void genRealToReal(int src, int srcSize, int dest, int destSize)
          Convert a real value in a real register to a real value in a real register.
protected  void genRegToReg(int src, int dest)
          Generate instructions to move data from one register to another.
protected  void genReturnAddressFtn(int dest, int src, Type type)
          Generate the code for the builtin_return_address() function.
protected  void genRoundReal(int src, int srcSize, int dest, int destSize)
          Convert real value in a real register to a rounded real value in a real register.
protected  void genSignFtn(int dest, int laReg, int raReg, Type rType)
          Generate the code for the Fortran SIGN() intrinsic function.
protected  void genSinFtn(int dest, int src, Type type)
          Generate the code for the sin() function.
protected  short[] genSingleUse(int reg)
          Generate the array of registers that a call to a function requires.
protected  void genSinhFtn(int dest, int src, Type type)
          Generate the code for the sinh() function.
protected  void genSqrtFtn(int dest, int src, Type type)
          Generate the code for the sqrt() function.
protected  boolean genSwitchUsingIfs(int testReg, Chord[] cases, long[] keys, int num, long spread)
          Generate the code for a switch statement using branches for each case.
protected  void genSwitchUsingTransferVector(int testReg, Chord[] cases, long[] keys, Label labt, long min, long max)
          Generate the code for a switch statement using branches for each case.
protected  void genTanFtn(int dest, int src, Type type)
          Generate the code for the tan() function.
protected  void genTanhFtn(int dest, int src, Type type)
          Generate the code for the tanh() function.
protected  void genUnsignedIntToReal(int src, int srcSize, int dest, int destSize)
          Convert an unsigned integer value in an integer register to a real value in a real register.
 int getFirstArgRegister(int regType)
          Return the register used as the first argument in a function call.
 int getMaxAreaIndex()
          Return the maximum area index value.
 int getSAType(Type type)
          Return the SpaceAllocation type for the specified Type.
 java.lang.Object getSpillLocation(int reg)
          Obtain the information needed for register spill loads and stores.
 Instruction insertSpillLoad(int reg, java.lang.Object spillLocation, Instruction after)
          Insert the instruction(s) to restore a spilled register.
 Instruction insertSpillStore(int reg, java.lang.Object spillLocation, Instruction after)
          Insert the instruction(s) to save a spilled register.
protected  void layoutParameters()
          Determine the layout of routine parameters for the call.
protected  void loadArrayElement(ArrayIndexExpr aie, int dest)
          Load an array element into a register.
protected  void loadFieldValue(FieldDecl fd, long fieldOffset, int adr, ResultMode adrha, int adraln, long adrrs, int dest)
          Load the value of a field to a register.
protected  void loadFromMemoryDoubleIndexing(int dest, int index1, int index2, int size, long alignment, boolean signed, boolean real)
          Generate instructions to load data from memory at the address that is the sum of the two index register values.
protected  void loadFromMemoryWithOffset(int dest, int address, Displacement offset, int size, long alignment, boolean signed, boolean real)
          Generate instructions to load data from memory at the address in a register plus an offset.
protected  void loadFromMemoryWithOffset(int dest, int address, long offset, int size, long alignment, boolean signed, boolean real)
          Generate instructions to load data from memory at the address in a register plus an offset.
protected  int loadMemoryAddress(Displacement disp)
          Load an address of a memory location into a register.
protected  void loadRegFromSymbolicLocation(int dest, int dsize, boolean isSigned, boolean isReal, Displacement disp)
          Load a register from a symbolic location in memory.
protected  int loadStackAddress(Displacement disp)
          Load an address of a stack location into a register.
protected  void moveWords(int src, long srcoff, int dest, Displacement destoff, int size, int aln)
          Generate an instruction sequence to move words from one location to another.
protected  void moveWords(int src, long srcoff, int dest, long destoff, int size, int aln)
          Generate an instruction sequence to move words from one location to another.
protected  void peepholeBeforeRegisterAllocation(Instruction first)
          Do peephole optimizations before registers are allocated.
protected  void processRoutineDecl(RoutineDecl rd, boolean topLevel)
          The RoutineDecl is assigned a tag.
protected  void processSourceLine(int line, Label lab, boolean newLine)
          The user has requested source line information be included.
 int returnRegister(int regType, boolean isCall)
          Return the register used to return the function value.
protected  Instruction startRoutineCode()
          Called at the start of code generation for a routine.
protected  void storeIntoMemory(int src, int address, int size, long alignment, boolean real)
          Generate instructions to store data into memory at the address specified by a register.
protected  void storeIntoMemoryWithOffset(int src, int address, Displacement offset, int size, long alignment, boolean real)
          Generate instructions to store data into memory at the address in a register plus an offset.
protected  void storeIntoMemoryWithOffset(int src, int address, long offset, int size, long alignment, boolean real)
          Generate instructions to store data into memory at the address in a register plus an offset.
protected  void storeLfae(LoadFieldAddressExpr lhs, Expr rhs)
          Store a value into a field of a structure.
protected  void storeRegToSymbolicLocation(int src, int dsize, long alignment, boolean isReal, Displacement disp)
          Store a value in a register to a symbolic location in memory.
 void visitAbsoluteValueExpr(AbsoluteValueExpr e)
           
 void visitBitComplementExpr(BitComplementExpr e)
           
 void visitCallFunctionExpr(CallFunctionExpr e)
           
 void visitCompareExpr(CompareExpr e)
           
 void visitConditionalExpr(ConditionalExpr e)
           
 void visitDivisionExpr(DivisionExpr e)
           
 void visitExponentiationExpr(ExponentiationExpr e)
           
 void visitMultiplicationExpr(MultiplicationExpr e)
           
 void visitNegativeExpr(NegativeExpr e)
           
 void visitNotExpr(NotExpr e)
           
 void visitRemainderExpr(RemainderExpr e)
           
 void visitReturnChord(ReturnChord c)
           
 void visitVaArgExpr(VaArgExpr e)
           
 void visitVaStartExpr(VaStartExpr e)
           
protected  void zeroFloatRegister(int dest, int destSize)
          Generate code to zero out a floating point register.
 
Methods inherited from class scale.backend.Generator
adjustImmediates, allocateData, allocateRegisters, allocateTextArea, allocateWithData, appendCallInstruction, appendInstruction, appendLabel, associateDispWithArea, avoidedAddressCalcs, avoidedLoads, calcAddressAndOffset, calcFieldAddress, calcFieldOffsets, convertCFG, copyPropagate, createLabel, createNewLabel, defineDeclInCommon, defineDeclInMemory, defineDeclInRegister, defineDeclOnStack, defineRoutineInfo, doBinaryOp, doNext, doStore, endModule, findAreaDisp, findAreaDisp, findAreaDisp, findLastInstruction, generate, generateConditionalBranch, genIfRegister, genIfRegister, genTrueFalseBranch, getBranchLabel, getBranchTarget, getCallGraph, getCurrentRoutine, getDisp, getLabel, getMachine, getName, getRegisterSet, getSourceLanguage, getSpaceAllocation, getStackPtr, insertInstruction, insertLabel, isAssignedRegister, isFortran, isSimple, labelCfgForBackend, loadDeclValue, loadVariable, loadVariableFromCommon, loadVariableFromMemory, loadVariableFromStack, moveInstructionSequence, needValue, needValue, newLabel, peepholeAfterRegisterAllocation, processDecls, processType, processType, processType, processType, processTypeDecl, processTypeName, processVariableDecl, propagate, putAddressInRegister, putAddressInRegister, putAddressInRegisterNO, regeneratedAddresses, regeneratedLiterals, regeneratedValues, regenerateRegister, removeUnneededInstructions, resetForBasicBlock, saveGeneratedCode, shouldBeRegenerated, specifyInReg, startModule, storeLdae, storeLdve, storeLiteral, storeLvie, unconditionalBranchNeeded, updateLabelIndex, valueOf, visitAdditionExpr, visitAllocateExpr, visitAndExpr, visitArrayIndexExpr, visitBeginChord, visitBinaryExpr, visitBitAndExpr, visitBitOrExpr, visitBitShiftExpr, visitBitXorExpr, visitBranchChord, visitCallExpr, visitCallMethodExpr, visitChord, visitComplexValueExpr, visitConversionExpr, visitDecisionChord, visitDualExpr, visitEndChord, visitEqualityExpr, visitExitChord, visitExpr, visitExprChord, visitExprPhiExpr, visitGotoChord, visitGreaterEqualExpr, visitGreaterExpr, visitIfThenElseChord, visitLeaveChord, visitLessEqualExpr, visitLessExpr, visitLiteralExpr, visitLoadDeclAddressExpr, visitLoadDeclValueExpr, visitLoadExpr, visitLoadFieldAddressExpr, visitLoadFieldValueExpr, visitLoadValueIndirectExpr, visitLoopExitChord, visitLoopHeaderChord, visitLoopInitChord, visitLoopPreHeaderChord, visitLoopTailChord, visitMarkerChord, visitMaxExpr, visitMinExpr, visitNaryExpr, visitNilExpr, visitNote, visitNotEqualExpr, visitNullChord, visitOrExpr, visitPhiExpr, visitPhiExprChord, visitSequentialChord, visitSubscriptExpr, visitSubtractionExpr, visitSwitchChord, visitTernaryExpr, visitTranscendental2Expr, visitTranscendentalExpr, visitUnaryExpr, visitVaEndExpr, visitValueExpr, visitVarArgExpr, visitVectorExpr, whatIsThis
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BSS

public static final int BSS
Un-initialized large data area.

See Also:
Constant Field Values

SBSS

public static final int SBSS
Un-initialized small data area.

See Also:
Constant Field Values

DATA

public static final int DATA
Initialized large data area.

See Also:
Constant Field Values

LIT4

public static final int LIT4
Initialized 4-byte data area.

See Also:
Constant Field Values

LIT8

public static final int LIT8
Initialized 8-byte data area.

See Also:
Constant Field Values

LITA

public static final int LITA
Initialized address data area.

See Also:
Constant Field Values

RCONST

public static final int RCONST
Read-only constants

See Also:
Constant Field Values

RDATA

public static final int RDATA
Read-only data.

See Also:
Constant Field Values

SDATA

public static final int SDATA
Initialized small data area.

See Also:
Constant Field Values

TEXT

public static final int TEXT
Instructions.

See Also:
Constant Field Values
Constructor Detail

X86Generator

public X86Generator(CallGraph cg,
                    Machine machine,
                    int features)
Parameters:
cg - is the call graph to be transformed
machine - specifies machine details
features - contains various flags
Method Detail

generateScribble

public void generateScribble()
Description copied from class: Generator
Generate the machine instructions for a CFG.

Overrides:
generateScribble in class Generator

peepholeBeforeRegisterAllocation

protected void peepholeBeforeRegisterAllocation(Instruction first)
Description copied from class: Generator
Do peephole optimizations before registers are allocated.

Overrides:
peepholeBeforeRegisterAllocation in class Generator

assemble

public void assemble(Emit emit,
                     java.lang.String source,
                     java.util.Enumeration<java.lang.String> comments)
Description copied from class: Generator
Generate assembly language.

Specified by:
assemble in class Generator
Parameters:
emit - is the stream to use.
source - is the source file name
comments - is a list of Strings containing comments

dataType

public int dataType(int size,
                    boolean flt)
Description copied from class: Generator
Return the data type as an integer.

Specified by:
dataType in class Generator
Parameters:
size - is the size in memory units
flt - is true for floating point values
See Also:
SpaceAllocation

getSAType

public int getSAType(Type type)
Description copied from class: Generator
Return the SpaceAllocation type for the specified Type.

Overrides:
getSAType in class Generator

assignDeclToMemory

protected void assignDeclToMemory(java.lang.String name,
                                  VariableDecl vd)
Description copied from class: Generator
Assign the specified variable to a location in memory using the specified name. The decision to place this variable in memory has already been made.

Specified by:
assignDeclToMemory in class Generator
See Also:
VariableDecl.getStorageLoc()

assignDeclToRegister

protected void assignDeclToRegister(VariableDecl vd)
Description copied from class: Generator
Assign the specified variable to a register. The decision to place this variable in a register has already been made.

Specified by:
assignDeclToRegister in class Generator
See Also:
VariableDecl.getStorageLoc()

assignDeclToStack

protected void assignDeclToStack(VariableDecl vd)
Description copied from class: Generator
Assign the specified variable to a location in the stack frame. The decision to place this variable on the stack has already been made.

Specified by:
assignDeclToStack in class Generator
See Also:
VariableDecl.getStorageLoc()

processRoutineDecl

protected void processRoutineDecl(RoutineDecl rd,
                                  boolean topLevel)
Description copied from class: Generator
The RoutineDecl is assigned a tag. The tag can be used to retrieve information about the declaration. For a RoutineDecl, the information is a Displacement, the data area for the routine and the label to be used for BSR calls to the routine.

Specified by:
processRoutineDecl in class Generator
Parameters:
rd - is the declaration
topLevel - is true if this declaration is defined outside of a routine

layoutParameters

protected void layoutParameters()
Description copied from class: Generator
Determine the layout of routine parameters for the call. This method determines where the arguments to a function will be kept. Usually arguments are kept in registers. However, if the address of the argument is taken, the argument will be placed on the stack. Also, if the argument is passed on the stack, it may be left on the stack. It's a mistake to assign an argument to a real register because real registers can't be spilled.

The generateProlog method generates instructions to move the arguments to the location determined by this method.

Specified by:
layoutParameters in class Generator

returnRegister

public int returnRegister(int regType,
                          boolean isCall)
Description copied from class: Generator
Return the register used to return the function value.

Specified by:
returnRegister in class Generator
Parameters:
regType - specifies the type of value
isCall - is true if the calling routine is asking

getFirstArgRegister

public final int getFirstArgRegister(int regType)
Description copied from class: Generator
Return the register used as the first argument in a function call.

Specified by:
getFirstArgRegister in class Generator
Parameters:
regType - specifies the type of argument value

defStringValue

protected Displacement defStringValue(java.lang.String v,
                                      int size)
Description copied from class: Generator
Return the displacement for a string.

Specified by:
defStringValue in class Generator
Parameters:
v - is the string
size - is the length of the string

genRegToReg

protected void genRegToReg(int src,
                           int dest)
Description copied from class: Generator
Generate instructions to move data from one register to another. If one is an integer register and the other is a floating point register, a memory location may be required.

Specified by:
genRegToReg in class Generator
Parameters:
src - specifies the source register
dest - specifies the destination register

addRegs

protected void addRegs(int laReg,
                       int raReg,
                       int dest)
Description copied from class: Generator
Generate an add of address registers laReg and raReg.

Specified by:
addRegs in class Generator

loadMemoryAddress

protected int loadMemoryAddress(Displacement disp)
Description copied from class: Generator
Load an address of a memory location into a register.

Specified by:
loadMemoryAddress in class Generator
Parameters:
disp - specifies the address (should be a SymbolDisplacement or offset of one)
Returns:
the register that is set with the address

loadStackAddress

protected int loadStackAddress(Displacement disp)
Description copied from class: Generator
Load an address of a stack location into a register.

Specified by:
loadStackAddress in class Generator
Parameters:
disp - specifies the address (should be a SymbolDisplacement or offset of one)
Returns:
the register that is set with the address

genLoadImmediate

protected void genLoadImmediate(long value,
                                int base,
                                int dest)
Description copied from class: Generator
Generate instructions to load an immediate integer value added to the value in a register into a register.

Specified by:
genLoadImmediate in class Generator
Parameters:
value - is the value to load
base - is the base register (e.g., AlphaRegisterSet.I0_REG)
dest - is the register conatining the result

genLoadImmediate

protected int genLoadImmediate(long value,
                               int dest)
Description copied from class: Generator
Generate instructions to load an immediate integer value into a register.

Specified by:
genLoadImmediate in class Generator
Parameters:
value - is the value to load
dest - is the register conatining the result
Returns:
the register containing the value (usually dest but may be a hardware zero register)

genLoadDblImmediate

protected int genLoadDblImmediate(double value,
                                  int dest,
                                  int destSize)
Description copied from class: Generator
Generate instructions to load an immediate integer value into a register. The destination register type is ignored so that single values can be loaded into PAIRREG registers. Note, we know that any value referenced from memory is aligned because it is created by this routine.

Specified by:
genLoadDblImmediate in class Generator
Parameters:
value - is the value to load
dest - is the register conatining the result
destSize - is the size of the value
Returns:
the register containing the value (usually dest but may be a hardware zero register)

genLoadHighImmediate

protected long genLoadHighImmediate(long value,
                                    int base)
Description copied from class: Generator
Generate instructions to calculate a valid offset. Most ISAs provide only a small number of bits for an offset from an address in a register for load and store instructions. The Alpha provides 16-bit signed offsets and the Sparc provides 13-bit signed offsets. The *resultReg* register is set to the register containing the address to be used and the remaining offset is returned.

Specified by:
genLoadHighImmediate in class Generator
Parameters:
value - is the value to add to the base address
base - is the base address
Returns:
the lower 16 bits of the constant

basicBlockEnd

protected void basicBlockEnd()
Description copied from class: Generator
Called after the last CFG node in a basic block is processed.

Overrides:
basicBlockEnd in class Generator

allocStackAddress

protected int allocStackAddress(int adrReg,
                                Type type)
Description copied from class: Generator
Allocate a location on the stack for storing a value of the specified size. Put the address of the location in the register.

Specified by:
allocStackAddress in class Generator
Parameters:
adrReg - specifies the register to receive the address
type - is the type of the value
Returns:
the size of the value to be stored

loadFromMemoryWithOffset

protected void loadFromMemoryWithOffset(int dest,
                                        int address,
                                        long offset,
                                        int size,
                                        long alignment,
                                        boolean signed,
                                        boolean real)
Description copied from class: Generator
Generate instructions to load data from memory at the address in a register plus an offset.

Specified by:
loadFromMemoryWithOffset in class Generator
Parameters:
dest - is the destination register
address - is the register containing the address of the data
offset - is the offset from the address
size - specifies the size of the data to be loaded
alignment - is the alignment of the data (usually 1, 2, 4, or 8)
signed - is true if the data is to be sign extended
real - is true if the data is known to be a real

loadFromMemoryWithOffset

protected void loadFromMemoryWithOffset(int dest,
                                        int address,
                                        Displacement offset,
                                        int size,
                                        long alignment,
                                        boolean signed,
                                        boolean real)
Description copied from class: Generator
Generate instructions to load data from memory at the address in a register plus an offset. The offset must not be symbolic.

Specified by:
loadFromMemoryWithOffset in class Generator
Parameters:
dest - is the destination register
address - is the register containing the address of the data
offset - is the offset from the address
size - specifies the size of the data to be loaded
alignment - is the alignment of the data (usually 1, 2, 4, or 8)
signed - is true if the data is to be sign extended
real - is true if the data is known to be a real

loadFromMemoryDoubleIndexing

protected void loadFromMemoryDoubleIndexing(int dest,
                                            int index1,
                                            int index2,
                                            int size,
                                            long alignment,
                                            boolean signed,
                                            boolean real)
Description copied from class: Generator
Generate instructions to load data from memory at the address that is the sum of the two index register values.

Specified by:
loadFromMemoryDoubleIndexing in class Generator
Parameters:
dest - is the destination register
index1 - is the register containing the first index
index2 - is the register containing the second index
size - specifies the size of the data to be loaded
alignment - is the alignment of the data (usually 1, 2, 4, or 8)
signed - is true if the data is to be sign extended
real - is true if the data is known to be a real

storeIntoMemory

protected void storeIntoMemory(int src,
                               int address,
                               int size,
                               long alignment,
                               boolean real)
Description copied from class: Generator
Generate instructions to store data into memory at the address specified by a register.

Specified by:
storeIntoMemory in class Generator
Parameters:
src - is the source register
address - is the register containing the address of the data in memory
size - specifies the size of the data to be loaded
alignment - is the alignment of the data (usually 1, 2, 4, or 8)
real - is true if the data is known to be real

storeIntoMemoryWithOffset

protected void storeIntoMemoryWithOffset(int src,
                                         int address,
                                         long offset,
                                         int size,
                                         long alignment,
                                         boolean real)
Description copied from class: Generator
Generate instructions to store data into memory at the address in a register plus an offset.

Specified by:
storeIntoMemoryWithOffset in class Generator
Parameters:
src - is the register containing the value to be stored
address - is the register containing the address of the data
offset - is the offset from the address
size - specifies the size of the data to be loaded
alignment - is the alignment of the data (usually 1, 2, 4, or 8)
real - is true if the data is known to be real

storeIntoMemoryWithOffset

protected void storeIntoMemoryWithOffset(int src,
                                         int address,
                                         Displacement offset,
                                         int size,
                                         long alignment,
                                         boolean real)
Description copied from class: Generator
Generate instructions to store data into memory at the address in a register plus an offset. The offset must not be symbolic.

Specified by:
storeIntoMemoryWithOffset in class Generator
Parameters:
src - is the register containing the value to be stored
address - is the register containing the address of the data
offset - is the offset from the address
size - specifies the size of the data to be loaded
alignment - is the alignment of the data (usually 1, 2, 4, or 8)
real - is true if the data is known to be real

moveWords

protected void moveWords(int src,
                         long srcoff,
                         int dest,
                         Displacement destoff,
                         int size,
                         int aln)
Description copied from class: Generator
Generate an instruction sequence to move words from one location to another. The destination offset must not be symbolic.

Specified by:
moveWords in class Generator
Parameters:
src - specifies the register containing the source address
srcoff - specifies the offset from the address
dest - specifies the register containing the destination address
destoff - specifies the offset from the address
size - specifes the number of bytes to move
aln - is the alignment that can be assumed for both the source and destination addresses

moveWords

protected void moveWords(int src,
                         long srcoff,
                         int dest,
                         long destoff,
                         int size,
                         int aln)
Description copied from class: Generator
Generate an instruction sequence to move words from one location to another.

Specified by:
moveWords in class Generator
Parameters:
src - specifies the register containing the source address
srcoff - specifies the offset from the address
dest - specifies the register containing the destination address
destoff - specifies the offset from the address
size - specifes the number of bytes to move
aln - is the alignment that can be assumed for both the source and destination addresses

loadRegFromSymbolicLocation

protected void loadRegFromSymbolicLocation(int dest,
                                           int dsize,
                                           boolean isSigned,
                                           boolean isReal,
                                           Displacement disp)
Description copied from class: Generator
Load a register from a symbolic location in memory.

Specified by:
loadRegFromSymbolicLocation in class Generator
Parameters:
dest - is the register
dsize - is the size of the value in addressable memory units
isSigned - is true if the value in the register is signed
isReal - is true if the value in the register is a floating point value
disp - specifies the location

doBinaryOp

protected void doBinaryOp(int which,
                          Type ct,
                          Expr la,
                          Expr ra,
                          int ir)
Description copied from class: Generator
Generate instructions to do a binary operation on two values.

Specified by:
doBinaryOp in class Generator
Parameters:
which - specifies the binary operation (ADD, SUB, ...)
ct - is the result type
la - is the left argument
ra - is the right argument
ir - is the destination register

doCompareOp

protected void doCompareOp(BinaryExpr c,
                           CompareMode which)
Description copied from class: Generator
Generate instructions to do a comparison of two values.

Specified by:
doCompareOp in class Generator
Parameters:
c - is the compare expression
which - specifies the compare (EQ, NE, ...)

startRoutineCode

protected Instruction startRoutineCode()
Description copied from class: Generator
Called at the start of code generation for a routine.

Specified by:
startRoutineCode in class Generator

processSourceLine

protected void processSourceLine(int line,
                                 Label lab,
                                 boolean newLine)
Description copied from class: Generator
The user has requested source line information be included.

Specified by:
processSourceLine in class Generator
Parameters:
line - is the current line number
lab - is the last label encountered or null
newLine - is true if a new source line with no label

generateUnconditionalBranch

public void generateUnconditionalBranch(Label lab)
Description copied from class: Generator
Generate an unconditional branch to the label specified.

Specified by:
generateUnconditionalBranch in class Generator

getSpillLocation

public java.lang.Object getSpillLocation(int reg)
Description copied from class: Generator
Obtain the information needed for register spill loads and stores. The Object returned will probably specify a memory location. It will be passed to getSpillLoad() and getSpillStore().

Specified by:
getSpillLocation in class Generator
Parameters:
reg - specifies which virtual register will be spilled

insertSpillLoad

public Instruction insertSpillLoad(int reg,
                                   java.lang.Object spillLocation,
                                   Instruction after)
Description copied from class: Generator
Insert the instruction(s) to restore a spilled register. At this point, we are using a one-to-one mapping between real registers and virtual registers, so only a single instruction is required.

Specified by:
insertSpillLoad in class Generator
Parameters:
reg - specifies which virtual register will be loaded
spillLocation - specifies the offset on the stack to the spill location
after - specifies the instruction to insert the load after
Returns:
the last instruction inserted
See Also:
Generator.getSpillLocation(int)

insertSpillStore

public Instruction insertSpillStore(int reg,
                                    java.lang.Object spillLocation,
                                    Instruction after)
Description copied from class: Generator
Insert the instruction(s) to save a spilled register. At this point, we are using a one-to-one mapping between real registers and virtual registers, so only a single instruction is required.

Specified by:
insertSpillStore in class Generator
Parameters:
reg - specifies which virtual register will be stored
spillLocation - specifies the offset on the stack to the spill location
after - specifies the instruction to insert the store after
Returns:
the last instruction inserted
See Also:
Generator.getSpillLocation(int)

endRoutineCode

protected void endRoutineCode(int[] regMap)
Description copied from class: Generator
Called at the end of code generation for a routine. This method is responsible for inserting any prolog or epilog instructions required. It may also adjust stack offsets.

Specified by:
endRoutineCode in class Generator

genFtnCall

protected Branch genFtnCall(java.lang.String name,
                            short[] uses,
                            short[] defs)
Description copied from class: Generator
Create a call to the routine with the specified name. This is used to call things like the divide subroutine.

Specified by:
genFtnCall in class Generator
Parameters:
name - is the name of the function
uses - is the set of registers used by the call
defs - is the set of registers defined by the call or null
Returns:
the branch instruction generated

visitAbsoluteValueExpr

public void visitAbsoluteValueExpr(AbsoluteValueExpr e)

generateProlog

public void generateProlog(ProcedureType pt)
Description copied from class: Generator
This method is responsible for generating instructions to move function arguments to the position assigned by the layoutParameters method.

Specified by:
generateProlog in class Generator

visitBitComplementExpr

public void visitBitComplementExpr(BitComplementExpr e)

callArgs

protected short[] callArgs(Expr[] args,
                           boolean retStruct)
Description copied from class: Generator
Load the arguments into registers for a routine call. Only the first machine-dependent words of arguements are placed into registers. The remaining words are placed on the stack.

Specified by:
callArgs in class Generator
Parameters:
args - is the set of arguments
retStruct - is true if the first argument register is reserved
Returns:
the set of registers used for the argument values

visitCallFunctionExpr

public void visitCallFunctionExpr(CallFunctionExpr e)

visitCompareExpr

public void visitCompareExpr(CompareExpr e)

convertIntRegValue

protected int convertIntRegValue(int src,
                                 int srcSize,
                                 boolean srcSigned,
                                 int dest,
                                 int destSize,
                                 boolean destSigned)
Description copied from class: Generator
Generate instructions to convert an integer value in an integer register to an integer value of a different size. The source and destination may be the same register. This logic assumes that the value in the source register conforms to the specified type.

The semantics are that the register passed in as dest is the register the caller wants used. But, the register returned as the value of the method is the actual register used which may or may not be dest. For example, the register passed in as the source may not need to be modified. Thus, a move can be avoided if src is used instead of the specified destination. In some cases the source may be a register that is a hard-wired zero such as $31 on the alpha or %g0 on the sparc. The caller may still need to do a genRegToReg if it must have the result in the specified register. Note that genRegToReg generates no move if the source and destination registers are the same.

Specified by:
convertIntRegValue in class Generator
Parameters:
src - is the register containing the source value
srcSize - is the source value size
srcSigned - is true if the source value is signed
dest - is the suggested register to contain the result
destSize - is the size of the result value
destSigned - is true if the result value is signed
Returns:
the register containing the converted value

zeroFloatRegister

protected void zeroFloatRegister(int dest,
                                 int destSize)
Description copied from class: Generator
Generate code to zero out a floating point register.

Specified by:
zeroFloatRegister in class Generator

genRealPart

protected void genRealPart(int src,
                           int srcSize,
                           int dest,
                           int destSize)

genRealToInt

protected int genRealToInt(int src,
                           int srcSize,
                           int dest,
                           int destSize,
                           boolean destSigned)
Description copied from class: Generator
Convert real value in a real register to an integer value in a real register. The result is rounded down.

Specified by:
genRealToInt in class Generator
Parameters:
src - is the register containing the source value
srcSize - is the source value size
dest - is the register containing the result
destSize - is the size of the result value
destSigned - is true if the result value is signed
Returns:
the register containing the converted value

genRealToReal

protected void genRealToReal(int src,
                             int srcSize,
                             int dest,
                             int destSize)
Description copied from class: Generator
Convert a real value in a real register to a real value in a real register.

Specified by:
genRealToReal in class Generator

genRealToIntRound

protected void genRealToIntRound(int src,
                                 int srcSize,
                                 int dest,
                                 int destSize)
Description copied from class: Generator
Convert real value in a real register to an integer value in a real register. The result is rounded to the nearest integer.

Specified by:
genRealToIntRound in class Generator

genRoundReal

protected void genRoundReal(int src,
                            int srcSize,
                            int dest,
                            int destSize)
Description copied from class: Generator
Convert real value in a real register to a rounded real value in a real register. The result is rounded to the nearest integer.

Specified by:
genRoundReal in class Generator

genIntToReal

protected void genIntToReal(int src,
                            int srcSize,
                            int dest,
                            int destSize)
Description copied from class: Generator
Convert an integer value in an integer register to a real value in a real register.

Specified by:
genIntToReal in class Generator
Parameters:
src - is the register containing the source integer value
srcSize - is the size of the integer value
dest - is the register that will conatin the result real value
destSize - is the size of the real value

genUnsignedIntToReal

protected void genUnsignedIntToReal(int src,
                                    int srcSize,
                                    int dest,
                                    int destSize)
Description copied from class: Generator
Convert an unsigned integer value in an integer register to a real value in a real register.

Specified by:
genUnsignedIntToReal in class Generator
Parameters:
src - is the register containing the source integer value
srcSize - is the size of the integer value
dest - is the register that will conatin the result real value
destSize - is the size of the real value

genFloorOfReal

protected void genFloorOfReal(int src,
                              int srcSize,
                              int dest,
                              int destSize)
Description copied from class: Generator
Generate instructions to compute the floor of a real vaue in a real register to a real register.

Specified by:
genFloorOfReal in class Generator

visitExponentiationExpr

public void visitExponentiationExpr(ExponentiationExpr e)

visitDivisionExpr

public void visitDivisionExpr(DivisionExpr e)

visitRemainderExpr

public void visitRemainderExpr(RemainderExpr e)

genSingleUse

protected short[] genSingleUse(int reg)
Description copied from class: Generator
Generate the array of registers that a call to a function requires. The specified register is the argument register. Other registers required by the calling convention are added to the array.

Specified by:
genSingleUse in class Generator

genDoubleUse

protected short[] genDoubleUse(int reg1,
                               int reg2)
Description copied from class: Generator
Generate the array of registers that a call to a function requires. The specified registers are the two argument registers. Other registers required by the calling convention are added to the array.

Specified by:
genDoubleUse in class Generator

loadFieldValue

protected void loadFieldValue(FieldDecl fd,
                              long fieldOffset,
                              int adr,
                              ResultMode adrha,
                              int adraln,
                              long adrrs,
                              int dest)
Description copied from class: Generator
Load the value of a field to a register.

Specified by:
loadFieldValue in class Generator
Parameters:
fd - defines the field
fieldOffset - is the offset from the specified address
adr - is the register holding the address
adrha - specifies the type of address
adraln - specifies the alignment of the address
adrrs - specifies the size of the structure if it is in a register
dest - specifies the register to hold the field value

genIfRegister

protected void genIfRegister(CompareMode which,
                             int treg,
                             boolean signed,
                             Label labt,
                             Label labf)
Description copied from class: Generator
Generate a branch based on the value of an expression compared to zero. The value may be floating point or integer but it is never a value pair.

Specified by:
genIfRegister in class Generator
Parameters:
which - specifies the branch test (EQ, NE, LT, ...)
treg - specifies the register containing the value
signed - is true if the value is signed
labt - specifies the path if the test fails
labf - specifies the path if the test succeeds

genIfRelational

protected void genIfRelational(boolean rflag,
                               MatchExpr predicate,
                               Chord tc,
                               Chord fc)
Description copied from class: Generator
Generate a branch based on a relational expression.

Specified by:
genIfRelational in class Generator
Parameters:
rflag - true if the test condition should be reversed
predicate - specifies the relational expression
tc - specifies the path if the test succeeds
fc - specifies the path if the test fails

loadArrayElement

protected void loadArrayElement(ArrayIndexExpr aie,
                                int dest)
Description copied from class: Generator
Load an array element into a register.

Specified by:
loadArrayElement in class Generator
Parameters:
aie - specifies the array element
dest - specifies the register

calcArrayElementAddress

protected void calcArrayElementAddress(ArrayIndexExpr aie,
                                       long offseta)
Description copied from class: Generator
Load the address of an array element into a register. Return the offset from the address in resultRegAddressOffset. The address is specified in resultReg.

Specified by:
calcArrayElementAddress in class Generator
Parameters:
aie - specifies the array elementxpression
offseta - is the offset from the address

visitMultiplicationExpr

public void visitMultiplicationExpr(MultiplicationExpr e)

visitNegativeExpr

public void visitNegativeExpr(NegativeExpr e)

genAlloca

protected void genAlloca(Expr arg,
                         int reg)
Description copied from class: Generator
Generate the code for the alloca() function.

Specified by:
genAlloca in class Generator

genSignFtn

protected void genSignFtn(int dest,
                          int laReg,
                          int raReg,
                          Type rType)
Description copied from class: Generator
Generate the code for the Fortran SIGN() intrinsic function.

Specified by:
genSignFtn in class Generator

genAtan2Ftn

protected void genAtan2Ftn(int dest,
                           int laReg,
                           int raReg,
                           Type rType)
Description copied from class: Generator
Generate the code for the Fortran ATAN2() intrinsic function.

Specified by:
genAtan2Ftn in class Generator

genDimFtn

protected void genDimFtn(int dest,
                         int laReg,
                         int raReg,
                         Type rType)
Description copied from class: Generator
Generate the code for the Fortran DIM() intrinsic function.

Specified by:
genDimFtn in class Generator

genSqrtFtn

protected void genSqrtFtn(int dest,
                          int src,
                          Type type)
Description copied from class: Generator
Generate the code for the sqrt() function.

Specified by:
genSqrtFtn in class Generator

genExpFtn

protected void genExpFtn(int dest,
                         int src,
                         Type type)
Description copied from class: Generator
Generate the code for the exp() function.

Specified by:
genExpFtn in class Generator

genLogFtn

protected void genLogFtn(int dest,
                         int src,
                         Type type)
Description copied from class: Generator
Generate the code for the log() function.

Specified by:
genLogFtn in class Generator

genLog10Ftn

protected void genLog10Ftn(int dest,
                           int src,
                           Type type)
Description copied from class: Generator
Generate the code for the log10() function.

Specified by:
genLog10Ftn in class Generator

genSinFtn

protected void genSinFtn(int dest,
                         int src,
                         Type type)
Description copied from class: Generator
Generate the code for the sin() function.

Specified by:
genSinFtn in class Generator

genCosFtn

protected void genCosFtn(int dest,
                         int src,
                         Type type)
Description copied from class: Generator
Generate the code for the cos() function.

Specified by:
genCosFtn in class Generator

genTanFtn

protected void genTanFtn(int dest,
                         int src,
                         Type type)
Description copied from class: Generator
Generate the code for the tan() function.

Specified by:
genTanFtn in class Generator

genAsinFtn

protected void genAsinFtn(int dest,
                          int src,
                          Type type)
Description copied from class: Generator
Generate the code for the asin() function.

Specified by:
genAsinFtn in class Generator

genAcosFtn

protected void genAcosFtn(int dest,
                          int src,
                          Type type)
Description copied from class: Generator
Generate the code for the acos() function.

Specified by:
genAcosFtn in class Generator

genAtanFtn

protected void genAtanFtn(int dest,
                          int src,
                          Type type)
Description copied from class: Generator
Generate the code for the atan() function.

Specified by:
genAtanFtn in class Generator

genSinhFtn

protected void genSinhFtn(int dest,
                          int src,
                          Type type)
Description copied from class: Generator
Generate the code for the sinh() function.

Specified by:
genSinhFtn in class Generator

genCoshFtn

protected void genCoshFtn(int dest,
                          int src,
                          Type type)
Description copied from class: Generator
Generate the code for the cosh() function.

Specified by:
genCoshFtn in class Generator

genTanhFtn

protected void genTanhFtn(int dest,
                          int src,
                          Type type)
Description copied from class: Generator
Generate the code for the tanh() function.

Specified by:
genTanhFtn in class Generator

genConjgFtn

protected void genConjgFtn(int dest,
                           int src,
                           Type type)
Description copied from class: Generator
Generate the code for the conjg() function.

Specified by:
genConjgFtn in class Generator

genReturnAddressFtn

protected void genReturnAddressFtn(int dest,
                                   int src,
                                   Type type)
Description copied from class: Generator
Generate the code for the builtin_return_address() function.

Specified by:
genReturnAddressFtn in class Generator

genFrameAddressFtn

protected void genFrameAddressFtn(int dest,
                                  int src,
                                  Type type)
Description copied from class: Generator
Generate the code for the builtin_fram_address() function.

Specified by:
genFrameAddressFtn in class Generator

visitNotExpr

public void visitNotExpr(NotExpr e)

visitReturnChord

public void visitReturnChord(ReturnChord c)

storeRegToSymbolicLocation

protected void storeRegToSymbolicLocation(int src,
                                          int dsize,
                                          long alignment,
                                          boolean isReal,
                                          Displacement disp)
Description copied from class: Generator
Store a value in a register to a symbolic location in memory.

Specified by:
storeRegToSymbolicLocation in class Generator
Parameters:
src - is the value
dsize - is the size of the value in addressable memory units
alignment - is the alignment of the data (usually 1, 2, 4, or 8)
isReal - is true if the value in the register is a floating point value
disp - specifies the location

storeLfae

protected void storeLfae(LoadFieldAddressExpr lhs,
                         Expr rhs)
Description copied from class: Generator
Store a value into a field of a structure.

Specified by:
storeLfae in class Generator
Parameters:
lhs - specifies the field of the structure
rhs - specifies the value

genSwitchUsingIfs

protected boolean genSwitchUsingIfs(int testReg,
                                    Chord[] cases,
                                    long[] keys,
                                    int num,
                                    long spread)
Description copied from class: Generator
Generate the code for a switch statement using branches for each case.

Specified by:
genSwitchUsingIfs in class Generator
Parameters:
testReg - is the register holding the selected key value
cases - is the list of CFG nodes for the switch cases
keys - is the list of case values
num - is the number of cases
spread - is a measure of the density of the cases values
Returns:
true if code for the switch statement was generated

genSwitchUsingTransferVector

protected void genSwitchUsingTransferVector(int testReg,
                                            Chord[] cases,
                                            long[] keys,
                                            Label labt,
                                            long min,
                                            long max)
Description copied from class: Generator
Generate the code for a switch statement using branches for each case.

Specified by:
genSwitchUsingTransferVector in class Generator
Parameters:
testReg - is the register holding the selected key value
cases - is the list of CFG nodes for the switch cases
keys - is the list of case values
labt - is the label for the default case
min - is the smallest case value
max - is the largest case value

visitVaStartExpr

public void visitVaStartExpr(VaStartExpr e)
Specified by:
visitVaStartExpr in interface Predicate
Overrides:
visitVaStartExpr in class Generator

doVaCopy

protected void doVaCopy(Expr dst,
                        Expr src)
Description copied from class: Generator
Generate code for a va_copy().

Overrides:
doVaCopy in class Generator

visitVaArgExpr

public void visitVaArgExpr(VaArgExpr e)

visitConditionalExpr

public void visitConditionalExpr(ConditionalExpr e)
Specified by:
visitConditionalExpr in interface Predicate
Overrides:
visitConditionalExpr in class Generator

getMaxAreaIndex

public int getMaxAreaIndex()
Description copied from class: Generator
Return the maximum area index value.

Specified by:
getMaxAreaIndex in class Generator