diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp --- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp @@ -833,24 +833,6 @@ IsInTTDRegion = false; } -// Create a unique global variable to indicate the execution mode of this target -// region. The execution mode is either 'generic', or 'spmd' depending on the -// target directive. This variable is picked up by the offload library to setup -// the device appropriately before kernel launch. If the execution mode is -// 'generic', the runtime reserves one warp for the master, otherwise, all -// warps participate in parallel work. -static void setPropertyExecutionMode(CodeGenModule &CGM, StringRef Name, - bool Mode) { - auto *GVMode = new llvm::GlobalVariable( - CGM.getModule(), CGM.Int8Ty, /*isConstant=*/true, - llvm::GlobalValue::WeakAnyLinkage, - llvm::ConstantInt::get(CGM.Int8Ty, Mode ? OMP_TGT_EXEC_MODE_SPMD - : OMP_TGT_EXEC_MODE_GENERIC), - Twine(Name, "_exec_mode")); - GVMode->setVisibility(llvm::GlobalVariable::ProtectedVisibility); - CGM.addCompilerUsedGlobal(GVMode); -} - void CGOpenMPRuntimeGPU::emitTargetOutlinedFunction( const OMPExecutableDirective &D, StringRef ParentName, llvm::Function *&OutlinedFn, llvm::Constant *&OutlinedFnID, @@ -868,7 +850,10 @@ emitNonSPMDKernel(D, ParentName, OutlinedFn, OutlinedFnID, IsOffloadEntry, CodeGen); - setPropertyExecutionMode(CGM, OutlinedFn->getName(), Mode); + llvm::OpenMPIRBuilder &OMPBuilder = getOMPBuilder(); + llvm::GlobalVariable *GVMode = + OMPBuilder.setPropertyExecutionMode(OutlinedFn->getName(), Mode); + CGM.addCompilerUsedGlobal(GVMode); } CGOpenMPRuntimeGPU::CGOpenMPRuntimeGPU(CodeGenModule &CGM) diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -1012,6 +1012,10 @@ return EmittedGlobalBlocks.lookup(BE); } + std::vector &getLLVMCompilerUsed() { + return LLVMCompilerUsed; + } + /// Notes that BE's global block is available via Addr. Asserts that BE /// isn't already emitted. void setAddrOfGlobalBlock(const BlockExpr *BE, llvm::Constant *Addr); diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h --- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h +++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h @@ -1493,6 +1493,17 @@ void emitIfClause(Value *Cond, BodyGenCallbackTy ThenGen, BodyGenCallbackTy ElseGen, InsertPointTy AllocaIP = {}); + /// Create a unique global variable to indicate the execution mode of this + /// target region. The execution mode is either 'generic', or 'spmd' depending + /// on the target directive. This variable is picked up by the offload library + /// to setup the device appropriately before kernel launch. If the execution + /// mode is 'generic', the runtime reserves one warp for the master, + /// otherwise, all warps participate in parallel work. + /// \param Name The symbol name associated with the global. + /// \param IsSPMDMode is boolean to indicate if the kernel is an SPMD kernel + /// or not. + GlobalVariable *setPropertyExecutionMode(StringRef Name, bool IsSPMDMode); + /// Create the global variable holding the offload mappings information. GlobalVariable *createOffloadMaptypes(SmallVectorImpl &Mappings, std::string VarName); diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp --- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp +++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp @@ -4933,14 +4933,27 @@ emitBlock(ContBlock, CurFn, /*IsFinished=*/true); } +GlobalVariable *OpenMPIRBuilder::setPropertyExecutionMode(StringRef Name, + bool IsSPMDMode) { + auto *GVMode = new GlobalVariable( + M, Type::getInt8Ty(M.getContext()), /*isConstant=*/true, + GlobalValue::WeakAnyLinkage, + ConstantInt::get(llvm::Type::getInt8Ty(M.getContext()), + IsSPMDMode ? OMP_TGT_EXEC_MODE_SPMD + : OMP_TGT_EXEC_MODE_GENERIC), + Twine(Name, "_exec_mode")); + GVMode->setVisibility(GlobalVariable::ProtectedVisibility); + return GVMode; +} + bool OpenMPIRBuilder::checkAndEmitFlushAfterAtomic( - const LocationDescription &Loc, llvm::AtomicOrdering AO, AtomicKind AK) { - assert(!(AO == AtomicOrdering::NotAtomic || - AO == llvm::AtomicOrdering::Unordered) && - "Unexpected Atomic Ordering."); + const LocationDescription &Loc, AtomicOrdering AO, AtomicKind AK) { + assert( + !(AO == AtomicOrdering::NotAtomic || AO == AtomicOrdering::Unordered) && + "Unexpected Atomic Ordering."); bool Flush = false; - llvm::AtomicOrdering FlushAO = AtomicOrdering::Monotonic; + AtomicOrdering FlushAO = AtomicOrdering::Monotonic; switch (AK) { case Read: