Line data Source code
1 : /* Classes for manipulating the supergraph.
2 : Copyright (C) 2025-2026 Free Software Foundation, Inc.
3 : Contributed by David Malcolm <dmalcolm@redhat.com>.
4 :
5 : This file is part of GCC.
6 :
7 : GCC is free software; you can redistribute it and/or modify it
8 : under the terms of the GNU General Public License as published by
9 : the Free Software Foundation; either version 3, or (at your option)
10 : any later version.
11 :
12 : GCC is distributed in the hope that it will be useful, but
13 : WITHOUT ANY WARRANTY; without even the implied warranty of
14 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 : General Public License for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along with GCC; see the file COPYING3. If not see
19 : <http://www.gnu.org/licenses/>. */
20 :
21 : #ifndef GCC_ANALYZER_SUPERGRAPH_MANIPULATION_H
22 : #define GCC_ANALYZER_SUPERGRAPH_MANIPULATION_H
23 :
24 : #if ENABLE_ANALYZER
25 :
26 : namespace ana {
27 : namespace supergraph_manipulation {
28 :
29 6754 : class worklist
30 : {
31 : public:
32 6754 : worklist ()
33 6754 : : m_indices ()
34 : {
35 6754 : bitmap_clear (m_indices);
36 6754 : }
37 :
38 275430 : void ensure_node_queued (supernode *node, ana::logger *logger)
39 : {
40 275430 : if (bitmap_bit_p (m_indices, node->m_id))
41 : return; // already in queue
42 263599 : if (logger)
43 120 : logger->log ("queued SN: %i", node->m_id);
44 263599 : m_queue.push_back (node);
45 263599 : bitmap_set_bit (m_indices, node->m_id);
46 : }
47 :
48 270353 : supernode *pop ()
49 : {
50 270353 : if (m_queue.empty ())
51 : return nullptr;
52 263599 : supernode *node = m_queue.front ();
53 263599 : m_queue.pop_front ();
54 263599 : bitmap_clear_bit (m_indices, node->m_id);
55 263599 : return node;
56 : }
57 :
58 : private:
59 : // The queue
60 : std::deque<supernode *> m_queue;
61 :
62 : /* Indices of all nodes in the queue, so
63 : we can lazily add them in constant time. */
64 : auto_bitmap m_indices;
65 : };
66 :
67 :
68 : } // namespace ana::supergraph_manipulation
69 : } // namespace ana
70 :
71 : #endif /* #if ENABLE_ANALYZER */
72 :
73 : #endif /* GCC_ANALYZER_SUPERGRAPH_MANIPULATION_H */
|