Skip to content

Commit 34e6ac5

Browse files
committed
Re-enable improvements to debug emission for optimized code
Reverts dotnet#33021, which was a reversion of dotnet#2107. Fix the IG boundary sensitivity for debug emission. Allow debug info to be summarized in a way that makes it amenable to analyze with our jitutils tooling (namely, `jit-analyze`).
1 parent 4ef07c2 commit 34e6ac5

File tree

6 files changed

+71
-10
lines changed

6 files changed

+71
-10
lines changed

src/coreclr/src/jit/codegencommon.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12314,9 +12314,28 @@ void CodeGenInterface::VariableLiveKeeper::VariableLiveDescriptor::startLiveRang
1231412314
// Is the first "VariableLiveRange" or the previous one has been closed so its "m_EndEmitLocation" is valid
1231512315
noway_assert(m_VariableLiveRanges->empty() || m_VariableLiveRanges->back().m_EndEmitLocation.Valid());
1231612316

12317-
// Creates new live range with invalid end
12318-
m_VariableLiveRanges->emplace_back(varLocation, emitLocation(), emitLocation());
12319-
m_VariableLiveRanges->back().m_StartEmitLocation.CaptureLocation(emit);
12317+
if (!m_VariableLiveRanges->empty() &&
12318+
siVarLoc::Equals(&varLocation, &(m_VariableLiveRanges->back().m_VarLocation)) &&
12319+
m_VariableLiveRanges->back().m_EndEmitLocation.IsPreviousInsNum(emit))
12320+
{
12321+
JITDUMP("Extending debug range...\n");
12322+
12323+
// The variable is being born just after the instruction at which it died.
12324+
// In this case, i.e. an update of the variable's value, we coalesce the live ranges.
12325+
m_VariableLiveRanges->back().m_EndEmitLocation.Init();
12326+
}
12327+
else
12328+
{
12329+
JITDUMP("New debug range: %s\n",
12330+
m_VariableLiveRanges->empty()
12331+
? "first"
12332+
: siVarLoc::Equals(&varLocation, &(m_VariableLiveRanges->back().m_VarLocation))
12333+
? "new var or location"
12334+
: "not adjacent");
12335+
// Creates new live range with invalid end
12336+
m_VariableLiveRanges->emplace_back(varLocation, emitLocation(), emitLocation());
12337+
m_VariableLiveRanges->back().m_StartEmitLocation.CaptureLocation(emit);
12338+
}
1232012339

