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

Functions

static tree self_referential_size (tree)
static void finalize_record_size (record_layout_info)
static void finalize_type_size (tree)
static void place_union_field (record_layout_info, tree)
static int excess_unit_span (HOST_WIDE_INT, HOST_WIDE_INT, HOST_WIDE_INT, HOST_WIDE_INT, tree)
void debug_rli (record_layout_info)
void internal_reference_types ()
tree variable_size ()
static tree copy_self_referential_tree_r ()
static tree self_referential_size ()
void finalize_size_functions ()
enum machine_mode mode_for_size ()
enum machine_mode mode_for_size_tree ()
enum machine_mode smallest_mode_for_size ()
enum machine_mode int_mode_for_mode ()
enum machine_mode mode_for_vector ()
unsigned int get_mode_alignment ()
unsigned int element_precision ()
static enum machine_mode mode_for_array ()
static void do_type_align ()
void layout_decl ()
void relayout_decl ()
record_layout_info start_record_layout ()
tree bit_from_pos ()
tree byte_from_pos ()
void pos_from_bit (tree *poffset, tree *pbitpos, unsigned int off_align, tree pos)
void normalize_offset ()
DEBUG_FUNCTION void debug_rli ()
void normalize_rli ()
tree rli_size_unit_so_far ()
tree rli_size_so_far ()
unsigned int update_alignment_for_field (record_layout_info rli, tree field, unsigned int known_align)
static void place_union_field ()
void place_field ()
static void finalize_record_size ()
void compute_record_mode ()
static void finalize_type_size ()
static tree start_bitfield_representative ()
static void finish_bitfield_representative ()
static void finish_bitfield_layout ()
void finish_record_layout ()
void finish_builtin_struct (tree type, const char *name, tree fields, tree align_type)
void layout_type ()
enum machine_mode vector_type_mode ()
tree make_signed_type ()
tree make_unsigned_type ()
tree make_fract_type ()
tree make_accum_type ()
void initialize_sizetypes ()
void set_min_and_max_values_for_integral_type (tree type, int precision, bool is_unsigned)
void fixup_signed_type ()
void fixup_unsigned_type ()
enum machine_mode get_best_mode (int bitsize, int bitpos, unsigned HOST_WIDE_INT bitregion_start, unsigned HOST_WIDE_INT bitregion_end, unsigned int align, enum machine_mode largest_mode, bool volatilep)
void get_mode_bounds (enum machine_mode mode, int sign, enum machine_mode target_mode, rtx *mmin, rtx *mmax)

Variables

tree sizetype_tab [(int) stk_type_kind_last]
unsigned int maximum_field_alignment = TARGET_DEFAULT_PACK_STRUCT * BITS_PER_UNIT
static int reference_types_internal = 0
static vec< tree, va_gc > * size_functions

Function Documentation

tree bit_from_pos ( )
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.   

Referenced by bit_position(), and rli_size_so_far().

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

References tree_int_cst_equal().

Referenced by byte_position(), and rli_size_unit_so_far().

void compute_record_mode ( )
Compute the TYPE_MODE for the TYPE (which is a RECORD_TYPE).   

References bit_position(), host_integerp(), integer_zerop(), mode_for_size_tree(), simple_cst_equal(), and targetm.

Referenced by finish_record_layout().

static tree copy_self_referential_tree_r ( )
static
Similar to copy_tree_r but do not copy component references involving
   PLACEHOLDER_EXPRs.  These nodes are spotted in find_placeholder_in_expr
   and substituted in substitute_in_expr.   

References copy_tree_r(), tcc_constant, tcc_declaration, and tcc_type.

Referenced by self_referential_size().

void debug_rli ( record_layout_info  )
static void do_type_align ( )
inlinestatic
Subroutine of layout_decl: Force alignment required for the data type.
   But if the decl itself wants greater alignment, don't override that.   

Referenced by layout_decl().

unsigned int element_precision ( )
Return the precision of the mode, or for a complex or vector mode the
   precision of the mode of its elements.   
