GCC Middle and Back End API Reference
stor-layout.h File Reference

Go to the source code of this file.

Macros

#define make_signed_fract_type(P)   make_fract_type (P, 0, 0)
 
#define make_unsigned_fract_type(P)   make_fract_type (P, 1, 0)
 
#define make_sat_signed_fract_type(P)   make_fract_type (P, 0, 1)
 
#define make_sat_unsigned_fract_type(P)   make_fract_type (P, 1, 1)
 
#define make_signed_accum_type(P)   make_accum_type (P, 0, 0)
 
#define make_unsigned_accum_type(P)   make_accum_type (P, 1, 0)
 
#define make_sat_signed_accum_type(P)   make_accum_type (P, 0, 1)
 
#define make_sat_unsigned_accum_type(P)   make_accum_type (P, 1, 1)
 
#define make_or_reuse_signed_fract_type(P)    make_or_reuse_fract_type (P, 0, 0)
 
#define make_or_reuse_unsigned_fract_type(P)    make_or_reuse_fract_type (P, 1, 0)
 
#define make_or_reuse_sat_signed_fract_type(P)    make_or_reuse_fract_type (P, 0, 1)
 
#define make_or_reuse_sat_unsigned_fract_type(P)    make_or_reuse_fract_type (P, 1, 1)
 
#define make_or_reuse_signed_accum_type(P)    make_or_reuse_accum_type (P, 0, 0)
 
#define make_or_reuse_unsigned_accum_type(P)    make_or_reuse_accum_type (P, 1, 0)
 
#define make_or_reuse_sat_signed_accum_type(P)    make_or_reuse_accum_type (P, 0, 1)
 
#define make_or_reuse_sat_unsigned_accum_type(P)    make_or_reuse_accum_type (P, 1, 1)
 

Functions

void set_min_and_max_values_for_integral_type (tree, int, signop)
 
void fixup_signed_type (tree)
 
unsigned int update_alignment_for_field (record_layout_info, tree, unsigned int)
 
record_layout_info start_record_layout (tree)
 
tree bit_from_pos (tree, tree)
 
tree byte_from_pos (tree, tree)
 
void pos_from_bit (tree *, tree *, unsigned int, tree)
 
void normalize_offset (tree *, tree *, unsigned int)
 
tree rli_size_unit_so_far (record_layout_info)
 
tree rli_size_so_far (record_layout_info)
 
void normalize_rli (record_layout_info)
 
void place_field (record_layout_info, tree)
 
void compute_record_mode (tree)
 
void finish_bitfield_layout (tree)
 
void finish_record_layout (record_layout_info, int)
 
void finalize_size_functions (void)
 
void fixup_unsigned_type (tree)
 
void initialize_sizetypes (void)
 
void finish_builtin_struct (tree, const char *, tree, tree)
 
void layout_decl (tree, unsigned)
 
void layout_type (tree)
 
unsigned int min_align_of_type (tree)
 
tree make_fract_type (int, int, int)
 
tree make_accum_type (int, int, int)
 
tree make_signed_type (int)
 
tree make_unsigned_type (int)
 
opt_machine_mode mode_for_size_tree (const_tree, enum mode_class, int)
 
tree bitwise_type_for_mode (machine_mode)
 
opt_machine_mode bitwise_mode_for_size (poly_uint64)
 
void relayout_decl (tree)
 
tree variable_size (tree)
 

Macro Definition Documentation

◆ make_or_reuse_sat_signed_accum_type

#define make_or_reuse_sat_signed_accum_type ( P)     make_or_reuse_accum_type (P, 0, 1)

◆ make_or_reuse_sat_signed_fract_type

#define make_or_reuse_sat_signed_fract_type ( P)     make_or_reuse_fract_type (P, 0, 1)

◆ make_or_reuse_sat_unsigned_accum_type

#define make_or_reuse_sat_unsigned_accum_type ( P)     make_or_reuse_accum_type (P, 1, 1)

◆ make_or_reuse_sat_unsigned_fract_type

#define make_or_reuse_sat_unsigned_fract_type ( P)     make_or_reuse_fract_type (P, 1, 1)

