[Mlir-commits] [mlir] 0c02106 - [mlir][EDSC] Retire OperationHandle

Nicolas Vasilache llvmlistbot at llvm.org
Tue Apr 28 21:38:40 PDT 2020


Author: Nicolas Vasilache
Date: 2020-04-29T00:32:44-04:00
New Revision: 0c02106058a35493339e3275d8ca6b825fad8a67

URL: https://github.com/llvm/llvm-project/commit/0c02106058a35493339e3275d8ca6b825fad8a67
DIFF: https://github.com/llvm/llvm-project/commit/0c02106058a35493339e3275d8ca6b825fad8a67.diff

LOG: [mlir][EDSC] Retire OperationHandle

OperationHandle mostly existed to mirror the behavior of ValueHandle.
This has become unnecessary and can be retired.

Differential Revision: https://reviews.llvm.org/D78692

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Affine/EDSC/Builders.h
    mlir/include/mlir/Dialect/Affine/EDSC/Intrinsics.h
    mlir/include/mlir/Dialect/Linalg/EDSC/Builders.h
    mlir/include/mlir/Dialect/LoopOps/EDSC/Intrinsics.h
    mlir/include/mlir/Dialect/StandardOps/EDSC/Intrinsics.h
    mlir/include/mlir/Dialect/Vector/EDSC/Builders.h
    mlir/include/mlir/EDSC/Builders.h
    mlir/lib/Conversion/AVX512ToLLVM/ConvertAVX512ToLLVM.cpp
    mlir/lib/Dialect/Linalg/EDSC/Builders.cpp
    mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp
    mlir/lib/Dialect/LoopOps/EDSC/Builders.cpp
    mlir/lib/Dialect/StandardOps/EDSC/Intrinsics.cpp
    mlir/lib/Dialect/Vector/EDSC/Builders.cpp
    mlir/lib/EDSC/Builders.cpp
    mlir/test/EDSC/builder-api-test.cpp

