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.OperationNotImplementedException;
016    import org.jikesrvm.compilers.opt.OptOptions;
017    import org.jikesrvm.compilers.opt.driver.CompilerPhase;
018    import org.jikesrvm.compilers.opt.driver.OptimizingCompiler;
019    import org.jikesrvm.compilers.opt.ir.IR;
020    
021    /**
022     * Driver routine for dominator tree computation
023     */
024    public final class DominatorTreePhase extends CompilerPhase {
025    
026      /**
027       * Should this phase be performed?
028       * @param options controlling compiler options
029       * @return true or false
030       */
031      public boolean shouldPerform(OptOptions options) {
032        // only perform if the dominators were successfully computed and
033        // one of the following options are set.
034        return options.SSA || options.PRINT_DOMINATORS;
035      }
036    
037      /**
038       * Returns "Dominator Tree"
039       * @return "Dominator Tree"
040       */
041      public String getName() {
042        return "Dominator Tree";
043      }
044    
045      /**
046       * Should the IR be printed before and/or after this phase?
047       * @param options controlling compiler options
048       * @param before query control
049       * @return true or false.
050       */
051      public boolean printingEnabled(OptOptions options, boolean before) {
052        return false;
053      }
054    
055      /**
056       * Main driver.
057       *
058       * @param ir the governing IR
059       */
060      public void perform(IR ir) {
061        // make sure the dominator computation completed successfully
062        if (!ir.HIRInfo.dominatorsAreComputed) {
063          return;
064        }
065        try {
066          DominatorTree.perform(ir, true);
067        } catch (OperationNotImplementedException e) {
068          if (ir.options.PRINT_DOMINATORS || ir.options.PRINT_SSA) {
069            OptimizingCompiler.report(e.getMessage());
070          }
071        }
072      }
073    }