annotate graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/PureFunctionMacroNode.java @ 19471:880717e44675

Use typed NodeClass in node constructors.
author Roland Schatz <roland.schatz@oracle.com>
date Wed, 18 Feb 2015 12:12:26 +0100
parents 61d3cb8e1280
children 8fc336a04d77
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11251
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
1 /*
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 16841
diff changeset
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
11251
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
4 *
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
8 *
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
13 * accompanied this code).
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
14 *
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
18 *
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
21 * questions.
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
22 */
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
23 package com.oracle.graal.replacements.nodes;
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
24
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
25 import com.oracle.graal.api.meta.*;
11880
9a747d8e0d0f broadened types in Canonicalizable interface so that it can be moved to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents: 11417
diff changeset
26 import com.oracle.graal.graph.*;
11881
da9db8331658 moved Canonicalizable and Simplifiable to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents: 11880
diff changeset
27 import com.oracle.graal.graph.spi.*;
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
28 import com.oracle.graal.nodeinfo.*;
11251
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
29 import com.oracle.graal.nodes.*;
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
30
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
31 /**
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
32 * This node class can be used to create {@link MacroNode}s for simple pure functions like
11417
98d96597a8e6 small JavaDoc fix in PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 11251
diff changeset
33 * {@link System#identityHashCode(Object)}.
11251
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
34 */
16811
5d468add216f added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents: 16290
diff changeset
35 @NodeInfo
16290
e6622e77e8c7 split MacroNode into MacroNode and MacroStateSplitNode
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16248
diff changeset
36 public abstract class PureFunctionMacroNode extends MacroStateSplitNode implements Canonicalizable {
11251
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
37
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
38 public static final NodeClass<PureFunctionMacroNode> TYPE = NodeClass.get(PureFunctionMacroNode.class);
19403
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18937
diff changeset
39
19471
880717e44675 Use typed NodeClass in node constructors.
Roland Schatz <roland.schatz@oracle.com>
parents: 19410
diff changeset
40 protected PureFunctionMacroNode(NodeClass<? extends PureFunctionMacroNode> c, Invoke invoke) {
19403
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18937
diff changeset
41 super(c, invoke);
11251
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
42 }
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
43
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
44 /**
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
45 * This method should return either a constant that represents the result of the function, or
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
46 * null if no such result could be determined.
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
47 */
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 16841
diff changeset
48 protected abstract JavaConstant evaluate(JavaConstant param, MetaAccessProvider metaAccess);
11251
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
49
11882
51059863da73 replace instanceof type tests for Canonicalizable and Simplifiable with extra boolean properties in NodeClass (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents: 11881
diff changeset
50 @Override
11880
9a747d8e0d0f broadened types in Canonicalizable interface so that it can be moved to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents: 11417
diff changeset
51 public Node canonical(CanonicalizerTool tool) {
18937
ff232ff8d028 Add utility Node#hasNoUsages.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18187
diff changeset
52 if (hasNoUsages()) {
11251
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
53 return null;
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
54 } else {
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
55 ValueNode param = arguments.get(0);
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
56 if (param.isConstant()) {
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 16841
diff changeset
57 JavaConstant constant = evaluate(param.asJavaConstant(), tool.getMetaAccess());
11251
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
58 if (constant != null) {
16248
c5b2a3c22318 refactor more Canonicalizable implementations to not add new nodes to the graph
Lukas Stadler <lukas.stadler@oracle.com>
parents: 11959
diff changeset
59 return ConstantNode.forConstant(constant, tool.getMetaAccess());
11251
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
60 }
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
61 }
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
62 }
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
63 return this;
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
64 }
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
65 }