Mercurial > hg > graal-compiler
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 |
rev | line source |
---|---|
11251 | 1 /* |
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.graal.replacements.nodes; | |
24 | |
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 | 28 import com.oracle.graal.nodes.*; |
29 | |
30 /** | |
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 | 33 */ |
34 public abstract class PureFunctionMacroNode extends MacroNode implements Canonicalizable { | |
35 | |
36 public PureFunctionMacroNode(Invoke invoke) { | |
37 super(invoke); | |
38 } | |
39 | |
40 /** | |
41 * This method should return either a constant that represents the result of the function, or | |
42 * null if no such result could be determined. | |
43 */ | |
44 protected abstract Constant evaluate(Constant param, MetaAccessProvider metaAccess); | |
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 | 48 if (usages().isEmpty()) { |
49 return null; | |
50 } else { | |
51 ValueNode param = arguments.get(0); | |
52 if (param.isConstant()) { | |
53 Constant constant = evaluate(param.asConstant(), tool.runtime()); | |
54 if (constant != null) { | |
55 return ConstantNode.forConstant(constant, tool.runtime(), graph()); | |
56 } | |
57 } | |
58 } | |
59 return this; | |
60 } | |
61 } |