GCC Middle and Back End API Reference
reachability.h
Go to the documentation of this file.
1/* Digraph reachability.
2 Copyright (C) 2020-2024 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it
8under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 3, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful, but
13WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21#ifndef GCC_ANALYZER_REACHABILITY_H
22#define GCC_ANALYZER_REACHABILITY_H
23
24namespace ana {
25
26/* The set of nodes from which a target node in a digraph can be reached. */
27// TODO(stage1): move to gcc
28
29template <typename GraphTraits>
31{
32public:
33 typedef typename GraphTraits::graph_t graph_t;
34 typedef typename GraphTraits::node_t node_t;
35 typedef typename GraphTraits::edge_t edge_t;
36
38 const node_t *target_node)
39 : m_indices (graph.m_nodes.length ())
40 {
43 worklist.safe_push (target_node);
44 bitmap_set_bit (m_indices, target_node->m_index);
45
46 while (worklist.length () > 0)
47 {
48 const node_t *next = worklist.pop ();
49 unsigned i;
50 edge_t *pred;
51 FOR_EACH_VEC_ELT (next->m_preds, i, pred)
52 {
53 if (!reachable_from_p (pred->m_src))
54 {
55 worklist.safe_push (pred->m_src);
56 bitmap_set_bit (m_indices, pred->m_src->m_index);
57 }
58 }
59 }
60 }
61
62 bool reachable_from_p (const node_t *src_node) const
63 {
64 return bitmap_bit_p (m_indices, src_node->m_index);
65 }
66
67private:
68 /* The nodes that can reach the target. */
70};
71
72//TODO: selftests for reachability
73
74} // namespace ana
75
76#endif /* GCC_ANALYZER_REACHABILITY_H */
void bitmap_clear(bitmap head)
Definition bitmap.cc:713
Definition reachability.h:31
GraphTraits::edge_t edge_t
Definition reachability.h:35
GraphTraits::graph_t graph_t
Definition reachability.h:33
GraphTraits::node_t node_t
Definition reachability.h:34
auto_sbitmap m_indices
Definition reachability.h:69
bool reachable_from_p(const node_t *src_node) const
Definition reachability.h:62
reachability(const graph_t &graph, const node_t *target_node)
Definition reachability.h:37
Definition exploded-graph.h:723
unsigned length() const
Definition sbitmap.h:300
Definition vec.h:1656
static vec< rtx_insn * > worklist
Definition dce.cc:54
#define bitmap_bit_p(bitstring, bitno)
Definition genautomata.cc:3429
#define bitmap_set_bit(bitstring, bitno)
Definition genautomata.cc:3419
Definition access-diagram.h:30
i
Definition poly-int.h:776
Definition graphds.h:48
#define FOR_EACH_VEC_ELT(V, I, P)
Definition vec.h:1884