Skip to content

Commit 64ccaf3

Browse files
committed
[clang] Delay checking of -fopenmp-host-ir-file-path (llvm#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. (cherry picked from commit a24e11f)
1 parent fd46f22 commit 64ccaf3

File tree

5 files changed

+10
-16
lines changed

5 files changed

+10
-16
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,6 @@ def err_drv_optimization_remark_format : Error<
367367
def err_drv_no_neon_modifier : Error<"[no]neon is not accepted as modifier, please use [no]simd instead">;
368368
def err_drv_invalid_omp_target : Error<"OpenMP target is invalid: '%0'">;
369369
def err_drv_incompatible_omp_arch : Error<"OpenMP target architecture '%0' pointer size is incompatible with host '%1'">;
370-
def err_drv_omp_host_ir_file_not_found : Error<
371-
"provided host compiler IR file '%0' is required to generate code for OpenMP "
372-
"target regions but cannot be found">;
373370
def err_drv_omp_host_target_not_supported : Error<
374371
"target '%0' is not a supported OpenMP host target">;
375372
def err_drv_ptrauth_not_supported : Error<

clang/include/clang/Basic/DiagnosticFrontendKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ def err_target_unsupported_type_for_abi
327327
: Error<"%0 requires %1 type support, but ABI '%2' does not support it">;
328328
}
329329

330+
def err_omp_host_ir_file_not_found : Error<
331+
"provided host compiler IR file '%0' is required to generate code for OpenMP "
332+
"target regions but cannot be found">;
330333
def err_alias_to_undefined : Error<
331334
"%select{alias|ifunc}0 must point to a defined "
332335
"%select{variable or |}1function">;

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8886,7 +8886,8 @@ def fopenmp_is_target_device : Flag<["-"], "fopenmp-is-target-device">,
88868886
HelpText<"Generate code only for an OpenMP target device.">;
88878887
def : Flag<["-"], "fopenmp-is-device">, Alias<fopenmp_is_target_device>;
88888888
def fopenmp_host_ir_file_path : Separate<["-"], "fopenmp-host-ir-file-path">,
8889-
HelpText<"Path to the IR file produced by the frontend for the host.">;
8889+
HelpText<"Path to the IR file produced by the frontend for the host.">,
8890+
MarshallingInfoString<LangOpts<"OMPHostIRFile">>;
88908891

88918892
} // let Visibility = [CC1Option, FC1Option]
88928893

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,11 @@ void CodeGenModule::createOpenCLRuntime() {
588588
}
589589

590590
void CodeGenModule::createOpenMPRuntime() {
591+
if (!LangOpts.OMPHostIRFile.empty() &&
592+
!llvm::sys::fs::exists(LangOpts.OMPHostIRFile))
593+
Diags.Report(diag::err_omp_host_ir_file_not_found)
594+
<< LangOpts.OMPHostIRFile;
595+
591596
// Select a specialized code generation class based on the target, if any.
592597
// If it does not exist use the default implementation.
593598
switch (getTriple().getArch()) {

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4264,9 +4264,6 @@ void CompilerInvocationBase::GenerateLangArgs(const LangOptions &Opts,
42644264
GenerateArg(Consumer, OPT_offload_targets_EQ, Targets);
42654265
}
42664266

4267-
if (!Opts.OMPHostIRFile.empty())
4268-
GenerateArg(Consumer, OPT_fopenmp_host_ir_file_path, Opts.OMPHostIRFile);
4269-
42704267
if (Opts.OpenMPCUDAMode)
42714268
GenerateArg(Consumer, OPT_fopenmp_cuda_mode);
42724269

@@ -4892,15 +4889,6 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
48924889
}
48934890
}
48944891

4895-
// Get OpenMP host file path if any and report if a non existent file is
4896-
// found
4897-
if (Arg *A = Args.getLastArg(options::OPT_fopenmp_host_ir_file_path)) {
4898-
Opts.OMPHostIRFile = A->getValue();
4899-
if (!llvm::sys::fs::exists(Opts.OMPHostIRFile))
4900-
Diags.Report(diag::err_drv_omp_host_ir_file_not_found)
4901-
<< Opts.OMPHostIRFile;
4902-
}
4903-
49044892
// Set CUDA mode for OpenMP target NVPTX/AMDGCN if specified in options
49054893
Opts.OpenMPCUDAMode = Opts.OpenMPIsTargetDevice &&
49064894
(T.isNVPTX() || T.isAMDGCN()) &&

0 commit comments

Comments
 (0)