[Mlir-commits] [mlir] [mlir] Fold operation trait lookup without a temporary array (NFC) (PR #226081)
Mehdi Amini
llvmlistbot at llvm.org
Thu Sep 24 02:10:18 PDT 2026
https://github.com/joker-eph created https://github.com/llvm/llvm-project/pull/226081
Compare trait IDs directly in the generated pack expansion. This avoids building and scanning a local array in every operation trait lookup.
Assisted-by: Codex
>From a38eda39b21892303d2bf30012e188554adb735e Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Wed, 23 Sep 2026 13:32:01 -0700
Subject: [PATCH] [mlir] Fold operation trait lookup without a temporary array
Compare trait IDs directly in the generated pack expansion. This avoids
building and scanning a local array in every operation trait lookup.
Assisted-by: Codex
---
mlir/include/mlir/IR/OpDefinition.h | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h
index 4741eecb4a874..36bff607c2a69 100644
--- a/mlir/include/mlir/IR/OpDefinition.h
+++ b/mlir/include/mlir/IR/OpDefinition.h
@@ -1567,11 +1567,7 @@ namespace op_definition_impl {
/// trait types `Traits`.
template <template <typename T> class... Traits>
inline bool hasTrait(TypeID traitID) {
- TypeID traitIDs[] = {TypeID::get<Traits>()...};
- for (unsigned i = 0, e = sizeof...(Traits); i != e; ++i)
- if (traitIDs[i] == traitID)
- return true;
- return false;
+ return ((traitID == TypeID::get<Traits>()) || ...);
}
template <>
inline bool hasTrait<>(TypeID traitID) {
More information about the Mlir-commits
mailing list