EDSC: use llvm::function_ref instead of std::function
authorAlex Zinenko <zinenko@google.com>
Wed, 29 May 2019 12:47:15 +0000 (05:47 -0700)
committerMehdi Amini <joker.eph@gmail.com>
Sun, 2 Jun 2019 03:06:30 +0000 (20:06 -0700)
    Region body constructors in EDSC now take a callback to the function that fills
    in the body.  This callback is called immediately and not stored, so it is
    sufficient to pass a reference to it and avoid a potentially expensive copy.

--

PiperOrigin-RevId: 250473793

mlir/include/mlir/EDSC/Builders.h
mlir/lib/EDSC/Builders.cpp

index 2e9879b..4be2755 100644 (file)
@@ -171,7 +171,7 @@ public:
   /// The only purpose of this operator is to serve as a sequence point so that
   /// the evaluation of `fun` (which build IR snippets in a scoped fashion) is
   /// scoped within a LoopBuilder.
-  ValueHandle operator()(std::function<void(void)> fun = nullptr);
+  ValueHandle operator()(llvm::function_ref<void(void)> fun = nullptr);
 };
 
 /// Explicit nested LoopBuilder. Offers a compressed multi-loop builder to avoid
@@ -201,7 +201,7 @@ public:
   LoopNestBuilder(ArrayRef<ValueHandle *> ivs, ArrayRef<ValueHandle> lbs,
                   ArrayRef<ValueHandle> ubs, ArrayRef<int64_t> steps);
 
-  ValueHandle operator()(std::function<void(void)> fun = nullptr);
+  ValueHandle operator()(llvm::function_ref<void(void)> fun = nullptr);
 
 private:
   SmallVector<LoopBuilder, 4> loops;
@@ -234,7 +234,7 @@ public:
   /// The only purpose of this operator is to serve as a sequence point so that
   /// the evaluation of `fun` (which build IR snippets in a scoped fashion) is
   /// scoped within a BlockBuilder.
-  void operator()(std::function<void(void)> fun = nullptr);
+  void operator()(llvm::function_ref<void(void)> fun = nullptr);
 
 private:
   BlockBuilder(BlockBuilder &) = delete;
index 2708de9..d0fd3e9 100644 (file)
@@ -184,7 +184,8 @@ mlir::edsc::LoopBuilder::LoopBuilder(ValueHandle *iv,
   enter(body, /*prev=*/1);
 }
 
-ValueHandle mlir::edsc::LoopBuilder::operator()(std::function<void(void)> fun) {
+ValueHandle
+mlir::edsc::LoopBuilder::operator()(llvm::function_ref<void(void)> fun) {
   // Call to `exit` must be explicit and asymmetric (cannot happen in the
   // destructor) because of ordering wrt comma operator.
   /// The particular use case concerns nested blocks:
@@ -223,7 +224,7 @@ mlir::edsc::LoopNestBuilder::LoopNestBuilder(ArrayRef<ValueHandle *> ivs,
 }
 
 ValueHandle
-mlir::edsc::LoopNestBuilder::operator()(std::function<void(void)> fun) {
+mlir::edsc::LoopNestBuilder::operator()(llvm::function_ref<void(void)> fun) {
   if (fun)
     fun();
   // Iterate on the calling operator() on all the loops in the nest.
@@ -261,7 +262,7 @@ mlir::edsc::BlockBuilder::BlockBuilder(BlockHandle *bh,
 
 /// Only serves as an ordering point between entering nested block and creating
 /// stmts.
-void mlir::edsc::BlockBuilder::operator()(std::function<void(void)> fun) {
+void mlir::edsc::BlockBuilder::operator()(llvm::function_ref<void(void)> fun) {
   // Call to `exit` must be explicit and asymmetric (cannot happen in the
   // destructor) because of ordering wrt comma operator.
   if (fun)