Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/coreclr/jit/codegenarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3285,7 +3285,7 @@ void CodeGen::genCall(GenTreeCall* call)

// If there is nothing next, that means the result is thrown away, so this value is not live.
// However, for minopts or debuggable code, we keep it live to support managed return value debugging.
if ((call->gtNext == nullptr) && !compiler->opts.MinOpts() && !compiler->opts.compDbgCode)
if ((call->gtNext == nullptr) && !compiler->opts.MinOpts() && !compiler->opts.DbgCode())
Copy link
Member

Choose a reason for hiding this comment

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

!compiler->opts.MinOpts() && !compiler->opts.DbgCode()

This is doing the same thing if (opts.OptimizationsEnabled()) does. Should it just be simplified to that?

{
gcInfo.gcMarkRegSetNpt(RBM_INTRET);
}
Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1799,7 +1799,7 @@ void CodeGen::genGenerateMachineCode()
{
printf("; EnC code\n");
}
else if (compiler->opts.compDbgCode)
else if (compiler->opts.DbgCode())
{
printf("; debuggable code\n");
}
Expand Down Expand Up @@ -4588,7 +4588,7 @@ void CodeGen::genZeroInitFrame(int untrLclHi, int untrLclLo, regNumber initReg,
// or when in debug code

noway_assert(varTypeIsGC(varDsc->TypeGet()) || (varDsc->TypeGet() == TYP_STRUCT) ||
compiler->info.compInitMem || compiler->opts.compDbgCode);
compiler->info.compInitMem || compiler->opts.DbgCode());

