[MLIR] Use `if constexpr` in `StorageUniquer` and `IR/AffineExpr`
authorJoe Loser <joeloser@fastmail.com>
Sun, 4 Dec 2022 01:01:53 +0000 (18:01 -0700)
committerJoe Loser <joeloser@fastmail.com>
Sun, 4 Dec 2022 02:07:11 +0000 (19:07 -0700)
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
mlir/include/mlir/Support/StorageUniquer.h

index e72e299..1d0688a 100644 (file)
@@ -82,7 +82,7 @@ public:
   bool operator!() const { return expr == nullptr; }
 
   template <typename U>
-  bool isa() const;
+  constexpr bool isa() const;
   template <typename U>
   U dyn_cast() const;
   template <typename U>
@@ -267,14 +267,14 @@ AffineExpr getAffineExprFromFlatForm(ArrayRef<int64_t> flatExprs,
 raw_ostream &operator<<(raw_ostream &os, AffineExpr expr);
 
 template <typename U>
-bool AffineExpr::isa() const {
-  if (std::is_same<U, AffineBinaryOpExpr>::value)
+constexpr bool AffineExpr::isa() const {
+  if constexpr (std::is_same_v<U, AffineBinaryOpExpr>)
     return getKind() <= AffineExprKind::LAST_AFFINE_BINARY_OP;
-  if (std::is_same<U, AffineDimExpr>::value)
+  if constexpr (std::is_same_v<U, AffineDimExpr>)
     return getKind() == AffineExprKind::DimId;
-  if (std::is_same<U, AffineSymbolExpr>::value)
+  if constexpr (std::is_same_v<U, AffineSymbolExpr>)
     return getKind() == AffineExprKind::SymbolId;
-  if (std::is_same<U, AffineConstantExpr>::value)
+  if constexpr (std::is_same_v<U, AffineConstantExpr>)
     return getKind() == AffineExprKind::Constant;
 }
 template <typename U>
index 39fe1e5..0ef6453 100644 (file)
@@ -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<Storage>::value)
+    if constexpr (std::is_trivially_destructible_v<Storage>)
       return registerParametricStorageTypeImpl(id, nullptr);
     registerParametricStorageTypeImpl(id, [](BaseStorage *storage) {
       static_cast<Storage *>(storage)->~Storage();