1 /* Lower TLS operations to emulation functions.
2 Copyright (C) 2006-2014 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
11 GCC is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
24 #include "stor-layout.h"
26 #include "basic-block.h"
27 #include "tree-ssa-alias.h"
28 #include "internal-fn.h"
29 #include "gimple-expr.h"
32 #include "gimple-iterator.h"
33 #include "gimple-walk.h"
34 #include "tree-pass.h"
35 #include "gimple-ssa.h"
37 #include "tree-phinodes.h"
38 #include "ssa-iterators.h"
39 #include "stringpool.h"
40 #include "tree-ssanames.h"
41 #include "langhooks.h"
43 #include "targhooks.h"
44 #include "tree-iterator.h"
47 /* Whenever a target does not support thread-local storage (TLS) natively,
48 we can emulate it with some run-time support in libgcc. This will in
49 turn rely on "keyed storage" a-la pthread_key_create; essentially all
50 thread libraries provide such functionality.
52 In order to coordinate with the libgcc runtime, each TLS variable is
53 described by a "control variable". This control variable records the
54 required size, alignment, and initial value of the TLS variable for
55 instantiation at runtime. It also stores an integer token to be used
56 by the runtime to find the address of the variable within each thread.
58 On the compiler side, this means that we need to replace all instances
59 of "tls_var" in the code with "*__emutls_get_addr(&control_var)". We
60 also need to eliminate "tls_var" from the symbol table and introduce
63 We used to perform all of the transformations during conversion to rtl,
64 and the variable substitutions magically within assemble_variable.
65 However, this late fiddling of the symbol table conflicts with LTO and
66 whole-program compilation. Therefore we must now make all the changes
67 to the symbol table early in the GIMPLE optimization path, before we
68 write things out to LTO intermediate files. */
70 /* These two vectors, once fully populated, are kept in lock-step so that
71 the index of a TLS variable equals the index of its control variable in
73 static varpool_node_set tls_vars
;
74 static vec
<varpool_node
*> control_vars
;
76 /* For the current basic block, an SSA_NAME that has computed the address
77 of the TLS variable at the corresponding index. */
78 static vec
<tree
> access_vars
;
80 /* The type of the control structure, shared with the emutls.c runtime. */
81 static tree emutls_object_type
;
83 #if !defined (NO_DOT_IN_LABEL)
84 # define EMUTLS_SEPARATOR "."
85 #elif !defined (NO_DOLLAR_IN_LABEL)
86 # define EMUTLS_SEPARATOR "$"
88 # define EMUTLS_SEPARATOR "_"
91 /* Create an IDENTIFIER_NODE by prefixing PREFIX to the
92 IDENTIFIER_NODE NAME's name. */
95 prefix_name (const char *prefix
, tree name
)
97 unsigned plen
= strlen (prefix
);
98 unsigned nlen
= strlen (IDENTIFIER_POINTER (name
));
99 char *toname
= (char *) alloca (plen
+ nlen
+ 1);
101 memcpy (toname
, prefix
, plen
);
102 memcpy (toname
+ plen
, IDENTIFIER_POINTER (name
), nlen
+ 1);
104 return get_identifier (toname
);
107 /* Create an identifier for the struct __emutls_object, given an identifier
108 of the DECL_ASSEMBLY_NAME of the original object. */
111 get_emutls_object_name (tree name
)
113 const char *prefix
= (targetm
.emutls
.var_prefix
114 ? targetm
.emutls
.var_prefix
115 : "__emutls_v" EMUTLS_SEPARATOR
);
116 return prefix_name (prefix
, name
);
119 /* Create the fields of the type for the control variables. Ordinarily
120 this must match struct __emutls_object defined in emutls.c. However
121 this is a target hook so that VxWorks can define its own layout. */
124 default_emutls_var_fields (tree type
, tree
*name ATTRIBUTE_UNUSED
)
126 tree word_type_node
, field
, next_field
;
128 field
= build_decl (UNKNOWN_LOCATION
,
129 FIELD_DECL
, get_identifier ("__templ"), ptr_type_node
);
130 DECL_CONTEXT (field
) = type
;
133 field
= build_decl (UNKNOWN_LOCATION
,
134 FIELD_DECL
, get_identifier ("__offset"),
136 DECL_CONTEXT (field
) = type
;
137 DECL_CHAIN (field
) = next_field
;
140 word_type_node
= lang_hooks
.types
.type_for_mode (word_mode
, 1);
141 field
= build_decl (UNKNOWN_LOCATION
,
142 FIELD_DECL
, get_identifier ("__align"),
144 DECL_CONTEXT (field
) = type
;
145 DECL_CHAIN (field
) = next_field
;
148 field
= build_decl (UNKNOWN_LOCATION
,
149 FIELD_DECL
, get_identifier ("__size"), word_type_node
);
150 DECL_CONTEXT (field
) = type
;
151 DECL_CHAIN (field
) = next_field
;
156 /* Initialize emulated tls object TO, which refers to TLS variable DECL and
157 is initialized by PROXY. As above, this is the default implementation of
158 a target hook overridden by VxWorks. */
161 default_emutls_var_init (tree to
, tree decl
, tree proxy
)
163 vec
<constructor_elt
, va_gc
> *v
;
166 tree type
= TREE_TYPE (to
);
167 tree field
= TYPE_FIELDS (type
);
170 elt
.value
= fold_convert (TREE_TYPE (field
), DECL_SIZE_UNIT (decl
));
173 field
= DECL_CHAIN (field
);
175 elt
.value
= build_int_cst (TREE_TYPE (field
),
176 DECL_ALIGN_UNIT (decl
));
179 field
= DECL_CHAIN (field
);
181 elt
.value
= null_pointer_node
;
184 field
= DECL_CHAIN (field
);
189 return build_constructor (type
, v
);
192 /* Create the structure for struct __emutls_object. This should match the
193 structure at the top of emutls.c, modulo the union there. */
196 get_emutls_object_type (void)
198 tree type
, type_name
, field
;
200 type
= emutls_object_type
;
204 emutls_object_type
= type
= lang_hooks
.types
.make_type (RECORD_TYPE
);
206 field
= targetm
.emutls
.var_fields (type
, &type_name
);
208 type_name
= get_identifier ("__emutls_object");
209 type_name
= build_decl (UNKNOWN_LOCATION
,
210 TYPE_DECL
, type_name
, type
);
211 TYPE_NAME (type
) = type_name
;
212 TYPE_FIELDS (type
) = field
;
218 /* Create a read-only variable like DECL, with the same DECL_INITIAL.
219 This will be used for initializing the emulated tls data area. */
222 get_emutls_init_templ_addr (tree decl
)
226 if (targetm
.emutls
.register_common
&& !DECL_INITIAL (decl
)
227 && !DECL_SECTION_NAME (decl
))
228 return null_pointer_node
;
230 name
= DECL_ASSEMBLER_NAME (decl
);
231 if (!targetm
.emutls
.tmpl_prefix
|| targetm
.emutls
.tmpl_prefix
[0])
233 const char *prefix
= (targetm
.emutls
.tmpl_prefix
234 ? targetm
.emutls
.tmpl_prefix
235 : "__emutls_t" EMUTLS_SEPARATOR
);
236 name
= prefix_name (prefix
, name
);
239 to
= build_decl (DECL_SOURCE_LOCATION (decl
),
240 VAR_DECL
, name
, TREE_TYPE (decl
));
241 SET_DECL_ASSEMBLER_NAME (to
, DECL_NAME (to
));
243 DECL_ARTIFICIAL (to
) = 1;
244 TREE_USED (to
) = TREE_USED (decl
);
245 TREE_READONLY (to
) = 1;
246 DECL_IGNORED_P (to
) = 1;
247 DECL_CONTEXT (to
) = DECL_CONTEXT (decl
);
248 DECL_PRESERVE_P (to
) = DECL_PRESERVE_P (decl
);
250 DECL_WEAK (to
) = DECL_WEAK (decl
);
251 if (DECL_ONE_ONLY (decl
))
253 TREE_STATIC (to
) = TREE_STATIC (decl
);
254 TREE_PUBLIC (to
) = TREE_PUBLIC (decl
);
255 DECL_VISIBILITY (to
) = DECL_VISIBILITY (decl
);
256 make_decl_one_only (to
, DECL_ASSEMBLER_NAME (to
));
259 TREE_STATIC (to
) = 1;
261 DECL_VISIBILITY_SPECIFIED (to
) = DECL_VISIBILITY_SPECIFIED (decl
);
262 DECL_INITIAL (to
) = DECL_INITIAL (decl
);
263 DECL_INITIAL (decl
) = NULL
;
265 if (targetm
.emutls
.tmpl_section
)
266 set_decl_section_name (to
, targetm
.emutls
.tmpl_section
);
268 set_decl_section_name (to
, DECL_SECTION_NAME (decl
));
270 /* Create varpool node for the new variable and finalize it if it is
272 if (DECL_EXTERNAL (to
))
273 varpool_node::get_create (to
);
275 varpool_add_new_variable (to
);
276 return build_fold_addr_expr (to
);
279 /* Create and return the control variable for the TLS variable DECL. */
282 new_emutls_decl (tree decl
, tree alias_of
)
286 name
= DECL_ASSEMBLER_NAME (decl
);
287 to
= build_decl (DECL_SOURCE_LOCATION (decl
), VAR_DECL
,
288 get_emutls_object_name (name
),
289 get_emutls_object_type ());
291 SET_DECL_ASSEMBLER_NAME (to
, DECL_NAME (to
));
293 DECL_ARTIFICIAL (to
) = 1;
294 DECL_IGNORED_P (to
) = 1;
295 TREE_READONLY (to
) = 0;
296 TREE_STATIC (to
) = 1;
298 DECL_PRESERVE_P (to
) = DECL_PRESERVE_P (decl
);
299 DECL_CONTEXT (to
) = DECL_CONTEXT (decl
);
300 TREE_USED (to
) = TREE_USED (decl
);
301 TREE_PUBLIC (to
) = TREE_PUBLIC (decl
);
302 DECL_EXTERNAL (to
) = DECL_EXTERNAL (decl
);
303 DECL_COMMON (to
) = DECL_COMMON (decl
);
304 DECL_WEAK (to
) = DECL_WEAK (decl
);
305 DECL_VISIBILITY (to
) = DECL_VISIBILITY (decl
);
306 DECL_VISIBILITY_SPECIFIED (to
) = DECL_VISIBILITY_SPECIFIED (decl
);
307 DECL_DLLIMPORT_P (to
) = DECL_DLLIMPORT_P (decl
);
309 DECL_ATTRIBUTES (to
) = targetm
.merge_decl_attributes (decl
, to
);
311 if (DECL_ONE_ONLY (decl
))
312 make_decl_one_only (to
, DECL_ASSEMBLER_NAME (to
));
314 set_decl_tls_model (to
, TLS_MODEL_EMULATED
);
316 /* If we're not allowed to change the proxy object's alignment,
317 pretend it has been set by the user. */
318 if (targetm
.emutls
.var_align_fixed
)
319 DECL_USER_ALIGN (to
) = 1;
321 /* If the target wants the control variables grouped, do so. */
322 if (!DECL_COMMON (to
) && targetm
.emutls
.var_section
)
324 set_decl_section_name (to
, targetm
.emutls
.var_section
);
327 /* If this variable is defined locally, then we need to initialize the
328 control structure with size and alignment information. Initialization
329 of COMMON block variables happens elsewhere via a constructor. */
330 if (!DECL_EXTERNAL (to
)
331 && (!DECL_COMMON (to
)
332 || (DECL_INITIAL (decl
)
333 && DECL_INITIAL (decl
) != error_mark_node
)))
335 tree tmpl
= get_emutls_init_templ_addr (decl
);
336 DECL_INITIAL (to
) = targetm
.emutls
.var_init (to
, decl
, tmpl
);
337 record_references_in_initializer (to
, false);
340 /* Create varpool node for the new variable and finalize it if it is
342 if (DECL_EXTERNAL (to
))
343 varpool_node::get_create (to
);
345 varpool_add_new_variable (to
);
347 varpool_node::create_alias (to
,
348 varpool_node::get_for_asmname
349 (DECL_ASSEMBLER_NAME (DECL_VALUE_EXPR (alias_of
)))->decl
);
353 /* Look up the index of the TLS variable DECL. This index can then be
354 used in both the control_vars and access_vars arrays. */
357 emutls_index (tree decl
)
359 varpool_node_set_iterator i
;
361 i
= varpool_node_set_find (tls_vars
, varpool_node::get (decl
));
362 gcc_assert (i
.index
!= ~0u);
367 /* Look up the control variable for the TLS variable DECL. */
370 emutls_decl (tree decl
)
375 i
= emutls_index (decl
);
376 var
= control_vars
[i
];
380 /* Generate a call statement to initialize CONTROL_DECL for TLS_DECL.
381 This only needs to happen for TLS COMMON variables; non-COMMON
382 variables can be initialized statically. Insert the generated
383 call statement at the end of PSTMTS. */
386 emutls_common_1 (tree tls_decl
, tree control_decl
, tree
*pstmts
)
391 if (! DECL_COMMON (tls_decl
)
392 || (DECL_INITIAL (tls_decl
)
393 && DECL_INITIAL (tls_decl
) != error_mark_node
))
396 word_type_node
= lang_hooks
.types
.type_for_mode (word_mode
, 1);
398 x
= build_call_expr (builtin_decl_explicit (BUILT_IN_EMUTLS_REGISTER_COMMON
),
399 4, build_fold_addr_expr (control_decl
),
400 fold_convert (word_type_node
,
401 DECL_SIZE_UNIT (tls_decl
)),
402 build_int_cst (word_type_node
,
403 DECL_ALIGN_UNIT (tls_decl
)),
404 get_emutls_init_templ_addr (tls_decl
));
406 append_to_statement_list (x
, pstmts
);
409 struct lower_emutls_data
411 struct cgraph_node
*cfun_node
;
412 struct cgraph_node
*builtin_node
;
420 /* Given a TLS variable DECL, return an SSA_NAME holding its address.
421 Append any new computation statements required to D->SEQ. */
424 gen_emutls_addr (tree decl
, struct lower_emutls_data
*d
)
429 /* Compute the address of the TLS variable with help from runtime. */
430 index
= emutls_index (decl
);
431 addr
= access_vars
[index
];
438 cvar
= control_vars
[index
];
440 TREE_ADDRESSABLE (cdecl) = 1;
442 addr
= create_tmp_var (build_pointer_type (TREE_TYPE (decl
)), NULL
);
443 x
= gimple_build_call (d
->builtin_decl
, 1, build_fold_addr_expr (cdecl));
444 gimple_set_location (x
, d
->loc
);
446 addr
= make_ssa_name (addr
, x
);
447 gimple_call_set_lhs (x
, addr
);
449 gimple_seq_add_stmt (&d
->seq
, x
);
451 d
->cfun_node
->create_edge (d
->builtin_node
, x
, d
->bb
->count
, d
->bb_freq
);
453 /* We may be adding a new reference to a new variable to the function.
454 This means we have to play with the ipa-reference web. */
455 d
->cfun_node
->add_reference (cvar
, IPA_REF_ADDR
, x
);
457 /* Record this ssa_name for possible use later in the basic block. */
458 access_vars
[index
] = addr
;
464 /* Callback for walk_gimple_op. D = WI->INFO is a struct lower_emutls_data.
465 Given an operand *PTR within D->STMT, if the operand references a TLS
466 variable, then lower the reference to a call to the runtime. Insert
467 any new statements required into D->SEQ; the caller is responsible for
468 placing those appropriately. */
471 lower_emutls_1 (tree
*ptr
, int *walk_subtrees
, void *cb_data
)
473 struct walk_stmt_info
*wi
= (struct walk_stmt_info
*) cb_data
;
474 struct lower_emutls_data
*d
= (struct lower_emutls_data
*) wi
->info
;
476 bool is_addr
= false;
481 switch (TREE_CODE (t
))
484 /* If this is not a straight-forward "&var", but rather something
485 like "&var.a", then we may need special handling. */
486 if (TREE_CODE (TREE_OPERAND (t
, 0)) != VAR_DECL
)
490 /* If we're allowed more than just is_gimple_val, continue. */
497 /* See if any substitution would be made. */
498 save_changed
= wi
->changed
;
500 wi
->val_only
= false;
501 walk_tree (&TREE_OPERAND (t
, 0), lower_emutls_1
, wi
, NULL
);
504 /* If so, then extract this entire sub-expression "&p->a" into a
505 new assignment statement, and substitute yet another SSA_NAME. */
510 addr
= create_tmp_var (TREE_TYPE (t
), NULL
);
511 x
= gimple_build_assign (addr
, t
);
512 gimple_set_location (x
, d
->loc
);
514 addr
= make_ssa_name (addr
, x
);
515 gimple_assign_set_lhs (x
, addr
);
517 gimple_seq_add_stmt (&d
->seq
, x
);
522 wi
->changed
= save_changed
;
527 t
= TREE_OPERAND (t
, 0);
532 if (!DECL_THREAD_LOCAL_P (t
))
537 /* We're not interested in other decls or types, only subexpressions. */
543 /* Special-case the return of SSA_NAME, since it's so common. */
547 addr
= gen_emutls_addr (t
, d
);
550 /* Replace "&var" with "addr" in the statement. */
555 /* Replace "var" with "*addr" in the statement. */
556 t
= build2 (MEM_REF
, TREE_TYPE (t
), addr
,
557 build_int_cst (TREE_TYPE (addr
), 0));
565 /* Lower all of the operands of STMT. */
568 lower_emutls_stmt (gimple stmt
, struct lower_emutls_data
*d
)
570 struct walk_stmt_info wi
;
572 d
->loc
= gimple_location (stmt
);
574 memset (&wi
, 0, sizeof (wi
));
577 walk_gimple_op (stmt
, lower_emutls_1
, &wi
);
583 /* Lower the I'th operand of PHI. */
586 lower_emutls_phi_arg (gimple phi
, unsigned int i
, struct lower_emutls_data
*d
)
588 struct walk_stmt_info wi
;
589 struct phi_arg_d
*pd
= gimple_phi_arg (phi
, i
);
591 /* Early out for a very common case we don't care about. */
592 if (TREE_CODE (pd
->def
) == SSA_NAME
)
597 memset (&wi
, 0, sizeof (wi
));
600 walk_tree (&pd
->def
, lower_emutls_1
, &wi
, NULL
);
602 /* For normal statements, we let update_stmt do its job. But for phi
603 nodes, we have to manipulate the immediate use list by hand. */
606 gcc_assert (TREE_CODE (pd
->def
) == SSA_NAME
);
607 link_imm_use_stmt (&pd
->imm_use
, pd
->def
, phi
);
611 /* Clear the ACCESS_VARS array, in order to begin a new block. */
614 clear_access_vars (void)
616 memset (access_vars
.address (), 0,
617 access_vars
.length () * sizeof (tree
));
620 /* Lower the entire function NODE. */
623 lower_emutls_function_body (struct cgraph_node
*node
)
625 struct lower_emutls_data d
;
626 bool any_edge_inserts
= false;
628 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
631 d
.builtin_decl
= builtin_decl_explicit (BUILT_IN_EMUTLS_GET_ADDRESS
);
632 /* This is where we introduce the declaration to the IL and so we have to
633 create a node for it. */
634 d
.builtin_node
= cgraph_node::get_create (d
.builtin_decl
);
636 FOR_EACH_BB_FN (d
.bb
, cfun
)
638 gimple_stmt_iterator gsi
;
639 unsigned int i
, nedge
;
641 /* Lower each of the PHI nodes of the block, as we may have
642 propagated &tlsvar into a PHI argument. These loops are
643 arranged so that we process each edge at once, and each
644 PHI argument for that edge. */
645 if (!gimple_seq_empty_p (phi_nodes (d
.bb
)))
647 /* The calls will be inserted on the edges, and the frequencies
648 will be computed during the commit process. */
651 nedge
= EDGE_COUNT (d
.bb
->preds
);
652 for (i
= 0; i
< nedge
; ++i
)
654 edge e
= EDGE_PRED (d
.bb
, i
);
656 /* We can re-use any SSA_NAME created on this edge. */
657 clear_access_vars ();
660 for (gsi
= gsi_start_phis (d
.bb
);
663 lower_emutls_phi_arg (gsi_stmt (gsi
), i
, &d
);
665 /* Insert all statements generated by all phi nodes for this
666 particular edge all at once. */
669 gsi_insert_seq_on_edge (e
, d
.seq
);
670 any_edge_inserts
= true;
675 d
.bb_freq
= compute_call_stmt_bb_frequency (current_function_decl
, d
.bb
);
677 /* We can re-use any SSA_NAME created during this basic block. */
678 clear_access_vars ();
680 /* Lower each of the statements of the block. */
681 for (gsi
= gsi_start_bb (d
.bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
684 lower_emutls_stmt (gsi_stmt (gsi
), &d
);
686 /* If any new statements were created, insert them immediately
687 before the first use. This prevents variable lifetimes from
688 becoming unnecessarily long. */
690 gsi_insert_seq_before (&gsi
, d
.seq
, GSI_SAME_STMT
);
694 if (any_edge_inserts
)
695 gsi_commit_edge_inserts ();
700 /* Create emutls variable for VAR, DATA is pointer to static
701 ctor body we can add constructors to.
702 Callback for varpool_for_variable_and_aliases. */
705 create_emultls_var (varpool_node
*var
, void *data
)
710 cdecl = new_emutls_decl (var
->decl
,
711 var
->alias
&& var
->analyzed
712 ? var
->get_alias_target ()->decl
: NULL
);
714 cvar
= varpool_node::get (cdecl);
715 control_vars
.quick_push (cvar
);
719 /* Make sure the COMMON block control variable gets initialized.
720 Note that there's no point in doing this for aliases; we only
721 need to do this once for the main variable. */
722 emutls_common_1 (var
->decl
, cdecl, (tree
*)data
);
724 if (var
->alias
&& !var
->analyzed
)
727 /* Indicate that the value of the TLS variable may be found elsewhere,
728 preventing the variable from re-appearing in the GIMPLE. We cheat
729 and use the control variable here (rather than a full call_expr),
730 which is special-cased inside the DWARF2 output routines. */
731 SET_DECL_VALUE_EXPR (var
->decl
, cdecl);
732 DECL_HAS_VALUE_EXPR_P (var
->decl
) = 1;
736 /* Main entry point to the tls lowering pass. */
739 ipa_lower_emutls (void)
742 struct cgraph_node
*func
;
743 bool any_aliases
= false;
744 tree ctor_body
= NULL
;
745 unsigned int i
, n_tls
;
747 tls_vars
= varpool_node_set_new ();
749 /* Examine all global variables for TLS variables. */
750 FOR_EACH_VARIABLE (var
)
751 if (DECL_THREAD_LOCAL_P (var
->decl
))
753 gcc_checking_assert (TREE_STATIC (var
->decl
)
754 || DECL_EXTERNAL (var
->decl
));
755 varpool_node_set_add (tls_vars
, var
);
756 if (var
->alias
&& var
->definition
)
757 varpool_node_set_add (tls_vars
, var
->ultimate_alias_target ());
760 /* If we found no TLS variables, then there is no further work to do. */
761 if (!tls_vars
->nodes
.exists ())
765 fprintf (dump_file
, "No TLS variables found.\n");
769 /* Allocate the on-the-side arrays that share indicies with the TLS vars. */
770 n_tls
= tls_vars
->nodes
.length ();
771 control_vars
.create (n_tls
);
772 access_vars
.create (n_tls
);
773 access_vars
.safe_grow_cleared (n_tls
);
775 /* Create the control variables for each TLS variable. */
776 FOR_EACH_VEC_ELT (tls_vars
->nodes
, i
, var
)
778 var
= tls_vars
->nodes
[i
];
780 if (var
->alias
&& !var
->analyzed
)
782 else if (!var
->alias
)
783 var
->call_for_node_and_aliases (create_emultls_var
, &ctor_body
, true);
786 /* If there were any aliases, then frob the alias_pairs vector. */
790 FOR_EACH_VEC_SAFE_ELT (alias_pairs
, i
, p
)
791 if (DECL_THREAD_LOCAL_P (p
->decl
))
793 p
->decl
= emutls_decl (p
->decl
);
794 p
->target
= get_emutls_object_name (p
->target
);
798 /* Adjust all uses of TLS variables within the function bodies. */
799 FOR_EACH_DEFINED_FUNCTION (func
)
801 lower_emutls_function_body (func
);
803 /* Generate the constructor for any COMMON control variables created. */
805 cgraph_build_static_cdtor ('I', ctor_body
, DEFAULT_INIT_PRIORITY
);
807 control_vars
.release ();
808 access_vars
.release ();
809 free_varpool_node_set (tls_vars
);
816 const pass_data pass_data_ipa_lower_emutls
=
818 SIMPLE_IPA_PASS
, /* type */
820 OPTGROUP_NONE
, /* optinfo_flags */
821 TV_IPA_OPT
, /* tv_id */
822 ( PROP_cfg
| PROP_ssa
), /* properties_required */
823 0, /* properties_provided */
824 0, /* properties_destroyed */
825 0, /* todo_flags_start */
826 0, /* todo_flags_finish */
829 class pass_ipa_lower_emutls
: public simple_ipa_opt_pass
832 pass_ipa_lower_emutls (gcc::context
*ctxt
)
833 : simple_ipa_opt_pass (pass_data_ipa_lower_emutls
, ctxt
)
836 /* opt_pass methods: */
837 virtual bool gate (function
*)
839 /* If the target supports TLS natively, we need do nothing here. */
840 return !targetm
.have_tls
;
843 virtual unsigned int execute (function
*) { return ipa_lower_emutls (); }
845 }; // class pass_ipa_lower_emutls
849 simple_ipa_opt_pass
*
850 make_pass_ipa_lower_emutls (gcc::context
*ctxt
)
852 return new pass_ipa_lower_emutls (ctxt
);