Skip to content

Commit 543c6f6

Browse files
committed
[Clang] Introduce '--offload-targets=' to genericall target toolchains
Summary: This is a new option that tries to make selecting offloading toolchains more generic. Currently we infer the toolchain from a combination of the kind and the `--offload-arch=` option. Doing this becomes complicated when we want to start supporting multiple targets for a single toolchain, i.e. HIP on SPIR-V or AMDGCN. Currently we hack in a special 'architecture' instead, which isn't extensible. Additionally in the future we may accept compiling CUDA or HIP to some other architecture.
1 parent 02d3738 commit 543c6f6

19 files changed

+367
-527
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: 5 additions & 2 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,6 +370,7 @@ class Driver {
367370
/// stored in it, and will clean them up when torn down.
368371
mutable llvm::StringMap<std::unique_ptr<ToolChain>> ToolChains;
369372

373+
public:
370374
/// The associated offloading architectures with each toolchain.
371375
llvm::DenseMap<const ToolChain *, llvm::SmallVector<llvm::StringRef>>
372376
OffloadArchs;
@@ -537,8 +541,7 @@ class Driver {
537541
/// empty string.
538542
llvm::SmallVector<StringRef>
539543
getOffloadArchs(Compilation &C, const llvm::opt::DerivedArgList &Args,
540-
Action::OffloadKind Kind, const ToolChain *TC,
541-
bool SpecificToolchain = true) const;
544+
Action::OffloadKind Kind, const ToolChain &TC) const;
542545

543546
/// Check that the file referenced by Value exists. If it doesn't,
544547
/// 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.">;
@@ -1637,7 +1637,7 @@ defm auto_import : BoolFOption<"auto-import",
16371637
// In the future this option will be supported by other offloading
16381638
// languages and accept other values such as CPU/GPU architectures,
16391639
// offload kinds and target aliases.
1640-
def offload_EQ : CommaJoined<["--"], "offload=">, Flags<[NoXarchOption]>,
1640+
def offload_EQ : CommaJoined<["--"], "offload=">, Flags<[NoXarchOption]>, Alias<offload_targets_EQ>,
16411641
HelpText<"Specify comma-separated list of offloading target triples (CUDA and HIP only)">;
16421642

16431643
// 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)