◆ make_or_reuse_signed_accum_type

#define make_or_reuse_signed_accum_type ( P)     make_or_reuse_accum_type (P, 0, 0)

◆ make_or_reuse_signed_fract_type

#define make_or_reuse_signed_fract_type ( P)     make_or_reuse_fract_type (P, 0, 0)

◆ make_or_reuse_unsigned_accum_type

#define make_or_reuse_unsigned_accum_type ( P)     make_or_reuse_accum_type (P, 1, 0)

◆ make_or_reuse_unsigned_fract_type

#define make_or_reuse_unsigned_fract_type ( P)     make_or_reuse_fract_type (P, 1, 0)

◆ make_sat_signed_accum_type

#define make_sat_signed_accum_type ( P)    make_accum_type (P, 0, 1)

◆ make_sat_signed_fract_type

#define make_sat_signed_fract_type ( P)    make_fract_type (P, 0, 1)

◆ make_sat_unsigned_accum_type

#define make_sat_unsigned_accum_type ( P)    make_accum_type (P, 1, 1)

◆ make_sat_unsigned_fract_type

#define make_sat_unsigned_fract_type ( P)    make_fract_type (P, 1, 1)

◆ make_signed_accum_type

#define make_signed_accum_type ( P)    make_accum_type (P, 0, 0)

◆ make_signed_fract_type

#define make_signed_fract_type ( P)    make_fract_type (P, 0, 0)

◆ make_unsigned_accum_type

#define make_unsigned_accum_type ( P)    make_accum_type (P, 1, 0)

◆ make_unsigned_fract_type

#define make_unsigned_fract_type ( P)    make_fract_type (P, 1, 0)

Function Documentation

◆ bit_from_pos()

tree bit_from_pos ( tree offset,
tree bitpos )
extern
Return the combined bit position for the byte offset OFFSET and the
bit position BITPOS.

These functions operate on byte and bit positions present in FIELD_DECLs
and assume that these expressions result in no (intermediate) overflow.
This assumption is necessary to fold the expressions as much as possible,
so as to avoid creating artificially variable-sized types in languages
supporting variable-sized types like Ada.   

References bits_from_bytes(), bitsize_unit_node, ggc_alloc(), offset, and size_binop.

Referenced by add_data_member_location_attribute(), bit_position(), eliminate_dom_walker::eliminate_stmt(), and rli_size_so_far().

◆ bitwise_mode_for_size()

opt_machine_mode bitwise_mode_for_size ( poly_uint64 size)
extern
Find a mode that can be used for efficient bitwise operations on SIZE
bits, if one exists.   

References FOR_EACH_MODE_FROM, GET_MODE_BITSIZE(), GET_MODE_INNER, ggc_alloc(), have_regs_of_mode, known_eq, known_le, MAX_FIXED_MODE_SIZE, mode_for_size(), and targetm.

Referenced by gimple_fold_builtin_memory_op().

◆ bitwise_type_for_mode()

tree bitwise_type_for_mode ( machine_mode mode)
extern
Find a type that can be used for efficient bitwise operations on MODE.
Return null if no such mode exists.   

References bitwise_mode_for_mode(), build_complex_type(), build_nonstandard_integer_type(), build_vector_type_for_mode(), COMPLEX_MODE_P, gcc_checking_assert, GET_MODE_INNER, GET_MODE_UNIT_BITSIZE, ggc_alloc(), NULL_TREE, and VECTOR_MODE_P.

Referenced by gimple_fold_builtin_memory_op().

◆ byte_from_pos()

tree byte_from_pos ( tree offset,
tree bitpos )
extern
Return the combined truncated byte position for the byte offset OFFSET and
the bit position BITPOS.   

References bitsize_unit_node, fold_convert, ggc_alloc(), offset, size_binop, sizetype, TREE_CODE, tree_int_cst_equal(), and TREE_OPERAND.

Referenced by byte_position(), and rli_size_unit_so_far().

◆ compute_record_mode()

◆ finalize_size_functions()

