Skip to content

Commit

Permalink
Improve live variable JitDump output (#54256)
Browse files Browse the repository at this point in the history
The variable live range output is unnecessarily verbose. Simplify it; clean it up;
make it smaller; use standard dumpers.

Example, before:
```
////////////////////////////////////////
////////////////////////////////////////
Variable Live Range History Dump for Block 2
IL Var Num 0:
[rcx [ (G_M13669_IG02,ins#0,ofs#0), (G_M13669_IG03,ins#1,ofs#2) ]; rbp[16] (1 slot) [ (G_M13669_IG03,ins#1,ofs#2), NON_CLOSED_RANGE ]; ]
IL Var Num 1:
[rsi [ (G_M13669_IG03,ins#1,ofs#2), NON_CLOSED_RANGE ]; ]
////////////////////////////////////////
////////////////////////////////////////
End Generating code for Block 2
```
After:
```
Variable Live Range History Dump for BB02
V00 this: rcx [(G_M13669_IG02,ins#0,ofs#0), (G_M13669_IG03,ins#1,ofs#2)]; rbp[16] (1 slot) [(G_M13669_IG03,ins#1,ofs#2), ...]
V01 loc0: rsi [(G_M13669_IG03,ins#1,ofs#2), ...]
```

And the end-of-dump output, before:
```
////////////////////////////////////////
////////////////////////////////////////
PRINTING VARIABLE LIVE RANGES:
IL Var Num 0:
[rsi [18 , B5 )rsi [100 , 13A )rsi [14D , 186 )rsi [196 , 1C5 )rsi [1E3 , 271 )rsi [280 , 285 )]
IL Var Num 1:
[rdi [18 , B9 )rdi [100 , 137 )rdi [14D , 184 )rdi [196 , 1C2 )rdi [1E3 , 271 )rdi [280 , 288 )]
IL Var Num 2:
[rbx [18 , CA )rbx [100 , 10D )rbx [14D , 15A )rbx [196 , 1C7 )rbx [1E3 , 271 )rbx [280 , 28B )]
IL Var Num 3:
[rbp [3A , F0 )rbp [100 , 141 )rbp [14D , 18C )rbp [196 , 1D6 )rbp [1E3 , 275 )]
IL Var Num 4:
[r14 [3E , EC )r14 [100 , 13D )r14 [14D , 188 )r14 [196 , 1D2 )r14 [1E3 , 271 )]
IL Var Num 5:
[rcx [22A , 263 )]
////////////////////////////////////////
////////////////////////////////////////
```
After:
```
VARIABLE LIVE RANGES:
V00 arg0: rsi [18, B5); rsi [100, 13A); rsi [14D, 186); rsi [196, 1C5); rsi [1E3, 271); rsi [280, 285)
V01 arg1: rdi [18, B9); rdi [100, 137); rdi [14D, 184); rdi [196, 1C2); rdi [1E3, 271); rdi [280, 288)
V02 arg2: rbx [18, CA); rbx [100, 10D); rbx [14D, 15A); rbx [196, 1C7); rbx [1E3, 271); rbx [280, 28B)
V03 loc0: rbp [3A, F0); rbp [100, 141); rbp [14D, 18C); rbp [196, 1D6); rbp [1E3, 275)
V04 loc1: r14 [3E, EC); r14 [100, 13D); r14 [14D, 188); r14 [196, 1D2); r14 [1E3, 271)
V05 loc2: rcx [22A, 263)
```
  • Loading branch information
BruceForstall committed Jun 16, 2021
1 parent afcbd8c commit a02b668
Showing 1 changed file with 51 additions and 58 deletions.
109 changes: 51 additions & 58 deletions src/coreclr/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11700,7 +11700,8 @@ void CodeGenInterface::VariableLiveKeeper::VariableLiveRange::dumpVariableLiveRa
const CodeGenInterface* codeGen) const
{
codeGen->dumpSiVarLoc(&m_VarLocation);
printf(" [ ");

printf(" [");
m_StartEmitLocation.Print(codeGen->GetCompiler()->compMethodID);
printf(", ");
if (m_EndEmitLocation.Valid())
Expand All @@ -11709,9 +11710,9 @@ void CodeGenInterface::VariableLiveKeeper::VariableLiveRange::dumpVariableLiveRa
}
else
{
printf("NON_CLOSED_RANGE");
printf("...");
}
printf(" ]; ");
printf("]");
}

// Dump "VariableLiveRange" when code has been generated and we have the assembly native offset of each "emitLocation"
Expand All @@ -11727,7 +11728,7 @@ void CodeGenInterface::VariableLiveKeeper::VariableLiveRange::dumpVariableLiveRa
// If this is an open "VariableLiveRange", "m_EndEmitLocation" is non-valid and print -1
UNATIVE_OFFSET endAssemblyOffset = m_EndEmitLocation.Valid() ? m_EndEmitLocation.CodeOffset(emit) : -1;

printf(" [%X , %X )", m_StartEmitLocation.CodeOffset(emit), m_EndEmitLocation.CodeOffset(emit));
printf(" [%X, %X)", m_StartEmitLocation.CodeOffset(emit), m_EndEmitLocation.CodeOffset(emit));
}

