From 14e6577700f3cc02cb01f12694ac48135961421f Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Fri, 3 Aug 2018 15:34:51 +0300 Subject: [PATCH] SPU LLVM: improve debugging RPCS3 Build cache in reverse order Catch exceptions in instruction loop: print IR --- rpcs3/Emu/Cell/SPURecompiler.cpp | 30 +++++++++++++++++++++--------- rpcs3/Emu/Cell/SPURecompiler.h | 3 ++- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/rpcs3/Emu/Cell/SPURecompiler.cpp b/rpcs3/Emu/Cell/SPURecompiler.cpp index 6344e53d7d..ae57b3b907 100644 --- a/rpcs3/Emu/Cell/SPURecompiler.cpp +++ b/rpcs3/Emu/Cell/SPURecompiler.cpp @@ -33,9 +33,9 @@ spu_cache::~spu_cache() { } -std::vector> spu_cache::get() +std::deque> spu_cache::get() { - std::vector> result; + std::deque> result; if (!m_file) { @@ -64,7 +64,7 @@ std::vector> spu_cache::get() break; } - result.emplace_back(std::move(func)); + result.emplace_front(std::move(func)); } return result; @@ -2161,6 +2161,11 @@ public: fs::file(m_spurt->m_cache_path + "spu.log", fs::write + fs::append).write(log); } + if (m_cache && g_cfg.core.spu_cache) + { + m_cache->add(func); + } + using namespace llvm; // Create LLVM module @@ -2447,7 +2452,19 @@ public: } // Execute recompiler function (TODO) - (this->*g_decoder.decode(op))({op}); + try + { + (this->*g_decoder.decode(op))({op}); + } + catch (const std::exception& e) + { + std::string dump; + raw_string_ostream out(dump); + out << *module; // print IR + out.flush(); + LOG_ERROR(SPU, "[0x%x] LLVM dump:\n%s", m_pos, dump); + throw; + } } // Finalize block with fallthrough if necessary @@ -2780,11 +2797,6 @@ public: fs::file(m_spurt->m_cache_path + "spu.log", fs::write + fs::append).write(log); } - if (m_cache && g_cfg.core.spu_cache) - { - m_cache->add(func); - } - return fn; } diff --git a/rpcs3/Emu/Cell/SPURecompiler.h b/rpcs3/Emu/Cell/SPURecompiler.h index 9a38df7a69..bcce0aebd8 100644 --- a/rpcs3/Emu/Cell/SPURecompiler.h +++ b/rpcs3/Emu/Cell/SPURecompiler.h @@ -6,6 +6,7 @@ #include #include #include +#include // Helper class class spu_cache @@ -22,7 +23,7 @@ public: return m_file.operator bool(); } - std::vector> get(); + std::deque> get(); void add(const std::vector& func);