Skip to content
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

[flang] Adopt NoRegionArguments (WhereOp) and ParentOneOf (ResultOp) traits #275

Merged
merged 2 commits into from Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions flang/include/flang/Optimizer/Dialect/FIROps.td
Expand Up @@ -2131,7 +2131,9 @@ def fir_LenParamIndexOp : fir_OneResultOp<"len_param_index", [NoSideEffect]> {
// Fortran loops
//===----------------------------------------------------------------------===//

def fir_ResultOp : fir_Op<"result", [NoSideEffect, ReturnLike, Terminator]> {
def fir_ResultOp : fir_Op<"result",
[NoSideEffect, ReturnLike, Terminator,
ParentOneOf<["WhereOp", "LoopOp", "IterWhileOp"]>]> {
let summary = "special terminator for use in fir region operations";

let description = [{
Expand Down Expand Up @@ -2248,7 +2250,7 @@ def fir_LoopOp : region_Op<"do_loop",
}];
}

def fir_WhereOp : region_Op<"if"> {
def fir_WhereOp : region_Op<"if", [NoRegionArguments]> {
let summary = "if-then-else conditional operation";
let description = [{
Used to conditionally execute operations. This operation is the FIR
Expand Down
29 changes: 6 additions & 23 deletions flang/lib/Optimizer/Dialect/FIROps.cpp
Expand Up @@ -1017,19 +1017,12 @@ static mlir::LogicalResult verify(fir::ResultOp op) {
auto results = parentOp->getResults();
auto operands = op.getOperands();

if (isa<fir::WhereOp>(parentOp) || isa<fir::LoopOp>(parentOp) ||
isa<fir::IterWhileOp>(parentOp)) {
if (parentOp->getNumResults() != op.getNumOperands())
return op.emitOpError() << "parent of result must have same arity";
for (auto e : llvm::zip(results, operands)) {
if (std::get<0>(e).getType() != std::get<1>(e).getType())
return op.emitOpError()
<< "types mismatch between result op and its parent";
}
} else {
return op.emitOpError()
<< "result only terminates if, do_loop, or iterate_while regions";
}
if (parentOp->getNumResults() != op.getNumOperands())
return op.emitOpError() << "parent of result must have same arity";
for (auto e : llvm::zip(results, operands))
if (std::get<0>(e).getType() != std::get<1>(e).getType())
return op.emitOpError()
<< "types mismatch between result op and its parent";
return success();
}

Expand Down Expand Up @@ -1503,16 +1496,6 @@ static mlir::ParseResult parseWhereOp(OpAsmParser &parser,
}

static LogicalResult verify(fir::WhereOp op) {
// Verify that the entry of each child region does not have arguments.
for (auto &region : op.getOperation()->getRegions()) {
if (region.empty())
continue;

for (auto &b : region)
if (b.getNumArguments() != 0)
return op.emitOpError(
"requires that child entry blocks have no arguments");
}
if (op.getNumResults() != 0 && op.otherRegion().empty())
return op.emitOpError("must have an else block if defining values");

Expand Down