Skip to content

Commit

Permalink
Start tracking debug info for inlined statements (#61220)
Browse files Browse the repository at this point in the history
* Refactor IL_OFFSETX into DebugInfo

Remove IL_OFFSETX in favor of a DebugInfo structure. Previously we were
packing extra information into the upper bits of IL_OFFSETX, which are
now separate bit fields on a new ILLocation structure. DebugInfo
contains an ILLocation and also an inline context, which will be used in
the future when tracking debug info inside of inlinees.

Another problem with IL_OFFSETX was that there were several sentinel
values used to describe prologs, epilogs and no mappings. However these
were only used in code-gen, so refactor codegen to track this separately
instead of having to muddle it into IL_OFFSETX. This makes it clearer
what we can expect from IL offsets during JIT.

This change is no-diff and PIN also shows that TP is not negatively
affected; in fact, there seems to be a small TP gain, maybe because we
don't have to handle sentinel values anymore.

* Track debug information in statements from inlinees

Add support for tracking debug information in statements coming from
inlinees. Changes:

* Turn on compDbgInfo in inlinees. We use the implicit boundaries from
  the inline root, but we do not use any explicit boundaries. That is,
  we do not query the EE for explicit boundaries for the inlinee.

* Create InlineContexts eagerly and use them during import. All
  DebugInfo created in the JIT is in a "consistent" state, meaning that
  we never see an IL location set without a corresponding inline
  context. This was difficult before as InlineContexts would be created
  quite late, after the importer for the inlinee had run. We now create
  it eagerly and attach it to debug info during importation. Later, when
  we figure out whether an inline succeeded or not, we mark it as
  succeeded or failed.

* Stop carrying InlineContext around unconditionally in Statement. The
  inline context is now only part of the debug info, which may not be
  set. Inlining needs the inline context to create new inline contexts
  and to check for recursive inlines. Previously it retrieved it from
  the inline statement, but due to the above change we now have to get
  it from somewhere else. To do this we now keep it unconditionally
  together with InlineCandidateInfo so that we can retrieve it later.

* Validate all created debug information when associated with a
  statement. This is done by creating a bitvector containing IL
  locations that mark the beginning of IL instructions, and validating
  that all IL offsets point to these when Statement::SetDebugInfo is
  called.

* While we track debug info in statements from inlinees, the runtime
  side is still not hooked up. Currently we track the information until
  we get to rationalize, where we normalize all debug info back to the
  root inserted as GT_IL_OFFSET nodes. The change is free of any diffs
  due to this normalization. We also track IL offsets as part of basic
  blocks: these are also normalized to be in the root.
  • Loading branch information
jakobbotsch authored Nov 9, 2021
1 parent 8d93078 commit 731364d
Show file tree
Hide file tree
Showing 40 changed files with 1,098 additions and 1,007 deletions.
2 changes: 1 addition & 1 deletion src/coreclr/inc/cordebuginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ICorDebugInfo
struct OffsetMapping
{
uint32_t nativeOffset;
uint32_t ilOffset;
uint32_t ilOffset; // IL offset or one of the special values in MappingTypes
SourceTypes source; // The debugger needs this so that
// we don't put Edit and Continue breakpoints where
// the stack isn't empty. We can put regular breakpoints
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/jit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ set( JIT_SOURCES
codegenlinear.cpp
compiler.cpp
copyprop.cpp
debuginfo.cpp
disasm.cpp
earlyprop.cpp
ee_il_dll.cpp
Expand Down Expand Up @@ -178,6 +179,7 @@ if (CLR_CMAKE_TARGET_WIN32)
compmemkind.h
compphases.h
dataflow.h
debuginfo.h
decomposelongs.h
disasm.h
emit.h
Expand Down
17 changes: 9 additions & 8 deletions src/coreclr/jit/codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,10 @@ class CodeGen final : public CodeGenInterface
CORINFO_METHOD_HANDLE methHnd,
INDEBUG_LDISASM_COMMA(CORINFO_SIG_INFO* sigInfo)
void* addr
X86_ARG(int argSize),
X86_ARG(int argSize),
emitAttr retSize
MULTIREG_HAS_SECOND_GC_RET_ONLY_ARG(emitAttr secondRetSize),
IL_OFFSETX ilOffset,
const DebugInfo& di,
regNumber base,
bool isJump);
// clang-format on
Expand All @@ -447,10 +447,10 @@ class CodeGen final : public CodeGenInterface
CORINFO_METHOD_HANDLE methHnd,
INDEBUG_LDISASM_COMMA(CORINFO_SIG_INFO* sigInfo)
GenTreeIndir* indir
X86_ARG(int argSize),
X86_ARG(int argSize),
emitAttr retSize
MULTIREG_HAS_SECOND_GC_RET_ONLY_ARG(emitAttr secondRetSize),
IL_OFFSETX ilOffset,
const DebugInfo& di,
bool isJump);
// clang-format on

Expand Down Expand Up @@ -552,15 +552,16 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/

#ifdef DEBUG
void genIPmappingDisp(unsigned mappingNum, Compiler::IPmappingDsc* ipMapping);
void genIPmappingDisp(unsigned mappingNum, IPmappingDsc* ipMapping);
void genIPmappingListDisp();
#endif // DEBUG

void genIPmappingAdd(IL_OFFSETX offset, bool isLabel);
void genIPmappingAddToFront(IL_OFFSETX offset);
IPmappingDsc* genCreateIPMapping(IPmappingDscKind kind, const DebugInfo& di, bool isLabel);
void genIPmappingAdd(IPmappingDscKind kind, const DebugInfo& di, bool isLabel);
void genIPmappingAddToFront(IPmappingDscKind kind, const DebugInfo& di, bool isLabel);
void genIPmappingGen();

void genEnsureCodeEmitted(IL_OFFSETX offsx);
void genEnsureCodeEmitted(const DebugInfo& di);

//-------------------------------------------------------------------------
// scope info for the variables
Expand Down
5 changes: 2 additions & 3 deletions src/coreclr/jit/codegenarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1632,8 +1632,7 @@ void CodeGen::genEmitHelperCall(unsigned helper, int argSize, emitAttr retSize,
GetEmitter()->emitIns_Call(emitter::EC_INDIR_R, compiler->eeFindHelper(helper),
INDEBUG_LDISASM_COMMA(nullptr) NULL, // addr
argSize, retSize, gcInfo.gcVarPtrSetCur, gcInfo.gcRegGCrefSetCur,
gcInfo.gcRegByrefSetCur,
BAD_IL_OFFSET, // ilOffset
gcInfo.gcRegByrefSetCur, DebugInfo(),
callTargetReg, // ireg
REG_NA, 0, 0, // xreg, xmul, disp
false // isJump
Expand All @@ -1643,7 +1642,7 @@ void CodeGen::genEmitHelperCall(unsigned helper, int argSize, emitAttr retSize,
{
GetEmitter()->emitIns_Call(emitter::EC_FUNC_TOKEN, compiler->eeFindHelper(helper),
INDEBUG_LDISASM_COMMA(nullptr) addr, argSize, retSize, gcInfo.gcVarPtrSetCur,
gcInfo.gcRegGCrefSetCur, gcInfo.gcRegByrefSetCur, BAD_IL_OFFSET, REG_NA, REG_NA, 0,
gcInfo.gcRegGCrefSetCur, gcInfo.gcRegByrefSetCur, DebugInfo(), REG_NA, REG_NA, 0,
0, /* ilOffset, ireg, xreg, xmul, disp */
false /* isJump */
);
Expand Down
7 changes: 3 additions & 4 deletions src/coreclr/jit/codegenarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3846,10 +3846,9 @@ void CodeGen::genEmitHelperCall(unsigned helper, int argSize, emitAttr retSize,

GetEmitter()->emitIns_Call(callType, compiler->eeFindHelper(helper), INDEBUG_LDISASM_COMMA(nullptr) addr, argSize,
retSize, EA_UNKNOWN, gcInfo.gcVarPtrSetCur, gcInfo.gcRegGCrefSetCur,
gcInfo.gcRegByrefSetCur, BAD_IL_OFFSET, /* IL offset */
callTarget, /* ireg */
REG_NA, 0, 0, /* xreg, xmul, disp */
false /* isJump */
gcInfo.gcRegByrefSetCur, DebugInfo(), callTarget, /* ireg */
REG_NA, 0, 0, /* xreg, xmul, disp */
false /* isJump */
);

regMaskTP killMask = compiler->compHelperCallKillSet((CorInfoHelpFunc)helper);
Expand Down
18 changes: 8 additions & 10 deletions src/coreclr/jit/codegenarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2463,16 +2463,14 @@ void CodeGen::genCallInstruction(GenTreeCall* call)
}
}

// We need to propagate the IL offset information to the call instruction, so we can emit
DebugInfo di;
// We need to propagate the debug information to the call instruction, so we can emit
// an IL to native mapping record for the call, to support managed return value debugging.
// We don't want tail call helper calls that were converted from normal calls to get a record,
// so we skip this hash table lookup logic in that case.

IL_OFFSETX ilOffset = BAD_IL_OFFSET;

if (compiler->opts.compDbgInfo && compiler->genCallSite2ILOffsetMap != nullptr && !call->IsTailCall())
if (compiler->opts.compDbgInfo && compiler->genCallSite2DebugInfoMap != nullptr && !call->IsTailCall())
{
(void)compiler->genCallSite2ILOffsetMap->Lookup(call, &ilOffset);
(void)compiler->genCallSite2DebugInfoMap->Lookup(call, &di);
}

CORINFO_SIG_INFO* sigInfo = nullptr;
Expand Down Expand Up @@ -2512,7 +2510,7 @@ void CodeGen::genCallInstruction(GenTreeCall* call)
nullptr, // addr
retSize
MULTIREG_HAS_SECOND_GC_RET_ONLY_ARG(secondRetSize),
ilOffset,
di,
target->GetRegNum(),
call->IsFastTailCall());
// clang-format on
Expand Down Expand Up @@ -2552,7 +2550,7 @@ void CodeGen::genCallInstruction(GenTreeCall* call)
nullptr, // addr
retSize
MULTIREG_HAS_SECOND_GC_RET_ONLY_ARG(secondRetSize),
ilOffset,
di,
targetAddrReg,
call->IsFastTailCall());
// clang-format on
Expand Down Expand Up @@ -2600,7 +2598,7 @@ void CodeGen::genCallInstruction(GenTreeCall* call)
INDEBUG_LDISASM_COMMA(sigInfo)
NULL,
retSize,
ilOffset,
di,
tmpReg,
call->IsFastTailCall());
// clang-format on
Expand All @@ -2615,7 +2613,7 @@ void CodeGen::genCallInstruction(GenTreeCall* call)
addr,
retSize
MULTIREG_HAS_SECOND_GC_RET_ONLY_ARG(secondRetSize),
ilOffset,
di,
REG_NA,
call->IsFastTailCall());
// clang-format on
Expand Down
Loading

0 comments on commit 731364d

Please sign in to comment.