-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[clang] Use VFS for -fopenmp-host-ir-file-path
#156727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[clang] Use VFS for -fopenmp-host-ir-file-path
#156727
Conversation
@llvm/pr-subscribers-mlir-openmp @llvm/pr-subscribers-clang-codegen Author: Jan Svoboda (jansvoboda11) ChangesThis is a follow-up to #150124. This PR makes it so that the Full diff: https://github.com/llvm/llvm-project/pull/156727.diff 5 Files Affected:
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index b38eb54036e60..68ecf6ae347c3 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1038,7 +1038,8 @@ CGOpenMPRuntime::CGOpenMPRuntime(CodeGenModule &CGM)
/*HasRequiresReverseOffload*/ false, /*HasRequiresUnifiedAddress*/ false,
hasRequiresUnifiedSharedMemory(), /*HasRequiresDynamicAllocators*/ false);
OMPBuilder.initialize();
- OMPBuilder.loadOffloadInfoMetadata(CGM.getLangOpts().OpenMPIsTargetDevice
+ OMPBuilder.loadOffloadInfoMetadata(*CGM.getFileSystem(),
+ CGM.getLangOpts().OpenMPIsTargetDevice
? CGM.getLangOpts().OMPHostIRFile
: StringRef{});
OMPBuilder.setConfig(Config);
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index f1ddaa875f3e4..89fc9baa73d98 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -582,8 +582,7 @@ void CodeGenModule::createOpenCLRuntime() {
}
void CodeGenModule::createOpenMPRuntime() {
- if (!LangOpts.OMPHostIRFile.empty() &&
- !llvm::sys::fs::exists(LangOpts.OMPHostIRFile))
+ if (!LangOpts.OMPHostIRFile.empty() && !FS->exists(LangOpts.OMPHostIRFile))
Diags.Report(diag::err_omp_host_ir_file_not_found)
<< LangOpts.OMPHostIRFile;
diff --git a/clang/test/OpenMP/host-ir-file-vfs.c b/clang/test/OpenMP/host-ir-file-vfs.c
new file mode 100644
index 0000000000000..394d8fbcc94ac
--- /dev/null
+++ b/clang/test/OpenMP/host-ir-file-vfs.c
@@ -0,0 +1,33 @@
+// This test checks that the OpenMP host IR file goes through VFS overlays.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: sed -e "s|DIR|%/t|g" %t/vfs.json.in > %t/vfs.json
+// RUN: %clang_cc1 -fopenmp-simd -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm-bc %t/host.c -o %t/host.bc
+
+// RUN: %clang_cc1 -fopenmp-simd -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %t/device.c -o - \
+// RUN: -fopenmp-is-target-device -fopenmp-host-ir-file-path %t/virtual/host.bc -ivfsoverlay %t/vfs.json -verify
+
+//--- vfs.json.in
+{
+ 'version': 0,
+ 'use-external-names': true,
+ 'roots': [
+ {
+ 'name': 'DIR/virtual',
+ 'type': 'directory',
+ 'contents': [
+ {
+ 'name': 'host.bc',
+ 'type': 'file',
+ 'external-contents': 'DIR/host.bc'
+ }
+ ]
+ }
+ ]
+}
+
+//--- host.c
+//--- device.c
+// expected-no-diagnostics
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index 1050e3d8b08dd..cc1177ba3d11c 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -39,6 +39,10 @@ class Loop;
class LoopAnalysis;
class LoopInfo;
+namespace vfs {
+class FileSystem;
+} // namespace vfs
+
/// Move the instruction after an InsertPoint to the beginning of another
/// BasicBlock.
///
@@ -3629,7 +3633,8 @@ class OpenMPIRBuilder {
/// \param HostFilePath The path to the host IR file,
/// used to load in offload metadata for the device, allowing host and device
/// to maintain the same metadata mapping.
- LLVM_ABI void loadOffloadInfoMetadata(StringRef HostFilePath);
+ LLVM_ABI void loadOffloadInfoMetadata(vfs::FileSystem &VFS,
+ StringRef HostFilePath);
/// Gets (if variable with the given name already exist) or creates
/// internal global variable with the specified Name. The created variable has
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 03ea58318d4a9..f2ba0f65fd464 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -50,6 +50,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
@@ -10523,11 +10524,12 @@ void OpenMPIRBuilder::loadOffloadInfoMetadata(Module &M) {
}
}
-void OpenMPIRBuilder::loadOffloadInfoMetadata(StringRef HostFilePath) {
+void OpenMPIRBuilder::loadOffloadInfoMetadata(vfs::FileSystem &VFS,
+ StringRef HostFilePath) {
if (HostFilePath.empty())
return;
- auto Buf = MemoryBuffer::getFile(HostFilePath);
+ auto Buf = VFS.getBufferForFile(HostFilePath);
if (std::error_code Err = Buf.getError()) {
report_fatal_error(("error opening host file from host file path inside of "
"OpenMPIRBuilder: " +
|
@@ -0,0 +1,33 @@ | |||
// This test checks that the OpenMP host IR file goes through VFS overlays. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This it should be executed on linux only. Can we try to avoid using rm, sed, etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why should this test be executed on Linux only? The Clang arguments were taken from clang/test/OpenMP/simd_codegen.cpp
that doesn't have any REQUIRES
lines, so I don't think this is testing something specific to the host platform. If the reason is the rm
and sed
commands you mention, I believe those are guaranteed to be available on all platforms where we support running tests - for example on Windows, we require Git bash tools to be installed.
This is a follow-up to #150124. This PR makes it so that the
-fopenmp-host-ir-file-path
respects VFS overlays, like any other input file.