[Mlir-commits] [mlir] 3e08dcd - [mlir][inliner] Move callback types from InlinerConfig -> InlinerInterface. NFC.
Benjamin Kramer
llvmlistbot at llvm.org
Sun Apr 6 04:03:08 PDT 2025
Author: Benjamin Kramer
Date: 2025-04-06T13:02:42+02:00
New Revision: 3e08dcd767a217fa91580704a378b37167e20f74
URL: https://github.com/llvm/llvm-project/commit/3e08dcd767a217fa91580704a378b37167e20f74
DIFF: https://github.com/llvm/llvm-project/commit/3e08dcd767a217fa91580704a378b37167e20f74.diff
LOG: [mlir][inliner] Move callback types from InlinerConfig -> InlinerInterface. NFC.
The proper layering here is that Inliner depends on InlinerUtils, and
not the other way round. Maybe it's time to give InliningUtils a less
terrible file name.
Added:
Modified:
mlir/include/mlir/Transforms/Inliner.h
mlir/include/mlir/Transforms/InliningUtils.h
mlir/lib/Transforms/Utils/InliningUtils.cpp
mlir/test/lib/Transforms/TestInliningCallback.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Transforms/Inliner.h b/mlir/include/mlir/Transforms/Inliner.h
index 506b4455af646..0d3d3d1a3f9f2 100644
--- a/mlir/include/mlir/Transforms/Inliner.h
+++ b/mlir/include/mlir/Transforms/Inliner.h
@@ -17,6 +17,7 @@
#include "mlir/Interfaces/CallInterfaces.h"
#include "mlir/Pass/AnalysisManager.h"
#include "mlir/Pass/PassManager.h"
+#include "mlir/Transforms/InliningUtils.h"
#include "llvm/ADT/StringMap.h"
namespace mlir {
@@ -27,11 +28,6 @@ class InlinerConfig {
public:
using DefaultPipelineTy = std::function<void(OpPassManager &)>;
using OpPipelinesTy = llvm::StringMap<OpPassManager>;
- using CloneCallbackSigTy = void(OpBuilder &builder, Region *src,
- Block *inlineBlock, Block *postInsertBlock,
- IRMapping &mapper,
- bool shouldCloneInlinedRegion);
- using CloneCallbackTy = std::function<CloneCallbackSigTy>;
InlinerConfig() = default;
InlinerConfig(DefaultPipelineTy defaultPipeline,
@@ -44,7 +40,9 @@ class InlinerConfig {
}
const OpPipelinesTy &getOpPipelines() const { return opPipelines; }
unsigned getMaxInliningIterations() const { return maxInliningIterations; }
- const CloneCallbackTy &getCloneCallback() const { return cloneCallback; }
+ const InlinerInterface::CloneCallbackTy &getCloneCallback() const {
+ return cloneCallback;
+ }
bool getCanHandleMultipleBlocks() const { return canHandleMultipleBlocks; }
void setDefaultPipeline(DefaultPipelineTy pipeline) {
@@ -54,7 +52,7 @@ class InlinerConfig {
opPipelines = std::move(pipelines);
}
void setMaxInliningIterations(unsigned max) { maxInliningIterations = max; }
- void setCloneCallback(CloneCallbackTy callback) {
+ void setCloneCallback(InlinerInterface::CloneCallbackTy callback) {
cloneCallback = std::move(callback);
}
void setCanHandleMultipleBlocks(bool value = true) {
@@ -75,21 +73,21 @@ class InlinerConfig {
/// when inlining within an SCC.
unsigned maxInliningIterations{0};
/// Callback for cloning operations during inlining
- CloneCallbackTy cloneCallback = [](OpBuilder &builder, Region *src,
- Block *inlineBlock, Block *postInsertBlock,
- IRMapping &mapper,
- bool shouldCloneInlinedRegion) {
- // Check to see if the region is being cloned, or moved inline. In
- // either case, move the new blocks after the 'insertBlock' to improve
- // IR readability.
- Region *insertRegion = inlineBlock->getParent();
- if (shouldCloneInlinedRegion)
- src->cloneInto(insertRegion, postInsertBlock->getIterator(), mapper);
- else
- insertRegion->getBlocks().splice(postInsertBlock->getIterator(),
- src->getBlocks(), src->begin(),
- src->end());
- };
+ InlinerInterface::CloneCallbackTy cloneCallback =
+ [](OpBuilder &builder, Region *src, Block *inlineBlock,
+ Block *postInsertBlock, IRMapping &mapper,
+ bool shouldCloneInlinedRegion) {
+ // Check to see if the region is being cloned, or moved inline. In
+ // either case, move the new blocks after the 'insertBlock' to improve
+ // IR readability.
+ Region *insertRegion = inlineBlock->getParent();
+ if (shouldCloneInlinedRegion)
+ src->cloneInto(insertRegion, postInsertBlock->getIterator(), mapper);
+ else
+ insertRegion->getBlocks().splice(postInsertBlock->getIterator(),
+ src->getBlocks(), src->begin(),
+ src->end());
+ };
/// Determine if the inliner can inline a function containing multiple
/// blocks into a region that requires a single block. By default, it is
/// not allowed. If it is true, cloneCallback should perform the extra
diff --git a/mlir/include/mlir/Transforms/InliningUtils.h b/mlir/include/mlir/Transforms/InliningUtils.h
index 552030983d724..ed6413d8cd44c 100644
--- a/mlir/include/mlir/Transforms/InliningUtils.h
+++ b/mlir/include/mlir/Transforms/InliningUtils.h
@@ -18,7 +18,6 @@
#include "mlir/IR/Location.h"
#include "mlir/IR/Region.h"
#include "mlir/IR/ValueRange.h"
-#include "mlir/Transforms/Inliner.h"
#include <optional>
namespace mlir {
@@ -192,6 +191,12 @@ class DialectInlinerInterface
class InlinerInterface
: public DialectInterfaceCollection<DialectInlinerInterface> {
public:
+ using CloneCallbackSigTy = void(OpBuilder &builder, Region *src,
+ Block *inlineBlock, Block *postInsertBlock,
+ IRMapping &mapper,
+ bool shouldCloneInlinedRegion);
+ using CloneCallbackTy = std::function<CloneCallbackSigTy>;
+
using Base::Base;
/// Process a set of blocks that have been inlined. This callback is invoked
@@ -256,14 +261,14 @@ class InlinerInterface
/// region should be cloned into the 'inlinePoint' or spliced directly.
LogicalResult
inlineRegion(InlinerInterface &interface,
- function_ref<InlinerConfig::CloneCallbackSigTy> cloneCallback,
+ function_ref<InlinerInterface::CloneCallbackSigTy> cloneCallback,
Region *src, Operation *inlinePoint, IRMapping &mapper,
ValueRange resultsToReplace, TypeRange regionResultTypes,
std::optional<Location> inlineLoc = std::nullopt,
bool shouldCloneInlinedRegion = true);
LogicalResult
inlineRegion(InlinerInterface &interface,
- function_ref<InlinerConfig::CloneCallbackSigTy> cloneCallback,
+ function_ref<InlinerInterface::CloneCallbackSigTy> cloneCallback,
Region *src, Block *inlineBlock, Block::iterator inlinePoint,
IRMapping &mapper, ValueRange resultsToReplace,
TypeRange regionResultTypes,
@@ -275,14 +280,14 @@ inlineRegion(InlinerInterface &interface,
/// in-favor of the region arguments when inlining.
LogicalResult
inlineRegion(InlinerInterface &interface,
- function_ref<InlinerConfig::CloneCallbackSigTy> cloneCallback,
+ function_ref<InlinerInterface::CloneCallbackSigTy> cloneCallback,
Region *src, Operation *inlinePoint, ValueRange inlinedOperands,
ValueRange resultsToReplace,
std::optional<Location> inlineLoc = std::nullopt,
bool shouldCloneInlinedRegion = true);
LogicalResult
inlineRegion(InlinerInterface &interface,
- function_ref<InlinerConfig::CloneCallbackSigTy> cloneCallback,
+ function_ref<InlinerInterface::CloneCallbackSigTy> cloneCallback,
Region *src, Block *inlineBlock, Block::iterator inlinePoint,
ValueRange inlinedOperands, ValueRange resultsToReplace,
std::optional<Location> inlineLoc = std::nullopt,
@@ -296,7 +301,7 @@ inlineRegion(InlinerInterface &interface,
/// spliced directly.
LogicalResult
inlineCall(InlinerInterface &interface,
- function_ref<InlinerConfig::CloneCallbackSigTy> cloneCallback,
+ function_ref<InlinerInterface::CloneCallbackSigTy> cloneCallback,
CallOpInterface call, CallableOpInterface callable, Region *src,
bool shouldCloneInlinedRegion = true);
diff --git a/mlir/lib/Transforms/Utils/InliningUtils.cpp b/mlir/lib/Transforms/Utils/InliningUtils.cpp
index 3dd95d2845715..f654e962d631f 100644
--- a/mlir/lib/Transforms/Utils/InliningUtils.cpp
+++ b/mlir/lib/Transforms/Utils/InliningUtils.cpp
@@ -11,7 +11,6 @@
//===----------------------------------------------------------------------===//
#include "mlir/Transforms/InliningUtils.h"
-#include "mlir/Transforms/Inliner.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/IRMapping.h"
@@ -266,13 +265,13 @@ static void handleResultImpl(InlinerInterface &interface, OpBuilder &builder,
}
}
-static LogicalResult
-inlineRegionImpl(InlinerInterface &interface,
- function_ref<InlinerConfig::CloneCallbackSigTy> cloneCallback,
- Region *src, Block *inlineBlock, Block::iterator inlinePoint,
- IRMapping &mapper, ValueRange resultsToReplace,
- TypeRange regionResultTypes, std::optional<Location> inlineLoc,
- bool shouldCloneInlinedRegion, CallOpInterface call = {}) {
+static LogicalResult inlineRegionImpl(
+ InlinerInterface &interface,
+ function_ref<InlinerInterface::CloneCallbackSigTy> cloneCallback,
+ Region *src, Block *inlineBlock, Block::iterator inlinePoint,
+ IRMapping &mapper, ValueRange resultsToReplace, TypeRange regionResultTypes,
+ std::optional<Location> inlineLoc, bool shouldCloneInlinedRegion,
+ CallOpInterface call = {}) {
assert(resultsToReplace.size() == regionResultTypes.size());
// We expect the region to have at least one block.
if (src->empty())
@@ -369,13 +368,13 @@ inlineRegionImpl(InlinerInterface &interface,
return success();
}
-static LogicalResult
-inlineRegionImpl(InlinerInterface &interface,
- function_ref<InlinerConfig::CloneCallbackSigTy> cloneCallback,
- Region *src, Block *inlineBlock, Block::iterator inlinePoint,
- ValueRange inlinedOperands, ValueRange resultsToReplace,
- std::optional<Location> inlineLoc,
- bool shouldCloneInlinedRegion, CallOpInterface call = {}) {
+static LogicalResult inlineRegionImpl(
+ InlinerInterface &interface,
+ function_ref<InlinerInterface::CloneCallbackSigTy> cloneCallback,
+ Region *src, Block *inlineBlock, Block::iterator inlinePoint,
+ ValueRange inlinedOperands, ValueRange resultsToReplace,
+ std::optional<Location> inlineLoc, bool shouldCloneInlinedRegion,
+ CallOpInterface call = {}) {
// We expect the region to have at least one block.
if (src->empty())
return failure();
@@ -404,10 +403,10 @@ inlineRegionImpl(InlinerInterface &interface,
LogicalResult mlir::inlineRegion(
InlinerInterface &interface,
- function_ref<InlinerConfig::CloneCallbackSigTy> cloneCallback, Region *src,
- Operation *inlinePoint, IRMapping &mapper, ValueRange resultsToReplace,
- TypeRange regionResultTypes, std::optional<Location> inlineLoc,
- bool shouldCloneInlinedRegion) {
+ function_ref<InlinerInterface::CloneCallbackSigTy> cloneCallback,
+ Region *src, Operation *inlinePoint, IRMapping &mapper,
+ ValueRange resultsToReplace, TypeRange regionResultTypes,
+ std::optional<Location> inlineLoc, bool shouldCloneInlinedRegion) {
return inlineRegion(interface, cloneCallback, src, inlinePoint->getBlock(),
++inlinePoint->getIterator(), mapper, resultsToReplace,
regionResultTypes, inlineLoc, shouldCloneInlinedRegion);
@@ -415,9 +414,9 @@ LogicalResult mlir::inlineRegion(
LogicalResult mlir::inlineRegion(
InlinerInterface &interface,
- function_ref<InlinerConfig::CloneCallbackSigTy> cloneCallback, Region *src,
- Block *inlineBlock, Block::iterator inlinePoint, IRMapping &mapper,
- ValueRange resultsToReplace, TypeRange regionResultTypes,
+ function_ref<InlinerInterface::CloneCallbackSigTy> cloneCallback,
+ Region *src, Block *inlineBlock, Block::iterator inlinePoint,
+ IRMapping &mapper, ValueRange resultsToReplace, TypeRange regionResultTypes,
std::optional<Location> inlineLoc, bool shouldCloneInlinedRegion) {
return inlineRegionImpl(
interface, cloneCallback, src, inlineBlock, inlinePoint, mapper,
@@ -426,8 +425,8 @@ LogicalResult mlir::inlineRegion(
LogicalResult mlir::inlineRegion(
InlinerInterface &interface,
- function_ref<InlinerConfig::CloneCallbackSigTy> cloneCallback, Region *src,
- Operation *inlinePoint, ValueRange inlinedOperands,
+ function_ref<InlinerInterface::CloneCallbackSigTy> cloneCallback,
+ Region *src, Operation *inlinePoint, ValueRange inlinedOperands,
ValueRange resultsToReplace, std::optional<Location> inlineLoc,
bool shouldCloneInlinedRegion) {
return inlineRegion(interface, cloneCallback, src, inlinePoint->getBlock(),
@@ -437,10 +436,10 @@ LogicalResult mlir::inlineRegion(
LogicalResult mlir::inlineRegion(
InlinerInterface &interface,
- function_ref<InlinerConfig::CloneCallbackSigTy> cloneCallback, Region *src,
- Block *inlineBlock, Block::iterator inlinePoint, ValueRange inlinedOperands,
- ValueRange resultsToReplace, std::optional<Location> inlineLoc,
- bool shouldCloneInlinedRegion) {
+ function_ref<InlinerInterface::CloneCallbackSigTy> cloneCallback,
+ Region *src, Block *inlineBlock, Block::iterator inlinePoint,
+ ValueRange inlinedOperands, ValueRange resultsToReplace,
+ std::optional<Location> inlineLoc, bool shouldCloneInlinedRegion) {
return inlineRegionImpl(interface, cloneCallback, src, inlineBlock,
inlinePoint, inlinedOperands, resultsToReplace,
inlineLoc, shouldCloneInlinedRegion);
@@ -474,11 +473,11 @@ static Value materializeConversion(const DialectInlinerInterface *interface,
/// failure, no changes are made to the module. 'shouldCloneInlinedRegion'
/// corresponds to whether the source region should be cloned into the 'call' or
/// spliced directly.
-LogicalResult
-mlir::inlineCall(InlinerInterface &interface,
- function_ref<InlinerConfig::CloneCallbackSigTy> cloneCallback,
- CallOpInterface call, CallableOpInterface callable,
- Region *src, bool shouldCloneInlinedRegion) {
+LogicalResult mlir::inlineCall(
+ InlinerInterface &interface,
+ function_ref<InlinerInterface::CloneCallbackSigTy> cloneCallback,
+ CallOpInterface call, CallableOpInterface callable, Region *src,
+ bool shouldCloneInlinedRegion) {
// We expect the region to have at least one block.
if (src->empty())
return failure();
diff --git a/mlir/test/lib/Transforms/TestInliningCallback.cpp b/mlir/test/lib/Transforms/TestInliningCallback.cpp
index 012d62b7b1b42..c518f3f4ac85f 100644
--- a/mlir/test/lib/Transforms/TestInliningCallback.cpp
+++ b/mlir/test/lib/Transforms/TestInliningCallback.cpp
@@ -61,8 +61,7 @@ struct InlinerCallback
src->cloneInto(®ion, mapper);
// Split block before scf operation.
- Block *continueBlock =
- inlineBlock->splitBlock(executeRegionOp.getOperation());
+ inlineBlock->splitBlock(executeRegionOp.getOperation());
// Replace all test.return with scf.yield
for (mlir::Block &block : region) {
More information about the Mlir-commits
mailing list