Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/ArrayEqualsNode.java @ 16919:0fe4732e5181
made use of generated Node classes predicated on value of graal.useGeneratedNodes system property (default is false)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 25 Aug 2014 13:45:12 +0200 |
parents | f90dcdbbb75e |
children | ffb974bef674 |
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:
16811
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 */ | |
16811
5d468add216f
added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents:
16708
diff
changeset
|
38 @NodeInfo |
16708
3d177d06e47c
ArrayEqualsNode is a memory access
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16248
diff
changeset
|
39 public class ArrayEqualsNode extends FixedWithNextNode implements LIRLowerable, Canonicalizable, Virtualizable, MemoryAccess { |
13973 | 40 |
41 /** {@link Kind} of the arrays to compare. */ | |
42 private final Kind kind; | |
43 | |
44 /** 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
|
45 @Input ValueNode array1; |
13973 | 46 |
47 /** 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
|
48 @Input ValueNode array2; |
13973 | 49 |
50 /** 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
|
51 @Input ValueNode length; |
13973 | 52 |
16895
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
16841
diff
changeset
|
53 public static ArrayEqualsNode create(ValueNode array1, ValueNode array2, ValueNode length) { |
16919
0fe4732e5181
made use of generated Node classes predicated on value of graal.useGeneratedNodes system property (default is false)
Doug Simon <doug.simon@oracle.com>
parents:
16897
diff
changeset
|
54 return USE_GENERATED_NODES ? new ArrayEqualsNodeGen(array1, array2, length) : new ArrayEqualsNode(array1, array2, length); |
16895
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
16841
diff
changeset
|
55 } |
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
16841
diff
changeset
|
56 |
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
16841
diff
changeset
|
57 protected ArrayEqualsNode(ValueNode array1, ValueNode array2, ValueNode length) { |
13973 | 58 super(StampFactory.forKind(Kind.Boolean)); |
59 | |
60 assert array1.stamp().equals(array2.stamp()); | |
61 ObjectStamp stamp = (ObjectStamp) array1.stamp(); | |
62 ResolvedJavaType componentType = stamp.type().getComponentType(); | |
63 this.kind = componentType.getKind(); | |
64 | |
65 this.array1 = array1; | |
66 this.array2 = array2; | |
67 this.length = length; | |
68 } | |
69 | |
70 @Override | |
71 public Node canonical(CanonicalizerTool tool) { | |
14611
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
72 if (usages().isEmpty()) { |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
73 return null; |
13973 | 74 } |
14611
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
75 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
|
76 return ConstantNode.forBoolean(true); |
14611
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
77 } |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
78 return this; |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
79 } |
13973 | 80 |
14611
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
81 public void virtualize(VirtualizerTool tool) { |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
82 State state1 = tool.getObjectState(array1); |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
83 if (state1 != null) { |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
84 State state2 = tool.getObjectState(array2); |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
85 if (state2 != null) { |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
86 if (state1.getVirtualObject() == state2.getVirtualObject()) { |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
87 // 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
|
88 tool.replaceWithValue(ConstantNode.forBoolean(true, graph())); |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
89 } 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
|
90 int entryCount = state1.getVirtualObject().entryCount(); |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
91 boolean allEqual = true; |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
92 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
|
93 ValueNode entry1 = state1.getEntry(i); |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
94 ValueNode entry2 = state2.getEntry(i); |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
95 if (entry1 != entry2) { |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
96 // the contents might be different |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
97 allEqual = false; |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
98 } |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
99 if (entry1.stamp().alwaysDistinct(entry2.stamp())) { |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
100 // the contents are different |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
101 tool.replaceWithValue(ConstantNode.forBoolean(false, graph())); |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
102 return; |
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 if (allEqual) { |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
106 tool.replaceWithValue(ConstantNode.forBoolean(true, graph())); |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
107 } |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
108 } |
1d853e629891
fixed canonicalization of ArrayEqualsNode, added Virtualizable implementation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14585
diff
changeset
|
109 } |
13973 | 110 } |
111 } | |
112 | |
113 @NodeIntrinsic | |
114 public static native boolean equals(boolean[] array1, boolean[] array2, int length); | |
115 | |
116 @NodeIntrinsic | |
117 public static native boolean equals(byte[] array1, byte[] array2, int length); | |
118 | |
119 @NodeIntrinsic | |
120 public static native boolean equals(char[] array1, char[] array2, int length); | |
121 | |
122 @NodeIntrinsic | |
123 public static native boolean equals(short[] array1, short[] array2, int length); | |
124 | |
125 @NodeIntrinsic | |
126 public static native boolean equals(int[] array1, int[] array2, int length); | |
127 | |
128 @NodeIntrinsic | |
129 public static native boolean equals(long[] array1, long[] array2, int length); | |
130 | |
131 @NodeIntrinsic | |
132 public static native boolean equals(float[] array1, float[] array2, int length); | |
133 | |
134 @NodeIntrinsic | |
135 public static native boolean equals(double[] array1, double[] array2, int length); | |
136 | |
137 @Override | |
15334
abebb5c2dc09
Use NodeLIRBuilderTool in LIRGenLowerable.
Josef Eisl <josef.eisl@jku.at>
parents:
15261
diff
changeset
|
138 public void generate(NodeLIRBuilderTool gen) { |
16092
51ba6c521922
Refactor LIRGeneratorTool methods.
Roland Schatz <roland.schatz@oracle.com>
parents:
15335
diff
changeset
|
139 Value result = gen.getLIRGeneratorTool().emitArrayEquals(kind, gen.operand(array1), gen.operand(array2), gen.operand(length)); |
13973 | 140 gen.setResult(this, result); |
141 } | |
16708
3d177d06e47c
ArrayEqualsNode is a memory access
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16248
diff
changeset
|
142 |
3d177d06e47c
ArrayEqualsNode is a memory access
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16248
diff
changeset
|
143 public LocationIdentity getLocationIdentity() { |
3d177d06e47c
ArrayEqualsNode is a memory access
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16248
diff
changeset
|
144 return NamedLocationIdentity.getArrayLocation(kind); |
3d177d06e47c
ArrayEqualsNode is a memory access
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16248
diff
changeset
|
145 } |
13973 | 146 } |