Removed: 
    mlir/include/mlir/EDSC/Intrinsics.h


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Affine/EDSC/Builders.h b/mlir/include/mlir/Dialect/Affine/EDSC/Builders.h
index 863915aa15bf..0d9da1fe0dce 100644
--- a/mlir/include/mlir/Dialect/Affine/EDSC/Builders.h
+++ b/mlir/include/mlir/Dialect/Affine/EDSC/Builders.h
@@ -127,34 +127,34 @@ Value TemplatedIndexedValue<Load, Store>::operator^(Value e) {
 
 /// Assignment-arithmetic operator overloadings.
 template <typename Load, typename Store>
-OperationHandle TemplatedIndexedValue<Load, Store>::operator+=(Value e) {
+Store TemplatedIndexedValue<Load, Store>::operator+=(Value e) {
   using op::operator+;
-  return Store(*this + e, getBase(), {indices.begin(), indices.end()});
+  return Store(*this + e, getBase(), indices);
 }
 template <typename Load, typename Store>
-OperationHandle TemplatedIndexedValue<Load, Store>::operator-=(Value e) {
+Store TemplatedIndexedValue<Load, Store>::operator-=(Value e) {
   using op::operator-;
-  return Store(*this - e, getBase(), {indices.begin(), indices.end()});
+  return Store(*this - e, getBase(), indices);
 }
 template <typename Load, typename Store>
-OperationHandle TemplatedIndexedValue<Load, Store>::operator*=(Value e) {
+Store TemplatedIndexedValue<Load, Store>::operator*=(Value e) {
   using op::operator*;
-  return Store(*this * e, getBase(), {indices.begin(), indices.end()});
+  return Store(*this * e, getBase(), indices);
 }
 template <typename Load, typename Store>
-OperationHandle TemplatedIndexedValue<Load, Store>::operator/=(Value e) {
+Store TemplatedIndexedValue<Load, Store>::operator/=(Value e) {
   using op::operator/;
-  return Store(*this / e, getBase(), {indices.begin(), indices.end()});
+  return Store(*this / e, getBase(), indices);
 }
 template <typename Load, typename Store>
-OperationHandle TemplatedIndexedValue<Load, Store>::operator%=(Value e) {
+Store TemplatedIndexedValue<Load, Store>::operator%=(Value e) {
   using op::operator%;
-  return Store(*this % e, getBase(), {indices.begin(), indices.end()});
+  return Store(*this % e, getBase(), indices);
 }
 template <typename Load, typename Store>
-OperationHandle TemplatedIndexedValue<Load, Store>::operator^=(Value e) {
+Store TemplatedIndexedValue<Load, Store>::operator^=(Value e) {
   using op::operator^;
-  return Store(*this ^ e, getBase(), {indices.begin(), indices.end()});
+  return Store(*this ^ e, getBase(), indices);
 }
 
 /// Logical operator overloadings.

diff  --git a/mlir/include/mlir/Dialect/Affine/EDSC/Intrinsics.h b/mlir/include/mlir/Dialect/Affine/EDSC/Intrinsics.h
index 392e2433b992..04595b7fd862 100644
--- a/mlir/include/mlir/Dialect/Affine/EDSC/Intrinsics.h
+++ b/mlir/include/mlir/Dialect/Affine/EDSC/Intrinsics.h
@@ -9,7 +9,6 @@
 #define MLIR_DIALECT_AFFINE_EDSC_INTRINSICS_H_
 
 #include "mlir/Dialect/Affine/EDSC/Builders.h"
-#include "mlir/EDSC/Intrinsics.h"
 
 namespace mlir {
 namespace edsc {

diff  --git a/mlir/include/mlir/Dialect/Linalg/EDSC/Builders.h b/mlir/include/mlir/Dialect/Linalg/EDSC/Builders.h
index 1608a1ad4ab1..5180c58b6498 100644
--- a/mlir/include/mlir/Dialect/Linalg/EDSC/Builders.h
+++ b/mlir/include/mlir/Dialect/Linalg/EDSC/Builders.h
@@ -18,7 +18,6 @@
 #include "mlir/Dialect/StandardOps/IR/Ops.h"
 #include "mlir/Dialect/Utils/StructuredOpsUtils.h"
 #include "mlir/EDSC/Builders.h"
-#include "mlir/EDSC/Intrinsics.h"
 #include "mlir/IR/AffineExpr.h"
 #include "mlir/IR/Builders.h"
 

diff  --git a/mlir/include/mlir/Dialect/LoopOps/EDSC/Intrinsics.h b/mlir/include/mlir/Dialect/LoopOps/EDSC/Intrinsics.h
index 21803e2bf13b..1a1b3a0010b2 100644
--- a/mlir/include/mlir/Dialect/LoopOps/EDSC/Intrinsics.h
+++ b/mlir/include/mlir/Dialect/LoopOps/EDSC/Intrinsics.h
@@ -10,11 +10,11 @@
 #define MLIR_DIALECT_LOOPOPS_EDSC_INTRINSICS_H_
 
 #include "mlir/Dialect/LoopOps/EDSC/Builders.h"
-#include "mlir/EDSC/Intrinsics.h"
 
 namespace mlir {
 namespace edsc {
 namespace intrinsics {
+
 using loop_yield = OperationBuilder<loop::YieldOp>;
 
 } // namespace intrinsics

diff  --git a/mlir/include/mlir/Dialect/StandardOps/EDSC/Intrinsics.h b/mlir/include/mlir/Dialect/StandardOps/EDSC/Intrinsics.h
index ca1a19609490..2644c82d6406 100644
--- a/mlir/include/mlir/Dialect/StandardOps/EDSC/Intrinsics.h
+++ b/mlir/include/mlir/Dialect/StandardOps/EDSC/Intrinsics.h
@@ -9,7 +9,6 @@
 #define MLIR_DIALECT_STANDARDOPS_EDSC_INTRINSICS_H_
 
 #include "mlir/Dialect/StandardOps/EDSC/Builders.h"
-#include "mlir/EDSC/Intrinsics.h"
 
 namespace mlir {
 namespace edsc {
@@ -46,7 +45,7 @@ using std_sign_extendi = ValueBuilder<SignExtendIOp>;
 ///
 /// Prerequisites:
 ///   All Handles have already captured previously constructed IR objects.
-OperationHandle std_br(BlockHandle bh, ArrayRef<Value> operands);
+BranchOp std_br(BlockHandle bh, ValueRange operands);
 
 /// Creates a new mlir::Block* and branches to it from the current block.
 /// Argument types are specified by `operands`.
@@ -61,9 +60,8 @@ OperationHandle std_br(BlockHandle bh, ArrayRef<Value> operands);
 ///   All `operands` have already captured an mlir::Value
 ///   captures.size() == operands.size()
 ///   captures and operands are pairwise of the same type.
-OperationHandle std_br(BlockHandle *bh, ArrayRef<Type> types,
-                       MutableArrayRef<Value> captures,
-                       ArrayRef<Value> operands);
+BranchOp std_br(BlockHandle *bh, ArrayRef<Type> types,
+                MutableArrayRef<Value> captures, ValueRange operands);
 
 /// Branches into the mlir::Block* captured by BlockHandle `trueBranch` with
 /// `trueOperands` if `cond` evaluates to `true` (resp. `falseBranch` and
@@ -71,10 +69,9 @@ OperationHandle std_br(BlockHandle *bh, ArrayRef<Type> types,
 ///
 /// Prerequisites:
 ///   All Handles have captured previously constructed IR objects.
-OperationHandle std_cond_br(Value cond, BlockHandle trueBranch,
-                            ArrayRef<Value> trueOperands,
-                            BlockHandle falseBranch,
-                            ArrayRef<Value> falseOperands);
+CondBranchOp std_cond_br(Value cond, BlockHandle trueBranch,
+                         ValueRange trueOperands, BlockHandle falseBranch,
+                         ValueRange falseOperands);
 
 /// Eagerly creates new mlir::Block* with argument types specified by
 /// `trueOperands`/`falseOperands`.
@@ -92,13 +89,11 @@ OperationHandle std_cond_br(Value cond, BlockHandle trueBranch,
 ///   `falseCaptures`.size() == `falseOperands`.size()
 ///   `trueCaptures` and `trueOperands` are pairwise of the same type
 ///   `falseCaptures` and `falseOperands` are pairwise of the same type.
-OperationHandle std_cond_br(Value cond, BlockHandle *trueBranch,
-                            ArrayRef<Type> trueTypes,
-                            MutableArrayRef<Value> trueCaptures,
-                            ArrayRef<Value> trueOperands,
-                            BlockHandle *falseBranch, ArrayRef<Type> falseTypes,
-                            MutableArrayRef<Value> falseCaptures,
-                            ArrayRef<Value> falseOperands);
+CondBranchOp
+std_cond_br(Value cond, BlockHandle *trueBranch, ArrayRef<Type> trueTypes,
+            MutableArrayRef<Value> trueCaptures, ValueRange trueOperands,
+            BlockHandle *falseBranch, ArrayRef<Type> falseTypes,
+            MutableArrayRef<Value> falseCaptures, ValueRange falseOperands);
 
 /// Provide an index notation around sdt_load and std_store.
 using StdIndexedValue =

diff  --git a/mlir/include/mlir/Dialect/Vector/EDSC/Builders.h b/mlir/include/mlir/Dialect/Vector/EDSC/Builders.h
index 396053f63213..65767af61b2d 100644
--- a/mlir/include/mlir/Dialect/Vector/EDSC/Builders.h
+++ b/mlir/include/mlir/Dialect/Vector/EDSC/Builders.h
@@ -16,7 +16,6 @@
 #include "mlir/Dialect/Utils/StructuredOpsUtils.h"
 #include "mlir/Dialect/Vector/VectorOps.h"
 #include "mlir/EDSC/Builders.h"
-#include "mlir/EDSC/Intrinsics.h"
 #include "mlir/IR/AffineExpr.h"
 #include "mlir/IR/Builders.h"
 

diff  --git a/mlir/include/mlir/EDSC/Builders.h b/mlir/include/mlir/EDSC/Builders.h
index 0ef894930ed8..f0bc1e8bad9a 100644
--- a/mlir/include/mlir/EDSC/Builders.h
+++ b/mlir/include/mlir/EDSC/Builders.h
@@ -72,21 +72,28 @@ class ScopedContext {
 
 template <typename Op>
 struct ValueBuilder {
-  // Builder-based
   template <typename... Args>
   ValueBuilder(Args... args) {
-    Operation *op = ScopedContext::getBuilder()
-                        .create<Op>(ScopedContext::getLocation(), args...)
-                        .getOperation();
-    if (op->getNumResults() != 1)
-      llvm_unreachable("unsupported operation, use OperationBuilder instead");
-    value = op->getResult(0);
+    value = ScopedContext::getBuilder()
+                .create<Op>(ScopedContext::getLocation(), args...)
+                .getResult();
   }
-
   operator Value() { return value; }
   Value value;
 };
 
+template <typename Op>
+struct OperationBuilder {
+  template <typename... Args>
+  OperationBuilder(Args... args) {
+    op = ScopedContext::getBuilder().create<Op>(ScopedContext::getLocation(),
+                                                args...);
+  }
+  operator Op() { return op; }
+  operator Operation *() { return op.getOperation(); }
+  Op op;
+};
+
 /// A NestedBuilder is a scoping abstraction to create an idiomatic syntax
 /// embedded in C++ that serves the purpose of building nested MLIR.
 /// Nesting and compositionality is obtained by using the strict ordering that
@@ -168,15 +175,13 @@ class LoopBuilder : public NestedBuilder {
 private:
   LoopBuilder() = default;
 
-  friend LoopBuilder makeAffineLoopBuilder(Value *iv, ArrayRef<Value> lbHandles,
-                                           ArrayRef<Value> ubHandles,
-                                           int64_t step);
+  friend LoopBuilder makeAffineLoopBuilder(Value *iv, ArrayRef<Value> lbs,
+                                           ArrayRef<Value> ubs, int64_t step);
   friend LoopBuilder makeParallelLoopBuilder(MutableArrayRef<Value> ivs,
-                                             ArrayRef<Value> lbHandles,
-                                             ArrayRef<Value> ubHandles,
+                                             ArrayRef<Value> lbs,
+                                             ArrayRef<Value> ubs,
                                              ArrayRef<Value> steps);
-  friend LoopBuilder makeLoopBuilder(Value *iv, Value lbHandle, Value ubHandle,
-                                     Value stepHandle,
+  friend LoopBuilder makeLoopBuilder(Value *iv, Value lb, Value ub, Value step,
                                      MutableArrayRef<Value> iterArgsHandles,
                                      ValueRange iterArgsInitValues);
   Operation *op;
@@ -229,52 +234,12 @@ class BlockBuilder : public NestedBuilder {
   BlockBuilder &operator=(BlockBuilder &other) = delete;
 };
 
-/// Base class for Value, OperationHandle and BlockHandle.
-/// Not meant to be used outside of these classes.
-class CapturableHandle {
-protected:
-  CapturableHandle() = default;
-};
-
-/// An OperationHandle can be used in lieu of Value to capture the
-/// operation in cases when one does not care about, or cannot extract, a
-/// unique Value from the operation.
-/// This can be used for capturing zero result operations as well as
-/// multi-result operations that are not supported by Value.
-/// We do not distinguish further between zero and multi-result operations at
-/// this time.
-struct OperationHandle : public CapturableHandle {
-  OperationHandle() : op(nullptr) {}
-  OperationHandle(Operation *op) : op(op) {}
-
-  OperationHandle(const OperationHandle &) = default;
-  OperationHandle &operator=(const OperationHandle &) = default;
-
-  /// Generic mlir::Op create. This is the key to being extensible to the whole
-  /// of MLIR without duplicating the type system or the op definitions.
-  template <typename Op, typename... Args>
-  static OperationHandle create(Args... args);
-  template <typename Op, typename... Args>
-  static Op createOp(Args... args);
-
-  /// Generic create for a named operation.
-  static OperationHandle create(StringRef name, ArrayRef<Value> operands,
-                                ArrayRef<Type> resultTypes,
-                                ArrayRef<NamedAttribute> attributes = {});
-
-  operator Operation *() { return op; }
-  Operation *getOperation() const { return op; }
-
-private:
-  Operation *op;
-};
-
 /// A BlockHandle represents a (potentially "delayed") Block abstraction.
 /// This extra abstraction is necessary because an mlir::Block is not an
 /// mlir::Value.
 /// A BlockHandle should be captured by pointer but otherwise passed by Value
 /// everywhere.
-class BlockHandle : public CapturableHandle {
+class BlockHandle {
 public:
   /// A BlockHandle constructed without an mlir::Block* represents a "delayed"
   /// Block. A delayed Block represents the declaration (in the PL sense) of a
@@ -361,22 +326,6 @@ struct StructuredIndexed {
   SmallVector<AffineExpr, 4> exprs;
 };
 
-template <typename Op, typename... Args>
-OperationHandle OperationHandle::create(Args... args) {
-  return OperationHandle(ScopedContext::getBuilder()
-                             .create<Op>(ScopedContext::getLocation(), args...)
-                             .getOperation());
-}
-
-template <typename Op, typename... Args>
-Op OperationHandle::createOp(Args... args) {
-  return cast<Op>(
-      OperationHandle(ScopedContext::getBuilder()
-                          .create<Op>(ScopedContext::getLocation(), args...)
-                          .getOperation())
-          .getOperation());
-}
-
 /// A TemplatedIndexedValue brings an index notation over the template Load and
 /// Store parameters. Assigning to an IndexedValue emits an actual `Store`
 /// operation, while converting an IndexedValue to a Value emits an actual
@@ -404,10 +353,10 @@ class TemplatedIndexedValue {
   }
 
   /// Emits a `store`.
-  OperationHandle operator=(const TemplatedIndexedValue &rhs) {
+  Store operator=(const TemplatedIndexedValue &rhs) {
     return Store(rhs, value, indices);
   }
-  OperationHandle operator=(Value rhs) { return Store(rhs, value, indices); }
+  Store operator=(Value rhs) { return Store(rhs, value, indices); }
 
   /// Emits a `load` when converting to a Value.
   operator Value() const { return Load(value, indices); }
@@ -441,28 +390,28 @@ class TemplatedIndexedValue {
   }
 
   /// Assignment-arithmetic operator overloadings.
-  OperationHandle operator+=(Value e);
-  OperationHandle operator-=(Value e);
-  OperationHandle operator*=(Value e);
-  OperationHandle operator/=(Value e);
-  OperationHandle operator%=(Value e);
-  OperationHandle operator^=(Value e);
-  OperationHandle operator+=(TemplatedIndexedValue e) {
+  Store operator+=(Value e);
+  Store operator-=(Value e);
+  Store operator*=(Value e);
+  Store operator/=(Value e);
+  Store operator%=(Value e);
+  Store operator^=(Value e);
+  Store operator+=(TemplatedIndexedValue e) {
     return this->operator+=(static_cast<Value>(e));
   }
-  OperationHandle operator-=(TemplatedIndexedValue e) {
+  Store operator-=(TemplatedIndexedValue e) {
     return this->operator-=(static_cast<Value>(e));
   }
-  OperationHandle operator*=(TemplatedIndexedValue e) {
+  Store operator*=(TemplatedIndexedValue e) {
     return this->operator*=(static_cast<Value>(e));
   }
-  OperationHandle operator/=(TemplatedIndexedValue e) {
+  Store operator/=(TemplatedIndexedValue e) {
     return this->operator/=(static_cast<Value>(e));
   }
-  OperationHandle operator%=(TemplatedIndexedValue e) {
+  Store operator%=(TemplatedIndexedValue e) {
     return this->operator%=(static_cast<Value>(e));
   }
-  OperationHandle operator^=(TemplatedIndexedValue e) {
+  Store operator^=(TemplatedIndexedValue e) {
     return this->operator^=(static_cast<Value>(e));
   }
 

diff  --git a/mlir/include/mlir/EDSC/Intrinsics.h b/mlir/include/mlir/EDSC/Intrinsics.h
deleted file mode 100644
index 14fa16ae0602..000000000000
--- a/mlir/include/mlir/EDSC/Intrinsics.h
+++ /dev/null
@@ -1,56 +0,0 @@
-//===- Intrinsics.h - MLIR Operations for Declarative Builders ---*- C++-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Provides intuitive composable intrinsics for building snippets of MLIR
-// declaratively.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef MLIR_EDSC_INTRINSICS_H_
-#define MLIR_EDSC_INTRINSICS_H_
-
-#include "mlir/EDSC/Builders.h"
-#include "mlir/IR/StandardTypes.h"
-#include "mlir/Support/LLVM.h"
-
-namespace mlir {
-
-class MemRefType;
-class Type;
-
-namespace edsc {
-
-/// Provides a set of first class intrinsics.
-/// In the future, most of intrinsics related to Operation that don't contain
-/// other operations should be Tablegen'd.
-namespace intrinsics {
-
-template <typename Op>
-struct OperationBuilder : public OperationHandle {
-  template <typename... Args>
-  OperationBuilder(Args... args)
-      : OperationHandle(OperationHandle::create<Op>(args...)) {}
-  OperationBuilder(ArrayRef<Value> vs)
-      : OperationHandle(OperationHandle::create<Op>(vs)) {}
-  template <typename... Args>
-  OperationBuilder(ArrayRef<Value> vs, Args... args)
-      : OperationHandle(OperationHandle::create<Op>(vs, args...)) {}
-  template <typename T, typename... Args>
-  OperationBuilder(T t, ArrayRef<Value> vs, Args... args)
-      : OperationHandle(OperationHandle::create<Op>(t, vs, args...)) {}
-  template <typename T1, typename T2, typename... Args>
-  OperationBuilder(T1 t1, T2 t2, ArrayRef<Value> vs, Args... args)
-      : OperationHandle(OperationHandle::create<Op>(t1, t2, vs, args...)) {}
-  OperationBuilder() : OperationHandle(OperationHandle::create<Op>()) {}
-};
-
-} // namespace intrinsics
-} // namespace edsc
-} // namespace mlir
-
-#endif // MLIR_EDSC_INTRINSICS_H_

diff  --git a/mlir/lib/Conversion/AVX512ToLLVM/ConvertAVX512ToLLVM.cpp b/mlir/lib/Conversion/AVX512ToLLVM/ConvertAVX512ToLLVM.cpp
index 33fd169c6fda..0753e388f72e 100644
--- a/mlir/lib/Conversion/AVX512ToLLVM/ConvertAVX512ToLLVM.cpp
+++ b/mlir/lib/Conversion/AVX512ToLLVM/ConvertAVX512ToLLVM.cpp
@@ -17,14 +17,11 @@
 #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
 #include "mlir/Dialect/StandardOps/IR/Ops.h"
 #include "mlir/Dialect/Vector/VectorOps.h"
-#include "mlir/EDSC/Intrinsics.h"
 #include "mlir/IR/Module.h"
 #include "mlir/IR/PatternMatch.h"
 #include "mlir/Pass/Pass.h"
 
 using namespace mlir;
-using namespace mlir::edsc;
-using namespace mlir::edsc::intrinsics;
 using namespace mlir::vector;
 using namespace mlir::avx512;
 

diff  --git a/mlir/lib/Dialect/Linalg/EDSC/Builders.cpp b/mlir/lib/Dialect/Linalg/EDSC/Builders.cpp
index ed0b2d66da61..1b78af019cfb 100644
--- a/mlir/lib/Dialect/Linalg/EDSC/Builders.cpp
+++ b/mlir/lib/Dialect/Linalg/EDSC/Builders.cpp
@@ -28,7 +28,7 @@ mlir::edsc::LoopRangeBuilder::LoopRangeBuilder(Value *iv, Value range) {
   auto lb = rangeOp.min();
   auto ub = rangeOp.max();
   auto step = rangeOp.step();
-  auto forOp = OperationHandle::createOp<ForOp>(lb, ub, step);
+  ForOp forOp = OperationBuilder<ForOp>(lb, ub, step);
   *iv = forOp.getInductionVar();
   auto *body = forOp.getBody();
   enter(body, /*prev=*/1);
@@ -36,8 +36,7 @@ mlir::edsc::LoopRangeBuilder::LoopRangeBuilder(Value *iv, Value range) {
 
 mlir::edsc::LoopRangeBuilder::LoopRangeBuilder(Value *iv,
                                                SubViewOp::Range range) {
-  auto forOp =
-      OperationHandle::createOp<ForOp>(range.offset, range.size, range.stride);
+  ForOp forOp = OperationBuilder<ForOp>(range.offset, range.size, range.stride);
   *iv = forOp.getInductionVar();
   auto *body = forOp.getBody();
   enter(body, /*prev=*/1);
@@ -53,18 +52,16 @@ Value mlir::edsc::LoopRangeBuilder::operator()(std::function<void(void)> fun) {
 mlir::edsc::LoopNestRangeBuilder::LoopNestRangeBuilder(
     MutableArrayRef<Value> ivs, ArrayRef<SubViewOp::Range> ranges) {
   loops.reserve(ranges.size());
-  for (unsigned i = 0, e = ranges.size(); i < e; ++i) {
+  for (unsigned i = 0, e = ranges.size(); i < e; ++i)
     loops.emplace_back(&ivs[i], ranges[i]);
-  }
   assert(loops.size() == ivs.size() && "Mismatch loops vs ivs size");
 }
 
 mlir::edsc::LoopNestRangeBuilder::LoopNestRangeBuilder(
     MutableArrayRef<Value> ivs, ArrayRef<Value> ranges) {
   loops.reserve(ranges.size());
-  for (unsigned i = 0, e = ranges.size(); i < e; ++i) {
+  for (unsigned i = 0, e = ranges.size(); i < e; ++i)
     loops.emplace_back(&ivs[i], ranges[i]);
-  }
   assert(loops.size() == ivs.size() && "Mismatch loops vs ivs size");
 }
 

diff  --git a/mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp b/mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp
index 88678e5d085c..4a6d54c97865 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp
@@ -547,10 +547,6 @@ class GenerateLoopNest<loop::ParallelOp, ConcreteOpTy> {
     // TODO(ravishankarm): Generate loop.parallel for all "parallel" iterator
     // types, not just the outer most ones. Also handle "reduction" iterator
     // types.
-    auto nPar = linalgOp.getNumParallelLoops();
-    auto nRed = linalgOp.getNumReductionLoops();
-    auto nWin = linalgOp.getNumWindowLoops();
-    auto nLoops = nPar + nRed + nWin;
     auto nOuterPar = linalgOp.iterator_types()
                          .getValue()
                          .take_while([](Attribute attr) {
@@ -560,14 +556,6 @@ class GenerateLoopNest<loop::ParallelOp, ConcreteOpTy> {
                          .size();
     // If there are no outer parallel loops, then number of loop ops is same as
     // the number of loops, and they are all loop.for ops.
-    auto nLoopOps = (nOuterPar ? nLoops - nOuterPar + 1 : nLoops);
-    SmallVector<OperationHandle, 4> allLoops(nLoopOps, OperationHandle());
-    SmallVector<OperationHandle *, 4> allPLoops;
-    allPLoops.reserve(allLoops.size());
-    for (OperationHandle &loop : allLoops)
-      allPLoops.push_back(&loop);
-    ArrayRef<OperationHandle *> allPLoopsRef(allPLoops);
-
     if (nOuterPar) {
       GenericLoopNestRangeBuilder<loop::ParallelOp>(
           allIvs.take_front(nOuterPar), loopRanges.take_front(nOuterPar))([&] {

diff  --git a/mlir/lib/Dialect/LoopOps/EDSC/Builders.cpp b/mlir/lib/Dialect/LoopOps/EDSC/Builders.cpp
index fec803deaec2..d8aa1a6a0f4a 100644
--- a/mlir/lib/Dialect/LoopOps/EDSC/Builders.cpp
+++ b/mlir/lib/Dialect/LoopOps/EDSC/Builders.cpp
@@ -82,13 +82,13 @@ LoopBuilder mlir::edsc::makeParallelLoopBuilder(MutableArrayRef<Value> ivs,
                                                 ArrayRef<Value> lbs,
                                                 ArrayRef<Value> ubs,
                                                 ArrayRef<Value> steps) {
-  LoopBuilder result;
-  auto opHandle = OperationHandle::create<loop::ParallelOp>(lbs, ubs, steps);
-
-  loop::ParallelOp parallelOp =
-      cast<loop::ParallelOp>(*opHandle.getOperation());
+  loop::ParallelOp parallelOp = OperationBuilder<loop::ParallelOp>(
+      SmallVector<Value, 4>(lbs.begin(), lbs.end()),
+      SmallVector<Value, 4>(ubs.begin(), ubs.end()),
+      SmallVector<Value, 4>(steps.begin(), steps.end()));
   for (size_t i = 0, e = ivs.size(); i < e; ++i)
     ivs[i] = parallelOp.getBody()->getArgument(i);
+  LoopBuilder result;
   result.enter(parallelOp.getBody(), /*prev=*/1);
   return result;
 }
@@ -98,9 +98,9 @@ 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>(lb, ub, step, iterArgsInitValues);
-  *iv = forOp.getInductionVar();
+  loop::ForOp forOp =
+      OperationBuilder<loop::ForOp>(lb, ub, step, iterArgsInitValues);
+  *iv = Value(forOp.getInductionVar());
   auto *body = loop::getForInductionVarOwner(*iv).getBody();
   for (size_t i = 0, e = iterArgsHandles.size(); i < e; ++i) {
     // Skipping the induction variable.

diff  --git a/mlir/lib/Dialect/StandardOps/EDSC/Intrinsics.cpp b/mlir/lib/Dialect/StandardOps/EDSC/Intrinsics.cpp
index cd8ad74ed4fd..614dfa926a0c 100644
--- a/mlir/lib/Dialect/StandardOps/EDSC/Intrinsics.cpp
+++ b/mlir/lib/Dialect/StandardOps/EDSC/Intrinsics.cpp
@@ -12,47 +12,43 @@
 using namespace mlir;
 using namespace mlir::edsc;
 
-OperationHandle mlir::edsc::intrinsics::std_br(BlockHandle bh,
-                                               ArrayRef<Value> operands) {
+BranchOp mlir::edsc::intrinsics::std_br(BlockHandle bh, ValueRange operands) {
   assert(bh && "Expected already captured BlockHandle");
-  for (auto &o : operands) {
-    (void)o;
-    assert(o && "Expected already captured Value");
-  }
   SmallVector<Value, 4> ops(operands.begin(), operands.end());
-  return OperationHandle::create<BranchOp>(bh.getBlock(), ops);
+  return OperationBuilder<BranchOp>(bh.getBlock(), ops);
 }
 
-OperationHandle mlir::edsc::intrinsics::std_br(BlockHandle *bh,
-                                               ArrayRef<Type> types,
-                                               MutableArrayRef<Value> captures,
-                                               ArrayRef<Value> operands) {
+BranchOp mlir::edsc::intrinsics::std_br(BlockHandle *bh, ArrayRef<Type> types,
+                                        MutableArrayRef<Value> captures,
+                                        ValueRange operands) {
   assert(!*bh && "Unexpected already captured BlockHandle");
   BlockBuilder(bh, types, captures)(/* no body */);
   SmallVector<Value, 4> ops(operands.begin(), operands.end());
-  return OperationHandle::create<BranchOp>(bh->getBlock(), ops);
+  return OperationBuilder<BranchOp>(bh->getBlock(), ops);
 }
 
-OperationHandle mlir::edsc::intrinsics::std_cond_br(
-    Value cond, BlockHandle trueBranch, ArrayRef<Value> trueOperands,
-    BlockHandle falseBranch, ArrayRef<Value> falseOperands) {
+CondBranchOp mlir::edsc::intrinsics::std_cond_br(Value cond,
+                                                 BlockHandle trueBranch,
+                                                 ValueRange trueOperands,
+                                                 BlockHandle falseBranch,
+                                                 ValueRange falseOperands) {
   SmallVector<Value, 4> trueOps(trueOperands.begin(), trueOperands.end());
   SmallVector<Value, 4> falseOps(falseOperands.begin(), falseOperands.end());
-  return OperationHandle::create<CondBranchOp>(
-      cond, trueBranch.getBlock(), trueOps, falseBranch.getBlock(), falseOps);
+  return OperationBuilder<CondBranchOp>(cond, trueBranch.getBlock(), trueOps,
+                                        falseBranch.getBlock(), falseOps);
 }
 
-OperationHandle mlir::edsc::intrinsics::std_cond_br(
+CondBranchOp mlir::edsc::intrinsics::std_cond_br(
     Value cond, BlockHandle *trueBranch, ArrayRef<Type> trueTypes,
-    MutableArrayRef<Value> trueCaptures, ArrayRef<Value> trueOperands,
+    MutableArrayRef<Value> trueCaptures, ValueRange trueOperands,
     BlockHandle *falseBranch, ArrayRef<Type> falseTypes,
-    MutableArrayRef<Value> falseCaptures, ArrayRef<Value> falseOperands) {
+    MutableArrayRef<Value> falseCaptures, ValueRange falseOperands) {
   assert(!*trueBranch && "Unexpected already captured BlockHandle");
   assert(!*falseBranch && "Unexpected already captured BlockHandle");
   BlockBuilder(trueBranch, trueTypes, trueCaptures)(/* no body */);
   BlockBuilder(falseBranch, falseTypes, falseCaptures)(/* no body */);
   SmallVector<Value, 4> trueOps(trueOperands.begin(), trueOperands.end());
   SmallVector<Value, 4> falseOps(falseOperands.begin(), falseOperands.end());
-  return OperationHandle::create<CondBranchOp>(
-      cond, trueBranch->getBlock(), trueOps, falseBranch->getBlock(), falseOps);
+  return OperationBuilder<CondBranchOp>(cond, trueBranch->getBlock(), trueOps,
+                                        falseBranch->getBlock(), falseOps);
 }

diff  --git a/mlir/lib/Dialect/Vector/EDSC/Builders.cpp b/mlir/lib/Dialect/Vector/EDSC/Builders.cpp
index 0759f93edaec..7d6d2b9432d7 100644
--- a/mlir/lib/Dialect/Vector/EDSC/Builders.cpp
+++ b/mlir/lib/Dialect/Vector/EDSC/Builders.cpp
@@ -10,7 +10,6 @@
 #include "mlir/Dialect/Vector/EDSC/Intrinsics.h"
 #include "mlir/Dialect/Vector/VectorOps.h"
 #include "mlir/EDSC/Builders.h"
-#include "mlir/EDSC/Intrinsics.h"
 #include "mlir/IR/AffineExpr.h"
 #include "mlir/IR/Builders.h"
 

diff  --git a/mlir/lib/EDSC/Builders.cpp b/mlir/lib/EDSC/Builders.cpp
index 247ca4af6c1a..5b94ebc994a7 100644
--- a/mlir/lib/EDSC/Builders.cpp
+++ b/mlir/lib/EDSC/Builders.cpp
@@ -65,20 +65,6 @@ MLIRContext *mlir::edsc::ScopedContext::getContext() {
   return getBuilder().getContext();
 }
 
-OperationHandle OperationHandle::create(StringRef name,
-                                        ArrayRef<Value> operands,
-                                        ArrayRef<Type> resultTypes,
-                                        ArrayRef<NamedAttribute> attributes) {
-  OperationState state(ScopedContext::getLocation(), name);
-  SmallVector<Value, 4> ops(operands.begin(), operands.end());
-  state.addOperands(ops);
-  state.addTypes(resultTypes);
-  for (const auto &attr : attributes) {
-    state.addAttribute(attr.first, attr.second);
-  }
-  return OperationHandle(ScopedContext::getBuilder().createOperation(state));
-}
-
 BlockHandle mlir::edsc::BlockHandle::create(ArrayRef<Type> argTypes) {
   auto &currentB = ScopedContext::getBuilder();
   auto *ib = currentB.getInsertionBlock();

diff  --git a/mlir/test/EDSC/builder-api-test.cpp b/mlir/test/EDSC/builder-api-test.cpp
index 76f478f46c8a..09e2d2f0d32f 100644
--- a/mlir/test/EDSC/builder-api-test.cpp
+++ b/mlir/test/EDSC/builder-api-test.cpp
@@ -15,7 +15,6 @@
 #include "mlir/Dialect/StandardOps/EDSC/Intrinsics.h"
 #include "mlir/Dialect/Vector/EDSC/Intrinsics.h"
 #include "mlir/EDSC/Builders.h"
-#include "mlir/EDSC/Intrinsics.h"
 #include "mlir/IR/AffineExpr.h"
 #include "mlir/IR/Builders.h"
 #include "mlir/IR/IntegerSet.h"


        


More information about the Mlir-commits mailing list