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_LatticeCell;
016    import org.jikesrvm.compilers.opt.dfsolver.DF_Operator;
017    import org.jikesrvm.compilers.opt.ir.BasicBlock;
018    import org.jikesrvm.compilers.opt.ir.IR;
019    import org.jikesrvm.util.BitVector;
020    
021    /**
022     * This class implements the MEET operation for the
023     * dataflow equations for the dominator calculation.
024     */
025    class DominatorOperator extends DF_Operator {
026      /**
027       * A singleton instance of this class.
028       */
029      static final DominatorOperator MEET = new DominatorOperator();
030    
031      /**
032       * Evaluate an equation with the MEET operation
033       * @param operands the lhs(operands[0]) and rhs(operands[1])
034       *       of the equation.
035       * @return true if the value of the lhs changes. false otherwise
036       */
037      public boolean evaluate(DF_LatticeCell[] operands) {
038        DominatorCell lhs = (DominatorCell) operands[0];
039        IR ir = lhs.ir;
040        BasicBlock bb = lhs.block;
041        BitVector oldSet = lhs.dominators.dup();
042        BitVector newDominators = new BitVector(ir.getMaxBasicBlockNumber() + 1);
043        if (operands.length > 1) {
044          if (operands[1] != null) {
045            newDominators.or(((DominatorCell) operands[1]).dominators);
046          }
047        }
048        for (int i = 2; i < operands.length; i++) {
049          newDominators.and(((DominatorCell) operands[i]).dominators);
050        }
051        newDominators.set(bb.getNumber());
052        lhs.dominators = newDominators;
053        return !lhs.dominators.equals(oldSet);
054      }
055    
056      /**
057       * Return a String representation of the operator
058       * @return "MEET"
059       */
060      public String toString() {
061        return "MEET";
062      }
063    }