annotate graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/PureFunctionMacroNode.java @ 11882:51059863da73

replace instanceof type tests for Canonicalizable and Simplifiable with extra boolean properties in NodeClass (GRAAL-506)
author Doug Simon <doug.simon@oracle.com>
date Wed, 02 Oct 2013 20:57:11 +0200
parents da9db8331658
children 23ccaa863eda
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 /*
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
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.*;
11251
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
28 import com.oracle.graal.nodes.*;
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
29
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 * 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
32 * {@link System#identityHashCode(Object)}.
11251
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
33 */
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
34 public abstract class PureFunctionMacroNode extends MacroNode implements Canonicalizable {
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
35
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
36 public PureFunctionMacroNode(Invoke invoke) {
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
37 super(invoke);
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
38 }
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
39
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
40 /**
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
41 * 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
42 * null if no such result could be determined.
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 protected abstract Constant evaluate(Constant param, MetaAccessProvider metaAccess);
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
45
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
46 @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
47 public Node canonical(CanonicalizerTool tool) {
11251
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
48 if (usages().isEmpty()) {
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
49 return null;
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
50 } else {
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
51 ValueNode param = arguments.get(0);
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
52 if (param.isConstant()) {
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
53 Constant constant = evaluate(param.asConstant(), tool.runtime());
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
54 if (constant != null) {
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
55 return ConstantNode.forConstant(constant, tool.runtime(), graph());
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
56 }
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
57 }
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
58 }
e428ffc7a0ad new PureFunctionMacroNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
59 return this;
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 }