|
GCC Middle and Back End API Reference
|
#include "config.h"#include "system.h"#include "coretypes.h"#include "timevar.h"#include "diagnostic-core.h"#include "ggc-internal.h"#include "hosthooks.h"#include "plugin.h"#include "options.h"
Data Structures | |
| struct | ptr_data |
| struct | saving_hasher |
| struct | traversal_state |
| struct | mmap_info |
| class | ggc_usage |
Macros | |
| #define | INCLUDE_MALLOC_H |
| #define | POINTER_HASH(x) |
Typedefs | |
| typedef const struct ggc_root_tab * | const_ggc_root_tab_t |
Functions | |
| static int | compare_ptr_data (const void *, const void *) |
| static void | relocate_ptrs (void *, void *, void *) |
| static void | write_pch_globals (const struct ggc_root_tab *const *tab, struct traversal_state *state) |
| void | ggc_register_root_tab (const struct ggc_root_tab *rt) |
| static void | ggc_mark_root_tab (const_ggc_root_tab_t rt) |
| static void | ggc_zero_rtab_roots (const_ggc_root_tab_t rt) |
| void | ggc_mark_roots (void) |
| void * | ggc_internal_cleared_alloc (size_t size, void(*f)(void *), size_t s, size_t n MEM_STAT_DECL) |
| void * | ggc_internal_cleared_alloc_no_dtor (size_t size, void(*f)(void *), size_t s, size_t n MEM_STAT_DECL) |
| void * | ggc_realloc (void *x, size_t size MEM_STAT_DECL) |
| void * | ggc_cleared_alloc_htab_ignore_args (size_t c, size_t n) |
| void * | ggc_cleared_alloc_ptr_array_two_args (size_t c, size_t n) |
| void * | ggc_splay_alloc (int sz, void *nl) |
| void | ggc_splay_dont_free (void *x, void *nl) |
| void | ggc_print_common_statistics (FILE *stream, ggc_statistics *stats) |
| int | gt_pch_note_object (void *obj, void *note_ptr_cookie, gt_note_pointers note_ptr_fn, size_t length_override) |
| void | gt_pch_note_callback (void *obj, void *base) |
| void | gt_pch_note_reorder (void *obj, void *note_ptr_cookie, gt_handle_reorder reorder_fn) |
| int | ggc_call_count (ptr_data **slot, traversal_state *state) |
| int | ggc_call_alloc (ptr_data **slot, traversal_state *state) |
| static int | compare_ptr (const void *p1_p, const void *p2_p) |
| static unsigned char * | read_uleb128 (unsigned char *p, size_t *val) |
| static size_t | write_uleb128 (unsigned char *p, size_t val) |
| void | gt_pch_save (FILE *f) |
| void | gt_pch_restore (FILE *f) |
| void * | default_gt_pch_get_address (size_t size, int fd) |
| int | default_gt_pch_use_address (void *&base, size_t size, int fd, size_t offset) |
| size_t | default_gt_pch_alloc_granularity (void) |
| static double | ggc_rlimit_bound (double limit) |
| static int | ggc_min_expand_heuristic (void) |
| static int | ggc_min_heapsize_heuristic (void) |
| void | init_ggc_heuristics (void) |
| auto & | ggc_mem_desc () |
| void | dump_ggc_loc_statistics () |
| void | ggc_record_overhead (size_t allocated, size_t overhead, void *ptr MEM_STAT_DECL) |
| void | ggc_free_overhead (void *ptr) |
| void | ggc_prune_overhead_list (void) |
| void | report_heap_memory_use () |
| void | ggc_common_finalize () |
Variables | |
| bool | ggc_protect_identifiers = true |
| static ggc_statistics * | ggc_stats |
| static vec< const_ggc_root_tab_t > | extra_root_vec |
| static hash_table< saving_hasher > * | saving_htab |
| static vec< void * > | callback_vec |
| static vec< void * > | reloc_addrs_vec |
| #define INCLUDE_MALLOC_H |
Simple garbage collection for the GNU compiler. Copyright (C) 1999-2026 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 version. GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 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 <http://www.gnu.org/licenses/>.
Generic garbage collection (GC) functions and data, not specific to any particular GC implementation.
| #define POINTER_HASH | ( | x | ) |
Referenced by gt_pch_note_callback(), gt_pch_note_object(), gt_pch_note_reorder(), saving_hasher::hash(), relocate_ptrs(), and write_pch_globals().
| typedef const struct ggc_root_tab* const_ggc_root_tab_t |
Maintain global roots that are preserved during GC.
This extra vector of dynamically registered root_tab-s is used by ggc_mark_roots and gives the ability to dynamically add new GGC root tables, for instance from some plugins; this vector is on the heap since it is used by GGC internally.
|
static |
|
static |
Callback for qsort.
References compare_ptr_data(), and ptr_data::new_addr.
Referenced by compare_ptr_data(), and gt_pch_save().
| size_t default_gt_pch_alloc_granularity | ( | void | ) |
Default version of HOST_HOOKS_GT_PCH_GET_ADDRESS. Return the alignment required for allocating virtual memory. Usually this is the same as pagesize.
References default_gt_pch_alloc_granularity().
Referenced by default_gt_pch_alloc_granularity().
| void * default_gt_pch_get_address | ( | size_t | size, |
| int | fd ) |
Default version of HOST_HOOKS_GT_PCH_GET_ADDRESS when mmap is not present. Select no address whatsoever, and let gt_pch_save choose what it will with malloc, presumably.
References default_gt_pch_get_address(), and NULL.
Referenced by default_gt_pch_get_address().
| int default_gt_pch_use_address | ( | void *& | base, |
| size_t | size, | ||
| int | fd, | ||
| size_t | offset ) |
Default version of HOST_HOOKS_GT_PCH_USE_ADDRESS when mmap is not present. Allocate SIZE bytes with malloc. Return 0 if the address we got is the same as base, indicating that the memory has been allocated but needs to be read in from the file. Return -1 if the address differs, to relocation of the PCH file would be required.
References default_gt_pch_use_address().
Referenced by default_gt_pch_use_address().
| void dump_ggc_loc_statistics | ( | ) |
Dump per-site memory statistics.
References dump_ggc_loc_statistics(), GGC_COLLECT_FORCE, ggc_mem_desc(), and GGC_ORIGIN.
Referenced by dump_ggc_loc_statistics(), dump_memory_report(), and ggc_realloc().
| int ggc_call_alloc | ( | ptr_data ** | slot, |
| traversal_state * | state ) |
References ggc_call_alloc(), ggc_pch_alloc_object(), ptr_data::new_addr, ptr_data::obj, and ptr_data::size.
Referenced by ggc_call_alloc(), and gt_pch_save().
| int ggc_call_count | ( | ptr_data ** | slot, |
| traversal_state * | state ) |
Callbacks for htab_traverse.
References ggc_call_count(), ggc_pch_count_object(), ptr_data::obj, and ptr_data::size.
Referenced by ggc_call_count(), and gt_pch_save().
| void * ggc_cleared_alloc_htab_ignore_args | ( | size_t | c, |
| size_t | n ) |
References gcc_assert, ggc_cleared_alloc(), and ggc_cleared_alloc_htab_ignore_args().
Referenced by ggc_cleared_alloc_htab_ignore_args().
| void * ggc_cleared_alloc_ptr_array_two_args | ( | size_t | c, |
| size_t | n ) |
TODO: once we actually use type information in GGC, create a new tag gt_gcc_ptr_array and use it for pointer arrays.
References gcc_assert, ggc_cleared_alloc_ptr_array_two_args(), and ggc_cleared_vec_alloc().
Referenced by ggc_cleared_alloc_ptr_array_two_args().
| void ggc_common_finalize | ( | ) |
Forcibly clear all GTY roots.
References ggc_root_tab::base, ggc_common_finalize(), ggc_zero_rtab_roots(), gt_ggc_deletable_rtab, gt_ggc_rtab, gt_pch_scalar_rtab, ggc_root_tab::nelt, NULL, and ggc_root_tab::stride.
Referenced by toplev::finalize(), and ggc_common_finalize().
| void ggc_free_overhead | ( | void * | ptr | ) |
Notice that the pointer has been freed.
References ggc_free_overhead(), and ggc_mem_desc().
Referenced by ggc_free(), ggc_free_overhead(), and ggc_record_overhead().
| void * ggc_internal_cleared_alloc | ( | size_t | size, |
| void(* | f )(void *), | ||
| size_t | s, | ||
| size_t n | MEM_STAT_DECL ) |
Allocate a block of memory, then clear it.
References ggc_internal_alloc(), ggc_internal_cleared_alloc(), MEM_STAT_DECL, and PASS_MEM_STAT.
| void * ggc_internal_cleared_alloc_no_dtor | ( | size_t | size, |
| void(* | f )(void *), | ||
| size_t | s, | ||
| size_t n | MEM_STAT_DECL ) |
|
static |
Mark all the roots in the table RT.
References ggc_root_tab::base, ggc_root_tab::cb, ggc_mark_root_tab(), i, ggc_root_tab::nelt, NULL, and ggc_root_tab::stride.
Referenced by ggc_mark_root_tab(), and ggc_mark_roots().
| void ggc_mark_roots | ( | void | ) |
Iterate through all registered roots and mark each element.
Garbage collection for the GNU compiler. Internal definitions for ggc-*.c and stringpool.cc. Copyright (C) 2009-2026 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 version. GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 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 <http://www.gnu.org/licenses/>.
Call ggc_set_mark on all the roots.
References ggc_root_tab::base, extra_root_vec, FOR_EACH_VEC_ELT, ggc_mark_root_tab(), ggc_mark_roots(), ggc_mark_stringpool(), ggc_protect_identifiers, ggc_purge_stringpool(), gt_clear_caches(), gt_ggc_deletable_rtab, gt_ggc_rtab, i, invoke_plugin_callbacks(), ggc_root_tab::nelt, NULL, and ggc_root_tab::stride.
Referenced by ggc_collect(), and ggc_mark_roots().
|
inline |
GCC memory description.
References ggc_mem_desc(), and mem_alloc_description< T >::instance().
Referenced by dump_ggc_loc_statistics(), ggc_free_overhead(), ggc_mem_desc(), ggc_prune_overhead_list(), and ggc_record_overhead().
|
static |
Heuristic to set a default for GGC_MIN_EXPAND.
References ggc_min_expand_heuristic(), ggc_rlimit_bound(), MIN, and ONE_G.
Referenced by ggc_min_expand_heuristic(), ggc_min_heapsize_heuristic(), and init_ggc_heuristics().
|
static |
Heuristic to set a default for GGC_MIN_HEAPSIZE.
References ggc_min_expand_heuristic(), ggc_min_heapsize_heuristic(), ggc_rlimit_bound(), MAX, MIN, and ONE_K.
Referenced by ggc_min_heapsize_heuristic(), and init_ggc_heuristics().
| void ggc_print_common_statistics | ( | FILE * | stream, |
| ggc_statistics * | stats ) |
Used by the various collectors to gather and print statistics that do not depend on the collector in use.
References ggc_print_common_statistics(), ggc_stats, and NULL.
Referenced by ggc_print_common_statistics(), and ggc_print_statistics().
| void ggc_prune_overhead_list | ( | void | ) |
After live values has been marked, walk all recorded pointers and see if they are still live.
References ggc_marked_p(), ggc_mem_desc(), and ggc_prune_overhead_list().
Referenced by ggc_collect(), ggc_prune_overhead_list(), and ggc_record_overhead().
| void * ggc_realloc | ( | void * | x, |
| size_t size | MEM_STAT_DECL ) |
Resize a block of memory, possibly re-allocating it.
References ggc_free(), ggc_get_size(), ggc_internal_alloc(), ggc_realloc(), MEM_STAT_DECL, NULL, PASS_MEM_STAT, r, and VALGRIND_DISCARD.
Referenced by ggc_realloc(), ggc_realloc(), ggc_realloc(), grow_tree_vec(), and realloc_for_line_map().
| void ggc_record_overhead | ( | size_t | allocated, |
| size_t | overhead, | ||
| void *ptr | MEM_STAT_DECL ) |
Record ALLOCATED and OVERHEAD bytes to descriptor NAME:LINE (FUNCTION).
References FINAL_PASS_MEM_STAT, ggc_mem_desc(), GGC_ORIGIN, ggc_record_overhead(), MEM_STAT_DECL, and ggc_usage::register_overhead().
Referenced by ggc_internal_alloc(), ggc_record_overhead(), and ggc_record_overhead().
| void ggc_register_root_tab | ( | const struct ggc_root_tab * | rt | ) |
Dynamically register a new GGC root table RT. This is useful for plugins.
Register an additional root table. This can be useful for some plugins. Does nothing if the passed pointer is NULL.
References extra_root_vec, and ggc_register_root_tab().
Referenced by ggc_register_root_tab(), and register_callback().
|
static |
Modify the bound based on rlimits.
References ggc_rlimit_bound(), and ONE_M.
Referenced by ggc_min_expand_heuristic(), ggc_min_heapsize_heuristic(), and ggc_rlimit_bound().
| void * ggc_splay_alloc | ( | int | sz, |
| void * | nl ) |
These are for splay_tree_new_ggc.
References gcc_assert, ggc_internal_alloc(), and ggc_splay_alloc().
Referenced by ggc_splay_alloc().
| void ggc_splay_dont_free | ( | void * | x, |
| void * | nl ) |
References gcc_assert, and ggc_splay_dont_free().
Referenced by ggc_splay_dont_free().
|
static |
Zero out all the roots in the table RT.
References ggc_root_tab::base, ggc_zero_rtab_roots(), i, ggc_root_tab::nelt, NULL, and ggc_root_tab::stride.
Referenced by ggc_common_finalize(), and ggc_zero_rtab_roots().
| void gt_pch_note_callback | ( | void * | obj, |
| void * | base ) |
Register address of a callback pointer.
Used by the gt_pch_p_* routines. Register address of a callback pointer.
References callback_vec, gcc_assert, gt_pch_note_callback(), NULL, ptr_data::obj, POINTER_HASH, and saving_htab.
Referenced by gt_pch_note_callback().
| int gt_pch_note_object | ( | void * | obj, |
| void * | note_ptr_cookie, | ||
| gt_note_pointers | note_ptr_fn, | ||
| size_t | length_override = (size_t) -1 ) |
Register an object in the hash table.
Used by the gt_pch_n_* routines. Register an object in the hash table.
References gcc_assert, ggc_get_size(), gt_pch_note_object(), gt_pch_p_S(), ptr_data::note_ptr_cookie, ptr_data::note_ptr_fn, NULL, ptr_data::obj, POINTER_HASH, and saving_htab.
Referenced by gt_pch_n_S(), gt_pch_n_S2(), gt_pch_note_object(), and gt_pch_nx().
| void gt_pch_note_reorder | ( | void * | obj, |
| void * | note_ptr_cookie, | ||
| gt_handle_reorder | reorder_fn ) |
Register an object in the hash table.
Used by the gt_pch_n_* routines. Register that an object has a reorder function.
References gcc_assert, gcc_checking_assert, gt_pch_note_reorder(), gt_pch_p_S(), ptr_data::note_ptr_cookie, NULL, ptr_data::obj, POINTER_HASH, ptr_data::reorder_fn, and saving_htab.
Referenced by gt_pch_note_reorder().
| void gt_pch_restore | ( | FILE * | f | ) |
Read the state of the compiler back in from F.
Read objects previously saved with gt_pch_save from F.
References ggc_root_tab::base, fatal_error(), gcc_assert, ggc_pch_read(), gt_ggc_deletable_rtab, gt_ggc_rtab, gt_pch_restore(), gt_pch_restore_stringpool(), gt_pch_save(), gt_pch_scalar_rtab, host_hooks::gt_pch_use_address, i, input_location, line_table, MIN, ggc_root_tab::nelt, NULL, mmap_info::offset, mmap_info::preferred_base, read_uleb128(), SEEK_CUR, SEEK_SET, mmap_info::size, sorry_at(), and ggc_root_tab::stride.
Referenced by gt_pch_restore().
| void gt_pch_save | ( | FILE * | f | ) |
Write out the state of the compiler to F.
Write out all GCed objects to F.
References ggc_root_tab::base, callback_vec, compare_ptr(), compare_ptr_data(), fatal_error(), gcc_assert, gcc_checking_assert, ggc_call_alloc(), ggc_call_count(), ggc_pch_finish(), ggc_pch_prepare_write(), ggc_pch_this_base(), ggc_pch_total_size(), ggc_pch_write_object(), gt_ggc_rtab, host_hooks::gt_pch_alloc_granularity, gt_pch_fixup_stringpool(), host_hooks::gt_pch_get_address, gt_pch_p_S(), gt_pch_save(), gt_pch_save_stringpool(), gt_pch_scalar_rtab, hash_table< Descriptor, Lazy, Allocator >::hash_table(), i, init_ggc_pch(), input_location, ggc_root_tab::nelt, NULL, mmap_info::offset, ggc_root_tab::pchw, mmap_info::preferred_base, qsort, reloc_addrs_vec, relocate_ptrs(), saving_htab, SEEK_SET, mmap_info::size, ggc_root_tab::stride, timevar_pop(), timevar_push(), UNLIKELY, VALGRIND_DISCARD, vNULL, write_pch_globals(), and write_uleb128().
Referenced by gt_pch_restore(), and gt_pch_save().
| void init_ggc_heuristics | ( | void | ) |
Heuristics.
References ggc_min_expand_heuristic(), ggc_min_heapsize_heuristic(), and init_ggc_heuristics().
Referenced by init_ggc_heuristics(), and toplev::main().
|
static |
Decode one uleb128 from P, return first byte after it, store decoded value into *VAL.
References read_uleb128().
Referenced by gt_pch_restore(), and read_uleb128().
|
static |
Callbacks for note_ptr_fn.
References gcc_assert, ptr_data::new_addr, NULL, POINTER_HASH, reloc_addrs_vec, relocate_ptrs(), and saving_htab.
Referenced by gt_pch_save(), and relocate_ptrs().
| void report_heap_memory_use | ( | void | ) |
Print memory used by heap if this info is available.
Report current heap memory use to stderr.
References PRsa, report_heap_memory_use(), and SIZE_AMOUNT.
Referenced by execute_one_pass(), ipa_read_optimization_summaries_1(), ipa_read_summaries_1(), and report_heap_memory_use().
|
static |
Write out, after relocation, the pointers in TAB.
References ggc_root_tab::base, fatal_error(), i, input_location, ggc_root_tab::nelt, ptr_data::new_addr, NULL, POINTER_HASH, saving_htab, ggc_root_tab::stride, and write_pch_globals().
Referenced by gt_pch_save(), and write_pch_globals().
|
static |
Store VAL as uleb128 at P, return length in bytes.
References write_uleb128().
Referenced by gt_pch_save(), and write_uleb128().
|
static |
Referenced by gt_pch_note_callback(), and gt_pch_save().
|
static |
Referenced by ggc_mark_roots(), and ggc_register_root_tab().
When true, protect the contents of the identifier hash table.
When true, identifier nodes are considered as GC roots. When false, identifier nodes are treated like any other GC-allocated object, and the identifier hash table is treated as a weak hash.
Referenced by compile_file(), do_compile(), and ggc_mark_roots().
|
static |
Statistics about the allocation.
Referenced by ggc_print_common_statistics().
|
static |
Referenced by gt_pch_save(), and relocate_ptrs().
|
static |
Referenced by gt_pch_note_callback(), gt_pch_note_object(), gt_pch_note_reorder(), gt_pch_save(), relocate_ptrs(), and write_pch_globals().