Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clang/lib/CodeGen/CGOpenMPRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
33 changes: 33 additions & 0 deletions clang/test/OpenMP/host-ir-file-vfs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// This test checks that the OpenMP host IR file goes through VFS overlays.
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// 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
7 changes: 6 additions & 1 deletion llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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: " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/ReplaceConstant.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/TargetParser/Triple.h"
#include "llvm/Transforms/Utils/ModuleUtils.h"

Expand Down Expand Up @@ -6300,7 +6301,9 @@ LogicalResult OpenMPDialectLLVMIRTranslationInterface::amendOperation(
if (auto filepathAttr = dyn_cast<StringAttr>(attr)) {
llvm::OpenMPIRBuilder *ompBuilder =
moduleTranslation.getOpenMPBuilder();
ompBuilder->loadOffloadInfoMetadata(filepathAttr.getValue());
auto VFS = llvm::vfs::getRealFileSystem();
ompBuilder->loadOffloadInfoMetadata(*VFS,
filepathAttr.getValue());
return success();
}
return failure();
Expand Down