Direct UT output to PPULLVMRecompiler.log

This commit is contained in:
S Gopal Rajagopal 2014-11-21 00:04:59 +05:30
parent 6661018691
commit 5addbcbbb0
2 changed files with 22 additions and 16 deletions

View file

@ -82,8 +82,6 @@ Compiler::Compiler(RecompilationEngine & recompilation_engine, const Executable
InitRotateMask(); InitRotateMask();
s_rotate_mask_inited = true; s_rotate_mask_inited = true;
} }
RunAllTests();
} }
Compiler::~Compiler() { Compiler::~Compiler() {
@ -4884,9 +4882,7 @@ RecompilationEngine::RecompilationEngine()
: ThreadBase("PPU Recompilation Engine") : ThreadBase("PPU Recompilation Engine")
, m_next_ordinal(0) , m_next_ordinal(0)
, m_compiler(*this, ExecutionEngine::ExecuteFunction, ExecutionEngine::ExecuteTillReturn) { , m_compiler(*this, ExecutionEngine::ExecuteFunction, ExecutionEngine::ExecuteTillReturn) {
std::string error; m_compiler.RunAllTests();
m_log = new raw_fd_ostream("PPULLVMRecompiler.log", error, sys::fs::F_Text);
m_log->SetUnbuffered();
} }
RecompilationEngine::~RecompilationEngine() { RecompilationEngine::~RecompilationEngine() {
@ -4943,6 +4939,12 @@ void RecompilationEngine::NotifyTrace(ExecutionTrace * execution_trace) {
} }
raw_fd_ostream & RecompilationEngine::Log() { raw_fd_ostream & RecompilationEngine::Log() {
if (!m_log) {
std::string error;
m_log = new raw_fd_ostream("PPULLVMRecompiler.log", error, sys::fs::F_Text);
m_log->SetUnbuffered();
}
return *m_log; return *m_log;
} }

View file

@ -235,6 +235,8 @@ void Compiler::VerifyInstructionAgainstInterpreter(const char * name, CompilerFn
void Compiler::RunTest(const char * name, std::function<void()> test_case, std::function<void()> input, std::function<bool(std::string & msg)> check_result) { void Compiler::RunTest(const char * name, std::function<void()> test_case, std::function<void()> input, std::function<bool(std::string & msg)> check_result) {
#ifdef PPU_LLVM_RECOMPILER_UNIT_TESTS #ifdef PPU_LLVM_RECOMPILER_UNIT_TESTS
m_recompilation_engine.Log() << "Running test " << name << '\n';
// Create the function // Create the function
m_state.function = (Function *)m_module->getOrInsertFunction(name, m_compiled_function_type); m_state.function = (Function *)m_module->getOrInsertFunction(name, m_compiled_function_type);
m_state.function->setCallingConv(CallingConv::X86_64_Win64); m_state.function->setCallingConv(CallingConv::X86_64_Win64);
@ -258,12 +260,12 @@ void Compiler::RunTest(const char * name, std::function<void()> test_case, std::
std::string ir; std::string ir;
raw_string_ostream ir_ostream(ir); raw_string_ostream ir_ostream(ir);
m_state.function->print(ir_ostream); m_state.function->print(ir_ostream);
LOG_NOTICE(PPU, "[UT %s] LLVM IR:%s", name, ir.c_str()); m_recompilation_engine.Log() << "LLVM IR:" << ir;
std::string verify; std::string verify_results;
raw_string_ostream verify_ostream(verify); raw_string_ostream verify_results_ostream(verify_results);
if (verifyFunction(*m_state.function, &verify_ostream)) { if (verifyFunction(*m_state.function, &verify_results_ostream)) {
LOG_ERROR(PPU, "[UT %s] Verification Failed:%s", name, verify.c_str()); m_recompilation_engine.Log() << "Verification Failed:" << verify_results;
return; return;
} }
@ -273,7 +275,7 @@ void Compiler::RunTest(const char * name, std::function<void()> test_case, std::
// Print the optimized IR // Print the optimized IR
ir = ""; ir = "";
m_state.function->print(ir_ostream); m_state.function->print(ir_ostream);
LOG_NOTICE(PPU, "[UT %s] Optimized LLVM IR:%s", name, ir.c_str()); m_recompilation_engine.Log() << "Optimized LLVM IR:" << ir;
// Generate the function // Generate the function
MachineCodeInfo mci; MachineCodeInfo mci;
@ -282,12 +284,12 @@ void Compiler::RunTest(const char * name, std::function<void()> test_case, std::
// Disassemble the generated function // Disassemble the generated function
auto disassembler = LLVMCreateDisasm(sys::getProcessTriple().c_str(), nullptr, 0, nullptr, nullptr); auto disassembler = LLVMCreateDisasm(sys::getProcessTriple().c_str(), nullptr, 0, nullptr, nullptr);
LOG_NOTICE(PPU, "[UT %s] Disassembly:", name); m_recompilation_engine.Log() << "Disassembly:\n";
for (uint64_t pc = 0; pc < mci.size();) { for (uint64_t pc = 0; pc < mci.size();) {
char str[1024]; char str[1024];
auto size = LLVMDisasmInstruction(disassembler, (uint8_t *)mci.address() + pc, mci.size() - pc, (uint64_t)((uint8_t *)mci.address() + pc), str, sizeof(str)); auto size = LLVMDisasmInstruction(disassembler, (uint8_t *)mci.address() + pc, mci.size() - pc, (uint64_t)((uint8_t *)mci.address() + pc), str, sizeof(str));
LOG_NOTICE(PPU, "[UT %s] %p: %s.", name, (uint8_t *)mci.address() + pc, str); m_recompilation_engine.Log() << ((uint8_t *)mci.address() + pc) << ':' << str << '\n';
pc += size; pc += size;
} }
@ -302,9 +304,9 @@ void Compiler::RunTest(const char * name, std::function<void()> test_case, std::
std::string msg; std::string msg;
bool pass = check_result(msg); bool pass = check_result(msg);
if (pass) { if (pass) {
LOG_NOTICE(PPU, "[UT %s] Test passed. %s", name, msg.c_str()); m_recompilation_engine.Log() << "Test " << name << " passed\n" << msg << "\n";
} else { } else {
LOG_ERROR(PPU, "[UT %s] Test failed. %s", name, msg.c_str()); m_recompilation_engine.Log() << "Test " << name << " failed\n" << msg << "\n";
} }
m_execution_engine->freeMachineCodeForFunction(m_state.function); m_execution_engine->freeMachineCodeForFunction(m_state.function);
@ -319,7 +321,7 @@ void Compiler::RunAllTests() {
s_ppu_state = &ppu_state; s_ppu_state = &ppu_state;
s_interpreter = &interpreter; s_interpreter = &interpreter;
LOG_NOTICE(PPU, "Running Unit Tests"); m_recompilation_engine.Log() << "Starting Unit Tests\n";
VERIFY_INSTRUCTION_AGAINST_INTERPRETER_USING_RANDOM_INPUT(MFVSCR, 0, 5, 1); VERIFY_INSTRUCTION_AGAINST_INTERPRETER_USING_RANDOM_INPUT(MFVSCR, 0, 5, 1);
VERIFY_INSTRUCTION_AGAINST_INTERPRETER_USING_RANDOM_INPUT(MTVSCR, 0, 5, 1); VERIFY_INSTRUCTION_AGAINST_INTERPRETER_USING_RANDOM_INPUT(MTVSCR, 0, 5, 1);
@ -767,5 +769,7 @@ void Compiler::RunAllTests() {
VERIFY_INSTRUCTION_AGAINST_INTERPRETER(STSWI, 3, input, 5, 23, 25); VERIFY_INSTRUCTION_AGAINST_INTERPRETER(STSWI, 3, input, 5, 23, 25);
VERIFY_INSTRUCTION_AGAINST_INTERPRETER(DCBZ, 0, input, 0, 23); VERIFY_INSTRUCTION_AGAINST_INTERPRETER(DCBZ, 0, input, 0, 23);
VERIFY_INSTRUCTION_AGAINST_INTERPRETER(DCBZ, 1, input, 14, 23); VERIFY_INSTRUCTION_AGAINST_INTERPRETER(DCBZ, 1, input, 14, 23);
m_recompilation_engine.Log() << "Finished Unit Tests\n";
#endif // PPU_LLVM_RECOMPILER_UNIT_TESTS #endif // PPU_LLVM_RECOMPILER_UNIT_TESTS
} }