scale.backend
Class Generator

java.lang.Object
  extended by scale.backend.Generator
All Implemented Interfaces:
Predicate
Direct Known Subclasses:
AlphaGenerator, MipsGenerator, PPCGenerator, SparcGenerator, Trips2Generator, X86Generator, XyzGenerator

public abstract class Generator
extends java.lang.Object
implements Predicate

This class is the base class for code generators.

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

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

A generator translates Scribble CFGs into a linear sequence of machine instructions.

The primary rule: Thou shall not use a register obtained from a visit() as a destination register until all other registers obtained from visit() have been used for the last time for the simple reason that they may be the same register.

The secondary rule:Thou shall not define the destination register until the very last instruction in the sequence for the simple reason that the register allocator does not know where a sequence begins and ends.

The most important methods are those dealing with the calling conventions. The visitCallFunctionExpr method operates the viewpoint of the caller and generates the instructions to call a sub-function. The generateProlog, layoutParameters, and endRoutineCode methods operate from the viewpoint of the callee.


Field Summary
protected static int ADD
          Add operation
protected  Displacement addrDisp
          Last displacement generated for an address.
protected static int AND
          Bit and operation
static boolean annotateCode
          True if annotation comments are to be generated.
protected  boolean ansic
          True if ANSI C source code specified.
static int ANSIC
          Specify ANSI C.
protected  double branchPrediction
          Probability of most recent IfThenElseChord taking the true branch.
protected  boolean callsRoutine
          True if this routine calls another routine.
protected  CallGraph cg
          The call graph being processed.
static boolean classTrace
          True if traces are to be performed.
protected  HashMap<java.lang.String,SpaceAllocation> codeMap
          Map from routine to instructions.
protected static boolean[] commutative
          Is the dyadic operation commutative?
protected  Marker currentBeginMarker
          Mark the start of the routine's code.
protected  RoutineDecl currentRoutine
          The declaration associated with this routine.
protected  SpaceAllocation[] dataAreas
          Array of data areas - indexed by handle.
static int DEBUG
          Debug info should be generated.
protected static int DIV
          Divide operation
protected static int[] fieldAlignment
          Map from lower three bits of an offset to the alignment.
protected  boolean genDebugInfo
          True if information for debuggers should be generated.
protected  Instruction lastInstruction
          Last instruction generated.
protected  Label lastLabel
          Last label generated.
static int LINENUM
          Generate source line information.
protected  boolean lineNumbers
          True if source line number information should be placed in the assembly code.
protected  boolean little
          True if target machine is little-endian.
protected  Machine machine
          Machine specific information.
protected static int MOD
          Modulo operation
protected static int MUL
          Multiply operation
protected  boolean naln
          True if we assume indirect loads are not aligned.
static int NALN
          Indirect loads are not aligned.
protected  int nextArea
          Next available in dataAreas.
protected  boolean nis
          True if instructions should not be scheduled.
static int NIS
          Inhibit instruction scheduling.
protected  boolean nph
          True if the peephole optimizer should not be run.
static int NPH
          Inhibit peephole optimization.
protected static java.lang.String[] operation
          Map operation to string.
protected static int OR
          Bit or operation
protected  boolean predicatedOnTrue
          Indicates if an expression predicated by predicateReg is predicated on true or false.
protected  int predicateReg
          Register containing the current predicate.
protected  int readOnlyDataArea
          The data area to use to for constant data.
protected  RegisterSet registers
          The register set definition.
protected  int resultReg
          Register containing the last generated expression result, usually as a result of a call to visit().
protected  int resultRegAddressAlignment
          If resultRegMode is ResultMode.ADDRESS, this value is alignment of the address contained in the register specified by resultReg.
protected  long resultRegAddressOffset
          If resultRegMode is ResultMode.ADDRESS, this value is offset from the address contained in the register specified by resultReg.
protected  ResultMode resultRegMode
          The type of the resultReg value.
protected  long resultRegSize
          If resultRegMode is ResultMode.STRUCT_VALUE, this value is size of the struct contained in the register specified by resultReg.
protected  Instruction returnInst
          The instruction just before the one and only return instruction.
protected  Scribble scribble
          The CFG associated with this routine.
protected static int SLL
          Shift left logical operation
protected static int SRA
          Shift right arithmetic operation
protected static int SRL
          Shift right logical operation
protected  int stkPtrReg
          The register to use to access the stack frame for the function.
protected static int SUB
          Subtract operation
protected  Chord successorCFGNode
          The successor to the current CFG node.
protected  boolean trace
          True if tracing requested.
protected  UniqueName un
          Generate unique names for constants in memory.
protected  boolean useMemory
          True if programmer variables should be placed in memory.
protected  boolean usesAlloca
          True if the current routine uses __builtin_alloca().
protected  boolean usesVaStart
          True if the current routine uses va_start().
protected static int XOR
          Bit exclusive or operation
 
Constructor Summary
Generator(CallGraph cg, RegisterSet registers, Machine machine, int features)
          This class is used to convert the Scribble CFG to machine instructions.
 
Method Summary
protected abstract  void addRegs(int laReg, int raReg, int dest)
          Generate an add of address registers laReg and raReg.
 void adjustImmediates(Instruction firstInstruction)
          Adjust large immediate values.
protected  int allocateData(java.lang.String name, int section, int type, long size, boolean readOnly, java.lang.Object value, int reps, int alignment)
          Return the handle of a new memory area.
protected  int[] allocateRegisters(Instruction first, boolean trace)
          Generate a mapping from virtual register to real register and then modify the instructions to use real registers.
 int allocateTextArea(java.lang.String name, int area)
          Return the handle of a new area of memory to contain instructions.
protected  int allocateWithData(java.lang.String name, Type type, long ts, Expression init, int area, boolean readOnly, int reps, int aln)
          Allocate an area for the data specified by the Clef Expression.
protected abstract  int allocStackAddress(int adrReg, Type type)
          Allocate a location on the stack for storing a value of the specified size.
protected  void appendCallInstruction(Branch call, Label lab, short[] uses, short[] kills, short[] defs, boolean genLabel)
          Append the subroutine call instruction to the end of the sequence of instructions.
protected  void appendInstruction(Instruction inst)
          Append the instruction to the end of the sequence of instructions.
protected  void appendLabel(Label label)
          Append the label to the end of the sequence of instructions.
abstract  void assemble(Emit emit, java.lang.String source, java.util.Enumeration<java.lang.String> comments)
          Generate assembly language.
protected abstract  void assignDeclToMemory(java.lang.String name, VariableDecl vd)
          Assign the specified variable to a location in memory using the specified name.
protected abstract  void assignDeclToRegister(VariableDecl vd)
          Assign the specified variable to a register.
protected abstract  void assignDeclToStack(VariableDecl vd)
          Assign the specified variable to a location in the stack frame.
 void associateDispWithArea(int handle, Displacement disp)
          Associate a displacement with an area.
static int avoidedAddressCalcs()
          Return the number of variable address calculations that were eliminated.
static int avoidedLoads()
          Return the number of variable loads that were eliminated.
protected  void basicBlockEnd()
          Called after the last CFG node in a basic block is processed.
protected  void calcAddressAndOffset(Expr exp, long offset)
          Load the address generated by an expression into a register.
protected abstract  void calcArrayElementAddress(ArrayIndexExpr aie, long offset)
          Load the address of an array element into a register.
protected  void calcFieldAddress(LoadFieldAddressExpr c, long offset)
          Calculate the offset and base address of a field.
protected  void calcFieldOffsets(AggregateType at)
          Determine the offsets for fields of a struct or union.
protected abstract  short[] callArgs(Expr[] args, boolean specialFirstArg)
          Load the arguments into registers for a routine call.
protected  void convertCFG(Chord start)
          Generate the instructions for the CFG node.
protected abstract  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.
protected  void copyPropagate(Instruction first)
          Copy-propagate register numbers from move instructions.
 Label createLabel()
          Create a new Label and return it.
protected  Label createNewLabel()
          Allocate a machine-specific label.
abstract  int dataType(int size, boolean flt)
          Return the data type as an integer.
protected  void defineDeclInCommon(Declaration decl, Displacement disp)
          Associate information with a Declaration in COMMON.
protected  void defineDeclInMemory(Declaration decl, Displacement disp)
          Associate information with a Declaration kept in memory.
protected  void defineDeclInRegister(Declaration decl, int register, ResultMode regha)
          Associate information with a variable Declaration kept in a register.
protected  void defineDeclOnStack(Declaration decl, Displacement disp)
          Associate information with a Declaration kept on the stack.
protected  void defineRoutineInfo(RoutineDecl rd, Displacement disp)
          Associate information with a routine.
protected abstract  Displacement defStringValue(java.lang.String v, int size)
          Return the displacement for a string.
protected  void doBinaryOp(BinaryExpr c, int which)
          Generate instructions to do a binary operation on two values.
protected abstract  void doBinaryOp(int which, Type ct, Expr la, Expr ra, int dest)
          Generate instructions to do a binary operation on two values.