void finalize_size_functions ( void )
extern
Take, queue and compile all the size functions.  It is essential that
the size functions be gimplified at the very end of the compilation
in order to guarantee transparent handling of self-referential sizes.
Otherwise the GENERIC inliner would not be able to inline them back
at each of their call sites, thus creating artificial non-constant
size expressions which would trigger nasty problems later on.   

References allocate_struct_function(), debug_hooks, dump_function(), cgraph_node::finalize_function(), gimplify_function_tree(), i, NULL, set_cfun(), gcc_debug_hooks::size_function, size_functions, TDI_original, and vec_free().

Referenced by symbol_table::finalize_compilation_unit().

◆ finish_bitfield_layout()

void finish_bitfield_layout ( tree t)
extern

◆ finish_builtin_struct()

void finish_builtin_struct ( tree type,
const char * name,
tree fields,
tree align_type )
extern
Finish up a builtin RECORD_TYPE. Give it a name and provide its
fields. Optionally specify an alignment, and then lay it out.   
Finish processing a builtin RECORD_TYPE type TYPE.  It's name is
NAME, its fields are chained in reverse on FIELDS.

If ALIGN_TYPE is non-null, it is given the same alignment as
ALIGN_TYPE.   

References build_decl(), BUILTINS_LOCATION, DECL_CHAIN, DECL_FIELD_CONTEXT, fields, get_identifier(), ggc_alloc(), layout_decl(), layout_type(), NULL_TREE, SET_TYPE_ALIGN, SET_TYPE_WARN_IF_NOT_ALIGN, type(), TYPE_ALIGN, TYPE_FIELDS, TYPE_NAME, TYPE_STUB_DECL, TYPE_USER_ALIGN, and TYPE_WARN_IF_NOT_ALIGN.

Referenced by build_fn_info_type(), build_info_type(), init_ic_make_global_vars(), and lhd_simulate_record_decl().

◆ finish_record_layout()

void finish_record_layout ( record_layout_info rli,
int free_p )
extern
Do all of the work required to layout the type indicated by RLI,
once the fields have been laid out.  This function will call `free'
for RLI, unless FREE_P is false.  Passing a value other than false
for FREE_P is bad practice; this option only exists to support the
G++ 3.2 ABI.   

References compute_record_mode(), finalize_record_size(), finalize_type_size(), finish_bitfield_layout(), free(), ggc_alloc(), layout_decl(), TYPE_NEXT_VARIANT, TYPE_PACKED, TYPE_REVERSE_STORAGE_ORDER, vec_free(), and vec_safe_is_empty().

Referenced by layout_type().

◆ fixup_signed_type()

void fixup_signed_type ( tree type)
extern
Set the extreme values of TYPE based on its precision in bits,
then lay it out.  Used when make_signed_type won't do
because the tree code is not INTEGER_TYPE.   

References layout_type(), set_min_and_max_values_for_integral_type(), SIGNED, and TYPE_PRECISION.

Referenced by build_bitint_type(), build_nonstandard_boolean_type(), build_nonstandard_integer_type(), and make_signed_type().

◆ fixup_unsigned_type()

void fixup_unsigned_type ( tree type)
extern
Set the extreme values of TYPE based on its precision in bits,
then lay it out.  This is used both in `make_unsigned_type'
and for enumeral types.   

References layout_type(), set_min_and_max_values_for_integral_type(), TYPE_PRECISION, TYPE_UNSIGNED, and UNSIGNED.

Referenced by build_bitint_type(), build_nonstandard_integer_type(), and make_unsigned_type().

◆ initialize_sizetypes()

◆ layout_decl()

void layout_decl ( tree ,
unsigned  )
extern
Given a VAR_DECL, PARM_DECL, RESULT_DECL or FIELD_DECL node,
calculates the DECL_SIZE, DECL_SIZE_UNIT, DECL_ALIGN and DECL_MODE
fields.  Call this only once for any given decl node.

Second argument is the boundary that this field can be assumed to
be starting at (in bits).  Zero means it can be assumed aligned
on any boundary that may be needed.   

◆ layout_type()

