harpoon.Backend.Generic
Class InstrBuilder

java.lang.Object
  extended by harpoon.Backend.Generic.InstrBuilder
Direct Known Subclasses:
InstrBuilder, InstrBuilder, InstrBuilder

public abstract class InstrBuilder
extends Object

InstrBuilder defines an interface that general program transformations can call to generate needed assembly code blocks for arbitrary target architectures.

Many of the Instr optimizations need to insert new code to support the transformations that they make on the code. This class provides a set of generic Instr creation routines that each backend wil implement, to be used in creating the support code.

Version:
$Id: InstrBuilder.java,v 1.5 2004/02/08 01:57:30 cananian Exp $
Author:
Felix S. Klock II <pnkfelix@mit.edu>
See Also:
harpoon.Analysis.Instr

Constructor Summary
InstrBuilder()
          Creates a InstrBuilder.
 
Method Summary
 int getSize(Temp temp)
          Returns the size of temp on the stack.
 InstrLABEL makeLabel(Label l, Instr template)
          Returns a new InstrLABEL for generating new arbitrary code blocks to branch to.
 List makeLoad(List regs, int startingOffset, Instr template)
          Generates a new set of Instrs for memory traffic from RAM to multiple registers in the register file.
protected abstract  List makeLoad(Temp reg, int offset, Instr template)
          Generates a new set of Instrs for memory traffic from RAM to one register in the register file.
 List makeStore(List regs, int startingOffset, Instr template)
          Generates a new set of Instrs for memory traffic from multiple registers in the register file to RAM.
protected abstract  List makeStore(Temp reg, int offset, Instr template)
          Generates a new set of Instrs for memory traffic from the register file to RAM.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InstrBuilder

public InstrBuilder()
Creates a InstrBuilder.

Method Detail

makeLoad

public List makeLoad(List regs,
                     int startingOffset,
                     Instr template)
Generates a new set of Instrs for memory traffic from RAM to multiple registers in the register file. This method's default implementation simply calls makeLoad(Temp,int,Instr) for each element of regs and concatenates the returned Lists of Instrs, so architectures with more efficient memory-to-multiple-register operations should override this implementation with a better one.

Parameters:
regs - The target register Temps to hold the values that will be loaded from startingOffset in memory.
startingOffset - The stack offset (zero-indexed). This is an ordinal number, it is NOT meant to be a multiple of some byte size. Note that this method will load values starting at startingOffset and go up to startingOffset + regs.size()-1 (with the first register in regs corresponding to startingOffset + 0, the second to startingOffset + 1, and so on), so code planning to reference the locations corresponding to the sources for the data in the register file should account for any additional offsets.
template - An Instr to derive the generated List from. template gives this the ability to incorporate additional information into the produced List of Instrs.
See Also:
makeLoad(Temp, int, Instr), getSize(harpoon.Temp.Temp)

makeStore

public List makeStore(List regs,
                      int startingOffset,
                      Instr template)
Generates a new set of Instrs for memory traffic from multiple registers in the register file to RAM. This method's default implementation simply calls makeStore(Temp,int,Instr) for each element of regs and concatenates the returned Lists of Instrs, so architectures with more efficient multiple-register-to-memory operations should override this implementation with a better one.

Parameters:
regs - The register Temps holding the values that will be stored starting at startingOffset in memory.
startingOffset - The stack offset (zero-indexed). This is an ordinal number, it is NOT meant to be a multiple of some byte size. Note that this method will store values starting at startingOffset and go up to startingOffset + regs.size()-1 (with the first register in regs corresponding to startingOffset + 0, the second to startingOffset + 1, and so on), so code planning to reference the locations corresponding to the targets for the data in the register file should account for any additional offsets.
template - An Instr to derive the generated List from. template gives this the ability to incorporate additional information into the produced List of Instrs.
See Also:
makeStore(Temp, int, Instr), getSize(harpoon.Temp.Temp)

makeLoad

protected abstract List makeLoad(Temp reg,
                                 int offset,
                                 Instr template)
Generates a new set of Instrs for memory traffic from RAM to one register in the register file.

Parameters:
reg - The target register Temp to hold the value that will be loaded from offset in memory.
offset - The stack offset (zero-indexed). This is an ordinal number, it is NOT meant to be a multiple of some byte size. This frame should perform the necessary magic to turn the number into an appropriate stack offset.
template - An Instr to derive the generated List from. template gives this the ability to incorporate additional information into the produced List of Instrs.
See Also:
getSize(harpoon.Temp.Temp)

makeStore

protected abstract List makeStore(Temp reg,
                                  int offset,
                                  Instr template)
Generates a new set of Instrs for memory traffic from the register file to RAM.

Parameters:
reg - The register Temp holding the value that will be stored at offset in memory.
offset - The stack offset (zero-indexed). This is an abstract number, it is NOT necessarily a multiple of some byte size. This frame should perform the necessary magic to turn the number into an appropriate stack offset.
template - An Instr to derive the generated List from template gives this the ability to incorporate additional information into the produced List of Instrs.
See Also:
getSize(harpoon.Temp.Temp)

getSize

public int getSize(Temp temp)
Returns the size of temp on the stack.
effects: Calculates the size that a value of the type of temp would have on the stack (in terms of the abstract number used for calculating stack offsets in makeLoad() and makeStore()).
When constructing loads and stores, the register allocator should ensure that live values do not overlap on the stack. Thus, given two temps t1 and t2, either ( offset(t2) is greater than or equal to offset(t1) + getSize(t1) ) OR ( offset(t1) is greater than or equal to offset(t2) + getSize(t2) ).
The default implementation simply returns 1; subclasses should override this and check for double word temps, etc.

See Also:
makeLoad(java.util.List, int, harpoon.IR.Assem.Instr), makeStore(java.util.List, int, harpoon.IR.Assem.Instr)

makeLabel

public InstrLABEL makeLabel(Label l,
                            Instr template)
Returns a new InstrLABEL for generating new arbitrary code blocks to branch to.

Parameters:
template - An Instr to base the generated InstrLABEL. template should be part of the instruction stream that the returned InstrLABEL is intended for.