/** * All files in the distribution of BLOAT (Bytecode Level Optimization and * Analysis tool for Java(tm)) are Copyright 1997-2001 by the Purdue * Research Foundation of Purdue University. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ package EDU.purdue.cs.bloat.cfg; import java.util.*; import EDU.purdue.cs.bloat.editor.*; import EDU.purdue.cs.bloat.tree.*; import EDU.purdue.cs.bloat.util.*; /** * Block represents a basic block of code used in control flow * graphs. A basic block is always entered at its beginning and exits at its * end. That is, its first statement is a label and its last statement is a * jump. There are no other labels or jumps in between. *
* Each Block knows its parent block and its children in the * dominator and postdominator trees. It also knows which blocks are in its * dominance frontier and its postdominance frontier. * * @see FlowGraph * @see DominatorTree * @see DominanceFrontier */ public class Block extends GraphNode { // There are several "types" of Blocks. A NON_HEADER block is not the // header of a loop. An IRREDUCIBLE block is one of the headers of an // irreducible loop. An irriducible loop has more than one entry // point. They are very rare and are really ugly. The loop // transformer tries to fix up mutiple headers. A REDUCIBLE header is // a header for a reducible loop. public static final int NON_HEADER = 0; public static final int IRREDUCIBLE = 1; public static final int REDUCIBLE = 2; FlowGraph graph; // CFG to which this Block belongs Label label; // This Block's Label Tree tree; // Expression tree for this block Block domParent; // Block that (immediately) dominates this Block Block pdomParent; Set domChildren; // Blocks that this Block dominates Set pdomChildren; // The postdominator children of this block Set domFrontier; // This Block's dominance frontier Set pdomFrontier; // This Block's postdominace frontier int blockType; // NON_HEADER, IRREDUCIBLE, or REDUCIBLE Block header; // The block's loop header StackOptimizer stackOptimizer; // Stack Optimizer /** * Constructor. * * @param label * The block's label. The label may be thought of as the line of * code at which the block begins. * @param graph * The CFG containing the block. */ Block(final Label label, final FlowGraph graph) { this.label = label; this.graph = graph; this.tree = null; this.header = null; this.blockType = Block.NON_HEADER; label.setStartsBlock(true); domParent = null; pdomParent = null; domChildren = new HashSet(); pdomChildren = new HashSet(); domFrontier = new HashSet(); pdomFrontier = new HashSet(); stackOptimizer = new StackOptimizer(this); // make StackOptimizer // object } /** * Returns the stack optimizer for this block. * * @return The stack optimizer. */ public StackOptimizer stackOptimizer() { return stackOptimizer; } /** * Returns the expression tree for this block. * * @return The tree. */ public Tree tree() { return tree; } /** * Sets the expression tree for this block. */ public void setTree(final Tree tree) { this.tree = tree; } /** * Returns the CFG containing the block. * * @return The CFG. */ public FlowGraph graph() { return graph; } /** * Returns the label associated with this block. */ public Label label() { return label; } /** * Visits the expression tree contained in this block. */ public void visitChildren(final TreeVisitor visitor) { if (tree != null) { tree.visit(visitor); } } public void visit(final TreeVisitor visitor) { visitor.visitBlock(this); } /** * Sets the type of this Block. A Block may have one of three types: * *