Skip to content

Commit 39d0a85

Browse files
Improve emitter output for IG creation/saving and other improvements (#80151)
1. When outputting IG information, be explicit if the IG is being created or saved. Previously, it was harder to understand in a JitDump when an "IGxx" line showed up, and was somewhat confusing when one showed up after a new label BB started being generated that was actually saving the previous, pre-BB code. 2. Use the standard `emitDispIG()` function to display an IG, in more places. 3. Move the `Mapped BBxx to IGyy` output to a more appropriate location (when code from that BB has actually been generated into that IG -- which can happen for multiple BBs). 4. Fix `refCntWtd2str()` to work better for non-aligned cases. This function tries to generate a string like "8" with 3 trailing spaces so it will line up with the "1" in "1.50" in aligned output (instead of generating something like "8.00" which is more cluttered). But that's annoying when using the function for non-aligned cases. 5. Fixed a wrongly attributed memory allocation, for `igBlocks`
1 parent 9da463c commit 39d0a85

File tree

9 files changed

+107
-70
lines changed

9 files changed

+107
-70
lines changed

src/coreclr/jit/codegencommon.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,7 +2019,7 @@ void CodeGen::genEmitMachineCode()
20192019
if (verbose)
20202020
{
20212021
printf("*************** After end code gen, before unwindEmit()\n");
2022-
GetEmitter()->emitDispIGlist(true);
2022+
GetEmitter()->emitDispIGlist(/* displayInstructions */ true);
20232023
}
20242024
#else
20252025
if (compiler->opts.disAsm)
@@ -6409,7 +6409,7 @@ void CodeGen::genGeneratePrologsAndEpilogs()
64096409
if (verbose)
64106410
{
64116411
printf("*************** Before prolog / epilog generation\n");
6412-
GetEmitter()->emitDispIGlist(false);
6412+
GetEmitter()->emitDispIGlist(/* displayInstructions */ false);
64136413
}
64146414
#endif
64156415

@@ -6457,7 +6457,7 @@ void CodeGen::genGeneratePrologsAndEpilogs()
64576457
if (verbose)
64586458
{
64596459
printf("*************** After prolog / epilog generation\n");
6460-
GetEmitter()->emitDispIGlist(false);
6460+
GetEmitter()->emitDispIGlist(/* displayInstructions */ false);
64616461
}
64626462
#endif
64636463
}

src/coreclr/jit/compiler.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ inline double getR8LittleEndian(const BYTE* ptr)
741741

742742
#ifdef DEBUG
743743
const char* genES2str(BitVecTraits* traits, EXPSET_TP set);
744-
const char* refCntWtd2str(weight_t refCntWtd);
744+
const char* refCntWtd2str(weight_t refCntWtd, bool padForDecimalPlaces = false);
745745
#endif
746746

747747
/*

src/coreclr/jit/emit.cpp

Lines changed: 71 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,28 @@ void emitter::emitGenIG(insGroup* ig)
685685
emitCurIGfreeEndp = emitCurIGfreeBase + emitIGbuffSize;
686686
}
687687

688+
/*****************************************************************************
689+
*
690+
* Add a new IG to the current list, and get it ready to receive code.
691+
*/
692+
693+
void emitter::emitNewIG()
694+
{
695+
insGroup* ig = emitAllocAndLinkIG();
696+
697+
/* It's linked in. Now, set it up to accept code */
698+
699+
emitGenIG(ig);
700+
701+
#ifdef DEBUG
702+
if (emitComp->verbose)
703+
{
704+
printf("Created:\n ");
705+
emitDispIG(ig, nullptr, /* displayInstructions */ false, /* displayLocation */ false);
706+
}
707+
#endif // DEBUG
708+
}
709+
688710
/*****************************************************************************
689711
*
690712
* Finish and save the current IG.
@@ -850,20 +872,17 @@ insGroup* emitter::emitSavIG(bool emitAdd)
850872
#ifdef DEBUG
851873
if (emitComp->opts.dspCode)
852874
{
853-
printf("\n %s:", emitLabelString(ig));
854875
if (emitComp->verbose)
855876
{
856-
printf(" ; offs=%06XH, funclet=%02u, bbWeight=%s", ig->igOffs, ig->igFuncIdx,
857-
refCntWtd2str(ig->igWeight));
858-
emitDispIGflags(ig->igFlags);
877+
printf("Saved:\n ");
878+
emitDispIG(ig, nullptr, /* displayInstructions */ false, /* displayLocation */ false);
859879
}
860880
else
861881
{
862-
printf(" ; funclet=%02u", ig->igFuncIdx);
882+
printf(" %s: ; funclet=%02u\n", emitLabelString(ig), ig->igFuncIdx);
863883
}
864-
printf("\n");
865884
}
866-
#endif
885+
#endif // DEBUG
867886

