10#include "llvm/Support/ErrorHandling.h"
29 return "api-extractor";
42 return "clang-offload-bundler";
44 return "llvm-offload-binary";
46 return "clang-linker-wrapper";
48 return "static-lib-linker";
50 return "binary-analyzer";
52 return "binary-translator";
57 llvm_unreachable(
"invalid class");
67 "Setting device kind to a different device??");
73 for (
auto *A : Inputs)
83 "Setting a host kind in a device action.");
87 for (
auto *A : Inputs)
105 llvm_unreachable(
"Host kind is not an offloading device kind.");
108 return "device-cuda";
110 return "device-openmp";
114 return "device-sycl";
122 std::string Res(
"host");
125 "Cannot offload CUDA and HIP at the same time");
144 StringRef NormalizedTriple,
145 bool CreatePrefixForHost) {
150 std::string Res(
"-");
153 Res += NormalizedTriple;
176 llvm_unreachable(
"invalid offload kind");
179void InputAction::anchor() {}
184void BindArchAction::anchor() {}
189void OffloadAction::anchor() {}
201 DevToolChains(DDeps.getToolChains()) {
207 if (llvm::all_equal(OKinds))
211 if (OKinds.size() == 1)
216 getInputs()[i]->propagateDeviceOffloadInfo(OKinds[i], BArchs[i], OTCs[i]);
222 DevToolChains(DDeps.getToolChains()) {
230 for (
unsigned i = 0, e = DDeps.
getActions().size(); i != e; ++i) {
231 if (auto *A = DDeps.getActions()[i]) {
232 getInputs().push_back(A);
233 A->propagateDeviceOffloadInfo(DDeps.getOffloadKinds()[i],
234 DDeps.getBoundArchs()[i],
235 DDeps.getToolChains()[i]);
237 if (DDeps.getActions().size() == 1)
238 OffloadingToolChain = DDeps.getToolChains()[i];
246 assert(!
getInputs().empty() &&
"No dependencies for offload action??");
248 Work(A, HostTC, A->getOffloadingArch());
261 assert(
getInputs().
size() == DevToolChains.size() + (HostTC ? 1 : 0) &&
262 "Sizes of action dependences and toolchains are not consistent!");
268 auto TI = DevToolChains.begin();
269 for (; I != E; ++I, ++TI)
270 Work(*I, *TI, (*I)->getOffloadingArch());
280 if (IsHostDependence)
290 assert(!
getInputs().empty() &&
"No dependencies for offload action??");
291 return HostTC ?
getInputs().front() :
nullptr;
295 bool DoNotConsiderHostActions)
const {
296 if (DoNotConsiderHostActions)
297 return getInputs().size() == (HostTC ? 2 : 1);
298 return !HostTC &&
getInputs().size() == 1;
304 "Single device dependence does not exist!");
312 DeviceActions.push_back(&A);
313 DeviceToolChains.push_back(&TC);
314 DeviceBoundArchs.push_back(BA);
315 DeviceOffloadKinds.push_back(OKind);
320 unsigned OffloadKindMask) {
321 DeviceActions.push_back(&A);
322 DeviceToolChains.push_back(&TC);
323 DeviceBoundArchs.push_back(BA);
327 if (OKind & OffloadKindMask)
328 DeviceOffloadKinds.push_back(OKind);
334 : HostAction(A), HostToolChain(TC), HostBoundArch(BA) {
336 HostOffloadKinds |= K;
339void JobAction::anchor() {}
342 :
Action(Kind, Input, Type) {}
345 :
Action(Kind, Inputs, Type) {}
347void PreprocessJobAction::anchor() {}
352void PrecompileJobAction::anchor() {}
363void ExtractAPIJobAction::anchor() {}
368void AnalyzeJobAction::anchor() {}
373void CompileJobAction::anchor() {}
378void BackendJobAction::anchor() {}
383void AssembleJobAction::anchor() {}
388void IfsMergeJobAction::anchor() {}
393void LinkJobAction::anchor() {}
398void LipoJobAction::anchor() {}
403void DsymutilJobAction::anchor() {}
408void VerifyJobAction::anchor() {}
414 "ActionClass is not a valid VerifyJobAction");
417void VerifyDebugInfoJobAction::anchor() {}
423void VerifyPCHJobAction::anchor() {}
428void OffloadBundlingJobAction::anchor() {}
433void OffloadPackagerJobAction::anchor() {}
439void LinkerWrapperJobAction::anchor() {}
445void StaticLibJobAction::anchor() {}
450void BinaryAnalyzeJobAction::anchor() {}
455void BinaryTranslatorJobAction::anchor() {}
461void 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.
@ 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(ActionList &Inputs, 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)
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.
Top level wrappers for InstallAPI frontend operations.
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.