Author: Jan Svoboda
Date: 2025-09-02T13:04:13-07:00
New Revision: a24e11fd951d3396ccbb469b2c5dc707dc4196a6
URL: https://github.com/llvm/llvm-project/commit/a24e11fd951d3396ccbb469b2c5dc707dc4196a6
DIFF: https://github.com/llvm/llvm-project/commit/a24e11fd951d3396ccbb469b2c5dc707dc4196a6.diff
LOG: [clang] Delay checking of `-fopenmp-host-ir-file-path` (#150124)
This PR is part of an effort to remove file system usage from the
command line parsing code. The reason for that is that it's impossible
to do file system access correctly without a configured VFS, and the VFS
can only be configured after the command line is parsed. I don't want to
intertwine command line parsing and VFS configuration, so I decided to
perform the file system access after the command line is parsed and the
VFS is configured - ideally right before the file system entity is used
for the first time.
This patch delays opening the OpenMP host IR file until codegen.
Added:
Modified:
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Frontend/CompilerInvocation.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index b8c7c6e8d6909..561637f3f957b 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -361,9 +361,6 @@ def err_drv_optimization_remark_format : Error<
def err_drv_no_neon_modifier : Error<"[no]neon is not accepted as modifier, please use [no]simd instead">;
def err_drv_invalid_omp_target : Error<"OpenMP target is invalid: '%0'">;
def err_drv_incompatible_omp_arch : Error<"OpenMP target architecture '%0' pointer size is incompatible with host '%1'">;
-def err_drv_omp_host_ir_file_not_found : Error<
- "provided host compiler IR file '%0' is required to generate code for OpenMP "
- "target regions but cannot be found">;
def err_drv_omp_host_target_not_supported : Error<
"target '%0' is not a supported OpenMP host target">;
def err_drv_expecting_fopenmp_with_fopenmp_targets : Error<
diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index b7e27d8f94c6e..15447558cf952 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -312,6 +312,9 @@ def err_target_unsupported_type_for_abi
: Error<"%0 requires %1 type support, but ABI '%2' does not support it">;
}
+def err_omp_host_ir_file_not_found : Error<
+ "provided host compiler IR file '%0' is required to generate code for OpenMP "
+ "target regions but cannot be found">;
def err_alias_to_undefined : Error<
"%select{alias|ifunc}0 must point to a defined "
"%select{variable or |}1function">;
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 902a28d60b349..49e917a6a0786 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8719,7 +8719,8 @@ def fopenmp_is_target_device : Flag<["-"], "fopenmp-is-target-device">,
HelpText<"Generate code only for an OpenMP target device.">;
def : Flag<["-"], "fopenmp-is-device">, Alias<fopenmp_is_target_device>;
def fopenmp_host_ir_file_path : Separate<["-"], "fopenmp-host-ir-file-path">,
- HelpText<"Path to the IR file produced by the frontend for the host.">;
+ HelpText<"Path to the IR file produced by the frontend for the host.">,
+ MarshallingInfoString<LangOpts<"OMPHostIRFile">>;
} // let Visibility = [CC1Option, FC1Option]
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 323823c964a79..f1ddaa875f3e4 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -582,6 +582,11 @@ void CodeGenModule::createOpenCLRuntime() {
}
void CodeGenModule::createOpenMPRuntime() {
+ if (!LangOpts.OMPHostIRFile.empty() &&
+ !llvm::sys::fs::exists(LangOpts.OMPHostIRFile))
+ Diags.Report(diag::err_omp_host_ir_file_not_found)
+ << LangOpts.OMPHostIRFile;
+
// Select a specialized code generation class based on the target, if any.
// If it does not exist use the default implementation.
switch (getTriple().getArch()) {
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index f8fecbaf40267..8411d00cc7812 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3919,9 +3919,6 @@ void CompilerInvocationBase::GenerateLangArgs(const LangOptions &Opts,
GenerateArg(Consumer, OPT_offload_targets_EQ, Targets);
}
- if (!Opts.OMPHostIRFile.empty())
- GenerateArg(Consumer, OPT_fopenmp_host_ir_file_path, Opts.OMPHostIRFile);
-
if (Opts.OpenMPCUDAMode)
GenerateArg(Consumer, OPT_fopenmp_cuda_mode);
@@ -4388,15 +4385,6 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
}
}
- // Get OpenMP host file path if any and report if a non existent file is
- // found
- if (Arg *A = Args.getLastArg(options::OPT_fopenmp_host_ir_file_path)) {
- Opts.OMPHostIRFile = A->getValue();
- if (!llvm::sys::fs::exists(Opts.OMPHostIRFile))
- Diags.Report(diag::err_drv_omp_host_ir_file_not_found)
- << Opts.OMPHostIRFile;
- }
-
// Set CUDA mode for OpenMP target NVPTX/AMDGCN if specified in options
Opts.OpenMPCUDAMode = Opts.OpenMPIsTargetDevice &&
(T.isNVPTX() || T.isAMDGCN()) &&