From bbb3d5379b90c030e50abf7f8f49f4e7ae9fe20b Mon Sep 17 00:00:00 2001 From: Nikolaj Bjorner Date: Wed, 28 May 2025 17:10:23 +0100 Subject: [PATCH] initialize tag class circular linked list --- src/util/trace.cpp | 31 +++++++++++++++++++++++++++++++ src/util/trace_tags.h | 17 +++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/util/trace.cpp b/src/util/trace.cpp index bb4812e00..8c379ca6b 100644 --- a/src/util/trace.cpp +++ b/src/util/trace.cpp @@ -57,6 +57,37 @@ void finalize_trace() { g_enabled_trace_tags = nullptr; } +const TraceTag* get_tag_classes() { + static bool tag_class_init = false; // ignore thread safety assuming TRACE is already under a lock. + if (!tag_class_init) { + // Arrays to track first and last tag in each class + TraceTag first[static_cast(TraceTag::Count)]; + TraceTag last[static_cast(TraceTag::Count)]; + for (unsigned i = 0; i < static_cast(TraceTag::Count); ++i) + first[i] = last[i] = TraceTag::Count; + + // Link tags in each class + for (unsigned i = 0; i < static_cast(TraceTag::Count); ++i) { + TraceTag tag = static_cast(i); + TraceTag tag_class = get_trace_tag_class(tag); + unsigned cls = static_cast(tag_class); + if (first[cls] == TraceTag::Count) + first[cls] = tag; + else + tag_classes[static_cast(last[cls])] = tag; + last[cls] = tag; + } + // Close the circular list for each class + for (unsigned cls = 0; cls < static_cast(TraceTag::Count); ++cls) + if (last[cls] != TraceTag::Count && first[cls] != TraceTag::Count) + tag_classes[static_cast(last[cls])] = first[cls]; + + tag_class_init = true; + } + return tag_classes; +} + + void enable_trace(const char * tag) { get_enabled_trace_tags().insert(tag); diff --git a/src/util/trace_tags.h b/src/util/trace_tags.h index 73c9c0f1f..cef20d3cd 100644 --- a/src/util/trace_tags.h +++ b/src/util/trace_tags.h @@ -29,6 +29,15 @@ inline const char* get_trace_tag_doc(TraceTag tag) { } } +inline TraceTag get_trace_tag_class(TraceTag tag) { + switch (tag) { +#define X(tag, tag_class, desc) case TraceTag::tag: return TraceTag::tag_class; +#include "util/trace_tags.def" +#undef X + default: return TraceTag::Count; + } +} + // Return the number of TraceTags inline constexpr int trace_tag_count() { return static_cast(TraceTag::Count); @@ -44,6 +53,14 @@ inline constexpr int count_tags_in_class(TraceTag cls) { return count; } + +static TraceTag tag_classes[] = { +#define X(tag, tc, desc) TraceTag::tag, +#include "util/trace_tags.def" +#undef X +}; + + // TODO(#7663): Implement tag_class activation of all associated tags // TODO: Need to consider implementation approach and memory management // Return all tags that belong to the given class