43972
|
1 |
/*
|
57537
|
2 |
* Copyright (c) 2015, 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.lir.jtt;
|
|
26 |
|
|
27 |
import static org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant;
|
|
28 |
import static org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant;
|
|
29 |
|
|
30 |
import org.junit.Before;
|
|
31 |
import org.junit.Test;
|
|
32 |
|
|
33 |
import org.graalvm.compiler.core.common.LIRKind;
|
|
34 |
import org.graalvm.compiler.debug.GraalError;
|
|
35 |
import org.graalvm.compiler.lir.ConstantValue;
|
|
36 |
import org.graalvm.compiler.lir.VirtualStackSlot;
|
|
37 |
import org.graalvm.compiler.lir.framemap.FrameMapBuilder;
|
|
38 |
import org.graalvm.compiler.lir.gen.LIRGeneratorTool;
|
|
39 |
|
|
40 |
import jdk.vm.ci.meta.JavaConstant;
|
|
41 |
import jdk.vm.ci.meta.JavaKind;
|
|
42 |
import jdk.vm.ci.meta.PlatformKind;
|
|
43 |
import jdk.vm.ci.meta.Value;
|
|
44 |
|
|
45 |
/**
|
|
46 |
* Tests move from a constant to a wider stack slot (e.g. byte constant to integer stack slot).
|
|
47 |
*/
|
|
48 |
public class ConstantStackCastTest extends LIRTest {
|
|
49 |
private static PlatformKind byteKind;
|
|
50 |
private static final LoadConstantStackSpec stackCopyByte = new LoadConstantStackSpec();
|
|
51 |
|
|
52 |
@Before
|
|
53 |
public void setup() {
|
|
54 |
// Necessary to get the PlatformKind on which we're currently running on
|
|
55 |
byteKind = getBackend().getTarget().arch.getPlatformKind(JavaKind.Byte);
|
|
56 |
stackCopyByte.dstKind = LIRKind.fromJavaKind(getBackend().getTarget().arch, JavaKind.Int);
|
|
57 |
stackCopyByte.srcKind = LIRKind.fromJavaKind(getBackend().getTarget().arch, JavaKind.Byte);
|
|
58 |
}
|
|
59 |
|
|
60 |
private static class LoadConstantStackSpec extends LIRTestSpecification {
|
|
61 |
LIRKind dstKind;
|
|
62 |
LIRKind srcKind;
|
|
63 |
|
|
64 |
@Override
|
|
65 |
public void generate(LIRGeneratorTool gen, Value value) {
|
|
66 |
FrameMapBuilder frameMapBuilder = gen.getResult().getFrameMapBuilder();
|
|
67 |
// create slots
|
|
68 |
VirtualStackSlot s1 = frameMapBuilder.allocateSpillSlot(dstKind);
|
|
69 |
// move stuff around
|
|
70 |
Value srcValue;
|
|
71 |
if (isJavaConstant(value)) {
|
|
72 |
srcValue = getConstant(srcKind, asJavaConstant(value));
|
|
73 |
} else {
|
|
74 |
srcValue = value;
|
|
75 |
}
|
|
76 |
gen.emitMove(s1, srcValue);
|
|
77 |
gen.emitBlackhole(s1);
|
|
78 |
setResult(gen.emitMove(s1));
|
|
79 |
}
|
|
80 |
|
|
81 |
private static ConstantValue getConstant(LIRKind srcKind, JavaConstant c) {
|
|
82 |
if (srcKind.getPlatformKind() == byteKind) {
|
|
83 |
JavaConstant byteConst = JavaConstant.forByte((byte) c.asInt());
|
|
84 |
return new ConstantValue(srcKind, byteConst);
|
|
85 |
} else {
|
|
86 |
throw GraalError.shouldNotReachHere("Kind not supported: " + srcKind);
|
|
87 |
}
|
|
88 |
}
|
|
89 |
|
|
90 |
}
|
|
91 |
|
|
92 |
@LIRIntrinsic
|
|
93 |
public static byte testCopyByte(@SuppressWarnings("unused") LoadConstantStackSpec spec, byte value) {
|
|
94 |
return value;
|
|
95 |
}
|
|
96 |
|
|
97 |
public byte testByte(byte value) {
|
|
98 |
return testCopyByte(stackCopyByte, value);
|
|
99 |
}
|
|
100 |
|
|
101 |
@Test
|
57537
|
102 |
public void runByte() {
|
43972
|
103 |
runTest("testByte", (byte) 0);
|
|
104 |
}
|
|
105 |
|
|
106 |
}
|