diff options
author | Alexey Bataev <a.bataev@hotmail.com> | 2019-03-21 20:36:16 +0000 |
---|---|---|
committer | Alexey Bataev <a.bataev@hotmail.com> | 2019-03-21 20:36:16 +0000 |
commit | 084b0c2f03786c1a40f834eec7e6d5a5458d27e6 (patch) | |
tree | 0f7ab6892a4a6df9184d64892e9314f879269d50 /clang/lib/CodeGen | |
parent | 7339e61b891404631b92ae6130e24e641c2a5cb7 (diff) | |
download | bcm5719-llvm-084b0c2f03786c1a40f834eec7e6d5a5458d27e6.tar.gz bcm5719-llvm-084b0c2f03786c1a40f834eec7e6d5a5458d27e6.zip |
[OPENMP] Simplify codegen for allocate directive on local variables.
Simplified codegen for the allocate directive for local variables,
initial implementation of the codegen for NVPTX target.
llvm-svn: 356710
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CGOpenMPRuntime.cpp | 86 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp | 24 |
2 files changed, 65 insertions, 45 deletions
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index d3736b7244d..a8af23b63ac 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -9745,54 +9745,50 @@ public: Address CGOpenMPRuntime::getAddressOfLocalVariable(CodeGenFunction &CGF, const VarDecl *VD) { + if (!VD) + return Address::invalid(); const VarDecl *CVD = VD->getCanonicalDecl(); if (!CVD->hasAttr<OMPAllocateDeclAttr>()) return Address::invalid(); - for (const Attr *A: CVD->getAttrs()) { - if (const auto *AA = dyn_cast<OMPAllocateDeclAttr>(A)) { - auto &Elem = OpenMPLocThreadIDMap.FindAndConstruct(CGF.CurFn); - if (!Elem.second.ServiceInsertPt) - setLocThreadIdInsertPt(CGF); - CGBuilderTy::InsertPointGuard IPG(CGF.Builder); - CGF.Builder.SetInsertPoint(Elem.second.ServiceInsertPt); - llvm::Value *Size; - CharUnits Align = CGM.getContext().getDeclAlign(CVD); - if (CVD->getType()->isVariablyModifiedType()) { - Size = CGF.getTypeSize(CVD->getType()); - Align = CGM.getContext().getTypeAlignInChars(CVD->getType()); - } else { - CharUnits Sz = CGM.getContext().getTypeSizeInChars(CVD->getType()); - Align = CGM.getContext().getDeclAlign(CVD); - Size = CGM.getSize(Sz.alignTo(Align)); - } - llvm::Value *ThreadID = getThreadID(CGF, CVD->getBeginLoc()); - llvm::Value *Allocator; - if (const Expr *AllocExpr = AA->getAllocator()) { - Allocator = CGF.EmitScalarExpr(AllocExpr); - } else { - // Default allocator in libomp is nullptr. - Allocator = llvm::ConstantPointerNull::get(CGM.VoidPtrPtrTy); - } - llvm::Value *Args[] = {ThreadID, Size, Allocator}; - - llvm::Value *Addr = - CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_alloc), Args, - CVD->getName() + ".void.addr"); - llvm::Value *FiniArgs[OMPAllocateCleanupTy::CleanupArgs] = { - ThreadID, Addr, Allocator}; - llvm::FunctionCallee FiniRTLFn = createRuntimeFunction(OMPRTL__kmpc_free); - - CGF.EHStack.pushCleanup<OMPAllocateCleanupTy>( - NormalAndEHCleanup, FiniRTLFn, llvm::makeArrayRef(FiniArgs)); - Addr = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast( - Addr, - CGF.ConvertTypeForMem( - CGM.getContext().getPointerType(CVD->getType())), - CVD->getName() + ".addr"); - return Address(Addr, Align); - } - } - return Address::invalid(); + const auto *AA = CVD->getAttr<OMPAllocateDeclAttr>(); + // Use the default allocation. + if (AA->getAllocatorType() == OMPAllocateDeclAttr::OMPDefaultMemAlloc) + return Address::invalid(); + auto &Elem = OpenMPLocThreadIDMap.FindAndConstruct(CGF.CurFn); + if (!Elem.second.ServiceInsertPt) + setLocThreadIdInsertPt(CGF); + CGBuilderTy::InsertPointGuard IPG(CGF.Builder); + CGF.Builder.SetInsertPoint(Elem.second.ServiceInsertPt); + llvm::Value *Size; + CharUnits Align = CGM.getContext().getDeclAlign(CVD); + if (CVD->getType()->isVariablyModifiedType()) { + Size = CGF.getTypeSize(CVD->getType()); + Align = CGM.getContext().getTypeAlignInChars(CVD->getType()); + } else { + CharUnits Sz = CGM.getContext().getTypeSizeInChars(CVD->getType()); + Align = CGM.getContext().getDeclAlign(CVD); + Size = CGM.getSize(Sz.alignTo(Align)); + } + llvm::Value *ThreadID = getThreadID(CGF, CVD->getBeginLoc()); + assert(AA->getAllocator() && + "Expected allocator expression for non-default allocator."); + llvm::Value *Allocator = CGF.EmitScalarExpr(AA->getAllocator()); + llvm::Value *Args[] = {ThreadID, Size, Allocator}; + + llvm::Value *Addr = + CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_alloc), Args, + CVD->getName() + ".void.addr"); + llvm::Value *FiniArgs[OMPAllocateCleanupTy::CleanupArgs] = {ThreadID, Addr, + Allocator}; + llvm::FunctionCallee FiniRTLFn = createRuntimeFunction(OMPRTL__kmpc_free); + + CGF.EHStack.pushCleanup<OMPAllocateCleanupTy>(NormalAndEHCleanup, FiniRTLFn, + llvm::makeArrayRef(FiniArgs)); + Addr = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast( + Addr, + CGF.ConvertTypeForMem(CGM.getContext().getPointerType(CVD->getType())), + CVD->getName() + ".addr"); + return Address(Addr, Align); } llvm::Function *CGOpenMPSIMDRuntime::emitParallelOutlinedFunction( diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp b/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp index 7de16032269..fd294dab640 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp @@ -4725,6 +4725,28 @@ void CGOpenMPRuntimeNVPTX::emitFunctionProlog(CodeGenFunction &CGF, Address CGOpenMPRuntimeNVPTX::getAddressOfLocalVariable(CodeGenFunction &CGF, const VarDecl *VD) { + bool UseDefaultAllocator = true; + if (VD && VD->hasAttr<OMPAllocateDeclAttr>()) { + const auto *A = VD->getAttr<OMPAllocateDeclAttr>(); + switch (A->getAllocatorType()) { + // Use the default allocator here as by default local vars are + // threadlocal. + case OMPAllocateDeclAttr::OMPDefaultMemAlloc: + case OMPAllocateDeclAttr::OMPThreadMemAlloc: + // Just pass-through to check if the globalization is required. + break; + case OMPAllocateDeclAttr::OMPLargeCapMemAlloc: + case OMPAllocateDeclAttr::OMPCGroupMemAlloc: + case OMPAllocateDeclAttr::OMPHighBWMemAlloc: + case OMPAllocateDeclAttr::OMPLowLatMemAlloc: + case OMPAllocateDeclAttr::OMPConstMemAlloc: + case OMPAllocateDeclAttr::OMPPTeamMemAlloc: + case OMPAllocateDeclAttr::OMPUserDefinedMemAlloc: + UseDefaultAllocator = false; + break; + } + } + if (getDataSharingMode(CGM) != CGOpenMPRuntimeNVPTX::Generic) return Address::invalid(); @@ -4746,7 +4768,9 @@ Address CGOpenMPRuntimeNVPTX::getAddressOfLocalVariable(CodeGenFunction &CGF, return VDI->second.PrivateAddr; } } + // TODO: replace it with return + // UseDefaultAllocator ? Address::invalid : // CGOpenMPRuntime::getAddressOfLocalVariable(CGF, VD); when NVPTX libomp // supports __kmpc_alloc|__kmpc_free. return Address::invalid(); |