annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ConstantNode.java @ 12445:66efe95dd46b

Make sure constants have the correct stack kind and unsafe accesses the correct access kind.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Wed, 16 Oct 2013 03:02:03 +0200
parents 9ad59f7fd57e
children af39ea2dc39d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
23 package com.oracle.graal.nodes;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
5813
3b8bc07f8d17 Add ability to give an existing to getDebugProperties
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5629
diff changeset
25 import java.util.*;
3b8bc07f8d17 Add ability to give an existing to getDebugProperties
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5629
diff changeset
26
5507
dc71b06d09f8 Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5504
diff changeset
27 import com.oracle.graal.api.meta.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
28 import com.oracle.graal.graph.*;
7767
4a6646d8eb87 separate BooleanNode and ConstantNode hierarchy, rename BooleanNode to LogicNode and LogicNode to BitLogicNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
29 import com.oracle.graal.nodes.calc.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
30 import com.oracle.graal.nodes.spi.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
31 import com.oracle.graal.nodes.type.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
33 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7098
diff changeset
34 * The {@code ConstantNode} represents a constant such as an integer value, long, float, object
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7098
diff changeset
35 * reference, address, etc.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
36 */
5813
3b8bc07f8d17 Add ability to give an existing to getDebugProperties
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5629
diff changeset
37 @NodeInfo(shortName = "Const", nameTemplate = "Const({p#rawvalue})")
7767
4a6646d8eb87 separate BooleanNode and ConstantNode hierarchy, rename BooleanNode to LogicNode and LogicNode to BitLogicNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
38 public class ConstantNode extends FloatingNode implements LIRLowerable {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
39
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5510
diff changeset
40 public final Constant value;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5510
diff changeset
42 protected ConstantNode(Constant value) {
5085
5bdaa08ba96b add and enable new PropagateTypeCachePhase, add type system tests
Lukas Stadler <lukas.stadler@jku.at>
parents: 5061
diff changeset
43 super(StampFactory.forConstant(value));
5bdaa08ba96b add and enable new PropagateTypeCachePhase, add type system tests
Lukas Stadler <lukas.stadler@jku.at>
parents: 5061
diff changeset
44 this.value = value;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
48 * Constructs a new ConstantNode representing the specified constant.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7098
diff changeset
49 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
50 * @param value the constant
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
51 */
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11958
diff changeset
52 protected ConstantNode(Constant value, MetaAccessProvider metaAccess) {
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11958
diff changeset
53 super(StampFactory.forConstant(value, metaAccess));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
54 this.value = value;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
55 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
56
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
57 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
58 public void generate(LIRGeneratorTool gen) {
11944
506d4520435d Do not emit code for constants in virtual state.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11477
diff changeset
59 if (gen.canInlineConstant(value) || onlyUsedInVirtualState()) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
60 gen.setResult(this, value);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
61 } else {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
62 gen.setResult(this, gen.emitMove(value));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
63 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
64 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
65
11944
506d4520435d Do not emit code for constants in virtual state.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11477
diff changeset
66 private boolean onlyUsedInVirtualState() {
506d4520435d Do not emit code for constants in virtual state.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11477
diff changeset
67 for (Node n : this.usages()) {
11958
a0f5be106e67 Simplify ConstantNode.onlyUsedInVirtualState
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11954
diff changeset
68 if (n instanceof VirtualState) {
11944
506d4520435d Do not emit code for constants in virtual state.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11477
diff changeset
69 // Only virtual usage.
506d4520435d Do not emit code for constants in virtual state.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11477
diff changeset
70 } else {
506d4520435d Do not emit code for constants in virtual state.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11477
diff changeset
71 return false;
506d4520435d Do not emit code for constants in virtual state.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11477
diff changeset
72 }
506d4520435d Do not emit code for constants in virtual state.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11477
diff changeset
73 }
506d4520435d Do not emit code for constants in virtual state.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11477
diff changeset
74 return true;
4654
c3de4449719f Don't emit moves for constants that are used only in frame states.
Andreas Woess <andreas.woess@jku.at>
parents: 4423
diff changeset
75 }
c3de4449719f Don't emit moves for constants that are used only in frame states.
Andreas Woess <andreas.woess@jku.at>
parents: 4423
diff changeset
76
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11958
diff changeset
77 public static ConstantNode forConstant(Constant constant, MetaAccessProvider metaAccess, Graph graph) {
12445
66efe95dd46b Make sure constants have the correct stack kind and unsafe accesses the correct access kind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12416
diff changeset
78 if (constant.getKind().getStackKind() == Kind.Int && constant.getKind() != Kind.Int) {
66efe95dd46b Make sure constants have the correct stack kind and unsafe accesses the correct access kind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12416
diff changeset
79 return forInt(constant.asInt(), graph);
66efe95dd46b Make sure constants have the correct stack kind and unsafe accesses the correct access kind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12416
diff changeset
80 } else if (constant.getKind() == Kind.Object) {
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11958
diff changeset
81 return graph.unique(new ConstantNode(constant, metaAccess));
5085
5bdaa08ba96b add and enable new PropagateTypeCachePhase, add type system tests
Lukas Stadler <lukas.stadler@jku.at>
parents: 5061
diff changeset
82 } else {
5bdaa08ba96b add and enable new PropagateTypeCachePhase, add type system tests
Lukas Stadler <lukas.stadler@jku.at>
parents: 5061
diff changeset
83 return graph.unique(new ConstantNode(constant));
5bdaa08ba96b add and enable new PropagateTypeCachePhase, add type system tests
Lukas Stadler <lukas.stadler@jku.at>
parents: 5061
diff changeset
84 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
85 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
86
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
87 /**
11477
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
88 * Returns a node for a primitive constant.
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
89 */
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
90 public static ConstantNode forPrimitive(Constant constant, Graph graph) {
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
91 assert constant.getKind() != Kind.Object;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
92 return forConstant(constant, null, graph);
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
93 }
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
94
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
95 /**
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
96 * Returns a node for a double constant.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7098
diff changeset
97 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
98 * @param d the double value for which to create the instruction
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
99 * @param graph
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
100 * @return a node for a double constant
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
101 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
102 public static ConstantNode forDouble(double d, Graph graph) {
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5510
diff changeset
103 return graph.unique(new ConstantNode(Constant.forDouble(d)));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
104 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
105
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
106 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
107 * Returns a node for a float constant.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7098
diff changeset
108 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
109 * @param f the float value for which to create the instruction
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
110 * @param graph
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
111 * @return a node for a float constant
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
112 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
113 public static ConstantNode forFloat(float f, Graph graph) {
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5510
diff changeset
114 return graph.unique(new ConstantNode(Constant.forFloat(f)));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
115 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
116
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
117 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
118 * Returns a node for an long constant.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7098
diff changeset
119 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
120 * @param i the long value for which to create the instruction
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
121 * @param graph
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
122 * @return a node for an long constant
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
123 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
124 public static ConstantNode forLong(long i, Graph graph) {
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5510
diff changeset
125 return graph.unique(new ConstantNode(Constant.forLong(i)));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
126 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
127
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
128 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
129 * Returns a node for an integer constant.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7098
diff changeset
130 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
131 * @param i the integer value for which to create the instruction
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
132 * @param graph
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
133 * @return a node for an integer constant
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
134 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
135 public static ConstantNode forInt(int i, Graph graph) {
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5510
diff changeset
136 return graph.unique(new ConstantNode(Constant.forInt(i)));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
137 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
138
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
139 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
140 * Returns a node for a boolean constant.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7098
diff changeset
141 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
142 * @param i the boolean value for which to create the instruction
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
143 * @param graph
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
144 * @return a node representing the boolean
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
145 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
146 public static ConstantNode forBoolean(boolean i, Graph graph) {
12445
66efe95dd46b Make sure constants have the correct stack kind and unsafe accesses the correct access kind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12416
diff changeset
147 return graph.unique(new ConstantNode(Constant.forInt(i ? 1 : 0)));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
148 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
149
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
150 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
151 * Returns a node for a byte constant.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7098
diff changeset
152 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
153 * @param i the byte value for which to create the instruction
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
154 * @param graph
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
155 * @return a node representing the byte
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
156 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
157 public static ConstantNode forByte(byte i, Graph graph) {
12445
66efe95dd46b Make sure constants have the correct stack kind and unsafe accesses the correct access kind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12416
diff changeset
158 return graph.unique(new ConstantNode(Constant.forInt(i)));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
159 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
160
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
161 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
162 * Returns a node for a char constant.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7098
diff changeset
163 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
164 * @param i the char value for which to create the instruction
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
165 * @param graph
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
166 * @return a node representing the char
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
167 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
168 public static ConstantNode forChar(char i, Graph graph) {
12445
66efe95dd46b Make sure constants have the correct stack kind and unsafe accesses the correct access kind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12416
diff changeset
169 return graph.unique(new ConstantNode(Constant.forInt(i)));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
170 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
171
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
172 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
173 * Returns a node for a short constant.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7098
diff changeset
174 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
175 * @param i the short value for which to create the instruction
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
176 * @param graph
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
177 * @return a node representing the short
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
178 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
179 public static ConstantNode forShort(short i, Graph graph) {
12445
66efe95dd46b Make sure constants have the correct stack kind and unsafe accesses the correct access kind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12416
diff changeset
180 return graph.unique(new ConstantNode(Constant.forInt(i)));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
181 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
182
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
183 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
184 * Returns a node for an object constant.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7098
diff changeset
185 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
186 * @param o the object value for which to create the instruction
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
187 * @param graph
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
188 * @return a node representing the object
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
189 */
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11958
diff changeset
190 public static ConstantNode forObject(Object o, MetaAccessProvider metaAccess, Graph graph) {
6551
4ecd2f236bd8 Add assertion to prevent use of wrong factory method
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6539
diff changeset
191 assert !(o instanceof Constant) : "wrapping a Constant into a Constant";
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11958
diff changeset
192 return graph.unique(new ConstantNode(Constant.forObject(o), metaAccess));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
193 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
194
5540
a891c53a295b Renaming RiKind => Kind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5538
diff changeset
195 public static ConstantNode forIntegerKind(Kind kind, long value, Graph graph) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
196 switch (kind) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
197 case Byte:
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
198 case Short:
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
199 case Int:
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
200 return ConstantNode.forInt((int) value, graph);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
201 case Long:
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
202 return ConstantNode.forLong(value, graph);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
203 default:
12416
9ad59f7fd57e ConstantNode methods should not throw InternalError
twisti
parents: 11959
diff changeset
204 throw GraalInternalError.shouldNotReachHere("unknown kind " + kind);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
205 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
206 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
207
5540
a891c53a295b Renaming RiKind => Kind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5538
diff changeset
208 public static ConstantNode forFloatingKind(Kind kind, double value, Graph graph) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
209 switch (kind) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
210 case Float:
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
211 return ConstantNode.forFloat((float) value, graph);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
212 case Double:
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
213 return ConstantNode.forDouble(value, graph);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
214 default:
12416
9ad59f7fd57e ConstantNode methods should not throw InternalError
twisti
parents: 11959
diff changeset
215 throw GraalInternalError.shouldNotReachHere("unknown kind " + kind);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
216 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
217 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
218
5540
a891c53a295b Renaming RiKind => Kind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5538
diff changeset
219 public static ConstantNode defaultForKind(Kind kind, Graph graph) {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7098
diff changeset
220 switch (kind) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
221 case Boolean:
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
222 case Byte:
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
223 case Char:
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
224 case Short:
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
225 case Int:
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
226 return ConstantNode.forInt(0, graph);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
227 case Double:
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
228 return ConstantNode.forDouble(0.0, graph);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
229 case Float:
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
230 return ConstantNode.forFloat(0.0f, graph);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
231 case Long:
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
232 return ConstantNode.forLong(0L, graph);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
233 case Object:
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
234 return ConstantNode.forObject(null, null, graph);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
235 default:
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
236 return null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
237 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
238 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
239
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
240 @Override
5813
3b8bc07f8d17 Add ability to give an existing to getDebugProperties
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5629
diff changeset
241 public Map<Object, Object> getDebugProperties(Map<Object, Object> map) {
3b8bc07f8d17 Add ability to give an existing to getDebugProperties
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5629
diff changeset
242 Map<Object, Object> properties = super.getDebugProperties(map);
7098
e23980f4a890 Cleanup of Kind class: remove isXxx methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6551
diff changeset
243 properties.put("rawvalue", value.getKind() == Kind.Object ? value.getKind().format(value.asBoxedValue()) : value.asBoxedValue());
5813
3b8bc07f8d17 Add ability to give an existing to getDebugProperties
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5629
diff changeset
244 return properties;
3b8bc07f8d17 Add ability to give an existing to getDebugProperties
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5629
diff changeset
245 }
3b8bc07f8d17 Add ability to give an existing to getDebugProperties
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5629
diff changeset
246
3b8bc07f8d17 Add ability to give an existing to getDebugProperties
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5629
diff changeset
247 @Override
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
248 public String toString(Verbosity verbosity) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
249 if (verbosity == Verbosity.Name) {
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6329
diff changeset
250 return super.toString(Verbosity.Name) + "(" + value.getKind().format(value.asBoxedValue()) + ")";
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
251 } else {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
252 return super.toString(verbosity);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
253 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
254 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
255 }