Dramatically speeding up HIR comments.

This commit is contained in:
Ben Vanik 2015-06-10 00:28:02 -07:00
parent 56a4620cdf
commit 14e1438ec0
3 changed files with 42 additions and 16 deletions

View File

@ -56,9 +56,9 @@ bool PPCHIRBuilder::Emit(FunctionInfo* symbol_info, uint32_t flags) {
with_debug_info_ = (flags & EMIT_DEBUG_COMMENTS) == EMIT_DEBUG_COMMENTS;
if (with_debug_info_) {
Comment("%s fn %.8X-%.8X %s", symbol_info->module()->name().c_str(),
symbol_info->address(), symbol_info->end_address(),
symbol_info->name().c_str());
CommentFormat("%s fn %.8X-%.8X %s", symbol_info->module()->name().c_str(),
symbol_info->address(), symbol_info->end_address(),
symbol_info->name().c_str());
}
// Allocate offset list.
@ -101,8 +101,9 @@ bool PPCHIRBuilder::Emit(FunctionInfo* symbol_info, uint32_t flags) {
AnnotateLabel(address, label);
}
comment_buffer_.Reset();
comment_buffer_.AppendFormat("%.8X %.8X ", address, i.code);
DisasmPPC(i, &comment_buffer_);
Comment("%.8X %.8X %s", address, i.code, comment_buffer_.GetString());
Comment(comment_buffer_);
first_instr = last_instr();
}

View File

@ -16,6 +16,9 @@
#include "xenia/cpu/symbol_info.h"
#include "xenia/profiling.h"
// Will scribble arena memory to hopefully find use before clears.
//#define SCRIBBLE_ARENA_ON_RESET
namespace xe {
namespace cpu {
namespace hir {
@ -57,7 +60,7 @@ void HIRBuilder::Reset() {
locals_.clear();
block_head_ = block_tail_ = NULL;
current_block_ = NULL;
#if XE_DEBUG
#if SCRIBBLE_ARENA_ON_RESET
arena_->DebugFill();
#endif
arena_->Reset();
@ -727,18 +730,38 @@ Value* HIRBuilder::CloneValue(Value* source) {
return value;
}
void HIRBuilder::Comment(const char* format, ...) {
char buffer[1024];
va_list args;
va_start(args, format);
vsnprintf(buffer, 1024, format, args);
va_end(args);
size_t len = strlen(buffer);
if (!len) {
void HIRBuilder::Comment(const char* value) {
size_t length = std::strlen(value);
if (!length) {
return;
}
void* p = arena_->Alloc(len + 1);
memcpy(p, buffer, len + 1);
void* p = arena_->Alloc(length + 1);
std::memcpy(p, value, length + 1);
Instr* i = AppendInstr(OPCODE_COMMENT_info, 0);
i->src1.offset = (uint64_t)p;
i->src2.value = i->src3.value = NULL;
}
void HIRBuilder::Comment(const StringBuffer& value) {
if (!value.length()) {
return;
}
void* p = arena_->Alloc(value.length() + 1);
std::memcpy(p, value.GetString(), value.length() + 1);
Instr* i = AppendInstr(OPCODE_COMMENT_info, 0);
i->src1.offset = (uint64_t)p;
i->src2.value = i->src3.value = NULL;
}
void HIRBuilder::CommentFormat(const char* format, ...) {
static const uint32_t kMaxCommentSize = 1024;
char* p = reinterpret_cast<char*>(arena_->Alloc(kMaxCommentSize));
va_list args;
va_start(args, format);
size_t chars_written = vsnprintf(p, kMaxCommentSize - 1, format, args);
va_end(args);
size_t rewind = kMaxCommentSize - chars_written;
arena_->Rewind(rewind);
Instr* i = AppendInstr(OPCODE_COMMENT_info, 0);
i->src1.offset = (uint64_t)p;
i->src2.value = i->src3.value = NULL;

View File

@ -68,7 +68,9 @@ class HIRBuilder {
// static allocations:
// Value* AllocStatic(size_t length);
void Comment(const char* format, ...);
void Comment(const char* value);
void Comment(const StringBuffer& value);
void CommentFormat(const char* format, ...);
void Nop();