From cfb60e8fa6741edb1aab76b522fc75efc6d03178 Mon Sep 17 00:00:00 2001 From: Manman Ren Date: Wed, 11 Nov 2015 19:19:26 +0000 Subject: [PATCH] [TLS] move setting tls_guard in tls_init. We used to emit the store prior to branch in the entry block. To make it more efficient, this commit moves it to the init block. We still mark as initialized before initializing anything else. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@252777 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDeclCXX.cpp | 8 ++++---- test/CodeGenCXX/cxx11-thread-local.cpp | 2 +- test/OpenMP/threadprivate_codegen.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/CodeGen/CGDeclCXX.cpp b/lib/CodeGen/CGDeclCXX.cpp index e74467bb14..df75045c78 100644 --- a/lib/CodeGen/CGDeclCXX.cpp +++ b/lib/CodeGen/CGDeclCXX.cpp @@ -518,14 +518,14 @@ CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn, llvm::Value *GuardVal = Builder.CreateLoad(Guard); llvm::Value *Uninit = Builder.CreateIsNull(GuardVal, "guard.uninitialized"); - // Mark as initialized before initializing anything else. If the - // initializers use previously-initialized thread_local vars, that's - // probably supposed to be OK, but the standard doesn't say. - Builder.CreateStore(llvm::ConstantInt::get(GuardVal->getType(),1), Guard); llvm::BasicBlock *InitBlock = createBasicBlock("init"); ExitBlock = createBasicBlock("exit"); Builder.CreateCondBr(Uninit, InitBlock, ExitBlock); EmitBlock(InitBlock); + // Mark as initialized before initializing anything else. If the + // initializers use previously-initialized thread_local vars, that's + // probably supposed to be OK, but the standard doesn't say. + Builder.CreateStore(llvm::ConstantInt::get(GuardVal->getType(),1), Guard); } RunCleanupsScope Scope(*this); diff --git a/test/CodeGenCXX/cxx11-thread-local.cpp b/test/CodeGenCXX/cxx11-thread-local.cpp index e28447e01e..9d9d255dcb 100644 --- a/test/CodeGenCXX/cxx11-thread-local.cpp +++ b/test/CodeGenCXX/cxx11-thread-local.cpp @@ -173,9 +173,9 @@ void set_anon_i() { // CHECK: define {{.*}}@__tls_init() // CHECK: load i8, i8* @__tls_guard // CHECK: %[[NEED_TLS_INIT:.*]] = icmp eq i8 %{{.*}}, 0 -// CHECK: store i8 1, i8* @__tls_guard // CHECK: br i1 %[[NEED_TLS_INIT]], // init: +// CHECK: store i8 1, i8* @__tls_guard // CHECK: call void @[[A_INIT]]() // CHECK: call void @[[D_INIT]]() // CHECK: call void @[[U_M_INIT]]() diff --git a/test/OpenMP/threadprivate_codegen.cpp b/test/OpenMP/threadprivate_codegen.cpp index 97678b4b66..53d7ef7083 100644 --- a/test/OpenMP/threadprivate_codegen.cpp +++ b/test/OpenMP/threadprivate_codegen.cpp @@ -939,9 +939,9 @@ int foobar() { // CHECK-TLS: define internal void @__tls_init() // CHECK-TLS: [[GRD:%.*]] = load i8, i8* @__tls_guard // CHECK-TLS-NEXT: [[IS_INIT:%.*]] = icmp eq i8 [[GRD]], 0 -// CHECK-TLS-NEXT: store i8 1, i8* @__tls_guard // CHECK-TLS-NEXT: br i1 [[IS_INIT]], label %[[INIT_LABEL:[^,]+]], label %[[DONE_LABEL:[^,]+]]{{.*}} // CHECK-TLS: [[INIT_LABEL]] +// CHECK-TLS-NEXT: store i8 1, i8* @__tls_guard // CHECK-TLS: call void [[GS1_CXX_INIT]] // CHECK-TLS-NOT: call void [[GS2_CXX_INIT]] // CHECK-TLS: call void [[ARR_X_CXX_INIT]] -- 2.50.1