Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LabelRef.java @ 21720:d915361cc3a1
moved asm, bytecode and asm.test code back to com.oracle.graal name space (JBS:GRAAL-53)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 04 Jun 2015 13:35:47 +0200 |
parents | 6df25b1418be |
children | 05183a084a08 |
rev | line source |
---|---|
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2011, 2011, Oracle and/or its affiliates. All rights reserved. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
4 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
8 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
14 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
18 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
21 * questions. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
22 */ |
5060
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
23 package com.oracle.graal.lir; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
24 |
21720
d915361cc3a1
moved asm, bytecode and asm.test code back to com.oracle.graal name space (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21708
diff
changeset
|
25 import com.oracle.graal.asm.*; |
15192
644dfe49c0f4
Move packages com.oracle.graal.cfg to com.oracle.graal.compiler.common.cfg.
Josef Eisl <josef.eisl@jku.at>
parents:
15157
diff
changeset
|
26 import com.oracle.graal.compiler.common.cfg.*; |
13268
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
27 import com.oracle.graal.lir.StandardOp.BranchOp; |
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
28 import com.oracle.graal.lir.StandardOp.JumpOp; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
29 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
30 /** |
13268
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
31 * LIR instructions such as {@link JumpOp} and {@link BranchOp} need to reference their target |
19572
9bb45bec2b1f
Run eclipseformat.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19567
diff
changeset
|
32 * {@link AbstractBlockBase}. However, direct references are not possible since the control flow |
9bb45bec2b1f
Run eclipseformat.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19567
diff
changeset
|
33 * graph (and therefore successors lists) can be changed by optimizations - and fixing the |
9bb45bec2b1f
Run eclipseformat.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19567
diff
changeset
|
34 * instructions is error prone. Therefore, we represent an edge to block B from block A via the |
9bb45bec2b1f
Run eclipseformat.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19567
diff
changeset
|
35 * tuple {@code (A, |
13268
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
36 * successor-index-of-B)}. That is, indirectly by storing the index into the successor list of A. |
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
37 * Note therefore that the successor list cannot be re-ordered. |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
38 */ |
13268
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
39 public final class LabelRef { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
40 |
13268
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
41 private final LIR lir; |
19567
4d70d150944f
Remove AbstractBlock interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
15301
diff
changeset
|
42 private final AbstractBlockBase<?> block; |
13268
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
43 private final int suxIndex; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
44 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
45 /** |
8322
4f8143c9947a
Remove unused code in LabelRef.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
46 * Returns a new reference to a successor of the given block. |
14946
31ded66cd2cb
Use AbstractBlock in LabelRef.
Josef Eisl <josef.eisl@jku.at>
parents:
14806
diff
changeset
|
47 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
48 * @param block The base block that contains the successor list. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
49 * @param suxIndex The index of the successor. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
50 * @return The newly created label reference. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
51 */ |
19567
4d70d150944f
Remove AbstractBlock interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
15301
diff
changeset
|
52 public static LabelRef forSuccessor(final LIR lir, final AbstractBlockBase<?> block, final int suxIndex) { |
13268
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
53 return new LabelRef(lir, block, suxIndex); |
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
54 } |
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
55 |
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
56 /** |
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
57 * Returns a new reference to a successor of the given block. |
14946
31ded66cd2cb
Use AbstractBlock in LabelRef.
Josef Eisl <josef.eisl@jku.at>
parents:
14806
diff
changeset
|
58 * |
13268
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
59 * @param block The base block that contains the successor list. |
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
60 * @param suxIndex The index of the successor. |
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
61 */ |
19567
4d70d150944f
Remove AbstractBlock interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
15301
diff
changeset
|
62 private LabelRef(final LIR lir, final AbstractBlockBase<?> block, final int suxIndex) { |
13268
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
63 this.lir = lir; |
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
64 this.block = block; |
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
65 this.suxIndex = suxIndex; |
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
66 } |
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
67 |
19567
4d70d150944f
Remove AbstractBlock interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
15301
diff
changeset
|
68 public AbstractBlockBase<?> getSourceBlock() { |
13268
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
69 return block; |
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
70 } |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7497
diff
changeset
|
71 |
19567
4d70d150944f
Remove AbstractBlock interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
15301
diff
changeset
|
72 public AbstractBlockBase<?> getTargetBlock() { |
13268
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
73 return block.getSuccessors().get(suxIndex); |
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
74 } |
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
75 |
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
76 public Label label() { |
14806
a8723f1ff542
LIR renamed setter and getter functions.
Josef Eisl <josef.eisl@jku.at>
parents:
13318
diff
changeset
|
77 return ((StandardOp.LabelOp) lir.getLIRforBlock(getTargetBlock()).get(0)).getLabel(); |
13268
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
78 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
79 |
13268
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
80 @Override |
68b964b6dc8e
introduced BlockEndOp interface and require that every LIR block is terminated by such an operation
Doug Simon <doug.simon@oracle.com>
parents:
8322
diff
changeset
|
81 public String toString() { |
13316
26472d911fcd
improved LabelRef.toString()
Doug Simon <doug.simon@oracle.com>
parents:
13268
diff
changeset
|
82 return getSourceBlock() + " -> " + (suxIndex < block.getSuccessors().size() ? getTargetBlock() : "?"); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
83 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
84 } |