static int excess_unit_span ( HOST_WIDE_INT  byte_offset,
HOST_WIDE_INT  bit_offset,
HOST_WIDE_INT  size,
HOST_WIDE_INT  align,
tree  type 
)
static
A bitfield of SIZE with a required access alignment of ALIGN is allocated
   at BYTE_OFFSET / BIT_OFFSET.  Return nonzero if the field would span more
   units of alignment than the underlying TYPE.   

References HOST_WIDE_INT, offset, and tree_low_cst().

Referenced by place_field().

static void finalize_record_size ( record_layout_info  )
static

Referenced by finish_record_layout().

static void finalize_record_size ( )
static
void finalize_size_functions ( void  )
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(), cgraph_finalize_function(), dump_function(), gimplify_function_tree(), set_cfun(), size_functions, TDI_generic, TDI_original, and vec_free().

Referenced by finalize_compilation_unit().

static void finalize_type_size ( tree  )
static
static void finalize_type_size ( )
static
Compute TYPE_SIZE and TYPE_ALIGN for TYPE, once it has been laid
   out.   

References variable_size().

static void finish_bitfield_layout ( )
static
Compute and set FIELD_DECLs for the underlying objects we should
   use for bitfield access for the structure laid out with RLI.   

References finish_bitfield_representative(), host_integerp(), integer_zerop(), operand_equal_p(), start_bitfield_representative(), and record_layout_info_s::t.

Referenced by finish_record_layout().

static void finish_bitfield_representative ( )
static
Finish up a bitfield group that was started by creating the underlying
   object REPR with the last field in the bitfield group FIELD.   

References build_array_type_nelts(), host_integerp(), HOST_WIDE_INT, tree_low_cst(), lang_hooks_for_types::type_for_mode, and lang_hooks::types.

Referenced by finish_bitfield_layout().

void finish_builtin_struct ( tree  type,
const char *  name,
tree  fields,
tree  align_type 
)
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 get_identifier(), layout_decl(), layout_type(), and type().

Referenced by build_fn_info_type(), and build_info_type().

void finish_record_layout ( )
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(), layout_decl(), record_layout_info_s::pending_statics, record_layout_info_s::t, vec_free(), and vec_safe_is_empty().

Referenced by layout_type().

void fixup_signed_type ( )
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.
   E.g. for Pascal, when the -fsigned-char option is given.   

References layout_type(), and set_min_and_max_values_for_integral_type().

Referenced by build_nonstandard_integer_type(), and make_signed_type().

void fixup_unsigned_type ( )
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(), and set_min_and_max_values_for_integral_type().

Referenced by build_nonstandard_integer_type(), and make_unsigned_type().

enum machine_mode get_best_mode ( int  bitsize,
int  bitpos,
unsigned HOST_WIDE_INT  bitregion_start,
unsigned HOST_WIDE_INT  bitregion_end,
unsigned int  align,
enum machine_mode  largest_mode,
bool  volatilep 
)
Find the best machine mode to use when referencing a bit field of length
   BITSIZE bits starting at BITPOS.

   BITREGION_START is the bit position of the first bit in this
   sequence of bit fields.  BITREGION_END is the last bit in this
   sequence.  If these two fields are non-zero, we should restrict the
   memory access to that range.  Otherwise, we are allowed to touch
   any adjacent non bit-fields.

   The underlying object is known to be aligned to a boundary of ALIGN bits.
   If LARGEST_MODE is not VOIDmode, it means that we should not use a mode
   larger than LARGEST_MODE (usually SImode).

   If no mode meets all these conditions, we return VOIDmode.

   If VOLATILEP is false and SLOW_BYTE_ACCESS is false, we return the
   smallest mode meeting these conditions.

   If VOLATILEP is false and SLOW_BYTE_ACCESS is true, we return the
   largest mode (but a mode no wider than UNITS_PER_WORD) that meets
   all the conditions.

   If VOLATILEP is true the narrow_volatile_bitfields target hook is used to
   decide which of the above modes should be used.   

References bit_field_mode_iterator::next_mode(), and bit_field_mode_iterator::prefer_smaller_modes().

Referenced by extract_fixed_bit_field(), fold_truth_andor_1(), optimize_bit_field_compare(), optimize_bitfield_assignment_op(), store_bit_field(), and store_fixed_bit_field().

unsigned int get_mode_alignment ( )
Return the alignment of MODE. This will be bounded by 1 and
   BIGGEST_ALIGNMENT.   

