Skip to content

Commit 7601d44

Browse files
authored
JIT: some small profile related fixes (#43408)
1. If we're inheriting a fraction of the profile weight of a profiled block, mark the inheriting block as profiled. This prevents methods like `optSetBlockWeights` or `optMarkLoopBlocks` from coming along later and setting the weights to something else. Since the full inheritance method has similar logic, make it delegate to the fractional one, with a scale of 100 (no scaling). 2. If we switch from Tier0 to FullOpt, make sure to clear the BBINSTR flag, else we'll put probes into optimized code. 3. Dump edge weights in the dot graph, if we have them. 4. Only dump the flow graph twice per phase.
1 parent 8c48ae8 commit 7601d44

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

src/coreclr/src/jit/block.h

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -568,47 +568,37 @@ struct BasicBlock : private LIR::Range
568568
}
569569

570570
// this block will inherit the same weight and relevant bbFlags as bSrc
571+
//
571572
void inheritWeight(BasicBlock* bSrc)
572573
{
573-
this->bbWeight = bSrc->bbWeight;
574-
575-
if (bSrc->hasProfileWeight())
576-
{
577-
this->bbFlags |= BBF_PROF_WEIGHT;
578-
}
579-
else
580-
{
581-
this->bbFlags &= ~BBF_PROF_WEIGHT;
582-
}
583-
584-
if (this->bbWeight == 0)
585-
{
586-
this->bbFlags |= BBF_RUN_RARELY;
587-
}
588-
else
589-
{
590-
this->bbFlags &= ~BBF_RUN_RARELY;
591-
}
574+
inheritWeightPercentage(bSrc, 100);
592575
}
593576

594577
// Similar to inheritWeight(), but we're splitting a block (such as creating blocks for qmark removal).
595-
// So, specify a percentage (0 to 99; if it's 100, just use inheritWeight()) of the weight that we're
596-
// going to inherit. Since the number isn't exact, clear the BBF_PROF_WEIGHT flag.
578+
// So, specify a percentage (0 to 100) of the weight the block should inherit.
579+
//
597580
void inheritWeightPercentage(BasicBlock* bSrc, unsigned percentage)
598581
{
599-
assert(0 <= percentage && percentage < 100);
582+
assert(0 <= percentage && percentage <= 100);
600583

601584
// Check for overflow
602-
if (bSrc->bbWeight * 100 <= bSrc->bbWeight)
585+
if ((bSrc->bbWeight * 100) <= bSrc->bbWeight)
603586
{
604587
this->bbWeight = bSrc->bbWeight;
605588
}
606589
else
607590
{
608-
this->bbWeight = bSrc->bbWeight * percentage / 100;
591+
this->bbWeight = (bSrc->bbWeight * percentage) / 100;
609592
}
610593

611-
this->bbFlags &= ~BBF_PROF_WEIGHT;
594+
if (bSrc->hasProfileWeight())
595+
{
596+
this->bbFlags |= BBF_PROF_WEIGHT;
597+
}
598+
else
599+
{
600+
this->bbFlags &= ~BBF_PROF_WEIGHT;
601+
}
612602

613603
if (this->bbWeight == 0)
614604
{

src/coreclr/src/jit/compiler.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4215,9 +4215,7 @@ void Compiler::EndPhase(Phases phase)
42154215
pCompJitTimer->EndPhase(this, phase);
42164216
}
42174217
#endif
4218-
#if DUMP_FLOWGRAPHS
4219-
fgDumpFlowGraph(phase);
4220-
#endif // DUMP_FLOWGRAPHS
4218+
42214219
mostRecentlyActivePhase = phase;
42224220
}
42234221

src/coreclr/src/jit/flowgraph.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4344,6 +4344,7 @@ void Compiler::fgSwitchToOptimized()
43444344
JITDUMP("****\n**** JIT Tier0 jit request switching to Tier1 because of loop\n****\n");
43454345
assert(opts.jitFlags->IsSet(JitFlags::JIT_FLAG_TIER0));
43464346
opts.jitFlags->Clear(JitFlags::JIT_FLAG_TIER0);
4347+
opts.jitFlags->Clear(JitFlags::JIT_FLAG_BBINSTR);
43474348

43484349
// Leave a note for jit diagnostics
43494350
compSwitchedToOptimized = true;
@@ -19929,8 +19930,7 @@ bool Compiler::fgDumpFlowGraph(Phases phase)
1992919930
return false;
1993019931
}
1993119932
bool validWeights = fgHaveValidEdgeWeights;
19932-
unsigned calledCount = max(fgCalledCount, BB_UNITY_WEIGHT) / BB_UNITY_WEIGHT;
19933-
double weightDivisor = (double)(calledCount * BB_UNITY_WEIGHT);
19933+
double weightDivisor = (double)fgCalledCount;
1993419934
const char* escapedString;
1993519935
const char* regionString = "NONE";
1993619936

@@ -19972,7 +19972,7 @@ bool Compiler::fgDumpFlowGraph(Phases phase)
1997219972

1997319973
if (fgHaveProfileData())
1997419974
{
19975-
fprintf(fgxFile, "\n calledCount=\"%d\"", calledCount);
19975+
fprintf(fgxFile, "\n calledCount=\"%d\"", fgCalledCount);
1997619976
fprintf(fgxFile, "\n profileData=\"true\"");
1997719977
}
1997819978
if (compHndBBtabCount > 0)
@@ -20122,20 +20122,32 @@ bool Compiler::fgDumpFlowGraph(Phases phase)
2012220122
{
2012320123
fprintf(fgxFile, " " FMT_BB " -> " FMT_BB, bSource->bbNum, bTarget->bbNum);
2012420124

20125+
const char* sep = "";
20126+
2012520127
if (bSource->bbNum > bTarget->bbNum)
2012620128
{
2012720129
// Lexical backedge
20128-
fprintf(fgxFile, " [color=green]\n");
20130+
fprintf(fgxFile, " [color=green");
20131+
sep = ", ";
2012920132
}
2013020133
else if ((bSource->bbNum + 1) == bTarget->bbNum)
2013120134
{
2013220135
// Lexical successor
20133-
fprintf(fgxFile, " [color=blue, weight=20]\n");
20136+
fprintf(fgxFile, " [color=blue, weight=20");
20137+
sep = ", ";
2013420138
}
2013520139
else
2013620140
{
20137-
fprintf(fgxFile, ";\n");
20141+
fprintf(fgxFile, " [");
2013820142
}
20143+
20144+
if (validWeights)
20145+
{
20146+
unsigned edgeWeight = (edge->edgeWeightMin() + edge->edgeWeightMax()) / 2;
20147+
fprintf(fgxFile, "%slabel=\"%7.2f\"", sep, (double)edgeWeight / weightDivisor);
20148+
}
20149+
20150+
fprintf(fgxFile, "];\n");
2013920151
}
2014020152
else
2014120153
{

0 commit comments

Comments
 (0)