Skip to content

Commit f42e94d

Browse files
committed
[clang] Use the VFS to create the OpenMP region entry ID (llvm#160918)
This PR uses the VFS to create the OpenMP target entry instead of going straight to the real file system. This matches the behavior of other input files of the compiler.
1 parent 45254b2 commit f42e94d

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,8 @@ static llvm::TargetRegionEntryInfo getEntryInfoFromPresumedLoc(
15471547
return std::pair<std::string, uint64_t>(PLoc.getFilename(), PLoc.getLine());
15481548
};
15491549

1550-
return OMPBuilder.getTargetEntryUniqueInfo(FileInfoCallBack, ParentName);
1550+
return OMPBuilder.getTargetEntryUniqueInfo(FileInfoCallBack,
1551+
*CGM.getFileSystem(), ParentName);
15511552
}
15521553

15531554
ConstantAddress CGOpenMPRuntime::getAddrOfDeclareTargetVar(const VarDecl *VD) {

llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ class OpenMPIRBuilder {
13501350
/// any.
13511351
LLVM_ABI static TargetRegionEntryInfo
13521352
getTargetEntryUniqueInfo(FileIdentifierInfoCallbackTy CallBack,
1353-
StringRef ParentName = "");
1353+
vfs::FileSystem &VFS, StringRef ParentName = "");
13541354

13551355
/// Enum class for the RedctionGen CallBack type to be used.
13561356
enum class ReductionGenCBKind { Clang, MLIR };

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9849,17 +9849,19 @@ void OffloadEntriesInfoManager::getTargetRegionEntryFnName(
98499849

98509850
TargetRegionEntryInfo
98519851
OpenMPIRBuilder::getTargetEntryUniqueInfo(FileIdentifierInfoCallbackTy CallBack,
9852+
vfs::FileSystem &VFS,
98529853
StringRef ParentName) {
98539854
sys::fs::UniqueID ID(0xdeadf17e, 0);
98549855
auto FileIDInfo = CallBack();
98559856
uint64_t FileID = 0;
9856-
std::error_code EC = sys::fs::getUniqueID(std::get<0>(FileIDInfo), ID);
9857-
// If the inode ID could not be determined, create a hash value
9858-
// the current file name and use that as an ID.
9859-
if (EC)
9857+
if (ErrorOr<vfs::Status> Status = VFS.status(std::get<0>(FileIDInfo))) {
9858+
ID = Status->getUniqueID();
9859+
FileID = Status->getUniqueID().getFile();
9860+
} else {
9861+
// If the inode ID could not be determined, create a hash value
9862+
// the current file name and use that as an ID.
98609863
FileID = hash_value(std::get<0>(FileIDInfo));
9861-
else
9862-
FileID = ID.getFile();
9864+
}
98639865

98649866
return TargetRegionEntryInfo(ParentName, ID.getDevice(), FileID,
98659867
std::get<1>(FileIDInfo));

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3534,8 +3534,10 @@ getDeclareTargetRefPtrSuffix(LLVM::GlobalOp globalOp,
35343534
llvm::StringRef(loc.getFilename()), loc.getLine());
35353535
};
35363536

3537+
auto vfs = llvm::vfs::getRealFileSystem();
35373538
os << llvm::format(
3538-
"_%x", ompBuilder.getTargetEntryUniqueInfo(fileInfoCallBack).FileID);
3539+
"_%x",
3540+
ompBuilder.getTargetEntryUniqueInfo(fileInfoCallBack, *vfs).FileID);
35393541
}
35403542
os << "_decl_tgt_ref_ptr";
35413543

@@ -5809,10 +5811,12 @@ convertDeclareTargetAttr(Operation *op, mlir::omp::DeclareTargetAttr attribute,
58095811
lineNo);
58105812
};
58115813

5814+
auto vfs = llvm::vfs::getRealFileSystem();
5815+
58125816
ompBuilder->registerTargetGlobalVariable(
58135817
captureClause, deviceClause, isDeclaration, isExternallyVisible,
5814-
ompBuilder->getTargetEntryUniqueInfo(fileInfoCallBack), mangledName,
5815-
generatedRefs, /*OpenMPSimd*/ false, targetTriple,
5818+
ompBuilder->getTargetEntryUniqueInfo(fileInfoCallBack, *vfs),
5819+
mangledName, generatedRefs, /*OpenMPSimd*/ false, targetTriple,
58165820
/*GlobalInitializer*/ nullptr, /*VariableLinkage*/ nullptr,
58175821
gVal->getType(), gVal);
58185822

@@ -5822,9 +5826,9 @@ convertDeclareTargetAttr(Operation *op, mlir::omp::DeclareTargetAttr attribute,
58225826
ompBuilder->Config.hasRequiresUnifiedSharedMemory())) {
58235827
ompBuilder->getAddrOfDeclareTargetVar(
58245828
captureClause, deviceClause, isDeclaration, isExternallyVisible,
5825-
ompBuilder->getTargetEntryUniqueInfo(fileInfoCallBack), mangledName,
5826-
generatedRefs, /*OpenMPSimd*/ false, targetTriple, gVal->getType(),
5827-
/*GlobalInitializer*/ nullptr,
5829+
ompBuilder->getTargetEntryUniqueInfo(fileInfoCallBack, *vfs),
5830+
mangledName, generatedRefs, /*OpenMPSimd*/ false, targetTriple,
5831+
gVal->getType(), /*GlobalInitializer*/ nullptr,
58285832
/*VariableLinkage*/ nullptr);
58295833
}
58305834
}

0 commit comments

Comments
 (0)