Skip to content

Re-enable USING_VARIABLE_LIVE_RANGE #50162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 27, 2021
25 changes: 22 additions & 3 deletions src/coreclr/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11863,9 +11863,28 @@ void CodeGenInterface::VariableLiveKeeper::VariableLiveDescriptor::startLiveRang
// Is the first "VariableLiveRange" or the previous one has been closed so its "m_EndEmitLocation" is valid
noway_assert(m_VariableLiveRanges->empty() || m_VariableLiveRanges->back().m_EndEmitLocation.Valid());

// Creates new live range with invalid end
m_VariableLiveRanges->emplace_back(varLocation, emitLocation(), emitLocation());
m_VariableLiveRanges->back().m_StartEmitLocation.CaptureLocation(emit);
if (!m_VariableLiveRanges->empty() &&
siVarLoc::Equals(&varLocation, &(m_VariableLiveRanges->back().m_VarLocation)) &&
m_VariableLiveRanges->back().m_EndEmitLocation.IsPreviousInsNum(emit))
{
JITDUMP("Extending debug range...\n");

// The variable is being born just after the instruction at which it died.
// In this case, i.e. an update of the variable's value, we coalesce the live ranges.
m_VariableLiveRanges->back().m_EndEmitLocation.Init();
}
else
{
JITDUMP("New debug range: %s\n",
m_VariableLiveRanges->empty()
? "first"
: siVarLoc::Equals(&varLocation, &(m_VariableLiveRanges->back().m_VarLocation))
? "new var or location"
: "not adjacent");
// Creates new live range with invalid end
m_VariableLiveRanges->emplace_back(varLocation, emitLocation(), emitLocation());
m_VariableLiveRanges->back().m_StartEmitLocation.CaptureLocation(emit);
}

#ifdef DEBUG
if (!m_VariableLifeBarrier->hasLiveRangesToDump())
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/codegeninterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
#include "treelifeupdater.h"
#include "emit.h"

#if 1
#if 0
// Enable USING_SCOPE_INFO flag to use psiScope/siScope info to report variables' locations.
#define USING_SCOPE_INFO
#endif
#if 0
#if 1
// Enable USING_VARIABLE_LIVE_RANGE flag to use VariableLiveRange info to report variables' locations.
// Note: if both USING_SCOPE_INFO and USING_VARIABLE_LIVE_RANGE are defined, then USING_SCOPE_INFO
// information is reported to the debugger.
Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/jit/ee_il_dll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,8 @@ void Compiler::eeDispVar(ICorDebugInfo::NativeVarInfo* var)
// Same parameters as ICorStaticInfo::setVars().
void Compiler::eeDispVars(CORINFO_METHOD_HANDLE ftn, ULONG32 cVars, ICorDebugInfo::NativeVarInfo* vars)
{
// Estimate number of unique vars with debug info
//
ALLVARSET_TP uniqueVars(AllVarSetOps::MakeEmpty(this));
for (unsigned i = 0; i < cVars; i++)
{
Expand All @@ -870,7 +872,8 @@ void Compiler::eeDispVars(CORINFO_METHOD_HANDLE ftn, ULONG32 cVars, ICorDebugInf
AllVarSetOps::AddElemD(this, uniqueVars, vars[i].varNumber);
}
}
printf("; Variable debug info: %d live range(s), %d var(s) for method %s\n", cVars,

printf("; Variable debug info: %d live ranges, %d vars for method %s\n", cVars,
AllVarSetOps::Count(this, uniqueVars), info.compFullName);

for (unsigned i = 0; i < cVars; i++)
Expand Down
26 changes: 26 additions & 0 deletions src/coreclr/jit/emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,32 @@ UNATIVE_OFFSET emitLocation::GetFuncletPrologOffset(emitter* emit) const
return emit->emitCurIGsize;
}

//------------------------------------------------------------------------
// IsPreviousInsNum: Returns true if the emitter is on the next instruction
// of the same group as this emitLocation.
//
// Arguments:
// emit - an emitter* instance
//
bool emitLocation::IsPreviousInsNum(emitter* emit) const
{
assert(Valid());

// Within the same IG?
if (ig == emit->emitCurIG)
{
return (emitGetInsNumFromCodePos(codePos) == emitGetInsNumFromCodePos(emit->emitCurOffset()) - 1);
}

// Spanning an IG boundary?
if (ig->igNext == emit->emitCurIG)
{
return (emitGetInsNumFromCodePos(codePos) == ig->igInsCnt) && (emit->emitCurIGinsCnt == 1);
}

return false;
}

#ifdef DEBUG
void emitLocation::Print(LONG compMethodID) const
{
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/jit/emit.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ class emitLocation

UNATIVE_OFFSET GetFuncletPrologOffset(emitter* emit) const;

bool IsPreviousInsNum(emitter* emit) const;

#ifdef DEBUG
void Print(LONG compMethodID) const;
#endif // DEBUG
Expand Down