Skip to content

Commit 7fbde87

Browse files
committed
Add RISC-V LLVM backend for Native Image
1 parent 25922e0 commit 7fbde87

File tree

54 files changed

+2643
-40
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2643
-40
lines changed

compiler/mx.compiler/mx_compiler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,8 @@ def compiler_gate_benchmark_runner(tasks, extraVMarguments=None, prefix=''):
620620

621621
_registers = {
622622
'amd64': 'rbx,r11,r10,r14,xmm3,xmm2,xmm11,xmm14,k1?',
623-
'aarch64': 'r0,r1,r2,r3,r4,v0,v1,v2,v3'
623+
'aarch64': 'r0,r1,r2,r3,r4,v0,v1,v2,v3',
624+
'riscv64': 'x10,x11,x12,x13,x14,v10,v11,v12,v13'
624625
}
625626
if mx.get_arch() not in _registers:
626627
mx.warn('No registers for register pressure tests are defined for architecture ' + mx.get_arch())

compiler/mx.compiler/suite.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@
167167
"digest" : "sha512:422e1078fe5d9e2f71c04ca2bbefef4e09cf9675d132c7531f1fb17330e2b1f9441470541b66c8db2f3d8e105d167e25a78dc11aada524ed623b1ae9a4cfdeeb",
168168
"urls" : ["{urlbase}/hsdis-aarch64-linux-fcc9b70ac91c00db8a50b0d4345490a68e3743e1.tar.gz"],
169169
},
170+
"riscv64" : {
171+
"optional" : True,
172+
}
170173
},
171174
"darwin" : {
172175
"amd64" : {
@@ -681,6 +684,27 @@
681684
"workingSets" : "Graal,HotSpot,AMD64",
682685
},
683686

687+
"org.graalvm.compiler.hotspot.riscv64" : {
688+
"subDir" : "src",
689+
"sourceDirs" : ["src"],
690+
"dependencies" : [
691+
"org.graalvm.compiler.core.riscv64",
692+
"org.graalvm.compiler.hotspot",
693+
],
694+
"requiresConcealed" : {
695+
"jdk.internal.vm.ci" : [
696+
"jdk.vm.ci.meta",
697+
"jdk.vm.ci.code",
698+
],
699+
},
700+
"checkstyle" : "org.graalvm.compiler.graph",
701+
"annotationProcessors" : [
702+
"GRAAL_PROCESSOR"
703+
],
704+
"javaCompliance" : "11+",
705+
"workingSets" : "Graal,HotSpot,RISCV64",
706+
},
707+
684708
"org.graalvm.compiler.hotspot.test" : {
685709
"subDir" : "src",
686710
"sourceDirs" : ["src"],
@@ -1389,6 +1413,20 @@
13891413
"workingSets" : "Graal,AMD64,Test",
13901414
},
13911415

1416+
"org.graalvm.compiler.core.riscv64" : {
1417+
"subDir" : "src",
1418+
"sourceDirs" : ["src"],
1419+
"dependencies" : [
1420+
"org.graalvm.compiler.core",
1421+
],
1422+
"checkstyle" : "org.graalvm.compiler.graph",
1423+
"annotationProcessors" : [
1424+
"GRAAL_PROCESSOR",
1425+
],
1426+
"javaCompliance" : "11+",
1427+
"workingSets" : "Graal,RISCV64",
1428+
},
1429+
13921430
"org.graalvm.compiler.runtime" : {
13931431
"subDir" : "src",
13941432
"sourceDirs" : ["src"],
@@ -2110,8 +2148,10 @@
21102148
"org.graalvm.compiler.replacements.aarch64",
21112149
"org.graalvm.compiler.core.amd64",
21122150
"org.graalvm.compiler.replacements.amd64",
2151+
"org.graalvm.compiler.core.riscv64",
21132152
"org.graalvm.compiler.hotspot.aarch64",
21142153
"org.graalvm.compiler.hotspot.amd64",
2154+
"org.graalvm.compiler.hotspot.riscv64",
21152155
"org.graalvm.compiler.hotspot",
21162156
"org.graalvm.compiler.lir.aarch64",
21172157
"org.graalvm.compiler.truffle.runtime.serviceprovider",
@@ -2187,6 +2227,9 @@
21872227
"description" : "Disassembler support distribution for the GraalVM",
21882228
"os_arch" : {
21892229
"linux" : {
2230+
"riscv64" : {
2231+
"optional" : True,
2232+
},
21902233
"<others>" : {
21912234
"layout" : {
21922235
"hsdis-<arch>.so" : "file:<path:HSDIS>/*",
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
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. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
package org.graalvm.compiler.core.riscv64;
27+
28+
import org.graalvm.compiler.core.common.memory.MemoryExtendKind;
29+
import org.graalvm.compiler.nodes.memory.ExtendableMemoryAccess;
30+
import org.graalvm.compiler.nodes.spi.LoweringProvider;
31+
32+
public interface RISCV64LoweringProviderMixin extends LoweringProvider {
33+
34+
@Override
35+
default boolean divisionOverflowIsJVMSCompliant() {
36+
return true;
37+
}
38+
39+
@Override
40+
default Integer smallestCompareWidth() {
41+
return 32;
42+
}
43+
44+
@Override
45+
default boolean supportsBulkZeroing() {
46+
return false;
47+
}
48+
49+
@Override
50+
default boolean supportsRounding() {
51+
return false;
52+
}
53+
54+
@Override
55+
default boolean writesStronglyOrdered() {
56+
return false;
57+
}
58+
59+
@Override
60+
default boolean narrowsUseCastValue() {
61+
return false;
62+
}
63+
64+
@Override
65+
default boolean supportsFoldingExtendIntoAccess(ExtendableMemoryAccess access, MemoryExtendKind extendKind) {
66+
return false;
67+
}
68+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
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. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
package org.graalvm.compiler.core.riscv64;
27+
28+
import org.graalvm.compiler.core.gen.NodeMatchRules;
29+
import org.graalvm.compiler.lir.gen.LIRGeneratorTool;
30+
31+
public class RISCV64NodeMatchRules extends NodeMatchRules {
32+
public RISCV64NodeMatchRules(LIRGeneratorTool gen) {
33+
super(gen);
34+
}
35+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
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. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
package org.graalvm.compiler.core.riscv64;
27+
28+
import java.lang.reflect.Method;
29+
30+
/**
31+
* This class contains utility methods for accessing RISC-V JVMCI classes and fields using
32+
* reflection. This is needed as all JDK versions used by Graal currently do not implement JVMCI for
33+
* RISC-V, which causes unwanted build errors.
34+
*/
35+
public class RISCV64ReflectionUtil {
36+
public static final String archClass = "jdk.vm.ci.riscv64.RISCV64";
37+
public static final String featureClass = archClass + "$CPUFeature";
38+
public static final String flagClass = archClass + "$Flag";
39+
public static final String hotSpotClass = "jdk.vm.ci.hotspot.riscv64.RISCV64HotSpotRegisterConfig";
40+
41+
public static Class<?> lookupClass(boolean optional, String className) {
42+
try {
43+
return Class.forName(className);
44+
} catch (ClassNotFoundException ex) {
45+
if (optional) {
46+
return null;
47+
}
48+
throw new ReflectionUtilError(ex);
49+
}
50+
}
51+
52+
public static Class<?> getArch(boolean optional) {
53+
return lookupClass(optional, archClass);
54+
}
55+
56+
@SuppressWarnings("unchecked")
57+
public static <T> T readStaticField(Class<?> declaringClass, String fieldName) {
58+
try {
59+
return (T) declaringClass.getField(fieldName).get(null);
60+
} catch (ReflectiveOperationException ex) {
61+
throw new ReflectionUtilError(ex);
62+
}
63+
}
64+
65+
@SuppressWarnings("serial")
66+
public static final class ReflectionUtilError extends Error {
67+
private ReflectionUtilError(Throwable cause) {
68+
super(cause);
69+
}
70+
}
71+
72+
public static Method lookupMethod(Class<?> declaringClass, String methodName, Class<?>... parameterTypes) {
73+
try {
74+
return declaringClass.getDeclaredMethod(methodName, parameterTypes);
75+
} catch (ReflectiveOperationException ex) {
76+
throw new ReflectionUtilError(ex);
77+
}
78+
}
79+
80+
public static Object invokeMethod(Method method, Object obj, Object... args) {
81+
try {
82+
return method.invoke(obj, args);
83+
} catch (ReflectiveOperationException ex) {
84+
throw new ReflectionUtilError(ex);
85+
}
86+
}
87+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
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. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
package org.graalvm.compiler.core.riscv64;
27+
28+
import jdk.vm.ci.code.Architecture;
29+
import jdk.vm.ci.code.Register;
30+
import jdk.vm.ci.code.RegisterArray;
31+
32+
public class ShadowedRISCV64 {
33+
public static final Class<?> riscv64OrNull = RISCV64ReflectionUtil.getArch(true);
34+
35+
public static final Register x0 = getRegister("x0");
36+
public static final Register x1 = getRegister("x1");
37+
public static final Register x2 = getRegister("x2");
38+
public static final Register x3 = getRegister("x3");
39+
public static final Register x4 = getRegister("x4");
40+
public static final Register x5 = getRegister("x5");
41+
public static final Register x6 = getRegister("x6");
42+
public static final Register x7 = getRegister("x7");
43+
public static final Register x8 = getRegister("x8");
44+
public static final Register x9 = getRegister("x9");
45+
public static final Register x10 = getRegister("x10");
46+
public static final Register x11 = getRegister("x11");
47+
public static final Register x12 = getRegister("x12");
48+
public static final Register x13 = getRegister("x13");
49+
public static final Register x14 = getRegister("x14");
50+
public static final Register x15 = getRegister("x15");
51+
public static final Register x16 = getRegister("x16");
52+
public static final Register x17 = getRegister("x17");
53+
public static final Register x18 = getRegister("x18");
54+
public static final Register x19 = getRegister("x19");
55+
public static final Register x20 = getRegister("x20");
56+
public static final Register x21 = getRegister("x21");
57+
public static final Register x22 = getRegister("x22");
58+
public static final Register x23 = getRegister("x23");
59+
public static final Register x24 = getRegister("x24");
60+
public static final Register x25 = getRegister("x25");
61+
public static final Register x26 = getRegister("x26");
62+
public static final Register x27 = getRegister("x27");
63+
public static final Register x28 = getRegister("x28");
64+
public static final Register x29 = getRegister("x29");
65+
public static final Register x30 = getRegister("x30");
66+
public static final Register x31 = getRegister("x31");
67+
68+
public static final Register f0 = getRegister("f0");
69+
public static final Register f1 = getRegister("f1");
70+
public static final Register f2 = getRegister("f2");
71+
public static final Register f3 = getRegister("f3");
72+
public static final Register f4 = getRegister("f4");
73+
public static final Register f5 = getRegister("f5");
74+
public static final Register f6 = getRegister("f6");
75+
public static final Register f7 = getRegister("f7");
76+
public static final Register f8 = getRegister("f8");
77+
public static final Register f9 = getRegister("f9");
78+
public static final Register f10 = getRegister("f10");
79+
public static final Register f11 = getRegister("f11");
80+
public static final Register f12 = getRegister("f12");
81+
public static final Register f13 = getRegister("f13");
82+
public static final Register f14 = getRegister("f14");
83+
public static final Register f15 = getRegister("f15");
84+
public static final Register f16 = getRegister("f16");
85+
public static final Register f17 = getRegister("f17");
86+
public static final Register f18 = getRegister("f18");
87+
public static final Register f19 = getRegister("f19");
88+
public static final Register f20 = getRegister("f20");
89+
public static final Register f21 = getRegister("f21");
90+
public static final Register f22 = getRegister("f22");
91+
public static final Register f23 = getRegister("f23");
92+
public static final Register f24 = getRegister("f24");
93+
public static final Register f25 = getRegister("f25");
94+
public static final Register f26 = getRegister("f26");
95+
public static final Register f27 = getRegister("f27");
96+
public static final Register f28 = getRegister("f28");
97+
public static final Register f29 = getRegister("f29");
98+
public static final Register f30 = getRegister("f30");
99+
public static final Register f31 = getRegister("f31");
100+
101+
public static final RegisterArray allRegisters = riscv64OrNull == null ? null : RISCV64ReflectionUtil.readStaticField(riscv64OrNull, "allRegisters");
102+
103+
public static boolean instanceOf(Architecture arch) {
104+
return ShadowedRISCV64.riscv64OrNull != null && ShadowedRISCV64.riscv64OrNull.isInstance(arch);
105+
}
106+
107+
private static Register getRegister(String register) {
108+
return riscv64OrNull == null ? null : RISCV64ReflectionUtil.readStaticField(riscv64OrNull, register);
109+
}
110+
}

0 commit comments

Comments
 (0)