1232112340
#ifdef DEBUG
1232212341
if (!m_VariableLifeBarrier->hasLiveRangesToDump())
@@ -12707,7 +12726,7 @@ void CodeGenInterface::VariableLiveKeeper::siEndAllVariableLiveRange(VARSET_VALA
1270712726
// Notes:
1270812727
// This overload exists for the case we are jitting code compiled in
1270912728
// debug mode. When that happen we don't have variable liveness info
12710-
// as "BaiscBlock::bbLiveIn" or "BaiscBlock::bbLiveOut" and there is no
12729+
// as "BasicBlock::bbLiveIn" or "BasicBlock::bbLiveOut" and there is no
1271112730
// tracked variable.
1271212731
//
1271312732
void CodeGenInterface::VariableLiveKeeper::siEndAllVariableLiveRange()

src/coreclr/src/jit/codegeninterface.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
#include "treelifeupdater.h"
2727
#include "emit.h"
2828

29-
#if 1
29+
#if 0
3030
// Enable USING_SCOPE_INFO flag to use psiScope/siScope info to report variables' locations.
3131
#define USING_SCOPE_INFO
3232
#endif
33-
#if 0
33+
#if 1
3434
// Enable USING_VARIABLE_LIVE_RANGE flag to use VariableLiveRange info to report variables' locations.
3535
// Note: if both USING_SCOPE_INFO and USING_VARIABLE_LIVE_RANGE are defined, then USING_SCOPE_INFO
3636
// information is reported to the debugger.

src/coreclr/src/jit/ee_il_dll.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,8 +835,21 @@ void Compiler::eeDispVar(ICorDebugInfo::NativeVarInfo* var)
835835
// Same parameters as ICorStaticInfo::setVars().
836836
void Compiler::eeDispVars(CORINFO_METHOD_HANDLE ftn, ULONG32 cVars, ICorDebugInfo::NativeVarInfo* vars)
837837
{
838-
printf("*************** Variable debug info\n");
839-
printf("%d live ranges\n", cVars);
838+
// Estimate number of unique vars with debug info
839+
//
840+
ALLVARSET_TP uniqueVars(AllVarSetOps::MakeEmpty(this));
841+
for (unsigned i = 0; i < cVars; i++)
842+
{
843+
// ignore "special vars" and out of bounds vars
844+
if ((((int)vars[i].varNumber) >= 0) && (vars[i].varNumber < lclMAX_ALLSET_TRACKED))
845+
{
846+
AllVarSetOps::AddElemD(this, uniqueVars, vars[i].varNumber);
847+
}
848+
}
849+
850+
printf("; Variable debug info: %d live ranges, %d vars for method %s\n", cVars,
851+
AllVarSetOps::Count(this, uniqueVars), info.compFullName);
852+
840853
for (unsigned i = 0; i < cVars; i++)
841854
{
842855
eeDispVar(&vars[i]);

src/coreclr/src/jit/emit.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,33 @@ UNATIVE_OFFSET emitLocation::GetFuncletPrologOffset(emitter* emit) const
6565
return emit->emitCurIGsize;
6666
}
6767

68+
//------------------------------------------------------------------------
69+
// IsPreviousInsNum: Returns true if the emitter is on the next instruction
70+
// of the same group as this emitLocation, or the first instruction of
71+
// an extension of this location's IG.
72+
//
73+
// Arguments:
74+
// emit - an emitter* instance
75+
//
76+
bool emitLocation::IsPreviousInsNum(const emitter* emit) const
77+
{
78+
assert(Valid());
79+
80+
// Within the same IG?
81+
if (ig == emit->emitCurIG)
82+
{
83+
return (emitGetInsNumFromCodePos(codePos) == emitGetInsNumFromCodePos(emit->emitCurOffset()) - 1);
84+
}
85+
86+
// Spanning an IG boundary?
87+
if (ig->igNext == emit->emitCurIG)
88+
{
89+
return (emitGetInsNumFromCodePos(codePos) == ig->igInsCnt) && (emit->emitCurIGinsCnt == 1);
90+
}
91+
92+
return false;
93+
}
94+
6895
#ifdef DEBUG
6996
void emitLocation::Print(LONG compMethodID) const
7097
{

src/coreclr/src/jit/emit.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ class emitLocation
191191

192192
UNATIVE_OFFSET GetFuncletPrologOffset(emitter* emit) const;
193193

194+
bool emitLocation::IsPreviousInsNum(const emitter* emit) const;
195+
194196
#ifdef DEBUG
195197
void Print(LONG compMethodID) const;
196198
#endif // DEBUG
@@ -2386,7 +2388,7 @@ inline unsigned emitGetInsOfsFromCodePos(unsigned codePos)
23862388
return (codePos >> 16);
23872389
}
23882390

2389-
inline unsigned emitter::emitCurOffset()
2391+
inline unsigned emitter::emitCurOffset() const
23902392
{
23912393
unsigned codePos = emitCurIGinsCnt + (emitCurIGsize << 16);
23922394

src/coreclr/src/jit/emitpub.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void emitFinishPrologEpilogGeneration();
6565
/************************************************************************/
6666

6767
void* emitCurBlock();
68-
unsigned emitCurOffset();
68+
unsigned emitCurOffset() const;
6969

7070
UNATIVE_OFFSET emitCodeOffset(void* blockPtr, unsigned codeOffs);
7171

0 commit comments

Comments
 (0)