diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.h b/flang/include/flang/Optimizer/Dialect/FIROps.h --- a/flang/include/flang/Optimizer/Dialect/FIROps.h +++ b/flang/include/flang/Optimizer/Dialect/FIROps.h @@ -18,7 +18,7 @@ namespace fir { class FirEndOp; -class LoopOp; +class DoLoopOp; class RealAttr; void buildCmpFOp(mlir::OpBuilder &builder, mlir::OperationState &result, @@ -29,7 +29,7 @@ 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 --- a/flang/include/flang/Optimizer/Dialect/FIROps.td +++ b/flang/include/flang/Optimizer/Dialect/FIROps.td @@ -1852,7 +1852,7 @@ 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 @@ 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 @@ 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 --- 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 --- a/flang/lib/Lower/DoLoopHelper.cpp +++ b/flang/lib/Lower/DoLoopHelper.cpp @@ -19,7 +19,7 @@ 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 --- a/flang/lib/Lower/IO.cpp +++ b/flang/lib/Lower/IO.cpp @@ -387,7 +387,7 @@ 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 --- a/flang/lib/Optimizer/Dialect/FIROps.cpp +++ b/flang/lib/Optimizer/Dialect/FIROps.cpp @@ -786,13 +786,14 @@ } //===----------------------------------------------------------------------===// -// 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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();