@@ -6,7 +6,7 @@ IRTranslator
6
6
.. contents ::
7
7
:local:
8
8
9
- This pass translates the input LLVM-IR ``Function `` to a GMIR
9
+ This pass translates the input LLVM-IR ``Function `` to a :doc: ` GMIR `
10
10
``MachineFunction ``. This is typically a direct translation but does
11
11
occasionally get a bit more involved. For example:
12
12
@@ -51,8 +51,37 @@ Translating Function Calls
51
51
52
52
The ``IRTranslator `` also implements the ABI's calling convention by lowering
53
53
calls, returns, and arguments to the appropriate physical register usage and
54
- instruction sequences. This is achieved using the ``CallLowering ``
55
- implementation,
54
+ instruction sequences. This is achieved using the ``CallLowering `` interface,
55
+ which provides several hooks that targets should implement:
56
+ ``lowerFormalArguments ``, ``lowerReturn ``, ``lowerCall `` etc.
57
+
58
+ In essence, all of these hooks need to find a way to move the argument/return
59
+ values between the virtual registers used in the rest of the function and either
60
+ physical registers or the stack, as dictated by the ABI. This may involve
61
+ splitting large types into smaller ones, introducing sign/zero extensions etc.
62
+ In order to share as much of this code as possible between the different
63
+ backends, ``CallLowering `` makes available a few helpers and interfaces:
64
+
65
+ * ``ArgInfo `` - used for formal arguments, but also return values, actual
66
+ arguments and call results; contains info such as the IR type, the virtual
67
+ registers etc; large values will likely have to be split into several
68
+ ``ArgInfo `` objects (``CallLowering::splitToValueTypes `` can help with that);
69
+
70
+ * ``ValueAssigner `` - uses a ``CCAssignFn ``, usually generated by TableGen (see
71
+ :ref: `backend-calling-convs `), to decide where to put each
72
+ ``ArgInfo `` (physical register or stack); backends can use the provided
73
+ ``IncomingValueAssigner `` (for formal arguments and call results) and
74
+ ``OutgoingValueAssigner `` (for actual arguments and function returns), but
75
+ it's also possible to subclass them;
76
+
77
+ * ``ValueHandler `` - inserts the necessary instructions for putting each value
78
+ where it belongs; it has pure virtual methods for assigning values to
79
+ registers or to addresses, and a host of other helpers;
80
+
81
+ * ``determineAndHandleAssignments `` (or for more fine grained control,
82
+ ``determineAssignments `` and ``handleAssignments ``) - contains some boilerplate
83
+ for invoking a given ``ValueAssigner `` and ``ValueHandler `` on a series of
84
+ ``ArgInfo `` objects.
56
85
57
86
.. _irtranslator-aggregates :
58
87
0 commit comments