[Mlir-commits] [mlir] b4280d6 - [mlir][docs] Clarify operation parser generation context (NFC) (#229460)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Oct 6 08:48:52 PDT 2026
Author: Mehdi Amini
Date: 2026-10-06T15:48:45Z
New Revision: b4280d6b668ad2e1392f8cd677e140ff7508be1c
URL: https://github.com/llvm/llvm-project/commit/b4280d6b668ad2e1392f8cd677e140ff7508be1c
DIFF: https://github.com/llvm/llvm-project/commit/b4280d6b668ad2e1392f8cd677e140ff7508be1c.diff
LOG: [mlir][docs] Clarify operation parser generation context (NFC) (#229460)
Explain how GenContext and ODS optionality control attribute parsing,
and why attributes are required once an optional group selects a branch.
Assisted-by: Codex
Added:
Modified:
mlir/tools/mlir-tblgen/OpFormatGen.cpp
Removed:
################################################################################
diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
index a4798440cf28d..dd635aef1e3a2 100644
--- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
@@ -354,11 +354,17 @@ struct OperationFormat {
std::optional<StringRef> variableTransformer;
};
- /// The context in which an element is generated.
+ /// The context used to generate an element's parser. This controls whether
+ /// attribute variables are parsed optionally; it does not change the parsing
+ /// of other element kinds.
enum class GenContext {
- /// The element is generated at the top-level or with the same behaviour.
+ /// Use the default parsing behaviour: an ODS optional attribute may be
+ /// absent. Used at the top level and by callers using the default context.
Normal,
- /// The element is generated inside an optional group.
+ /// Generate an element in a selected branch of an optional group. Attribute
+ /// variables must be present, even if they are optional in ODS. The group
+ /// is optional, but its contents are required once the branch is selected.
+ /// The group's first element is parsed separately to select the branch.
Optional
};
@@ -384,6 +390,8 @@ struct OperationFormat {
/// Generate the operation parser from this format.
void genParser(Operator &op, OpClass &opClass);
/// Generate the parser code for a specific format element.
+ /// `genCtx`, together with ODS optionality, determines whether attribute
+ /// variables may be absent at this position.
void genElementParser(FormatElement *element, MethodBody &body,
FmtContext &attrTypeCtx,
GenContext genCtx = GenContext::Normal);
@@ -1904,8 +1912,9 @@ void OperationFormat::genElementParser(FormatElement *element, MethodBody &body,
}
}
- // Generate the rest of the elements inside an optional group. Elements in
- // an optional group after the guard are parsed as required.
+ // Generate the remaining then-elements or all else-elements after the
+ // guard has selected a branch. Optional attributes must be parsed as
+ // required here so that an incomplete group is rejected.
for (FormatElement *childElement : elements)
if (childElement != elidedAnchorElement)
genElementParser(childElement, body, attrTypeCtx,
More information about the Mlir-commits
mailing list