void layout_type ( tree type)
extern
Given a ..._TYPE node, calculate the TYPE_SIZE, TYPE_SIZE_UNIT,
TYPE_ALIGN and TYPE_MODE fields.  If called more than once on one
node, does nothing except for the first time.   
Calculate the mode, size, and alignment for TYPE.
For an array type, calculate the element separation as well.
Record TYPE on the chain of permanent or temporary types
so that dbxout will find out about it.

TYPE_SIZE of a type is nonzero if the type has been laid out already.
layout_type does nothing on such a type.

If the type is incomplete, its TYPE_SIZE remains zero.   

References bitint_info::abi_limb_mode, AGGREGATE_TYPE_P, bitint_info::big_endian, bits_from_bytes(), bitsize_int, build_int_cst(), CEIL, compare_tree_int(), DECL_CHAIN, opt_mode< T >::else_blk(), error(), error_mark_node, ffs_hwi(), finalize_type_size(), finish_record_layout(), float_mode_for_size(), fold_convert, gcc_assert, gcc_checking_assert, gcc_unreachable, GET_MODE_ALIGNMENT, GET_MODE_BITSIZE(), GET_MODE_COMPLEX_MODE, GET_MODE_PRECISION(), GET_MODE_SIZE(), ggc_alloc(), int_const_binop(), int_mode_for_size(), integer_zerop(), bitint_info::limb_mode, MAX, mode_for_array(), mode_for_size_tree(), mode_for_vector(), nreverse(), NULL_TREE, place_field(), POINTER_SIZE, POINTER_SIZE_UNITS, RECORD_OR_UNION_TYPE_P, require(), SCALAR_INT_TYPE_MODE, SCALAR_TYPE_MODE, SET_TYPE_ALIGN, SET_TYPE_MODE, SET_TYPE_WARN_IF_NOT_ALIGN, SIGNED, size_binop, size_int, size_zero_node, sizetype, smallest_int_mode_for_size(), ssizetype, start_record_layout(), targetm, wi::to_wide(), TREE_CODE, tree_int_cst_lt(), TREE_OVERFLOW, TREE_TYPE, TYPE_ALIAS_SET_KNOWN_P, TYPE_ALIGN, TYPE_ALIGN_UNIT, TYPE_DOMAIN, TYPE_FIELDS, TYPE_MAIN_VARIANT, TYPE_MAX_VALUE, TYPE_MIN_VALUE, TYPE_MODE, TYPE_NEXT_VARIANT, TYPE_NO_FORCE_BLK, TYPE_PRECISION, TYPE_SATURATING, TYPE_SIZE, TYPE_SIZE_UNIT, TYPE_TYPELESS_STORAGE, TYPE_UNSIGNED, TYPE_USER_ALIGN, TYPE_VECTOR_SUBPARTS(), TYPE_WARN_IF_NOT_ALIGN, VECTOR_BOOLEAN_TYPE_P, wide_int_to_tree(), and wi::zext().

Referenced by asan_global_struct(), build_array_type_1(), build_common_tree_nodes(), build_function_type(), build_method_type_directly(), build_offset_type(), build_pointer_type_for_mode(), build_reference_type_for_mode(), finalize_nesting_tree_1(), finish_builtin_struct(), finish_taskreg_scan(), fixup_child_record_type(), fixup_signed_type(), fixup_unsigned_type(), get_descriptor_type(), get_emutls_object_type(), get_trampoline_type(), go_format_type(), init_eh(), lhd_simulate_enum_decl(), lower_omp_task_reductions(), make_accum_type(), make_fract_type(), make_vector_type(), oacc_do_neutering(), ompdevlow_adjust_simt_enter(), scan_omp_single(), scan_omp_target(), separate_decls_in_region(), task_copyfn_remap_type(), thunk_adjust(), type_hash_canon(), ubsan_create_data(), ubsan_get_source_location_type(), and ubsan_get_type_descriptor_type().

◆ make_accum_type()

tree make_accum_type ( int precision,
int unsignedp,
int satp )
extern
Create and return a type for accum of PRECISION bits, UNSIGNEDP,
and SATP.   

