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.  
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.  
         Make sure the COMMON block control variable gets initialized.
         Note that there's no point in doing this for aliases; we only
         need to do this once for the main variable.  
     Indicate that the value of the TLS variable may be found elsewhere,
     preventing the variable from re-appearing in the GIMPLE.  We cheat
     and use the control variable here (rather than a full call_expr),
     which is special-cased inside the DWARF2 output routines.  
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.  
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.  
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.  
static tree emutls_decl ( )
static
   Look up the control variable for the TLS variable DECL.  

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.  
static bool gate_emutls ( )
static
   If the target supports TLS natively, we need do nothing here.  
static tree gen_emutls_addr ( )
static
   Given a TLS variable DECL, return an SSA_NAME holding its address.
   Append any new computation statements required to D->SEQ.  
     Compute the address of the TLS variable with help from runtime.  
         We may be adding a new reference to a new variable to the function.
         This means we have to play with the ipa-reference web.  
         Record this ssa_name for possible use later in the basic block.  
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.  
     Create varpool node for the new variable and finalize it if it is
     not external one.  

References targetm.

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 get_identifier(), and type().

Referenced by ipa_lower_emutls().

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 targetm.

static unsigned int ipa_lower_emutls ( )
static
   Main entry point to the tls lowering pass.  
     Examine all global variables for TLS variables.  
     If we found no TLS variables, then there is no further work to do.  
     Allocate the on-the-side arrays that share indicies with the TLS vars.  
     Create the control variables for each TLS variable.  
     If there were any aliases, then frob the alias_pairs vector.  
     Adjust all uses of TLS variables within the function bodies.  
     Generate the constructor for any COMMON control variables created.  

References alias_pair::decl, emutls_decl(), get_emutls_object_name(), and alias_pair::target.

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.  
         If this is not a straight-forward "&var", but rather something
         like "&var.a", then we may need special handling.  
             If we're allowed more than just is_gimple_val, continue.  
             See if any substitution would be made.  
             If so, then extract this entire sub-expression "&p->a" into a
             new assignment statement, and substitute yet another SSA_NAME.  
         FALLTHRU 
         We're not interested in other decls or types, only subexpressions.  
         FALLTHRU 
         Special-case the return of SSA_NAME, since it's so common.  
         Replace "&var" with "addr" in the statement.  
         Replace "var" with "*addr" in the statement.  
static void lower_emutls_function_body ( )
static
   Lower the entire function NODE.  
     This is where we introduce the declaration to the IL and so we have to
     create a node for it.  
         Lower each of the PHI nodes of the block, as we may have 
         propagated &tlsvar into a PHI argument.  These loops are
         arranged so that we process each edge at once, and each
         PHI argument for that edge.  
             The calls will be inserted on the edges, and the frequencies
             will be computed during the commit process.  
                 We can re-use any SSA_NAME created on this edge.  
                 Insert all statements generated by all phi nodes for this
                 particular edge all at once.  
         We can re-use any SSA_NAME created during this basic block.  
         Lower each of the statements of the block.  
             If any new statements were created, insert them immediately
             before the first use.  This prevents variable lifetimes from
             becoming unnecessarily long.  

References gsi_insert_seq_on_edge(), and lower_emutls_data::seq.

static void lower_emutls_phi_arg ( )
static
   Lower the I'th operand of PHI.  
     Early out for a very common case we don't care about.  
     For normal statements, we let update_stmt do its job.  But for phi
     nodes, we have to manipulate the immediate use list by hand.  

References lower_emutls_data::bb, lower_emutls_data::bb_freq, lower_emutls_data::builtin_decl, builtin_decl_explicit(), lower_emutls_data::builtin_node, lower_emutls_data::cfun_node, cgraph_get_create_node(), symtab_node_base::decl, gimple_seq_empty_p(), phi_nodes(), basic_block_def::preds, and push_cfun().

static void lower_emutls_stmt ( )
static
   Lower all of the operands of STMT.  

References link_imm_use_stmt().

simple_ipa_opt_pass* make_pass_ipa_lower_emutls ( )
static tree new_emutls_decl ( )
static
   Create and return the control variable for the TLS variable DECL.  
     If we're not allowed to change the proxy object's alignment,
     pretend it has been set by the user.  
     If the target wants the control variables grouped, do so.  
     If this variable is defined locally, then we need to initialize the
     control structure with size and alignment information.  Initialization
     of COMMON block variables happens elsewhere via a constructor.  
     Create varpool node for the new variable and finalize it if it is
     not external one.  

References targetm.

static tree prefix_name ( )
static
   Create an IDENTIFIER_NODE by prefixing PREFIX to the
   IDENTIFIER_NODE NAME's 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.  
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.