llvm-16.0: Fix some issues in Reactor/LLVMJIT for LoongArch.
This CL fixes issues same as RISCV:
https://issuetracker.google.com/issues/217573066#comment2
1) JIT Linking on LoongArch is only supported with
ObjectLinkingLayer.
2) jitTargetMachineBuilder.getFeatures() on LoongArch
does not return the LoongArch CPU extensions, so they
are manually added.
Bug: swiftshader:178
Change-Id: Ie454f353d617eb96b46f0c082ce6cd205cb43718
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/73328
Reviewed-by: Geoff Lang <geofflang@google.com>
Presubmit-Ready: Ben Clayton <bclayton@google.com>
Commit-Queue: Geoff Lang <geofflang@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Tested-by: Ben Clayton <bclayton@google.com>
diff --git a/src/Reactor/LLVMJIT.cpp b/src/Reactor/LLVMJIT.cpp
index 0f61e07..262c69e 100644
--- a/src/Reactor/LLVMJIT.cpp
+++ b/src/Reactor/LLVMJIT.cpp
@@ -28,8 +28,8 @@
// See https://groups.google.com/g/llvm-dev/c/CAE7Va57h2c/m/74ITeXFEAQAJ
// for information about `RTDyldObjectLinkingLayer` vs `ObjectLinkingLayer`.
-// On RISC-V, only `ObjectLinkingLayer` is supported.
-#if defined(__riscv)
+// On RISC-V and LoongArch, only `ObjectLinkingLayer` is supported.
+#if defined(__riscv) || defined(__loongarch__)
#define USE_LEGACY_OBJECT_LINKING_LAYER 0
#else
#define USE_LEGACY_OBJECT_LINKING_LAYER 1
@@ -250,6 +250,11 @@
// On RISC-V, using the default code model results in an
// "Unsupported riscv relocation" error.
jitTargetMachineBuilder.setCodeModel(llvm::CodeModel::Medium);
+#elif defined(__loongarch__)
+ // jitTargetMachineBuilder.getFeatures() on LoongArch does
+ // not return the LoongArch CPU extensions, so they are
+ // manually added.
+ jitTargetMachineBuilder.getFeatures().AddFeature("+d");
#endif
jitTargetMachineBuilder.setCPU(std::string(llvm::sys::getHostCPUName()));