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 */
013package org.jikesrvm.compilers.opt.controlflow;
014
015import org.jikesrvm.compilers.opt.DefUse;
016import org.jikesrvm.compilers.opt.OptOptions;
017import org.jikesrvm.compilers.opt.driver.CompilerPhase;
018import org.jikesrvm.compilers.opt.ir.IR;
019
020/**
021 * The driver that creates an annotated {@link AnnotatedLSTGraph}.
022 *
023 * @see AnnotatedLSTGraph
024 */
025public class LoopAnalysis extends CompilerPhase {
026  /**
027   * Return a string name for this phase.
028   * @return "Loop Analysis"
029   */
030  @Override
031  public final String getName() {
032    return "Loop Analysis";
033  }
034
035  /**
036   * This phase is disabled by default.
037   * <p>
038   * It will run only on O3 but O2 is the default maximum optimization level.
039   */
040  @Override
041  public boolean shouldPerform(OptOptions options) {
042    return options.getOptLevel() >= 3;
043  }
044
045  @Override
046  public final void perform(IR ir) {
047    if (!ir.hasReachableExceptionHandlers()) {
048      // Build LST tree and dominator info
049      new DominatorsPhase(false).perform(ir);
050      DefUse.computeDU(ir);
051      // Build annotated version
052      ir.HIRInfo.loopStructureTree = new AnnotatedLSTGraph(ir, ir.HIRInfo.loopStructureTree);
053    }
054  }
055}