Skip to content

Commit c5ff147

Browse files
Refactor SYCL compilation with #125556 changes from LLVM community (#19709)
This patch reworks the creation of SYCL offloading toolchains, now basing it on the Offloading Kind and the target triple string, passed via either `--offload-targets` or `--offload-arch`. The following PRs/patches from LLVM community have been included in this patch: llvm/llvm-project#125556 llvm/llvm-project@08ac781 llvm/llvm-project@dc87a14 llvm/llvm-project@efffa42 d65cc97 llvm/llvm-project@34447ef intel-restricted/applications.compilers.llvm-project#30861 llvm/llvm-project@4f58c82 llvm/llvm-project@56ba118
1 parent a235ab1 commit c5ff147

31 files changed

+651
-895
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ def warn_flag_no_sycl_libspirv
130130
InGroup<UnsafeLibspirvNotLinked>;
131131
def err_drv_mix_cuda_hip : Error<
132132
"mixed CUDA and HIP compilation is not supported">;
133+
def err_drv_mix_offload
134+
: Error<"mixed %0 and %1 offloading compilation is not supported">;
133135
def err_drv_bad_target_id : Error<
134136
"invalid target ID '%0'; format is a processor name followed by an optional "
135137
"colon-delimited list of features followed by an enable/disable sign (e.g., "
@@ -415,9 +417,11 @@ def err_drv_sycl_offload_arch_new_driver: Error<
415417
"'--offload-arch' is supported when '-fsycl' is set with '--offload-new-driver'">;
416418
def err_drv_sycl_offload_arch_missing_value : Error<
417419
"must pass in an explicit cpu or gpu architecture to '--offload-arch'">;
418-
def warn_drv_sycl_offload_target_duplicate : Warning<
419-
"SYCL offloading target '%0' is similar to target '%1' already specified; "
420-
"will be ignored">, InGroup<SyclTarget>;
420+
def warn_drv_offload_target_duplicate
421+
: Warning<
422+
"offloading target '%0' is similar to target '%1' already specified; "
423+
"will be ignored">,
424+
InGroup<OffloadTarget>;
421425
def warn_drv_sycl_target_missing : Warning<
422426
"linked binaries do not contain expected '%0' target; found targets: '%1'">,
423427
InGroup<SyclTarget>;
@@ -445,11 +449,8 @@ def err_drv_omp_offload_target_missingbcruntime : Error<
445449
"; use '--libomptarget-%1-bc-path' to specify %1 bitcode library">;
446450
def err_drv_omp_offload_target_bcruntime_not_found : Error<
447451
"bitcode library '%0' does not exist">;
448-
def err_drv_omp_offload_target_cuda_version_not_support : Error<
449-
"NVPTX target requires CUDA 9.2 or above; CUDA %0 detected">;
450-
def warn_drv_omp_offload_target_duplicate : Warning<
451-
"OpenMP offloading target '%0' is similar to target '%1' already specified; "
452-
"will be ignored">, InGroup<OpenMPTarget>;
452+
def err_drv_omp_offload_target_cuda_version_not_support
453+
: Error<"NVPTX target requires CUDA 9.2 or above; CUDA %0 detected">;
453454
def err_drv_unsupported_embed_bitcode
454455
: Error<"%0 is not supported with -fembed-bitcode">;
455456
def err_drv_bitcode_unsupported_on_toolchain : Error<

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,9 @@ def SyclAspectMismatch : DiagGroup<"sycl-aspect-mismatch">;
15601560
def SyclNativeCPUTargets: DiagGroup<"sycl-native-cpu-targets">;
15611561
def SyclPrivateAllocaPositiveSize : DiagGroup<"sycl-private-alloca-positive-size">;
15621562

1563+
// Common warnings for SYCL and OpenMP offloading
1564+
def OffloadTarget : DiagGroup<"offload-target">;
1565+
15631566
// OpenACC warnings.
15641567
def SourceUsesOpenACC : DiagGroup<"source-uses-openacc">;
15651568
def OpenACC : DiagGroup<"openacc", [SourceUsesOpenACC]>;

