10#include "llvm/Support/ErrorHandling.h"
15using namespace driver;
29 return "api-extractor";
42 return "clang-offload-bundler";
44 return "clang-offload-unbundler";
46 return "clang-offload-packager";
48 return "clang-linker-wrapper";
50 return "static-lib-linker";
52 return "binary-analyzer";
54 return "binary-translator";
59 llvm_unreachable(
"invalid class");
72 "Setting device kind to a different device??");
78 for (
auto *A : Inputs)
88 "Setting a host kind in a device action.");
92 for (
auto *A : Inputs)
110 llvm_unreachable(
"Host kind is not an offloading device kind.");
113 return "device-cuda";
115 return "device-openmp";
119 return "device-sycl";
127 std::string Res(
"host");
130 "Cannot offload CUDA and HIP at the same time");
149 StringRef NormalizedTriple,
150 bool CreatePrefixForHost) {
155 std::string Res(
"-");
158 Res += NormalizedTriple;
181 llvm_unreachable(
"invalid offload kind");
184void InputAction::anchor() {}
187 :
Action(InputClass, _Type), Input(_Input),
Id(_Id.str()) {}
189void BindArchAction::anchor() {}
194void OffloadAction::anchor() {}
197 :
Action(OffloadClass, HDep.getAction()), HostTC(HDep.getToolChain()) {
205 :
Action(OffloadClass, DDeps.getActions(), Ty),
206 DevToolChains(DDeps.getToolChains()) {
212 if (llvm::all_equal(OKinds))
216 if (OKinds.size() == 1)
221 getInputs()[i]->propagateDeviceOffloadInfo(OKinds[i], BArchs[i], OTCs[i]);
226 :
Action(OffloadClass, HDep.getAction()), HostTC(HDep.getToolChain()),
227 DevToolChains(DDeps.getToolChains()) {
236 for (
unsigned i = 0, e = DDeps.
getActions().size(); i != e; ++i) {
252 assert(!
getInputs().empty() &&
"No dependencies for offload action??");
254 Work(A, HostTC, A->getOffloadingArch());
267 assert(
getInputs().
size() == DevToolChains.size() + (HostTC ? 1 : 0) &&
268 "Sizes of action dependences and toolchains are not consistent!");
274 auto TI = DevToolChains.begin();
275 for (; I !=
E; ++I, ++TI)
276 Work(*I, *TI, (*I)->getOffloadingArch());
286 if (IsHostDependence)
296 assert(!
getInputs().empty() &&
"No dependencies for offload action??");
297 return HostTC ?
getInputs().front() :
nullptr;
301 bool DoNotConsiderHostActions)
const {
302 if (DoNotConsiderHostActions)
303 return getInputs().size() == (HostTC ? 2 : 1);
304 return !HostTC &&
getInputs().size() == 1;
310 "Single device dependence does not exist!");
317 const char *BoundArch,
319 DeviceActions.push_back(&A);
320 DeviceToolChains.push_back(&TC);
321 DeviceBoundArchs.push_back(BoundArch);
322 DeviceOffloadKinds.push_back(OKind);
326 const char *BoundArch,
327 unsigned OffloadKindMask) {
328 DeviceActions.push_back(&A);
329 DeviceToolChains.push_back(&TC);
330 DeviceBoundArchs.push_back(BoundArch);
334 if (OKind & OffloadKindMask)
335 DeviceOffloadKinds.push_back(OKind);
339 const char *BoundArch,
341 : HostAction(A), HostToolChain(TC), HostBoundArch(BoundArch) {
343 HostOffloadKinds |= K;
346void JobAction::anchor() {}
354void PreprocessJobAction::anchor() {}
357 :
JobAction(PreprocessJobClass, Input, OutputType) {}
359void PrecompileJobAction::anchor() {}
362 :
JobAction(PrecompileJobClass, Input, OutputType) {}
367 assert(isa<PrecompileJobAction>((
Action*)
this) &&
"invalid action kind");
370void ExtractAPIJobAction::anchor() {}
373 :
JobAction(ExtractAPIJobClass, Inputs, OutputType) {}
375void AnalyzeJobAction::anchor() {}
378 :
JobAction(AnalyzeJobClass, Input, OutputType) {}
380void CompileJobAction::anchor() {}
383 :
JobAction(CompileJobClass, Input, OutputType) {}
385void BackendJobAction::anchor() {}
388 :
JobAction(BackendJobClass, Input, OutputType) {}
390void AssembleJobAction::anchor() {}
393 :
JobAction(AssembleJobClass, Input, OutputType) {}
395void IfsMergeJobAction::anchor() {}
400void LinkJobAction::anchor() {}
405void LipoJobAction::anchor() {}
410void DsymutilJobAction::anchor() {}
415void VerifyJobAction::anchor() {}
421 "ActionClass is not a valid VerifyJobAction");
424void VerifyDebugInfoJobAction::anchor() {}
430void VerifyPCHJobAction::anchor() {}
435void OffloadBundlingJobAction::anchor() {}
438 :
JobAction(OffloadBundlingJobClass, Inputs, Inputs.back()->getType()) {}
440void OffloadUnbundlingJobAction::anchor() {}
443 :
JobAction(OffloadUnbundlingJobClass, Input, Input->getType()) {}
445void OffloadPackagerJobAction::anchor() {}
451void LinkerWrapperJobAction::anchor() {}
457void StaticLibJobAction::anchor() {}
462void BinaryAnalyzeJobAction::anchor() {}
467void BinaryTranslatorJobAction::anchor() {}
473void ObjcopyJobAction::anchor() {}
The base class of the type hierarchy.
Action - Represent an abstract compilation step to perform.
OffloadKind OffloadingDeviceKind
Offloading kind of the device.
const char * getOffloadingArch() const
std::string getOffloadingKindPrefix() const
Return a string containing the offload kind of the action.
void propagateDeviceOffloadInfo(OffloadKind OKind, const char *OArch, const ToolChain *OToolChain)
Set the device offload info of this action and propagate it to its dependences.
const ToolChain * getOffloadingToolChain() const
const ToolChain * OffloadingToolChain
The Offloading toolchain associated with this device action.
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...
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...
static StringRef GetOffloadKindName(OffloadKind Kind)
Return a string containing a offload kind name.
const char * getClassName() const
OffloadKind getOffloadingDeviceKind() const
void propagateHostOffloadInfo(unsigned OKinds, const char *OArch)
Append the host offload info of this action and propagate it to its dependences.
unsigned ActiveOffloadKindMask
Offload information.
const char * OffloadingArch
The Offloading architecture associated with this action.
@ OffloadUnbundlingJobClass
@ BinaryTranslatorJobClass
@ OffloadBundlingJobClass
@ VerifyDebugInfoJobClass
@ OffloadPackagerJobClass
unsigned getOffloadingHostActiveKinds() const
AnalyzeJobAction(Action *Input, types::ID OutputType)
AssembleJobAction(Action *Input, types::ID OutputType)
BackendJobAction(Action *Input, types::ID OutputType)
BinaryAnalyzeJobAction(Action *Input, types::ID Type)
BinaryTranslatorJobAction(Action *Input, types::ID Type)
BindArchAction(Action *Input, StringRef ArchName)
CompileJobAction(Action *Input, types::ID OutputType)
DsymutilJobAction(ActionList &Inputs, types::ID Type)
IfsMergeJobAction(ActionList &Inputs, types::ID Type)
JobAction(ActionClass Kind, Action *Input, types::ID Type)
LinkJobAction(ActionList &Inputs, types::ID Type)
LinkerWrapperJobAction(ActionList &Inputs, types::ID Type)
LipoJobAction(ActionList &Inputs, types::ID Type)
ObjcopyJobAction(Action *Input, types::ID Type)
Type used to communicate device actions.
void add(Action &A, const ToolChain &TC, const char *BoundArch, OffloadKind OKind)
Add an action along with the associated toolchain, bound arch, and offload kind.
const BoundArchList & getBoundArchs() const
const OffloadKindList & getOffloadKinds() const
const ActionList & getActions() const
Get each of the individual arrays.
const ToolChainList & getToolChains() const
Type used to communicate host actions.
Action * getAction() const
HostDependence(Action &A, const ToolChain &TC, const char *BoundArch, const unsigned OffloadKinds)
unsigned getOffloadKinds() const
const char * getBoundArch() const
void doOnEachDependence(const OffloadActionWorkTy &Work) const
Execute the work specified in Work on each dependence.
Action * getSingleDeviceDependence(bool DoNotConsiderHostActions=false) const
Return the single device dependence of this action.
bool hasSingleDeviceDependence(bool DoNotConsiderHostActions=false) const
Return true if the action has a single device dependence.
Action * getHostDependence() const
Return the host dependence of this action.
llvm::function_ref< void(Action *, const ToolChain *, const char *)> OffloadActionWorkTy
void doOnEachDeviceDependence(const OffloadActionWorkTy &Work) const
Execute the work specified in Work on each device dependence.
bool hasHostDependence() const
Return true if the action has a host dependence.
void doOnHostDependence(const OffloadActionWorkTy &Work) const
Execute the work specified in Work on the host dependence.
OffloadAction(const HostDependence &HDep)
OffloadBundlingJobAction(ActionList &Inputs)
OffloadPackagerJobAction(ActionList &Inputs, types::ID Type)
OffloadUnbundlingJobAction(Action *Input)
PrecompileJobAction(ActionClass Kind, Action *Input, types::ID OutputType)
PreprocessJobAction(Action *Input, types::ID OutputType)
StaticLibJobAction(ActionList &Inputs, types::ID Type)
VerifyDebugInfoJobAction(Action *Input, types::ID Type)
VerifyJobAction(ActionClass Kind, Action *Input, types::ID Type)
VerifyPCHJobAction(Action *Input, types::ID Type)
The JSON file list parser is used to communicate input to InstallAPI.