# HG changeset patch # User Thomas Wuerthinger # Date 1423006885 -3600 # Node ID 61c772f6d8ebce64f22e40a9e25ffebb60df1e9b # Parent c4cb2ccd0b96680445a618715ac3258e92cee80a More restructuring in PartialEvaluator. diff -r c4cb2ccd0b96 -r 61c772f6d8eb graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java Wed Feb 04 00:31:33 2015 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java Wed Feb 04 00:41:25 2015 +0100 @@ -103,65 +103,35 @@ } catch (Throwable e) { throw Debug.handle(e); } - final StructuredGraph graph = createRootGraph(callTarget.toString()); + + final StructuredGraph graph = new StructuredGraph(callTarget.toString(), callRootMethod); assert graph != null : "no graph for root method"; try (Scope s = Debug.scope("CreateGraph", graph); Indent indent = Debug.logAndIndent("createGraph %s", graph)) { - // Canonicalize / constant propagate. - PhaseContext baseContext = new PhaseContext(providers, assumptions); - injectConstantCallTarget(graph, callTarget, baseContext); - - Debug.dump(graph, "Before expansion"); - - TruffleExpansionLogger expansionLogger = null; - if (TraceTruffleExpansion.getValue()) { - expansionLogger = new TruffleExpansionLogger(providers, graph); - } + createRootGraph(graph); - expandTree(graph, assumptions, expansionLogger); + Map graphCache = null; + if (CacheGraphs.getValue()) { + graphCache = new HashMap<>(); + } + PhaseContext baseContext = new PhaseContext(providers, assumptions); + HighTierContext tierContext = new HighTierContext(providers, assumptions, graphCache, new PhaseSuite(), OptimisticOptimizations.NONE); - TruffleInliningCache inliningCache = null; - if (TruffleFunctionInlining.getValue()) { - callTarget.setInlining(new TruffleInlining(callTarget, new DefaultInliningPolicy())); - if (TruffleFunctionInliningCache.getValue()) { - inliningCache = new TruffleInliningCache(); - } + if (TruffleCompilerOptions.FastPE.getValue()) { + fastPartialEvaluation(callTarget, assumptions, graph, baseContext, tierContext); + } else { + partialEvaluation(callTarget, assumptions, graph, baseContext, tierContext); } - expandDirectCalls(graph, assumptions, expansionLogger, callTarget.getInlining(), inliningCache); - if (Thread.currentThread().isInterrupted()) { return null; } new VerifyFrameDoesNotEscapePhase().apply(graph, false); - if (TraceTruffleCompilationHistogram.getValue() && constantReceivers != null) { createHistogram(); } - - canonicalizer.apply(graph, baseContext); - Map graphCache = null; - if (CacheGraphs.getValue()) { - graphCache = new HashMap<>(); - } - HighTierContext tierContext = new HighTierContext(providers, assumptions, graphCache, new PhaseSuite(), OptimisticOptimizations.NONE); - - // EA frame and clean up. - do { - try (Scope pe = Debug.scope("TrufflePartialEscape", graph)) { - new PartialEscapePhase(true, canonicalizer).apply(graph, tierContext); - new IncrementalCanonicalizerPhase<>(canonicalizer, new ConditionalEliminationPhase()).apply(graph, tierContext); - } catch (Throwable t) { - Debug.handle(t); - } - } while (expandTree(graph, assumptions, expansionLogger)); - - if (expansionLogger != null) { - expansionLogger.print(callTarget); - } - postPartialEvaluation(graph); } catch (Throwable e) { @@ -171,8 +141,53 @@ return graph; } - public StructuredGraph createRootGraph(String name) { - StructuredGraph graph = new StructuredGraph(name, callRootMethod); + @SuppressWarnings("unused") + private void fastPartialEvaluation(OptimizedCallTarget callTarget, Assumptions assumptions, StructuredGraph graph, PhaseContext baseContext, HighTierContext tierContext) { + } + + private void partialEvaluation(final OptimizedCallTarget callTarget, final Assumptions assumptions, final StructuredGraph graph, PhaseContext baseContext, HighTierContext tierContext) { + injectConstantCallTarget(graph, callTarget, baseContext); + + Debug.dump(graph, "Before expansion"); + + TruffleExpansionLogger expansionLogger = null; + if (TraceTruffleExpansion.getValue()) { + expansionLogger = new TruffleExpansionLogger(providers, graph); + } + + expandTree(graph, assumptions, expansionLogger); + + TruffleInliningCache inliningCache = null; + if (TruffleFunctionInlining.getValue()) { + callTarget.setInlining(new TruffleInlining(callTarget, new DefaultInliningPolicy())); + if (TruffleFunctionInliningCache.getValue()) { + inliningCache = new TruffleInliningCache(); + } + } + + expandDirectCalls(graph, assumptions, expansionLogger, callTarget.getInlining(), inliningCache); + + if (Thread.currentThread().isInterrupted()) { + return; + } + + canonicalizer.apply(graph, baseContext); + // EA frame and clean up. + do { + try (Scope pe = Debug.scope("TrufflePartialEscape", graph)) { + new PartialEscapePhase(true, canonicalizer).apply(graph, tierContext); + new IncrementalCanonicalizerPhase<>(canonicalizer, new ConditionalEliminationPhase()).apply(graph, tierContext); + } catch (Throwable t) { + Debug.handle(t); + } + } while (expandTree(graph, assumptions, expansionLogger)); + + if (expansionLogger != null) { + expansionLogger.print(callTarget); + } + } + + public StructuredGraph createRootGraph(StructuredGraph graph) { new GraphBuilderPhase.Instance(providers.getMetaAccess(), providers.getStampProvider(), new Assumptions(false), configForRoot, TruffleCompilerImpl.Optimizations).apply(graph); return graph; }