868887
#if FEATURE_LOOP_ALIGN
869888
// Did we have any align instructions in this group?
@@ -1580,6 +1599,8 @@ void* emitter::emitAllocAnyInstr(size_t sz, emitAttr opsz)
15801599
{
15811600
emitCurIG->igBlocks.push_back(emitComp->compCurBB);
15821601
emitCurIG->lastGeneratedBlock = emitComp->compCurBB;
1602+
1603+
JITDUMP("Mapped " FMT_BB " to %s\n", emitComp->compCurBB->bbNum, emitLabelString(emitCurIG));
15831604
}
15841605
#endif // DEBUG
15851606

@@ -1902,7 +1923,7 @@ void emitter::emitCreatePlaceholderIG(insGroupPlaceholderType igType,
19021923
if (emitComp->verbose)
19031924
{
19041925
printf("*************** After placeholder IG creation\n");
1905-
emitDispIGlist(false);
1926+
emitDispIGlist(/* displayInstructions */ false);
19061927
}
19071928
#endif
19081929
}
@@ -2604,11 +2625,9 @@ void* emitter::emitAddLabel(VARSET_VALARG_TP GCvars,
26042625
#endif // defined(FEATURE_EH_FUNCLETS) && defined(TARGET_ARM)
26052626

26062627
#ifdef DEBUG
2607-
JITDUMP("Mapped " FMT_BB " to %s\n", block->bbNum, emitLabelString(emitCurIG));
2608-
26092628
if (EMIT_GC_VERBOSE)
26102629
{
2611-
printf("Label: IG%02u, GCvars=%s ", emitCurIG->igNum, VarSetOps::ToString(emitComp, GCvars));
2630+
printf("Label: %s, GCvars=%s ", emitLabelString(emitCurIG), VarSetOps::ToString(emitComp, GCvars));
26122631
dumpConvertedVarSet(emitComp, GCvars);
26132632
printf(", gcrefRegs=");
26142633
printRegMaskInt(gcrefRegs);
@@ -3589,7 +3608,7 @@ void emitter::emitDispIGflags(unsigned flags)
35893608
}
35903609
}
35913610

