[llvm] a3463a9 - [OpenMP][OpenMPIRBuilder] Migrate loadOffloadInfoMetadata from clang to OMPIRbuilder
Akash Banerjee via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 2 11:56:32 PDT 2022
Author: Akash Banerjee
Date: 2022-11-02T18:54:25Z
New Revision: a3463a9f5cb0880357fd3e4c47ed4c2b09f0e6fc
URL: https://github.com/llvm/llvm-project/commit/a3463a9f5cb0880357fd3e4c47ed4c2b09f0e6fc
DIFF: https://github.com/llvm/llvm-project/commit/a3463a9f5cb0880357fd3e4c47ed4c2b09f0e6fc.diff
LOG: [OpenMP][OpenMPIRBuilder] Migrate loadOffloadInfoMetadata from clang to OMPIRbuilder
This patch moves the implementation of the loadOffloadInfoMetadata to the OMPIRbuilder.
Differential Revision: https://reviews.llvm.org/D136872
Added:
Modified:
clang/lib/CodeGen/CGOpenMPRuntime.cpp
llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 122006f667ed2..9a2fc93ce40c6 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -3171,52 +3171,7 @@ void CGOpenMPRuntime::loadOffloadInfoMetadata() {
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;
- }
- }
+ OMPBuilder.loadOffloadInfoMetadata(*ME.get(), OffloadEntriesInfoManager);
}
void CGOpenMPRuntime::emitKmpRoutineEntryT(QualType KmpInt32Ty) {
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index 8ba71d55584a2..3f9fa6d3c8147 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1681,6 +1681,19 @@ class OpenMPIRBuilder {
BasicBlock *PreInsertBefore,
BasicBlock *PostInsertBefore,
const Twine &Name = {});
+ /// OMP Offload Info Metadata name string
+ const std::string ompOffloadInfoName = "omp_offload.info";
+
+ /// Loads all the offload entries information from the host IR
+ /// metadata. This function is only meant to be used with device code
+ /// generation.
+ ///
+ /// \param M Module to load Metadata info from. Module passed maybe
+ /// loaded from bitcode file, i.e,
diff erent from OpenMPIRBuilder::M module.
+ /// \param OffloadEntriesInfoManager Initialize Offload Entry information.
+ void
+ loadOffloadInfoMetadata(Module &M,
+ OffloadEntriesInfoManager &OffloadEntriesInfoManager);
};
/// Data structure to contain the information needed to uniquely identify
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 6a3700e3adb70..5052ddc5dde88 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4705,6 +4705,54 @@ void TargetRegionEntryInfo::getTargetRegionEntryFnName(
getTargetRegionEntryFnName(Name, ParentName, DeviceID, FileID, Line);
}
+/// Loads all the offload entries information from the host IR
+/// metadata.
+void OpenMPIRBuilder::loadOffloadInfoMetadata(
+ Module &M, OffloadEntriesInfoManager &OffloadEntriesInfoManager) {
+ // If we are in target mode, load the metadata from the host IR. This code has
+ // to match the metadata creation in createOffloadEntriesAndInfoMetadata().
+
+ NamedMDNode *MD = M.getNamedMetadata(ompOffloadInfoName);
+ if (!MD)
+ return;
+
+ for (MDNode *MN : MD->operands()) {
+ auto &&GetMDInt = [MN](unsigned Idx) {
+ auto *V = cast<ConstantAsMetadata>(MN->getOperand(Idx));
+ return cast<ConstantInt>(V->getValue())->getZExtValue();
+ };
+
+ auto &&GetMDString = [MN](unsigned Idx) {
+ auto *V = cast<MDString>(MN->getOperand(Idx));
+ return V->getString();
+ };
+
+ switch (GetMDInt(0)) {
+ default:
+ llvm_unreachable("Unexpected metadata!");
+ break;
+ case OffloadEntriesInfoManager::OffloadEntryInfo::
+ OffloadingEntryInfoTargetRegion: {
+ TargetRegionEntryInfo EntryInfo(/*ParentName=*/GetMDString(3),
+ /*DeviceID=*/GetMDInt(1),
+ /*FileID=*/GetMDInt(2),
+ /*Line=*/GetMDInt(4));
+ OffloadEntriesInfoManager.initializeTargetRegionEntryInfo(
+ EntryInfo, /*Order=*/GetMDInt(5));
+ break;
+ }
+ case OffloadEntriesInfoManager::OffloadEntryInfo::
+ OffloadingEntryInfoDeviceGlobalVar:
+ OffloadEntriesInfoManager.initializeDeviceGlobalVarEntryInfo(
+ /*MangledName=*/GetMDString(1),
+ static_cast<OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind>(
+ /*Flags=*/GetMDInt(2)),
+ /*Order=*/GetMDInt(3));
+ break;
+ }
+ }
+}
+
bool OffloadEntriesInfoManager::empty() const {
return OffloadEntriesTargetRegion.empty() &&
OffloadEntriesDeviceGlobalVar.empty();
More information about the llvm-commits
mailing list