From 5d3c972a3565df01bb4ac15262b6fe4c3157b807 Mon Sep 17 00:00:00 2001 From: Joe Loser Date: Sat, 3 Dec 2022 18:01:53 -0700 Subject: [PATCH] [MLIR] Use `if constexpr` in `StorageUniquer` and `IR/AffineExpr` Querying the type trait is something that can be done at compile time. So, replace the runtime `if` with `if constexpr`. Differential Revision: https://reviews.llvm.org/D139264 --- mlir/include/mlir/IR/AffineExpr.h | 12 ++++++------ mlir/include/mlir/Support/StorageUniquer.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mlir/include/mlir/IR/AffineExpr.h b/mlir/include/mlir/IR/AffineExpr.h index e72e299..1d0688a 100644 --- a/mlir/include/mlir/IR/AffineExpr.h +++ b/mlir/include/mlir/IR/AffineExpr.h @@ -82,7 +82,7 @@ public: bool operator!() const { return expr == nullptr; } template - bool isa() const; + constexpr bool isa() const; template U dyn_cast() const; template @@ -267,14 +267,14 @@ AffineExpr getAffineExprFromFlatForm(ArrayRef flatExprs, raw_ostream &operator<<(raw_ostream &os, AffineExpr expr); template -bool AffineExpr::isa() const { - if (std::is_same::value) +constexpr bool AffineExpr::isa() const { + if constexpr (std::is_same_v) return getKind() <= AffineExprKind::LAST_AFFINE_BINARY_OP; - if (std::is_same::value) + if constexpr (std::is_same_v) return getKind() == AffineExprKind::DimId; - if (std::is_same::value) + if constexpr (std::is_same_v) return getKind() == AffineExprKind::SymbolId; - if (std::is_same::value) + if constexpr (std::is_same_v) return getKind() == AffineExprKind::Constant; } template diff --git a/mlir/include/mlir/Support/StorageUniquer.h b/mlir/include/mlir/Support/StorageUniquer.h index 39fe1e5..0ef6453 100644 --- a/mlir/include/mlir/Support/StorageUniquer.h +++ b/mlir/include/mlir/Support/StorageUniquer.h @@ -149,7 +149,7 @@ public: void registerParametricStorageType(TypeID id) { // If the storage is trivially destructible, we don't need a destructor // function. - if (std::is_trivially_destructible::value) + if constexpr (std::is_trivially_destructible_v) return registerParametricStorageTypeImpl(id, nullptr); registerParametricStorageTypeImpl(id, [](BaseStorage *storage) { static_cast(storage)->~Storage(); -- 2.7.4