Skip to content

Commit 7c2ef38

Browse files
committed
[mlir][NFC] Use llvm::to_underlying in sparse tensor IR detail
1 parent 96410a6 commit 7c2ef38

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "Var.h"
1313

1414
#include "mlir/Dialect/SparseTensor/IR/SparseTensor.h"
15+
#include "llvm/ADT/STLForwardCompat.h"
1516

1617
namespace mlir {
1718
namespace sparse_tensor {
@@ -22,7 +23,7 @@ enum class ExprKind : bool { Dimension = false, Level = true };
2223

2324
constexpr VarKind getVarKindAllowedInExpr(ExprKind ek) {
2425
using VK = std::underlying_type_t<VarKind>;
25-
return VarKind{2 * static_cast<VK>(!to_underlying(ek))};
26+
return VarKind{2 * static_cast<VK>(!llvm::to_underlying(ek))};
2627
}
2728
static_assert(getVarKindAllowedInExpr(ExprKind::Dimension) == VarKind::Level &&
2829
getVarKindAllowedInExpr(ExprKind::Level) == VarKind::Dimension);

mlir/lib/Dialect/SparseTensor/IR/Detail/TemplateExtras.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,6 @@ operator<<(llvm::raw_ostream &os, T const &t) {
3737
return os;
3838
}
3939

40-
//===----------------------------------------------------------------------===//
41-
/// Convert an enum to its underlying type.
42-
template <typename Enum>
43-
constexpr std::underlying_type_t<Enum> to_underlying(Enum e) noexcept {
44-
return static_cast<std::underlying_type_t<Enum>>(e);
45-
}
46-
4740
//===----------------------------------------------------------------------===//
4841
template <typename T>
4942
static constexpr bool IsZeroCostAbstraction =

mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "mlir/IR/OpImplementation.h"
1515
#include "llvm/ADT/EnumeratedArray.h"
16+
#include "llvm/ADT/STLForwardCompat.h"
1617
#include "llvm/ADT/SmallBitVector.h"
1718
#include "llvm/ADT/StringMap.h"
1819

@@ -31,13 +32,13 @@ namespace ir_detail {
3132
enum class VarKind { Symbol = 1, Dimension = 0, Level = 2 };
3233

3334
[[nodiscard]] constexpr bool isWF(VarKind vk) {
34-
const auto vk_ = to_underlying(vk);
35+
const auto vk_ = llvm::to_underlying(vk);
3536
return 0 <= vk_ && vk_ <= 2;
3637
}
3738

3839
/// Swaps `Dimension` and `Level`, but leaves `Symbol` the same.
3940
constexpr VarKind flipVarKind(VarKind vk) {
40-
return VarKind{2 - to_underlying(vk)};
41+
return VarKind{2 - llvm::to_underlying(vk)};
4142
}
4243
static_assert(flipVarKind(VarKind::Symbol) == VarKind::Symbol &&
4344
flipVarKind(VarKind::Dimension) == VarKind::Level &&
@@ -49,7 +50,7 @@ constexpr char toChar(VarKind vk) {
4950
// in the range [-44..126] (where that lower bound is under worst-case
5051
// rearranging of the expression); and `int_fast8_t` is the fastest type
5152
// which can support that range without over-/underflow.
52-
const auto vk_ = static_cast<int_fast8_t>(to_underlying(vk));
53+
const auto vk_ = static_cast<int_fast8_t>(llvm::to_underlying(vk));
5354
return static_cast<char>(100 + vk_ * (26 - vk_ * 11));
5455
}
5556
static_assert(toChar(VarKind::Symbol) == 's' &&
@@ -100,7 +101,7 @@ class Var {
100101
public:
101102
constexpr Impl(VarKind vk, Num n)
102103
: data((static_cast<Storage>(n) << 2) |
103-
static_cast<Storage>(to_underlying(vk))) {
104+
static_cast<Storage>(llvm::to_underlying(vk))) {
104105
assert(isWF(vk) && "unknown VarKind");
105106
assert(isWF_Num(n) && "Var::Num is too large");
106107
}
@@ -215,7 +216,7 @@ class Ranks final {
215216

216217
static constexpr unsigned to_index(VarKind vk) {
217218
assert(isWF(vk) && "unknown VarKind");
218-
return static_cast<unsigned>(to_underlying(vk));
219+
return static_cast<unsigned>(llvm::to_underlying(vk));
219220
}
220221

221222
public:
@@ -349,7 +350,7 @@ class VarEnv final {
349350
/// to live too long.
350351
VarInfo const &access(VarInfo::ID id) const {
351352
// `SmallVector::operator[]` already asserts the index is in-bounds.
352-
return vars[to_underlying(id)];
353+
return vars[llvm::to_underlying(id)];
353354
}
354355
VarInfo const *access(std::optional<VarInfo::ID> oid) const {
355356
return oid ? &access(*oid) : nullptr;

0 commit comments

Comments
 (0)