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.driver; 014 015 import org.jikesrvm.classloader.NormalMethod; 016 import org.jikesrvm.classloader.TypeReference; 017 import org.jikesrvm.compilers.opt.OptOptions; 018 import org.jikesrvm.compilers.opt.inlining.DefaultInlineOracle; 019 import org.jikesrvm.compilers.opt.inlining.InlineOracle; 020 import org.jikesrvm.compilers.opt.ir.IR; 021 022 /* 023 * An instance of this class acts instructs the optimizing 024 * compiler how to compile the specified method. 025 */ 026 public final class CompilationPlan { 027 /** 028 * The method to be compiled. 029 */ 030 public final NormalMethod method; 031 032 public NormalMethod getMethod() { 033 return method; 034 } 035 036 /** 037 * The specialized parameters to use in place of those defined in method. 038 */ 039 public final TypeReference[] params; 040 041 /** 042 * The OptimizationPlanElements to be invoked during compilation. 043 */ 044 public final OptimizationPlanElement[] optimizationPlan; 045 /** 046 * The instrumentation plan for the method. 047 */ 048 public final InstrumentationPlan instrumentationPlan; 049 /** 050 * The oracle to be consulted for all inlining decisions. 051 */ 052 public InlineOracle inlinePlan; 053 /** 054 * The Options object that contains misc compilation control data 055 */ 056 public final OptOptions options; 057 058 /** 059 * Whether this compilation is for analysis only? 060 */ 061 public boolean analyzeOnly; 062 063 public boolean irGeneration; 064 065 /** 066 * Construct a compilation plan 067 * 068 * @param m The NormalMethod representing the source method to be compiled 069 * @param pms The specialized parameters to use in place of those defined in method 070 * @param op The optimization plan to be executed on m 071 * @param mp The instrumentation plan to be executed on m 072 * @param opts The Options to be used for compiling m 073 */ 074 public CompilationPlan(NormalMethod m, TypeReference[] pms, OptimizationPlanElement[] op, InstrumentationPlan mp, 075 OptOptions opts) { 076 method = m; 077 params = pms; 078 inlinePlan = new DefaultInlineOracle(); 079 optimizationPlan = op; 080 instrumentationPlan = mp; 081 options = opts; 082 } 083 084 /** 085 * Construct a compilation plan 086 * 087 * @param m The NormalMethod representing the source method to be compiled 088 * @param op The optimization plan to be executed on m 089 * @param mp The instrumentation plan to be executed on m 090 * @param opts The Options to be used for compiling m 091 */ 092 public CompilationPlan(NormalMethod m, OptimizationPlanElement[] op, InstrumentationPlan mp, 093 OptOptions opts) { 094 this(m, null, op, mp, opts); 095 } 096 097 /** 098 * Construct a compilation plan 099 * @param m The NormalMethod representing the source method to be compiled 100 * @param op A single optimization pass to execute on m 101 * @param mp The instrumentation plan to be executed on m 102 * @param opts The Options to be used for compiling m 103 */ 104 public CompilationPlan(NormalMethod m, OptimizationPlanElement op, InstrumentationPlan mp, 105 OptOptions opts) { 106 this(m, new OptimizationPlanElement[]{op}, mp, opts); 107 } 108 109 /** 110 * Set the inline oracle 111 */ 112 public void setInlineOracle(InlineOracle o) { 113 inlinePlan = o; 114 } 115 116 /** 117 * Execute a compilation plan by executing each element 118 * in the optimization plan. 119 */ 120 public IR execute() { 121 IR ir = new IR(method, this); 122 123 // If there is instrumentation to perform, do some initialization 124 if (instrumentationPlan != null) { 125 instrumentationPlan.initInstrumentation(method); 126 } 127 for (OptimizationPlanElement element : optimizationPlan) { 128 element.perform(ir); 129 } 130 // If instrumentation has occured, perform some 131 // cleanup/finalization. NOTE: This code won't execute when 132 // compilation fails with an exception. TODO: Figure out 133 // whether this matters. 134 if (instrumentationPlan != null) { 135 instrumentationPlan.finalizeInstrumentation(method); 136 } 137 138 return ir; 139 } 140 }