Skip to content

JIT: give inlinees their own EH table #112968

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 2 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 0 additions & 7 deletions src/coreclr/jit/fgbasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3513,13 +3513,6 @@ void Compiler::fgFindBasicBlocks()
return;
}

noway_assert(info.compXcptnsCount == 0);
compHndBBtab = impInlineInfo->InlinerCompiler->compHndBBtab;
compHndBBtabAllocCount =
impInlineInfo->InlinerCompiler->compHndBBtabAllocCount; // we probably only use the table, not add to it.
compHndBBtabCount = impInlineInfo->InlinerCompiler->compHndBBtabCount;
info.compXcptnsCount = impInlineInfo->InlinerCompiler->info.compXcptnsCount;

// Use a spill temp for the return value if there are multiple return blocks,
// or if the inlinee has GC ref locals.
if ((info.compRetNativeType != TYP_VOID) && ((fgReturnCount > 1) || impInlineInfo->HasGcRefLocals()))
Expand Down
47 changes: 21 additions & 26 deletions src/coreclr/jit/importercalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ var_types Compiler::impImportCall(OPCODE opcode,
{
if (IsTargetAbi(CORINFO_NATIVEAOT_ABI))
{
// See comment in impCheckForPInvokeCall
BasicBlock* block = compIsForInlining() ? impInlineInfo->iciBlock : compCurBB;
if (info.compCompHnd->convertPInvokeCalliToCall(pResolvedToken, !impCanPInvokeInlineCallSite(block)))
if (info.compCompHnd->convertPInvokeCalliToCall(pResolvedToken, !impCanPInvokeInlineCallSite(compCurBB)))
{
eeGetCallInfo(pResolvedToken, nullptr, CORINFO_CALLINFO_ALLOWINSTPARAM, callInfo);
return impImportCall(CEE_CALL, pResolvedToken, nullptr, nullptr, prefixFlags, callInfo, rawILOffset);
Expand Down Expand Up @@ -633,17 +631,9 @@ var_types Compiler::impImportCall(OPCODE opcode,
}

//--------------------------- Inline NDirect ------------------------------

// For inline cases we technically should look at both the current
// block and the call site block (or just the latter if we've
// fused the EH trees). However the block-related checks pertain to
// EH and we currently won't inline a method with EH. So for
// inlinees, just checking the call site block is sufficient.
{
// New lexical block here to avoid compilation errors because of GOTOs.
BasicBlock* block = compIsForInlining() ? impInlineInfo->iciBlock : compCurBB;
impCheckForPInvokeCall(call->AsCall(), methHnd, sig, mflags, block);
}
// If this is a call to a PInvoke method, we may be able to inline the invocation frame.
//
impCheckForPInvokeCall(call->AsCall(), methHnd, sig, mflags, compCurBB);

#ifdef UNIX_X86_ABI
// On Unix x86 we use caller-cleaned convention.
Expand Down Expand Up @@ -6366,8 +6356,7 @@ bool Compiler::impCanPInvokeInline()
// from a call to see if the call qualifies as an inline pinvoke.
//
// Arguments:
// block - block containing the call, or for inlinees, block
// containing the call being inlined
// block - block containing the call
//
// Return Value:
// true if this call can legally qualify as an inline pinvoke, false otherwise
Expand All @@ -6384,9 +6373,9 @@ bool Compiler::impCanPInvokeInline()
// TODO-CQ: The inlining frame no longer has a GSCookie, so the common on this
// restriction is out of date. However, given that there is a comment
// about protecting the framelet, I'm not confident about what this
// is actually protecteing, so I don't want to remove this
// is actually protecting, so I don't want to remove this
// restriction without further analysis analysis.
// * We disable pinvoke inlini1ng inside handlers since the GSCookie
// * We disable pinvoke inlining inside handlers since the GSCookie
// is in the inlined Frame (see
// CORINFO_EE_INFO::InlinedCallFrameInfo::offsetOfGSCookie), but
// this would not protect framelets/return-address of handlers.
Expand Down Expand Up @@ -6438,12 +6427,17 @@ bool Compiler::impCanPInvokeInlineCallSite(BasicBlock* block)
return false;
}
}
}
#endif // USE_PER_FRAME_PINVOKE_INIT

if (!compIsForInlining())
{
return true;
}
#endif // USE_PER_FRAME_PINVOKE_INIT

return true;
// If inlining, verify conditions for the call site block too.
//
return impInlineRoot()->impCanPInvokeInlineCallSite(impInlineInfo->iciBlock);
}

//------------------------------------------------------------------------
Expand All @@ -6455,8 +6449,7 @@ bool Compiler::impCanPInvokeInlineCallSite(BasicBlock* block)
// methHnd - handle for the method being called (may be null)
// sig - signature of the method being called
// mflags - method flags for the method being called
// block - block containing the call, or for inlinees, block
// containing the call being inlined
// block - block containing the call
//
// Notes:
// Sets GTF_CALL_M_PINVOKE on the call for pinvokes.
Expand Down Expand Up @@ -6554,7 +6547,11 @@ void Compiler::impCheckForPInvokeCall(
// Size-speed tradeoff: don't use inline pinvoke at rarely
// executed call sites. The non-inline version is more
// compact.
if (block->isRunRarely())
//
// Zero-diff quirk: the first clause below should simply be block->isRunRarely()
//
if ((!compIsForInlining() && block->isRunRarely()) ||
(compIsForInlining() && impInlineInfo->iciBlock->isRunRarely()))
{
return;
}
Expand Down Expand Up @@ -7742,9 +7739,7 @@ void Compiler::impMarkInlineCandidateHelper(GenTreeCall* call,

if (methAttr & CORINFO_FLG_PINVOKE)
{
// See comment in impCheckForPInvokeCall
BasicBlock* block = compIsForInlining() ? impInlineInfo->iciBlock : compCurBB;
if (!impCanPInvokeInlineCallSite(block))
if (!impCanPInvokeInlineCallSite(compCurBB))
{
inlineResult->NoteFatal(InlineObservation::CALLSITE_PINVOKE_EH);
return;
Expand Down
Loading