annotate graal/GraalCompiler/src/com/sun/c1x/ir/If.java @ 2862:45422967cbcf

Rename Materialize => NormalizeCompare
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Tue, 07 Jun 2011 16:32:35 +0200
parents 14708c03abba
children 7d7cf33f8466
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.ir;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
24
2602
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2581
diff changeset
25 import com.oracle.graal.graph.*;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
26 import com.sun.c1x.debug.*;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
27 import com.sun.c1x.util.*;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
28 import com.sun.cri.ci.*;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
29
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
30 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
31 * The {@code If} instruction represents a branch that can go one of two directions
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
32 * depending on the outcome of a comparison.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
33 */
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
34 public final class If extends BlockEnd {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
35
2862
45422967cbcf Rename Materialize => NormalizeCompare
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2851
diff changeset
36 private static final int INPUT_COUNT = 1;
45422967cbcf Rename Materialize => NormalizeCompare
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2851
diff changeset
37 private static final int INPUT_COMPARE = 0;
2602
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2581
diff changeset
38
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2581
diff changeset
39 private static final int SUCCESSOR_COUNT = 0;
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2581
diff changeset
40
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2581
diff changeset
41 @Override
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2581
diff changeset
42 protected int inputCount() {
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2581
diff changeset
43 return super.inputCount() + INPUT_COUNT;
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2581
diff changeset
44 }
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2581
diff changeset
45
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2581
diff changeset
46 @Override
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2581
diff changeset
47 protected int successorCount() {
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2581
diff changeset
48 return super.successorCount() + SUCCESSOR_COUNT;
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2581
diff changeset
49 }
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2581
diff changeset
50
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2581
diff changeset
51 /**
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2581
diff changeset
52 * The instruction that produces the first input to this comparison.
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2581
diff changeset
53 */
2862
45422967cbcf Rename Materialize => NormalizeCompare
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2851
diff changeset
54 public Compare compare() {
45422967cbcf Rename Materialize => NormalizeCompare
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2851
diff changeset
55 return (Compare) inputs().get(super.inputCount() + INPUT_COMPARE);
2602
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2581
diff changeset
56 }
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2581
diff changeset
57
2862
45422967cbcf Rename Materialize => NormalizeCompare
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2851
diff changeset
58 public Value setCompare(Compare n) {
45422967cbcf Rename Materialize => NormalizeCompare
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2851
diff changeset
59 return (Value) inputs().set(super.inputCount() + INPUT_COMPARE, n);
2507
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
2862
45422967cbcf Rename Materialize => NormalizeCompare
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2851
diff changeset
62 public If(Compare compare, Graph graph) {
45422967cbcf Rename Materialize => NormalizeCompare
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2851
diff changeset
63 super(CiKind.Illegal, 2, INPUT_COUNT, SUCCESSOR_COUNT, graph);
45422967cbcf Rename Materialize => NormalizeCompare
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2851
diff changeset
64 setCompare(compare);
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
65 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
66
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
67 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
68 * Gets the block corresponding to the true successor.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
69 * @return the true successor
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
70 */
2755
80b024e75b29 small fix for dead blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2750
diff changeset
71 public Instruction trueSuccessor() {
2602
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2581
diff changeset
72 return blockSuccessor(0);
2507
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
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
75 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
76 * Gets the block corresponding to the false successor.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
77 * @return the false successor
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
78 */
2755
80b024e75b29 small fix for dead blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2750
diff changeset
79 public Instruction falseSuccessor() {
2602
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2581
diff changeset
80 return blockSuccessor(1);
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
81 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
82
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
83 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
84 * Gets the block corresponding to the specified outcome of the branch.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
85 * @param istrue {@code true} if the true successor is requested, {@code false} otherwise
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
86 * @return the corresponding successor
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
87 */
2755
80b024e75b29 small fix for dead blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2750
diff changeset
88 public Instruction successor(boolean istrue) {
2602
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2581
diff changeset
89 return blockSuccessor(istrue ? 0 : 1);
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
90 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
91
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
92 @Override
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
93 public void accept(ValueVisitor v) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
94 v.visitIf(this);
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
95 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
96
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
97 @Override
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
98 public void print(LogStream out) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
99 out.print("if ").
2862
45422967cbcf Rename Materialize => NormalizeCompare
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2851
diff changeset
100 print(compare().x()).
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
101 print(' ').
2862
45422967cbcf Rename Materialize => NormalizeCompare
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2851
diff changeset
102 print(compare().condition().operator).
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
103 print(' ').
2862
45422967cbcf Rename Materialize => NormalizeCompare
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2851
diff changeset
104 print(compare().y()).
2793
d3fc4fe063bf Rename BlockBegin to Merge, remove some Block related member from it. Made CFGPrinter work with the Block class from schedule
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2776
diff changeset
105 print(" then ").
d3fc4fe063bf Rename BlockBegin to Merge, remove some Block related member from it. Made CFGPrinter work with the Block class from schedule
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2776
diff changeset
106 print(blockSuccessors().get(0)).
d3fc4fe063bf Rename BlockBegin to Merge, remove some Block related member from it. Made CFGPrinter work with the Block class from schedule
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2776
diff changeset
107 print(" else ").
d3fc4fe063bf Rename BlockBegin to Merge, remove some Block related member from it. Made CFGPrinter work with the Block class from schedule
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2776
diff changeset
108 print(blockSuccessors().get(1));
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
109 }
2616
3558ca7088c0 FrameState and Graphviz changes:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2602
diff changeset
110
3558ca7088c0 FrameState and Graphviz changes:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2602
diff changeset
111 @Override
3558ca7088c0 FrameState and Graphviz changes:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2602
diff changeset
112 public String shortName() {
2862
45422967cbcf Rename Materialize => NormalizeCompare
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2851
diff changeset
113 return "If " + compare().condition.operator;
2616
3558ca7088c0 FrameState and Graphviz changes:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2602
diff changeset
114 }
3558ca7088c0 FrameState and Graphviz changes:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2602
diff changeset
115
2827
bd17ac598c6e Graph cloning, initial version (not completely working)
Lukas Stadler <lukas.stadler@jku.at>
parents: 2793
diff changeset
116 @Override
bd17ac598c6e Graph cloning, initial version (not completely working)
Lukas Stadler <lukas.stadler@jku.at>
parents: 2793
diff changeset
117 public Node copy(Graph into) {
2862
45422967cbcf Rename Materialize => NormalizeCompare
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2851
diff changeset
118 return new If(compare(), into);
2827
bd17ac598c6e Graph cloning, initial version (not completely working)
Lukas Stadler <lukas.stadler@jku.at>
parents: 2793
diff changeset
119 }
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
120 }