References ggc_alloc(), layout_type(), make_node(), mode_for_size(), require(), SET_TYPE_MODE, type(), TYPE_PRECISION, TYPE_SATURATING, and TYPE_UNSIGNED.

Referenced by make_or_reuse_accum_type().

◆ make_fract_type()

tree make_fract_type ( int precision,
int unsignedp,
int satp )
extern
Construct various nodes representing fract or accum data types.   
Create and return a type for fract of PRECISION bits, UNSIGNEDP,
and SATP.   

References ggc_alloc(), layout_type(), make_node(), mode_for_size(), require(), SET_TYPE_MODE, type(), TYPE_PRECISION, TYPE_SATURATING, and TYPE_UNSIGNED.

Referenced by make_or_reuse_fract_type().

◆ make_signed_type()

tree make_signed_type ( int precision)
extern
Create and return a type for signed integers of PRECISION bits.   

References fixup_signed_type(), ggc_alloc(), make_node(), type(), and TYPE_PRECISION.

Referenced by build_common_tree_nodes(), and initialize_sizetypes().

◆ make_unsigned_type()

tree make_unsigned_type ( int precision)
extern
Create and return a type for unsigned integers of PRECISION bits.   

References fixup_unsigned_type(), ggc_alloc(), make_node(), type(), and TYPE_PRECISION.

Referenced by build_common_tree_nodes(), vect_create_epilog_for_reduction(), and vectorizable_reduction().

◆ min_align_of_type()

unsigned int min_align_of_type ( tree type)
extern
Return the least alignment in bytes required for type TYPE.   
Return the least alignment required for type TYPE.   

References ggc_alloc(), MIN, NULL_TREE, TYPE_ALIGN, and TYPE_USER_ALIGN.

Referenced by fold_unary_loc(), get_object_alignment_2(), gimple_fold_builtin_clear_padding(), and instrument_mem_ref().

◆ mode_for_size_tree()

opt_machine_mode mode_for_size_tree ( const_tree size,
enum mode_class mclass,
int limit )
extern
Return the mode for data of a given size SIZE and mode class CLASS.
If LIMIT is nonzero, then don't use modes bigger than MAX_FIXED_MODE_SIZE.
The value is BLKmode if no other mode is found.  This is like
mode_for_size, but is passed a tree.   
Similar, except passed a tree node.   

References ggc_alloc(), mode_for_size(), tree_fits_uhwi_p(), tree_to_uhwi(), and ui.

Referenced by compute_record_mode(), layout_decl(), layout_type(), and mode_for_array().

◆ normalize_offset()

void normalize_offset ( tree * poffset,
tree * pbitpos,
unsigned int off_align )
extern
Given a pointer to bit and byte offsets and an offset alignment,
normalize the offsets so they are within the alignment.   

References compare_tree_int(), ggc_alloc(), offset, pos_from_bit(), and size_binop.

Referenced by normalize_rli().

◆ normalize_rli()

void normalize_rli ( record_layout_info rli)
extern
Given an RLI with a possibly-incremented BITPOS, adjust OFFSET and
BITPOS if necessary to keep BITPOS below OFFSET_ALIGN.   

References ggc_alloc(), and normalize_offset().

Referenced by finalize_record_size(), and place_field().

◆ place_field()

◆ pos_from_bit()

void pos_from_bit ( tree * poffset,
tree * pbitpos,
unsigned int off_align,
tree pos )
extern
Split the bit position POS into a byte offset *POFFSET and a bit
position *PBITPOS with the byte offset aligned to OFF_ALIGN bits.   

References bitsize_int, bitsize_zero_node, fold_convert, ggc_alloc(), size_binop, size_int, sizetype, TREE_CODE, tree_int_cst_equal(), and TREE_OPERAND.

Referenced by normalize_offset().

◆ relayout_decl()

void relayout_decl ( tree decl)
extern
Given a VAR_DECL, PARM_DECL or RESULT_DECL, clears the results of
a previous call to layout_decl and calls it again.   
Given a VAR_DECL, PARM_DECL, RESULT_DECL, or FIELD_DECL, clears the
results of a previous call to layout_decl and calls it again.   

