GCC Middle and Back End API Reference
tree-emutls.c File Reference

Data Structures

struct  lower_emutls_data

Functions

static tree prefix_name ()
static tree get_emutls_object_name ()
tree default_emutls_var_fields ()
tree default_emutls_var_init ()
static tree get_emutls_object_type ()
static tree get_emutls_init_templ_addr ()
static tree new_emutls_decl ()
static unsigned int emutls_index ()
static tree emutls_decl ()
static void emutls_common_1 ()
static tree gen_emutls_addr ()
static tree lower_emutls_1 ()
static void lower_emutls_stmt ()
static void lower_emutls_phi_arg ()
static void clear_access_vars ()
static void lower_emutls_function_body ()
static bool create_emultls_var ()
static unsigned int ipa_lower_emutls ()
static bool gate_emutls ()
simple_ipa_opt_passmake_pass_ipa_lower_emutls ()

Variables

static varpool_node_set tls_vars
static vec< varpool_node_ptrcontrol_vars
static vec< treeaccess_vars
static tree emutls_object_type

Function Documentation

static void clear_access_vars ( )
inlinestatic
Clear the ACCESS_VARS array, in order to begin a new block.   

References memset().

Referenced by lower_emutls_function_body().

static bool create_emultls_var ( )
static
Create emutls variable for VAR, DATA is pointer to static
   ctor body we can add constructors to.
   Callback for varpool_for_variable_and_aliases.   

References symtab_node_base::alias, symtab_node_base::analyzed, symtab_node_base::decl, emutls_common_1(), new_emutls_decl(), varpool_node::symbol, varpool_alias_target(), and varpool_get_node().

Referenced by ipa_lower_emutls().

tree default_emutls_var_fields ( )
Create the fields of the type for the control variables.  Ordinarily
   this must match struct __emutls_object defined in emutls.c.  However
   this is a target hook so that VxWorks can define its own layout.   

References get_identifier(), type(), lang_hooks_for_types::type_for_mode, lang_hooks::types, and word_mode.

tree default_emutls_var_init ( )
Initialize emulated tls object TO, which refers to TLS variable DECL and
   is initialized by PROXY.  As above, this is the default implementation of
   a target hook overridden by VxWorks.   

References build_constructor(), build_int_cst(), constructor_elt_d::index, constructor_elt_d::value, and vec_alloc().

static void emutls_common_1 ( )
static
Generate a call statement to initialize CONTROL_DECL for TLS_DECL.
   This only needs to happen for TLS COMMON variables; non-COMMON
   variables can be initialized statically.  Insert the generated
   call statement at the end of PSTMTS.   

References append_to_statement_list(), build_call_expr(), build_int_cst(), builtin_decl_explicit(), get_emutls_init_templ_addr(), lang_hooks_for_types::type_for_mode, lang_hooks::types, and word_mode.

Referenced by create_emultls_var().

static tree emutls_decl ( )
static
Look up the control variable for the TLS variable DECL.   

References symtab_node_base::decl, emutls_index(), and varpool_node::symbol.

Referenced by ipa_lower_emutls().

static unsigned int emutls_index ( )
static
Look up the index of the TLS variable DECL.  This index can then be
   used in both the control_vars and access_vars arrays.   

References varpool_node_set_iterator::index, varpool_get_node(), and varpool_node_set_find().

Referenced by emutls_decl(), and gen_emutls_addr().

static bool gate_emutls ( )
static
If the target supports TLS natively, we need do nothing here.   

References targetm.

static tree get_emutls_init_templ_addr ( )
static
Create a read-only variable like DECL, with the same DECL_INITIAL.
   This will be used for initializing the emulated tls data area.   

References build_string(), make_decl_one_only(), prefix_name(), strlen(), targetm, varpool_add_new_variable(), and varpool_node_for_decl().

Referenced by emutls_common_1(), and new_emutls_decl().

static tree get_emutls_object_name ( )
static
Create an identifier for the struct __emutls_object, given an identifier
   of the DECL_ASSEMBLY_NAME of the original object.   

References prefix_name(), and targetm.

Referenced by ipa_lower_emutls(), and new_emutls_decl().

static tree get_emutls_object_type ( )
static
Create the structure for struct __emutls_object.  This should match the
   structure at the top of emutls.c, modulo the union there.   

References emutls_object_type, get_identifier(), layout_type(), lang_hooks_for_types::make_type, targetm, type(), and lang_hooks::types.

Referenced by new_emutls_decl().

static tree lower_emutls_1 ( )
static
Callback for walk_gimple_op.  D = WI->INFO is a struct lower_emutls_data.
   Given an operand *PTR within D->STMT, if the operand references a TLS
   variable, then lower the reference to a call to the runtime.  Insert
   any new statements required into D->SEQ; the caller is responsible for
   placing those appropriately.   

References build_int_cst(), walk_stmt_info::changed, create_tmp_var(), gen_emutls_addr(), gimple_assign_set_lhs(), gimple_seq_add_stmt(), gimple_set_location(), walk_stmt_info::info, lower_emutls_data::loc, make_ssa_name(), lower_emutls_data::seq, and walk_stmt_info::val_only.

Referenced by lower_emutls_phi_arg(), and lower_emutls_stmt().

static void lower_emutls_stmt ( )
static
simple_ipa_opt_pass* make_pass_ipa_lower_emutls ( )
static tree prefix_name ( )
static
Create an IDENTIFIER_NODE by prefixing PREFIX to the
   IDENTIFIER_NODE NAME's name.   

References get_identifier(), memcpy(), and strlen().

Referenced by get_emutls_init_templ_addr(), and get_emutls_object_name().


Variable Documentation

vec<tree> access_vars
static
For the current basic block, an SSA_NAME that has computed the address 
   of the TLS variable at the corresponding index.   
vec<varpool_node_ptr> control_vars
static
tree emutls_object_type
static
The type of the control structure, shared with the emutls.c runtime.   

Referenced by get_emutls_object_type().

varpool_node_set tls_vars
static
@verbatim Lower TLS operations to emulation functions.

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

Whenever a target does not support thread-local storage (TLS) natively,
   we can emulate it with some run-time support in libgcc.  This will in
   turn rely on "keyed storage" a-la pthread_key_create; essentially all
   thread libraries provide such functionality.

   In order to coordinate with the libgcc runtime, each TLS variable is
   described by a "control variable".  This control variable records the
   required size, alignment, and initial value of the TLS variable for
   instantiation at runtime.  It also stores an integer token to be used
   by the runtime to find the address of the variable within each thread.

   On the compiler side, this means that we need to replace all instances
   of "tls_var" in the code with "*__emutls_get_addr(&control_var)".  We
   also need to eliminate "tls_var" from the symbol table and introduce
   "control_var".

   We used to perform all of the transformations during conversion to rtl,
   and the variable substitutions magically within assemble_variable.
   However, this late fiddling of the symbol table conflicts with LTO and
   whole-program compilation.  Therefore we must now make all the changes
   to the symbol table early in the GIMPLE optimization path, before we
   write things out to LTO intermediate files.   
These two vectors, once fully populated, are kept in lock-step so that
   the index of a TLS variable equals the index of its control variable in
   the other vector.