comparison graal/Compiler/src/com/sun/c1x/ir/If.java @ 2507:9ec15d6914ca

Pull over of compiler from maxine repository.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 27 Apr 2011 11:43:22 +0200
parents
children
comparison
equal deleted inserted replaced
2506:4a3bf8a5bf41 2507:9ec15d6914ca
1 /*
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.sun.c1x.ir;
24
25 import com.sun.c1x.debug.*;
26 import com.sun.c1x.util.*;
27 import com.sun.c1x.value.*;
28 import com.sun.cri.ci.*;
29
30 /**
31 * The {@code If} instruction represents a branch that can go one of two directions
32 * depending on the outcome of a comparison.
33 *
34 * @author Ben L. Titzer
35 */
36 public final class If extends BlockEnd {
37
38 Value x;
39 Value y;
40 Condition condition;
41
42 /**
43 * Constructs a new If instruction.
44 * @param x the instruction producing the first input to the instruction
45 * @param cond the condition (comparison operation)
46 * @param unorderedIsTrue {@code true} if unordered is treated as true (floating point operations)
47 * @param y the instruction that produces the second input to this instruction
48 * @param trueSucc the block representing the true successor
49 * @param falseSucc the block representing the false successor
50 * @param stateAfter the state before the branch but after the input values have been popped
51 * @param isSafepoint {@code true} if this branch should be considered a safepoint
52 */
53 public If(Value x, Condition cond, boolean unorderedIsTrue, Value y,
54 BlockBegin trueSucc, BlockBegin falseSucc, FrameState stateAfter, boolean isSafepoint) {
55 super(CiKind.Illegal, stateAfter, isSafepoint);
56 this.x = x;
57 this.y = y;
58 condition = cond;
59 assert Util.archKindsEqual(x, y);
60 initFlag(Flag.UnorderedIsTrue, unorderedIsTrue);
61 successors.add(trueSucc);
62 successors.add(falseSucc);
63 }
64
65 /**
66 * Gets the instruction that produces the first input to this comparison.
67 * @return the instruction producing the first input
68 */
69 public Value x() {
70 return x;
71 }
72
73 /**
74 * Gets the instruction that produces the second input to this comparison.
75 * @return the instruction producing the second input
76 */
77 public Value y() {
78 return y;
79 }
80
81 /**
82 * Gets the condition (comparison operation) for this instruction.
83 * @return the condition
84 */
85 public Condition condition() {
86 return condition;
87 }
88
89 /**
90 * Checks whether unordered inputs mean true or false.
91 * @return {@code true} if unordered inputs produce true
92 */
93 public boolean unorderedIsTrue() {
94 return checkFlag(Flag.UnorderedIsTrue);
95 }
96
97 /**
98 * Gets the block corresponding to the true successor.
99 * @return the true successor
100 */
101 public BlockBegin trueSuccessor() {
102 return successors.get(0);
103 }
104
105 /**
106 * Gets the block corresponding to the false successor.
107 * @return the false successor
108 */
109 public BlockBegin falseSuccessor() {
110 return successors.get(1);
111 }
112
113 /**
114 * Gets the block corresponding to the specified outcome of the branch.
115 * @param istrue {@code true} if the true successor is requested, {@code false} otherwise
116 * @return the corresponding successor
117 */
118 public BlockBegin successor(boolean istrue) {
119 return successors.get(istrue ? 0 : 1);
120 }
121
122 /**
123 * Gets the successor of this instruction for the unordered case.
124 * @return the successor for unordered inputs
125 */
126 public BlockBegin unorderedSuccessor() {
127 return successor(unorderedIsTrue());
128 }
129
130 /**
131 * Swaps the operands to this if and reverses the condition (e.g. > goes to <=).
132 * @see Condition#mirror()
133 */
134 public void swapOperands() {
135 condition = condition.mirror();
136 Value t = x;
137 x = y;
138 y = t;
139 }
140
141 /**
142 * Swaps the successor blocks to this if and negates the condition (e.g. == goes to !=)
143 * @see Condition#negate()
144 */
145 public void swapSuccessors() {
146 setFlag(Flag.UnorderedIsTrue, !unorderedIsTrue());
147 condition = condition.negate();
148 BlockBegin t = successors.get(0);
149 BlockBegin f = successors.get(1);
150 successors.set(0, f);
151 successors.set(1, t);
152 }
153
154 @Override
155 public void inputValuesDo(ValueClosure closure) {
156 x = closure.apply(x);
157 y = closure.apply(y);
158 }
159
160 @Override
161 public void accept(ValueVisitor v) {
162 v.visitIf(this);
163 }
164
165 @Override
166 public void print(LogStream out) {
167 out.print("if ").
168 print(x()).
169 print(' ').
170 print(condition().operator).
171 print(' ').
172 print(y()).
173 print(" then B").
174 print(successors().get(0).blockID).
175 print(" else B").
176 print(successors().get(1).blockID);
177 if (isSafepoint()) {
178 out.print(" (safepoint)");
179 }
180 }
181 }