port r209917 from google/gcc_4-9 branch
[official-gcc.git] / main / gcc / l-ipo.c
blob057f42d79ac0cc9177e70a5120c12d2c7573ffb7
1 /* Copyright (C) 2009. Free Software Foundation, Inc.
2 Contributed by Xinliang David Li (davidxl@google.com) and
3 Raksit Ashok (raksit@google.com)
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tree.h"
25 #include "is-a.h"
26 #include "predict.h"
27 #include "function.h"
28 #include "basic-block.h"
29 #include "stor-layout.h"
30 #include "pointer-set.h"
31 #include "stringpool.h"
32 #include "c-family/c-common.h"
33 #include "toplev.h"
34 #include "langhooks.h"
35 #include "langhooks-def.h"
36 #include "diagnostic.h"
37 #include "debug.h"
38 #include "tree-ssa-alias.h"
39 #include "internal-fn.h"
40 #include "gimple-expr.h"
41 #include "gimple.h"
42 #include "gimple-iterator.h"
43 #include "cgraph.h"
44 #include "l-ipo.h"
45 #include "coverage.h"
46 #include "gcov-io.h"
47 #include "timevar.h"
48 #include "vec.h"
49 #include "params.h"
51 unsigned ggc_total_memory; /* in KB */
53 struct GTY(()) saved_module_scope
55 vec<tree, va_gc> *module_decls;
56 unsigned module_id;
59 static GTY (()) struct saved_module_scope *current_module_scope;
60 static GTY ((param_is (saved_module_scope))) htab_t saved_module_scope_map;
61 static int primary_module_last_funcdef_no = 0;
62 /* Function id space for each module are qualified by the module id. After all the files
63 are parsed, we need to reset the funcdef_no to the max value from all module so that
64 the function clones do not assigned with ids colliding with some other orignal function
65 in the same module. */
66 static int max_funcdef_no = 0;
67 static location_t primary_module_last_loc;
68 /* Primary module pending templates. */
69 /* Referenced asm ids in primary module. */
70 static GTY (()) vec<tree, va_gc> *referenced_asm_ids = NULL;
71 bool parser_parsing_start = false;
72 /* Nonzero if we're done parsing and into end-of-file activities. */
73 int at_eof;
75 static int aggr_has_equiv_id (tree t1, tree t2);
77 /* Module scope hash function. */
79 static hashval_t
80 htab_module_scope_hash (const void *ent)
82 const struct saved_module_scope *const entry
83 = (const struct saved_module_scope *) ent;
84 return (hashval_t) entry->module_id;
87 /* Module scope equality function. */
89 static int
90 htab_module_scope_eq (const void *ent1, const void *ent2)
92 const struct saved_module_scope *const entry1
93 = (const struct saved_module_scope *) ent1;
94 const struct saved_module_scope *const entry2
95 = (const struct saved_module_scope *) ent2;
97 return entry1->module_id == entry2->module_id;
100 /* Returns the module scope given a module id MOD_ID. */
102 static struct saved_module_scope *
103 get_module_scope (unsigned mod_id)
105 struct saved_module_scope **slot, key, *module_scope;
107 gcc_assert (mod_id);
109 if (saved_module_scope_map == NULL)
110 saved_module_scope_map = htab_create_ggc (10, htab_module_scope_hash,
111 htab_module_scope_eq, NULL);
112 key.module_id = mod_id;
113 slot = (struct saved_module_scope **)
114 htab_find_slot (saved_module_scope_map, &key, INSERT);
115 module_scope = *slot;
116 if (!module_scope)
118 module_scope = ggc_alloc_cleared_saved_module_scope ();
119 module_scope->module_id = mod_id;
120 *slot = module_scope;
122 return module_scope;
125 /* Allocate memory for struct lang_decl for tree T. */
127 static struct lang_decl *
128 alloc_lang_decl (tree t)
130 size_t size;
131 size = lang_hooks.l_ipo.get_lang_decl_size (t);
132 return ggc_alloc_cleared_lang_decl (size);
135 /* Return a cloned copy of tree SRC. */
137 tree
138 lipo_save_decl (tree src)
140 tree saved = copy_node (src);
141 enum tree_code tc = TREE_CODE (src);
142 if (TREE_CODE_CLASS (tc) == tcc_declaration)
144 struct lang_decl *ls = NULL;
145 struct function *func = NULL;
146 DECL_CONTEXT (saved) = DECL_CONTEXT (src);
147 if (DECL_LANG_SPECIFIC (src))
149 ls = alloc_lang_decl (src);
150 memcpy (ls, DECL_LANG_SPECIFIC (src),
151 lang_hooks.l_ipo.get_lang_decl_size (src));
153 DECL_LANG_SPECIFIC (saved) = ls;
154 if (tc == FUNCTION_DECL && DECL_STRUCT_FUNCTION (src))
156 func = ggc_alloc_cleared_function ();
157 *func = *(DECL_STRUCT_FUNCTION (src));
158 DECL_STRUCT_FUNCTION (saved) = func;
161 else
163 gcc_assert (TREE_CODE_CLASS (tc) == tcc_type &&
164 TYPE_MAIN_VARIANT (src) == src);
165 TYPE_CONTEXT (saved) = TYPE_CONTEXT (src);
166 lang_hooks.l_ipo.dup_lang_type (src, saved);
169 return saved;
172 /* Copy tree SAVED to tree DEST. */
174 void
175 lipo_restore_decl (tree dest, tree saved)
177 enum tree_code tc;
178 unsigned old_uid;
179 struct lang_decl *oldls;
181 tc = TREE_CODE (saved);
182 if (TREE_CODE_CLASS (tc) == tcc_declaration)
184 struct function *oldfunc = NULL;
185 old_uid = DECL_UID (dest);
186 oldls = DECL_LANG_SPECIFIC (dest);
187 oldfunc
188 = (tc == FUNCTION_DECL ? DECL_STRUCT_FUNCTION (dest) : NULL);
190 memcpy ((char *) dest + sizeof (struct tree_common),
191 (char *) saved + sizeof (struct tree_common),
192 sizeof (struct tree_decl_common) - sizeof (struct tree_common));
194 if (tc == FUNCTION_DECL)
195 memcpy ((char *) dest + sizeof (struct tree_decl_common),
196 (char *) saved + sizeof (struct tree_decl_common),
197 sizeof (struct tree_function_decl)
198 - sizeof (struct tree_decl_common));
200 DECL_UID (dest) = old_uid;
201 if (DECL_LANG_SPECIFIC (saved))
203 if (!oldls)
204 oldls = alloc_lang_decl (dest);
205 memcpy (oldls, DECL_LANG_SPECIFIC (saved),
206 lang_hooks.l_ipo.get_lang_decl_size (saved));
207 DECL_LANG_SPECIFIC (dest) = oldls;
209 else
210 DECL_LANG_SPECIFIC (dest) = NULL;
212 if (tc == FUNCTION_DECL)
214 if (DECL_STRUCT_FUNCTION (saved))
216 if (!oldfunc)
217 oldfunc = ggc_alloc_cleared_function ();
218 *oldfunc = *(DECL_STRUCT_FUNCTION (saved));
219 DECL_STRUCT_FUNCTION (dest) = oldfunc;
221 else
222 DECL_STRUCT_FUNCTION (dest) = NULL;
225 else
227 gcc_assert (TREE_CODE_CLASS (tc) == tcc_type);
228 lang_hooks.l_ipo.copy_lang_type (saved, dest);
233 /* Return the name for tree TD which is either a decl or type. */
235 tree
236 get_type_or_decl_name (tree td)
238 tree id;
240 if (DECL_P (td))
241 id = DECL_NAME (td);
242 else
244 id = TYPE_NAME (td);
245 if (DECL_P (id))
246 id = DECL_NAME (id);
248 return id;
251 /* For a DECL (a type or a decl) in SCOPE, check to see if it is in
252 global or namespace scope. If yes, add it to the current module scope. */
254 void
255 add_decl_to_current_module_scope (tree decl, void *scope)
257 struct saved_module_scope *module_scope;
258 tree id;
260 if (!flag_dyn_ipa)
261 return;
263 if (!parser_parsing_start)
265 /* The source file may contains only global variable declations
266 -- there is no module grouping data associated with it, so
267 neither primary_module_id nor current_module_id is set. */
268 lang_hooks.l_ipo.add_built_in_decl (decl);
269 return;
272 if (!L_IPO_COMP_MODE)
273 return;
275 if (!lang_hooks.l_ipo.has_global_name (decl, scope))
276 return;
278 /* Unlike C++ where names are attached to type decls, for C, the type name
279 is identifier node. Thus we need to track type names as well. */
280 id = get_type_or_decl_name (decl);
281 if (!id)
282 return;
284 module_scope = current_module_scope;
285 gcc_assert (module_scope && module_scope->module_id == current_module_id);
286 vec_safe_push (module_scope->module_decls, decl);
289 /* Clear name bindings for all decls created in MODULE_SCOPE. */
291 static void
292 clear_module_scope_bindings (struct saved_module_scope *module_scope)
294 size_t i;
295 tree decl;
297 for (i = 0;
298 vec_safe_iterate (module_scope->module_decls, i, &decl);
299 ++i)
301 lang_hooks.l_ipo.clear_global_name_bindings (
302 get_type_or_decl_name (decl));
303 /* Now force creating assembly name. */
304 if (VAR_OR_FUNCTION_DECL_P (decl))
306 tree assembler_name;
308 if (HAS_DECL_ASSEMBLER_NAME_P (decl)
309 && DECL_ASSEMBLER_NAME_SET_P (decl))
311 assembler_name = DECL_ASSEMBLER_NAME (decl);
312 lang_hooks.l_ipo.clear_global_name_bindings (assembler_name);
318 /* The referenced attribute of a decl is not associated with the
319 decl itself but with the assembler name. Remember the referenced
320 bits before clearing them. */
322 static void
323 save_assembler_name_reference_bit (void)
325 varpool_get_referenced_asm_ids (&referenced_asm_ids);
328 /* Clear the reference bits for assembler names before closing the
329 module scope. */
331 static void
332 clear_assembler_name_reference_bit (void)
334 varpool_clear_asm_id_reference_bit ();
337 /* Restore the reference bits for assembler names. */
339 static void
340 restore_assembler_name_reference_bit (void)
342 size_t i;
343 tree nm;
344 for (i = 0;
345 vec_safe_iterate (referenced_asm_ids, i, &nm);
346 ++i)
347 TREE_SYMBOL_REFERENCED (nm) = 1;
350 /* Set up the module scope before the parsing of the
351 associated source file. */
353 void
354 push_module_scope (void)
356 struct saved_module_scope *prev_module_scope;
358 if (!flag_dyn_ipa || !L_IPO_COMP_MODE)
360 parser_parsing_start = true;
361 return;
364 prev_module_scope = current_module_scope;
365 if (L_IPO_IS_PRIMARY_MODULE)
367 gcc_assert (!prev_module_scope);
368 lang_hooks.l_ipo.save_built_in_decl_pre_parsing ();
369 parser_parsing_start = true;
372 gcc_assert (current_module_id);
374 /* Set up the module scope. */
375 current_module_scope = get_module_scope (current_module_id);
376 return;
379 /* Restore the shared decls to their post parsing states. */
381 static void
382 restore_post_parsing_states (void)
384 current_module_id = primary_module_id;
385 current_module_scope = get_module_scope (primary_module_id);
386 set_funcdef_no (max_funcdef_no);
387 input_location = primary_module_last_loc;
389 restore_assembler_name_reference_bit ();
390 lang_hooks.l_ipo.restore_built_in_decl_post_module_parsing ();
393 /* Pop the current module scope (by clearing name bindings etc.)
394 and prepare for parsing of the next module. In particular,
395 built-in decls need to be restored to the state before file
396 parsing starts. */
398 void
399 pop_module_scope (void)
401 bool is_last = false;
402 int last_funcdef_no;
404 if (!flag_dyn_ipa || !L_IPO_COMP_MODE)
405 return;
407 gcc_assert (current_module_id && current_module_scope);
409 if (L_IPO_IS_PRIMARY_MODULE)
410 primary_module_last_loc = input_location;
412 at_eof = 1;
413 cgraph_process_same_body_aliases ();
414 lang_hooks.l_ipo.process_pending_decls (input_location);
415 lang_hooks.l_ipo.clear_deferred_fns ();
416 at_eof = 0;
418 is_last = is_last_module (current_module_id);
420 last_funcdef_no = get_last_funcdef_no ();
421 if (last_funcdef_no > max_funcdef_no)
422 max_funcdef_no = last_funcdef_no;
424 lang_hooks.l_ipo.save_built_in_decl_post_module_parsing ();
425 /* Save primary module state if needed (when module group
426 size > 1) */
427 if (L_IPO_IS_PRIMARY_MODULE && num_in_fnames > 1)
429 save_assembler_name_reference_bit ();
430 primary_module_last_funcdef_no = last_funcdef_no;
433 if (!is_last)
435 /* More aux modules are anticipated, clear
436 the parsing state. */
437 gcc_assert (num_in_fnames > 1);
438 clear_assembler_name_reference_bit ();
439 clear_module_scope_bindings (current_module_scope);
440 /* Restore symtab bindings for builtins */
441 lang_hooks.l_ipo.restore_built_in_decl_pre_parsing ();
442 /* The map can not be cleared because the names of operator
443 decls are used to store the information about the conversion
444 target type. This forces the coversion operator ids to be
445 incremented across different modules, and assember id must
446 be used for checksum computation. */
447 /* cp_clear_conv_type_map (); */
449 else if (num_in_fnames > 1)
451 clear_module_scope_bindings (current_module_scope);
452 restore_post_parsing_states ();
454 else
455 gcc_assert (L_IPO_IS_PRIMARY_MODULE && num_in_fnames == 1);
459 /* Type merging support for LIPO */
461 struct type_ec
463 tree rep_type;
464 vec<tree> *eq_types;
467 static vec<tree> *pending_types = NULL;
468 static struct pointer_set_t *type_set = NULL;
469 static htab_t type_hash_tab = NULL;
471 /* Hash function for the type table. */
473 static hashval_t
474 type_hash_hash (const void *ent)
476 tree type, name;
477 const struct type_ec *const entry
478 = (const struct type_ec *) ent;
480 type = entry->rep_type;
481 name = TYPE_NAME (type);
482 if (DECL_P (name))
483 name = DECL_NAME (name);
485 return htab_hash_string (IDENTIFIER_POINTER (name));
488 /* Equality function for type hash table. */
490 static int
491 type_hash_eq (const void *ent1, const void *ent2)
493 tree type1, type2;
494 const struct type_ec *const entry1
495 = (const struct type_ec *) ent1;
496 const struct type_ec *const entry2
497 = (const struct type_ec *) ent2;
499 type1 = entry1->rep_type;
500 type2 = entry2->rep_type;
502 return aggr_has_equiv_id (type1, type2);
505 /* Function to delete type hash entries. */
507 static void
508 type_hash_del (void *ent)
510 struct type_ec *const entry
511 = (struct type_ec *) ent;
513 vec_free (entry->eq_types);
514 free (entry);
517 struct GTY(()) type_ent
519 tree type;
520 unsigned eq_id;
523 static GTY ((param_is (type_ent))) htab_t l_ipo_type_tab = 0;
524 static unsigned l_ipo_eq_id = 0;
526 /* Address hash function for struct type_ent. */
528 static hashval_t
529 type_addr_hash (const void *ent)
531 const struct type_ent *const entry
532 = (const struct type_ent *) ent;
533 return (hashval_t) (long) entry->type;
536 /* Address equality function for type_ent. */
538 static int
539 type_addr_eq (const void *ent1, const void *ent2)
541 const struct type_ent *const entry1
542 = (const struct type_ent *) ent1;
543 const struct type_ent *const entry2
544 = (const struct type_ent *) ent2;
545 return entry1->type == entry2->type;
548 /* Returns 1 if NS1 and NS2 refer to the same namespace. */
550 static int
551 is_ns_equiv (tree ns1, tree ns2)
553 tree n1, n2;
554 if (ns1 == NULL && ns2 == NULL)
555 return 1;
557 if ((!ns1 && ns2) || (ns1 && !ns2))
558 return 0;
560 gcc_assert (DECL_P (ns1) && DECL_P (ns2));
562 if (!is_ns_equiv (DECL_CONTEXT (ns1),
563 DECL_CONTEXT (ns2)))
564 return 0;
566 n1 = DECL_NAME (ns1);
567 n2 = DECL_NAME (ns2);
568 if (n1 == 0 && n2 == 0)
569 /* Conservative (which can happen when two NSes are from
570 different modules but with same UID) quivalence is allowed. */
571 return DECL_UID (ns1) == DECL_UID (ns2);
572 if (!n1 || !n2)
573 return 0;
575 if (!strcmp (IDENTIFIER_POINTER (n1),
576 IDENTIFIER_POINTER (n2)))
577 return 1;
579 return 0;
582 /* Returns 1 if aggregate type T1 and T2 have equivalent qualified
583 ids. */
585 static int
586 aggr_has_equiv_id (tree t1, tree t2)
588 int ctx_match;
589 tree ctx1, ctx2, tn1, tn2;
590 gcc_assert (TYPE_P (t1) && TYPE_P (t2));
592 ctx1 = TYPE_CONTEXT (t1);
593 ctx2 = TYPE_CONTEXT (t2);
595 if ((ctx1 && !ctx2) || (!ctx1 && ctx2))
596 return 0;
598 if (ctx1 && TREE_CODE (ctx1) != TREE_CODE (ctx2))
599 return 0;
601 if (ctx1 && (TREE_CODE (ctx1) == FUNCTION_DECL
602 || TREE_CODE (ctx1) == BLOCK))
603 return 0;
605 if (!ctx1)
607 ctx_match = 1;
608 gcc_assert (!ctx2);
610 else if (TREE_CODE (ctx1) == NAMESPACE_DECL)
611 ctx_match = is_ns_equiv (ctx1, ctx2);
612 else if (TYPE_P (ctx1))
613 ctx_match = aggr_has_equiv_id (ctx1, ctx2);
614 else
616 gcc_assert (TREE_CODE (ctx1) == TRANSLATION_UNIT_DECL);
617 ctx_match = 1;
620 if (!ctx_match)
621 return 0;
623 /* Now compare the name of the types. */
624 tn1 = TYPE_NAME (t1);
625 tn2 = TYPE_NAME (t2);
626 if ((tn1 && !tn2) || !(tn1 && tn2))
627 return 0;
628 else if (!tn1 && !tn2)
629 /* Be conservative on unamed types. */
630 return 1;
632 if (DECL_P (tn1))
633 tn1 = DECL_NAME (tn1);
634 if (DECL_P (tn2))
635 tn2 = DECL_NAME (tn2);
636 if (strcmp (IDENTIFIER_POINTER (tn1),
637 IDENTIFIER_POINTER (tn2)))
638 return 0;
640 return lang_hooks.l_ipo.cmp_lang_type (t1, t2);
643 /* Return the canonical type of the type's main variant. */
644 static inline tree
645 get_norm_type (const_tree type)
647 tree cano_type = TYPE_MAIN_VARIANT (type);
648 if (TYPE_CANONICAL (cano_type))
649 cano_type = TYPE_CANONICAL (cano_type);
651 return cano_type;
654 /* Return 1 if type T1 and T2 are equivalent. Struct/union/class
655 types are compared using qualified name ids. Alias sets of
656 equivalent types will be merged. Client code may choose to do
657 structural equivalence check for sanity. Note the difference
658 between the types_compatible_p (and its langhooks subroutines)
659 and this interface. The former is mainly used to remove useless
660 type conversion and value numbering computation. It returns 1
661 only when it is sure and should not be used in contexts where
662 erroneously returning 0 causes problems. This interface
663 lipo_cmp_type behaves differently - it returns 1 when it is not
664 sure -- as the primary purpose of the interface is for alias
665 set computation. */
668 lipo_cmp_type (tree t1, tree t2)
670 if (TREE_CODE (t1) != TREE_CODE (t2))
671 return 0;
672 if (TYPE_READONLY (t1) != TYPE_READONLY (t2))
673 return 0;
674 if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (t2))
675 return 0;
677 t1 = get_norm_type (t1);
678 t2 = get_norm_type (t2);
680 switch (TREE_CODE (t1))
682 case RECORD_TYPE:
683 case UNION_TYPE:
684 case QUAL_UNION_TYPE:
685 return aggr_has_equiv_id (t1, t2);
687 case POINTER_TYPE:
688 case REFERENCE_TYPE:
689 case COMPLEX_TYPE:
690 return lipo_cmp_type (TREE_TYPE (t1), TREE_TYPE (t2));
691 case ARRAY_TYPE:
692 return (TYPE_DOMAIN (t1) == NULL || TYPE_DOMAIN (t2) == NULL
693 || (lipo_cmp_type (TYPE_DOMAIN (t1), TYPE_DOMAIN (t2))
694 && lipo_cmp_type (TREE_TYPE (t1), TREE_TYPE (t2))));
695 case METHOD_TYPE:
696 return lipo_cmp_type (TYPE_METHOD_BASETYPE (t1),
697 TYPE_METHOD_BASETYPE (t2));
698 case FUNCTION_TYPE:
700 tree arg1, arg2;
701 for (arg1 = TYPE_ARG_TYPES (t1), arg2 = TYPE_ARG_TYPES (t2);
702 arg1 && arg2;
703 arg1 = TREE_CHAIN (arg1), arg2 = TREE_CHAIN (arg2))
704 if (!lipo_cmp_type (TREE_VALUE (arg1),
705 TREE_VALUE (arg2)))
706 return 0;
707 if (arg1 || arg2)
708 return 0;
709 return 1;
711 case OFFSET_TYPE:
712 return lipo_cmp_type (TYPE_OFFSET_BASETYPE (t1),
713 TYPE_OFFSET_BASETYPE (t2));
714 case ENUMERAL_TYPE:
715 return lipo_cmp_type (TREE_TYPE (t1), TREE_TYPE (t2));
716 case REAL_TYPE:
717 case FIXED_POINT_TYPE:
718 case INTEGER_TYPE:
719 return (TYPE_PRECISION (t1) == TYPE_PRECISION (t2)
720 && TYPE_MODE (t1) == TYPE_MODE (t2)
721 && TYPE_MIN_VALUE (t1) == TYPE_MIN_VALUE (t2)
722 && TYPE_MAX_VALUE (t1) == TYPE_MAX_VALUE (t2));
723 case VECTOR_TYPE:
724 return (TYPE_VECTOR_SUBPARTS (t1) == TYPE_VECTOR_SUBPARTS (t2)
725 && lipo_cmp_type (TREE_TYPE (t1), TREE_TYPE (t2)));
726 case VOID_TYPE:
727 case BOOLEAN_TYPE:
728 case NULLPTR_TYPE:
729 return 1;
730 case TEMPLATE_TYPE_PARM:
731 return 1;
732 default:
733 gcc_unreachable ();
737 #ifndef ANON_AGGRNAME_PREFIX
738 #define ANON_AGGRNAME_PREFIX "__anon_"
739 #endif
740 #ifndef ANON_AGGRNAME_P
741 #define ANON_AGGRNAME_P(ID_NODE) \
742 (!strncmp (IDENTIFIER_POINTER (ID_NODE), ANON_AGGRNAME_PREFIX, \
743 sizeof (ANON_AGGRNAME_PREFIX) - 1))
744 #endif
746 /* Callback function used in tree walk to find referenced struct types. */
748 static tree
749 find_struct_types (tree *tp,
750 int *walk_subtrees ATTRIBUTE_UNUSED,
751 void *data ATTRIBUTE_UNUSED)
753 if (!(*tp))
754 return NULL_TREE;
756 if (TYPE_P (*tp))
758 if (lang_hooks.l_ipo.is_compiler_generated_type (*tp))
759 return NULL_TREE;
761 switch (TREE_CODE (*tp))
763 case RECORD_TYPE:
764 case UNION_TYPE:
765 case QUAL_UNION_TYPE:
767 tree cano_type, name;
768 tree context;
769 tree field;
771 cano_type = get_norm_type (*tp);
772 name = TYPE_NAME (cano_type);
773 if (!name)
775 /* the main variant of typedef of unnamed struct
776 has no name, use the orignal type for equivalence. */
777 cano_type = *tp;
778 name = TYPE_NAME (cano_type);
780 if (!name)
781 return NULL_TREE;
782 if (DECL_P (name)
783 && (DECL_IGNORED_P (name)
784 || ANON_AGGRNAME_P (DECL_NAME (name))))
785 return NULL_TREE;
787 if (!pointer_set_insert (type_set, cano_type))
788 pending_types->safe_push (cano_type);
789 else
790 return NULL_TREE; /* Or use walk tree without dups. */
792 context = TYPE_CONTEXT (cano_type);
793 if (context && TYPE_P (context))
794 walk_tree (&context, find_struct_types, NULL, NULL);
796 /* Instantiate a nested work as the tree walker does not
797 get to the fields. */
798 if (TYPE_BINFO (cano_type))
800 int i;
801 tree binfo, base_binfo;
803 for (binfo = TYPE_BINFO (cano_type), i = 0;
804 BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
805 walk_tree (&BINFO_TYPE (base_binfo), find_struct_types,
806 NULL, NULL);
808 for (field = TYPE_FIELDS (cano_type);
809 field != 0;
810 field = TREE_CHAIN (field))
811 walk_tree (&TREE_TYPE (field), find_struct_types,
812 NULL, NULL);
813 return NULL_TREE;
815 default:
816 return NULL_TREE;
819 else if (DECL_P (*tp))
820 /* walk tree does not walk down decls, so do a nested walk here. */
821 walk_tree (&(TREE_TYPE (*tp)), find_struct_types, NULL, NULL);
823 return NULL_TREE;
826 /* Collect referenced struct types. */
828 static void
829 cgraph_collect_type_referenced (void)
831 basic_block bb;
832 gimple_stmt_iterator gi;
834 FOR_EACH_BB_FN (bb, cfun)
836 for (gi = gsi_start_bb (bb); !gsi_end_p (gi); gsi_next (&gi))
838 unsigned i;
839 gimple stmt = gsi_stmt (gi);
840 for (i = 0; i < gimple_num_ops (stmt); i++)
841 walk_tree (gimple_op_ptr (stmt, i), find_struct_types, NULL, NULL);
846 /* Check type equivalence. Returns 1 if T1 and T2 are equivalent
847 for tbaa; return 0 if not. -1 is returned if it is unknown. */
850 equivalent_struct_types_for_tbaa (const_tree t1, const_tree t2)
852 struct type_ent key, *tent1, *tent2, **slot;
854 if (!l_ipo_type_tab)
855 return -1;
857 t1 = get_norm_type (t1);
858 t2 = get_norm_type (t2);
860 key.type = (tree) (long) t1;
861 slot = (struct type_ent **)
862 htab_find_slot (l_ipo_type_tab, &key, NO_INSERT);
863 if (!slot || !*slot)
864 return -1;
865 tent1 = *slot;
867 key.type = (tree) (long) t2;
868 slot = (struct type_ent **)
869 htab_find_slot (l_ipo_type_tab, &key, NO_INSERT);
870 if (!slot || !*slot)
871 return -1;
872 tent2 = *slot;
874 return tent1->eq_id == tent2->eq_id;
877 /* Build type hash table. */
879 static void
880 cgraph_build_type_equivalent_classes (void)
882 unsigned n, i;
883 n = pending_types->length ();
884 for (i = 0; i < n; i++)
886 struct type_ec **slot;
887 struct type_ec te;
888 te.rep_type = (*pending_types)[i];
889 te.eq_types = NULL;
890 slot = (struct type_ec **) htab_find_slot (type_hash_tab,
891 &te, INSERT);
892 if (!*slot)
894 *slot = XCNEW (struct type_ec);
895 (*slot)->rep_type = te.rep_type;
896 vec_alloc ((*slot)->eq_types, 10);
898 (*slot)->eq_types->safe_push (te.rep_type);
902 /* Re-propagate component types's alias set to that of TYPE. PROCESSED
903 is the pointer set of processed types. */
905 static void
906 re_record_component_aliases (tree type,
907 struct pointer_set_t *processed)
909 alias_set_type superset = get_alias_set (type);
910 tree field;
912 if (superset == 0)
913 return;
915 if (pointer_set_insert (processed, type))
916 return;
918 switch (TREE_CODE (type))
920 case RECORD_TYPE:
921 case UNION_TYPE:
922 case QUAL_UNION_TYPE:
923 /* Recursively record aliases for the base classes, if there are any. */
924 if (TYPE_BINFO (type))
926 int i;
927 tree binfo, base_binfo;
929 for (binfo = TYPE_BINFO (type), i = 0;
930 BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
932 re_record_component_aliases (BINFO_TYPE (base_binfo),
933 processed);
934 record_alias_subset (superset,
935 get_alias_set (BINFO_TYPE (base_binfo)));
938 for (field = TYPE_FIELDS (type); field != 0; field = TREE_CHAIN (field))
939 if (TREE_CODE (field) == FIELD_DECL && !DECL_NONADDRESSABLE_P (field))
941 re_record_component_aliases (TREE_TYPE (field), processed);
942 record_alias_subset (superset, get_alias_set (TREE_TYPE (field)));
944 break;
946 case COMPLEX_TYPE:
947 re_record_component_aliases (TREE_TYPE (type), processed);
948 record_alias_subset (superset, get_alias_set (TREE_TYPE (type)));
949 break;
951 /* VECTOR_TYPE and ARRAY_TYPE share the alias set with their
952 element type. */
954 default:
955 break;
959 /* The callback function to merge alias sets of equivalent types. */
961 static int
962 type_eq_process (void **slot, void *data ATTRIBUTE_UNUSED)
964 unsigned i;
965 alias_set_type alias_set, ptr_alias_set = -1;
966 tree rep_type, type;
967 vec<tree> *eq_types;
968 struct type_ec ** te = (struct type_ec **)slot;
969 bool zero_set = false, ptr_zero_set = false;
970 struct type_ent **slot2, key, *tent;
973 rep_type = (*te)->rep_type;
974 eq_types = (*te)->eq_types;
975 alias_set = get_alias_set (rep_type);
977 for (i = 0; eq_types->iterate (i, &type); ++i)
979 alias_set_type als, ptr_als = -1;
980 tree type_ptr = TYPE_POINTER_TO (type);;
982 als = get_alias_set (type);
983 if (als == 0)
984 zero_set = true;
986 if (alias_set && als && alias_set != als)
987 record_alias_subset (alias_set, als);
989 if (type_ptr)
991 ptr_als = get_alias_set (type_ptr);
992 if (ptr_als == 0)
993 ptr_zero_set = true;
995 if (ptr_alias_set == -1)
996 ptr_alias_set = ptr_als;
997 else
999 if (!ptr_zero_set && ptr_alias_set != ptr_als)
1000 record_alias_subset (ptr_alias_set, ptr_als);
1005 /* Now propagate back. */
1006 for (i = 0; eq_types->iterate (i, &type); ++i)
1008 alias_set_type als, ptr_als;
1009 tree ptr_type = TYPE_POINTER_TO (type);
1011 als = get_alias_set (type);
1013 if (zero_set)
1014 TYPE_ALIAS_SET (type) = 0;
1015 else if (alias_set != als)
1016 record_alias_subset (als, alias_set);
1018 if (ptr_type)
1020 ptr_als = get_alias_set (ptr_type);
1021 if (ptr_zero_set)
1022 TYPE_ALIAS_SET (ptr_type) = 0;
1023 else if (ptr_alias_set != ptr_als)
1024 record_alias_subset (ptr_als, ptr_alias_set);
1029 /* Now populate the type table. */
1030 l_ipo_eq_id++;
1031 for (i = 0; eq_types->iterate (i, &type); ++i)
1033 key.type = type;
1034 slot2 = (struct type_ent **)
1035 htab_find_slot (l_ipo_type_tab, &key, INSERT);
1036 tent = *slot2;
1037 gcc_assert (!tent);
1038 tent = ggc_alloc_cleared_type_ent ();
1039 tent->type = key.type;
1040 tent->eq_id = l_ipo_eq_id;
1041 *slot2 = tent;
1044 return 1;
1047 /* Regenerate alias set for aggregate types. */
1049 static void
1050 record_components_for_parent_types (void)
1052 unsigned n, i;
1053 struct pointer_set_t *processed_types;
1055 processed_types = pointer_set_create ();
1056 n = pending_types->length ();
1057 for (i = 0; i < n; i++)
1059 tree type = (*pending_types)[i];
1060 re_record_component_aliases (type, processed_types);
1063 pointer_set_destroy (processed_types);
1066 /* Unify type alias sets for equivalent types. */
1068 void
1069 cgraph_unify_type_alias_sets (void)
1071 struct cgraph_node *node;
1072 struct varpool_node *pv;
1074 /* Only need to do type unification when we are in LIPO mode
1075 and have a non-trivial module group (size is >1). However,
1076 override the size check under non-zero PARAM_LIPO_RANDOM_GROUP_SIZE,
1077 which indicates that we are stress-testing LIPO. In that case
1078 try to flush out problems with type unification by always
1079 performing it. */
1080 if (!L_IPO_COMP_MODE
1081 || (num_in_fnames == 1
1082 && PARAM_VALUE (PARAM_LIPO_RANDOM_GROUP_SIZE) == 0))
1083 return;
1085 vec_alloc (pending_types, 100);
1086 type_set = pointer_set_create ();
1087 type_hash_tab = htab_create (10, type_hash_hash,
1088 type_hash_eq, type_hash_del);
1089 l_ipo_type_tab = htab_create_ggc (10, type_addr_hash,
1090 type_addr_eq, NULL);
1092 FOR_EACH_DEFINED_FUNCTION (node)
1094 if (!gimple_has_body_p (node->decl))
1095 continue;
1096 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
1097 current_function_decl = node->decl;
1098 if (gimple_has_body_p (current_function_decl))
1099 cgraph_collect_type_referenced ();
1100 current_function_decl = NULL;
1101 set_cfun (NULL);
1102 pop_cfun ();
1105 FOR_EACH_VARIABLE (pv)
1106 walk_tree (&pv->decl, find_struct_types, NULL, NULL);
1108 /* Compute type equivalent classes. */
1109 cgraph_build_type_equivalent_classes ();
1110 /* Now unify alias sets of equivelent types. */
1111 htab_traverse (type_hash_tab, type_eq_process, NULL);
1112 /* Finally re-populating parent's alias set. */
1113 record_components_for_parent_types ();
1115 pointer_set_destroy (type_set);
1116 vec_free (pending_types);
1117 htab_delete (type_hash_tab);
1120 /* Return true if NODE->decl from an auxiliary module has external
1121 definition (and therefore is not needed for expansion). */
1123 bool
1124 cgraph_is_aux_decl_external (struct cgraph_node *node)
1126 tree decl = node->decl;
1128 if (!L_IPO_COMP_MODE)
1129 return false;
1131 if (!cgraph_is_auxiliary (decl))
1132 return false;
1134 /* Versioned clones from auxiliary moduels are not external. */
1135 if (node->is_versioned_clone)
1136 return false;
1138 /* Comdat or weak functions in aux modules are not external --
1139 there is no guarantee that the definitition will be emitted
1140 in the primary compilation of this auxiliary module. */
1141 if (DECL_COMDAT (decl) || DECL_WEAK (decl))
1142 return false;
1144 /* virtual functions won't be deleted in the primary module. */
1145 if (DECL_VIRTUAL_P (decl))
1146 return true;
1148 if (!TREE_PUBLIC (decl))
1149 return false;
1151 /* The others from aux modules are external. */
1152 return true;
1155 /* Linked function symbol (cgraph node) table. */
1156 static GTY((param_is (cgraph_sym))) htab_t cgraph_symtab;
1158 /* This is true when global linking is needed and performed (for C++).
1159 For C, symbol linking is performed on the fly during parsing, and
1160 the cgraph_symtab is used only for keeping additional information
1161 for any already merged symbol if needed. */
1163 static bool global_link_performed = 0;
1165 /* For an external (non-defined) function DECL, return the primary
1166 module id (even though when the declaration is declared in an aux
1167 module). For a defined function DECL, return the module id in which
1168 it is defined. */
1170 unsigned
1171 cgraph_get_module_id (tree decl)
1173 struct function *func = DECL_STRUCT_FUNCTION (decl);
1174 /* Not defined. */
1175 if (!func)
1176 return primary_module_id;
1177 return FUNC_DECL_MODULE_ID (func);
1180 /* Return true if function decl is defined in an auxiliary module. */
1182 bool
1183 cgraph_is_auxiliary (tree decl)
1185 return (cgraph_get_module_id (decl) != primary_module_id);
1188 /* Return the hash value for cgraph_sym pointed to by P. The
1189 hash value is computed using function's assembler name. */
1191 static hashval_t
1192 hash_sym_by_assembler_name (const void *p)
1194 const struct cgraph_sym *n = (const struct cgraph_sym *) p;
1195 return (hashval_t) decl_assembler_name_hash (n->assembler_name);
1198 /* Return nonzero if P1 and P2 are equal. */
1200 static int
1201 eq_assembler_name (const void *p1, const void *p2)
1203 const struct cgraph_sym *n1 = (const struct cgraph_sym *) p1;
1204 const_tree name = (const_tree) p2;
1205 return (decl_assembler_name_equal (n1->rep_decl, name));
1208 /* Return the cgraph_sym for function declaration DECL. */
1210 static struct cgraph_sym **
1211 cgraph_sym (tree decl)
1213 struct cgraph_sym **slot;
1214 tree name;
1216 if (!cgraph_symtab)
1218 gcc_assert (!global_link_performed);
1219 return NULL;
1222 name = DECL_ASSEMBLER_NAME (decl);
1223 slot = (struct cgraph_sym **)
1224 htab_find_slot_with_hash (cgraph_symtab, name,
1225 decl_assembler_name_hash (name),
1226 NO_INSERT);
1227 return slot;
1230 /* Return the representative declaration for assembler name
1231 ASM_NAME. */
1233 tree
1234 cgraph_find_decl (tree asm_name)
1236 struct cgraph_sym **slot;
1237 if (!L_IPO_COMP_MODE)
1238 return NULL;
1239 if (!cgraph_symtab || !global_link_performed)
1240 return NULL;
1242 slot = (struct cgraph_sym **)
1243 htab_find_slot_with_hash (cgraph_symtab, asm_name,
1244 decl_assembler_name_hash (asm_name),
1245 NO_INSERT);
1246 if (!slot || !*slot)
1247 return NULL;
1249 return (*slot)->rep_node->decl;
1252 /* Return true if function declaration DECL is originally file scope
1253 static, which is promoted to global scope. */
1255 bool
1256 cgraph_is_promoted_static_func (tree decl)
1258 struct cgraph_sym ** sym;
1259 gcc_assert (L_IPO_COMP_MODE);
1261 /* cgraph_symtab will be created when any symbol got
1262 promoted. */
1263 if (!cgraph_symtab)
1264 return false;
1266 sym = cgraph_sym (decl);
1267 if (!sym)
1268 return false;
1269 return (*sym)->is_promoted_static;
1272 /* Hash function for module information table. ENT
1273 is a pointer to a cgraph_module_info. */
1275 static hashval_t
1276 htab_sym_hash (const void *ent)
1278 const struct cgraph_mod_info * const mi
1279 = (const struct cgraph_mod_info * const ) ent;
1280 return (hashval_t) mi->module_id;
1283 /* Hash equality function for module information table. */
1285 static int
1286 htab_sym_eq (const void *ent1, const void *ent2)
1288 const struct cgraph_mod_info * const mi1
1289 = (const struct cgraph_mod_info * const ) ent1;
1290 const struct cgraph_mod_info * const mi2
1291 = (const struct cgraph_mod_info * const ) ent2;
1292 return (mi1->module_id == mi2->module_id);
1295 /* cgraph_sym SYM may be defined in more than one source modules.
1296 Add declaration DECL's definiting module to SYM. */
1298 static void
1299 add_define_module (struct cgraph_sym *sym, tree decl)
1301 unsigned module_id;
1302 struct cgraph_mod_info **slot;
1303 struct cgraph_mod_info mi;
1305 struct function *f = DECL_STRUCT_FUNCTION (decl);
1306 if (!f)
1307 return;
1308 module_id = FUNC_DECL_MODULE_ID (f);
1310 if (!sym->def_module_hash)
1311 sym->def_module_hash
1312 = htab_create_ggc (10, htab_sym_hash, htab_sym_eq, NULL);
1314 mi.module_id = module_id;
1315 slot = (struct cgraph_mod_info **)htab_find_slot (sym->def_module_hash,
1316 &mi, INSERT);
1317 if (!*slot)
1319 *slot = ggc_alloc_cleared_cgraph_mod_info ();
1320 (*slot)->module_id = module_id;
1322 else
1323 gcc_assert ((*slot)->module_id == module_id);
1326 static int
1327 add_def_module (void **slot, void *data)
1329 struct cgraph_mod_info **m = (struct cgraph_mod_info **)slot;
1330 htab_t mod_set = (htab_t) data;
1331 struct cgraph_mod_info **new_slot;
1333 new_slot = (struct cgraph_mod_info **)htab_find_slot (mod_set, *m, INSERT);
1334 if (!*new_slot)
1336 *new_slot = ggc_alloc_cleared_cgraph_mod_info ();
1337 (*new_slot)->module_id = (*m)->module_id;
1339 else
1340 gcc_assert ((*new_slot)->module_id == (*m)->module_id);
1341 return 1;
1344 /* Clone defined module hash table from ORIG to CLONE. */
1346 void
1347 copy_defined_module_set (tree clone, tree orig)
1349 struct cgraph_sym **orig_sym, **clone_sym;
1351 orig_sym = cgraph_sym (orig);
1352 clone_sym = cgraph_sym (clone);
1353 if (!orig_sym || !(*orig_sym)->def_module_hash)
1354 return;
1355 if (!(*clone_sym)->def_module_hash)
1356 (*clone_sym)->def_module_hash
1357 = htab_create_ggc (10, htab_sym_hash, htab_sym_eq, NULL);
1358 htab_traverse ((*orig_sym)->def_module_hash, add_def_module, (*clone_sym)->def_module_hash);
1361 /* Return true if the symbol associated with DECL is defined in module
1362 MODULE_ID. This interface is used by the inliner to make sure profile-gen
1363 and profile-use pass (L-IPO mode) make consistent inline decision. */
1365 bool
1366 cgraph_is_inline_body_available_in_module (tree decl, unsigned module_id)
1368 struct cgraph_sym **sym;
1369 void **slot;
1370 struct cgraph_mod_info mi;
1372 gcc_assert (L_IPO_COMP_MODE);
1374 if (DECL_BUILT_IN (decl))
1375 return true;
1377 /* TODO: revisit this. */
1378 if (DECL_IN_SYSTEM_HEADER (decl) && DECL_DECLARED_INLINE_P (decl))
1379 return true;
1381 gcc_assert (TREE_STATIC (decl) || DECL_DECLARED_INLINE_P (decl));
1383 if (cgraph_get_module_id (decl) == module_id)
1384 return true;
1386 sym = cgraph_sym (decl);
1387 if (!sym || !(*sym)->def_module_hash)
1388 return false;
1390 mi.module_id = module_id;
1391 slot = htab_find_slot ((*sym)->def_module_hash, &mi, NO_INSERT);
1392 if (slot)
1394 gcc_assert (((struct cgraph_mod_info*)*slot)->module_id == module_id);
1395 return true;
1397 return false;
1400 /* Return the linked cgraph node using DECL's assembler name. DO_ASSERT
1401 is a flag indicating that a non null link target must be returned. */
1403 struct cgraph_node *
1404 cgraph_lipo_get_resolved_node_1 (tree decl, bool do_assert)
1406 struct cgraph_sym **slot;
1408 /* Handle alias decl. */
1409 slot = cgraph_sym (decl);
1411 if (!slot || !*slot)
1413 if (!do_assert)
1414 return NULL;
1415 else
1417 /* Nodes that are indirectly called are not 'reachable' in
1418 the callgraph. If they are not needed (comdat, inline
1419 extern etc), they may be removed from the link table
1420 before direct calls to them are exposed (via indirect
1421 call promtion by const folding etc). When this happens,
1422 the node will need to be relinked. A probably better fix
1423 is to modify the callgraph so that they are not eliminated
1424 in the first place -- this will allow inlining to happen. */
1426 struct cgraph_node *n = cgraph_get_create_node (decl);
1427 if (!n->analyzed)
1429 gcc_assert (DECL_EXTERNAL (decl)
1430 || cgraph_is_aux_decl_external (n)
1431 || DECL_VIRTUAL_P (decl));
1432 gcc_assert (/* This is the case for explicit extern instantiation,
1433 when cgraph node is not created before link. */
1434 DECL_EXTERNAL (decl));
1435 cgraph_link_node (n);
1436 return n;
1438 else
1439 gcc_unreachable ();
1442 else
1444 struct cgraph_sym *sym = *slot;
1445 return sym->rep_node;
1449 /* Return the cgraph_node of DECL if decl has definition; otherwise return
1450 the cgraph node of the representative decl, which is the declaration DECL
1451 is resolved to after linking/symbol resolution. */
1453 struct cgraph_node *
1454 cgraph_lipo_get_resolved_node (tree decl)
1456 struct cgraph_node *node = NULL;
1458 gcc_assert (L_IPO_COMP_MODE && global_link_performed);
1459 gcc_assert (cgraph_symtab);
1461 /* Never merged. */
1462 if (!TREE_PUBLIC (decl) || DECL_ARTIFICIAL (decl)
1463 /* builtin function decls are shared across modules, but 'linking'
1464 is still performed for them to keep track of the set of defining
1465 modules. Skip the real resolution here to avoid merging '__builtin_xxx'
1466 with 'xxx'. */
1467 || DECL_BUILT_IN (decl))
1468 return cgraph_get_create_node (decl);
1470 node = cgraph_lipo_get_resolved_node_1 (decl, true);
1471 return node;
1474 /* When NODE->decl is dead function eliminated,
1475 remove the entry in the link table. */
1477 void
1478 cgraph_remove_link_node (struct cgraph_node *node)
1480 tree name, decl;
1482 if (!L_IPO_COMP_MODE || !cgraph_symtab)
1483 return;
1485 decl = node->decl;
1487 /* Skip nodes that are not in the link table. */
1488 if (!TREE_PUBLIC (decl) || DECL_ARTIFICIAL (decl))
1489 return;
1491 /* Skip if node is an inline clone or if the node has
1492 defintion that is not really resolved to the merged node. */
1493 if (cgraph_lipo_get_resolved_node_1 (decl, false) != node)
1494 return;
1496 name = DECL_ASSEMBLER_NAME (decl);
1497 htab_remove_elt_with_hash (cgraph_symtab, name,
1498 decl_assembler_name_hash (name));
1501 /* Return true if the function body for DECL has profile information. */
1503 static bool
1504 has_profile_info (tree decl)
1506 gcov_type *ctrs = NULL;
1507 unsigned n;
1508 struct function* f = DECL_STRUCT_FUNCTION (decl);
1510 ctrs = get_coverage_counts_no_warn (f, GCOV_COUNTER_ARCS, &n);
1511 if (ctrs)
1513 unsigned i;
1514 for (i = 0; i < n; i++)
1515 if (ctrs[i])
1516 return true;
1519 return false;
1522 /* Resolve delaration NODE->decl for function symbol *SLOT. */
1524 static void
1525 resolve_cgraph_node (struct cgraph_sym **slot, struct cgraph_node *node)
1527 tree decl1, decl2;
1528 int decl1_defined = 0;
1529 int decl2_defined = 0;
1531 decl1 = (*slot)->rep_decl;
1532 decl2 = node->decl;
1534 decl1_defined = gimple_has_body_p (decl1);
1535 decl2_defined = gimple_has_body_p (decl2);
1537 if (decl1_defined && !decl2_defined)
1538 return;
1540 if (!decl1_defined && decl2_defined)
1542 (*slot)->rep_node = node;
1543 (*slot)->rep_decl = decl2;
1544 add_define_module (*slot, decl2);
1545 return;
1548 if (decl2_defined)
1550 bool has_prof1 = false;
1551 bool has_prof2 = false;
1552 gcc_assert (decl1_defined);
1553 add_define_module (*slot, decl2);
1555 has_prof1 = has_profile_info (decl1);
1556 if (has_prof1)
1557 return;
1558 has_prof2 = has_profile_info (decl2);
1559 if (has_prof2)
1561 (*slot)->rep_node = node;
1562 (*slot)->rep_decl = decl2;
1564 return;
1567 /* Handle aliases properly. Make sure the alias symbol resolution
1568 is consistent with alias target */
1569 if (node->alias && !node->thunk.thunk_p)
1571 struct cgraph_node *decl2_tgt = cgraph_function_or_thunk_node (node, NULL);
1572 if (cgraph_lipo_get_resolved_node_1 (decl2_tgt->decl, false) == decl2_tgt)
1574 (*slot)->rep_node = node;
1575 (*slot)->rep_decl = decl2;
1578 return;
1582 /* Resolve NODE->decl in the function symbol table. */
1584 struct cgraph_sym *
1585 cgraph_link_node (struct cgraph_node *node)
1587 void **slot;
1588 tree name;
1590 if (!L_IPO_COMP_MODE)
1591 return NULL;
1593 if (!cgraph_symtab)
1594 return NULL;
1596 /* Skip the cases when the defintion can be locally resolved, and
1597 when we do not need to keep track of defining modules. */
1598 if (!TREE_PUBLIC (node->decl) || DECL_ARTIFICIAL (node->decl))
1599 return NULL;
1601 name = DECL_ASSEMBLER_NAME (node->decl);
1602 slot = htab_find_slot_with_hash (cgraph_symtab, name,
1603 decl_assembler_name_hash (name),
1604 INSERT);
1605 if (*slot)
1606 resolve_cgraph_node ((struct cgraph_sym **) slot, node);
1607 else
1609 struct cgraph_sym *sym = ggc_alloc_cleared_cgraph_sym ();
1610 sym->rep_node = node;
1611 sym->rep_decl = node->decl;
1612 sym->assembler_name = name;
1613 add_define_module (sym, node->decl);
1614 *slot = sym;
1616 return (struct cgraph_sym *) *slot;
1619 /* Perform cross module linking of function declarations. */
1621 void
1622 cgraph_do_link (void)
1624 struct cgraph_node *node;
1626 if (!L_IPO_COMP_MODE)
1627 return;
1629 global_link_performed = 1;
1630 gcc_assert (cgraph_pre_profiling_inlining_done);
1632 if (!cgraph_symtab)
1633 cgraph_symtab
1634 = htab_create_ggc (10, hash_sym_by_assembler_name,
1635 eq_assembler_name, NULL);
1637 FOR_EACH_FUNCTION (node)
1639 gcc_assert (!node->global.inlined_to);
1640 /* Delay aliases */
1641 if (node->alias && !node->thunk.thunk_p)
1642 continue;
1643 cgraph_link_node (node);
1646 /* Now handle aliases */
1647 FOR_EACH_FUNCTION (node)
1649 if (node->alias && !node->thunk.thunk_p)
1650 cgraph_link_node (node);
1654 struct promo_ent
1656 char* assemb_name;
1657 tree decl;
1658 int seq;
1661 /* Hash function for promo_ent table. */
1663 static hashval_t
1664 promo_ent_hash (const void *ent)
1666 const struct promo_ent *const entry
1667 = (const struct promo_ent *) ent;
1669 return htab_hash_string (entry->assemb_name);
1672 /* Hash_eq function for promo_ent table. */
1674 static int
1675 promo_ent_eq (const void *ent1, const void *ent2)
1677 const struct promo_ent *const entry1
1678 = (const struct promo_ent *) ent1;
1679 const struct promo_ent *const entry2
1680 = (const struct promo_ent *) ent2;
1681 if (!strcmp (entry1->assemb_name, entry2->assemb_name))
1682 return 1;
1683 return 0;
1686 /* Delete function for promo_ent hash table. */
1688 static void
1689 promo_ent_del (void *ent)
1691 struct promo_ent *const entry
1692 = (struct promo_ent *) ent;
1694 free (entry->assemb_name);
1695 free (entry);
1698 static htab_t promo_ent_hash_tab = NULL;
1700 /* Make the var decl for weak symbol as extern. */
1702 static inline void
1703 externalize_weak_decl (tree decl)
1705 gcc_assert (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl));
1707 DECL_EXTERNAL (decl) = 1;
1708 TREE_STATIC (decl) = 0;
1709 DECL_INITIAL (decl) = NULL;
1711 /* Keep the context so that devirt_variable_node_removal_hook
1712 can do cleanup properly for vtables.
1713 DECL_CONTEXT (decl) = NULL; */
1716 /* Return a unique sequence number for NAME. This is needed to avoid
1717 name conflict -- function scope statics may have identical names.
1719 When DECL is NULL,
1720 this function returns a zero sequence number if it is called with
1721 a particular NAME for the first time, and non-zero otherwise.
1722 This fact is used to keep track of unseen weak variables.
1724 When DECL is not NULL, this function is supposed to be called by
1725 varpool_remove_duplicate_weak_decls. */
1727 static int
1728 get_name_seq_num (const char *name, tree decl)
1730 struct promo_ent **slot;
1731 struct promo_ent ent;
1732 int ret = 0;
1734 gcc_assert (!decl || TREE_CODE (decl) == VAR_DECL);
1735 ent.assemb_name = xstrdup (name);
1736 ent.seq = 0;
1738 slot = (struct promo_ent **)
1739 htab_find_slot (promo_ent_hash_tab, &ent, INSERT);
1741 if (!*slot)
1743 *slot = XCNEW (struct promo_ent);
1744 (*slot)->assemb_name = ent.assemb_name;
1745 (*slot)->decl = decl;
1747 else
1749 /* During output, the previously selected weak decl may not be
1750 referenced by any function that is expanded thus they do not have
1751 DECL_RTL_SET_P to be true and therefore can be eliminated by
1752 varpool_remove_unreferenced_decls later. To avoid that, logic is
1753 added to replace previously selected decl when needed. */
1754 if (decl && DECL_RTL_SET_P (decl)
1755 && !DECL_RTL_SET_P ((*slot)->decl))
1757 externalize_weak_decl ((*slot)->decl);
1758 (*slot)->decl = decl;
1759 ret = 0;
1761 else
1762 ret = ++(*slot)->seq;
1763 free (ent.assemb_name);
1765 return ret;
1768 /* Returns a unique assembler name for DECL. */
1770 static tree
1771 create_unique_name (tree decl, unsigned module_id)
1773 tree id, assemb_id;
1774 char *assembler_name;
1775 const char *name;
1776 struct function *context = NULL;
1777 int seq = 0;
1779 if (TREE_CODE (decl) == FUNCTION_DECL)
1781 if (!DECL_CONTEXT (decl)
1782 || TREE_CODE (DECL_CONTEXT (decl)) == TRANSLATION_UNIT_DECL)
1784 id = DECL_NAME (decl);
1785 /* if (IDENTIFIER_OPNAME_P (id)) */
1786 if (TREE_LANG_FLAG_2 (id))
1787 id = DECL_ASSEMBLER_NAME (decl);
1789 else
1790 id = DECL_ASSEMBLER_NAME (decl);
1792 else
1794 if (!DECL_CONTEXT (decl))
1795 id = DECL_NAME (decl);
1796 else if (TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
1797 id = DECL_ASSEMBLER_NAME (decl);
1798 else if (TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL)
1800 id = DECL_NAME (decl);
1801 context = DECL_STRUCT_FUNCTION (DECL_CONTEXT (decl));
1803 else
1804 /* file scope context */
1805 id = DECL_NAME (decl);
1808 name = IDENTIFIER_POINTER (id);
1809 if (context)
1811 char *n;
1812 unsigned fno = FUNC_DECL_FUNC_ID (context);
1813 n = (char *)alloca (strlen (name) + 15);
1814 sprintf (n, "%s.%u", name, fno);
1815 name = n;
1818 assembler_name = (char*) alloca (strlen (name) + 30);
1819 sprintf (assembler_name, "%s.cmo.%u", name, module_id);
1820 seq = get_name_seq_num (assembler_name, NULL);
1821 if (seq)
1822 sprintf (assembler_name, "%s.%d", assembler_name, seq);
1824 assemb_id = get_identifier (assembler_name);
1826 return assemb_id;
1829 /* Promote DECL to be global. MODULE_ID is the id of the module where
1830 DECL is defined. IS_EXTERN is a flag indicating if externalization
1831 is needed. */
1833 static void
1834 promote_static_var_func (unsigned module_id, tree decl, bool is_extern)
1836 tree assemb_id;
1837 tree alias;
1839 /* No need to promote symbol alias. */
1840 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
1841 if (alias)
1842 return;
1844 /* Function decls in C++ may contain characters not taken by assembler.
1845 Similarly, function scope static variable has UID as the assembler name
1846 suffix which is not consistent across modules. */
1847 assemb_id = create_unique_name (decl, module_id);
1849 if (DECL_ASSEMBLER_NAME_SET_P (decl))
1851 if (TREE_CODE (decl) == FUNCTION_DECL)
1852 unlink_from_assembler_name_hash (cgraph_get_create_node (decl),
1853 false);
1854 else
1855 unlink_from_assembler_name_hash (varpool_get_node (decl), false);
1858 SET_DECL_ASSEMBLER_NAME (decl, assemb_id);
1859 TREE_PUBLIC (decl) = 1;
1860 DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
1861 DECL_VISIBILITY_SPECIFIED (decl) = 1;
1863 if (TREE_CODE (decl) == FUNCTION_DECL)
1865 struct cgraph_node *node = cgraph_get_create_node (decl);
1867 node->resolution = LDPR_UNKNOWN;
1868 insert_to_assembler_name_hash (node, false);
1870 else
1872 struct varpool_node *node = varpool_get_node (decl);
1873 node->resolution = LDPR_UNKNOWN;
1874 /* Statics from exported primary module are very likely
1875 referenced by other modules, so they should be made
1876 externally visible (to be avoided to be localized again).
1877 Another way to do this is to set force_output bit or
1878 change the logic in varpool_externally_visible in ipa.c. */
1879 if (!is_extern)
1881 node->resolution = LDPR_PREVAILING_DEF;
1882 node->externally_visible = true;
1884 varpool_link_node (node);
1885 insert_to_assembler_name_hash (node, false);
1888 if (is_extern)
1890 if (TREE_CODE (decl) == VAR_DECL)
1892 TREE_STATIC (decl) = 0;
1893 DECL_EXTERNAL (decl) = 1;
1894 /* Keep the initializer to allow const prop. */
1895 /* DECL_INITIAL (decl) = 0; */
1896 /* Keep the context so that devirt_variable_node_removal_hook
1897 can do cleanup properly for vtables.
1898 DECL_CONTEXT (decl) = 0; */
1900 /* else
1901 Function body will be deleted later before expansion. */
1903 else
1904 TREE_STATIC (decl) = 1;
1907 /* Externalize global variables from aux modules and promote
1908 static variables.
1909 WEAK variables are treated especially in
1910 varpool_remove_duplicate_weak_decls. */
1912 static void
1913 process_module_scope_static_var (struct varpool_node *vnode)
1915 tree decl = vnode->decl;
1917 if (varpool_is_auxiliary (vnode))
1919 gcc_assert (vnode->module_id != primary_module_id);
1920 if (TREE_PUBLIC (decl))
1922 /* Externalize non-weak variables. */
1923 if (!DECL_WEAK (decl))
1925 DECL_EXTERNAL (decl) = 1;
1926 TREE_STATIC (decl) = 0;
1927 /* Keep the initializer to allow const prop. */
1928 /* DECL_INITIAL (decl) = NULL; */
1929 if (DECL_CONTEXT (decl))
1931 DECL_ASSEMBLER_NAME (decl);
1933 /* Keep the context so that devirt_variable_node_removal_hook
1934 can do cleanup properly for vtables.
1935 DECL_CONTEXT (decl) = NULL; */
1938 else
1940 /* Promote static vars to global. */
1941 if (vnode->module_id)
1942 promote_static_var_func (vnode->module_id, decl,
1943 varpool_is_auxiliary (vnode));
1946 else
1948 if (PRIMARY_MODULE_EXPORTED && !TREE_PUBLIC (decl))
1949 promote_static_var_func (vnode->module_id, decl,
1950 varpool_is_auxiliary (vnode));
1954 /* Promote all aliases of CNODE. */
1956 static void
1957 promote_function_aliases (struct cgraph_node *cnode, unsigned mod_id,
1958 bool is_extern)
1960 int i;
1961 struct ipa_ref *ref;
1963 for (i = 0; ipa_ref_list_referring_iterate (&cnode->ref_list, i, ref);
1964 i++)
1966 if (ref->use == IPA_REF_ALIAS)
1968 struct cgraph_node *alias = ipa_ref_referring_node (ref);
1969 tree alias_decl = alias->decl;
1970 /* Should assert */
1971 if (cgraph_get_module_id (alias_decl) == mod_id)
1972 promote_static_var_func (mod_id, alias_decl, is_extern);
1977 /* Promote static function CNODE->decl to be global. */
1979 static void
1980 process_module_scope_static_func (struct cgraph_node *cnode)
1982 tree decl = cnode->decl;
1983 bool addr_taken;
1984 unsigned mod_id;
1985 struct ipa_ref *ref;
1986 int i;
1988 if (TREE_PUBLIC (decl)
1989 || !TREE_STATIC (decl)
1990 || DECL_EXTERNAL (decl)
1991 || DECL_ARTIFICIAL (decl))
1992 return;
1994 if (flag_ripa_no_promote_always_inline
1995 && lookup_attribute ("always_inline", DECL_ATTRIBUTES (decl)) != NULL)
1996 return;
1998 /* Can be local -- the promotion pass need to be done after
1999 callgraph build when address taken bit is set. */
2000 addr_taken = cnode->address_taken;
2001 if (!addr_taken)
2003 for (i = 0; ipa_ref_list_referring_iterate (&cnode->ref_list, i, ref);
2004 i++)
2005 if (ref->use == IPA_REF_ALIAS)
2007 struct cgraph_node *alias = ipa_ref_referring_node (ref);
2008 if (alias->address_taken)
2009 addr_taken = true;
2012 if (!addr_taken)
2014 tree assemb_id = create_unique_name (decl, cgraph_get_module_id (decl));
2016 if (DECL_ASSEMBLER_NAME_SET_P (decl))
2017 unlink_from_assembler_name_hash (cnode, false);
2018 SET_DECL_ASSEMBLER_NAME (decl, assemb_id);
2019 insert_to_assembler_name_hash (cnode, false);
2020 return;
2023 mod_id = cgraph_get_module_id (decl);
2024 if (cgraph_is_auxiliary (decl))
2026 gcc_assert (mod_id != primary_module_id);
2027 /* Promote static function to global. */
2028 if (mod_id)
2030 promote_static_var_func (mod_id, decl, 1);
2031 promote_function_aliases (cnode, mod_id, 1);
2034 else
2036 if (PRIMARY_MODULE_EXPORTED
2037 /* skip static_init routines. */
2038 && !DECL_ARTIFICIAL (decl))
2040 promote_static_var_func (mod_id, decl, 0);
2042 promote_function_aliases (cnode, mod_id, 0);
2047 /* Process var_decls, func_decls with static storage. */
2049 void
2050 cgraph_process_module_scope_statics (void)
2052 struct cgraph_node *pf;
2053 struct varpool_node *pv;
2055 if (!L_IPO_COMP_MODE)
2056 return;
2058 promo_ent_hash_tab = htab_create (10, promo_ent_hash,
2059 promo_ent_eq, promo_ent_del);
2061 /* Process variable first. */
2062 FOR_EACH_DEFINED_VARIABLE (pv)
2063 process_module_scope_static_var (pv);
2065 FOR_EACH_FUNCTION (pf)
2066 process_module_scope_static_func (pf);
2068 htab_delete (promo_ent_hash_tab);
2071 /* There could be duplicate non-extern WEAK decls in the varpool queue,
2072 coming from different modules. All but one of these need to be externalized
2073 and removed from the varpool queue.
2074 Duplicate WEAK decls can be added to varpool queue as late as
2075 cgraph_expand_function, when a WEAK decl is marked referenced as assembler
2076 is being output. Therefore, a call to this function should be made after
2077 cgraph_expand_function. */
2079 void
2080 varpool_remove_duplicate_weak_decls (void)
2082 struct varpool_node *node = NULL;
2084 if (!L_IPO_COMP_MODE)
2085 return;
2087 promo_ent_hash_tab = htab_create (10, promo_ent_hash,
2088 promo_ent_eq, promo_ent_del);
2090 FOR_EACH_VARIABLE (node)
2092 tree decl = node->decl;
2094 if (TREE_PUBLIC (decl) && DECL_WEAK (decl) && !DECL_EXTERNAL (decl)
2095 && get_name_seq_num (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), decl))
2096 externalize_weak_decl (decl);
2099 htab_delete (promo_ent_hash_tab);
2102 static GTY((param_is (symtab_node))) htab_t varpool_symtab;
2104 /* Hash function for varpool node. */
2106 static hashval_t
2107 hash_node_by_assembler_name (const void *p)
2109 const struct varpool_node *n = (const struct varpool_node *) p;
2110 return (hashval_t) decl_assembler_name_hash (
2111 DECL_ASSEMBLER_NAME (n->decl));
2114 /* Returns nonzero if P1 and P2 are equal. */
2116 static int
2117 eq_node_assembler_name (const void *p1, const void *p2)
2119 const struct varpool_node *n1 = (const struct varpool_node *) p1;
2120 const_tree name = (const_tree)p2;
2121 return (decl_assembler_name_equal (n1->decl, name));
2124 /* Return true if NODE's decl is declared in an auxiliary module. */
2126 bool
2127 varpool_is_auxiliary (struct varpool_node *node)
2129 return (node->module_id
2130 && node->module_id != primary_module_id);
2133 /* Return the varpool_node to which DECL is resolved to during linking.
2134 This method can not be used after static to global promotion happens. */
2136 static struct varpool_node *
2137 real_varpool_node_1 (tree decl, bool assert)
2139 void **slot;
2140 tree name;
2142 if (!L_IPO_COMP_MODE || !varpool_symtab)
2143 return varpool_get_node (decl);
2145 if (!TREE_PUBLIC (decl) || DECL_ARTIFICIAL (decl))
2146 return varpool_get_node (decl);
2148 name = DECL_ASSEMBLER_NAME (decl);
2149 slot = htab_find_slot_with_hash (varpool_symtab, name,
2150 decl_assembler_name_hash (name),
2151 NO_INSERT);
2152 if (!slot)
2154 gcc_assert (!assert);
2155 return NULL;
2158 gcc_assert (slot && *slot);
2159 return (struct varpool_node *)*slot;
2162 struct varpool_node *
2163 real_varpool_node (tree decl)
2165 return real_varpool_node_1 (decl, true);
2168 /* Remove NODE from the link table. */
2170 void
2171 varpool_remove_link_node (struct varpool_node *node)
2173 tree name;
2174 tree decl;
2176 if (!L_IPO_COMP_MODE || !varpool_symtab)
2177 return;
2179 decl = node->decl;
2181 if (!TREE_PUBLIC (decl) || DECL_ARTIFICIAL (decl))
2182 return;
2184 if (real_varpool_node_1 (decl, false) != node)
2185 return;
2187 name = DECL_ASSEMBLER_NAME (decl);
2188 htab_remove_elt_with_hash (varpool_symtab, name,
2189 decl_assembler_name_hash (name));
2192 /* Merge the addressable attribute from DECL2 to DECL1. */
2194 static inline void
2195 merge_addressable_attr (tree decl1, tree decl2)
2197 if (TREE_ADDRESSABLE (decl2))
2198 TREE_ADDRESSABLE (decl1) = 1;
2201 /* Resolve NODE->decl to symbol table entry *SLOT. */
2203 static void
2204 resolve_varpool_node (struct varpool_node **slot, struct varpool_node *node)
2206 tree decl1, decl2;
2208 decl1 = (*slot)->decl;
2209 decl2 = node->decl;
2211 /* Take the decl with the complete type. */
2212 if (COMPLETE_TYPE_P (TREE_TYPE (decl1))
2213 && !COMPLETE_TYPE_P (TREE_TYPE (decl2)))
2215 merge_addressable_attr (decl1, decl2);
2216 return;
2218 if (!COMPLETE_TYPE_P (TREE_TYPE (decl1))
2219 && COMPLETE_TYPE_P (TREE_TYPE (decl2)))
2221 *slot = node;
2222 merge_addressable_attr (decl2, decl1);
2223 return;
2226 if (DECL_INITIAL (decl1) && !DECL_INITIAL (decl2))
2228 merge_addressable_attr (decl1, decl2);
2229 return;
2232 if (!DECL_INITIAL (decl1) && DECL_INITIAL (decl2))
2234 *slot = node;
2235 merge_addressable_attr (decl2, decl1);
2236 return;
2239 /* Either all complete or neither's type is complete. Just
2240 pick the primary module's decl. */
2241 if (!varpool_is_auxiliary (*slot))
2243 merge_addressable_attr (decl1, decl2);
2244 return;
2247 if (!varpool_is_auxiliary (node))
2249 *slot = node;
2250 merge_addressable_attr (decl2, decl1);
2251 return;
2254 merge_addressable_attr (decl1, decl2);
2255 return;
2258 /* Link NODE into var_decl symbol table. */
2260 void
2261 varpool_link_node (struct varpool_node *node)
2263 tree name;
2264 void **slot;
2266 if (!L_IPO_COMP_MODE || !varpool_symtab)
2267 return;
2269 if (!TREE_PUBLIC (node->decl) || DECL_ARTIFICIAL (node->decl))
2270 return;
2272 name = DECL_ASSEMBLER_NAME (node->decl);
2273 slot = htab_find_slot_with_hash (varpool_symtab, name,
2274 decl_assembler_name_hash (name),
2275 INSERT);
2276 if (*slot)
2277 resolve_varpool_node ((struct varpool_node **) slot, node);
2278 else
2279 *slot = node;
2282 /* Fixup references of VNODE. */
2284 static void
2285 fixup_reference_list (struct varpool_node *node)
2287 int i;
2288 struct ipa_ref *ref;
2289 struct ipa_ref_list *list = &node->ref_list;
2290 vec<cgraph_node_ptr> new_refered;
2291 vec<int> new_refered_type;
2292 struct cgraph_node *c;
2293 enum ipa_ref_use use_type = IPA_REF_LOAD;
2295 new_refered.create (10);
2296 new_refered_type.create (10);
2297 for (i = 0; ipa_ref_list_reference_iterate (list, i, ref); i++)
2299 if (!is_a <cgraph_node> (ref->referred))
2300 continue;
2302 struct cgraph_node *cnode = ipa_ref_node (ref);
2303 struct cgraph_node *r_cnode
2304 = cgraph_lipo_get_resolved_node (cnode->decl);
2305 if (r_cnode != cnode)
2307 new_refered.safe_push (r_cnode);
2308 use_type = ref->use;
2309 new_refered_type.safe_push ((int) use_type);
2312 for (i = 0; new_refered.iterate (i, &c); ++i)
2314 ipa_record_reference (node, c,
2315 (enum ipa_ref_use) new_refered_type[i], NULL);
2319 /* Perform cross module linking for var_decls. */
2321 void
2322 varpool_do_link (void)
2324 struct varpool_node *node;
2326 if (!L_IPO_COMP_MODE)
2327 return;
2329 varpool_symtab
2330 = htab_create_ggc (10, hash_node_by_assembler_name,
2331 eq_node_assembler_name, NULL);
2332 FOR_EACH_VARIABLE (node)
2333 varpool_link_node (node);
2335 /* Merge the externally visible attribute. */
2336 FOR_EACH_VARIABLE (node)
2338 if (node->externally_visible)
2339 (real_varpool_node (node->decl))->externally_visible = true;
2340 fixup_reference_list (node);
2344 /* Get the list of assembler name ids with reference bit set. */
2346 void
2347 varpool_get_referenced_asm_ids (vec<tree,va_gc> **ids)
2349 struct varpool_node *node;
2350 FOR_EACH_VARIABLE (node)
2352 tree asm_id = NULL;
2353 tree decl = node->decl;
2354 if (DECL_ASSEMBLER_NAME_SET_P (decl))
2356 asm_id = DECL_ASSEMBLER_NAME (decl);
2357 vec_safe_push (*ids, asm_id);
2362 /* Clear the referenced bit in all assembler ids. */
2364 void
2365 varpool_clear_asm_id_reference_bit (void)
2367 struct varpool_node *node;
2368 FOR_EACH_VARIABLE (node)
2370 tree asm_id = NULL;
2371 tree decl = node->decl;
2372 if (DECL_ASSEMBLER_NAME_SET_P (decl))
2374 asm_id = DECL_ASSEMBLER_NAME (decl);
2375 TREE_SYMBOL_REFERENCED (asm_id) = 0;
2381 #include "gt-l-ipo.h"