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

Add pMethod param to getHelperFtn EE-JIT API #110267

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Nov 29, 2024

This change is part of "Allow inlining for helper methods" effort, I already implemented it locally, but it turns out to be a lot of changes so I split it into 3 PRs for simpler code review

  • Add JIT-EE API to query real CORINFO_METHOD_HANDLE out of a helper id (this PR)
  • Refactor GenTreeCall::gtCallMethHnd (currently, we store helper id in it, I want it to be always a real method handle and the actual id is stored separately, fortunately, we have a room for that in GenTreeCall) -- quite a lot of changes.
  • Minor changes in the inliner to allow helper calls

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Nov 29, 2024
Copy link
Contributor

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

@EgorBo
Copy link
Member Author

EgorBo commented Nov 29, 2024

PTAL @jkotas, no functional changes (yet).

@EgorBo EgorBo requested a review from jkotas November 29, 2024 14:27
@am11
Copy link
Member

am11 commented Nov 29, 2024

@EgorBo, thank you for this. Sound like it will help existing helpers as well. 👍

Minor changes in the inliner to allow helper calls

Would it inline FCall in managed -> fcall transition? Current (main branch) codegen for DIV on win-x86 is approximately https://godbolt.org/z/P8Pnx4Tdn.

@EgorBo
Copy link
Member Author

EgorBo commented Nov 29, 2024

Would it inline FCall in managed -> fcall transition?

I am not sure I understand the question. An FCall that redirects to managed? Why is it an FCall in the first place?

@am11
Copy link
Member

am11 commented Nov 29, 2024

Would it inline FCall in managed -> fcall transition?

I am not sure I understand the question. An FCall that redirects to managed? Why is it an FCall in the first place?

In main, it's using native helpers. With #109087, it is using managed helpers which make fcall to get CRT div/mod impl. Managed call is taking care of overflow/divbyzero checks.

@EgorBo
Copy link
Member Author

EgorBo commented Nov 29, 2024

Would it inline FCall in managed -> fcall transition?

I am not sure I understand the question. An FCall that redirects to managed? Why is it an FCall in the first place?

In main, it's using native helpers. With #109087, it is using managed helpers which make fcall to get CRT div/mod impl. Managed call is taking care of overflow/divbyzero checks.

Then yes, it should be handled, because JIT knows these methods as helpers.

@@ -3063,7 +3063,8 @@ class ICorDynamicInfo : public ICorStaticInfo
// return the native entry point to an EE helper (see CorInfoHelpFunc)
virtual void* getHelperFtn (
Copy link
Member

Choose a reason for hiding this comment

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

Is the JIT going to use both the code pointer and the method handle when callling this method with non-null pMethod?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is the JIT going to use both the code pointer and the method handle when callling this method with non-null pMethod?

No, are you implying that it's better to have a separate API?

Copy link
Member

@jkotas jkotas Dec 2, 2024

Choose a reason for hiding this comment

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

It does not have to be a separate API. It can be one API with two optional out args. Using ppIndirection to indicate whether you are interested in the actual entrypoint would look odd. I am thinking something like this may be the best shape:

void getHelperFtn(CorInfoHelpFunc ftnNum, 
    CORINFO_CONST_LOOKUP* addr, // optional [OUT]
    CORINFO_METHOD_HANDLE* method) // optional [OUT]

MichalStrehovsky added a commit to MichalStrehovsky/runtime that referenced this pull request Dec 5, 2024
We had indirections set up where we'd `RuntimeExport` a method under a symbolic name and then `RuntimeImport` it elsewhere (or call the export from JIT-generated code).

Most of this was motivated by the old Redhawk layering where things like casting and interface dispatch were part of Runtime.Base and not part of CoreLib. Since we decided if we ever reintroduce a Runtime.Base, we wouldn't have casting in it, this indirection will no longer be needed.

Motivated by dotnet#110267 (and also the reason why I'm only doing it for `RuntimeExport`s used from the JIT right now). Once that PR gets in, calling methods through `RuntimeExport`s would actually become a bigger deoptimization than it is now.
MichalStrehovsky added a commit that referenced this pull request Dec 9, 2024
We had indirections set up where we'd `RuntimeExport` a method under a symbolic name and then `RuntimeImport` it elsewhere (or call the export from JIT-generated code).

Most of this was motivated by the old Redhawk layering where things like casting and interface dispatch were part of Runtime.Base and not part of CoreLib. Since we decided if we ever reintroduce a Runtime.Base, we wouldn't have casting in it, this indirection will no longer be needed.

Motivated by #110267 (and also the reason why I'm only doing it for `RuntimeExport`s used from the JIT right now). Once that PR gets in, calling methods through `RuntimeExport`s would actually become a bigger deoptimization than it is now.
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