-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[GlobalISel] Expand IRTranslator docs. NFC #89186
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add some more details about how calls are lowered and what APIs are available.
@llvm/pr-subscribers-llvm-globalisel Author: Diana Picus (rovka) ChangesAdd some more details about how calls are lowered and what APIs are available. Full diff: https://github.com/llvm/llvm-project/pull/89186.diff 2 Files Affected:
diff --git a/llvm/docs/GlobalISel/IRTranslator.rst b/llvm/docs/GlobalISel/IRTranslator.rst
index 6268ebb4f4a1d7..3e15d4ba1df312 100644
--- a/llvm/docs/GlobalISel/IRTranslator.rst
+++ b/llvm/docs/GlobalISel/IRTranslator.rst
@@ -6,7 +6,7 @@ IRTranslator
.. contents::
:local:
-This pass translates the input LLVM-IR ``Function`` to a GMIR
+This pass translates the input LLVM-IR ``Function`` to a :doc:`GMIR`
``MachineFunction``. This is typically a direct translation but does
occasionally get a bit more involved. For example:
@@ -51,8 +51,37 @@ Translating Function Calls
The ``IRTranslator`` also implements the ABI's calling convention by lowering
calls, returns, and arguments to the appropriate physical register usage and
-instruction sequences. This is achieved using the ``CallLowering``
-implementation,
+instruction sequences. This is achieved using the ``CallLowering`` interface,
+which provides several hooks that targets should implement:
+``lowerFormalArguments``, ``lowerReturn``, ``lowerCall`` etc.
+
+In essence, all of these hooks need to find a way to move the argument/return
+values between the virtual registers used in the rest of the function and either
+physical registers or the stack, as dictated by the ABI. This may involve
+splitting large types into smaller ones, introducing sign/zero extensions etc.
+In order to share as much of this code as possible between the different
+backends, ``CallLowering`` makes available a few helpers and interfaces:
+
+* ``ArgInfo`` - used for formal arguments, but also return values, call
+ parameters and call returns; contains info such as the IR type, the virtual
+ registers etc; large values will likely have to be split into several
+ ``ArgInfo`` objects (``CallLowering::splitToValueTypes`` can help with that);
+
+* ``ValueAssigner`` - uses a ``CCAssignFn``, usually generated by TableGen (see
+ :ref:`backend-calling-convs`), to decide where to put each
+ ``ArgInfo`` (physical register or stack); backends can use the provided
+ ``IncomingValueAssigner`` (for formal arguments and call results) and
+ ``OutgoingValueAssigner`` (for call paramters and function returns), but it's
+ also possible to subclass them;
+
+* ``ValueHandler`` - inserts the necessary instructions for putting each value
+ where it belongs; it has pure virtual methods for assigning values to
+ registers or to addresses, and a host of other helpers;
+
+* ``determineAndHandleAssignments`` (or for more fine grained control,
+ ``determineAssignments`` and ``handleAssignments``) - contains some boilerplate
+ for invoking a given ``ValueAssigner`` and ``ValueHandler`` on a series of
+ ``ArgInfo`` objects.
.. _irtranslator-aggregates:
diff --git a/llvm/docs/WritingAnLLVMBackend.rst b/llvm/docs/WritingAnLLVMBackend.rst
index 31ebc6204c98fa..f1f07e4681d509 100644
--- a/llvm/docs/WritingAnLLVMBackend.rst
+++ b/llvm/docs/WritingAnLLVMBackend.rst
@@ -1503,6 +1503,8 @@ non-v9 SPARC implementations.
if (TM.getSubtarget<SparcSubtarget>().isV9())
setOperationAction(ISD::CTPOP, MVT::i32, Legal);
+.. _backend-calling-convs:
+
Calling Conventions
-------------------
|
arsenm
approved these changes
Apr 18, 2024
jayfoad
reviewed
Apr 18, 2024
:ref:`backend-calling-convs`), to decide where to put each | ||
``ArgInfo`` (physical register or stack); backends can use the provided | ||
``IncomingValueAssigner`` (for formal arguments and call results) and | ||
``OutgoingValueAssigner`` (for call paramters and function returns), but it's |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo "parameters"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add some more details about how calls are lowered and what APIs are available.