Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Improve LIR dumping #10140

Merged
merged 3 commits into from
Mar 14, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/jit/codegenarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,11 +501,13 @@ void CodeGen::genCodeForTreeNode(GenTreePtr treeNode)

#ifdef DEBUG
lastConsumedNode = nullptr;
if (compiler->verbose)
{
unsigned seqNum = treeNode->gtSeqNum; // Useful for setting a conditional break in Visual Studio
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you not set a breakpoint on treeNode->gtSeqNum itself?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it. I just copy-and-pasted that from the other codegen files. Since it doesn't hurt, it made sense to keep it the same.

compiler->gtDispLIRNode(treeNode, "Generating: ");
}
#endif

JITDUMP("Generating: ");
DISPNODE(treeNode);

// contained nodes are part of their parents for codegen purposes
// ex : immediates, most LEAs
if (treeNode->isContained())
Expand Down
3 changes: 1 addition & 2 deletions src/jit/codegenarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1923,8 +1923,7 @@ void CodeGen::genCodeForTreeNode(GenTreePtr treeNode)
if (compiler->verbose)
{
unsigned seqNum = treeNode->gtSeqNum; // Useful for setting a conditional break in Visual Studio
printf("Generating: ");
compiler->gtDispTree(treeNode, nullptr, nullptr, true);
compiler->gtDispLIRNode(treeNode, "Generating: ");
}
#endif // DEBUG

Expand Down
3 changes: 1 addition & 2 deletions src/jit/codegenxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1266,8 +1266,7 @@ void CodeGen::genCodeForTreeNode(GenTreePtr treeNode)
if (compiler->verbose)
{
unsigned seqNum = treeNode->gtSeqNum; // Useful for setting a conditional break in Visual Studio
printf("Generating: ");
compiler->gtDispTree(treeNode, nullptr, nullptr, true);
compiler->gtDispLIRNode(treeNode, "Generating: ");
}
#endif // DEBUG

Expand Down
15 changes: 14 additions & 1 deletion src/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8164,11 +8164,12 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
* The versions that start with 'd' use the tlsCompiler, so don't require a Compiler*.
*
* Summary:
* cBlock, dBlock : Display a basic block (call fgDispBasicBlock()).
* cBlock, dBlock : Display a basic block (call fgTableDispBasicBlock()).
* cBlocks, dBlocks : Display all the basic blocks of a function (call fgDispBasicBlocks()).
* cBlocksV, dBlocksV : Display all the basic blocks of a function (call fgDispBasicBlocks(true)).
* "V" means "verbose", and will dump all the trees.
* cTree, dTree : Display a tree (call gtDispTree()).
* cTreeLIR, dTreeLIR : Display a tree in LIR form (call gtDispLIRNode()).
* cTrees, dTrees : Display all the trees in a function (call fgDumpTrees()).
* cEH, dEH : Display the EH handler table (call fgDispHandlerTab()).
* cVar, dVar : Display a local variable given its number (call lvaDumpEntry()).
Expand Down Expand Up @@ -8238,6 +8239,13 @@ void cTree(Compiler* comp, GenTree* tree)
comp->gtDispTree(tree, nullptr, ">>>");
}

void cTreeLIR(Compiler* comp, GenTree* tree)
{
static unsigned sequenceNumber = 0; // separate calls with a number to indicate this function has been called
printf("===================================================================== *TreeLIR %u\n", sequenceNumber++);
comp->gtDispLIRNode(tree);
}

void cTrees(Compiler* comp)
{
static unsigned sequenceNumber = 0; // separate calls with a number to indicate this function has been called
Expand Down Expand Up @@ -8352,6 +8360,11 @@ void dTree(GenTree* tree)
cTree(JitTls::GetCompiler(), tree);
}

void dTreeLIR(GenTree* tree)
{
cTreeLIR(JitTls::GetCompiler(), tree);
}

