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";
55 llvm_unreachable(
"invalid class");
68 "Setting device kind to a different device??");
74 for (
auto *A : Inputs)
84 "Setting a host kind in a device action.");
88 for (
auto *A : Inputs)
106 llvm_unreachable(
"Host kind is not an offloading device kind.");
109 return "device-cuda";
111 return "device-openmp";
115 return "device-sycl";
123 std::string Res(
"host");
126 "Cannot offload CUDA and HIP at the same time");
145 StringRef NormalizedTriple,
146 bool CreatePrefixForHost) {
151 std::string Res(
"-");
154 Res += NormalizedTriple;
177 llvm_unreachable(
"invalid offload kind");
180void InputAction::anchor() {}
183 :
Action(InputClass, _Type), Input(_Input),
Id(_Id.str()) {}
185void BindArchAction::anchor() {}
188 :
Action(BindArchClass, Input), ArchName(ArchName) {}
190void OffloadAction::anchor() {}
193 :
Action(OffloadClass, HDep.getAction()), HostTC(HDep.getToolChain()) {
201 :
Action(OffloadClass, DDeps.getActions(), Ty),
202 DevToolChains(DDeps.getToolChains()) {
208 if (llvm::all_equal(OKinds))
212 if (OKinds.size() == 1)
217 getInputs()[i]->propagateDeviceOffloadInfo(OKinds[i], BArchs[i], OTCs[i]);
222 :
Action(OffloadClass, HDep.getAction()), HostTC(HDep.getToolChain()),
223 DevToolChains(DDeps.getToolChains()) {
232 for (
unsigned i = 0, e = DDeps.
getActions().size(); i != e; ++i) {
248 assert(!
getInputs().empty() &&
"No dependencies for offload action??");
250 Work(A, HostTC, A->getOffloadingArch());
263 assert(
getInputs().
size() == DevToolChains.size() + (HostTC ? 1 : 0) &&
264 "Sizes of action dependences and toolchains are not consistent!");
270 auto TI = DevToolChains.begin();
271 for (; I !=
E; ++I, ++TI)
272 Work(*I, *TI, (*I)->getOffloadingArch());
282 if (IsHostDependence)
292 assert(!
getInputs().empty() &&
"No dependencies for offload action??");
293 return HostTC ?
getInputs().front() :
nullptr;
297 bool DoNotConsiderHostActions)
const {
298 if (DoNotConsiderHostActions)
299 return getInputs().size() == (HostTC ? 2 : 1);
300 return !HostTC &&
getInputs().size() == 1;
306 "Single device dependence does not exist!");
313 const char *BoundArch,
315 DeviceActions.push_back(&A);
316 DeviceToolChains.push_back(&TC);
317 DeviceBoundArchs.push_back(BoundArch);
318 DeviceOffloadKinds.push_back(OKind);
322 const char *BoundArch,
323 unsigned OffloadKindMask) {
324 DeviceActions.push_back(&A);
325 DeviceToolChains.push_back(&TC);
326 DeviceBoundArchs.push_back(BoundArch);
330 if (OKind & OffloadKindMask)
331 DeviceOffloadKinds.push_back(OKind);
335 const char *BoundArch,
337 : HostAction(A), HostToolChain(TC), HostBoundArch(BoundArch) {
339 HostOffloadKinds |= K;
342void JobAction::anchor() {}
350void PreprocessJobAction::anchor() {}
353 :
JobAction(PreprocessJobClass, Input, OutputType) {}
355void PrecompileJobAction::anchor() {}
358 :
JobAction(PrecompileJobClass, Input, OutputType) {}
363 assert(isa<PrecompileJobAction>((
Action*)
this) &&
"invalid action kind");
366void ExtractAPIJobAction::anchor() {}
369 :
JobAction(ExtractAPIJobClass, Inputs, OutputType) {}
371void AnalyzeJobAction::anchor() {}
374 :
JobAction(AnalyzeJobClass, Input, OutputType) {}
376void MigrateJobAction::anchor() {}
379 :
JobAction(MigrateJobClass, Input, OutputType) {}
381void CompileJobAction::anchor() {}
384 :
JobAction(CompileJobClass, Input, OutputType) {}
386void BackendJobAction::anchor() {}
389 :
JobAction(BackendJobClass, Input, OutputType) {}
391void AssembleJobAction::anchor() {}
394 :
JobAction(AssembleJobClass, Input, OutputType) {}
396void IfsMergeJobAction::anchor() {}
401void LinkJobAction::anchor() {}
406void LipoJobAction::anchor() {}
411void DsymutilJobAction::anchor() {}
416void VerifyJobAction::anchor() {}
422 "ActionClass is not a valid VerifyJobAction");
425void VerifyDebugInfoJobAction::anchor() {}
431void VerifyPCHJobAction::anchor() {}
436void OffloadBundlingJobAction::anchor() {}
439 :
JobAction(OffloadBundlingJobClass, Inputs, Inputs.back()->getType()) {}
441void OffloadUnbundlingJobAction::anchor() {}
444 :
JobAction(OffloadUnbundlingJobClass, Input, Input->getType()) {}
446void OffloadPackagerJobAction::anchor() {}
452void LinkerWrapperJobAction::anchor() {}
458void StaticLibJobAction::anchor() {}
463void BinaryAnalyzeJobAction::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
@ 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)
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)
MigrateJobAction(Action *Input, types::ID OutputType)
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.