TIFitis created this revision.
TIFitis added a reviewer: jdoerfert.
Herald added subscribers: guansong, hiraditya, yaxunl.
Herald added a project: All.
TIFitis published this revision for review.
TIFitis added reviewers: ABataev, jhuber6.
Herald added subscribers: llvm-commits, cfe-commits, sstefan1.
Herald added projects: clang, LLVM.

This patch moves the implementation of the loadOffloadInfoMetadata to the 
OMPIRbuilder.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136872

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
@@ -4705,6 +4705,65 @@
   getTargetRegionEntryFnName(Name, ParentName, DeviceID, FileID, Line);
 }
 
+/// Loads all the offload entries information from the host IR
+/// metadata.
+void llvm::loadOffloadInfoMetadata(
+    Module &M, OffloadEntriesInfoManager &OffloadEntriesInfoManager,
+    bool isDevice) {
+  // If we are in target mode, load the metadata from the host IR. This code has
+  // to match the metadaata creation in createOffloadEntriesAndInfoMetadata().
+
+  if (!isDevice)
+    return;
+
+  llvm::NamedMDNode *MD = M.getNamedMetadata("omp_offload.info");
+  if (!MD)
+    return;
+
+  for (llvm::MDNode *MN : MD->operands()) {
+    auto &&GetMDInt = [MN](unsigned Idx) {
+      auto *V = cast<llvm::ConstantAsMetadata>(MN->getOperand(Idx));
+      return cast<llvm::ConstantInt>(V->getValue())->getZExtValue();
+    };
+
+    auto &&GetMDString = [MN](unsigned Idx) {
+      auto *V = cast<llvm::MDString>(MN->getOperand(Idx));
+      return V->getString();
+    };
+
+    switch (GetMDInt(0)) {
+    default:
+      llvm_unreachable("Unexpected metadata!");
+      break;
+    case llvm::OffloadEntriesInfoManager::OffloadEntryInfo::
+        OffloadingEntryInfoTargetRegion: {
+      assert(isDevice && "Initialization of entries is "
+                                                 "only required for the "
+                                                 "device code generation.");
+      llvm::TargetRegionEntryInfo EntryInfo(/*ParentName=*/GetMDString(3),
+                                            /*DeviceID=*/GetMDInt(1),
+                                            /*FileID=*/GetMDInt(2),
+                                            /*Line=*/GetMDInt(4));
+      OffloadEntriesInfoManager.initializeTargetRegionEntryInfo(
+          EntryInfo, /*Order=*/GetMDInt(5));
+      break;
+    }
+    case llvm::OffloadEntriesInfoManager::OffloadEntryInfo::
+        OffloadingEntryInfoDeviceGlobalVar:
+      assert(isDevice && "Initialization of entries is "
+                                                 "only required for the "
+                                                 "device code generation.");
+      OffloadEntriesInfoManager.initializeDeviceGlobalVarEntryInfo(
+          /*MangledName=*/GetMDString(1),
+          static_cast<
+              llvm::OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind>(
+              /*Flags=*/GetMDInt(2)),
+          /*Order=*/GetMDInt(3));
+      break;
+    }
+  }
+}
+
 bool OffloadEntriesInfoManager::empty() const {
   return OffloadEntriesTargetRegion.empty() &&
          OffloadEntriesDeviceGlobalVar.empty();
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===================================================================
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -2160,6 +2160,12 @@
   void invalidate();
 };
 
+/// Loads all the offload entries information from the host IR
+/// metadata.
+void loadOffloadInfoMetadata(
+    Module &M, llvm::OffloadEntriesInfoManager &OffloadEntriesInfoManager,
+    bool isDevice);
+
 } // end namespace llvm
 
 #endif // LLVM_FRONTEND_OPENMP_OMPIRBUILDER_H
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===================================================================
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -3172,52 +3172,7 @@
     return;
   }
 
-  llvm::NamedMDNode *MD = ME.get()->getNamedMetadata("omp_offload.info");
-  if (!MD)
-    return;
-
-  for (llvm::MDNode *MN : MD->operands()) {
-    auto &&GetMDInt = [MN](unsigned Idx) {
-      auto *V = cast<llvm::ConstantAsMetadata>(MN->getOperand(Idx));
-      return cast<llvm::ConstantInt>(V->getValue())->getZExtValue();
-    };
-
-    auto &&GetMDString = [MN](unsigned Idx) {
-      auto *V = cast<llvm::MDString>(MN->getOperand(Idx));
-      return V->getString();
-    };
-
-    switch (GetMDInt(0)) {
-    default:
-      llvm_unreachable("Unexpected metadata!");
-      break;
-    case llvm::OffloadEntriesInfoManager::OffloadEntryInfo::
-        OffloadingEntryInfoTargetRegion: {
-      assert(CGM.getLangOpts().OpenMPIsDevice && "Initialization of entries is "
-                                                 "only required for the "
-                                                 "device code generation.");
-      llvm::TargetRegionEntryInfo EntryInfo(/*ParentName=*/GetMDString(3),
-                                            /*DeviceID=*/GetMDInt(1),
-                                            /*FileID=*/GetMDInt(2),
-                                            /*Line=*/GetMDInt(4));
-      OffloadEntriesInfoManager.initializeTargetRegionEntryInfo(
-          EntryInfo, /*Order=*/GetMDInt(5));
-      break;
-    }
-    case llvm::OffloadEntriesInfoManager::OffloadEntryInfo::
-        OffloadingEntryInfoDeviceGlobalVar:
-      assert(CGM.getLangOpts().OpenMPIsDevice && "Initialization of entries is "
-                                                 "only required for the "
-                                                 "device code generation.");
-      OffloadEntriesInfoManager.initializeDeviceGlobalVarEntryInfo(
-          /*MangledName=*/GetMDString(1),
-          static_cast<
-              llvm::OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind>(
-              /*Flags=*/GetMDInt(2)),
-          /*Order=*/GetMDInt(3));
-      break;
-    }
-  }
+  llvm::loadOffloadInfoMetadata(*ME.get(), OffloadEntriesInfoManager, CGM.getLangOpts().OpenMPIsDevice);
 }
 
 void CGOpenMPRuntime::emitKmpRoutineEntryT(QualType KmpInt32Ty) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to