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.OperationNotImplementedException; 016import org.jikesrvm.compilers.opt.OptOptions; 017import org.jikesrvm.compilers.opt.driver.CompilerPhase; 018import org.jikesrvm.compilers.opt.driver.OptimizingCompiler; 019import org.jikesrvm.compilers.opt.ir.IR; 020 021/** 022 * Driver routine for post-dominator computation. This phase invokes 023 * the Lengauer-Tarjan dominator calculation. 024 */ 025public final class PostDominatorsPhase extends CompilerPhase { 026 027 /** 028 * Should we unfactor the CFG? 029 */ 030 private final boolean unfactor; 031 032 /** 033 * @param unfactor Should we unfactor the CFG before computing 034 * dominators? 035 */ 036 public PostDominatorsPhase(boolean unfactor) { 037 this.unfactor = unfactor; 038 } 039 040 /** 041 * Should this phase be performed? This is a member of a composite 042 * phase, so always return {@code true}. The parent composite phase will 043 * dictate. 044 * @param options controlling compiler options 045 */ 046 @Override 047 public boolean shouldPerform(OptOptions options) { 048 return true; 049 } 050 051 /** 052 * Return a string representation of this phase 053 * @return "Post-Dominators" 054 */ 055 @Override 056 public String getName() { 057 return "Post-Dominators"; 058 } 059 060 /** 061 * Should the IR be printed before and/or after this phase? 062 * @param options controlling compiler options 063 * @param before query control 064 * @return {@code false} 065 */ 066 @Override 067 public boolean printingEnabled(OptOptions options, boolean before) { 068 return false; 069 } 070 071 /** 072 * Main driver for the post-dominator calculation. 073 */ 074 @Override 075 public void perform(IR ir) { 076 try { 077 // reset flags in case an exception is thrown inside "perform" 078 // and it doesn't return normally 079 ir.HIRInfo.postDominatorsAreComputed = false; 080 081 // compute post-dominators 082 LTDominators.perform(ir, false, unfactor); 083 084 // create the dominator tree 085 DominatorTree.perform(ir, false); 086 087 // computation completed, so set flag 088 ir.HIRInfo.postDominatorsAreComputed = true; 089 090 } catch (OperationNotImplementedException e) { 091 OptOptions options = ir.options; 092 if (options.PRINT_POST_DOMINATORS) { 093 OptimizingCompiler.report(e.getMessage()); 094 } 095 } 096 } 097}