[Mlir-commits] [mlir] [mlir][bufferization]-Add unhandled cases in EmptyTensorElimination (PR #118958)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Dec 6 04:27:57 PST 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 99dc3967595c472b6edbe789a1346b0350294567 cc099096617d2e301300eb91ddd5e6f5fa75a646 --extensions cpp,h -- mlir/include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp mlir/lib/Dialect/Bufferization/Transforms/EmptyTensorElimination.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/mlir/include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h b/mlir/include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h
index 284521177c..58afdd5df6 100644
--- a/mlir/include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h
+++ b/mlir/include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h
@@ -486,7 +486,7 @@ public:
SetVector<Value> findValueInReverseUseDefChain(
Value value, llvm::function_ref<bool(Value)> condition,
TraversalConfig config = TraversalConfig(),
- llvm::DenseSet<OpOperand*> *visitedOpOperands = nullptr) const;
+ llvm::DenseSet<OpOperand *> *visitedOpOperands = nullptr) const;
/// Find the values that may define the contents of the given value at
/// runtime. A block argument is always a definition. An OpResult is a
diff --git a/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp
index 3fbcf55475..03d8f2a934 100644
--- a/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp
+++ b/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp
@@ -488,7 +488,7 @@ bool AnalysisState::isValueRead(Value value) const {
llvm::SetVector<Value> AnalysisState::findValueInReverseUseDefChain(
Value value, llvm::function_ref<bool(Value)> condition,
TraversalConfig config,
- llvm::DenseSet<OpOperand*> *visitedOpOperands) const {
+ llvm::DenseSet<OpOperand *> *visitedOpOperands) const {
llvm::DenseSet<Value> visited;
llvm::SetVector<Value> result, workingSet;
workingSet.insert(value);
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/EmptyTensorElimination.cpp b/mlir/lib/Dialect/Bufferization/Transforms/EmptyTensorElimination.cpp
index 7f8c10350e..f814c3b2a6 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/EmptyTensorElimination.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/EmptyTensorElimination.cpp
@@ -57,17 +57,18 @@ neededValuesDominateInsertionPoint(const DominanceInfo &domInfo,
return true;
}
-/// Find a valid insertion point for a replacement of `useToBeEliminated`, assuming
-/// that the replacement may use any value from `neededValues`.
+/// Find a valid insertion point for a replacement of `useToBeEliminated`,
+/// assuming that the replacement may use any value from `neededValues`.
static Operation *
findValidInsertionPoint(OpOperand *useToBeEliminated,
const SmallVector<Value> &neededValues) {
DominanceInfo domInfo;
- Operation * candidateInsertionPoint = useToBeEliminated->getOwner();
+ Operation *candidateInsertionPoint = useToBeEliminated->getOwner();
assert(isa<OpResult>(useToBeEliminated->get()) && "expected a result value");
// Both `tensor.empty` and its user are within different blocks.
- if (useToBeEliminated->getOwner()->getBlock() != useToBeEliminated->get().getDefiningOp()->getBlock())
+ if (useToBeEliminated->getOwner()->getBlock() !=
+ useToBeEliminated->get().getDefiningOp()->getBlock())
candidateInsertionPoint = useToBeEliminated->get().getDefiningOp();
// Trying to move the needed values before the `emptyTensorOp`.
@@ -80,15 +81,17 @@ findValidInsertionPoint(OpOperand *useToBeEliminated,
bool isItSafeToMoveOp =
llvm::all_of(definingOp->getOperands(), [&](Value operand) {
- return valueDominateInsertionPoint(domInfo, candidateInsertionPoint, operand);
+ return valueDominateInsertionPoint(domInfo, candidateInsertionPoint,
+ operand);
});
if (isItSafeToMoveOp)
definingOp->moveBefore(candidateInsertionPoint);
}
- // Gather all possible insertion points: the location of `candidateInsertionPoint` and
- // right after the definition of each value in `neededValues`.
+ // Gather all possible insertion points: the location of
+ // `candidateInsertionPoint` and right after the definition of each value in
+ // `neededValues`.
SmallVector<Operation *> insertionPointCandidates;
insertionPointCandidates.push_back(candidateInsertionPoint);
for (Value val : neededValues) {
@@ -154,16 +157,17 @@ LogicalResult mlir::bufferization::eliminateEmptyTensors(
config.followSameTypeOrCastsOnly = true;
SetVector<Value> emptyTensors = state.findValueInReverseUseDefChain(
source.get(), /*condition=*/
- [&](Value val) { return val.getDefiningOp<tensor::EmptyOp>(); },
- config, &visitedOpOperands);
+ [&](Value val) { return val.getDefiningOp<tensor::EmptyOp>(); }, config,
+ &visitedOpOperands);
for (Value v : emptyTensors) {
Operation *emptyTensorOp = v.getDefiningOp();
// Find the use to be replaced from the use-def chain
- auto iter = llvm::find_if(visitedOpOperands, [&emptyTensorOp](OpOperand *opOperand){
- return llvm::count(emptyTensorOp->getUses(), *opOperand);
- });
+ auto iter = llvm::find_if(
+ visitedOpOperands, [&emptyTensorOp](OpOperand *opOperand) {
+ return llvm::count(emptyTensorOp->getUses(), *opOperand);
+ });
if (iter == visitedOpOperands.end())
continue;
OpOperand *useToBeReplaced = *iter;
@@ -191,7 +195,8 @@ LogicalResult mlir::bufferization::eliminateEmptyTensors(
replacement);
}
// Replace the specific use of the tensor::EmptyOp.
- useToBeReplaced->getOwner()->setOperand(useToBeReplaced->getOperandNumber(), replacement);
+ useToBeReplaced->getOwner()->setOperand(
+ useToBeReplaced->getOperandNumber(), replacement);
state.resetCache();
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/118958
More information about the Mlir-commits
mailing list