[PATCH] D79363: [mlir][EDSC] Fix off-by-one BlockBuilder insertion point.

Nicolas Vasilache via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 4 18:18:58 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG036772acfda8: [mlir][EDSC] Fix off-by-one BlockBuilder insertion point. (authored by nicolasvasilache).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79363

Files:
  mlir/include/mlir/EDSC/Builders.h
  mlir/test/EDSC/builder-api-test.cpp


Index: mlir/test/EDSC/builder-api-test.cpp
===================================================================
--- mlir/test/EDSC/builder-api-test.cpp
+++ mlir/test/EDSC/builder-api-test.cpp
@@ -175,6 +175,33 @@
   f.erase();
 }
 
+TEST_FUNC(builder_block_append) {
+  using namespace edsc::op;
+  auto f = makeFunction("builder_blocks");
+
+  OpBuilder builder(f.getBody());
+  ScopedContext scope(builder, f.getLoc());
+
+  BlockHandle b1, functionBlock(&f.front());
+  BlockBuilder(&b1, {}, {})([&] { std_constant_index(0); });
+  BlockBuilder(b1, Append())([&] { std_constant_index(1); });
+  BlockBuilder(b1, Append())([&] { std_ret(); });
+  // Get back to entry block and add a branch into b1
+  BlockBuilder(functionBlock, Append())([&] { std_br(b1, {}); });
+
+  // clang-format off
+  // CHECK-LABEL: @builder_blocks
+  // CHECK-NEXT:   br ^bb1
+  // CHECK-NEXT: ^bb1: // pred: ^bb0
+  // CHECK-NEXT:   constant 0 : index
+  // CHECK-NEXT:   constant 1 : index
+  // CHECK-NEXT:   return
+  // CHECK-NEXT: }
+  // clang-format on
+  f.print(llvm::outs());
+  f.erase();
+}
+
 TEST_FUNC(builder_blocks) {
   using namespace edsc::op;
   auto f = makeFunction("builder_blocks");
@@ -1071,8 +1098,8 @@
   // CHECK:     [[sum:%[0-9]+]] = addf [[arg0]], [[arg1]] : f32
   // CHECK:     loop.yield [[arg1]], [[sum]] : f32, f32
   // CHECK:     addf [[res]]#0, [[res]]#1 : f32
-
   // clang-format on
+
   f.print(llvm::outs());
   f.erase();
 }
Index: mlir/include/mlir/EDSC/Builders.h
===================================================================
--- mlir/include/mlir/EDSC/Builders.h
+++ mlir/include/mlir/EDSC/Builders.h
@@ -118,10 +118,9 @@
   /// As a consequence we must allocate a new OpBuilder + ScopedContext and
   /// let the escape.
   void enter(mlir::Block *block) {
-    bodyScope = new ScopedContext(
-        ScopedContext::getBuilderRef(),
-        OpBuilder::InsertPoint(block, std::prev(block->end())),
-        ScopedContext::getLocation());
+    bodyScope = new ScopedContext(ScopedContext::getBuilderRef(),
+                                  OpBuilder::InsertPoint(block, block->end()),
+                                  ScopedContext::getLocation());
     if (!block->empty()) {
       auto &termOp = block->back();
       if (termOp.isKnownTerminator())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79363.261982.patch
Type: text/x-patch
Size: 2290 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200505/9563ccb7/attachment.bin>


More information about the llvm-commits mailing list