[clang] [llvm] [mlir] [clang] Use the VFS to create the OpenMP region entry ID (PR #160918)
Jan Svoboda via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 26 10:40:18 PDT 2025
https://github.com/jansvoboda11 updated https://github.com/llvm/llvm-project/pull/160918
>From d149b833da496cb2749410b1692789c1075819f1 Mon Sep 17 00:00:00 2001
From: Jan Svoboda <jan_svoboda at apple.com>
Date: Thu, 25 Sep 2025 15:57:31 -0700
Subject: [PATCH 1/2] [clang] Use the VFS to create the OpenMP region entry ID
---
clang/lib/CodeGen/CGOpenMPRuntime.cpp | 3 ++-
llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h | 2 +-
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 14 ++++++++------
3 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index c90e1a487daf9..9004296a7e453 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1550,7 +1550,8 @@ static llvm::TargetRegionEntryInfo getEntryInfoFromPresumedLoc(
return std::pair<std::string, uint64_t>(PLoc.getFilename(), PLoc.getLine());
};
- return OMPBuilder.getTargetEntryUniqueInfo(FileInfoCallBack, ParentName);
+ return OMPBuilder.getTargetEntryUniqueInfo(FileInfoCallBack,
+ *CGM.getFileSystem(), ParentName);
}
ConstantAddress CGOpenMPRuntime::getAddrOfDeclareTargetVar(const VarDecl *VD) {
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index f43ef932e965a..bfe1c8090acfe 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1402,7 +1402,7 @@ class OpenMPIRBuilder {
/// any.
LLVM_ABI static TargetRegionEntryInfo
getTargetEntryUniqueInfo(FileIdentifierInfoCallbackTy CallBack,
- StringRef ParentName = "");
+ vfs::FileSystem &VFS, StringRef ParentName = "");
/// Enum class for the RedctionGen CallBack type to be used.
enum class ReductionGenCBKind { Clang, MLIR };
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 9b67465faab0b..8fc1a99e4bc4c 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -10312,17 +10312,19 @@ void OffloadEntriesInfoManager::getTargetRegionEntryFnName(
TargetRegionEntryInfo
OpenMPIRBuilder::getTargetEntryUniqueInfo(FileIdentifierInfoCallbackTy CallBack,
+ vfs::FileSystem &VFS,
StringRef ParentName) {
sys::fs::UniqueID ID(0xdeadf17e, 0);
auto FileIDInfo = CallBack();
uint64_t FileID = 0;
- std::error_code EC = sys::fs::getUniqueID(std::get<0>(FileIDInfo), ID);
- // If the inode ID could not be determined, create a hash value
- // the current file name and use that as an ID.
- if (EC)
+ if (ErrorOr<vfs::Status> Status = VFS.status(std::get<0>(FileIDInfo))) {
+ ID = Status->getUniqueID();
+ FileID = Status->getUniqueID().getFile();
+ } else {
+ // If the inode ID could not be determined, create a hash value
+ // the current file name and use that as an ID.
FileID = hash_value(std::get<0>(FileIDInfo));
- else
- FileID = ID.getFile();
+ }
return TargetRegionEntryInfo(ParentName, ID.getDevice(), FileID,
std::get<1>(FileIDInfo));
>From 94b8dfc0c5077f84ade9ac440c48a8f55d0ea6f1 Mon Sep 17 00:00:00 2001
From: Jan Svoboda <jan_svoboda at apple.com>
Date: Fri, 26 Sep 2025 10:40:03 -0700
Subject: [PATCH 2/2] Fix MLIR build
---
.../Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index 4921a1990b6e8..39d88313f49dd 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -3595,8 +3595,10 @@ getDeclareTargetRefPtrSuffix(LLVM::GlobalOp globalOp,
llvm::StringRef(loc.getFilename()), loc.getLine());
};
+ auto vfs = llvm::vfs::getRealFileSystem();
os << llvm::format(
- "_%x", ompBuilder.getTargetEntryUniqueInfo(fileInfoCallBack).FileID);
+ "_%x",
+ ompBuilder.getTargetEntryUniqueInfo(*vfs, fileInfoCallBack).FileID);
}
os << "_decl_tgt_ref_ptr";
@@ -5888,10 +5890,12 @@ convertDeclareTargetAttr(Operation *op, mlir::omp::DeclareTargetAttr attribute,
lineNo);
};
+ auto vfs = llvm::vfs::getRealFileSystem();
+
ompBuilder->registerTargetGlobalVariable(
captureClause, deviceClause, isDeclaration, isExternallyVisible,
- ompBuilder->getTargetEntryUniqueInfo(fileInfoCallBack), mangledName,
- generatedRefs, /*OpenMPSimd*/ false, targetTriple,
+ ompBuilder->getTargetEntryUniqueInfo(*vfs, fileInfoCallBack),
+ mangledName, generatedRefs, /*OpenMPSimd*/ false, targetTriple,
/*GlobalInitializer*/ nullptr, /*VariableLinkage*/ nullptr,
gVal->getType(), gVal);
@@ -5901,9 +5905,9 @@ convertDeclareTargetAttr(Operation *op, mlir::omp::DeclareTargetAttr attribute,
ompBuilder->Config.hasRequiresUnifiedSharedMemory())) {
ompBuilder->getAddrOfDeclareTargetVar(
captureClause, deviceClause, isDeclaration, isExternallyVisible,
- ompBuilder->getTargetEntryUniqueInfo(fileInfoCallBack), mangledName,
- generatedRefs, /*OpenMPSimd*/ false, targetTriple, gVal->getType(),
- /*GlobalInitializer*/ nullptr,
+ ompBuilder->getTargetEntryUniqueInfo(*vfs, fileInfoCallBack),
+ mangledName, generatedRefs, /*OpenMPSimd*/ false, targetTriple,
+ gVal->getType(), /*GlobalInitializer*/ nullptr,
/*VariableLinkage*/ nullptr);
}
}
More information about the llvm-commits
mailing list