protected abstract  void doCompareOp(BinaryExpr c, CompareMode which)
          Generate instructions to do a comparison of two values.
protected  boolean doNext(Chord nxt)
          Make sure the specified Chord is converted next.
protected  void doStore(Expr lhs, Expr rhs, boolean vaCopy)
          Generate code for a copy (i.e., assignment).
protected  void doVaCopy(Expr lhs, Expr rhs)
          Generate code for a va_copy().
protected  void endModule()
          Called at the end of a call graph (module).
protected abstract  void endRoutineCode(int[] regMap)
          Called at the end of code generation for a routine.
 Displacement findAreaDisp(int section, int type, boolean readOnly, long size, double value, int alignment)
          Find an allocation of a floating point value.
 Displacement findAreaDisp(int section, int type, boolean readOnly, long size, long value, int alignment)
          Find an allocation of a long value.
 Displacement findAreaDisp(int section, int type, boolean readOnly, long size, java.lang.String value, int alignment)
          Find an allocation of a String value.
protected  void findLastInstruction(Instruction firstInstruction)
          Find the last instruction.
protected abstract  void genAcosFtn(int dest, int src, Type type)
          Generate the code for the acos() function.
protected abstract  void genAlloca(Expr arg, int reg)
          Generate the code for the alloca() function.
protected abstract  void genAsinFtn(int dest, int src, Type type)
          Generate the code for the asin() function.
protected abstract  void genAtan2Ftn(int dest, int laReg, int raReg, Type rType)
          Generate the code for the Fortran ATAN2() intrinsic function.
protected abstract  void genAtanFtn(int dest, int src, Type type)
          Generate the code for the atan() function.
protected abstract  void genConjgFtn(int dest, int src, Type type)
          Generate the code for the conjg() function.
protected abstract  void genCosFtn(int dest, int src, Type type)
          Generate the code for the cos() function.
protected abstract  void genCoshFtn(int dest, int src, Type type)
          Generate the code for the cosh() function.
protected abstract  void genDimFtn(int dest, int laReg, int raReg, Type rType)
          Generate the code for the Fortran DIM() intrinsic function.
protected abstract  short[] genDoubleUse(int reg1, int reg2)
          Generate the array of registers that a call to a function requires.
 void generate()
          Generate the machine instructions for each routine in the call graph.
 void generateConditionalBranch(int which, int treg, Label l)
          Generate a predicated branch to a single location.
protected abstract  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.
protected abstract  void generateUnconditionalBranch(Label lab)
          Generate an unconditional branch to the label specified.
protected abstract  void genExpFtn(int dest, int src, Type type)
          Generate the code for the exp() function.
protected abstract  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 abstract  void genFrameAddressFtn(int dest, int src, Type type)
          Generate the code for the builtin_fram_address() function.
protected abstract  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, Expr predicate, Chord tc, Chord fc)
          Generate a branch based on the value of an expression compared to zero.
protected  void genIfRegister(CompareMode which, int treg, boolean signed, Chord tc, Chord fc)
          Generate a branch based on the value of an expression compared to zero.
protected abstract  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 abstract  void genIfRelational(boolean rflag, MatchExpr predicate, Chord tc, Chord fc)
          Generate a branch based on a relational expression.
protected abstract  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 abstract  int genLoadDblImmediate(double value, int dest, int destSize)
          Generate instructions to load an immediate integer value into a register.
protected abstract  long genLoadHighImmediate(long value, int base)
          Generate instructions to calculate a valid offset.
protected abstract  int genLoadImmediate(long value, int dest)
          Generate instructions to load an immediate integer value into a register.
protected abstract  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 abstract  void genLog10Ftn(int dest, int src, Type type)
          Generate the code for the log10() function.
protected abstract  void genLogFtn(int dest, int src, Type type)
          Generate the code for the log() function.
protected abstract  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 abstract  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 abstract  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 abstract  void genRegToReg(int src, int dest)
          Generate instructions to move data from one register to another.
protected abstract  void genReturnAddressFtn(int dest, int src, Type type)
          Generate the code for the builtin_return_address() function.
protected abstract  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 abstract  void genSignFtn(int dest, int laReg, int raReg, Type rType)
          Generate the code for the Fortran SIGN() intrinsic function.
protected abstract  void genSinFtn(int dest, int src, Type type)
          Generate the code for the sin() function.
protected abstract  short[] genSingleUse(int reg)
          Generate the array of registers that a call to a function requires.
protected abstract  void genSinhFtn(int dest, int src, Type type)
          Generate the code for the sinh() function.
protected abstract  void genSqrtFtn(int dest, int src, Type type)
          Generate the code for the sqrt() function.
protected abstract  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 abstract  void genSwitchUsingTransferVector(int testReg, Chord[] cases, long[] keys, Label dflt, long min, long max)
          Generate the code for a switch statement using branches for each case.
protected abstract  void genTanFtn(int dest, int src, Type type)
          Generate the code for the tan() function.
protected abstract  void genTanhFtn(int dest, int src, Type type)
          Generate the code for the tanh() function.
protected  void genTrueFalseBranch(int predicate, Chord tc, Chord fc)
          Generate a branch based on the value of an expression which is guaranteed to be either 0 or 1.
protected abstract  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.
protected  Label getBranchLabel(Chord location)
          Return the label for a branch location.
protected  Chord getBranchTarget(Chord s)
          Skip nodes that don't result in generating instructions.
 CallGraph getCallGraph()
          Return the call graph associated with this invocation of the code generator.
 RoutineDecl getCurrentRoutine()
          Return the current routine being processed.
protected  IntegerDisplacement getDisp(int value)
          Generate an integer displacement.
abstract  int getFirstArgRegister(int regType)
          Return the register used as the first argument in a function call.
 Label getLabel(int index)
          Return the label whose index is specified.
 Machine getMachine()
          Return the machine definition in use.
abstract  int getMaxAreaIndex()
          Return the maximum area index value.
 java.lang.String getName(int handle)
          Return the name associated with an area of memory.
 RegisterSet getRegisterSet()
          Return the register set definition in use.
 int getSAType(Type type)
          Return the SpaceAllocation type for the specified Type.
 SourceLanguage getSourceLanguage()
          Return the source language of the original program.
 SpaceAllocation getSpaceAllocation(int handle)
          Return the SpaceAllocation associated with the specified handle.
abstract  java.lang.Object getSpillLocation(int reg)
          Obtain the information needed for register spill loads and stores.
 int getStackPtr()
          Return the register assignment of the stack pointer.
protected  Instruction insertInstruction(Instruction inst, Instruction location)
          Insert the instruction after the specified instruction.
protected  Instruction insertLabel(Label label, Instruction location)
          Insert the label after the specified instruction.
abstract  Instruction insertSpillLoad(int reg, java.lang.Object spillLocation, Instruction after)
          Insert the instruction(s) to restore a spilled register.
abstract  Instruction insertSpillStore(int reg, java.lang.Object spillLocation, Instruction after)
          Insert the instruction(s) to save a spilled register.
protected  boolean isAssignedRegister(int reg)
          Return true if the register is assigned to a variable.
 boolean isFortran()
          Return true if the source language is Fortran.
 boolean isSimple(Expr arg)
          Return true if the expression will not result in a call to a routine.
protected  void labelCfgForBackend()
          Label the basic blocks.
protected abstract  void layoutParameters()
          Determine the layout of routine parameters for the call.
protected abstract  void loadArrayElement(ArrayIndexExpr aie, int dest)
          Load an array element into a register.
protected  void loadDeclValue(Declaration decl, Type vt, boolean isPredicated)
          Load the value of a declaration into a register.
protected abstract  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 abstract  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 abstract  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 abstract  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 abstract  int loadMemoryAddress(Displacement disp)
          Load an address of a memory location into a register.
protected abstract  void loadRegFromSymbolicLocation(int dest, int dsize, boolean isSigned, boolean isReal, Displacement disp)
          Load a register from a symbolic location in memory.
protected abstract  int loadStackAddress(Displacement disp)
          Load an address of a stack location into a register.
protected  void loadVariable(VariableDecl vd, Type vt, boolean isPredicated)
          Load the value of a variable into a register.
protected  void loadVariableFromCommon(int adr, Type vt, long offset)
          Load the value of a variable in COMMON into a register.
protected  void loadVariableFromMemory(Displacement vdisp, Type vt)
          Load the value of a variable in memory into a register.
protected  void loadVariableFromStack(Displacement vdisp, Type vt)
          Load the value of a variable on the stack into a register.
protected  void moveInstructionSequence(Instruction prior, Instruction last, Instruction after)
          Move a sequence of instructions to another position.
protected abstract  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 abstract  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 needValue(Expr exp)
          Process the expression and if the result is an address value, add any offset required to the base address.
protected  void needValue(int src, long srcoff, ResultMode srcha)
          If the register contains an address value, add any offset required to the base address.
 int newLabel()
          Create a new Label and return its index.
