--- /dev/null
+/* channels.h - Publish/Subscribe channels on compiler-specific topics.
+ Copyright (C) 2025 Free Software Foundation, Inc.
+ Contributed by David Malcolm <dmalcolm@redhat.com>.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3. If not see
+<http://www.gnu.org/licenses/>. */
+
+#ifndef GCC_CHANNELS_H
+#define GCC_CHANNELS_H
+
+#include "pub-sub.h"
+
+namespace gcc {
+
+/* Forward decls of subscribers for the various topics we have
+ publish/subscribe channels for. */
+namespace topics {
+ namespace pass_events { struct subscriber; }
+} // namespace gcc::topics
+
+/* Publish/subscribe channels on various compiler-specific topics. */
+
+struct compiler_channels
+{
+ pub_sub::channel<topics::pass_events::subscriber> pass_events_channel;
+};
+
+} // namespace gcc
+
+#endif /* ! GCC_CHANNELS_H */
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
+#define INCLUDE_LIST
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "pass_manager.h"
#include "dumpfile.h"
#include "realmpfr.h"
+#include "channels.h"
/* The singleton holder of global state: */
gcc::context *g;
gcc::context::context ()
- : m_passes (NULL), m_dumps (new gcc::dump_manager ())
+: m_passes (NULL),
+ m_dumps (new gcc::dump_manager ()),
+ m_channels (new gcc::compiler_channels ())
{
have_offload = false;
}
{
delete m_passes;
delete m_dumps;
+ delete m_channels;
/* Release MPFR caches to avoid Valgrind leak reports. */
mpfr_free_cache ();
class pass_manager;
class dump_manager;
+struct compiler_channels;
/* GCC's internal state can be divided into zero or more
"parallel universe" of state; an instance of this class is one such
dump_manager *get_dumps () {gcc_assert (m_dumps); return m_dumps; }
+ /* Publish/subscribe channels for events
+ on various compiler-specific topics. */
+ compiler_channels &
+ get_channels () const
+ {
+ gcc_assert (m_channels);
+ return *m_channels;
+ }
+
private:
/* Pass-management. */
pass_manager *m_passes;
/* Dump files. */
dump_manager *m_dumps;
+ compiler_channels *m_channels;
+
}; // class context
} // namespace gcc
in the proper order, and counts the time used by each.
Error messages and low-level interface to malloc also handled here. */
+#define INCLUDE_LIST
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "diagnostic-core.h" /* for fnotice */
#include "stringpool.h"
#include "attribs.h"
+#include "topics/pass-events.h"
+#include "channels.h"
/* Reserved TODOs */
#define TODO_verify_il (1u << 31)
bool
execute_one_pass (opt_pass *pass)
{
+ namespace pass_events = gcc::topics::pass_events;
+
unsigned int todo_after = 0;
bool gate_status;
+ if (auto channel = g->get_channels ().pass_events_channel.get_if_active ())
+ channel->publish (pass_events::before_pass {pass, cfun});
+
/* IPA passes are executed on whole program, so cfun should be NULL.
Other passes need function context set. */
if (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS)
if (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS)
report_heap_memory_use ();
+
+ if (auto channel = g->get_channels ().pass_events_channel.get_if_active ())
+ channel->publish (pass_events::after_pass {pass, cfun});
+
return true;
}
cpython-plugin-test-PyList_Append.c \
cpython-plugin-test-PyList_New.c \
cpython-plugin-test-PyLong_FromLong.c } \
+ { progress_notifications_plugin.cc } \
]
foreach plugin_test $plugin_test_list {
--- /dev/null
+/* Toy implementation of progress notifications about the compiler,
+ using gcc::topics::pass_events. */
+
+#define INCLUDE_LIST
+#include "gcc-plugin.h"
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tree-pass.h"
+#include "diagnostic-core.h"
+#include "context.h"
+#include "channels.h"
+#include "topics/pass-events.h"
+
+int plugin_is_GPL_compatible;
+
+namespace pass_events = gcc::topics::pass_events;
+
+namespace {
+
+class notification_event_subscriber : public pass_events::subscriber
+{
+public:
+ void on_message (const pass_events::before_pass &m) final override
+ {
+ if (m.fun)
+ inform (m.fun->function_start_locus, "starting pass %qs on %qD",
+ m.pass->name, m.fun->decl);
+ else
+ inform (UNKNOWN_LOCATION, "starting pass %qs", m.pass->name);
+ }
+ void on_message (const pass_events::after_pass &m) final override
+ {
+ if (m.fun)
+ inform (m.fun->function_end_locus, "finished pass %qs on %qD",
+ m.pass->name, m.fun->decl);
+ else
+ inform (UNKNOWN_LOCATION, "finished pass %qs", m.pass->name);
+ }
+} my_event_subscriber;
+
+} // anonymous namespace
+
+int
+plugin_init (struct plugin_name_args *,
+ struct plugin_gcc_version *)
+{
+ g->get_channels ().pass_events_channel.add_subscriber (my_event_subscriber);
+
+ return 0;
+}
--- /dev/null
+/* pass-events.h - pub/sub messages about GCC optimization passes.
+ Copyright (C) 2025 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3. If not see
+<http://www.gnu.org/licenses/>. */
+
+#ifndef GCC_TOPICS_PASS_EVENTS_H
+#define GCC_TOPICS_PASS_EVENTS_H
+
+#include "pub-sub.h"
+
+namespace gcc {
+namespace topics {
+
+/* A topic for messages relating to GCC optimization passes. */
+
+namespace pass_events {
+
+struct before_pass
+{
+ opt_pass *pass;
+ function *fun;
+};
+
+struct after_pass
+{
+ opt_pass *pass;
+ function *fun;
+};
+
+/* Abstract base class for a subscriber to messages about
+ GCC optimization passes. */
+
+struct subscriber
+{
+ virtual ~subscriber () = default;
+
+ virtual void on_message (const before_pass &) = 0;
+ virtual void on_message (const after_pass &) = 0;
+};
+
+} // namespace gcc::topics::pass_events
+} // namespace gcc::topics
+} // namespace gcc
+
+#endif /* ! GCC_TOPICS_PASS_EVENTS_H */