Skip to content

Commit

Permalink
better isa implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-Leo-Smith committed Feb 4, 2025
1 parent 874222a commit 0cdd7f7
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions include/luisa/xir/pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,18 @@

namespace luisa::compute::xir {

#define LUISA_XIR_DEFINED_ISA_METHOD(BaseType, base_name) \
template<typename Derived> \
requires std::derived_from<Derived, BaseType> \
[[nodiscard]] bool isa() const noexcept { \
if constexpr (std::is_same_v<BaseType, Derived>) { \
return true; \
} else { \
using ImmediateDerived = typename Derived::derived_##base_name##_type; \
if constexpr (std::is_final_v<ImmediateDerived>) { \
return derived_##base_name##_tag() == Derived::static_derived_##base_name##_tag(); \
} else { \
return derived_##base_name##_tag() == Derived::static_derived_##base_name##_tag() && \
static_cast<const ImmediateDerived *>(this)->template isa<Derived>(); \
} \
} \
#define LUISA_XIR_DEFINED_ISA_METHOD(BaseType, base_name) \
template<typename Derived> \
requires std::derived_from<Derived, BaseType> \
[[nodiscard]] bool isa() const noexcept { \
if constexpr (std::is_same_v<BaseType, Derived>) { \
return true; \
} else { \
using ImmediateDerived = typename Derived::derived_##base_name##_type; \
return derived_##base_name##_tag() == Derived::static_derived_##base_name##_tag() && \
(std::is_final_v<ImmediateDerived> || std::is_same_v<ImmediateDerived, Derived> || \
static_cast<const ImmediateDerived *>(this)->template isa<Derived>()); \
} \
}

class Pool;
Expand Down

0 comments on commit 0cdd7f7

Please sign in to comment.