annotate graal/GraalCompiler/src/com/sun/c1x/ir/Compare.java @ 2876:7d7cf33f8466

Subclasses for arithmetic
author Gilles Duboscq <gilles.duboscq@oracle.com>
date Tue, 07 Jun 2011 22:51:22 +0200
parents 29d33aac5ae3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 * Copyright (c) 2011, 2011, Oracle and/or its affiliates. All rights reserved.
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
4 *
29d33aac5ae3 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
29d33aac5ae3 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
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
7 * published by the Free Software Foundation.
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
8 *
29d33aac5ae3 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
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
29d33aac5ae3 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
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
13 * accompanied this code).
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
14 *
29d33aac5ae3 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
29d33aac5ae3 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,
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
18 *
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
29d33aac5ae3 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
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
21 * questions.
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
22 */
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
23 package com.sun.c1x.ir;
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
24
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
25 import com.oracle.graal.graph.*;
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
26 import com.sun.c1x.debug.*;
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
27 import com.sun.c1x.util.*;
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
28 import com.sun.cri.ci.*;
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
29
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
30 public final class Compare extends Value {
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
31
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
32 private static final int INPUT_COUNT = 2;
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
33 private static final int INPUT_X = 0;
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
34 private static final int INPUT_Y = 1;
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
35
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
36 private static final int SUCCESSOR_COUNT = 0;
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
37
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
38 @Override
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
39 protected int inputCount() {
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
40 return super.inputCount() + INPUT_COUNT;
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
41 }
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 @Override
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
44 protected int successorCount() {
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
45 return super.successorCount() + SUCCESSOR_COUNT;
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
46 }
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 * The instruction that produces the first input to this comparison.
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
50 */
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
51 public Value x() {
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
52 return (Value) inputs().get(super.inputCount() + INPUT_X);
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
53 }
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 public Value setX(Value n) {
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
56 return (Value) inputs().set(super.inputCount() + INPUT_X, n);
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
57 }
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 * The instruction that produces the second input to this comparison.
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
61 */
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
62 public Value y() {
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
63 return (Value) inputs().get(super.inputCount() + INPUT_Y);
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
64 }
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 public Value setY(Value n) {
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
67 return (Value) inputs().set(super.inputCount() + INPUT_Y, n);
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
68 }
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 Condition condition;
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
71 boolean unorderedIsTrue;
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
72
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 * Constructs a new If instruction.
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
75 * @param x the instruction producing the first input to the instruction
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
76 * @param condition the condition (comparison operation)
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
77 * @param y the instruction that produces the second input to this instruction
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
78 * @param graph
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
79 */
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
80 public Compare(Value x, Condition condition, Value y, Graph graph) {
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
81 super(CiKind.Illegal, INPUT_COUNT, SUCCESSOR_COUNT, graph);
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
82 assert (x == null && y == null) || Util.archKindsEqual(x, y);
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
83 this.condition = condition;
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
84 setX(x);
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
85 setY(y);
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
86 }
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 * Gets the condition (comparison operation) for this instruction.
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
90 * @return the condition
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
91 */
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
92 public Condition condition() {
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
93 return condition;
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
94 }
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 * Checks whether unordered inputs mean true or false.
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
98 * @return {@code true} if unordered inputs produce true
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
99 */
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
100 public boolean unorderedIsTrue() {
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
101 return unorderedIsTrue;
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
102 }
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 * 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
106 * @see Condition#mirror()
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
107 */
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
108 public void swapOperands() {
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
109 condition = condition.mirror();
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
110 Value t = x();
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
111 setX(y());
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
112 setY(t);
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
113 }
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 @Override
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
116 public void accept(ValueVisitor v) {
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
117 }
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 @Override
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
120 public void print(LogStream out) {
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
121 out.print("comp ").
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
122 print(x()).
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
123 print(' ').
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
124 print(condition().operator).
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
125 print(' ').
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
126 print(y());
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
127 }
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 @Override
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
130 public String shortName() {
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
131 return "Comp " + condition.operator;
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
132 }
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 @Override
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
135 public Node copy(Graph into) {
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
136 Compare x = new Compare(null, condition, null, into);
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
137 x.unorderedIsTrue = unorderedIsTrue;
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
138 return x;
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
139 }
29d33aac5ae3 Added compare node.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
140 }