From 33dc956647076d9a1e214db53099b82b012025b9 Mon Sep 17 00:00:00 2001 From: Alex Zinenko Date: Wed, 29 May 2019 05:47:15 -0700 Subject: [PATCH] EDSC: use llvm::function_ref instead of std::function 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 | 6 +++--- mlir/lib/EDSC/Builders.cpp | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/mlir/include/mlir/EDSC/Builders.h b/mlir/include/mlir/EDSC/Builders.h index 2e9879b..4be2755 100644 --- a/mlir/include/mlir/EDSC/Builders.h +++ b/mlir/include/mlir/EDSC/Builders.h @@ -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 fun = nullptr); + ValueHandle operator()(llvm::function_ref fun = nullptr); }; /// Explicit nested LoopBuilder. Offers a compressed multi-loop builder to avoid @@ -201,7 +201,7 @@ public: LoopNestBuilder(ArrayRef ivs, ArrayRef lbs, ArrayRef ubs, ArrayRef steps); - ValueHandle operator()(std::function fun = nullptr); + ValueHandle operator()(llvm::function_ref fun = nullptr); private: SmallVector 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 fun = nullptr); + void operator()(llvm::function_ref fun = nullptr); private: BlockBuilder(BlockBuilder &) = delete; diff --git a/mlir/lib/EDSC/Builders.cpp b/mlir/lib/EDSC/Builders.cpp index 2708de9..d0fd3e9 100644 --- a/mlir/lib/EDSC/Builders.cpp +++ b/mlir/lib/EDSC/Builders.cpp @@ -184,7 +184,8 @@ mlir::edsc::LoopBuilder::LoopBuilder(ValueHandle *iv, enter(body, /*prev=*/1); } -ValueHandle mlir::edsc::LoopBuilder::operator()(std::function fun) { +ValueHandle +mlir::edsc::LoopBuilder::operator()(llvm::function_ref 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 ivs, } ValueHandle -mlir::edsc::LoopNestBuilder::operator()(std::function fun) { +mlir::edsc::LoopNestBuilder::operator()(llvm::function_ref 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 fun) { +void mlir::edsc::BlockBuilder::operator()(llvm::function_ref fun) { // Call to `exit` must be explicit and asymmetric (cannot happen in the // destructor) because of ordering wrt comma operator. if (fun) -- 2.7.4