From 50df01d00e8c80ede4e0928ee9ba6a822ef408d8 Mon Sep 17 00:00:00 2001 From: oltolm Date: Mon, 25 Sep 2023 17:04:48 +0200 Subject: [PATCH] llvm: add support for LLVM 17 --- 3rdparty/llvm/CMakeLists.txt | 9 ++++++++- Utilities/JIT.cpp | 2 +- rpcs3/Emu/CPU/CPUTranslator.h | 10 +++++++++- rpcs3/Emu/Cell/PPUThread.cpp | 2 +- rpcs3/Emu/Cell/SPURecompiler.cpp | 12 +++++++++++- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/3rdparty/llvm/CMakeLists.txt b/3rdparty/llvm/CMakeLists.txt index 679cb23a61..fdadd8c5d3 100644 --- a/3rdparty/llvm/CMakeLists.txt +++ b/3rdparty/llvm/CMakeLists.txt @@ -38,6 +38,10 @@ if(WITH_LLVM) # now tries to find LLVM again find_package(LLVM 16.0 CONFIG) + if(NOT LLVM_FOUND) + set(LLVM_DIR "${CMAKE_CURRENT_BINARY_DIR}/llvm_build/lib/cmake/llvm/") + find_package(LLVM 17.0 CONFIG) + endif() if(NOT LLVM_FOUND) message(FATAL_ERROR "Couldn't build LLVM from the submodule. You might need to run `git submodule update --init`") endif() @@ -50,10 +54,13 @@ if(WITH_LLVM) endif() find_package(LLVM 16.0 CONFIG) + if(NOT LLVM_FOUND) + find_package(LLVM 17.0 CONFIG) + endif() if (NOT LLVM_FOUND) if (LLVM_VERSION AND LLVM_VERSION_MAJOR LESS 16) - message(FATAL_ERROR "Found LLVM version ${LLVM_VERSION}. Required version 16. \ + message(FATAL_ERROR "Found LLVM version ${LLVM_VERSION}. Required versions 16...17. \ Enable BUILD_LLVM option to build LLVM from included as a git submodule.") endif() diff --git a/Utilities/JIT.cpp b/Utilities/JIT.cpp index caec5a6b22..b183f16f7d 100644 --- a/Utilities/JIT.cpp +++ b/Utilities/JIT.cpp @@ -866,7 +866,7 @@ void asmjit::simd_builder::vec_extract_gpr(u32 esize, const x86::Gp& dst, const #endif #include "llvm/Support/TargetSelect.h" #include "llvm/Support/FormattedStream.h" -#include "llvm/Support/Host.h" +#include "llvm/TargetParser/Host.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" #include "llvm/ExecutionEngine/RTDyldMemoryManager.h" #include "llvm/ExecutionEngine/ObjectCache.h" diff --git a/rpcs3/Emu/CPU/CPUTranslator.h b/rpcs3/Emu/CPU/CPUTranslator.h index edf6c92a65..57948d2d1a 100644 --- a/rpcs3/Emu/CPU/CPUTranslator.h +++ b/rpcs3/Emu/CPU/CPUTranslator.h @@ -922,6 +922,14 @@ inline llvm_div operator /(T1&& a1, T2&& a2) return {a1, a2}; } +inline llvm::Constant* getZeroValueForNegation(llvm::Type* Ty) +{ + if (Ty->isFPOrFPVectorTy()) + return llvm::ConstantFP::getNegativeZero(Ty); + + return llvm::Constant::getNullValue(Ty); +} + template > struct llvm_neg { @@ -971,7 +979,7 @@ struct llvm_neg { v1 = i->getOperand(1); - if (i->getOperand(0) == llvm::ConstantFP::getZeroValueForNegation(v1->getType())) + if (i->getOperand(0) == getZeroValueForNegation(v1->getType())) { if (auto r1 = a1.match(v1, _m); v1) { diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index ee89bb4692..b69dca2405 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -41,7 +41,7 @@ #pragma GCC diagnostic ignored "-Wmissing-noreturn" #endif #include "llvm/Support/FormattedStream.h" -#include "llvm/Support/Host.h" +#include "llvm/TargetParser/Host.h" #include "llvm/Object/ObjectFile.h" #if LLVM_VERSION_MAJOR < 17 #include "llvm/ADT/Triple.h" diff --git a/rpcs3/Emu/Cell/SPURecompiler.cpp b/rpcs3/Emu/Cell/SPURecompiler.cpp index e90133c93c..f69e7924a8 100644 --- a/rpcs3/Emu/Cell/SPURecompiler.cpp +++ b/rpcs3/Emu/Cell/SPURecompiler.cpp @@ -4373,7 +4373,7 @@ void spu_recompiler_base::dump(const spu_program& result, std::string& out) #if LLVM_VERSION_MAJOR < 17 #include "llvm/ADT/Triple.h" #endif -#include "llvm/Support/Host.h" +#include "llvm/TargetParser/Host.h" #include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Verifier.h" #include "llvm/IR/InlineAsm.h" @@ -6304,9 +6304,15 @@ public: pm.add(createEarlyCSEPass()); pm.add(createCFGSimplificationPass()); //pm.add(createNewGVNPass()); +#if LLVM_VERSION_MAJOR < 17 pm.add(createDeadStoreEliminationPass()); +#endif pm.add(createLICMPass()); +#if LLVM_VERSION_MAJOR < 17 pm.add(createAggressiveDCEPass()); +#else + pm.add(createDeadCodeEliminationPass()); +#endif //pm.add(createLintPass()); // Check for (auto& f : *m_module) @@ -6772,8 +6778,12 @@ public: // Basic optimizations pm.add(createEarlyCSEPass()); pm.add(createCFGSimplificationPass()); +#if LLVM_VERSION_MAJOR < 17 pm.add(createDeadStoreEliminationPass()); pm.add(createAggressiveDCEPass()); +#else + pm.add(createDeadCodeEliminationPass()); +#endif //pm.add(createLintPass()); for (auto& f : *_module)