if (!varDsc->lvOnFrame)
{
Expand Down Expand Up @@ -6918,7 +6918,7 @@ void CodeGen::genSetScopeInfo(unsigned which,
PREFIX_ASSUME(compiler->lvaVarargsHandleArg < compiler->info.compArgsCount);
if (!compiler->lvaGetDesc(compiler->lvaVarargsHandleArg)->lvOnFrame)
{
noway_assert(!compiler->opts.compDbgCode);
noway_assert(!compiler->opts.DbgCode());
return;
}

Expand Down Expand Up @@ -7198,7 +7198,7 @@ void CodeGen::genIPmappingAddToFront(IPmappingDscKind kind, const DebugInfo& di,

void CodeGen::genEnsureCodeEmitted(const DebugInfo& di)
{
if (!compiler->opts.compDbgCode)
if (!compiler->opts.DbgCode())
{
return;
}
Expand Down Expand Up @@ -7343,7 +7343,7 @@ void CodeGen::genIPmappingGen()
//different source lines. As a result, we have all sorts of latent problems with how we emit debug
//info, but very few actual ones. Whenever someone wants to tackle that problem in general, turn this
//assert back on.
if (compiler->opts.compDbgCode)
if (compiler->opts.DbgCode())
{
//Assert that the first instruction of every basic block with more than one incoming edge has a
//different sequence point from each incoming block.
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/codegenloongarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7084,7 +7084,7 @@ void CodeGen::genCall(GenTreeCall* call)

// If there is nothing next, that means the result is thrown away, so this value is not live.
// However, for minopts or debuggable code, we keep it live to support managed return value debugging.
if ((call->gtNext == nullptr) && !compiler->opts.MinOpts() && !compiler->opts.compDbgCode)
if ((call->gtNext == nullptr) && !compiler->opts.MinOpts() && !compiler->opts.DbgCode())
Copy link
Member

Choose a reason for hiding this comment

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

Same here. This is really just if ((call->gtNext == nullptr) && compiler->opts.OptimizationsEnabled())

{
gcInfo.gcMarkRegSetNpt(RBM_INTRET);
}
Expand Down
28 changes: 14 additions & 14 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1914,10 +1914,10 @@ void Compiler::compInit(ArenaAllocator* pAlloc,
compRationalIRForm = false;

#ifdef DEBUG
compCodeGenDone = false;
opts.compMinOptsIsUsed = false;
compCodeGenDone = false;
#endif
opts.compMinOptsIsSet = false;

opts.InitializeMinOpts();

// Used by fgFindJumpTargets for inlining heuristics.
opts.instrCount = 0;
Expand Down Expand Up @@ -2428,7 +2428,7 @@ void Compiler::compInitOptions(JitFlags* jitFlags)

//-------------------------------------------------------------------------

opts.compDbgCode = jitFlags->IsSet(JitFlags::JIT_FLAG_DEBUG_CODE);
opts.SetDbgCode(jitFlags->IsSet(JitFlags::JIT_FLAG_DEBUG_CODE));
opts.compDbgInfo = jitFlags->IsSet(JitFlags::JIT_FLAG_DEBUG_INFO);
opts.compDbgEnC = jitFlags->IsSet(JitFlags::JIT_FLAG_DEBUG_EnC);

Expand Down Expand Up @@ -2487,7 +2487,7 @@ void Compiler::compInitOptions(JitFlags* jitFlags)

#if REGEN_SHORTCUTS || REGEN_CALLPAT
// We never want to have debugging enabled when regenerating GC encoding patterns
opts.compDbgCode = false;
opts.SetDbgCode(false);
opts.compDbgInfo = false;
opts.compDbgEnC = false;
#endif
Expand Down Expand Up @@ -3199,8 +3199,8 @@ void Compiler::compInitOptions(JitFlags* jitFlags)

if (opts.compProcedureSplitting)
{
// Note that opts.compdbgCode is true under ngen for checked assemblies!
opts.compProcedureSplitting = !opts.compDbgCode || enableFakeSplitting;
// Note that opts.DbgCode() is true under ngen for checked assemblies!
opts.compProcedureSplitting = !opts.DbgCode() || enableFakeSplitting;

#ifdef DEBUG
// JitForceProcedureSplitting is used to force procedure splitting on checked assemblies.
Expand Down Expand Up @@ -3289,7 +3289,7 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
: (opts.compCodeOpt == SMALL_CODE) ? "SMALL_CODE"
: (opts.compCodeOpt == FAST_CODE) ? "FAST_CODE" : "UNKNOWN_CODE");

printf("OPTIONS: compDbgCode = %s\n", dspBool(opts.compDbgCode));
printf("OPTIONS: compDbgCode = %s\n", dspBool(opts.DbgCode()));
printf("OPTIONS: compDbgInfo = %s\n", dspBool(opts.compDbgInfo));
printf("OPTIONS: compDbgEnC = %s\n", dspBool(opts.compDbgEnC));
printf("OPTIONS: compProcedureSplitting = %s\n", dspBool(opts.compProcedureSplitting));
Expand Down Expand Up @@ -3555,12 +3555,12 @@ void Compiler::compInitDebuggingInfo()

compInitVarScopeMap();

if (opts.compScopeInfo || opts.compDbgCode)
if (opts.compScopeInfo || opts.DbgCode())
{
compInitScopeLists();
}

if (opts.compDbgCode && (info.compVarScopesCount > 0))
if (opts.DbgCode() && (info.compVarScopesCount > 0))
{
/* Create a new empty basic block. fgExtendDbgLifetimes() may add
initialization of variables which are in scope right from the
Expand Down Expand Up @@ -3858,7 +3858,7 @@ void Compiler::compSetOptimizationLevel()

// Notify the VM if MinOpts is being used when not requested
if (theMinOptsValue && !compIsForInlining() && !opts.jitFlags->IsSet(JitFlags::JIT_FLAG_TIER0) &&
!opts.jitFlags->IsSet(JitFlags::JIT_FLAG_MIN_OPT) && !opts.compDbgCode)
!opts.jitFlags->IsSet(JitFlags::JIT_FLAG_MIN_OPT) && !opts.DbgCode())
{
info.compCompHnd->setMethodAttribs(info.compMethodHnd, CORINFO_FLG_SWITCHED_TO_MIN_OPT);
opts.jitFlags->Clear(JitFlags::JIT_FLAG_TIER1);
Expand Down Expand Up @@ -4110,9 +4110,9 @@ const char* Compiler::compGetTieringName(bool wantShortName) const
const bool tier1 = opts.jitFlags->IsSet(JitFlags::JIT_FLAG_TIER1);
const bool instrumenting = opts.jitFlags->IsSet(JitFlags::JIT_FLAG_BBINSTR);

if (!opts.compMinOptsIsSet)
if (!opts.IsMinOptsSet())
{
// If 'compMinOptsIsSet' is not set, just return here. Otherwise, if this method is called
// If 'IsMinOptsSet()' is not true, just return here. Otherwise, if this method is called
// by the assertAbort(), we would recursively call assert while trying to get MinOpts()
// and eventually stackoverflow.
return "Optimization-Level-Not-Yet-Set";
Expand Down Expand Up @@ -4164,7 +4164,7 @@ const char* Compiler::compGetTieringName(bool wantShortName) const
return "MinOpts";
}
}
else if (opts.compDbgCode)
else if (opts.DbgCode())
{
return "Debug";
}
Expand Down
53 changes: 44 additions & 9 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9191,39 +9191,61 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// Maximum number of locals before turning off the inlining
#define MAX_LV_NUM_COUNT_FOR_INLINING 512

private:
bool compMinOpts;
bool compMinOptsIsSet;
bool compDbgCode; // Generate debugger-friendly code?
bool compOptimizationEnabled; // A cached, composite value

#ifdef DEBUG
mutable bool compMinOptsIsUsed;
#endif // !DEBUG

void SetOptimizationEnabled()
{
// We want to be careful with the `compMinOptsIsSet` and `compMinOptsIsUsed` values.
// Caching the value shouldn't touch these. However, using this value should have the
// same asserts as using `MinOpts()`.
compOptimizationEnabled = !compMinOpts && !compDbgCode;
}

public:
void InitializeMinOpts()
{
INDEBUG(compMinOptsIsUsed = false);
compMinOptsIsSet = false;
}

#ifdef DEBUG
bool MinOpts() const
{
assert(compMinOptsIsSet);
compMinOptsIsUsed = true;
Copy link
Member

Choose a reason for hiding this comment

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

Just wondering, what's the general point of this and why do we need to track it as part of the check whether min opts is enabled

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree. Shouldn't compMinOptsIsSet sufficient to make sure that we are not calling MinOpts() before it is set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Once we read the value, we should never try to set it afterwards -- someone has taken a dependency on the value. Like the PhasedVar stuff.

Copy link
Member

Choose a reason for hiding this comment

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

Couldn't we just have a check in SetMinOpts to assert we aren't past import or anything?

We should really only be setting it when the compiler is created or in the case we fault and fallback to minopts, right?

Once we've hit import, we're basically guaranteed to have some path that checks it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps, but the effect would not be as obvious or direct, and of course, compMinOptsIsUsed is DEBUG-only code.

return compMinOpts;
}
bool IsMinOptsSet() const
{
return compMinOptsIsSet;
}
#else // !DEBUG
bool MinOpts() const
{
return compMinOpts;
}
#endif // !DEBUG

bool IsMinOptsSet() const
{
return compMinOptsIsSet;
}
#endif // !DEBUG

bool OptimizationDisabled() const
{
return MinOpts() || compDbgCode;
assert(compMinOptsIsSet);
INDEBUG(compMinOptsIsUsed = true);
return !compOptimizationEnabled;
}
bool OptimizationEnabled() const
{
return !OptimizationDisabled();
assert(compMinOptsIsSet);
INDEBUG(compMinOptsIsUsed = true);
return compOptimizationEnabled;
}

void SetMinOpts(bool val)
Expand All @@ -9232,6 +9254,20 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
assert(!compMinOptsIsSet || (compMinOpts == val));
compMinOpts = val;
compMinOptsIsSet = true;

SetOptimizationEnabled(); // Update compOptimizationEnabled
}

bool DbgCode() const
{
return compDbgCode;
}

void SetDbgCode(bool val)
{
compDbgCode = val;

SetOptimizationEnabled(); // Update compOptimizationEnabled
}

// true if the CLFLG_* for an optimization is set.
Expand Down Expand Up @@ -9325,7 +9361,6 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
}

bool compScopeInfo; // Generate the LocalVar info ?
bool compDbgCode; // Generate debugger-friendly code?
bool compDbgInfo; // Gather debugging info?
bool compDbgEnC;

Expand Down Expand Up @@ -9932,7 +9967,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
if (opts.IsOSR())
return false;
#endif
return !info.compInitMem && opts.compDbgCode;
return !info.compInitMem && opts.DbgCode();
}

// Returns true if the jit supports having patchpoints in this method.
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1983,7 +1983,7 @@ inline bool Compiler::lvaKeepAliveAndReportThis()
if (info.compXcptnsCount > 0)
return true;

if (opts.compDbgCode)
if (opts.DbgCode())
return true;

if (lvaGenericsContextInUse)
Expand Down
8 changes: 4 additions & 4 deletions src/coreclr/jit/fgbasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2280,7 +2280,7 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, Fixed

const bool notStruct = !varTypeIsStruct(lvaGetDesc(varNum));
const bool notLastInstr = (codeAddr < codeEndp - sz);
const bool notDebugCode = !opts.compDbgCode;
const bool notDebugCode = !opts.DbgCode();

if (notStruct && notLastInstr && notDebugCode && impILConsumesAddr(codeAddr + sz))
{
Expand Down Expand Up @@ -2809,7 +2809,7 @@ unsigned Compiler::fgMakeBasicBlocks(const BYTE* codeAddr, IL_OFFSET codeSize, F

// Keep track of where we are in the scope lists, as we will also
// create blocks at scope boundaries.
if (opts.compDbgCode && (info.compVarScopesCount > 0))
if (opts.DbgCode() && (info.compVarScopesCount > 0))
{
compResetScopeLists();

Expand Down Expand Up @@ -3186,7 +3186,7 @@ unsigned Compiler::fgMakeBasicBlocks(const BYTE* codeAddr, IL_OFFSET codeSize, F

bool foundScope = false;

if (opts.compDbgCode && (info.compVarScopesCount > 0))
if (opts.DbgCode() && (info.compVarScopesCount > 0))
{
while (compGetNextEnterScope(nxtBBoffs))
{
Expand Down Expand Up @@ -6888,5 +6888,5 @@ BasicBlock* Compiler::fgNewBBinRegionWorker(BBjumpKinds jumpKind,
// true if 'throw' helper block should be created.
bool Compiler::fgUseThrowHelperBlocks()
{
return !opts.compDbgCode;
return !opts.DbgCode();
}
8 changes: 4 additions & 4 deletions src/coreclr/jit/fgehopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ PhaseStatus Compiler::fgRemoveEmptyFinally()
return PhaseStatus::MODIFIED_NOTHING;
}

if (opts.compDbgCode)
if (opts.DbgCode())
{
JITDUMP("Method compiled with debug codegen, no removal.\n");
return PhaseStatus::MODIFIED_NOTHING;
Expand Down Expand Up @@ -320,7 +320,7 @@ PhaseStatus Compiler::fgRemoveEmptyTry()
return PhaseStatus::MODIFIED_NOTHING;
}

if (opts.compDbgCode)
if (opts.DbgCode())
{
JITDUMP("Method compiled with debug codegen, no removal.\n");
return PhaseStatus::MODIFIED_NOTHING;
Expand Down Expand Up @@ -657,7 +657,7 @@ PhaseStatus Compiler::fgCloneFinally()
return PhaseStatus::MODIFIED_NOTHING;
}

if (opts.compDbgCode)
if (opts.DbgCode())
{
JITDUMP("Method compiled with debug codegen, no cloning.\n");
return PhaseStatus::MODIFIED_NOTHING;
Expand Down Expand Up @@ -1657,7 +1657,7 @@ PhaseStatus Compiler::fgMergeFinallyChains()
return PhaseStatus::MODIFIED_NOTHING;
}

if (opts.compDbgCode)
if (opts.DbgCode())
{
JITDUMP("Method compiled with debug codegen, no merging.\n");
return PhaseStatus::MODIFIED_NOTHING;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/fgopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4761,7 +4761,7 @@ bool Compiler::fgExpandRarelyRunBlocks()
//
bool Compiler::fgReorderBlocks(bool useProfile)
{
noway_assert(opts.compDbgCode == false);
noway_assert(!opts.DbgCode());

#if defined(FEATURE_EH_FUNCLETS)
assert(fgFuncletsCreated);
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/fgstmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ void Compiler::fgRemoveStmt(BasicBlock* block, Statement* stmt DEBUGARG(bool isU
}
#endif // DEBUG

if (opts.compDbgCode && stmt->GetPrevStmt() != stmt && stmt->GetDebugInfo().IsValid())
if (opts.DbgCode() && stmt->GetPrevStmt() != stmt && stmt->GetDebugInfo().IsValid())
{
/* TODO: For debuggable code, should we remove significant
statement boundaries. Or should we leave a GT_NO_OP in its place? */
Expand Down Expand Up @@ -546,7 +546,7 @@ inline bool OperIsControlFlow(genTreeOps oper)

bool Compiler::fgCheckRemoveStmt(BasicBlock* block, Statement* stmt)
{
if (opts.compDbgCode)
if (opts.DbgCode())
{
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/jit/flowgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ BasicBlock* Compiler::fgCreateGCPoll(GCPollType pollType, BasicBlock* block)
bool Compiler::fgCanSwitchToOptimized()
{
bool result = opts.jitFlags->IsSet(JitFlags::JIT_FLAG_TIER0) && !opts.jitFlags->IsSet(JitFlags::JIT_FLAG_MIN_OPT) &&
!opts.compDbgCode && !compIsForInlining();
!opts.DbgCode() && !compIsForInlining();
if (result)
{
// Ensure that it would be safe to change the opt level
Expand Down Expand Up @@ -2303,7 +2303,7 @@ class MergedReturns

// Do not look for mergeable constant returns in debug codegen as
// we may lose track of sequence points.
if ((returnBlock != nullptr) && (maxReturns > 1) && !comp->opts.compDbgCode)
if ((returnBlock != nullptr) && (maxReturns > 1) && !comp->opts.DbgCode())
{
// Check to see if this is a constant return so that we can search
// for and/or create a constant return block for it.
Expand Down Expand Up @@ -2695,7 +2695,7 @@ PhaseStatus Compiler::fgAddInternal()

CORINFO_JUST_MY_CODE_HANDLE* pDbgHandle = nullptr;
CORINFO_JUST_MY_CODE_HANDLE dbgHandle = nullptr;
if (opts.compDbgCode && !opts.jitFlags->IsSet(JitFlags::JIT_FLAG_IL_STUB))
if (opts.DbgCode() && !opts.jitFlags->IsSet(JitFlags::JIT_FLAG_IL_STUB))
{
dbgHandle = info.compCompHnd->getJustMyCodeHandle(info.compMethodHnd, &pDbgHandle);
}
Expand Down
Loading