Mercurial > hg > truffle
comparison graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java @ 15011:c8e575742f36
allow compilation with custom RegisterConfig
author | Lukas Stadler <lukas.stadler@oracle.com> |
---|---|
date | Mon, 07 Apr 2014 19:21:22 +0200 |
parents | 88dfaf6448e0 |
children | f4e31f06b019 2c940b1a48d8 |
comparison
equal
deleted
inserted
replaced
15010:f36e56e9dd9a | 15011:c8e575742f36 |
---|---|
136 TargetDescription target, Map<ResolvedJavaMethod, StructuredGraph> cache, PhaseSuite<HighTierContext> graphBuilderSuite, OptimisticOptimizations optimisticOpts, | 136 TargetDescription target, Map<ResolvedJavaMethod, StructuredGraph> cache, PhaseSuite<HighTierContext> graphBuilderSuite, OptimisticOptimizations optimisticOpts, |
137 ProfilingInfo profilingInfo, SpeculationLog speculationLog, Suites suites, T compilationResult, CompilationResultBuilderFactory factory) { | 137 ProfilingInfo profilingInfo, SpeculationLog speculationLog, Suites suites, T compilationResult, CompilationResultBuilderFactory factory) { |
138 assert !graph.isFrozen(); | 138 assert !graph.isFrozen(); |
139 try (Scope s0 = Debug.scope("GraalCompiler", graph, providers.getCodeCache())) { | 139 try (Scope s0 = Debug.scope("GraalCompiler", graph, providers.getCodeCache())) { |
140 Assumptions assumptions = new Assumptions(OptAssumptions.getValue()); | 140 Assumptions assumptions = new Assumptions(OptAssumptions.getValue()); |
141 SchedulePhase schedule = null; | 141 SchedulePhase schedule = emitFrontEnd(providers, target, graph, assumptions, cache, graphBuilderSuite, optimisticOpts, profilingInfo, speculationLog, suites); |
142 try (Scope s = Debug.scope("FrontEnd"); TimerCloseable a = FrontEnd.start()) { | 142 emitBackEnd(graph, stub, cc, installedCodeOwner, backend, target, compilationResult, factory, assumptions, schedule, null); |
143 schedule = emitHIR(providers, target, graph, assumptions, cache, graphBuilderSuite, optimisticOpts, profilingInfo, speculationLog, suites); | |
144 } catch (Throwable e) { | |
145 throw Debug.handle(e); | |
146 } | |
147 try (TimerCloseable a = BackEnd.start()) { | |
148 LIRGenerationResult lirGenRes = null; | |
149 lirGenRes = emitLIR(backend, target, schedule, graph, stub, cc); | |
150 try (Scope s = Debug.scope("CodeGen", lirGenRes)) { | |
151 emitCode(backend, assumptions, lirGenRes, compilationResult, installedCodeOwner, factory); | |
152 } catch (Throwable e) { | |
153 throw Debug.handle(e); | |
154 } | |
155 } catch (Throwable e) { | |
156 throw Debug.handle(e); | |
157 } | |
158 } catch (Throwable e) { | 143 } catch (Throwable e) { |
159 throw Debug.handle(e); | 144 throw Debug.handle(e); |
160 } | 145 } |
161 return compilationResult; | 146 return compilationResult; |
162 } | 147 } |
170 } | 155 } |
171 | 156 |
172 /** | 157 /** |
173 * Builds the graph, optimizes it. | 158 * Builds the graph, optimizes it. |
174 */ | 159 */ |
175 public static SchedulePhase emitHIR(Providers providers, TargetDescription target, StructuredGraph graph, Assumptions assumptions, Map<ResolvedJavaMethod, StructuredGraph> cache, | 160 public static SchedulePhase emitFrontEnd(Providers providers, TargetDescription target, StructuredGraph graph, Assumptions assumptions, Map<ResolvedJavaMethod, StructuredGraph> cache, |
176 PhaseSuite<HighTierContext> graphBuilderSuite, OptimisticOptimizations optimisticOpts, ProfilingInfo profilingInfo, SpeculationLog speculationLog, Suites suites) { | 161 PhaseSuite<HighTierContext> graphBuilderSuite, OptimisticOptimizations optimisticOpts, ProfilingInfo profilingInfo, SpeculationLog speculationLog, Suites suites) { |
177 | 162 try (Scope s = Debug.scope("FrontEnd"); TimerCloseable a = FrontEnd.start()) { |
178 if (speculationLog != null) { | 163 if (speculationLog != null) { |
179 speculationLog.collectFailedSpeculations(); | 164 speculationLog.collectFailedSpeculations(); |
180 } | 165 } |
181 | 166 |
182 HighTierContext highTierContext = new HighTierContext(providers, assumptions, cache, graphBuilderSuite, optimisticOpts); | 167 HighTierContext highTierContext = new HighTierContext(providers, assumptions, cache, graphBuilderSuite, optimisticOpts); |
183 if (graph.start().next() == null) { | 168 if (graph.start().next() == null) { |
184 graphBuilderSuite.apply(graph, highTierContext); | 169 graphBuilderSuite.apply(graph, highTierContext); |
185 new DeadCodeEliminationPhase().apply(graph); | 170 new DeadCodeEliminationPhase().apply(graph); |
186 } else { | 171 } else { |
187 Debug.dump(graph, "initial state"); | 172 Debug.dump(graph, "initial state"); |
188 } | 173 } |
189 | 174 |
190 suites.getHighTier().apply(graph, highTierContext); | 175 suites.getHighTier().apply(graph, highTierContext); |
191 graph.maybeCompress(); | 176 graph.maybeCompress(); |
192 | 177 |
193 MidTierContext midTierContext = new MidTierContext(providers, assumptions, target, optimisticOpts, profilingInfo, speculationLog); | 178 MidTierContext midTierContext = new MidTierContext(providers, assumptions, target, optimisticOpts, profilingInfo, speculationLog); |
194 suites.getMidTier().apply(graph, midTierContext); | 179 suites.getMidTier().apply(graph, midTierContext); |
195 graph.maybeCompress(); | 180 graph.maybeCompress(); |
196 | 181 |
197 LowTierContext lowTierContext = new LowTierContext(providers, assumptions, target); | 182 LowTierContext lowTierContext = new LowTierContext(providers, assumptions, target); |
198 suites.getLowTier().apply(graph, lowTierContext); | 183 suites.getLowTier().apply(graph, lowTierContext); |
199 graph.maybeCompress(); | 184 graph.maybeCompress(); |
200 | 185 |
201 SchedulePhase schedule = new SchedulePhase(); | 186 SchedulePhase schedule = new SchedulePhase(); |
202 schedule.apply(graph); | 187 schedule.apply(graph); |
203 Debug.dump(schedule, "Final HIR schedule"); | 188 Debug.dump(schedule, "Final HIR schedule"); |
204 return schedule; | 189 return schedule; |
205 | 190 } catch (Throwable e) { |
191 throw Debug.handle(e); | |
192 } | |
193 } | |
194 | |
195 public static <T extends CompilationResult> void emitBackEnd(StructuredGraph graph, Object stub, CallingConvention cc, ResolvedJavaMethod installedCodeOwner, Backend backend, | |
196 TargetDescription target, T compilationResult, CompilationResultBuilderFactory factory, Assumptions assumptions, SchedulePhase schedule, RegisterConfig registerConfig) { | |
197 try (TimerCloseable a = BackEnd.start()) { | |
198 LIRGenerationResult lirGen = null; | |
199 lirGen = emitLIR(backend, target, schedule, graph, stub, cc, registerConfig); | |
200 try (Scope s = Debug.scope("CodeGen", lirGen)) { | |
201 emitCode(backend, assumptions, lirGen, compilationResult, installedCodeOwner, factory); | |
202 } catch (Throwable e) { | |
203 throw Debug.handle(e); | |
204 } | |
205 } catch (Throwable e) { | |
206 throw Debug.handle(e); | |
207 } | |
206 } | 208 } |
207 | 209 |
208 private static void emitBlock(NodeLIRBuilder nodeLirGen, LIRGenerationResult lirGenRes, Block b, StructuredGraph graph, BlockMap<List<ScheduledNode>> blockMap) { | 210 private static void emitBlock(NodeLIRBuilder nodeLirGen, LIRGenerationResult lirGenRes, Block b, StructuredGraph graph, BlockMap<List<ScheduledNode>> blockMap) { |
209 if (lirGenRes.getLIR().getLIRforBlock(b) == null) { | 211 if (lirGenRes.getLIR().getLIRforBlock(b) == null) { |
210 for (Block pred : b.getPredecessors()) { | 212 for (Block pred : b.getPredecessors()) { |
214 } | 216 } |
215 nodeLirGen.doBlock(b, graph, blockMap); | 217 nodeLirGen.doBlock(b, graph, blockMap); |
216 } | 218 } |
217 } | 219 } |
218 | 220 |
219 public static LIRGenerationResult emitLIR(Backend backend, TargetDescription target, SchedulePhase schedule, StructuredGraph graph, Object stub, CallingConvention cc) { | 221 public static LIRGenerationResult emitLIR(Backend backend, TargetDescription target, SchedulePhase schedule, StructuredGraph graph, Object stub, CallingConvention cc, RegisterConfig registerConfig) { |
220 Block[] blocks = schedule.getCFG().getBlocks(); | 222 Block[] blocks = schedule.getCFG().getBlocks(); |
221 Block startBlock = schedule.getCFG().getStartBlock(); | 223 Block startBlock = schedule.getCFG().getStartBlock(); |
222 assert startBlock != null; | 224 assert startBlock != null; |
223 assert startBlock.getPredecessorCount() == 0; | 225 assert startBlock.getPredecessorCount() == 0; |
224 | 226 |
239 } | 241 } |
240 } catch (Throwable e) { | 242 } catch (Throwable e) { |
241 throw Debug.handle(e); | 243 throw Debug.handle(e); |
242 } | 244 } |
243 try (Scope ds = Debug.scope("BackEnd", lir)) { | 245 try (Scope ds = Debug.scope("BackEnd", lir)) { |
244 FrameMap frameMap = backend.newFrameMap(); | 246 FrameMap frameMap = backend.newFrameMap(registerConfig); |
245 LIRGenerationResult lirGenRes = backend.newLIRGenerationResult(lir, frameMap, stub); | 247 LIRGenerationResult lirGenRes = backend.newLIRGenerationResult(lir, frameMap, stub); |
246 LIRGenerator lirGen = backend.newLIRGenerator(cc, lirGenRes); | 248 LIRGenerator lirGen = backend.newLIRGenerator(cc, lirGenRes); |
247 NodeLIRBuilder nodeLirGen = backend.newNodeLIRGenerator(graph, lirGen); | 249 NodeLIRBuilder nodeLirGen = backend.newNodeLIRGenerator(graph, lirGen); |
248 | 250 |
249 try (Scope s = Debug.scope("LIRGen", lirGen)) { | 251 try (Scope s = Debug.scope("LIRGen", lirGen)) { |