Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ReinterpretNode.java @ 19403:7e2c87dae93e
Create static final NodeClass field named TYPE in Node subclasses.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Mon, 16 Feb 2015 15:43:03 +0100 |
parents | f57d86eb036f |
children | 61d3cb8e1280 |
rev | line source |
---|---|
12656 | 1 /* |
18793
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
2 * Copyright (c) 2013, 2015, 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 | |
18793
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
25 import java.nio.*; |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
26 |
12656 | 27 import com.oracle.graal.api.meta.*; |
15198
2c0cfbf454b5
Move LIRTypeTool and Stamp to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents:
15193
diff
changeset
|
28 import com.oracle.graal.compiler.common.type.*; |
19403
7e2c87dae93e
Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
29 import com.oracle.graal.graph.*; |
12656 | 30 import com.oracle.graal.graph.spi.*; |
15299
60406b8d6ad1
Move ArithmeticLIRGenerator to graal.lir (errors).
Josef Eisl <josef.eisl@jku.at>
parents:
15261
diff
changeset
|
31 import com.oracle.graal.lir.gen.*; |
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
|
32 import com.oracle.graal.nodeinfo.*; |
12656 | 33 import com.oracle.graal.nodes.*; |
34 import com.oracle.graal.nodes.spi.*; | |
35 | |
36 /** | |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
37 * 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
|
38 * 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
|
39 * the old stamp. |
12656 | 40 */ |
16811
5d468add216f
added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents:
16216
diff
changeset
|
41 @NodeInfo |
19403
7e2c87dae93e
Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
42 public final class ReinterpretNode extends UnaryNode implements ArithmeticLIRLowerable { |
7e2c87dae93e
Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
43 |
7e2c87dae93e
Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
44 public static final NodeClass TYPE = NodeClass.get(ReinterpretNode.class); |
12656 | 45 |
18845
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18793
diff
changeset
|
46 public ReinterpretNode(Kind to, ValueNode value) { |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
47 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
|
48 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
49 |
18845
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18793
diff
changeset
|
50 public ReinterpretNode(Stamp to, ValueNode value) { |
19403
7e2c87dae93e
Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
51 super(TYPE, to, value); |
18793
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
52 assert to instanceof ArithmeticStamp; |
12656 | 53 } |
54 | |
18793
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
55 private SerializableConstant evalConst(SerializableConstant c) { |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
56 /* |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
57 * We don't care about byte order here. Either would produce the correct result. |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
58 */ |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
59 ByteBuffer buffer = ByteBuffer.wrap(new byte[c.getSerializedSize()]).order(ByteOrder.nativeOrder()); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
60 c.serialize(buffer); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
61 |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
62 buffer.rewind(); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
63 SerializableConstant ret = ((ArithmeticStamp) stamp()).deserialize(buffer); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
64 |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
65 assert !buffer.hasRemaining(); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
66 return ret; |
12656 | 67 } |
68 | |
69 @Override | |
16216
388b787a5fe6
implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16156
diff
changeset
|
70 public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) { |
388b787a5fe6
implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16156
diff
changeset
|
71 if (forValue.isConstant()) { |
18793
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
72 return ConstantNode.forConstant(stamp(), evalConst((SerializableConstant) forValue.asConstant()), null); |
12656 | 73 } |
16216
388b787a5fe6
implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16156
diff
changeset
|
74 if (stamp().isCompatible(forValue.stamp())) { |
388b787a5fe6
implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16156
diff
changeset
|
75 return forValue; |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
76 } |
16216
388b787a5fe6
implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16156
diff
changeset
|
77 if (forValue instanceof ReinterpretNode) { |
388b787a5fe6
implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16156
diff
changeset
|
78 ReinterpretNode reinterpret = (ReinterpretNode) forValue; |
18845
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18793
diff
changeset
|
79 return new ReinterpretNode(stamp(), reinterpret.getValue()); |
14591
dbe41340d0a6
eliminate sequential reinterprets
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14011
diff
changeset
|
80 } |
12656 | 81 return this; |
82 } | |
83 | |
84 @Override | |
15130
ec22234bde0d
Pass more restricted interfaces to ArithmeticLIRLowerable and LocationNode in LIR generation.
Roland Schatz <roland.schatz@oracle.com>
parents:
14950
diff
changeset
|
85 public void generate(NodeMappableLIRBuilder builder, ArithmeticLIRGenerator gen) { |
16094
c0b8d395368b
Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
15413
diff
changeset
|
86 LIRKind kind = gen.getLIRKind(stamp()); |
16156
0993768dfc8e
new UnaryNode base class
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16094
diff
changeset
|
87 builder.setResult(this, gen.emitReinterpret(kind, builder.operand(getValue()))); |
12656 | 88 } |
89 | |
90 public static ValueNode reinterpret(Kind toKind, ValueNode value) { | |
18845
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18793
diff
changeset
|
91 return value.graph().unique(new ReinterpretNode(toKind, value)); |
12656 | 92 } |
93 | |
94 @NodeIntrinsic | |
95 public static native float reinterpret(@ConstantNodeParameter Kind kind, int value); | |
96 | |
97 @NodeIntrinsic | |
98 public static native int reinterpret(@ConstantNodeParameter Kind kind, float value); | |
99 | |
100 @NodeIntrinsic | |
101 public static native double reinterpret(@ConstantNodeParameter Kind kind, long value); | |
102 | |
103 @NodeIntrinsic | |
104 public static native long reinterpret(@ConstantNodeParameter Kind kind, double value); | |
105 } |