Skip to content

Commit 181ade5

Browse files
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.
1 parent e9293b1 commit 181ade5

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

lib/Backend/IR.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4301,7 +4301,20 @@ Instr::Dump(IRDumpFlags flags)
43014301

43024302
const auto PrintOpCodeName = [&]() {
43034303
Output::SkipToColumn(23);
4304+
#if DBG
4305+
WORD oldValue = 0;
4306+
if (this->highlight != 0)
4307+
{
4308+
oldValue = Output::SetConsoleForeground(this->highlight);
4309+
}
4310+
#endif
43044311
Output::Print(_u("%s "), Js::OpCodeUtil::GetOpCodeName(m_opcode));
4312+
#if DBG
4313+
if (this->highlight != 0)
4314+
{
4315+
Output::SetConsoleForeground(oldValue);
4316+
}
4317+
#endif
43054318
Output::SkipToColumn(38);
43064319
};
43074320

@@ -4585,7 +4598,16 @@ LabelInstr::Dump(IRDumpFlags flags)
45854598
{
45864599
this->m_block->DumpHeader();
45874600
}
4588-
Output::Print(_u("$L%d:"), this->m_id);
4601+
#if DBG
4602+
if (this->m_name != nullptr)
4603+
{
4604+
Output::Print(_u("$L%d (%s):"), this->m_id, this->m_name);
4605+
}
4606+
else
4607+
#endif
4608+
{
4609+
Output::Print(_u("$L%d:"), this->m_id);
4610+
}
45894611
if (this->isOpHelper)
45904612
{
45914613
Output::Print(_u(" [helper]"));

lib/Backend/IR.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ class Instr
169169
isCallInstrProtectedByNoProfileBailout(false),
170170
hasSideEffects(false),
171171
isNonFastPathFrameDisplay(false)
172+
#if DBG
173+
, highlight(0)
174+
#endif
172175
{
173176
}
174177
public:
@@ -530,6 +533,9 @@ class Instr
530533
Opnd * m_dst;
531534
Opnd * m_src1;
532535
Opnd * m_src2;
536+
#if DBG
537+
WORD highlight;
538+
#endif
533539

534540

535541

@@ -664,6 +670,7 @@ class LabelInstr : public Instr
664670
m_hasNonBranchRef(false), m_region(nullptr), m_loweredBasicBlock(nullptr), m_isDataLabel(false), m_isForInExit(false)
665671
#if DBG
666672
, m_noHelperAssert(false)
673+
, m_name(nullptr)
667674
#endif
668675
{
669676
#if DBG_DUMP
@@ -692,6 +699,9 @@ class LabelInstr : public Instr
692699
#endif
693700
unsigned int m_id;
694701
LoweredBasicBlock* m_loweredBasicBlock;
702+
#if DBG
703+
const char16* m_name;
704+
#endif
695705
private:
696706
union labelLocation
697707
{
@@ -732,7 +742,15 @@ class LabelInstr : public Instr
732742

733743
protected:
734744
void Init(Js::OpCode opcode, IRKind kind, Func *func, bool isOpHelper);
735-
};
745+
};
746+
747+
#if DBG
748+
#define LABELNAMESET(label, name) do { label->m_name = _u(name); } while(false)
749+
#define LABELNAME(label) do { label->m_name = _u(#label); } while(false)
750+
#else
751+
#define LABELNAMESET(label, name)
752+
#define LABELNAME(label)
753+
#endif
736754

737755
class ProfiledLabelInstr: public LabelInstr
738756
{

0 commit comments

Comments
 (0)