void dTrees()
{
cTrees(JitTls::GetCompiler());
Expand Down
2 changes: 1 addition & 1 deletion src/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -2235,7 +2235,7 @@ class Compiler

void gtDispTreeRange(LIR::Range& containingRange, GenTree* tree);

void gtDispLIRNode(GenTree* node);
void gtDispLIRNode(GenTree* node, const char* prefixMsg = nullptr);
#endif

// For tree walks
Expand Down
49 changes: 29 additions & 20 deletions src/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12002,16 +12002,22 @@ void Compiler::gtDispTreeRange(LIR::Range& containingRange, GenTree* tree)
//
// Arguments:
// node - the LIR node to dump.
// prefixMsg - an optional prefix for each line of output.
//
void Compiler::gtDispLIRNode(GenTree* node)
void Compiler::gtDispLIRNode(GenTree* node, const char* prefixMsg /* = nullptr */)
{
auto displayOperand = [](GenTree* operand, const char* message, IndentInfo operandArc, IndentStack& indentStack) {
auto displayOperand = [](GenTree* operand, const char* message, IndentInfo operandArc, IndentStack& indentStack, const char* prefixMsg = nullptr) {
assert(operand != nullptr);
assert(message != nullptr);

if (prefixMsg != nullptr)
{
printf("%s", prefixMsg);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: you could capture the length of prefixMsg and use it to adjust the alignment below. I'd be interested to see how the codegen dumps looked in both cases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that the prefixMsg is output for both the operand (here), and the operator (below), and the operator doesn't have any leading space. And, I want the operator and operands to be indented by the same amount, when a prefixMsg is given.

Here's an example from codegen:

Generating: N037 (  1,  4) [000034] ------------       t34 =    const(h)  int    0x8B6604 ftn REG NA
Generating:                                                  /--*  t34    int
Generating: N039 (  3,  6) [000035] ------------       t35 = *  indir     int    REG NA
Generating:                                                  /--*  t35    int    control expr
Generating: N041 ( 69, 33) [000008] --C-G-------             *  call      void   System.Console.WriteLine $VN.Void

A "full dump" looks like:

                                                 /--*  t32    int    control expr
N029 ( 45, 22) [000005] --C-G-------        t5 = *  call      float  Program.f2 $c3
                                                 /--*  t5     float
N031 ( 49, 25) [000021] DAC-G-----L-             *  st.lclVar float  V02 tmp1         d:2 REG NA
N033 (  3,  2) [000022] ------------       t22 =    lclVar    float  V02 tmp1         u:2 (last use) REG NA $c3
                                                 /--*  t22    float
N035 (???,???) [000033] ------------             *  putarg_stk [+0x00] float  REG NA
N037 (  1,  4) [000034] ------------       t34 =    const(h)  int    0x8B6604 ftn REG NA
                                                 /--*  t34    int
N039 (  3,  6) [000035] ------------       t35 = *  indir     int    REG NA
                                                 /--*  t35    int    control expr
N041 ( 69, 33) [000008] --C-G-------             *  call      void   System.Console.WriteLine $VN.Void
N043 (  2,  2) [000013] ------------                il_offset void   IL offset: 25 REG NA
N045 (  1,  1) [000011] ------------       t11 =    const     int    100 REG NA $42
                                                 /--*  t11    int
N047 (  2,  2) [000012] ------------             *  return    int    REG NA $1c0

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is hugely picky of me, but is there any chance we could avoid printing the message before the operands? No big deal if there isn't.

}

// 49 spaces for alignment
printf("%-49s", "");
#ifdef FEATURE_SET_FLAGS
#if FEATURE_SET_FLAGS
// additional flag enlarges the flag field by one character
printf(" ");
#endif
Expand All @@ -12022,7 +12028,6 @@ void Compiler::gtDispLIRNode(GenTree* node)
operandArc = IIArc;

printf(" t%-5d %-6s %s\n", operand->gtTreeID, varTypeName(operand->TypeGet()), message);

};

IndentStack indentStack(this);
Expand All @@ -12048,19 +12053,19 @@ void Compiler::gtDispLIRNode(GenTree* node)
if (operand == call->gtCallObjp)
{
sprintf_s(buf, sizeof(buf), "this in %s", compRegVarName(REG_ARG_0));
displayOperand(operand, buf, operandArc, indentStack);
displayOperand(operand, buf, operandArc, indentStack, prefixMsg);
}
else if (operand == call->gtCallAddr)
{
displayOperand(operand, "calli tgt", operandArc, indentStack);
displayOperand(operand, "calli tgt", operandArc, indentStack, prefixMsg);
}
else if (operand == call->gtControlExpr)
{
displayOperand(operand, "control expr", operandArc, indentStack);
displayOperand(operand, "control expr", operandArc, indentStack, prefixMsg);
}
else if (operand == call->gtCallCookie)
{
displayOperand(operand, "cookie", operandArc, indentStack);
displayOperand(operand, "cookie", operandArc, indentStack, prefixMsg);
}
else
{
Expand All @@ -12082,7 +12087,7 @@ void Compiler::gtDispLIRNode(GenTree* node)
gtGetLateArgMsg(call, operand, curArgTabEntry->lateArgInx, listIndex, buf, sizeof(buf));
}

displayOperand(operand, buf, operandArc, indentStack);
displayOperand(operand, buf, operandArc, indentStack, prefixMsg);
operandArc = IIArc;
}
}
Expand All @@ -12097,63 +12102,67 @@ void Compiler::gtDispLIRNode(GenTree* node)
gtGetLateArgMsg(call, operand, curArgTabEntry->lateArgInx, -1, buf, sizeof(buf));
}

