[flang-commits] [flang] 1165a35 - [IndexedAccessorRange] Only offset the base if the index is non-zero.

River Riddle via flang-commits flang-commits at lists.llvm.org
Fri May 1 12:03:07 PDT 2020


Author: River Riddle
Date: 2020-05-01T11:56:39-07:00
New Revision: 1165a35a7312ccd723bbe3e5fe95cd3a3109ec66

URL: https://github.com/llvm/llvm-project/commit/1165a35a7312ccd723bbe3e5fe95cd3a3109ec66
DIFF: https://github.com/llvm/llvm-project/commit/1165a35a7312ccd723bbe3e5fe95cd3a3109ec66.diff

LOG: [IndexedAccessorRange] Only offset the base if the index is non-zero.

This is more efficient and removes the need for derived ranges to handle the degenerate empty case.

Added: 
    

Modified: 
    flang/lib/Optimizer/Dialect/FIROps.cpp
    llvm/include/llvm/ADT/STLExtras.h

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index e2d94885e8fc..2e67c86486fc 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -611,8 +611,7 @@ void fir::IterWhileOp::build(mlir::OpBuilder &builder,
   bodyRegion->push_back(new Block{});
   bodyRegion->front().addArgument(builder.getIndexType());
   bodyRegion->front().addArgument(iterate.getType());
-  for (auto v : iterArgs)
-    bodyRegion->front().addArgument(v.getType());
+  bodyRegion->front().addArguments(iterArgs.getTypes());
   result.addAttributes(attributes);
 }
 
@@ -799,8 +798,7 @@ void fir::LoopOp::build(mlir::OpBuilder &builder, mlir::OperationState &result,
   if (iterArgs.empty())
     LoopOp::ensureTerminator(*bodyRegion, builder, result.location);
   bodyRegion->front().addArgument(builder.getIndexType());
-  for (auto v : iterArgs)
-    bodyRegion->front().addArgument(v.getType());
+  bodyRegion->front().addArguments(iterArgs.getTypes());
   if (unordered)
     result.addAttribute(unorderedAttrName(), builder.getUnitAttr());
   result.addAttributes(attributes);

diff  --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index 595ecbd07291..30bcdf5268a8 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -1108,7 +1108,7 @@ class indexed_accessor_range_base {
   };
 
   indexed_accessor_range_base(iterator begin, iterator end)
-      : base(DerivedT::offset_base(begin.getBase(), begin.getIndex())),
+      : base(offset_base(begin.getBase(), begin.getIndex())),
         count(end.getIndex() - begin.getIndex()) {}
   indexed_accessor_range_base(const iterator_range<iterator> &range)
       : indexed_accessor_range_base(range.begin(), range.end()) {}
@@ -1141,7 +1141,7 @@ class indexed_accessor_range_base {
   /// Drop the first N elements, and keep M elements.
   DerivedT slice(size_t n, size_t m) const {
     assert(n + m <= size() && "invalid size specifiers");
-    return DerivedT(DerivedT::offset_base(base, n), m);
+    return DerivedT(offset_base(base, n), m);
   }
 
   /// Drop the first n elements.
@@ -1174,6 +1174,12 @@ class indexed_accessor_range_base {
     return RangeT(iterator_range<iterator>(*this));
   }
 
+private:
+  /// Offset the given base by the given amount.
+  static BaseT offset_base(const BaseT &base, size_t n) {
+    return n == 0 ? base : DerivedT::offset_base(base, n);
+  }
+
 protected:
   indexed_accessor_range_base(const indexed_accessor_range_base &) = default;
   indexed_accessor_range_base(indexed_accessor_range_base &&) = default;


        


More information about the flang-commits mailing list