[PATCH] D75764: [mlir] Create a std op instead of chain of ops.

Han-Chung Wang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 10 15:22:14 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rGc0f4408d76f0: [mlir] Create a std op instead of chain of ops. (authored by hanchung).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75764

Files:
  mlir/lib/Dialect/AffineOps/EDSC/Builders.cpp
  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
@@ -480,6 +480,44 @@
   f.erase();
 }
 
+TEST_FUNC(operator_or) {
+  auto i1Type = IntegerType::get(/*width=*/1, &globalContext());
+  auto f = makeFunction("operator_or", {}, {i1Type, i1Type});
+
+  OpBuilder builder(f.getBody());
+  ScopedContext scope(builder, f.getLoc());
+
+  using op::operator||;
+  ValueHandle lhs(f.getArgument(0));
+  ValueHandle rhs(f.getArgument(1));
+  lhs || rhs;
+
+  // CHECK-LABEL: @operator_or
+  //       CHECK: [[ARG0:%.*]]: i1, [[ARG1:%.*]]: i1
+  //       CHECK: or [[ARG0]], [[ARG1]]
+  f.print(llvm::outs());
+  f.erase();
+}
+
+TEST_FUNC(operator_and) {
+  auto i1Type = IntegerType::get(/*width=*/1, &globalContext());
+  auto f = makeFunction("operator_and", {}, {i1Type, i1Type});
+
+  OpBuilder builder(f.getBody());
+  ScopedContext scope(builder, f.getLoc());
+
+  using op::operator&&;
+  ValueHandle lhs(f.getArgument(0));
+  ValueHandle rhs(f.getArgument(1));
+  lhs &&rhs;
+
+  // CHECK-LABEL: @operator_and
+  //       CHECK: [[ARG0:%.*]]: i1, [[ARG1:%.*]]: i1
+  //       CHECK: and [[ARG0]], [[ARG1]]
+  f.print(llvm::outs());
+  f.erase();
+}
+
 TEST_FUNC(select_op_i32) {
   using namespace edsc::op;
   auto indexType = IndexType::get(&globalContext());
Index: mlir/lib/Dialect/AffineOps/EDSC/Builders.cpp
===================================================================
--- mlir/lib/Dialect/AffineOps/EDSC/Builders.cpp
+++ mlir/lib/Dialect/AffineOps/EDSC/Builders.cpp
@@ -209,11 +209,13 @@
 ValueHandle mlir::edsc::op::operator&&(ValueHandle lhs, ValueHandle rhs) {
   assert(lhs.getType().isInteger(1) && "expected boolean expression on LHS");
   assert(rhs.getType().isInteger(1) && "expected boolean expression on RHS");
-  return lhs * rhs;
+  return ValueHandle::create<AndOp>(lhs, rhs);
 }
 
 ValueHandle mlir::edsc::op::operator||(ValueHandle lhs, ValueHandle rhs) {
-  return !(!lhs && !rhs);
+  assert(lhs.getType().isInteger(1) && "expected boolean expression on LHS");
+  assert(rhs.getType().isInteger(1) && "expected boolean expression on RHS");
+  return ValueHandle::create<OrOp>(lhs, rhs);
 }
 
 static ValueHandle createIComparisonExpr(CmpIPredicate predicate,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75764.249506.patch
Type: text/x-patch
Size: 2331 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200310/6f1b3599/attachment.bin>


More information about the llvm-commits mailing list