43972
|
1 |
/*
|
58533
|
2 |
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
|
43972
|
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 |
*/
|
50858
|
23 |
|
|
24 |
|
43972
|
25 |
package org.graalvm.compiler.replacements.amd64;
|
|
26 |
|
46393
|
27 |
import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_8;
|
43972
|
28 |
import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_1;
|
58533
|
29 |
import static org.graalvm.compiler.nodes.calc.BinaryArithmeticNode.getArithmeticOpTable;
|
43972
|
30 |
|
|
31 |
import org.graalvm.compiler.core.common.calc.FloatConvert;
|
58533
|
32 |
import org.graalvm.compiler.core.common.type.ArithmeticOpTable;
|
43972
|
33 |
import org.graalvm.compiler.core.common.type.ArithmeticOpTable.FloatConvertOp;
|
58533
|
34 |
import org.graalvm.compiler.core.common.type.ArithmeticOpTable.UnaryOp;
|
50609
|
35 |
import org.graalvm.compiler.core.common.type.IntegerStamp;
|
|
36 |
import org.graalvm.compiler.core.common.type.Stamp;
|
|
37 |
import org.graalvm.compiler.core.common.type.StampFactory;
|
43972
|
38 |
import org.graalvm.compiler.graph.NodeClass;
|
|
39 |
import org.graalvm.compiler.graph.spi.CanonicalizerTool;
|
|
40 |
import org.graalvm.compiler.lir.gen.ArithmeticLIRGeneratorTool;
|
|
41 |
import org.graalvm.compiler.nodeinfo.NodeInfo;
|
|
42 |
import org.graalvm.compiler.nodes.ValueNode;
|
|
43 |
import org.graalvm.compiler.nodes.calc.FloatConvertNode;
|
|
44 |
import org.graalvm.compiler.nodes.calc.UnaryArithmeticNode;
|
|
45 |
import org.graalvm.compiler.nodes.spi.ArithmeticLIRLowerable;
|
|
46 |
import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
|
|
47 |
|
58533
|
48 |
import jdk.vm.ci.meta.JavaConstant;
|
|
49 |
|
43972
|
50 |
/**
|
|
51 |
* This node has the semantics of the AMD64 floating point conversions. It is used in the lowering
|
|
52 |
* of the {@link FloatConvertNode} which, on AMD64 needs a {@link AMD64FloatConvertNode} plus some
|
|
53 |
* fixup code that handles the corner cases that differ between AMD64 and Java.
|
50609
|
54 |
*
|
|
55 |
* Since this node evaluates to a special value if the conversion is inexact, its stamp must be
|
|
56 |
* modified to avoid optimizing away {@link AMD64ConvertSnippets}.
|
43972
|
57 |
*/
|
46393
|
58 |
@NodeInfo(cycles = CYCLES_8, size = SIZE_1)
|
43972
|
59 |
public final class AMD64FloatConvertNode extends UnaryArithmeticNode<FloatConvertOp> implements ArithmeticLIRLowerable {
|
|
60 |
public static final NodeClass<AMD64FloatConvertNode> TYPE = NodeClass.create(AMD64FloatConvertNode.class);
|
|
61 |
|
|
62 |
protected final FloatConvert op;
|
|
63 |
|
|
64 |
public AMD64FloatConvertNode(FloatConvert op, ValueNode value) {
|
58533
|
65 |
super(TYPE, getArithmeticOpTable(value).getFloatConvert(op), value);
|
43972
|
66 |
this.op = op;
|
50609
|
67 |
this.stamp = this.stamp.meet(createInexactCaseStamp());
|
43972
|
68 |
}
|
|
69 |
|
|
70 |
@Override
|
58533
|
71 |
protected UnaryOp<FloatConvertOp> getOp(ArithmeticOpTable table) {
|
|
72 |
return table.getFloatConvert(op);
|
|
73 |
}
|
|
74 |
|
|
75 |
@Override
|
43972
|
76 |
public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) {
|
|
77 |
// nothing to do
|
|
78 |
return this;
|
|
79 |
}
|
|
80 |
|
|
81 |
@Override
|
50609
|
82 |
public Stamp foldStamp(Stamp newStamp) {
|
|
83 |
// The semantics of the x64 CVTTSS2SI instruction allow returning 0x8000000 in the special
|
|
84 |
// cases.
|
|
85 |
Stamp foldedStamp = super.foldStamp(newStamp);
|
|
86 |
return foldedStamp.meet(createInexactCaseStamp());
|
|
87 |
}
|
|
88 |
|
|
89 |
private Stamp createInexactCaseStamp() {
|
|
90 |
IntegerStamp intStamp = (IntegerStamp) this.stamp;
|
|
91 |
long inexactValue = intStamp.getBits() <= 32 ? 0x8000_0000L : 0x8000_0000_0000_0000L;
|
|
92 |
return StampFactory.forConstant(JavaConstant.forPrimitiveInt(intStamp.getBits(), inexactValue));
|
|
93 |
}
|
|
94 |
|
|
95 |
@Override
|
43972
|
96 |
public void generate(NodeLIRBuilderTool nodeValueMap, ArithmeticLIRGeneratorTool gen) {
|
|
97 |
nodeValueMap.setResult(this, gen.emitFloatConvert(op, nodeValueMap.operand(getValue())));
|
|
98 |
}
|
|
99 |
}
|