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