1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef GCC_COMMON_H_INCLUDED
3*4882a593Smuzhiyun #define GCC_COMMON_H_INCLUDED
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun #include "bversion.h"
6*4882a593Smuzhiyun #if BUILDING_GCC_VERSION >= 6000
7*4882a593Smuzhiyun #include "gcc-plugin.h"
8*4882a593Smuzhiyun #else
9*4882a593Smuzhiyun #include "plugin.h"
10*4882a593Smuzhiyun #endif
11*4882a593Smuzhiyun #include "plugin-version.h"
12*4882a593Smuzhiyun #include "config.h"
13*4882a593Smuzhiyun #include "system.h"
14*4882a593Smuzhiyun #include "coretypes.h"
15*4882a593Smuzhiyun #include "tm.h"
16*4882a593Smuzhiyun #include "line-map.h"
17*4882a593Smuzhiyun #include "input.h"
18*4882a593Smuzhiyun #include "tree.h"
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun #include "tree-inline.h"
21*4882a593Smuzhiyun #include "version.h"
22*4882a593Smuzhiyun #include "rtl.h"
23*4882a593Smuzhiyun #include "tm_p.h"
24*4882a593Smuzhiyun #include "flags.h"
25*4882a593Smuzhiyun #include "hard-reg-set.h"
26*4882a593Smuzhiyun #include "output.h"
27*4882a593Smuzhiyun #include "except.h"
28*4882a593Smuzhiyun #include "function.h"
29*4882a593Smuzhiyun #include "toplev.h"
30*4882a593Smuzhiyun #if BUILDING_GCC_VERSION >= 5000
31*4882a593Smuzhiyun #include "expr.h"
32*4882a593Smuzhiyun #endif
33*4882a593Smuzhiyun #include "basic-block.h"
34*4882a593Smuzhiyun #include "intl.h"
35*4882a593Smuzhiyun #include "ggc.h"
36*4882a593Smuzhiyun #include "timevar.h"
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun #if BUILDING_GCC_VERSION < 10000
39*4882a593Smuzhiyun #include "params.h"
40*4882a593Smuzhiyun #endif
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun #if BUILDING_GCC_VERSION <= 4009
43*4882a593Smuzhiyun #include "pointer-set.h"
44*4882a593Smuzhiyun #else
45*4882a593Smuzhiyun #include "hash-map.h"
46*4882a593Smuzhiyun #endif
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun #if BUILDING_GCC_VERSION >= 7000
49*4882a593Smuzhiyun #include "memmodel.h"
50*4882a593Smuzhiyun #endif
51*4882a593Smuzhiyun #include "emit-rtl.h"
52*4882a593Smuzhiyun #include "debug.h"
53*4882a593Smuzhiyun #include "target.h"
54*4882a593Smuzhiyun #include "langhooks.h"
55*4882a593Smuzhiyun #include "cfgloop.h"
56*4882a593Smuzhiyun #include "cgraph.h"
57*4882a593Smuzhiyun #include "opts.h"
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun #if BUILDING_GCC_VERSION == 4005
60*4882a593Smuzhiyun #include <sys/mman.h>
61*4882a593Smuzhiyun #endif
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun #if BUILDING_GCC_VERSION >= 4007
64*4882a593Smuzhiyun #include "tree-pretty-print.h"
65*4882a593Smuzhiyun #include "gimple-pretty-print.h"
66*4882a593Smuzhiyun #endif
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun #if BUILDING_GCC_VERSION >= 4006
69*4882a593Smuzhiyun /*
70*4882a593Smuzhiyun * The c-family headers were moved into a subdirectory in GCC version
71*4882a593Smuzhiyun * 4.7, but most plugin-building users of GCC 4.6 are using the Debian
72*4882a593Smuzhiyun * or Ubuntu package, which has an out-of-tree patch to move this to the
73*4882a593Smuzhiyun * same location as found in 4.7 and later:
74*4882a593Smuzhiyun * https://sources.debian.net/src/gcc-4.6/4.6.3-14/debian/patches/pr45078.diff/
75*4882a593Smuzhiyun */
76*4882a593Smuzhiyun #include "c-family/c-common.h"
77*4882a593Smuzhiyun #else
78*4882a593Smuzhiyun #include "c-common.h"
79*4882a593Smuzhiyun #endif
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun #if BUILDING_GCC_VERSION <= 4008
82*4882a593Smuzhiyun #include "tree-flow.h"
83*4882a593Smuzhiyun #else
84*4882a593Smuzhiyun #include "tree-cfgcleanup.h"
85*4882a593Smuzhiyun #include "tree-ssa-operands.h"
86*4882a593Smuzhiyun #include "tree-into-ssa.h"
87*4882a593Smuzhiyun #endif
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun #if BUILDING_GCC_VERSION >= 4008
90*4882a593Smuzhiyun #include "is-a.h"
91*4882a593Smuzhiyun #endif
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun #include "diagnostic.h"
94*4882a593Smuzhiyun #include "tree-dump.h"
95*4882a593Smuzhiyun #include "tree-pass.h"
96*4882a593Smuzhiyun #if BUILDING_GCC_VERSION >= 4009
97*4882a593Smuzhiyun #include "pass_manager.h"
98*4882a593Smuzhiyun #endif
99*4882a593Smuzhiyun #include "predict.h"
100*4882a593Smuzhiyun #include "ipa-utils.h"
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun #if BUILDING_GCC_VERSION >= 8000
103*4882a593Smuzhiyun #include "stringpool.h"
104*4882a593Smuzhiyun #endif
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun #if BUILDING_GCC_VERSION >= 4009
107*4882a593Smuzhiyun #include "attribs.h"
108*4882a593Smuzhiyun #include "varasm.h"
109*4882a593Smuzhiyun #include "stor-layout.h"
110*4882a593Smuzhiyun #include "internal-fn.h"
111*4882a593Smuzhiyun #include "gimple-expr.h"
112*4882a593Smuzhiyun #include "gimple-fold.h"
113*4882a593Smuzhiyun #include "context.h"
114*4882a593Smuzhiyun #include "tree-ssa-alias.h"
115*4882a593Smuzhiyun #include "tree-ssa.h"
116*4882a593Smuzhiyun #include "stringpool.h"
117*4882a593Smuzhiyun #if BUILDING_GCC_VERSION >= 7000
118*4882a593Smuzhiyun #include "tree-vrp.h"
119*4882a593Smuzhiyun #endif
120*4882a593Smuzhiyun #include "tree-ssanames.h"
121*4882a593Smuzhiyun #include "print-tree.h"
122*4882a593Smuzhiyun #include "tree-eh.h"
123*4882a593Smuzhiyun #include "stmt.h"
124*4882a593Smuzhiyun #include "gimplify.h"
125*4882a593Smuzhiyun #endif
126*4882a593Smuzhiyun
127*4882a593Smuzhiyun #include "gimple.h"
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun #if BUILDING_GCC_VERSION >= 4009
130*4882a593Smuzhiyun #include "tree-ssa-operands.h"
131*4882a593Smuzhiyun #include "tree-phinodes.h"
132*4882a593Smuzhiyun #include "tree-cfg.h"
133*4882a593Smuzhiyun #include "gimple-iterator.h"
134*4882a593Smuzhiyun #include "gimple-ssa.h"
135*4882a593Smuzhiyun #include "ssa-iterators.h"
136*4882a593Smuzhiyun #endif
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun #if BUILDING_GCC_VERSION >= 5000
139*4882a593Smuzhiyun #include "builtins.h"
140*4882a593Smuzhiyun #endif
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun /* missing from basic_block.h... */
143*4882a593Smuzhiyun void debug_dominance_info(enum cdi_direction dir);
144*4882a593Smuzhiyun void debug_dominance_tree(enum cdi_direction dir, basic_block root);
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun #if BUILDING_GCC_VERSION == 4006
147*4882a593Smuzhiyun void debug_gimple_stmt(gimple);
148*4882a593Smuzhiyun void debug_gimple_seq(gimple_seq);
149*4882a593Smuzhiyun void print_gimple_seq(FILE *, gimple_seq, int, int);
150*4882a593Smuzhiyun void print_gimple_stmt(FILE *, gimple, int, int);
151*4882a593Smuzhiyun void print_gimple_expr(FILE *, gimple, int, int);
152*4882a593Smuzhiyun void dump_gimple_stmt(pretty_printer *, gimple, int, int);
153*4882a593Smuzhiyun #endif
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun #ifndef __unused
156*4882a593Smuzhiyun #define __unused __attribute__((__unused__))
157*4882a593Smuzhiyun #endif
158*4882a593Smuzhiyun #ifndef __visible
159*4882a593Smuzhiyun #define __visible __attribute__((visibility("default")))
160*4882a593Smuzhiyun #endif
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun #define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
163*4882a593Smuzhiyun #define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
164*4882a593Smuzhiyun #define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
165*4882a593Smuzhiyun #define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun /* should come from c-tree.h if only it were installed for gcc 4.5... */
168*4882a593Smuzhiyun #define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
169*4882a593Smuzhiyun
build_const_char_string(int len,const char * str)170*4882a593Smuzhiyun static inline tree build_const_char_string(int len, const char *str)
171*4882a593Smuzhiyun {
172*4882a593Smuzhiyun tree cstr, elem, index, type;
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun cstr = build_string(len, str);
175*4882a593Smuzhiyun elem = build_type_variant(char_type_node, 1, 0);
176*4882a593Smuzhiyun index = build_index_type(size_int(len - 1));
177*4882a593Smuzhiyun type = build_array_type(elem, index);
178*4882a593Smuzhiyun TREE_TYPE(cstr) = type;
179*4882a593Smuzhiyun TREE_CONSTANT(cstr) = 1;
180*4882a593Smuzhiyun TREE_READONLY(cstr) = 1;
181*4882a593Smuzhiyun TREE_STATIC(cstr) = 1;
182*4882a593Smuzhiyun return cstr;
183*4882a593Smuzhiyun }
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun #define PASS_INFO(NAME, REF, ID, POS) \
186*4882a593Smuzhiyun struct register_pass_info NAME##_pass_info = { \
187*4882a593Smuzhiyun .pass = make_##NAME##_pass(), \
188*4882a593Smuzhiyun .reference_pass_name = REF, \
189*4882a593Smuzhiyun .ref_pass_instance_number = ID, \
190*4882a593Smuzhiyun .pos_op = POS, \
191*4882a593Smuzhiyun }
192*4882a593Smuzhiyun
193*4882a593Smuzhiyun #if BUILDING_GCC_VERSION == 4005
194*4882a593Smuzhiyun #define FOR_EACH_LOCAL_DECL(FUN, I, D) \
195*4882a593Smuzhiyun for (tree vars = (FUN)->local_decls, (I) = 0; \
196*4882a593Smuzhiyun vars && ((D) = TREE_VALUE(vars)); \
197*4882a593Smuzhiyun vars = TREE_CHAIN(vars), (I)++)
198*4882a593Smuzhiyun #define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
199*4882a593Smuzhiyun #define FOR_EACH_VEC_ELT(T, V, I, P) \
200*4882a593Smuzhiyun for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
201*4882a593Smuzhiyun #define TODO_rebuild_cgraph_edges 0
202*4882a593Smuzhiyun #define SCOPE_FILE_SCOPE_P(EXP) (!(EXP))
203*4882a593Smuzhiyun
204*4882a593Smuzhiyun #ifndef O_BINARY
205*4882a593Smuzhiyun #define O_BINARY 0
206*4882a593Smuzhiyun #endif
207*4882a593Smuzhiyun
208*4882a593Smuzhiyun typedef struct varpool_node *varpool_node_ptr;
209*4882a593Smuzhiyun
gimple_call_builtin_p(gimple stmt,enum built_in_function code)210*4882a593Smuzhiyun static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
211*4882a593Smuzhiyun {
212*4882a593Smuzhiyun tree fndecl;
213*4882a593Smuzhiyun
214*4882a593Smuzhiyun if (!is_gimple_call(stmt))
215*4882a593Smuzhiyun return false;
216*4882a593Smuzhiyun fndecl = gimple_call_fndecl(stmt);
217*4882a593Smuzhiyun if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
218*4882a593Smuzhiyun return false;
219*4882a593Smuzhiyun return DECL_FUNCTION_CODE(fndecl) == code;
220*4882a593Smuzhiyun }
221*4882a593Smuzhiyun
is_simple_builtin(tree decl)222*4882a593Smuzhiyun static inline bool is_simple_builtin(tree decl)
223*4882a593Smuzhiyun {
224*4882a593Smuzhiyun if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
225*4882a593Smuzhiyun return false;
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun switch (DECL_FUNCTION_CODE(decl)) {
228*4882a593Smuzhiyun /* Builtins that expand to constants. */
229*4882a593Smuzhiyun case BUILT_IN_CONSTANT_P:
230*4882a593Smuzhiyun case BUILT_IN_EXPECT:
231*4882a593Smuzhiyun case BUILT_IN_OBJECT_SIZE:
232*4882a593Smuzhiyun case BUILT_IN_UNREACHABLE:
233*4882a593Smuzhiyun /* Simple register moves or loads from stack. */
234*4882a593Smuzhiyun case BUILT_IN_RETURN_ADDRESS:
235*4882a593Smuzhiyun case BUILT_IN_EXTRACT_RETURN_ADDR:
236*4882a593Smuzhiyun case BUILT_IN_FROB_RETURN_ADDR:
237*4882a593Smuzhiyun case BUILT_IN_RETURN:
238*4882a593Smuzhiyun case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
239*4882a593Smuzhiyun case BUILT_IN_FRAME_ADDRESS:
240*4882a593Smuzhiyun case BUILT_IN_VA_END:
241*4882a593Smuzhiyun case BUILT_IN_STACK_SAVE:
242*4882a593Smuzhiyun case BUILT_IN_STACK_RESTORE:
243*4882a593Smuzhiyun /* Exception state returns or moves registers around. */
244*4882a593Smuzhiyun case BUILT_IN_EH_FILTER:
245*4882a593Smuzhiyun case BUILT_IN_EH_POINTER:
246*4882a593Smuzhiyun case BUILT_IN_EH_COPY_VALUES:
247*4882a593Smuzhiyun return true;
248*4882a593Smuzhiyun
249*4882a593Smuzhiyun default:
250*4882a593Smuzhiyun return false;
251*4882a593Smuzhiyun }
252*4882a593Smuzhiyun }
253*4882a593Smuzhiyun
add_local_decl(struct function * fun,tree d)254*4882a593Smuzhiyun static inline void add_local_decl(struct function *fun, tree d)
255*4882a593Smuzhiyun {
256*4882a593Smuzhiyun gcc_assert(TREE_CODE(d) == VAR_DECL);
257*4882a593Smuzhiyun fun->local_decls = tree_cons(NULL_TREE, d, fun->local_decls);
258*4882a593Smuzhiyun }
259*4882a593Smuzhiyun #endif
260*4882a593Smuzhiyun
261*4882a593Smuzhiyun #if BUILDING_GCC_VERSION <= 4006
262*4882a593Smuzhiyun #define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
263*4882a593Smuzhiyun #define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
264*4882a593Smuzhiyun #define EDGE_PRESERVE 0ULL
265*4882a593Smuzhiyun #define HOST_WIDE_INT_PRINT_HEX_PURE "%" HOST_WIDE_INT_PRINT "x"
266*4882a593Smuzhiyun #define flag_fat_lto_objects true
267*4882a593Smuzhiyun
268*4882a593Smuzhiyun #define get_random_seed(noinit) ({ \
269*4882a593Smuzhiyun unsigned HOST_WIDE_INT seed; \
270*4882a593Smuzhiyun sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
271*4882a593Smuzhiyun seed * seed; })
272*4882a593Smuzhiyun
273*4882a593Smuzhiyun #define int_const_binop(code, arg1, arg2) \
274*4882a593Smuzhiyun int_const_binop((code), (arg1), (arg2), 0)
275*4882a593Smuzhiyun
gimple_clobber_p(gimple s __unused)276*4882a593Smuzhiyun static inline bool gimple_clobber_p(gimple s __unused)
277*4882a593Smuzhiyun {
278*4882a593Smuzhiyun return false;
279*4882a593Smuzhiyun }
280*4882a593Smuzhiyun
gimple_asm_clobbers_memory_p(const_gimple stmt)281*4882a593Smuzhiyun static inline bool gimple_asm_clobbers_memory_p(const_gimple stmt)
282*4882a593Smuzhiyun {
283*4882a593Smuzhiyun unsigned i;
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun for (i = 0; i < gimple_asm_nclobbers(stmt); i++) {
286*4882a593Smuzhiyun tree op = gimple_asm_clobber_op(stmt, i);
287*4882a593Smuzhiyun
288*4882a593Smuzhiyun if (!strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "memory"))
289*4882a593Smuzhiyun return true;
290*4882a593Smuzhiyun }
291*4882a593Smuzhiyun
292*4882a593Smuzhiyun return false;
293*4882a593Smuzhiyun }
294*4882a593Smuzhiyun
builtin_decl_implicit(enum built_in_function fncode)295*4882a593Smuzhiyun static inline tree builtin_decl_implicit(enum built_in_function fncode)
296*4882a593Smuzhiyun {
297*4882a593Smuzhiyun return implicit_built_in_decls[fncode];
298*4882a593Smuzhiyun }
299*4882a593Smuzhiyun
ipa_reverse_postorder(struct cgraph_node ** order)300*4882a593Smuzhiyun static inline int ipa_reverse_postorder(struct cgraph_node **order)
301*4882a593Smuzhiyun {
302*4882a593Smuzhiyun return cgraph_postorder(order);
303*4882a593Smuzhiyun }
304*4882a593Smuzhiyun
cgraph_create_node(tree decl)305*4882a593Smuzhiyun static inline struct cgraph_node *cgraph_create_node(tree decl)
306*4882a593Smuzhiyun {
307*4882a593Smuzhiyun return cgraph_node(decl);
308*4882a593Smuzhiyun }
309*4882a593Smuzhiyun
cgraph_get_create_node(tree decl)310*4882a593Smuzhiyun static inline struct cgraph_node *cgraph_get_create_node(tree decl)
311*4882a593Smuzhiyun {
312*4882a593Smuzhiyun struct cgraph_node *node = cgraph_get_node(decl);
313*4882a593Smuzhiyun
314*4882a593Smuzhiyun return node ? node : cgraph_node(decl);
315*4882a593Smuzhiyun }
316*4882a593Smuzhiyun
cgraph_function_with_gimple_body_p(struct cgraph_node * node)317*4882a593Smuzhiyun static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
318*4882a593Smuzhiyun {
319*4882a593Smuzhiyun return node->analyzed && !node->thunk.thunk_p && !node->alias;
320*4882a593Smuzhiyun }
321*4882a593Smuzhiyun
cgraph_first_function_with_gimple_body(void)322*4882a593Smuzhiyun static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
323*4882a593Smuzhiyun {
324*4882a593Smuzhiyun struct cgraph_node *node;
325*4882a593Smuzhiyun
326*4882a593Smuzhiyun for (node = cgraph_nodes; node; node = node->next)
327*4882a593Smuzhiyun if (cgraph_function_with_gimple_body_p(node))
328*4882a593Smuzhiyun return node;
329*4882a593Smuzhiyun return NULL;
330*4882a593Smuzhiyun }
331*4882a593Smuzhiyun
cgraph_next_function_with_gimple_body(struct cgraph_node * node)332*4882a593Smuzhiyun static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
333*4882a593Smuzhiyun {
334*4882a593Smuzhiyun for (node = node->next; node; node = node->next)
335*4882a593Smuzhiyun if (cgraph_function_with_gimple_body_p(node))
336*4882a593Smuzhiyun return node;
337*4882a593Smuzhiyun return NULL;
338*4882a593Smuzhiyun }
339*4882a593Smuzhiyun
cgraph_for_node_and_aliases(cgraph_node_ptr node,bool (* callback)(cgraph_node_ptr,void *),void * data,bool include_overwritable)340*4882a593Smuzhiyun static inline bool cgraph_for_node_and_aliases(cgraph_node_ptr node, bool (*callback)(cgraph_node_ptr, void *), void *data, bool include_overwritable)
341*4882a593Smuzhiyun {
342*4882a593Smuzhiyun cgraph_node_ptr alias;
343*4882a593Smuzhiyun
344*4882a593Smuzhiyun if (callback(node, data))
345*4882a593Smuzhiyun return true;
346*4882a593Smuzhiyun
347*4882a593Smuzhiyun for (alias = node->same_body; alias; alias = alias->next) {
348*4882a593Smuzhiyun if (include_overwritable || cgraph_function_body_availability(alias) > AVAIL_OVERWRITABLE)
349*4882a593Smuzhiyun if (cgraph_for_node_and_aliases(alias, callback, data, include_overwritable))
350*4882a593Smuzhiyun return true;
351*4882a593Smuzhiyun }
352*4882a593Smuzhiyun
353*4882a593Smuzhiyun return false;
354*4882a593Smuzhiyun }
355*4882a593Smuzhiyun
356*4882a593Smuzhiyun #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
357*4882a593Smuzhiyun for ((node) = cgraph_first_function_with_gimple_body(); (node); \
358*4882a593Smuzhiyun (node) = cgraph_next_function_with_gimple_body(node))
359*4882a593Smuzhiyun
varpool_add_new_variable(tree decl)360*4882a593Smuzhiyun static inline void varpool_add_new_variable(tree decl)
361*4882a593Smuzhiyun {
362*4882a593Smuzhiyun varpool_finalize_decl(decl);
363*4882a593Smuzhiyun }
364*4882a593Smuzhiyun #endif
365*4882a593Smuzhiyun
366*4882a593Smuzhiyun #if BUILDING_GCC_VERSION <= 4007
367*4882a593Smuzhiyun #define FOR_EACH_FUNCTION(node) \
368*4882a593Smuzhiyun for (node = cgraph_nodes; node; node = node->next)
369*4882a593Smuzhiyun #define FOR_EACH_VARIABLE(node) \
370*4882a593Smuzhiyun for (node = varpool_nodes; node; node = node->next)
371*4882a593Smuzhiyun #define PROP_loops 0
372*4882a593Smuzhiyun #define NODE_SYMBOL(node) (node)
373*4882a593Smuzhiyun #define NODE_DECL(node) (node)->decl
374*4882a593Smuzhiyun #define INSN_LOCATION(INSN) RTL_LOCATION(INSN)
375*4882a593Smuzhiyun #define vNULL NULL
376*4882a593Smuzhiyun
bb_loop_depth(const_basic_block bb)377*4882a593Smuzhiyun static inline int bb_loop_depth(const_basic_block bb)
378*4882a593Smuzhiyun {
379*4882a593Smuzhiyun return bb->loop_father ? loop_depth(bb->loop_father) : 0;
380*4882a593Smuzhiyun }
381*4882a593Smuzhiyun
gimple_store_p(gimple gs)382*4882a593Smuzhiyun static inline bool gimple_store_p(gimple gs)
383*4882a593Smuzhiyun {
384*4882a593Smuzhiyun tree lhs = gimple_get_lhs(gs);
385*4882a593Smuzhiyun
386*4882a593Smuzhiyun return lhs && !is_gimple_reg(lhs);
387*4882a593Smuzhiyun }
388*4882a593Smuzhiyun
gimple_init_singleton(gimple g __unused)389*4882a593Smuzhiyun static inline void gimple_init_singleton(gimple g __unused)
390*4882a593Smuzhiyun {
391*4882a593Smuzhiyun }
392*4882a593Smuzhiyun #endif
393*4882a593Smuzhiyun
394*4882a593Smuzhiyun #if BUILDING_GCC_VERSION == 4007 || BUILDING_GCC_VERSION == 4008
cgraph_alias_target(struct cgraph_node * n)395*4882a593Smuzhiyun static inline struct cgraph_node *cgraph_alias_target(struct cgraph_node *n)
396*4882a593Smuzhiyun {
397*4882a593Smuzhiyun return cgraph_alias_aliased_node(n);
398*4882a593Smuzhiyun }
399*4882a593Smuzhiyun #endif
400*4882a593Smuzhiyun
401*4882a593Smuzhiyun #if BUILDING_GCC_VERSION <= 4008
402*4882a593Smuzhiyun #define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
403*4882a593Smuzhiyun #define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
404*4882a593Smuzhiyun #define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
405*4882a593Smuzhiyun #define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
406*4882a593Smuzhiyun #define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
407*4882a593Smuzhiyun #define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
408*4882a593Smuzhiyun #define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
409*4882a593Smuzhiyun #define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
410*4882a593Smuzhiyun #define BASIC_BLOCK_FOR_FN(FN, N) BASIC_BLOCK_FOR_FUNCTION((FN), (N))
411*4882a593Smuzhiyun #define NODE_IMPLICIT_ALIAS(node) (node)->same_body_alias
412*4882a593Smuzhiyun #define VAR_P(NODE) (TREE_CODE(NODE) == VAR_DECL)
413*4882a593Smuzhiyun
tree_fits_shwi_p(const_tree t)414*4882a593Smuzhiyun static inline bool tree_fits_shwi_p(const_tree t)
415*4882a593Smuzhiyun {
416*4882a593Smuzhiyun if (t == NULL_TREE || TREE_CODE(t) != INTEGER_CST)
417*4882a593Smuzhiyun return false;
418*4882a593Smuzhiyun
419*4882a593Smuzhiyun if (TREE_INT_CST_HIGH(t) == 0 && (HOST_WIDE_INT)TREE_INT_CST_LOW(t) >= 0)
420*4882a593Smuzhiyun return true;
421*4882a593Smuzhiyun
422*4882a593Smuzhiyun if (TREE_INT_CST_HIGH(t) == -1 && (HOST_WIDE_INT)TREE_INT_CST_LOW(t) < 0 && !TYPE_UNSIGNED(TREE_TYPE(t)))
423*4882a593Smuzhiyun return true;
424*4882a593Smuzhiyun
425*4882a593Smuzhiyun return false;
426*4882a593Smuzhiyun }
427*4882a593Smuzhiyun
tree_fits_uhwi_p(const_tree t)428*4882a593Smuzhiyun static inline bool tree_fits_uhwi_p(const_tree t)
429*4882a593Smuzhiyun {
430*4882a593Smuzhiyun if (t == NULL_TREE || TREE_CODE(t) != INTEGER_CST)
431*4882a593Smuzhiyun return false;
432*4882a593Smuzhiyun
433*4882a593Smuzhiyun return TREE_INT_CST_HIGH(t) == 0;
434*4882a593Smuzhiyun }
435*4882a593Smuzhiyun
tree_to_shwi(const_tree t)436*4882a593Smuzhiyun static inline HOST_WIDE_INT tree_to_shwi(const_tree t)
437*4882a593Smuzhiyun {
438*4882a593Smuzhiyun gcc_assert(tree_fits_shwi_p(t));
439*4882a593Smuzhiyun return TREE_INT_CST_LOW(t);
440*4882a593Smuzhiyun }
441*4882a593Smuzhiyun
tree_to_uhwi(const_tree t)442*4882a593Smuzhiyun static inline unsigned HOST_WIDE_INT tree_to_uhwi(const_tree t)
443*4882a593Smuzhiyun {
444*4882a593Smuzhiyun gcc_assert(tree_fits_uhwi_p(t));
445*4882a593Smuzhiyun return TREE_INT_CST_LOW(t);
446*4882a593Smuzhiyun }
447*4882a593Smuzhiyun
get_tree_code_name(enum tree_code code)448*4882a593Smuzhiyun static inline const char *get_tree_code_name(enum tree_code code)
449*4882a593Smuzhiyun {
450*4882a593Smuzhiyun gcc_assert(code < MAX_TREE_CODES);
451*4882a593Smuzhiyun return tree_code_name[code];
452*4882a593Smuzhiyun }
453*4882a593Smuzhiyun
454*4882a593Smuzhiyun #define ipa_remove_stmt_references(cnode, stmt)
455*4882a593Smuzhiyun
456*4882a593Smuzhiyun typedef union gimple_statement_d gasm;
457*4882a593Smuzhiyun typedef union gimple_statement_d gassign;
458*4882a593Smuzhiyun typedef union gimple_statement_d gcall;
459*4882a593Smuzhiyun typedef union gimple_statement_d gcond;
460*4882a593Smuzhiyun typedef union gimple_statement_d gdebug;
461*4882a593Smuzhiyun typedef union gimple_statement_d ggoto;
462*4882a593Smuzhiyun typedef union gimple_statement_d gphi;
463*4882a593Smuzhiyun typedef union gimple_statement_d greturn;
464*4882a593Smuzhiyun
as_a_gasm(gimple stmt)465*4882a593Smuzhiyun static inline gasm *as_a_gasm(gimple stmt)
466*4882a593Smuzhiyun {
467*4882a593Smuzhiyun return stmt;
468*4882a593Smuzhiyun }
469*4882a593Smuzhiyun
as_a_const_gasm(const_gimple stmt)470*4882a593Smuzhiyun static inline const gasm *as_a_const_gasm(const_gimple stmt)
471*4882a593Smuzhiyun {
472*4882a593Smuzhiyun return stmt;
473*4882a593Smuzhiyun }
474*4882a593Smuzhiyun
as_a_gassign(gimple stmt)475*4882a593Smuzhiyun static inline gassign *as_a_gassign(gimple stmt)
476*4882a593Smuzhiyun {
477*4882a593Smuzhiyun return stmt;
478*4882a593Smuzhiyun }
479*4882a593Smuzhiyun
as_a_const_gassign(const_gimple stmt)480*4882a593Smuzhiyun static inline const gassign *as_a_const_gassign(const_gimple stmt)
481*4882a593Smuzhiyun {
482*4882a593Smuzhiyun return stmt;
483*4882a593Smuzhiyun }
484*4882a593Smuzhiyun
as_a_gcall(gimple stmt)485*4882a593Smuzhiyun static inline gcall *as_a_gcall(gimple stmt)
486*4882a593Smuzhiyun {
487*4882a593Smuzhiyun return stmt;
488*4882a593Smuzhiyun }
489*4882a593Smuzhiyun
as_a_const_gcall(const_gimple stmt)490*4882a593Smuzhiyun static inline const gcall *as_a_const_gcall(const_gimple stmt)
491*4882a593Smuzhiyun {
492*4882a593Smuzhiyun return stmt;
493*4882a593Smuzhiyun }
494*4882a593Smuzhiyun
as_a_gcond(gimple stmt)495*4882a593Smuzhiyun static inline gcond *as_a_gcond(gimple stmt)
496*4882a593Smuzhiyun {
497*4882a593Smuzhiyun return stmt;
498*4882a593Smuzhiyun }
499*4882a593Smuzhiyun
as_a_const_gcond(const_gimple stmt)500*4882a593Smuzhiyun static inline const gcond *as_a_const_gcond(const_gimple stmt)
501*4882a593Smuzhiyun {
502*4882a593Smuzhiyun return stmt;
503*4882a593Smuzhiyun }
504*4882a593Smuzhiyun
as_a_gdebug(gimple stmt)505*4882a593Smuzhiyun static inline gdebug *as_a_gdebug(gimple stmt)
506*4882a593Smuzhiyun {
507*4882a593Smuzhiyun return stmt;
508*4882a593Smuzhiyun }
509*4882a593Smuzhiyun
as_a_const_gdebug(const_gimple stmt)510*4882a593Smuzhiyun static inline const gdebug *as_a_const_gdebug(const_gimple stmt)
511*4882a593Smuzhiyun {
512*4882a593Smuzhiyun return stmt;
513*4882a593Smuzhiyun }
514*4882a593Smuzhiyun
as_a_ggoto(gimple stmt)515*4882a593Smuzhiyun static inline ggoto *as_a_ggoto(gimple stmt)
516*4882a593Smuzhiyun {
517*4882a593Smuzhiyun return stmt;
518*4882a593Smuzhiyun }
519*4882a593Smuzhiyun
as_a_const_ggoto(const_gimple stmt)520*4882a593Smuzhiyun static inline const ggoto *as_a_const_ggoto(const_gimple stmt)
521*4882a593Smuzhiyun {
522*4882a593Smuzhiyun return stmt;
523*4882a593Smuzhiyun }
524*4882a593Smuzhiyun
as_a_gphi(gimple stmt)525*4882a593Smuzhiyun static inline gphi *as_a_gphi(gimple stmt)
526*4882a593Smuzhiyun {
527*4882a593Smuzhiyun return stmt;
528*4882a593Smuzhiyun }
529*4882a593Smuzhiyun
as_a_const_gphi(const_gimple stmt)530*4882a593Smuzhiyun static inline const gphi *as_a_const_gphi(const_gimple stmt)
531*4882a593Smuzhiyun {
532*4882a593Smuzhiyun return stmt;
533*4882a593Smuzhiyun }
534*4882a593Smuzhiyun
as_a_greturn(gimple stmt)535*4882a593Smuzhiyun static inline greturn *as_a_greturn(gimple stmt)
536*4882a593Smuzhiyun {
537*4882a593Smuzhiyun return stmt;
538*4882a593Smuzhiyun }
539*4882a593Smuzhiyun
as_a_const_greturn(const_gimple stmt)540*4882a593Smuzhiyun static inline const greturn *as_a_const_greturn(const_gimple stmt)
541*4882a593Smuzhiyun {
542*4882a593Smuzhiyun return stmt;
543*4882a593Smuzhiyun }
544*4882a593Smuzhiyun #endif
545*4882a593Smuzhiyun
546*4882a593Smuzhiyun #if BUILDING_GCC_VERSION == 4008
547*4882a593Smuzhiyun #define NODE_SYMBOL(node) (&(node)->symbol)
548*4882a593Smuzhiyun #define NODE_DECL(node) (node)->symbol.decl
549*4882a593Smuzhiyun #endif
550*4882a593Smuzhiyun
551*4882a593Smuzhiyun #if BUILDING_GCC_VERSION >= 4008
552*4882a593Smuzhiyun #define add_referenced_var(var)
553*4882a593Smuzhiyun #define mark_sym_for_renaming(var)
554*4882a593Smuzhiyun #define varpool_mark_needed_node(node)
555*4882a593Smuzhiyun #define create_var_ann(var)
556*4882a593Smuzhiyun #define TODO_dump_func 0
557*4882a593Smuzhiyun #define TODO_dump_cgraph 0
558*4882a593Smuzhiyun #endif
559*4882a593Smuzhiyun
560*4882a593Smuzhiyun #if BUILDING_GCC_VERSION <= 4009
561*4882a593Smuzhiyun #define TODO_verify_il 0
562*4882a593Smuzhiyun #define AVAIL_INTERPOSABLE AVAIL_OVERWRITABLE
563*4882a593Smuzhiyun
564*4882a593Smuzhiyun #define section_name_prefix LTO_SECTION_NAME_PREFIX
565*4882a593Smuzhiyun #define fatal_error(loc, gmsgid, ...) fatal_error((gmsgid), __VA_ARGS__)
566*4882a593Smuzhiyun
567*4882a593Smuzhiyun rtx emit_move_insn(rtx x, rtx y);
568*4882a593Smuzhiyun
569*4882a593Smuzhiyun typedef struct rtx_def rtx_insn;
570*4882a593Smuzhiyun
get_decl_section_name(const_tree decl)571*4882a593Smuzhiyun static inline const char *get_decl_section_name(const_tree decl)
572*4882a593Smuzhiyun {
573*4882a593Smuzhiyun if (DECL_SECTION_NAME(decl) == NULL_TREE)
574*4882a593Smuzhiyun return NULL;
575*4882a593Smuzhiyun
576*4882a593Smuzhiyun return TREE_STRING_POINTER(DECL_SECTION_NAME(decl));
577*4882a593Smuzhiyun }
578*4882a593Smuzhiyun
set_decl_section_name(tree node,const char * value)579*4882a593Smuzhiyun static inline void set_decl_section_name(tree node, const char *value)
580*4882a593Smuzhiyun {
581*4882a593Smuzhiyun if (value)
582*4882a593Smuzhiyun DECL_SECTION_NAME(node) = build_string(strlen(value) + 1, value);
583*4882a593Smuzhiyun else
584*4882a593Smuzhiyun DECL_SECTION_NAME(node) = NULL;
585*4882a593Smuzhiyun }
586*4882a593Smuzhiyun #endif
587*4882a593Smuzhiyun
588*4882a593Smuzhiyun #if BUILDING_GCC_VERSION == 4009
589*4882a593Smuzhiyun typedef struct gimple_statement_asm gasm;
590*4882a593Smuzhiyun typedef struct gimple_statement_base gassign;
591*4882a593Smuzhiyun typedef struct gimple_statement_call gcall;
592*4882a593Smuzhiyun typedef struct gimple_statement_base gcond;
593*4882a593Smuzhiyun typedef struct gimple_statement_base gdebug;
594*4882a593Smuzhiyun typedef struct gimple_statement_base ggoto;
595*4882a593Smuzhiyun typedef struct gimple_statement_phi gphi;
596*4882a593Smuzhiyun typedef struct gimple_statement_base greturn;
597*4882a593Smuzhiyun
as_a_gasm(gimple stmt)598*4882a593Smuzhiyun static inline gasm *as_a_gasm(gimple stmt)
599*4882a593Smuzhiyun {
600*4882a593Smuzhiyun return as_a<gasm>(stmt);
601*4882a593Smuzhiyun }
602*4882a593Smuzhiyun
as_a_const_gasm(const_gimple stmt)603*4882a593Smuzhiyun static inline const gasm *as_a_const_gasm(const_gimple stmt)
604*4882a593Smuzhiyun {
605*4882a593Smuzhiyun return as_a<const gasm>(stmt);
606*4882a593Smuzhiyun }
607*4882a593Smuzhiyun
as_a_gassign(gimple stmt)608*4882a593Smuzhiyun static inline gassign *as_a_gassign(gimple stmt)
609*4882a593Smuzhiyun {
610*4882a593Smuzhiyun return stmt;
611*4882a593Smuzhiyun }
612*4882a593Smuzhiyun
as_a_const_gassign(const_gimple stmt)613*4882a593Smuzhiyun static inline const gassign *as_a_const_gassign(const_gimple stmt)
614*4882a593Smuzhiyun {
615*4882a593Smuzhiyun return stmt;
616*4882a593Smuzhiyun }
617*4882a593Smuzhiyun
as_a_gcall(gimple stmt)618*4882a593Smuzhiyun static inline gcall *as_a_gcall(gimple stmt)
619*4882a593Smuzhiyun {
620*4882a593Smuzhiyun return as_a<gcall>(stmt);
621*4882a593Smuzhiyun }
622*4882a593Smuzhiyun
as_a_const_gcall(const_gimple stmt)623*4882a593Smuzhiyun static inline const gcall *as_a_const_gcall(const_gimple stmt)
624*4882a593Smuzhiyun {
625*4882a593Smuzhiyun return as_a<const gcall>(stmt);
626*4882a593Smuzhiyun }
627*4882a593Smuzhiyun
as_a_gcond(gimple stmt)628*4882a593Smuzhiyun static inline gcond *as_a_gcond(gimple stmt)
629*4882a593Smuzhiyun {
630*4882a593Smuzhiyun return stmt;
631*4882a593Smuzhiyun }
632*4882a593Smuzhiyun
as_a_const_gcond(const_gimple stmt)633*4882a593Smuzhiyun static inline const gcond *as_a_const_gcond(const_gimple stmt)
634*4882a593Smuzhiyun {
635*4882a593Smuzhiyun return stmt;
636*4882a593Smuzhiyun }
637*4882a593Smuzhiyun
as_a_gdebug(gimple stmt)638*4882a593Smuzhiyun static inline gdebug *as_a_gdebug(gimple stmt)
639*4882a593Smuzhiyun {
640*4882a593Smuzhiyun return stmt;
641*4882a593Smuzhiyun }
642*4882a593Smuzhiyun
as_a_const_gdebug(const_gimple stmt)643*4882a593Smuzhiyun static inline const gdebug *as_a_const_gdebug(const_gimple stmt)
644*4882a593Smuzhiyun {
645*4882a593Smuzhiyun return stmt;
646*4882a593Smuzhiyun }
647*4882a593Smuzhiyun
as_a_ggoto(gimple stmt)648*4882a593Smuzhiyun static inline ggoto *as_a_ggoto(gimple stmt)
649*4882a593Smuzhiyun {
650*4882a593Smuzhiyun return stmt;
651*4882a593Smuzhiyun }
652*4882a593Smuzhiyun
as_a_const_ggoto(const_gimple stmt)653*4882a593Smuzhiyun static inline const ggoto *as_a_const_ggoto(const_gimple stmt)
654*4882a593Smuzhiyun {
655*4882a593Smuzhiyun return stmt;
656*4882a593Smuzhiyun }
657*4882a593Smuzhiyun
as_a_gphi(gimple stmt)658*4882a593Smuzhiyun static inline gphi *as_a_gphi(gimple stmt)
659*4882a593Smuzhiyun {
660*4882a593Smuzhiyun return as_a<gphi>(stmt);
661*4882a593Smuzhiyun }
662*4882a593Smuzhiyun
as_a_const_gphi(const_gimple stmt)663*4882a593Smuzhiyun static inline const gphi *as_a_const_gphi(const_gimple stmt)
664*4882a593Smuzhiyun {
665*4882a593Smuzhiyun return as_a<const gphi>(stmt);
666*4882a593Smuzhiyun }
667*4882a593Smuzhiyun
as_a_greturn(gimple stmt)668*4882a593Smuzhiyun static inline greturn *as_a_greturn(gimple stmt)
669*4882a593Smuzhiyun {
670*4882a593Smuzhiyun return stmt;
671*4882a593Smuzhiyun }
672*4882a593Smuzhiyun
as_a_const_greturn(const_gimple stmt)673*4882a593Smuzhiyun static inline const greturn *as_a_const_greturn(const_gimple stmt)
674*4882a593Smuzhiyun {
675*4882a593Smuzhiyun return stmt;
676*4882a593Smuzhiyun }
677*4882a593Smuzhiyun #endif
678*4882a593Smuzhiyun
679*4882a593Smuzhiyun #if BUILDING_GCC_VERSION >= 4009
680*4882a593Smuzhiyun #define TODO_ggc_collect 0
681*4882a593Smuzhiyun #define NODE_SYMBOL(node) (node)
682*4882a593Smuzhiyun #define NODE_DECL(node) (node)->decl
683*4882a593Smuzhiyun #define cgraph_node_name(node) (node)->name()
684*4882a593Smuzhiyun #define NODE_IMPLICIT_ALIAS(node) (node)->cpp_implicit_alias
685*4882a593Smuzhiyun
get_pass_for_id(int id)686*4882a593Smuzhiyun static inline opt_pass *get_pass_for_id(int id)
687*4882a593Smuzhiyun {
688*4882a593Smuzhiyun return g->get_passes()->get_pass_for_id(id);
689*4882a593Smuzhiyun }
690*4882a593Smuzhiyun #endif
691*4882a593Smuzhiyun
692*4882a593Smuzhiyun #if BUILDING_GCC_VERSION >= 5000 && BUILDING_GCC_VERSION < 6000
693*4882a593Smuzhiyun /* gimple related */
694*4882a593Smuzhiyun template <>
695*4882a593Smuzhiyun template <>
test(const_gimple gs)696*4882a593Smuzhiyun inline bool is_a_helper<const gassign *>::test(const_gimple gs)
697*4882a593Smuzhiyun {
698*4882a593Smuzhiyun return gs->code == GIMPLE_ASSIGN;
699*4882a593Smuzhiyun }
700*4882a593Smuzhiyun #endif
701*4882a593Smuzhiyun
702*4882a593Smuzhiyun #if BUILDING_GCC_VERSION >= 5000
703*4882a593Smuzhiyun #define TODO_verify_ssa TODO_verify_il
704*4882a593Smuzhiyun #define TODO_verify_flow TODO_verify_il
705*4882a593Smuzhiyun #define TODO_verify_stmts TODO_verify_il
706*4882a593Smuzhiyun #define TODO_verify_rtl_sharing TODO_verify_il
707*4882a593Smuzhiyun
708*4882a593Smuzhiyun #define INSN_DELETED_P(insn) (insn)->deleted()
709*4882a593Smuzhiyun
get_decl_section_name(const_tree decl)710*4882a593Smuzhiyun static inline const char *get_decl_section_name(const_tree decl)
711*4882a593Smuzhiyun {
712*4882a593Smuzhiyun return DECL_SECTION_NAME(decl);
713*4882a593Smuzhiyun }
714*4882a593Smuzhiyun
715*4882a593Smuzhiyun /* symtab/cgraph related */
716*4882a593Smuzhiyun #define debug_cgraph_node(node) (node)->debug()
717*4882a593Smuzhiyun #define cgraph_get_node(decl) cgraph_node::get(decl)
718*4882a593Smuzhiyun #define cgraph_get_create_node(decl) cgraph_node::get_create(decl)
719*4882a593Smuzhiyun #define cgraph_create_node(decl) cgraph_node::create(decl)
720*4882a593Smuzhiyun #define cgraph_n_nodes symtab->cgraph_count
721*4882a593Smuzhiyun #define cgraph_max_uid symtab->cgraph_max_uid
722*4882a593Smuzhiyun #define varpool_get_node(decl) varpool_node::get(decl)
723*4882a593Smuzhiyun #define dump_varpool_node(file, node) (node)->dump(file)
724*4882a593Smuzhiyun
725*4882a593Smuzhiyun #if BUILDING_GCC_VERSION >= 8000
726*4882a593Smuzhiyun #define cgraph_create_edge(caller, callee, call_stmt, count, freq) \
727*4882a593Smuzhiyun (caller)->create_edge((callee), (call_stmt), (count))
728*4882a593Smuzhiyun
729*4882a593Smuzhiyun #define cgraph_create_edge_including_clones(caller, callee, \
730*4882a593Smuzhiyun old_call_stmt, call_stmt, count, freq, reason) \
731*4882a593Smuzhiyun (caller)->create_edge_including_clones((callee), \
732*4882a593Smuzhiyun (old_call_stmt), (call_stmt), (count), (reason))
733*4882a593Smuzhiyun #else
734*4882a593Smuzhiyun #define cgraph_create_edge(caller, callee, call_stmt, count, freq) \
735*4882a593Smuzhiyun (caller)->create_edge((callee), (call_stmt), (count), (freq))
736*4882a593Smuzhiyun
737*4882a593Smuzhiyun #define cgraph_create_edge_including_clones(caller, callee, \
738*4882a593Smuzhiyun old_call_stmt, call_stmt, count, freq, reason) \
739*4882a593Smuzhiyun (caller)->create_edge_including_clones((callee), \
740*4882a593Smuzhiyun (old_call_stmt), (call_stmt), (count), (freq), (reason))
741*4882a593Smuzhiyun #endif
742*4882a593Smuzhiyun
743*4882a593Smuzhiyun typedef struct cgraph_node *cgraph_node_ptr;
744*4882a593Smuzhiyun typedef struct cgraph_edge *cgraph_edge_p;
745*4882a593Smuzhiyun typedef struct varpool_node *varpool_node_ptr;
746*4882a593Smuzhiyun
change_decl_assembler_name(tree decl,tree name)747*4882a593Smuzhiyun static inline void change_decl_assembler_name(tree decl, tree name)
748*4882a593Smuzhiyun {
749*4882a593Smuzhiyun symtab->change_decl_assembler_name(decl, name);
750*4882a593Smuzhiyun }
751*4882a593Smuzhiyun
varpool_finalize_decl(tree decl)752*4882a593Smuzhiyun static inline void varpool_finalize_decl(tree decl)
753*4882a593Smuzhiyun {
754*4882a593Smuzhiyun varpool_node::finalize_decl(decl);
755*4882a593Smuzhiyun }
756*4882a593Smuzhiyun
varpool_add_new_variable(tree decl)757*4882a593Smuzhiyun static inline void varpool_add_new_variable(tree decl)
758*4882a593Smuzhiyun {
759*4882a593Smuzhiyun varpool_node::add(decl);
760*4882a593Smuzhiyun }
761*4882a593Smuzhiyun
rebuild_cgraph_edges(void)762*4882a593Smuzhiyun static inline unsigned int rebuild_cgraph_edges(void)
763*4882a593Smuzhiyun {
764*4882a593Smuzhiyun return cgraph_edge::rebuild_edges();
765*4882a593Smuzhiyun }
766*4882a593Smuzhiyun
cgraph_function_node(cgraph_node_ptr node,enum availability * availability)767*4882a593Smuzhiyun static inline cgraph_node_ptr cgraph_function_node(cgraph_node_ptr node, enum availability *availability)
768*4882a593Smuzhiyun {
769*4882a593Smuzhiyun return node->function_symbol(availability);
770*4882a593Smuzhiyun }
771*4882a593Smuzhiyun
772*4882a593Smuzhiyun static inline cgraph_node_ptr cgraph_function_or_thunk_node(cgraph_node_ptr node, enum availability *availability = NULL)
773*4882a593Smuzhiyun {
774*4882a593Smuzhiyun return node->ultimate_alias_target(availability);
775*4882a593Smuzhiyun }
776*4882a593Smuzhiyun
cgraph_only_called_directly_p(cgraph_node_ptr node)777*4882a593Smuzhiyun static inline bool cgraph_only_called_directly_p(cgraph_node_ptr node)
778*4882a593Smuzhiyun {
779*4882a593Smuzhiyun return node->only_called_directly_p();
780*4882a593Smuzhiyun }
781*4882a593Smuzhiyun
cgraph_function_body_availability(cgraph_node_ptr node)782*4882a593Smuzhiyun static inline enum availability cgraph_function_body_availability(cgraph_node_ptr node)
783*4882a593Smuzhiyun {
784*4882a593Smuzhiyun return node->get_availability();
785*4882a593Smuzhiyun }
786*4882a593Smuzhiyun
cgraph_alias_target(cgraph_node_ptr node)787*4882a593Smuzhiyun static inline cgraph_node_ptr cgraph_alias_target(cgraph_node_ptr node)
788*4882a593Smuzhiyun {
789*4882a593Smuzhiyun return node->get_alias_target();
790*4882a593Smuzhiyun }
791*4882a593Smuzhiyun
cgraph_for_node_and_aliases(cgraph_node_ptr node,bool (* callback)(cgraph_node_ptr,void *),void * data,bool include_overwritable)792*4882a593Smuzhiyun static inline bool cgraph_for_node_and_aliases(cgraph_node_ptr node, bool (*callback)(cgraph_node_ptr, void *), void *data, bool include_overwritable)
793*4882a593Smuzhiyun {
794*4882a593Smuzhiyun return node->call_for_symbol_thunks_and_aliases(callback, data, include_overwritable);
795*4882a593Smuzhiyun }
796*4882a593Smuzhiyun
cgraph_add_function_insertion_hook(cgraph_node_hook hook,void * data)797*4882a593Smuzhiyun static inline struct cgraph_node_hook_list *cgraph_add_function_insertion_hook(cgraph_node_hook hook, void *data)
798*4882a593Smuzhiyun {
799*4882a593Smuzhiyun return symtab->add_cgraph_insertion_hook(hook, data);
800*4882a593Smuzhiyun }
801*4882a593Smuzhiyun
cgraph_remove_function_insertion_hook(struct cgraph_node_hook_list * entry)802*4882a593Smuzhiyun static inline void cgraph_remove_function_insertion_hook(struct cgraph_node_hook_list *entry)
803*4882a593Smuzhiyun {
804*4882a593Smuzhiyun symtab->remove_cgraph_insertion_hook(entry);
805*4882a593Smuzhiyun }
806*4882a593Smuzhiyun
cgraph_add_node_removal_hook(cgraph_node_hook hook,void * data)807*4882a593Smuzhiyun static inline struct cgraph_node_hook_list *cgraph_add_node_removal_hook(cgraph_node_hook hook, void *data)
808*4882a593Smuzhiyun {
809*4882a593Smuzhiyun return symtab->add_cgraph_removal_hook(hook, data);
810*4882a593Smuzhiyun }
811*4882a593Smuzhiyun
cgraph_remove_node_removal_hook(struct cgraph_node_hook_list * entry)812*4882a593Smuzhiyun static inline void cgraph_remove_node_removal_hook(struct cgraph_node_hook_list *entry)
813*4882a593Smuzhiyun {
814*4882a593Smuzhiyun symtab->remove_cgraph_removal_hook(entry);
815*4882a593Smuzhiyun }
816*4882a593Smuzhiyun
cgraph_add_node_duplication_hook(cgraph_2node_hook hook,void * data)817*4882a593Smuzhiyun static inline struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook(cgraph_2node_hook hook, void *data)
818*4882a593Smuzhiyun {
819*4882a593Smuzhiyun return symtab->add_cgraph_duplication_hook(hook, data);
820*4882a593Smuzhiyun }
821*4882a593Smuzhiyun
cgraph_remove_node_duplication_hook(struct cgraph_2node_hook_list * entry)822*4882a593Smuzhiyun static inline void cgraph_remove_node_duplication_hook(struct cgraph_2node_hook_list *entry)
823*4882a593Smuzhiyun {
824*4882a593Smuzhiyun symtab->remove_cgraph_duplication_hook(entry);
825*4882a593Smuzhiyun }
826*4882a593Smuzhiyun
cgraph_call_node_duplication_hooks(cgraph_node_ptr node,cgraph_node_ptr node2)827*4882a593Smuzhiyun static inline void cgraph_call_node_duplication_hooks(cgraph_node_ptr node, cgraph_node_ptr node2)
828*4882a593Smuzhiyun {
829*4882a593Smuzhiyun symtab->call_cgraph_duplication_hooks(node, node2);
830*4882a593Smuzhiyun }
831*4882a593Smuzhiyun
cgraph_call_edge_duplication_hooks(cgraph_edge * cs1,cgraph_edge * cs2)832*4882a593Smuzhiyun static inline void cgraph_call_edge_duplication_hooks(cgraph_edge *cs1, cgraph_edge *cs2)
833*4882a593Smuzhiyun {
834*4882a593Smuzhiyun symtab->call_edge_duplication_hooks(cs1, cs2);
835*4882a593Smuzhiyun }
836*4882a593Smuzhiyun
837*4882a593Smuzhiyun #if BUILDING_GCC_VERSION >= 6000
838*4882a593Smuzhiyun typedef gimple *gimple_ptr;
839*4882a593Smuzhiyun typedef const gimple *const_gimple_ptr;
840*4882a593Smuzhiyun #define gimple gimple_ptr
841*4882a593Smuzhiyun #define const_gimple const_gimple_ptr
842*4882a593Smuzhiyun #undef CONST_CAST_GIMPLE
843*4882a593Smuzhiyun #define CONST_CAST_GIMPLE(X) CONST_CAST(gimple, (X))
844*4882a593Smuzhiyun #endif
845*4882a593Smuzhiyun
846*4882a593Smuzhiyun /* gimple related */
gimple_build_assign_with_ops(enum tree_code subcode,tree lhs,tree op1,tree op2 MEM_STAT_DECL)847*4882a593Smuzhiyun static inline gimple gimple_build_assign_with_ops(enum tree_code subcode, tree lhs, tree op1, tree op2 MEM_STAT_DECL)
848*4882a593Smuzhiyun {
849*4882a593Smuzhiyun return gimple_build_assign(lhs, subcode, op1, op2 PASS_MEM_STAT);
850*4882a593Smuzhiyun }
851*4882a593Smuzhiyun
852*4882a593Smuzhiyun #if BUILDING_GCC_VERSION < 10000
853*4882a593Smuzhiyun template <>
854*4882a593Smuzhiyun template <>
test(const_gimple gs)855*4882a593Smuzhiyun inline bool is_a_helper<const ggoto *>::test(const_gimple gs)
856*4882a593Smuzhiyun {
857*4882a593Smuzhiyun return gs->code == GIMPLE_GOTO;
858*4882a593Smuzhiyun }
859*4882a593Smuzhiyun
860*4882a593Smuzhiyun template <>
861*4882a593Smuzhiyun template <>
test(const_gimple gs)862*4882a593Smuzhiyun inline bool is_a_helper<const greturn *>::test(const_gimple gs)
863*4882a593Smuzhiyun {
864*4882a593Smuzhiyun return gs->code == GIMPLE_RETURN;
865*4882a593Smuzhiyun }
866*4882a593Smuzhiyun #endif
867*4882a593Smuzhiyun
as_a_gasm(gimple stmt)868*4882a593Smuzhiyun static inline gasm *as_a_gasm(gimple stmt)
869*4882a593Smuzhiyun {
870*4882a593Smuzhiyun return as_a<gasm *>(stmt);
871*4882a593Smuzhiyun }
872*4882a593Smuzhiyun
as_a_const_gasm(const_gimple stmt)873*4882a593Smuzhiyun static inline const gasm *as_a_const_gasm(const_gimple stmt)
874*4882a593Smuzhiyun {
875*4882a593Smuzhiyun return as_a<const gasm *>(stmt);
876*4882a593Smuzhiyun }
877*4882a593Smuzhiyun
as_a_gassign(gimple stmt)878*4882a593Smuzhiyun static inline gassign *as_a_gassign(gimple stmt)
879*4882a593Smuzhiyun {
880*4882a593Smuzhiyun return as_a<gassign *>(stmt);
881*4882a593Smuzhiyun }
882*4882a593Smuzhiyun
as_a_const_gassign(const_gimple stmt)883*4882a593Smuzhiyun static inline const gassign *as_a_const_gassign(const_gimple stmt)
884*4882a593Smuzhiyun {
885*4882a593Smuzhiyun return as_a<const gassign *>(stmt);
886*4882a593Smuzhiyun }
887*4882a593Smuzhiyun
as_a_gcall(gimple stmt)888*4882a593Smuzhiyun static inline gcall *as_a_gcall(gimple stmt)
889*4882a593Smuzhiyun {
890*4882a593Smuzhiyun return as_a<gcall *>(stmt);
891*4882a593Smuzhiyun }
892*4882a593Smuzhiyun
as_a_const_gcall(const_gimple stmt)893*4882a593Smuzhiyun static inline const gcall *as_a_const_gcall(const_gimple stmt)
894*4882a593Smuzhiyun {
895*4882a593Smuzhiyun return as_a<const gcall *>(stmt);
896*4882a593Smuzhiyun }
897*4882a593Smuzhiyun
as_a_ggoto(gimple stmt)898*4882a593Smuzhiyun static inline ggoto *as_a_ggoto(gimple stmt)
899*4882a593Smuzhiyun {
900*4882a593Smuzhiyun return as_a<ggoto *>(stmt);
901*4882a593Smuzhiyun }
902*4882a593Smuzhiyun
as_a_const_ggoto(const_gimple stmt)903*4882a593Smuzhiyun static inline const ggoto *as_a_const_ggoto(const_gimple stmt)
904*4882a593Smuzhiyun {
905*4882a593Smuzhiyun return as_a<const ggoto *>(stmt);
906*4882a593Smuzhiyun }
907*4882a593Smuzhiyun
as_a_gphi(gimple stmt)908*4882a593Smuzhiyun static inline gphi *as_a_gphi(gimple stmt)
909*4882a593Smuzhiyun {
910*4882a593Smuzhiyun return as_a<gphi *>(stmt);
911*4882a593Smuzhiyun }
912*4882a593Smuzhiyun
as_a_const_gphi(const_gimple stmt)913*4882a593Smuzhiyun static inline const gphi *as_a_const_gphi(const_gimple stmt)
914*4882a593Smuzhiyun {
915*4882a593Smuzhiyun return as_a<const gphi *>(stmt);
916*4882a593Smuzhiyun }
917*4882a593Smuzhiyun
as_a_greturn(gimple stmt)918*4882a593Smuzhiyun static inline greturn *as_a_greturn(gimple stmt)
919*4882a593Smuzhiyun {
920*4882a593Smuzhiyun return as_a<greturn *>(stmt);
921*4882a593Smuzhiyun }
922*4882a593Smuzhiyun
as_a_const_greturn(const_gimple stmt)923*4882a593Smuzhiyun static inline const greturn *as_a_const_greturn(const_gimple stmt)
924*4882a593Smuzhiyun {
925*4882a593Smuzhiyun return as_a<const greturn *>(stmt);
926*4882a593Smuzhiyun }
927*4882a593Smuzhiyun
928*4882a593Smuzhiyun /* IPA/LTO related */
929*4882a593Smuzhiyun #define ipa_ref_list_referring_iterate(L, I, P) \
930*4882a593Smuzhiyun (L)->referring.iterate((I), &(P))
931*4882a593Smuzhiyun #define ipa_ref_list_reference_iterate(L, I, P) \
932*4882a593Smuzhiyun (L)->reference.iterate((I), &(P))
933*4882a593Smuzhiyun
ipa_ref_referring_node(struct ipa_ref * ref)934*4882a593Smuzhiyun static inline cgraph_node_ptr ipa_ref_referring_node(struct ipa_ref *ref)
935*4882a593Smuzhiyun {
936*4882a593Smuzhiyun return dyn_cast<cgraph_node_ptr>(ref->referring);
937*4882a593Smuzhiyun }
938*4882a593Smuzhiyun
ipa_remove_stmt_references(symtab_node * referring_node,gimple stmt)939*4882a593Smuzhiyun static inline void ipa_remove_stmt_references(symtab_node *referring_node, gimple stmt)
940*4882a593Smuzhiyun {
941*4882a593Smuzhiyun referring_node->remove_stmt_references(stmt);
942*4882a593Smuzhiyun }
943*4882a593Smuzhiyun #endif
944*4882a593Smuzhiyun
945*4882a593Smuzhiyun #if BUILDING_GCC_VERSION < 6000
946*4882a593Smuzhiyun #define get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep, keep_aligning) \
947*4882a593Smuzhiyun get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, pvolatilep, keep_aligning)
948*4882a593Smuzhiyun #define gen_rtx_set(ARG0, ARG1) gen_rtx_SET(VOIDmode, (ARG0), (ARG1))
949*4882a593Smuzhiyun #endif
950*4882a593Smuzhiyun
951*4882a593Smuzhiyun #if BUILDING_GCC_VERSION >= 6000
952*4882a593Smuzhiyun #define gen_rtx_set(ARG0, ARG1) gen_rtx_SET((ARG0), (ARG1))
953*4882a593Smuzhiyun #endif
954*4882a593Smuzhiyun
955*4882a593Smuzhiyun #ifdef __cplusplus
debug_tree(const_tree t)956*4882a593Smuzhiyun static inline void debug_tree(const_tree t)
957*4882a593Smuzhiyun {
958*4882a593Smuzhiyun debug_tree(CONST_CAST_TREE(t));
959*4882a593Smuzhiyun }
960*4882a593Smuzhiyun
debug_gimple_stmt(const_gimple s)961*4882a593Smuzhiyun static inline void debug_gimple_stmt(const_gimple s)
962*4882a593Smuzhiyun {
963*4882a593Smuzhiyun debug_gimple_stmt(CONST_CAST_GIMPLE(s));
964*4882a593Smuzhiyun }
965*4882a593Smuzhiyun #else
966*4882a593Smuzhiyun #define debug_tree(t) debug_tree(CONST_CAST_TREE(t))
967*4882a593Smuzhiyun #define debug_gimple_stmt(s) debug_gimple_stmt(CONST_CAST_GIMPLE(s))
968*4882a593Smuzhiyun #endif
969*4882a593Smuzhiyun
970*4882a593Smuzhiyun #if BUILDING_GCC_VERSION >= 7000
971*4882a593Smuzhiyun #define get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep, keep_aligning) \
972*4882a593Smuzhiyun get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep)
973*4882a593Smuzhiyun #endif
974*4882a593Smuzhiyun
975*4882a593Smuzhiyun #if BUILDING_GCC_VERSION < 7000
976*4882a593Smuzhiyun #define SET_DECL_ALIGN(decl, align) DECL_ALIGN(decl) = (align)
977*4882a593Smuzhiyun #define SET_DECL_MODE(decl, mode) DECL_MODE(decl) = (mode)
978*4882a593Smuzhiyun #endif
979*4882a593Smuzhiyun
980*4882a593Smuzhiyun #endif
981