llvm.org GIT mirror llvm / 70716e5
[TLS] use emulated TLS if the target supports only this mode Emulated TLS is enabled by llc flag -emulated-tls, which is passed by clang driver. When llc is called explicitly or from other drivers like LTO, missing -emulated-tls flag would generate wrong TLS code for targets that supports only this mode. Now use useEmulatedTLS() instead of Options.EmulatedTLS to decide whether emulated TLS code should be generated. Unit tests are modified to run with and without the -emulated-tls flag. Differential Revision: https://reviews.llvm.org/D42999 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326341 91177308-0d34-0410-b5e6-96231b3b80d8 Chih-Hung Hsieh 2 years ago
32 changed file(s) with 133 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
664664 return !isOSBinFormatMachO();
665665 }
666666
667 /// Tests whether the target uses emulated TLS as default.
668 bool hasDefaultEmulatedTLS() const {
669 return isAndroid() || isOSOpenBSD() || isWindowsCygwinEnvironment();
670 }
671
667672 /// @}
668673 /// @name Mutators
669674 /// @{
285285 Options.FunctionSections = FunctionSections;
286286 Options.UniqueSectionNames = UniqueSectionNames;
287287 Options.EmulatedTLS = EmulatedTLS;
288 Options.ExplicitEmulatedTLS = EmulatedTLS.getNumOccurrences() > 0;
288289 Options.ExceptionModel = ExceptionModel;
289290 Options.EmitStackSizeSection = EnableStackSizeSection;
290291
171171
172172 bool shouldAssumeDSOLocal(const Module &M, const GlobalValue *GV) const;
173173
174 /// Returns true if this target uses emulated TLS.
175 bool useEmulatedTLS() const;
176
174177 /// Returns the TLS model which should be used for the given global variable.
175178 TLSModel::Model getTLSModel(const GlobalValue *GV) const;
176179
106106 EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false),
107107 DisableIntegratedAS(false), RelaxELFRelocations(false),
108108 FunctionSections(false), DataSections(false),
109 UniqueSectionNames(true), TrapUnreachable(false), EmulatedTLS(false),
109 UniqueSectionNames(true), TrapUnreachable(false),
110 EmulatedTLS(false), ExplicitEmulatedTLS(false),
110111 EnableIPRA(false), EmitStackSizeSection(false) {}
111112
112113 /// PrintMachineCode - This flag is enabled when the -print-machineinstrs
214215 /// EmulatedTLS - This flag enables emulated TLS model, using emutls
215216 /// function in the runtime library..
216217 unsigned EmulatedTLS : 1;
218
219 /// Whether -emulated-tls or -no-emulated-tls is set.
220 unsigned ExplicitEmulatedTLS : 1;
217221
218222 /// This flag enables InterProcedural Register Allocation (IPRA).
219223 unsigned EnableIPRA : 1;
428428
429429 /// EmitGlobalVariable - Emit the specified global variable to the .s file.
430430 void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
431 bool IsEmuTLSVar = TM.Options.EmulatedTLS && GV->isThreadLocal();
431 bool IsEmuTLSVar = TM.useEmulatedTLS() && GV->isThreadLocal();
432432 assert(!(IsEmuTLSVar && GV->hasCommonLinkage()) &&
433433 "No emulated TLS variables in the common section");
434434
197197 if (Global) {
198198 const MCSymbol *Sym = Asm->getSymbol(Global);
199199 if (Global->isThreadLocal()) {
200 if (Asm->TM.Options.EmulatedTLS) {
200 if (Asm->TM.useEmulatedTLS()) {
201201 // TODO: add debug info for emulated thread local mode.
202202 } else {
203203 // FIXME: Make this work with -gsplit-dwarf.
6767 return false;
6868
6969 auto &TM = TPC->getTM();
70 if (!TM.Options.EmulatedTLS)
70 if (!TM.useEmulatedTLS())
7171 return false;
7272
7373 bool Changed = false;
747747 }
748748
749749 bool TargetPassConfig::addISelPasses() {
750 if (TM->Options.EmulatedTLS)
750 if (TM->useEmulatedTLS())
751751 addPass(createLowerEmuTLSPass());
752752
753753 addPass(createPreISelIntrinsicLoweringPass());
9696 Options, RelocModel, CMModel, OptLevel,
9797 /*JIT*/ true);
9898 Target->Options.EmulatedTLS = EmulatedTLS;
99 Target->Options.ExplicitEmulatedTLS = true;
100
99101 assert(Target && "Could not allocate target machine!");
100102 return Target;
101103 }
39783978 SDValue AArch64TargetLowering::LowerGlobalTLSAddress(SDValue Op,
39793979 SelectionDAG &DAG) const {
39803980 const GlobalAddressSDNode *GA = cast(Op);
3981 if (DAG.getTarget().Options.EmulatedTLS)
3981 if (DAG.getTarget().useEmulatedTLS())
39823982 return LowerToTLSEmulatedModel(GA, DAG);
39833983
39843984 if (Subtarget->isTargetDarwin())
30043004 SDValue
30053005 ARMTargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const {
30063006 GlobalAddressSDNode *GA = cast(Op);
3007 if (DAG.getTarget().Options.EmulatedTLS)
3007 if (DAG.getTarget().useEmulatedTLS())
30083008 return LowerToTLSEmulatedModel(GA, DAG);
30093009
30103010 if (Subtarget->isTargetDarwin())
20682068 // Local Exec TLS Model.
20692069
20702070 GlobalAddressSDNode *GA = cast(Op);
2071 if (DAG.getTarget().Options.EmulatedTLS)
2071 if (DAG.getTarget().useEmulatedTLS())
20722072 return LowerToTLSEmulatedModel(GA, DAG);
20732073
20742074 SDLoc DL(GA);
25702570 // large models could be added if users need it, at the cost of
25712571 // additional complexity.
25722572 GlobalAddressSDNode *GA = cast(Op);
2573 if (DAG.getTarget().Options.EmulatedTLS)
2573 if (DAG.getTarget().useEmulatedTLS())
25742574 return LowerToTLSEmulatedModel(GA, DAG);
25752575
25762576 SDLoc dl(GA);
20352035 SelectionDAG &DAG) const {
20362036
20372037 GlobalAddressSDNode *GA = cast(Op);
2038 if (DAG.getTarget().Options.EmulatedTLS)
2038 if (DAG.getTarget().useEmulatedTLS())
20392039 return LowerToTLSEmulatedModel(GA, DAG);
20402040
20412041 SDLoc DL(GA);
26622662
26632663 SDValue SystemZTargetLowering::lowerGlobalTLSAddress(GlobalAddressSDNode *Node,
26642664 SelectionDAG &DAG) const {
2665 if (DAG.getTarget().Options.EmulatedTLS)
2665 if (DAG.getTarget().useEmulatedTLS())
26662666 return LowerToTLSEmulatedModel(Node, DAG);
26672667 SDLoc DL(Node);
26682668 const GlobalValue *GV = Node->getGlobal();
191191 return false;
192192 }
193193
194 bool TargetMachine::useEmulatedTLS() const {
195 // Returns Options.EmulatedTLS if the -emulated-tls or -no-emulated-tls
196 // was specified explicitly; otherwise uses target triple to decide default.
197 if (Options.ExplicitEmulatedTLS)
198 return Options.EmulatedTLS;
199 return getTargetTriple().hasDefaultEmulatedTLS();
200 }
201
194202 TLSModel::Model TargetMachine::getTLSModel(const GlobalValue *GV) const {
195203 bool IsPIE = GV->getParent()->getPIELevel() != PIELevel::Default;
196204 Reloc::Model RM = getRelocationModel();
1563715637
1563815638 GlobalAddressSDNode *GA = cast(Op);
1563915639
15640 if (DAG.getTarget().Options.EmulatedTLS)
15640 if (DAG.getTarget().useEmulatedTLS())
1564115641 return LowerToTLSEmulatedModel(GA, DAG);
1564215642
1564315643 const GlobalValue *GV = GA->getGlobal();
0 ; RUN: llc -emulated-tls -mtriple=aarch64-linux-android \
1 ; RUN: -relocation-model=pic -disable-fp-elim < %s | FileCheck -check-prefix=ARM64 %s
2 ; RUN: llc -mtriple=aarch64-linux-android \
13 ; RUN: -relocation-model=pic -disable-fp-elim < %s | FileCheck -check-prefix=ARM64 %s
24
35 ; Copied from X86/emutls.ll
77 ; RUN: | FileCheck -check-prefix=ARM_64 %s
88 ; RUN: llc < %s -emulated-tls -mtriple=aarch64-apple-darwin -O3 \
99 ; RUN: | FileCheck -check-prefix=DARWIN %s
10
11 ; RUN: llc < %s -mtriple=aarch64-linux-android -relocation-model=pic \
12 ; RUN: | FileCheck -check-prefix=ARM_64 %s
13 ; RUN: llc < %s -mtriple=aarch64-linux-android -relocation-model=pic -O3 \
14 ; RUN: | FileCheck -check-prefix=ARM_64 %s
15 ; RUN: llc < %s -mtriple=aarch64-linux-android -O3 \
16 ; RUN: | FileCheck -check-prefix=ARM_64 %s
17 ; aarch64-windows-gnu needs explicit -emulated-tls
18 ; RUN: llc < %s -mtriple=aarch64-apple-darwin -O3 \
19 ; RUN: | FileCheck -check-prefix=NoEMU %s
20
21 ; NoEMU-NOT: __emutls
1022
1123 ; Make sure that TLS symbols are emitted in expected order.
1224
0 ; RUN: llc -emulated-tls -mtriple=arm-linux-android \
1 ; RUN: -relocation-model=pic < %s | FileCheck -check-prefix=ARM32 %s
2 ; RUN: llc -mtriple=arm-linux-android \
13 ; RUN: -relocation-model=pic < %s | FileCheck -check-prefix=ARM32 %s
24
35 ; Copied from X86/emutls.ll
99 ; RUN: | FileCheck -check-prefix=DARWIN %s
1010 ; RUN: llc < %s -emulated-tls -mtriple=thumbv7-windows-gnu -O3 \
1111 ; RUN: | FileCheck -check-prefix=WIN %s
12
13 ; RUN: llc < %s -mtriple=arm-linux-android -relocation-model=pic \
14 ; RUN: | FileCheck -check-prefix=ARM_32 %s
15 ; RUN: llc < %s -mtriple=arm-linux-androidabi -relocation-model=pic \
16 ; RUN: | FileCheck -check-prefix=ARM_32 %s
17 ; RUN: llc < %s -mtriple=arm-linux-androidabi -relocation-model=pic -O3 \
18 ; RUN: | FileCheck -check-prefix=ARM_32 %s
19 ; RUN: llc < %s -mtriple=arm-linux-androidabi -O3 \
20 ; RUN: | FileCheck -check-prefix=ARM_32 %s
21 ; arm-apple-darwin must use -emulated-tls
22 ; windows must use -emulated-tls
1223
1324 ; Make sure that TLS symbols are emitted in expected order.
1425
0 ; RUN: llc < %s -emulated-tls -mtriple=mipsel-linux-android -relocation-model=pic \
11 ; RUN: | FileCheck -check-prefix=MIPS_32 %s
22 ; RUN: llc < %s -emulated-tls -mtriple=mips64el-linux-android -relocation-model=pic \
3 ; RUN: | FileCheck -check-prefix=MIPS_64 %s
4
5 ; RUN: llc < %s -mtriple=mipsel-linux-android -relocation-model=pic \
6 ; RUN: | FileCheck -check-prefix=MIPS_32 %s
7 ; RUN: llc < %s -mtriple=mips64el-linux-android -relocation-model=pic \
38 ; RUN: | FileCheck -check-prefix=MIPS_64 %s
49
510 ; Make sure that TLS symbols are emitted in expected order.
11 ; RUN: | FileCheck %s
22 ; RUN: llc < %s -emulated-tls -mtriple=powerpc-unknown-linux-gnu -relocation-model=pic \
33 ; RUN: | FileCheck %s
4
5 ; RUN: llc < %s -mtriple=powerpc64-unknown-linux-gnu -relocation-model=pic \
6 ; RUN: | FileCheck -check-prefix=NoEMU %s
7 ; RUN: llc < %s -mtriple=powerpc-unknown-linux-gnu -relocation-model=pic \
8 ; RUN: | FileCheck -check-prefix=NoEMU %s
9
10 ; NoEMU-NOT: __emutls
411
512 ; Make sure that TLS symbols are emitted in expected order.
613
11 ; RUN: llc < %s -emulated-tls -mtriple=x86_64-linux-gnu -relocation-model=pic | FileCheck -check-prefix=X64 %s
22 ; RUN: llc < %s -emulated-tls -mtriple=i386-linux-android -relocation-model=pic | FileCheck -check-prefix=X32 %s
33 ; RUN: llc < %s -emulated-tls -mtriple=x86_64-linux-android -relocation-model=pic | FileCheck -check-prefix=X64 %s
4
5 ; RUN: llc < %s -mtriple=i386-linux-gnu -relocation-model=pic | FileCheck -check-prefix=NoEMU %s
6 ; RUN: llc < %s -mtriple=x86_64-linux-gnu -relocation-model=pic | FileCheck -check-prefix=NoEMU %s
7 ; RUN: llc < %s -mtriple=i386-linux-android -relocation-model=pic | FileCheck -check-prefix=X32 %s
8 ; RUN: llc < %s -mtriple=x86_64-linux-android -relocation-model=pic | FileCheck -check-prefix=X64 %s
9
10 ; NoEMU-NOT: __emutls
411
512 ; Use my_emutls_get_address like __emutls_get_address.
613 @my_emutls_v_xyz = external global i8*, align 4
55 ; RUN: | FileCheck -check-prefix=X32 %s
66 ; RUN: llc < %s -emulated-tls -mcpu=generic -mtriple=x86_64-linux-android -relocation-model=pic \
77 ; RUN: | FileCheck -check-prefix=X64 %s
8
9 ; RUN: llc < %s -mcpu=generic -mtriple=i386-linux-gnu -relocation-model=pic \
10 ; RUN: | FileCheck -check-prefix=NoEMU %s
11 ; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux-gnu -relocation-model=pic \
12 ; RUN: | FileCheck -check-prefix=NoEMU %s
13 ; RUN: llc < %s -mcpu=generic -mtriple=i386-linux-android -relocation-model=pic \
14 ; RUN: | FileCheck -check-prefix=X32 %s
15 ; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux-android -relocation-model=pic \
16 ; RUN: | FileCheck -check-prefix=X64 %s
17
18 ; NoEMU-NOT: __emutls
819
920 ; Use my_emutls_get_address like __emutls_get_address.
1021 @my_emutls_v_xyz = external global i8*, align 4
22 ; RUN: llc < %s -emulated-tls -mtriple=i386-linux-android | FileCheck -check-prefix=X32 %s
33 ; RUN: llc < %s -emulated-tls -mtriple=x86_64-linux-android | FileCheck -check-prefix=X64 %s
44
5 ; RUN: llc < %s -mtriple=i386-linux-gnu | FileCheck -check-prefix=NoEMU %s
6 ; RUN: llc < %s -mtriple=x86_64-linux-gnu | FileCheck -check-prefix=NoEMU %s
7 ; RUN: llc < %s -mtriple=i386-linux-android | FileCheck -check-prefix=X32 %s
8 ; RUN: llc < %s -mtriple=x86_64-linux-android | FileCheck -check-prefix=X64 %s
9
510 ; Copied from tls.ll; emulated TLS model is not implemented
6 ; for *-pc-win32 and *-pc-winows targets yet.
11 ; for *-pc-win32 and *-pc-windows targets yet.
12
13 ; NoEMU-NOT: __emutls
714
815 ; Use my_emutls_get_address like __emutls_get_address.
916 @my_emutls_v_xyz = external global i8*, align 4
55 ; RUN: | FileCheck -check-prefix=X86_64 %s
66 ; RUN: llc < %s -emulated-tls -mtriple=i386-linux-gnu -relocation-model=pic \
77 ; RUN: | FileCheck %s
8
9 ; RUN: llc < %s -mtriple=i686-linux-android -relocation-model=pic \
10 ; RUN: | FileCheck -check-prefix=X86_32 %s
11 ; RUN: llc < %s -mtriple=i686-linux-android -relocation-model=pic \
12 ; RUN: | FileCheck -check-prefix=X86_32 %s
13 ; RUN: llc < %s -mtriple=x86_64-linux-android -relocation-model=pic \
14 ; RUN: | FileCheck -check-prefix=X86_64 %s
15 ; RUN: llc < %s -mtriple=i386-linux-gnu -relocation-model=pic \
16 ; RUN: | FileCheck -check-prefix=NoEMU %s
17
18 ; NoEMU-NOT: __emutls
819
920 ; Make sure that TLS symbols are emitted in expected order.
1021
0 ; RUN: llc < %s -emulated-tls -relocation-model=pic -mtriple=i686-unknown-linux-gnu -fast-isel | FileCheck %s
1 ; RUN: llc < %s -relocation-model=pic -mtriple=i686-unknown-linux-gnu -fast-isel \
2 ; RUN: | FileCheck -check-prefix=NoEMU %s
13 ; PR3654
4
5 ; NoEMU-NOT: __emutls
26
37 @v = thread_local global i32 0
48 define i32 @f() nounwind {
0 ; RUN: llc < %s -emulated-tls -mcpu=generic -mtriple=x86_64-linux-gnu -relocation-model=pic -pie-copy-relocations \
1 ; RUN: | FileCheck -check-prefix=X64 %s
2 ; RUN: llc < %s -emulated-tls -mcpu=generic -mtriple=i386-linux-gnu -relocation-model=pic -pie-copy-relocations \
3 ; RUN: | FileCheck -check-prefix=X32 %s
4
5 ; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux-gnu -relocation-model=pic -pie-copy-relocations \
16 ; RUN: | FileCheck -check-prefix=X64 %s
2 ; RUN: llc < %s -emulated-tls -mcpu=generic -mtriple=i386-linux-gnu -relocation-model=pic -pie-copy-relocations \
7 ; RUN: llc < %s -mcpu=generic -mtriple=i386-linux-gnu -relocation-model=pic -pie-copy-relocations \
38 ; RUN: | FileCheck -check-prefix=X32 %s
49
510 ; External Linkage
0 ; RUN: llc < %s -emulated-tls -mcpu=generic -mtriple=x86_64-linux-gnu -relocation-model=pic \
1 ; RUN: | FileCheck -check-prefix=X64 %s
2 ; RUN: llc < %s -emulated-tls -mcpu=generic -mtriple=i386-linux-gnu -relocation-model=pic \
3 ; RUN: | FileCheck -check-prefix=X32 %s
4
5 ; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux-gnu -relocation-model=pic \
16 ; RUN: | FileCheck -check-prefix=X64 %s
2 ; RUN: llc < %s -emulated-tls -mcpu=generic -mtriple=i386-linux-gnu -relocation-model=pic \
7 ; RUN: llc < %s -mcpu=generic -mtriple=i386-linux-gnu -relocation-model=pic \
38 ; RUN: | FileCheck -check-prefix=X32 %s
49
510 ; External Linkage
0 ; RUN: llc < %s -emulated-tls -mtriple=i686-linux-android -relocation-model=pic | FileCheck %s
11 ; RUN: llc < %s -emulated-tls -mtriple=x86_64-linux-android -relocation-model=pic | FileCheck %s
2
3 ; RUN: llc < %s -mtriple=i686-linux-android -relocation-model=pic | FileCheck %s
4 ; RUN: llc < %s -mtriple=x86_64-linux-android -relocation-model=pic | FileCheck %s
25
36 ; Make sure that some symboles are not emitted in emulated TLS model.
47
0 ; RUN: llc < %s -emulated-tls -mtriple=i686-linux-android -relocation-model=pic | FileCheck %s
11 ; RUN: llc < %s -emulated-tls -mtriple=x86_64-linux-android -relocation-model=pic | FileCheck -check-prefix=X64 %s
2
3 ; RUN: llc < %s -mtriple=i686-linux-android -relocation-model=pic | FileCheck %s
4 ; RUN: llc < %s -mtriple=x86_64-linux-android -relocation-model=pic | FileCheck -check-prefix=X64 %s
25
36 ; Make sure that TLS symboles are emitted in expected order.
47