annotate gcc/ipa-predicate.h @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* IPA predicates.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2003-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 Contributed by Jan Hubicka
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 This file is part of GCC.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
8 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
9 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
10 version.
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
15 for more details.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 /* Representation of inline parameters that do depend on context function is
kono
parents:
diff changeset
22 inlined into (i.e. known constant values of function parameters.
kono
parents:
diff changeset
23
kono
parents:
diff changeset
24 Conditions that are interesting for function body are collected into CONDS
kono
parents:
diff changeset
25 vector. They are of simple for function_param OP VAL, where VAL is
kono
parents:
diff changeset
26 IPA invariant. The conditions are then referred by predicates. */
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 struct GTY(()) condition
kono
parents:
diff changeset
29 {
kono
parents:
diff changeset
30 /* If agg_contents is set, this is the offset from which the used data was
kono
parents:
diff changeset
31 loaded. */
kono
parents:
diff changeset
32 HOST_WIDE_INT offset;
kono
parents:
diff changeset
33 /* Size of the access reading the data (or the PARM_DECL SSA_NAME). */
kono
parents:
diff changeset
34 HOST_WIDE_INT size;
kono
parents:
diff changeset
35 tree val;
kono
parents:
diff changeset
36 int operand_num;
kono
parents:
diff changeset
37 ENUM_BITFIELD(tree_code) code : 16;
kono
parents:
diff changeset
38 /* Set if the used data were loaded from an aggregate parameter or from
kono
parents:
diff changeset
39 data received by reference. */
kono
parents:
diff changeset
40 unsigned agg_contents : 1;
kono
parents:
diff changeset
41 /* If agg_contents is set, this differentiates between loads from data
kono
parents:
diff changeset
42 passed by reference and by value. */
kono
parents:
diff changeset
43 unsigned by_ref : 1;
kono
parents:
diff changeset
44 };
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 /* Information kept about parameter of call site. */
kono
parents:
diff changeset
47 struct inline_param_summary
kono
parents:
diff changeset
48 {
kono
parents:
diff changeset
49 /* REG_BR_PROB_BASE based probability that parameter will change in between
kono
parents:
diff changeset
50 two invocation of the calls.
kono
parents:
diff changeset
51 I.e. loop invariant parameters
kono
parents:
diff changeset
52 REG_BR_PROB_BASE/estimated_iterations and regular
kono
parents:
diff changeset
53 parameters REG_BR_PROB_BASE.
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 Value 0 is reserved for compile time invariants. */
kono
parents:
diff changeset
56 int change_prob;
kono
parents:
diff changeset
57 };
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 typedef vec<condition, va_gc> *conditions;
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 /* Predicates are used to repesent function parameters (such as runtime)
kono
parents:
diff changeset
62 which depend on a context function is called in.
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 Predicates are logical formulas in conjunctive-disjunctive form consisting
kono
parents:
diff changeset
65 of clauses which are bitmaps specifying a set of condition that must
kono
parents:
diff changeset
66 be true for a clause to be satisfied. Physically they are represented as
kono
parents:
diff changeset
67 array of clauses terminated by 0.
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 In order to make predicate (possibly) true, all of its clauses must
kono
parents:
diff changeset
70 be (possibly) true. To make clause (possibly) true, one of conditions
kono
parents:
diff changeset
71 it mentions must be (possibly) true.
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 There are fixed bounds on number of clauses and conditions and all the
kono
parents:
diff changeset
74 manipulation functions are conservative in positive direction. I.e. we
kono
parents:
diff changeset
75 may lose precision by thinking that predicate may be true even when it
kono
parents:
diff changeset
76 is not. */
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 typedef uint32_t clause_t;
kono
parents:
diff changeset
79 class predicate
kono
parents:
diff changeset
80 {
kono
parents:
diff changeset
81 public:
kono
parents:
diff changeset
82 enum predicate_conditions
kono
parents:
diff changeset
83 {
kono
parents:
diff changeset
84 false_condition = 0,
kono
parents:
diff changeset
85 not_inlined_condition = 1,
kono
parents:
diff changeset
86 first_dynamic_condition = 2
kono
parents:
diff changeset
87 };
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 /* Maximal number of conditions predicate can reffer to. This is limited
kono
parents:
diff changeset
90 by using clause_t to be 32bit. */
kono
parents:
diff changeset
91 static const int num_conditions = 32;
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 /* Special condition code we use to represent test that operand is compile
kono
parents:
diff changeset
94 time constant. */
kono
parents:
diff changeset
95 static const tree_code is_not_constant = ERROR_MARK;
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 /* Special condition code we use to represent test that operand is not changed
kono
parents:
diff changeset
98 across invocation of the function. When operand IS_NOT_CONSTANT it is
kono
parents:
diff changeset
99 always CHANGED, however i.e. loop invariants can be NOT_CHANGED given
kono
parents:
diff changeset
100 percentage of executions even when they are not compile time constants. */
kono
parents:
diff changeset
101 static const tree_code changed = IDENTIFIER_NODE;
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 /* Initialize predicate either to true of false depending on P. */
kono
parents:
diff changeset
106 inline predicate (bool p = true)
kono
parents:
diff changeset
107 {
kono
parents:
diff changeset
108 if (p)
kono
parents:
diff changeset
109 /* True predicate. */
kono
parents:
diff changeset
110 m_clause[0] = 0;
kono
parents:
diff changeset
111 else
kono
parents:
diff changeset
112 /* False predicate. */
kono
parents:
diff changeset
113 set_to_cond (false_condition);
kono
parents:
diff changeset
114 }
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 /* Sanity check that we do not mix pointers to predicates with predicates. */
kono
parents:
diff changeset
117 inline predicate (predicate *)
kono
parents:
diff changeset
118 {
kono
parents:
diff changeset
119 gcc_unreachable ();
kono
parents:
diff changeset
120 }
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122 /* Return predicate testing condition I. */
kono
parents:
diff changeset
123 static inline predicate predicate_testing_cond (int i)
kono
parents:
diff changeset
124 {
kono
parents:
diff changeset
125 class predicate p;
kono
parents:
diff changeset
126 p.set_to_cond (i + first_dynamic_condition);
kono
parents:
diff changeset
127 return p;
kono
parents:
diff changeset
128 }
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 /* Return predicate testing that function was not inlined. */
kono
parents:
diff changeset
131 static predicate not_inlined (void)
kono
parents:
diff changeset
132 {
kono
parents:
diff changeset
133 class predicate p;
kono
parents:
diff changeset
134 p.set_to_cond (not_inlined_condition);
kono
parents:
diff changeset
135 return p;
kono
parents:
diff changeset
136 }
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 /* Compute logical and of predicates. */
kono
parents:
diff changeset
139 predicate & operator &= (const predicate &);
kono
parents:
diff changeset
140 inline predicate operator &(const predicate &p) const
kono
parents:
diff changeset
141 {
kono
parents:
diff changeset
142 predicate ret = *this;
kono
parents:
diff changeset
143 ret &= p;
kono
parents:
diff changeset
144 return ret;
kono
parents:
diff changeset
145 }
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 /* Compute logical or of predicates. This is not operator because
kono
parents:
diff changeset
148 extra parameter CONDITIONS is needed */
kono
parents:
diff changeset
149 predicate or_with (conditions, const predicate &) const;
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 /* Return true if predicates are known to be equal. */
kono
parents:
diff changeset
152 inline bool operator==(const predicate &p2) const
kono
parents:
diff changeset
153 {
kono
parents:
diff changeset
154 int i;
kono
parents:
diff changeset
155 for (i = 0; m_clause[i]; i++)
kono
parents:
diff changeset
156 {
kono
parents:
diff changeset
157 gcc_checking_assert (i < max_clauses);
kono
parents:
diff changeset
158 gcc_checking_assert (m_clause[i] > m_clause[i + 1]);
kono
parents:
diff changeset
159 gcc_checking_assert (!p2.m_clause[i]
kono
parents:
diff changeset
160 || p2.m_clause[i] > p2.m_clause[i + 1]);
kono
parents:
diff changeset
161 if (m_clause[i] != p2.m_clause[i])
kono
parents:
diff changeset
162 return false;
kono
parents:
diff changeset
163 }
kono
parents:
diff changeset
164 return !p2.m_clause[i];
kono
parents:
diff changeset
165 }
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 /* Return true if predicates are known to be true or false depending
kono
parents:
diff changeset
168 on COND. */
kono
parents:
diff changeset
169 inline bool operator==(const bool cond) const
kono
parents:
diff changeset
170 {
kono
parents:
diff changeset
171 if (cond)
kono
parents:
diff changeset
172 return !m_clause[0];
kono
parents:
diff changeset
173 if (m_clause[0] == (1 << false_condition))
kono
parents:
diff changeset
174 {
kono
parents:
diff changeset
175 gcc_checking_assert (!m_clause[1]
kono
parents:
diff changeset
176 && m_clause[0] == 1
kono
parents:
diff changeset
177 << false_condition);
kono
parents:
diff changeset
178 return true;
kono
parents:
diff changeset
179 }
kono
parents:
diff changeset
180 return false;
kono
parents:
diff changeset
181 }
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 inline bool operator!=(const predicate &p2) const
kono
parents:
diff changeset
184 {
kono
parents:
diff changeset
185 return !(*this == p2);
kono
parents:
diff changeset
186 }
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 inline bool operator!=(const bool cond) const
kono
parents:
diff changeset
189 {
kono
parents:
diff changeset
190 return !(*this == cond);
kono
parents:
diff changeset
191 }
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 /* Evaluate if predicate is known to be false given the clause of possible
kono
parents:
diff changeset
194 truths. */
kono
parents:
diff changeset
195 bool evaluate (clause_t) const;
kono
parents:
diff changeset
196
kono
parents:
diff changeset
197 /* Estimate probability that predicate will be true in a given context. */
kono
parents:
diff changeset
198 int probability (conditions, clause_t, vec<inline_param_summary>) const;
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 /* Dump predicate to F. Output newline if nl. */
kono
parents:
diff changeset
201 void dump (FILE *f, conditions, bool nl=true) const;
kono
parents:
diff changeset
202 void DEBUG_FUNCTION debug (conditions) const;
kono
parents:
diff changeset
203
kono
parents:
diff changeset
204 /* Return predicate equal to THIS after duplication. */
kono
parents:
diff changeset
205 predicate remap_after_duplication (clause_t);
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207 /* Return predicate equal to THIS after inlining. */
kono
parents:
diff changeset
208 predicate remap_after_inlining (struct ipa_fn_summary *,
kono
parents:
diff changeset
209 struct ipa_fn_summary *,
kono
parents:
diff changeset
210 vec<int>, vec<int>, clause_t, const predicate &);
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 void stream_in (struct lto_input_block *);
kono
parents:
diff changeset
213 void stream_out (struct output_block *);
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215 private:
kono
parents:
diff changeset
216 static const int max_clauses = 8;
kono
parents:
diff changeset
217 clause_t m_clause[max_clauses + 1];
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 /* Initialize predicate to one testing single condition number COND. */
kono
parents:
diff changeset
220 inline void set_to_cond (int cond)
kono
parents:
diff changeset
221 {
kono
parents:
diff changeset
222 m_clause[0] = 1 << cond;
kono
parents:
diff changeset
223 m_clause[1] = 0;
kono
parents:
diff changeset
224 }
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 void add_clause (conditions conditions, clause_t);
kono
parents:
diff changeset
227 };
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 void dump_condition (FILE *f, conditions conditions, int cond);
kono
parents:
diff changeset
230 predicate add_condition (struct ipa_fn_summary *summary, int operand_num,
kono
parents:
diff changeset
231 HOST_WIDE_INT size, struct agg_position_info *aggpos,
kono
parents:
diff changeset
232 enum tree_code code, tree val);