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