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