[Mlir-commits] [mlir] 0ad6ac8 - [NFC][MLIR] Fix: `alloca` promotion for `AllocationOpInterface` (#97672)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Jul 3 23:49:35 PDT 2024
Author: Nikhil Kalra
Date: 2024-07-04T08:49:33+02:00
New Revision: 0ad6ac8c5338e42192bc006576397a02b838d265
URL: https://github.com/llvm/llvm-project/commit/0ad6ac8c5338e42192bc006576397a02b838d265
DIFF: https://github.com/llvm/llvm-project/commit/0ad6ac8c5338e42192bc006576397a02b838d265.diff
LOG: [NFC][MLIR] Fix: `alloca` promotion for `AllocationOpInterface` (#97672)
The std::optional returned by buildPromotedAlloc was directly
dereferenced and assumed to be non-null, even though the documentation
for AllocationOpInterface indicates that std::nullopt is a legal value
if buffer stack promotion is not supported (and is the default value
supplied by the TableGen interface file). This patch removes the direct
dereference so that the optional can be null-checked prior to use.
Co-authored-by: Nikhil Kalra <nkalra at apple.com>
Added:
Modified:
mlir/lib/Dialect/Bufferization/Transforms/BufferOptimizations.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/BufferOptimizations.cpp b/mlir/lib/Dialect/Bufferization/Transforms/BufferOptimizations.cpp
index d7056f35cbc8d..93c1f9a4f2b55 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/BufferOptimizations.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/BufferOptimizations.cpp
@@ -397,12 +397,12 @@ class BufferPlacementPromotion : BufferPlacementTransformationBase {
OpBuilder builder(startOperation);
Operation *allocOp = alloc.getDefiningOp();
if (auto allocInterface = dyn_cast<AllocationOpInterface>(allocOp)) {
- Operation *alloca =
- allocInterface.buildPromotedAlloc(builder, alloc).value();
+ std::optional<Operation *> alloca =
+ allocInterface.buildPromotedAlloc(builder, alloc);
if (!alloca)
continue;
// Replace the original alloc by a newly created alloca.
- allocOp->replaceAllUsesWith(alloca);
+ allocOp->replaceAllUsesWith(alloca.value());
allocOp->erase();
}
}
More information about the Mlir-commits
mailing list