clang/include/clang/Driver/Driver.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ class Driver {
360360
// handleArguments.
361361
phases::ID getFinalPhase(const llvm::opt::DerivedArgList &DAL,
362362
llvm::opt::Arg **FinalPhaseArg = nullptr) const;
363+
llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
364+
executeProgram(llvm::ArrayRef<llvm::StringRef> Args) const;
363365

364366
private:
365367
/// Certain options suppress the 'no input files' warning.
@@ -549,8 +551,7 @@ class Driver {
549551
/// empty string.
550552
llvm::SmallVector<StringRef>
551553
getOffloadArchs(Compilation &C, const llvm::opt::DerivedArgList &Args,
552-
Action::OffloadKind Kind, const ToolChain *TC,
553-
bool SpecificToolchain = true) const;
554+
Action::OffloadKind Kind, const ToolChain &TC) const;
554555

555556
/// Check that the file referenced by Value exists. If it doesn't,
556557
/// issue a diagnostic and return false.

clang/include/clang/Driver/Options.td

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,10 +1236,12 @@ def offload_arch_EQ : CommaJoined<["--"], "offload-arch=">,
12361236
"If 'native' is used the compiler will detect locally installed architectures. "
12371237
"For HIP offloading, the device architecture can be followed by target ID features "
12381238
"delimited by a colon (e.g. gfx908:xnack+:sramecc-). May be specified more than once.">;
1239-
def no_offload_arch_EQ : Joined<["--"], "no-offload-arch=">,
1240-
Visibility<[ClangOption, FlangOption]>,
1241-
HelpText<"Remove CUDA/HIP offloading device architecture (e.g. sm_35, gfx906) from the list of devices to compile for. "
1242-
"'all' resets the list to its default value.">;
1239+
def no_offload_arch_EQ
1240+
: CommaJoined<["--"], "no-offload-arch=">,
1241+
Visibility<[ClangOption, FlangOption]>,
1242+
HelpText<"Remove CUDA/HIP offloading device architecture (e.g. sm_35, "
1243+
"gfx906) from the list of devices to compile for. "
1244+
"'all' resets the list to its default value.">;
12431245

12441246
def offload_new_driver : Flag<["--"], "offload-new-driver">,
12451247
Visibility<[ClangOption, CC1Option]>, Group<f_Group>,
@@ -1732,8 +1734,11 @@ defm auto_import : BoolFOption<"auto-import",
17321734
// In the future this option will be supported by other offloading
17331735
// languages and accept other values such as CPU/GPU architectures,
17341736
// offload kinds and target aliases.
1735-
def offload_EQ : CommaJoined<["--"], "offload=">, Flags<[NoXarchOption]>,
1736-
HelpText<"Specify comma-separated list of offloading target triples (CUDA and HIP only)">;
1737+
def offload_EQ : CommaJoined<["--"], "offload=">,
1738+
Flags<[NoXarchOption]>,
1739+
Alias<offload_targets_EQ>,
1740+
HelpText<"Specify comma-separated list of offloading target "
1741+
"triples (CUDA and HIP only)">;
17371742

17381743
// C++ Coroutines
17391744
defm coroutines : BoolFOption<"coroutines",
@@ -7274,10 +7279,14 @@ defm sycl_rtc_mode: BoolFOption<"sycl-rtc-mode",
72747279
def fno_sycl_esimd_build_host_code : Flag<["-"], "fno-sycl-esimd-build-host-code">,
72757280
Visibility<[ClangOption, CLOption, CC1Option]>, Flags<[HelpHidden]>,
72767281
HelpText<"Do not build the host implementation of ESIMD functions.">;
7277-
def fsycl_targets_EQ : CommaJoined<["-"], "fsycl-targets=">,
7278-
Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, CC1Option]>,
7279-
HelpText<"Specify comma-separated list of triples SYCL offloading targets "
7280-
"to be supported">;
7282+
def fsycl_targets_EQ
7283+
: CommaJoined<["-"], "fsycl-targets=">,
7284+
Alias<offload_targets_EQ>,
7285+
Flags<[NoXarchOption]>,
7286+
Visibility<[ClangOption, CLOption, CC1Option]>,
7287+
HelpText<
7288+
"Specify comma-separated list of triples SYCL offloading targets "
7289+
"to be supported">;
72817290
def fsycl_force_target_EQ : Joined<["-"], "fsycl-force-target=">,
72827291
Flags<[NoXarchOption]>,
72837292
HelpText<"Force the usage of the given triple when extracting device code "

clang/include/clang/Driver/ToolChain.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,6 @@ class ToolChain {
218218
ToolChain(const Driver &D, const llvm::Triple &T,
219219
const llvm::opt::ArgList &Args);
220220

221-
/// Executes the given \p Executable and returns the stdout.
222-
llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
223-
executeToolChainProgram(StringRef Executable) const;
224-
225221
void setTripleEnvironment(llvm::Triple::EnvironmentType Env);
226222

227223
virtual Tool *buildAssembler() const;

0 commit comments

Comments
 (0)