From 4463e39d91c6c54e671f409ae6e170d67239c577 Mon Sep 17 00:00:00 2001 From: Sourabh Singh Tomar Date: Wed, 3 Feb 2021 20:00:21 +0530 Subject: [PATCH] [flang][NFCI] Relpace `LoopOp` Op with `DoLoopOp` Op in FIR Dialect Part of upstreaming effort, PR: https://github.com/flang-compiler/f18-llvm-project/pull/296 Reviewed By: schweitz Differential Revision: https://reviews.llvm.org/D95950 --- flang/include/flang/Optimizer/Dialect/FIROps.h | 4 +-- flang/include/flang/Optimizer/Dialect/FIROps.td | 6 ++-- flang/include/flang/Optimizer/Transforms/Passes.td | 2 +- flang/lib/Lower/DoLoopHelper.cpp | 2 +- flang/lib/Lower/IO.cpp | 2 +- flang/lib/Optimizer/Dialect/FIROps.cpp | 39 +++++++++++----------- 6 files changed, 28 insertions(+), 27 deletions(-) diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.h b/flang/include/flang/Optimizer/Dialect/FIROps.h index fe5e944..6647784 100644 --- a/flang/include/flang/Optimizer/Dialect/FIROps.h +++ b/flang/include/flang/Optimizer/Dialect/FIROps.h @@ -18,7 +18,7 @@ using namespace mlir; namespace fir { class FirEndOp; -class LoopOp; +class DoLoopOp; class RealAttr; void buildCmpFOp(mlir::OpBuilder &builder, mlir::OperationState &result, @@ -29,7 +29,7 @@ void buildCmpCOp(mlir::OpBuilder &builder, mlir::OperationState &result, mlir::Value rhs); unsigned getCaseArgumentOffset(llvm::ArrayRef cases, unsigned dest); -LoopOp getForInductionVarOwner(mlir::Value val); +DoLoopOp getForInductionVarOwner(mlir::Value val); bool isReferenceLike(mlir::Type type); mlir::ParseResult isValidCaseAttr(mlir::Attribute attr); mlir::ParseResult parseCmpfOp(mlir::OpAsmParser &parser, diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td index f6658f6..3064379 100644 --- a/flang/include/flang/Optimizer/Dialect/FIROps.td +++ b/flang/include/flang/Optimizer/Dialect/FIROps.td @@ -1852,7 +1852,7 @@ def fir_LenParamIndexOp : fir_OneResultOp<"len_param_index", [NoSideEffect]> { def fir_ResultOp : fir_Op<"result", [NoSideEffect, ReturnLike, Terminator, - ParentOneOf<["WhereOp", "LoopOp", "IterWhileOp"]>]> { + ParentOneOf<["WhereOp", "DoLoopOp", "IterWhileOp"]>]> { let summary = "special terminator for use in fir region operations"; let description = [{ @@ -1883,7 +1883,7 @@ class region_Op traits = []> : let parser = [{ return ::parse$cppClass(parser, result); }]; } -def fir_LoopOp : region_Op<"do_loop", +def fir_DoLoopOp : region_Op<"do_loop", [DeclareOpInterfaceMethods]> { let summary = "generalized loop operation"; let description = [{ @@ -2020,7 +2020,7 @@ def fir_IterWhileOp : region_Op<"iterate_while", let summary = "DO loop with early exit condition"; let description = [{ This construct is useful for lowering implied-DO loops. It is very similar - to `fir::LoopOp` with the addition that it requires a single loop-carried + to `fir::DoLoopOp` with the addition that it requires a single loop-carried bool value that signals an early exit condition to the operation. A `true` disposition means the next loop iteration should proceed. A `false` indicates that the `fir.iterate_while` operation should terminate and diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td index c558d99..cfa7e34 100644 --- a/flang/include/flang/Optimizer/Transforms/Passes.td +++ b/flang/include/flang/Optimizer/Transforms/Passes.td @@ -17,7 +17,7 @@ include "mlir/Pass/PassBase.td" def AffineDialectPromotion : FunctionPass<"promote-to-affine"> { - let summary = "Promotes fir.loop and fir.where to affine.for and affine.if where possible"; + let summary = "Promotes fir.do_loop and fir.where to affine.for and affine.if where possible"; let description = [{ TODO }]; diff --git a/flang/lib/Lower/DoLoopHelper.cpp b/flang/lib/Lower/DoLoopHelper.cpp index 35ef743..714af5d 100644 --- a/flang/lib/Lower/DoLoopHelper.cpp +++ b/flang/lib/Lower/DoLoopHelper.cpp @@ -19,7 +19,7 @@ void Fortran::lower::DoLoopHelper::createLoop( auto ubi = builder.convertToIndexType(loc, ub); assert(step && "step must be an actual Value"); auto inc = builder.convertToIndexType(loc, step); - auto loop = builder.create(loc, lbi, ubi, inc); + auto loop = builder.create(loc, lbi, ubi, inc); auto insertPt = builder.saveInsertionPoint(); builder.setInsertionPointToStart(loop.getBody()); auto index = loop.getInductionVar(); diff --git a/flang/lib/Lower/IO.cpp b/flang/lib/Lower/IO.cpp index 973c1c2..1183879 100644 --- a/flang/lib/Lower/IO.cpp +++ b/flang/lib/Lower/IO.cpp @@ -387,7 +387,7 @@ static void genIoLoop(Fortran::lower::AbstractConverter &converter, if (!checkResult) { // No I/O call result checks - the loop is a fir.do_loop op. auto loopOp = - builder.create(loc, lowerValue, upperValue, stepValue); + builder.create(loc, lowerValue, upperValue, stepValue); builder.setInsertionPointToStart(loopOp.getBody()); auto lcv = builder.createConvert(loc, converter.genType(loopSym), loopOp.getInductionVar()); diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp index 7ab2432..7b0d7a1 100644 --- a/flang/lib/Optimizer/Dialect/FIROps.cpp +++ b/flang/lib/Optimizer/Dialect/FIROps.cpp @@ -786,13 +786,14 @@ mlir::ParseResult fir::LoadOp::getElementOf(mlir::Type &ele, mlir::Type ref) { } //===----------------------------------------------------------------------===// -// LoopOp +// DoLoopOp //===----------------------------------------------------------------------===// -void fir::LoopOp::build(mlir::OpBuilder &builder, mlir::OperationState &result, - mlir::Value lb, mlir::Value ub, mlir::Value step, - bool unordered, mlir::ValueRange iterArgs, - llvm::ArrayRef attributes) { +void fir::DoLoopOp::build(mlir::OpBuilder &builder, + mlir::OperationState &result, mlir::Value lb, + mlir::Value ub, mlir::Value step, bool unordered, + mlir::ValueRange iterArgs, + llvm::ArrayRef attributes) { result.addOperands({lb, ub, step}); result.addOperands(iterArgs); for (auto v : iterArgs) @@ -800,7 +801,7 @@ void fir::LoopOp::build(mlir::OpBuilder &builder, mlir::OperationState &result, mlir::Region *bodyRegion = result.addRegion(); bodyRegion->push_back(new Block{}); if (iterArgs.empty()) - LoopOp::ensureTerminator(*bodyRegion, builder, result.location); + DoLoopOp::ensureTerminator(*bodyRegion, builder, result.location); bodyRegion->front().addArgument(builder.getIndexType()); bodyRegion->front().addArguments(iterArgs.getTypes()); if (unordered) @@ -808,8 +809,8 @@ void fir::LoopOp::build(mlir::OpBuilder &builder, mlir::OperationState &result, result.addAttributes(attributes); } -static mlir::ParseResult parseLoopOp(mlir::OpAsmParser &parser, - mlir::OperationState &result) { +static mlir::ParseResult parseDoLoopOp(mlir::OpAsmParser &parser, + mlir::OperationState &result) { auto &builder = parser.getBuilder(); mlir::OpAsmParser::OperandType inductionVariable, lb, ub, step; // Parse the induction variable followed by '='. @@ -827,7 +828,7 @@ static mlir::ParseResult parseLoopOp(mlir::OpAsmParser &parser, return failure(); if (mlir::succeeded(parser.parseOptionalKeyword("unordered"))) - result.addAttribute(fir::LoopOp::unorderedAttrName(), + result.addAttribute(fir::DoLoopOp::unorderedAttrName(), builder.getUnitAttr()); // Parse the optional initial iteration arguments. @@ -864,22 +865,22 @@ static mlir::ParseResult parseLoopOp(mlir::OpAsmParser &parser, if (parser.parseRegion(*body, regionArgs, argTypes)) return failure(); - fir::LoopOp::ensureTerminator(*body, builder, result.location); + fir::DoLoopOp::ensureTerminator(*body, builder, result.location); return mlir::success(); } -fir::LoopOp fir::getForInductionVarOwner(mlir::Value val) { +fir::DoLoopOp fir::getForInductionVarOwner(mlir::Value val) { auto ivArg = val.dyn_cast(); if (!ivArg) return {}; assert(ivArg.getOwner() && "unlinked block argument"); auto *containingInst = ivArg.getOwner()->getParentOp(); - return dyn_cast_or_null(containingInst); + return dyn_cast_or_null(containingInst); } // Lifted from loop.loop -static mlir::LogicalResult verify(fir::LoopOp op) { +static mlir::LogicalResult verify(fir::DoLoopOp op) { if (auto cst = dyn_cast_or_null(op.step().getDefiningOp())) if (cst.getValue() <= 0) return op.emitOpError("constant step operand must be positive"); @@ -918,9 +919,9 @@ static mlir::LogicalResult verify(fir::LoopOp op) { return success(); } -static void print(mlir::OpAsmPrinter &p, fir::LoopOp op) { +static void print(mlir::OpAsmPrinter &p, fir::DoLoopOp op) { bool printBlockTerminators = false; - p << fir::LoopOp::getOperationName() << ' ' << op.getInductionVar() << " = " + p << fir::DoLoopOp::getOperationName() << ' ' << op.getInductionVar() << " = " << op.lowerBound() << " to " << op.upperBound() << " step " << op.step(); if (op.unordered()) p << " unordered"; @@ -935,19 +936,19 @@ static void print(mlir::OpAsmPrinter &p, fir::LoopOp op) { printBlockTerminators = true; } p.printOptionalAttrDictWithKeyword(op->getAttrs(), - {fir::LoopOp::unorderedAttrName()}); + {fir::DoLoopOp::unorderedAttrName()}); p.printRegion(op.region(), /*printEntryBlockArgs=*/false, printBlockTerminators); } -mlir::Region &fir::LoopOp::getLoopBody() { return region(); } +mlir::Region &fir::DoLoopOp::getLoopBody() { return region(); } -bool fir::LoopOp::isDefinedOutsideOfLoop(mlir::Value value) { +bool fir::DoLoopOp::isDefinedOutsideOfLoop(mlir::Value value) { return !region().isAncestor(value.getParentRegion()); } mlir::LogicalResult -fir::LoopOp::moveOutOfLoop(llvm::ArrayRef ops) { +fir::DoLoopOp::moveOutOfLoop(llvm::ArrayRef ops) { for (auto op : ops) op->moveBefore(*this); return success(); -- 2.7.4