annotate graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/typesystem/UnsafeTypeCastMacroNode.java @ 19410:61d3cb8e1280

Add generic parameter to NodeClass. Change Graph#getNodes(Class) to Graph#getNodes(NodeClass).
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Mon, 16 Feb 2015 17:47:43 +0100
parents 7e2c87dae93e
children 9c4168877444
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11898
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
19403
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19241
diff changeset
2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
11898
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.truffle.nodes.typesystem;
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
25 import com.oracle.graal.api.meta.*;
15200
97eed257999b Move Condition to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents: 15198
diff changeset
26 import com.oracle.graal.compiler.common.calc.*;
15198
2c0cfbf454b5 Move LIRTypeTool and Stamp to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents: 15018
diff changeset
27 import com.oracle.graal.compiler.common.type.*;
19403
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19241
diff changeset
28 import com.oracle.graal.graph.*;
11898
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
29 import com.oracle.graal.graph.spi.*;
16841
cbd42807a31f moved NodeInfo and friends into separate com.oracle.graal.nodeinfo project so that annotation processor can be applied to the base Node class
Doug Simon <doug.simon@oracle.com>
parents: 16811
diff changeset
30 import com.oracle.graal.nodeinfo.*;
11898
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
31 import com.oracle.graal.nodes.*;
11938
bdfdd110bd9a Introduce ConditionAnchorNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11898
diff changeset
32 import com.oracle.graal.nodes.calc.*;
16252
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15448
diff changeset
33 import com.oracle.graal.nodes.util.*;
11898
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
34 import com.oracle.graal.truffle.nodes.asserts.*;
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
36 /**
18907
7536b78cd31d Truffle: remove references to unsafe in comments
Andreas Woess <andreas.woess@jku.at>
parents: 18845
diff changeset
37 * Macro node for method CompilerDirectives#unsafeCast.
11898
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
38 */
16811
5d468add216f added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents: 16252
diff changeset
39 @NodeInfo
19403
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19241
diff changeset
40 public final class UnsafeTypeCastMacroNode extends NeverPartOfCompilationNode implements Simplifiable {
11898
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41
19410
61d3cb8e1280 Add generic parameter to NodeClass. Change Graph#getNodes(Class) to Graph#getNodes(NodeClass).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19403
diff changeset
42 public static final NodeClass<UnsafeTypeCastMacroNode> TYPE = NodeClass.get(UnsafeTypeCastMacroNode.class);
11898
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
43 private static final int OBJECT_ARGUMENT_INDEX = 0;
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44 private static final int CLASS_ARGUMENT_INDEX = 1;
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45 private static final int CONDITION_ARGUMENT_INDEX = 2;
14880
73546bd550f0 CompilerDirectives: add optional nonNull parameter to unsafeCast
Andreas Woess <andreas.woess@jku.at>
parents: 12655
diff changeset
46 private static final int NONNULL_ARGUMENT_INDEX = 3;
73546bd550f0 CompilerDirectives: add optional nonNull parameter to unsafeCast
Andreas Woess <andreas.woess@jku.at>
parents: 12655
diff changeset
47 private static final int ARGUMENT_COUNT = 4;
11898
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
48
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18487
diff changeset
49 public UnsafeTypeCastMacroNode(Invoke invoke) {
19403
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19241
diff changeset
50 super(TYPE, invoke, "The class of the unsafe cast could not be reduced to a compile time constant.");
11898
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
51 assert arguments.size() == ARGUMENT_COUNT;
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52 }
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
54 @Override
16252
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15448
diff changeset
55 public void simplify(SimplifierTool tool) {
11898
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
56 ValueNode classArgument = arguments.get(CLASS_ARGUMENT_INDEX);
14880
73546bd550f0 CompilerDirectives: add optional nonNull parameter to unsafeCast
Andreas Woess <andreas.woess@jku.at>
parents: 12655
diff changeset
57 ValueNode nonNullArgument = arguments.get(NONNULL_ARGUMENT_INDEX);
73546bd550f0 CompilerDirectives: add optional nonNull parameter to unsafeCast
Andreas Woess <andreas.woess@jku.at>
parents: 12655
diff changeset
58 if (classArgument.isConstant() && nonNullArgument.isConstant()) {
11898
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
59 ValueNode objectArgument = arguments.get(OBJECT_ARGUMENT_INDEX);
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
60 ValueNode conditionArgument = arguments.get(CONDITION_ARGUMENT_INDEX);
18487
0f4813e0b4a9 Use asConstant() instead of asJavaConstant() where possible.
Roland Schatz <roland.schatz@oracle.com>
parents: 18416
diff changeset
61 ResolvedJavaType lookupJavaType = tool.getConstantReflection().asJavaType(classArgument.asConstant());
16252
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15448
diff changeset
62 tool.addToWorkList(usages());
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14880
diff changeset
63 if (lookupJavaType == null) {
16252
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15448
diff changeset
64 replaceAtUsages(objectArgument);
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15448
diff changeset
65 GraphUtil.removeFixedWithUnusedInputs(this);
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15448
diff changeset
66 } else {
18416
0c6504598b65 StampTool: add more methods to create object stamps to avoid using too many boolean arguments, add some javadoc, use them.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 18187
diff changeset
67 Stamp piStamp = StampFactory.declaredTrusted(lookupJavaType, nonNullArgument.asJavaConstant().asInt() != 0);
16252
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15448
diff changeset
68 ConditionAnchorNode valueAnchorNode = graph().add(
19241
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18907
diff changeset
69 new ConditionAnchorNode(CompareNode.createCompareNode(graph(), Condition.EQ, conditionArgument, ConstantNode.forBoolean(true, graph()), tool.getConstantReflection())));
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18487
diff changeset
70 PiNode piCast = graph().unique(new PiNode(objectArgument, piStamp, valueAnchorNode));
16252
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15448
diff changeset
71 replaceAtUsages(piCast);
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15448
diff changeset
72 graph().replaceFixedWithFixed(this, valueAnchorNode);
11898
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
73 }
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
74 }
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
75 }
f753092f608d Adjustments to unsafe access and unsafe cast compiler directives in Truffle API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
76 }