Skip to content

Commit bdf7270

Browse files
authored
[Offload] Add support for loongarch64 to host plugin
This adds support for the loongarch64 architecture to the offload host plugin. Similar to #115773 To fix some test issues, I've had to add the LoongArch64 target to: - CompilerInvocation::ParseLangArgs - linkDevice in ClangLinuxWrapper.cpp - OMPContext::OMPContext (to set the device_kind_cpu trait) Reviewed By: jhuber6 Pull Request: #120173
1 parent a7dafea commit bdf7270

File tree

8 files changed

+15
-2
lines changed

8 files changed

+15
-2
lines changed

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4257,6 +4257,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
42574257
if (TT.getArch() == llvm::Triple::UnknownArch ||
42584258
!(TT.getArch() == llvm::Triple::aarch64 || TT.isPPC() ||
42594259
TT.getArch() == llvm::Triple::systemz ||
4260+
TT.getArch() == llvm::Triple::loongarch64 ||
42604261
TT.getArch() == llvm::Triple::nvptx ||
42614262
TT.getArch() == llvm::Triple::nvptx64 ||
42624263
TT.getArch() == llvm::Triple::amdgcn ||

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ Expected<StringRef> linkDevice(ArrayRef<StringRef> InputFiles,
596596
case Triple::ppc64:
597597
case Triple::ppc64le:
598598
case Triple::systemz:
599+
case Triple::loongarch64:
599600
return generic::clang(InputFiles, Args);
600601
default:
601602
return createStringError(Triple.getArchName() +

llvm/lib/Frontend/OpenMP/OMPContext.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ OMPContext::OMPContext(bool IsDeviceCompilation, Triple TargetTriple) {
3636
case Triple::aarch64:
3737
case Triple::aarch64_be:
3838
case Triple::aarch64_32:
39+
case Triple::loongarch64:
3940
case Triple::mips:
4041
case Triple::mipsel:
4142
case Triple::mips64:

offload/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} s390x-ibm-linux-gnu")
207207
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} s390x-ibm-linux-gnu-LTO")
208208
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} riscv64-unknown-linux-gnu")
209209
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} riscv64-unknown-linux-gnu-LTO")
210+
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} loongarch64-unknown-linux-gnu")
211+
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} loongarch64-unknown-linux-gnu-LTO")
210212

211213
# Once the plugins for the different targets are validated, they will be added to
212214
# the list of supported targets in the current system.

offload/plugins-nextgen/common/src/Utils/ELF.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ uint16_t utils::elf::getTargetMachine() {
4747
return EM_PPC64;
4848
#elif defined(__riscv)
4949
return EM_RISCV;
50+
#elif defined(__loongarch__)
51+
return EM_LOONGARCH;
5052
#else
5153
#warning "Unknown ELF compilation target architecture"
5254
return EM_NONE;

offload/plugins-nextgen/host/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set(supported_targets x86_64 aarch64 ppc64 ppc64le riscv64 s390x)
1+
set(supported_targets x86_64 aarch64 ppc64 ppc64le riscv64 s390x loongarch64)
22
if(NOT ${CMAKE_SYSTEM_PROCESSOR} IN_LIST supported_targets)
33
message(STATUS "Not building ${machine} NextGen offloading plugin")
44
return()
@@ -63,4 +63,8 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "riscv64$")
6363
list(APPEND LIBOMPTARGET_SYSTEM_TARGETS
6464
"riscv64-unknown-linux-gnu" "riscv64-unknown-linux-gnu-LTO")
6565
set(LIBOMPTARGET_SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS}" PARENT_SCOPE)
66+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "loongarch64$")
67+
list(APPEND LIBOMPTARGET_SYSTEM_TARGETS
68+
"loongarch64-unknown-linux-gnu" "loongarch64-unknown-linux-gnu-LTO")
69+
set(LIBOMPTARGET_SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS}" PARENT_SCOPE)
6670
endif()

offload/plugins-nextgen/host/dynamic_ffi/ffi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ typedef enum ffi_abi {
4444
#if (defined(_M_X64) || defined(__x86_64__))
4545
FFI_DEFAULT_ABI = 2, // FFI_UNIX64.
4646
#elif defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64) || \
47-
defined(__riscv)
47+
defined(__riscv) || defined(__loongarch__)
4848
FFI_DEFAULT_ABI = 1, // FFI_SYSV.
4949
#elif defined(__powerpc64__)
5050
FFI_DEFAULT_ABI = 8, // FFI_LINUX.

offload/plugins-nextgen/host/src/rtl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,8 @@ struct GenELF64PluginTy final : public GenericPluginTy {
442442
#endif
443443
#elif defined(__riscv) && (__riscv_xlen == 64)
444444
return llvm::Triple::riscv64;
445+
#elif defined(__loongarch__) && (__loongarch_grlen == 64)
446+
return llvm::Triple::loongarch64;
445447
#else
446448
return llvm::Triple::UnknownArch;
447449
#endif

0 commit comments

Comments
 (0)