Mercurial > hg > truffle
annotate graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/calc/CompareNode.java @ 3531:dc4268828826
Fourth round of refactoring.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 10 Aug 2011 01:12:36 +0200 |
parents | |
children |
rev | line source |
---|---|
3531
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
1 /* |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
2 * Copyright (c) 2011, 2011, Oracle and/or its affiliates. All rights reserved. |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
4 * |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
8 * |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
13 * accompanied this code). |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
14 * |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
18 * |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
21 * questions. |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
22 */ |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
23 package com.oracle.max.graal.nodes.calc; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
24 |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
25 import java.util.*; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
26 |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
27 import com.oracle.max.graal.graph.*; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
28 import com.oracle.max.graal.nodes.*; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
29 import com.oracle.max.graal.nodes.spi.*; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
30 import com.sun.cri.ci.*; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
31 |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
32 /* (tw/gd) For high-level optimization purpose the compare node should be a boolean *value* (it is currently only a helper node) |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
33 * But in the back-end the comparison should not always be materialized (for example in x86 the comparison result will not be in a register but in a flag) |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
34 * |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
35 * Compare should probably be made a value (so that it can be canonicalized for example) and in later stages some Compare usage should be transformed |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
36 * into variants that do not materialize the value (CompareIf, CompareGuard...) |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
37 * |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
38 */ |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
39 public final class CompareNode extends BooleanNode implements Canonicalizable { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
40 |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
41 @Input private ValueNode x; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
42 @Input private ValueNode y; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
43 |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
44 @Data private Condition condition; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
45 @Data private boolean unorderedIsTrue; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
46 |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
47 public ValueNode x() { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
48 return x; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
49 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
50 |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
51 public void setX(ValueNode x) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
52 updateUsages(this.x, x); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
53 this.x = x; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
54 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
55 |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
56 public ValueNode y() { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
57 return y; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
58 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
59 |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
60 public void setY(ValueNode x) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
61 updateUsages(y, x); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
62 this.y = x; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
63 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
64 |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
65 /** |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
66 * Constructs a new Compare instruction. |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
67 * |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
68 * @param x the instruction producing the first input to the instruction |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
69 * @param condition the condition (comparison operation) |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
70 * @param y the instruction that produces the second input to this instruction |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
71 * @param graph |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
72 */ |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
73 public CompareNode(ValueNode x, Condition condition, ValueNode y, Graph graph) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
74 super(CiKind.Illegal, graph); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
75 assert (x == null && y == null) || x.kind == y.kind; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
76 this.condition = condition; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
77 setX(x); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
78 setY(y); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
79 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
80 |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
81 /** |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
82 * Gets the condition (comparison operation) for this instruction. |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
83 * |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
84 * @return the condition |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
85 */ |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
86 public Condition condition() { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
87 return condition; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
88 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
89 |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
90 /** |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
91 * Checks whether unordered inputs mean true or false. |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
92 * |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
93 * @return {@code true} if unordered inputs produce true |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
94 */ |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
95 public boolean unorderedIsTrue() { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
96 return unorderedIsTrue; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
97 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
98 |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
99 public void setUnorderedIsTrue(boolean unorderedIsTrue) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
100 this.unorderedIsTrue = unorderedIsTrue; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
101 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
102 |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
103 /** |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
104 * Swaps the operands to this if and mirrors the condition (e.g. > becomes <). |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
105 * |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
106 * @see Condition#mirror() |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
107 */ |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
108 public void swapOperands() { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
109 condition = condition.mirror(); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
110 ValueNode t = x(); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
111 setX(y()); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
112 setY(t); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
113 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
114 |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
115 public void negate() { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
116 condition = condition.negate(); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
117 unorderedIsTrue = !unorderedIsTrue; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
118 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
119 |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
120 @Override |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
121 public void accept(ValueVisitor v) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
122 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
123 |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
124 @Override |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
125 public String shortName() { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
126 return "Comp " + condition.operator; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
127 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
128 |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
129 @Override |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
130 public Map<Object, Object> getDebugProperties() { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
131 Map<Object, Object> properties = super.getDebugProperties(); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
132 properties.put("unorderedIsTrue", unorderedIsTrue()); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
133 return properties; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
134 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
135 |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
136 private Node optimizeMaterialize(CiConstant constant, MaterializeNode materializeNode) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
137 if (constant.kind == CiKind.Int) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
138 boolean isFalseCheck = (constant.asInt() == 0); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
139 if (condition == Condition.EQ || condition == Condition.NE) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
140 if (condition == Condition.NE) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
141 isFalseCheck = !isFalseCheck; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
142 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
143 BooleanNode result = materializeNode.condition(); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
144 if (isFalseCheck) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
145 result = new NegateBooleanNode(result, graph()); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
146 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
147 return result; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
148 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
149 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
150 return this; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
151 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
152 |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
153 private Node optimizeNormalizeCmp(CiConstant constant, NormalizeCompareNode normalizeNode) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
154 if (constant.kind == CiKind.Int && constant.asInt() == 0) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
155 Condition condition = condition(); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
156 if (normalizeNode == y()) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
157 condition = condition.mirror(); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
158 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
159 CompareNode result = new CompareNode(normalizeNode.x(), condition, normalizeNode.y(), graph()); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
160 boolean isLess = condition == Condition.LE || condition == Condition.LT || condition == Condition.BE || condition == Condition.BT; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
161 result.unorderedIsTrue = condition != Condition.EQ && (condition == Condition.NE || !(isLess ^ normalizeNode.isUnorderedLess())); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
162 return result; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
163 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
164 return this; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
165 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
166 |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
167 @Override |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
168 public Node canonical(NotifyReProcess reProcess) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
169 if (x().isConstant() && !y().isConstant()) { // move constants to the left (y) |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
170 swapOperands(); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
171 } else if (x().isConstant() && y().isConstant()) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
172 CiConstant constX = x().asConstant(); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
173 CiConstant constY = y().asConstant(); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
174 Boolean result = condition().foldCondition(constX, constY, ((CompilerGraph) graph()).runtime(), unorderedIsTrue()); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
175 if (result != null) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
176 return ConstantNode.forBoolean(result, graph()); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
177 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
178 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
179 |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
180 if (y().isConstant()) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
181 if (x() instanceof MaterializeNode) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
182 return optimizeMaterialize(y().asConstant(), (MaterializeNode) x()); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
183 } else if (x() instanceof NormalizeCompareNode) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
184 return optimizeNormalizeCmp(y().asConstant(), (NormalizeCompareNode) x()); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
185 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
186 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
187 |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
188 if (x() == y() && x().kind != CiKind.Float && x().kind != CiKind.Double) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
189 return ConstantNode.forBoolean(condition().check(1, 1), graph()); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
190 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
191 if ((condition == Condition.NE || condition == Condition.EQ) && x().kind == CiKind.Object) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
192 ValueNode object = null; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
193 if (x().isNullConstant()) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
194 object = y(); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
195 } else if (y().isNullConstant()) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
196 object = x(); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
197 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
198 if (object != null) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
199 IsNonNullNode nonNull = new IsNonNullNode(object, graph()); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
200 if (condition == Condition.NE) { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
201 return nonNull; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
202 } else { |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
203 assert condition == Condition.EQ; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
204 return new NegateBooleanNode(nonNull, graph()); |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
205 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
206 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
207 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
208 return this; |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
209 } |
dc4268828826
Fourth round of refactoring.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
210 } |