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 IfsMergeJobClass:
return "interface-stub-merger";
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";
44 case OffloadWrapperJobClass:
45 return "clang-offload-wrapper";
48 llvm_unreachable(
"invalid class");
53 if (
Kind == OffloadClass)
56 if (
Kind == OffloadUnbundlingJobClass)
59 assert((OffloadingDeviceKind == OKind || OffloadingDeviceKind == OFK_None) &&
60 "Setting device kind to a different device??");
61 assert(!ActiveOffloadKindMask &&
"Setting a device kind in a host action??");
62 OffloadingDeviceKind = OKind;
63 OffloadingArch = OArch;
65 for (
auto *A : Inputs)
66 A->propagateDeviceOffloadInfo(OffloadingDeviceKind, OArch);
71 if (
Kind == OffloadClass)
74 assert(OffloadingDeviceKind == OFK_None &&
75 "Setting a host kind in a device action.");
76 ActiveOffloadKindMask |= OKinds;
77 OffloadingArch = OArch;
79 for (
auto *A : Inputs)
80 A->propagateHostOffloadInfo(ActiveOffloadKindMask, OArch);
92 switch (OffloadingDeviceKind) {
96 llvm_unreachable(
"Host kind is not an offloading device kind.");
101 return "device-openmp";
108 if (!ActiveOffloadKindMask)
111 std::string Res(
"host");
112 assert(!((ActiveOffloadKindMask & OFK_Cuda) &&
113 (ActiveOffloadKindMask & OFK_HIP)) &&
114 "Cannot offload CUDA and HIP at the same time");
115 if (ActiveOffloadKindMask & OFK_Cuda)
117 if (ActiveOffloadKindMask & OFK_HIP)
119 if (ActiveOffloadKindMask & OFK_OpenMP)
131 StringRef NormalizedTriple,
132 bool CreatePrefixForHost) {
134 if (!CreatePrefixForHost && (Kind == OFK_None || Kind == OFK_Host))
137 std::string Res(
"-");
138 Res += GetOffloadKindName(Kind);
140 Res += NormalizedTriple;
161 llvm_unreachable(
"invalid offload kind");
164 void InputAction::anchor() {}
167 :
Action(InputClass, _Type), Input(_Input) {}
169 void BindArchAction::anchor() {}
174 void OffloadAction::anchor() {}
186 DevToolChains(DDeps.getToolChains()) {
191 if (llvm::all_of(OKinds, [&](
OffloadKind K) {
return K == OKinds.front(); }))
195 if (OKinds.size() == 1)
200 getInputs()[i]->propagateDeviceOffloadInfo(OKinds[i], BArchs[i]);
206 DevToolChains(DDeps.getToolChains()) {
215 for (
unsigned i = 0, e = DDeps.
getActions().size(); i != e; ++i)
226 assert(!
getInputs().empty() &&
"No dependencies for offload action??");
228 Work(A, HostTC, A->getOffloadingArch());
241 assert(
getInputs().
size() == DevToolChains.size() + (HostTC ? 1 : 0) &&
242 "Sizes of action dependences and toolchains are not consistent!");
248 auto TI = DevToolChains.begin();
249 for (; I != E; ++I, ++TI)
250 Work(*I, *TI, (*I)->getOffloadingArch());
260 if (IsHostDependence)
270 assert(!
getInputs().empty() &&
"No dependencies for offload action??");
271 return HostTC ?
getInputs().front() :
nullptr;
275 bool DoNotConsiderHostActions)
const {
276 if (DoNotConsiderHostActions)
277 return getInputs().size() == (HostTC ? 2 : 1);
278 return !HostTC &&
getInputs().size() == 1;
284 "Single device dependence does not exist!");
291 const char *BoundArch,
293 DeviceActions.push_back(&A);
294 DeviceToolChains.push_back(&TC);
295 DeviceBoundArchs.push_back(BoundArch);
296 DeviceOffloadKinds.push_back(OKind);
300 const char *BoundArch,
302 : HostAction(A), HostToolChain(TC), HostBoundArch(BoundArch) {
304 HostOffloadKinds |= K;
307 void JobAction::anchor() {}
310 :
Action(Kind, Input, Type) {}
313 :
Action(Kind, Inputs, Type) {}
315 void PreprocessJobAction::anchor() {}
320 void PrecompileJobAction::anchor() {}
328 assert(isa<PrecompileJobAction>((
Action*)
this) &&
"invalid action kind");
331 void HeaderModulePrecompileJobAction::anchor() {}
336 ModuleName(ModuleName) {}
338 void AnalyzeJobAction::anchor() {}
343 void MigrateJobAction::anchor() {}
348 void CompileJobAction::anchor() {}
353 void BackendJobAction::anchor() {}
358 void AssembleJobAction::anchor() {}
363 void IfsMergeJobAction::anchor() {}
368 void LinkJobAction::anchor() {}
373 void LipoJobAction::anchor() {}
378 void DsymutilJobAction::anchor() {}
383 void VerifyJobAction::anchor() {}
389 "ActionClass is not a valid VerifyJobAction");
392 void VerifyDebugInfoJobAction::anchor() {}
398 void VerifyPCHJobAction::anchor() {}
403 void OffloadBundlingJobAction::anchor() {}
408 void OffloadUnbundlingJobAction::anchor() {}
413 void OffloadWrapperJobAction::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.
IfsMergeJobAction(ActionList &Inputs, types::ID Type)
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)
OffloadWrapperJobAction(ActionList &Inputs, types::ID Type)
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