From: Joe Loser Date: Sun, 4 Dec 2022 01:01:53 +0000 (-0700) Subject: [MLIR] Use `if constexpr` in `StorageUniquer` and `IR/AffineExpr` X-Git-Tag: upstream/17.0.6~25420 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5d3c972a3565df01bb4ac15262b6fe4c3157b807;p=platform%2Fupstream%2Fllvm.git [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 --- 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();