aboutsummaryrefslogtreecommitdiff
path: root/mlir/lib/AsmParser/DialectSymbolParser.cpp
diff options
context:
space:
mode:
authorMarkus Böck <markus.boeck02@gmail.com>2024-02-02 12:47:05 +0100
committerMarkus Böck <markus.boeck02@gmail.com>2024-02-02 13:15:15 +0100
commite67e980cd077de77bb1683f4a9ad948f13ad4289 (patch)
tree0fb7c084b806d605986aa1153159e7436ba22e58 /mlir/lib/AsmParser/DialectSymbolParser.cpp
parentf9f2f00dc37d979b459c7d9d1dc6f52ec3466206 (diff)
downloadllvm-users/zero9178/simplify-builtin-parsing.zip
llvm-users/zero9178/simplify-builtin-parsing.tar.gz
llvm-users/zero9178/simplify-builtin-parsing.tar.bz2
[mlir] Start moving some builtin type formats to the dialectusers/zero9178/simplify-builtin-parsing
Most types and attributes in the builtin dialect are parsed and printed using special-purpose printers and parsers for that type. They also use the low-level `Printer` rather than the `AsmPrinter`, making the implementations inconsistent compared to all other dialects in MLIR. This PR starts moving some builtin types to be parsed using the usual `print` and `parse` methods like all other MLIR dialects. This has the following advantages: * The implementation now looks like any other dialect's types * It is now possible to use `assemblyFormat` for builtin types and attributes * The code can be easily moved to other dialects if desired * Arguably better layering and less code * As a side-effect, it is now also possible to write `!builtin.<type>` for any types moved A future benefit would include being able to print types and attributes in stripped format as well (e.g. `<f32>` vs `complex<f32>`), just like all other dialect types and attributes. This is currently explicitly disabled as it causes a LOT of changes in IR syntax and I believe some ambiguities in the parser. For the purpose of reviewing and incremental development, this PR only moves `tuple`, `tensor`, `none`, `memref` and `complex`. The plan is to eventually move all attributes and types where the current syntax can be implemented within the dialect. For backwards compatibility with the existing syntax, the builtin dialect is special-cased in the printer where the `builtin.` prefix is omitted.
Diffstat (limited to 'mlir/lib/AsmParser/DialectSymbolParser.cpp')
-rw-r--r--mlir/lib/AsmParser/DialectSymbolParser.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/mlir/lib/AsmParser/DialectSymbolParser.cpp b/mlir/lib/AsmParser/DialectSymbolParser.cpp
index 80cce7e..400d263 100644
--- a/mlir/lib/AsmParser/DialectSymbolParser.cpp
+++ b/mlir/lib/AsmParser/DialectSymbolParser.cpp
@@ -322,6 +322,30 @@ Type Parser::parseExtendedType() {
});
}
+Type Parser::parseExtendedBuiltinType() {
+ // Initially set to just the mnemonic of the type.
+ llvm::StringRef symbolData = getToken().getSpelling();
+ const char *startOfTypePos = symbolData.data();
+ consumeToken();
+ // Extend 'symbolData' to include the body if it is not a singleton type.
+ // Note that all types in the builtin type always use the pretty dialect form
+ // aka 'dialect.mnemonic<body>'.
+ if (getToken().is(Token::less))
+ if (failed(parseDialectSymbolBody(symbolData)))
+ return nullptr;
+
+ const char *endOfTypePos = getToken().getLoc().getPointer();
+
+ // With the body of the type captured, hand it off to the dialect parser.
+ resetToken(startOfTypePos);
+ CustomDialectAsmParser customParser(symbolData, *this);
+ Type type = builtinDialect->parseType(customParser);
+
+ // Move the lexer past the type.
+ resetToken(endOfTypePos);
+ return type;
+}
+
//===----------------------------------------------------------------------===//
// mlir::parseAttribute/parseType
//===----------------------------------------------------------------------===//