displayOperand(operand, buf, operandArc, indentStack);
displayOperand(operand, buf, operandArc, indentStack, prefixMsg);
}
}
}
else if (node->OperIsDynBlkOp())
{
if (operand == node->AsBlk()->Addr())
{
displayOperand(operand, "lhs", operandArc, indentStack);
displayOperand(operand, "lhs", operandArc, indentStack, prefixMsg);
}
else if (operand == node->AsBlk()->Data())
{
displayOperand(operand, "rhs", operandArc, indentStack);
displayOperand(operand, "rhs", operandArc, indentStack, prefixMsg);
}
else
{
assert(operand == node->AsDynBlk()->gtDynamicSize);
displayOperand(operand, "size", operandArc, indentStack);
displayOperand(operand, "size", operandArc, indentStack, prefixMsg);
}
}
else if (node->OperGet() == GT_DYN_BLK)
{
if (operand == node->AsBlk()->Addr())
{
displayOperand(operand, "lhs", operandArc, indentStack);
displayOperand(operand, "lhs", operandArc, indentStack, prefixMsg);
}
else
{
assert(operand == node->AsDynBlk()->gtDynamicSize);
displayOperand(operand, "size", operandArc, indentStack);
displayOperand(operand, "size", operandArc, indentStack, prefixMsg);
}
}
else if (node->OperIsAssignment())
{
if (operand == node->gtGetOp1())
{
displayOperand(operand, "lhs", operandArc, indentStack);
displayOperand(operand, "lhs", operandArc, indentStack, prefixMsg);
}
else
{
displayOperand(operand, "rhs", operandArc, indentStack);
displayOperand(operand, "rhs", operandArc, indentStack, prefixMsg);
}
}
else
{
displayOperand(operand, "", operandArc, indentStack);
displayOperand(operand, "", operandArc, indentStack, prefixMsg);
}

operandArc = IIArc;
}

// Visit the operator

if (prefixMsg != nullptr)
{
printf("%s", prefixMsg);
}

const bool topOnly = true;
const bool isLIR = true;
gtDispTree(node, &indentStack, nullptr, topOnly, isLIR);

printf("\n");
}

/*****************************************************************************/
Expand Down