Skip to content

Conversation

@jtschuster
Copy link
Member

Adds a SetAsyncCallContinuationArg intrinsic to be used in async resumption stubs created by crossgen and ilc. This would enable the resumption stubs to emit a regular call to the async method rather than ldftn+calli or ldc+calli. The runtime stashes the continuation to be passed as a hidden parameter to the next async call.

@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Nov 10, 2025
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@jkotas
Copy link
Member

jkotas commented Nov 10, 2025

Can you switch CoreCLR to use this intrinsic to validate that it actually works?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a new SetAsyncCallContinuationArg intrinsic to support more efficient async resumption stubs in crossgen and ILC. The intrinsic allows resumption stubs to emit regular calls to async methods instead of using indirect calls (ldftn+calli or ldc+calli) by storing the continuation argument in a local variable that gets passed as a hidden parameter.

Key changes:

  • Adds the SetAsyncCallContinuationArg intrinsic to the JIT's intrinsic catalog
  • Implements JIT support to store continuation arguments in a temporary variable and pass them to async calls
  • Updates the async liveness analysis to exclude the new temporary variable from capture requirements

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/coreclr/jit/namedintrinsiclist.h Adds enum entry for the new intrinsic
src/coreclr/jit/importercalls.cpp Implements intrinsic expansion and modifies async call argument passing to use stored continuation
src/coreclr/jit/compiler.h Declares the compiler field for tracking the continuation argument variable
src/coreclr/jit/async.cpp Excludes the continuation argument variable from async capture
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs Defines the new intrinsic method and changes AsyncCallContinuation visibility from private to internal

Comment on lines +878 to +880
GenTree* arg = lvaNextAsyncCallContArgVar != BAD_VAR_NUM
? (GenTree*)gtNewLclVarNode(lvaNextAsyncCallContArgVar)
: gtNewNull();
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

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

The conditional logic to determine the async continuation argument is duplicated (appears twice at lines 878-880 and 897-899). Consider extracting this logic into a helper method like GetAsyncContinuationArg() to avoid duplication and improve maintainability.

Copilot uses AI. Check for mistakes.
@jtschuster jtschuster marked this pull request as draft November 10, 2025 21:25
pCode->EmitLDIND_I();
}

pCode->EmitCALLI(pCode->GetSigToken(calliSig.GetRawSig(), calliSig.GetRawSigLen()), numArgs, msig.IsReturnTypeVoid() ? 0 : 1);
Copy link
Member

Choose a reason for hiding this comment

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

calliSig can be deleted.

if (ncv.GetOptimizationTier() == NativeCodeVersion::OptimizationTier1OSR)
{
#ifdef FEATURE_ON_STACK_REPLACEMENT
// The OSR version needs to resume in the tier0 version. The tier0
Copy link
Member

Choose a reason for hiding this comment

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

This special-case needs to move to GetCallInfo or getFunctionEntryPoint

… is a resumption stub and the callee is async.
@VSadov
Copy link
Member

VSadov commented Nov 20, 2025

This PR seems superseded by #121799

@jkotas jkotas closed this Nov 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants