From 181ade5c491ebd72a1ab6f3c829a0a2f1ea07d9e Mon Sep 17 00:00:00 2001 From: Derek Morris Date: Mon, 12 Mar 2018 17:46:29 -0700 Subject: [PATCH] Allow naming labels and highlighting instructions This change is designed to make following some code paths easier when doing JIT work. The first change is that it adds debug-only code that puts names on labels, which should help users looking at instructions that expand to a great number of blocks. The second change is to have developers be able to set a color for a particular Instr such that in dumps it stands out better, which may be useful in some situations. --- lib/Backend/IR.cpp | 24 +++++++++++++++++++++++- lib/Backend/IR.h | 20 +++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/lib/Backend/IR.cpp b/lib/Backend/IR.cpp index 2927680fa61..127fd3c5a00 100644 --- a/lib/Backend/IR.cpp +++ b/lib/Backend/IR.cpp @@ -4301,7 +4301,20 @@ Instr::Dump(IRDumpFlags flags) const auto PrintOpCodeName = [&]() { Output::SkipToColumn(23); +#if DBG + WORD oldValue = 0; + if (this->highlight != 0) + { + oldValue = Output::SetConsoleForeground(this->highlight); + } +#endif Output::Print(_u("%s "), Js::OpCodeUtil::GetOpCodeName(m_opcode)); +#if DBG + if (this->highlight != 0) + { + Output::SetConsoleForeground(oldValue); + } +#endif Output::SkipToColumn(38); }; @@ -4585,7 +4598,16 @@ LabelInstr::Dump(IRDumpFlags flags) { this->m_block->DumpHeader(); } - Output::Print(_u("$L%d:"), this->m_id); +#if DBG + if (this->m_name != nullptr) + { + Output::Print(_u("$L%d (%s):"), this->m_id, this->m_name); + } + else +#endif + { + Output::Print(_u("$L%d:"), this->m_id); + } if (this->isOpHelper) { Output::Print(_u(" [helper]")); diff --git a/lib/Backend/IR.h b/lib/Backend/IR.h index ec7b1fa9cb0..70570ed1bcd 100644 --- a/lib/Backend/IR.h +++ b/lib/Backend/IR.h @@ -169,6 +169,9 @@ class Instr isCallInstrProtectedByNoProfileBailout(false), hasSideEffects(false), isNonFastPathFrameDisplay(false) +#if DBG + , highlight(0) +#endif { } public: @@ -530,6 +533,9 @@ class Instr Opnd * m_dst; Opnd * m_src1; Opnd * m_src2; +#if DBG + WORD highlight; +#endif @@ -664,6 +670,7 @@ class LabelInstr : public Instr m_hasNonBranchRef(false), m_region(nullptr), m_loweredBasicBlock(nullptr), m_isDataLabel(false), m_isForInExit(false) #if DBG , m_noHelperAssert(false) + , m_name(nullptr) #endif { #if DBG_DUMP @@ -692,6 +699,9 @@ class LabelInstr : public Instr #endif unsigned int m_id; LoweredBasicBlock* m_loweredBasicBlock; +#if DBG + const char16* m_name; +#endif private: union labelLocation { @@ -732,7 +742,15 @@ class LabelInstr : public Instr protected: void Init(Js::OpCode opcode, IRKind kind, Func *func, bool isOpHelper); - }; +}; + +#if DBG +#define LABELNAMESET(label, name) do { label->m_name = _u(name); } while(false) +#define LABELNAME(label) do { label->m_name = _u(#label); } while(false) +#else +#define LABELNAMESET(label, name) +#define LABELNAME(label) +#endif class ProfiledLabelInstr: public LabelInstr {