-
Notifications
You must be signed in to change notification settings - Fork 15.6k
[CIR] Introduce syntax for scalable vectors #172683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -828,6 +828,75 @@ 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(), | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add an invalid vector cir test to make sure errors are emitted correctly
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be different in CIR, but in MLIR we don't really test the parser and tests in I am happy to add a test if you think that that would be helpful, but we’d probably want to add a dedicated file for parser errors - perhaps one already exists? I didn’t find any.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usually, for the handwritten parser or verifier, we have a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, Only this error need to be covered "missing closing
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a test in this commit. IMO, it's not great :/ (suggestions for improvement are welcome) .Testing /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 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.
Perhaps it would be better to skip testing in this case as well? WDYT?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for adding it. I am fine with both options, but I think it will be better to keep this test case 🤔
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm sure we've been inconsistent about this. I generally only look for tests for verifier errors and have been satisfied with round-trip tests for printing/parsing. My view is that the tests for the verifier check that we are correctly catching incorrectly constructed IR, which can occur anywhere during IR generation or processing, whereas the printing and parsing are paired so they test each other for correctness.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets me keep the test for now, we can always remove it later. |
||||
| "failed to parse CIR_VectorType parameter " | ||||
| "'elementType' which is to be a `mlir::Type`"); | ||||
| return {}; | ||||
| } | ||||
|
|
||||
| // Parse literal '>' | ||||
| if (odsParser.parseGreater()) | ||||
| return {}; | ||||
| return odsParser.getChecked<VectorType>(odsLoc, odsParser.getContext(), | ||||
| mlir::Type((*elementType)), | ||||
| uint64_t((*size)), isScalabe); | ||||
| } | ||||
|
|
||||
| void cir::VectorType::print(mlir::AsmPrinter &odsPrinter) const { | ||||
| mlir::Builder odsBuilder(getContext()); | ||||
| odsPrinter << "<"; | ||||
| if (this->getIsScalable()) | ||||
| odsPrinter << "["; | ||||
|
|
||||
| odsPrinter.printStrippedAttrOrType(getSize()); | ||||
| if (this->getIsScalable()) | ||||
| odsPrinter << "]"; | ||||
| odsPrinter << ' ' << "x"; | ||||
| odsPrinter << ' '; | ||||
| odsPrinter.printStrippedAttrOrType(getElementType()); | ||||
| odsPrinter << ">"; | ||||
| } | ||||
|
|
||||
| //===----------------------------------------------------------------------===// | ||||
| // TargetAddressSpace definitions | ||||
| //===----------------------------------------------------------------------===// | ||||
|
|
||||
Uh oh!
There was an error while loading. Please reload this page.