Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ReinterpretNode.java @ 14011:134491e79cde
Use correct PlatformKind in reinterpret LIR generation.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Mon, 24 Feb 2014 15:06:07 +0100 |
parents | 958c99d0790c |
children | dbe41340d0a6 |
rev | line source |
---|---|
12656 | 1 /* |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. |
12656 | 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.nodes.calc; | |
24 | |
25 import com.oracle.graal.api.meta.*; | |
26 import com.oracle.graal.graph.*; | |
27 import com.oracle.graal.graph.spi.*; | |
28 import com.oracle.graal.nodes.*; | |
29 import com.oracle.graal.nodes.spi.*; | |
30 import com.oracle.graal.nodes.type.*; | |
31 | |
32 /** | |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
33 * The {@code ReinterpretNode} class represents a reinterpreting conversion that changes the stamp |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
34 * of a primitive value to some other incompatible stamp. The new stamp must have the same width as |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
35 * the old stamp. |
12656 | 36 */ |
37 public class ReinterpretNode extends FloatingNode implements Canonicalizable, ArithmeticLIRLowerable { | |
38 | |
39 @Input private ValueNode value; | |
40 | |
41 public ValueNode value() { | |
42 return value; | |
43 } | |
44 | |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
45 private ReinterpretNode(Kind to, ValueNode value) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
46 this(StampFactory.forKind(to), value); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
47 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
48 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
49 public ReinterpretNode(Stamp to, ValueNode value) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
50 super(to); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
51 assert to instanceof PrimitiveStamp; |
12656 | 52 this.value = value; |
53 } | |
54 | |
55 public Constant evalConst(Constant... inputs) { | |
56 assert inputs.length == 1; | |
57 Constant c = inputs[0]; | |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
58 assert c.getKind().getBitCount() == ((PrimitiveStamp) stamp()).getBits(); |
12656 | 59 switch (c.getKind()) { |
60 case Int: | |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
61 if (stamp() instanceof FloatStamp) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
62 return Constant.forFloat(Float.intBitsToFloat(c.asInt())); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
63 } else { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
64 return c; |
12656 | 65 } |
66 case Long: | |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
67 if (stamp() instanceof FloatStamp) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
68 return Constant.forDouble(Double.longBitsToDouble(c.asLong())); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
69 } else { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
70 return c; |
12656 | 71 } |
72 case Float: | |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
73 if (stamp() instanceof IntegerStamp) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
74 return Constant.forInt(Float.floatToRawIntBits(c.asFloat())); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
75 } else { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
76 return c; |
12656 | 77 } |
78 case Double: | |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
79 if (stamp() instanceof IntegerStamp) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
80 return Constant.forLong(Double.doubleToRawLongBits(c.asDouble())); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
81 } else { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
82 return c; |
12656 | 83 } |
84 } | |
85 throw GraalInternalError.shouldNotReachHere(); | |
86 } | |
87 | |
88 @Override | |
89 public Node canonical(CanonicalizerTool tool) { | |
90 if (value.isConstant()) { | |
91 return ConstantNode.forPrimitive(evalConst(value.asConstant()), graph()); | |
92 } | |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
93 if (stamp().isCompatible(value.stamp())) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
94 return value; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
95 } |
12656 | 96 return this; |
97 } | |
98 | |
99 @Override | |
100 public void generate(ArithmeticLIRGenerator gen) { | |
14011
134491e79cde
Use correct PlatformKind in reinterpret LIR generation.
Roland Schatz <roland.schatz@oracle.com>
parents:
14000
diff
changeset
|
101 PlatformKind kind = gen.getPlatformKind(stamp()); |
134491e79cde
Use correct PlatformKind in reinterpret LIR generation.
Roland Schatz <roland.schatz@oracle.com>
parents:
14000
diff
changeset
|
102 gen.setResult(this, gen.emitReinterpret(kind, gen.operand(value()))); |
12656 | 103 } |
104 | |
105 public static ValueNode reinterpret(Kind toKind, ValueNode value) { | |
106 return value.graph().unique(new ReinterpretNode(toKind, value)); | |
107 } | |
108 | |
109 @NodeIntrinsic | |
110 public static native float reinterpret(@ConstantNodeParameter Kind kind, int value); | |
111 | |
112 @NodeIntrinsic | |
113 public static native int reinterpret(@ConstantNodeParameter Kind kind, float value); | |
114 | |
115 @NodeIntrinsic | |
116 public static native double reinterpret(@ConstantNodeParameter Kind kind, long value); | |
117 | |
118 @NodeIntrinsic | |
119 public static native long reinterpret(@ConstantNodeParameter Kind kind, double value); | |
120 } |