Commit 7cec1885 authored by Leszek Swirski's avatar Leszek Swirski Committed by V8 LUCI CQ

[maglev] Fix specializations in non-namespace scope

Bug: v8:7700
Change-Id: I801b482039b6f8ba19332747a8fee0fcdbcb8764
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3487553Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79254}
parent 46b7ed47
...@@ -257,22 +257,26 @@ class Input : public ValueLocation { ...@@ -257,22 +257,26 @@ class Input : public ValueLocation {
// Dummy type for the initial raw allocation. // Dummy type for the initial raw allocation.
struct NodeWithInlineInputs {}; struct NodeWithInlineInputs {};
class NodeBase : public ZoneObject { namespace detail {
private: // Helper for getting the static opcode of a Node subclass. This is in a
template <class T> // "detail" namespace rather than in NodeBase because we can't template
struct opcode_of_helper; // specialize outside of namespace scopes before C++17.
template <class T>
struct opcode_of_helper;
#define DEF_OPCODE_OF(Name) \ #define DEF_OPCODE_OF(Name) \
template <> \ template <> \
struct opcode_of_helper<Name> { \ struct opcode_of_helper<Name> { \
static constexpr Opcode value = Opcode::k##Name; \ static constexpr Opcode value = Opcode::k##Name; \
}; };
NODE_BASE_LIST(DEF_OPCODE_OF) NODE_BASE_LIST(DEF_OPCODE_OF)
#undef DEF_OPCODE_OF #undef DEF_OPCODE_OF
} // namespace detail
class NodeBase : public ZoneObject {
protected: protected:
template <class T> template <class T>
static constexpr Opcode opcode_of = opcode_of_helper<T>::value; static constexpr Opcode opcode_of = detail::opcode_of_helper<T>::value;
public: public:
template <class Derived, typename... Args> template <class Derived, typename... Args>
...@@ -305,9 +309,8 @@ class NodeBase : public ZoneObject { ...@@ -305,9 +309,8 @@ class NodeBase : public ZoneObject {
constexpr Opcode opcode() const { return OpcodeField::decode(bit_field_); } constexpr Opcode opcode() const { return OpcodeField::decode(bit_field_); }
template <class T> template <class T>
constexpr bool Is() const { constexpr bool Is() const;
return opcode() == opcode_of<T>;
}
template <class T> template <class T>
constexpr T* Cast() { constexpr T* Cast() {
DCHECK(Is<T>()); DCHECK(Is<T>());
...@@ -323,20 +326,6 @@ class NodeBase : public ZoneObject { ...@@ -323,20 +326,6 @@ class NodeBase : public ZoneObject {
return Is<T>() ? static_cast<T*>(this) : nullptr; return Is<T>() ? static_cast<T*>(this) : nullptr;
} }
// Specialized sub-hierarchy type checks.
template <>
constexpr bool Is<ValueNode>() const {
return IsValueNode(opcode());
}
template <>
constexpr bool Is<ConditionalControlNode>() const {
return IsConditionalControlNode(opcode());
}
template <>
constexpr bool Is<UnconditionalControlNode>() const {
return IsUnconditionalControlNode(opcode());
}
constexpr bool has_inputs() const { return input_count() > 0; } constexpr bool has_inputs() const { return input_count() > 0; }
constexpr uint16_t input_count() const { constexpr uint16_t input_count() const {
return InputCountField::decode(bit_field_); return InputCountField::decode(bit_field_);
...@@ -464,6 +453,25 @@ class NodeBase : public ZoneObject { ...@@ -464,6 +453,25 @@ class NodeBase : public ZoneObject {
NodeBase& operator=(NodeBase&&) = delete; NodeBase& operator=(NodeBase&&) = delete;
}; };
template <class T>
constexpr bool NodeBase::Is() const {
return opcode() == opcode_of<T>;
}
// Specialized sub-hierarchy type checks.
template <>
constexpr bool NodeBase::Is<ValueNode>() const {
return IsValueNode(opcode());
}
template <>
constexpr bool NodeBase::Is<ConditionalControlNode>() const {
return IsConditionalControlNode(opcode());
}
template <>
constexpr bool NodeBase::Is<UnconditionalControlNode>() const {
return IsUnconditionalControlNode(opcode());
}
// The Node class hierarchy contains all non-control nodes. // The Node class hierarchy contains all non-control nodes.
class Node : public NodeBase { class Node : public NodeBase {
public: public:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment