annotate graal/GraalCompiler/src/com/sun/c1x/graph/BlockMap.java @ 2773:27512ea6bbcb

exception dispatch simplification: * BlockMap creates exception dispatch blocks (so they're iterated in the right order) * GraphBuilder uses exception dispatch blocks, simplified handleException, removed updateDispatchChain * simplified mergeOrClone * removed successor & predecessor methods from BlockBegin
author Lukas Stadler <lukas.stadler@jku.at>
date Tue, 24 May 2011 12:07:17 +0200
parents 49a8790b85a2
children 706047ee5f2e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
1 /*
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
4 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
7 * published by the Free Software Foundation.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
8 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
13 * accompanied this code).
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
14 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
18 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
21 * questions.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
22 */
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
23 package com.sun.c1x.graph;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
24
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.*;
2730
027adfafd47e first batch of GraphBuilder changes to remove dependencies on BlockBegin
Lukas Stadler <lukas.stadler@jku.at>
parents: 2693
diff changeset
30 import com.sun.c1x.ir.*;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
31 import com.sun.cri.bytecode.*;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
32 import com.sun.cri.ci.*;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
33 import com.sun.cri.ri.*;
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 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
36 * 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
37 * 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
38 * 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
39 * 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
40 * 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
41 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
42 * 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
43 * 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
44 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
45 * <H2>More Details on {@link BlockMap#build}</H2>
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
46 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
47 * 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
48 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
49 * 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
50 * {@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
51 * 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
52 * More TBD.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
53 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
54 * 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
55 * 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
56 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
57 * <H3>Example</H3>
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
58 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
59 * Consider the following source code:
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
60 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
61 * <pre>
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
62 * <code>
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
63 * public static int test(int arg1, int arg2) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
64 * int x = 0;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
65 * while (arg2 > 0) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
66 * if (arg1 > 0) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
67 * x += 1;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
68 * } else if (arg1 < 0) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
69 * x -= 1;
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 * }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
72 * return x;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
73 * }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
74 * </code>
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
75 * </pre>
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
76 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
77 * 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
78 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
79 * <pre>
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
80 * <code>
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
81 * 0: iconst_0
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
82 * 1: istore_2
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
83 * 2: goto 22
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
84 * 5: iload_0
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
85 * 6: ifle 15
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
86 * 9: iinc 2, 1
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
87 * 12: goto 22
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
88 * 15: iload_0
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
89 * 16: ifge 22
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
90 * 19: iinc 2, -1
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
91 * 22: iload_1
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
92 * 23: ifgt 5
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
93 * 26: iload_2
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
94 * 27: ireturn
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
95 * </code>
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
96 * </pre>
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
97 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
98 * 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
99 * 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
100 * 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
101 * 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
102 * 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
103 * 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
104 * <p>
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
105 * 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
106 * 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
107 * 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
108 * 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
109 * 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
110 * (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
111 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
112 * 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
113 * 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
114 */
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
115 public final class BlockMap {
2730
027adfafd47e first batch of GraphBuilder changes to remove dependencies on BlockBegin
Lukas Stadler <lukas.stadler@jku.at>
parents: 2693
diff changeset
116 public static class Block {
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
117 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
118 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
119 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
120 public boolean isLoopHeader;
2730
027adfafd47e first batch of GraphBuilder changes to remove dependencies on BlockBegin
Lukas Stadler <lukas.stadler@jku.at>
parents: 2693
diff changeset
121 public int blockID;
027adfafd47e first batch of GraphBuilder changes to remove dependencies on BlockBegin
Lukas Stadler <lukas.stadler@jku.at>
parents: 2693
diff changeset
122
027adfafd47e first batch of GraphBuilder changes to remove dependencies on BlockBegin
Lukas Stadler <lukas.stadler@jku.at>
parents: 2693
diff changeset
123 public Instruction firstInstruction;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
124
2773
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
125 final HashSet<Block> successors = new HashSet<Block>();
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
126 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
127 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
128 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
129 }
bcd20d26d52d Refactoring of 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
2773
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
131 public static class ExceptionBlock extends Block {
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
132 public RiExceptionHandler handler;
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
133 public Block next;
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
134 public Block handlerBlock;
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
135 }
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
136
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
137 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
138
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 * 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
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 public final List<Block> blocks;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
143
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
144 /**
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
145 * 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
146 * 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
147 */
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
148 public final BitSet storesInLoops;
2507
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 private final RiMethod method;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
151
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
152 private Block[] blockMap;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
153
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 private BitSet canTrap;
2602
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2519
diff changeset
155
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
156 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
157 * 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
158 * @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
159 */
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
160 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
161 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
162 this.blockMap = new Block[method.code().length];
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
163 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
164 this.canTrap = new BitSet(blockMap.length);
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
165 }
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 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
167 this.storesInLoops = new BitSet(method.maxLocals());
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
168 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
169
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
170 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
171 * 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
172 */
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
173 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
174 makeExceptionEntries();
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
175 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
176 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
177 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
178
2730
027adfafd47e first batch of GraphBuilder changes to remove dependencies on BlockBegin
Lukas Stadler <lukas.stadler@jku.at>
parents: 2693
diff changeset
179 initializeBlockIds();
027adfafd47e first batch of GraphBuilder changes to remove dependencies on BlockBegin
Lukas Stadler <lukas.stadler@jku.at>
parents: 2693
diff changeset
180
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
181 // 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
182 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
183 canTrap = null;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
184 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
185
2730
027adfafd47e first batch of GraphBuilder changes to remove dependencies on BlockBegin
Lukas Stadler <lukas.stadler@jku.at>
parents: 2693
diff changeset
186 private void initializeBlockIds() {
027adfafd47e first batch of GraphBuilder changes to remove dependencies on BlockBegin
Lukas Stadler <lukas.stadler@jku.at>
parents: 2693
diff changeset
187 for (int i = 0; i < blocks.size(); i++) {
027adfafd47e first batch of GraphBuilder changes to remove dependencies on BlockBegin
Lukas Stadler <lukas.stadler@jku.at>
parents: 2693
diff changeset
188 blocks.get(i).blockID = i;
027adfafd47e first batch of GraphBuilder changes to remove dependencies on BlockBegin
Lukas Stadler <lukas.stadler@jku.at>
parents: 2693
diff changeset
189 }
027adfafd47e first batch of GraphBuilder changes to remove dependencies on BlockBegin
Lukas Stadler <lukas.stadler@jku.at>
parents: 2693
diff changeset
190 }
027adfafd47e first batch of GraphBuilder changes to remove dependencies on BlockBegin
Lukas Stadler <lukas.stadler@jku.at>
parents: 2693
diff changeset
191
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
192 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
193 // 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
194 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
195 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
196 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
197 }
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
198 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
199
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
200 private void iterateOverBytecodes() {
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
201 // iterate over the bytecodes top to bottom.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
202 // 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
203 // 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
204 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
205 Block current = null;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
206 int bci = 0;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
207 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
208 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
209 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
210 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
211 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
212 }
bcd20d26d52d Refactoring of 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 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
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 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
216 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
217
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
218 int opcode = Bytes.beU1(code, bci);
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
219 switch (opcode) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
220 case IRETURN: // fall through
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
221 case LRETURN: // fall through
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
222 case FRETURN: // fall through
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
223 case DRETURN: // fall through
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
224 case ARETURN: // fall through
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
225 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
226 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
227 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
228
bcd20d26d52d Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents: 2646
diff changeset
229 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
230 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
231 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
232 }
bcd20d26d52d Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents: 2646
diff changeset
233
bcd20d26d52d Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents: 2646
diff changeset
234 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
235 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
236 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
237 canTrap.set(bci);
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
238 }
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
239
bcd20d26d52d Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents: 2646
diff changeset
240 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
241 bci += 1;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
242 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
243 }
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
244
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
245 case IFEQ: // fall through
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
246 case IFNE: // fall through
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
247 case IFLT: // fall through
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
248 case IFGE: // fall through
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
249 case IFGT: // fall through
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
250 case IFLE: // fall through
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
251 case IF_ICMPEQ: // fall through
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
252 case IF_ICMPNE: // fall through
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
253 case IF_ICMPLT: // fall through
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
254 case IF_ICMPGE: // fall through
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
255 case IF_ICMPGT: // fall through
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
256 case IF_ICMPLE: // fall through
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
257 case IF_ACMPEQ: // fall through
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
258 case IF_ACMPNE: // fall through
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
259 case IFNULL: // fall through
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
260 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
261 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
262 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
263 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
264 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
265
bcd20d26d52d Refactoring of 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 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
267 bci += 3;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
268 break;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
269 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
270
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
271 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
272 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
273 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
274 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
275
bcd20d26d52d Refactoring of 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 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
277 bci += 3;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
278 break;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
279 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
280
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
281 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
282 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
283 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
284 setSuccessors(bci, b1);
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
285
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
286 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
287 bci += 5;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
288 break;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
289 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
290
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
291 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
292 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
293 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
294 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
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 assert lengthOf(code, bci) == sw.size();
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
297 bci += sw.size();
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
298 break;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
299 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
300
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
301 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
302 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
303 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
304 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
305
bcd20d26d52d Refactoring of 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 assert lengthOf(code, bci) == sw.size();
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
307 bci += sw.size();
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
308 break;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
309 }
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
310
bcd20d26d52d Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents: 2646
diff changeset
311 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
312 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
313 }
bcd20d26d52d Refactoring of 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 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
315 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
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 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
318 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
319 }
bcd20d26d52d Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents: 2646
diff changeset
320
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
321 case WIDE: {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
322 bci += lengthOf(code, bci);
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
323 break;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
324 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
325
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
326 default: {
2734
e40c665e6f86 Fixed regression in BlockMap builder.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2733
diff changeset
327 if (canTrap != null && canTrap(opcode)) {
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
328 canTrap.set(bci);
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
329 }
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
330
bcd20d26d52d Refactoring of 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 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
332 bci += lengthOf(opcode);
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
333 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
334 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
335 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
336 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
337
2740
49a8790b85a2 Fixed block map regression.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2734
diff changeset
338 public static boolean canTrap(int opcode) {
49a8790b85a2 Fixed block map regression.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2734
diff changeset
339 switch (opcode) {
49a8790b85a2 Fixed block map regression.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2734
diff changeset
340 case INVOKESTATIC:
49a8790b85a2 Fixed block map regression.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2734
diff changeset
341 case INVOKESPECIAL:
49a8790b85a2 Fixed block map regression.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2734
diff changeset
342 case INVOKEVIRTUAL:
49a8790b85a2 Fixed block map regression.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2734
diff changeset
343 case INVOKEINTERFACE: {
49a8790b85a2 Fixed block map regression.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2734
diff changeset
344 return true;
49a8790b85a2 Fixed block map regression.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2734
diff changeset
345 }
49a8790b85a2 Fixed block map regression.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2734
diff changeset
346 }
49a8790b85a2 Fixed block map regression.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2734
diff changeset
347 return false;
49a8790b85a2 Fixed block map regression.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2734
diff changeset
348 }
49a8790b85a2 Fixed block map regression.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2734
diff changeset
349
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
350 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
351 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
352 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
353 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
354 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
355 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
356 return newBlock;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
357
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
358 } 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
359 // 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
360 // 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
361 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
362 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
363 newBlock.endBci = oldBlock.endBci;
2773
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
364 newBlock.successors.addAll(oldBlock.successors);
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
365
bcd20d26d52d Refactoring of 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 oldBlock.endBci = startBci - 1;
2773
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
367 oldBlock.successors.clear();
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
368 oldBlock.successors.add(newBlock);
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
369
bcd20d26d52d Refactoring of 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 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
371 blockMap[i] = newBlock;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
372 }
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
373 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
374
bcd20d26d52d Refactoring of 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 } 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
376 return oldBlock;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
377 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
378 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
379
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
380 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
381 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
382 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
383 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
384 successors[i] = makeBlock(tswitch.targetAt(i));
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
385 }
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
386 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
387 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
388 }
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 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
391 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
392 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
393 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
394 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
395 }
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
396 Block predecessor = blockMap[predBci];
2773
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
397 assert predecessor.successors.size() == 0;
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
398 predecessor.successors.addAll(Arrays.asList(successors));
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
399 }
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
400
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
401 private HashMap<RiExceptionHandler, ExceptionBlock> exceptionDispatch = new HashMap<RiExceptionHandler, ExceptionBlock>();
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
402
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
403 private ExceptionBlock unwindBlock;
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
404
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
405 private ExceptionBlock makeUnwind() {
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
406 if (unwindBlock == null) {
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
407 unwindBlock = new ExceptionBlock();
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
408 unwindBlock.startBci = -1;
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
409 unwindBlock.endBci = -1;
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
410 }
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
411 return unwindBlock;
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
412 }
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
413
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
414 private Block makeExceptionDispatch(List<RiExceptionHandler> handlers, int index) {
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
415 RiExceptionHandler handler = handlers.get(index);
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
416 if (handler.isCatchAll()) {
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
417 return blockMap[handler.handlerBCI()];
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
418 }
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
419 ExceptionBlock block = exceptionDispatch.get(handler);
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
420 if (block == null) {
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
421 block = new ExceptionBlock();
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
422 block.startBci = -1;
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
423 block.endBci = -1;
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
424 block.handler = handler;
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
425 block.successors.add(blockMap[handler.handlerBCI()]);
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
426 block.handlerBlock = blockMap[handler.handlerBCI()];
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
427 Block next;
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
428 if (index < handlers.size() - 1) {
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
429 next = makeExceptionDispatch(handlers, index + 1);
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
430 } else {
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
431 next = makeUnwind();
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
432 }
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
433 block.successors.add(next);
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
434 block.next = next;
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
435 exceptionDispatch.put(handler, block);
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
436 }
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
437 return block;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
438 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
439
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
440 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
441 if (canTrap == null) {
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
442 return;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
443 }
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
444
2773
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
445 for (int bci = canTrap.nextSetBit(0); bci >= 0; bci = canTrap.nextSetBit(bci + 1)) {
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
446 Block block = blockMap[bci];
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
447
2773
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
448 ArrayList<RiExceptionHandler> handlers = null;
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
449 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
450 if (h.startBCI() <= bci && bci < h.endBCI()) {
2773
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
451 if (handlers == null) {
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
452 handlers = new ArrayList<RiExceptionHandler>();
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
453 }
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
454 handlers.add(h);
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
455 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
456 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
457 }
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
458 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
459 }
2773
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
460 if (handlers != null) {
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
461 Block dispatch = makeExceptionDispatch(handlers, 0);
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
462 block.successors.add(dispatch);
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
463 }
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
464 }
bcd20d26d52d Refactoring of 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 }
bcd20d26d52d Refactoring of 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 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
468 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
469
bcd20d26d52d Refactoring of 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 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
471 // 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
472 // 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
473 // 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
474 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
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 // 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
478 Collections.reverse(blocks);
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
479 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
480
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
481 /**
bcd20d26d52d Refactoring of 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 * 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
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 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
485
bcd20d26d52d Refactoring of 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 /**
bcd20d26d52d Refactoring of 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 * 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
488 * 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
489 */
bcd20d26d52d Refactoring of 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 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
491 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
492 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
493
bcd20d26d52d Refactoring of 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 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
495 // 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
496 // 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
497 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
498 }
bcd20d26d52d Refactoring of 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 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
500 // 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
501 // 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
502 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
503 }
bcd20d26d52d Refactoring of 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
bcd20d26d52d Refactoring of 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 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
506 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
507 nextLoop++;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
508 }
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
509 assert Integer.bitCount(block.loops) == 1;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
510 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
511
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
512 /**
bcd20d26d52d Refactoring of 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 * 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
514 * 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
515 * 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
516 */
bcd20d26d52d Refactoring of 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 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
518 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
519 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
520 // 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
521 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
522 }
bcd20d26d52d Refactoring of 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 // 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
524 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
525 }
bcd20d26d52d Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents: 2646
diff changeset
526
bcd20d26d52d Refactoring of 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 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
528 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
529
bcd20d26d52d Refactoring of 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 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
531 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
532 // 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
533 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
534 }
bcd20d26d52d Refactoring of 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
bcd20d26d52d Refactoring of 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 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
537 processLoopBlock(block);
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
538 }
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
539 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
540 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
541 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
542 }
bcd20d26d52d Refactoring of 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
bcd20d26d52d Refactoring of 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 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
545 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
546 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
547
bcd20d26d52d Refactoring of 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 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
549 }
bcd20d26d52d Refactoring of 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
bcd20d26d52d Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents: 2646
diff changeset
551 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
552 // 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
553 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
554 int bci = block.startBci;
2773
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
555 if (bci >= 0) {
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
556 while (bci <= block.endBci) {
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
557 int opcode = Bytes.beU1(code, bci);
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
558 if (isStore(opcode)) {
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
559 processStore(opcode, Bytes.beU1(code, bci + 1));
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
560
2773
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
561 } else if (opcode == WIDE) {
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
562 opcode = Bytes.beU1(code, bci + 1);
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
563 if (isStore(opcode)) {
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
564 processStore(opcode, Bytes.beU2(code, bci + 2));
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
565 }
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
566 }
2773
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2740
diff changeset
567 bci += lengthOf(code, bci);
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
568 }
bcd20d26d52d Refactoring of 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 }
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
570 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
571
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
572 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
573 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
574 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
575 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
576 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
577 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
578 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
579 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
580 break;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
581
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
582 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
583 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
584 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
585 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
586 break;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
587
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
588 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
589 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
590 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
591 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
592 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
593 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
594 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
595 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
596 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
597 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
598 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
599 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
600 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
601 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
602 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
603 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
604 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
605 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
606 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
607 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
608 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
609 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
610 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
611 break;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
612
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
613 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
614 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
615 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
616 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
617 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
618 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
619 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
620 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
621 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
622 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
623 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
624 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
625 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
626 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
627 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
628 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
629 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
630 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
631 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
632 break;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
633
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
634 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
635 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
636 }
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
637 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
638
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
639
bcd20d26d52d Refactoring of 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 * 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
643 * 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
644 */
bcd20d26d52d Refactoring of 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 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
646 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
647 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
648 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
649
bcd20d26d52d Refactoring of 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 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
651
bcd20d26d52d Refactoring of 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 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
653 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
654 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
655 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
656 }
bcd20d26d52d Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents: 2646
diff changeset
657 }
bcd20d26d52d Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents: 2646
diff changeset
658 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
659
bcd20d26d52d Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents: 2646
diff changeset
660 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
661 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
662 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
663 out.print("\"B").print(succ.startBci).print("\" ");
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
664 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
665 }
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
666 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
667
bcd20d26d52d Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents: 2646
diff changeset
668 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
669 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
670 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
671 }
bcd20d26d52d Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents: 2646
diff changeset
672 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
673 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
674 }
bcd20d26d52d Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents: 2646
diff changeset
675 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
676
bcd20d26d52d Refactoring of BlockMap so that it doesn't create BlockBegin objects, but maintains its own Block data structure
Christian.Wimmer@Oracle.com
parents: 2646
diff changeset
677 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
678 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
679 }