annotate graal/GraalCompiler/src/com/sun/c1x/graph/IR.java @ 2842:7596ae867a7b

basic inlining passes all tests, including optimistic inlining
author Lukas Stadler <lukas.stadler@jku.at>
date Wed, 01 Jun 2011 16:26:17 +0200
parents 633e66de40fe
children a97605b0489b 7f14e6b48a9c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
1 /*
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
4 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
7 * published by the Free Software Foundation.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
8 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
13 * accompanied this code).
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
14 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
18 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
21 * questions.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
22 */
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
23 package com.sun.c1x.graph;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
24
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
25 import java.lang.reflect.*;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
26 import java.util.*;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
27
2801
2af109bec0c0 Make block contains a list of nodes instead a list of instructions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2789
diff changeset
28 import com.oracle.graal.graph.*;
2744
45a58c9536de Added BFS node iteration. Started drafting scheduling.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2736
diff changeset
29 import com.oracle.max.graal.schedule.*;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
30 import com.sun.c1x.*;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
31 import com.sun.c1x.debug.*;
2807
50b5db2c3e68 Fix for degenerated phis. Now jtt and DaCapo/fop passes with ArithmeticOp and Constant being flexible in the graph.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2805
diff changeset
32 import com.sun.c1x.gen.*;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
33 import com.sun.c1x.ir.*;
2718
c1ce2a53d6c3 Attempt to remove dependency between backend and BlockBegin.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2716
diff changeset
34 import com.sun.c1x.lir.*;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
35 import com.sun.c1x.observer.*;
2840
75e0d39833a0 new CompilerGraph, create only one Return and one Unwind per CompilerGraph
Lukas Stadler <lukas.stadler@jku.at>
parents: 2835
diff changeset
36 import com.sun.c1x.value.*;
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
37 import com.sun.cri.ci.*;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
38 import com.sun.cri.ri.*;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
39
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
40 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
41 * This class implements the overall container for the HIR (high-level IR) graph
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
42 * and directs its construction, optimization, and finalization.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
43 */
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
44 public class IR {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
45
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
46 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
47 * The compilation associated with this IR.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
48 */
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
49 public final C1XCompilation compilation;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
50
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
51 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
52 * The start block of this IR.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
53 */
2718
c1ce2a53d6c3 Attempt to remove dependency between backend and BlockBegin.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2716
diff changeset
54 public LIRBlock startBlock;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
55
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
56 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
57 * The linear-scan ordered list of blocks.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
58 */
2718
c1ce2a53d6c3 Attempt to remove dependency between backend and BlockBegin.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2716
diff changeset
59 private List<LIRBlock> orderedBlocks;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
60
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
61 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
62 * Creates a new IR instance for the specified compilation.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
63 * @param compilation the compilation
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
64 */
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
65 public IR(C1XCompilation compilation) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
66 this.compilation = compilation;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
67 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
68
2801
2af109bec0c0 Make block contains a list of nodes instead a list of instructions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2789
diff changeset
69 public Map<Node, LIRBlock> valueToBlock;
2759
b72e6638b9e6 Removed the link from BlockBegin to LIRBlock.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2756
diff changeset
70
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
71 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
72 * Builds the graph, optimizes it, and computes the linear scan block order.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
73 */
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
74 public void build() {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
75 if (C1XOptions.PrintTimers) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
76 C1XTimers.HIR_CREATE.start();
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
77 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
78
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
79 buildGraph();
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
80
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
81 if (C1XOptions.PrintTimers) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
82 C1XTimers.HIR_CREATE.stop();
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
83 C1XTimers.HIR_OPTIMIZE.start();
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
84 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
85
2807
50b5db2c3e68 Fix for degenerated phis. Now jtt and DaCapo/fop passes with ArithmeticOp and Constant being flexible in the graph.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2805
diff changeset
86 new PhiSimplifier(this);
2834
bfce42cd9c07 Graph duplication now passes all tests
Lukas Stadler <lukas.stadler@jku.at>
parents: 2827
diff changeset
87
bfce42cd9c07 Graph duplication now passes all tests
Lukas Stadler <lukas.stadler@jku.at>
parents: 2827
diff changeset
88 // Graph newGraph = new Graph();
bfce42cd9c07 Graph duplication now passes all tests
Lukas Stadler <lukas.stadler@jku.at>
parents: 2827
diff changeset
89 // HashMap<Node, Node> replacement = new HashMap<Node, Node>();
bfce42cd9c07 Graph duplication now passes all tests
Lukas Stadler <lukas.stadler@jku.at>
parents: 2827
diff changeset
90 // replacement.put(compilation.graph.start(), newGraph.start());
bfce42cd9c07 Graph duplication now passes all tests
Lukas Stadler <lukas.stadler@jku.at>
parents: 2827
diff changeset
91 // replacement.put(compilation.graph.end(), newGraph.end());
bfce42cd9c07 Graph duplication now passes all tests
Lukas Stadler <lukas.stadler@jku.at>
parents: 2827
diff changeset
92 // newGraph.addDuplicate(compilation.graph.getNodes(), replacement);
bfce42cd9c07 Graph duplication now passes all tests
Lukas Stadler <lukas.stadler@jku.at>
parents: 2827
diff changeset
93 // compilation.graph = newGraph;
bfce42cd9c07 Graph duplication now passes all tests
Lukas Stadler <lukas.stadler@jku.at>
parents: 2827
diff changeset
94
2838
adc4b3ec0a8c Deleted LIR critical edge splitter and replaced with GraalIR edge splitter using Anchor nodes (=> simpler).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2835
diff changeset
95 Graph graph = compilation.graph;
adc4b3ec0a8c Deleted LIR critical edge splitter and replaced with GraalIR edge splitter using Anchor nodes (=> simpler).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2835
diff changeset
96
adc4b3ec0a8c Deleted LIR critical edge splitter and replaced with GraalIR edge splitter using Anchor nodes (=> simpler).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2835
diff changeset
97 // Split critical edges.
adc4b3ec0a8c Deleted LIR critical edge splitter and replaced with GraalIR edge splitter using Anchor nodes (=> simpler).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2835
diff changeset
98 List<Node> nodes = graph.getNodes();
adc4b3ec0a8c Deleted LIR critical edge splitter and replaced with GraalIR edge splitter using Anchor nodes (=> simpler).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2835
diff changeset
99 for (int i = 0; i < nodes.size(); ++i) {
adc4b3ec0a8c Deleted LIR critical edge splitter and replaced with GraalIR edge splitter using Anchor nodes (=> simpler).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2835
diff changeset
100 Node n = nodes.get(i);
adc4b3ec0a8c Deleted LIR critical edge splitter and replaced with GraalIR edge splitter using Anchor nodes (=> simpler).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2835
diff changeset
101 if (Schedule.trueSuccessorCount(n) > 1) {
adc4b3ec0a8c Deleted LIR critical edge splitter and replaced with GraalIR edge splitter using Anchor nodes (=> simpler).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2835
diff changeset
102 for (int j = 0; j < n.successors().size(); ++j) {
adc4b3ec0a8c Deleted LIR critical edge splitter and replaced with GraalIR edge splitter using Anchor nodes (=> simpler).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2835
diff changeset
103 Node succ = n.successors().get(j);
adc4b3ec0a8c Deleted LIR critical edge splitter and replaced with GraalIR edge splitter using Anchor nodes (=> simpler).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2835
diff changeset
104 if (Schedule.truePredecessorCount(succ) > 1) {
adc4b3ec0a8c Deleted LIR critical edge splitter and replaced with GraalIR edge splitter using Anchor nodes (=> simpler).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2835
diff changeset
105 Anchor a = new Anchor(null, graph);
adc4b3ec0a8c Deleted LIR critical edge splitter and replaced with GraalIR edge splitter using Anchor nodes (=> simpler).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2835
diff changeset
106 a.successors().setAndClear(1, n, j);
adc4b3ec0a8c Deleted LIR critical edge splitter and replaced with GraalIR edge splitter using Anchor nodes (=> simpler).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2835
diff changeset
107 n.successors().set(j, a);
adc4b3ec0a8c Deleted LIR critical edge splitter and replaced with GraalIR edge splitter using Anchor nodes (=> simpler).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2835
diff changeset
108 }
adc4b3ec0a8c Deleted LIR critical edge splitter and replaced with GraalIR edge splitter using Anchor nodes (=> simpler).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2835
diff changeset
109 }
adc4b3ec0a8c Deleted LIR critical edge splitter and replaced with GraalIR edge splitter using Anchor nodes (=> simpler).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2835
diff changeset
110 }
adc4b3ec0a8c Deleted LIR critical edge splitter and replaced with GraalIR edge splitter using Anchor nodes (=> simpler).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2835
diff changeset
111 }
adc4b3ec0a8c Deleted LIR critical edge splitter and replaced with GraalIR edge splitter using Anchor nodes (=> simpler).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2835
diff changeset
112
adc4b3ec0a8c Deleted LIR critical edge splitter and replaced with GraalIR edge splitter using Anchor nodes (=> simpler).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2835
diff changeset
113 Schedule schedule = new Schedule(graph);
2760
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
114 List<Block> blocks = schedule.getBlocks();
2778
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
115 List<LIRBlock> lirBlocks = new ArrayList<LIRBlock>();
2760
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
116 Map<Block, LIRBlock> map = new HashMap<Block, LIRBlock>();
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
117 for (Block b : blocks) {
2777
3e4d992fd312 towards replacing computelinearscanorder with scheduler.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2776
diff changeset
118 LIRBlock block = new LIRBlock(b.blockID());
3e4d992fd312 towards replacing computelinearscanorder with scheduler.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2776
diff changeset
119 map.put(b, block);
3e4d992fd312 towards replacing computelinearscanorder with scheduler.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2776
diff changeset
120 block.setInstructions(b.getInstructions());
2778
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
121 block.setLinearScanNumber(b.blockID());
2805
c3f64b66fc78 Towards removing the next pointer from Constant and ArithmeticOp
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2801
diff changeset
122
c3f64b66fc78 Towards removing the next pointer from Constant and ArithmeticOp
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2801
diff changeset
123 block.setFirstInstruction(b.firstNode());
c3f64b66fc78 Towards removing the next pointer from Constant and ArithmeticOp
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2801
diff changeset
124 block.setLastInstruction(b.lastNode());
2778
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
125 lirBlocks.add(block);
2760
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
126 }
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
127
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
128 for (Block b : blocks) {
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
129 for (Block succ : b.getSuccessors()) {
2833
1cd59ca9ac86 Removed Throw HIR instruction. Removed special handling for exceptions in register allocator.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2832
diff changeset
130 map.get(b).blockSuccessors().add(map.get(succ));
2760
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
131 }
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
132
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
133 for (Block pred : b.getPredecessors()) {
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
134 map.get(b).blockPredecessors().add(map.get(pred));
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
135 }
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
136 }
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
137
2778
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
138 orderedBlocks = lirBlocks;
2801
2af109bec0c0 Make block contains a list of nodes instead a list of instructions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2789
diff changeset
139 valueToBlock = new HashMap<Node, LIRBlock>();
2777
3e4d992fd312 towards replacing computelinearscanorder with scheduler.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2776
diff changeset
140 for (LIRBlock b : orderedBlocks) {
2801
2af109bec0c0 Make block contains a list of nodes instead a list of instructions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2789
diff changeset
141 for (Node i : b.getInstructions()) {
2777
3e4d992fd312 towards replacing computelinearscanorder with scheduler.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2776
diff changeset
142 valueToBlock.put(i, b);
3e4d992fd312 towards replacing computelinearscanorder with scheduler.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2776
diff changeset
143 }
3e4d992fd312 towards replacing computelinearscanorder with scheduler.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2776
diff changeset
144 }
2789
aeccd2af4e9e Fixes around critical edge split and placeholder removal after goto removal.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2788
diff changeset
145 startBlock = lirBlocks.get(0);
2777
3e4d992fd312 towards replacing computelinearscanorder with scheduler.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2776
diff changeset
146 assert startBlock != null;
2789
aeccd2af4e9e Fixes around critical edge split and placeholder removal after goto removal.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2788
diff changeset
147 assert startBlock.blockPredecessors().size() == 0;
2788
df4c5254c5cc Towards goto removal.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2783
diff changeset
148
2778
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
149 ComputeLinearScanOrder clso = new ComputeLinearScanOrder(lirBlocks.size(), startBlock);
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
150 orderedBlocks = clso.linearScanOrder();
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
151 this.compilation.stats.loopCount = clso.numLoops();
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
152
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
153 int z = 0;
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
154 for (LIRBlock b : orderedBlocks) {
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
155 b.setLinearScanNumber(z++);
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
156 }
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
157
2788
df4c5254c5cc Towards goto removal.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2783
diff changeset
158 verifyAndPrint("After linear scan order");
2778
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
159
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
160 if (C1XOptions.PrintTimers) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
161 C1XTimers.HIR_OPTIMIZE.stop();
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
162 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
163 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
164
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
165 private void buildGraph() {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
166 // Graph builder must set the startBlock and the osrEntryBlock
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
167 new GraphBuilder(compilation, compilation.method, compilation.graph).build();
2827
bd17ac598c6e Graph cloning, initial version (not completely working)
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
168
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
169 verifyAndPrint("After graph building");
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
170
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
171 List<Invoke> trivialInline = new ArrayList<Invoke>();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
172 List<Invoke> deoptInline = new ArrayList<Invoke>();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
173 List<RiMethod> deoptMethods = new ArrayList<RiMethod>();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
174 for (Node node : compilation.graph.getNodes()) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
175 if (node instanceof Invoke) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
176 Invoke invoke = (Invoke) node;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
177 RiMethod target = invoke.target;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
178 if (target.isResolved() && !Modifier.isNative(target.accessFlags())) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
179 if (target.canBeStaticallyBound()) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
180 trivialInline.add(invoke);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
181 } else {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
182 RiMethod concrete = invoke.target.holder().uniqueConcreteMethod(invoke.target);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
183 if (concrete != null) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
184 deoptInline.add(invoke);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
185 deoptMethods.add(concrete);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
186 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
187 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
188 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
189 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
190 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
191
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
192 int allowedInlinings = 50;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
193 for (Invoke invoke : trivialInline) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
194 if (inlineMethod(invoke, invoke.target)) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
195 if (--allowedInlinings <= 0) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
196 break;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
197 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
198 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
199 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
200
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
201 for (int i = 0; i < deoptInline.size(); i++) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
202 Invoke invoke = deoptInline.get(i);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
203 RiMethod method = deoptMethods.get(i);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
204 if (inlineMethod(invoke, method)) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
205 if (C1XOptions.TraceInlining) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
206 System.out.println("registering concrete method assumption...");
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
207 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
208 compilation.assumptions.recordConcreteMethod(invoke.target, method);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
209 if (--allowedInlinings <= 0) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
210 break;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
211 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
212 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
213 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
214
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
215 if (C1XOptions.PrintCompilation) {
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
216 TTY.print(String.format("%3d blocks | ", compilation.stats.blockCount));
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
217 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
218 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
219
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
220 private boolean inlineMethod(Invoke invoke, RiMethod method) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
221 String name = invoke.id() + ": " + CiUtil.format("%H.%n(%p):%r", method, false) + " (" + method.code().length + " bytes)";
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
222
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
223 if (method.code().length > 50) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
224 if (C1XOptions.TraceInlining) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
225 System.out.println("not inlining " + name + " because of code size");
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
226 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
227 return false;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
228 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
229
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
230 Instruction exceptionEdge = invoke.exceptionEdge();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
231 if (exceptionEdge != null) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
232 if (C1XOptions.TraceInlining) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
233 System.out.println("not inlining " + name + " because of exceptionEdge");
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
234 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
235 return false;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
236 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
237 if (!method.holder().isInitialized()) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
238 if (C1XOptions.TraceInlining) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
239 System.out.println("not inlining " + name + " because of non-initialized class");
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
240 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
241 return false;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
242 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
243
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
244 if (C1XOptions.TraceInlining) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
245 System.out.println("building graph: " + name);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
246 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
247 CompilerGraph graph = new CompilerGraph();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
248 new GraphBuilder(compilation, method, graph).build();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
249
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
250 boolean withReceiver = !Modifier.isStatic(method.accessFlags());
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
251
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
252 int argumentCount = method.signature().argumentCount(false);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
253 Value[] parameters = new Value[argumentCount + (withReceiver ? 1 : 0)];
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
254 int slot = withReceiver ? 1 : 0;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
255 int param = withReceiver ? 1 : 0;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
256 for (int i = 0; i < argumentCount; i++) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
257 parameters[param++] = invoke.argument(slot);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
258 slot += method.signature().argumentKindAt(i).sizeInSlots();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
259 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
260 if (withReceiver) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
261 parameters[0] = invoke.argument(0);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
262 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
263
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
264 HashMap<Node, Node> replacements = new HashMap<Node, Node>();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
265 ArrayList<Node> nodes = new ArrayList<Node>();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
266 ArrayList<Node> frameStates = new ArrayList<Node>();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
267 Return returnNode = null;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
268 Unwind unwindNode = null;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
269 StartNode startNode = null;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
270 boolean invokes = false;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
271 for (Node node : graph.getNodes()) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
272 if (node != null) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
273 if (node instanceof StartNode) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
274 startNode = (StartNode) node;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
275 } else if (node instanceof Local) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
276 replacements.put(node, parameters[((Local) node).index()]);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
277 } else {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
278 nodes.add(node);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
279 if (node instanceof Return) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
280 returnNode = (Return) node;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
281 } else if (node instanceof Unwind) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
282 unwindNode = (Unwind) node;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
283 } else if (node instanceof FrameState) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
284 frameStates.add(node);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
285 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
286 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
287 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
288 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
289 if (unwindNode != null) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
290 if (C1XOptions.TraceInlining) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
291 System.out.println("not inlining " + name + " because of unwind node");
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
292 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
293 return false;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
294 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
295 if (invokes) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
296 if (C1XOptions.TraceInlining) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
297 System.out.println("not inlining " + name + " because of invokes");
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
298 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
299 return false;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
300 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
301
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
302 if (C1XOptions.TraceInlining) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
303 System.out.println("inlining " + name + ": " + frameStates.size() + " frame states, " + nodes.size() + " nodes");
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
304 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
305
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
306 Instruction pred;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
307 if (withReceiver) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
308 pred = new NullCheck(parameters[0], compilation.graph);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
309 } else {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
310 pred = new Merge(compilation.graph);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
311 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
312 assert invoke.predecessors().size() == 1;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
313 invoke.predecessors().get(0).successors().replace(invoke, pred);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
314 replacements.put(startNode, pred);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
315
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
316 Map<Node, Node> duplicates = compilation.graph.addDuplicate(nodes, replacements);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
317
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
318 if (returnNode != null) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
319 List<Node> usages = new ArrayList<Node>(invoke.usages());
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
320 for (Node usage : usages) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
321 if (returnNode.result() instanceof Local) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
322 usage.inputs().replace(invoke, replacements.get(returnNode.result()));
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
323 } else {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
324 usage.inputs().replace(invoke, duplicates.get(returnNode.result()));
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
325 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
326 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
327 Node returnDuplicate = duplicates.get(returnNode);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
328 returnDuplicate.inputs().clearAll();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
329
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
330 assert returnDuplicate.predecessors().size() == 1;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
331 Node returnPred = returnDuplicate.predecessors().get(0);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
332 int index = returnDuplicate.predecessorsIndex().get(0);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
333 returnPred.successors().setAndClear(index, invoke, 0);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
334
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
335 returnDuplicate.delete();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
336 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
337 FrameState stateAfter = invoke.stateAfter();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
338 if (frameStates.size() > 0) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
339 FrameState outerFrameState = stateAfter.duplicateModified(invoke.bci, invoke.kind);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
340 for (Node frameState : frameStates) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
341 ((FrameState) duplicates.get(frameState)).setOuterFrameState(outerFrameState);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
342 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
343 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
344
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
345 invoke.successors().clearAll();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
346 invoke.inputs().clearAll();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
347 invoke.delete();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
348
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
349 stateAfter.delete();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
350
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
351 deleteUnused(exceptionEdge);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
352
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
353 verifyAndPrint("After inlining " + CiUtil.format("%H.%n(%p):%r", method, false));
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
354 return true;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
355 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
356
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
357 private void deleteUnused(Node node) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
358 if (node != null && node.predecessors().size() == 0) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
359 if (node instanceof ExceptionObject) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
360 Node successor = node.successors().get(0);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
361 node.successors().clearAll();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
362 if (successor instanceof ExceptionDispatch) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
363 ExceptionDispatch dispatch = (ExceptionDispatch) successor;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
364 Node succ1 = dispatch.catchSuccessor();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
365 Node succ2 = dispatch.otherSuccessor();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
366 if (succ1 instanceof Merge) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
367 ((Merge) succ1).removePhiPredecessor(dispatch);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
368 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
369 if (succ2 instanceof Merge) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
370 ((Merge) succ2).removePhiPredecessor(dispatch);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
371 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
372 dispatch.successors().clearAll();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
373 deleteUnused(succ1);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
374 deleteUnused(succ2);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
375 dispatch.delete();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
376 } else {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
377 assert successor instanceof Merge;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
378 System.out.println("succ: " + successor.successors().get(0));
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
379 Node next = successor.successors().get(0);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
380 successor.successors().clearAll();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
381 deleteUnused(next);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
382 successor.delete();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
383 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
384 node.delete();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
385 } else if (node instanceof Unwind) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
386 node.delete();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
387 }
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
388 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
389 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
390
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
391 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
392 * Gets the linear scan ordering of blocks as a list.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
393 * @return the blocks in linear scan order
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
394 */
2718
c1ce2a53d6c3 Attempt to remove dependency between backend and BlockBegin.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2716
diff changeset
395 public List<LIRBlock> linearScanOrder() {
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
396 return orderedBlocks;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
397 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
398
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
399 private void print(boolean cfgOnly) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
400 if (!TTY.isSuppressed()) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
401 TTY.println("IR for " + compilation.method);
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
402 final InstructionPrinter ip = new InstructionPrinter(TTY.out());
2546
e1b3db8031ee Removed liveness marking.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2531
diff changeset
403 final BlockPrinter bp = new BlockPrinter(this, ip, cfgOnly);
2783
9bc0c2eb00d6 Made graph builder removal of BlockBegin work.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2782
diff changeset
404 //getHIRStartBlock().iteratePreOrder(bp);
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
405 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
406 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
407
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
408 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
409 * Verifies the IR and prints it out if the relevant options are set.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
410 * @param phase the name of the phase for printing
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
411 */
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
412 public void verifyAndPrint(String phase) {
2653
7c8ad40c1f88 No need for stateAfter on volatile field loads.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2616
diff changeset
413 if (C1XOptions.PrintHIR && !TTY.isSuppressed()) {
7c8ad40c1f88 No need for stateAfter on volatile field loads.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2616
diff changeset
414 TTY.println(phase);
7c8ad40c1f88 No need for stateAfter on volatile field loads.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2616
diff changeset
415 print(false);
7c8ad40c1f88 No need for stateAfter on volatile field loads.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2616
diff changeset
416 }
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
417
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
418 if (compilation.compiler.isObserved()) {
2809
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2807
diff changeset
419 compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, phase, compilation.graph, true, false));
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
420 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
421 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
422
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
423 public int numLoops() {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
424 return compilation.stats.loopCount;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
425 }
2564
274360f98f97 Remove inlining (2nd part) removed IRScope
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2546
diff changeset
426
274360f98f97 Remove inlining (2nd part) removed IRScope
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2546
diff changeset
427 /**
2840
75e0d39833a0 new CompilerGraph, create only one Return and one Unwind per CompilerGraph
Lukas Stadler <lukas.stadler@jku.at>
parents: 2835
diff changeset
428 * Gets the maximum number of locks in the graph's frame states.
2564
274360f98f97 Remove inlining (2nd part) removed IRScope
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2546
diff changeset
429 */
274360f98f97 Remove inlining (2nd part) removed IRScope
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2546
diff changeset
430 public final int maxLocks() {
2840
75e0d39833a0 new CompilerGraph, create only one Return and one Unwind per CompilerGraph
Lukas Stadler <lukas.stadler@jku.at>
parents: 2835
diff changeset
431 int maxLocks = 0;
75e0d39833a0 new CompilerGraph, create only one Return and one Unwind per CompilerGraph
Lukas Stadler <lukas.stadler@jku.at>
parents: 2835
diff changeset
432 for (Node node : compilation.graph.getNodes()) {
75e0d39833a0 new CompilerGraph, create only one Return and one Unwind per CompilerGraph
Lukas Stadler <lukas.stadler@jku.at>
parents: 2835
diff changeset
433 if (node instanceof FrameState) {
75e0d39833a0 new CompilerGraph, create only one Return and one Unwind per CompilerGraph
Lukas Stadler <lukas.stadler@jku.at>
parents: 2835
diff changeset
434 int lockCount = ((FrameState) node).locksSize();
75e0d39833a0 new CompilerGraph, create only one Return and one Unwind per CompilerGraph
Lukas Stadler <lukas.stadler@jku.at>
parents: 2835
diff changeset
435 if (lockCount > maxLocks) {
75e0d39833a0 new CompilerGraph, create only one Return and one Unwind per CompilerGraph
Lukas Stadler <lukas.stadler@jku.at>
parents: 2835
diff changeset
436 maxLocks = lockCount;
75e0d39833a0 new CompilerGraph, create only one Return and one Unwind per CompilerGraph
Lukas Stadler <lukas.stadler@jku.at>
parents: 2835
diff changeset
437 }
75e0d39833a0 new CompilerGraph, create only one Return and one Unwind per CompilerGraph
Lukas Stadler <lukas.stadler@jku.at>
parents: 2835
diff changeset
438 }
75e0d39833a0 new CompilerGraph, create only one Return and one Unwind per CompilerGraph
Lukas Stadler <lukas.stadler@jku.at>
parents: 2835
diff changeset
439 }
2564
274360f98f97 Remove inlining (2nd part) removed IRScope
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2546
diff changeset
440 return maxLocks;
274360f98f97 Remove inlining (2nd part) removed IRScope
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2546
diff changeset
441 }
2718
c1ce2a53d6c3 Attempt to remove dependency between backend and BlockBegin.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2716
diff changeset
442
2781
bda5972a40a5 remove unnecessary BlockBegin nodes in frontend
Lukas Stadler <lukas.stadler@jku.at>
parents: 2776
diff changeset
443 public Instruction getHIRStartBlock() {
bda5972a40a5 remove unnecessary BlockBegin nodes in frontend
Lukas Stadler <lukas.stadler@jku.at>
parents: 2776
diff changeset
444 return (Instruction) compilation.graph.start().successors().get(0);
2718
c1ce2a53d6c3 Attempt to remove dependency between backend and BlockBegin.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2716
diff changeset
445 }
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
446 }