References mode_base_align.

void get_mode_bounds ( enum machine_mode  mode,
int  sign,
enum machine_mode  target_mode,
rtx mmin,
rtx mmax 
)
Gets minimal and maximal values for MODE (signed or unsigned depending on
   SIGN).  The returned constants are made to be usable in TARGET_MODE.   

References gen_int_mode(), HOST_BITS_PER_WIDE_INT, and HOST_WIDE_INT.

Referenced by determine_max_iter(), iv_number_of_iterations(), shorten_into_mode(), and simplify_const_relational_operation().

void initialize_sizetypes ( void  )
Initialize sizetypes so layout_type can use them.   

References get_identifier(), make_signed_type(), set_min_and_max_values_for_integral_type(), and smallest_mode_for_size().

Referenced by build_common_tree_nodes().

enum machine_mode int_mode_for_mode ( )
Find an integer mode of the exact same size, or BLKmode on failure.   

References mode_for_size().

void internal_reference_types ( void  )
Show that REFERENCE_TYPES are internal and should use address_mode.
   Called only by front end.   

References reference_types_internal.

void layout_decl ( )
Set the size, mode and alignment of a ..._DECL node.
   TYPE_DECL does need this for C++.
   Note that LABEL_DECL and CONST_DECL nodes do not need this,
   and FUNCTION_DECL nodes have them set up in a special (and simple) way.
   Don't call layout_decl for them.

   KNOWN_ALIGN is the amount of alignment we can assume this
   decl has with no special effort.  It is relevant only for FIELD_DECLs
   and depends on the previous fields.
   All that matters about KNOWN_ALIGN is which powers of 2 divide it.
   If KNOWN_ALIGN is 0, it means, "as much alignment as you like":
   the record will be aligned to suit.   

References compare_tree_int(), do_type_align(), fold_convert_loc(), integer_zerop(), maximum_field_alignment, mode_for_size_tree(), set_mem_attributes(), size_binop_loc(), targetm, type(), variable_size(), and warning().

Referenced by assemble_variable(), build_decl_stat(), build_fake_var_decl(), expand_expr_real_1(), finalize_nesting_tree_1(), finish_builtin_struct(), finish_record_layout(), ipa_modify_formal_parameters(), place_field(), relayout_decl(), split_complex_args(), and update_alignment_for_field().

tree make_accum_type ( )
Create and return a type for accum of PRECISION bits, UNSIGNEDP,
   and SATP.   

References layout_type(), mode_for_size(), and type().

Referenced by make_or_reuse_accum_type().

tree make_fract_type ( )
Create and return a type for fract of PRECISION bits, UNSIGNEDP,
   and SATP.   

References layout_type(), mode_for_size(), and type().

Referenced by make_or_reuse_fract_type().

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

References fixup_signed_type(), and type().

Referenced by build_common_tree_nodes(), initialize_sizetypes(), and make_or_reuse_type().

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

References fixup_unsigned_type(), and type().

Referenced by build_common_tree_nodes(), and make_or_reuse_type().

static enum machine_mode mode_for_array ( )
static
Return the natural mode of an array, given that it is SIZE bytes in
   total and has elements of type ELEM_TYPE.   

References host_integerp(), HOST_WIDE_INT, mode_for_size_tree(), simple_cst_equal(), targetm, and tree_low_cst().

Referenced by layout_type().

enum machine_mode mode_for_size ( )
Return the machine mode to use for a nonscalar of SIZE bits.  The
   mode must be in class MCLASS, and have exactly that many value bits;
   it may have padding as well.  If LIMIT is nonzero, modes of wider
   than MAX_FIXED_MODE_SIZE will not be used.   
enum machine_mode mode_for_size_tree ( )
Similar, except passed a tree node.   

References host_integerp(), HOST_WIDE_INT, mode_for_size(), tree_low_cst(), and ui.

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

enum machine_mode mode_for_vector ( )
Find a mode that is suitable for representing a vector with
   NUNITS elements of mode INNERMODE.  Returns BLKmode if there
   is no suitable mode.   

References mode_for_size().

void normalize_offset ( )
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(), offset, and pos_from_bit().

Referenced by normalize_rli().

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

