Skip to content

Commit bcabaa5

Browse files
XiaoleiShi-NVjoker-eph
authored andcommitted
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
1 parent 8c8aecd commit bcabaa5

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

mlir/include/mlir/Dialect/Bufferization/IR/AllocationOpInterface.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ namespace mlir {
1919
// Enum class representing different hoisting kinds for the allocation
2020
// operation
2121
enum class HoistingKind : uint8_t {
22-
None = 0, // No hoisting kind selected
23-
Loop = 1 << 0, // Indicates loop hoisting kind
24-
Block = 1 << 1 // Indicates dominated block hoisting kind
22+
None = 0, // No hoisting kind selected
23+
Loop = 1 << 0, // Indicates loop hoisting kind
24+
Block = 1 << 1, // Indicates dominated block hoisting kind
25+
LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ Block)
2526
};
2627
} // namespace mlir
2728

mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,7 @@ struct DefaultAllocationInterface
645645
.getResult();
646646
}
647647
static ::mlir::HoistingKind getHoistingKind() {
648-
return static_cast<HoistingKind>(static_cast<uint8_t>(HoistingKind::Loop) |
649-
static_cast<uint8_t>(HoistingKind::Block));
648+
return HoistingKind::Loop | HoistingKind::Block;
650649
}
651650
static ::std::optional<::mlir::Operation *>
652651
buildPromotedAlloc(OpBuilder &builder, Value alloc) {

mlir/lib/Dialect/Bufferization/Transforms/BufferOptimizations.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ static bool isKnownControlFlowInterface(Operation *op) {
4444
/// and it supports the dominate block hoisting.
4545
static bool allowAllocDominateBlockHoisting(Operation *op) {
4646
auto allocOp = dyn_cast<AllocationOpInterface>(op);
47-
return allocOp && (static_cast<uint8_t>(allocOp.getHoistingKind()) &
48-
static_cast<uint8_t>(HoistingKind::Block));
47+
return allocOp &&
48+
static_cast<uint8_t>(allocOp.getHoistingKind() & HoistingKind::Block);
4949
}
5050

5151
/// Returns true if the given operation implements the AllocationOpInterface
5252
/// and it supports the loop hoisting.
5353
static bool allowAllocLoopHoisting(Operation *op) {
5454
auto allocOp = dyn_cast<AllocationOpInterface>(op);
55-
return allocOp && (static_cast<uint8_t>(allocOp.getHoistingKind()) &
56-
static_cast<uint8_t>(HoistingKind::Loop));
55+
return allocOp &&
56+
static_cast<uint8_t>(allocOp.getHoistingKind() & HoistingKind::Loop);
5757
}
5858

5959
/// Check if the size of the allocation is less than the given size. The

0 commit comments

Comments
 (0)