[DRAFT][TIR] Prototype of T.macro #15238
Closed
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.
Initial draft of
T.macro
as discussed in https://discuss.tvm.apache.org/t/discussion-tir-macros/15247.The basic idea is to introduce a decorator
T.macro
that, similarly toT.prim_func
would annotate a piece of code as a TIR macro. The macro would not be subject to any parameter restrictions, since the intent is to simply insert the macro's body at the place of use, substituting parameters with the actual arguments. Since no function call is generated, no ABI constraints apply.A macro is used with a pseudo function call
T.include
, where the first argument is the macro name followed by actual arguments to the macro.Functionally, the macro is stored as
doc.AST
, and no further processing is done on the macro definition (until it's used).In the TIR parser, when
doc.Call
is encountered and the call is toT.include
, this expression is treated specially:Example:
Output:
bar
has the macro expanded in its body, whilefoo1
prints as<tvm.script...Module>
.The detailed representation of the `foo1` macro in JSON format