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,8 +1059,8 @@ CGOpenMPRuntime::CGOpenMPRuntime(CodeGenModule &CGM, StringRef FirstSeparator, StringRef Separator) - : CGM(CGM), FirstSeparator(FirstSeparator), Separator(Separator), - OMPBuilder(CGM.getModule()), OffloadEntriesInfoManager() { + : CGM(CGM), OMPBuilder(CGM.getModule(), FirstSeparator, Separator), + OffloadEntriesInfoManager() { KmpCriticalNameTy = llvm::ArrayType::get(CGM.Int32Ty, /*NumElements*/ 8); // Initialize Types used in OpenMPIRBuilder from OMPKinds.def @@ -1084,14 +1084,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: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h =================================================================== --- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h +++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h @@ -77,10 +77,23 @@ /// /// Each OpenMP directive has a corresponding public generator method. class OpenMPIRBuilder { +protected: + /// First separator used between the initial two parts of a name. + StringRef FirstSeparator; + /// Separator used between all of the rest consecutive parts of s name + StringRef Separator; + public: /// Create a new OpenMPIRBuilder operating on the given module \p M. This will /// not have an effect on \p M (see initialize). - OpenMPIRBuilder(Module &M) : M(M), Builder(M.getContext()) {} + OpenMPIRBuilder(Module &M) + : FirstSeparator(""), Separator(""), M(M), Builder(M.getContext()) {} + /// Create a new OpenMPIRBuilder operating on the given module \p M and + /// strings \p FirstSeparator and \p Separator. This will not have an effect + /// on \p M (see initialize). + OpenMPIRBuilder(Module &M, StringRef FirstSeparator, StringRef Separator) + : FirstSeparator(FirstSeparator), Separator(Separator), M(M), + Builder(M.getContext()) {} ~OpenMPIRBuilder(); /// Initialize the internal state, this will put structures types and @@ -99,6 +112,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, FirstSeparator, + Separator); +} + Constant *OpenMPIRBuilder::getOrCreateOMPInternalVariable( llvm::Type *Ty, const llvm::Twine &Name, unsigned AddressSpace) { // TODO: Replace the twine arg with stringref to get rid of the conversion