Mercurial > hg > truffle
annotate graal/GraalCompiler/src/com/sun/c1x/graph/BlockMap.java @ 2683:026b21a81651
Merge.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Mon, 16 May 2011 17:26:47 +0200 |
parents | bcd20d26d52d |
children | bcbda467e1ae |
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 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
25 import static com.sun.cri.bytecode.Bytecodes.*; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
26 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
27 import java.util.*; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
28 |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
29 import com.sun.c1x.debug.*; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
30 import com.sun.cri.bytecode.*; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
31 import com.sun.cri.ci.*; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
32 import com.sun.cri.ri.*; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
33 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
34 /** |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
35 * Builds a mapping between bytecodes and basic blocks and builds a conservative control flow |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
36 * graph. Note that this class serves a similar role to C1's {@code BlockListBuilder}, but makes fewer assumptions about |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
37 * what the compiler interface provides. It builds all basic blocks for the control flow graph without requiring the |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
38 * compiler interface to provide a bitmap of the beginning of basic blocks. It makes two linear passes; one over the |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
39 * bytecodes to build block starts and successor lists, and one pass over the block map to build the CFG. |
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 * Note that the CFG built by this class is <i>not</i> connected to the actual {@code BlockBegin} instances; this class |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
42 * does, however, compute and assign the reverse postorder number of the blocks. This comment needs refinement. (MJJ) |
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 * <H2>More Details on {@link BlockMap#build}</H2> |
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 * If the method has any exception handlers the {@linkplain #exceptionMap exception map} will be created (TBD). |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
47 * |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
48 * The bytecodes are then scanned linearly looking for bytecodes that contain control transfers, e.g., {@code GOTO}, |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
49 * {@code RETURN}, {@code IFGE}, and creating the corresponding entries in {@link #successorMap} and {@link #blockMap}. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
50 * In addition, if {@link #exceptionMap} is not null, entries are made for any bytecode that can cause an exception. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
51 * More TBD. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
52 * |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
53 * Observe that this process finds bytecodes that terminate basic blocks, so the {@link #moveSuccessorLists} method is |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
54 * called to reassign the successors to the {@code BlockBegin} node that actually starts the block. |
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 * <H3>Example</H3> |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
57 * |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
58 * Consider the following source code: |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
59 * |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
60 * <pre> |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
61 * <code> |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
62 * public static int test(int arg1, int arg2) { |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
63 * int x = 0; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
64 * while (arg2 > 0) { |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
65 * if (arg1 > 0) { |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
66 * x += 1; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
67 * } else if (arg1 < 0) { |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
68 * x -= 1; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
69 * } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
70 * } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
71 * return x; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
72 * } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
73 * </code> |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
74 * </pre> |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
75 * |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
76 * This is translated by javac to the following bytecode: |
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 * <pre> |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
79 * <code> |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
80 * 0: iconst_0 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
81 * 1: istore_2 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
82 * 2: goto 22 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
83 * 5: iload_0 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
84 * 6: ifle 15 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
85 * 9: iinc 2, 1 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
86 * 12: goto 22 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
87 * 15: iload_0 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
88 * 16: ifge 22 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
89 * 19: iinc 2, -1 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
90 * 22: iload_1 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
91 * 23: ifgt 5 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
92 * 26: iload_2 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
93 * 27: ireturn |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
94 * </code> |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
95 * </pre> |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
96 * |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
97 * There are seven basic blocks in this method, 0..2, 5..6, 9..12, 15..16, 19..19, 22..23 and 26..27. Therefore, before |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
98 * the call to {@code moveSuccessorLists}, the {@code blockMap} array has {@code BlockBegin} nodes at indices 0, 5, 9, |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
99 * 15, 19, 22 and 26. The {@code successorMap} array has entries at 2, 6, 12, 16, 23, 27 corresponding to the control |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
100 * transfer bytecodes. The entry at index 6, for example, is a length two array of {@code BlockBegin} nodes for indices |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
101 * 9 and 15, which are the successors for the basic block 5..6. After the call to {@code moveSuccessors}, {@code |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
102 * successorMap} has entries at 0, 5, 9, 15, 19, 22 and 26, i.e, matching {@code blockMap}. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
103 * <p> |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
104 * Next the blocks are numbered using <a href="http://en.wikipedia.org/wiki/Depth-first_search#Vertex_orderings">reverse |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
105 * post-order</a>. For the above example this results in the numbering 2, 4, 7, 5, 6, 3, 8. Also loop header blocks are |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
106 * detected during the traversal by detecting a repeat visit to a block that is still being processed. This causes the |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
107 * block to be flagged as a loop header and also added to the {@link #loopBlocks} list. The {@code loopBlocks} list |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
108 * contains the blocks at 0, 5, 9, 15, 19, 22, with 22 as the loop header. (N.B. the loop header block is added multiple |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
109 * (4) times to this list). (Should 0 be in? It's not inside the loop). |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
110 * |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
111 * If the {@code computeStoresInLoops} argument to {@code build} is true, the {@code loopBlocks} list is processed to |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
112 * mark all local variables that are stored in the blocks in the list. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
113 */ |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
114 public final class BlockMap { |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
115 public class Block { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
116 public int startBci; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
117 public int endBci; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
118 public boolean isExceptionEntry; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
119 public boolean isLoopHeader; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
120 |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
121 private Block[] successors; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
122 private boolean visited; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
123 private boolean active; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
124 private int loops; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
125 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
126 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
127 private static final Block[] NO_SUCCESSORS = new Block[0]; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
128 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
129 /** |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
130 * The blocks found in this method, in reverse postorder. |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
131 */ |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
132 public final List<Block> blocks; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
133 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
134 /** |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
135 * A bit map covering the locals with a bit set for each local that might be stored to within a |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
136 * loop. If the bit is cleared, it is guaranteed that the local is never stored in a loop. |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
137 */ |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
138 public final BitSet storesInLoops; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
139 |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
140 private final RiMethod method; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
141 |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
142 private Block[] blockMap; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
143 |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
144 private BitSet canTrap; |
2602
0c6564c254af
new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents:
2519
diff
changeset
|
145 |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
146 /** |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
147 * Creates a new BlockMap instance from bytecode of the given method . |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
148 * @param method the compiler interface method containing the code |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
149 */ |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
150 public BlockMap(RiMethod method) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
151 this.method = method; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
152 this.blockMap = new Block[method.code().length]; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
153 if (method.exceptionHandlers().length != 0) { |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
154 this.canTrap = new BitSet(blockMap.length); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
155 } |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
156 this.blocks = new ArrayList<Block>(); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
157 this.storesInLoops = new BitSet(method.maxLocals()); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
158 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
159 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
160 /** |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
161 * Builds the block map and conservative CFG and numbers blocks. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
162 */ |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
163 public void build() { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
164 makeExceptionEntries(); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
165 iterateOverBytecodes(); |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
166 addExceptionEdges(); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
167 computeBlockOrder(); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
168 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
169 // Discard big arrays so that they can be GCed |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
170 blockMap = null; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
171 canTrap = null; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
172 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
173 |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
174 private void makeExceptionEntries() { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
175 // start basic blocks at all exception handler blocks and mark them as exception entries |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
176 for (RiExceptionHandler h : method.exceptionHandlers()) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
177 Block xhandler = makeBlock(h.handlerBCI()); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
178 xhandler.isExceptionEntry = true; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
179 } |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
180 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
181 |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
182 private void iterateOverBytecodes() { |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
183 // iterate over the bytecodes top to bottom. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
184 // mark the entrypoints of basic blocks and build lists of successors for |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
185 // all bytecodes that end basic blocks (i.e. goto, ifs, switches, throw, jsr, returns, ret) |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
186 byte[] code = method.code(); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
187 Block current = null; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
188 int bci = 0; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
189 while (bci < code.length) { |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
190 if (current == null || blockMap[bci] != null) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
191 Block b = makeBlock(bci); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
192 if (current != null) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
193 setSuccessors(current.endBci, b); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
194 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
195 current = b; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
196 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
197 blockMap[bci] = current; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
198 current.endBci = bci; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
199 |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
200 int opcode = Bytes.beU1(code, bci); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
201 switch (opcode) { |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
202 case IRETURN: // fall through |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
203 case LRETURN: // fall through |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
204 case FRETURN: // fall through |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
205 case DRETURN: // fall through |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
206 case ARETURN: // fall through |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
207 case WRETURN: // fall through |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
208 case RETURN: { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
209 current = null; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
210 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
211 assert lengthOf(code, bci) == 1; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
212 bci += 1; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
213 break; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
214 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
215 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
216 case ATHROW: { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
217 current = null; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
218 if (canTrap != null) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
219 canTrap.set(bci); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
220 } |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
221 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
222 assert lengthOf(code, bci) == 1; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
223 bci += 1; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
224 break; |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
225 } |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
226 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
227 case IFEQ: // fall through |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
228 case IFNE: // fall through |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
229 case IFLT: // fall through |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
230 case IFGE: // fall through |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
231 case IFGT: // fall through |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
232 case IFLE: // fall through |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
233 case IF_ICMPEQ: // fall through |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
234 case IF_ICMPNE: // fall through |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
235 case IF_ICMPLT: // fall through |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
236 case IF_ICMPGE: // fall through |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
237 case IF_ICMPGT: // fall through |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
238 case IF_ICMPLE: // fall through |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
239 case IF_ACMPEQ: // fall through |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
240 case IF_ACMPNE: // fall through |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
241 case IFNULL: // fall through |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
242 case IFNONNULL: { |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
243 current = null; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
244 Block b1 = makeBlock(bci + 3); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
245 Block b2 = makeBlock(bci + Bytes.beS2(code, bci + 1)); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
246 setSuccessors(bci, b1, b2); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
247 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
248 assert lengthOf(code, bci) == 3; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
249 bci += 3; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
250 break; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
251 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
252 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
253 case GOTO: { |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
254 current = null; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
255 Block b1 = makeBlock(bci + Bytes.beS2(code, bci + 1)); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
256 setSuccessors(bci, b1); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
257 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
258 assert lengthOf(code, bci) == 3; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
259 bci += 3; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
260 break; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
261 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
262 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
263 case GOTO_W: { |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
264 current = null; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
265 Block b1 = makeBlock(bci + Bytes.beS4(code, bci + 1)); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
266 setSuccessors(bci, b1); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
267 |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
268 assert lengthOf(code, bci) == 5; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
269 bci += 5; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
270 break; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
271 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
272 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
273 case TABLESWITCH: { |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
274 BytecodeTableSwitch sw = new BytecodeTableSwitch(code, bci); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
275 setSuccessors(bci, makeSwitchSuccessors(sw)); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
276 current = null; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
277 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
278 assert lengthOf(code, bci) == sw.size(); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
279 bci += sw.size(); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
280 break; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
281 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
282 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
283 case LOOKUPSWITCH: { |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
284 current = null; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
285 BytecodeLookupSwitch sw = new BytecodeLookupSwitch(code, bci); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
286 setSuccessors(bci, makeSwitchSuccessors(sw)); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
287 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
288 assert lengthOf(code, bci) == sw.size(); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
289 bci += sw.size(); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
290 break; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
291 } |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
292 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
293 case JSR: { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
294 throw new JSRNotSupportedBailout(); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
295 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
296 case JSR_W: { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
297 throw new JSRNotSupportedBailout(); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
298 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
299 case RET: { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
300 throw new JSRNotSupportedBailout(); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
301 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
302 |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
303 case WIDE: { |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
304 if (canTrap != null && ProfileInformationStub.trappedFrequently(method, bci)) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
305 canTrap.set(bci); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
306 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
307 |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
308 bci += lengthOf(code, bci); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
309 break; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
310 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
311 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
312 default: { |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
313 if (canTrap != null && ProfileInformationStub.trappedFrequently(method, bci)) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
314 canTrap.set(bci); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
315 } |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
316 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
317 assert lengthOf(code, bci) == lengthOf(opcode); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
318 bci += lengthOf(opcode); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
319 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
320 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
321 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
322 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
323 |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
324 private Block makeBlock(int startBci) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
325 Block oldBlock = blockMap[startBci]; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
326 if (oldBlock == null) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
327 Block newBlock = new Block(); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
328 newBlock.startBci = startBci; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
329 newBlock.successors = NO_SUCCESSORS; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
330 blockMap[startBci] = newBlock; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
331 return newBlock; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
332 |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
333 } else if (oldBlock.startBci != startBci) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
334 // Backward branch into the middle of an already processed block. |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
335 // Add the correct fall-through successor. |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
336 Block newBlock = new Block(); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
337 newBlock.startBci = startBci; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
338 newBlock.endBci = oldBlock.endBci; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
339 newBlock.successors = oldBlock.successors; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
340 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
341 oldBlock.endBci = startBci - 1; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
342 oldBlock.successors = new Block[] {newBlock }; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
343 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
344 for (int i = startBci; i <= newBlock.endBci; i++) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
345 blockMap[i] = newBlock; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
346 } |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
347 return newBlock; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
348 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
349 } else { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
350 return oldBlock; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
351 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
352 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
353 |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
354 private Block[] makeSwitchSuccessors(BytecodeSwitch tswitch) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
355 int max = tswitch.numberOfCases(); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
356 Block[] successors = new Block[max + 1]; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
357 for (int i = 0; i < max; i++) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
358 successors[i] = makeBlock(tswitch.targetAt(i)); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
359 } |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
360 successors[max] = makeBlock(tswitch.defaultTarget()); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
361 return successors; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
362 } |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
363 |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
364 private void setSuccessors(int predBci, Block... successors) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
365 for (Block sux : successors) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
366 if (sux.isExceptionEntry) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
367 throw new CiBailout("Exception handler can be reached by both normal and exceptional control flow"); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
368 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
369 } |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
370 Block predecessor = blockMap[predBci]; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
371 assert predecessor.successors.length == 0; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
372 predecessor.successors = successors; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
373 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
374 |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
375 private void addExceptionEdges() { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
376 if (canTrap == null) { |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
377 return; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
378 } |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
379 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
380 Block block = null; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
381 HashSet<Block> newSuccessorsOfBlock = new HashSet<Block>(); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
382 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
383 for (int bci = canTrap.nextSetBit(0); bci >= 0; bci = canTrap.nextSetBit(bci + 1)) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
384 Block newBlock = blockMap[bci]; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
385 if (newBlock != block) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
386 if (block != null) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
387 block.successors = newSuccessorsOfBlock.toArray(new Block[newSuccessorsOfBlock.size()]); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
388 newSuccessorsOfBlock.clear(); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
389 } |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
390 Collections.addAll(newSuccessorsOfBlock, newBlock.successors); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
391 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
392 block = newBlock; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
393 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
394 for (RiExceptionHandler h : method.exceptionHandlers()) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
395 if (h.startBCI() <= bci && bci < h.endBCI()) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
396 newSuccessorsOfBlock.add(blockMap[h.handlerBCI()]); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
397 if (h.isCatchAll()) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
398 break; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
399 } |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
400 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
401 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
402 } |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
403 if (block != null) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
404 block.successors = newSuccessorsOfBlock.toArray(new Block[newSuccessorsOfBlock.size()]); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
405 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
406 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
407 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
408 private void computeBlockOrder() { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
409 int loop = computeBlockOrder(blockMap[0]); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
410 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
411 if (loop != 0) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
412 // There is a path from a loop end to the method entry that does not pass the loop header. |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
413 // Therefore, the loop is non reducible (has more than one entry). |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
414 // We don't want to compile such methods because the IR only supports structured loops. |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
415 throw new CiBailout("Non-reducible loop"); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
416 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
417 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
418 // Convert postorder to the desired reverse postorder. |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
419 Collections.reverse(blocks); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
420 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
421 |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
422 /** |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
423 * The next available loop number. |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
424 */ |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
425 private int nextLoop = 0; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
426 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
427 /** |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
428 * Mark the block as a loop header, using the next available loop number. |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
429 * Also checks for corner cases that we don't want to compile. |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
430 */ |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
431 private void makeLoopHeader(Block block) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
432 if (!block.isLoopHeader) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
433 block.isLoopHeader = true; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
434 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
435 if (block.isExceptionEntry) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
436 // Loops that are implicitly formed by an exception handler lead to all sorts of corner cases. |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
437 // Don't compile such methods for now, until we see a concrete case that allows checking for correctness. |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
438 throw new CiBailout("Loop formed by an exception handler"); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
439 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
440 if (nextLoop >= Integer.SIZE) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
441 // This restriction can be removed by using a fall-back to a BitSet in case we have more than 32 loops |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
442 // Don't compile such methods for now, until we see a concrete case that allows checking for correctness. |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
443 throw new CiBailout("Too many loops in method"); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
444 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
445 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
446 assert block.loops == 0; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
447 block.loops = 1 << nextLoop; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
448 nextLoop++; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
449 } |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
450 assert Integer.bitCount(block.loops) == 1; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
451 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
452 |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
453 /** |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
454 * Depth-first traversal of the control flow graph. The flag {@linkplain Block#visited} is used to |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
455 * visit every block only once. The flag {@linkplain Block#active} is used to detect cycles (backward |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
456 * edges). |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
457 */ |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
458 private int computeBlockOrder(Block block) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
459 if (block.visited) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
460 if (block.active) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
461 // Reached block via backward branch. |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
462 makeLoopHeader(block); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
463 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
464 // Return cached loop information for this block. |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
465 return block.loops; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
466 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
467 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
468 block.visited = true; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
469 block.active = true; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
470 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
471 int loops = 0; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
472 for (Block successor : block.successors) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
473 // Recursively process successors. |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
474 loops |= computeBlockOrder(successor); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
475 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
476 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
477 if (loops != 0) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
478 processLoopBlock(block); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
479 } |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
480 if (block.isLoopHeader) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
481 assert Integer.bitCount(block.loops) == 1; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
482 loops &= ~block.loops; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
483 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
484 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
485 block.loops = loops; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
486 block.active = false; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
487 blocks.add(block); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
488 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
489 return loops; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
490 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
491 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
492 private void processLoopBlock(Block block) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
493 // process all the stores in this block |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
494 byte[] code = method.code(); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
495 int bci = block.startBci; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
496 while (bci <= block.endBci) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
497 int opcode = Bytes.beU1(code, bci); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
498 if (isStore(opcode)) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
499 processStore(opcode, Bytes.beU1(code, bci + 1)); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
500 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
501 } else if (opcode == WIDE) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
502 opcode = Bytes.beU1(code, bci + 1); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
503 if (isStore(opcode)) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
504 processStore(opcode, Bytes.beU2(code, bci + 2)); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
505 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
506 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
507 bci += lengthOf(code, bci); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
508 } |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
509 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
510 |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
511 private void processStore(int opcode, int local) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
512 switch (opcode) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
513 case IINC: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
514 case ISTORE: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
515 case FSTORE: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
516 case WSTORE: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
517 case ASTORE: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
518 storesInLoops.set(local); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
519 break; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
520 |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
521 case LSTORE: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
522 case DSTORE: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
523 storesInLoops.set(local); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
524 storesInLoops.set(local + 1); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
525 break; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
526 |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
527 case ISTORE_0: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
528 case FSTORE_0: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
529 case ASTORE_0: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
530 case WSTORE_0: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
531 storesInLoops.set(0); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
532 break; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
533 case ISTORE_1: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
534 case FSTORE_1: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
535 case ASTORE_1: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
536 case WSTORE_1: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
537 storesInLoops.set(1); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
538 break; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
539 case ISTORE_2: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
540 case FSTORE_2: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
541 case ASTORE_2: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
542 case WSTORE_2: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
543 storesInLoops.set(2); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
544 break; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
545 case ISTORE_3: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
546 case FSTORE_3: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
547 case ASTORE_3: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
548 case WSTORE_3: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
549 storesInLoops.set(3); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
550 break; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
551 |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
552 case LSTORE_0: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
553 case DSTORE_0: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
554 storesInLoops.set(0); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
555 storesInLoops.set(1); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
556 break; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
557 case LSTORE_1: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
558 case DSTORE_1: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
559 storesInLoops.set(1); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
560 storesInLoops.set(2); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
561 break; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
562 case LSTORE_2: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
563 case DSTORE_2: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
564 storesInLoops.set(2); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
565 storesInLoops.set(3); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
566 break; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
567 case LSTORE_3: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
568 case DSTORE_3: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
569 storesInLoops.set(3); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
570 storesInLoops.set(4); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
571 break; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
572 |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
573 default: |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
574 throw new InternalError("undefined store bytecode"); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
575 } |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
576 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
577 |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
578 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
579 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
580 /** |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
581 * Print block information in the format required by {@linkplain CFGPrinter}. The method must |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
582 * be here because it accesses private state of a block. |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
583 */ |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
584 public void printBlock(Block block, LogStream out) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
585 out.print("name \"B").print(block.startBci).println('"'); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
586 out.print("from_bci ").println(block.startBci); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
587 out.print("to_bci ").println(block.endBci); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
588 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
589 out.println("predecessors "); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
590 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
591 out.print("successors "); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
592 for (Block succ : block.successors) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
593 if (!succ.isExceptionEntry) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
594 out.print("\"B").print(succ.startBci).print("\" "); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
595 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
596 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
597 out.println(); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
598 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
599 out.print("xhandlers"); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
600 for (Block succ : block.successors) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
601 if (succ.isExceptionEntry) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
602 out.print("\"B").print(succ.startBci).print("\" "); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
603 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
604 } |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
605 out.println(); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
606 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
607 out.print("flags "); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
608 if (block.isExceptionEntry) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
609 out.print("\"ex\" "); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
610 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
611 if (block.isLoopHeader) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
612 out.print("\"plh\" "); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
613 } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
614 out.println(); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
615 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
616 out.print("loop_depth ").println(Integer.bitCount(block.loops)); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
617 } |
2675
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
618 |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
619 // |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
620 // private static StringBuilder append(StringBuilder sb, BlockBegin block) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
621 // return sb.append('B').append(block.blockID).append('@').append(block.bci()); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
622 // } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
623 // |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
624 // @Override |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
625 // public String toString() { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
626 // StringBuilder sb = new StringBuilder(); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
627 // for (int bci = 0; bci < blockMap.length; ++bci) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
628 // BlockBegin block = blockMap[bci]; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
629 // if (block != null) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
630 // append(sb, block); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
631 // if (loopBlocks != null && loopBlocks.contains(block)) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
632 // sb.append("{loop-header}"); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
633 // } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
634 // if (successorMap != null) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
635 // BlockBegin[] succs = successorMap[bci]; |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
636 // if (succs != null && succs.length > 0) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
637 // sb.append(" ->"); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
638 // for (BlockBegin succ : succs) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
639 // append(sb.append(' '), succ); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
640 // } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
641 // } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
642 // } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
643 // Collection<BlockBegin> handlers = getHandlers(block); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
644 // if (!handlers.isEmpty()) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
645 // sb.append(" xhandlers{"); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
646 // for (BlockBegin h : handlers) { |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
647 // append(sb, h).append(' '); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
648 // } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
649 // sb.append('}'); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
650 // } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
651 // sb.append(String.format("%n")); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
652 // } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
653 // } |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
654 // return sb.toString(); |
bcd20d26d52d
Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents:
2646
diff
changeset
|
655 // } |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
656 } |