r263854 - [TLS on Darwin] use CXX_FAST_TLS calling convention for tls_init.
Manman Ren via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 18 16:35:21 PDT 2016
Author: mren
Date: Fri Mar 18 18:35:21 2016
New Revision: 263854
URL: http://llvm.org/viewvc/llvm-project?rev=263854&view=rev
Log:
[TLS on Darwin] use CXX_FAST_TLS calling convention for tls_init.
This makes sure we don't generate a lot of code to spill/reload
CSRs when calling tls_init from the access functions.
This helps performance when tls_init is not inlined into the access
functions.
Modified:
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/test/CodeGenCXX/cxx11-thread-local-reference.cpp
cfe/trunk/test/CodeGenCXX/cxx11-thread-local.cpp
Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=263854&r1=263853&r2=263854&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Fri Mar 18 18:35:21 2016
@@ -2237,6 +2237,11 @@ void ItaniumCXXABI::EmitThreadLocalInitF
CodeGenFunction(CGM)
.GenerateCXXGlobalInitFunc(InitFunc, CXXThreadLocalInits,
Address(Guard, GuardAlign));
+ // On Darwin platforms, use CXX_FAST_TLS calling convention.
+ if (CGM.getTarget().getTriple().isOSDarwin()) {
+ InitFunc->setCallingConv(llvm::CallingConv::CXX_FAST_TLS);
+ InitFunc->addFnAttr(llvm::Attribute::NoUnwind);
+ }
}
for (const VarDecl *VD : CXXThreadLocals) {
llvm::GlobalVariable *Var =
@@ -2286,8 +2291,11 @@ void ItaniumCXXABI::EmitThreadLocalInitF
llvm::BasicBlock *Entry = llvm::BasicBlock::Create(Context, "", Wrapper);
CGBuilderTy Builder(CGM, Entry);
if (InitIsInitFunc) {
- if (Init)
- Builder.CreateCall(Init);
+ if (Init) {
+ llvm::CallInst *CallVal = Builder.CreateCall(Init);
+ if (isThreadWrapperReplaceable(VD, CGM))
+ CallVal->setCallingConv(llvm::CallingConv::CXX_FAST_TLS);
+ }
} else {
// Don't know whether we have an init function. Call it if it exists.
llvm::Value *Have = Builder.CreateIsNotNull(Init);
Modified: cfe/trunk/test/CodeGenCXX/cxx11-thread-local-reference.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx11-thread-local-reference.cpp?rev=263854&r1=263853&r2=263854&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/cxx11-thread-local-reference.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/cxx11-thread-local-reference.cpp Fri Mar 18 18:35:21 2016
@@ -23,11 +23,13 @@ int &g() { return r; }
// LINUX: define weak_odr hidden i32* @_ZTW1r() [[ATTR0:#[0-9]+]] {
// DARWIN: define cxx_fast_tlscc i32* @_ZTW1r() [[ATTR1:#[0-9]+]] {
-// CHECK: call void @_ZTH1r()
+// LINUX: call void @_ZTH1r()
+// DARWIN: call cxx_fast_tlscc void @_ZTH1r()
// CHECK: load i32*, i32** @r, align 8
// CHECK: ret i32* %{{.*}}
-// CHECK-LABEL: define internal void @__tls_init()
+// LINUX-LABEL: define internal void @__tls_init()
+// DARWIN-LABEL: define internal cxx_fast_tlscc void @__tls_init()
// CHECK: call void @[[R_INIT]]()
// LINUX: attributes [[ATTR0]] = { {{.*}}"target-features"{{.*}} }
Modified: cfe/trunk/test/CodeGenCXX/cxx11-thread-local.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx11-thread-local.cpp?rev=263854&r1=263853&r2=263854&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/cxx11-thread-local.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/cxx11-thread-local.cpp Fri Mar 18 18:35:21 2016
@@ -122,7 +122,8 @@ int f() {
// LINUX-LABEL: define weak_odr hidden i32* @_ZTWN1VIiE1mE()
// DARWIN-LABEL: define weak_odr hidden cxx_fast_tlscc i32* @_ZTWN1VIiE1mE()
-// CHECK: call void @_ZTHN1VIiE1mE()
+// LINUX: call void @_ZTHN1VIiE1mE()
+// DARWIN: call cxx_fast_tlscc void @_ZTHN1VIiE1mE()
// CHECK: ret i32* @_ZN1VIiE1mE
@@ -212,7 +213,8 @@ void set_anon_i() {
// LIUNX: define weak_odr hidden i32* @_ZTW1a() {
// DARWIN: define cxx_fast_tlscc i32* @_ZTW1a()
-// CHECK: call void @_ZTH1a()
+// LINUX: call void @_ZTH1a()
+// DARWIN: call cxx_fast_tlscc void @_ZTH1a()
// CHECK: ret i32* @a
// CHECK: }
@@ -222,12 +224,14 @@ void set_anon_i() {
// LINUX-LABEL: define internal i32* @_ZTWL1d()
// DARWIN-LABEL: define internal cxx_fast_tlscc i32* @_ZTWL1d()
-// CHECK: call void @_ZTHL1d()
+// LINUX: call void @_ZTHL1d()
+// DARWIN: call cxx_fast_tlscc void @_ZTHL1d()
// CHECK: ret i32* @_ZL1d
// LINUX-LABEL: define weak_odr hidden i32* @_ZTWN1U1mE()
// DARWIN-LABEL: define cxx_fast_tlscc i32* @_ZTWN1U1mE()
-// CHECK: call void @_ZTHN1U1mE()
+// LINUX: call void @_ZTHN1U1mE()
+// DARWIN: call cxx_fast_tlscc void @_ZTHN1U1mE()
// CHECK: ret i32* @_ZN1U1mE
// LINUX: attributes [[ATTR]] = { {{.+}} }
More information about the cfe-commits
mailing list