protected  void peepholeAfterRegisterAllocation(Instruction first)
          Do peephole optimizations after registers are allocated.
protected  void peepholeBeforeRegisterAllocation(Instruction first)
          Do peephole optimizations before registers are allocated.
protected  void processDecls()
          Process the declarations of this CFG.
protected abstract  void processRoutineDecl(RoutineDecl rd, boolean topLevel)
          The RoutineDecl is assigned a tag.
protected abstract  void processSourceLine(int line, Label label, boolean newLine)
          The user has requested source line information be included.
protected  Type processType(Declaration decl)
          Insure that all types have their register types specified and all structure fields have had their offsets determined.
protected  Type processType(Expr expr)
          Insure that all types have their register types specified and all structure fields have had their offsets determined.
protected  Type processType(Expression expr)
          Insure that all types have their register types specified and all structure fields have had their offsets determined.
protected  Type processType(Type type)
          Insure that all types have their register types specified and all structure fields have had their offsets determined.
protected  void processTypeDecl(TypeDecl td, boolean complete)
          Called for every TypeDecl instance so that the target code generator can perform any needed processing such as making Stabs entries.
protected  void processTypeName(TypeName td)
          Called for every TypeName instance so that the target code generator can perform any needed processing such as making Stabs entries.
protected  void processVariableDecl(VariableDecl vd, boolean topLevel)
          The VariableDecl is assigned a tag.
protected  void propagate(Instruction inst, int newReg, int oldReg)
          Perform copy propagation for the specified registers within the basic block that begins with the specified instruction.
protected  void putAddressInRegister(Declaration decl, boolean isPredicated)
          Load the address of a declaration into a register.
protected  void putAddressInRegister(Expr expr)
          Place the address of the argument in a register.
protected  void putAddressInRegisterNO(Declaration decl, boolean isPredicated)
          Load the address of a declaration into a register and place any offset into resultRegAddressOffset.
static int regeneratedAddresses()
          Return the number of spill loads that were avoided because of regenerating the address value.
static int regeneratedLiterals()
          Return the number of spills were avoided because of regenerating the literal value.
static int regeneratedValues()
          Return the number of spills were avoided because of regenerating the value.
protected  Instruction regenerateRegister(int reg, Instruction after)
          Regenerate a register value instead of performing a spill load.
 boolean removeUnneededInstructions(Instruction first)
          Remove instructions that do not change the machine state.
protected  void resetForBasicBlock()
          This method is called at the end of each basic block and at the start before any CFG nodes are processed.
abstract  int returnRegister(int regType, boolean isCall)
          Return the register used to return the function value.
protected  void saveGeneratedCode(Instruction first)
          Save the generated code in a TEXT section using the name of the current routine.
protected  boolean shouldBeRegenerated(int reg)
          Return true if the value in the register can be easily regenerated.
protected  void specifyInReg(Declaration decl, int reg, ResultMode regha)
          Specify that the value of a variable kept in memory is now in a register.
protected  void startModule()
          Called at the beginning of a call graph (module).
protected abstract  Instruction startRoutineCode()
          Called at the start of code generation for a routine.
protected abstract  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 abstract  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 abstract  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 storeLdae(LoadDeclAddressExpr lhs, Expr rhs)
          Store a value into a variable.
protected  void storeLdve(LoadDeclValueExpr lhs, Expr rhs)
          Store a value into the location specied by an address in a variable.
protected abstract  void storeLfae(LoadFieldAddressExpr lhs, Expr rhs)
          Store a value into a field of a structure.
protected  void storeLiteral(LiteralExpr le, Expr rhs)
          Store a value into the location specied by a literal value.
protected  void storeLvie(LoadValueIndirectExpr lhs, Expr rhs)
          Store a value into the location specied by the value of an expression.
protected abstract  void storeRegToSymbolicLocation(int src, int dsize, long alignment, boolean isReal, Displacement disp)
          Store a value in a register to a symbolic location in memory.
protected  boolean unconditionalBranchNeeded(Chord c, Chord nxt, java.lang.Object actual)
          Return true if an unconditional branch is needed.
 void updateLabelIndex(Label label)
          Update the unique identifier for a label.
protected  long valueOf(SizeofLiteral il)
          Return the value of the SizeofLiteral.
 void visitAdditionExpr(AdditionExpr e)
           
 void visitAllocateExpr(AllocateExpr e)
           
 void visitAndExpr(AndExpr e)
           
 void visitArrayIndexExpr(ArrayIndexExpr e)
           
 void visitBeginChord(BeginChord c)
           
 void visitBinaryExpr(BinaryExpr e)
           
 void visitBitAndExpr(BitAndExpr e)
           
 void visitBitOrExpr(BitOrExpr e)
           
 void visitBitShiftExpr(BitShiftExpr e)
           
 void visitBitXorExpr(BitXorExpr e)
           
 void visitBranchChord(BranchChord c)
           
 void visitCallExpr(CallExpr e)
           
 void visitCallMethodExpr(CallMethodExpr e)
           
 void visitChord(Chord c)
           
 void visitComplexValueExpr(ComplexValueExpr e)
           
 void visitConditionalExpr(ConditionalExpr e)
           
 void visitConversionExpr(ConversionExpr e)
           
 void visitDecisionChord(DecisionChord c)
           
 void visitDualExpr(DualExpr e)
           
 void visitEndChord(EndChord c)
           
 void visitEqualityExpr(EqualityExpr e)
           
 void visitExitChord(ExitChord c)
           
 void visitExpr(Expr e)
           
 void visitExprChord(ExprChord c)
           
 void visitExprPhiExpr(ExprPhiExpr e)
           
 void visitGotoChord(GotoChord c)
           
 void visitGreaterEqualExpr(GreaterEqualExpr e)
           
 void visitGreaterExpr(GreaterExpr e)
           
 void visitIfThenElseChord(IfThenElseChord c)
           
 void visitLeaveChord(LeaveChord c)
           
 void visitLessEqualExpr(LessEqualExpr e)
           
 void visitLessExpr(LessExpr e)
           
 void visitLiteralExpr(LiteralExpr e)
           
 void visitLoadDeclAddressExpr(LoadDeclAddressExpr e)
           
 void visitLoadDeclValueExpr(LoadDeclValueExpr e)
           
 void visitLoadExpr(LoadExpr e)
           
 void visitLoadFieldAddressExpr(LoadFieldAddressExpr e)
           
 void visitLoadFieldValueExpr(LoadFieldValueExpr e)
           
 void visitLoadValueIndirectExpr(LoadValueIndirectExpr lvie)
           
 void visitLoopExitChord(LoopExitChord c)
           
 void visitLoopHeaderChord(LoopHeaderChord c)
           
 void visitLoopInitChord(LoopInitChord c)
           
 void visitLoopPreHeaderChord(LoopPreHeaderChord c)
           
 void visitLoopTailChord(LoopTailChord c)
           
 void visitMarkerChord(MarkerChord c)
           
 void visitMaxExpr(MaxExpr e)
           
 void visitMinExpr(MinExpr e)
           
 void visitNaryExpr(NaryExpr e)
           
 void visitNilExpr(NilExpr e)
           
 void visitNote(Note n)
           
 void visitNotEqualExpr(NotEqualExpr e)
           
 void visitNullChord(NullChord c)
           
 void visitOrExpr(OrExpr e)
           
 void visitPhiExpr(PhiExpr e)
           
 void visitPhiExprChord(PhiExprChord c)
           
 void visitSequentialChord(SequentialChord c)
           
 void visitSubscriptExpr(SubscriptExpr e)
           
 void visitSubtractionExpr(SubtractionExpr e)
           
 void visitSwitchChord(SwitchChord c)
           
 void visitTernaryExpr(TernaryExpr e)
           
 void visitTranscendental2Expr(Transcendental2Expr e)
           
 void visitTranscendentalExpr(TranscendentalExpr e)
           
 void visitUnaryExpr(UnaryExpr e)
           
 void visitVaEndExpr(VaEndExpr e)
           
 void visitValueExpr(ValueExpr e)
           
 void visitVarArgExpr(VarArgExpr e)
           
 void visitVaStartExpr(VaStartExpr e)
           
 void visitVectorExpr(VectorExpr e)
           
protected  void whatIsThis(Note n)
          Generate an error.
protected abstract  void zeroFloatRegister(int dest, int destSize)
          Generate code to zero out a floating point register.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface scale.score.Predicate
visitAbsoluteValueExpr, visitBitComplementExpr, visitCallFunctionExpr, visitCompareExpr, visitDivisionExpr, visitExponentiationExpr, visitMultiplicationExpr, visitNegativeExpr, visitNotExpr, visitRemainderExpr, visitReturnChord, visitVaArgExpr
 

Field Detail

DEBUG

public static final int DEBUG
Debug info should be generated.

See Also:
Constant Field Values

NALN

public static final int NALN
Indirect loads are not aligned.

See Also:
Constant Field Values

NIS

public static final int NIS
Inhibit instruction scheduling.

See Also:
Constant Field Values

NPH

