diff options
-rw-r--r-- | mlir/lib/Dialect/SCF/IR/SCF.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/mlir/lib/Dialect/SCF/IR/SCF.cpp b/mlir/lib/Dialect/SCF/IR/SCF.cpp index 4481417..1f70ad5 100644 --- a/mlir/lib/Dialect/SCF/IR/SCF.cpp +++ b/mlir/lib/Dialect/SCF/IR/SCF.cpp @@ -499,8 +499,20 @@ ParseResult ForOp::parse(OpAsmParser &parser, OperationState &result) { else if (parser.parseType(type)) return failure(); - // Resolve input operands. + // Set block argument types, so that they are known when parsing the region. regionArgs.front().type = type; + for (auto [iterArg, type] : + llvm::zip(llvm::drop_begin(regionArgs), result.types)) + iterArg.type = type; + + // Parse the body region. + Region *body = result.addRegion(); + if (parser.parseRegion(*body, regionArgs)) + return failure(); + ForOp::ensureTerminator(*body, builder, result.location); + + // Resolve input operands. This should be done after parsing the region to + // catch invalid IR where operands were defined inside of the region. if (parser.resolveOperand(lb, type, result.operands) || parser.resolveOperand(ub, type, result.operands) || parser.resolveOperand(step, type, result.operands)) @@ -516,13 +528,6 @@ ParseResult ForOp::parse(OpAsmParser &parser, OperationState &result) { } } - // Parse the body region. - Region *body = result.addRegion(); - if (parser.parseRegion(*body, regionArgs)) - return failure(); - - ForOp::ensureTerminator(*body, builder, result.location); - // Parse the optional attribute list. if (parser.parseOptionalAttrDict(result.attributes)) return failure(); |