[CUDA] Fixes minor cuda-related issues in the driver
* Only the last of the --cuda-host-only/--cuda-device-only options has effect.
* CudaHostAction always wraps host-side compilation now.
* Fixed printing of empty action lists.
Differential Revision: http://reviews.llvm.org/D12892
llvm-svn: 248297
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 2f58c42..ebf8b7d 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -920,12 +920,15 @@
} else
AL = &A->getInputs();
- const char *Prefix = "{";
- for (Action *PreRequisite : *AL) {
- os << Prefix << PrintActions1(C, PreRequisite, Ids);
- Prefix = ", ";
- }
- os << "}";
+ if (AL->size()) {
+ const char *Prefix = "{";
+ for (Action *PreRequisite : *AL) {
+ os << Prefix << PrintActions1(C, PreRequisite, Ids);
+ Prefix = ", ";
+ }
+ os << "}";
+ } else
+ os << "{}";
}
unsigned Id = Ids.size();
@@ -1243,6 +1246,13 @@
buildCudaActions(const Driver &D, const ToolChain &TC, DerivedArgList &Args,
const Arg *InputArg, std::unique_ptr<Action> HostAction,
ActionList &Actions) {
+ Arg *PartialCompilationArg = Args.getLastArg(options::OPT_cuda_host_only,
+ options::OPT_cuda_device_only);
+ // Host-only compilation case.
+ if (PartialCompilationArg &&
+ PartialCompilationArg->getOption().matches(options::OPT_cuda_host_only))
+ return std::unique_ptr<Action>(
+ new CudaHostAction(std::move(HostAction), {}));
// Collect all cuda_gpu_arch parameters, removing duplicates.
SmallVector<const char *, 4> GpuArchList;
@@ -1288,7 +1298,7 @@
// Figure out what to do with device actions -- pass them as inputs to the
// host action or run each of them independently.
- bool DeviceOnlyCompilation = Args.hasArg(options::OPT_cuda_device_only);
+ bool DeviceOnlyCompilation = PartialCompilationArg != nullptr;
if (PartialCompilation || DeviceOnlyCompilation) {
// In case of partial or device-only compilation results of device actions
// are not consumed by the host action device actions have to be added to
@@ -1421,11 +1431,8 @@
continue;
}
- phases::ID CudaInjectionPhase;
- bool InjectCuda = (InputType == types::TY_CUDA &&
- !Args.hasArg(options::OPT_cuda_host_only));
- CudaInjectionPhase = FinalPhase;
- for (auto &Phase : PL)
+ phases::ID CudaInjectionPhase = FinalPhase;
+ for (const auto &Phase : PL)
if (Phase <= FinalPhase && Phase == phases::Compile) {
CudaInjectionPhase = Phase;
break;
@@ -1457,7 +1464,7 @@
// Otherwise construct the appropriate action.
Current = ConstructPhaseAction(TC, Args, Phase, std::move(Current));
- if (InjectCuda && Phase == CudaInjectionPhase) {
+ if (InputType == types::TY_CUDA && Phase == CudaInjectionPhase) {
Current = buildCudaActions(*this, TC, Args, InputArg,
std::move(Current), Actions);
if (!Current)