From 446a5f1cb1775ccbc984fa917b52f159ec62a1c2 Mon Sep 17 00:00:00 2001 From: kobalicek Date: Tue, 29 Mar 2016 04:57:56 +0200 Subject: [PATCH] Improved asmjit trace - pretty print nodes being removed --- src/asmjit/base/compilercontext.cpp | 6 ++++-- src/asmjit/base/compilercontext_p.h | 7 +++++++ src/asmjit/x86/x86compilercontext.cpp | 12 ++++++++---- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/asmjit/base/compilercontext.cpp b/src/asmjit/base/compilercontext.cpp index 7b0f4a2..683f001 100644 --- a/src/asmjit/base/compilercontext.cpp +++ b/src/asmjit/base/compilercontext.cpp @@ -27,11 +27,11 @@ namespace asmjit { Context::Context(Compiler* compiler) : _compiler(compiler), _zoneAllocator(8192 - Zone::kZoneOverhead), + _traceNode(nullptr), _varMapToVaListOffset(0) { Context::reset(); } - Context::~Context() {} // ============================================================================ @@ -312,7 +312,9 @@ Error Context::removeUnreachableCode() { } if (remove) { - ASMJIT_TLOG("[%05d] Removing unreachable node\n", node->getFlowId()); + ASMJIT_TSEC({ + this->_traceNode(this, node, "[REMOVED UNREACHABLE] "); + }); compiler->removeNode(node); } diff --git a/src/asmjit/base/compilercontext_p.h b/src/asmjit/base/compilercontext_p.h index 4b51fcf..81e8937 100644 --- a/src/asmjit/base/compilercontext_p.h +++ b/src/asmjit/base/compilercontext_p.h @@ -816,6 +816,13 @@ struct Context { //! Zone allocator. Zone _zoneAllocator; + //! \internal + typedef void (ASMJIT_CDECL* TraceNodeFunc)(Context* self, HLNode* node_, const char* prefix); + //! \internal + //! + //! Only non-NULL when ASMJIT_TRACE is enabled. + TraceNodeFunc _traceNode; + //! \internal //! //! Offset (how many bytes to add) to `VarMap` to get `VarAttr` array. Used diff --git a/src/asmjit/x86/x86compilercontext.cpp b/src/asmjit/x86/x86compilercontext.cpp index d7d435e..d224d5d 100644 --- a/src/asmjit/x86/x86compilercontext.cpp +++ b/src/asmjit/x86/x86compilercontext.cpp @@ -156,7 +156,7 @@ static bool X86Context_annotateInstruction(X86Context* self, #endif // !ASMJIT_DISABLE_LOGGER #if defined(ASMJIT_TRACE) -static void X86Context_traceNode(X86Context* self, HLNode* node_, const char* prefix) { +static void ASMJIT_CDECL X86Context_traceNode(X86Context* self, HLNode* node_, const char* prefix) { StringBuilderTmp<256> sb; switch (node_->getType()) { @@ -263,6 +263,10 @@ X86Context::X86Context(X86Compiler* compiler) : Context(compiler) { _memSlot._vmem.type = kMemTypeStackIndex; _memSlot.setGpdBase(compiler->getArch() == kArchX86); +#if defined(ASMJIT_TRACE) + _traceNode = (TraceNodeFunc)X86Context_traceNode; +#endif // ASMJIT_TRACE + #if !defined(ASMJIT_DISABLE_LOGGER) _emitComments = compiler->getAssembler()->hasLogger(); #endif // !ASMJIT_DISABLE_LOGGER @@ -2279,7 +2283,7 @@ _NextGroup: node_->setFlowId(flowId); ASMJIT_TSEC({ - X86Context_traceNode(this, node_, "[F] "); + this->_traceNode(this, node_, "[F] "); }); switch (node_->getType()) { @@ -3777,7 +3781,7 @@ ASMJIT_INLINE uint32_t X86VarAlloc::guessAlloc(VarData* vd, uint32_t allocableRe for (;;) { do { ASMJIT_TSEC({ - X86Context_traceNode(_context, node, " "); + _context->_traceNode(_context, node, " "); }); // Terminate if we have seen this node already. @@ -5449,7 +5453,7 @@ _NextGroup: node_->orFlags(HLNode::kFlagIsTranslated); ASMJIT_TSEC({ - X86Context_traceNode(this, node_, "[T] "); + this->_traceNode(this, node_, "[T] "); }); switch (node_->getType()) {