Skip to content

Commit

Permalink
[Offload] Add support for loongarch64 to host plugin
Browse files Browse the repository at this point in the history
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: llvm/llvm-project#120173
  • Loading branch information
wangleiat authored Dec 17, 2024
1 parent a7dafea commit bdf7270
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions clang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4257,6 +4257,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
if (TT.getArch() == llvm::Triple::UnknownArch ||
!(TT.getArch() == llvm::Triple::aarch64 || TT.isPPC() ||
TT.getArch() == llvm::Triple::systemz ||
TT.getArch() == llvm::Triple::loongarch64 ||
TT.getArch() == llvm::Triple::nvptx ||
TT.getArch() == llvm::Triple::nvptx64 ||
TT.getArch() == llvm::Triple::amdgcn ||
Expand Down
1 change: 1 addition & 0 deletions clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ Expected<StringRef> linkDevice(ArrayRef<StringRef> InputFiles,
case Triple::ppc64:
case Triple::ppc64le:
case Triple::systemz:
case Triple::loongarch64:
return generic::clang(InputFiles, Args);
default:
return createStringError(Triple.getArchName() +
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Frontend/OpenMP/OMPContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ OMPContext::OMPContext(bool IsDeviceCompilation, Triple TargetTriple) {
case Triple::aarch64:
case Triple::aarch64_be:
case Triple::aarch64_32:
case Triple::loongarch64:
case Triple::mips:
case Triple::mipsel:
case Triple::mips64:
Expand Down
2 changes: 2 additions & 0 deletions offload/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} s390x-ibm-linux-gnu")
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} s390x-ibm-linux-gnu-LTO")
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} riscv64-unknown-linux-gnu")
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} riscv64-unknown-linux-gnu-LTO")
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} loongarch64-unknown-linux-gnu")
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} loongarch64-unknown-linux-gnu-LTO")

# Once the plugins for the different targets are validated, they will be added to
# the list of supported targets in the current system.
Expand Down
2 changes: 2 additions & 0 deletions offload/plugins-nextgen/common/src/Utils/ELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ uint16_t utils::elf::getTargetMachine() {
return EM_PPC64;
#elif defined(__riscv)
return EM_RISCV;
#elif defined(__loongarch__)
return EM_LOONGARCH;
#else
#warning "Unknown ELF compilation target architecture"
return EM_NONE;
Expand Down
6 changes: 5 additions & 1 deletion offload/plugins-nextgen/host/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(supported_targets x86_64 aarch64 ppc64 ppc64le riscv64 s390x)
set(supported_targets x86_64 aarch64 ppc64 ppc64le riscv64 s390x loongarch64)
if(NOT ${CMAKE_SYSTEM_PROCESSOR} IN_LIST supported_targets)
message(STATUS "Not building ${machine} NextGen offloading plugin")
return()
Expand Down Expand Up @@ -63,4 +63,8 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "riscv64$")
list(APPEND LIBOMPTARGET_SYSTEM_TARGETS
"riscv64-unknown-linux-gnu" "riscv64-unknown-linux-gnu-LTO")
set(LIBOMPTARGET_SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS}" PARENT_SCOPE)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "loongarch64$")
list(APPEND LIBOMPTARGET_SYSTEM_TARGETS
"loongarch64-unknown-linux-gnu" "loongarch64-unknown-linux-gnu-LTO")
set(LIBOMPTARGET_SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS}" PARENT_SCOPE)
endif()
2 changes: 1 addition & 1 deletion offload/plugins-nextgen/host/dynamic_ffi/ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ typedef enum ffi_abi {
#if (defined(_M_X64) || defined(__x86_64__))
FFI_DEFAULT_ABI = 2, // FFI_UNIX64.
#elif defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64) || \
defined(__riscv)
defined(__riscv) || defined(__loongarch__)
FFI_DEFAULT_ABI = 1, // FFI_SYSV.
#elif defined(__powerpc64__)
FFI_DEFAULT_ABI = 8, // FFI_LINUX.
Expand Down
2 changes: 2 additions & 0 deletions offload/plugins-nextgen/host/src/rtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@ struct GenELF64PluginTy final : public GenericPluginTy {
#endif
#elif defined(__riscv) && (__riscv_xlen == 64)
return llvm::Triple::riscv64;
#elif defined(__loongarch__) && (__loongarch_grlen == 64)
return llvm::Triple::loongarch64;
#else
return llvm::Triple::UnknownArch;
#endif
Expand Down

0 comments on commit bdf7270

Please sign in to comment.