[flang-commits] [flang] 4463e39 - [flang][NFCI] Relpace `LoopOp` Op with `DoLoopOp` Op in FIR Dialect

Sourabh Singh Tomar via flang-commits flang-commits at lists.llvm.org
Wed Feb 3 09:28:08 PST 2021


Author: Sourabh Singh Tomar
Date: 2021-02-03T22:57:49+05:30
New Revision: 4463e39d91c6c54e671f409ae6e170d67239c577

URL: https://github.com/llvm/llvm-project/commit/4463e39d91c6c54e671f409ae6e170d67239c577
DIFF: https://github.com/llvm/llvm-project/commit/4463e39d91c6c54e671f409ae6e170d67239c577.diff

LOG: [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

Added: 
    

Modified: 
    flang/include/flang/Optimizer/Dialect/FIROps.h
    flang/include/flang/Optimizer/Dialect/FIROps.td
    flang/include/flang/Optimizer/Transforms/Passes.td
    flang/lib/Lower/DoLoopHelper.cpp
    flang/lib/Lower/IO.cpp
    flang/lib/Optimizer/Dialect/FIROps.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Optimizer/Dialect/FIROps.h b/flang/include/flang/Optimizer/Dialect/FIROps.h
index fe5e944fe267..66477846589a 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<mlir::Attribute> 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 f6658f670a57..3064379378b8 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<string mnemonic, list<OpTrait> traits = []> :
   let parser = [{ return ::parse$cppClass(parser, result); }];
 }
 
-def fir_LoopOp : region_Op<"do_loop",
+def fir_DoLoopOp : region_Op<"do_loop",
     [DeclareOpInterfaceMethods<LoopLikeOpInterface>]> {
   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 c558d99af8dc..cfa7e34bf807 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 35ef7434daaa..714af5dfee93 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<fir::LoopOp>(loc, lbi, ubi, inc);
+  auto loop = builder.create<fir::DoLoopOp>(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 973c1c270895..1183879cda87 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<fir::LoopOp>(loc, lowerValue, upperValue, stepValue);
+        builder.create<fir::DoLoopOp>(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 7ab24320a666..7b0d7a159b4b 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<mlir::NamedAttribute> 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<mlir::NamedAttribute> 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<mlir::BlockArgument>();
   if (!ivArg)
     return {};
   assert(ivArg.getOwner() && "unlinked block argument");
   auto *containingInst = ivArg.getOwner()->getParentOp();
-  return dyn_cast_or_null<fir::LoopOp>(containingInst);
+  return dyn_cast_or_null<fir::DoLoopOp>(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<ConstantIndexOp>(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<mlir::Operation *> ops) {
+fir::DoLoopOp::moveOutOfLoop(llvm::ArrayRef<mlir::Operation *> ops) {
   for (auto op : ops)
     op->moveBefore(*this);
   return success();


        


More information about the flang-commits mailing list