Mercurial > hg > truffle
annotate graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/ArrayEqualsNode.java @ 19499:787a3c7235ef
weakened assertion in ArrayEqualsNode constructor
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 19 Feb 2015 11:21:40 +0100 |
parents | 61d3cb8e1280 |
children | 8fc336a04d77 |
rev | line source |
---|---|
13973 | 1 /* |
2 * Copyright (c) 2013, 2014, 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.oracle.graal.replacements.nodes; | |
24 | |
25 import com.oracle.graal.api.meta.*; | |
15261
882f4cb7cfcf
Move Stamps to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents:
14888
diff
changeset
|
26 import com.oracle.graal.compiler.common.type.*; |
13973 | 27 import com.oracle.graal.graph.*; |
28 import com.oracle.graal.graph.spi.*; | |
16841
cbd42807a31f
moved NodeInfo and friends into separate com.oracle.graal.nodeinfo project so that annotation processor can be applied to the base Node class
Doug Simon <doug.simon@oracle.com>
parents:
16822
diff
changeset
|
29 import com.oracle.graal.nodeinfo.*; |
13973 | 30 import com.oracle.graal.nodes.*; |
16708
3d177d06e47c
ArrayEqualsNode is a memory access
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16248
diff
changeset
|
31 import com.oracle.graal.nodes.extended.*; |
14611
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
32 import com.oracle.graal.nodes.spi.*; |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
33 import com.oracle.graal.nodes.util.*; |
13973 | 34 |
35 /** | |
36 * Compares two arrays with the same length. | |
37 */ | |
16822
5d468add216f
added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents:
16708
diff
changeset
|
38 @NodeInfo |
18998
ec0733b5a90a
Allow final modifier on node subclasses and start adding the modifier to leaf classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18937
diff
changeset
|
39 public final class ArrayEqualsNode extends FixedWithNextNode implements LIRLowerable, Canonicalizable, Virtualizable, MemoryAccess { |
13973 | 40 |
19403
61d3cb8e1280
Add generic parameter to NodeClass. Change Graph#getNodes(Class) to Graph#getNodes(NodeClass).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19396
diff
changeset
|
41 public static final NodeClass<ArrayEqualsNode> TYPE = NodeClass.get(ArrayEqualsNode.class); |
13973 | 42 /** {@link Kind} of the arrays to compare. */ |
17328
c9bb0da795d4
Backed out of changeset 17322:655f3e6b467b
Doug Simon <doug.simon@oracle.com>
parents:
17327
diff
changeset
|
43 protected final Kind kind; |
13973 | 44 |
45 /** One array to be tested for equality. */ | |
16897
f90dcdbbb75e
switched to using new NodeFieldIterator and NodeFieldIterable for traversing Node inputs and successors
Doug Simon <doug.simon@oracle.com>
parents:
16895
diff
changeset
|
46 @Input ValueNode array1; |
13973 | 47 |
48 /** The other array to be tested for equality. */ | |
16897
f90dcdbbb75e
switched to using new NodeFieldIterator and NodeFieldIterable for traversing Node inputs and successors
Doug Simon <doug.simon@oracle.com>
parents:
16895
diff
changeset
|
49 @Input ValueNode array2; |
13973 | 50 |
51 /** Length of both arrays. */ | |
16897
f90dcdbbb75e
switched to using new NodeFieldIterator and NodeFieldIterable for traversing Node inputs and successors
Doug Simon <doug.simon@oracle.com>
parents:
16895
diff
changeset
|
52 @Input ValueNode length; |
13973 | 53 |
18845
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
17450
diff
changeset
|
54 public ArrayEqualsNode(ValueNode array1, ValueNode array2, ValueNode length) { |
19396
7e2c87dae93e
Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18998
diff
changeset
|
55 super(TYPE, StampFactory.forKind(Kind.Boolean)); |
19499
787a3c7235ef
weakened assertion in ArrayEqualsNode constructor
Doug Simon <doug.simon@oracle.com>
parents:
19403
diff
changeset
|
56 // Ignore nullness in stamp equality test |
787a3c7235ef
weakened assertion in ArrayEqualsNode constructor
Doug Simon <doug.simon@oracle.com>
parents:
19403
diff
changeset
|
57 assert array1.stamp().join(StampFactory.objectNonNull()).equals(array2.stamp().join(StampFactory.objectNonNull())); |
17276
ffb974bef674
moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
58 ObjectStamp array1Stamp = (ObjectStamp) array1.stamp(); |
ffb974bef674
moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
59 ResolvedJavaType componentType = array1Stamp.type().getComponentType(); |
13973 | 60 this.kind = componentType.getKind(); |
61 this.array1 = array1; | |
62 this.array2 = array2; | |
63 this.length = length; | |
64 } | |
65 | |
66 @Override | |
67 public Node canonical(CanonicalizerTool tool) { | |
18937
ff232ff8d028
Add utility Node#hasNoUsages.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
68 if (hasNoUsages()) { |
14611
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
69 return null; |
13973 | 70 } |
14611
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
71 if (GraphUtil.unproxify(array1) == GraphUtil.unproxify(array2)) { |
16248
c5b2a3c22318
refactor more Canonicalizable implementations to not add new nodes to the graph
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16092
diff
changeset
|
72 return ConstantNode.forBoolean(true); |
14611
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
73 } |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
74 return this; |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
75 } |
13973 | 76 |
14611
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
77 public void virtualize(VirtualizerTool tool) { |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
78 State state1 = tool.getObjectState(array1); |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
79 if (state1 != null) { |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
80 State state2 = tool.getObjectState(array2); |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
81 if (state2 != null) { |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
82 if (state1.getVirtualObject() == state2.getVirtualObject()) { |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
83 // the same virtual objects will always have the same contents |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
84 tool.replaceWithValue(ConstantNode.forBoolean(true, graph())); |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
85 } else if (state1.getVirtualObject().entryCount() == state2.getVirtualObject().entryCount()) { |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
86 int entryCount = state1.getVirtualObject().entryCount(); |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
87 boolean allEqual = true; |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
88 for (int i = 0; i < entryCount; i++) { |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
89 ValueNode entry1 = state1.getEntry(i); |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
90 ValueNode entry2 = state2.getEntry(i); |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
91 if (entry1 != entry2) { |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
92 // the contents might be different |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
93 allEqual = false; |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
94 } |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
95 if (entry1.stamp().alwaysDistinct(entry2.stamp())) { |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
96 // the contents are different |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
97 tool.replaceWithValue(ConstantNode.forBoolean(false, graph())); |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
98 return; |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
99 } |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
100 } |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
101 if (allEqual) { |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
102 tool.replaceWithValue(ConstantNode.forBoolean(true, graph())); |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
103 } |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
104 } |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
105 } |
13973 | 106 } |
107 } | |
108 | |
109 @NodeIntrinsic | |
110 public static native boolean equals(boolean[] array1, boolean[] array2, int length); | |
111 | |
112 @NodeIntrinsic | |
113 public static native boolean equals(byte[] array1, byte[] array2, int length); | |
114 | |
115 @NodeIntrinsic | |
116 public static native boolean equals(char[] array1, char[] array2, int length); | |
117 | |
118 @NodeIntrinsic | |
119 public static native boolean equals(short[] array1, short[] array2, int length); | |
120 | |
121 @NodeIntrinsic | |
122 public static native boolean equals(int[] array1, int[] array2, int length); | |
123 | |
124 @NodeIntrinsic | |
125 public static native boolean equals(long[] array1, long[] array2, int length); | |
126 | |
127 @NodeIntrinsic | |
128 public static native boolean equals(float[] array1, float[] array2, int length); | |
129 | |
130 @NodeIntrinsic | |
131 public static native boolean equals(double[] array1, double[] array2, int length); | |
132 | |
133 @Override | |
15334
abebb5c2dc09
Use NodeLIRBuilderTool in LIRGenLowerable.
Josef Eisl <josef.eisl@jku.at>
parents:
15261
diff
changeset
|
134 public void generate(NodeLIRBuilderTool gen) { |
16092
51ba6c521922
Refactor LIRGeneratorTool methods.
Roland Schatz <roland.schatz@oracle.com>
parents:
15335
diff
changeset
|
135 Value result = gen.getLIRGeneratorTool().emitArrayEquals(kind, gen.operand(array1), gen.operand(array2), gen.operand(length)); |
13973 | 136 gen.setResult(this, result); |
137 } | |
16708
3d177d06e47c
ArrayEqualsNode is a memory access
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16248
diff
changeset
|
138 |
3d177d06e47c
ArrayEqualsNode is a memory access
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16248
diff
changeset
|
139 public LocationIdentity getLocationIdentity() { |
3d177d06e47c
ArrayEqualsNode is a memory access
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16248
diff
changeset
|
140 return NamedLocationIdentity.getArrayLocation(kind); |
3d177d06e47c
ArrayEqualsNode is a memory access
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16248
diff
changeset
|
141 } |
13973 | 142 } |