harpoon.Backend.Generic
Class Code

java.lang.Object
  extended by harpoon.ClassFile.HCode<Instr>
      extended by harpoon.IR.Assem.Code
          extended by harpoon.Backend.Generic.Code
All Implemented Interfaces:
Graph<Instr,InstrEdge>

public abstract class Code
extends Code

Generic.Code is an abstract superclass of codeviews which use Instrs.

Version:
$Id: Code.java,v 1.5 2002/04/10 03:02:42 cananian Exp $
Author:
Andrew Berkheimer <andyb@mit.edu>

Nested Class Summary
 
Nested classes/interfaces inherited from class harpoon.ClassFile.HCode
HCode.PrintCallback<HCE extends HCodeElement>
 
Nested classes/interfaces inherited from interface harpoon.Util.Collections.Graph
Graph.Edge<N extends Graph.Node<N,E>,E extends Graph.Edge<N,E>>, Graph.Node<N extends Graph.Node<N,E>,E extends Graph.Edge<N,E>>
 
Field Summary
static boolean PEEPHOLE_OPTIMIZATIONS
           
 
Fields inherited from class harpoon.IR.Assem.Code
frame, inf, instrs, parent
 
Constructor Summary
protected Code(Code treeCode)
           
protected Code(Code code, Instr i, Derivation d, String codeName)
          Generates a new Generic.Code from another Generic.Code, code, with i as the root instruction (instead of whatever root was used in code, and codeName as the value that would be returned by a call getName().
 
Method Summary
abstract  void assignRegister(Instr i, Temp pseudoReg, List regs)
          Assigns a register to a Temp in i.
 Derivation getDerivation()
          Returns the Derivation associated with this.
abstract  String getName()
          Return the name of this code view.
abstract  List getRegisters(Instr i, Temp val)
          Returns all of the Register Temps that val maps to in i.
 boolean isSafeToRemove(Instr instr)
          Returns false if instr cannot be safely deleted.
 void printPreallocatedCode()
           
 void printPreallocatedCode(HCode.PrintCallback callback)
           
abstract  boolean registerAssigned(Instr i, Temp pseudoReg)
          Checks if pseudoReg has been assigned to some registers in i.
 void removeAssignment(Instr i, Temp pseudoReg)
           
 String toAssem(Instr instr)
          Overrides superclass implementation of toAssem to return an empty string if instr can be safely eliminated from output.
 
Methods inherited from class harpoon.IR.Assem.Code
elementArrayFactory, formatCommentedInstr, getElementsI, getFrame, getInstrFactory, getLeafElements, getMethod, getRegisterName, getRootElement, myPrint, myPrint, myPrint, nodes, print, print
 
Methods inherited from class harpoon.ClassFile.HCode
clone, clone, elementIndexer, getElements, getElementsL, print, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PEEPHOLE_OPTIMIZATIONS

public static boolean PEEPHOLE_OPTIMIZATIONS
Constructor Detail

Code

protected Code(Code code,
               Instr i,
               Derivation d,
               String codeName)
Generates a new Generic.Code from another Generic.Code, code, with i as the root instruction (instead of whatever root was used in code, and codeName as the value that would be returned by a call getName(). (the codeName argument is a hack to get around a dependency problem in the constructor for Assem.Code.


Code

protected Code(Code treeCode)
Method Detail

printPreallocatedCode

public void printPreallocatedCode()

printPreallocatedCode

public void printPreallocatedCode(HCode.PrintCallback callback)

getDerivation

public Derivation getDerivation()
Description copied from class: Code
Returns the Derivation associated with this. Returns null if Derivation information is not available.

Overrides:
getDerivation in class Code

isSafeToRemove

public boolean isSafeToRemove(Instr instr)
Returns false if instr cannot be safely deleted.
effects: If it is safe to remove instr from this stream of instructions without changing the semantic meaning of the program, then this might return true. Otherwise, returns false.


toAssem

public String toAssem(Instr instr)
Overrides superclass implementation of toAssem to return an empty string if instr can be safely eliminated from output.

Overrides:
toAssem in class Code

getName

public abstract String getName()
Description copied from class: HCode
Return the name of this code view. The default bytecode view is named "bytecode". It is suggested that additional views be named in a similarly human-friendly fashion.

Specified by:
getName in class HCode<Instr>

getRegisters

public abstract List getRegisters(Instr i,
                                  Temp val)
Returns all of the Register Temps that val maps to in i.
requires:
  1. val must be a Temp that is an element of i.defC() or i.useC()
  2. (val is not Register for this architecture) => registerAssigned(i, val) is true
    effects: Returns a Collection of the Register Temps that are assigned to val in i. Every member of the Collection returned will be a valid Register for this architecture.


assignRegister

public abstract void assignRegister(Instr i,
                                    Temp pseudoReg,
                                    List regs)
Assigns a register to a Temp in i.
modifies: i (FSK: potentially at least)
effects: creates a mapping
NOTE: This is only an experimental method; only FSK should be using it until he makes sure that it implies no design flaws.

FSK: Flaw 1 -- if there are multiple references to pseudoReg in i, like a := a + 1, then this method is too general; it does not allow us to put a's def in a different register from its use. Now, since we're using SSI form at a high level, I don't know if we'll ever encounter code like that (depends on how Tree->Instr form is performed), but
(1.) I don't like relying on SSI to catch undocumented problems like this implicitly,
(2.) we could, in theory, try to use this backend with a non-SSI front end
The other issue here is I don't know when allowing the flexibility of having different registers for a's def and use will buy us anything... UPDATE: it does buy us something: since it allows for smaller webs w/o move instructions. we can get around this problem relatively cheaply by maintaining not just a Instr x Temp -> List<Reg> mapping, but instead two mappings: Instr x Use -> List<Reg> Instr x Def -> List<Reg>. i will implement this after preliminary Global Register Allocation is working.


registerAssigned

public abstract boolean registerAssigned(Instr i,
                                         Temp pseudoReg)
Checks if pseudoReg has been assigned to some registers in i.
requires: val must be a Temp that is an element of i.defC() or i.useC()
effects: If pseudoReg has been assigned to some List of registers in i and removeAssignment(i, pseudoReg) has not been called since, returns true. Else returns false.


removeAssignment

public void removeAssignment(Instr i,
                             Temp pseudoReg)