annotate graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeRewriterPhase.java @ 14633:da2431cc1506

Rename ValueNode kind() to getKind().
author Josef Eisl <josef.eisl@jku.at>
date Thu, 20 Mar 2014 11:48:39 +0100
parents 34c07ef28bc9
children ed8533832ea4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
1 /*
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
4 *
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
8 *
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
13 * accompanied this code).
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
14 *
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
18 *
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
21 * questions.
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
22 */
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.word.phases;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
24
9793
b4f12c603be5 added support for the runtime to specify for each foreign call whether it is re-executable and what memory locations it kills
Doug Simon <doug.simon@oracle.com>
parents: 9792
diff changeset
25 import static com.oracle.graal.api.meta.LocationIdentity.*;
b4f12c603be5 added support for the runtime to specify for each foreign call whether it is re-executable and what memory locations it kills
Doug Simon <doug.simon@oracle.com>
parents: 9792
diff changeset
26
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
27 import java.lang.reflect.*;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
28
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
29 import com.oracle.graal.api.meta.*;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
30 import com.oracle.graal.graph.*;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
31 import com.oracle.graal.nodes.*;
10828
b05e1ff3aac0 Rename WriteBarrierType to BarrierType
Christos Kotselidis <christos.kotselidis@oracle.com>
parents: 10821
diff changeset
32 import com.oracle.graal.nodes.HeapAccess.BarrierType;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
33 import com.oracle.graal.nodes.calc.*;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
34 import com.oracle.graal.nodes.extended.*;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
35 import com.oracle.graal.nodes.java.*;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
36 import com.oracle.graal.nodes.type.*;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
37 import com.oracle.graal.nodes.util.*;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
38 import com.oracle.graal.phases.*;
13941
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13211
diff changeset
39 import com.oracle.graal.phases.graph.*;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
40 import com.oracle.graal.word.*;
10759
7f186f1486f7 Use initializing write node in object clone snippets.
Roland Schatz <roland.schatz@oracle.com>
parents: 10546
diff changeset
41 import com.oracle.graal.word.Word.Opcode;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
42 import com.oracle.graal.word.Word.Operation;
11752
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11703
diff changeset
43 import com.oracle.graal.word.nodes.*;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
44
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
45 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7305
diff changeset
46 * Transforms all uses of the {@link Word} class into unsigned operations on {@code int} or
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7305
diff changeset
47 * {@code long} values, depending on the word kind of the underlying platform.
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
48 */
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
49 public class WordTypeRewriterPhase extends Phase {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
50
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
51 protected final MetaAccessProvider metaAccess;
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
52 protected final ResolvedJavaType wordBaseType;
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
53 protected final ResolvedJavaType wordImplType;
11816
8db5e8c4f542 Provide object read/write methods similar to Pointer.readXxxx/writeXxx that do not require casts to Word first, and use them in relevant places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11752
diff changeset
54 protected final ResolvedJavaType objectAccessType;
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
55 protected final Kind wordKind;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
56
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
57 public WordTypeRewriterPhase(MetaAccessProvider metaAccess, Kind wordKind) {
9601
278a50fb49c7 Create a LoadFieldNode for a getstatic of a static final field in the graph builder, and rely on the canonicalizer for replacing it with the constant value.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9526
diff changeset
58 this.metaAccess = metaAccess;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
59 this.wordKind = wordKind;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
60 this.wordBaseType = metaAccess.lookupJavaType(WordBase.class);
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
61 this.wordImplType = metaAccess.lookupJavaType(Word.class);
11816
8db5e8c4f542 Provide object read/write methods similar to Pointer.readXxxx/writeXxx that do not require casts to Word first, and use them in relevant places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11752
diff changeset
62 this.objectAccessType = metaAccess.lookupJavaType(ObjectAccess.class);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
63 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
64
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
65 @Override
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
66 protected void run(StructuredGraph graph) {
13941
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13211
diff changeset
67 InferStamps.inferStamps(graph);
10817
2c9332a969d6 made it possible to use enum constants in snippets
Doug Simon <doug.simon@oracle.com>
parents: 10800
diff changeset
68
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
69 for (Node n : graph.getNodes()) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
70 if (n instanceof ValueNode) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
71 changeToWord(graph, (ValueNode) n);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
72 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
73 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
74
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
75 for (Node node : graph.getNodes()) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
76 rewriteNode(graph, node);
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
77 }
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
78 }
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
79
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
80 /**
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
81 * Change the stamp for word nodes from the object stamp ({@link WordBase} or anything extending
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
82 * or implementing that interface) to the primitive word stamp.
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
83 */
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
84 protected void changeToWord(StructuredGraph graph, ValueNode node) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
85 if (isWord(node)) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
86 if (node.isConstant()) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
87 ConstantNode oldConstant = (ConstantNode) node;
12655
2c4aa758ee18 made ConstantNodes external to a Graph (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 11816
diff changeset
88 assert oldConstant.getValue().getKind() == Kind.Object;
2c4aa758ee18 made ConstantNodes external to a Graph (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 11816
diff changeset
89 WordBase value = (WordBase) oldConstant.getValue().asObject();
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
90 ConstantNode newConstant = ConstantNode.forIntegerKind(wordKind, value.rawValue(), node.graph());
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
91 graph.replaceFloating(oldConstant, newConstant);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
92
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
93 } else {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
94 node.setStamp(StampFactory.forKind(wordKind));
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
95 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
96 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
97 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
98
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
99 /**
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
100 * Clean up nodes that are no longer necessary or valid after the stamp change, and perform
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
101 * intrinsification of all methods called on word types.
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
102 */
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
103 protected void rewriteNode(StructuredGraph graph, Node node) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
104 if (node instanceof CheckCastNode) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
105 rewriteCheckCast(graph, (CheckCastNode) node);
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
106 } else if (node instanceof LoadFieldNode) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
107 rewriteLoadField(graph, (LoadFieldNode) node);
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
108 } else if (node instanceof AccessIndexedNode) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
109 rewriteAccessIndexed(graph, (AccessIndexedNode) node);
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
110 } else if (node instanceof MethodCallTargetNode) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
111 rewriteInvoke(graph, (MethodCallTargetNode) node);
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
112 }
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
113 }
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
114
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
115 /**
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
116 * Remove casts between word types (which by now no longer have kind Object).
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
117 */
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
118 protected void rewriteCheckCast(StructuredGraph graph, CheckCastNode node) {
14633
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 14024
diff changeset
119 if (node.getKind() == wordKind) {
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
120 node.replaceAtUsages(node.object());
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
121 graph.removeFixed(node);
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
122 }
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
123 }
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
124
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
125 /**
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
126 * Fold constant field reads, e.g. enum constants.
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
127 */
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
128 protected void rewriteLoadField(StructuredGraph graph, LoadFieldNode node) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
129 ConstantNode constant = node.asConstant(metaAccess);
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
130 if (constant != null) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
131 node.replaceAtUsages(constant);
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
132 graph.removeFixed(node);
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
133 }
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
134 }
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
135
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
136 /**
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
137 * Change loads and stores of word-arrays. Since the element kind is managed by the node on its
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
138 * own and not in the stamp, {@link #changeToWord} does not perform all necessary changes.
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
139 */
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
140 protected void rewriteAccessIndexed(StructuredGraph graph, AccessIndexedNode node) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
141 ResolvedJavaType arrayType = ObjectStamp.typeOrNull(node.array());
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
142 /*
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
143 * There are cases where the array does not have a known type yet, i.e., the type is null.
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
144 * In that case we assume it is not a word type.
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
145 */
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
146 if (arrayType != null && isWord(arrayType.getComponentType()) && node.elementKind() != wordKind) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
147 /*
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
148 * The elementKind of the node is a final field, and other information such as the stamp
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
149 * depends on elementKind. Therefore, just create a new node and replace the old one.
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
150 */
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
151 if (node instanceof LoadIndexedNode) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
152 graph.replaceFixedWithFixed(node, graph.add(new LoadIndexedNode(node.array(), node.index(), wordKind)));
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
153 } else if (node instanceof StoreIndexedNode) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
154 graph.replaceFixedWithFixed(node, graph.add(new StoreIndexedNode(node.array(), node.index(), wordKind, ((StoreIndexedNode) node).value())));
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
155 } else {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
156 throw GraalInternalError.shouldNotReachHere();
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
157 }
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
158 }
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
159 }
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
160
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
161 /**
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
162 * Intrinsification of methods defined on the {@link Word} class that are annotated with
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
163 * {@link Operation}.
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
164 */
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
165 protected void rewriteInvoke(StructuredGraph graph, MethodCallTargetNode callTargetNode) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
166 ResolvedJavaMethod targetMethod = callTargetNode.targetMethod();
11816
8db5e8c4f542 Provide object read/write methods similar to Pointer.readXxxx/writeXxx that do not require casts to Word first, and use them in relevant places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11752
diff changeset
167 if (!wordBaseType.isAssignableFrom(targetMethod.getDeclaringClass()) && !objectAccessType.equals(targetMethod.getDeclaringClass())) {
8db5e8c4f542 Provide object read/write methods similar to Pointer.readXxxx/writeXxx that do not require casts to Word first, and use them in relevant places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11752
diff changeset
168 /*
8db5e8c4f542 Provide object read/write methods similar to Pointer.readXxxx/writeXxx that do not require casts to Word first, and use them in relevant places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11752
diff changeset
169 * Not a method defined on WordBase or a subclass / subinterface, and not on
8db5e8c4f542 Provide object read/write methods similar to Pointer.readXxxx/writeXxx that do not require casts to Word first, and use them in relevant places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11752
diff changeset
170 * ObjectAccess, so nothing to rewrite.
8db5e8c4f542 Provide object read/write methods similar to Pointer.readXxxx/writeXxx that do not require casts to Word first, and use them in relevant places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11752
diff changeset
171 */
11703
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
172 return;
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
173 }
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
174
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
175 if (!callTargetNode.isStatic()) {
14633
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 14024
diff changeset
176 assert callTargetNode.receiver().getKind() == wordKind : "changeToWord() missed the receiver";
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
177 targetMethod = wordImplType.resolveMethod(targetMethod);
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
178 }
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
179 Operation operation = targetMethod.getAnnotation(Word.Operation.class);
11703
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
180 assert operation != null : targetMethod;
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
181
11703
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
182 NodeInputList<ValueNode> arguments = callTargetNode.arguments();
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
183 Invoke invoke = callTargetNode.invoke();
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
184
11703
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
185 switch (operation.opcode()) {
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
186 case NODE_CLASS:
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
187 assert arguments.size() == 2;
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
188 ValueNode left = arguments.get(0);
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
189 ValueNode right = operation.rightOperandIsInt() ? toUnsigned(graph, arguments.get(1), Kind.Int) : fromSigned(graph, arguments.get(1));
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
190
11703
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
191 ValueNode replacement = graph.addOrUnique(createBinaryNodeInstance(operation.node(), wordKind, left, right));
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
192 if (replacement instanceof FixedWithNextNode) {
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
193 graph.addBeforeFixed(invoke.asNode(), (FixedWithNextNode) replacement);
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
194 }
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
195 replace(invoke, replacement);
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
196 break;
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
197
11703
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
198 case COMPARISON:
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
199 assert arguments.size() == 2;
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
200 replace(invoke, comparisonOp(graph, operation.condition(), arguments.get(0), fromSigned(graph, arguments.get(1))));
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
201 break;
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
202
11703
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
203 case NOT:
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
204 assert arguments.size() == 1;
14024
34c07ef28bc9 Support integer arithmetic for arbitrary types.
Roland Schatz <roland.schatz@oracle.com>
parents: 14000
diff changeset
205 replace(invoke, graph.unique(new XorNode(StampFactory.forKind(wordKind), arguments.get(0), ConstantNode.forIntegerKind(wordKind, -1, graph))));
11703
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
206 break;
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
207
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
208 case READ: {
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
209 assert arguments.size() == 2 || arguments.size() == 3;
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
210 Kind readKind = asKind(callTargetNode.returnType());
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
211 LocationNode location;
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
212 if (arguments.size() == 2) {
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
213 location = makeLocation(graph, arguments.get(1), readKind, ANY_LOCATION);
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
214 } else {
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
215 location = makeLocation(graph, arguments.get(1), readKind, arguments.get(2));
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
216 }
13135
c7ce697ddb9a Improvements and bugfixes of word type rewriter
Christian Wimmer <christian.wimmer@oracle.com>
parents: 12656
diff changeset
217 replace(invoke, readOp(graph, arguments.get(0), invoke, location, readKind, BarrierType.NONE, false));
11703
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
218 break;
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
219 }
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
220 case READ_HEAP: {
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
221 assert arguments.size() == 4;
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
222 Kind readKind = asKind(callTargetNode.returnType());
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
223 LocationNode location = makeLocation(graph, arguments.get(1), readKind, ANY_LOCATION);
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
224 BarrierType barrierType = (BarrierType) arguments.get(2).asConstant().asObject();
13135
c7ce697ddb9a Improvements and bugfixes of word type rewriter
Christian Wimmer <christian.wimmer@oracle.com>
parents: 12656
diff changeset
225 replace(invoke, readOp(graph, arguments.get(0), invoke, location, readKind, barrierType, arguments.get(3).asConstant().asInt() == 0 ? false : true));
11703
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
226 break;
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
227 }
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
228 case WRITE:
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
229 case INITIALIZE: {
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
230 assert arguments.size() == 3 || arguments.size() == 4;
11816
8db5e8c4f542 Provide object read/write methods similar to Pointer.readXxxx/writeXxx that do not require casts to Word first, and use them in relevant places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11752
diff changeset
231 Kind writeKind = asKind(targetMethod.getSignature().getParameterType(Modifier.isStatic(targetMethod.getModifiers()) ? 2 : 1, targetMethod.getDeclaringClass()));
11703
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
232 LocationNode location;
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
233 if (arguments.size() == 3) {
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
234 location = makeLocation(graph, arguments.get(1), writeKind, LocationIdentity.ANY_LOCATION);
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
235 } else {
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
236 location = makeLocation(graph, arguments.get(1), writeKind, arguments.get(3));
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
237 }
11703
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
238 replace(invoke, writeOp(graph, arguments.get(0), arguments.get(2), invoke, location, operation.opcode()));
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
239 break;
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
240 }
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
241 case ZERO:
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
242 assert arguments.size() == 0;
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
243 replace(invoke, ConstantNode.forIntegerKind(wordKind, 0L, graph));
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
244 break;
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
245
11703
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
246 case FROM_UNSIGNED:
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
247 assert arguments.size() == 1;
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
248 replace(invoke, fromUnsigned(graph, arguments.get(0)));
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
249 break;
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
250
11703
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
251 case FROM_SIGNED:
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
252 assert arguments.size() == 1;
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
253 replace(invoke, fromSigned(graph, arguments.get(0)));
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
254 break;
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
255
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
256 case TO_RAW_VALUE:
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
257 assert arguments.size() == 1;
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
258 replace(invoke, toUnsigned(graph, arguments.get(0), Kind.Long));
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
259 break;
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
260
11703
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
261 case FROM_OBJECT:
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
262 assert arguments.size() == 1;
11752
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11703
diff changeset
263 WordCastNode objectToWord = graph.add(WordCastNode.objectToWord(arguments.get(0), wordKind));
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11703
diff changeset
264 graph.addBeforeFixed(invoke.asNode(), objectToWord);
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11703
diff changeset
265 replace(invoke, objectToWord);
11703
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
266 break;
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
267
11703
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
268 case FROM_ARRAY:
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
269 assert arguments.size() == 2;
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
270 replace(invoke, graph.unique(new ComputeAddressNode(arguments.get(0), arguments.get(1), StampFactory.forKind(wordKind))));
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
271 break;
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
272
11703
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
273 case TO_OBJECT:
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
274 assert arguments.size() == 1;
11752
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11703
diff changeset
275 WordCastNode wordToObject = graph.add(WordCastNode.wordToObject(arguments.get(0), wordKind));
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11703
diff changeset
276 graph.addBeforeFixed(invoke.asNode(), wordToObject);
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11703
diff changeset
277 replace(invoke, wordToObject);
11703
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
278 break;
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
279
11703
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
280 default:
300ee6e4fe14 Improve performance of WordTypeRewriterPhase
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11698
diff changeset
281 throw new GraalInternalError("Unknown opcode: %s", operation.opcode());
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
282 }
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
283 }
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
284
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
285 protected ValueNode fromUnsigned(StructuredGraph graph, ValueNode value) {
12656
9334392ed279 Refactor ConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents: 12655
diff changeset
286 return convert(graph, value, wordKind, true);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
287 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
288
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
289 private ValueNode fromSigned(StructuredGraph graph, ValueNode value) {
12656
9334392ed279 Refactor ConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents: 12655
diff changeset
290 return convert(graph, value, wordKind, false);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
291 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
292
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
293 protected ValueNode toUnsigned(StructuredGraph graph, ValueNode value, Kind toKind) {
12656
9334392ed279 Refactor ConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents: 12655
diff changeset
294 return convert(graph, value, toKind, true);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
295 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
296
12656
9334392ed279 Refactor ConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents: 12655
diff changeset
297 private static ValueNode convert(StructuredGraph graph, ValueNode value, Kind toKind, boolean unsigned) {
14633
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 14024
diff changeset
298 if (value.getKind() == toKind) {
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
299 return value;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
300 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
301
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
302 if (toKind == Kind.Int) {
14633
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 14024
diff changeset
303 assert value.getKind() == Kind.Long;
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents: 13999
diff changeset
304 return graph.unique(new NarrowNode(value, 32));
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
305 } else {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
306 assert toKind == Kind.Long;
14633
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 14024
diff changeset
307 assert value.getKind().getStackKind() == Kind.Int;
12656
9334392ed279 Refactor ConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents: 12655
diff changeset
308 if (unsigned) {
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents: 13999
diff changeset
309 return graph.unique(new ZeroExtendNode(value, 64));
12656
9334392ed279 Refactor ConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents: 12655
diff changeset
310 } else {
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents: 13999
diff changeset
311 return graph.unique(new SignExtendNode(value, 64));
12656
9334392ed279 Refactor ConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents: 12655
diff changeset
312 }
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
313 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
314 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
315
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
316 /**
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
317 * Create an instance of a binary node which is used to lower Word operations. This method is
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
318 * called for all Word operations which are annotated with @Operation(node = ...) and
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
319 * encapsulates the reflective allocation of the node.
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
320 */
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
321 private static ValueNode createBinaryNodeInstance(Class<? extends ValueNode> nodeClass, Kind kind, ValueNode left, ValueNode right) {
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
322 try {
14024
34c07ef28bc9 Support integer arithmetic for arbitrary types.
Roland Schatz <roland.schatz@oracle.com>
parents: 14000
diff changeset
323 Constructor<? extends ValueNode> constructor = nodeClass.getConstructor(Stamp.class, ValueNode.class, ValueNode.class);
34c07ef28bc9 Support integer arithmetic for arbitrary types.
Roland Schatz <roland.schatz@oracle.com>
parents: 14000
diff changeset
324 return constructor.newInstance(StampFactory.forKind(kind), left, right);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
325 } catch (Throwable ex) {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
326 throw new GraalInternalError(ex).addContext(nodeClass.getName());
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
327 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
328 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
329
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
330 private ValueNode comparisonOp(StructuredGraph graph, Condition condition, ValueNode left, ValueNode right) {
14633
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 14024
diff changeset
331 assert left.getKind() == wordKind && right.getKind() == wordKind;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
332
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
333 // mirroring gets the condition into canonical form
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
334 boolean mirror = condition.canonicalMirror();
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
335
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
336 ValueNode a = mirror ? right : left;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
337 ValueNode b = mirror ? left : right;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
338
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
339 CompareNode comparison;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
340 if (condition == Condition.EQ || condition == Condition.NE) {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
341 comparison = new IntegerEqualsNode(a, b);
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
342 } else if (condition.isUnsigned()) {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
343 comparison = new IntegerBelowThanNode(a, b);
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
344 } else {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
345 comparison = new IntegerLessThanNode(a, b);
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
346 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
347
8272
0db1cb049a78 Remove usage of negate() in word type rewriter phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7904
diff changeset
348 ConstantNode trueValue = ConstantNode.forInt(1, graph);
0db1cb049a78 Remove usage of negate() in word type rewriter phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7904
diff changeset
349 ConstantNode falseValue = ConstantNode.forInt(0, graph);
0db1cb049a78 Remove usage of negate() in word type rewriter phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7904
diff changeset
350
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
351 if (condition.canonicalNegate()) {
8272
0db1cb049a78 Remove usage of negate() in word type rewriter phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7904
diff changeset
352 ConstantNode temp = trueValue;
0db1cb049a78 Remove usage of negate() in word type rewriter phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7904
diff changeset
353 trueValue = falseValue;
0db1cb049a78 Remove usage of negate() in word type rewriter phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7904
diff changeset
354 falseValue = temp;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
355 }
8272
0db1cb049a78 Remove usage of negate() in word type rewriter phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7904
diff changeset
356 ConditionalNode materialize = graph.unique(new ConditionalNode(graph.unique(comparison), trueValue, falseValue));
0db1cb049a78 Remove usage of negate() in word type rewriter phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7904
diff changeset
357 return materialize;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
358 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
359
9601
278a50fb49c7 Create a LoadFieldNode for a getstatic of a static final field in the graph builder, and rely on the canonicalizer for replacing it with the constant value.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9526
diff changeset
360 private LocationNode makeLocation(StructuredGraph graph, ValueNode offset, Kind readKind, ValueNode locationIdentity) {
278a50fb49c7 Create a LoadFieldNode for a getstatic of a static final field in the graph builder, and rely on the canonicalizer for replacing it with the constant value.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9526
diff changeset
361 if (locationIdentity.isConstant()) {
278a50fb49c7 Create a LoadFieldNode for a getstatic of a static final field in the graph builder, and rely on the canonicalizer for replacing it with the constant value.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9526
diff changeset
362 return makeLocation(graph, offset, readKind, (LocationIdentity) locationIdentity.asConstant().asObject());
278a50fb49c7 Create a LoadFieldNode for a getstatic of a static final field in the graph builder, and rely on the canonicalizer for replacing it with the constant value.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9526
diff changeset
363 }
13135
c7ce697ddb9a Improvements and bugfixes of word type rewriter
Christian Wimmer <christian.wimmer@oracle.com>
parents: 12656
diff changeset
364 return SnippetLocationNode.create(locationIdentity, ConstantNode.forObject(readKind, metaAccess, graph), ConstantNode.forLong(0, graph), fromSigned(graph, offset),
c7ce697ddb9a Improvements and bugfixes of word type rewriter
Christian Wimmer <christian.wimmer@oracle.com>
parents: 12656
diff changeset
365 ConstantNode.forInt(1, graph), graph);
9601
278a50fb49c7 Create a LoadFieldNode for a getstatic of a static final field in the graph builder, and rely on the canonicalizer for replacing it with the constant value.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9526
diff changeset
366 }
278a50fb49c7 Create a LoadFieldNode for a getstatic of a static final field in the graph builder, and rely on the canonicalizer for replacing it with the constant value.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9526
diff changeset
367
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
368 protected LocationNode makeLocation(StructuredGraph graph, ValueNode offset, Kind readKind, LocationIdentity locationIdentity) {
13135
c7ce697ddb9a Improvements and bugfixes of word type rewriter
Christian Wimmer <christian.wimmer@oracle.com>
parents: 12656
diff changeset
369 return IndexedLocationNode.create(locationIdentity, readKind, 0, fromSigned(graph, offset), graph, 1);
9601
278a50fb49c7 Create a LoadFieldNode for a getstatic of a static final field in the graph builder, and rely on the canonicalizer for replacing it with the constant value.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9526
diff changeset
370 }
278a50fb49c7 Create a LoadFieldNode for a getstatic of a static final field in the graph builder, and rely on the canonicalizer for replacing it with the constant value.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9526
diff changeset
371
13135
c7ce697ddb9a Improvements and bugfixes of word type rewriter
Christian Wimmer <christian.wimmer@oracle.com>
parents: 12656
diff changeset
372 protected ValueNode readOp(StructuredGraph graph, ValueNode base, Invoke invoke, LocationNode location, Kind readKind, BarrierType barrierType, boolean compressible) {
13999
f2b300c6e621 Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents: 13941
diff changeset
373 ReadNode read = graph.add(new ReadNode(base, location, StampFactory.forKind(readKind.getStackKind()), barrierType, compressible));
9089
5ab06146e985 Rename "node()" methods in interfaces to "asNode"
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8935
diff changeset
374 graph.addBeforeFixed(invoke.asNode(), read);
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
375 /*
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
376 * The read must not float outside its block otherwise it may float above an explicit zero
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
377 * check on its base address.
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
378 */
9646
183d33c76419 Removed ValueNode.dependencies
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9602
diff changeset
379 read.setGuard(AbstractBeginNode.prevBegin(invoke.asNode()));
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
380 return read;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
381 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
382
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
383 protected ValueNode writeOp(StructuredGraph graph, ValueNode base, ValueNode value, Invoke invoke, LocationNode location, Opcode op) {
10759
7f186f1486f7 Use initializing write node in object clone snippets.
Roland Schatz <roland.schatz@oracle.com>
parents: 10546
diff changeset
384 assert op == Opcode.WRITE || op == Opcode.INITIALIZE;
10833
079513fc609e Rename isInitialized to isInitialization (inverting semantics!).
Roland Schatz <roland.schatz@oracle.com>
parents: 10828
diff changeset
385 WriteNode write = graph.add(new WriteNode(base, value, location, BarrierType.NONE, false, op == Opcode.INITIALIZE));
7903
f19c4d447e73 more bug fixes and tests for Word read/write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7898
diff changeset
386 write.setStateAfter(invoke.stateAfter());
9089
5ab06146e985 Rename "node()" methods in interfaces to "asNode"
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8935
diff changeset
387 graph.addBeforeFixed(invoke.asNode(), write);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
388 return write;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
389 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
390
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
391 protected void replace(Invoke invoke, ValueNode value) {
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
392 FixedNode next = invoke.next();
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
393 invoke.setNext(null);
9089
5ab06146e985 Rename "node()" methods in interfaces to "asNode"
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8935
diff changeset
394 invoke.asNode().replaceAtPredecessor(next);
5ab06146e985 Rename "node()" methods in interfaces to "asNode"
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8935
diff changeset
395 invoke.asNode().replaceAtUsages(value);
5ab06146e985 Rename "node()" methods in interfaces to "asNode"
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8935
diff changeset
396 GraphUtil.killCFG(invoke.asNode());
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
397 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
398
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
399 protected boolean isWord(ValueNode node) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
400 return isWord(ObjectStamp.typeOrNull(node));
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
401 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
402
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
403 protected boolean isWord(ResolvedJavaType type) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
404 return type != null && wordBaseType.isAssignableFrom(type);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
405 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
406
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
407 protected Kind asKind(JavaType type) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
408 if (type instanceof ResolvedJavaType && isWord((ResolvedJavaType) type)) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
409 return wordKind;
7898
1aca91e4333d fix Word.readByte/writeByte/readShort/writeShort/readChar/writeChar
Lukas Stadler <lukas.stadler@jku.at>
parents: 7868
diff changeset
410 } else {
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11652
diff changeset
411 return type.getKind();
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
412 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
413 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
414 }