Skip to content

Commit a7d9365

Browse files
authored
[Clang] Rework creating offloading toolchains (#125556)
Summary: This patch reworks how we create offloading toolchains. Previously we would handle this separately for all the different kinds. This patch instead changes this to use the target triple and the offloading kind to determine the proper toolchain. In the old case where the user only passes `--offload-arch` we instead infer the triple from the passed arguments. This is a pretty major overhaul but currently passes all the clang tests with only minor changes to error messages.
1 parent 354944d commit a7d9365

19 files changed

+376
-541
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ def err_drv_cuda_host_arch : Error<
116116
"unsupported architecture '%0' for host compilation">;
117117
def err_drv_mix_cuda_hip : Error<
118118
"mixed CUDA and HIP compilation is not supported">;
119+
def err_drv_mix_offload : Error<
120+
"mixed %0 and %1 offloading compilation is not supported">;
119121
def err_drv_bad_target_id : Error<
120122
"invalid target ID '%0'; format is a processor name followed by an optional "
121123
"colon-delimited list of features followed by an enable/disable sign (e.g., "

clang/include/clang/Driver/Driver.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ class Driver {
355355
phases::ID getFinalPhase(const llvm::opt::DerivedArgList &DAL,
356356
llvm::opt::Arg **FinalPhaseArg = nullptr) const;
357357

358+
llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
359+
executeProgram(llvm::ArrayRef<llvm::StringRef> Args) const;
360+
358361
private:
359362
/// Certain options suppress the 'no input files' warning.
360363
LLVM_PREFERRED_TYPE(bool)
@@ -367,10 +370,6 @@ class Driver {
367370
/// stored in it, and will clean them up when torn down.
368371
mutable llvm::StringMap<std::unique_ptr<ToolChain>> ToolChains;
369372

370-
/// The associated offloading architectures with each toolchain.
371-
llvm::DenseMap<const ToolChain *, llvm::SmallVector<llvm::StringRef>>
372-
OffloadArchs;
373-
374373
private:
375374
/// TranslateInputArgs - Create a new derived argument list from the input
376375
/// arguments, after applying the standard argument translations.
@@ -537,8 +536,7 @@ class Driver {
537536
/// empty string.
538537
llvm::SmallVector<StringRef>
539538
getOffloadArchs(Compilation &C, const llvm::opt::DerivedArgList &Args,
540-
Action::OffloadKind Kind, const ToolChain *TC,
541-
bool SpecificToolchain = true) const;
539+
Action::OffloadKind Kind, const ToolChain &TC) const;
542540

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

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ def offload_arch_EQ : CommaJoined<["--"], "offload-arch=">,
11561156
"If 'native' is used the compiler will detect locally installed architectures. "
11571157
"For HIP offloading, the device architecture can be followed by target ID features "
11581158
"delimited by a colon (e.g. gfx908:xnack+:sramecc-). May be specified more than once.">;
1159-
def no_offload_arch_EQ : Joined<["--"], "no-offload-arch=">,
1159+
def no_offload_arch_EQ : CommaJoined<["--"], "no-offload-arch=">,
11601160
Visibility<[ClangOption, FlangOption]>,
11611161
HelpText<"Remove CUDA/HIP offloading device architecture (e.g. sm_35, gfx906) from the list of devices to compile for. "
11621162
"'all' resets the list to its default value.">;
@@ -1624,7 +1624,7 @@ defm auto_import : BoolFOption<"auto-import",
16241624
// In the future this option will be supported by other offloading
16251625
// languages and accept other values such as CPU/GPU architectures,
16261626
// offload kinds and target aliases.
1627-
def offload_EQ : CommaJoined<["--"], "offload=">, Flags<[NoXarchOption]>,
1627+
def offload_EQ : CommaJoined<["--"], "offload=">, Flags<[NoXarchOption]>, Alias<offload_targets_EQ>,
16281628
HelpText<"Specify comma-separated list of offloading target triples (CUDA and HIP only)">;
16291629

16301630
// C++ Coroutines

clang/include/clang/Driver/ToolChain.h

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

205-
/// Executes the given \p Executable and returns the stdout.
206-
llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
207-
executeToolChainProgram(StringRef Executable) const;
208-
209205
void setTripleEnvironment(llvm::Triple::EnvironmentType Env);
210206

211207
virtual Tool *buildAssembler() const;

0 commit comments

Comments
 (0)