Splitting logging core into poly.

This commit is contained in:
Ben Vanik
2014-08-21 20:26:55 -07:00
parent 08b0226a16
commit e1b0388faf
19 changed files with 194 additions and 144 deletions

View File

@@ -194,7 +194,7 @@ void X64CodeChunk::AddTableEntry(uint8_t* code, size_t code_size,
if (fn_table_count + 1 > fn_table_capacity) {
// Table exhausted, need to realloc. If this happens a lot we should tune
// the table size to prevent this.
XELOGW("X64CodeCache growing FunctionTable - adjust ESTIMATED_FN_SIZE");
PLOGW("X64CodeCache growing FunctionTable - adjust ESTIMATED_FN_SIZE");
RtlDeleteGrowableFunctionTable(fn_table_handle);
size_t old_size = fn_table_capacity * sizeof(RUNTIME_FUNCTION);
size_t new_size = old_size * 2;

View File

@@ -193,7 +193,7 @@ int X64Emitter::Emit(HIRBuilder* builder, size_t& out_stack_size) {
if (!SelectSequence(*this, instr, &new_tail)) {
// No sequence found!
assert_always();
XELOGE("Unable to process HIR opcode %s", instr->opcode->name);
PLOGE("Unable to process HIR opcode %s", instr->opcode->name);
break;
}
instr = new_tail;
@@ -372,7 +372,7 @@ void X64Emitter::Trap(uint16_t trap_type) {
db(0xCC);
break;
default:
XELOGW("Unknown trap type %d", trap_type);
PLOGW("Unknown trap type %d", trap_type);
db(0xCC);
break;
}
@@ -598,8 +598,8 @@ void X64Emitter::CallIndirect(const hir::Instr* instr, const Reg64& reg) {
uint64_t UndefinedCallExtern(void* raw_context, uint64_t symbol_info_ptr) {
auto symbol_info = reinterpret_cast<FunctionInfo*>(symbol_info_ptr);
XELOGW("undefined extern call to %.8llX %s", symbol_info->address(),
symbol_info->name().c_str());
PLOGW("undefined extern call to %.8llX %s", symbol_info->address(),
symbol_info->name().c_str());
return 0;
}
void X64Emitter::CallExtern(const hir::Instr* instr,

View File

@@ -5392,7 +5392,7 @@ bool SelectSequence(X64Emitter& e, const Instr* i, const Instr** new_tail) {
return true;
}
}
XELOGE("No sequence match for variant %s", i->opcode->name);
PLOGE("No sequence match for variant %s", i->opcode->name);
return false;
}

View File

@@ -145,7 +145,7 @@ int RegisterAllocationPass::Run(HIRBuilder* builder) {
// We spill only those registers we aren't using.
if (!SpillOneRegister(builder, block, instr->dest->type)) {
// Unable to spill anything - this shouldn't happen.
XELOGE("Unable to spill any registers");
PLOGE("Unable to spill any registers");
assert_always();
return 1;
}
@@ -153,7 +153,7 @@ int RegisterAllocationPass::Run(HIRBuilder* builder) {
// Demand allocation.
if (!TryAllocateRegister(instr->dest)) {
// Boned.
XELOGE("Register allocation failed");
PLOGE("Register allocation failed");
assert_always();
return 1;
}

View File

@@ -11,7 +11,6 @@
#define ALLOY_CORE_H_
// TODO(benvanik): move the common stuff into here?
#include <xenia/logging.h>
#include <xenia/profiling.h>
#endif // ALLOY_CORE_H_

View File

@@ -116,7 +116,7 @@ int PPCHIRBuilder::Emit(FunctionInfo* symbol_info, uint32_t flags) {
instr_offset_list_[offset] = first_instr;
if (!i.type) {
XELOGCPU("Invalid instruction %.8llX %.8X", i.address, i.code);
PLOGE("Invalid instruction %.8llX %.8X", i.address, i.code);
Comment("INVALID!");
// TraceInvalidInstruction(i);
continue;
@@ -131,8 +131,8 @@ int PPCHIRBuilder::Emit(FunctionInfo* symbol_info, uint32_t flags) {
}
if (!i.type->emit || emit(*this, i)) {
XELOGCPU("Unimplemented instr %.8llX %.8X %s", i.address, i.code,
i.type->name);
PLOGE("Unimplemented instr %.8llX %.8X %s", i.address, i.code,
i.type->name);
Comment("UNIMPLEMENTED!");
// DebugBreak();
// TraceInvalidInstruction(i);

View File

@@ -15,8 +15,15 @@
#include <alloy/frontend/ppc/ppc_frontend.h>
#include <alloy/frontend/ppc/ppc_instr.h>
#include <alloy/runtime/runtime.h>
#include <poly/logging.h>
#include <poly/memory.h>
#if 0
#define LOGPPC(fmt, ...) PLOGCORE('p', fmt, ##__VA_ARGS__)
#else
#define LOGPPC(fmt, ...) POLY_EMPTY_MACRO
#endif
namespace alloy {
namespace frontend {
namespace ppc {
@@ -48,7 +55,7 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
Memory* memory = frontend_->memory();
const uint8_t* p = memory->membase();
XELOGSDB("Analyzing function %.8X...", symbol_info->address());
LOGPPC("Analyzing function %.8X...", symbol_info->address());
uint32_t start_address = static_cast<uint32_t>(symbol_info->address());
uint32_t end_address = static_cast<uint32_t>(symbol_info->end_address());
@@ -65,7 +72,7 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
// If we fetched 0 assume that we somehow hit one of the awesome
// 'no really we meant to end after that bl' functions.
if (!i.code) {
XELOGSDB("function end %.8X (0x00000000 read)", address);
LOGPPC("function end %.8X (0x00000000 read)", address);
// Don't include the 0's.
address -= 4;
break;
@@ -94,17 +101,16 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
// Invalid instruction.
// We can just ignore it because there's (very little)/no chance it'll
// affect flow control.
XELOGSDB("Invalid instruction at %.8X: %.8X", address, i.code);
LOGPPC("Invalid instruction at %.8X: %.8X", address, i.code);
} else if (i.code == 0x4E800020) {
// blr -- unconditional branch to LR.
// This is generally a return.
if (furthest_target > address) {
// Remaining targets within function, not end.
XELOGSDB("ignoring blr %.8X (branch to %.8X)", address,
furthest_target);
LOGPPC("ignoring blr %.8X (branch to %.8X)", address, furthest_target);
} else {
// Function end point.
XELOGSDB("function end %.8X", address);
LOGPPC("function end %.8X", address);
ends_fn = true;
}
ends_block = true;
@@ -115,11 +121,10 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
// TODO(benvanik): decode jump tables.
if (furthest_target > address) {
// Remaining targets within function, not end.
XELOGSDB("ignoring bctr %.8X (branch to %.8X)", address,
furthest_target);
LOGPPC("ignoring bctr %.8X (branch to %.8X)", address, furthest_target);
} else {
// Function end point.
XELOGSDB("function end %.8X", address);
LOGPPC("function end %.8X", address);
ends_fn = true;
}
ends_block = true;
@@ -129,25 +134,25 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
(uint32_t)XEEXTS26(i.I.LI << 2) + (i.I.AA ? 0 : (int32_t)address);
if (i.I.LK) {
XELOGSDB("bl %.8X -> %.8X", address, target);
LOGPPC("bl %.8X -> %.8X", address, target);
// Queue call target if needed.
// GetOrInsertFunction(target);
} else {
XELOGSDB("b %.8X -> %.8X", address, target);
LOGPPC("b %.8X -> %.8X", address, target);
// If the target is back into the function and there's no further target
// we are at the end of a function.
// (Indirect branches may still go beyond, but no way of knowing).
if (target >= start_address && target < address &&
furthest_target <= address) {
XELOGSDB("function end %.8X (back b)", address);
LOGPPC("function end %.8X (back b)", address);
ends_fn = true;
}
// If the target is not a branch and it goes to before the current
// address it's definitely a tail call.
if (!ends_fn && target < start_address && furthest_target <= address) {
XELOGSDB("function end %.8X (back b before addr)", address);
LOGPPC("function end %.8X (back b before addr)", address);
ends_fn = true;
}
@@ -156,7 +161,7 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
// of the function somewhere, so ensure we don't have any branches over
// it.
if (!ends_fn && furthest_target <= address && IsRestGprLr(target)) {
XELOGSDB("function end %.8X (__restgprlr_*)", address);
LOGPPC("function end %.8X (__restgprlr_*)", address);
ends_fn = true;
}
@@ -168,7 +173,7 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
// This check may hit on functions that jump over data code, so only
// trigger this check in leaf functions (no mfspr lr/prolog).
if (!ends_fn && !starts_with_mfspr_lr && blocks_found == 1) {
XELOGSDB("HEURISTIC: ending at simple leaf thunk %.8X", address);
LOGPPC("HEURISTIC: ending at simple leaf thunk %.8X", address);
ends_fn = true;
}
@@ -186,7 +191,7 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
if (!ends_fn &&
target > addr &&
furthest_target < addr) {
XELOGSDB("HEURISTIC: ending at tail call branch %.8X", addr);
LOGPPC("HEURISTIC: ending at tail call branch %.8X", addr);
ends_fn = true;
}
*/
@@ -206,14 +211,14 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
uint32_t target =
(uint32_t)XEEXTS16(i.B.BD << 2) + (i.B.AA ? 0 : (int32_t)address);
if (i.B.LK) {
XELOGSDB("bcl %.8X -> %.8X", address, target);
LOGPPC("bcl %.8X -> %.8X", address, target);
// Queue call target if needed.
// TODO(benvanik): see if this is correct - not sure anyone makes
// function calls with bcl.
// GetOrInsertFunction(target);
} else {
XELOGSDB("bc %.8X -> %.8X", address, target);
LOGPPC("bc %.8X -> %.8X", address, target);
// TODO(benvanik): GetOrInsertFunction? it's likely a BB
@@ -225,17 +230,17 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
} else if (i.type->opcode == 0x4C000020) {
// bclr/bclrl
if (i.XL.LK) {
XELOGSDB("bclrl %.8X", address);
LOGPPC("bclrl %.8X", address);
} else {
XELOGSDB("bclr %.8X", address);
LOGPPC("bclr %.8X", address);
}
ends_block = true;
} else if (i.type->opcode == 0x4C000420) {
// bcctr/bcctrl
if (i.XL.LK) {
XELOGSDB("bcctrl %.8X", address);
LOGPPC("bcctrl %.8X", address);
} else {
XELOGSDB("bcctr %.8X", address);
LOGPPC("bcctr %.8X", address);
}
ends_block = true;
}
@@ -250,8 +255,7 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
address += 4;
if (end_address && address > end_address) {
// Hmm....
XELOGSDB("Ran over function bounds! %.8X-%.8X", start_address,
end_address);
LOGPPC("Ran over function bounds! %.8X-%.8X", start_address, end_address);
break;
}
}
@@ -261,8 +265,8 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
// from someplace valid (like method hints) this may indicate an error.
// It's also possible that we guessed in hole-filling and there's another
// function below this one.
XELOGSDB("Function ran under: %.8X-%.8X ended at %.8X", start_address,
end_address, address + 4);
LOGPPC("Function ran under: %.8X-%.8X ended at %.8X", start_address,
end_address, address + 4);
}
symbol_info->set_end_address(address);
@@ -274,7 +278,7 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
// - if present, flag function as needing a stack
// - record prolog/epilog lengths/stack size/etc
XELOGSDB("Finished analyzing %.8X", start_address);
LOGPPC("Finished analyzing %.8X", start_address);
return 0;
}

View File

@@ -65,7 +65,7 @@ Breakpoint* Function::FindBreakpoint(uint64_t address) {
}
int Function::Call(ThreadState* thread_state, uint64_t return_address) {
SCOPE_profile_cpu_f("alloy");
//SCOPE_profile_cpu_f("alloy");
ThreadState* original_thread_state = ThreadState::Get();
if (original_thread_state != thread_state) {
@@ -90,8 +90,8 @@ int Function::Call(ThreadState* thread_state, uint64_t return_address) {
handler(thread_state->raw_context(), symbol_info_->extern_arg0(),
symbol_info_->extern_arg1());
} else {
XELOGW("undefined extern call to %.8llX %s", symbol_info_->address(),
symbol_info_->name().c_str());
PLOGW("undefined extern call to %.8llX %s", symbol_info_->address(),
symbol_info_->name().c_str());
result = 1;
}