Mercurial > hg > graal-compiler
comparison graal/GraalCompiler/src/com/sun/c1x/ir/Conditional.java @ 2852:c6bdec623ef9
Move TypeCHeck to floating nodes, rename Nodes to aboid using an *Op suffix
author | Gilles Duboscq <gilles.duboscq@oracle.com> |
---|---|
date | Tue, 07 Jun 2011 12:10:27 +0200 |
parents | graal/GraalCompiler/src/com/sun/c1x/ir/IfOp.java@14708c03abba |
children |
comparison
equal
deleted
inserted
replaced
2851:14708c03abba | 2852:c6bdec623ef9 |
---|---|
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.oracle.graal.graph.*; | |
26 import com.sun.c1x.debug.*; | |
27 import com.sun.c1x.util.*; | |
28 import com.sun.cri.bytecode.*; | |
29 import com.sun.cri.ci.*; | |
30 | |
31 /** | |
32 * The {@code IfOp} class represents a comparison that yields one of two values. | |
33 * Note that these nodes are not built directly from the bytecode but are introduced | |
34 * by conditional expression elimination. | |
35 */ | |
36 public final class Conditional extends Binary { | |
37 | |
38 private static final int INPUT_COUNT = 2; | |
39 private static final int INPUT_TRUE_VALUE = 0; | |
40 private static final int INPUT_FALSE_VALUE = 1; | |
41 | |
42 private static final int SUCCESSOR_COUNT = 0; | |
43 | |
44 @Override | |
45 protected int inputCount() { | |
46 return super.inputCount() + INPUT_COUNT; | |
47 } | |
48 | |
49 @Override | |
50 protected int successorCount() { | |
51 return super.successorCount() + SUCCESSOR_COUNT; | |
52 } | |
53 | |
54 | |
55 /** | |
56 * The instruction that produces the value if the comparison is true. | |
57 */ | |
58 public Value trueValue() { | |
59 return (Value) inputs().get(super.inputCount() + INPUT_TRUE_VALUE); | |
60 } | |
61 | |
62 public Value setTrueValue(Value n) { | |
63 return (Value) inputs().set(super.inputCount() + INPUT_TRUE_VALUE, n); | |
64 } | |
65 | |
66 /** | |
67 * The instruction that produces the value if the comparison is false. | |
68 */ | |
69 public Value falseValue() { | |
70 return (Value) inputs().get(super.inputCount() + INPUT_FALSE_VALUE); | |
71 } | |
72 | |
73 public Value setFalseValue(Value n) { | |
74 return (Value) inputs().set(super.inputCount() + INPUT_FALSE_VALUE, n); | |
75 } | |
76 | |
77 | |
78 Condition condition; | |
79 | |
80 /** | |
81 * Constructs a new IfOp. | |
82 * @param x the instruction producing the first value to be compared | |
83 * @param condition the condition of the comparison | |
84 * @param y the instruction producing the second value to be compared | |
85 * @param trueValue the value produced if the condition is true | |
86 * @param falseValue the value produced if the condition is false | |
87 */ | |
88 public Conditional(Value x, Condition condition, Value y, Value trueValue, Value falseValue, Graph graph) { | |
89 // TODO: return the appropriate bytecode IF_ICMPEQ, etc | |
90 super(trueValue.kind.meet(falseValue.kind), Bytecodes.ILLEGAL, x, y, INPUT_COUNT, SUCCESSOR_COUNT, graph); | |
91 this.condition = condition; | |
92 setTrueValue(trueValue); | |
93 setFalseValue(falseValue); | |
94 } | |
95 | |
96 // for copying | |
97 private Conditional(CiKind kind, Condition cond, Graph graph) { | |
98 super(kind, Bytecodes.ILLEGAL, null, null, INPUT_COUNT, SUCCESSOR_COUNT, graph); | |
99 this.condition = cond; | |
100 } | |
101 | |
102 /** | |
103 * Gets the condition of this if operation. | |
104 * @return the condition | |
105 */ | |
106 public Condition condition() { | |
107 return condition; | |
108 } | |
109 | |
110 /** | |
111 * Checks whether this comparison operator is commutative (i.e. it is either == or !=). | |
112 * @return {@code true} if this comparison is commutative | |
113 */ | |
114 public boolean isCommutative() { | |
115 return condition == Condition.EQ || condition == Condition.NE; | |
116 } | |
117 | |
118 @Override | |
119 public void accept(ValueVisitor v) { | |
120 v.visitIfOp(this); | |
121 } | |
122 | |
123 @Override | |
124 public int valueNumber() { | |
125 return Util.hash4(condition.hashCode(), x(), y(), trueValue(), falseValue()); | |
126 } | |
127 | |
128 @Override | |
129 public boolean valueEqual(Node i) { | |
130 if (i instanceof Conditional) { | |
131 Conditional o = (Conditional) i; | |
132 return opcode == o.opcode && x() == o.x() && y() == o.y() && trueValue() == o.trueValue() && falseValue() == o.falseValue(); | |
133 } | |
134 return false; | |
135 } | |
136 | |
137 @Override | |
138 public void print(LogStream out) { | |
139 out.print(x()). | |
140 print(' '). | |
141 print(condition().operator). | |
142 print(' '). | |
143 print(y()). | |
144 print(" ? "). | |
145 print(trueValue()). | |
146 print(" : "). | |
147 print(falseValue()); | |
148 } | |
149 | |
150 @Override | |
151 public Node copy(Graph into) { | |
152 Conditional x = new Conditional(kind, condition, into); | |
153 return x; | |
154 } | |
155 } |