[TIR] Make syntax of AST nodes different than ops #13358
Merged
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.
Motivation example: in the current TVMScript, the snippet below:
is actually different from this one:
This is because 128 * 128 is not immediately constant-folded into 16384, but becomes an AST node:
T.Mul(128, 128). This can be quite error-prone if not used carefully.As part of effort of more formal TIR semantics, we want to more explicitly differentiate TIR AST nodes (defined in
tir/expr.h) and TIR ops (defined intir/op.h). The naming convention is that:tvm.tir.mulor operator*, means an TIR op, which will be eagerly constant-folded, i.e.mul(1, 2)returns3immediately rather than creating an AST node.Mul, means creating an AST node without constant folding.This PR makes this behavior more explictly by printing
T.Mul(a, b)directly whenaandbare both constants, rather than sugaring it intomul(a. b)ora * b, so that the difference between an op and an AST node is clarified.Co-authored-by: Yaxing Cai <caiyaxing666@gmail.com>