Index: clang/lib/CodeGen/CGOpenMPRuntime.h =================================================================== --- clang/lib/CodeGen/CGOpenMPRuntime.h +++ clang/lib/CodeGen/CGOpenMPRuntime.h @@ -306,7 +306,6 @@ protected: CodeGenModule &CGM; - StringRef FirstSeparator, Separator; /// An OpenMP-IR-Builder instance. llvm::OpenMPIRBuilder OMPBuilder; Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp =================================================================== --- clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -1059,12 +1059,11 @@ CGOpenMPRuntime::CGOpenMPRuntime(CodeGenModule &CGM, StringRef FirstSeparator, StringRef Separator) - : CGM(CGM), FirstSeparator(FirstSeparator), Separator(Separator), - OMPBuilder(CGM.getModule()), OffloadEntriesInfoManager() { + : CGM(CGM), OMPBuilder(CGM.getModule()), OffloadEntriesInfoManager() { KmpCriticalNameTy = llvm::ArrayType::get(CGM.Int32Ty, /*NumElements*/ 8); llvm::OpenMPIRBuilderConfig Config(CGM.getLangOpts().OpenMPIsDevice, false, - hasRequiresUnifiedSharedMemory()); - + hasRequiresUnifiedSharedMemory(), + FirstSeparator, Separator); // Initialize Types used in OpenMPIRBuilder from OMPKinds.def OMPBuilder.initialize(); OMPBuilder.setConfig(Config); @@ -1088,14 +1087,7 @@ } std::string CGOpenMPRuntime::getName(ArrayRef Parts) const { - SmallString<128> Buffer; - llvm::raw_svector_ostream OS(Buffer); - StringRef Sep = FirstSeparator; - for (StringRef Part : Parts) { - OS << Sep << Part; - Sep = Separator; - } - return std::string(OS.str()); + return OMPBuilder.getName(Parts); } static llvm::Function * Index: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp =================================================================== --- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp +++ clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp @@ -889,9 +889,10 @@ } CGOpenMPRuntimeGPU::CGOpenMPRuntimeGPU(CodeGenModule &CGM) - : CGOpenMPRuntime(CGM, "_", "$") { + : CGOpenMPRuntime(CGM) { llvm::OpenMPIRBuilderConfig Config(CGM.getLangOpts().OpenMPIsDevice, true, - hasRequiresUnifiedSharedMemory()); + hasRequiresUnifiedSharedMemory(), "_", + "$"); OMPBuilder.setConfig(Config); OffloadEntriesInfoManager.setConfig(Config); Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h =================================================================== --- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h +++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h @@ -92,34 +92,53 @@ /// directive is present or not. Optional HasRequiresUnifiedSharedMemory; + /// First separator used between the initial two parts of a name. + Optional FirstSeparator; + /// Separator used between all of the rest consecutive parts of s name + Optional Separator; + OpenMPIRBuilderConfig() {} OpenMPIRBuilderConfig(bool IsEmbedded, bool IsTargetCodegen, - bool HasRequiresUnifiedSharedMemory) + bool HasRequiresUnifiedSharedMemory, + StringRef FirstSeparator, StringRef Separator) : IsEmbedded(IsEmbedded), IsTargetCodegen(IsTargetCodegen), - HasRequiresUnifiedSharedMemory(HasRequiresUnifiedSharedMemory) {} + HasRequiresUnifiedSharedMemory(HasRequiresUnifiedSharedMemory), + FirstSeparator(FirstSeparator), Separator(Separator) {} // Convenience getter functions that assert if the value is not present. - bool isEmbedded() { + bool isEmbedded() const { assert(IsEmbedded.has_value() && "IsEmbedded is not set"); return IsEmbedded.value(); } - bool isTargetCodegen() { + bool isTargetCodegen() const { assert(IsTargetCodegen.has_value() && "IsTargetCodegen is not set"); return IsTargetCodegen.value(); } - bool hasRequiresUnifiedSharedMemory() { + bool hasRequiresUnifiedSharedMemory() const { assert(HasRequiresUnifiedSharedMemory.has_value() && "HasUnifiedSharedMemory is not set"); return HasRequiresUnifiedSharedMemory.value(); } + StringRef firstSeparator() const { + assert(FirstSeparator.has_value() && "FirstSeparator is not set"); + return FirstSeparator.value(); + } + + StringRef separator() const { + assert(Separator.has_value() && "Separator is not set"); + return Separator.value(); + } + void setIsEmbedded(bool Value) { IsEmbedded = Value; } void setIsTargetCodegen(bool Value) { IsTargetCodegen = Value; } void setHasRequiresUnifiedSharedMemory(bool Value) { HasRequiresUnifiedSharedMemory = Value; } + void setFirstSeparator(StringRef FS) { FirstSeparator = FS; } + void setSeparator(StringRef S) { Separator = S; } }; /// An interface to create LLVM-IR for OpenMP directives. @@ -150,6 +169,10 @@ /// Type used throughout for insertion points. using InsertPointTy = IRBuilder<>::InsertPoint; + /// Get the platform-specific name separator. + /// \param Parts different parts of the final name that needs separation + std::string getName(ArrayRef Parts) const; + /// Callback type for variable finalization (think destructors). /// /// \param CodeGenIP is the insertion point at which the finalization code Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp =================================================================== --- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp +++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp @@ -3963,6 +3963,11 @@ return OS.str().str(); } +std::string OpenMPIRBuilder::getName(ArrayRef Parts) const { + return OpenMPIRBuilder::getNameWithSeparators(Parts, Config.firstSeparator(), + Config.separator()); +} + GlobalVariable * OpenMPIRBuilder::getOrCreateInternalVariable(Type *Ty, const StringRef &Name, unsigned AddressSpace) {