11 #include "llvm/Support/ErrorHandling.h" 15 using namespace clang;
16 using namespace driver;
23 case InputClass:
return "input";
24 case BindArchClass:
return "bind-arch";
27 case PreprocessJobClass:
return "preprocessor";
28 case PrecompileJobClass:
return "precompiler";
29 case HeaderModulePrecompileJobClass:
return "header-module-precompiler";
30 case AnalyzeJobClass:
return "analyzer";
31 case MigrateJobClass:
return "migrator";
32 case CompileJobClass:
return "compiler";
33 case BackendJobClass:
return "backend";
34 case AssembleJobClass:
return "assembler";
35 case LinkJobClass:
return "linker";
36 case LipoJobClass:
return "lipo";
37 case DsymutilJobClass:
return "dsymutil";
38 case VerifyDebugInfoJobClass:
return "verify-debug-info";
39 case VerifyPCHJobClass:
return "verify-pch";
40 case OffloadBundlingJobClass:
41 return "clang-offload-bundler";
42 case OffloadUnbundlingJobClass:
43 return "clang-offload-unbundler";
46 llvm_unreachable(
"invalid class");
51 if (
Kind == OffloadClass)
54 if (
Kind == OffloadUnbundlingJobClass)
57 assert((OffloadingDeviceKind == OKind || OffloadingDeviceKind == OFK_None) &&
58 "Setting device kind to a different device??");
59 assert(!ActiveOffloadKindMask &&
"Setting a device kind in a host action??");
60 OffloadingDeviceKind = OKind;
61 OffloadingArch = OArch;
63 for (
auto *A : Inputs)
64 A->propagateDeviceOffloadInfo(OffloadingDeviceKind, OArch);
69 if (
Kind == OffloadClass)
72 assert(OffloadingDeviceKind == OFK_None &&
73 "Setting a host kind in a device action.");
74 ActiveOffloadKindMask |= OKinds;
75 OffloadingArch = OArch;
77 for (
auto *A : Inputs)
78 A->propagateHostOffloadInfo(ActiveOffloadKindMask, OArch);
90 switch (OffloadingDeviceKind) {
94 llvm_unreachable(
"Host kind is not an offloading device kind.");
99 return "device-openmp";
106 if (!ActiveOffloadKindMask)
109 std::string Res(
"host");
110 assert(!((ActiveOffloadKindMask & OFK_Cuda) &&
111 (ActiveOffloadKindMask & OFK_HIP)) &&
112 "Cannot offload CUDA and HIP at the same time");
113 if (ActiveOffloadKindMask & OFK_Cuda)
115 if (ActiveOffloadKindMask & OFK_HIP)
117 if (ActiveOffloadKindMask & OFK_OpenMP)
129 StringRef NormalizedTriple,
130 bool CreatePrefixForHost) {
132 if (!CreatePrefixForHost && (Kind == OFK_None || Kind == OFK_Host))
135 std::string Res(
"-");
136 Res += GetOffloadKindName(Kind);
138 Res += NormalizedTriple;
159 llvm_unreachable(
"invalid offload kind");
162 void InputAction::anchor() {}
165 :
Action(InputClass, _Type), Input(_Input) {}
167 void BindArchAction::anchor() {}
172 void OffloadAction::anchor() {}
184 DevToolChains(DDeps.getToolChains()) {
189 if (llvm::all_of(OKinds, [&](
OffloadKind K) {
return K == OKinds.front(); }))
193 if (OKinds.size() == 1)
198 getInputs()[i]->propagateDeviceOffloadInfo(OKinds[i], BArchs[i]);
204 DevToolChains(DDeps.getToolChains()) {
213 for (
unsigned i = 0, e = DDeps.
getActions().size(); i != e; ++i)
224 assert(!
getInputs().empty() &&
"No dependencies for offload action??");
226 Work(A, HostTC, A->getOffloadingArch());
239 assert(
getInputs().
size() == DevToolChains.size() + (HostTC ? 1 : 0) &&
240 "Sizes of action dependences and toolchains are not consistent!");
246 auto TI = DevToolChains.begin();
247 for (; I != E; ++I, ++TI)
248 Work(*I, *TI, (*I)->getOffloadingArch());
258 if (IsHostDependence)
268 assert(!
getInputs().empty() &&
"No dependencies for offload action??");
269 return HostTC ?
getInputs().front() :
nullptr;
273 bool DoNotConsiderHostActions)
const {
274 if (DoNotConsiderHostActions)
275 return getInputs().size() == (HostTC ? 2 : 1);
276 return !HostTC &&
getInputs().size() == 1;
282 "Single device dependence does not exist!");
289 const char *BoundArch,
291 DeviceActions.push_back(&A);
292 DeviceToolChains.push_back(&TC);
293 DeviceBoundArchs.push_back(BoundArch);
294 DeviceOffloadKinds.push_back(OKind);
298 const char *BoundArch,
300 : HostAction(A), HostToolChain(TC), HostBoundArch(BoundArch) {
302 HostOffloadKinds |= K;
305 void JobAction::anchor() {}
308 :
Action(Kind, Input, Type) {}
311 :
Action(Kind, Inputs, Type) {}
313 void PreprocessJobAction::anchor() {}
318 void PrecompileJobAction::anchor() {}
326 assert(isa<PrecompileJobAction>((
Action*)
this) &&
"invalid action kind");
329 void HeaderModulePrecompileJobAction::anchor() {}
334 ModuleName(ModuleName) {}
336 void AnalyzeJobAction::anchor() {}
341 void MigrateJobAction::anchor() {}
346 void CompileJobAction::anchor() {}
351 void BackendJobAction::anchor() {}
356 void AssembleJobAction::anchor() {}
361 void LinkJobAction::anchor() {}
366 void LipoJobAction::anchor() {}
371 void DsymutilJobAction::anchor() {}
376 void VerifyJobAction::anchor() {}
382 "ActionClass is not a valid VerifyJobAction");
385 void VerifyDebugInfoJobAction::anchor() {}
391 void VerifyPCHJobAction::anchor() {}
396 void OffloadBundlingJobAction::anchor() {}
401 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