public static final int NPH
Inhibit peephole optimization.

See Also:
Constant Field Values

ANSIC

public static final int ANSIC
Specify ANSI C.

See Also:
Constant Field Values

LINENUM

public static final int LINENUM
Generate source line information.

See Also:
Constant Field Values

classTrace

public static boolean classTrace
True if traces are to be performed.


annotateCode

public static boolean annotateCode
True if annotation comments are to be generated. Not all code generators provide annotations.


ADD

protected static final int ADD
Add operation

See Also:
commutative, Constant Field Values

SUB

protected static final int SUB
Subtract operation

See Also:
commutative, Constant Field Values

MUL

protected static final int MUL
Multiply operation

See Also:
commutative, Constant Field Values

DIV

protected static final int DIV
Divide operation

See Also:
commutative, Constant Field Values

AND

protected static final int AND
Bit and operation

See Also:
commutative, Constant Field Values

OR

protected static final int OR
Bit or operation

See Also:
commutative, Constant Field Values

XOR

protected static final int XOR
Bit exclusive or operation

See Also:
commutative, Constant Field Values

SRA

protected static final int SRA
Shift right arithmetic operation

See Also:
commutative, Constant Field Values

SRL

protected static final int SRL
Shift right logical operation

See Also:
commutative, Constant Field Values

SLL

protected static final int SLL
Shift left logical operation

See Also:
commutative, Constant Field Values

MOD

protected static final int MOD
Modulo operation

See Also:
commutative, Constant Field Values

commutative

protected static final boolean[] commutative
Is the dyadic operation commutative?


operation

protected static final java.lang.String[] operation
Map operation to string.


fieldAlignment

protected static final int[] fieldAlignment
Map from lower three bits of an offset to the alignment.


trace

protected boolean trace
True if tracing requested.


little

protected boolean little
True if target machine is little-endian.


useMemory

protected boolean useMemory
True if programmer variables should be placed in memory.


genDebugInfo

protected boolean genDebugInfo
True if information for debuggers should be generated.


naln

protected boolean naln
True if we assume indirect loads are not aligned.


nis

protected boolean nis
True if instructions should not be scheduled.


nph

protected boolean nph
True if the peephole optimizer should not be run.


ansic

protected boolean ansic
True if ANSI C source code specified.


lineNumbers

protected boolean lineNumbers
True if source line number information should be placed in the assembly code.


usesAlloca

protected boolean usesAlloca
True if the current routine uses __builtin_alloca().


usesVaStart

protected boolean usesVaStart
True if the current routine uses va_start().


callsRoutine

protected boolean callsRoutine
True if this routine calls another routine.


successorCFGNode

protected Chord successorCFGNode
The successor to the current CFG node. It's null if the last CFG node generated a branch.


currentRoutine

protected RoutineDecl currentRoutine
The declaration associated with this routine.


scribble

protected Scribble scribble
The CFG associated with this routine.


addrDisp

protected Displacement addrDisp
Last displacement generated for an address.


currentBeginMarker

protected Marker currentBeginMarker
Mark the start of the routine's code.


cg

protected CallGraph cg
The call graph being processed.


lastInstruction

protected Instruction lastInstruction
Last instruction generated.


lastLabel

protected Label lastLabel
Last label generated.


returnInst

protected Instruction returnInst
The instruction just before the one and only return instruction.


registers

protected RegisterSet registers
The register set definition.


dataAreas

protected SpaceAllocation[] dataAreas
Array of data areas - indexed by handle.


nextArea

protected int nextArea
Next available in dataAreas.


codeMap

protected HashMap<java.lang.String,SpaceAllocation> codeMap
Map from routine to instructions.


machine

protected Machine machine
Machine specific information.


un

protected UniqueName un
Generate unique names for constants in memory.


stkPtrReg

protected int stkPtrReg
The register to use to access the stack frame for the function.


readOnlyDataArea

protected int readOnlyDataArea
The data area to use to for constant data.


resultRegMode

protected ResultMode resultRegMode
The type of the resultReg value.

See Also:
ResultMode

resultReg

protected int resultReg
Register containing the last generated expression result, usually as a result of a call to visit().

It is very important that the register returned as a result of a visit NEVER be used as the destination of any instruction; It may be the register containing a variable. And, if a source register must be used in multiple instructions, the destination register must not be used for intermediate values.


resultRegAddressAlignment

protected int resultRegAddressAlignment
If resultRegMode is ResultMode.ADDRESS, this value is alignment of the address contained in the register specified by resultReg. The value 8 is used to specify the normal alignment for variables and the value 1 is used if the alignment is not known. Typical values are 8 and 4. Note - this alignment does not account for the value in resultRegAddressOffset.


resultRegAddressOffset

protected long resultRegAddressOffset
If resultRegMode is ResultMode.ADDRESS, this value is offset from the address contained in the register specified by resultReg.

See Also:
resultRegMode

resultRegSize

protected long resultRegSize
If resultRegMode is ResultMode.STRUCT_VALUE, this value is size of the struct contained in the register specified by resultReg.

See Also:
resultRegMode

predicateReg

protected int predicateReg
Register containing the current predicate. Set by generateProlog(). If predicateReg is -1, there is no predicate set.


predicatedOnTrue

protected boolean predicatedOnTrue
Indicates if an expression predicated by predicateReg is predicated on true or false.


branchPrediction

protected double branchPrediction
Probability of most recent IfThenElseChord taking the true branch.

Constructor Detail

Generator

public Generator(CallGraph cg,
                 RegisterSet registers,
                 Machine machine,
                 int features)
This class is used to convert the Scribble CFG to machine instructions.

Parameters:
cg - is the call graph to be used
registers - is the register set definition to be used
machine - specifies the target architecture
features - contains various flags that control the backend
Method Detail

avoidedLoads

public static int avoidedLoads()
Return the number of variable loads that were eliminated.


avoidedAddressCalcs

public static int avoidedAddressCalcs()
Return the number of variable address calculations that were eliminated.


regeneratedAddresses

public static int regeneratedAddresses()
Return the number of spill loads that were avoided because of regenerating the address value.


regeneratedValues

public static int regeneratedValues()
Return the number of spills were avoided because of regenerating the value.


regeneratedLiterals

public static int regeneratedLiterals()
Return the number of spills were avoided because of regenerating the literal value.


getMachine

public Machine getMachine()
Return the machine definition in use.


getCurrentRoutine

public RoutineDecl getCurrentRoutine()
Return the current routine being processed.


getRegisterSet

public RegisterSet getRegisterSet()
Return the register set definition in use.


getStackPtr

public int getStackPtr()
Return the register assignment of the stack pointer.


isFortran

public final boolean isFortran()
Return true if the source language is Fortran.


generate

public void generate()
Generate the machine instructions for each routine in the call graph.


processTypeDecl

protected void processTypeDecl(TypeDecl td,
                               boolean complete)
Called for every TypeDecl instance so that the target code generator can perform any needed processing such as making Stabs entries.


processTypeName

protected void processTypeName(TypeName td)
Called for every TypeName instance so that the target code generator can perform any needed processing such as making Stabs entries.


startModule

protected void startModule()
Called at the beginning of a call graph (module).


endModule

protected void endModule()
Called at the end of a call graph (module).


labelCfgForBackend

protected void labelCfgForBackend()
Label the basic blocks.


findLastInstruction

protected void findLastInstruction(Instruction firstInstruction)
Find the last instruction.


generateScribble

public void generateScribble()
Generate the machine instructions for a CFG.


adjustImmediates

public void adjustImmediates(Instruction firstInstruction)
Adjust large immediate values. For example, some instructions have an immediate field but the instruction limits it to a small size such as 16 bits. As a result, the instruction cannot represent large immediate values. These large values have to be split into two instructions, one for the MSBs and the other for the LSBs.


saveGeneratedCode

protected void saveGeneratedCode(Instruction first)
Save the generated code in a TEXT section using the name of the current routine.


processDecls

protected void processDecls()
Process the declarations of this CFG.


defineDeclInRegister

protected void defineDeclInRegister(Declaration decl,
                                    int register,
                                    ResultMode regha)
Associate information with a variable Declaration kept in a register.

Parameters:
decl - is the variable
register - is the register allocated for the variable
regha - is mode of the register

defineDeclOnStack

protected void defineDeclOnStack(Declaration decl,
                                 Displacement disp)
Associate information with a Declaration kept on the stack. A unique integer value is set into the declaration label. This value can be used to retrieve the information supplied.

Parameters:
decl - is the variable
disp - - displacement associated with declaration

defineDeclInMemory

protected void defineDeclInMemory(Declaration decl,
                                  Displacement disp)
Associate information with a Declaration kept in memory. A unique integer value is set into the declaration label. This value can be used to retrieve the information supplied.

Parameters:
decl - is the variable
disp - - displacement associated with declaration

defineDeclInCommon

protected void defineDeclInCommon(Declaration decl,
                                  Displacement disp)
