Line data Source code
1 : /* Callback attribute summary
2 : Copyright (C) 2026 Free Software Foundation, Inc.
3 : Contributed by Josef Melcr <jmelcr@gcc.gnu.org>
4 :
5 : This file is part of GCC.
6 :
7 : GCC is free software; you can redistribute it and/or modify
8 : under the terms of the GNU General Public License as published by
9 : the Free Software Foundation; either version 3 of the License, or
10 : (at your option) any later version.
11 :
12 : GCC is distributed in the hope that it will be useful,
13 : but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : GNU 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 CALLBACK_INFO_H
22 : #define CALLBACK_INFO_H
23 :
24 : /* Summary aggregating all information relevant to callback edges. Most of the
25 : information can be calculated from the attribute as well, but keeping it
26 : separate allows us to modify the info without touching the underlying
27 : attribute. */
28 32130 : class callback_info
29 : {
30 : public:
31 : /* Index of the callback function in the argument list. Currently also used
32 : as an id for the callback attribute of the function (needed if a function
33 : has multiple callback attributes). This limits us to a single callback
34 : attribute per parameter. If we want to allow multiple attributes per
35 : parameter, we will need a separate id field. */
36 : unsigned fn_idx;
37 :
38 : /* Mapping from the indices of the arguments passed to the callback to their
39 : indices in the call to the dispatching function or to
40 : ARG_MAPPING_UNKNOWN_IDX if they do not correspond to any. */
41 : auto_vec<int> arg_mapping;
42 :
43 : /* Mapping in the opposite direction, from indices of the actual
44 : arguments of the call to the dispatcher to indices of arguments in
45 : which they are passed to the callback or to ARG_MAPPING_UNKNOWN_IDX
46 : if they are not passed to the callback. */
47 : auto_vec<int> inverted_mapping;
48 :
49 : /* TRUE iff the associated callback edge was redirected. */
50 : bool redirected;
51 :
52 : /* Stream in callback_info. */
53 : void stream_in (lto_input_block *ib);
54 :
55 : /* Stream out callback_info. */
56 : void stream_out (lto_simple_output_block *ib) const;
57 :
58 : /* Returns the id of the associated callback attribute. */
59 : unsigned get_id () const;
60 :
61 : /* Initializes the summary. */
62 : void init (cgraph_edge *e, unsigned fn_idx, tree attr);
63 :
64 : /* Create the summary for a callback call CBE of internal function IFN. */
65 : static callback_info *create_internal_summary (cgraph_edge *cbe,
66 : internal_fn ifn);
67 : };
68 :
69 : class callback_info_sum_t : public call_summary<callback_info *>
70 : {
71 : public:
72 260238 : callback_info_sum_t (symbol_table *table, bool ggc)
73 260238 : : call_summary<callback_info *> (table, ggc)
74 : {}
75 :
76 : /* Populates the callback_info_sum if it's NULL. */
77 : static void check_create_info_sum ();
78 :
79 : /* Frees the callback_info_sum pointer. */
80 : static void free_info_sum ();
81 :
82 : /* Duplication function for the cgraph_edge duplication hook. */
83 : void duplicate (cgraph_edge *src, cgraph_edge *dst, callback_info *src_s,
84 : callback_info *dst_s) override;
85 : };
86 :
87 : extern callback_info_sum_t *callback_info_sum;
88 :
89 : /* Return the argument of STMT at IDX if CI is null, otherwise use the mapping
90 : in CI and return the remapped argument. Presumes that the remapped index is
91 : not ARG_MAPPING_UNKNOWN_IDX. */
92 : tree callback_call_arg_summary (const gimple *stmt, int idx, callback_info *ci);
93 :
94 : /* Return the number of arguments of STMT if CI is null,
95 : ci->arg_mapping.length() otherwise. */
96 : unsigned callback_call_num_args_summary (const gcall *stmt, callback_info *ci);
97 :
98 : /* Returns TRUE iff STMT is an internal call statement to IFN_ASSUME. */
99 : bool callback_ifn_assume_call_p (const gimple *stmt);
100 :
101 : /* Returns TRUE iff STMT is an internal call statement to IFN_ASSUME with a
102 : callback edge pointing to the outlined body. */
103 : bool callback_ifn_assume_call_with_edge_p (cgraph_node *caller, gimple *stmt);
104 :
105 : #endif /* CALLBACK_INFO_H */
|