annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnsafeAccessNode.java @ 11881:da9db8331658

moved Canonicalizable and Simplifiable to the com.oracle.graal.graph project (GRAAL-506)
author Doug Simon <doug.simon@oracle.com>
date Tue, 01 Oct 2013 20:38:25 +0200
parents 9a747d8e0d0f
children 88fb9cba8751
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7090
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
1 /*
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
4 *
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
8 *
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
13 * accompanied this code).
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
14 *
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
18 *
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
21 * questions.
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
22 */
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
23 package com.oracle.graal.nodes.extended;
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
24
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
25 import com.oracle.graal.api.meta.*;
11880
9a747d8e0d0f broadened types in Canonicalizable interface so that it can be moved to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents: 11265
diff changeset
26 import com.oracle.graal.graph.*;
11881
da9db8331658 moved Canonicalizable and Simplifiable to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents: 11880
diff changeset
27 import com.oracle.graal.graph.spi.*;
7090
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
28 import com.oracle.graal.nodes.*;
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
29 import com.oracle.graal.nodes.type.*;
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
30
10647
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
31 public abstract class UnsafeAccessNode extends FixedWithNextNode implements Canonicalizable {
7090
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
32
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
33 @Input private ValueNode object;
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
34 @Input private ValueNode offset;
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
35 private final int displacement;
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
36 private final Kind accessKind;
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
37
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
38 public UnsafeAccessNode(Stamp stamp, ValueNode object, int displacement, ValueNode offset, Kind accessKind) {
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
39 super(stamp);
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
40 assert accessKind != null;
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
41 this.object = object;
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
42 this.displacement = displacement;
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
43 this.offset = offset;
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
44 this.accessKind = accessKind;
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
45 }
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
46
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
47 public ValueNode object() {
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
48 return object;
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
49 }
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
50
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
51 public int displacement() {
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
52 return displacement;
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
53 }
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
54
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
55 public ValueNode offset() {
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
56 return offset;
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
57 }
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
58
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
59 public Kind accessKind() {
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
60 return accessKind;
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
61 }
10647
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
62
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
63 @Override
11880
9a747d8e0d0f broadened types in Canonicalizable interface so that it can be moved to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents: 11265
diff changeset
64 public Node canonical(CanonicalizerTool tool) {
10647
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
65 if (offset().isConstant()) {
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
66 long constantOffset = offset().asConstant().asLong();
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
67
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
68 // Try to canonicalize to a field access.
11265
ef6915cf1e59 Add illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 10653
diff changeset
69 ResolvedJavaType receiverType = ObjectStamp.typeOrNull(object());
ef6915cf1e59 Add illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 10653
diff changeset
70 if (receiverType != null) {
ef6915cf1e59 Add illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 10653
diff changeset
71 ResolvedJavaField field = receiverType.findInstanceFieldWithOffset(displacement() + constantOffset);
ef6915cf1e59 Add illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 10653
diff changeset
72 // No need for checking that the receiver is non-null. The field access includes
ef6915cf1e59 Add illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 10653
diff changeset
73 // the null check and if a field is found, the offset is so small that this is
ef6915cf1e59 Add illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 10653
diff changeset
74 // never a valid access of an arbitrary address.
ef6915cf1e59 Add illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 10653
diff changeset
75 if (field != null && field.getKind() == this.accessKind()) {
ef6915cf1e59 Add illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 10653
diff changeset
76 return cloneAsFieldAccess(field);
10647
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
77 }
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
78 }
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
79
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
80 if (constantOffset != 0 && Integer.MAX_VALUE - displacement() >= constantOffset) {
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
81 int intDisplacement = (int) (constantOffset + displacement());
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
82 if (constantOffset == intDisplacement) {
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
83 return cloneWithZeroOffset(intDisplacement);
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
84 }
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
85 }
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
86 }
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
87 return this;
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
88 }
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
89
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
90 protected abstract ValueNode cloneAsFieldAccess(ResolvedJavaField field);
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
91
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
92 protected abstract ValueNode cloneWithZeroOffset(int intDisplacement);
7090
05ce1defa4f9 Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
93 }