comparison 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
comparison
equal deleted inserted replaced
2846:9b8c194c1b1f 2856:3a4ad04d60a1
1 /*
2 * Copyright (c) 2011, 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.ci.*;
29
30 public final class Compare extends Value {
31
32 private static final int INPUT_COUNT = 2;
33 private static final int INPUT_X = 0;
34 private static final int INPUT_Y = 1;
35
36 private static final int SUCCESSOR_COUNT = 0;
37
38 @Override
39 protected int inputCount() {
40 return super.inputCount() + INPUT_COUNT;
41 }
42
43 @Override
44 protected int successorCount() {
45 return super.successorCount() + SUCCESSOR_COUNT;
46 }
47
48 /**
49 * The instruction that produces the first input to this comparison.
50 */
51 public Value x() {
52 return (Value) inputs().get(super.inputCount() + INPUT_X);
53 }
54
55 public Value setX(Value n) {
56 return (Value) inputs().set(super.inputCount() + INPUT_X, n);
57 }
58
59 /**
60 * The instruction that produces the second input to this comparison.
61 */
62 public Value y() {
63 return (Value) inputs().get(super.inputCount() + INPUT_Y);
64 }
65
66 public Value setY(Value n) {
67 return (Value) inputs().set(super.inputCount() + INPUT_Y, n);
68 }
69
70 Condition condition;
71 boolean unorderedIsTrue;
72
73 /**
74 * Constructs a new If instruction.
75 * @param x the instruction producing the first input to the instruction
76 * @param condition the condition (comparison operation)
77 * @param y the instruction that produces the second input to this instruction
78 * @param graph
79 */
80 public Compare(Value x, Condition condition, Value y, Graph graph) {
81 super(CiKind.Illegal, INPUT_COUNT, SUCCESSOR_COUNT, graph);
82 assert (x == null && y == null) || Util.archKindsEqual(x, y);
83 this.condition = condition;
84 setX(x);
85 setY(y);
86 }
87
88 /**
89 * Gets the condition (comparison operation) for this instruction.
90 * @return the condition
91 */
92 public Condition condition() {
93 return condition;
94 }
95
96 /**
97 * Checks whether unordered inputs mean true or false.
98 * @return {@code true} if unordered inputs produce true
99 */
100 public boolean unorderedIsTrue() {
101 return unorderedIsTrue;
102 }
103
104 /**
105 * Swaps the operands to this if and reverses the condition (e.g. > goes to <=).
106 * @see Condition#mirror()
107 */
108 public void swapOperands() {
109 condition = condition.mirror();
110 Value t = x();
111 setX(y());
112 setY(t);
113 }
114
115 @Override
116 public void accept(ValueVisitor v) {
117 }
118
119 @Override
120 public void print(LogStream out) {
121 out.print("comp ").
122 print(x()).
123 print(' ').
124 print(condition().operator).
125 print(' ').
126 print(y());
127 }
128
129 @Override
130 public String shortName() {
131 return "Comp " + condition.operator;
132 }
133
134 @Override
135 public Node copy(Graph into) {
136 Compare x = new Compare(null, condition, null, into);
137 x.unorderedIsTrue = unorderedIsTrue;
138 x.setNonNull(isNonNull());
139 return x;
140 }
141 }