Skip to content

Commit

Permalink
[1.8>1.9] Allow naming labels and highlighting instructions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Penguinwizzard committed Mar 14, 2018
2 parents f882a20 + 181ade5 commit 1b527d5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
24 changes: 23 additions & 1 deletion lib/Backend/IR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down Expand Up @@ -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]"));
Expand Down
20 changes: 19 additions & 1 deletion lib/Backend/IR.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ class Instr
isCallInstrProtectedByNoProfileBailout(false),
hasSideEffects(false),
isNonFastPathFrameDisplay(false)
#if DBG
, highlight(0)
#endif
{
}
public:
Expand Down Expand Up @@ -530,6 +533,9 @@ class Instr
Opnd * m_dst;
Opnd * m_src1;
Opnd * m_src2;
#if DBG
WORD highlight;
#endif



Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 1b527d5

Please sign in to comment.