Associate information with a Declaration in COMMON. A unique integer value is set into the declaration label. This value can be used to retrieve the information supplied.

Parameters:
decl - is the variable
disp - - displacement associated with declaration

defineRoutineInfo

protected void defineRoutineInfo(RoutineDecl rd,
                                 Displacement disp)
Associate information with a routine. A unique integer value is set into the declaration label. This value can be used to retrieve the information supplied.

Parameters:
rd - is the routine
disp - - displacement associated with declaration

calcFieldOffsets

protected void calcFieldOffsets(AggregateType at)
Determine the offsets for fields of a struct or union. This method assumes 8-bit addressable memory units.


allocateRegisters

protected int[] allocateRegisters(Instruction first,
                                  boolean trace)
Generate a mapping from virtual register to real register and then modify the instructions to use real registers.


doNext

protected boolean doNext(Chord nxt)
Make sure the specified Chord is converted next. If the Chord has already been processed, the method returns the value false.

Returns:
true if the specified Chord will be processed next

copyPropagate

protected void copyPropagate(Instruction first)
Copy-propagate register numbers from move instructions.


propagate

protected void propagate(Instruction inst,
                         int newReg,
                         int oldReg)
Perform copy propagation for the specified registers within the basic block that begins with the specified instruction.


resetForBasicBlock

protected void resetForBasicBlock()
This method is called at the end of each basic block and at the start before any CFG nodes are processed.


convertCFG

protected void convertCFG(Chord start)
Generate the instructions for the CFG node.


unconditionalBranchNeeded

protected boolean unconditionalBranchNeeded(Chord c,
                                            Chord nxt,
                                            java.lang.Object actual)
Return true if an unconditional branch is needed.

Parameters:
c - is the current node
nxt - is the successor to the current node
actual - is the actual node that will be converted to assembly next

basicBlockEnd

protected void basicBlockEnd()
Called after the last CFG node in a basic block is processed.


getBranchTarget

protected final Chord getBranchTarget(Chord s)
Skip nodes that don't result in generating instructions. Special CFG nodes do not generate code. But, we must always generate the label for the loop header.


removeUnneededInstructions

public boolean removeUnneededInstructions(Instruction first)
Remove instructions that do not change the machine state.


peepholeBeforeRegisterAllocation

protected void peepholeBeforeRegisterAllocation(Instruction first)
Do peephole optimizations before registers are allocated.


peepholeAfterRegisterAllocation

protected void peepholeAfterRegisterAllocation(Instruction first)
Do peephole optimizations after registers are allocated.


processVariableDecl

protected void processVariableDecl(VariableDecl vd,
                                   boolean topLevel)
The VariableDecl is assigned a tag. The tag can be used to retrieve information about the declaration. For a VariableDecl, the information is a Displacement, the residency of the variable (register, stack, or memory), its size in bytes, and whether it is known to be aligned.

For register-assigned variable, the virtual register is specified. For stack-assigned variables, the stack offset is assigned. (The stack offset will be adjusted later.) For memory-assigned variables, a data area is created.

Parameters:
vd - is the declaration
topLevel - is true if this declaration is defined outside of a routine

assignDeclToMemory

protected abstract void assignDeclToMemory(java.lang.String name,
                                           VariableDecl vd)
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.

See Also:
VariableDecl.getStorageLoc()

assignDeclToRegister

protected abstract void assignDeclToRegister(VariableDecl vd)
Assign the specified variable to a register. The decision to place this variable in a register has already been made.

See Also:
VariableDecl.getStorageLoc()

assignDeclToStack

protected abstract void assignDeclToStack(VariableDecl vd)
Assign the specified variable to a location in the stack frame. The decision to place this variable on the stack has already been made.

See Also:
VariableDecl.getStorageLoc()

processRoutineDecl

protected abstract void processRoutineDecl(RoutineDecl rd,
                                           boolean topLevel)
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.

Parameters:
rd - is the declaration
topLevel - is true if this declaration is defined outside of a routine

getSpillLocation

public abstract java.lang.Object getSpillLocation(int reg)
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().

Parameters:
reg - specifies which virtual register will be spilled

insertSpillLoad

public abstract Instruction insertSpillLoad(int reg,
                                            java.lang.Object spillLocation,
                                            Instruction after)
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.

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:
getSpillLocation(int)

insertSpillStore

public abstract Instruction insertSpillStore(int reg,
                                             java.lang.Object spillLocation,
                                             Instruction after)
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.

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:
getSpillLocation(int)

returnRegister

public abstract int returnRegister(int regType,
                                   boolean isCall)
Return the register used to return the function value.

Parameters:
regType - specifies the type of value
isCall - is true if the calling routine is asking

getFirstArgRegister

public abstract int getFirstArgRegister(int regType)
Return the register used as the first argument in a function call.

Parameters:
regType - specifies the type of argument value

shouldBeRegenerated

protected boolean shouldBeRegenerated(int reg)
Return true if the value in the register can be easily regenerated. The value can be easily regenerated if it is just the load of a variable or constant value that is kept in memory. We know that the value in the register is the same as the value in memory at any point in the program because new values of variables, that are stored in memory, are always stored into memory. We also know that this mapping is never used for variables kept in registers.


regenerateRegister

protected Instruction regenerateRegister(int reg,
                                         Instruction after)
Regenerate a register value instead of performing a spill load.


generateConditionalBranch

public void generateConditionalBranch(int which,
                                      int treg,
                                      Label l)
Generate a predicated branch to a single location. This is only relevant when hyperblocks are enabled.

Parameters:
which - specifies the branch test (EQ, NE, LT, ...)
treg - specifies the condition to test
l - is the label to branch to.

assemble

public abstract void assemble(Emit emit,
                              java.lang.String source,
                              java.util.Enumeration<java.lang.String> comments)
Generate assembly language.

Parameters:
emit - is the stream to use.
source - is the source file name
comments - is a list of Strings containing comments

generateUnconditionalBranch

protected abstract void generateUnconditionalBranch(Label lab)
Generate an unconditional branch to the label specified.


processSourceLine

protected abstract void processSourceLine(int line,
                                          Label label,
                                          boolean newLine)
The user has requested source line information be included.

Parameters:
line - is the current line number
label - is the last label encountered or null
newLine - is true if a new source line with no label

startRoutineCode

protected abstract Instruction startRoutineCode()
Called at the start of code generation for a routine.


endRoutineCode

protected abstract void endRoutineCode(int[] regMap)
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.


layoutParameters

protected abstract void layoutParameters()
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.


generateProlog

protected abstract void generateProlog(ProcedureType pt)
This method is responsible for generating instructions to move function arguments to the position assigned by the layoutParameters method.


storeLfae

protected abstract void storeLfae(LoadFieldAddressExpr lhs,
                                  Expr rhs)
Store a value into a field of a structure.

Parameters:
lhs - specifies the field of the structure
rhs - specifies the value

loadVariableFromStack

protected void loadVariableFromStack(Displacement vdisp,
                                     Type vt)
Load the value of a variable on the stack into a register. Return the register into which the variable value is loaded in resultReg.

Parameters:
vdisp - is the variable displacement
vt - specifies the type of the value

loadVariableFromCommon

protected void loadVariableFromCommon(int adr,
                                      Type vt,
                                      long offset)
Load the value of a variable in COMMON into a register. Return the register into which the variable value is loaded in resultReg.

Parameters:
adr - specifies the base address
vt - specifies the type of the value
offset - is the offset of the variable from the base of common

loadVariableFromMemory

protected void loadVariableFromMemory(Displacement vdisp,
                                      Type vt)
Load the value of a variable in memory into a register. Return the register into which the variable value is loaded in resultReg.

Parameters:
vdisp - is the variable displacement
vt - specifies the type of the value

loadRegFromSymbolicLocation

protected abstract void loadRegFromSymbolicLocation(int dest,
                                                    int dsize,
                                                    boolean isSigned,
                                                    boolean isReal,
                                                    Displacement disp)
Load a register from a symbolic location in memory.

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

loadFromMemoryWithOffset

protected abstract 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.

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 abstract 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. The offset must not be symbolic.

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

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

loadArrayElement

protected abstract void loadArrayElement(ArrayIndexExpr aie,
                                         int dest)
Load an array element into a register.

Parameters:
aie - specifies the array element
dest - specifies the register

storeIntoMemoryWithOffset

protected abstract 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.

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 abstract 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. The offset must not be symbolic.

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

storeRegToSymbolicLocation

protected abstract void storeRegToSymbolicLocation(int src,
                                                   int dsize,
                                                   long alignment,
                                                   boolean isReal,
                                                   Displacement disp)
Store a value in a register to a symbolic location in memory.

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

storeIntoMemory

protected abstract 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.

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

putAddressInRegister

protected void putAddressInRegister(Declaration decl,
                                    boolean isPredicated)
Load the address of a declaration into a register. The register is specified in resultReg. The resultRegAddressOffset value is always 0. The resultRegMode value is always ResultMode.NORMAL_VALUE.

Parameters:
decl - specifies the declaration
isPredicated - is true if this sequence of instructions will be predicated

