Package jminusminus
Class NControlFlowGraph
java.lang.Object
jminusminus.NControlFlowGraph
Representation of a control flow graph (cfg) for a method.
-
Field Summary
Modifier and TypeFieldDescriptionList of blocks forming the cfg for the method.static int
Block identifier.SPIM code for string literals added to the data segment.Descriptor of the method this cfg corresponds to.static int
HIR instruction identifier.Maps HIR instruction ids in this cfg to HIR instructions.Intervals allocated by the register allocation algorithm.Used to construct jump labels in spim output.static int
HIR instruction identifier.static int
Loop identifier.int
The total number of intervals.Name of the method this cfg corresponds to.int
Stack offset counter..Physical registers allocated for this cfg by the HIR to LIR conversion algorithm.static int
Virtual register identifier.Registers allocated for this cfg by the HIR to LIR conversion algorithm. -
Constructor Summary
ConstructorDescriptionConstructs a NControlFlowGraph object for a method.. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Replaces references to virtual registers in LIR instructions with references to physical registers.blockAt
(int id) Returns the basic block at a particular instruction id, or null.void
computeDominators
(NBasicBlock block, NBasicBlock pred) Computes the dominator of each block in this cfg recursively given the starting block and its predecessor.void
detectLoops
(NBasicBlock block, NBasicBlock pred) Implements loop detection algorithm to figure out if the specified block is a loop head or a loop tail.void
Eliminates redundant phi functions of the form x = (y, x, x, ..., x) with y.void
hirToLir()
Converts the hir instructions in this cfg to lir instructions.void
optimize()
Carries out optimizations on the high-level instructions.void
Computes optimal ordering of the basic blocks in this cfg.void
Removes blocks that cannot be reached from the begin block (B0).void
Assigns new ids to the LIR instructions in this cfg.void
Resolves the phi functions in this cfg, i.e., for each x = phi(x1, x2, ..., xn) generate an (LIR) move xi, x instruction at the end of the predecessor i of thte block defining the phi function; if the instruction there is a branch, add the instruction prior to the branch.void
Converts tuples in each block to their high-level (HIR) representations.void
Writes the hir instructions in this cfg to standard output.void
Writes the intervals in this cfg to standard output.void
Writes the lir instructions in this cfg to standard output.void
Writes the tuples in this cfg to standard output.
-
Field Details
-
blockId
public static int blockIdBlock identifier. -
hirId
public static int hirIdHIR instruction identifier. -
lirId
public static int lirIdHIR instruction identifier. -
regId
public static int regIdVirtual register identifier. -
offset
public int offsetStack offset counter.. -
loopIndex
public static int loopIndexLoop identifier. -
name
Name of the method this cfg corresponds to. -
desc
Descriptor of the method this cfg corresponds to. -
basicBlocks
List of blocks forming the cfg for the method. -
hirMap
Maps HIR instruction ids in this cfg to HIR instructions. -
registers
Registers allocated for this cfg by the HIR to LIR conversion algorithm. -
maxIntervals
public int maxIntervalsThe total number of intervals. This is used to name split children and grows as more intervals are created by spills. -
pRegisters
Physical registers allocated for this cfg by the HIR to LIR conversion algorithm. -
intervals
Intervals allocated by the register allocation algorithm. -
labelPrefix
Used to construct jump labels in spim output. -
data
SPIM code for string literals added to the data segment.
-
-
Constructor Details
-
NControlFlowGraph
Constructs a NControlFlowGraph object for a method..- Parameters:
cp
- constant pool for the class containing the method.m
- contains information about the method.
-
-
Method Details
-
detectLoops
Implements loop detection algorithm to figure out if the specified block is a loop head or a loop tail. Also calculates the number of backward branches to the block.- Parameters:
block
- a block.pred
- block's predecessor or null.
-
removeUnreachableBlocks
public void removeUnreachableBlocks()Removes blocks that cannot be reached from the begin block (B0). Also removes these blocks from the predecessor lists. -
computeDominators
Computes the dominator of each block in this cfg recursively given the starting block and its predecessor.- Parameters:
block
- starting block.pred
- block's predecessor.
-
tuplesToHir
public void tuplesToHir()Converts tuples in each block to their high-level (HIR) representations. -
optimize
public void optimize()Carries out optimizations on the high-level instructions. -
eliminateRedundantPhiFunctions
public void eliminateRedundantPhiFunctions()Eliminates redundant phi functions of the form x = (y, x, x, ..., x) with y. -
hirToLir
public void hirToLir()Converts the hir instructions in this cfg to lir instructions. -
resolvePhiFunctions
public void resolvePhiFunctions()Resolves the phi functions in this cfg, i.e., for each x = phi(x1, x2, ..., xn) generate an (LIR) move xi, x instruction at the end of the predecessor i of thte block defining the phi function; if the instruction there is a branch, add the instruction prior to the branch. -
orderBlocks
public void orderBlocks()Computes optimal ordering of the basic blocks in this cfg. -
blockAt
Returns the basic block at a particular instruction id, or null.- Parameters:
id
- the (LIR) instruction id.- Returns:
- the basic block at a particular instruction id, or null.
-
renumberLirInstructions
public void renumberLirInstructions()Assigns new ids to the LIR instructions in this cfg. -
allocatePhysicalRegisters
public void allocatePhysicalRegisters()Replaces references to virtual registers in LIR instructions with references to physical registers. -
writeTuplesToStdOut
Writes the tuples in this cfg to standard output.- Parameters:
p
- for pretty printing with indentation.
-
writeHirToStdOut
Writes the hir instructions in this cfg to standard output.- Parameters:
p
- for pretty printing with indentation.
-
writeLirToStdOut
Writes the lir instructions in this cfg to standard output.- Parameters:
p
- for pretty printing with indentation.
-
writeIntervalsToStdOut
Writes the intervals in this cfg to standard output.- Parameters:
p
- for pretty printing with indentation.
-