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 {@code true} if the value of the lhs changes. {@code false} otherwise
036       */
037      @Override
038      public boolean evaluate(DF_LatticeCell[] operands) {
039        DominatorCell lhs = (DominatorCell) operands[0];
040        IR ir = lhs.ir;
041        BasicBlock bb = lhs.block;
042        BitVector oldSet = lhs.dominators.dup();
043        BitVector newDominators = new BitVector(ir.getMaxBasicBlockNumber() + 1);
044        if (operands.length > 1) {
045          if (operands[1] != null) {
046            newDominators.or(((DominatorCell) operands[1]).dominators);
047          }
048        }
049        for (int i = 2; i < operands.length; i++) {
050          newDominators.and(((DominatorCell) operands[i]).dominators);
051        }
052        newDominators.set(bb.getNumber());
053        lhs.dominators = newDominators;
054        return !lhs.dominators.equals(oldSet);
055      }
056    
057      /**
058       * Return a String representation of the operator
059       * @return "MEET"
060       */
061      @Override
062      public String toString() {
063        return "MEET";
064      }
065    }