annotate graal/GraalCompiler/src/com/sun/c1x/graph/IR.java @ 2866:7f14e6b48a9c

added dead code elimination added ValueAnchor (temp workaround) more inlining logic (now uses DCE) IdealGraphPrinter: print even if Scheduler fails added inlining and DCE tracing options to C1XOptions
author Lukas Stadler <lukas.stadler@jku.at>
date Tue, 07 Jun 2011 16:27:08 +0200
parents 7596ae867a7b
children 5c545fef2c81
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
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
86 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
87
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
88 // 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
89 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
90 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
91 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
92 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
93 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
94 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
95 if (Schedule.truePredecessorCount(succ) > 1) {
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
96 Anchor a = new Anchor(graph);
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
97 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
98 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
99 }
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 }
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 }
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 }
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
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 Schedule schedule = new Schedule(graph);
2760
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
105 List<Block> blocks = schedule.getBlocks();
2778
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
106 List<LIRBlock> lirBlocks = new ArrayList<LIRBlock>();
2760
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
107 Map<Block, LIRBlock> map = new HashMap<Block, LIRBlock>();
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
108 for (Block b : blocks) {
2777
3e4d992fd312 towards replacing computelinearscanorder with scheduler.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2776
diff changeset
109 LIRBlock block = new LIRBlock(b.blockID());
3e4d992fd312 towards replacing computelinearscanorder with scheduler.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2776
diff changeset
110 map.put(b, block);
3e4d992fd312 towards replacing computelinearscanorder with scheduler.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2776
diff changeset
111 block.setInstructions(b.getInstructions());
2778
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
112 block.setLinearScanNumber(b.blockID());
2805
c3f64b66fc78 Towards removing the next pointer from Constant and ArithmeticOp
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2801
diff changeset
113
c3f64b66fc78 Towards removing the next pointer from Constant and ArithmeticOp
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2801
diff changeset
114 block.setFirstInstruction(b.firstNode());
c3f64b66fc78 Towards removing the next pointer from Constant and ArithmeticOp
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2801
diff changeset
115 block.setLastInstruction(b.lastNode());
2778
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
116 lirBlocks.add(block);
2760
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
117 }
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
118
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
119 for (Block b : blocks) {
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
120 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
121 map.get(b).blockSuccessors().add(map.get(succ));
2760
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
122 }
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
123
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
124 for (Block pred : b.getPredecessors()) {
127db58b044e One more step towards schedule.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2759
diff changeset
125 map.get(b).blockPredecessors().add(map.get(pred));
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
2778
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
129 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
130 valueToBlock = new HashMap<Node, LIRBlock>();
2777
3e4d992fd312 towards replacing computelinearscanorder with scheduler.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2776
diff changeset
131 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
132 for (Node i : b.getInstructions()) {
2777
3e4d992fd312 towards replacing computelinearscanorder with scheduler.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2776
diff changeset
133 valueToBlock.put(i, b);
3e4d992fd312 towards replacing computelinearscanorder with scheduler.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2776
diff changeset
134 }
3e4d992fd312 towards replacing computelinearscanorder with scheduler.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2776
diff changeset
135 }
2789
aeccd2af4e9e Fixes around critical edge split and placeholder removal after goto removal.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2788
diff changeset
136 startBlock = lirBlocks.get(0);
2777
3e4d992fd312 towards replacing computelinearscanorder with scheduler.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2776
diff changeset
137 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
138 assert startBlock.blockPredecessors().size() == 0;
2788
df4c5254c5cc Towards goto removal.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2783
diff changeset
139
2778
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
140 ComputeLinearScanOrder clso = new ComputeLinearScanOrder(lirBlocks.size(), startBlock);
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
141 orderedBlocks = clso.linearScanOrder();
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
142 this.compilation.stats.loopCount = clso.numLoops();
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
143
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
144 int z = 0;
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
145 for (LIRBlock b : orderedBlocks) {
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
146 b.setLinearScanNumber(z++);
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
147 }
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
148
2788
df4c5254c5cc Towards goto removal.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2783
diff changeset
149 verifyAndPrint("After linear scan order");
2778
2ac7b30b7290 Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2777
diff changeset
150
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
151 if (C1XOptions.PrintTimers) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
152 C1XTimers.HIR_OPTIMIZE.stop();
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
153 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
154 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
155
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
156 private void buildGraph() {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
157 // Graph builder must set the startBlock and the osrEntryBlock
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
158 new GraphBuilder(compilation, compilation.method, compilation.graph).build(false);
2827
bd17ac598c6e Graph cloning, initial version (not completely working)
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
159
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
160 verifyAndPrint("After graph building");
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
161
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
162 DeadCodeElimination dce = new DeadCodeElimination();
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
163 dce.apply(compilation.graph);
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
164 if (dce.deletedNodeCount > 0) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
165 verifyAndPrint("After dead code elimination");
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
166 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
167
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
168 if (C1XOptions.Inline) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
169 inlineMethods();
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
170 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
171
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
172 if (C1XOptions.PrintCompilation) {
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
173 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
174 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
175 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
176
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
177 private void inlineMethods() {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
178 int inliningSize = compilation.method.code().length;
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
179 boolean inlined;
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
180 int iterations = C1XOptions.MaximumRecursiveInlineLevel;
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
181 do {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
182 inlined = false;
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
183
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
184 List<Invoke> trivialInline = new ArrayList<Invoke>();
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
185 List<Invoke> deoptInline = new ArrayList<Invoke>();
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
186 List<RiMethod> deoptMethods = new ArrayList<RiMethod>();
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
187 for (Node node : compilation.graph.getNodes()) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
188 if (node instanceof Invoke) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
189 Invoke invoke = (Invoke) node;
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
190 RiMethod target = invoke.target;
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
191 if (target.isResolved() && !Modifier.isNative(target.accessFlags())) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
192 if (target.canBeStaticallyBound()) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
193 trivialInline.add(invoke);
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
194 } else {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
195 RiMethod concrete = invoke.target.holder().uniqueConcreteMethod(invoke.target);
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
196 if (concrete != null && concrete.isResolved() && !Modifier.isNative(concrete.accessFlags())) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
197 deoptInline.add(invoke);
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
198 deoptMethods.add(concrete);
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
199 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
200 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
201 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
202 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
203 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
204
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
205 for (Invoke invoke : trivialInline) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
206 if (inlineMethod(invoke, invoke.target)) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
207 inlined = true;
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
208 inliningSize += invoke.target.code().length;
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
209 if (inliningSize > C1XOptions.MaximumInstructionCount) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
210 break;
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
211 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
212 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
213 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
214
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
215 for (int i = 0; i < deoptInline.size(); i++) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
216 Invoke invoke = deoptInline.get(i);
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
217 RiMethod method = deoptMethods.get(i);
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
218 if (inlineMethod(invoke, method)) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
219 if (C1XOptions.TraceInlining) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
220 System.out.println("registering concrete method assumption...");
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
221 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
222 compilation.assumptions.recordConcreteMethod(invoke.target, method);
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
223 inlined = true;
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
224 inliningSize += method.code().length;
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
225 if (inliningSize > C1XOptions.MaximumInstructionCount) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
226 break;
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
227 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
228 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
229 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
230
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
231 if (inlined) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
232 DeadCodeElimination dce = new DeadCodeElimination();
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
233 dce.apply(compilation.graph);
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
234 if (dce.deletedNodeCount > 0) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
235 verifyAndPrint("After dead code elimination");
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
236 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
237 verifyAndPrint("After inlining iteration");
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
238 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
239
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
240 if (inliningSize > C1XOptions.MaximumInstructionCount) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
241 break;
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
242 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
243 } while(inlined && (--iterations > 0));
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
244 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
245
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
246 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
247 String name = invoke.id() + ": " + CiUtil.format("%H.%n(%p):%r", method, false) + " (" + method.code().length + " bytes)";
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
248 FrameState stateAfter = invoke.stateAfter();
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
249
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
250 if (method.code().length > C1XOptions.MaximumInlineSize) {
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
251 if (C1XOptions.TraceInlining) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
252 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
253 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
254 return false;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
255 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
256
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
257 if (invoke.predecessors().size() == 0) {
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
258 if (C1XOptions.TraceInlining) {
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
259 System.out.println("not inlining " + name + " because the invoke is dead code");
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
260 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
261 return false;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
262 }
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
263
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
264 Instruction exceptionEdge = invoke.exceptionEdge();
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
265 // if (exceptionEdge != null) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
266 // if (C1XOptions.TraceInlining) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
267 // System.out.println("not inlining " + name + " because of exceptionEdge");
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
268 // }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
269 // return false;
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
270 // }
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
271 if (!method.holder().isInitialized()) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
272 if (C1XOptions.TraceInlining) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
273 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
274 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
275 return false;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
276 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
277
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
278 if (C1XOptions.TraceInlining) {
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
279 System.out.printf("Building graph for %s, locals: %d, stack: %d\n", name, method.maxLocals(), method.maxStackSize());
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
280 }
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
281
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
282 CompilerGraph graph = new CompilerGraph();
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
283 new GraphBuilder(compilation, method, graph).build(true);
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
284
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
285 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
286
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
287 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
288 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
289 int slot = withReceiver ? 1 : 0;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
290 int param = withReceiver ? 1 : 0;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
291 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
292 parameters[param++] = invoke.argument(slot);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
293 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
294 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
295 if (withReceiver) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
296 parameters[0] = invoke.argument(0);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
297 }
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 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
300 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
301 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
302 Return returnNode = null;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
303 Unwind unwindNode = null;
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
304 StartNode startNode = graph.start();
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
305 for (Node node : graph.getNodes()) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
306 if (node != null) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
307 if (node instanceof StartNode) {
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
308 assert startNode == node;
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
309 } else if (node instanceof Local) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
310 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
311 } else {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
312 nodes.add(node);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
313 if (node instanceof Return) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
314 returnNode = (Return) node;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
315 } else if (node instanceof Unwind) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
316 unwindNode = (Unwind) node;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
317 } else if (node instanceof FrameState) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
318 frameStates.add(node);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
319 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
320 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
321 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
322 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
323
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
324 if (C1XOptions.TraceInlining) {
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
325 printGraph("Subgraph " + CiUtil.format("%H.%n(%p):%r", method, false), graph);
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
326 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
327 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
328
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
329 assert invoke.predecessors().size() == 1 : "size: " + invoke.predecessors().size();
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
330 Instruction pred;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
331 if (withReceiver) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
332 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
333 } else {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
334 pred = new Merge(compilation.graph);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
335 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
336 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
337 replacements.put(startNode, pred);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
338
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
339 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
340
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
341 if (returnNode != null) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
342 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
343 for (Node usage : usages) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
344 if (returnNode.result() instanceof Local) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
345 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
346 } else {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
347 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
348 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
349 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
350 Node returnDuplicate = duplicates.get(returnNode);
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
351 returnDuplicate.inputs().clearAll();
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 assert returnDuplicate.predecessors().size() == 1;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
354 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
355 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
356 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
357 returnDuplicate.delete();
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
358 }
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
359
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
360 // if (invoke.next() instanceof Merge) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
361 // ((Merge) invoke.next()).removePhiPredecessor(invoke);
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
362 // }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
363 // invoke.successors().clearAll();
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
364 invoke.inputs().clearAll();
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
365 invoke.setExceptionEdge(null);
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
366 // invoke.delete();
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
367
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
368
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
369 if (exceptionEdge != null) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
370 if (unwindNode != null) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
371 assert unwindNode.predecessors().size() == 1;
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
372 assert exceptionEdge.successors().size() == 1;
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
373 ExceptionObject obj = (ExceptionObject) exceptionEdge;
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
374
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
375 List<Node> usages = new ArrayList<Node>(obj.usages());
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
376 for (Node usage : usages) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
377 if (replacements.containsKey(unwindNode.exception())) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
378 usage.inputs().replace(obj, replacements.get(unwindNode.exception()));
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
379 } else {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
380 usage.inputs().replace(obj, duplicates.get(unwindNode.exception()));
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
381 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
382 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
383 Node unwindDuplicate = duplicates.get(unwindNode);
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
384 unwindDuplicate.inputs().clearAll();
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
385
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
386 assert unwindDuplicate.predecessors().size() == 1;
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
387 Node unwindPred = unwindDuplicate.predecessors().get(0);
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
388 int index = unwindDuplicate.predecessorsIndex().get(0);
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
389 unwindPred.successors().setAndClear(index, obj, 0);
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
390
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
391 obj.inputs().clearAll();
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
392 obj.delete();
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
393 unwindDuplicate.delete();
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
394
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
395 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
396 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
397
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
398 // adjust all frame states that were copied
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
399 if (frameStates.size() > 0) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
400 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
401 for (Node frameState : frameStates) {
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
402 ((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
403 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
404 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
405
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
406 if (C1XOptions.TraceInlining) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
407 verifyAndPrint("After inlining " + CiUtil.format("%H.%n(%p):%r", method, false));
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
408 }
2842
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
409 return true;
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
410 }
7596ae867a7b basic inlining passes all tests, including optimistic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents: 2841
diff changeset
411
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
412 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
413 * 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
414 * @return the blocks in linear scan order
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
415 */
2718
c1ce2a53d6c3 Attempt to remove dependency between backend and BlockBegin.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2716
diff changeset
416 public List<LIRBlock> linearScanOrder() {
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
417 return orderedBlocks;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
418 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
419
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
420 private void print(boolean cfgOnly) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
421 if (!TTY.isSuppressed()) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
422 TTY.println("IR for " + compilation.method);
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
423 final InstructionPrinter ip = new InstructionPrinter(TTY.out());
2546
e1b3db8031ee Removed liveness marking.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2531
diff changeset
424 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
425 //getHIRStartBlock().iteratePreOrder(bp);
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
426 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
427 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
428
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
429 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
430 * 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
431 * @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
432 */
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
433 public void verifyAndPrint(String phase) {
2653
7c8ad40c1f88 No need for stateAfter on volatile field loads.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2616
diff changeset
434 if (C1XOptions.PrintHIR && !TTY.isSuppressed()) {
7c8ad40c1f88 No need for stateAfter on volatile field loads.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2616
diff changeset
435 TTY.println(phase);
7c8ad40c1f88 No need for stateAfter on volatile field loads.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2616
diff changeset
436 print(false);
7c8ad40c1f88 No need for stateAfter on volatile field loads.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2616
diff changeset
437 }
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
438
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
439 if (compilation.compiler.isObserved()) {
2809
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2807
diff changeset
440 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
441 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
442 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
443
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
444 public void printGraph(String phase, Graph graph) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
445 if (C1XOptions.PrintHIR && !TTY.isSuppressed()) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
446 TTY.println(phase);
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
447 print(false);
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
448 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
449
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
450 if (compilation.compiler.isObserved()) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
451 compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, phase, graph, true, false));
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
452 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
453 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2842
diff changeset
454
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
455 public int numLoops() {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
456 return compilation.stats.loopCount;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
457 }
2564
274360f98f97 Remove inlining (2nd part) removed IRScope
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2546
diff changeset
458
274360f98f97 Remove inlining (2nd part) removed IRScope
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2546
diff changeset
459 /**
2840
75e0d39833a0 new CompilerGraph, create only one Return and one Unwind per CompilerGraph
Lukas Stadler <lukas.stadler@jku.at>
parents: 2835
diff changeset
460 * 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
461 */
274360f98f97 Remove inlining (2nd part) removed IRScope
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2546
diff changeset
462 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
463 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
464 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
465 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
466 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
467 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
468 maxLocks = lockCount;
75e0d39833a0 new CompilerGraph, create only one Return and one Unwind per CompilerGraph
Lukas Stadler <lukas.stadler@jku.at>
parents: 2835
diff changeset
469 }
75e0d39833a0 new CompilerGraph, create only one Return and one Unwind per CompilerGraph
Lukas Stadler <lukas.stadler@jku.at>
parents: 2835
diff changeset
470 }
75e0d39833a0 new CompilerGraph, create only one Return and one Unwind per CompilerGraph
Lukas Stadler <lukas.stadler@jku.at>
parents: 2835
diff changeset
471 }
2564
274360f98f97 Remove inlining (2nd part) removed IRScope
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2546
diff changeset
472 return maxLocks;
274360f98f97 Remove inlining (2nd part) removed IRScope
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2546
diff changeset
473 }
2718
c1ce2a53d6c3 Attempt to remove dependency between backend and BlockBegin.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2716
diff changeset
474
2781
bda5972a40a5 remove unnecessary BlockBegin nodes in frontend
Lukas Stadler <lukas.stadler@jku.at>
parents: 2776
diff changeset
475 public Instruction getHIRStartBlock() {
bda5972a40a5 remove unnecessary BlockBegin nodes in frontend
Lukas Stadler <lukas.stadler@jku.at>
parents: 2776
diff changeset
476 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
477 }
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
478 }