[Mlir-commits] [mlir] bcabaa5 - Add LLVM_MARK_AS_BITMASK_ENUM to HoistingKind enum
Mehdi Amini
llvmlistbot at llvm.org
Tue Aug 22 23:22:42 PDT 2023
Author: Xiaolei Shi
Date: 2023-08-22T23:22:32-07:00
New Revision: bcabaa5590052d1e9f78522a1f45621fe1a95b06
URL: https://github.com/llvm/llvm-project/commit/bcabaa5590052d1e9f78522a1f45621fe1a95b06
DIFF: https://github.com/llvm/llvm-project/commit/bcabaa5590052d1e9f78522a1f45621fe1a95b06.diff
LOG: Add LLVM_MARK_AS_BITMASK_ENUM to HoistingKind enum
This revision adds LLVM_MARK_AS_BITMASK_ENUM to HoistingKind to avoid static_cast when performing bitwise operations.
Reviewed By: mehdi_amini
Differential Revision: https://reviews.llvm.org/D158580
Added:
Modified:
mlir/include/mlir/Dialect/Bufferization/IR/AllocationOpInterface.h
mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp
mlir/lib/Dialect/Bufferization/Transforms/BufferOptimizations.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/Bufferization/IR/AllocationOpInterface.h b/mlir/include/mlir/Dialect/Bufferization/IR/AllocationOpInterface.h
index f785fd398f3923..5e0d3ca244c796 100644
--- a/mlir/include/mlir/Dialect/Bufferization/IR/AllocationOpInterface.h
+++ b/mlir/include/mlir/Dialect/Bufferization/IR/AllocationOpInterface.h
@@ -19,9 +19,10 @@ namespace mlir {
// Enum class representing
diff erent hoisting kinds for the allocation
// operation
enum class HoistingKind : uint8_t {
- None = 0, // No hoisting kind selected
- Loop = 1 << 0, // Indicates loop hoisting kind
- Block = 1 << 1 // Indicates dominated block hoisting kind
+ None = 0, // No hoisting kind selected
+ Loop = 1 << 0, // Indicates loop hoisting kind
+ Block = 1 << 1, // Indicates dominated block hoisting kind
+ LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ Block)
};
} // namespace mlir
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp b/mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp
index 35d48b87bd7016..582974873263d2 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp
@@ -645,8 +645,7 @@ struct DefaultAllocationInterface
.getResult();
}
static ::mlir::HoistingKind getHoistingKind() {
- return static_cast<HoistingKind>(static_cast<uint8_t>(HoistingKind::Loop) |
- static_cast<uint8_t>(HoistingKind::Block));
+ return HoistingKind::Loop | HoistingKind::Block;
}
static ::std::optional<::mlir::Operation *>
buildPromotedAlloc(OpBuilder &builder, Value alloc) {
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/BufferOptimizations.cpp b/mlir/lib/Dialect/Bufferization/Transforms/BufferOptimizations.cpp
index 90ea890d65e778..9f5d6a466780ad 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/BufferOptimizations.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/BufferOptimizations.cpp
@@ -44,16 +44,16 @@ static bool isKnownControlFlowInterface(Operation *op) {
/// and it supports the dominate block hoisting.
static bool allowAllocDominateBlockHoisting(Operation *op) {
auto allocOp = dyn_cast<AllocationOpInterface>(op);
- return allocOp && (static_cast<uint8_t>(allocOp.getHoistingKind()) &
- static_cast<uint8_t>(HoistingKind::Block));
+ return allocOp &&
+ static_cast<uint8_t>(allocOp.getHoistingKind() & HoistingKind::Block);
}
/// Returns true if the given operation implements the AllocationOpInterface
/// and it supports the loop hoisting.
static bool allowAllocLoopHoisting(Operation *op) {
auto allocOp = dyn_cast<AllocationOpInterface>(op);
- return allocOp && (static_cast<uint8_t>(allocOp.getHoistingKind()) &
- static_cast<uint8_t>(HoistingKind::Loop));
+ return allocOp &&
+ static_cast<uint8_t>(allocOp.getHoistingKind() & HoistingKind::Loop);
}
/// Check if the size of the allocation is less than the given size. The
More information about the Mlir-commits
mailing list