Mercurial > hg > graal-compiler
annotate graal/GraalCompiler/src/com/sun/c1x/alloc/ControlFlowOptimizer.java @ 2772:3e3338a1abb9
Disabled dead phi elimination and phi simplifier.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Tue, 24 May 2011 10:27:15 +0200 |
parents | d3398b21faf9 |
children | 2ac7b30b7290 |
rev | line source |
---|---|
2761
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
1 /* |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
4 * |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
8 * |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
13 * accompanied this code). |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
14 * |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
18 * |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
21 * questions. |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
22 */ |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
23 package com.sun.c1x.alloc; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
24 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
25 import java.util.*; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
26 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
27 import com.sun.c1x.*; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
28 import com.sun.c1x.graph.*; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
29 import com.sun.c1x.ir.*; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
30 import com.sun.c1x.lir.*; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
31 import com.sun.c1x.util.*; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
32 import com.sun.cri.ci.*; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
33 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
34 /** |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
35 * This class performs basic optimizations on the control flow graph after LIR generation. |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
36 */ |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
37 final class ControlFlowOptimizer { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
38 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
39 /** |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
40 * Performs control flow optimizations on the given IR graph. |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
41 * @param ir the IR graph that should be optimized |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
42 */ |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
43 public static void optimize(IR ir) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
44 ControlFlowOptimizer optimizer = new ControlFlowOptimizer(ir); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
45 List<LIRBlock> code = ir.linearScanOrder(); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
46 optimizer.reorderShortLoops(code); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
47 optimizer.deleteEmptyBlocks(code); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
48 optimizer.deleteUnnecessaryJumps(code); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
49 optimizer.deleteJumpsToReturn(code); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
50 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
51 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
52 private final IR ir; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
53 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
54 private ControlFlowOptimizer(IR ir) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
55 this.ir = ir; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
56 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
57 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
58 private void reorderShortLoop(List<LIRBlock> code, LIRBlock headerBlock, int headerIdx) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
59 int i = headerIdx + 1; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
60 int maxEnd = Math.min(headerIdx + C1XOptions.MaximumShortLoopSize, code.size()); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
61 while (i < maxEnd && code.get(i).loopDepth() >= headerBlock.loopDepth()) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
62 i++; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
63 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
64 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
65 if (i == code.size() || code.get(i).loopDepth() < headerBlock.loopDepth()) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
66 int endIdx = i - 1; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
67 LIRBlock endBlock = code.get(endIdx); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
68 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
69 if (endBlock.numberOfSux() == 1 && endBlock.suxAt(0) == headerBlock) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
70 // short loop from headerIdx to endIdx found . reorder blocks such that |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
71 // the headerBlock is the last block instead of the first block of the loop |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
72 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
73 for (int j = headerIdx; j < endIdx; j++) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
74 code.set(j, code.get(j + 1)); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
75 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
76 code.set(endIdx, headerBlock); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
77 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
78 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
79 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
80 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
81 private void reorderShortLoops(List<LIRBlock> code) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
82 for (int i = code.size() - 1; i >= 0; i--) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
83 LIRBlock block = code.get(i); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
84 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
85 if (block.isLinearScanLoopHeader()) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
86 reorderShortLoop(code, block, i); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
87 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
88 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
89 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
90 assert verify(code); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
91 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
92 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
93 // only blocks with exactly one successor can be deleted. Such blocks |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
94 // must always end with an unconditional branch to this successor |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
95 private boolean canDeleteBlock(LIRBlock block) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
96 if (block.numberOfSux() != 1 || |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
97 block == ir.startBlock || |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
98 block.suxAt(0) == block) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
99 return false; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
100 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
101 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
102 List<LIRInstruction> instructions = block.lir().instructionsList(); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
103 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
104 assert instructions.size() >= 2 : "block must have label and branch"; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
105 assert instructions.get(0).code == LIROpcode.Label : "first instruction must always be a label"; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
106 assert instructions.get(instructions.size() - 1) instanceof LIRBranch : "last instruction must always be a branch"; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
107 assert ((LIRBranch) instructions.get(instructions.size() - 1)).cond() == Condition.TRUE : "branch must be unconditional"; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
108 assert ((LIRBranch) instructions.get(instructions.size() - 1)).block() == block.suxAt(0) : "branch target must be the successor"; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
109 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
110 // block must have exactly one successor |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
111 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
112 return instructions.size() == 2 && instructions.get(instructions.size() - 1).info == null; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
113 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
114 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
115 private void deleteEmptyBlocks(List<LIRBlock> code) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
116 int oldPos = 0; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
117 int newPos = 0; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
118 int numBlocks = code.size(); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
119 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
120 while (oldPos < numBlocks) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
121 LIRBlock block = code.get(oldPos); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
122 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
123 if (canDeleteBlock(block)) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
124 LIRBlock newTarget = block.suxAt(0); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
125 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
126 // update the block references in any branching LIR instructions |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
127 for (LIRBlock pred : block.blockPredecessors()) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
128 for (LIRInstruction instr : pred.lir().instructionsList()) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
129 if (instr instanceof LIRBranch) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
130 ((LIRBranch) instr).substitute(block, newTarget); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
131 } else if (instr instanceof LIRTableSwitch) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
132 ((LIRTableSwitch) instr).substitute(block, newTarget); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
133 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
134 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
135 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
136 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
137 // adjust successor and predecessor lists |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
138 block.replaceWith(newTarget); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
139 C1XMetrics.BlocksDeleted++; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
140 } else { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
141 // adjust position of this block in the block list if blocks before |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
142 // have been deleted |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
143 if (newPos != oldPos) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
144 code.set(newPos, code.get(oldPos)); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
145 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
146 newPos++; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
147 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
148 oldPos++; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
149 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
150 assert verify(code); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
151 Util.truncate(code, newPos); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
152 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
153 assert verify(code); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
154 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
155 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
156 private void deleteUnnecessaryJumps(List<LIRBlock> code) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
157 // skip the last block because there a branch is always necessary |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
158 for (int i = code.size() - 2; i >= 0; i--) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
159 LIRBlock block = code.get(i); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
160 List<LIRInstruction> instructions = block.lir().instructionsList(); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
161 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
162 LIRInstruction lastOp = instructions.get(instructions.size() - 1); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
163 if (lastOp.code == LIROpcode.Branch) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
164 assert lastOp instanceof LIRBranch : "branch must be of type LIRBranch"; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
165 LIRBranch lastBranch = (LIRBranch) lastOp; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
166 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
167 assert lastBranch.block() != null : "last branch must always have a block as target"; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
168 assert lastBranch.label() == lastBranch.block().label() : "must be equal"; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
169 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
170 if (lastBranch.info == null) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
171 if (lastBranch.block() == code.get(i + 1)) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
172 // delete last branch instruction |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
173 Util.truncate(instructions, instructions.size() - 1); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
174 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
175 } else { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
176 LIRInstruction prevOp = instructions.get(instructions.size() - 2); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
177 if (prevOp.code == LIROpcode.Branch || prevOp.code == LIROpcode.CondFloatBranch) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
178 assert prevOp instanceof LIRBranch : "branch must be of type LIRBranch"; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
179 LIRBranch prevBranch = (LIRBranch) prevOp; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
180 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
181 if (prevBranch.block() == code.get(i + 1) && prevBranch.info == null) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
182 // eliminate a conditional branch to the immediate successor |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
183 prevBranch.changeBlock(lastBranch.block()); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
184 prevBranch.negateCondition(); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
185 Util.truncate(instructions, instructions.size() - 1); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
186 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
187 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
188 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
189 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
190 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
191 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
192 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
193 assert verify(code); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
194 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
195 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
196 private void deleteJumpsToReturn(List<LIRBlock> code) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
197 for (int i = code.size() - 1; i >= 0; i--) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
198 LIRBlock block = code.get(i); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
199 List<LIRInstruction> curInstructions = block.lir().instructionsList(); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
200 LIRInstruction curLastOp = curInstructions.get(curInstructions.size() - 1); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
201 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
202 assert curInstructions.get(0).code == LIROpcode.Label : "first instruction must always be a label"; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
203 if (curInstructions.size() == 2 && curLastOp.code == LIROpcode.Return) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
204 // the block contains only a label and a return |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
205 // if a predecessor ends with an unconditional jump to this block, then the jump |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
206 // can be replaced with a return instruction |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
207 // |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
208 // Note: the original block with only a return statement cannot be deleted completely |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
209 // because the predecessors might have other (conditional) jumps to this block. |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
210 // this may lead to unnecesary return instructions in the final code |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
211 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
212 assert curLastOp.info == null : "return instructions do not have debug information"; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
213 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
214 assert curLastOp instanceof LIROp1 : "return must be LIROp1"; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
215 CiValue returnOpr = ((LIROp1) curLastOp).operand(); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
216 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
217 for (int j = block.numberOfPreds() - 1; j >= 0; j--) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
218 LIRBlock pred = block.predAt(j); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
219 List<LIRInstruction> predInstructions = pred.lir().instructionsList(); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
220 LIRInstruction predLastOp = predInstructions.get(predInstructions.size() - 1); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
221 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
222 if (predLastOp.code == LIROpcode.Branch) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
223 assert predLastOp instanceof LIRBranch : "branch must be LIRBranch"; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
224 LIRBranch predLastBranch = (LIRBranch) predLastOp; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
225 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
226 if (predLastBranch.block() == block && predLastBranch.cond() == Condition.TRUE && predLastBranch.info == null) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
227 // replace the jump to a return with a direct return |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
228 // Note: currently the edge between the blocks is not deleted |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
229 predInstructions.set(predInstructions.size() - 1, new LIROp1(LIROpcode.Return, returnOpr)); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
230 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
231 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
232 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
233 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
234 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
235 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
236 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
237 private boolean verify(List<LIRBlock> code) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
238 for (LIRBlock block : code) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
239 List<LIRInstruction> instructions = block.lir().instructionsList(); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
240 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
241 for (LIRInstruction instr : instructions) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
242 if (instr instanceof LIRBranch) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
243 LIRBranch opBranch = (LIRBranch) instr; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
244 assert opBranch.block() == null || code.contains(opBranch.block()) : "missing successor branch from: " + block + " to: " + opBranch.block(); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
245 assert opBranch.unorderedBlock() == null || code.contains(opBranch.unorderedBlock()) : "missing successor branch from: " + block + " to: " + opBranch.unorderedBlock(); |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
246 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
247 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
248 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
249 for (LIRBlock sux : block.blockSuccessors()) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
250 assert code.contains(sux) : "missing successor from: " + block + "to: " + sux; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
251 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
252 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
253 for (LIRBlock pred : block.blockPredecessors()) { |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
254 assert code.contains(pred) : "missing predecessor from: " + block + "to: " + pred; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
255 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
256 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
257 |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
258 return true; |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
259 } |
d3398b21faf9
Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
260 } |