Skip to content

Commit 9ad94c1

Browse files
committed
[clang][cli] Port OpenMP-related LangOpts to marshalling system
Port some OpenMP-related language options to the marshalling system for automatic command line parsing and generation. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D95348
1 parent 88b8c1f commit 9ad94c1

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,18 +2145,24 @@ def fopenmp_EQ : Joined<["-"], "fopenmp=">, Group<f_Group>;
21452145
def fopenmp_use_tls : Flag<["-"], "fopenmp-use-tls">, Group<f_Group>,
21462146
Flags<[NoArgumentUnused, HelpHidden]>;
21472147
def fnoopenmp_use_tls : Flag<["-"], "fnoopenmp-use-tls">, Group<f_Group>,
2148-
Flags<[CC1Option, NoArgumentUnused, HelpHidden]>;
2148+
Flags<[CC1Option, NoArgumentUnused, HelpHidden]>,
2149+
MarshallingInfoNegativeFlag<LangOpts<"OpenMPUseTLS">, !strconcat("(bool)", fopenmp.KeyPath)>,
2150+
ShouldParseIf<fopenmp.KeyPath>;
21492151
def fopenmp_targets_EQ : CommaJoined<["-"], "fopenmp-targets=">, Flags<[NoXarchOption, CC1Option]>,
21502152
HelpText<"Specify comma-separated list of triples OpenMP offloading targets to be supported">;
21512153
def fopenmp_relocatable_target : Flag<["-"], "fopenmp-relocatable-target">,
21522154
Group<f_Group>, Flags<[CC1Option, NoArgumentUnused, HelpHidden]>;
21532155
def fnoopenmp_relocatable_target : Flag<["-"], "fnoopenmp-relocatable-target">,
21542156
Group<f_Group>, Flags<[CC1Option, NoArgumentUnused, HelpHidden]>;
2155-
def fopenmp_simd : Flag<["-"], "fopenmp-simd">, Group<f_Group>, Flags<[CC1Option, NoArgumentUnused]>,
2156-
HelpText<"Emit OpenMP code only for SIMD-based constructs.">;
2157+
defm openmp_simd : BoolFOption<"openmp-simd",
2158+
LangOpts<"OpenMPSimd">, DefaultFalse,
2159+
PosFlag<SetTrue, [], "Emit OpenMP code only for SIMD-based constructs.">,
2160+
NegFlag<SetFalse>, BothFlags<[CC1Option, NoArgumentUnused]>>,
2161+
ShouldParseIf<!strconcat("!", fopenmp.KeyPath)>;
21572162
def fopenmp_enable_irbuilder : Flag<["-"], "fopenmp-enable-irbuilder">, Group<f_Group>, Flags<[CC1Option, NoArgumentUnused, HelpHidden]>,
2158-
HelpText<"Use the experimental OpenMP-IR-Builder codegen path.">;
2159-
def fno_openmp_simd : Flag<["-"], "fno-openmp-simd">, Group<f_Group>, Flags<[CC1Option, NoArgumentUnused]>;
2163+
HelpText<"Use the experimental OpenMP-IR-Builder codegen path.">,
2164+
MarshallingInfoFlag<LangOpts<"OpenMPIRBuilder">>,
2165+
ShouldParseIf<fopenmp.KeyPath>;
21602166
def fopenmp_cuda_mode : Flag<["-"], "fopenmp-cuda-mode">, Group<f_Group>,
21612167
Flags<[CC1Option, NoArgumentUnused, HelpHidden]>;
21622168
def fno_openmp_cuda_mode : Flag<["-"], "fno-openmp-cuda-mode">, Group<f_Group>,
@@ -5367,9 +5373,12 @@ def fno_cuda_host_device_constexpr : Flag<["-"], "fno-cuda-host-device-constexpr
53675373
//===----------------------------------------------------------------------===//
53685374

53695375
def fopenmp_is_device : Flag<["-"], "fopenmp-is-device">,
5370-
HelpText<"Generate code only for an OpenMP target device.">;
5376+
HelpText<"Generate code only for an OpenMP target device.">,
5377+
MarshallingInfoFlag<LangOpts<"OpenMPIsDevice">>,
5378+
ShouldParseIf<fopenmp.KeyPath>;
53715379
def fopenmp_host_ir_file_path : Separate<["-"], "fopenmp-host-ir-file-path">,
5372-
HelpText<"Path to the IR file produced by the frontend for the host.">;
5380+
HelpText<"Path to the IR file produced by the frontend for the host.">,
5381+
MarshallingInfoString<LangOpts<"OMPHostIRFile">>;
53735382

53745383
//===----------------------------------------------------------------------===//
53755384
// SYCL Options

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,12 @@ static void FixupInvocation(CompilerInvocation &Invocation,
477477
<< A->getSpelling() << T.getTriple();
478478
}
479479

480+
// Report if OpenMP host file does not exist.
481+
if (!LangOpts.OMPHostIRFile.empty() &&
482+
!llvm::sys::fs::exists(LangOpts.OMPHostIRFile))
483+
Diags.Report(diag::err_drv_omp_host_ir_file_not_found)
484+
<< LangOpts.OMPHostIRFile;
485+
480486
if (!CodeGenOpts.ProfileRemappingFile.empty() && CodeGenOpts.LegacyPassManager)
481487
Diags.Report(diag::err_drv_argument_only_allowed_with)
482488
<< Args.getLastArg(OPT_fprofile_remapping_file_EQ)->getAsString(Args)
@@ -2382,13 +2388,6 @@ void CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
23822388
bool IsSimdSpecified =
23832389
Args.hasFlag(options::OPT_fopenmp_simd, options::OPT_fno_openmp_simd,
23842390
/*Default=*/false);
2385-
Opts.OpenMPSimd = !Opts.OpenMP && IsSimdSpecified;
2386-
Opts.OpenMPUseTLS =
2387-
Opts.OpenMP && !Args.hasArg(options::OPT_fnoopenmp_use_tls);
2388-
Opts.OpenMPIsDevice =
2389-
Opts.OpenMP && Args.hasArg(options::OPT_fopenmp_is_device);
2390-
Opts.OpenMPIRBuilder =
2391-
Opts.OpenMP && Args.hasArg(options::OPT_fopenmp_enable_irbuilder);
23922391
bool IsTargetSpecified =
23932392
Opts.OpenMPIsDevice || Args.hasArg(options::OPT_fopenmp_targets_EQ);
23942393

@@ -2462,15 +2461,6 @@ void CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
24622461
}
24632462
}
24642463

2465-
// Get OpenMP host file path if any and report if a non existent file is
2466-
// found
2467-
if (Arg *A = Args.getLastArg(options::OPT_fopenmp_host_ir_file_path)) {
2468-
Opts.OMPHostIRFile = A->getValue();
2469-
if (!llvm::sys::fs::exists(Opts.OMPHostIRFile))
2470-
Diags.Report(diag::err_drv_omp_host_ir_file_not_found)
2471-
<< Opts.OMPHostIRFile;
2472-
}
2473-
24742464
// Set CUDA mode for OpenMP target NVPTX/AMDGCN if specified in options
24752465
Opts.OpenMPCUDAMode = Opts.OpenMPIsDevice && (T.isNVPTX() || T.isAMDGCN()) &&
24762466
Args.hasArg(options::OPT_fopenmp_cuda_mode);

0 commit comments

Comments
 (0)