clementval created this revision.
clementval added reviewers: jdoerfert, kiranchandramohan.
Herald added subscribers: rriddle, guansong, hiraditya, yaxunl.
clementval requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, sstefan1, 
stephenneuendorffer.
Herald added projects: clang, LLVM.

Add function to create the offload_maptypes and the offload_mapnames globals. 
These two functions
are used in clang. They will be used in the Flang/MLIR lowering as well.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101503

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  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
@@ -2095,6 +2095,33 @@
   return getOrCreateOMPInternalVariable(KmpCriticalNameTy, Name);
 }
 
+// Create the global variable holding the offload mappings information.
+GlobalVariable *
+OpenMPIRBuilder::createOffloadMaptypes(SmallVector<uint64_t> &Mappings) {
+  llvm::Constant *MaptypesArrayInit =
+      llvm::ConstantDataArray::get(M.getContext(), Mappings);
+  auto *MaptypesArrayGlobal = new llvm::GlobalVariable(
+      M, MaptypesArrayInit->getType(),
+      /*isConstant=*/true, llvm::GlobalValue::PrivateLinkage, MaptypesArrayInit,
+      "offload_maptypes");
+  MaptypesArrayGlobal->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
+  return MaptypesArrayGlobal;
+}
+
+// Create the global variables holding the offload names information.
+GlobalVariable *
+OpenMPIRBuilder::createOffloadMapnames(SmallVector<llvm::Constant *> &Names) {
+  llvm::Constant *MapNamesArrayInit = llvm::ConstantArray::get(
+      llvm::ArrayType::get(
+          llvm::Type::getInt8Ty(M.getContext())->getPointerTo(), Names.size()),
+      Names);
+  auto *MapNamesArrayGlobal = new llvm::GlobalVariable(
+      M, MapNamesArrayInit->getType(),
+      /*isConstant=*/true, llvm::GlobalValue::PrivateLinkage, MapNamesArrayInit,
+      "offload_mapnames");
+  return MapNamesArrayGlobal;
+}
+
 // Create all simple and struct types exposed by the runtime and remember
 // the llvm::PointerTypes of them for easy access later.
 void OpenMPIRBuilder::initializeTypes(Module &M) {
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===================================================================
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -615,6 +615,12 @@
   /// variables.
   StringMap<AssertingVH<Constant>, BumpPtrAllocator> InternalVars;
 
+  /// Create the global variable holding the offload mappings information.
+  GlobalVariable *createOffloadMaptypes(SmallVector<uint64_t> &Mappings);
+
+  /// Create the global variable holding the offload names information.
+  GlobalVariable *createOffloadMapnames(SmallVector<llvm::Constant *> &Names);
+
 public:
   /// Generator for __kmpc_copyprivate
   ///
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===================================================================
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -9375,17 +9375,9 @@
 
     // The map types are always constant so we don't need to generate code to
     // fill arrays. Instead, we create an array constant.
-    SmallVector<uint64_t, 4> Mapping(CombinedInfo.Types.size(), 0);
+    SmallVector<uint64_t> Mapping(CombinedInfo.Types.size(), 0);
     llvm::copy(CombinedInfo.Types, Mapping.begin());
-    llvm::Constant *MapTypesArrayInit =
-        llvm::ConstantDataArray::get(CGF.Builder.getContext(), Mapping);
-    std::string MaptypesName =
-        CGM.getOpenMPRuntime().getName({"offload_maptypes"});
-    auto *MapTypesArrayGbl = new llvm::GlobalVariable(
-        CGM.getModule(), MapTypesArrayInit->getType(),
-        /*isConstant=*/true, llvm::GlobalValue::PrivateLinkage,
-        MapTypesArrayInit, MaptypesName);
-    MapTypesArrayGbl->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
+    auto *MapTypesArrayGbl = OMPBuilder.createOffloadMaptypes(Mapping);
     Info.MapTypesArray = MapTypesArrayGbl;
 
     // The information types are only built if there is debug information
@@ -9397,19 +9389,10 @@
       auto fillInfoMap = [&](MappableExprsHandler::MappingExprInfo &MapExpr) {
         return emitMappingInformation(CGF, OMPBuilder, MapExpr);
       };
-      SmallVector<llvm::Constant *, 4> InfoMap(CombinedInfo.Exprs.size());
+      SmallVector<llvm::Constant *> InfoMap(CombinedInfo.Exprs.size());
       llvm::transform(CombinedInfo.Exprs, InfoMap.begin(), fillInfoMap);
 
-      llvm::Constant *MapNamesArrayInit = llvm::ConstantArray::get(
-          llvm::ArrayType::get(
-              llvm::Type::getInt8Ty(CGF.Builder.getContext())->getPointerTo(),
-              CombinedInfo.Exprs.size()),
-          InfoMap);
-      auto *MapNamesArrayGbl = new llvm::GlobalVariable(
-          CGM.getModule(), MapNamesArrayInit->getType(),
-          /*isConstant=*/true, llvm::GlobalValue::PrivateLinkage,
-          MapNamesArrayInit,
-          CGM.getOpenMPRuntime().getName({"offload_mapnames"}));
+      auto *MapNamesArrayGbl = OMPBuilder.createOffloadMapnames(InfoMap);
       Info.MapNamesArray = MapNamesArrayGbl;
     }
 
@@ -9424,15 +9407,7 @@
         }
       }
       if (EndMapTypesDiffer) {
-        MapTypesArrayInit =
-            llvm::ConstantDataArray::get(CGF.Builder.getContext(), Mapping);
-        MaptypesName = CGM.getOpenMPRuntime().getName({"offload_maptypes"});
-        MapTypesArrayGbl = new llvm::GlobalVariable(
-            CGM.getModule(), MapTypesArrayInit->getType(),
-            /*isConstant=*/true, llvm::GlobalValue::PrivateLinkage,
-            MapTypesArrayInit, MaptypesName);
-        MapTypesArrayGbl->setUnnamedAddr(
-            llvm::GlobalValue::UnnamedAddr::Global);
+        MapTypesArrayGbl = OMPBuilder.createOffloadMaptypes(Mapping);
         Info.MapTypesArrayEnd = MapTypesArrayGbl;
       }
     }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to