1*e4b17023SJohn Marino /* Default language-specific hooks.
2*e4b17023SJohn Marino Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3*e4b17023SJohn Marino Free Software Foundation, Inc.
4*e4b17023SJohn Marino Contributed by Alexandre Oliva <aoliva@redhat.com>
5*e4b17023SJohn Marino
6*e4b17023SJohn Marino This file is part of GCC.
7*e4b17023SJohn Marino
8*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify
9*e4b17023SJohn Marino it under the terms of the GNU General Public License as published by
10*e4b17023SJohn Marino the Free Software Foundation; either version 3, or (at your option)
11*e4b17023SJohn Marino any later version.
12*e4b17023SJohn Marino
13*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful,
14*e4b17023SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of
15*e4b17023SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16*e4b17023SJohn Marino GNU General Public License for more details.
17*e4b17023SJohn Marino
18*e4b17023SJohn Marino You should have received a copy of the GNU General Public License
19*e4b17023SJohn Marino along with GCC; see the file COPYING3. If not see
20*e4b17023SJohn Marino <http://www.gnu.org/licenses/>. */
21*e4b17023SJohn Marino
22*e4b17023SJohn Marino #include "config.h"
23*e4b17023SJohn Marino #include "system.h"
24*e4b17023SJohn Marino #include "coretypes.h"
25*e4b17023SJohn Marino #include "intl.h"
26*e4b17023SJohn Marino #include "tm.h"
27*e4b17023SJohn Marino #include "toplev.h"
28*e4b17023SJohn Marino #include "tree.h"
29*e4b17023SJohn Marino #include "tree-inline.h"
30*e4b17023SJohn Marino #include "gimple.h"
31*e4b17023SJohn Marino #include "rtl.h"
32*e4b17023SJohn Marino #include "insn-config.h"
33*e4b17023SJohn Marino #include "integrate.h"
34*e4b17023SJohn Marino #include "flags.h"
35*e4b17023SJohn Marino #include "langhooks.h"
36*e4b17023SJohn Marino #include "target.h"
37*e4b17023SJohn Marino #include "langhooks-def.h"
38*e4b17023SJohn Marino #include "ggc.h"
39*e4b17023SJohn Marino #include "diagnostic.h"
40*e4b17023SJohn Marino #include "tree-diagnostic.h"
41*e4b17023SJohn Marino #include "cgraph.h"
42*e4b17023SJohn Marino #include "output.h"
43*e4b17023SJohn Marino
44*e4b17023SJohn Marino /* Do nothing; in many cases the default hook. */
45*e4b17023SJohn Marino
46*e4b17023SJohn Marino void
lhd_do_nothing(void)47*e4b17023SJohn Marino lhd_do_nothing (void)
48*e4b17023SJohn Marino {
49*e4b17023SJohn Marino }
50*e4b17023SJohn Marino
51*e4b17023SJohn Marino /* Do nothing (tree). */
52*e4b17023SJohn Marino
53*e4b17023SJohn Marino void
lhd_do_nothing_t(tree ARG_UNUSED (t))54*e4b17023SJohn Marino lhd_do_nothing_t (tree ARG_UNUSED (t))
55*e4b17023SJohn Marino {
56*e4b17023SJohn Marino }
57*e4b17023SJohn Marino
58*e4b17023SJohn Marino /* Pass through (tree). */
59*e4b17023SJohn Marino tree
lhd_pass_through_t(tree t)60*e4b17023SJohn Marino lhd_pass_through_t (tree t)
61*e4b17023SJohn Marino {
62*e4b17023SJohn Marino return t;
63*e4b17023SJohn Marino }
64*e4b17023SJohn Marino
65*e4b17023SJohn Marino /* Do nothing (int, int, int). Return NULL_TREE. */
66*e4b17023SJohn Marino
67*e4b17023SJohn Marino tree
lhd_do_nothing_iii_return_null_tree(int ARG_UNUSED (i),int ARG_UNUSED (j),int ARG_UNUSED (k))68*e4b17023SJohn Marino lhd_do_nothing_iii_return_null_tree (int ARG_UNUSED (i),
69*e4b17023SJohn Marino int ARG_UNUSED (j),
70*e4b17023SJohn Marino int ARG_UNUSED (k))
71*e4b17023SJohn Marino {
72*e4b17023SJohn Marino return NULL_TREE;
73*e4b17023SJohn Marino }
74*e4b17023SJohn Marino
75*e4b17023SJohn Marino /* Do nothing (function). */
76*e4b17023SJohn Marino
77*e4b17023SJohn Marino void
lhd_do_nothing_f(struct function * ARG_UNUSED (f))78*e4b17023SJohn Marino lhd_do_nothing_f (struct function * ARG_UNUSED (f))
79*e4b17023SJohn Marino {
80*e4b17023SJohn Marino }
81*e4b17023SJohn Marino
82*e4b17023SJohn Marino /* Do nothing (return NULL_TREE). */
83*e4b17023SJohn Marino
84*e4b17023SJohn Marino tree
lhd_return_null_tree_v(void)85*e4b17023SJohn Marino lhd_return_null_tree_v (void)
86*e4b17023SJohn Marino {
87*e4b17023SJohn Marino return NULL_TREE;
88*e4b17023SJohn Marino }
89*e4b17023SJohn Marino
90*e4b17023SJohn Marino /* Do nothing (return NULL_TREE). */
91*e4b17023SJohn Marino
92*e4b17023SJohn Marino tree
lhd_return_null_tree(tree ARG_UNUSED (t))93*e4b17023SJohn Marino lhd_return_null_tree (tree ARG_UNUSED (t))
94*e4b17023SJohn Marino {
95*e4b17023SJohn Marino return NULL_TREE;
96*e4b17023SJohn Marino }
97*e4b17023SJohn Marino
98*e4b17023SJohn Marino /* Do nothing (return NULL_TREE). */
99*e4b17023SJohn Marino
100*e4b17023SJohn Marino tree
lhd_return_null_const_tree(const_tree ARG_UNUSED (t))101*e4b17023SJohn Marino lhd_return_null_const_tree (const_tree ARG_UNUSED (t))
102*e4b17023SJohn Marino {
103*e4b17023SJohn Marino return NULL_TREE;
104*e4b17023SJohn Marino }
105*e4b17023SJohn Marino
106*e4b17023SJohn Marino /* The default post options hook. */
107*e4b17023SJohn Marino
108*e4b17023SJohn Marino bool
lhd_post_options(const char ** ARG_UNUSED (pfilename))109*e4b17023SJohn Marino lhd_post_options (const char ** ARG_UNUSED (pfilename))
110*e4b17023SJohn Marino {
111*e4b17023SJohn Marino /* Excess precision other than "fast" requires front-end
112*e4b17023SJohn Marino support. */
113*e4b17023SJohn Marino flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
114*e4b17023SJohn Marino return false;
115*e4b17023SJohn Marino }
116*e4b17023SJohn Marino
117*e4b17023SJohn Marino /* Called from by print-tree.c. */
118*e4b17023SJohn Marino
119*e4b17023SJohn Marino void
lhd_print_tree_nothing(FILE * ARG_UNUSED (file),tree ARG_UNUSED (node),int ARG_UNUSED (indent))120*e4b17023SJohn Marino lhd_print_tree_nothing (FILE * ARG_UNUSED (file),
121*e4b17023SJohn Marino tree ARG_UNUSED (node),
122*e4b17023SJohn Marino int ARG_UNUSED (indent))
123*e4b17023SJohn Marino {
124*e4b17023SJohn Marino }
125*e4b17023SJohn Marino
126*e4b17023SJohn Marino /* Called from check_global_declarations. */
127*e4b17023SJohn Marino
128*e4b17023SJohn Marino bool
lhd_warn_unused_global_decl(const_tree decl)129*e4b17023SJohn Marino lhd_warn_unused_global_decl (const_tree decl)
130*e4b17023SJohn Marino {
131*e4b17023SJohn Marino /* This is what used to exist in check_global_declarations. Probably
132*e4b17023SJohn Marino not many of these actually apply to non-C languages. */
133*e4b17023SJohn Marino
134*e4b17023SJohn Marino if (TREE_CODE (decl) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (decl))
135*e4b17023SJohn Marino return false;
136*e4b17023SJohn Marino if (TREE_CODE (decl) == VAR_DECL && TREE_READONLY (decl))
137*e4b17023SJohn Marino return false;
138*e4b17023SJohn Marino if (DECL_IN_SYSTEM_HEADER (decl))
139*e4b17023SJohn Marino return false;
140*e4b17023SJohn Marino
141*e4b17023SJohn Marino return true;
142*e4b17023SJohn Marino }
143*e4b17023SJohn Marino
144*e4b17023SJohn Marino /* Set the DECL_ASSEMBLER_NAME for DECL. */
145*e4b17023SJohn Marino void
lhd_set_decl_assembler_name(tree decl)146*e4b17023SJohn Marino lhd_set_decl_assembler_name (tree decl)
147*e4b17023SJohn Marino {
148*e4b17023SJohn Marino tree id;
149*e4b17023SJohn Marino
150*e4b17023SJohn Marino /* The language-independent code should never use the
151*e4b17023SJohn Marino DECL_ASSEMBLER_NAME for lots of DECLs. Only FUNCTION_DECLs and
152*e4b17023SJohn Marino VAR_DECLs for variables with static storage duration need a real
153*e4b17023SJohn Marino DECL_ASSEMBLER_NAME. */
154*e4b17023SJohn Marino gcc_assert (TREE_CODE (decl) == FUNCTION_DECL
155*e4b17023SJohn Marino || (TREE_CODE (decl) == VAR_DECL
156*e4b17023SJohn Marino && (TREE_STATIC (decl)
157*e4b17023SJohn Marino || DECL_EXTERNAL (decl)
158*e4b17023SJohn Marino || TREE_PUBLIC (decl))));
159*e4b17023SJohn Marino
160*e4b17023SJohn Marino /* By default, assume the name to use in assembly code is the same
161*e4b17023SJohn Marino as that used in the source language. (That's correct for C, and
162*e4b17023SJohn Marino GCC used to set DECL_ASSEMBLER_NAME to the same value as
163*e4b17023SJohn Marino DECL_NAME in build_decl, so this choice provides backwards
164*e4b17023SJohn Marino compatibility with existing front-ends. This assumption is wrapped
165*e4b17023SJohn Marino in a target hook, to allow for target-specific modification of the
166*e4b17023SJohn Marino identifier.
167*e4b17023SJohn Marino
168*e4b17023SJohn Marino Can't use just the variable's own name for a variable whose scope
169*e4b17023SJohn Marino is less than the whole compilation. Concatenate a distinguishing
170*e4b17023SJohn Marino number - we use the DECL_UID. */
171*e4b17023SJohn Marino
172*e4b17023SJohn Marino if (TREE_PUBLIC (decl) || DECL_FILE_SCOPE_P (decl))
173*e4b17023SJohn Marino id = targetm.mangle_decl_assembler_name (decl, DECL_NAME (decl));
174*e4b17023SJohn Marino else
175*e4b17023SJohn Marino {
176*e4b17023SJohn Marino const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
177*e4b17023SJohn Marino char *label;
178*e4b17023SJohn Marino
179*e4b17023SJohn Marino ASM_FORMAT_PRIVATE_NAME (label, name, DECL_UID (decl));
180*e4b17023SJohn Marino id = get_identifier (label);
181*e4b17023SJohn Marino }
182*e4b17023SJohn Marino SET_DECL_ASSEMBLER_NAME (decl, id);
183*e4b17023SJohn Marino
184*e4b17023SJohn Marino }
185*e4b17023SJohn Marino
186*e4b17023SJohn Marino /* Type promotion for variable arguments. */
187*e4b17023SJohn Marino tree
lhd_type_promotes_to(tree ARG_UNUSED (type))188*e4b17023SJohn Marino lhd_type_promotes_to (tree ARG_UNUSED (type))
189*e4b17023SJohn Marino {
190*e4b17023SJohn Marino gcc_unreachable ();
191*e4b17023SJohn Marino }
192*e4b17023SJohn Marino
193*e4b17023SJohn Marino /* Registration of machine- or os-specific builtin types. */
194*e4b17023SJohn Marino void
lhd_register_builtin_type(tree ARG_UNUSED (type),const char * ARG_UNUSED (name))195*e4b17023SJohn Marino lhd_register_builtin_type (tree ARG_UNUSED (type),
196*e4b17023SJohn Marino const char * ARG_UNUSED (name))
197*e4b17023SJohn Marino {
198*e4b17023SJohn Marino }
199*e4b17023SJohn Marino
200*e4b17023SJohn Marino /* Invalid use of an incomplete type. */
201*e4b17023SJohn Marino void
lhd_incomplete_type_error(const_tree ARG_UNUSED (value),const_tree type)202*e4b17023SJohn Marino lhd_incomplete_type_error (const_tree ARG_UNUSED (value), const_tree type)
203*e4b17023SJohn Marino {
204*e4b17023SJohn Marino gcc_assert (TREE_CODE (type) == ERROR_MARK);
205*e4b17023SJohn Marino return;
206*e4b17023SJohn Marino }
207*e4b17023SJohn Marino
208*e4b17023SJohn Marino /* Provide a default routine for alias sets that always returns -1. This
209*e4b17023SJohn Marino is used by languages that don't need to do anything special. */
210*e4b17023SJohn Marino
211*e4b17023SJohn Marino alias_set_type
lhd_get_alias_set(tree ARG_UNUSED (t))212*e4b17023SJohn Marino lhd_get_alias_set (tree ARG_UNUSED (t))
213*e4b17023SJohn Marino {
214*e4b17023SJohn Marino return -1;
215*e4b17023SJohn Marino }
216*e4b17023SJohn Marino
217*e4b17023SJohn Marino /* This is the default decl_printable_name function. */
218*e4b17023SJohn Marino
219*e4b17023SJohn Marino const char *
lhd_decl_printable_name(tree decl,int ARG_UNUSED (verbosity))220*e4b17023SJohn Marino lhd_decl_printable_name (tree decl, int ARG_UNUSED (verbosity))
221*e4b17023SJohn Marino {
222*e4b17023SJohn Marino gcc_assert (decl && DECL_NAME (decl));
223*e4b17023SJohn Marino return IDENTIFIER_POINTER (DECL_NAME (decl));
224*e4b17023SJohn Marino }
225*e4b17023SJohn Marino
226*e4b17023SJohn Marino /* This is the default dwarf_name function. */
227*e4b17023SJohn Marino
228*e4b17023SJohn Marino const char *
lhd_dwarf_name(tree t,int verbosity)229*e4b17023SJohn Marino lhd_dwarf_name (tree t, int verbosity)
230*e4b17023SJohn Marino {
231*e4b17023SJohn Marino gcc_assert (DECL_P (t));
232*e4b17023SJohn Marino
233*e4b17023SJohn Marino return lang_hooks.decl_printable_name (t, verbosity);
234*e4b17023SJohn Marino }
235*e4b17023SJohn Marino
236*e4b17023SJohn Marino /* This compares two types for equivalence ("compatible" in C-based languages).
237*e4b17023SJohn Marino This routine should only return 1 if it is sure. It should not be used
238*e4b17023SJohn Marino in contexts where erroneously returning 0 causes problems. */
239*e4b17023SJohn Marino
240*e4b17023SJohn Marino int
lhd_types_compatible_p(tree x,tree y)241*e4b17023SJohn Marino lhd_types_compatible_p (tree x, tree y)
242*e4b17023SJohn Marino {
243*e4b17023SJohn Marino return TYPE_MAIN_VARIANT (x) == TYPE_MAIN_VARIANT (y);
244*e4b17023SJohn Marino }
245*e4b17023SJohn Marino
246*e4b17023SJohn Marino /* lang_hooks.tree_dump.dump_tree: Dump language-specific parts of tree
247*e4b17023SJohn Marino nodes. Returns nonzero if it does not want the usual dumping of the
248*e4b17023SJohn Marino second argument. */
249*e4b17023SJohn Marino
250*e4b17023SJohn Marino bool
lhd_tree_dump_dump_tree(void * di ATTRIBUTE_UNUSED,tree t ATTRIBUTE_UNUSED)251*e4b17023SJohn Marino lhd_tree_dump_dump_tree (void *di ATTRIBUTE_UNUSED, tree t ATTRIBUTE_UNUSED)
252*e4b17023SJohn Marino {
253*e4b17023SJohn Marino return false;
254*e4b17023SJohn Marino }
255*e4b17023SJohn Marino
256*e4b17023SJohn Marino /* lang_hooks.tree_dump.type_qual: Determine type qualifiers in a
257*e4b17023SJohn Marino language-specific way. */
258*e4b17023SJohn Marino
259*e4b17023SJohn Marino int
lhd_tree_dump_type_quals(const_tree t)260*e4b17023SJohn Marino lhd_tree_dump_type_quals (const_tree t)
261*e4b17023SJohn Marino {
262*e4b17023SJohn Marino return TYPE_QUALS (t);
263*e4b17023SJohn Marino }
264*e4b17023SJohn Marino
265*e4b17023SJohn Marino /* lang_hooks.gimplify_expr re-writes *EXPR_P into GIMPLE form. */
266*e4b17023SJohn Marino
267*e4b17023SJohn Marino int
lhd_gimplify_expr(tree * expr_p ATTRIBUTE_UNUSED,gimple_seq * pre_p ATTRIBUTE_UNUSED,gimple_seq * post_p ATTRIBUTE_UNUSED)268*e4b17023SJohn Marino lhd_gimplify_expr (tree *expr_p ATTRIBUTE_UNUSED,
269*e4b17023SJohn Marino gimple_seq *pre_p ATTRIBUTE_UNUSED,
270*e4b17023SJohn Marino gimple_seq *post_p ATTRIBUTE_UNUSED)
271*e4b17023SJohn Marino {
272*e4b17023SJohn Marino return GS_UNHANDLED;
273*e4b17023SJohn Marino }
274*e4b17023SJohn Marino
275*e4b17023SJohn Marino /* lang_hooks.tree_size: Determine the size of a tree with code C,
276*e4b17023SJohn Marino which is a language-specific tree code in category tcc_constant or
277*e4b17023SJohn Marino tcc_exceptional. The default expects never to be called. */
278*e4b17023SJohn Marino size_t
lhd_tree_size(enum tree_code c ATTRIBUTE_UNUSED)279*e4b17023SJohn Marino lhd_tree_size (enum tree_code c ATTRIBUTE_UNUSED)
280*e4b17023SJohn Marino {
281*e4b17023SJohn Marino gcc_unreachable ();
282*e4b17023SJohn Marino }
283*e4b17023SJohn Marino
284*e4b17023SJohn Marino /* Return true if decl, which is a function decl, may be called by a
285*e4b17023SJohn Marino sibcall. */
286*e4b17023SJohn Marino
287*e4b17023SJohn Marino bool
lhd_decl_ok_for_sibcall(const_tree decl ATTRIBUTE_UNUSED)288*e4b17023SJohn Marino lhd_decl_ok_for_sibcall (const_tree decl ATTRIBUTE_UNUSED)
289*e4b17023SJohn Marino {
290*e4b17023SJohn Marino return true;
291*e4b17023SJohn Marino }
292*e4b17023SJohn Marino
293*e4b17023SJohn Marino /* lang_hooks.decls.final_write_globals: perform final processing on
294*e4b17023SJohn Marino global variables. */
295*e4b17023SJohn Marino void
write_global_declarations(void)296*e4b17023SJohn Marino write_global_declarations (void)
297*e4b17023SJohn Marino {
298*e4b17023SJohn Marino tree globals, decl, *vec;
299*e4b17023SJohn Marino int len, i;
300*e4b17023SJohn Marino
301*e4b17023SJohn Marino /* This lang hook is dual-purposed, and also finalizes the
302*e4b17023SJohn Marino compilation unit. */
303*e4b17023SJohn Marino cgraph_finalize_compilation_unit ();
304*e4b17023SJohn Marino
305*e4b17023SJohn Marino /* Really define vars that have had only a tentative definition.
306*e4b17023SJohn Marino Really output inline functions that must actually be callable
307*e4b17023SJohn Marino and have not been output so far. */
308*e4b17023SJohn Marino
309*e4b17023SJohn Marino globals = lang_hooks.decls.getdecls ();
310*e4b17023SJohn Marino len = list_length (globals);
311*e4b17023SJohn Marino vec = XNEWVEC (tree, len);
312*e4b17023SJohn Marino
313*e4b17023SJohn Marino /* Process the decls in reverse order--earliest first.
314*e4b17023SJohn Marino Put them into VEC from back to front, then take out from front. */
315*e4b17023SJohn Marino
316*e4b17023SJohn Marino for (i = 0, decl = globals; i < len; i++, decl = DECL_CHAIN (decl))
317*e4b17023SJohn Marino vec[len - i - 1] = decl;
318*e4b17023SJohn Marino
319*e4b17023SJohn Marino wrapup_global_declarations (vec, len);
320*e4b17023SJohn Marino check_global_declarations (vec, len);
321*e4b17023SJohn Marino emit_debug_global_declarations (vec, len);
322*e4b17023SJohn Marino
323*e4b17023SJohn Marino /* Clean up. */
324*e4b17023SJohn Marino free (vec);
325*e4b17023SJohn Marino }
326*e4b17023SJohn Marino
327*e4b17023SJohn Marino /* Called to perform language-specific initialization of CTX. */
328*e4b17023SJohn Marino void
lhd_initialize_diagnostics(diagnostic_context * ctx ATTRIBUTE_UNUSED)329*e4b17023SJohn Marino lhd_initialize_diagnostics (diagnostic_context *ctx ATTRIBUTE_UNUSED)
330*e4b17023SJohn Marino {
331*e4b17023SJohn Marino }
332*e4b17023SJohn Marino
333*e4b17023SJohn Marino /* Called to perform language-specific options initialization. */
334*e4b17023SJohn Marino void
lhd_init_options(unsigned int decoded_options_count ATTRIBUTE_UNUSED,struct cl_decoded_option * decoded_options ATTRIBUTE_UNUSED)335*e4b17023SJohn Marino lhd_init_options (unsigned int decoded_options_count ATTRIBUTE_UNUSED,
336*e4b17023SJohn Marino struct cl_decoded_option *decoded_options ATTRIBUTE_UNUSED)
337*e4b17023SJohn Marino {
338*e4b17023SJohn Marino }
339*e4b17023SJohn Marino
340*e4b17023SJohn Marino /* By default, always complain about options for the wrong language. */
341*e4b17023SJohn Marino bool
lhd_complain_wrong_lang_p(const struct cl_option * option ATTRIBUTE_UNUSED)342*e4b17023SJohn Marino lhd_complain_wrong_lang_p (const struct cl_option *option ATTRIBUTE_UNUSED)
343*e4b17023SJohn Marino {
344*e4b17023SJohn Marino return true;
345*e4b17023SJohn Marino }
346*e4b17023SJohn Marino
347*e4b17023SJohn Marino /* By default, no language-specific options are valid. */
348*e4b17023SJohn Marino bool
lhd_handle_option(size_t code ATTRIBUTE_UNUSED,const char * arg ATTRIBUTE_UNUSED,int value ATTRIBUTE_UNUSED,int kind ATTRIBUTE_UNUSED,location_t loc ATTRIBUTE_UNUSED,const struct cl_option_handlers * handlers ATTRIBUTE_UNUSED)349*e4b17023SJohn Marino lhd_handle_option (size_t code ATTRIBUTE_UNUSED,
350*e4b17023SJohn Marino const char *arg ATTRIBUTE_UNUSED,
351*e4b17023SJohn Marino int value ATTRIBUTE_UNUSED, int kind ATTRIBUTE_UNUSED,
352*e4b17023SJohn Marino location_t loc ATTRIBUTE_UNUSED,
353*e4b17023SJohn Marino const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
354*e4b17023SJohn Marino {
355*e4b17023SJohn Marino return false;
356*e4b17023SJohn Marino }
357*e4b17023SJohn Marino
358*e4b17023SJohn Marino /* The default function to print out name of current function that caused
359*e4b17023SJohn Marino an error. */
360*e4b17023SJohn Marino void
lhd_print_error_function(diagnostic_context * context,const char * file,diagnostic_info * diagnostic)361*e4b17023SJohn Marino lhd_print_error_function (diagnostic_context *context, const char *file,
362*e4b17023SJohn Marino diagnostic_info *diagnostic)
363*e4b17023SJohn Marino {
364*e4b17023SJohn Marino if (diagnostic_last_function_changed (context, diagnostic))
365*e4b17023SJohn Marino {
366*e4b17023SJohn Marino const char *old_prefix = context->printer->prefix;
367*e4b17023SJohn Marino tree abstract_origin = diagnostic_abstract_origin (diagnostic);
368*e4b17023SJohn Marino char *new_prefix = (file && abstract_origin == NULL)
369*e4b17023SJohn Marino ? file_name_as_prefix (file) : NULL;
370*e4b17023SJohn Marino
371*e4b17023SJohn Marino pp_set_prefix (context->printer, new_prefix);
372*e4b17023SJohn Marino
373*e4b17023SJohn Marino if (current_function_decl == NULL)
374*e4b17023SJohn Marino pp_printf (context->printer, _("At top level:"));
375*e4b17023SJohn Marino else
376*e4b17023SJohn Marino {
377*e4b17023SJohn Marino tree fndecl, ao;
378*e4b17023SJohn Marino
379*e4b17023SJohn Marino if (abstract_origin)
380*e4b17023SJohn Marino {
381*e4b17023SJohn Marino ao = BLOCK_ABSTRACT_ORIGIN (abstract_origin);
382*e4b17023SJohn Marino while (TREE_CODE (ao) == BLOCK
383*e4b17023SJohn Marino && BLOCK_ABSTRACT_ORIGIN (ao)
384*e4b17023SJohn Marino && BLOCK_ABSTRACT_ORIGIN (ao) != ao)
385*e4b17023SJohn Marino ao = BLOCK_ABSTRACT_ORIGIN (ao);
386*e4b17023SJohn Marino gcc_assert (TREE_CODE (ao) == FUNCTION_DECL);
387*e4b17023SJohn Marino fndecl = ao;
388*e4b17023SJohn Marino }
389*e4b17023SJohn Marino else
390*e4b17023SJohn Marino fndecl = current_function_decl;
391*e4b17023SJohn Marino
392*e4b17023SJohn Marino if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE)
393*e4b17023SJohn Marino pp_printf
394*e4b17023SJohn Marino (context->printer, _("In member function %qs"),
395*e4b17023SJohn Marino identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2)));
396*e4b17023SJohn Marino else
397*e4b17023SJohn Marino pp_printf
398*e4b17023SJohn Marino (context->printer, _("In function %qs"),
399*e4b17023SJohn Marino identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2)));
400*e4b17023SJohn Marino
401*e4b17023SJohn Marino while (abstract_origin)
402*e4b17023SJohn Marino {
403*e4b17023SJohn Marino location_t *locus;
404*e4b17023SJohn Marino tree block = abstract_origin;
405*e4b17023SJohn Marino
406*e4b17023SJohn Marino locus = &BLOCK_SOURCE_LOCATION (block);
407*e4b17023SJohn Marino fndecl = NULL;
408*e4b17023SJohn Marino block = BLOCK_SUPERCONTEXT (block);
409*e4b17023SJohn Marino while (block && TREE_CODE (block) == BLOCK
410*e4b17023SJohn Marino && BLOCK_ABSTRACT_ORIGIN (block))
411*e4b17023SJohn Marino {
412*e4b17023SJohn Marino ao = BLOCK_ABSTRACT_ORIGIN (block);
413*e4b17023SJohn Marino
414*e4b17023SJohn Marino while (TREE_CODE (ao) == BLOCK
415*e4b17023SJohn Marino && BLOCK_ABSTRACT_ORIGIN (ao)
416*e4b17023SJohn Marino && BLOCK_ABSTRACT_ORIGIN (ao) != ao)
417*e4b17023SJohn Marino ao = BLOCK_ABSTRACT_ORIGIN (ao);
418*e4b17023SJohn Marino
419*e4b17023SJohn Marino if (TREE_CODE (ao) == FUNCTION_DECL)
420*e4b17023SJohn Marino {
421*e4b17023SJohn Marino fndecl = ao;
422*e4b17023SJohn Marino break;
423*e4b17023SJohn Marino }
424*e4b17023SJohn Marino else if (TREE_CODE (ao) != BLOCK)
425*e4b17023SJohn Marino break;
426*e4b17023SJohn Marino
427*e4b17023SJohn Marino block = BLOCK_SUPERCONTEXT (block);
428*e4b17023SJohn Marino }
429*e4b17023SJohn Marino if (fndecl)
430*e4b17023SJohn Marino abstract_origin = block;
431*e4b17023SJohn Marino else
432*e4b17023SJohn Marino {
433*e4b17023SJohn Marino while (block && TREE_CODE (block) == BLOCK)
434*e4b17023SJohn Marino block = BLOCK_SUPERCONTEXT (block);
435*e4b17023SJohn Marino
436*e4b17023SJohn Marino if (block && TREE_CODE (block) == FUNCTION_DECL)
437*e4b17023SJohn Marino fndecl = block;
438*e4b17023SJohn Marino abstract_origin = NULL;
439*e4b17023SJohn Marino }
440*e4b17023SJohn Marino if (fndecl)
441*e4b17023SJohn Marino {
442*e4b17023SJohn Marino expanded_location s = expand_location (*locus);
443*e4b17023SJohn Marino pp_character (context->printer, ',');
444*e4b17023SJohn Marino pp_newline (context->printer);
445*e4b17023SJohn Marino if (s.file != NULL)
446*e4b17023SJohn Marino {
447*e4b17023SJohn Marino if (context->show_column)
448*e4b17023SJohn Marino pp_printf (context->printer,
449*e4b17023SJohn Marino _(" inlined from %qs at %s:%d:%d"),
450*e4b17023SJohn Marino identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2)),
451*e4b17023SJohn Marino s.file, s.line, s.column);
452*e4b17023SJohn Marino else
453*e4b17023SJohn Marino pp_printf (context->printer,
454*e4b17023SJohn Marino _(" inlined from %qs at %s:%d"),
455*e4b17023SJohn Marino identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2)),
456*e4b17023SJohn Marino s.file, s.line);
457*e4b17023SJohn Marino
458*e4b17023SJohn Marino }
459*e4b17023SJohn Marino else
460*e4b17023SJohn Marino pp_printf (context->printer, _(" inlined from %qs"),
461*e4b17023SJohn Marino identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2)));
462*e4b17023SJohn Marino }
463*e4b17023SJohn Marino }
464*e4b17023SJohn Marino pp_character (context->printer, ':');
465*e4b17023SJohn Marino }
466*e4b17023SJohn Marino
467*e4b17023SJohn Marino diagnostic_set_last_function (context, diagnostic);
468*e4b17023SJohn Marino pp_flush (context->printer);
469*e4b17023SJohn Marino context->printer->prefix = old_prefix;
470*e4b17023SJohn Marino free ((char*) new_prefix);
471*e4b17023SJohn Marino }
472*e4b17023SJohn Marino }
473*e4b17023SJohn Marino
474*e4b17023SJohn Marino tree
lhd_callgraph_analyze_expr(tree * tp ATTRIBUTE_UNUSED,int * walk_subtrees ATTRIBUTE_UNUSED)475*e4b17023SJohn Marino lhd_callgraph_analyze_expr (tree *tp ATTRIBUTE_UNUSED,
476*e4b17023SJohn Marino int *walk_subtrees ATTRIBUTE_UNUSED)
477*e4b17023SJohn Marino {
478*e4b17023SJohn Marino return NULL;
479*e4b17023SJohn Marino }
480*e4b17023SJohn Marino
481*e4b17023SJohn Marino tree
lhd_make_node(enum tree_code code)482*e4b17023SJohn Marino lhd_make_node (enum tree_code code)
483*e4b17023SJohn Marino {
484*e4b17023SJohn Marino return make_node (code);
485*e4b17023SJohn Marino }
486*e4b17023SJohn Marino
487*e4b17023SJohn Marino HOST_WIDE_INT
lhd_to_target_charset(HOST_WIDE_INT c)488*e4b17023SJohn Marino lhd_to_target_charset (HOST_WIDE_INT c)
489*e4b17023SJohn Marino {
490*e4b17023SJohn Marino return c;
491*e4b17023SJohn Marino }
492*e4b17023SJohn Marino
493*e4b17023SJohn Marino tree
lhd_expr_to_decl(tree expr,bool * tc ATTRIBUTE_UNUSED,bool * se ATTRIBUTE_UNUSED)494*e4b17023SJohn Marino lhd_expr_to_decl (tree expr, bool *tc ATTRIBUTE_UNUSED, bool *se ATTRIBUTE_UNUSED)
495*e4b17023SJohn Marino {
496*e4b17023SJohn Marino return expr;
497*e4b17023SJohn Marino }
498*e4b17023SJohn Marino
499*e4b17023SJohn Marino /* Return sharing kind if OpenMP sharing attribute of DECL is
500*e4b17023SJohn Marino predetermined, OMP_CLAUSE_DEFAULT_UNSPECIFIED otherwise. */
501*e4b17023SJohn Marino
502*e4b17023SJohn Marino enum omp_clause_default_kind
lhd_omp_predetermined_sharing(tree decl ATTRIBUTE_UNUSED)503*e4b17023SJohn Marino lhd_omp_predetermined_sharing (tree decl ATTRIBUTE_UNUSED)
504*e4b17023SJohn Marino {
505*e4b17023SJohn Marino if (DECL_ARTIFICIAL (decl))
506*e4b17023SJohn Marino return OMP_CLAUSE_DEFAULT_SHARED;
507*e4b17023SJohn Marino return OMP_CLAUSE_DEFAULT_UNSPECIFIED;
508*e4b17023SJohn Marino }
509*e4b17023SJohn Marino
510*e4b17023SJohn Marino /* Generate code to copy SRC to DST. */
511*e4b17023SJohn Marino
512*e4b17023SJohn Marino tree
lhd_omp_assignment(tree clause ATTRIBUTE_UNUSED,tree dst,tree src)513*e4b17023SJohn Marino lhd_omp_assignment (tree clause ATTRIBUTE_UNUSED, tree dst, tree src)
514*e4b17023SJohn Marino {
515*e4b17023SJohn Marino return build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
516*e4b17023SJohn Marino }
517*e4b17023SJohn Marino
518*e4b17023SJohn Marino /* Register language specific type size variables as potentially OpenMP
519*e4b17023SJohn Marino firstprivate variables. */
520*e4b17023SJohn Marino
521*e4b17023SJohn Marino void
lhd_omp_firstprivatize_type_sizes(struct gimplify_omp_ctx * c ATTRIBUTE_UNUSED,tree t ATTRIBUTE_UNUSED)522*e4b17023SJohn Marino lhd_omp_firstprivatize_type_sizes (struct gimplify_omp_ctx *c ATTRIBUTE_UNUSED,
523*e4b17023SJohn Marino tree t ATTRIBUTE_UNUSED)
524*e4b17023SJohn Marino {
525*e4b17023SJohn Marino }
526*e4b17023SJohn Marino
527*e4b17023SJohn Marino /* Common function for add_builtin_function and
528*e4b17023SJohn Marino add_builtin_function_ext_scope. */
529*e4b17023SJohn Marino static tree
add_builtin_function_common(const char * name,tree type,int function_code,enum built_in_class cl,const char * library_name,tree attrs,tree (* hook)(tree))530*e4b17023SJohn Marino add_builtin_function_common (const char *name,
531*e4b17023SJohn Marino tree type,
532*e4b17023SJohn Marino int function_code,
533*e4b17023SJohn Marino enum built_in_class cl,
534*e4b17023SJohn Marino const char *library_name,
535*e4b17023SJohn Marino tree attrs,
536*e4b17023SJohn Marino tree (*hook) (tree))
537*e4b17023SJohn Marino {
538*e4b17023SJohn Marino tree id = get_identifier (name);
539*e4b17023SJohn Marino tree decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL, id, type);
540*e4b17023SJohn Marino
541*e4b17023SJohn Marino TREE_PUBLIC (decl) = 1;
542*e4b17023SJohn Marino DECL_EXTERNAL (decl) = 1;
543*e4b17023SJohn Marino DECL_BUILT_IN_CLASS (decl) = cl;
544*e4b17023SJohn Marino
545*e4b17023SJohn Marino DECL_FUNCTION_CODE (decl) = (enum built_in_function) function_code;
546*e4b17023SJohn Marino
547*e4b17023SJohn Marino /* DECL_FUNCTION_CODE is a bitfield; verify that the value fits. */
548*e4b17023SJohn Marino gcc_assert (DECL_FUNCTION_CODE (decl) == function_code);
549*e4b17023SJohn Marino
550*e4b17023SJohn Marino if (library_name)
551*e4b17023SJohn Marino {
552*e4b17023SJohn Marino tree libname = get_identifier (library_name);
553*e4b17023SJohn Marino SET_DECL_ASSEMBLER_NAME (decl, libname);
554*e4b17023SJohn Marino }
555*e4b17023SJohn Marino
556*e4b17023SJohn Marino /* Possibly apply some default attributes to this built-in function. */
557*e4b17023SJohn Marino if (attrs)
558*e4b17023SJohn Marino decl_attributes (&decl, attrs, ATTR_FLAG_BUILT_IN);
559*e4b17023SJohn Marino else
560*e4b17023SJohn Marino decl_attributes (&decl, NULL_TREE, 0);
561*e4b17023SJohn Marino
562*e4b17023SJohn Marino return hook (decl);
563*e4b17023SJohn Marino
564*e4b17023SJohn Marino }
565*e4b17023SJohn Marino
566*e4b17023SJohn Marino /* Create a builtin function. */
567*e4b17023SJohn Marino
568*e4b17023SJohn Marino tree
add_builtin_function(const char * name,tree type,int function_code,enum built_in_class cl,const char * library_name,tree attrs)569*e4b17023SJohn Marino add_builtin_function (const char *name,
570*e4b17023SJohn Marino tree type,
571*e4b17023SJohn Marino int function_code,
572*e4b17023SJohn Marino enum built_in_class cl,
573*e4b17023SJohn Marino const char *library_name,
574*e4b17023SJohn Marino tree attrs)
575*e4b17023SJohn Marino {
576*e4b17023SJohn Marino return add_builtin_function_common (name, type, function_code, cl,
577*e4b17023SJohn Marino library_name, attrs,
578*e4b17023SJohn Marino lang_hooks.builtin_function);
579*e4b17023SJohn Marino }
580*e4b17023SJohn Marino
581*e4b17023SJohn Marino /* Like add_builtin_function, but make sure the scope is the external scope.
582*e4b17023SJohn Marino This is used to delay putting in back end builtin functions until the ISA
583*e4b17023SJohn Marino that defines the builtin is declared via function specific target options,
584*e4b17023SJohn Marino which can save memory for machines like the x86_64 that have multiple ISAs.
585*e4b17023SJohn Marino If this points to the same function as builtin_function, the backend must
586*e4b17023SJohn Marino add all of the builtins at program initialization time. */
587*e4b17023SJohn Marino
588*e4b17023SJohn Marino tree
add_builtin_function_ext_scope(const char * name,tree type,int function_code,enum built_in_class cl,const char * library_name,tree attrs)589*e4b17023SJohn Marino add_builtin_function_ext_scope (const char *name,
590*e4b17023SJohn Marino tree type,
591*e4b17023SJohn Marino int function_code,
592*e4b17023SJohn Marino enum built_in_class cl,
593*e4b17023SJohn Marino const char *library_name,
594*e4b17023SJohn Marino tree attrs)
595*e4b17023SJohn Marino {
596*e4b17023SJohn Marino return add_builtin_function_common (name, type, function_code, cl,
597*e4b17023SJohn Marino library_name, attrs,
598*e4b17023SJohn Marino lang_hooks.builtin_function_ext_scope);
599*e4b17023SJohn Marino }
600*e4b17023SJohn Marino
601*e4b17023SJohn Marino tree
lhd_builtin_function(tree decl)602*e4b17023SJohn Marino lhd_builtin_function (tree decl)
603*e4b17023SJohn Marino {
604*e4b17023SJohn Marino lang_hooks.decls.pushdecl (decl);
605*e4b17023SJohn Marino return decl;
606*e4b17023SJohn Marino }
607*e4b17023SJohn Marino
608*e4b17023SJohn Marino /* LTO hooks. */
609*e4b17023SJohn Marino
610*e4b17023SJohn Marino /* Used to save and restore any previously active section. */
611*e4b17023SJohn Marino static section *saved_section;
612*e4b17023SJohn Marino
613*e4b17023SJohn Marino
614*e4b17023SJohn Marino /* Begin a new LTO output section named NAME. This default implementation
615*e4b17023SJohn Marino saves the old section and emits assembly code to switch to the new
616*e4b17023SJohn Marino section. */
617*e4b17023SJohn Marino
618*e4b17023SJohn Marino void
lhd_begin_section(const char * name)619*e4b17023SJohn Marino lhd_begin_section (const char *name)
620*e4b17023SJohn Marino {
621*e4b17023SJohn Marino section *section;
622*e4b17023SJohn Marino
623*e4b17023SJohn Marino /* Save the old section so we can restore it in lto_end_asm_section. */
624*e4b17023SJohn Marino gcc_assert (!saved_section);
625*e4b17023SJohn Marino saved_section = in_section;
626*e4b17023SJohn Marino if (!saved_section)
627*e4b17023SJohn Marino saved_section = text_section;
628*e4b17023SJohn Marino
629*e4b17023SJohn Marino /* Create a new section and switch to it. */
630*e4b17023SJohn Marino section = get_section (name, SECTION_DEBUG, NULL);
631*e4b17023SJohn Marino switch_to_section (section);
632*e4b17023SJohn Marino }
633*e4b17023SJohn Marino
634*e4b17023SJohn Marino
635*e4b17023SJohn Marino /* Write DATA of length LEN to the current LTO output section. This default
636*e4b17023SJohn Marino implementation just calls assemble_string and frees BLOCK. */
637*e4b17023SJohn Marino
638*e4b17023SJohn Marino void
lhd_append_data(const void * data,size_t len,void * block)639*e4b17023SJohn Marino lhd_append_data (const void *data, size_t len, void *block)
640*e4b17023SJohn Marino {
641*e4b17023SJohn Marino if (data)
642*e4b17023SJohn Marino assemble_string ((const char *)data, len);
643*e4b17023SJohn Marino free (block);
644*e4b17023SJohn Marino }
645*e4b17023SJohn Marino
646*e4b17023SJohn Marino
647*e4b17023SJohn Marino /* Finish the current LTO output section. This default implementation emits
648*e4b17023SJohn Marino assembly code to switch to any section previously saved by
649*e4b17023SJohn Marino lhd_begin_section. */
650*e4b17023SJohn Marino
651*e4b17023SJohn Marino void
lhd_end_section(void)652*e4b17023SJohn Marino lhd_end_section (void)
653*e4b17023SJohn Marino {
654*e4b17023SJohn Marino if (saved_section)
655*e4b17023SJohn Marino {
656*e4b17023SJohn Marino switch_to_section (saved_section);
657*e4b17023SJohn Marino saved_section = NULL;
658*e4b17023SJohn Marino }
659*e4b17023SJohn Marino }
660