This commit is contained in:
Danila Malyutin 2015-07-23 20:28:03 +03:00 committed by Nekotekina
parent 6832910187
commit 6849192b39
4 changed files with 5982 additions and 5984 deletions

View File

@ -62,7 +62,6 @@ Compiler::~Compiler() {
delete m_llvm_context; delete m_llvm_context;
} }
class CustomSectionMemoryManager : public llvm::SectionMemoryManager { class CustomSectionMemoryManager : public llvm::SectionMemoryManager {
private: private:
std::unordered_map<std::string, Executable> &executableMap; std::unordered_map<std::string, Executable> &executableMap;
@ -232,7 +231,8 @@ std::pair<Executable, llvm::ExecutionEngine *> Compiler::Compile(const std::stri
m_ir_builder->SetInsertPoint(merge_bb); m_ir_builder->SetInsertPoint(merge_bb);
m_ir_builder->CreateRet(m_ir_builder->getInt32(0)); m_ir_builder->CreateRet(m_ir_builder->getInt32(0));
} else { }
else {
m_ir_builder->CreateRet(exit_instr_i32); m_ir_builder->CreateRet(exit_instr_i32);
} }
} }
@ -258,7 +258,8 @@ std::pair<Executable, llvm::ExecutionEngine *> Compiler::Compile(const std::stri
m_ir_builder->SetInsertPoint(merge_bb); m_ir_builder->SetInsertPoint(merge_bb);
m_ir_builder->CreateRet(m_ir_builder->getInt32(0)); m_ir_builder->CreateRet(m_ir_builder->getInt32(0));
} else { }
else {
m_ir_builder->CreateRet(exit_instr_i32); m_ir_builder->CreateRet(exit_instr_i32);
} }
} }
@ -272,7 +273,6 @@ std::pair<Executable, llvm::ExecutionEngine *> Compiler::Compile(const std::stri
} }
} }
m_recompilation_engine.Log() << *m_module; m_recompilation_engine.Log() << *m_module;
std::string verify; std::string verify;
@ -281,7 +281,6 @@ std::pair<Executable, llvm::ExecutionEngine *> Compiler::Compile(const std::stri
m_recompilation_engine.Log() << "Verification failed: " << verify << "\n"; m_recompilation_engine.Log() << "Verification failed: " << verify << "\n";
} }
auto ir_build_end = std::chrono::high_resolution_clock::now(); auto ir_build_end = std::chrono::high_resolution_clock::now();
m_stats.ir_build_time += std::chrono::duration_cast<std::chrono::nanoseconds>(ir_build_end - compilation_start); m_stats.ir_build_time += std::chrono::duration_cast<std::chrono::nanoseconds>(ir_build_end - compilation_start);
@ -426,7 +425,8 @@ void RecompilationEngine::Task() {
if (!work_done_this_iteration) { if (!work_done_this_iteration) {
// TODO: Reduce the priority of the recompilation engine thread if its set to high priority // TODO: Reduce the priority of the recompilation engine thread if its set to high priority
} else { }
else {
is_idling = false; is_idling = false;
} }
@ -520,7 +520,8 @@ void RecompilationEngine::ProcessExecutionTrace(const ExecutionTrace & execution
const ExecutionTraceEntry * next_trace = nullptr; const ExecutionTraceEntry * next_trace = nullptr;
if (trace_i + 1 != execution_trace.entries.end()) { if (trace_i + 1 != execution_trace.entries.end()) {
next_trace = &(*(trace_i + 1)); next_trace = &(*(trace_i + 1));
} else if (!split_trace && execution_trace.type == ExecutionTrace::Type::Loop) { }
else if (!split_trace && execution_trace.type == ExecutionTrace::Type::Loop) {
next_trace = &(*(execution_trace.entries.begin())); next_trace = &(*(execution_trace.entries.begin()));
} }
@ -556,15 +557,18 @@ void RecompilationEngine::UpdateControlFlowGraph(ControlFlowGraph & cfg, const E
if (next_entry->GetPrimaryAddress() != (this_entry.GetPrimaryAddress() + 4)) { if (next_entry->GetPrimaryAddress() != (this_entry.GetPrimaryAddress() + 4)) {
cfg.branches[this_entry.GetPrimaryAddress()].insert(next_entry->GetPrimaryAddress()); cfg.branches[this_entry.GetPrimaryAddress()].insert(next_entry->GetPrimaryAddress());
} }
} else if (next_entry->type == ExecutionTraceEntry::Type::FunctionCall) { }
else if (next_entry->type == ExecutionTraceEntry::Type::FunctionCall) {
cfg.calls[this_entry.data.instruction.address].insert(next_entry->GetPrimaryAddress()); cfg.calls[this_entry.data.instruction.address].insert(next_entry->GetPrimaryAddress());
} }
} }
} else if (this_entry.type == ExecutionTraceEntry::Type::CompiledBlock) { }
else if (this_entry.type == ExecutionTraceEntry::Type::CompiledBlock) {
if (next_entry) { if (next_entry) {
if (next_entry->type == ExecutionTraceEntry::Type::Instruction || next_entry->type == ExecutionTraceEntry::Type::CompiledBlock) { if (next_entry->type == ExecutionTraceEntry::Type::Instruction || next_entry->type == ExecutionTraceEntry::Type::CompiledBlock) {
cfg.branches[this_entry.data.compiled_block.exit_address].insert(next_entry->GetPrimaryAddress()); cfg.branches[this_entry.data.compiled_block.exit_address].insert(next_entry->GetPrimaryAddress());
} else if (next_entry->type == ExecutionTraceEntry::Type::FunctionCall) { }
else if (next_entry->type == ExecutionTraceEntry::Type::FunctionCall) {
cfg.calls[this_entry.data.compiled_block.exit_address].insert(next_entry->GetPrimaryAddress()); cfg.calls[this_entry.data.compiled_block.exit_address].insert(next_entry->GetPrimaryAddress());
} }
} }
@ -594,8 +598,6 @@ void RecompilationEngine::CompileBlock(BlockEntry & block_entry) {
std::get<0>(m_address_to_function[block_entry.cfg.start_address]) = compileResult.first; std::get<0>(m_address_to_function[block_entry.cfg.start_address]) = compileResult.first;
block_entry.last_compiled_cfg_size = block_entry.cfg.GetSize(); block_entry.last_compiled_cfg_size = block_entry.cfg.GetSize();
block_entry.is_compiled = true; block_entry.is_compiled = true;
} }
std::shared_ptr<RecompilationEngine> RecompilationEngine::GetInstance() { std::shared_ptr<RecompilationEngine> RecompilationEngine::GetInstance() {
@ -698,11 +700,9 @@ ppu_recompiler_llvm::CPUHybridDecoderRecompiler::CPUHybridDecoderRecompiler(PPUT
} }
ppu_recompiler_llvm::CPUHybridDecoderRecompiler::~CPUHybridDecoderRecompiler() { ppu_recompiler_llvm::CPUHybridDecoderRecompiler::~CPUHybridDecoderRecompiler() {
} }
u32 ppu_recompiler_llvm::CPUHybridDecoderRecompiler::DecodeMemory(const u32 address) { u32 ppu_recompiler_llvm::CPUHybridDecoderRecompiler::DecodeMemory(const u32 address) {
ExecuteFunction(&m_ppu, 0); ExecuteFunction(&m_ppu, 0);
return 0; return 0;
} }
@ -751,7 +751,8 @@ u32 ppu_recompiler_llvm::CPUHybridDecoderRecompiler::ExecuteTillReturn(PPUThread
execution_engine->m_tracer.Trace(Tracer::TraceType::ExitFromCompiledBlock, entry, exit); execution_engine->m_tracer.Trace(Tracer::TraceType::ExitFromCompiledBlock, entry, exit);
if (exit == 0) if (exit == 0)
return 0; return 0;
} else { }
else {
execution_engine->m_tracer.Trace(Tracer::TraceType::Instruction, ppu_state->PC, 0); execution_engine->m_tracer.Trace(Tracer::TraceType::Instruction, ppu_state->PC, 0);
u32 instruction = vm::ps3::read32(ppu_state->PC); u32 instruction = vm::ps3::read32(ppu_state->PC);
u32 oldPC = ppu_state->PC; u32 oldPC = ppu_state->PC;

View File

@ -3232,7 +3232,6 @@ void Compiler::MTSPR(u32 spr, u32 rs) {
assert(0); assert(0);
break; break;
} }
} }
void Compiler::NAND(u32 ra, u32 rs, u32 rb, u32 rc) { void Compiler::NAND(u32 ra, u32 rs, u32 rb, u32 rc) {

View File

@ -12,7 +12,7 @@
#include <sstream> #include <sstream>
#define PPU_LLVM_RECOMPILER_UNIT_TESTS 1 // Uncomment to enable tests //#define PPU_LLVM_RECOMPILER_UNIT_TESTS 1 // Uncomment to enable tests
//#define PPU_LLVM_RECOMPILER_UNIT_TESTS_VERBOSE 1 // Uncomment to print everything (even for passed tests) //#define PPU_LLVM_RECOMPILER_UNIT_TESTS_VERBOSE 1 // Uncomment to print everything (even for passed tests)
using namespace llvm; using namespace llvm;
@ -244,7 +244,6 @@ static std::string StateDiff(PPUState const & recomp, PPUState const & interp) {
} }
#endif // PPU_LLVM_RECOMPILER_UNIT_TESTS #endif // PPU_LLVM_RECOMPILER_UNIT_TESTS
#ifdef PPU_LLVM_RECOMPILER_UNIT_TESTS #ifdef PPU_LLVM_RECOMPILER_UNIT_TESTS
static PPUThread * s_ppu_state = nullptr; static PPUThread * s_ppu_state = nullptr;
static PPUInterpreter * s_interpreter = nullptr; static PPUInterpreter * s_interpreter = nullptr;
@ -326,8 +325,6 @@ void Compiler::RunTest(const char * name, std::function<void()> test_case, std::
return; return;
} }
// Optimize // Optimize
fpm->run(*m_state.function); fpm->run(*m_state.function);
@ -373,7 +370,8 @@ void Compiler::RunTest(const char * name, std::function<void()> test_case, std::
#else #else
m_recompilation_engine.Log() << "Test " << name << " passed\n"; m_recompilation_engine.Log() << "Test " << name << " passed\n";
#endif // PPU_LLVM_RECOMPILER_UNIT_TESTS_VERBOSE #endif // PPU_LLVM_RECOMPILER_UNIT_TESTS_VERBOSE
} else { }
else {
m_recompilation_engine.Log() << logmsg.str() << "Test " << name << " failed\n" << msg << "\n"; m_recompilation_engine.Log() << logmsg.str() << "Test " << name << " failed\n" << msg << "\n";
} }