From aa34fa8baa92581dc676c87fa29cdce0c5b9b077 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Wed, 28 Jun 2017 14:56:35 +0300 Subject: [PATCH] PPU LLVM: some passes disabled --- rpcs3/Emu/Cell/PPUThread.cpp | 18 +++++++++--------- rpcs3/Emu/Cell/PPUTranslator.cpp | 17 ++++++++++------- rpcs3/Emu/Cell/PPUTranslator.h | 4 ++-- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index 116dd83211..7ce3e7dfee 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -1185,20 +1185,20 @@ static void ppu_initialize2(jit_compiler& jit, const ppu_module& module_part, co //pm.add(createCFGSimplificationPass()); //pm.add(createPromoteMemoryToRegisterPass()); pm.add(createEarlyCSEPass()); - pm.add(createTailCallEliminationPass()); + //pm.add(createTailCallEliminationPass()); //pm.add(createInstructionCombiningPass()); //pm.add(createBasicAAWrapperPass()); //pm.add(new MemoryDependenceAnalysis()); - pm.add(createLICMPass()); - pm.add(createLoopInstSimplifyPass()); + //pm.add(createLICMPass()); + //pm.add(createLoopInstSimplifyPass()); //pm.add(createNewGVNPass()); pm.add(createDeadStoreEliminationPass()); - pm.add(createSCCPPass()); - pm.add(createReassociatePass()); - pm.add(createInstructionCombiningPass()); - pm.add(createInstructionSimplifierPass()); - pm.add(createAggressiveDCEPass()); - pm.add(createCFGSimplificationPass()); + //pm.add(createSCCPPass()); + //pm.add(createReassociatePass()); + //pm.add(createInstructionCombiningPass()); + //pm.add(createInstructionSimplifierPass()); + //pm.add(createAggressiveDCEPass()); + //pm.add(createCFGSimplificationPass()); //pm.add(createLintPass()); // Check // Initialize message dialog diff --git a/rpcs3/Emu/Cell/PPUTranslator.cpp b/rpcs3/Emu/Cell/PPUTranslator.cpp index c646370333..42b1f39b7d 100644 --- a/rpcs3/Emu/Cell/PPUTranslator.cpp +++ b/rpcs3/Emu/Cell/PPUTranslator.cpp @@ -85,7 +85,7 @@ Function* PPUTranslator::Translate(const ppu_function& info) // Create tail call to the check function m_ir->SetInsertPoint(vcheck); - Call(GetType(), "__check", m_thread, m_ir->getInt64(m_start_addr)); + Call(GetType(), "__check", m_thread, m_ir->getInt64(m_start_addr))->setTailCallKind(llvm::CallInst::TCK_Tail); m_ir->CreateRetVoid(); m_ir->SetInsertPoint(m_body); @@ -143,6 +143,8 @@ Value* PPUTranslator::RotateLeft(Value* arg, Value* n) void PPUTranslator::CallFunction(u64 target, Value* indirect) { + const auto type = FunctionType::get(GetType(), {m_thread_type->getPointerTo()}, false); + if (!indirect) { if (target < 0x10000 || target >= -0x10000) @@ -151,16 +153,17 @@ void PPUTranslator::CallFunction(u64 target, Value* indirect) return; } - m_ir->CreateCall(m_module->getOrInsertFunction(fmt::format("__0x%llx", target), FunctionType::get(GetType(), {m_thread_type->getPointerTo()}, false)), {m_thread}); + indirect = m_module->getOrInsertFunction(fmt::format("__0x%llx", target), type); } else { const auto addr = indirect ? indirect : (Value*)m_ir->getInt64(target); const auto pos = m_ir->CreateLShr(addr, 2, "", true); const auto ptr = m_ir->CreateGEP(m_ir->CreateLoad(m_call), {m_ir->getInt64(0), pos}); - m_ir->CreateCall(m_ir->CreateIntToPtr(m_ir->CreateLoad(ptr), FunctionType::get(GetType(), {m_thread_type->getPointerTo()}, false)->getPointerTo()), {m_thread}); + indirect = m_ir->CreateIntToPtr(m_ir->CreateLoad(ptr), type->getPointerTo()); } + m_ir->CreateCall(indirect, {m_thread})->setTailCallKind(llvm::CallInst::TCK_Tail); m_ir->CreateRetVoid(); } @@ -1591,13 +1594,13 @@ void PPUTranslator::SC(ppu_opcode_t op) if (index < 1024) { // Call the syscall directly - Call(GetType(), fmt::format("%s", ppu_syscall_code(index)), m_thread); + Call(GetType(), fmt::format("%s", ppu_syscall_code(index)), m_thread)->setTailCallKind(llvm::CallInst::TCK_Tail); m_ir->CreateRetVoid(); return; } } - Call(GetType(), op.lev ? "__lv1call" : "__syscall", m_thread, num); + Call(GetType(), op.lev ? "__lv1call" : "__syscall", m_thread, num)->setTailCallKind(llvm::CallInst::TCK_Tail); m_ir->CreateRetVoid(); } @@ -3797,7 +3800,7 @@ void PPUTranslator::FCFID(ppu_opcode_t op) void PPUTranslator::UNK(ppu_opcode_t op) { FlushRegisters(); - Call(GetType(), "__error", m_thread, m_ir->getInt64(m_current_addr), m_ir->getInt32(op.opcode)); + Call(GetType(), "__error", m_thread, m_ir->getInt64(m_current_addr), m_ir->getInt32(op.opcode))->setTailCallKind(llvm::CallInst::TCK_Tail); m_ir->CreateRetVoid(); } @@ -4060,7 +4063,7 @@ Value* PPUTranslator::CheckTrapCondition(u32 to, Value* left, Value* right) void PPUTranslator::Trap(u64 addr) { - Call(GetType(), "__trap", m_thread, m_ir->getInt64(m_current_addr)); + Call(GetType(), "__trap", m_thread, m_ir->getInt64(m_current_addr))->setTailCallKind(llvm::CallInst::TCK_Tail); m_ir->CreateRetVoid(); } diff --git a/rpcs3/Emu/Cell/PPUTranslator.h b/rpcs3/Emu/Cell/PPUTranslator.h index 2a8e365263..47867cf994 100644 --- a/rpcs3/Emu/Cell/PPUTranslator.h +++ b/rpcs3/Emu/Cell/PPUTranslator.h @@ -386,7 +386,7 @@ public: // Call a function with attribute list template - llvm::Value* Call(llvm::Type* ret, llvm::AttributeSet attr, llvm::StringRef name, Args... args) + llvm::CallInst* Call(llvm::Type* ret, llvm::AttributeSet attr, llvm::StringRef name, Args... args) { // Call the function return m_ir->CreateCall(m_module->getOrInsertFunction(name, llvm::FunctionType::get(ret, {args->getType()...}, false), attr), {args...}); @@ -394,7 +394,7 @@ public: // Call a function template - llvm::Value* Call(llvm::Type* ret, llvm::StringRef name, Args... args) + llvm::CallInst* Call(llvm::Type* ret, llvm::StringRef name, Args... args) { return Call(ret, llvm::AttributeSet{}, name, args...); }