10#include "llvm/Support/ErrorHandling.h"
29 return "api-extractor";
42 return "clang-offload-bundler";
44 return "clang-offload-unbundler";
46 return "llvm-offload-binary";
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() {}
189void BindArchAction::anchor() {}
194void OffloadAction::anchor() {}
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]);
227 DevToolChains(DDeps.getToolChains()) {
235 for (
unsigned i = 0, e = DDeps.
getActions().size(); i != e; ++i) {
236 if (auto *A = DDeps.getActions()[i]) {
237 getInputs().push_back(A);
238 A->propagateDeviceOffloadInfo(DDeps.getOffloadKinds()[i],
239 DDeps.getBoundArchs()[i],
240 DDeps.getToolChains()[i]);
242 if (DDeps.getActions().size() == 1)
243 OffloadingToolChain = DDeps.getToolChains()[i];
251 assert(!
getInputs().empty() &&
"No dependencies for offload action??");
253 Work(A, HostTC, A->getOffloadingArch());
266 assert(
getInputs().
size() == DevToolChains.size() + (HostTC ? 1 : 0) &&
267 "Sizes of action dependences and toolchains are not consistent!");
273 auto TI = DevToolChains.begin();
274 for (; I != E; ++I, ++TI)
275 Work(*I, *TI, (*I)->getOffloadingArch());
285 if (IsHostDependence)
295 assert(!
getInputs().empty() &&
"No dependencies for offload action??");
296 return HostTC ?
getInputs().front() :
nullptr;
300 bool DoNotConsiderHostActions)
const {
301 if (DoNotConsiderHostActions)
302 return getInputs().size() == (HostTC ? 2 : 1);
303 return !HostTC &&
getInputs().size() == 1;
309 "Single device dependence does not exist!");
317 DeviceActions.push_back(&A);
318 DeviceToolChains.push_back(&TC);
319 DeviceBoundArchs.push_back(BA);
320 DeviceOffloadKinds.push_back(OKind);
325 unsigned OffloadKindMask) {
326 DeviceActions.push_back(&A);
327 DeviceToolChains.push_back(&TC);
328 DeviceBoundArchs.push_back(BA);
332 if (OKind & OffloadKindMask)
333 DeviceOffloadKinds.push_back(OKind);
339 : HostAction(A), HostToolChain(TC), HostBoundArch(BA) {
341 HostOffloadKinds |= K;
344void JobAction::anchor() {}
347 :
Action(Kind, Input, Type) {}
350 :
Action(Kind, Inputs, Type) {}
352void PreprocessJobAction::anchor() {}
357void PrecompileJobAction::anchor() {}
368void ExtractAPIJobAction::anchor() {}
373void AnalyzeJobAction::anchor() {}
378void CompileJobAction::anchor() {}
383void BackendJobAction::anchor() {}
388void AssembleJobAction::anchor() {}
393void IfsMergeJobAction::anchor() {}
398void LinkJobAction::anchor() {}
403void LipoJobAction::anchor() {}
408void DsymutilJobAction::anchor() {}
413void VerifyJobAction::anchor() {}
419 "ActionClass is not a valid VerifyJobAction");
422void VerifyDebugInfoJobAction::anchor() {}
428void VerifyPCHJobAction::anchor() {}
433void OffloadBundlingJobAction::anchor() {}
438void OffloadUnbundlingJobAction::anchor() {}
443void OffloadPackagerJobAction::anchor() {}
449void LinkerWrapperJobAction::anchor() {}
455void StaticLibJobAction::anchor() {}
460void BinaryAnalyzeJobAction::anchor() {}
465void BinaryTranslatorJobAction::anchor() {}
471void ObjcopyJobAction::anchor() {}
Action - Represent an abstract compilation step to perform.
OffloadKind OffloadingDeviceKind
Offloading kind of the device.
Action(ActionClass Kind, types::ID Type)
types::ID getType() const
std::string getOffloadingKindPrefix() const
Return a string containing the offload kind of the action.
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...
BoundArch getOffloadingArch() const
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 propagateDeviceOffloadInfo(OffloadKind OKind, BoundArch OArch, const ToolChain *OToolChain)
Set the device offload info of this action and propagate it to its dependences.
unsigned ActiveOffloadKindMask
Offload information.
void propagateHostOffloadInfo(unsigned OKinds, BoundArch OArch)
Append the host offload info of this action and propagate it to its dependences.
BoundArch 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, BoundArch 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.
const BoundArchList & getBoundArchs() const
const OffloadKindList & getOffloadKinds() const
const ActionList & getActions() const
Get each of the individual arrays.
void add(Action &A, const ToolChain &TC, BoundArch BA, OffloadKind OKind)
Add an action along with the associated toolchain, bound arch, and offload kind.
const ToolChainList & getToolChains() const
Type used to communicate host actions.
Action * getAction() const
BoundArch getBoundArch() const
HostDependence(Action &A, const ToolChain &TC, BoundArch BA, const unsigned OffloadKinds)
unsigned getOffloadKinds() 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.
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.
llvm::function_ref< void(Action *, const ToolChain *, BoundArch)> OffloadActionWorkTy
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)
SmallVector< Action *, 3 > ActionList
ActionList - Type used for lists of actions.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
for(const auto &A :T->param_types())
Represents a bound architecture for offload / multiple architecture compilation.