c7131fb2b5
2015-07-07 Andrew MacLeod <amacleod@redhat.com> * tree-core.h: Include symtab.h. * rtl.h: Include hard-reg-set.h but not flags.h. (HARD_CONST): Remove condition compilation involving HARD_CONST since hard-reg-set.h is always included. * regs.h: Don't include hard-reg-set.h or rtl.h. * cfg.h: Include dominance.h. * gimple.h: Include tree-ssa-alias.h and gimple-expr.h. * backend.h: New. Aggregate commonly used backend header files. * gimple-ssa.h: Don't include tree-hasher.h. * ssa.h: New. Aggregate commonly used SSA header files. * regset.h: Remove bitmap.h and hard-reg-set.h #includes. * sel-sched-ir.h: Flatten includes. * lra-int.h: Flatten completely. * sel-sched-dump.h: Flatten includes. * ira-int.h: Flatten includes. * gimple-streamer.h: Remove all includes. * cfgloop.h: Remove all #includes except cfgloopmanip.h. * resource.h: Flatten hard-reg-set.h and df.h. * sched-int.h: Flatten insn-arrt.h and df.h. * valtrack.h: flatten bitmap.h, df.h, and rtl.h * df.h: Flatten includes, leaving regset.h, alloc-pool.h and timevar.h. * genattrtab.c (write_header): Adjust generated includes. * genautomata.c (main): Likewise. * genconditions.c (write-header): Likewise. * genemit.c (main): Likewise. * gengtype.c (open_base_files): Likewise. * genopinit.c (main): Likewise. * genoutput.c (output_prologue): Likewise. * genpeep.c (main): Likewise. * genpreds.c (write_insn_preds_c): Likewise. * genrecog.c (write_header): Likewise. * alias.c: Adjust includes. * asan.c: Likewise. * attribs.c: Likewise. * auto-inc-dec.c: Likewise. * auto-profile.c: Likewise. * bb-reorder.c: Likewise. * bt-load.c: Likewise. * builtins.c: Likewise. * caller-save.c: Likewise. * calls.c: Likewise. * ccmp.c: Likewise. * cfg.c: Likewise. * cfganal.c: Likewise. * cfgbuild.c: Likewise. * cfgcleanup.c: Likewise. * cfgexpand.c: Likewise. * cfghooks.c: Likewise. * cfgloop.c: Likewise. * cfgloopanal.c: Likewise. * cfgloopmanip.c: Likewise. * cfgrtl.c: Likewise. * cgraph.c: Likewise. * cgraphbuild.c: Likewise. * cgraphclones.c: Likewise. * cgraphunit.c: Likewise. * cilk-common.c: Likewise. * combine-stack-adj.c: Likewise. * combine.c: Likewise. * compare-elim.c: Likewise. * convert.c: Likewise. * coverage.c: Likewise. * cppbuiltin.c: Likewise. * cprop.c: Likewise. * cse.c: Likewise. * cselib.c: Likewise. * data-streamer-in.c: Likewise. * data-streamer-out.c: Likewise. * data-streamer.c: Likewise. * dbxout.c: Likewise. * dce.c: Likewise. * ddg.c: Likewise. * debug.c: Likewise. * df-core.c: Likewise. * df-problems.c: Likewise. * df-scan.c: Likewise. * dfp.c: Likewise. * dojump.c: Likewise. * dominance.c: Likewise. * domwalk.c: Likewise. * double-int.c: Likewise. * dse.c: Likewise. * dumpfile.c: Likewise. * dwarf2asm.c: Likewise. * dwarf2cfi.c: Likewise. * dwarf2out.c: Likewise. * emit-rtl.c: Likewise. * et-forest.c: Likewise. * except.c: Likewise. * explow.c: Likewise. * expmed.c: Likewise. * expr.c: Likewise. * final.c: Likewise. * fixed-value.c: Likewise. * fold-const.c: Likewise. * function.c: Likewise. * fwprop.c: Likewise. * gcc-plugin.h: Likewise. * gcse-common.c: Likewise. * gcse.c: Likewise. * generic-match-head.c: Likewise. * ggc-page.c: Likewise. * gimple-builder.c: Likewise. * gimple-expr.c: Likewise. * gimple-fold.c: Likewise. * gimple-iterator.c: Likewise. * gimple-low.c: Likewise. * gimple-match-head.c: Likewise. * gimple-pretty-print.c: Likewise. * gimple-ssa-isolate-paths.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * gimple-streamer-in.c: Likewise. * gimple-streamer-out.c: Likewise. * gimple-walk.c: Likewise. * gimple.c: Likewise. * gimplify-me.c: Likewise. * gimplify.c: Likewise. * godump.c: Likewise. * graph.c: Likewise. * graphite-blocking.c: Likewise. * graphite-dependences.c: Likewise. * graphite-interchange.c: Likewise. * graphite-isl-ast-to-gimple.c: Likewise. * graphite-optimize-isl.c: Likewise. * graphite-poly.c: Likewise. * graphite-scop-detection.c: Likewise. * graphite-sese-to-poly.c: Likewise. * graphite.c: Likewise. * haifa-sched.c: Likewise. * hw-doloop.c: Likewise. * ifcvt.c: Likewise. * init-regs.c: Likewise. * internal-fn.c: Likewise. * ipa-chkp.c: Likewise. * ipa-comdats.c: Likewise. * ipa-cp.c: Likewise. * ipa-devirt.c: Likewise. * ipa-icf-gimple.c: Likewise. * ipa-icf.c: Likewise. * ipa-inline-analysis.c: Likewise. * ipa-inline-transform.c: Likewise. * ipa-inline.c: Likewise. * ipa-polymorphic-call.c: Likewise. * ipa-profile.c: Likewise. * ipa-prop.c: Likewise. * ipa-pure-const.c: Likewise. * ipa-ref.c: Likewise. * ipa-reference.c: Likewise. * ipa-split.c: Likewise. * ipa-utils.c: Likewise. * ipa-visibility.c: Likewise. * ipa.c: Likewise. * ira-build.c: Likewise. * ira-color.c: Likewise. * ira-conflicts.c: Likewise. * ira-costs.c: Likewise. * ira-emit.c: Likewise. * ira-lives.c: Likewise. * ira.c: Likewise. * jump.c: Likewise. * langhooks.c: Likewise. * lcm.c: Likewise. * loop-doloop.c: Likewise. * loop-init.c: Likewise. * loop-invariant.c: Likewise. * loop-iv.c: Likewise. * loop-unroll.c: Likewise. * lower-subreg.c: Likewise. * lra-assigns.c: Likewise. * lra-coalesce.c: Likewise. * lra-constraints.c: Likewise. * lra-eliminations.c: Likewise. * lra-lives.c: Likewise. * lra-remat.c: Likewise. * lra-spills.c: Likewise. * lra.c: Likewise. * lto-cgraph.c: Likewise. * lto-compress.c: Likewise. * lto-opts.c: Likewise. * lto-section-in.c: Likewise. * lto-section-out.c: Likewise. * lto-streamer-in.c: Likewise. * lto-streamer-out.c: Likewise. * lto-streamer.c: Likewise. * mcf.c: Likewise. * mode-switching.c: Likewise. * modulo-sched.c: Likewise. * omega.c: Likewise. * omp-low.c: Likewise. * optabs.c: Likewise. * opts-global.c: Likewise. * passes.c: Likewise. * plugin.c: Likewise. * postreload-gcse.c: Likewise. * postreload.c: Likewise. * predict.c: Likewise. * print-rtl.c: Likewise. * print-tree.c: Likewise. * profile.c: Likewise. * real.c: Likewise. * realmpfr.c: Likewise. * recog.c: Likewise. * ree.c: Likewise. * reg-stack.c: Likewise. * regcprop.c: Likewise. * reginfo.c: Likewise. * regrename.c: Likewise. * regstat.c: Likewise. * reload.c: Likewise. * reload1.c: Likewise. * reorg.c: Likewise. * resource.c: Likewise. * rtl-chkp.c: Likewise. * rtlanal.c: Likewise. * rtlhooks.c: Likewise. * sanopt.c: Likewise. * sched-deps.c: Likewise. * sched-ebb.c: Likewise. * sched-rgn.c: Likewise. * sched-vis.c: Likewise. * sdbout.c: Likewise. * sel-sched-dump.c: Likewise. * sel-sched-ir.c: Likewise. * sel-sched.c: Likewise. * sese.c: Likewise. * shrink-wrap.c: Likewise. * simplify-rtx.c: Likewise. * stack-ptr-mod.c: Likewise. * stmt.c: Likewise. * stor-layout.c: Likewise. * store-motion.c: Likewise. * stringpool.c: Likewise. * symtab.c: Likewise. * target-globals.c: Likewise. * targhooks.c: Likewise. * toplev.c: Likewise. * tracer.c: Likewise. * trans-mem.c: Likewise. * tree-affine.c: Likewise. * tree-browser.c: Likewise. * tree-call-cdce.c: Likewise. * tree-cfg.c: Likewise. * tree-cfgcleanup.c: Likewise. * tree-chkp-opt.c: Likewise. * tree-chkp.c: Likewise. * tree-chrec.c: Likewise. * tree-complex.c: Likewise. * tree-data-ref.c: Likewise. * tree-dfa.c: Likewise. * tree-diagnostic.c: Likewise. * tree-dump.c: Likewise. * tree-eh.c: Likewise. * tree-emutls.c: Likewise. * tree-if-conv.c: Likewise. * tree-inline.c: Likewise. * tree-into-ssa.c: Likewise. * tree-iterator.c: Likewise. * tree-loop-distribution.c: Likewise. * tree-nested.c: Likewise. * tree-nrv.c: Likewise. * tree-object-size.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-predcom.c: Likewise. * tree-pretty-print.c: Likewise. * tree-profile.c: Likewise. * tree-scalar-evolution.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-address.c: Likewise. * tree-ssa-alias.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-coalesce.c: Likewise. * tree-ssa-copy.c: Likewise. * tree-ssa-copyrename.c: Likewise. * tree-ssa-dce.c: Likewise. * tree-ssa-dom.c: Likewise. * tree-ssa-dse.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-ifcombine.c: Likewise. * tree-ssa-live.c: Likewise. * tree-ssa-loop-ch.c: Likewise. * tree-ssa-loop-im.c: Likewise. * tree-ssa-loop-ivcanon.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-loop-prefetch.c: Likewise. * tree-ssa-loop-unswitch.c: Likewise. * tree-ssa-loop.c: Likewise. * tree-ssa-math-opts.c: Likewise. * tree-ssa-operands.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-pre.c: Likewise. * tree-ssa-propagate.c: Likewise. * tree-ssa-reassoc.c: Likewise. * tree-ssa-sccvn.c: Likewise. * tree-ssa-scopedtables.c: Likewise. * tree-ssa-sink.c: Likewise. * tree-ssa-strlen.c: Likewise. * tree-ssa-structalias.c: Likewise. * tree-ssa-tail-merge.c: Likewise. * tree-ssa-ter.c: Likewise. * tree-ssa-threadedge.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa-uncprop.c: Likewise. * tree-ssa-uninit.c: Likewise. * tree-ssa.c: Likewise. * tree-ssanames.c: Likewise. * tree-stdarg.c: Likewise. * tree-streamer-in.c: Likewise. * tree-streamer-out.c: Likewise. * tree-streamer.c: Likewise. * tree-switch-conversion.c: Likewise. * tree-tailcall.c: Likewise. * tree-vect-data-refs.c: Likewise. * tree-vect-generic.c: Likewise. * tree-vect-loop-manip.c: Likewise. * tree-vect-loop.c: Likewise. * tree-vect-patterns.c: Likewise. * tree-vect-slp.c: Likewise. * tree-vect-stmts.c: Likewise. * tree-vectorizer.c: Likewise. * tree-vrp.c: Likewise. * tree.c: Likewise. * tsan.c: Likewise. * ubsan.c: Likewise. * valtrack.c: Likewise. * value-prof.c: Likewise. * var-tracking.c: Likewise. * varasm.c: Likewise. * varpool.c: Likewise. * vmsdbgout.c: Likewise. * vtable-verify.c: Likewise. * web.c: Likewise. * wide-int.cc: Likewise. * xcoffout.c: Likewise. * config/aarch64/aarch64-builtins.c: Likewise. * config/aarch64/aarch64.c: Likewise. * config/aarch64/cortex-a57-fma-steering.c: Likewise. * config/alpha/alpha.c: Likewise. * config/arc/arc.c: Likewise. * config/arm/aarch-common.c: Likewise. * config/arm/arm-builtins.c: Likewise. * config/arm/arm-c.c: Likewise. * config/arm/arm.c: Likewise. * config/avr/avr-c.c: Likewise. * config/avr/avr-log.c: Likewise. * config/avr/avr.c: Likewise. * config/bfin/bfin.c: Likewise. * config/c6x/c6x.c: Likewise. * config/cr16/cr16.c: Likewise. * config/cris/cris.c: Likewise. * config/darwin-c.c: Likewise. * config/darwin.c: Likewise. * config/epiphany/epiphany.c: Likewise. * config/epiphany/mode-switch-use.c: Likewise. * config/epiphany/resolve-sw-modes.c: Likewise. * config/fr30/fr30.c: Likewise. * config/frv/frv.c: Likewise. * config/ft32/ft32.c: Likewise. * config/h8300/h8300.c: Likewise. * config/i386/i386-c.c: Likewise. * config/i386/i386.c: Likewise. * config/i386/msformat-c.c: Likewise. * config/i386/winnt-cxx.c: Likewise. * config/i386/winnt-stubs.c: Likewise. * config/i386/winnt.c: Likewise. * config/ia64/ia64-c.c: Likewise. * config/ia64/ia64.c: Likewise. * config/iq2000/iq2000.c: Likewise. * config/lm32/lm32.c: Likewise. * config/m32c/m32c-pragma.c: Likewise. * config/m32c/m32c.c: Likewise. * config/m32r/m32r.c: Likewise. * config/m68k/m68k.c: Likewise. * config/mcore/mcore.c: Likewise. * config/mep/mep-pragma.c: Likewise. * config/mep/mep.c: Likewise. * config/microblaze/microblaze-c.c: Likewise. * config/microblaze/microblaze.c: Likewise. * config/mips/mips.c: Likewise. * config/mmix/mmix.c: Likewise. * config/mn10300/mn10300.c: Likewise. * config/moxie/moxie.c: Likewise. * config/msp430/msp430-c.c: Likewise. * config/msp430/msp430.c: Likewise. * config/nds32/nds32-cost.c: Likewise. * config/nds32/nds32-fp-as-gp.c: Likewise. * config/nds32/nds32-intrinsic.c: Likewise. * config/nds32/nds32-isr.c: Likewise. * config/nds32/nds32-md-auxiliary.c: Likewise. * config/nds32/nds32-memory-manipulation.c: Likewise. * config/nds32/nds32-pipelines-auxiliary.c: Likewise. * config/nds32/nds32-predicates.c: Likewise. * config/nds32/nds32.c: Likewise. * config/nios2/nios2.c: Likewise. * config/nvptx/nvptx.c: Likewise. * config/pa/pa.c: Likewise. * config/pdp11/pdp11.c: Likewise. * config/rl78/rl78-c.c: Likewise. * config/rl78/rl78.c: Likewise. * config/rs6000/rs6000-c.c: Likewise. * config/rs6000/rs6000.c: Likewise. * config/rx/rx.c: Likewise. * config/s390/s390-c.c: Likewise. * config/s390/s390.c: Likewise. * config/sh/sh-c.c: Likewise. * config/sh/sh-mem.cc: Likewise. * config/sh/sh.c: Likewise. * config/sh/sh_optimize_sett_clrt.cc: Likewise. * config/sh/sh_treg_combine.cc: Likewise. * config/sol2-c.c: Likewise. * config/sol2-cxx.c: Likewise. * config/sol2-stubs.c: Likewise. * config/sol2.c: Likewise. * config/sparc/sparc-c.c: Likewise. * config/sparc/sparc.c: Likewise. * config/spu/spu-c.c: Likewise. * config/spu/spu.c: Likewise. * config/stormy16/stormy16.c: Likewise. * config/tilegx/mul-tables.c: Likewise. * config/tilegx/tilegx-c.c: Likewise. * config/tilegx/tilegx.c: Likewise. * config/tilepro/mul-tables.c: Likewise. * config/tilepro/tilepro-c.c: Likewise. * config/tilepro/tilepro.c: Likewise. * config/v850/v850-c.c: Likewise. * config/v850/v850.c: Likewise. * config/vax/vax.c: Likewise. * config/visium/visium.c: Likewise. * config/vms/vms-c.c: Likewise. * config/vms/vms.c: Likewise. * config/vxworks.c: Likewise. * config/xtensa/xtensa.c: Likewise. ada 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * gcc-interface/cuintp.c: Adjust includes. * gcc-interface/decl.c: Likewise. * gcc-interface/misc.c: Likewise. * gcc-interface/targtyps.c: Likewise. * gcc-interface/trans.c: Likewise. * gcc-interface/utils.c: Likewise. * gcc-interface/utils2.c: Likewise. c 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * c-array-notation.c: Adjust includes. * c-aux-info.c: Likewise. * c-convert.c: Likewise. * c-decl.c: Likewise. * c-errors.c: Likewise. * c-lang.c: Likewise. * c-objc-common.c: Likewise. * c-parser.c: Likewise. * c-typeck.c: Likewise. c-family 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * array-notation-common.c: Adjust includes. * c-ada-spec.c: Likewise. * c-cilkplus.c: Likewise. * c-common.h: Likewise. * c-cppbuiltin.c: Likewise. * c-dump.c: Likewise. * c-format.c: Likewise. * c-gimplify.c: Likewise. * c-indentation.c: Likewise. * c-lex.c: Likewise. * c-omp.c: Likewise. * c-opts.c: Likewise. * c-pch.c: Likewise. * c-ppoutput.c: Likewise. * c-pragma.c: Likewise. * c-pretty-print.c: Likewise. * c-semantics.c: Likewise. * c-ubsan.c: Likewise. * cilk.c: Likewise. * stub-objc.c: Likewise. cp 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * call.c: Adjust includes. * class.c: Likewise. * constexpr.c: Likewise. * cp-array-notation.c: Likewise. * cp-gimplify.c: Likewise. * cp-lang.c: Likewise. * cp-objcp-common.c: Likewise. * cp-ubsan.c: Likewise. * cvt.c: Likewise. * decl.c: Likewise. * decl2.c: Likewise. * dump.c: Likewise. * error.c: Likewise. * except.c: Likewise. * expr.c: Likewise. * friend.c: Likewise. * init.c: Likewise. * lambda.c: Likewise. * lex.c: Likewise. * mangle.c: Likewise. * method.c: Likewise. * name-lookup.c: Likewise. * optimize.c: Likewise. * parser.c: Likewise. * pt.c: Likewise. * ptree.c: Likewise. * repo.c: Likewise. * rtti.c: Likewise. * search.c: Likewise. * semantics.c: Likewise. * tree.c: Likewise. * typeck.c: Likewise. * typeck2.c: Likewise. fortran 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * convert.c: Adjust includes. * cpp.c: Likewise. * decl.c: Likewise. * f95-lang.c: Likewise. * iresolve.c: Likewise. * match.c: Likewise. * module.c: Likewise. * options.c: Likewise. * target-memory.c: Likewise. * trans-array.c: Likewise. * trans-common.c: Likewise. * trans-const.c: Likewise. * trans-decl.c: Likewise. * trans-expr.c: Likewise. * trans-intrinsic.c: Likewise. * trans-io.c: Likewise. * trans-openmp.c: Likewise. * trans-stmt.c: Likewise. * trans-types.c: Likewise. * trans.c: Likewise. go 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * go-backend.c: Adjust includes. * go-gcc.cc: Likewise. * go-lang.c: Likewise. java 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * boehm.c: Adjust includes. * builtins.c: Likewise. * class.c: Likewise. * constants.c: Likewise. * decl.c: Likewise. * except.c: Likewise. * expr.c: Likewise. * java-gimplify.c: Likewise. * jcf-dump.c: Likewise. * jcf-io.c: Likewise. * jcf-parse.c: Likewise. * jvgenmain.c: Likewise. * lang.c: Likewise. * mangle.c: Likewise. * mangle_name.c: Likewise. * resource.c: Likewise. * typeck.c: Likewise. * verify-glue.c: Likewise. jit 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * dummy-frontend.c: Adjust includes. * jit-common.h: Likewise. * jit-playback.c: Likewise. lto 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * lto-lang.c: Adjust includes. * lto-object.c: Likewise. * lto-partition.c: Likewise. * lto-symtab.c: Likewise. * lto.c: Likewise. objc 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * objc-act.c: Adjust includes. * objc-encoding.c: Likewise. * objc-gnu-runtime-abi-01.c: Likewise. * objc-lang.c: Likewise. * objc-map.c: Likewise. * objc-next-runtime-abi-01.c: Likewise. * objc-next-runtime-abi-02.c: Likewise. * objc-runtime-shared-support.c: Likewise. objcp 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * objcp-decl.c: Adjust includes. * objcp-lang.c: Likewise. From-SVN: r225531
837 lines
23 KiB
C
837 lines
23 KiB
C
/* Lower TLS operations to emulation functions.
|
|
Copyright (C) 2006-2015 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/>. */
|
|
|
|
#include "config.h"
|
|
#include "system.h"
|
|
#include "coretypes.h"
|
|
#include "alias.h"
|
|
#include "backend.h"
|
|
#include "tree.h"
|
|
#include "gimple.h"
|
|
#include "hard-reg-set.h"
|
|
#include "ssa.h"
|
|
#include "options.h"
|
|
#include "fold-const.h"
|
|
#include "stor-layout.h"
|
|
#include "varasm.h"
|
|
#include "internal-fn.h"
|
|
#include "gimple-iterator.h"
|
|
#include "gimple-walk.h"
|
|
#include "tree-pass.h"
|
|
#include "cgraph.h"
|
|
#include "langhooks.h"
|
|
#include "target.h"
|
|
#include "targhooks.h"
|
|
#include "tree-iterator.h"
|
|
|
|
/* 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. */
|
|
|
|
/* Value for TLS varpool node where a pointer to control variable and
|
|
access variable are stored. */
|
|
struct tls_var_data
|
|
{
|
|
varpool_node *control_var;
|
|
tree access;
|
|
};
|
|
|
|
/* TLS map accesses mapping between a TLS varpool node and a pair
|
|
made by control variable and access variable. */
|
|
static hash_map<varpool_node *, tls_var_data> *tls_map = NULL;
|
|
|
|
/* The type of the control structure, shared with the emutls.c runtime. */
|
|
static tree emutls_object_type;
|
|
|
|
#if !defined (NO_DOT_IN_LABEL)
|
|
# define EMUTLS_SEPARATOR "."
|
|
#elif !defined (NO_DOLLAR_IN_LABEL)
|
|
# define EMUTLS_SEPARATOR "$"
|
|
#else
|
|
# define EMUTLS_SEPARATOR "_"
|
|
#endif
|
|
|
|
/* Create an IDENTIFIER_NODE by prefixing PREFIX to the
|
|
IDENTIFIER_NODE NAME's name. */
|
|
|
|
static tree
|
|
prefix_name (const char *prefix, tree name)
|
|
{
|
|
unsigned plen = strlen (prefix);
|
|
unsigned nlen = strlen (IDENTIFIER_POINTER (name));
|
|
char *toname = (char *) alloca (plen + nlen + 1);
|
|
|
|
memcpy (toname, prefix, plen);
|
|
memcpy (toname + plen, IDENTIFIER_POINTER (name), nlen + 1);
|
|
|
|
return get_identifier (toname);
|
|
}
|
|
|
|
/* Create an identifier for the struct __emutls_object, given an identifier
|
|
of the DECL_ASSEMBLY_NAME of the original object. */
|
|
|
|
static tree
|
|
get_emutls_object_name (tree name)
|
|
{
|
|
const char *prefix = (targetm.emutls.var_prefix
|
|
? targetm.emutls.var_prefix
|
|
: "__emutls_v" EMUTLS_SEPARATOR);
|
|
return prefix_name (prefix, name);
|
|
}
|
|
|
|
/* 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_fields (tree type, tree *name ATTRIBUTE_UNUSED)
|
|
{
|
|
tree word_type_node, field, next_field;
|
|
|
|
field = build_decl (UNKNOWN_LOCATION,
|
|
FIELD_DECL, get_identifier ("__templ"), ptr_type_node);
|
|
DECL_CONTEXT (field) = type;
|
|
next_field = field;
|
|
|
|
field = build_decl (UNKNOWN_LOCATION,
|
|
FIELD_DECL, get_identifier ("__offset"),
|
|
ptr_type_node);
|
|
DECL_CONTEXT (field) = type;
|
|
DECL_CHAIN (field) = next_field;
|
|
next_field = field;
|
|
|
|
word_type_node = lang_hooks.types.type_for_mode (word_mode, 1);
|
|
field = build_decl (UNKNOWN_LOCATION,
|
|
FIELD_DECL, get_identifier ("__align"),
|
|
word_type_node);
|
|
DECL_CONTEXT (field) = type;
|
|
DECL_CHAIN (field) = next_field;
|
|
next_field = field;
|
|
|
|
field = build_decl (UNKNOWN_LOCATION,
|
|
FIELD_DECL, get_identifier ("__size"), word_type_node);
|
|
DECL_CONTEXT (field) = type;
|
|
DECL_CHAIN (field) = next_field;
|
|
|
|
return field;
|
|
}
|
|
|
|
/* 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. */
|
|
|
|
tree
|
|
default_emutls_var_init (tree to, tree decl, tree proxy)
|
|
{
|
|
vec<constructor_elt, va_gc> *v;
|
|
vec_alloc (v, 4);
|
|
constructor_elt elt;
|
|
tree type = TREE_TYPE (to);
|
|
tree field = TYPE_FIELDS (type);
|
|
|
|
elt.index = field;
|
|
elt.value = fold_convert (TREE_TYPE (field), DECL_SIZE_UNIT (decl));
|
|
v->quick_push (elt);
|
|
|
|
field = DECL_CHAIN (field);
|
|
elt.index = field;
|
|
elt.value = build_int_cst (TREE_TYPE (field),
|
|
DECL_ALIGN_UNIT (decl));
|
|
v->quick_push (elt);
|
|
|
|
field = DECL_CHAIN (field);
|
|
elt.index = field;
|
|
elt.value = null_pointer_node;
|
|
v->quick_push (elt);
|
|
|
|
field = DECL_CHAIN (field);
|
|
elt.index = field;
|
|
elt.value = proxy;
|
|
v->quick_push (elt);
|
|
|
|
return build_constructor (type, v);
|
|
}
|
|
|
|
/* Create the structure for struct __emutls_object. This should match the
|
|
structure at the top of emutls.c, modulo the union there. */
|
|
|
|
static tree
|
|
get_emutls_object_type (void)
|
|
{
|
|
tree type, type_name, field;
|
|
|
|
type = emutls_object_type;
|
|
if (type)
|
|
return type;
|
|
|
|
emutls_object_type = type = lang_hooks.types.make_type (RECORD_TYPE);
|
|
type_name = NULL;
|
|
field = targetm.emutls.var_fields (type, &type_name);
|
|
if (!type_name)
|
|
type_name = get_identifier ("__emutls_object");
|
|
type_name = build_decl (UNKNOWN_LOCATION,
|
|
TYPE_DECL, type_name, type);
|
|
TYPE_NAME (type) = type_name;
|
|
TYPE_FIELDS (type) = field;
|
|
layout_type (type);
|
|
|
|
return type;
|
|
}
|
|
|
|
/* Create a read-only variable like DECL, with the same DECL_INITIAL.
|
|
This will be used for initializing the emulated tls data area. */
|
|
|
|
static tree
|
|
get_emutls_init_templ_addr (tree decl)
|
|
{
|
|
tree name, to;
|
|
|
|
if (targetm.emutls.register_common && !DECL_INITIAL (decl)
|
|
&& !DECL_SECTION_NAME (decl))
|
|
return null_pointer_node;
|
|
|
|
name = DECL_ASSEMBLER_NAME (decl);
|
|
if (!targetm.emutls.tmpl_prefix || targetm.emutls.tmpl_prefix[0])
|
|
{
|
|
const char *prefix = (targetm.emutls.tmpl_prefix
|
|
? targetm.emutls.tmpl_prefix
|
|
: "__emutls_t" EMUTLS_SEPARATOR);
|
|
name = prefix_name (prefix, name);
|
|
}
|
|
|
|
to = build_decl (DECL_SOURCE_LOCATION (decl),
|
|
VAR_DECL, name, TREE_TYPE (decl));
|
|
SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
|
|
|
|
DECL_ARTIFICIAL (to) = 1;
|
|
TREE_USED (to) = TREE_USED (decl);
|
|
TREE_READONLY (to) = 1;
|
|
DECL_IGNORED_P (to) = 1;
|
|
DECL_CONTEXT (to) = DECL_CONTEXT (decl);
|
|
DECL_PRESERVE_P (to) = DECL_PRESERVE_P (decl);
|
|
|
|
DECL_WEAK (to) = DECL_WEAK (decl);
|
|
if (DECL_ONE_ONLY (decl))
|
|
{
|
|
TREE_STATIC (to) = TREE_STATIC (decl);
|
|
TREE_PUBLIC (to) = TREE_PUBLIC (decl);
|
|
DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
|
|
make_decl_one_only (to, DECL_ASSEMBLER_NAME (to));
|
|
}
|
|
else
|
|
TREE_STATIC (to) = 1;
|
|
|
|
DECL_VISIBILITY_SPECIFIED (to) = DECL_VISIBILITY_SPECIFIED (decl);
|
|
DECL_INITIAL (to) = DECL_INITIAL (decl);
|
|
DECL_INITIAL (decl) = NULL;
|
|
|
|
if (targetm.emutls.tmpl_section)
|
|
set_decl_section_name (to, targetm.emutls.tmpl_section);
|
|
else
|
|
set_decl_section_name (to, DECL_SECTION_NAME (decl));
|
|
|
|
/* Create varpool node for the new variable and finalize it if it is
|
|
not external one. */
|
|
if (DECL_EXTERNAL (to))
|
|
varpool_node::get_create (to);
|
|
else
|
|
varpool_node::add (to);
|
|
return build_fold_addr_expr (to);
|
|
}
|
|
|
|
/* Create and return the control variable for the TLS variable DECL. */
|
|
|
|
static tree
|
|
new_emutls_decl (tree decl, tree alias_of)
|
|
{
|
|
tree name, to;
|
|
|
|
name = DECL_ASSEMBLER_NAME (decl);
|
|
to = build_decl (DECL_SOURCE_LOCATION (decl), VAR_DECL,
|
|
get_emutls_object_name (name),
|
|
get_emutls_object_type ());
|
|
|
|
SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
|
|
|
|
DECL_ARTIFICIAL (to) = 1;
|
|
DECL_IGNORED_P (to) = 1;
|
|
TREE_READONLY (to) = 0;
|
|
TREE_STATIC (to) = 1;
|
|
|
|
DECL_PRESERVE_P (to) = DECL_PRESERVE_P (decl);
|
|
DECL_CONTEXT (to) = DECL_CONTEXT (decl);
|
|
TREE_USED (to) = TREE_USED (decl);
|
|
TREE_PUBLIC (to) = TREE_PUBLIC (decl);
|
|
DECL_EXTERNAL (to) = DECL_EXTERNAL (decl);
|
|
DECL_COMMON (to) = DECL_COMMON (decl);
|
|
DECL_WEAK (to) = DECL_WEAK (decl);
|
|
DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
|
|
DECL_VISIBILITY_SPECIFIED (to) = DECL_VISIBILITY_SPECIFIED (decl);
|
|
DECL_DLLIMPORT_P (to) = DECL_DLLIMPORT_P (decl);
|
|
|
|
DECL_ATTRIBUTES (to) = targetm.merge_decl_attributes (decl, to);
|
|
|
|
if (DECL_ONE_ONLY (decl))
|
|
make_decl_one_only (to, DECL_ASSEMBLER_NAME (to));
|
|
|
|
set_decl_tls_model (to, TLS_MODEL_EMULATED);
|
|
|
|
/* If we're not allowed to change the proxy object's alignment,
|
|
pretend it has been set by the user. */
|
|
if (targetm.emutls.var_align_fixed)
|
|
DECL_USER_ALIGN (to) = 1;
|
|
|
|
/* If the target wants the control variables grouped, do so. */
|
|
if (!DECL_COMMON (to) && targetm.emutls.var_section)
|
|
{
|
|
set_decl_section_name (to, targetm.emutls.var_section);
|
|
}
|
|
|
|
/* 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. */
|
|
if (!DECL_EXTERNAL (to)
|
|
&& (!DECL_COMMON (to)
|
|
|| (DECL_INITIAL (decl)
|
|
&& DECL_INITIAL (decl) != error_mark_node)))
|
|
{
|
|
tree tmpl = get_emutls_init_templ_addr (decl);
|
|
DECL_INITIAL (to) = targetm.emutls.var_init (to, decl, tmpl);
|
|
record_references_in_initializer (to, false);
|
|
}
|
|
|
|
/* Create varpool node for the new variable and finalize it if it is
|
|
not external one. */
|
|
if (DECL_EXTERNAL (to))
|
|
varpool_node::get_create (to);
|
|
else if (!alias_of)
|
|
varpool_node::add (to);
|
|
else
|
|
{
|
|
varpool_node *n;
|
|
varpool_node *t = varpool_node::get_for_asmname
|
|
(DECL_ASSEMBLER_NAME (DECL_VALUE_EXPR (alias_of)));
|
|
|
|
n = varpool_node::create_alias (to, t->decl);
|
|
n->resolve_alias (t);
|
|
}
|
|
return to;
|
|
}
|
|
|
|
/* 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 void
|
|
emutls_common_1 (tree tls_decl, tree control_decl, tree *pstmts)
|
|
{
|
|
tree x;
|
|
tree word_type_node;
|
|
|
|
if (! DECL_COMMON (tls_decl)
|
|
|| (DECL_INITIAL (tls_decl)
|
|
&& DECL_INITIAL (tls_decl) != error_mark_node))
|
|
return;
|
|
|
|
word_type_node = lang_hooks.types.type_for_mode (word_mode, 1);
|
|
|
|
x = build_call_expr (builtin_decl_explicit (BUILT_IN_EMUTLS_REGISTER_COMMON),
|
|
4, build_fold_addr_expr (control_decl),
|
|
fold_convert (word_type_node,
|
|
DECL_SIZE_UNIT (tls_decl)),
|
|
build_int_cst (word_type_node,
|
|
DECL_ALIGN_UNIT (tls_decl)),
|
|
get_emutls_init_templ_addr (tls_decl));
|
|
|
|
append_to_statement_list (x, pstmts);
|
|
}
|
|
|
|
struct lower_emutls_data
|
|
{
|
|
struct cgraph_node *cfun_node;
|
|
struct cgraph_node *builtin_node;
|
|
tree builtin_decl;
|
|
basic_block bb;
|
|
int bb_freq;
|
|
location_t loc;
|
|
gimple_seq seq;
|
|
};
|
|
|
|
/* Given a TLS variable DECL, return an SSA_NAME holding its address.
|
|
Append any new computation statements required to D->SEQ. */
|
|
|
|
static tree
|
|
gen_emutls_addr (tree decl, struct lower_emutls_data *d)
|
|
{
|
|
/* Compute the address of the TLS variable with help from runtime. */
|
|
tls_var_data *data = tls_map->get (varpool_node::get (decl));
|
|
tree addr = data->access;
|
|
|
|
if (addr == NULL)
|
|
{
|
|
varpool_node *cvar;
|
|
tree cdecl;
|
|
gcall *x;
|
|
|
|
cvar = data->control_var;
|
|
cdecl = cvar->decl;
|
|
TREE_ADDRESSABLE (cdecl) = 1;
|
|
|
|
addr = create_tmp_var (build_pointer_type (TREE_TYPE (decl)));
|
|
x = gimple_build_call (d->builtin_decl, 1, build_fold_addr_expr (cdecl));
|
|
gimple_set_location (x, d->loc);
|
|
|
|
addr = make_ssa_name (addr, x);
|
|
gimple_call_set_lhs (x, addr);
|
|
|
|
gimple_seq_add_stmt (&d->seq, x);
|
|
|
|
d->cfun_node->create_edge (d->builtin_node, x, d->bb->count, d->bb_freq);
|
|
|
|
/* 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. */
|
|
d->cfun_node->create_reference (cvar, IPA_REF_ADDR, x);
|
|
|
|
/* Record this ssa_name for possible use later in the basic block. */
|
|
data->access = addr;
|
|
}
|
|
|
|
return addr;
|
|
}
|
|
|
|
/* 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. */
|
|
|
|
static tree
|
|
lower_emutls_1 (tree *ptr, int *walk_subtrees, void *cb_data)
|
|
{
|
|
struct walk_stmt_info *wi = (struct walk_stmt_info *) cb_data;
|
|
struct lower_emutls_data *d = (struct lower_emutls_data *) wi->info;
|
|
tree t = *ptr;
|
|
bool is_addr = false;
|
|
tree addr;
|
|
|
|
*walk_subtrees = 0;
|
|
|
|
switch (TREE_CODE (t))
|
|
{
|
|
case ADDR_EXPR:
|
|
/* If this is not a straight-forward "&var", but rather something
|
|
like "&var.a", then we may need special handling. */
|
|
if (TREE_CODE (TREE_OPERAND (t, 0)) != VAR_DECL)
|
|
{
|
|
bool save_changed;
|
|
|
|
/* If we're allowed more than just is_gimple_val, continue. */
|
|
if (!wi->val_only)
|
|
{
|
|
*walk_subtrees = 1;
|
|
return NULL_TREE;
|
|
}
|
|
|
|
/* See if any substitution would be made. */
|
|
save_changed = wi->changed;
|
|
wi->changed = false;
|
|
wi->val_only = false;
|
|
walk_tree (&TREE_OPERAND (t, 0), lower_emutls_1, wi, NULL);
|
|
wi->val_only = true;
|
|
|
|
/* If so, then extract this entire sub-expression "&p->a" into a
|
|
new assignment statement, and substitute yet another SSA_NAME. */
|
|
if (wi->changed)
|
|
{
|
|
gimple x;
|
|
|
|
addr = create_tmp_var (TREE_TYPE (t));
|
|
x = gimple_build_assign (addr, t);
|
|
gimple_set_location (x, d->loc);
|
|
|
|
addr = make_ssa_name (addr, x);
|
|
gimple_assign_set_lhs (x, addr);
|
|
|
|
gimple_seq_add_stmt (&d->seq, x);
|
|
|
|
*ptr = addr;
|
|
}
|
|
else
|
|
wi->changed = save_changed;
|
|
|
|
return NULL_TREE;
|
|
}
|
|
|
|
t = TREE_OPERAND (t, 0);
|
|
is_addr = true;
|
|
/* FALLTHRU */
|
|
|
|
case VAR_DECL:
|
|
if (!DECL_THREAD_LOCAL_P (t))
|
|
return NULL_TREE;
|
|
break;
|
|
|
|
default:
|
|
/* We're not interested in other decls or types, only subexpressions. */
|
|
if (EXPR_P (t))
|
|
*walk_subtrees = 1;
|
|
/* FALLTHRU */
|
|
|
|
case SSA_NAME:
|
|
/* Special-case the return of SSA_NAME, since it's so common. */
|
|
return NULL_TREE;
|
|
}
|
|
|
|
addr = gen_emutls_addr (t, d);
|
|
if (is_addr)
|
|
{
|
|
/* Replace "&var" with "addr" in the statement. */
|
|
*ptr = addr;
|
|
}
|
|
else
|
|
{
|
|
/* Replace "var" with "*addr" in the statement. */
|
|
t = build2 (MEM_REF, TREE_TYPE (t), addr,
|
|
build_int_cst (TREE_TYPE (addr), 0));
|
|
*ptr = t;
|
|
}
|
|
|
|
wi->changed = true;
|
|
return NULL_TREE;
|
|
}
|
|
|
|
/* Lower all of the operands of STMT. */
|
|
|
|
static void
|
|
lower_emutls_stmt (gimple stmt, struct lower_emutls_data *d)
|
|
{
|
|
struct walk_stmt_info wi;
|
|
|
|
d->loc = gimple_location (stmt);
|
|
|
|
memset (&wi, 0, sizeof (wi));
|
|
wi.info = d;
|
|
wi.val_only = true;
|
|
walk_gimple_op (stmt, lower_emutls_1, &wi);
|
|
|
|
if (wi.changed)
|
|
update_stmt (stmt);
|
|
}
|
|
|
|
/* Lower the I'th operand of PHI. */
|
|
|
|
static void
|
|
lower_emutls_phi_arg (gphi *phi, unsigned int i,
|
|
struct lower_emutls_data *d)
|
|
{
|
|
struct walk_stmt_info wi;
|
|
struct phi_arg_d *pd = gimple_phi_arg (phi, i);
|
|
|
|
/* Early out for a very common case we don't care about. */
|
|
if (TREE_CODE (pd->def) == SSA_NAME)
|
|
return;
|
|
|
|
d->loc = pd->locus;
|
|
|
|
memset (&wi, 0, sizeof (wi));
|
|
wi.info = d;
|
|
wi.val_only = true;
|
|
walk_tree (&pd->def, lower_emutls_1, &wi, NULL);
|
|
|
|
/* For normal statements, we let update_stmt do its job. But for phi
|
|
nodes, we have to manipulate the immediate use list by hand. */
|
|
if (wi.changed)
|
|
{
|
|
gcc_assert (TREE_CODE (pd->def) == SSA_NAME);
|
|
link_imm_use_stmt (&pd->imm_use, pd->def, phi);
|
|
}
|
|
}
|
|
|
|
/* Reset access variable for a given TLS variable data DATA. */
|
|
|
|
bool
|
|
reset_access (varpool_node * const &, tls_var_data *data, void *)
|
|
{
|
|
data->access = NULL;
|
|
|
|
return true;
|
|
}
|
|
|
|
/* Clear the access variables, in order to begin a new block. */
|
|
|
|
static inline void
|
|
clear_access_vars (void)
|
|
{
|
|
tls_map->traverse<void *, reset_access> (NULL);
|
|
}
|
|
|
|
/* Lower the entire function NODE. */
|
|
|
|
static void
|
|
lower_emutls_function_body (struct cgraph_node *node)
|
|
{
|
|
struct lower_emutls_data d;
|
|
bool any_edge_inserts = false;
|
|
|
|
push_cfun (DECL_STRUCT_FUNCTION (node->decl));
|
|
|
|
d.cfun_node = node;
|
|
d.builtin_decl = builtin_decl_explicit (BUILT_IN_EMUTLS_GET_ADDRESS);
|
|
/* This is where we introduce the declaration to the IL and so we have to
|
|
create a node for it. */
|
|
d.builtin_node = cgraph_node::get_create (d.builtin_decl);
|
|
|
|
FOR_EACH_BB_FN (d.bb, cfun)
|
|
{
|
|
unsigned int i, nedge;
|
|
|
|
/* 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. */
|
|
if (!gimple_seq_empty_p (phi_nodes (d.bb)))
|
|
{
|
|
/* The calls will be inserted on the edges, and the frequencies
|
|
will be computed during the commit process. */
|
|
d.bb_freq = 0;
|
|
|
|
nedge = EDGE_COUNT (d.bb->preds);
|
|
for (i = 0; i < nedge; ++i)
|
|
{
|
|
edge e = EDGE_PRED (d.bb, i);
|
|
|
|
/* We can re-use any SSA_NAME created on this edge. */
|
|
clear_access_vars ();
|
|
d.seq = NULL;
|
|
|
|
for (gphi_iterator gsi = gsi_start_phis (d.bb);
|
|
!gsi_end_p (gsi);
|
|
gsi_next (&gsi))
|
|
lower_emutls_phi_arg (gsi.phi (), i, &d);
|
|
|
|
/* Insert all statements generated by all phi nodes for this
|
|
particular edge all at once. */
|
|
if (d.seq)
|
|
{
|
|
gsi_insert_seq_on_edge (e, d.seq);
|
|
any_edge_inserts = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
d.bb_freq = compute_call_stmt_bb_frequency (current_function_decl, d.bb);
|
|
|
|
/* We can re-use any SSA_NAME created during this basic block. */
|
|
clear_access_vars ();
|
|
|
|
/* Lower each of the statements of the block. */
|
|
for (gimple_stmt_iterator gsi = gsi_start_bb (d.bb); !gsi_end_p (gsi);
|
|
gsi_next (&gsi))
|
|
{
|
|
d.seq = NULL;
|
|
lower_emutls_stmt (gsi_stmt (gsi), &d);
|
|
|
|
/* If any new statements were created, insert them immediately
|
|
before the first use. This prevents variable lifetimes from
|
|
becoming unnecessarily long. */
|
|
if (d.seq)
|
|
gsi_insert_seq_before (&gsi, d.seq, GSI_SAME_STMT);
|
|
}
|
|
}
|
|
|
|
if (any_edge_inserts)
|
|
gsi_commit_edge_inserts ();
|
|
|
|
pop_cfun ();
|
|
}
|
|
|
|
/* Create emutls variable for VAR, DATA is pointer to static
|
|
ctor body we can add constructors to.
|
|
Callback for varpool_for_variable_and_aliases. */
|
|
|
|
static bool
|
|
create_emultls_var (varpool_node *var, void *data)
|
|
{
|
|
tree cdecl;
|
|
tls_var_data value;
|
|
|
|
cdecl = new_emutls_decl (var->decl,
|
|
var->alias && var->analyzed
|
|
? var->get_alias_target ()->decl : NULL);
|
|
|
|
varpool_node *cvar = varpool_node::get (cdecl);
|
|
|
|
if (!var->alias)
|
|
{
|
|
/* 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. */
|
|
emutls_common_1 (var->decl, cdecl, (tree *)data);
|
|
}
|
|
if (var->alias && !var->analyzed)
|
|
cvar->alias = true;
|
|
|
|
/* 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. */
|
|
SET_DECL_VALUE_EXPR (var->decl, cdecl);
|
|
DECL_HAS_VALUE_EXPR_P (var->decl) = 1;
|
|
|
|
value.control_var = cvar;
|
|
tls_map->put (var, value);
|
|
|
|
return false;
|
|
}
|
|
|
|
/* Main entry point to the tls lowering pass. */
|
|
|
|
static unsigned int
|
|
ipa_lower_emutls (void)
|
|
{
|
|
varpool_node *var;
|
|
cgraph_node *func;
|
|
bool any_aliases = false;
|
|
tree ctor_body = NULL;
|
|
hash_set <varpool_node *> visited;
|
|
auto_vec <varpool_node *> tls_vars;
|
|
|
|
/* Examine all global variables for TLS variables. */
|
|
FOR_EACH_VARIABLE (var)
|
|
if (DECL_THREAD_LOCAL_P (var->decl)
|
|
&& !visited.add (var))
|
|
{
|
|
gcc_checking_assert (TREE_STATIC (var->decl)
|
|
|| DECL_EXTERNAL (var->decl));
|
|
tls_vars.safe_push (var);
|
|
if (var->alias && var->definition
|
|
&& !visited.add (var->ultimate_alias_target ()))
|
|
tls_vars.safe_push (var->ultimate_alias_target ());
|
|
}
|
|
|
|
/* If we found no TLS variables, then there is no further work to do. */
|
|
if (tls_vars.is_empty ())
|
|
{
|
|
if (dump_file)
|
|
fprintf (dump_file, "No TLS variables found.\n");
|
|
return 0;
|
|
}
|
|
|
|
tls_map = new hash_map <varpool_node *, tls_var_data> ();
|
|
|
|
/* Create the control variables for each TLS variable. */
|
|
for (unsigned i = 0; i < tls_vars.length (); i++)
|
|
{
|
|
var = tls_vars[i];
|
|
|
|
if (var->alias && !var->analyzed)
|
|
any_aliases = true;
|
|
else if (!var->alias)
|
|
var->call_for_symbol_and_aliases (create_emultls_var, &ctor_body, true);
|
|
}
|
|
|
|
/* If there were any aliases, then frob the alias_pairs vector. */
|
|
if (any_aliases)
|
|
{
|
|
alias_pair *p;
|
|
unsigned int i;
|
|
FOR_EACH_VEC_SAFE_ELT (alias_pairs, i, p)
|
|
if (DECL_THREAD_LOCAL_P (p->decl))
|
|
{
|
|
p->decl = tls_map->get
|
|
(varpool_node::get (p->decl))->control_var->decl;
|
|
p->target = get_emutls_object_name (p->target);
|
|
}
|
|
}
|
|
|
|
/* Adjust all uses of TLS variables within the function bodies. */
|
|
FOR_EACH_DEFINED_FUNCTION (func)
|
|
if (func->lowered)
|
|
lower_emutls_function_body (func);
|
|
|
|
/* Generate the constructor for any COMMON control variables created. */
|
|
if (ctor_body)
|
|
cgraph_build_static_cdtor ('I', ctor_body, DEFAULT_INIT_PRIORITY);
|
|
|
|
delete tls_map;
|
|
|
|
return 0;
|
|
}
|
|
|
|
namespace {
|
|
|
|
const pass_data pass_data_ipa_lower_emutls =
|
|
{
|
|
SIMPLE_IPA_PASS, /* type */
|
|
"emutls", /* name */
|
|
OPTGROUP_NONE, /* optinfo_flags */
|
|
TV_IPA_OPT, /* tv_id */
|
|
( PROP_cfg | PROP_ssa ), /* properties_required */
|
|
0, /* properties_provided */
|
|
0, /* properties_destroyed */
|
|
0, /* todo_flags_start */
|
|
0, /* todo_flags_finish */
|
|
};
|
|
|
|
class pass_ipa_lower_emutls : public simple_ipa_opt_pass
|
|
{
|
|
public:
|
|
pass_ipa_lower_emutls (gcc::context *ctxt)
|
|
: simple_ipa_opt_pass (pass_data_ipa_lower_emutls, ctxt)
|
|
{}
|
|
|
|
/* opt_pass methods: */
|
|
virtual bool gate (function *)
|
|
{
|
|
/* If the target supports TLS natively, we need do nothing here. */
|
|
return !targetm.have_tls;
|
|
}
|
|
|
|
virtual unsigned int execute (function *) { return ipa_lower_emutls (); }
|
|
|
|
}; // class pass_ipa_lower_emutls
|
|
|
|
} // anon namespace
|
|
|
|
simple_ipa_opt_pass *
|
|
make_pass_ipa_lower_emutls (gcc::context *ctxt)
|
|
{
|
|
return new pass_ipa_lower_emutls (ctxt);
|
|
}
|