annotate graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningPhase.java @ 9203:f78437ffb8d3

Restructure class hierarchy of LocationNode.
author Roland Schatz <roland.schatz@oracle.com>
date Mon, 22 Apr 2013 10:30:06 +0200
parents 07f05f2a8149
children b9cf7d0b598e
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.*;
9147
07f05f2a8149 Remove methodCallTarget() method from the Invoke interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9091
diff changeset
34 import com.oracle.graal.nodes.java.*;
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
35 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
36 import com.oracle.graal.phases.*;
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
37 import com.oracle.graal.phases.PhasePlan.PhasePosition;
7307
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
38 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
39 import com.oracle.graal.phases.common.InliningUtil.InlineInfo;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
40 import com.oracle.graal.phases.common.InliningUtil.InliningCallback;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
41 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
42
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
43 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
44
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45 /*
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
46 * - 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
47 * 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
48 * 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
49 * invoke.bci, method, true);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
50 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
51
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
52 private final PhasePlan plan;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53
8608
056966f39a36 changed parameters of InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 8385
diff changeset
54 private final MetaAccessProvider runtime;
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
55 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
56 private final Replacements replacements;
5718
10341299528c renamings: ExtendedRiRuntime -> GraalCodeCacheProvider, CiLoweringTool -> LoweringTool, RiGraphCache -> GraphCache
Doug Simon <doug.simon@oracle.com>
parents: 5674
diff changeset
57 private final GraphCache cache;
4468
87a12a816e99 added C1 inlining policy for comparison, bugfixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
58 private final InliningPolicy inliningPolicy;
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
59 private final OptimisticOptimizations optimisticOpts;
7307
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
60 private CustomCanonicalizer customCanonicalizer;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
61
8548
51d5999900e2 simple iterative inlining, simple read elimination in PEA
Lukas Stadler <lukas.stadler@jku.at>
parents: 8385
diff changeset
62 private int inliningCount;
51d5999900e2 simple iterative inlining, simple read elimination in PEA
Lukas Stadler <lukas.stadler@jku.at>
parents: 8385
diff changeset
63
51d5999900e2 simple iterative inlining, simple read elimination in PEA
Lukas Stadler <lukas.stadler@jku.at>
parents: 8385
diff changeset
64 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
65
4348
d49c90e641cb Remove GraalMetrics, replace with new syntax for metrics.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4205
diff changeset
66 // Metrics
4356
249752adcb8d Rename Timer DebugTimer and Metric DebugMetric.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4352
diff changeset
67 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
68 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
69 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
70 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
71
8930
Lukas Stadler <lukas.stadler@jku.at>
parents: 8915 8637
diff changeset
72 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
73 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
74 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
75 }
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
76
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
77 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
78 OptimisticOptimizations optimisticOpts) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
79 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
80 this.replacements = replacements;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
81 this.assumptions = assumptions;
5177
a26b6248d398 added graph caching (-G:+CacheGraphs)
Lukas Stadler <lukas.stadler@jku.at>
parents: 5114
diff changeset
82 this.cache = cache;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
83 this.plan = plan;
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
84 this.inliningPolicy = inliningPolicy;
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
85 this.optimisticOpts = optimisticOpts;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
86 }
8618
832b9a115a2d style fixes
Christian Haeubl <haeubl@ssw.jku.at>
parents: 8617
diff changeset
87
8617
Christian Haeubl <haeubl@ssw.jku.at>
parents: 8608 8552
diff changeset
88 public void setCustomCanonicalizer(CustomCanonicalizer customCanonicalizer) {
Christian Haeubl <haeubl@ssw.jku.at>
parents: 8608 8552
diff changeset
89 this.customCanonicalizer = customCanonicalizer;
Christian Haeubl <haeubl@ssw.jku.at>
parents: 8608 8552
diff changeset
90 }
8618
832b9a115a2d style fixes
Christian Haeubl <haeubl@ssw.jku.at>
parents: 8617
diff changeset
91
8617
Christian Haeubl <haeubl@ssw.jku.at>
parents: 8608 8552
diff changeset
92 public void setMaxMethodsPerInlining(int max) {
Christian Haeubl <haeubl@ssw.jku.at>
parents: 8608 8552
diff changeset
93 maxMethodPerInlining = max;
Christian Haeubl <haeubl@ssw.jku.at>
parents: 8608 8552
diff changeset
94 }
8618
832b9a115a2d style fixes
Christian Haeubl <haeubl@ssw.jku.at>
parents: 8617
diff changeset
95
8548
51d5999900e2 simple iterative inlining, simple read elimination in PEA
Lukas Stadler <lukas.stadler@jku.at>
parents: 8385
diff changeset
96 public int getInliningCount() {
51d5999900e2 simple iterative inlining, simple read elimination in PEA
Lukas Stadler <lukas.stadler@jku.at>
parents: 8385
diff changeset
97 return inliningCount;
51d5999900e2 simple iterative inlining, simple read elimination in PEA
Lukas Stadler <lukas.stadler@jku.at>
parents: 8385
diff changeset
98 }
51d5999900e2 simple iterative inlining, simple read elimination in PEA
Lukas Stadler <lukas.stadler@jku.at>
parents: 8385
diff changeset
99
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
100 @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
101 protected void run(final StructuredGraph graph) {
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
102 inliningPolicy.initialize(graph);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
103
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
104 while (inliningPolicy.continueInlining(graph)) {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
105 final InlineInfo candidate = inliningPolicy.next();
7391
36dafe48bc38 added relevance-based inlining
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7388
diff changeset
106
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
107 if (candidate != null) {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
108 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
109 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
110
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
111 metricInliningConsidered.increment();
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
112 if (isWorthInlining) {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
113 int mark = graph.getMark();
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
114 try {
9089
5ab06146e985 Rename "node()" methods in interfaces to "asNode"
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8930
diff changeset
115 List<Node> invokeUsages = candidate.invoke().asNode().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
116 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
117 Debug.dump(graph, "after %s", candidate);
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
118 Iterable<Node> newNodes = graph.getNewNodes(mark);
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
119 inliningPolicy.scanInvokes(newNodes);
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
120 if (GraalOptions.OptCanonicalizer) {
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 8930
diff changeset
121 new CanonicalizerPhase.Instance(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
122 }
8548
51d5999900e2 simple iterative inlining, simple read elimination in PEA
Lukas Stadler <lukas.stadler@jku.at>
parents: 8385
diff changeset
123 inliningCount++;
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
124 metricInliningPerformed.increment();
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
125 } catch (BailoutException bailout) {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
126 throw bailout;
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
127 } catch (AssertionError e) {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
128 throw new GraalInternalError(e).addContext(candidate.toString());
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
129 } catch (RuntimeException e) {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
130 throw new GraalInternalError(e).addContext(candidate.toString());
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
131 } catch (GraalInternalError e) {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
132 throw e.addContext(candidate.toString());
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
133 }
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
134 } else if (optimisticOpts.devirtualizeInvokes()) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
135 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
136 }
3733
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
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
141 @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
142 public StructuredGraph buildGraph(final ResolvedJavaMethod method) {
6353
2590d9cc3b6d remove unnecessary debug scope during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 5788
diff changeset
143 metricInliningRuns.increment();
2590d9cc3b6d remove unnecessary debug scope during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 5788
diff changeset
144 if (GraalOptions.CacheGraphs && cache != null) {
2590d9cc3b6d remove unnecessary debug scope during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 5788
diff changeset
145 StructuredGraph cachedGraph = cache.get(method);
2590d9cc3b6d remove unnecessary debug scope during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 5788
diff changeset
146 if (cachedGraph != null) {
2590d9cc3b6d remove unnecessary debug scope during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 5788
diff changeset
147 return cachedGraph;
2590d9cc3b6d remove unnecessary debug scope during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 5788
diff changeset
148 }
2590d9cc3b6d remove unnecessary debug scope during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 5788
diff changeset
149 }
7879
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
150 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
151 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
152
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
153 @Override
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
154 public StructuredGraph call() throws Exception {
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
155 if (plan != null) {
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
156 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
157 }
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
158 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
159
7879
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
160 if (GraalOptions.ProbabilityAnalysis) {
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
161 new DeadCodeEliminationPhase().apply(newGraph);
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
162 new ComputeProbabilityPhase().apply(newGraph);
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
163 }
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
164 if (GraalOptions.OptCanonicalizer) {
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 8930
diff changeset
165 new CanonicalizerPhase.Instance(runtime, assumptions).apply(newGraph);
7879
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
166 }
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
167 if (GraalOptions.CullFrameStates) {
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
168 new CullFrameStatesPhase().apply(newGraph);
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
169 }
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
170 if (GraalOptions.CacheGraphs && cache != null) {
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
171 cache.put(newGraph);
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
172 }
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
173 return newGraph;
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
174 }
1474fe91323c create debug scope for graph building during inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
175 });
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
176 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
177
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
178 private interface InliningDecision {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
179
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
180 boolean isWorthInlining(InlineInfo info);
4670
41034914e2ee add MethodContents assumption to fix debbugging issue
Lukas Stadler <lukas.stadler@jku.at>
parents: 4598
diff changeset
181 }
41034914e2ee add MethodContents assumption to fix debbugging issue
Lukas Stadler <lukas.stadler@jku.at>
parents: 4598
diff changeset
182
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
183 private static class GreedySizeBasedInliningDecision implements InliningDecision {
7686
149092d59dd0 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7685
diff changeset
184
8608
056966f39a36 changed parameters of InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 8385
diff changeset
185 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
186 private final Replacements replacements;
8552
31b7a648b4b3 turn inlining hints into a map
Lukas Stadler <lukas.stadler@jku.at>
parents: 8548
diff changeset
187 private final Map<Invoke, Double> hints;
4594
eb6df44a1374 bugfixes, added bytecode complexity estimation
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4591
diff changeset
188
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
189 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
190 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
191 this.replacements = replacements;
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
192 this.hints = hints;
4594
eb6df44a1374 bugfixes, added bytecode complexity estimation
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4591
diff changeset
193 }
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
194
4594
eb6df44a1374 bugfixes, added bytecode complexity estimation
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4591
diff changeset
195 @Override
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
196 public boolean isWorthInlining(InlineInfo info) {
4594
eb6df44a1374 bugfixes, added bytecode complexity estimation
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4591
diff changeset
197 assert GraalOptions.ProbabilityAnalysis;
7690
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
198 /*
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
199 * 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
200 * 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
201 * 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
202 * also getting queued in the compilation queue concurrently)
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
203 */
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
204
8915
880619fd6a67 allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents: 8618
diff changeset
205 if (GraalOptions.AlwaysInlineIntrinsics) {
8930
Lukas Stadler <lukas.stadler@jku.at>
parents: 8915 8637
diff changeset
206 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
207 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
208 }
880619fd6a67 allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents: 8618
diff changeset
209 } else {
8930
Lukas Stadler <lukas.stadler@jku.at>
parents: 8915 8637
diff changeset
210 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
211 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
212 }
4594
eb6df44a1374 bugfixes, added bytecode complexity estimation
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4591
diff changeset
213 }
eb6df44a1374 bugfixes, added bytecode complexity estimation
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4591
diff changeset
214
8552
31b7a648b4b3 turn inlining hints into a map
Lukas Stadler <lukas.stadler@jku.at>
parents: 8548
diff changeset
215 double bonus = 1;
31b7a648b4b3 turn inlining hints into a map
Lukas Stadler <lukas.stadler@jku.at>
parents: 8548
diff changeset
216 if (hints != null && hints.containsKey(info.invoke())) {
31b7a648b4b3 turn inlining hints into a map
Lukas Stadler <lukas.stadler@jku.at>
parents: 8548
diff changeset
217 bonus = hints.get(info.invoke());
31b7a648b4b3 turn inlining hints into a map
Lukas Stadler <lukas.stadler@jku.at>
parents: 8548
diff changeset
218 }
8548
51d5999900e2 simple iterative inlining, simple read elimination in PEA
Lukas Stadler <lukas.stadler@jku.at>
parents: 8385
diff changeset
219
8552
31b7a648b4b3 turn inlining hints into a map
Lukas Stadler <lukas.stadler@jku.at>
parents: 8548
diff changeset
220 int bytecodeSize = (int) (bytecodeCodeSize(info) / bonus);
31b7a648b4b3 turn inlining hints into a map
Lukas Stadler <lukas.stadler@jku.at>
parents: 8548
diff changeset
221 int complexity = (int) (compilationComplexity(info) / bonus);
31b7a648b4b3 turn inlining hints into a map
Lukas Stadler <lukas.stadler@jku.at>
parents: 8548
diff changeset
222 int compiledCodeSize = (int) (compiledCodeSize(info) / bonus);
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
223 double relevance = info.invoke().inliningRelevance();
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
224
7690
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
225 /*
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
226 * 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
227 * 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
228 */
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
229 if (compiledCodeSize < GraalOptions.SmallCompiledCodeSize) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
230 if (isTrivialInlining(bytecodeSize, complexity, compiledCodeSize)) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
231 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
232 }
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
233
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
234 if (canInlineRelevanceBased(relevance, bytecodeSize, complexity, compiledCodeSize)) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
235 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
236 }
5021
a7c079d5dc87 try to reduce MaximumGreedyInlineSize significantly
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5019
diff changeset
237 }
a7c079d5dc87 try to reduce MaximumGreedyInlineSize significantly
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5019
diff changeset
238
7690
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
239 /*
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
240 * 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
241 * should still do the inlining
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
242 */
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
243 double probability = info.invoke().probability();
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
244 int transferredValues = numberOfTransferredValues(info);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
245 int invokeUsages = countInvokeUsages(info);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
246 int moreSpecificArguments = countMoreSpecificArgumentInfo(info);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
247 int level = info.level();
5005
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4993
diff changeset
248
7686
149092d59dd0 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7685
diff changeset
249 // 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
250
7686
149092d59dd0 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7685
diff changeset
251 return InliningUtil.logNotInlinedMethod(info,
8552
31b7a648b4b3 turn inlining hints into a map
Lukas Stadler <lukas.stadler@jku.at>
parents: 8548
diff changeset
252 "(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
253 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
254 }
eb6df44a1374 bugfixes, added bytecode complexity estimation
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4591
diff changeset
255
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
256 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
257 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
258 }
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
259
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
260 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
261 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
262 compiledCodeSize < computeMaximumSize(relevance, GraalOptions.NormalCompiledCodeSize);
7684
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
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
265 private static double computeMaximumSize(double relevance, int configuredMaximum) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
266 double inlineRatio = Math.min(GraalOptions.RelevanceCapForInlining, relevance);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
267 return configuredMaximum * inlineRatio;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
268 }
7065
cfacf5d5bade fixed logging of inlining decisions
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7064
diff changeset
269
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
270 private static int numberOfTransferredValues(InlineInfo info) {
9147
07f05f2a8149 Remove methodCallTarget() method from the Invoke interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9091
diff changeset
271 MethodCallTargetNode methodCallTargetNode = ((MethodCallTargetNode) info.invoke().callTarget());
07f05f2a8149 Remove methodCallTarget() method from the Invoke interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9091
diff changeset
272 Signature signature = methodCallTargetNode.targetMethod().getSignature();
07f05f2a8149 Remove methodCallTarget() method from the Invoke interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9091
diff changeset
273 int transferredValues = signature.getParameterCount(!Modifier.isStatic(methodCallTargetNode.targetMethod().getModifiers()));
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
274 if (signature.getReturnKind() != Kind.Void) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
275 transferredValues++;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
276 }
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
277 return transferredValues;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
278 }
7065
cfacf5d5bade fixed logging of inlining decisions
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7064
diff changeset
279
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
280 private static int countInvokeUsages(InlineInfo info) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
281 // 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
282 int usages = 0;
9089
5ab06146e985 Rename "node()" methods in interfaces to "asNode"
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8930
diff changeset
283 for (Node n : info.invoke().asNode().usages()) {
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
284 if (!(n instanceof FrameState)) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
285 usages++;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
286 }
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
287 }
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
288 return usages;
7065
cfacf5d5bade fixed logging of inlining decisions
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7064
diff changeset
289 }
cfacf5d5bade fixed logging of inlining decisions
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7064
diff changeset
290
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
291 private int countMoreSpecificArgumentInfo(InlineInfo info) {
7690
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
292 /*
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
293 * 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
294 * argument simplifies the callee
afa802ff433c better computation of inlining relevance
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7689
diff changeset
295 */
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
296 int moreSpecificArgumentInfo = 0;
9147
07f05f2a8149 Remove methodCallTarget() method from the Invoke interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9091
diff changeset
297 MethodCallTargetNode methodCallTarget = (MethodCallTargetNode) info.invoke().callTarget();
07f05f2a8149 Remove methodCallTarget() method from the Invoke interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9091
diff changeset
298 boolean isStatic = methodCallTarget.isStatic();
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
299 int signatureOffset = isStatic ? 0 : 1;
9147
07f05f2a8149 Remove methodCallTarget() method from the Invoke interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9091
diff changeset
300 NodeInputList arguments = methodCallTarget.arguments();
07f05f2a8149 Remove methodCallTarget() method from the Invoke interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9091
diff changeset
301 ResolvedJavaMethod targetMethod = methodCallTarget.targetMethod();
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
302 ResolvedJavaType methodHolderClass = targetMethod.getDeclaringClass();
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
303 Signature signature = targetMethod.getSignature();
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
304
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
305 for (int i = 0; i < arguments.size(); i++) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
306 Node n = arguments.get(i);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
307 if (n instanceof ConstantNode) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
308 moreSpecificArgumentInfo++;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
309 } 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
310 ResolvedJavaType actualType = ((ValueNode) n).stamp().javaType(runtime);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
311 JavaType declaredType;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
312 if (i == 0 && !isStatic) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
313 declaredType = methodHolderClass;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
314 } else {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
315 declaredType = signature.getParameterType(i - signatureOffset, methodHolderClass);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
316 }
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 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
319 moreSpecificArgumentInfo++;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
320 }
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
321 }
7685
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7684 7530
diff changeset
322
7388
599ea4fcdb6d added flag AlwaysInlineIntrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7256
diff changeset
323 }
599ea4fcdb6d added flag AlwaysInlineIntrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7256
diff changeset
324
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
325 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
326 }
333ce00358f4 added another inlining policy, added option to disable propagation of loop frequencies
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4564
diff changeset
327
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
328 private static int bytecodeCodeSize(InlineInfo info) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
329 int result = 0;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
330 for (int i = 0; i < info.numberOfMethods(); i++) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
331 result += info.methodAt(i).getCodeSize();
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 return result;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
334 }
7388
599ea4fcdb6d added flag AlwaysInlineIntrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7256
diff changeset
335
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
336 private static int compilationComplexity(InlineInfo info) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
337 int result = 0;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
338 for (int i = 0; i < info.numberOfMethods(); i++) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
339 result += info.methodAt(i).getCompilationComplexity();
4528
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4469
diff changeset
340 }
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
341 return result;
4528
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4469
diff changeset
342 }
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
343
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
344 private static int compiledCodeSize(InlineInfo info) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
345 int result = 0;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
346 for (int i = 0; i < info.numberOfMethods(); i++) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
347 result += info.methodAt(i).getCompiledCodeSize();
7388
599ea4fcdb6d added flag AlwaysInlineIntrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7256
diff changeset
348 }
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
349 return result;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
350 }
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
351
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
352 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
353 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
354 if (!InliningUtil.canIntrinsify(replacements, info.methodAt(i))) {
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
355 return false;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
356 }
7388
599ea4fcdb6d added flag AlwaysInlineIntrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7256
diff changeset
357 }
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
358 return true;
7065
cfacf5d5bade fixed logging of inlining decisions
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7064
diff changeset
359 }
8915
880619fd6a67 allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents: 8618
diff changeset
360
8930
Lukas Stadler <lukas.stadler@jku.at>
parents: 8915 8637
diff changeset
361 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
362 for (int i = 0; i < info.numberOfMethods(); i++) {
8930
Lukas Stadler <lukas.stadler@jku.at>
parents: 8915 8637
diff changeset
363 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
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 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
367 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
368 }
880619fd6a67 allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents: 8618
diff changeset
369 }
880619fd6a67 allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents: 8618
diff changeset
370 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
371 }
7065
cfacf5d5bade fixed logging of inlining decisions
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7064
diff changeset
372 }
cfacf5d5bade fixed logging of inlining decisions
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7064
diff changeset
373
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
374 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
375
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
376 private final InliningDecision inliningDecision;
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
377 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
378 private final Replacements replacements;
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
379 private final OptimisticOptimizations optimisticOpts;
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
380 private final Deque<Invoke> sortedInvokes;
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
381 private NodeBitMap visitedFixedNodes;
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
382 private FixedNode invokePredecessor;
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
383
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
384 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
385 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
386 this.replacements = replacements;
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
387 this.assumptions = assumptions;
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
388 this.optimisticOpts = optimisticOpts;
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
389 this.sortedInvokes = new ArrayDeque<>();
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
390 }
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
391
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
392 public boolean continueInlining(StructuredGraph graph) {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
393 if (graph.getNodeCount() >= GraalOptions.MaximumDesiredSize) {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
394 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
395 metricInliningStoppedByMaxDesiredSize.increment();
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
396 return false;
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 return !sortedInvokes.isEmpty();
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
400 }
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
401
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
402 public InlineInfo next() {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
403 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
404 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
405 if (info != null) {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
406 invokePredecessor = (FixedNode) info.invoke().predecessor();
7080
15055bdafbfc disabled control-flow-based inlining
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7068
diff changeset
407 assert invokePredecessor.isAlive();
7064
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 return info;
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
410 }
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 public boolean isWorthInlining(InlineInfo info) {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
413 return inliningDecision.isWorthInlining(info);
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
414 }
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
415
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
416 public void initialize(StructuredGraph graph) {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
417 visitedFixedNodes = graph.createNodeBitMap(true);
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
418 scanGraphForInvokes(graph.start());
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
419 }
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
420
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
421 public void scanInvokes(Iterable<? extends Node> newNodes) {
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
422 assert invokePredecessor.isAlive();
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
423 int invokes = scanGraphForInvokes(invokePredecessor);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
424 assert invokes == countInvokes(newNodes);
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
425 }
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
426
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
427 private int scanGraphForInvokes(FixedNode start) {
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
428 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
429
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
430 // 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
431 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
432 Invoke invoke = invokes.get(i);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
433 assert !sortedInvokes.contains(invoke);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
434 sortedInvokes.addFirst(invoke);
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
435
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 return invokes.size();
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
439 }
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
440
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
441 private static int countInvokes(Iterable<? extends Node> nodes) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
442 int count = 0;
7686
149092d59dd0 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7685
diff changeset
443 for (Node n : nodes) {
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
444 if (n instanceof Invoke) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
445 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 }
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
448 return count;
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
449 }
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
450 }
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
451
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
452 private static class InliningIterator {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
453
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
454 private final FixedNode start;
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
455 private final Deque<FixedNode> nodeQueue;
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
456 private final NodeBitMap queuedNodes;
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
457
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
458 public InliningIterator(FixedNode start, NodeBitMap visitedFixedNodes) {
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
459 this.start = start;
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
460 this.nodeQueue = new ArrayDeque<>();
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
461 this.queuedNodes = visitedFixedNodes;
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
462 assert start.isAlive();
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
463 }
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
464
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
465 public ArrayList<Invoke> apply() {
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
466 ArrayList<Invoke> invokes = new ArrayList<>();
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
467 FixedNode current;
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
468 forcedQueue(start);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
469
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
470 while ((current = nextQueuedNode()) != null) {
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
471 assert current.isAlive();
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
472
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
473 if (current instanceof Invoke) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
474 if (current != start) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
475 invokes.add((Invoke) current);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
476 }
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
477 queueSuccessors(current);
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
478 } else if (current instanceof LoopBeginNode) {
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
479 queueSuccessors(current);
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
480 } else if (current instanceof LoopEndNode) {
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
481 // nothing todo
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
482 } else if (current instanceof MergeNode) {
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
483 queueSuccessors(current);
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
484 } else if (current instanceof FixedWithNextNode) {
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
485 queueSuccessors(current);
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
486 } else if (current instanceof EndNode) {
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
487 queueMerge((EndNode) current);
8385
85d4392b9e26 Introduce a ControlSinkNode base class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7879
diff changeset
488 } else if (current instanceof ControlSinkNode) {
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
489 // nothing todo
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
490 } else if (current instanceof ControlSplitNode) {
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
491 queueSuccessors(current);
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
492 } else {
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
493 assert false : current;
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
494 }
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
495 }
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
496
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
497 return invokes;
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
498 }
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
499
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
500 private void queueSuccessors(FixedNode x) {
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
501 for (Node node : x.successors()) {
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
502 queue(node);
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
503 }
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
504 }
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
505
7684
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
506 private void queue(Node node) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
507 if (node != null && !queuedNodes.isMarked(node)) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
508 forcedQueue(node);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
509 }
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
510 }
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
511
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
512 private void forcedQueue(Node node) {
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
513 queuedNodes.mark(node);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
514 nodeQueue.addFirst((FixedNode) node);
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
515 }
bbf97d6688d3 cleanup for the inlining policies
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7392
diff changeset
516
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
517 private FixedNode nextQueuedNode() {
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
518 if (nodeQueue.isEmpty()) {
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
519 return null;
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
520 }
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
521
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
522 FixedNode result = nodeQueue.removeFirst();
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
523 assert queuedNodes.isMarked(result);
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
524 return result;
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
525 }
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
526
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
527 private void queueMerge(EndNode end) {
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
528 MergeNode merge = end.merge();
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
529 if (!queuedNodes.isMarked(merge) && visitedAllEnds(merge)) {
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
530 queuedNodes.mark(merge);
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
531 nodeQueue.add(merge);
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
532 }
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
533 }
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
534
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
535 private boolean visitedAllEnds(MergeNode merge) {
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
536 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
537 if (!queuedNodes.isMarked(merge.forwardEndAt(i))) {
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
538 return false;
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
539 }
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
540 }
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
541 return true;
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
542 }
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7063
diff changeset
543 }
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
544
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
545 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
546 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
547 return new CFInliningPolicy(inliningDecision, replacements, assumptions, optimisticOpts);
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
548 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
549 }