Mercurial > hg > graal-jvmci-8
annotate graal/GraalCompiler/src/com/sun/c1x/ir/Compare.java @ 2861:29d33aac5ae3
Added compare node.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Tue, 07 Jun 2011 16:16:56 +0200 |
parents | |
children | 9075634c8d11 7d7cf33f8466 |
rev | line source |
---|---|
2861
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
1 |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
2 /* |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
3 * Copyright (c) 2011, 2011, Oracle and/or its affiliates. All rights reserved. |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
5 * |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
6 * This code is free software; you can redistribute it and/or modify it |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
7 * under the terms of the GNU General Public License version 2 only, as |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
8 * published by the Free Software Foundation. |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
9 * |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
10 * This code is distributed in the hope that it will be useful, but WITHOUT |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
13 * version 2 for more details (a copy is included in the LICENSE file that |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
14 * accompanied this code). |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
15 * |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
16 * You should have received a copy of the GNU General Public License version |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
17 * 2 along with this work; if not, write to the Free Software Foundation, |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
19 * |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
21 * or visit www.oracle.com if you need additional information or have any |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
22 * questions. |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
23 */ |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
24 package com.sun.c1x.ir; |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
25 |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
26 import com.oracle.graal.graph.*; |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
27 import com.sun.c1x.debug.*; |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
28 import com.sun.c1x.util.*; |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
29 import com.sun.cri.ci.*; |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
30 |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
31 public final class Compare extends Value { |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
32 |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
33 private static final int INPUT_COUNT = 2; |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
34 private static final int INPUT_X = 0; |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
35 private static final int INPUT_Y = 1; |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
36 |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
37 private static final int SUCCESSOR_COUNT = 0; |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
38 |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
39 @Override |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
40 protected int inputCount() { |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
41 return super.inputCount() + INPUT_COUNT; |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
42 } |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
43 |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
44 @Override |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
45 protected int successorCount() { |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
46 return super.successorCount() + SUCCESSOR_COUNT; |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
47 } |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
48 |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
49 /** |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
50 * The instruction that produces the first input to this comparison. |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
51 */ |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
52 public Value x() { |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
53 return (Value) inputs().get(super.inputCount() + INPUT_X); |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
54 } |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
55 |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
56 public Value setX(Value n) { |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
57 return (Value) inputs().set(super.inputCount() + INPUT_X, n); |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
58 } |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
59 |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
60 /** |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
61 * The instruction that produces the second input to this comparison. |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
62 */ |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
63 public Value y() { |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
64 return (Value) inputs().get(super.inputCount() + INPUT_Y); |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
65 } |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
66 |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
67 public Value setY(Value n) { |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
68 return (Value) inputs().set(super.inputCount() + INPUT_Y, n); |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
69 } |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
70 |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
71 Condition condition; |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
72 boolean unorderedIsTrue; |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
73 |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
74 /** |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
75 * Constructs a new If instruction. |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
76 * @param x the instruction producing the first input to the instruction |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
77 * @param condition the condition (comparison operation) |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
78 * @param y the instruction that produces the second input to this instruction |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
79 * @param graph |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
80 */ |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
81 public Compare(Value x, Condition condition, Value y, Graph graph) { |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
82 super(CiKind.Illegal, INPUT_COUNT, SUCCESSOR_COUNT, graph); |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
83 assert (x == null && y == null) || Util.archKindsEqual(x, y); |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
84 this.condition = condition; |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
85 setX(x); |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
86 setY(y); |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
87 } |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
88 |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
89 /** |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
90 * Gets the condition (comparison operation) for this instruction. |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
91 * @return the condition |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
92 */ |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
93 public Condition condition() { |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
94 return condition; |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
95 } |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
96 |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
97 /** |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
98 * Checks whether unordered inputs mean true or false. |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
99 * @return {@code true} if unordered inputs produce true |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
100 */ |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
101 public boolean unorderedIsTrue() { |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
102 return unorderedIsTrue; |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
103 } |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
104 |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
105 /** |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
106 * Swaps the operands to this if and reverses the condition (e.g. > goes to <=). |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
107 * @see Condition#mirror() |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
108 */ |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
109 public void swapOperands() { |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
110 condition = condition.mirror(); |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
111 Value t = x(); |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
112 setX(y()); |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
113 setY(t); |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
114 } |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
115 |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
116 @Override |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
117 public void accept(ValueVisitor v) { |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
118 } |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
119 |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
120 @Override |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
121 public void print(LogStream out) { |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
122 out.print("comp "). |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
123 print(x()). |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
124 print(' '). |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
125 print(condition().operator). |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
126 print(' '). |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
127 print(y()); |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
128 } |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
129 |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
130 @Override |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
131 public String shortName() { |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
132 return "Comp " + condition.operator; |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
133 } |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
134 |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
135 @Override |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
136 public Node copy(Graph into) { |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
137 Compare x = new Compare(null, condition, null, into); |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
138 x.unorderedIsTrue = unorderedIsTrue; |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
139 return x; |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
140 } |
29d33aac5ae3
Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
141 } |