| 1 |
/* Trimming an exploded graph to a subset of nodes and edges. |
| 2 |
Copyright (C) 2021-2025 Free Software Foundation, Inc. |
| 3 |
Contributed by David Malcolm <[email protected]>. |
| 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_TRIMMED_GRAPH_H |
| 22 |
#define GCC_ANALYZER_TRIMMED_GRAPH_H |
| 23 |
|
| 24 |
namespace ana { |
| 25 |
|
| 26 |
/* Forward decls. */ |
| 27 |
|
| 28 |
class trimmed_node; |
| 29 |
class trimmed_edge; |
| 30 |
class trimmed_graph; |
| 31 |
class trimmed_cluster; |
| 32 |
|
| 33 |
/* A traits class for trimming a digraph to a subset of nodes and edges. */ |
| 34 |
|
| 35 |
struct tg_traits |
| 36 |
{ |
| 37 |
typedef trimmed_node node_t; |
| 38 |
typedef trimmed_edge edge_t; |
| 39 |
typedef trimmed_graph graph_t; |
| 40 |
struct dump_args_t |
| 41 |
{ |
| 42 |
typedef typename eg_traits::dump_args_t inner_args_t; |
| 43 |
|
| 44 |
dump_args_t (const inner_args_t &inner_args) |
| 45 |
: m_inner_args (inner_args) |
| 46 |
{ |
| 47 |
} |
| 48 |
|
| 49 |
const inner_args_t &m_inner_args; |
| 50 |
}; |
| 51 |
typedef trimmed_cluster cluster_t; |
| 52 |
}; |
| 53 |
|
| 54 |
/* A node within the trimmed_graph, corresponding to an "inner node" |
| 55 |
within the original exploded_graph. */ |
| 56 |
|
| 57 |
class trimmed_node : public dnode<tg_traits> |
| 58 |
{ |
| 59 |
public: |
| 60 |
trimmed_node (const exploded_node *inner_node) |
| 61 |
: m_inner_node (inner_node) {} |
| 62 |
|
| 63 |
void dump_dot (graphviz_out *gv, |
| 64 |
const dump_args_t &args) const final override; |
| 65 |
|
| 66 |
private: |
| 67 |
const exploded_node *m_inner_node; |
| 68 |
}; |
| 69 |
|
| 70 |
/* An edge within the trimmed_graph, corresponding to an "inner edge" |
| 71 |
within the original exploded_graph. */ |
| 72 |
|
| 73 |
class trimmed_edge : public dedge<tg_traits> |
| 74 |
{ |
| 75 |
public: |
| 76 |
trimmed_edge (trimmed_node *src, trimmed_node *dest, |
| 77 |
const exploded_edge *inner_edge); |
| 78 |
|
| 79 |
void dump_dot (graphviz_out *gv, |
| 80 |
const dump_args_t &args) const final override; |
| 81 |
|
| 82 |
private: |
| 83 |
const exploded_edge *m_inner_edge; |
| 84 |
}; |
| 85 |
|
| 86 |
/* A digraph for trimming an exploded_graph to the subset of nodes and edges |
| 87 |
from which paths reach INNER_DST_NODE (along with a precanned way to print |
| 88 |
these in .dot form). */ |
| 89 |
|
| 90 |
class trimmed_graph : public digraph <tg_traits> |
| 91 |
{ |
| 92 |
public: |
| 93 |
trimmed_graph (const exploded_graph &inner_graph, |
| 94 |
const exploded_node *inner_dst_node); |
| 95 |
|
| 96 |
bool contains_p (const exploded_edge *eedge) const |
| 97 |
{ |
| 98 |
hash_set <const exploded_edge *> & mut |
| 99 |
= const_cast <hash_set <const exploded_edge *> &> (m_eedges); |
| 100 |
return mut.contains (eedge); |
| 101 |
} |
| 102 |
|
| 103 |
void log_stats (logger *logger) const; |
| 104 |
|
| 105 |
private: |
| 106 |
/* The subset of nodes in the inner graph that are in the |
| 107 |
trimmed graph. */ |
| 108 |
hash_set <const exploded_node *> m_enodes; |
| 109 |
/* Likewise for edges. */ |
| 110 |
hash_set <const exploded_edge *> m_eedges; |
| 111 |
|
| 112 |
typedef hash_map<const exploded_node *, trimmed_node *> map_t; |
| 113 |
map_t m_map_from_enode_to_tnode; |
| 114 |
}; |
| 115 |
|
| 116 |
class trimmed_cluster : public cluster <tg_traits> |
| 117 |
{ |
| 118 |
}; |
| 119 |
|
| 120 |
} // namespace ana |
| 121 |
|
| 122 |
#endif /* GCC_ANALYZER_TRIMMED_GRAPH_H */ |