References record_layout_info_s::bitpos, normalize_offset(), record_layout_info_s::offset, and record_layout_info_s::offset_align.

Referenced by finalize_record_size(), and place_field().

static void place_union_field ( record_layout_info  ,
tree   
)
static

Referenced by place_field().

static void place_union_field ( )
static
Called from place_field to handle unions.   

References record_layout_info_s::offset, record_layout_info_s::t, and update_alignment_for_field().

void pos_from_bit ( tree poffset,
tree pbitpos,
unsigned int  off_align,
tree  pos 
)
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 tree_int_cst_equal().

Referenced by normalize_offset().

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

References layout_decl().

Referenced by decl_attributes(), and vectorize_loops().

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

References bit_from_pos(), record_layout_info_s::bitpos, and record_layout_info_s::offset.

Referenced by finalize_record_size().

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

References record_layout_info_s::bitpos, byte_from_pos(), and record_layout_info_s::offset.

Referenced by finalize_record_size().

static tree self_referential_size ( tree  )
static

Referenced by variable_size().

static tree self_referential_size ( )
static
void set_min_and_max_values_for_integral_type ( tree  type,
int  precision,
bool  is_unsigned 
)
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 build_int_cst(), build_int_cst_wide(), HOST_BITS_PER_WIDE_INT, and HOST_WIDE_INT.

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

enum machine_mode smallest_mode_for_size ( )
Similar, but never return BLKmode; return the narrowest mode that
   contains at least the requested number of value bits.   
static tree start_bitfield_representative ( )
static
Return a new underlying object for a bitfield started with FIELD.   

Referenced by finish_bitfield_layout().

record_layout_info start_record_layout ( )
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 record_layout_info_s::bitpos, maximum_field_alignment, record_layout_info_s::offset, record_layout_info_s::offset_align, record_layout_info_s::packed_maybe_necessary, record_layout_info_s::pending_statics, record_layout_info_s::prev_field, record_layout_info_s::record_align, record_layout_info_s::remaining_in_alignment, record_layout_info_s::t, and record_layout_info_s::unpacked_align.

Referenced by layout_type().

unsigned int update_alignment_for_field ( record_layout_info  rli,
tree  field,
unsigned int  known_align 
)
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 integer_zerop(), layout_decl(), maximum_field_alignment, record_layout_info_s::prev_field, record_layout_info_s::record_align, record_layout_info_s::t, targetm, and record_layout_info_s::unpacked_align.

Referenced by place_field(), and place_union_field().

tree variable_size ( )
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 lang_hooks::decls, lang_hooks_for_decls::global_bindings_p, save_expr(), and self_referential_size().

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

enum machine_mode vector_type_mode ( )
Vector types need to re-check the target flags each time we report
   the machine mode.  We need to do this because attribute target can
   change the result of vector_mode_supported_p and have_regs_of_mode
   on a per-function basis.  Thus the TYPE_MODE of a VECTOR_TYPE can
   change on a per-function basis.   
??? Possibly a better solution is to run through all the types
   referenced by a function and re-compute the TYPE_MODE once, rather
   than make the TYPE_MODE macro call a function.   

References mode_for_size(), and targetm.


Variable Documentation

unsigned int maximum_field_alignment = TARGET_DEFAULT_PACK_STRUCT * BITS_PER_UNIT
If nonzero, this is an upper limit on alignment of structure fields.
   The value is measured in bits.   

Referenced by layout_decl(), place_field(), process_options(), start_record_layout(), and update_alignment_for_field().

int reference_types_internal = 0
static
Nonzero if all REFERENCE_TYPEs are internal and hence should be allocated
   in the address spaces' address_mode, not pointer_mode.   Set only by
   internal_reference_types called only by a front end.   

Referenced by internal_reference_types(), and layout_type().

vec<tree, va_gc>* size_functions
static
An array of functions used for self-referential size computation.   

Referenced by finalize_size_functions(), and self_referential_size().

tree sizetype_tab[(int) stk_type_kind_last]
@verbatim C-compiler utilities for types and variables storage layout

Copyright (C) 1987-2013 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/.

Data type for the expressions representing sizes of data types.
   It is the first integer type laid out.   

Referenced by preload_common_nodes(), and size_int_kind().