Skip to content
Closed
Changes from 5 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
45 changes: 42 additions & 3 deletions src/coreclr/jit/fgbasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,35 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, Fixed
compInlineResult->Note(InlineObservation::CALLEE_BEGIN_OPCODE_SCAN);
}

auto doesMethodLookLikeWrapper = [](const BYTE* codeAddrNext, const BYTE* codeEndp) -> bool {
OPCODE opcodeNext = (OPCODE)getU1LittleEndian(codeAddrNext);
if (opcodeNext == CEE_LDLOC_0 || opcodeNext == CEE_LDLOC_1 || opcodeNext == CEE_LDLOC_2 ||
opcodeNext == CEE_LDLOC_3 || opcodeNext == CEE_LDLOC_S)
{
codeAddrNext += opcodeSizes[opcodeNext] + sizeof(int8_t);
if (codeAddrNext >= codeEndp)
{
return false;
}
opcodeNext = (OPCODE)getU1LittleEndian(codeAddrNext);
}
if (opcodeNext == CEE_BOX)
{
codeAddrNext += opcodeSizes[opcodeNext] + sizeof(int8_t);
if (codeAddrNext >= codeEndp)
{
return false;
}
opcodeNext = (OPCODE)getU1LittleEndian(codeAddrNext);
}
if (opcodeNext == CEE_RET)
{
// Assume it is a wrapper method if it is followed by {ldloc, box}, ret.
return true;
}
return false;
};

CORINFO_RESOLVED_TOKEN resolvedToken;

OPCODE opcode = CEE_NOP;
Expand Down Expand Up @@ -1608,10 +1637,8 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, Fixed
}
}

if ((codeAddr < codeEndp - sz) && (OPCODE)getU1LittleEndian(codeAddr + sz) == CEE_RET)
if ((codeAddr < codeEndp - sz) && doesMethodLookLikeWrapper(codeAddr + sz, codeEndp))
Copy link
Member

Choose a reason for hiding this comment

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

Given it's called only here, it only supports

call
ldloc
box
ret

?

is this some specific pattern we need to support?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope. it's just that doesMethodLookLikeWrapper can return true for a single ret so that it can be reused here.

{
// If the method has a call followed by a ret, assume that
// it is a wrapper method.
compInlineResult->Note(InlineObservation::CALLEE_LOOKS_LIKE_WRAPPER);
}

Expand All @@ -1624,6 +1651,18 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, Fixed
}
break;

case CEE_NEWARR:
case CEE_NEWOBJ:
case CEE_INITOBJ:
{
if (makeInlineObservations && (codeAddr < codeEndp - sz) &&
doesMethodLookLikeWrapper(codeAddr + sz, codeEndp))
{
compInlineResult->Note(InlineObservation::CALLEE_LOOKS_LIKE_WRAPPER);
}
break;
}

case CEE_LDIND_I1:
case CEE_LDIND_U1:
case CEE_LDIND_I2:
Expand Down
Loading