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 */ 013package org.jikesrvm.compilers.opt.controlflow; 014 015import java.util.Enumeration; 016 017import org.jikesrvm.compilers.opt.dfsolver.DF_AbstractCell; 018import org.jikesrvm.compilers.opt.ir.BasicBlock; 019import org.jikesrvm.compilers.opt.ir.IR; 020import org.jikesrvm.util.BitVector; 021 022/** 023 * DominatorCell represents a set of basic blocks, used in 024 * the dataflow calculation 025 */ 026class DominatorCell extends DF_AbstractCell { 027 028 /** 029 * Pointer to the governing IR. 030 */ 031 final IR ir; 032 /** 033 * The basic block corresponding to this lattice cell. 034 */ 035 final BasicBlock block; 036 /** 037 * Bit set representation of the dominators for this basic block. 038 */ 039 BitVector dominators; 040 /** 041 * A guess of the upper bound on the number of out edges for most basic 042 * blocks. 043 */ 044 private static final int CAPACITY = 5; 045 046 /** 047 * Make a bit set for a basic block 048 * @param bb the basic block 049 * @param ir the governing IR 050 */ 051 DominatorCell(BasicBlock bb, IR ir) { 052 super(CAPACITY); 053 block = bb; 054 dominators = new BitVector(ir.getMaxBasicBlockNumber() + 1); 055 this.ir = ir; 056 } 057 058 /** 059 * Return a String representation of this cell. 060 * @return a String representation of this cell. 061 */ 062 @Override 063 public String toString() { 064 return block + ":" + dominators; 065 } 066 067 /** 068 * Include a single basic block in this set. 069 * @param bb the basic block 070 */ 071 public void addSingleBlock(BasicBlock bb) { 072 dominators.set(bb.getNumber()); 073 } 074 075 /** 076 * Include all basic blocks in this set. 077 * <p> TODO: make this more efficient. 078 * @param ir the governing ir 079 */ 080 public void setTOP(IR ir) { 081 for (Enumeration<BasicBlock> e = ir.getBasicBlocks(); e.hasMoreElements();) { 082 BasicBlock b = e.nextElement(); 083 dominators.set(b.getNumber()); 084 } 085 } 086}