[Mlir-commits] [mlir] 37d417b - [mlir][EDSC] Hotfix - Provide impl for `negate`

Nicolas Vasilache llvmlistbot at llvm.org
Thu Apr 23 11:20:20 PDT 2020


Author: Nicolas Vasilache
Date: 2020-04-23T14:18:47-04:00
New Revision: 37d417bb0adca62b6902dd27019465f9ae4319a5

URL: https://github.com/llvm/llvm-project/commit/37d417bb0adca62b6902dd27019465f9ae4319a5
DIFF: https://github.com/llvm/llvm-project/commit/37d417bb0adca62b6902dd27019465f9ae4319a5.diff

LOG: [mlir][EDSC] Hotfix - Provide impl for `negate`

367229e100eca714276253bf95a0dd3d084a9624 retired ValueHandle but
mistakenly removed the implementation for `negate` which was not
tested and would result in linking errors.

This revision adds the implementation back and provides a test.

Added: 
    

Modified: 
    mlir/lib/Dialect/Affine/EDSC/Builders.cpp
    mlir/lib/Dialect/LoopOps/EDSC/Builders.cpp
    mlir/test/EDSC/builder-api-test.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Affine/EDSC/Builders.cpp b/mlir/lib/Dialect/Affine/EDSC/Builders.cpp
index 2cecb0c12e18..0e1b2a5bf0af 100644
--- a/mlir/lib/Dialect/Affine/EDSC/Builders.cpp
+++ b/mlir/lib/Dialect/Affine/EDSC/Builders.cpp
@@ -191,6 +191,11 @@ Value mlir::edsc::op::ceilDiv(Value lhs, Value rhs) {
       lhs, rhs, [](AffineExpr d0, AffineExpr d1) { return d0.ceilDiv(d1); });
 }
 
+Value mlir::edsc::op::negate(Value value) {
+  assert(value.getType().isInteger(1) && "expected boolean expression");
+  return ValueBuilder<ConstantIntOp>(1, 1) - value;
+}
+
 Value mlir::edsc::op::operator&&(Value lhs, Value rhs) {
   assert(lhs.getType().isInteger(1) && "expected boolean expression on LHS");
   assert(rhs.getType().isInteger(1) && "expected boolean expression on RHS");

diff  --git a/mlir/lib/Dialect/LoopOps/EDSC/Builders.cpp b/mlir/lib/Dialect/LoopOps/EDSC/Builders.cpp
index 7775d8dd0095..fec803deaec2 100644
--- a/mlir/lib/Dialect/LoopOps/EDSC/Builders.cpp
+++ b/mlir/lib/Dialect/LoopOps/EDSC/Builders.cpp
@@ -79,14 +79,11 @@ mlir::edsc::LoopNestBuilder::LoopNestBuilder::operator()(
 }
 
 LoopBuilder mlir::edsc::makeParallelLoopBuilder(MutableArrayRef<Value> ivs,
-                                                ArrayRef<Value> lbHandles,
-                                                ArrayRef<Value> ubHandles,
+                                                ArrayRef<Value> lbs,
+                                                ArrayRef<Value> ubs,
                                                 ArrayRef<Value> steps) {
   LoopBuilder result;
-  auto opHandle = OperationHandle::create<loop::ParallelOp>(
-      SmallVector<Value, 4>(lbHandles.begin(), lbHandles.end()),
-      SmallVector<Value, 4>(ubHandles.begin(), ubHandles.end()),
-      SmallVector<Value, 4>(steps.begin(), steps.end()));
+  auto opHandle = OperationHandle::create<loop::ParallelOp>(lbs, ubs, steps);
 
   loop::ParallelOp parallelOp =
       cast<loop::ParallelOp>(*opHandle.getOperation());
@@ -96,12 +93,13 @@ LoopBuilder mlir::edsc::makeParallelLoopBuilder(MutableArrayRef<Value> ivs,
   return result;
 }
 
-mlir::edsc::LoopBuilder mlir::edsc::makeLoopBuilder(
-    Value *iv, Value lbHandle, Value ubHandle, Value stepHandle,
-    MutableArrayRef<Value> iterArgsHandles, ValueRange iterArgsInitValues) {
+mlir::edsc::LoopBuilder
+mlir::edsc::makeLoopBuilder(Value *iv, Value lb, Value ub, Value step,
+                            MutableArrayRef<Value> iterArgsHandles,
+                            ValueRange iterArgsInitValues) {
   mlir::edsc::LoopBuilder result;
-  auto forOp = OperationHandle::createOp<loop::ForOp>(
-      lbHandle, ubHandle, stepHandle, iterArgsInitValues);
+  auto forOp =
+      OperationHandle::createOp<loop::ForOp>(lb, ub, step, iterArgsInitValues);
   *iv = forOp.getInductionVar();
   auto *body = loop::getForInductionVarOwner(*iv).getBody();
   for (size_t i = 0, e = iterArgsHandles.size(); i < e; ++i) {

diff  --git a/mlir/test/EDSC/builder-api-test.cpp b/mlir/test/EDSC/builder-api-test.cpp
index 75e85ea05722..76f478f46c8a 100644
--- a/mlir/test/EDSC/builder-api-test.cpp
+++ b/mlir/test/EDSC/builder-api-test.cpp
@@ -470,13 +470,16 @@ TEST_FUNC(operator_and) {
   ScopedContext scope(builder, f.getLoc());
 
   using op::operator&&;
+  using op::negate;
   Value lhs(f.getArgument(0));
   Value rhs(f.getArgument(1));
-  lhs &&rhs;
+  negate(lhs && rhs);
 
   // CHECK-LABEL: @operator_and
   //       CHECK: [[ARG0:%.*]]: i1, [[ARG1:%.*]]: i1
-  //       CHECK: and [[ARG0]], [[ARG1]]
+  //       CHECK: [[AND:%.*]] = and [[ARG0]], [[ARG1]]
+  //       CHECK: [[TRUE:%.*]] = constant 1 : i1
+  //       CHECK: subi [[TRUE]], [[AND]] : i1
   f.print(llvm::outs());
   f.erase();
 }


        


More information about the Mlir-commits mailing list