diff --git a/3rdparty/llvm/CMakeLists.txt b/3rdparty/llvm/CMakeLists.txt index 28dbf06b07..a5fe885f44 100644 --- a/3rdparty/llvm/CMakeLists.txt +++ b/3rdparty/llvm/CMakeLists.txt @@ -80,6 +80,7 @@ if(WITH_LLVM) Core ExecutionEngine MCJIT + Passes ) else() set(LLVM_LIBS LLVM) diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index 7c0018461f..af3f78279e 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -32,25 +32,25 @@ #pragma warning(push, 0) #else #pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wall" -#pragma GCC diagnostic ignored "-Wextra" #pragma GCC diagnostic ignored "-Wold-style-cast" #pragma GCC diagnostic ignored "-Wunused-parameter" -#pragma GCC diagnostic ignored "-Wstrict-aliasing" -#pragma GCC diagnostic ignored "-Weffc++" #pragma GCC diagnostic ignored "-Wmissing-noreturn" #endif -#include "llvm/Support/FormattedStream.h" -#include "llvm/TargetParser/Host.h" -#include "llvm/Object/ObjectFile.h" +#include +#include #if LLVM_VERSION_MAJOR < 17 -#include "llvm/ADT/Triple.h" +#include +#include +#include +#include +#include +#include +#else +#include +#include +#include +#include #endif -#include "llvm/IR/Verifier.h" -#include "llvm/IR/InstIterator.h" -#include "llvm/IR/LegacyPassManager.h" -#include "llvm/Transforms/Utils/BasicBlockUtils.h" -#include "llvm/Transforms/Scalar.h" #ifdef _MSC_VER #pragma warning(pop) #else @@ -60,7 +60,6 @@ #include "PPUTranslator.h" #endif -#include #include #include #include @@ -5064,6 +5063,7 @@ static void ppu_initialize2(jit_compiler& jit, const ppu_module& module_part, co translator.build_interpreter(); } +#if LLVM_VERSION_MAJOR < 17 legacy::FunctionPassManager pm(_module.get()); // Basic optimizations @@ -5085,6 +5085,32 @@ static void ppu_initialize2(jit_compiler& jit, const ppu_module& module_part, co //pm.add(createAggressiveDCEPass()); //pm.add(createCFGSimplificationPass()); //pm.add(createLintPass()); // Check +#else + // Create the analysis managers. + // These must be declared in this order so that they are destroyed in the + // correct order due to inter-analysis-manager references. + LoopAnalysisManager lam; + FunctionAnalysisManager fam; + CGSCCAnalysisManager cgam; + ModuleAnalysisManager mam; + + // Create the new pass manager builder. + // Take a look at the PassBuilder constructor parameters for more + // customization, e.g. specifying a TargetMachine or various debugging + // options. + PassBuilder pb; + + // Register all the basic analyses with the managers. + pb.registerModuleAnalyses(mam); + pb.registerCGSCCAnalyses(cgam); + pb.registerFunctionAnalyses(fam); + pb.registerLoopAnalyses(lam); + pb.crossRegisterProxies(lam, fam, cgam, mam); + + FunctionPassManager fpm; + // Basic optimizations + fpm.addPass(EarlyCSEPass()); +#endif // Translate functions for (usz fi = 0, fmax = module_part.funcs.size(); fi < fmax; fi++) @@ -5101,7 +5127,11 @@ static void ppu_initialize2(jit_compiler& jit, const ppu_module& module_part, co if (const auto func = translator.Translate(module_part.funcs[fi])) { // Run optimization passes +#if LLVM_VERSION_MAJOR < 17 pm.run(*func); +#else + fpm.run(*func, fam); +#endif } else { @@ -5117,7 +5147,11 @@ static void ppu_initialize2(jit_compiler& jit, const ppu_module& module_part, co if (const auto func = translator.GetSymbolResolver(whole_module)) { // Run optimization passes +#if LLVM_VERSION_MAJOR < 17 pm.run(*func); +#else + fpm.run(*func, fam); +#endif } else { diff --git a/rpcs3/Emu/Cell/SPULLVMRecompiler.cpp b/rpcs3/Emu/Cell/SPULLVMRecompiler.cpp index 395aebf2cc..b442056caf 100644 --- a/rpcs3/Emu/Cell/SPULLVMRecompiler.cpp +++ b/rpcs3/Emu/Cell/SPULLVMRecompiler.cpp @@ -11,6 +11,8 @@ #include "SPUThread.h" #include "SPUAnalyser.h" #include "SPUInterpreter.h" +#include "SPUDisAsm.h" +#include #include #include @@ -30,26 +32,32 @@ const extern spu_decoder g_spu_iflag; #pragma warning(push, 0) #else #pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wall" -#pragma GCC diagnostic ignored "-Wextra" #pragma GCC diagnostic ignored "-Wold-style-cast" #pragma GCC diagnostic ignored "-Wunused-parameter" -#pragma GCC diagnostic ignored "-Wstrict-aliasing" -#pragma GCC diagnostic ignored "-Weffc++" #pragma GCC diagnostic ignored "-Wmissing-noreturn" #endif +#include +#include +#include +#include +#include +#include #if LLVM_VERSION_MAJOR < 17 -#include "llvm/ADT/Triple.h" +#include +#include +#include +#else +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif -#include "llvm/TargetParser/Host.h" -#include "llvm/IR/LegacyPassManager.h" -#include "llvm/IR/Verifier.h" -#include "llvm/IR/InlineAsm.h" -#include "llvm/Transforms/Utils/BasicBlockUtils.h" -#include "llvm/Transforms/Scalar.h" -#include "llvm/Analysis/PostDominators.h" -#include "llvm/Analysis/AliasAnalysis.h" -#include "llvm/ADT/PostOrderIterator.h" #ifdef _MSC_VER #pragma warning(pop) #else @@ -2017,6 +2025,7 @@ public: m_function_table->eraseFromParent(); } +#if LLVM_VERSION_MAJOR < 17 // Initialize pass manager legacy::FunctionPassManager pm(_module.get()); @@ -2024,16 +2033,42 @@ 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 +#else + + // Create the analysis managers. + // These must be declared in this order so that they are destroyed in the + // correct order due to inter-analysis-manager references. + LoopAnalysisManager lam; + FunctionAnalysisManager fam; + CGSCCAnalysisManager cgam; + ModuleAnalysisManager mam; + + // Create the new pass manager builder. + // Take a look at the PassBuilder constructor parameters for more + // customization, e.g. specifying a TargetMachine or various debugging + // options. + PassBuilder pb; + + // Register all the basic analyses with the managers. + pb.registerModuleAnalyses(mam); + pb.registerCGSCCAnalyses(cgam); + pb.registerFunctionAnalyses(fam); + pb.registerLoopAnalyses(lam); + pb.crossRegisterProxies(lam, fam, cgam, mam); + + FunctionPassManager fpm; + // Basic optimizations + fpm.addPass(EarlyCSEPass(true)); + fpm.addPass(SimplifyCFGPass()); + fpm.addPass(DSEPass()); + fpm.addPass(createFunctionToLoopPassAdaptor(LICMPass(LICMOptions()), true)); + fpm.addPass(ADCEPass()); +#endif for (auto& f : *m_module) { @@ -2043,7 +2078,11 @@ public: for (const auto& func : m_functions) { const auto f = func.second.fn ? func.second.fn : func.second.chunk; +#if LLVM_VERSION_MAJOR < 17 pm.run(*f); +#else + fpm.run(*f, fam); +#endif } // Clear context (TODO) @@ -2507,24 +2546,9 @@ public: m_function_table->setInitializer(ConstantArray::get(ArrayType::get(if_type->getPointerTo(), 1ull << m_interp_magn), iptrs)); m_function_table = nullptr; - // Initialize pass manager - legacy::FunctionPassManager pm(_module.get()); - - // 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) { replace_intrinsics(f); - //pm.run(f); } std::string log;