[PATCH] D77128: [MLIR] Implement LoopLikeInterface for loop.parallel

Theodore Popp via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 31 02:47:36 PDT 2020


tpopp created this revision.
tpopp added reviewers: herhut, pifon2a.
Herald added subscribers: llvm-commits, grosul1, Joonsoo, liufengdb, lucyrfox, mgester, arpith-jacob, nicolasvasilache, antiagainst, shauheen, burmako, jpienaar, rriddle, mehdi_amini.
Herald added a reviewer: nicolasvasilache.
Herald added a project: LLVM.

This is to allow optimizations like loop invariant code motion to work
on the ParallelOp.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77128

Files:
  mlir/include/mlir/Dialect/LoopOps/LoopOps.td
  mlir/lib/Dialect/LoopOps/LoopOps.cpp
  mlir/test/Transforms/loop-invariant-code-motion.mlir


Index: mlir/test/Transforms/loop-invariant-code-motion.mlir
===================================================================
--- mlir/test/Transforms/loop-invariant-code-motion.mlir
+++ mlir/test/Transforms/loop-invariant-code-motion.mlir
@@ -244,3 +244,30 @@
 
   return
 }
+
+func @parallel_loop_with_invariant() {
+  %c0 = constant 0 : index
+  %c10 = constant 10 : index
+  %c1 = constant 1 : index
+  %c7 = constant 7 : i32
+  %c8 = constant 8 : i32
+  loop.parallel (%arg0, %arg1) = (%c0, %c0) to (%c10, %c10) step (%c1, %c1) {
+      %v0 = addi %c7, %c8 : i32
+      %v3 = addi %arg0, %arg1 : index
+  }
+
+  // CHECK: %c0 = constant 0 : index
+  // CHECK-NEXT: %c10 = constant 10 : index
+  // CHECK-NEXT: %c1 = constant 1 : index
+  // CHECK-NEXT: %c7_i32 = constant 7 : i32
+  // CHECK-NEXT: %c8_i32 = constant 8 : i32
+  // CHECK-NEXT: %0 = addi %c7_i32, %c8_i32 : i32
+  // CHECK-NEXT: loop.parallel (%arg0, %arg1) = (%c0, %c0) to (%c10, %c10) step (%c1, %c1)
+  // CHECK-NEXT:   %1 = addi %arg0, %arg1 : index
+  // CHECK-NEXT:   yield
+  // CHECK-NEXT: }
+  // CHECK-NEXT: return
+
+  return
+}
+
Index: mlir/lib/Dialect/LoopOps/LoopOps.cpp
===================================================================
--- mlir/lib/Dialect/LoopOps/LoopOps.cpp
+++ mlir/lib/Dialect/LoopOps/LoopOps.cpp
@@ -459,6 +459,18 @@
       op.getAttrs(), /*elidedAttrs=*/ParallelOp::getOperandSegmentSizeAttr());
 }
 
+Region &ParallelOp::getLoopBody() { return region(); }
+
+bool ParallelOp::isDefinedOutsideOfLoop(Value value) {
+  return !region().isAncestor(value.getParentRegion());
+}
+
+LogicalResult ParallelOp::moveOutOfLoop(ArrayRef<Operation *> ops) {
+  for (auto op : ops)
+    op->moveBefore(this->getOperation());
+  return success();
+}
+
 ParallelOp mlir::loop::getParallelForInductionVarOwner(Value val) {
   auto ivArg = val.dyn_cast<BlockArgument>();
   if (!ivArg)
Index: mlir/include/mlir/Dialect/LoopOps/LoopOps.td
===================================================================
--- mlir/include/mlir/Dialect/LoopOps/LoopOps.td
+++ mlir/include/mlir/Dialect/LoopOps/LoopOps.td
@@ -246,7 +246,9 @@
 }
 
 def ParallelOp : Loop_Op<"parallel",
-    [AttrSizedOperandSegments, SingleBlockImplicitTerminator<"YieldOp">]> {
+    [AttrSizedOperandSegments,
+     DeclareOpInterfaceMethods<LoopLikeOpInterface>,
+     SingleBlockImplicitTerminator<"YieldOp">]> {
   let summary = "parallel for operation";
   let description = [{
     The "loop.parallel" operation represents a loop nest taking 4 groups of SSA


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77128.253821.patch
Type: text/x-patch
Size: 2526 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200331/ea54c3a5/attachment-0001.bin>


More information about the llvm-commits mailing list