3592-
void emitter::emitDispIG(insGroup* ig, insGroup* igPrev, bool verbose)
3611+
void emitter::emitDispIG(insGroup* ig, insGroup* igPrev, bool displayInstructions, bool displayLocation)
35933612
{
35943613
const int TEMP_BUFFER_LEN = 40;
35953614
char buff[TEMP_BUFFER_LEN];
@@ -3649,18 +3668,22 @@ void emitter::emitDispIG(insGroup* ig, insGroup* igPrev, bool verbose)
36493668

36503669
emitDispIGflags(igPh->igFlags);
36513670

3652-
if (ig == emitCurIG)
3671+
if (displayLocation)
36533672
{
3654-
printf(" <-- Current IG");
3655-
}
3656-
if (igPh == emitPlaceholderList)
3657-
{
3658-
printf(" <-- First placeholder");
3659-
}
3660-
if (igPh == emitPlaceholderLast)
3661-
{
3662-
printf(" <-- Last placeholder");
3673+
if (ig == emitCurIG)
3674+
{
3675+
printf(" <-- Current IG");
3676+
}
3677+
if (igPh == emitPlaceholderList)
3678+
{
3679+
printf(" <-- First placeholder");
3680+
}
3681+
if (igPh == emitPlaceholderLast)
3682+
{
3683+
printf(" <-- Last placeholder");
3684+
}
36633685
}
3686+
36643687
printf("\n");
36653688

36663689
printf("%*s; PrevGCVars=%s ", strlen(buff), "",
@@ -3698,9 +3721,12 @@ void emitter::emitDispIG(insGroup* ig, insGroup* igPrev, bool verbose)
36983721
separator = ", ";
36993722
}
37003723

3724+
printf("%sbbWeight=%s", separator, refCntWtd2str(ig->igWeight));
3725+
separator = ", ";
3726+
37013727
if (emitComp->compCodeGenDone)
37023728
{
3703-
printf("%sbbWeight=%s PerfScore %.2f", separator, refCntWtd2str(ig->igWeight), ig->igPerfScore);
3729+
printf("%sPerfScore %.2f", separator, ig->igPerfScore);
37043730
separator = ", ";
37053731
}
37063732

@@ -3746,17 +3772,21 @@ void emitter::emitDispIG(insGroup* ig, insGroup* igPrev, bool verbose)
37463772

37473773
emitDispIGflags(ig->igFlags);
37483774

3749-
if (ig == emitCurIG)
3775+
if (displayLocation)
37503776
{
3751-
printf(" <-- Current IG");
3752-
}
3753-
if (ig == emitPrologIG)
3754-
{
3755-
printf(" <-- Prolog IG");
3777+
if (ig == emitCurIG)
3778+
{
3779+
printf(" <-- Current IG");
3780+
}
3781+
if (ig == emitPrologIG)
3782+
{
3783+
printf(" <-- Prolog IG");
3784+
}
37563785
}
3786+
37573787
printf("\n");
37583788

3759-
if (verbose)
3789+
if (displayInstructions)
37603790
{
37613791
instrDesc* id = emitFirstInstrDesc(ig->igData);
37623792
UNATIVE_OFFSET ofs = ig->igOffs;
@@ -3791,14 +3821,14 @@ void emitter::emitDispIG(insGroup* ig, insGroup* igPrev, bool verbose)
37913821
}
37923822
}
37933823

3794-
void emitter::emitDispIGlist(bool verbose)
3824+
void emitter::emitDispIGlist(bool displayInstructions)
37953825
{
37963826
insGroup* ig;
37973827
insGroup* igPrev;
37983828

37993829
for (igPrev = nullptr, ig = emitIGlist; ig; igPrev = ig, ig = ig->igNext)
38003830
{
3801-
emitDispIG(ig, igPrev, verbose);
3831+
emitDispIG(ig, igPrev, displayInstructions);
38023832
}
38033833
}
38043834

@@ -4156,7 +4186,7 @@ void emitter::emitRemoveJumpToNextInst()
41564186
if (EMIT_INSTLIST_VERBOSE)
41574187
{
41584188
JITDUMP("\nInstruction group list before unconditional jump to next instruction removal:\n\n");
4159-
emitDispIGlist(true);
4189+
emitDispIGlist(/* displayInstructions */ true);
41604190
}
41614191
if (EMITVERBOSE)
41624192
{
@@ -4216,9 +4246,9 @@ void emitter::emitRemoveJumpToNextInst()
42164246
printf(" id: %u: ", id->idDebugOnlyInfo()->idNum);
42174247
emitDispIns(id, false, true, false, 0, nullptr, 0, jmpGroup);
42184248
printf("jump group:\n");
4219-
emitDispIG(jmpGroup, nullptr, true);
4249+
emitDispIG(jmpGroup, nullptr, /* displayInstructions */ true);
42204250
printf("target group:\n");
4221-
emitDispIG(targetGroup, nullptr, false);
4251+
emitDispIG(targetGroup, nullptr, /* displayInstructions */ false);
42224252
assert(jmp == id);
42234253
}
42244254

