================
@@ -828,6 +828,76 @@ mlir::LogicalResult cir::VectorType::verify(
return success();
}
+mlir::Type cir::VectorType::parse(::mlir::AsmParser &odsParser) {
+
+ llvm::SMLoc odsLoc = odsParser.getCurrentLocation();
+ mlir::Builder odsBuilder(odsParser.getContext());
+ mlir::FailureOr<::mlir::Type> elementType;
+ mlir::FailureOr<uint64_t> size;
+ bool isScalabe = false;
+
+ // Parse literal '<'
+ if (odsParser.parseLess())
+ return {};
+
+ // Parse literal '[', if present, and set the scalability flag accordingly
+ if (odsParser.parseOptionalLSquare().succeeded()) {
+ isScalabe = true;
+ }
+
+ // Parse variable 'size'
+ size = mlir::FieldParser<uint64_t>::parse(odsParser);
+ if (mlir::failed(size)) {
+ odsParser.emitError(odsParser.getCurrentLocation(),
+ "failed to parse CIR_VectorType parameter 'size' which
"
+ "is to be a `uint64_t`");
+ return {};
+ }
+
+ // Parse literal ']', which is expected when dealing with scalable
+ // dim sizes
+ if (isScalabe && odsParser.parseRSquare().failed()) {
+ odsParser.emitError(odsParser.getCurrentLocation(),
+ "missing closing `]` for scalable dim size");
+ return {};
+ }
+
+ // Parse literal 'x'
+ if (odsParser.parseKeyword("x"))
+ return {};
+
+ // Parse variable 'elementType'
+ elementType = mlir::FieldParser<::mlir::Type>::parse(odsParser);
+ if (mlir::failed(elementType)) {
+ odsParser.emitError(odsParser.getCurrentLocation(),
----------------
banach-space wrote:
Added a test in this
[commit](https://github.com/llvm/llvm-project/pull/172683/commits/44b6e72f084104f99593423050eabb296babc87f).
IMO, it's not great :/ (suggestions for improvement are welcome) .Testing
`!cir.vector<[1 x !s32i>` (instead of `!cir.vector<[1 x] !s32i>`) would be
better, but the former is captured by
[Parser::parseDialectSymbolBody](https://github.com/llvm/llvm-project/blob/fa511cde48ea218dadfa8b35658ac06368f34607/mlir/lib/AsmParser/DialectSymbolParser.cpp?plain=1#L66-L67)
with:
```bash
/llvm-project/clang/test/CIR/IR/invalid-vector.cir:17:30: error: unbalanced '['
character in pretty dialect name
%3 = cir.alloca !cir.vector<[1 x !s32i>, !cir.ptr<!cir.vector<[1] x !s32i>>
^
```
That error is hit before getting into `cir::VectorType::parse`.
Btw, I don't want to come across as nit-picking or pushing back, but I see
quite a few CIR parser errors that are not tested, e.g.
https://github.com/llvm/llvm-project/blob/fa511cde48ea218dadfa8b35658ac06368f34607/clang/lib/CIR/Dialect/IR/CIRTypes.cpp?plain=1#L154
Perhaps it would be better to skip testing in this case as well? WDYT?
https://github.com/llvm/llvm-project/pull/172683
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits