annotate graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningPhase.java @ 8930:f50d10434d3e

Merge
author Lukas Stadler <lukas.stadler@jku.at>
date Mon, 08 Apr 2013 19:37:23 +0200
parents 880619fd6a67 ce5750014c3d
children 6d376d09880b 5ab06146e985
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
6526
ee651c726397 split phases out of graal.phases project into graal.phases.common project
Doug Simon <doug.simon@oracle.com>
parents: 6525
diff changeset
23 package com.oracle.graal.phases.common;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
5177
a26b6248d398 added graph caching (-G:+CacheGraphs)
Lukas Stadler <lukas.stadler@jku.at>
parents: 5114
diff changeset
25 import java.lang.reflect.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
26 import java.util.*;
7879
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
27 import java.util.concurrent.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
28
5510
426c605c9d3c Move cri.ci to api.code.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
29 import com.oracle.graal.api.code.*;
5507
dc71b06d09f8 Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5503
diff changeset
30 import com.oracle.graal.api.meta.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
31 import com.oracle.graal.debug.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
32 import com.oracle.graal.graph.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
33 import com.oracle.graal.nodes.*;
5720
46ad94a0574a moved everything from com.oracle.graal.nodes.cri into com.oracle.graal.nodes.spi
Doug Simon <doug.simon@oracle.com>
parents: 5718
diff changeset
34 import com.oracle.graal.nodes.spi.*;
6525
2c913b643422 rename packages in graal.phases to match project name
Doug Simon <doug.simon@oracle.com>
parents: 6522
diff changeset
35 import com.oracle.graal.phases.*;
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
36 import com.oracle.graal.phases.PhasePlan.PhasePosition;
7307
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
37 import com.oracle.graal.phases.common.CanonicalizerPhase.CustomCanonicalizer;
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
38 import com.oracle.graal.phases.common.InliningUtil.InlineInfo;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
39 import com.oracle.graal.phases.common.InliningUtil.InliningCallback;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
40 import com.oracle.graal.phases.common.InliningUtil.InliningPolicy;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
42 public class InliningPhase extends Phase implements InliningCallback {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
43
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44 /*
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
45 * - Detect method which only call another method with some parameters set to constants: void
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
46 * foo(a) -> void foo(a, b) -> void foo(a, b, c) ... These should not be taken into account when
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
47 * determining inlining depth. - honor the result of overrideInliningDecision(0, caller,
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
48 * invoke.bci, method, true);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
50
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
51 private final PhasePlan plan;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52
8608
056966f39a36 changed parameters of InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 8385
diff changeset
53 private final MetaAccessProvider runtime;
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
54 private final Assumptions assumptions;
8636
ac4dbfecec8f passed a Replacements object to inlining utility methods that need one instead of the GraalRuntime API
Doug Simon <doug.simon@oracle.com>
parents: 8618
diff changeset
55 private final Replacements replacements;
5718
10341299528c renamings: ExtendedRiRuntime -> GraalCodeCacheProvider, CiLoweringTool -> LoweringTool, RiGraphCache -> GraphCache
Doug Simon <doug.simon@oracle.com>
parents: 5674
diff changeset
56 private final GraphCache cache;
4468
87a12a816e99 added C1 inlining policy for comparison, bugfixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
57 private final InliningPolicy inliningPolicy;
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
58 private final OptimisticOptimizations optimisticOpts;
7307
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
59 private CustomCanonicalizer customCanonicalizer;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
60
8548
51d5999900e2 simple iterative inlining, simple read elimination in PEA
Lukas Stadler <lukas.stadler@jku.at>
parents: 8385
diff changeset
61 private int inliningCount;
51d5999900e2 simple iterative inlining, simple read elimination in PEA
Lukas Stadler <lukas.stadler@jku.at>
parents: 8385
diff changeset
62
51d5999900e2 simple iterative inlining, simple read elimination in PEA
Lukas Stadler <lukas.stadler@jku.at>
parents: 8385
diff changeset
63 private int maxMethodPerInlining = Integer.MAX_VALUE;
51d5999900e2 simple iterative inlining, simple read elimination in PEA
Lukas Stadler <lukas.stadler@jku.at>
parents: 8385
diff changeset
64
4348
d49c90e641cb Remove GraalMetrics, replace with new syntax for metrics.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4205
diff changeset
65 // Metrics
4356
249752adcb8d Rename Timer DebugTimer and Metric DebugMetric.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4352
diff changeset
66 private static final DebugMetric metricInliningPerformed = Debug.metric("InliningPerformed");
249752adcb8d Rename Timer DebugTimer and Metric DebugMetric.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4352
diff changeset
67 private static final DebugMetric metricInliningConsidered = Debug.metric("InliningConsidered");
4598
6a44a26ed9e6 set default inlining policy to the greedy one
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4594
diff changeset
68 private static final DebugMetric metricInliningStoppedByMaxDesiredSize = Debug.metric("InliningStoppedByMaxDesiredSize");
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
69 private static final DebugMetric metricInliningRuns = Debug.metric("Runs");
4348
d49c90e641cb Remove GraalMetrics, replace with new syntax for metrics.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4205
diff changeset
70
8930
Lukas Stadler <lukas.stadler@jku.at>
parents: 8915 8637
diff changeset
71 public InliningPhase(MetaAccessProvider runtime, Map<Invoke, Double> hints, Replacements replacements, Assumptions assumptions, GraphCache cache, PhasePlan plan,
Lukas Stadler <lukas.stadler@jku.at>
parents: 8915 8637
diff changeset
72 OptimisticOptimizations optimisticOpts) {
8636
ac4dbfecec8f passed a Replacements object to inlining utility methods that need one instead of the GraalRuntime API
Doug Simon <doug.simon@oracle.com>
parents: 8618
diff changeset
73 this(runtime, replacements, assumptions, cache, plan, createInliningPolicy(runtime, replacements, assumptions, optimisticOpts, hints), optimisticOpts);
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
74 }
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
75
8636
ac4dbfecec8f passed a Replacements object to inlining utility methods that need one instead of the GraalRuntime API
Doug Simon <doug.simon@oracle.com>
parents: 8618
diff changeset
76 public InliningPhase(MetaAccessProvider runtime, Replacements replacements, Assumptions assumptions, GraphCache cache, PhasePlan plan, InliningPolicy inliningPolicy,
ac4dbfecec8f passed a Replacements object to inlining utility methods that need one instead of the GraalRuntime API
Doug Simon <doug.simon@oracle.com>
parents: 8618
diff changeset
77 OptimisticOptimizations optimisticOpts) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
78 this.runtime = runtime;
8636
ac4dbfecec8f passed a Replacements object to inlining utility methods that need one instead of the GraalRuntime API
Doug Simon <doug.simon@oracle.com>
parents: 8618
diff changeset
79 this.replacements = replacements;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
80 this.assumptions = assumptions;
5177
a26b6248d398 added graph caching (-G:+CacheGraphs)
Lukas Stadler <lukas.stadler@jku.at>
parents: 5114
diff changeset
81 this.cache = cache;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
82 this.plan = plan;
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
83 this.inliningPolicy = inliningPolicy;
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
84 this.optimisticOpts = optimisticOpts;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
85 }
8618
832b9a115a2d style fixes
Christian Haeubl <haeubl@ssw.jku.at>
parents: 8617
diff changeset
86
8617
Christian Haeubl <haeubl@ssw.jku.at>
parents: 8608 8552
diff changeset
87 public void setCustomCanonicalizer(CustomCanonicalizer customCanonicalizer) {
Christian Haeubl <haeubl@ssw.jku.at>
parents: 8608 8552
diff changeset
88 this.customCanonicalizer = customCanonicalizer;
Christian Haeubl <haeubl@ssw.jku.at>
parents: 8608 8552
diff changeset
89 }
8618
832b9a115a2d style fixes
Christian Haeubl <haeubl@ssw.jku.at>
parents: 8617
diff changeset
90
8617
Christian Haeubl <haeubl@ssw.jku.at>
parents: 8608 8552
diff changeset
91 public void setMaxMethodsPerInlining(int max) {
Christian Haeubl <haeubl@ssw.jku.at>
parents: 8608 8552
diff changeset
92 maxMethodPerInlining = max;
Christian Haeubl <haeubl@ssw.jku.at>
parents: 8608 8552
diff changeset
93 }
8618
832b9a115a2d style fixes
Christian Haeubl <haeubl@ssw.jku.at>
parents: 8617
diff changeset
94
8548
51d5999900e2 simple iterative inlining, simple read elimination in PEA
Lukas Stadler <lukas.stadler@jku.at>
parents: 8385
diff changeset
95 public int getInliningCount() {
51d5999900e2 simple iterative inlining, simple read elimination in PEA
Lukas Stadler <lukas.stadler@jku.at>
parents: 8385
diff changeset
96 return inliningCount;
51d5999900e2 simple iterative inlining, simple read elimination in PEA
Lukas Stadler <lukas.stadler@jku.at>
parents: 8385
diff changeset
97 }
51d5999900e2 simple iterative inlining, simple read elimination in PEA
Lukas Stadler <lukas.stadler@jku.at>
parents: 8385
diff changeset
98
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
99 @Override
5316
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5299
diff changeset
100 protected void run(final StructuredGraph graph) {
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
101 inliningPolicy.initialize(graph);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
102
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
103 while (inliningPolicy.continueInlining(graph)) {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
104 final InlineInfo candidate = inliningPolicy.next();
7391
36dafe48bc38 added relevance-based inlining
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7388
diff changeset
105
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
106 if (candidate != null) {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
107 boolean isWorthInlining = inliningPolicy.isWorthInlining(candidate);
8548
51d5999900e2 simple iterative inlining, simple read elimination in PEA
Lukas Stadler <lukas.stadler@jku.at>
parents: 8385
diff changeset
108 isWorthInlining &= candidate.numberOfMethods() <= maxMethodPerInlining;
5316
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5299
diff changeset
109
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
110 metricInliningConsidered.increment();
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
111 if (isWorthInlining) {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
112 int mark = graph.getMark();
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
113 try {
7256
d0c4b6f8d67f canonicalize invoke usages during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7227
diff changeset
114 List<Node> invokeUsages = candidate.invoke().node().usages().snapshot();
8636
ac4dbfecec8f passed a Replacements object to inlining utility methods that need one instead of the GraalRuntime API
Doug Simon <doug.simon@oracle.com>
parents: 8618
diff changeset
115 candidate.inline(graph, runtime, replacements, this, assumptions);
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
116 Debug.dump(graph, "after %s", candidate);
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
117 Iterable<Node> newNodes = graph.getNewNodes(mark);
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
118 inliningPolicy.scanInvokes(newNodes);
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
119 if (GraalOptions.OptCanonicalizer) {
7827
961ad124cb21 Convert indexScalingEnabled boolean into an indexScaling integer value. This change removed the dependency on TargetDescription in large parts of the system.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7694
diff changeset
120 new CanonicalizerPhase(runtime, assumptions, invokeUsages, mark, customCanonicalizer).apply(graph);
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
121 }
8548
51d5999900e2 simple iterative inlining, simple read elimination in PEA
Lukas Stadler <lukas.stadler@jku.at>
parents: 8385
diff changeset
122 inliningCount++;
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
123 metricInliningPerformed.increment();
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
124 } catch (BailoutException bailout) {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
125 throw bailout;
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
126 } catch (AssertionError e) {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
127 throw new GraalInternalError(e).addContext(candidate.toString());
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
128 } catch (RuntimeException e) {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
129 throw new GraalInternalError(e).addContext(candidate.toString());
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
130 } catch (GraalInternalError e) {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
131 throw e.addContext(candidate.toString());
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
132 }
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
133 } else if (optimisticOpts.devirtualizeInvokes()) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
134 candidate.tryToDevirtualizeInvoke(graph, runtime, assumptions);
5316
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5299
diff changeset
135 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
136 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
137 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
138 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
139
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
140 @Override
5541
b4c406861c33 More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5540
diff changeset
141 public StructuredGraph buildGraph(final ResolvedJavaMethod method) {
6353
2590d9cc3b6d remove unnecessary debug scope during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 5788
diff changeset
142 metricInliningRuns.increment();
2590d9cc3b6d remove unnecessary debug scope during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 5788
diff changeset
143 if (GraalOptions.CacheGraphs && cache != null) {
2590d9cc3b6d remove unnecessary debug scope during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 5788
diff changeset
144 StructuredGraph cachedGraph = cache.get(method);
2590d9cc3b6d remove unnecessary debug scope during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 5788
diff changeset
145 if (cachedGraph != null) {
2590d9cc3b6d remove unnecessary debug scope during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 5788
diff changeset
146 return cachedGraph;
2590d9cc3b6d remove unnecessary debug scope during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 5788
diff changeset
147 }
2590d9cc3b6d remove unnecessary debug scope during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 5788
diff changeset
148 }
7879
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
149 final StructuredGraph newGraph = new StructuredGraph(method);
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
150 return Debug.scope("InlineGraph", newGraph, new Callable<StructuredGraph>() {
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
151
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
152 @Override
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
153 public StructuredGraph call() throws Exception {
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
154 if (plan != null) {
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
155 plan.runPhases(PhasePosition.AFTER_PARSING, newGraph);
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
156 }
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
157 assert newGraph.start().next() != null : "graph needs to be populated during PhasePosition.AFTER_PARSING";
5177
a26b6248d398 added graph caching (-G:+CacheGraphs)
Lukas Stadler <lukas.stadler@jku.at>
parents: 5114
diff changeset
158
7879
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
159 if (GraalOptions.ProbabilityAnalysis) {
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
160 new DeadCodeEliminationPhase().apply(newGraph);
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
161 new ComputeProbabilityPhase().apply(newGraph);
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
162 }
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
163 if (GraalOptions.OptCanonicalizer) {
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
164 new CanonicalizerPhase(runtime, assumptions).apply(newGraph);
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
165 }
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
166 if (GraalOptions.CullFrameStates) {
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
167 new CullFrameStatesPhase().apply(newGraph);
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
168 }
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
169 if (GraalOptions.CacheGraphs && cache != null) {
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
170 cache.put(newGraph);
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
171 }
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
172 return newGraph;
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
173 }
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
174 });
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
175 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
176
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
177 private interface InliningDecision {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
178
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
179 boolean isWorthInlining(InlineInfo info);
4670
41034914e2ee add MethodContents assumption to fix debbugging issue
Lukas Stadler <lukas.stadler@jku.at>
parents: 4598
diff changeset
180 }
41034914e2ee add MethodContents assumption to fix debbugging issue
Lukas Stadler <lukas.stadler@jku.at>
parents: 4598
diff changeset
181
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
182 private static class GreedySizeBasedInliningDecision implements InliningDecision {
7686
149092d59dd0 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7685
diff changeset
183
8608
056966f39a36 changed parameters of InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 8385
diff changeset
184 private final MetaAccessProvider runtime;
8636
ac4dbfecec8f passed a Replacements object to inlining utility methods that need one instead of the GraalRuntime API
Doug Simon <doug.simon@oracle.com>
parents: 8618
diff changeset
185 private final Replacements replacements;
8552
31b7a648b4b3 turn inlining hints into a map
Lukas Stadler <lukas.stadler@jku.at>
parents: 8548
diff changeset
186 private final Map<Invoke, Double> hints;
4594
eb6df44a1374 bugfixes, added bytecode complexity estimation
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4591
diff changeset
187
8636
ac4dbfecec8f passed a Replacements object to inlining utility methods that need one instead of the GraalRuntime API
Doug Simon <doug.simon@oracle.com>
parents: 8618
diff changeset
188 public GreedySizeBasedInliningDecision(MetaAccessProvider runtime, Replacements replacements, Map<Invoke, Double> hints) {
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
189 this.runtime = runtime;
8636
ac4dbfecec8f passed a Replacements object to inlining utility methods that need one instead of the GraalRuntime API
Doug Simon <doug.simon@oracle.com>
parents: 8618
diff changeset
190 this.replacements = replacements;
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
191 this.hints = hints;
4594
eb6df44a1374 bugfixes, added bytecode complexity estimation
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4591
diff changeset
192 }
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
193
4594
eb6df44a1374 bugfixes, added bytecode complexity estimation
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4591
diff changeset
194 @Override
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
195 public boolean isWorthInlining(InlineInfo info) {
4594
eb6df44a1374 bugfixes, added bytecode complexity estimation
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4591
diff changeset
196 assert GraalOptions.ProbabilityAnalysis;
7690
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
197 /*
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
198 * TODO (chaeubl): invoked methods that are on important paths but not yet compiled ->
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
199 * will be compiled anyways and it is likely that we are the only caller... might be
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
200 * useful to inline those methods but increases bootstrap time (maybe those methods are
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
201 * also getting queued in the compilation queue concurrently)
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
202 */
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
203
8915
880619fd6a67 allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents: 8618
diff changeset
204 if (GraalOptions.AlwaysInlineIntrinsics) {
8930
Lukas Stadler <lukas.stadler@jku.at>
parents: 8915 8637
diff changeset
205 if (onlyIntrinsics(replacements, info)) {
8915
880619fd6a67 allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents: 8618
diff changeset
206 return InliningUtil.logInlinedMethod(info, "intrinsic");
880619fd6a67 allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents: 8618
diff changeset
207 }
880619fd6a67 allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents: 8618
diff changeset
208 } else {
8930
Lukas Stadler <lukas.stadler@jku.at>
parents: 8915 8637
diff changeset
209 if (onlyForcedIntrinsics(replacements, info)) {
8915
880619fd6a67 allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents: 8618
diff changeset
210 return InliningUtil.logInlinedMethod(info, "intrinsic");
880619fd6a67 allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents: 8618
diff changeset
211 }
4594
eb6df44a1374 bugfixes, added bytecode complexity estimation
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4591
diff changeset
212 }
eb6df44a1374 bugfixes, added bytecode complexity estimation
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4591
diff changeset
213
8552
31b7a648b4b3 turn inlining hints into a map
Lukas Stadler <lukas.stadler@jku.at>
parents: 8548
diff changeset
214 double bonus = 1;
31b7a648b4b3 turn inlining hints into a map
Lukas Stadler <lukas.stadler@jku.at>
parents: 8548
diff changeset
215 if (hints != null && hints.containsKey(info.invoke())) {
31b7a648b4b3 turn inlining hints into a map
Lukas Stadler <lukas.stadler@jku.at>
parents: 8548
diff changeset
216 bonus = hints.get(info.invoke());
31b7a648b4b3 turn inlining hints into a map
Lukas Stadler <lukas.stadler@jku.at>
parents: 8548
diff changeset
217 }
8548
51d5999900e2 simple iterative inlining, simple read elimination in PEA
Lukas Stadler <lukas.stadler@jku.at>
parents: 8385
diff changeset
218
8552
31b7a648b4b3 turn inlining hints into a map
Lukas Stadler <lukas.stadler@jku.at>
parents: 8548
diff changeset
219 int bytecodeSize = (int) (bytecodeCodeSize(info) / bonus);
31b7a648b4b3 turn inlining hints into a map
Lukas Stadler <lukas.stadler@jku.at>
parents: 8548
diff changeset
220 int complexity = (int) (compilationComplexity(info) / bonus);
31b7a648b4b3 turn inlining hints into a map
Lukas Stadler <lukas.stadler@jku.at>
parents: 8548
diff changeset
221 int compiledCodeSize = (int) (compiledCodeSize(info) / bonus);
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
222 double relevance = info.invoke().inliningRelevance();
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
223
7690
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
224 /*
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
225 * as long as the compiled code size is small enough (or the method was not yet
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
226 * compiled), we can do a pretty general inlining that suits most situations
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
227 */
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
228 if (compiledCodeSize < GraalOptions.SmallCompiledCodeSize) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
229 if (isTrivialInlining(bytecodeSize, complexity, compiledCodeSize)) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
230 return InliningUtil.logInlinedMethod(info, "trivial (bytecodes=%d, complexity=%d, codeSize=%d)", bytecodeSize, complexity, compiledCodeSize);
5021
a7c079d5dc87 try to reduce MaximumGreedyInlineSize significantly
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5019
diff changeset
231 }
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
232
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
233 if (canInlineRelevanceBased(relevance, bytecodeSize, complexity, compiledCodeSize)) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
234 return InliningUtil.logInlinedMethod(info, "relevance-based (relevance=%f, bytecodes=%d, complexity=%d, codeSize=%d)", relevance, bytecodeSize, complexity, compiledCodeSize);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
235 }
5021
a7c079d5dc87 try to reduce MaximumGreedyInlineSize significantly
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5019
diff changeset
236 }
a7c079d5dc87 try to reduce MaximumGreedyInlineSize significantly
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5019
diff changeset
237
7690
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
238 /*
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
239 * the normal inlining did not fit this invoke, so check if we have any reason why we
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
240 * should still do the inlining
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
241 */
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
242 double probability = info.invoke().probability();
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
243 int transferredValues = numberOfTransferredValues(info);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
244 int invokeUsages = countInvokeUsages(info);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
245 int moreSpecificArguments = countMoreSpecificArgumentInfo(info);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
246 int level = info.level();
5005
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4993
diff changeset
247
7686
149092d59dd0 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7685
diff changeset
248 // TODO (chaeubl): compute metric that is used to check if this method should be inlined
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
249
7686
149092d59dd0 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7685
diff changeset
250 return InliningUtil.logNotInlinedMethod(info,
8552
31b7a648b4b3 turn inlining hints into a map
Lukas Stadler <lukas.stadler@jku.at>
parents: 8548
diff changeset
251 "(relevance=%f, bytecodes=%d, complexity=%d, codeSize=%d, probability=%f, transferredValues=%d, invokeUsages=%d, moreSpecificArguments=%d, level=%d, bonus=%f)", relevance,
31b7a648b4b3 turn inlining hints into a map
Lukas Stadler <lukas.stadler@jku.at>
parents: 8548
diff changeset
252 bytecodeSize, complexity, compiledCodeSize, probability, transferredValues, invokeUsages, moreSpecificArguments, level, bonus);
4594
eb6df44a1374 bugfixes, added bytecode complexity estimation
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4591
diff changeset
253 }
eb6df44a1374 bugfixes, added bytecode complexity estimation
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4591
diff changeset
254
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
255 private static boolean isTrivialInlining(int bytecodeSize, int complexity, int compiledCodeSize) {
7686
149092d59dd0 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7685
diff changeset
256 return bytecodeSize < GraalOptions.TrivialBytecodeSize || complexity < GraalOptions.TrivialComplexity || compiledCodeSize > 0 && compiledCodeSize < GraalOptions.TrivialCompiledCodeSize;
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
257 }
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
258
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
259 private static boolean canInlineRelevanceBased(double relevance, int bytecodeSize, int complexity, int compiledCodeSize) {
7686
149092d59dd0 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7685
diff changeset
260 return bytecodeSize < computeMaximumSize(relevance, GraalOptions.NormalBytecodeSize) || complexity < computeMaximumSize(relevance, GraalOptions.NormalComplexity) || compiledCodeSize > 0 &&
149092d59dd0 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7685
diff changeset
261 compiledCodeSize < computeMaximumSize(relevance, GraalOptions.NormalCompiledCodeSize);
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
262 }
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
263
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
264 private static double computeMaximumSize(double relevance, int configuredMaximum) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
265 double inlineRatio = Math.min(GraalOptions.RelevanceCapForInlining, relevance);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
266 return configuredMaximum * inlineRatio;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
267 }
7065
cfacf5d5bade fixed logging of inlining decisions
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7064
diff changeset
268
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
269 private static int numberOfTransferredValues(InlineInfo info) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
270 Signature signature = info.invoke().methodCallTarget().targetMethod().getSignature();
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
271 int transferredValues = signature.getParameterCount(!Modifier.isStatic(info.invoke().methodCallTarget().targetMethod().getModifiers()));
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
272 if (signature.getReturnKind() != Kind.Void) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
273 transferredValues++;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
274 }
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
275 return transferredValues;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
276 }
7065
cfacf5d5bade fixed logging of inlining decisions
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7064
diff changeset
277
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
278 private static int countInvokeUsages(InlineInfo info) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
279 // inlining calls with lots of usages simplifies the caller
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
280 int usages = 0;
7686
149092d59dd0 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7685
diff changeset
281 for (Node n : info.invoke().node().usages()) {
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
282 if (!(n instanceof FrameState)) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
283 usages++;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
284 }
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
285 }
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
286 return usages;
7065
cfacf5d5bade fixed logging of inlining decisions
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7064
diff changeset
287 }
cfacf5d5bade fixed logging of inlining decisions
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7064
diff changeset
288
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
289 private int countMoreSpecificArgumentInfo(InlineInfo info) {
7690
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
290 /*
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
291 * inlining invokes where the caller has very specific information about the passed
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
292 * argument simplifies the callee
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
293 */
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
294 int moreSpecificArgumentInfo = 0;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
295 boolean isStatic = info.invoke().methodCallTarget().isStatic();
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
296 int signatureOffset = isStatic ? 0 : 1;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
297 NodeInputList arguments = info.invoke().methodCallTarget().arguments();
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
298 ResolvedJavaMethod targetMethod = info.invoke().methodCallTarget().targetMethod();
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
299 ResolvedJavaType methodHolderClass = targetMethod.getDeclaringClass();
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
300 Signature signature = targetMethod.getSignature();
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
301
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
302 for (int i = 0; i < arguments.size(); i++) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
303 Node n = arguments.get(i);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
304 if (n instanceof ConstantNode) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
305 moreSpecificArgumentInfo++;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
306 } else if (n instanceof ValueNode && !((ValueNode) n).kind().isPrimitive()) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
307 ResolvedJavaType actualType = ((ValueNode) n).stamp().javaType(runtime);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
308 JavaType declaredType;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
309 if (i == 0 && !isStatic) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
310 declaredType = methodHolderClass;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
311 } else {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
312 declaredType = signature.getParameterType(i - signatureOffset, methodHolderClass);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
313 }
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
314
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
315 if (declaredType instanceof ResolvedJavaType && !actualType.equals(declaredType) && ((ResolvedJavaType) declaredType).isAssignableFrom(actualType)) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
316 moreSpecificArgumentInfo++;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
317 }
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
318 }
7685
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7684 7530
diff changeset
319
7388
599ea4fcdb6d added flag AlwaysInlineIntrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7256
diff changeset
320 }
599ea4fcdb6d added flag AlwaysInlineIntrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7256
diff changeset
321
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
322 return moreSpecificArgumentInfo;
4569
333ce00358f4 added another inlining policy, added option to disable propagation of loop frequencies
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4564
diff changeset
323 }
333ce00358f4 added another inlining policy, added option to disable propagation of loop frequencies
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4564
diff changeset
324
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
325 private static int bytecodeCodeSize(InlineInfo info) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
326 int result = 0;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
327 for (int i = 0; i < info.numberOfMethods(); i++) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
328 result += info.methodAt(i).getCodeSize();
7388
599ea4fcdb6d added flag AlwaysInlineIntrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7256
diff changeset
329 }
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
330 return result;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
331 }
7388
599ea4fcdb6d added flag AlwaysInlineIntrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7256
diff changeset
332
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
333 private static int compilationComplexity(InlineInfo info) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
334 int result = 0;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
335 for (int i = 0; i < info.numberOfMethods(); i++) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
336 result += info.methodAt(i).getCompilationComplexity();
4528
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4469
diff changeset
337 }
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
338 return result;
4528
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4469
diff changeset
339 }
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
340
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
341 private static int compiledCodeSize(InlineInfo info) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
342 int result = 0;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
343 for (int i = 0; i < info.numberOfMethods(); i++) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
344 result += info.methodAt(i).getCompiledCodeSize();
7388
599ea4fcdb6d added flag AlwaysInlineIntrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7256
diff changeset
345 }
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
346 return result;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
347 }
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
348
8636
ac4dbfecec8f passed a Replacements object to inlining utility methods that need one instead of the GraalRuntime API
Doug Simon <doug.simon@oracle.com>
parents: 8618
diff changeset
349 private static boolean onlyIntrinsics(Replacements replacements, InlineInfo info) {
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
350 for (int i = 0; i < info.numberOfMethods(); i++) {
8636
ac4dbfecec8f passed a Replacements object to inlining utility methods that need one instead of the GraalRuntime API
Doug Simon <doug.simon@oracle.com>
parents: 8618
diff changeset
351 if (!InliningUtil.canIntrinsify(replacements, info.methodAt(i))) {
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
352 return false;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
353 }
7388
599ea4fcdb6d added flag AlwaysInlineIntrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7256
diff changeset
354 }
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
355 return true;
7065
cfacf5d5bade fixed logging of inlining decisions
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7064
diff changeset
356 }
8915
880619fd6a67 allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents: 8618
diff changeset
357
8930
Lukas Stadler <lukas.stadler@jku.at>
parents: 8915 8637
diff changeset
358 private static boolean onlyForcedIntrinsics(Replacements replacements, InlineInfo info) {
8915
880619fd6a67 allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents: 8618
diff changeset
359 for (int i = 0; i < info.numberOfMethods(); i++) {
8930
Lukas Stadler <lukas.stadler@jku.at>
parents: 8915 8637
diff changeset
360 if (!InliningUtil.canIntrinsify(replacements, info.methodAt(i))) {
8915
880619fd6a67 allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents: 8618
diff changeset
361 return false;
880619fd6a67 allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents: 8618
diff changeset
362 }
880619fd6a67 allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents: 8618
diff changeset
363 if (!replacements.isForcedSubstitution(info.methodAt(i))) {
880619fd6a67 allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents: 8618
diff changeset
364 return false;
880619fd6a67 allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents: 8618
diff changeset
365 }
880619fd6a67 allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents: 8618
diff changeset
366 }
880619fd6a67 allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents: 8618
diff changeset
367 return true;
880619fd6a67 allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents: 8618
diff changeset
368 }
7065
cfacf5d5bade fixed logging of inlining decisions
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7064
diff changeset
369 }
cfacf5d5bade fixed logging of inlining decisions
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7064
diff changeset
370
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
371 private static class CFInliningPolicy implements InliningPolicy {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
372
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
373 private final InliningDecision inliningDecision;
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
374 private final Assumptions assumptions;
8636
ac4dbfecec8f passed a Replacements object to inlining utility methods that need one instead of the GraalRuntime API
Doug Simon <doug.simon@oracle.com>
parents: 8618
diff changeset
375 private final Replacements replacements;
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
376 private final OptimisticOptimizations optimisticOpts;
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
377 private final Deque<Invoke> sortedInvokes;
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
378 private NodeBitMap visitedFixedNodes;
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
379 private FixedNode invokePredecessor;
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
380
8636
ac4dbfecec8f passed a Replacements object to inlining utility methods that need one instead of the GraalRuntime API
Doug Simon <doug.simon@oracle.com>
parents: 8618
diff changeset
381 public CFInliningPolicy(InliningDecision inliningPolicy, Replacements replacements, Assumptions assumptions, OptimisticOptimizations optimisticOpts) {
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
382 this.inliningDecision = inliningPolicy;
8636
ac4dbfecec8f passed a Replacements object to inlining utility methods that need one instead of the GraalRuntime API
Doug Simon <doug.simon@oracle.com>
parents: 8618
diff changeset
383 this.replacements = replacements;
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
384 this.assumptions = assumptions;
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
385 this.optimisticOpts = optimisticOpts;
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
386 this.sortedInvokes = new ArrayDeque<>();
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
387 }
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
388
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
389 public boolean continueInlining(StructuredGraph graph) {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
390 if (graph.getNodeCount() >= GraalOptions.MaximumDesiredSize) {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
391 InliningUtil.logInliningDecision("inlining is cut off by MaximumDesiredSize");
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
392 metricInliningStoppedByMaxDesiredSize.increment();
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
393 return false;
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
394 }
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
395
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
396 return !sortedInvokes.isEmpty();
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
397 }
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
398
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
399 public InlineInfo next() {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
400 Invoke invoke = sortedInvokes.pop();
8636
ac4dbfecec8f passed a Replacements object to inlining utility methods that need one instead of the GraalRuntime API
Doug Simon <doug.simon@oracle.com>
parents: 8618
diff changeset
401 InlineInfo info = InliningUtil.getInlineInfo(invoke, replacements, assumptions, optimisticOpts);
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
402 if (info != null) {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
403 invokePredecessor = (FixedNode) info.invoke().predecessor();
7080
15055bdafbfc disabled control-flow-based inlining
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7068
diff changeset
404 assert invokePredecessor.isAlive();
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
405 }
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
406 return info;
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
407 }
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
408
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
409 public boolean isWorthInlining(InlineInfo info) {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
410 return inliningDecision.isWorthInlining(info);
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
411 }
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
412
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
413 public void initialize(StructuredGraph graph) {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
414 visitedFixedNodes = graph.createNodeBitMap(true);
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
415 scanGraphForInvokes(graph.start());
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
416 }
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
417
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
418 public void scanInvokes(Iterable<? extends Node> newNodes) {
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
419 assert invokePredecessor.isAlive();
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
420 int invokes = scanGraphForInvokes(invokePredecessor);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
421 assert invokes == countInvokes(newNodes);
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
422 }
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
423
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
424 private int scanGraphForInvokes(FixedNode start) {
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
425 ArrayList<Invoke> invokes = new InliningIterator(start, visitedFixedNodes).apply();
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
426
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
427 // insert the newly found invokes in their correct control-flow order
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
428 for (int i = invokes.size() - 1; i >= 0; i--) {
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
429 Invoke invoke = invokes.get(i);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
430 assert !sortedInvokes.contains(invoke);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
431 sortedInvokes.addFirst(invoke);
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
432
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
433 }
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
434
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
435 return invokes.size();
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
436 }
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
437
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
438 private static int countInvokes(Iterable<? extends Node> nodes) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
439 int count = 0;
7686
149092d59dd0 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7685
diff changeset
440 for (Node n : nodes) {
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
441 if (n instanceof Invoke) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
442 count++;
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
443 }
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
444 }
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
445 return count;
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
446 }
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
447 }
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
448
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
449 private static class InliningIterator {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
450
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
451 private final FixedNode start;
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
452 private final Deque<FixedNode> nodeQueue;
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
453 private final NodeBitMap queuedNodes;
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
454
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
455 public InliningIterator(FixedNode start, NodeBitMap visitedFixedNodes) {
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
456 this.start = start;
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
457 this.nodeQueue = new ArrayDeque<>();
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
458 this.queuedNodes = visitedFixedNodes;
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
459 assert start.isAlive();
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
460 }
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
461
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
462 public ArrayList<Invoke> apply() {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
463 ArrayList<Invoke> invokes = new ArrayList<>();
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
464 FixedNode current;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
465 forcedQueue(start);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
466
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
467 while ((current = nextQueuedNode()) != null) {
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
468 assert current.isAlive();
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
469
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
470 if (current instanceof Invoke) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
471 if (current != start) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
472 invokes.add((Invoke) current);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
473 }
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
474 queueSuccessors(current);
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
475 } else if (current instanceof LoopBeginNode) {
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
476 queueSuccessors(current);
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
477 } else if (current instanceof LoopEndNode) {
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
478 // nothing todo
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
479 } else if (current instanceof MergeNode) {
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
480 queueSuccessors(current);
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
481 } else if (current instanceof FixedWithNextNode) {
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
482 queueSuccessors(current);
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
483 } else if (current instanceof EndNode) {
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
484 queueMerge((EndNode) current);
8385
85d4392b9e26 Introduce a ControlSinkNode base class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7879
diff changeset
485 } else if (current instanceof ControlSinkNode) {
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
486 // nothing todo
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
487 } else if (current instanceof ControlSplitNode) {
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
488 queueSuccessors(current);
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
489 } else {
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
490 assert false : current;
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
491 }
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
492 }
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
493
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
494 return invokes;
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
495 }
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
496
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
497 private void queueSuccessors(FixedNode x) {
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
498 for (Node node : x.successors()) {
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
499 queue(node);
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
500 }
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
501 }
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
502
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
503 private void queue(Node node) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
504 if (node != null && !queuedNodes.isMarked(node)) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
505 forcedQueue(node);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
506 }
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
507 }
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
508
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
509 private void forcedQueue(Node node) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
510 queuedNodes.mark(node);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
511 nodeQueue.addFirst((FixedNode) node);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
512 }
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
513
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
514 private FixedNode nextQueuedNode() {
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
515 if (nodeQueue.isEmpty()) {
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
516 return null;
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
517 }
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
518
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
519 FixedNode result = nodeQueue.removeFirst();
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
520 assert queuedNodes.isMarked(result);
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
521 return result;
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
522 }
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
523
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
524 private void queueMerge(EndNode end) {
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
525 MergeNode merge = end.merge();
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
526 if (!queuedNodes.isMarked(merge) && visitedAllEnds(merge)) {
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
527 queuedNodes.mark(merge);
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
528 nodeQueue.add(merge);
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
529 }
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
530 }
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
531
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
532 private boolean visitedAllEnds(MergeNode merge) {
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
533 for (int i = 0; i < merge.forwardEndCount(); i++) {
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
534 if (!queuedNodes.isMarked(merge.forwardEndAt(i))) {
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
535 return false;
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
536 }
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
537 }
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
538 return true;
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
539 }
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
540 }
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
541
8636
ac4dbfecec8f passed a Replacements object to inlining utility methods that need one instead of the GraalRuntime API
Doug Simon <doug.simon@oracle.com>
parents: 8618
diff changeset
542 private static InliningPolicy createInliningPolicy(MetaAccessProvider runtime, Replacements replacements, Assumptions assumptions, OptimisticOptimizations optimisticOpts, Map<Invoke, Double> hints) {
ac4dbfecec8f passed a Replacements object to inlining utility methods that need one instead of the GraalRuntime API
Doug Simon <doug.simon@oracle.com>
parents: 8618
diff changeset
543 InliningDecision inliningDecision = new GreedySizeBasedInliningDecision(runtime, replacements, hints);
ac4dbfecec8f passed a Replacements object to inlining utility methods that need one instead of the GraalRuntime API
Doug Simon <doug.simon@oracle.com>
parents: 8618
diff changeset
544 return new CFInliningPolicy(inliningDecision, replacements, assumptions, optimisticOpts);
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
545 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
546 }