Skip to content

Commit

Permalink
Add OptRepeat phase start/end indications (#100471)
Browse files Browse the repository at this point in the history
When OptRepeat is active, for phases that are being repeated,
annotate the JitDump phase start/end output with the OptRepeat
iteration number.
  • Loading branch information
BruceForstall authored Apr 1, 2024
1 parent 1949bd2 commit e3dc83a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 18 deletions.
42 changes: 28 additions & 14 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2903,10 +2903,13 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
opts.disCodeBytes = false;

#ifdef OPT_CONFIG
opts.optRepeat = false;
opts.optRepeatCount = 1;
opts.optRepeat = false;
#endif // OPT_CONFIG

opts.optRepeatIteration = 0;
opts.optRepeatCount = 1;
opts.optRepeatActive = false;

#ifdef DEBUG
opts.dspInstrs = false;
opts.dspLines = false;
Expand Down Expand Up @@ -4993,7 +4996,6 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
bool doVNBasedIntrinExpansion = true;
bool doRangeAnalysis = true;
bool doVNBasedDeadStoreRemoval = true;
int iterations = 1;

#if defined(OPT_CONFIG)
doSsa = (JitConfig.JitDoSsa() != 0);
Expand All @@ -5008,15 +5010,25 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
doVNBasedIntrinExpansion = doValueNum;
doRangeAnalysis = doAssertionProp && (JitConfig.JitDoRangeAnalysis() != 0);
doVNBasedDeadStoreRemoval = doValueNum && (JitConfig.JitDoVNBasedDeadStoreRemoval() != 0);
#endif // defined(OPT_CONFIG)

#ifdef DEBUG
if (opts.optRepeat)
{
iterations = opts.optRepeatCount;
opts.optRepeatActive = true;
}
#endif // defined(OPT_CONFIG)
#endif // DEBUG

while (iterations > 0)
while (++opts.optRepeatIteration <= opts.optRepeatCount)
{
#ifdef DEBUG
if (verbose && opts.optRepeat)
{
printf("\n*************** JitOptRepeat: iteration %d of %d\n\n", opts.optRepeatIteration,
opts.optRepeatCount);
}
#endif // DEBUG

fgModified = false;

if (doSsa)
Expand Down Expand Up @@ -5128,19 +5140,14 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
DoPhase(this, PHASE_COMPUTE_EDGE_WEIGHTS2, &Compiler::fgComputeEdgeWeights);
}

#ifdef DEBUG
if (verbose && opts.optRepeat)
{
printf("\n*************** JitOptRepeat: iterations remaining: %d\n\n", iterations - 1);
}
#endif // DEBUG

// Iterate if requested, resetting annotations first.
if (--iterations == 0)
if (opts.optRepeatIteration == opts.optRepeatCount)
{
break;
}

assert(opts.optRepeat);

// We may have optimized away the canonical entry BB that SSA
// depends on above, so if we are going for another iteration then
// make sure we still have a canonical entry.
Expand All @@ -5158,6 +5165,13 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
}
#endif // DEBUG
}

#ifdef DEBUG
if (opts.optRepeat)
{
opts.optRepeatActive = false;
}
#endif // DEBUG
}

optLoopsCanonical = false;
Expand Down
9 changes: 7 additions & 2 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9875,10 +9875,15 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
bool altJit; // True if we are an altjit and are compiling this method

#ifdef OPT_CONFIG
bool optRepeat; // Repeat optimizer phases k times
int optRepeatCount; // How many times to repeat. By default, comes from JitConfig.JitOptRepeatCount().
bool optRepeat; // Repeat optimizer phases k times
#endif

int optRepeatIteration; // The current optRepeat iteration: from 0 to optRepeatCount. optRepeatCount can be
// zero, in which case no optimizations in the set of repeated optimizations are
// performed. optRepeatIteration will only be zero if optRepeatCount is zero.
int optRepeatCount; // How many times to repeat. By default, comes from JitConfig.JitOptRepeatCount().
bool optRepeatActive; // `true` if we are in the range of phases being repeated.

bool disAsm; // Display native code as it is generated
bool disTesting; // Display BEGIN METHOD/END METHOD anchors for disasm testing
bool dspDiffable; // Makes the Jit Dump 'diff-able' (currently uses same DOTNET_* flag as disDiffable)
Expand Down
20 changes: 18 additions & 2 deletions src/coreclr/jit/phase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,15 @@ void Phase::PrePhase()
}
else
{
printf("\n*************** Starting PHASE %s\n", m_name);
if (comp->opts.optRepeatActive)
{
printf("\n*************** Starting PHASE %s (OptRepeat iteration %d of %d)\n", m_name,
comp->opts.optRepeatIteration, comp->opts.optRepeatCount);
}
else
{
printf("\n*************** Starting PHASE %s\n", m_name);
}
}
}
#endif // DEBUG
Expand Down Expand Up @@ -124,7 +132,15 @@ void Phase::PostPhase(PhaseStatus status)
}
else
{
printf("\n*************** Finishing PHASE %s%s\n", m_name, statusMessage);
if (comp->opts.optRepeatActive)
{
printf("\n*************** Finishing PHASE %s%s (OptRepeat iteration %d of %d)\n", m_name, statusMessage,
comp->opts.optRepeatIteration, comp->opts.optRepeatCount);
}
else
{
printf("\n*************** Finishing PHASE %s%s\n", m_name, statusMessage);
}
}

if (doPostPhase && doPostPhaseDumps)
Expand Down

0 comments on commit e3dc83a

Please sign in to comment.