[Mlir-commits] [mlir] da12d88 - [mlir][NFC] Add inlineRegion overloads that take a block iterator insert position
River Riddle
llvmlistbot at llvm.org
Mon Aug 23 12:55:43 PDT 2021
Author: River Riddle
Date: 2021-08-23T19:49:53Z
New Revision: da12d88b1c5fc42b49b92fcf94917ca489dd677f
URL: https://github.com/llvm/llvm-project/commit/da12d88b1c5fc42b49b92fcf94917ca489dd677f
DIFF: https://github.com/llvm/llvm-project/commit/da12d88b1c5fc42b49b92fcf94917ca489dd677f.diff
LOG: [mlir][NFC] Add inlineRegion overloads that take a block iterator insert position
This allows for inlining into an empty block or to the beginning of a block. NFC as the existing implementations now foward to this overload.
Differential Revision: https://reviews.llvm.org/D108572
Added:
Modified:
mlir/include/mlir/Transforms/InliningUtils.h
mlir/lib/Transforms/Utils/InliningUtils.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Transforms/InliningUtils.h b/mlir/include/mlir/Transforms/InliningUtils.h
index 8dcc1f5eb699d..1bf318cf0ecee 100644
--- a/mlir/include/mlir/Transforms/InliningUtils.h
+++ b/mlir/include/mlir/Transforms/InliningUtils.h
@@ -211,6 +211,13 @@ LogicalResult inlineRegion(InlinerInterface &interface, Region *src,
TypeRange regionResultTypes,
Optional<Location> inlineLoc = llvm::None,
bool shouldCloneInlinedRegion = true);
+LogicalResult inlineRegion(InlinerInterface &interface, Region *src,
+ Block *inlineBlock, Block::iterator inlinePoint,
+ BlockAndValueMapping &mapper,
+ ValueRange resultsToReplace,
+ TypeRange regionResultTypes,
+ Optional<Location> inlineLoc = llvm::None,
+ bool shouldCloneInlinedRegion = true);
/// This function is an overload of the above 'inlineRegion' that allows for
/// providing the set of operands ('inlinedOperands') that should be used
@@ -220,6 +227,12 @@ LogicalResult inlineRegion(InlinerInterface &interface, Region *src,
ValueRange resultsToReplace,
Optional<Location> inlineLoc = llvm::None,
bool shouldCloneInlinedRegion = true);
+LogicalResult inlineRegion(InlinerInterface &interface, Region *src,
+ Block *inlineBlock, Block::iterator inlinePoint,
+ ValueRange inlinedOperands,
+ ValueRange resultsToReplace,
+ Optional<Location> inlineLoc = llvm::None,
+ bool shouldCloneInlinedRegion = true);
/// This function inlines a given region, 'src', of a callable operation,
/// 'callable', into the location defined by the given call operation. This
diff --git a/mlir/lib/Transforms/Utils/InliningUtils.cpp b/mlir/lib/Transforms/Utils/InliningUtils.cpp
index 5b50d212fb075..3eed22d8a5b42 100644
--- a/mlir/lib/Transforms/Utils/InliningUtils.cpp
+++ b/mlir/lib/Transforms/Utils/InliningUtils.cpp
@@ -145,11 +145,11 @@ static bool isLegalToInline(InlinerInterface &interface, Region *src,
//===----------------------------------------------------------------------===//
static LogicalResult
-inlineRegionImpl(InlinerInterface &interface, Region *src,
- Operation *inlinePoint, BlockAndValueMapping &mapper,
+inlineRegionImpl(InlinerInterface &interface, Region *src, Block *inlineBlock,
+ Block::iterator inlinePoint, BlockAndValueMapping &mapper,
ValueRange resultsToReplace, TypeRange regionResultTypes,
Optional<Location> inlineLoc, bool shouldCloneInlinedRegion,
- Operation *call) {
+ Operation *call = nullptr) {
assert(resultsToReplace.size() == regionResultTypes.size());
// We expect the region to have at least one block.
if (src->empty())
@@ -161,26 +161,18 @@ inlineRegionImpl(InlinerInterface &interface, Region *src,
[&](BlockArgument arg) { return !mapper.contains(arg); }))
return failure();
- // The insertion point must be within a block.
- Block *insertBlock = inlinePoint->getBlock();
- if (!insertBlock)
- return failure();
- Region *insertRegion = insertBlock->getParent();
-
// Check that the operations within the source region are valid to inline.
+ Region *insertRegion = inlineBlock->getParent();
if (!interface.isLegalToInline(insertRegion, src, shouldCloneInlinedRegion,
mapper) ||
!isLegalToInline(interface, src, insertRegion, shouldCloneInlinedRegion,
mapper))
return failure();
- // Split the insertion block.
- Block *postInsertBlock =
- insertBlock->splitBlock(++inlinePoint->getIterator());
-
// 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.
+ Block *postInsertBlock = inlineBlock->splitBlock(inlinePoint);
if (shouldCloneInlinedRegion)
src->cloneInto(insertRegion, postInsertBlock->getIterator(), mapper);
else
@@ -189,7 +181,7 @@ inlineRegionImpl(InlinerInterface &interface, Region *src,
src->end());
// Get the range of newly inserted blocks.
- auto newBlocks = llvm::make_range(std::next(insertBlock->getIterator()),
+ auto newBlocks = llvm::make_range(std::next(inlineBlock->getIterator()),
postInsertBlock->getIterator());
Block *firstNewBlock = &*newBlocks.begin();
@@ -234,17 +226,17 @@ inlineRegionImpl(InlinerInterface &interface, Region *src,
}
// Splice the instructions of the inlined entry block into the insert block.
- insertBlock->getOperations().splice(insertBlock->end(),
+ inlineBlock->getOperations().splice(inlineBlock->end(),
firstNewBlock->getOperations());
firstNewBlock->erase();
return success();
}
static LogicalResult
-inlineRegionImpl(InlinerInterface &interface, Region *src,
- Operation *inlinePoint, ValueRange inlinedOperands,
+inlineRegionImpl(InlinerInterface &interface, Region *src, Block *inlineBlock,
+ Block::iterator inlinePoint, ValueRange inlinedOperands,
ValueRange resultsToReplace, Optional<Location> inlineLoc,
- bool shouldCloneInlinedRegion, Operation *call) {
+ bool shouldCloneInlinedRegion, Operation *call = nullptr) {
// We expect the region to have at least one block.
if (src->empty())
return failure();
@@ -265,9 +257,9 @@ inlineRegionImpl(InlinerInterface &interface, Region *src,
}
// Call into the main region inliner function.
- return inlineRegionImpl(interface, src, inlinePoint, mapper, resultsToReplace,
- resultsToReplace.getTypes(), inlineLoc,
- shouldCloneInlinedRegion, call);
+ return inlineRegionImpl(interface, src, inlineBlock, inlinePoint, mapper,
+ resultsToReplace, resultsToReplace.getTypes(),
+ inlineLoc, shouldCloneInlinedRegion, call);
}
LogicalResult mlir::inlineRegion(InlinerInterface &interface, Region *src,
@@ -277,10 +269,19 @@ LogicalResult mlir::inlineRegion(InlinerInterface &interface, Region *src,
TypeRange regionResultTypes,
Optional<Location> inlineLoc,
bool shouldCloneInlinedRegion) {
- return inlineRegionImpl(interface, src, inlinePoint, mapper, resultsToReplace,
- regionResultTypes, inlineLoc,
- shouldCloneInlinedRegion,
- /*call=*/nullptr);
+ return inlineRegion(interface, src, inlinePoint->getBlock(),
+ ++inlinePoint->getIterator(), mapper, resultsToReplace,
+ regionResultTypes, inlineLoc, shouldCloneInlinedRegion);
+}
+LogicalResult
+mlir::inlineRegion(InlinerInterface &interface, Region *src, Block *inlineBlock,
+ Block::iterator inlinePoint, BlockAndValueMapping &mapper,
+ ValueRange resultsToReplace, TypeRange regionResultTypes,
+ Optional<Location> inlineLoc,
+ bool shouldCloneInlinedRegion) {
+ return inlineRegionImpl(interface, src, inlineBlock, inlinePoint, mapper,
+ resultsToReplace, regionResultTypes, inlineLoc,
+ shouldCloneInlinedRegion);
}
LogicalResult mlir::inlineRegion(InlinerInterface &interface, Region *src,
@@ -289,9 +290,18 @@ LogicalResult mlir::inlineRegion(InlinerInterface &interface, Region *src,
ValueRange resultsToReplace,
Optional<Location> inlineLoc,
bool shouldCloneInlinedRegion) {
- return inlineRegionImpl(interface, src, inlinePoint, inlinedOperands,
- resultsToReplace, inlineLoc, shouldCloneInlinedRegion,
- /*call=*/nullptr);
+ return inlineRegion(interface, src, inlinePoint->getBlock(),
+ ++inlinePoint->getIterator(), inlinedOperands,
+ resultsToReplace, inlineLoc, shouldCloneInlinedRegion);
+}
+LogicalResult
+mlir::inlineRegion(InlinerInterface &interface, Region *src, Block *inlineBlock,
+ Block::iterator inlinePoint, ValueRange inlinedOperands,
+ ValueRange resultsToReplace, Optional<Location> inlineLoc,
+ bool shouldCloneInlinedRegion) {
+ return inlineRegionImpl(interface, src, inlineBlock, inlinePoint,
+ inlinedOperands, resultsToReplace, inlineLoc,
+ shouldCloneInlinedRegion);
}
/// Utility function used to generate a cast operation from the given interface,
@@ -399,7 +409,8 @@ LogicalResult mlir::inlineCall(InlinerInterface &interface,
return cleanupState();
// Attempt to inline the call.
- if (failed(inlineRegionImpl(interface, src, call, mapper, callResults,
+ if (failed(inlineRegionImpl(interface, src, call->getBlock(),
+ ++call->getIterator(), mapper, callResults,
callableResultTypes, call.getLoc(),
shouldCloneInlinedRegion, call)))
return cleanupState();
More information about the Mlir-commits
mailing list