Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ControlFlowOptimizer.java @ 7530:5e3d1a68664e
applied mx eclipseformat to all Java files
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 23 Jan 2013 16:34:57 +0100 |
parents | ca3e5df0e6cf |
children | 68b964b6dc8e |
rev | line source |
---|---|
6321
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
4 * |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
8 * |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
14 * |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
18 * |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
21 * questions. |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
22 */ |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.lir; |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
24 |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
25 import java.util.*; |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
26 |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
27 import com.oracle.graal.debug.*; |
6529
2e96dc4eb8e2
renamed package: com.oracle.graal.lir.cfg -> com.oracle.graal.nodes.cfg
Doug Simon <doug.simon@oracle.com>
parents:
6411
diff
changeset
|
28 import com.oracle.graal.nodes.cfg.*; |
6321
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
29 |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
30 /** |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
31 * This class performs basic optimizations on the control flow graph after LIR generation. |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
32 */ |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
33 public final class ControlFlowOptimizer { |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
34 |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
35 /** |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
36 * Performs control flow optimizations on the given LIR graph. |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
37 */ |
6411
c5afcc2ebd3d
change of project structure: separate compiler and LIR, put EA into separate project
Lukas Stadler <lukas.stadler@jku.at>
parents:
6321
diff
changeset
|
38 public static void optimize(LIR ir) { |
c5afcc2ebd3d
change of project structure: separate compiler and LIR, put EA into separate project
Lukas Stadler <lukas.stadler@jku.at>
parents:
6321
diff
changeset
|
39 List<Block> blocks = ir.codeEmittingOrder(); |
c5afcc2ebd3d
change of project structure: separate compiler and LIR, put EA into separate project
Lukas Stadler <lukas.stadler@jku.at>
parents:
6321
diff
changeset
|
40 ControlFlowOptimizer.deleteEmptyBlocks(ir, blocks); |
c5afcc2ebd3d
change of project structure: separate compiler and LIR, put EA into separate project
Lukas Stadler <lukas.stadler@jku.at>
parents:
6321
diff
changeset
|
41 ControlFlowOptimizer.deleteUnnecessaryJumps(ir, blocks); |
6321
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
42 } |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
43 |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
44 private ControlFlowOptimizer() { |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
45 } |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
46 |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
47 /** |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
48 * Checks whether a block can be deleted. Only blocks with exactly one successor and an |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
49 * unconditional branch to this successor are eligable. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7499
diff
changeset
|
50 * |
6321
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
51 * @param block the block checked for deletion |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
52 * @return whether the block can be deleted |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
53 */ |
6411
c5afcc2ebd3d
change of project structure: separate compiler and LIR, put EA into separate project
Lukas Stadler <lukas.stadler@jku.at>
parents:
6321
diff
changeset
|
54 private static boolean canDeleteBlock(LIR ir, Block block) { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7499
diff
changeset
|
55 if (block.getSuccessorCount() != 1 || block.getPredecessorCount() == 0 || block.getFirstSuccessor() == block) { |
6321
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
56 return false; |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
57 } |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
58 |
6411
c5afcc2ebd3d
change of project structure: separate compiler and LIR, put EA into separate project
Lukas Stadler <lukas.stadler@jku.at>
parents:
6321
diff
changeset
|
59 List<LIRInstruction> instructions = ir.lir(block); |
6321
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
60 |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
61 assert instructions.size() >= 2 : "block must have label and branch"; |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
62 assert instructions.get(0) instanceof StandardOp.LabelOp : "first instruction must always be a label"; |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
63 assert instructions.get(instructions.size() - 1) instanceof StandardOp.JumpOp : "last instruction must always be a branch"; |
7498
600f7bad141c
Small clean up of the Block class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7497
diff
changeset
|
64 assert ((StandardOp.JumpOp) instructions.get(instructions.size() - 1)).destination().label() == ((StandardOp.LabelOp) ir.lir(block.getFirstSuccessor()).get(0)).getLabel() : "branch target must be the successor"; |
6321
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
65 |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
66 // Block must have exactly one successor. |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
67 return instructions.size() == 2 && !instructions.get(instructions.size() - 1).hasState(); |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
68 } |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
69 |
6411
c5afcc2ebd3d
change of project structure: separate compiler and LIR, put EA into separate project
Lukas Stadler <lukas.stadler@jku.at>
parents:
6321
diff
changeset
|
70 private static void deleteEmptyBlocks(LIR ir, List<Block> blocks) { |
6321
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
71 assert verify(blocks); |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
72 Iterator<Block> iterator = blocks.iterator(); |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
73 while (iterator.hasNext()) { |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
74 Block block = iterator.next(); |
6411
c5afcc2ebd3d
change of project structure: separate compiler and LIR, put EA into separate project
Lukas Stadler <lukas.stadler@jku.at>
parents:
6321
diff
changeset
|
75 if (canDeleteBlock(ir, block)) { |
6321
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
76 // adjust successor and predecessor lists |
7497
0f8c6dbf68be
Code clean up and documentation for ComputeBlockOrder class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
6529
diff
changeset
|
77 Block other = block.getFirstSuccessor(); |
6321
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
78 for (Block pred : block.getPredecessors()) { |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
79 Collections.replaceAll(pred.getSuccessors(), block, other); |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
80 } |
7499
ca3e5df0e6cf
Small clean up of access to predecessor/successor of blocks.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7498
diff
changeset
|
81 for (int i = 0; i < other.getPredecessorCount(); i++) { |
6321
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
82 if (other.getPredecessors().get(i) == block) { |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
83 other.getPredecessors().remove(i); |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
84 other.getPredecessors().addAll(i, block.getPredecessors()); |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
85 } |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
86 } |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
87 block.getSuccessors().clear(); |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
88 block.getPredecessors().clear(); |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
89 Debug.metric("BlocksDeleted").increment(); |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
90 iterator.remove(); |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
91 } |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
92 } |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
93 assert verify(blocks); |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
94 } |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
95 |
6411
c5afcc2ebd3d
change of project structure: separate compiler and LIR, put EA into separate project
Lukas Stadler <lukas.stadler@jku.at>
parents:
6321
diff
changeset
|
96 private static void deleteUnnecessaryJumps(LIR ir, List<Block> blocks) { |
6321
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
97 // skip the last block because there a branch is always necessary |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
98 for (int i = blocks.size() - 2; i >= 0; i--) { |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
99 Block block = blocks.get(i); |
6411
c5afcc2ebd3d
change of project structure: separate compiler and LIR, put EA into separate project
Lukas Stadler <lukas.stadler@jku.at>
parents:
6321
diff
changeset
|
100 List<LIRInstruction> instructions = ir.lir(block); |
6321
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
101 |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
102 LIRInstruction lastOp = instructions.get(instructions.size() - 1); |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
103 if (lastOp instanceof StandardOp.JumpOp) { |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
104 StandardOp.JumpOp lastJump = (StandardOp.JumpOp) lastOp; |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
105 |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
106 if (!lastOp.hasState()) { |
6411
c5afcc2ebd3d
change of project structure: separate compiler and LIR, put EA into separate project
Lukas Stadler <lukas.stadler@jku.at>
parents:
6321
diff
changeset
|
107 if (lastJump.destination().label() == ((StandardOp.LabelOp) ir.lir(blocks.get(i + 1)).get(0)).getLabel()) { |
6321
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
108 // delete last branch instruction |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
109 instructions.remove(instructions.size() - 1); |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
110 } else { |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
111 LIRInstruction prevOp = instructions.get(instructions.size() - 2); |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
112 if (prevOp instanceof StandardOp.BranchOp) { |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
113 StandardOp.BranchOp prevBranch = (StandardOp.BranchOp) prevOp; |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
114 |
6411
c5afcc2ebd3d
change of project structure: separate compiler and LIR, put EA into separate project
Lukas Stadler <lukas.stadler@jku.at>
parents:
6321
diff
changeset
|
115 if (prevBranch.destination().label() == ((StandardOp.LabelOp) ir.lir(blocks.get(i + 1)).get(0)).getLabel() && !prevOp.hasState()) { |
6321
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
116 // eliminate a conditional branch to the immediate successor |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
117 prevBranch.negate(lastJump.destination()); |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
118 instructions.remove(instructions.size() - 1); |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
119 } |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
120 } |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
121 } |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
122 } |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
123 } |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
124 } |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
125 assert verify(blocks); |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
126 } |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
127 |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
128 private static boolean verify(List<Block> code) { |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
129 for (Block block : code) { |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
130 for (Block sux : block.getSuccessors()) { |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
131 assert code.contains(sux) : "missing successor from: " + block + "to: " + sux; |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
132 } |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
133 for (Block pred : block.getPredecessors()) { |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
134 assert code.contains(pred) : "missing predecessor from: " + block + "to: " + pred; |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
135 } |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
136 } |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
137 |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
138 return true; |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
139 } |
9418ff4c9e7c
Clean up ControlFlowOptimizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
140 } |