GCC Middle and Back End API Reference
ipa-comdats.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "tree-pass.h"
#include "cgraph.h"
Include dependency graph for ipa-comdats.cc:


tree propagate_comdat_group (struct symtab_node *symbol, tree newgroup, hash_map< symtab_node *, tree > &map)
void enqueue_references (symtab_node **first, symtab_node *symbol)
bool set_comdat_group (symtab_node *symbol, void *head_p)
bool set_comdat_group_1 (cgraph_node *symbol, void *head_p)
static unsigned int ipa_comdats (void)
ipa_opt_pass_dmake_pass_ipa_comdats (gcc::context *ctxt)

Function Documentation

◆ enqueue_references()

void enqueue_references ( symtab_node ** first,
symtab_node * symbol )
Add all references of SYMBOL that are defined into queue started by FIRST
and linked by AUX pointer (unless they are already enqueued).
Walk recursively inlined functions.   

References symtab_node::aux, symtab_node::definition, enqueue_references(), ggc_alloc(), i, symtab_node::iterate_reference(), NULL, ipa_ref::referred, and symtab_node::ultimate_alias_target().

Referenced by enqueue_references(), and ipa_comdats().

◆ ipa_comdats()

◆ make_pass_ipa_comdats()

ipa_opt_pass_d * make_pass_ipa_comdats ( gcc::context * ctxt)

References ggc_alloc().

◆ propagate_comdat_group()

tree propagate_comdat_group ( struct symtab_node * symbol,
tree newgroup,
hash_map< symtab_node *, tree > & map )
Localize comdats.
   Copyright (C) 2014-2024 Free Software Foundation, Inc.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
This is very simple pass that looks for static symbols that are used
exclusively by symbol within one comdat group.  In this case it makes
sense to bring the symbol itself into the group to avoid dead code
that would arrise when the comdat group from current unit is replaced
by a different copy.  Consider for example:

 static int q(void)
 inline int t(void)
   return q();

if Q is used only by T, it makes sense to put Q into T's comdat group.

The pass solve simple dataflow across the callgraph trying to prove what
symbols are used exclusively from a given comdat group.

The implementation maintains a queue linked by AUX pointer terminated by
pointer value 1. Lattice values are NULL for TOP, actual comdat group, or
ERROR_MARK_NODE for bottom.

TODO: When symbol is used only by comdat symbols, but from different groups,
it would make sense to produce a new comdat group for it with anonymous name.

TODO2: We can't mix variables and functions within one group.  Currently
we just give up on references of symbols of different types.  We also should
handle this by anonymous comdat group section.   
Main dataflow loop propagating comdat groups across
the symbol table.  All references to SYMBOL are examined
and NEWGROUP is updated accordingly. MAP holds current lattice
values for individual symbols.   

References error_mark_node, ggc_alloc(), i, IPA_REF_ALIAS, symtab_node::iterate_referring(), map, propagate_comdat_group(), ipa_ref::referring, symtab_node::type, and ipa_ref::use.

Referenced by ipa_comdats(), and propagate_comdat_group().

◆ set_comdat_group()

bool set_comdat_group ( symtab_node * symbol,
void * head_p )
Set comdat group of SYMBOL to GROUP.
Callback for for_node_and_aliases.   

References symtab_node::add_to_same_comdat_group(), gcc_assert, symtab_node::get_comdat_group(), ggc_alloc(), symtab_node::real_symbol_p(), and symtab_node::set_comdat_group().

Referenced by ipa_comdats(), and set_comdat_group_1().

◆ set_comdat_group_1()

bool set_comdat_group_1 ( cgraph_node * symbol,
void * head_p )
Set comdat group of SYMBOL to GROUP.
Callback for for_node_thunks_and_aliases.   

References ggc_alloc(), and set_comdat_group().

Referenced by ipa_comdats().