PPU LLVM: fix phenoms

This commit is contained in:
Nekotekina 2018-07-22 19:06:28 +03:00
commit a424fcfcf7
2 changed files with 6 additions and 10 deletions

View file

@ -143,7 +143,7 @@ Function* PPUTranslator::Translate(const ppu_function& info)
std::fill(std::begin(m_globals), std::end(m_globals), nullptr); std::fill(std::begin(m_globals), std::end(m_globals), nullptr);
std::fill(std::begin(m_locals), std::end(m_locals), nullptr); std::fill(std::begin(m_locals), std::end(m_locals), nullptr);
IRBuilder<> irb(m_entry = BasicBlock::Create(m_context, "__entry", m_function)); IRBuilder<> irb(BasicBlock::Create(m_context, "__entry", m_function));
m_ir = &irb; m_ir = &irb;
// Instruction address is (m_addr + base) // Instruction address is (m_addr + base)
@ -153,18 +153,18 @@ Function* PPUTranslator::Translate(const ppu_function& info)
m_thread = &*m_function->arg_begin(); m_thread = &*m_function->arg_begin();
m_base_loaded = m_ir->CreateLoad(m_base); m_base_loaded = m_ir->CreateLoad(m_base);
m_body = BasicBlock::Create(m_context, "__body", m_function); const auto body = BasicBlock::Create(m_context, "__body", m_function);
// Check status register in the entry block // Check status register in the entry block
const auto vstate = m_ir->CreateLoad(m_ir->CreateStructGEP(nullptr, m_thread, 1), true); const auto vstate = m_ir->CreateLoad(m_ir->CreateStructGEP(nullptr, m_thread, 1), true);
const auto vcheck = BasicBlock::Create(m_context, "__test", m_function); const auto vcheck = BasicBlock::Create(m_context, "__test", m_function);
m_ir->CreateCondBr(m_ir->CreateIsNull(vstate), m_body, vcheck, m_md_likely); m_ir->CreateCondBr(m_ir->CreateIsNull(vstate), body, vcheck, m_md_likely);
// Create tail call to the check function // Create tail call to the check function
m_ir->SetInsertPoint(vcheck); m_ir->SetInsertPoint(vcheck);
Call(GetType<void>(), "__check", m_thread, GetAddr())->setTailCallKind(llvm::CallInst::TCK_Tail); Call(GetType<void>(), "__check", m_thread, GetAddr())->setTailCallKind(llvm::CallInst::TCK_Tail);
m_ir->CreateRetVoid(); m_ir->CreateRetVoid();
m_ir->SetInsertPoint(m_body); m_ir->SetInsertPoint(body);
// Process blocks // Process blocks
const auto block = std::make_pair(info.addr, info.size); const auto block = std::make_pair(info.addr, info.size);
@ -178,7 +178,7 @@ Function* PPUTranslator::Translate(const ppu_function& info)
// Process the instructions // Process the instructions
for (m_addr = block.first - base; m_addr < block.first + block.second - base; m_addr += 4) for (m_addr = block.first - base; m_addr < block.first + block.second - base; m_addr += 4)
{ {
if (m_body->getTerminator()) if (m_ir->GetInsertBlock()->getTerminator())
{ {
break; break;
} }
@ -207,7 +207,7 @@ Function* PPUTranslator::Translate(const ppu_function& info)
} }
// Finalize current block if necessary (create branch to the next address) // Finalize current block if necessary (create branch to the next address)
if (!m_body->getTerminator()) if (!m_ir->GetInsertBlock()->getTerminator())
{ {
FlushRegisters(); FlushRegisters();
CallFunction(m_addr); CallFunction(m_addr);

View file

@ -47,10 +47,6 @@ class PPUTranslator final : public cpu_translator
// Callable functions // Callable functions
llvm::GlobalVariable* m_call; llvm::GlobalVariable* m_call;
// Main block
llvm::BasicBlock* m_body;
llvm::BasicBlock* m_entry;
// Thread context struct // Thread context struct
llvm::StructType* m_thread_type; llvm::StructType* m_thread_type;