putAddressInRegisterNO

protected void putAddressInRegisterNO(Declaration decl,
                                      boolean isPredicated)
Load the address of a declaration into a register and place any offset into resultRegAddressOffset. The register is specified in resultReg. The resultRegMode value is always ResultMode.NORMAL_VALUE.

Parameters:
decl - specifies the declaration
isPredicated - is true if this sequence of instructions will be predicated

specifyInReg

protected void specifyInReg(Declaration decl,
                            int reg,
                            ResultMode regha)
Specify that the value of a variable kept in memory is now in a register.


isAssignedRegister

protected boolean isAssignedRegister(int reg)
Return true if the register is assigned to a variable.


calcAddressAndOffset

protected void calcAddressAndOffset(Expr exp,
                                    long offset)
Load the address generated by an expression into a register. Return the offset from the address in resultRegAddressOffset and the address is in resultReg.

Parameters:
exp - specifies the expression
offset - is the offset from the address

calcArrayElementAddress

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

Parameters:
aie - specifies the array elementxpression
offset - is the offset from the address

putAddressInRegister

protected void putAddressInRegister(Expr expr)
Place the address of the argument in a register. The result register is in resultReg. The resultRegAddressOffset value is always 0. The resultRegMode value is always false. Return the register containing the address in resultReg.


allocStackAddress

protected abstract int allocStackAddress(int adrReg,
                                         Type type)
Allocate a location on the stack for storing a value of the specified size. Put the address of the location in the register.

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

defStringValue

protected abstract Displacement defStringValue(java.lang.String v,
                                               int size)
Return the displacement for a string.

Parameters:
v - is the string
size - is the length of the string

loadMemoryAddress

protected abstract int loadMemoryAddress(Displacement disp)
Load an address of a memory location into a register.

Parameters:
disp - specifies the address (should be a SymbolDisplacement or offset of one)
Returns:
the register that is set with the address

loadStackAddress

protected abstract int loadStackAddress(Displacement disp)
Load an address of a stack location into a register.

Parameters:
disp - specifies the address (should be a SymbolDisplacement or offset of one)
Returns:
the register that is set with the address

genLoadImmediate

protected abstract int genLoadImmediate(long value,
                                        int dest)
Generate instructions to load an immediate integer value into a register.

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)

genLoadHighImmediate

protected abstract long genLoadHighImmediate(long value,
                                             int base)
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.

Parameters:
value - is the value to add to the base address
base - is the base address
Returns:
the lower 16 bits of the constant

genLoadDblImmediate

protected abstract int genLoadDblImmediate(double value,
                                           int dest,
                                           int destSize)
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.

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)

dataType

public abstract int dataType(int size,
                             boolean flt)
Return the data type as an integer.

Parameters:
size - is the size in memory units
flt - is true for floating point values
See Also:
SpaceAllocation

genRegToReg

protected abstract void genRegToReg(int src,
                                    int dest)
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.

Parameters:
src - specifies the source register
dest - specifies the destination register

addRegs

protected abstract void addRegs(int laReg,
                                int raReg,
                                int dest)
Generate an add of address registers laReg and raReg.


moveWords

protected abstract 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.

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 abstract 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. The destination offset must not be symbolic.

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

genIfRegister

protected abstract 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. The value may be floating point or integer but it is never a value pair.

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

genLoadImmediate

protected abstract 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.

Parameters:
value - is the value to load
base - is the base register (e.g., AlphaRegisterSet.I0_REG)
dest - is the register conatining the result

genIfRelational

protected abstract void genIfRelational(boolean rflag,
                                        MatchExpr predicate,
                                        Chord tc,
                                        Chord fc)
Generate a branch based on a relational expression.

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

genFtnCall

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

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

callArgs

protected abstract short[] callArgs(Expr[] args,
                                    boolean specialFirstArg)
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.

Parameters:
args - is the set of arguments
specialFirstArg - is true if the first argument register is reserved
Returns:
the set of registers used for the argument values

doBinaryOp

protected void doBinaryOp(BinaryExpr c,
                          int which)
Generate instructions to do a binary operation on two values.

Parameters:
c - is the binary expression
which - specifies the binary operation (ADD, SUB, ...)

doBinaryOp

protected abstract void doBinaryOp(int which,
                                   Type ct,
                                   Expr la,
                                   Expr ra,
                                   int dest)
Generate instructions to do a binary operation on two values.

Parameters:
which - specifies the binary operation (ADD, SUB, ...)
ct - is the result type
la - is the left argument
ra - is the right argument
dest - is the destination register

doCompareOp

protected abstract void doCompareOp(BinaryExpr c,
                                    CompareMode which)
Generate instructions to do a comparison of two values.

Parameters:
c - is the compare expression
which - specifies the compare (EQ, NE, ...)

getMaxAreaIndex

public abstract int getMaxAreaIndex()
Return the maximum area index value.


getDisp

protected final IntegerDisplacement getDisp(int value)
Generate an integer displacement. Reuse an exisiting one if possible.

Parameters:
value - specifies the value of the displacement
Returns:
the displacement

processType

protected Type processType(Type type)
Insure that all types have their register types specified and all structure fields have had their offsets determined. The tag field of the Type is set to the register type required to hold an element of that type (or its address).

Returns:
the core type

processType

protected Type processType(Declaration decl)
Insure that all types have their register types specified and all structure fields have had their offsets determined. The tag field of the Type is set to the register type required to hold an element of that type (or its address).

Returns:
the core type

processType

protected Type processType(Expr expr)
Insure that all types have their register types specified and all structure fields have had their offsets determined. The tag field of the Type is set to the register type required to hold an element of that type (or its address).

Returns:
the core type

processType

protected Type processType(Expression expr)
Insure that all types have their register types specified and all structure fields have had their offsets determined. The tag field of the Type is set to the register type required to hold an element of that type (or its address).

Returns:
the core type

appendInstruction

protected void appendInstruction(Instruction inst)
Append the instruction to the end of the sequence of instructions.


appendCallInstruction

protected void appendCallInstruction(Branch call,
                                     Label lab,
                                     short[] uses,
                                     short[] kills,
                                     short[] defs,
                                     boolean genLabel)
Append the subroutine call instruction to the end of the sequence of instructions.

Parameters:
call - is the call instruction
lab - is the label of the call return point
uses - specifies what registers are used by the call
kills - specifies what registers are killed by the call
defs - specifies what registers are defined by the call
genLabel - if the return label should be appended

appendLabel

protected void appendLabel(Label label)
Append the label to the end of the sequence of instructions. Record the last Label appended.


insertInstruction

protected Instruction insertInstruction(Instruction inst,
                                        Instruction location)
Insert the instruction after the specified instruction.

Returns:
the instruction inserted

insertLabel

protected Instruction insertLabel(Label label,
                                  Instruction location)
Insert the label after the specified instruction.

Returns:
the instruction inserted

updateLabelIndex

public void updateLabelIndex(Label label)
Update the unique identifier for a label.


moveInstructionSequence

protected void moveInstructionSequence(Instruction prior,
                                       Instruction last,
                                       Instruction after)
Move a sequence of instructions to another position. If the position (after) is null, the instructions are deleted

Parameters:
prior - is the instruction prior to the first instruction in the sequence
last - is the last instruction in the sequence
after - is the instruction to insert the sequence after

createNewLabel

protected Label createNewLabel()
Allocate a machine-specific label. This method should be called only by scale.backend.Generator.


createLabel

public final Label createLabel()
Create a new Label and return it.


newLabel

public final int newLabel()
Create a new Label and return its index.


getLabel

public final Label getLabel(int index)
Return the label whose index is specified.


getBranchLabel

protected final Label getBranchLabel(Chord location)
Return the label for a branch location.


getSpaceAllocation

public final SpaceAllocation getSpaceAllocation(int handle)
Return the SpaceAllocation associated with the specified handle.


findAreaDisp

public final Displacement findAreaDisp(int section,
                                       int type,
                                       boolean readOnly,
                                       long size,
                                       double value,
                                       int alignment)
Find an allocation of a floating point value. Return the Displacement or null if not found.

Parameters:
section - specifies the section in which the loader should place the area
type - specifies the type of data
readOnly - is true if the area is read-only
size - is the number of addressable units required
value - is the initial data value for the area
alignment - specifies the address alignment required
Returns:
the index of the area
See Also:
SpaceAllocation

findAreaDisp

public final Displacement findAreaDisp(int section,
                                       int type,
                                       boolean readOnly,
                                       long size,
                                       long value,
                                       int alignment)
Find an allocation of a long value. Return the Displacement or null if not found.

Parameters:
section - specifies the section in which the loader should place the area
type - specifies the type of data
readOnly - is true if the area is read-only
size - is the number of addressable units required
value - is the initial data value for the area
alignment - specifies the address alignment required
Returns:
the index of the area
See Also:
SpaceAllocation

findAreaDisp

