Skip to content
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

JIT: Rework retbuf handling during inlining #112010

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5210,7 +5210,7 @@ class Compiler
InlineCandidateInfo** ppInlineCandidateInfo,
InlineResult* inlineResult);

void impInlineRecordArgInfo(InlineInfo* pInlineInfo, CallArg* arg, unsigned argNum, InlineResult* inlineResult);
void impInlineRecordArgInfo(InlineInfo* pInlineInfo, CallArg* arg, InlArgInfo* argInfo, InlineResult* inlineResult);

void impInlineInitVars(InlineInfo* pInlineInfo);

Expand Down
42 changes: 27 additions & 15 deletions src/coreclr/jit/fginline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,7 @@ void Compiler::fgInvokeInlineeCompiler(GenTreeCall* call, InlineResult* inlineRe
inlineInfo.retExprClassHndIsExact = false;
inlineInfo.inlineResult = inlineResult;
inlineInfo.inlInstParamArgInfo = nullptr;
inlineInfo.inlRetBufferArgInfo = nullptr;
#ifdef FEATURE_SIMD
inlineInfo.hasSIMDTypeArgLocalOrReturn = false;
#endif // FEATURE_SIMD
Expand Down Expand Up @@ -1870,15 +1871,11 @@ void Compiler::fgInsertInlineeArgument(
DISPSTMT(*afterStmt);
}
}
else if (argInfo.argIsByRefToStructLocal)
{
// Do nothing. Arg was directly substituted as we read
// the inlinee.
}
else
{
// The argument is either not used or a const or lcl var
noway_assert(!argInfo.argIsUsed || argInfo.argIsInvariant || argInfo.argIsLclVar);
// The argument is either not used or of a shape we allowed to be duplicated
noway_assert(!argInfo.argIsUsed || argInfo.argIsInvariant || argInfo.argIsLclVar ||
argInfo.argDuplicateComplex);
noway_assert((argInfo.argIsLclVar == 0) ==
(argNode->gtOper != GT_LCL_VAR || (argNode->gtFlags & GTF_GLOB_REF)));

Expand Down Expand Up @@ -2045,22 +2042,37 @@ Statement* Compiler::fgInlinePrependStatements(InlineInfo* inlineInfo)
}
}

// Append the InstParam
if (inlineInfo->inlInstParamArgInfo != nullptr)
#ifdef DEBUG
if (call->gtArgs.CountArgs() > 0)
{
fgInsertInlineeArgument(*inlineInfo->inlInstParamArgInfo, block, &afterStmt, &newStmt, callDI);
JITDUMP("\nArguments setup:\n");
}
#endif

// Treat arguments that had to be assigned to temps
if (inlineInfo->argCnt)
unsigned ilArgNum = 0;
for (CallArg& arg : call->gtArgs.Args())
{
JITDUMP("\nArguments setup:\n");
for (unsigned argNum = 0; argNum < inlineInfo->argCnt; argNum++)
InlArgInfo* argInfo = nullptr;
switch (arg.GetWellKnownArg())
{
fgInsertInlineeArgument(inlArgInfo[argNum], block, &afterStmt, &newStmt, callDI);
case WellKnownArg::RetBuffer:
argInfo = inlineInfo->inlRetBufferArgInfo;
break;
case WellKnownArg::InstParam:
argInfo = inlineInfo->inlInstParamArgInfo;
break;
default:
assert(ilArgNum < inlineInfo->argCnt);
argInfo = &inlineInfo->inlArgInfo[ilArgNum++];
break;
}

assert(argInfo != nullptr);
fgInsertInlineeArgument(*argInfo, block, &afterStmt, &newStmt, callDI);
}

assert(ilArgNum == inlineInfo->argCnt);

// Add the CCTOR check if asked for.
// Note: We no longer do the optimization that is done before by staticAccessedFirstUsingHelper in the old inliner.
// Therefore we might prepend redundant call to HELPER.CORINFO_HELP_GETSHARED_NONGCSTATIC_BASE
Expand Down
31 changes: 31 additions & 0 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,37 @@ unsigned CallArgs::GetIndex(CallArg* arg)
return (unsigned)-1;
}

//---------------------------------------------------------------
// GetIndex: Get the user arg index for the specified argument (IL index).
//
// Parameters:
// arg - The argument to obtain the index of.
//
// Returns:
// The user index.
//
unsigned CallArgs::GetUserIndex(CallArg* arg)
{
unsigned i = 0;
for (CallArg& a : Args())
{
if (!a.IsUserArg())
{
continue;
}

if (&a == arg)
{
return i;
}

i++;
}

assert(!"Could not find argument in arg list");
return (unsigned)-1;
}

//---------------------------------------------------------------
// Reverse: Reverse the specified subrange of arguments.
//
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/gentree.h
Original file line number Diff line number Diff line change
Expand Up @@ -4920,6 +4920,7 @@ class CallArgs
CallArg* GetArgByIndex(unsigned index);
CallArg* GetUserArgByIndex(unsigned index);
unsigned GetIndex(CallArg* arg);
unsigned GetUserIndex(CallArg* arg);

bool IsEmpty() const
{
Expand Down
Loading
Loading