annotate graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/TruffleGraphBuilderPlugins.java @ 19521:9c4168877444

Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Fri, 20 Feb 2015 13:58:56 +0100
parents 95aa11d4822d
children 4efe39251424 98d7ecef3657
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19068
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1 /*
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
4 *
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
8 *
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
13 * accompanied this code).
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
14 *
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
18 *
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
21 * questions.
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
22 */
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.truffle.substitutions;
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
19178
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
25 import static java.lang.Character.*;
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
26
19068
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
27 import java.util.concurrent.*;
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
28
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
29 import com.oracle.graal.api.meta.*;
19241
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
30 import com.oracle.graal.compiler.common.*;
19178
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
31 import com.oracle.graal.compiler.common.calc.*;
19148
276bc2752feb Register plugin for NewFrame intrinsic.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19104
diff changeset
32 import com.oracle.graal.compiler.common.type.*;
19068
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
33 import com.oracle.graal.java.*;
19390
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19383
diff changeset
34 import com.oracle.graal.java.GraphBuilderPlugin.InvocationPlugin;
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19383
diff changeset
35 import com.oracle.graal.java.InvocationPlugins.Registration;
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19383
diff changeset
36 import com.oracle.graal.java.InvocationPlugins.Registration.Receiver;
19068
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
37 import com.oracle.graal.nodes.*;
19178
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
38 import com.oracle.graal.nodes.calc.*;
19068
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
39 import com.oracle.graal.nodes.extended.*;
19148
276bc2752feb Register plugin for NewFrame intrinsic.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19104
diff changeset
40 import com.oracle.graal.truffle.*;
19178
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
41 import com.oracle.graal.truffle.nodes.*;
19241
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
42 import com.oracle.graal.truffle.nodes.arithmetic.*;
19068
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
43 import com.oracle.graal.truffle.nodes.frame.*;
19309
c386ace07981 Truffle: move unsafe access methods out of CompilerDirectives
Andreas Woess <andreas.woess@oracle.com>
parents: 19308
diff changeset
44 import com.oracle.graal.truffle.unsafe.*;
19068
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
45 import com.oracle.truffle.api.*;
19148
276bc2752feb Register plugin for NewFrame intrinsic.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19104
diff changeset
46 import com.oracle.truffle.api.frame.*;
19068
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
47
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
48 /**
19407
40deedbc4f9b rename: registerPlugins -> registerInvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents: 19393
diff changeset
49 * Provides {@link InvocationPlugin}s for Truffle classes.
19068
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
50 */
19180
e99be967a753 renamed TruffleGraphBuilderPluginsProvider to TruffleGraphBuilderPlugins to reflect the fact that it is no longer a service provider
Doug Simon <doug.simon@oracle.com>
parents: 19178
diff changeset
51 public class TruffleGraphBuilderPlugins {
19407
40deedbc4f9b rename: registerPlugins -> registerInvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents: 19393
diff changeset
52 public static void registerInvocationPlugins(MetaAccessProvider metaAccess, InvocationPlugins plugins) {
19148
276bc2752feb Register plugin for NewFrame intrinsic.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19104
diff changeset
53
19504
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
54 registerOptimizedAssumptionPlugins(metaAccess, plugins);
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
55 registerExactMathPlugins(metaAccess, plugins);
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
56 registerCompilerDirectivesPlugins(metaAccess, plugins);
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
57 registerOptimizedCallTargetPlugins(metaAccess, plugins);
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
58 registerUnsafeAccessImplPlugins(metaAccess, plugins);
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
59
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
60 if (TruffleCompilerOptions.TruffleUseFrameWithoutBoxing.getValue()) {
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
61 registerFrameWithoutBoxingPlugins(metaAccess, plugins);
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
62 } else {
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
63 registerFrameWithBoxingPlugins(metaAccess, plugins);
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
64 }
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
65
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
66 }
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
67
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
68 public static void registerOptimizedAssumptionPlugins(MetaAccessProvider metaAccess, InvocationPlugins plugins) {
19241
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
69 Registration r = new Registration(plugins, metaAccess, OptimizedAssumption.class);
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
70 r.register1("isValid", Receiver.class, new InvocationPlugin() {
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
71 public boolean apply(GraphBuilderContext builder, ValueNode arg) {
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
72 if (arg.isConstant()) {
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
73 Constant constant = arg.asConstant();
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
74 OptimizedAssumption assumption = builder.getSnippetReflection().asObject(OptimizedAssumption.class, (JavaConstant) constant);
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
75 builder.push(Kind.Boolean.getStackKind(), builder.append(ConstantNode.forBoolean(assumption.isValid())));
19383
669f746ad3b1 Truffle graph builder plugin isValid should only record assumption is true.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19378
diff changeset
76 if (assumption.isValid()) {
669f746ad3b1 Truffle graph builder plugin isValid should only record assumption is true.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19378
diff changeset
77 builder.getAssumptions().record(new AssumptionValidAssumption(assumption));
669f746ad3b1 Truffle graph builder plugin isValid should only record assumption is true.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19378
diff changeset
78 }
19241
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
79 } else {
19521
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19504
diff changeset
80 throw builder.bailout("assumption could not be reduced to a constant");
19241
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
81 }
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
82 return true;
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
83 }
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
84 });
19504
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
85 }
19241
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
86
19504
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
87 public static void registerExactMathPlugins(MetaAccessProvider metaAccess, InvocationPlugins plugins) {
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
88 Registration r = new Registration(plugins, metaAccess, ExactMath.class);
19241
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
89 r.register2("addExact", Integer.TYPE, Integer.TYPE, new InvocationPlugin() {
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
90 public boolean apply(GraphBuilderContext builder, ValueNode x, ValueNode y) {
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
91 builder.push(Kind.Int.getStackKind(), builder.append(new IntegerAddExactNode(x, y)));
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
92 return true;
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
93 }
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
94 });
19393
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
95 r.register2("addExact", Long.TYPE, Long.TYPE, new InvocationPlugin() {
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
96 public boolean apply(GraphBuilderContext builder, ValueNode x, ValueNode y) {
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
97 builder.push(Kind.Long, builder.append(new IntegerAddExactNode(x, y)));
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
98 return true;
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
99 }
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
100 });
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
101 r.register2("subtractExact", Integer.TYPE, Integer.TYPE, new InvocationPlugin() {
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
102 public boolean apply(GraphBuilderContext builder, ValueNode x, ValueNode y) {
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
103 builder.push(Kind.Int.getStackKind(), builder.append(new IntegerSubExactNode(x, y)));
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
104 return true;
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
105 }
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
106 });
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
107 r.register2("subtractExact", Long.TYPE, Long.TYPE, new InvocationPlugin() {
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
108 public boolean apply(GraphBuilderContext builder, ValueNode x, ValueNode y) {
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
109 builder.push(Kind.Long, builder.append(new IntegerSubExactNode(x, y)));
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
110 return true;
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
111 }
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
112 });
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
113 r.register2("multiplyExact", Integer.TYPE, Integer.TYPE, new InvocationPlugin() {
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
114 public boolean apply(GraphBuilderContext builder, ValueNode x, ValueNode y) {
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
115 builder.push(Kind.Int.getStackKind(), builder.append(new IntegerMulExactNode(x, y)));
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
116 return true;
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
117 }
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
118 });
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
119 r.register2("multiplyExact", Long.TYPE, Long.TYPE, new InvocationPlugin() {
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
120 public boolean apply(GraphBuilderContext builder, ValueNode x, ValueNode y) {
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
121 builder.push(Kind.Long, builder.append(new IntegerMulExactNode(x, y)));
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
122 return true;
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
123 }
3917abffef82 Truffle: add more exact math graph builder plugins
Andreas Woess <andreas.woess@oracle.com>
parents: 19390
diff changeset
124 });
19504
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
125 }
19241
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
126
19504
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
127 public static void registerCompilerDirectivesPlugins(MetaAccessProvider metaAccess, InvocationPlugins plugins) {
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
128 Registration r = new Registration(plugins, metaAccess, CompilerDirectives.class);
19104
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
129 r.register0("inInterpreter", new InvocationPlugin() {
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
130 public boolean apply(GraphBuilderContext builder) {
19177
1a7b33c96c0d Fixes for TruffleGraphBuilderPluginsProvider.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19148
diff changeset
131 builder.push(Kind.Boolean.getStackKind(), builder.append(ConstantNode.forBoolean(false)));
19068
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
132 return true;
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
133 }
19104
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
134 });
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
135 r.register0("inCompiledCode", new InvocationPlugin() {
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
136 public boolean apply(GraphBuilderContext builder) {
19177
1a7b33c96c0d Fixes for TruffleGraphBuilderPluginsProvider.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19148
diff changeset
137 builder.push(Kind.Boolean.getStackKind(), builder.append(ConstantNode.forBoolean(true)));
19068
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
138 return true;
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
139 }
19104
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
140 });
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
141 r.register0("transferToInterpreter", new InvocationPlugin() {
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
142 public boolean apply(GraphBuilderContext builder) {
19068
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
143 builder.append(new DeoptimizeNode(DeoptimizationAction.None, DeoptimizationReason.TransferToInterpreter));
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
144 return true;
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
145 }
19104
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
146 });
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
147 r.register0("transferToInterpreterAndInvalidate", new InvocationPlugin() {
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
148 public boolean apply(GraphBuilderContext builder) {
19068
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
149 builder.append(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.TransferToInterpreter));
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
150 return true;
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
151 }
19104
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
152 });
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
153 r.register1("interpreterOnly", Runnable.class, new InvocationPlugin() {
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
154 public boolean apply(GraphBuilderContext builder, ValueNode arg) {
19068
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
155 return true;
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
156 }
19104
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
157 });
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
158 r.register1("interpreterOnly", Callable.class, new InvocationPlugin() {
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
159 public boolean apply(GraphBuilderContext builder, ValueNode arg) {
19068
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
160 return true;
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
161 }
19104
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
162 });
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
163 r.register2("injectBranchProbability", double.class, boolean.class, new InvocationPlugin() {
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
164 public boolean apply(GraphBuilderContext builder, ValueNode probability, ValueNode condition) {
19239
637ca4d37bca Extensions and fixes to inline and canonicalize during parsing.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19177
diff changeset
165 builder.push(Kind.Boolean.getStackKind(), builder.append(new BranchProbabilityNode(probability, condition)));
19068
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
166 return true;
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
167 }
19104
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
168 });
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
169 r.register1("bailout", String.class, new InvocationPlugin() {
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
170 public boolean apply(GraphBuilderContext builder, ValueNode message) {
19068
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
171 if (message.isConstant()) {
19521
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19504
diff changeset
172 throw builder.bailout(message.asConstant().toValueString());
19068
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
173 }
19521
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19504
diff changeset
174 throw builder.bailout("bailout (message is not compile-time constant, so no additional information is available)");
19068
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
175 }
19104
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
176 });
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
177 r.register1("isCompilationConstant", Object.class, new InvocationPlugin() {
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
178 public boolean apply(GraphBuilderContext builder, ValueNode value) {
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
179 if ((value instanceof BoxNode ? ((BoxNode) value).getValue() : value).isConstant()) {
19177
1a7b33c96c0d Fixes for TruffleGraphBuilderPluginsProvider.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19148
diff changeset
180 builder.push(Kind.Boolean.getStackKind(), builder.append(ConstantNode.forBoolean(true)));
19452
3e5c4e59c586 Correctly create IsCompilationConstantNode in FastPE mode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19440
diff changeset
181 } else {
3e5c4e59c586 Correctly create IsCompilationConstantNode in FastPE mode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19440
diff changeset
182 builder.push(Kind.Boolean.getStackKind(), builder.append(new IsCompilationConstantNode(value)));
19068
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
183 }
19452
3e5c4e59c586 Correctly create IsCompilationConstantNode in FastPE mode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19440
diff changeset
184 return true;
19068
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
185 }
19104
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
186 });
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
187 r.register1("materialize", Object.class, new InvocationPlugin() {
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
188 public boolean apply(GraphBuilderContext builder, ValueNode value) {
19476
bd2dd97f2bdb Truffle: fix CompilerDirectives.materialize invocation plugin
Andreas Woess <andreas.woess@oracle.com>
parents: 19474
diff changeset
189 builder.append(new ForceMaterializeNode(value));
19068
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
190 return true;
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
191 }
19104
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19070
diff changeset
192 });
19504
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
193 }
19178
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
194
19504
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
195 public static void registerOptimizedCallTargetPlugins(MetaAccessProvider metaAccess, InvocationPlugins plugins) {
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
196 Registration r = new Registration(plugins, metaAccess, OptimizedCallTarget.class);
19178
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
197 r.register2("createFrame", FrameDescriptor.class, Object[].class, new InvocationPlugin() {
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
198 public boolean apply(GraphBuilderContext builder, ValueNode arg1, ValueNode arg2) {
19437
2e91c189b0d8 Introduce option TruffleUseFrameWithoutBoxing, default to true.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19435
diff changeset
199 Class<?> frameClass = TruffleCompilerOptions.TruffleUseFrameWithoutBoxing.getValue() ? FrameWithoutBoxing.class : FrameWithBoxing.class;
2e91c189b0d8 Introduce option TruffleUseFrameWithoutBoxing, default to true.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19435
diff changeset
200 builder.push(Kind.Object, builder.append(new NewFrameNode(StampFactory.exactNonNull(metaAccess.lookupJavaType(frameClass)), arg1, arg2)));
19178
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
201 return true;
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
202 }
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
203 });
19504
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
204 }
19178
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
205
19504
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
206 public static void registerFrameWithoutBoxingPlugins(MetaAccessProvider metaAccess, InvocationPlugins plugins) {
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
207 Registration r = new Registration(plugins, metaAccess, FrameWithoutBoxing.class);
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
208 registerMaterialize(r);
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
209 registerUnsafeCast(r);
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
210 registerUnsafeLoadStorePlugins(r, Kind.Int, Kind.Long, Kind.Float, Kind.Double, Kind.Object);
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
211 }
19437
2e91c189b0d8 Introduce option TruffleUseFrameWithoutBoxing, default to true.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19435
diff changeset
212
19504
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
213 public static void registerFrameWithBoxingPlugins(MetaAccessProvider metaAccess, InvocationPlugins plugins) {
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
214 Registration r = new Registration(plugins, metaAccess, FrameWithBoxing.class);
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
215 registerMaterialize(r);
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
216 registerUnsafeCast(r);
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
217 }
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
218
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
219 public static void registerUnsafeAccessImplPlugins(MetaAccessProvider metaAccess, InvocationPlugins plugins) {
95aa11d4822d refactored per-class InvocationPlugins registration into separate methods
Doug Simon <doug.simon@oracle.com>
parents: 19476
diff changeset
220 Registration r = new Registration(plugins, metaAccess, UnsafeAccessImpl.class);
19437
2e91c189b0d8 Introduce option TruffleUseFrameWithoutBoxing, default to true.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19435
diff changeset
221 registerUnsafeCast(r);
2e91c189b0d8 Introduce option TruffleUseFrameWithoutBoxing, default to true.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19435
diff changeset
222 registerUnsafeLoadStorePlugins(r, Kind.Boolean, Kind.Byte, Kind.Int, Kind.Short, Kind.Long, Kind.Float, Kind.Double, Kind.Object);
2e91c189b0d8 Introduce option TruffleUseFrameWithoutBoxing, default to true.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19435
diff changeset
223 }
2e91c189b0d8 Introduce option TruffleUseFrameWithoutBoxing, default to true.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19435
diff changeset
224
2e91c189b0d8 Introduce option TruffleUseFrameWithoutBoxing, default to true.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19435
diff changeset
225 private static void registerMaterialize(Registration r) {
19178
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
226 r.register1("materialize", Receiver.class, new InvocationPlugin() {
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
227 public boolean apply(GraphBuilderContext builder, ValueNode frame) {
19378
1a9d5e9ab0f4 Fix "materialize" Truffle graph builder plugins.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19362
diff changeset
228 builder.push(Kind.Object, builder.append(new MaterializeFrameNode(frame)));
19178
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
229 return true;
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
230 }
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
231 });
19362
595ee09dfda6 Correctly register unsafe cast graph builder plugin.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19330
diff changeset
232 }
595ee09dfda6 Correctly register unsafe cast graph builder plugin.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19330
diff changeset
233
595ee09dfda6 Correctly register unsafe cast graph builder plugin.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19330
diff changeset
234 private static void registerUnsafeCast(Registration r) {
19178
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
235 r.register4("unsafeCast", Object.class, Class.class, boolean.class, boolean.class, new InvocationPlugin() {
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
236 public boolean apply(GraphBuilderContext builder, ValueNode object, ValueNode clazz, ValueNode condition, ValueNode nonNull) {
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
237 if (clazz.isConstant() && nonNull.isConstant()) {
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
238 ConstantReflectionProvider constantReflection = builder.getConstantReflection();
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
239 ResolvedJavaType javaType = constantReflection.asJavaType(clazz.asConstant());
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
240 if (javaType == null) {
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
241 builder.push(Kind.Object, object);
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
242 } else {
19435
cb470d088b74 Make array types exact types in unsafe casts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19393
diff changeset
243 Stamp piStamp = null;
cb470d088b74 Make array types exact types in unsafe casts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19393
diff changeset
244 if (javaType.isArray()) {
cb470d088b74 Make array types exact types in unsafe casts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19393
diff changeset
245 if (nonNull.asJavaConstant().asInt() != 0) {
cb470d088b74 Make array types exact types in unsafe casts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19393
diff changeset
246 piStamp = StampFactory.exactNonNull(javaType);
cb470d088b74 Make array types exact types in unsafe casts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19393
diff changeset
247 } else {
cb470d088b74 Make array types exact types in unsafe casts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19393
diff changeset
248 piStamp = StampFactory.exact(javaType);
cb470d088b74 Make array types exact types in unsafe casts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19393
diff changeset
249 }
cb470d088b74 Make array types exact types in unsafe casts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19393
diff changeset
250 } else {
cb470d088b74 Make array types exact types in unsafe casts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19393
diff changeset
251 piStamp = StampFactory.declaredTrusted(javaType, nonNull.asJavaConstant().asInt() != 0);
cb470d088b74 Make array types exact types in unsafe casts.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19393
diff changeset
252 }
19241
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
253 LogicNode compareNode = CompareNode.createCompareNode(object.graph(), Condition.EQ, condition, ConstantNode.forBoolean(true, object.graph()), constantReflection);
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
254 boolean skipAnchor = false;
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
255 if (compareNode instanceof LogicConstantNode) {
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
256 LogicConstantNode logicConstantNode = (LogicConstantNode) compareNode;
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
257 if (logicConstantNode.getValue()) {
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
258 skipAnchor = true;
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
259 }
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
260 }
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
261 ConditionAnchorNode valueAnchorNode = null;
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
262 if (!skipAnchor) {
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
263 valueAnchorNode = builder.append(new ConditionAnchorNode(compareNode));
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
264 }
19178
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
265 PiNode piCast = builder.append(new PiNode(object, piStamp, valueAnchorNode));
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
266 builder.push(Kind.Object, piCast);
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
267 }
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
268 return true;
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
269 }
19241
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
270 throw GraalInternalError.shouldNotReachHere("unsafeCast arguments could not reduce to a constant: " + clazz + ", " + nonNull);
19178
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
271 }
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
272 });
19246
d3e835fa6bbf added graph builder plugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents: 19241
diff changeset
273 }
d3e835fa6bbf added graph builder plugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents: 19241
diff changeset
274
d3e835fa6bbf added graph builder plugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents: 19241
diff changeset
275 protected static void registerUnsafeLoadStorePlugins(Registration r, Kind... kinds) {
d3e835fa6bbf added graph builder plugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents: 19241
diff changeset
276 for (Kind kind : kinds) {
19178
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
277 String kindName = kind.getJavaName();
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
278 kindName = toUpperCase(kindName.charAt(0)) + kindName.substring(1);
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
279 String getName = "unsafeGet" + kindName;
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
280 String putName = "unsafePut" + kindName;
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
281 r.register4(getName, Object.class, long.class, boolean.class, Object.class, new CustomizedUnsafeLoadPlugin(kind));
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
282 r.register4(putName, Object.class, long.class, kind == Kind.Object ? Object.class : kind.toJavaClass(), Object.class, new CustomizedUnsafeStorePlugin(kind));
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
283 }
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
284 }
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
285
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
286 static class CustomizedUnsafeLoadPlugin implements InvocationPlugin {
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
287
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
288 private final Kind returnKind;
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
289
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
290 public CustomizedUnsafeLoadPlugin(Kind returnKind) {
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
291 this.returnKind = returnKind;
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
292 }
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
293
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
294 public boolean apply(GraphBuilderContext builder, ValueNode object, ValueNode offset, ValueNode condition, ValueNode location) {
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
295 if (location.isConstant()) {
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
296 LocationIdentity locationIdentity;
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
297 if (location.isNullConstant()) {
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
298 locationIdentity = LocationIdentity.ANY_LOCATION;
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
299 } else {
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
300 locationIdentity = ObjectLocationIdentity.create(location.asJavaConstant());
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
301 }
19241
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19240
diff changeset
302 LogicNode compare = builder.append(CompareNode.createCompareNode(Condition.EQ, condition, ConstantNode.forBoolean(true, object.graph()), builder.getConstantReflection()));
19178
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
303 builder.push(returnKind.getStackKind(), builder.append(new UnsafeLoadNode(object, offset, returnKind, locationIdentity, compare)));
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
304 return true;
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
305 }
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
306 // TODO: should we throw GraalInternalError.shouldNotReachHere() here?
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
307 return false;
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
308 }
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
309 }
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
310
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
311 static class CustomizedUnsafeStorePlugin implements InvocationPlugin {
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
312
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
313 private final Kind kind;
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
314
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
315 public CustomizedUnsafeStorePlugin(Kind kind) {
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
316 this.kind = kind;
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
317 }
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
318
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
319 public boolean apply(GraphBuilderContext builder, ValueNode object, ValueNode offset, ValueNode value, ValueNode location) {
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
320 ValueNode locationArgument = location;
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
321 if (locationArgument.isConstant()) {
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
322 LocationIdentity locationIdentity;
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
323 if (locationArgument.isNullConstant()) {
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
324 locationIdentity = LocationIdentity.ANY_LOCATION;
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
325 } else {
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
326 locationIdentity = ObjectLocationIdentity.create(locationArgument.asJavaConstant());
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
327 }
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
328
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
329 builder.append(new UnsafeStoreNode(object, offset, value, kind, locationIdentity, null));
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
330 return true;
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
331 }
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
332 // TODO: should we throw GraalInternalError.shouldNotReachHere() here?
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
333 return false;
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19177
diff changeset
334 }
19068
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
335 }
835819187e23 added GraphBuilderPlugins for CompilerDirectives
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
336 }