public final Displacement findAreaDisp(int section,
                                       int type,
                                       boolean readOnly,
                                       long size,
                                       java.lang.String value,
                                       int alignment)
Find an allocation of a String value. Return the Displacement or null if not found.

Parameters:
section - specifies the section in which the loader should place the area
type - specifies the type of data
readOnly - is true if the area is read-only
size - is the number of addressable units required
value - is the initial data value for the area
alignment - specifies the address alignment required
Returns:
the index of the area
See Also:
SpaceAllocation

associateDispWithArea

public final void associateDispWithArea(int handle,
                                        Displacement disp)
Associate a displacement with an area.


valueOf

protected long valueOf(SizeofLiteral il)
Return the value of the SizeofLiteral.


allocateWithData

protected final int allocateWithData(java.lang.String name,
                                     Type type,
                                     long ts,
                                     Expression init,
                                     int area,
                                     boolean readOnly,
                                     int reps,
                                     int aln)
Allocate an area for the data specified by the Clef Expression.

Parameters:
name - is the name of the data
type - is the type of the variable
ts - is the size of the area to allocate
init - is the initial value
area - is the data area to use
readOnly - is true if the data should be read-only
reps - is the number os times to repeat the data to fill the area
aln - is the required alignment for the data
Returns:
data area handle

getSAType

public int getSAType(Type type)
Return the SpaceAllocation type for the specified Type.


allocateData

protected final int allocateData(java.lang.String name,
                                 int section,
                                 int type,
                                 long size,
                                 boolean readOnly,
                                 java.lang.Object value,
                                 int reps,
                                 int alignment)
Return the handle of a new memory area.

Parameters:
name - is the name of the area (variable, routine, etc) or null
section - specifies the section in which the loader should place the area
type - specifies the type of data
size - is the number of addressable units required
readOnly - is true if the area is read-only
value - is the initial data value for the area
reps - is the number of times the value must be replicated
alignment - specifies the address alignment required
See Also:
SpaceAllocation

allocateTextArea

public final int allocateTextArea(java.lang.String name,
                                  int area)
Return the handle of a new area of memory to contain instructions.


getName

public final java.lang.String getName(int handle)
Return the name associated with an area of memory.


getSourceLanguage

public final SourceLanguage getSourceLanguage()
Return the source language of the original program.


getCallGraph

public final CallGraph getCallGraph()
Return the call graph associated with this invocation of the code generator.


whatIsThis

protected void whatIsThis(Note n)
Generate an error.


needValue

protected final void needValue(Expr exp)
Process the expression and if the result is an address value, add any offset required to the base address. The result is in resultReg, et al.


needValue

protected final void needValue(int src,
                               long srcoff,
                               ResultMode srcha)
If the register contains an address value, add any offset required to the base address. The result is in resultReg, et al.


loadVariable

protected void loadVariable(VariableDecl vd,
                            Type vt,
                            boolean isPredicated)
Load the value of a variable into a register. Return the register into which the variable value is loaded in resultReg. If the value can not be loaded into a register, return the 2's complement of the register containing the address of the data.

Parameters:
vd - specifies the variable
vt - specifies the type of the value

isSimple

public boolean isSimple(Expr arg)
Return true if the expression will not result in a call to a routine.


visitLoadDeclAddressExpr

public void visitLoadDeclAddressExpr(LoadDeclAddressExpr e)
Specified by:
visitLoadDeclAddressExpr in interface Predicate

loadDeclValue

protected void loadDeclValue(Declaration decl,
                             Type vt,
                             boolean isPredicated)
Load the value of a declaration into a register.


visitLoadValueIndirectExpr

public void visitLoadValueIndirectExpr(LoadValueIndirectExpr lvie)
Specified by:
visitLoadValueIndirectExpr in interface Predicate

visitLoadDeclValueExpr

public void visitLoadDeclValueExpr(LoadDeclValueExpr e)
Specified by:
visitLoadDeclValueExpr in interface Predicate

visitLoadFieldAddressExpr

public void visitLoadFieldAddressExpr(LoadFieldAddressExpr e)
Specified by:
visitLoadFieldAddressExpr in interface Predicate

visitLoadFieldValueExpr

public void visitLoadFieldValueExpr(LoadFieldValueExpr e)
Specified by:
visitLoadFieldValueExpr in interface Predicate

loadFieldValue

protected abstract 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.

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

calcFieldAddress

protected void calcFieldAddress(LoadFieldAddressExpr c,
                                long offset)
Calculate the offset and base address of a field. The base address is returned in a register that is specified by the resultReg member. Return the offset from the address in resultRegAddressOffset. The address is specified in resultReg.

Parameters:
offset - is the initial offset (normally 0)

visitArrayIndexExpr

public void visitArrayIndexExpr(ArrayIndexExpr e)
Specified by:
visitArrayIndexExpr in interface Predicate

visitBeginChord

public void visitBeginChord(BeginChord c)
Specified by:
visitBeginChord in interface Predicate

visitExitChord

public void visitExitChord(ExitChord c)
Specified by:
visitExitChord in interface Predicate

genSingleUse

protected abstract short[] genSingleUse(int reg)
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.


genDoubleUse

protected abstract short[] genDoubleUse(int reg1,
                                        int reg2)
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.


visitExprChord

public void visitExprChord(ExprChord c)
Specified by:
visitExprChord in interface Predicate

doStore

protected void doStore(Expr lhs,
                       Expr rhs,
                       boolean vaCopy)
Generate code for a copy (i.e., assignment).


doVaCopy

protected void doVaCopy(Expr lhs,
                        Expr rhs)
Generate code for a va_copy().


visitIfThenElseChord

public void visitIfThenElseChord(IfThenElseChord c)
Specified by:
visitIfThenElseChord in interface Predicate

visitSwitchChord

public void visitSwitchChord(SwitchChord c)
Specified by:
visitSwitchChord in interface Predicate

genSwitchUsingIfs

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

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 abstract void genSwitchUsingTransferVector(int testReg,
                                                     Chord[] cases,
                                                     long[] keys,
                                                     Label dflt,
                                                     long min,
                                                     long max)
Generate the code for a switch statement using branches for each case.

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
dflt - is the label for the default case
min - is the smallest case value
max - is the largest case value

genTrueFalseBranch

protected void genTrueFalseBranch(int predicate,
                                  Chord tc,
                                  Chord fc)
Generate a branch based on the value of an expression which is guaranteed to be either 0 or 1.

Parameters:
predicate - specifies the register to test
tc - specifies the path if the test succeeds
fc - specifies the path if the test fails

genIfRegister

protected void genIfRegister(CompareMode which,
                             Expr predicate,
                             Chord tc,
                             Chord fc)
Generate a branch based on the value of an expression compared to zero.

Parameters:
which - specifies the branch test (EQ, NE, LT, ...)
predicate - specifies the condition to test
tc - specifies the path if the test succeeds
fc - specifies the path if the test fails

genIfRegister

protected void genIfRegister(CompareMode which,
                             int treg,
                             boolean signed,
                             Chord tc,
                             Chord fc)
Generate a branch based on the value of an expression compared to zero.

Parameters:
which - specifies the branch test (EQ, NE, LT, ...)
treg - specifies the condition (register value) to test
signed - is true if the value is signed
tc - specifies the path if the test succeeds
fc - specifies the path if the test fails

visitAdditionExpr

public void visitAdditionExpr(AdditionExpr e)
Specified by:
visitAdditionExpr in interface Predicate

visitAndExpr

public void visitAndExpr(AndExpr e)
Specified by:
visitAndExpr in interface Predicate

visitBitAndExpr

public void visitBitAndExpr(BitAndExpr e)
Specified by:
visitBitAndExpr in interface Predicate

visitBitOrExpr

public void visitBitOrExpr(BitOrExpr e)
Specified by:
visitBitOrExpr in interface Predicate

visitBitXorExpr

public void visitBitXorExpr(BitXorExpr e)
Specified by:
visitBitXorExpr in interface Predicate

visitOrExpr

public void visitOrExpr(OrExpr e)
Specified by:
visitOrExpr in interface Predicate

visitSubtractionExpr

public void visitSubtractionExpr(SubtractionExpr e)
Specified by:
visitSubtractionExpr in interface Predicate

visitBitShiftExpr

public void visitBitShiftExpr(BitShiftExpr e)
Specified by:
visitBitShiftExpr in interface Predicate

genAtan2Ftn

protected abstract void genAtan2Ftn(int dest,
                                    int laReg,
                                    int raReg,
                                    Type rType)
Generate the code for the Fortran ATAN2() intrinsic function.


genSignFtn

protected abstract void genSignFtn(int dest,
                                   int laReg,
                                   int raReg,
                                   Type rType)
Generate the code for the Fortran SIGN() intrinsic function.


genDimFtn

protected abstract void genDimFtn(int dest,
                                  int laReg,
                                  int raReg,
                                  Type rType)
Generate the code for the Fortran DIM() intrinsic function.


genSqrtFtn

protected abstract void genSqrtFtn(int dest,
                                   int src,
                                   Type type)
