[Mlir-commits] [mlir] 5d3c972 - [MLIR] Use `if constexpr` in `StorageUniquer` and `IR/AffineExpr`

Joe Loser llvmlistbot at llvm.org
Sat Dec 3 18:07:52 PST 2022


Author: Joe Loser
Date: 2022-12-03T19:07:11-07:00
New Revision: 5d3c972a3565df01bb4ac15262b6fe4c3157b807

URL: https://github.com/llvm/llvm-project/commit/5d3c972a3565df01bb4ac15262b6fe4c3157b807
DIFF: https://github.com/llvm/llvm-project/commit/5d3c972a3565df01bb4ac15262b6fe4c3157b807.diff

LOG: [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

Added: 
    

Modified: 
    mlir/include/mlir/IR/AffineExpr.h
    mlir/include/mlir/Support/StorageUniquer.h

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/AffineExpr.h b/mlir/include/mlir/IR/AffineExpr.h
index e72e2990d355..1d0688a38003 100644
--- a/mlir/include/mlir/IR/AffineExpr.h
+++ b/mlir/include/mlir/IR/AffineExpr.h
@@ -82,7 +82,7 @@ class AffineExpr {
   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>

diff  --git a/mlir/include/mlir/Support/StorageUniquer.h b/mlir/include/mlir/Support/StorageUniquer.h
index 39fe1e56d07f..0ef645393b20 100644
--- a/mlir/include/mlir/Support/StorageUniquer.h
+++ b/mlir/include/mlir/Support/StorageUniquer.h
@@ -149,7 +149,7 @@ class StorageUniquer {
   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();


        


More information about the Mlir-commits mailing list