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";
121 std::string Res(
"host");
124 "Cannot offload CUDA and HIP at the same time");
141 StringRef NormalizedTriple,
142 bool CreatePrefixForHost) {
147 std::string Res(
"-");
150 Res += NormalizedTriple;
171 llvm_unreachable(
"invalid offload kind");
174void InputAction::anchor() {}
177 :
Action(InputClass, _Type), Input(_Input),
Id(_Id.str()) {}
179void BindArchAction::anchor() {}
182 :
Action(BindArchClass, Input), ArchName(ArchName) {}
184void OffloadAction::anchor() {}
187 :
Action(OffloadClass, HDep.getAction()), HostTC(HDep.getToolChain()) {
195 :
Action(OffloadClass, DDeps.getActions(), Ty),
196 DevToolChains(DDeps.getToolChains()) {
202 if (llvm::all_equal(OKinds))
206 if (OKinds.size() == 1)
211 getInputs()[i]->propagateDeviceOffloadInfo(OKinds[i], BArchs[i], OTCs[i]);
216 :
Action(OffloadClass, HDep.getAction()), HostTC(HDep.getToolChain()),
217 DevToolChains(DDeps.getToolChains()) {
226 for (
unsigned i = 0, e = DDeps.
getActions().size(); i != e; ++i) {
242 assert(!
getInputs().empty() &&
"No dependencies for offload action??");
244 Work(A, HostTC, A->getOffloadingArch());
257 assert(
getInputs().
size() == DevToolChains.size() + (HostTC ? 1 : 0) &&
258 "Sizes of action dependences and toolchains are not consistent!");
264 auto TI = DevToolChains.begin();
265 for (; I !=
E; ++I, ++TI)
266 Work(*I, *TI, (*I)->getOffloadingArch());
276 if (IsHostDependence)
286 assert(!
getInputs().empty() &&
"No dependencies for offload action??");
287 return HostTC ?
getInputs().front() :
nullptr;
291 bool DoNotConsiderHostActions)
const {
292 if (DoNotConsiderHostActions)
293 return getInputs().size() == (HostTC ? 2 : 1);
294 return !HostTC &&
getInputs().size() == 1;
300 "Single device dependence does not exist!");
307 const char *BoundArch,
309 DeviceActions.push_back(&A);
310 DeviceToolChains.push_back(&TC);
311 DeviceBoundArchs.push_back(BoundArch);
312 DeviceOffloadKinds.push_back(OKind);
316 const char *BoundArch,
317 unsigned OffloadKindMask) {
318 DeviceActions.push_back(&A);
319 DeviceToolChains.push_back(&TC);
320 DeviceBoundArchs.push_back(BoundArch);
324 if (OKind & OffloadKindMask)
325 DeviceOffloadKinds.push_back(OKind);
329 const char *BoundArch,
331 : HostAction(A), HostToolChain(TC), HostBoundArch(BoundArch) {
333 HostOffloadKinds |= K;
336void JobAction::anchor() {}
344void PreprocessJobAction::anchor() {}
347 :
JobAction(PreprocessJobClass, Input, OutputType) {}
349void PrecompileJobAction::anchor() {}
352 :
JobAction(PrecompileJobClass, Input, OutputType) {}
357 assert(isa<PrecompileJobAction>((
Action*)
this) &&
"invalid action kind");
360void ExtractAPIJobAction::anchor() {}
363 :
JobAction(ExtractAPIJobClass, Inputs, OutputType) {}
365void AnalyzeJobAction::anchor() {}
368 :
JobAction(AnalyzeJobClass, Input, OutputType) {}
370void MigrateJobAction::anchor() {}
373 :
JobAction(MigrateJobClass, Input, OutputType) {}
375void CompileJobAction::anchor() {}
378 :
JobAction(CompileJobClass, Input, OutputType) {}
380void BackendJobAction::anchor() {}
383 :
JobAction(BackendJobClass, Input, OutputType) {}
385void AssembleJobAction::anchor() {}
388 :
JobAction(AssembleJobClass, Input, OutputType) {}
390void IfsMergeJobAction::anchor() {}
395void LinkJobAction::anchor() {}
400void LipoJobAction::anchor() {}
405void DsymutilJobAction::anchor() {}
410void VerifyJobAction::anchor() {}
416 "ActionClass is not a valid VerifyJobAction");
419void VerifyDebugInfoJobAction::anchor() {}
425void VerifyPCHJobAction::anchor() {}
430void OffloadBundlingJobAction::anchor() {}
433 :
JobAction(OffloadBundlingJobClass, Inputs, Inputs.back()->getType()) {}
435void OffloadUnbundlingJobAction::anchor() {}
438 :
JobAction(OffloadUnbundlingJobClass, Input, Input->getType()) {}
440void OffloadPackagerJobAction::anchor() {}
446void LinkerWrapperJobAction::anchor() {}
452void StaticLibJobAction::anchor() {}
457void 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.