[PATCH] D137725: [OpenMP][OMPIRBuilder] Mirgrate getName from clang to OMPIRBuilder

Jan Sjödin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 9 09:16:10 PST 2022


jsjodin created this revision.
jsjodin added reviewers: jdoerfert, ABataev, mikerice.
Herald added subscribers: guansong, hiraditya, yaxunl.
Herald added a project: All.
jsjodin requested review of this revision.
Herald added subscribers: llvm-commits, sstefan1.
Herald added a project: LLVM.

This change moves the getName function from clang and moves the separator class
members from CGOpenMPRuntime into OpenMPIRBuilder.

There is a question if we want this kind of state in the OpenMPIRBuilder, there
are other parameters that could be class members like IsEmbedded (IsDevice),
IsTargetCodegen etc.  These are currently derived from the CodeGenModule class in clang.
Moving more of the code generation into OpenMPIRBuilder requires knowledge of these parameters,
which have so far been passed in as arguments to the functions, but the number of parameters
might become too many to pass around all the time. There is a case where these parameters should
be made part of the OMPIRBuilder, and used in CGOpenMPRuntime.


https://reviews.llvm.org/D137725

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp


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<StringRef> 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
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<StringRef> Parts) const;
+
   /// Callback type for variable finalization (think destructors).
   ///
   /// \param CodeGenIP is the insertion point at which the finalization code
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<StringRef> 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 *


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137725.474294.patch
Type: text/x-patch
Size: 3990 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221109/206059fd/attachment.bin>


More information about the llvm-commits mailing list