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