[Mlir-commits] [mlir] [mlir][RegionBranchOpInterface] explicitly check for existance of block terminator (PR #76831)
Maksim Levental
llvmlistbot at llvm.org
Wed Jan 3 15:23:09 PST 2024
================
@@ -1186,6 +1206,31 @@ static ParseResult customParseProperties(OpAsmParser &parser,
prop.label = std::make_shared<std::string>(std::move(label));
return success();
}
+
+static ParseResult
+parseSwitchCases(OpAsmParser &p, DenseI64ArrayAttr &cases,
+ SmallVectorImpl<std::unique_ptr<Region>> &caseRegions) {
+ SmallVector<int64_t> caseValues;
+ while (succeeded(p.parseOptionalKeyword("case"))) {
+ int64_t value;
+ Region ®ion = *caseRegions.emplace_back(std::make_unique<Region>());
+ if (p.parseInteger(value) || p.parseRegion(region, /*arguments=*/{}))
+ return failure();
+ caseValues.push_back(value);
+ }
+ cases = p.getBuilder().getDenseI64ArrayAttr(caseValues);
+ return success();
+}
+
+static void printSwitchCases(OpAsmPrinter &p, Operation *op,
+ DenseI64ArrayAttr cases, RegionRange caseRegions) {
+ for (auto [value, region] : llvm::zip(cases.asArrayRef(), caseRegions)) {
+ p.printNewline();
+ p << "case " << value << ' ';
+ p.printRegion(*region, /*printEntryBlockArgs=*/false);
+ }
+}
----------------
makslevental wrote:
Copy pasta (mostly) from [scf](https://github.com/llvm/llvm-project/blob/10056c821a56a19cef732129e4e0c5883ae1ee49/mlir/lib/Dialect/SCF/IR/SCF.cpp#L3891). I thought about factoring it out but where would you put it and who else would use it 🤷.
https://github.com/llvm/llvm-project/pull/76831
More information about the Mlir-commits
mailing list