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.ir.BasicBlock;
016 import org.jikesrvm.util.BitVector;
017
018 /**
019 * DominatorInfo.java
020 *
021 * This structure holds dominator-related information for a basic block.
022 */
023 public class DominatorInfo {
024 /**
025 * A BitVector which represents the dominators of the basic block
026 */
027 final BitVector dominators;
028 /**
029 * The basic block's immediate dominator.
030 */
031 BasicBlock idom;
032
033 /**
034 * Make a structure with a given bit set holding the dominators
035 * of the basic block.
036 *
037 * @param dominators the bit set
038 */
039 DominatorInfo(BitVector dominators) {
040 this.dominators = dominators;
041 }
042
043 /**
044 * Return the immediate dominator of a basic block.
045 *
046 * <p> Note: the dominator info must be calculated before calling this
047 * routine
048 *
049 * @param bb the basic block in question
050 * @return bb's immediate dominator, as cached in bb's DominatorInfo
051 */
052 public static BasicBlock idom(BasicBlock bb) {
053 DominatorInfo info = (DominatorInfo) bb.scratchObject;
054 return info.idom;
055 }
056
057 /**
058 * Is the basic block represented by this structure dominated by another
059 * basic block?
060 *
061 * @param bb the basic block in question
062 * @return true or false
063 */
064 public boolean isDominatedBy(BasicBlock bb) {
065 return dominators.get(bb.getNumber());
066 }
067
068 /**
069 * Is one basic block (the slave) dominated by another (the master)?
070 *
071 * @param slave the potential dominatee
072 * @param master the potential dominator
073 * @return true or false
074 */
075 static boolean isDominatedBy(BasicBlock slave, BasicBlock master) {
076 return ((DominatorInfo) slave.scratchObject).
077 dominators.get(master.getNumber());
078 }
079 }
080
081
082