From 5e162947b3757e51724e7522385a9fdf4511b1b7 Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Wed, 7 May 2014 06:18:01 +0000 Subject: [PATCH] [OPENMP] Fixed problem with temp removal on some platforms in codegen for '#pragma omp parallel' git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208162 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGOpenMPRuntime.cpp | 14 ++++---------- lib/CodeGen/CGOpenMPRuntime.h | 3 +++ test/OpenMP/parallel_codegen.cpp | 2 -- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/CodeGen/CGOpenMPRuntime.cpp b/lib/CodeGen/CGOpenMPRuntime.cpp index 2009f40911..da86e2b52d 100644 --- a/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/lib/CodeGen/CGOpenMPRuntime.cpp @@ -38,10 +38,7 @@ CGOpenMPRuntime::CGOpenMPRuntime(CodeGenModule &CGM) llvm::Value * CGOpenMPRuntime::GetOrCreateDefaultOpenMPLocation(OpenMPLocationFlags Flags) { - llvm::Twine OpenMPDefaultLocName = - ".kmpc_default_loc_" + llvm::Twine::utohexstr(Flags) + ".addr"; - llvm::Value *Entry = - CGM.getModule().getNamedValue(OpenMPDefaultLocName.str()); + llvm::Value *Entry = OpenMPDefaultLocMap.lookup(Flags); if (!Entry) { if (!DefaultOpenMPPSource) { // Initialize default location for psource field of ident_t structure of @@ -54,7 +51,7 @@ CGOpenMPRuntime::GetOrCreateDefaultOpenMPLocation(OpenMPLocationFlags Flags) { llvm::ConstantExpr::getBitCast(DefaultOpenMPPSource, CGM.Int8PtrTy); } llvm::GlobalVariable *DefaultOpenMPLocation = cast( - CGM.CreateRuntimeVariable(IdentTy, OpenMPDefaultLocName.str())); + CGM.CreateRuntimeVariable(IdentTy, ".kmpc_default_loc.addr")); DefaultOpenMPLocation->setUnnamedAddr(true); DefaultOpenMPLocation->setConstant(true); DefaultOpenMPLocation->setLinkage(llvm::GlobalValue::PrivateLinkage); @@ -79,16 +76,13 @@ llvm::Value *CGOpenMPRuntime::EmitOpenMPUpdateLocation( assert(CGF.CurFn && "No function in current CodeGenFunction."); - llvm::Twine OpenMPLocName = - ".kmpc_loc_" + llvm::Twine::utohexstr(Flags) + ".addr"; - llvm::Value *LocValue = nullptr; OpenMPLocMapTy::iterator I = OpenMPLocMap.find(CGF.CurFn); if (I != OpenMPLocMap.end()) { LocValue = I->second; } else { - // Generate "ident_t .kmpc_loc_.addr;" - llvm::AllocaInst *AI = CGF.CreateTempAlloca(IdentTy, OpenMPLocName); + // Generate "ident_t .kmpc_loc.addr;" + llvm::AllocaInst *AI = CGF.CreateTempAlloca(IdentTy, ".kmpc_loc.addr"); AI->setAlignment(CGM.getDataLayout().getPrefTypeAlignment(IdentTy)); OpenMPLocMap[CGF.CurFn] = AI; LocValue = AI; diff --git a/lib/CodeGen/CGOpenMPRuntime.h b/lib/CodeGen/CGOpenMPRuntime.h index 7ba7ada2b1..06103cf4d6 100644 --- a/lib/CodeGen/CGOpenMPRuntime.h +++ b/lib/CodeGen/CGOpenMPRuntime.h @@ -76,6 +76,9 @@ private: /// \brief Default const ident_t object used for initialization of all other /// ident_t objects. llvm::Constant *DefaultOpenMPPSource; + /// \brief Map of flags and corrsponding default locations. + typedef llvm::DenseMap OpenMPDefaultLocMapTy; + OpenMPDefaultLocMapTy OpenMPDefaultLocMap; llvm::Value *GetOrCreateDefaultOpenMPLocation(OpenMPLocationFlags Flags); /// \brief Describes ident structure that describes a source location. /// All descriptions are taken from diff --git a/test/OpenMP/parallel_codegen.cpp b/test/OpenMP/parallel_codegen.cpp index 2bc57f5870..d20bc84856 100644 --- a/test/OpenMP/parallel_codegen.cpp +++ b/test/OpenMP/parallel_codegen.cpp @@ -2,8 +2,6 @@ // RUN: %clang_cc1 -fopenmp=libiomp5 -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s // RUN: %clang_cc1 -fopenmp=libiomp5 -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -g -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix=CHECK-DEBUG %s // expected-no-diagnostics -// FIXME: This test stiil crashing because of mem leak. -// REQUIRES: disabled #ifndef HEADER #define HEADER -- 2.40.0