References DECL_RTL_SET_P, DECL_SIZE, DECL_SIZE_UNIT, DECL_USER_ALIGN, ggc_alloc(), layout_decl(), SET_DECL_ALIGN, SET_DECL_MODE, and SET_DECL_RTL.

Referenced by allocate_struct_function(), decl_attributes(), shrink_simd_arrays(), and simd_clone_adjust().

◆ rli_size_so_far()

tree rli_size_so_far ( record_layout_info rli)
extern
Returns the size in bits allocated so far.   

References bit_from_pos(), and ggc_alloc().

Referenced by finalize_record_size().

◆ rli_size_unit_so_far()

tree rli_size_unit_so_far ( record_layout_info rli)
extern
Returns the size in bytes allocated so far.   

References byte_from_pos(), and ggc_alloc().

Referenced by finalize_record_size().

◆ set_min_and_max_values_for_integral_type()

void set_min_and_max_values_for_integral_type ( tree type,
int precision,
signop sgn )
extern
Definitions and declarations for stor-layout.cc.
   Copyright (C) 2013-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
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/>.   
TYPE is an integral type, i.e., an INTEGRAL_TYPE, ENUMERAL_TYPE
or BOOLEAN_TYPE.  Set TYPE_MIN_VALUE and TYPE_MAX_VALUE
for TYPE, based on the PRECISION and whether or not the TYPE
IS_UNSIGNED.  PRECISION need not correspond to a width supported
natively by the hardware; for example, on a machine with 8-bit,
16-bit, and 32-bit register modes, PRECISION might be 7, 23, or
61.   

References gcc_assert, wi::max_value(), wi::min_value(), TYPE_MAX_VALUE, TYPE_MIN_VALUE, WIDE_INT_MAX_PRECISION, and wide_int_to_tree().

Referenced by fixup_signed_type(), fixup_unsigned_type(), and initialize_sizetypes().

◆ start_record_layout()

record_layout_info start_record_layout ( tree t)
extern
Begin laying out type T, which may be a RECORD_TYPE, UNION_TYPE, or
QUAL_UNION_TYPE.  Return a pointer to a struct record_layout_info which
is to be passed to all other layout functions for this record.  It is the
responsibility of the caller to call `free' for the storage returned.
Note that garbage collection is not permitted until we finish laying
out the record.   

References bitsize_zero_node, ggc_alloc(), MAX, maximum_field_alignment, MIN, size_zero_node, TYPE_ALIGN, and TYPE_PACKED.

Referenced by layout_type().

◆ update_alignment_for_field()

unsigned int update_alignment_for_field ( record_layout_info rli,
tree field,
unsigned int known_align )
extern
FIELD is about to be added to RLI->T.  The alignment (in bits) of
the next available location within the record is given by KNOWN_ALIGN.
Update the variable alignment fields in RLI, and return the alignment
to give the FIELD.   

References DECL_ALIGN, DECL_BIT_FIELD_TYPE, DECL_NAME, DECL_PACKED, DECL_SIZE, DECL_USER_ALIGN, error_mark_node, ggc_alloc(), integer_zerop(), layout_decl(), MAX, maximum_field_alignment, MIN, NULL_TREE, PCC_BITFIELD_TYPE_MATTERS, targetm, TREE_CODE, TREE_TYPE, TYPE_ALIGN, TYPE_SIZE, and TYPE_USER_ALIGN.

Referenced by place_field(), and place_union_field().

◆ variable_size()

tree variable_size ( tree size)
extern
variable_size (EXP) is like save_expr (EXP) except that it
is for the special case of something that is part of a
variable size for a data type.  It makes special arrangements
to compute the value at the right time when the data type
belongs to a function parameter.   
Given a size SIZE that may not be a constant, return a SAVE_EXPR
to serve as the actual size-expression for a type or decl.   

References CONTAINS_PLACEHOLDER_P, lang_hooks::decls, lang_hooks_for_decls::global_bindings_p, save_expr(), self_referential_size(), and TREE_CONSTANT.

Referenced by finalize_type_size(), layout_decl(), place_field(), and store_one_arg().