10 #include "llvm/Support/ErrorHandling.h" 14 using namespace clang;
15 using namespace driver;
22 case InputClass:
return "input";
23 case BindArchClass:
return "bind-arch";
26 case PreprocessJobClass:
return "preprocessor";
27 case PrecompileJobClass:
return "precompiler";
28 case HeaderModulePrecompileJobClass:
return "header-module-precompiler";
29 case AnalyzeJobClass:
return "analyzer";
30 case MigrateJobClass:
return "migrator";
31 case CompileJobClass:
return "compiler";
32 case BackendJobClass:
return "backend";
33 case AssembleJobClass:
return "assembler";
34 case LinkJobClass:
return "linker";
35 case LipoJobClass:
return "lipo";
36 case DsymutilJobClass:
return "dsymutil";
37 case VerifyDebugInfoJobClass:
return "verify-debug-info";
38 case VerifyPCHJobClass:
return "verify-pch";
39 case OffloadBundlingJobClass:
40 return "clang-offload-bundler";
41 case OffloadUnbundlingJobClass:
42 return "clang-offload-unbundler";
45 llvm_unreachable(
"invalid class");
50 if (
Kind == OffloadClass)
53 if (
Kind == OffloadUnbundlingJobClass)
56 assert((OffloadingDeviceKind == OKind || OffloadingDeviceKind == OFK_None) &&
57 "Setting device kind to a different device??");
58 assert(!ActiveOffloadKindMask &&
"Setting a device kind in a host action??");
59 OffloadingDeviceKind = OKind;
60 OffloadingArch = OArch;
62 for (
auto *A : Inputs)
63 A->propagateDeviceOffloadInfo(OffloadingDeviceKind, OArch);
68 if (
Kind == OffloadClass)
71 assert(OffloadingDeviceKind == OFK_None &&
72 "Setting a host kind in a device action.");
73 ActiveOffloadKindMask |= OKinds;
74 OffloadingArch = OArch;
76 for (
auto *A : Inputs)
77 A->propagateHostOffloadInfo(ActiveOffloadKindMask, OArch);
89 switch (OffloadingDeviceKind) {
93 llvm_unreachable(
"Host kind is not an offloading device kind.");
98 return "device-openmp";
105 if (!ActiveOffloadKindMask)
108 std::string Res(
"host");
109 assert(!((ActiveOffloadKindMask & OFK_Cuda) &&
110 (ActiveOffloadKindMask & OFK_HIP)) &&
111 "Cannot offload CUDA and HIP at the same time");
112 if (ActiveOffloadKindMask & OFK_Cuda)
114 if (ActiveOffloadKindMask & OFK_HIP)
116 if (ActiveOffloadKindMask & OFK_OpenMP)
128 StringRef NormalizedTriple,
129 bool CreatePrefixForHost) {
131 if (!CreatePrefixForHost && (Kind == OFK_None || Kind == OFK_Host))
134 std::string Res(
"-");
135 Res += GetOffloadKindName(Kind);
137 Res += NormalizedTriple;
158 llvm_unreachable(
"invalid offload kind");
161 void InputAction::anchor() {}
164 :
Action(InputClass, _Type), Input(_Input) {}
166 void BindArchAction::anchor() {}
171 void OffloadAction::anchor() {}
183 DevToolChains(DDeps.getToolChains()) {
188 if (llvm::all_of(OKinds, [&](
OffloadKind K) {
return K == OKinds.front(); }))
192 if (OKinds.size() == 1)
197 getInputs()[
i]->propagateDeviceOffloadInfo(OKinds[
i], BArchs[i]);
203 DevToolChains(DDeps.getToolChains()) {
212 for (
unsigned i = 0, e = DDeps.
getActions().size();
i != e; ++
i)
223 assert(!
getInputs().empty() &&
"No dependencies for offload action??");
225 Work(A, HostTC, A->getOffloadingArch());
238 assert(
getInputs().
size() == DevToolChains.size() + (HostTC ? 1 : 0) &&
239 "Sizes of action dependences and toolchains are not consistent!");
245 auto TI = DevToolChains.begin();
246 for (; I != E; ++I, ++TI)
247 Work(*I, *TI, (*I)->getOffloadingArch());
257 if (IsHostDependence)
267 assert(!
getInputs().empty() &&
"No dependencies for offload action??");
268 return HostTC ?
getInputs().front() :
nullptr;
272 bool DoNotConsiderHostActions)
const {
273 if (DoNotConsiderHostActions)
274 return getInputs().size() == (HostTC ? 2 : 1);
275 return !HostTC &&
getInputs().size() == 1;
281 "Single device dependence does not exist!");
288 const char *BoundArch,
290 DeviceActions.push_back(&A);
291 DeviceToolChains.push_back(&TC);
292 DeviceBoundArchs.push_back(BoundArch);
293 DeviceOffloadKinds.push_back(OKind);
297 const char *BoundArch,
299 : HostAction(A), HostToolChain(TC), HostBoundArch(BoundArch) {
301 HostOffloadKinds |= K;
304 void JobAction::anchor() {}
307 :
Action(Kind, Input, Type) {}
310 :
Action(Kind, Inputs, Type) {}
312 void PreprocessJobAction::anchor() {}
317 void PrecompileJobAction::anchor() {}
325 assert(isa<PrecompileJobAction>((
Action*)
this) &&
"invalid action kind");
328 void HeaderModulePrecompileJobAction::anchor() {}
333 ModuleName(ModuleName) {}
335 void AnalyzeJobAction::anchor() {}
340 void MigrateJobAction::anchor() {}
345 void CompileJobAction::anchor() {}
350 void BackendJobAction::anchor() {}
355 void AssembleJobAction::anchor() {}
360 void LinkJobAction::anchor() {}
365 void LipoJobAction::anchor() {}
370 void DsymutilJobAction::anchor() {}
375 void VerifyJobAction::anchor() {}
381 "ActionClass is not a valid VerifyJobAction");
384 void VerifyDebugInfoJobAction::anchor() {}
390 void VerifyPCHJobAction::anchor() {}
395 void OffloadBundlingJobAction::anchor() {}
400 void OffloadUnbundlingJobAction::anchor() {}
AssembleJobAction(Action *Input, types::ID OutputType)
OffloadAction(const HostDependence &HDep)
BackendJobAction(Action *Input, types::ID OutputType)
const OffloadKindList & getOffloadKinds() const
MigrateJobAction(Action *Input, types::ID OutputType)
The base class of the type hierarchy.
LinkJobAction(ActionList &Inputs, types::ID Type)
Type used to communicate device actions.
const char * getClassName() const
void doOnHostDependence(const OffloadActionWorkTy &Work) const
Execute the work specified in Work on the host dependence.
VerifyJobAction(ActionClass Kind, Action *Input, types::ID Type)
VerifyDebugInfoJobAction(Action *Input, types::ID Type)
CompileJobAction(Action *Input, types::ID OutputType)
JobAction(ActionClass Kind, Action *Input, types::ID Type)
OffloadKind OffloadingDeviceKind
Offloading kind of the device.
void doOnEachDeviceDependence(const OffloadActionWorkTy &Work) const
Execute the work specified in Work on each device dependence.
LipoJobAction(ActionList &Inputs, types::ID Type)
Type used to communicate host actions.
Action - Represent an abstract compilation step to perform.
Action * getHostDependence() const
Return the host dependence of this action.
void propagateOffloadInfo(const Action *A)
Set the offload info of this action to be the same as the provided action, and propagate it to its de...
types::ID getType() const
DsymutilJobAction(ActionList &Inputs, types::ID Type)
PreprocessJobAction(Action *Input, types::ID OutputType)
OffloadKind getOffloadingDeviceKind() const
void doOnEachDependence(const OffloadActionWorkTy &Work) const
Execute the work specified in Work on each dependence.
void propagateDeviceOffloadInfo(OffloadKind OKind, const char *OArch)
Set the device offload info of this action and propagate it to its dependences.
void add(Action &A, const ToolChain &TC, const char *BoundArch, OffloadKind OKind)
Add a action along with the associated toolchain, bound arch, and offload kind.
const char * getBoundArch() const
bool hasHostDependence() const
Return true if the action has a host dependence.
unsigned ActiveOffloadKindMask
Offload information.
VerifyPCHJobAction(Action *Input, types::ID Type)
const BoundArchList & getBoundArchs() const
const ActionList & getActions() const
Get each of the individual arrays.
HostDependence(Action &A, const ToolChain &TC, const char *BoundArch, const unsigned OffloadKinds)
const char * OffloadingArch
The Offloading architecture associated with this action.
BindArchAction(Action *Input, StringRef ArchName)
OffloadUnbundlingJobAction(Action *Input)
AnalyzeJobAction(Action *Input, types::ID OutputType)
OffloadBundlingJobAction(ActionList &Inputs)
unsigned getOffloadingHostActiveKinds() const
Dataflow Directional Tag Classes.
llvm::function_ref< void(Action *, const ToolChain *, const char *)> OffloadActionWorkTy
bool hasSingleDeviceDependence(bool DoNotConsiderHostActions=false) const
Return true if the action has a single device dependence.
Action * getAction() const
static StringRef GetOffloadKindName(OffloadKind Kind)
Return a string containing a offload kind name.
unsigned getOffloadKinds() const
void propagateHostOffloadInfo(unsigned OKinds, const char *OArch)
Append the host offload info of this action and propagate it to its dependences.
static std::string GetOffloadingFileNamePrefix(OffloadKind Kind, StringRef NormalizedTriple, bool CreatePrefixForHost=false)
Return a string that can be used as prefix in order to generate unique files for each offloading kind...
std::string getOffloadingKindPrefix() const
Return a string containing the offload kind of the action.
PrecompileJobAction(ActionClass Kind, Action *Input, types::ID OutputType)
Action * getSingleDeviceDependence(bool DoNotConsiderHostActions=false) const
Return the single device dependence of this action.
const char * getOffloadingArch() const