@@ -4311,7 +4341,7 @@ void emitter::emitRemoveJumpToNextInst()
43114341
if (EMIT_INSTLIST_VERBOSE)
43124342
{
43134343
printf("\nInstruction group list after unconditional jump to next instruction removal:\n\n");
4314-
emitDispIGlist(false);
4344+
emitDispIGlist(/* displayInstructions */ false);
43154345
}
43164346
if (EMITVERBOSE)
43174347
{
@@ -4350,7 +4380,7 @@ void emitter::emitJumpDistBind()
43504380
if (EMIT_INSTLIST_VERBOSE)
43514381
{
43524382
printf("\nInstruction list before jump distance binding:\n\n");
4353-
emitDispIGlist(true);
4383+
emitDispIGlist(/* displayInstructions */ true);
43544384
}
43554385
if (EMITVERBOSE)
43564386
{
@@ -5097,7 +5127,7 @@ void emitter::emitJumpDistBind()
50975127
if (EMIT_INSTLIST_VERBOSE)
50985128
{
50995129
printf("\nLabels list after the jump dist binding:\n\n");
5100-
emitDispIGlist(false);
5130+
emitDispIGlist(/* displayInstructions */ false);
51015131
}
51025132

51035133
emitCheckIGoffsets();
@@ -6208,7 +6238,7 @@ unsigned emitter::emitEndCodeGen(Compiler* comp,
62086238
if (EMIT_INSTLIST_VERBOSE)
62096239
{
62106240
printf("\nInstruction list before instruction issue:\n\n");
6211-
emitDispIGlist(true);
6241+
emitDispIGlist(/* displayInstructions */ true);
62126242
}
62136243

62146244
emitCheckIGoffsets();
@@ -7099,7 +7129,7 @@ unsigned emitter::emitEndCodeGen(Compiler* comp,
70997129
if (EMIT_INSTLIST_VERBOSE)
71007130
{
71017131
printf("\nLabels list after the end of codegen:\n\n");
7102-
emitDispIGlist(false);
7132+
emitDispIGlist(/* displayInstructions */ false);
71037133
}
71047134

71057135
emitCheckIGoffsets();
@@ -9004,7 +9034,7 @@ void emitter::emitInitIG(insGroup* ig)
90049034
#ifdef DEBUG
90059035
ig->lastGeneratedBlock = nullptr;
90069036
// Explicitly call init, since IGs don't actually have a constructor.
9007-
ig->igBlocks.jitstd::list<BasicBlock*>::init(emitComp->getAllocator(CMK_LoopOpt));
9037+
ig->igBlocks.jitstd::list<BasicBlock*>::init(emitComp->getAllocator(CMK_DebugOnly));
90089038
#endif
90099039
}
90109040

src/coreclr/jit/emit.h

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,8 +1745,11 @@ class emitter
17451745
void emitDispGCInfoDelta();
17461746

17471747
void emitDispIGflags(unsigned flags);
1748-
void emitDispIG(insGroup* ig, insGroup* igPrev = nullptr, bool verbose = false);
1749-
void emitDispIGlist(bool verbose = false);
1748+
void emitDispIG(insGroup* ig,
1749+
insGroup* igPrev = nullptr,
1750+
bool displayInstructions = false,
1751+
bool displayLocation = true);
1752+
void emitDispIGlist(bool displayInstructions = false);
17501753
void emitDispGCinfo();
17511754
void emitDispJumpList();
17521755
void emitDispClsVar(CORINFO_FIELD_HANDLE fldHnd, ssize_t offs, bool reloc = false);
@@ -3355,20 +3358,6 @@ inline BYTE* emitter::emitCodeWithInstructionSize(BYTE* codePtrBefore, BYTE* new
33553358
return newCodePointer;
33563359
}
33573360

3358-
/*****************************************************************************
3359-
*
3360-
* Add a new IG to the current list, and get it ready to receive code.
3361-
*/
3362-
3363-
inline void emitter::emitNewIG()
3364-
{
3365-
insGroup* ig = emitAllocAndLinkIG();
3366-
3367-
/* It's linked in. Now, set it up to accept code */
3368-
3369-
emitGenIG(ig);
3370-
}
3371-
33723361
/*****************************************************************************/
33733362
#endif // _EMIT_H_
33743363
/*****************************************************************************/

src/coreclr/jit/fgdiagnostic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1916,7 +1916,7 @@ void Compiler::fgTableDispBasicBlock(BasicBlock* block, int ibcColWidth /* = 0 *
19161916
}
19171917
else // print weight in this format ddd.dd
19181918
{
1919-
printf("%6s", refCntWtd2str(weight));
1919+
printf("%6s", refCntWtd2str(weight, /* padForDecimalPlaces */ true));
19201920
}
19211921
}
19221922

