001 /*
002 * This file is part of the Jikes RVM project (http://jikesrvm.org).
003 *
004 * This file is licensed to You under the Eclipse Public License (EPL);
005 * You may not use this file except in compliance with the License. You
006 * may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/eclipse-1.0.php
009 *
010 * See the COPYRIGHT.txt file distributed with this work for information
011 * regarding copyright ownership.
012 */
013 package org.jikesrvm.compilers.opt.controlflow;
014
015 import org.jikesrvm.compilers.opt.dfsolver.DF_AbstractCell;
016 import org.jikesrvm.compilers.opt.ir.BasicBlock;
017 import org.jikesrvm.compilers.opt.ir.BasicBlockEnumeration;
018 import org.jikesrvm.compilers.opt.ir.IR;
019 import org.jikesrvm.util.BitVector;
020
021 /**
022 * DominatorCell represents a set of basic blocks, used in
023 * the dataflow calculation
024 */
025 class DominatorCell extends DF_AbstractCell {
026
027 /**
028 * Pointer to the governing IR.
029 */
030 final IR ir;
031 /**
032 * The basic block corresponding to this lattice cell.
033 */
034 final BasicBlock block;
035 /**
036 * Bit set representation of the dominators for this basic block.
037 */
038 BitVector dominators;
039 /**
040 * A guess of the upper bound on the number of out edges for most basic
041 * blocks.
042 */
043 private static final int CAPACITY = 5;
044
045 /**
046 * Make a bit set for a basic block
047 * @param bb the basic block
048 * @param ir the governing IR
049 */
050 public DominatorCell(BasicBlock bb, IR ir) {
051 super(CAPACITY);
052 block = bb;
053 dominators = new BitVector(ir.getMaxBasicBlockNumber() + 1);
054 this.ir = ir;
055 }
056
057 /**
058 * Return a String representation of this cell.
059 * @return a String representation of this cell.
060 */
061 public String toString() {
062 return block + ":" + dominators;
063 }
064
065 /**
066 * Include a single basic block in this set.
067 * @param bb the basic block
068 */
069 public void addSingleBlock(BasicBlock bb) {
070 dominators.set(bb.getNumber());
071 }
072
073 /**
074 * Include all basic blocks in this set.
075 * <p> TODO: make this more efficient.
076 * @param ir the governing ir
077 */
078 public void setTOP(IR ir) {
079 for (BasicBlockEnumeration e = ir.getBasicBlocks(); e.hasMoreElements();) {
080 BasicBlock b = e.next();
081 dominators.set(b.getNumber());
082 }
083 }
084 }