//------------------------------------------------------------------------
Expand Down Expand Up @@ -11971,25 +11972,31 @@ void CodeGenInterface::VariableLiveKeeper::VariableLiveDescriptor::updateLiveRan
void CodeGenInterface::VariableLiveKeeper::VariableLiveDescriptor::dumpAllRegisterLiveRangesForBlock(
emitter* emit, const CodeGenInterface* codeGen) const
{
printf("[");
bool first = true;
for (LiveRangeListIterator it = m_VariableLiveRanges->begin(); it != m_VariableLiveRanges->end(); it++)
{
if (!first)
{
printf("; ");
}
it->dumpVariableLiveRange(emit, codeGen);
first = false;
}
printf("]\n");
}

void CodeGenInterface::VariableLiveKeeper::VariableLiveDescriptor::dumpRegisterLiveRangesForBlockBeforeCodeGenerated(
const CodeGenInterface* codeGen) const
{
noway_assert(codeGen != nullptr);

printf("[");
bool first = true;
for (LiveRangeListIterator it = m_VariableLifeBarrier->getStartForDump(); it != m_VariableLiveRanges->end(); it++)
{
if (!first)
{
printf("; ");
}
it->dumpVariableLiveRange(codeGen);
first = false;
}
printf("]\n");
}

// Returns true if a live range for this variable has been recorded
Expand Down Expand Up @@ -12428,76 +12435,62 @@ void CodeGenInterface::VariableLiveKeeper::psiClosePrologVariableRanges()
#ifdef DEBUG
void CodeGenInterface::VariableLiveKeeper::dumpBlockVariableLiveRanges(const BasicBlock* block)
{
// "block" will be dereferenced
noway_assert(block != nullptr);
assert(block != nullptr);

bool hasDumpedHistory = false;

if (m_Compiler->verbose)
{
printf("////////////////////////////////////////\n");
printf("////////////////////////////////////////\n");
printf("Variable Live Range History Dump for Block %d \n", block->bbNum);
printf("\nVariable Live Range History Dump for " FMT_BB "\n", block->bbNum);

if (m_Compiler->opts.compDbgInfo)
if (m_Compiler->opts.compDbgInfo)
{
for (unsigned int varNum = 0; varNum < m_LiveDscCount; varNum++)
{
for (unsigned int varNum = 0; varNum < m_LiveDscCount; varNum++)
{
VariableLiveDescriptor* varLiveDsc = m_vlrLiveDsc + varNum;
VariableLiveDescriptor* varLiveDsc = m_vlrLiveDsc + varNum;

if (varLiveDsc->hasVarLiveRangesFromLastBlockToDump())
{
hasDumpedHistory = true;
printf("IL Var Num %d:\n", m_Compiler->compMap2ILvarNum(varNum));
varLiveDsc->dumpRegisterLiveRangesForBlockBeforeCodeGenerated(m_Compiler->codeGen);
varLiveDsc->endBlockLiveRanges();
}
if (varLiveDsc->hasVarLiveRangesFromLastBlockToDump())
{
hasDumpedHistory = true;
m_Compiler->gtDispLclVar(varNum, false);
printf(": ");
varLiveDsc->dumpRegisterLiveRangesForBlockBeforeCodeGenerated(m_Compiler->codeGen);
varLiveDsc->endBlockLiveRanges();
printf("\n");
}
}
}

if (!hasDumpedHistory)
{
printf("..None..\n");
}

printf("////////////////////////////////////////\n");
printf("////////////////////////////////////////\n");
printf("End Generating code for Block %d \n", block->bbNum);
if (!hasDumpedHistory)
{
printf("..None..\n");
}
}

void CodeGenInterface::VariableLiveKeeper::dumpLvaVariableLiveRanges() const
{
bool hasDumpedHistory = false;

if (m_Compiler->verbose)
{
printf("////////////////////////////////////////\n");
printf("////////////////////////////////////////\n");
printf("PRINTING VARIABLE LIVE RANGES:\n");
printf("VARIABLE LIVE RANGES:\n");

if (m_Compiler->opts.compDbgInfo)
if (m_Compiler->opts.compDbgInfo)
{
for (unsigned int varNum = 0; varNum < m_LiveDscCount; varNum++)
{
for (unsigned int varNum = 0; varNum < m_LiveDscCount; varNum++)
{
VariableLiveDescriptor* varLiveDsc = m_vlrLiveDsc + varNum;
VariableLiveDescriptor* varLiveDsc = m_vlrLiveDsc + varNum;

if (varLiveDsc->hasVarLiveRangesToDump())
{
hasDumpedHistory = true;
printf("IL Var Num %d:\n", m_Compiler->compMap2ILvarNum(varNum));
varLiveDsc->dumpAllRegisterLiveRangesForBlock(m_Compiler->GetEmitter(), m_Compiler->codeGen);
}
if (varLiveDsc->hasVarLiveRangesToDump())
{
hasDumpedHistory = true;
m_Compiler->gtDispLclVar(varNum, false);
printf(": ");
varLiveDsc->dumpAllRegisterLiveRangesForBlock(m_Compiler->GetEmitter(), m_Compiler->codeGen);
printf("\n");
}
}
}

if (!hasDumpedHistory)
{
printf("..None..\n");
}

printf("////////////////////////////////////////\n");
printf("////////////////////////////////////////\n");
if (!hasDumpedHistory)
{
printf("..None..\n");
}
}
#endif // DEBUG
Expand Down

0 comments on commit a02b668

Please sign in to comment.