src/coreclr/jit/lclvars.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3827,7 +3827,7 @@ void Compiler::lvaSortByRefCount()
38273827

38283828
INDEBUG(if (verbose) { gtDispLclVar(tracked[varIndex]); })
38293829
JITDUMP(" [%6s]: refCnt = %4u, refCntWtd = %6s\n", varTypeName(varDsc->TypeGet()), varDsc->lvRefCnt(),
3830-
refCntWtd2str(varDsc->lvRefCntWtd()));
3830+
refCntWtd2str(varDsc->lvRefCntWtd(), /* padForDecimalPlaces */ true));
38313831
}
38323832

38333833
JITDUMP("\n");
@@ -7652,7 +7652,8 @@ void Compiler::lvaDumpEntry(unsigned lclNum, FrameLayoutState curState, size_t r
76527652
printf(" ]");
76537653
}
76547654

7655-
printf(" (%3u,%*s)", varDsc->lvRefCnt(), (int)refCntWtdWidth, refCntWtd2str(varDsc->lvRefCntWtd()));
7655+
printf(" (%3u,%*s)", varDsc->lvRefCnt(), (int)refCntWtdWidth,
7656+
refCntWtd2str(varDsc->lvRefCntWtd(), /* padForDecimalPlaces */ true));
76567657

76577658
printf(" %7s ", varTypeName(type));
76587659
if (genTypeSize(type) == 0)
@@ -7913,7 +7914,7 @@ void Compiler::lvaTableDump(FrameLayoutState curState)
79137914
{
79147915
for (lclNum = 0, varDsc = lvaTable; lclNum < lvaCount; lclNum++, varDsc++)
79157916
{
7916-
size_t width = strlen(refCntWtd2str(varDsc->lvRefCntWtd()));
7917+
size_t width = strlen(refCntWtd2str(varDsc->lvRefCntWtd(), /* padForDecimalPlaces */ true));
79177918
if (width > refCntWtdWidth)
79187919
{
79197920
refCntWtdWidth = width;

src/coreclr/jit/lsra.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ void LinearScan::setBlockSequence()
958958
const LsraBlockInfo& bi = blockInfo[block->bbNum];
959959

960960
// Note that predBBNum isn't set yet.
961-
JITDUMP(" (%6s)", refCntWtd2str(bi.weight));
961+
JITDUMP(" (%6s)", refCntWtd2str(bi.weight, /* padForDecimalPlaces */ true));
962962

963963
if (bi.hasCriticalInEdge)
964964
{

src/coreclr/jit/optimizer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7718,7 +7718,8 @@ void Compiler::optHoistLoopBlocks(unsigned loopNum, ArrayStack<BasicBlock*>* blo
77187718
weight_t blockWeight = block->getBBWeight(this);
77197719

77207720
JITDUMP("\n optHoistLoopBlocks " FMT_BB " (weight=%6s) of loop " FMT_LP " <" FMT_BB ".." FMT_BB ">\n",
7721-
block->bbNum, refCntWtd2str(blockWeight), loopNum, loopDsc->lpTop->bbNum, loopDsc->lpBottom->bbNum);
7721+
block->bbNum, refCntWtd2str(blockWeight, /* padForDecimalPlaces */ true), loopNum,
7722+
loopDsc->lpTop->bbNum, loopDsc->lpBottom->bbNum);
77227723

77237724
if (blockWeight < (BB_UNITY_WEIGHT / 10))
77247725
{

0 commit comments

Comments
 (0)