Generate the code for the sqrt() function.


genAlloca

protected abstract void genAlloca(Expr arg,
                                  int reg)
Generate the code for the alloca() function.


genExpFtn

protected abstract void genExpFtn(int dest,
                                  int src,
                                  Type type)
Generate the code for the exp() function.


genLogFtn

protected abstract void genLogFtn(int dest,
                                  int src,
                                  Type type)
Generate the code for the log() function.


genLog10Ftn

protected abstract void genLog10Ftn(int dest,
                                    int src,
                                    Type type)
Generate the code for the log10() function.


genSinFtn

protected abstract void genSinFtn(int dest,
                                  int src,
                                  Type type)
Generate the code for the sin() function.


genCosFtn

protected abstract void genCosFtn(int dest,
                                  int src,
                                  Type type)
Generate the code for the cos() function.


genTanFtn

protected abstract void genTanFtn(int dest,
                                  int src,
                                  Type type)
Generate the code for the tan() function.


genAsinFtn

protected abstract void genAsinFtn(int dest,
                                   int src,
                                   Type type)
Generate the code for the asin() function.


genAcosFtn

protected abstract void genAcosFtn(int dest,
                                   int src,
                                   Type type)
Generate the code for the acos() function.


genAtanFtn

protected abstract void genAtanFtn(int dest,
                                   int src,
                                   Type type)
Generate the code for the atan() function.


genSinhFtn

protected abstract void genSinhFtn(int dest,
                                   int src,
                                   Type type)
Generate the code for the sinh() function.


genCoshFtn

protected abstract void genCoshFtn(int dest,
                                   int src,
                                   Type type)
Generate the code for the cosh() function.


genTanhFtn

protected abstract void genTanhFtn(int dest,
                                   int src,
                                   Type type)
Generate the code for the tanh() function.


genConjgFtn

protected abstract void genConjgFtn(int dest,
                                    int src,
                                    Type type)
Generate the code for the conjg() function.


genReturnAddressFtn

protected abstract void genReturnAddressFtn(int dest,
                                            int src,
                                            Type type)
Generate the code for the builtin_return_address() function.


genFrameAddressFtn

protected abstract void genFrameAddressFtn(int dest,
                                           int src,
                                           Type type)
Generate the code for the builtin_fram_address() function.


visitTranscendentalExpr

public void visitTranscendentalExpr(TranscendentalExpr e)
Specified by:
visitTranscendentalExpr in interface Predicate

visitTranscendental2Expr

public void visitTranscendental2Expr(Transcendental2Expr e)
Specified by:
visitTranscendental2Expr in interface Predicate

visitCallMethodExpr

public void visitCallMethodExpr(CallMethodExpr e)
Specified by:
visitCallMethodExpr in interface Predicate

visitComplexValueExpr

public void visitComplexValueExpr(ComplexValueExpr e)
Specified by:
visitComplexValueExpr in interface Predicate

convertIntRegValue

protected abstract 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. 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.

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

genRealToInt

protected abstract 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. The result is rounded down.

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


genIntToReal

protected abstract 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.

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

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

genRealToIntRound

protected abstract 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. The result is rounded to the nearest integer.


genRoundReal

protected abstract 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. The result is rounded to the nearest integer.


genFloorOfReal

protected abstract 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.


zeroFloatRegister

protected abstract void zeroFloatRegister(int dest,
                                          int destSize)
Generate code to zero out a floating point register.


visitConversionExpr

public void visitConversionExpr(ConversionExpr e)
Specified by:
visitConversionExpr in interface Predicate

visitDualExpr

public void visitDualExpr(DualExpr e)
Specified by:
visitDualExpr in interface Predicate

visitEqualityExpr

public void visitEqualityExpr(EqualityExpr e)
Specified by:
visitEqualityExpr in interface Predicate

visitGreaterEqualExpr

public void visitGreaterEqualExpr(GreaterEqualExpr e)
Specified by:
visitGreaterEqualExpr in interface Predicate

visitGreaterExpr

public void visitGreaterExpr(GreaterExpr e)
Specified by:
visitGreaterExpr in interface Predicate

visitLessEqualExpr

public void visitLessEqualExpr(LessEqualExpr e)
Specified by:
visitLessEqualExpr in interface Predicate

visitLessExpr

public void visitLessExpr(LessExpr e)
Specified by:
visitLessExpr in interface Predicate

visitNotEqualExpr

public void visitNotEqualExpr(NotEqualExpr e)
Specified by:
visitNotEqualExpr in interface Predicate

visitLiteralExpr

public void visitLiteralExpr(LiteralExpr e)
Specified by:
visitLiteralExpr in interface Predicate

visitNilExpr

public void visitNilExpr(NilExpr e)
Specified by:
visitNilExpr in interface Predicate

storeLiteral

protected void storeLiteral(LiteralExpr le,
                            Expr rhs)
Store a value into the location specied by a literal value.

Parameters:
le - specifies the literal
rhs - specifies the value

storeLdve

protected void storeLdve(LoadDeclValueExpr lhs,
                         Expr rhs)
Store a value into the location specied by an address in a variable.

Parameters:
lhs - specifies the variable
rhs - specifies the value

storeLvie

protected void storeLvie(LoadValueIndirectExpr lhs,
                         Expr rhs)
Store a value into the location specied by the value of an expression.

Parameters:
lhs - specifies the expression
rhs - specifies the value

storeLdae

protected void storeLdae(LoadDeclAddressExpr lhs,
                         Expr rhs)
Store a value into a variable.

Parameters:
lhs - specifies the variable
rhs - specifies the value

visitVaStartExpr

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

visitAllocateExpr

public void visitAllocateExpr(AllocateExpr e)
Specified by:
visitAllocateExpr in interface Predicate

visitBinaryExpr

public void visitBinaryExpr(BinaryExpr e)

visitBranchChord

public void visitBranchChord(BranchChord c)

visitCallExpr

public void visitCallExpr(CallExpr e)

visitChord

public void visitChord(Chord c)

visitDecisionChord

public void visitDecisionChord(DecisionChord c)

visitExpr

public void visitExpr(Expr e)

visitExprPhiExpr

public void visitExprPhiExpr(ExprPhiExpr e)
Specified by:
visitExprPhiExpr in interface Predicate

visitLoadExpr

public void visitLoadExpr(LoadExpr e)

visitMaxExpr

public void visitMaxExpr(MaxExpr e)
Specified by:
visitMaxExpr in interface Predicate

visitMinExpr

public void visitMinExpr(MinExpr e)
Specified by:
visitMinExpr in interface Predicate

visitNaryExpr

public void visitNaryExpr(NaryExpr e)

visitNote

public void visitNote(Note n)

visitMarkerChord

public void visitMarkerChord(MarkerChord c)
Specified by:
visitMarkerChord in interface Predicate

visitGotoChord

public void visitGotoChord(GotoChord c)
Specified by:
visitGotoChord in interface Predicate

visitLoopExitChord

public void visitLoopExitChord(LoopExitChord c)
Specified by:
visitLoopExitChord in interface Predicate

visitLoopHeaderChord

public void visitLoopHeaderChord(LoopHeaderChord c)
Specified by:
visitLoopHeaderChord in interface Predicate

visitLoopPreHeaderChord

public void visitLoopPreHeaderChord(LoopPreHeaderChord c)
Specified by:
visitLoopPreHeaderChord in interface Predicate

visitLoopTailChord

public void visitLoopTailChord(LoopTailChord c)
Specified by:
visitLoopTailChord in interface Predicate

visitLoopInitChord

public void visitLoopInitChord(LoopInitChord c)
Specified by:
visitLoopInitChord in interface Predicate

visitNullChord

public void visitNullChord(NullChord c)
Specified by:
visitNullChord in interface Predicate

visitPhiExpr

public void visitPhiExpr(PhiExpr e)
Specified by:
visitPhiExpr in interface Predicate

visitPhiExprChord

public void visitPhiExprChord(PhiExprChord c)
Specified by:
visitPhiExprChord in interface Predicate

visitSequentialChord

public void visitSequentialChord(SequentialChord c)

visitEndChord

public void visitEndChord(EndChord c)
Specified by:
visitEndChord in interface Predicate

visitLeaveChord

public void visitLeaveChord(LeaveChord c)

visitSubscriptExpr

public void visitSubscriptExpr(SubscriptExpr e)
Specified by:
visitSubscriptExpr in interface Predicate

visitTernaryExpr

public void visitTernaryExpr(TernaryExpr e)

visitUnaryExpr

public void visitUnaryExpr(UnaryExpr e)

visitValueExpr

public void visitValueExpr(ValueExpr e)

visitVarArgExpr

public void visitVarArgExpr(VarArgExpr e)

visitVaEndExpr

public void visitVaEndExpr(VaEndExpr e)
Specified by:
visitVaEndExpr in interface Predicate

visitVectorExpr

public void visitVectorExpr(VectorExpr e)
Specified by:
visitVectorExpr in interface Predicate

visitConditionalExpr

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