GCC Middle and Back End API Reference
ipa-modref.h
Go to the documentation of this file.
1/* Search for references that a functions loads or stores.
2 Copyright (C) 2019-2025 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#ifndef IPA_MODREF_H
21#define IPA_MODREF_H
22
23typedef modref_tree <alias_set_type> modref_records;
24typedef unsigned short eaf_flags_t;
25
26/* Single function summary. */
27
29{
30 /* Load and stores in function (transitively closed to all callees) */
35
38
39 unsigned writes_errno : 1;
40 /* Side effects does not include memory loads and stores which are
41 expressed using loads, stores and calls_interposable fields. */
42 unsigned side_effects : 1;
43 /* If true function can not be CSE optimized because it may behave
44 differently even if invoked with same inputs. */
45 unsigned nondeterministic : 1;
46 /* IF true the function may read any reachable memory but not use
47 it for anything useful. This may happen i.e. when interposing
48 function with optimized out conditional with unoptimized one.
49
50 In this situation the loads summary is not useful for DSE but
51 it is still useful for CSE. */
52 unsigned calls_interposable : 1;
53
54 /* Flags computed by finalize method. */
55
56 /* Total number of accesses in loads tree. */
57 unsigned int load_accesses;
58 /* global_memory_read is not set for functions calling functions
59 with !binds_to_current_def which, after interposition, may read global
60 memory but do nothing useful with it (except for crashing if some
61 stores are optimized out. */
62 unsigned global_memory_read : 1;
64 unsigned try_dse : 1;
65
66
69 void dump (FILE *) const;
70 bool useful_p (int ecf_flags, bool check_flags = true);
71 void finalize (tree);
72};
73
75modref_summary *get_modref_function_summary (gcall *call, bool *interposed);
79
80/* All flags that are implied by the ECF_CONST functions. */
86
87/* All flags that are implied by the ECF_PURE function. */
91
92/* All flags implied when we know we can ignore stores (i.e. when handling
93 call to noreturn). */
97
98/* Return slot is write-only. */
103
104/* If function does not bind to current def (i.e. it is inline in comdat
105 section), the modref analysis may not match the behavior of function
106 which will be later symbol interposed to. All side effects must match
107 however it is possible that the other function body contains more loads
108 which may trap.
109 MODREF_FLAGS are flags determined by analysis of function body while
110 FLAGS are flags known otherwise (i.e. by fnspec, pure/const attributes
111 etc.) */
112inline int
113interposable_eaf_flags (int modref_flags, int flags)
114{
115 /* If parameter was previously unused, we know it is only read
116 and its value is not used. */
117 if ((modref_flags & EAF_UNUSED) && !(flags & EAF_UNUSED))
118 {
119 modref_flags &= ~EAF_UNUSED;
123 }
124 /* We can not determine that value is not read at all. */
125 if ((modref_flags & EAF_NO_DIRECT_READ) && !(flags & EAF_NO_DIRECT_READ))
126 modref_flags &= ~EAF_NO_DIRECT_READ;
127 if ((modref_flags & EAF_NO_INDIRECT_READ) && !(flags & EAF_NO_INDIRECT_READ))
128 modref_flags &= ~EAF_NO_INDIRECT_READ;
129 return modref_flags;
130}
131
132#endif
Definition vec.h:1656
Definition cgraph.h:1700
#define GTY(x)
Definition coretypes.h:41
union tree_node * tree
Definition coretypes.h:97
modref_tree< alias_set_type > modref_records
Definition ipa-modref.h:23
void ipa_modref_cc_finalize()
Definition ipa-modref.cc:5602
static const int implicit_const_eaf_flags
Definition ipa-modref.h:82
bool ipa_modref_callee_reads_no_memory_p(gcall *call)
Definition ipa-modref.cc:5621
int interposable_eaf_flags(int modref_flags, int flags)
Definition ipa-modref.h:113
static const int implicit_pure_eaf_flags
Definition ipa-modref.h:89
unsigned short eaf_flags_t
Definition ipa-modref.h:24
static const int implicit_retslot_eaf_flags
Definition ipa-modref.h:100
void ipa_merge_modref_summary_after_inlining(cgraph_edge *e)
Definition ipa-modref.cc:5321
modref_summary * get_modref_function_summary(cgraph_node *func)
Definition ipa-modref.cc:744
static const int ignore_stores_eaf_flags
Definition ipa-modref.h:95
Definition cgraph.h:879
Definition gimple.h:352
Definition ipa-modref.h:29
bool useful_p(int ecf_flags, bool check_flags=true)
Definition ipa-modref.cc:325
auto_vec< eaf_flags_t > arg_flags
Definition ipa-modref.h:34
unsigned side_effects
Definition ipa-modref.h:42
modref_summary()
Definition ipa-modref.cc:279
unsigned calls_interposable
Definition ipa-modref.h:52
auto_vec< modref_access_node > kills
Definition ipa-modref.h:33
eaf_flags_t static_chain_flags
Definition ipa-modref.h:37
~modref_summary()
Definition ipa-modref.cc:287
unsigned global_memory_written
Definition ipa-modref.h:63
modref_records * loads
Definition ipa-modref.h:31
modref_records * stores
Definition ipa-modref.h:32
unsigned global_memory_read
Definition ipa-modref.h:62
unsigned try_dse
Definition ipa-modref.h:64
eaf_flags_t retslot_flags
Definition ipa-modref.h:36
unsigned int load_accesses
Definition ipa-modref.h:57
void dump(FILE *) const
Definition ipa-modref.cc:568
unsigned nondeterministic
Definition ipa-modref.h:45
unsigned writes_errno
Definition ipa-modref.h:39
Definition ipa-modref-tree.h:309
static void finalize()
Definition toplev.cc:2048
#define EAF_NO_INDIRECT_READ
Definition tree-core.h:124
#define EAF_NOT_RETURNED_INDIRECTLY
Definition tree-core.h:120
#define EAF_NO_INDIRECT_ESCAPE
Definition tree-core.h:116
#define EAF_NO_DIRECT_CLOBBER
Definition tree-core.h:111
#define EAF_NO_DIRECT_READ
Definition tree-core.h:123
#define EAF_NO_DIRECT_ESCAPE
Definition tree-core.h:115
#define EAF_NOT_RETURNED_DIRECTLY
Definition tree-core.h:119
#define EAF_NO_INDIRECT_CLOBBER
Definition tree-core.h:112
#define EAF_UNUSED
Definition tree-core.h:104