[PATCH] D73894: [MLIR] Add mapping based on ValueRange to BlockAndValueMapper.

Stephan Herhut via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 4 09:17:28 PST 2020


herhut updated this revision to Diff 242352.
herhut added a comment.

Less templates.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73894/new/

https://reviews.llvm.org/D73894

Files:
  mlir/include/mlir/IR/BlockAndValueMapping.h
  mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp


Index: mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp
===================================================================
--- mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp
+++ mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp
@@ -273,13 +273,11 @@
     // 2. Inline region, currently only works for a single basic block.
     BlockAndValueMapping map;
     auto &block = genericOp.region().front();
-    for (auto it : llvm::zip(block.getArguments(), indexedValues))
-      map.map(std::get<0>(it), std::get<1>(it));
+    map.map(block.getArguments(), indexedValues);
     for (auto &op : block.without_terminator()) {
       assert(op.getNumRegions() == 0);
       auto *newOp = b.clone(op, map);
-      for (auto it : llvm::zip(op.getResults(), newOp->getResults()))
-        map.map(std::get<0>(it), std::get<1>(it));
+      map.map(op.getResults(), newOp->getResults());
     }
 
     // 3. Emit std_store.
@@ -377,13 +375,11 @@
     // 2. Inline region, currently only works for a single basic block.
     BlockAndValueMapping map;
     auto &block = indexedGenericOp.region().front();
-    for (auto it : llvm::zip(block.getArguments(), indexedValues))
-      map.map(std::get<0>(it), std::get<1>(it));
+    map.map(block.getArguments(), indexedValues);
     for (auto &op : block.without_terminator()) {
       assert(op.getNumRegions() == 0);
       auto *newOp = b.clone(op, map);
-      for (auto it : llvm::zip(op.getResults(), newOp->getResults()))
-        map.map(std::get<0>(it), std::get<1>(it));
+      map.map(op.getResults(), newOp->getResults());
     }
 
     // 3. Emit std_store.
Index: mlir/include/mlir/IR/BlockAndValueMapping.h
===================================================================
--- mlir/include/mlir/IR/BlockAndValueMapping.h
+++ mlir/include/mlir/IR/BlockAndValueMapping.h
@@ -32,6 +32,14 @@
     valueMap[from.getAsOpaquePointer()] = to.getAsOpaquePointer();
   }
 
+  template <typename S, typename T,
+            std::enable_if_t<!std::is_assignable<Value, S>::value &&
+                             !std::is_same<S, Block *>::value> * = nullptr>
+  void map(S&& from, T&& to) {
+    for (auto pair : llvm::zip(from, to))
+      map(std::get<0>(pair), std::get<1>(pair));
+  }
+
   /// Erases a mapping for 'from'.
   void erase(Block *from) { valueMap.erase(from); }
   void erase(Value from) { valueMap.erase(from.getAsOpaquePointer()); }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73894.242352.patch
Type: text/x-patch
Size: 2406 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200204/2defffcd/attachment.bin>


More information about the llvm-commits mailing list