Added NoTerminator trait, and created a single builder
that adds a block into the region at operation construction.
Added custom assembly parser that automatically adds the body
block, when the region appears to be empty to parseRegion().
Details
Diff Detail
Event Timeline
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | ||
---|---|---|
1006–1013 | Sure. | |
mlir/test/Dialect/LLVMIR/invalid.mlir | ||
870 | The operation's region is defined as SizedRegion<1>, so removing the block id causes verification failure: 'llvm.metadata' op region #0 ('body') failed to verify constraint: region with 1 blocks I was not able to find the printer/parse API flag to avoid this - can you please give me a pointer? I could probably add custom parser that uses parseRegion and then automatically creates the body block, if one was not created due to parseRegionBody not being invoked in mlir/lib/AsmParser/Parser.cpp:OperationParser::parseRegion: // Parse the region body. if ((!entryArguments.empty() || getToken().isNot(Token::r_brace)) && parseRegionBody(region, lBraceTok.getLoc(), entryArguments, isIsolatedNameScope)) { return failure(); } Alternatively, we can define MetadataOp's region as: let regions = (region MaxSizedRegion<1>:$body); This will require adding MaxSizedRegion constraint definition (we only have MinSizedRegion right now). Which approach would you prefer? |
mlir/test/Dialect/LLVMIR/invalid.mlir | ||
---|---|---|
870 | We do custom parsing for, e.g., loop constructs such as scf.for, so I'd go with that. Allowing something in the ODS constraint only to disallow it in the verifier (assuming we don't really want zero-block regions here) is smelly. |
- Added custom printer/parser.
mlir/test/Dialect/LLVMIR/invalid.mlir | ||
---|---|---|
870 | For the latter, I thought about actually allowing zero-block regions for MetadataOp. This would be a nop operation, so it should make little sense but no harm. The custom printer/parser seems to be best solution. |
Nit: can we move this to a .cpp file?