clang  19.0.0git
Action.h
Go to the documentation of this file.
1 //===- Action.h - Abstract compilation steps --------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_CLANG_DRIVER_ACTION_H
10 #define LLVM_CLANG_DRIVER_ACTION_H
11 
12 #include "clang/Basic/LLVM.h"
13 #include "clang/Driver/Types.h"
14 #include "clang/Driver/Util.h"
15 #include "llvm/ADT/ArrayRef.h"
16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/ADT/SetVector.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/ADT/iterator_range.h"
21 #include <initializer_list>
22 #include <string>
23 
24 namespace llvm {
25 namespace opt {
26 
27 class Arg;
28 
29 } // namespace opt
30 } // namespace llvm
31 
32 namespace clang {
33 namespace driver {
34 
35 class ToolChain;
36 
37 /// Action - Represent an abstract compilation step to perform.
38 ///
39 /// An action represents an edge in the compilation graph; typically
40 /// it is a job to transform an input using some tool.
41 ///
42 /// The current driver is hard wired to expect actions which produce a
43 /// single primary output, at least in terms of controlling the
44 /// compilation. Actions can produce auxiliary files, but can only
45 /// produce a single output to feed into subsequent actions.
46 ///
47 /// Actions are usually owned by a Compilation, which creates new
48 /// actions via MakeAction().
49 class Action {
50 public:
51  using size_type = ActionList::size_type;
52  using input_iterator = ActionList::iterator;
53  using input_const_iterator = ActionList::const_iterator;
54  using input_range = llvm::iterator_range<input_iterator>;
55  using input_const_range = llvm::iterator_range<input_const_iterator>;
56 
57  enum ActionClass {
90 
93  };
94 
95  // The offloading kind determines if this action is binded to a particular
96  // programming model. Each entry reserves one bit. We also have a special kind
97  // to designate the host offloading tool chain.
98  enum OffloadKind {
99  OFK_None = 0x00,
100 
101  // The host offloading tool chain.
102  OFK_Host = 0x01,
103 
104  // The device offloading tool chains - one bit for each programming model.
105  OFK_Cuda = 0x02,
106  OFK_OpenMP = 0x04,
107  OFK_HIP = 0x08,
108  OFK_SYCL = 0x10
109  };
110 
111  static const char *getClassName(ActionClass AC);
112 
113 private:
114  ActionClass Kind;
115 
116  /// The output type of this action.
117  types::ID Type;
118 
119  ActionList Inputs;
120 
121  /// Flag that is set to true if this action can be collapsed with others
122  /// actions that depend on it. This is true by default and set to false when
123  /// the action is used by two different tool chains, which is enabled by the
124  /// offloading support implementation.
125  bool CanBeCollapsedWithNextDependentAction = true;
126 
127 protected:
128  ///
129  /// Offload information.
130  ///
131 
132  /// The host offloading kind - a combination of kinds encoded in a mask.
133  /// Multiple programming models may be supported simultaneously by the same
134  /// host.
135  unsigned ActiveOffloadKindMask = 0u;
136 
137  /// Offloading kind of the device.
139 
140  /// The Offloading architecture associated with this action.
141  const char *OffloadingArch = nullptr;
142 
143  /// The Offloading toolchain associated with this device action.
144  const ToolChain *OffloadingToolChain = nullptr;
145 
148  : Action(Kind, ActionList({Input}), Type) {}
149  Action(ActionClass Kind, Action *Input)
150  : Action(Kind, ActionList({Input}), Input->getType()) {}
152  : Kind(Kind), Type(Type), Inputs(Inputs) {}
153 
154 public:
155  virtual ~Action();
156 
157  const char *getClassName() const { return Action::getClassName(getKind()); }
158 
159  ActionClass getKind() const { return Kind; }
160  types::ID getType() const { return Type; }
161 
162  ActionList &getInputs() { return Inputs; }
163  const ActionList &getInputs() const { return Inputs; }
164 
165  size_type size() const { return Inputs.size(); }
166 
167  input_iterator input_begin() { return Inputs.begin(); }
168  input_iterator input_end() { return Inputs.end(); }
170  input_const_iterator input_begin() const { return Inputs.begin(); }
171  input_const_iterator input_end() const { return Inputs.end(); }
174  }
175 
176  /// Mark this action as not legal to collapse.
178  CanBeCollapsedWithNextDependentAction = false;
179  }
180 
181  /// Return true if this function can be collapsed with others.
183  return CanBeCollapsedWithNextDependentAction;
184  }
185 
186  /// Return a string containing the offload kind of the action.
187  std::string getOffloadingKindPrefix() const;
188 
189  /// Return a string that can be used as prefix in order to generate unique
190  /// files for each offloading kind. By default, no prefix is used for
191  /// non-device kinds, except if \a CreatePrefixForHost is set.
192  static std::string
194  StringRef NormalizedTriple,
195  bool CreatePrefixForHost = false);
196 
197  /// Return a string containing a offload kind name.
198  static StringRef GetOffloadKindName(OffloadKind Kind);
199 
200  /// Set the device offload info of this action and propagate it to its
201  /// dependences.
202  void propagateDeviceOffloadInfo(OffloadKind OKind, const char *OArch,
203  const ToolChain *OToolChain);
204 
205  /// Append the host offload info of this action and propagate it to its
206  /// dependences.
207  void propagateHostOffloadInfo(unsigned OKinds, const char *OArch);
208 
209  void setHostOffloadInfo(unsigned OKinds, const char *OArch) {
210  ActiveOffloadKindMask |= OKinds;
211  OffloadingArch = OArch;
212  }
213 
214  /// Set the offload info of this action to be the same as the provided action,
215  /// and propagate it to its dependences.
216  void propagateOffloadInfo(const Action *A);
217 
218  unsigned getOffloadingHostActiveKinds() const {
219  return ActiveOffloadKindMask;
220  }
221 
223  const char *getOffloadingArch() const { return OffloadingArch; }
225  return OffloadingToolChain;
226  }
227 
228  /// Check if this action have any offload kinds. Note that host offload kinds
229  /// are only set if the action is a dependence to a host offload action.
230  bool isHostOffloading(unsigned int OKind) const {
231  return ActiveOffloadKindMask & OKind;
232  }
233  bool isDeviceOffloading(OffloadKind OKind) const {
234  return OffloadingDeviceKind == OKind;
235  }
236  bool isOffloading(OffloadKind OKind) const {
237  return isHostOffloading(OKind) || isDeviceOffloading(OKind);
238  }
239 };
240 
241 class InputAction : public Action {
242  const llvm::opt::Arg &Input;
243  std::string Id;
244  virtual void anchor();
245 
246 public:
247  InputAction(const llvm::opt::Arg &Input, types::ID Type,
248  StringRef Id = StringRef());
249 
250  const llvm::opt::Arg &getInputArg() const { return Input; }
251 
252  void setId(StringRef _Id) { Id = _Id.str(); }
253  StringRef getId() const { return Id; }
254 
255  static bool classof(const Action *A) {
256  return A->getKind() == InputClass;
257  }
258 };
259 
260 class BindArchAction : public Action {
261  virtual void anchor();
262 
263  /// The architecture to bind, or 0 if the default architecture
264  /// should be bound.
265  StringRef ArchName;
266 
267 public:
268  BindArchAction(Action *Input, StringRef ArchName);
269 
270  StringRef getArchName() const { return ArchName; }
271 
272  static bool classof(const Action *A) {
273  return A->getKind() == BindArchClass;
274  }
275 };
276 
277 /// An offload action combines host or/and device actions according to the
278 /// programming model implementation needs and propagates the offloading kind to
279 /// its dependences.
280 class OffloadAction final : public Action {
281  virtual void anchor();
282 
283 public:
284  /// Type used to communicate device actions. It associates bound architecture,
285  /// toolchain, and offload kind to each action.
286  class DeviceDependences final {
287  public:
291 
292  private:
293  // Lists that keep the information for each dependency. All the lists are
294  // meant to be updated in sync. We are adopting separate lists instead of a
295  // list of structs, because that simplifies forwarding the actions list to
296  // initialize the inputs of the base Action class.
297 
298  /// The dependence actions.
299  ActionList DeviceActions;
300 
301  /// The offloading toolchains that should be used with the action.
302  ToolChainList DeviceToolChains;
303 
304  /// The architectures that should be used with this action.
305  BoundArchList DeviceBoundArchs;
306 
307  /// The offload kind of each dependence.
308  OffloadKindList DeviceOffloadKinds;
309 
310  public:
311  /// Add an action along with the associated toolchain, bound arch, and
312  /// offload kind.
313  void add(Action &A, const ToolChain &TC, const char *BoundArch,
314  OffloadKind OKind);
315 
316  /// Add an action along with the associated toolchain, bound arch, and
317  /// offload kinds.
318  void add(Action &A, const ToolChain &TC, const char *BoundArch,
319  unsigned OffloadKindMask);
320 
321  /// Get each of the individual arrays.
322  const ActionList &getActions() const { return DeviceActions; }
323  const ToolChainList &getToolChains() const { return DeviceToolChains; }
324  const BoundArchList &getBoundArchs() const { return DeviceBoundArchs; }
326  return DeviceOffloadKinds;
327  }
328  };
329 
330  /// Type used to communicate host actions. It associates bound architecture,
331  /// toolchain, and offload kinds to the host action.
332  class HostDependence final {
333  /// The dependence action.
334  Action &HostAction;
335 
336  /// The offloading toolchain that should be used with the action.
337  const ToolChain &HostToolChain;
338 
339  /// The architectures that should be used with this action.
340  const char *HostBoundArch = nullptr;
341 
342  /// The offload kind of each dependence.
343  unsigned HostOffloadKinds = 0u;
344 
345  public:
346  HostDependence(Action &A, const ToolChain &TC, const char *BoundArch,
347  const unsigned OffloadKinds)
348  : HostAction(A), HostToolChain(TC), HostBoundArch(BoundArch),
349  HostOffloadKinds(OffloadKinds) {}
350 
351  /// Constructor version that obtains the offload kinds from the device
352  /// dependencies.
353  HostDependence(Action &A, const ToolChain &TC, const char *BoundArch,
354  const DeviceDependences &DDeps);
355  Action *getAction() const { return &HostAction; }
356  const ToolChain *getToolChain() const { return &HostToolChain; }
357  const char *getBoundArch() const { return HostBoundArch; }
358  unsigned getOffloadKinds() const { return HostOffloadKinds; }
359  };
360 
362  llvm::function_ref<void(Action *, const ToolChain *, const char *)>;
363 
364 private:
365  /// The host offloading toolchain that should be used with the action.
366  const ToolChain *HostTC = nullptr;
367 
368  /// The tool chains associated with the list of actions.
369  DeviceDependences::ToolChainList DevToolChains;
370 
371 public:
372  OffloadAction(const HostDependence &HDep);
373  OffloadAction(const DeviceDependences &DDeps, types::ID Ty);
374  OffloadAction(const HostDependence &HDep, const DeviceDependences &DDeps);
375 
376  /// Execute the work specified in \a Work on the host dependence.
377  void doOnHostDependence(const OffloadActionWorkTy &Work) const;
378 
379  /// Execute the work specified in \a Work on each device dependence.
380  void doOnEachDeviceDependence(const OffloadActionWorkTy &Work) const;
381 
382  /// Execute the work specified in \a Work on each dependence.
383  void doOnEachDependence(const OffloadActionWorkTy &Work) const;
384 
385  /// Execute the work specified in \a Work on each host or device dependence if
386  /// \a IsHostDependenceto is true or false, respectively.
387  void doOnEachDependence(bool IsHostDependence,
388  const OffloadActionWorkTy &Work) const;
389 
390  /// Return true if the action has a host dependence.
391  bool hasHostDependence() const;
392 
393  /// Return the host dependence of this action. This function is only expected
394  /// to be called if the host dependence exists.
395  Action *getHostDependence() const;
396 
397  /// Return true if the action has a single device dependence. If \a
398  /// DoNotConsiderHostActions is set, ignore the host dependence, if any, while
399  /// accounting for the number of dependences.
400  bool hasSingleDeviceDependence(bool DoNotConsiderHostActions = false) const;
401 
402  /// Return the single device dependence of this action. This function is only
403  /// expected to be called if a single device dependence exists. If \a
404  /// DoNotConsiderHostActions is set, a host dependence is allowed.
405  Action *
406  getSingleDeviceDependence(bool DoNotConsiderHostActions = false) const;
407 
408  static bool classof(const Action *A) { return A->getKind() == OffloadClass; }
409 };
410 
411 class JobAction : public Action {
412  virtual void anchor();
413 
414 protected:
415  JobAction(ActionClass Kind, Action *Input, types::ID Type);
416  JobAction(ActionClass Kind, const ActionList &Inputs, types::ID Type);
417 
418 public:
419  static bool classof(const Action *A) {
420  return (A->getKind() >= JobClassFirst &&
421  A->getKind() <= JobClassLast);
422  }
423 };
424 
426  void anchor() override;
427 
428 public:
429  PreprocessJobAction(Action *Input, types::ID OutputType);
430 
431  static bool classof(const Action *A) {
432  return A->getKind() == PreprocessJobClass;
433  }
434 };
435 
437  void anchor() override;
438 
439 protected:
440  PrecompileJobAction(ActionClass Kind, Action *Input, types::ID OutputType);
441 
442 public:
443  PrecompileJobAction(Action *Input, types::ID OutputType);
444 
445  static bool classof(const Action *A) {
446  return A->getKind() == PrecompileJobClass;
447  }
448 };
449 
451  void anchor() override;
452 
453 public:
454  ExtractAPIJobAction(Action *Input, types::ID OutputType);
455 
456  static bool classof(const Action *A) {
457  return A->getKind() == ExtractAPIJobClass;
458  }
459 
460  void addHeaderInput(Action *Input) { getInputs().push_back(Input); }
461 };
462 
463 class AnalyzeJobAction : public JobAction {
464  void anchor() override;
465 
466 public:
467  AnalyzeJobAction(Action *Input, types::ID OutputType);
468 
469  static bool classof(const Action *A) {
470  return A->getKind() == AnalyzeJobClass;
471  }
472 };
473 
474 class MigrateJobAction : public JobAction {
475  void anchor() override;
476 
477 public:
478  MigrateJobAction(Action *Input, types::ID OutputType);
479 
480  static bool classof(const Action *A) {
481  return A->getKind() == MigrateJobClass;
482  }
483 };
484 
485 class CompileJobAction : public JobAction {
486  void anchor() override;
487 
488 public:
489  CompileJobAction(Action *Input, types::ID OutputType);
490 
491  static bool classof(const Action *A) {
492  return A->getKind() == CompileJobClass;
493  }
494 };
495 
496 class BackendJobAction : public JobAction {
497  void anchor() override;
498 
499 public:
500  BackendJobAction(Action *Input, types::ID OutputType);
501 
502  static bool classof(const Action *A) {
503  return A->getKind() == BackendJobClass;
504  }
505 };
506 
507 class AssembleJobAction : public JobAction {
508  void anchor() override;
509 
510 public:
511  AssembleJobAction(Action *Input, types::ID OutputType);
512 
513  static bool classof(const Action *A) {
514  return A->getKind() == AssembleJobClass;
515  }
516 };
517 
518 class IfsMergeJobAction : public JobAction {
519  void anchor() override;
520 
521 public:
523 
524  static bool classof(const Action *A) {
525  return A->getKind() == IfsMergeJobClass;
526  }
527 };
528 
529 class LinkJobAction : public JobAction {
530  void anchor() override;
531 
532 public:
534 
535  static bool classof(const Action *A) {
536  return A->getKind() == LinkJobClass;
537  }
538 };
539 
540 class LipoJobAction : public JobAction {
541  void anchor() override;
542 
543 public:
545 
546  static bool classof(const Action *A) {
547  return A->getKind() == LipoJobClass;
548  }
549 };
550 
551 class DsymutilJobAction : public JobAction {
552  void anchor() override;
553 
554 public:
556 
557  static bool classof(const Action *A) {
558  return A->getKind() == DsymutilJobClass;
559  }
560 };
561 
562 class VerifyJobAction : public JobAction {
563  void anchor() override;
564 
565 public:
567 
568  static bool classof(const Action *A) {
569  return A->getKind() == VerifyDebugInfoJobClass ||
570  A->getKind() == VerifyPCHJobClass;
571  }
572 };
573 
575  void anchor() override;
576 
577 public:
579 
580  static bool classof(const Action *A) {
581  return A->getKind() == VerifyDebugInfoJobClass;
582  }
583 };
584 
586  void anchor() override;
587 
588 public:
590 
591  static bool classof(const Action *A) {
592  return A->getKind() == VerifyPCHJobClass;
593  }
594 };
595 
597  void anchor() override;
598 
599 public:
600  // Offloading bundling doesn't change the type of output.
602 
603  static bool classof(const Action *A) {
604  return A->getKind() == OffloadBundlingJobClass;
605  }
606 };
607 
608 class OffloadUnbundlingJobAction final : public JobAction {
609  void anchor() override;
610 
611 public:
612  /// Type that provides information about the actions that depend on this
613  /// unbundling action.
614  struct DependentActionInfo final {
615  /// The tool chain of the dependent action.
616  const ToolChain *DependentToolChain = nullptr;
617 
618  /// The bound architecture of the dependent action.
620 
621  /// The offload kind of the dependent action.
623 
625  StringRef DependentBoundArch,
630  };
631 
632  /// Allow for a complete override of the target to unbundle.
633  /// This is used for specific unbundles used for SYCL AOT when generating full
634  /// device files that are bundled with the host object.
635  void setTargetString(std::string Target) { TargetString = Target; }
636 
637  std::string getTargetString() const { return TargetString; }
638 
639 private:
640  /// Container that keeps information about each dependence of this unbundling
641  /// action.
642  SmallVector<DependentActionInfo, 6> DependentActionInfoArray;
643 
644  /// Provides a specific type to be used that overrides the input type.
645  types::ID DependentType = types::TY_Nothing;
646 
647  std::string TargetString;
648 
649 public:
650  // Offloading unbundling doesn't change the type of output.
654 
655  /// Register information about a dependent action.
656  void registerDependentActionInfo(const ToolChain *TC, StringRef BoundArch,
657  OffloadKind Kind) {
658  DependentActionInfoArray.push_back({TC, BoundArch, Kind});
659  }
660 
661  /// Return the information about all depending actions.
663  return DependentActionInfoArray;
664  }
665 
666  static bool classof(const Action *A) {
667  return A->getKind() == OffloadUnbundlingJobClass;
668  }
669 
670  /// Set the dependent type.
671  void setDependentType(types::ID Type) { DependentType = Type; }
672 
673  /// Get the dependent type.
674  types::ID getDependentType() const { return DependentType; }
675 };
676 
678  void anchor() override;
679 
680  bool EmbedIR;
681 
682 public:
684  OffloadWrapperJobAction(Action *Input, types::ID OutputType,
685  bool EmbedIR = false);
686 
687  bool isEmbeddedIR() const { return EmbedIR; }
688 
689  static bool classof(const Action *A) {
690  return A->getKind() == OffloadWrapperJobClass;
691  }
692 
693  // Set the compilation step setting. This is used to tell the wrapper job
694  // action that the compilation step to create the object should be performed
695  // after the wrapping step is complete.
696  void setCompileStep(bool SetValue) { CompileStep = SetValue; }
697 
698  // Get the compilation step setting.
699  bool getCompileStep() const { return CompileStep; }
700 
701  // Set the offload kind for the current wrapping job action. Default usage
702  // is to use the kind of the current toolchain.
703  void setOffloadKind(OffloadKind SetKind) { Kind = SetKind; }
704 
705  // Get the offload kind.
706  OffloadKind getOffloadKind() const { return Kind; }
707 
708 private:
709  bool CompileStep = true;
710  OffloadKind Kind = OFK_None;
711 };
712 
714  void anchor() override;
715 
716 public:
718 
719  static bool classof(const Action *A) {
720  return A->getKind() == OffloadPackagerJobClass;
721  }
722 };
723 
724 class OffloadDepsJobAction final : public JobAction {
725  void anchor() override;
726 
727 public:
728  /// Type that provides information about the actions that depend on this
729  /// offload deps action.
730  struct DependentActionInfo final {
731  /// The tool chain of the dependent action.
732  const ToolChain *DependentToolChain = nullptr;
733 
734  /// The bound architecture of the dependent action.
736 
737  /// The offload kind of the dependent action.
739 
741  StringRef DependentBoundArch,
746  };
747 
748 private:
749  /// The host offloading toolchain that should be used with the action.
750  const ToolChain *HostTC = nullptr;
751 
752  /// Container that keeps information about each dependence of this deps
753  /// action.
754  SmallVector<DependentActionInfo, 6> DependentActionInfoArray;
755 
756 public:
758  types::ID Type);
759 
760  /// Register information about a dependent action.
761  void registerDependentActionInfo(const ToolChain *TC, StringRef BoundArch,
762  OffloadKind Kind) {
763  DependentActionInfoArray.push_back({TC, BoundArch, Kind});
764  }
765 
766  /// Return the information about all depending actions.
768  return DependentActionInfoArray;
769  }
770 
771  const ToolChain *getHostTC() const { return HostTC; }
772 
773  static bool classof(const Action *A) {
774  return A->getKind() == OffloadDepsJobClass;
775  }
776 };
777 
779  void anchor() override;
780 
781 public:
782  SPIRVTranslatorJobAction(Action *Input, types::ID OutputType);
783 
784  static bool classof(const Action *A) {
785  return A->getKind() == SPIRVTranslatorJobClass;
786  }
787 };
788 
790  void anchor() override;
791 
792 public:
793  // The tempfiletable management relies on shadowing the main file type by
794  // types::TY_Tempfiletable. The problem of shadowing is it prevents its
795  // integration with clang tools that relies on the file type to properly set
796  // args.
797  // We "trick" the driver by declaring the underlying file type and set a
798  // "true output type" which will be used by the SYCLPostLinkJobAction
799  // to properly set the job.
800  SYCLPostLinkJobAction(Action *Input, types::ID ShadowOutputType,
801  types::ID TrueOutputType);
802 
803  static bool classof(const Action *A) {
804  return A->getKind() == SYCLPostLinkJobClass;
805  }
806 
807  void setRTSetsSpecConstants(bool Val) { RTSetsSpecConsts = Val; }
808 
809  bool getRTSetsSpecConstants() const { return RTSetsSpecConsts; }
810 
811  types::ID getTrueType() const { return TrueOutputType; }
812 
813 private:
814  bool RTSetsSpecConsts = true;
815  types::ID TrueOutputType;
816 };
817 
819  void anchor() override;
820 
821 public:
822  BackendCompileJobAction(ActionList &Inputs, types::ID OutputType);
823  BackendCompileJobAction(Action *Input, types::ID OutputType);
824 
825  static bool classof(const Action *A) {
826  return A->getKind() == BackendCompileJobClass;
827  }
828 };
829 
830 // Represents a file table transformation action. The order of inputs to a
831 // FileTableTformJobAction at construction time must accord with the tforms
832 // added later - some tforms "consume" inputs. For example, "replace column"
833 // needs another file to read the replacement column from.
835  void anchor() override;
836 
837 public:
838  static constexpr const char *COL_CODE = "Code";
839  static constexpr const char *COL_ZERO = "0";
840  static constexpr const char *COL_SYM_AND_PROPS = "SymAndProps";
841 
842  struct Tform {
843  enum Kind {
850  MERGE
851  };
852 
853  Tform() = default;
854  Tform(Kind K, std::initializer_list<StringRef> Args) : TheKind(K) {
855  for (auto &A : Args)
856  TheArgs.emplace_back(A.str());
857  }
858 
861  };
862 
863  FileTableTformJobAction(Action *Input, types::ID ShadowOutputType,
864  types::ID TrueOutputType);
865  FileTableTformJobAction(ActionList &Inputs, types::ID ShadowOutputType,
866  types::ID TrueOutputType);
867 
868  // Deletes all columns except the one with given name.
869  void addExtractColumnTform(StringRef ColumnName, bool WithColTitle = true);
870 
871  // Replaces a column with title <From> in this table with a column with title
872  // <To> from another file table passed as input to this action.
873  void addReplaceColumnTform(StringRef From, StringRef To);
874 
875  // Replaces a cell in this table with column title <ColumnName> and row <Row>
876  // with the file name passed as input to this action.
877  void addReplaceCellTform(StringRef ColumnName, int Row);
878 
879  // Renames a column with title <From> in this table with a column with title
880  // <To> passed as input to this action.
881  void addRenameColumnTform(StringRef From, StringRef To);
882 
883  // Specifies that, instead of generating a new table, the transformation
884  // should copy the file at column <ColumnName> and row <Row> into the
885  // output file.
886  void addCopySingleFileTform(StringRef ColumnName, int Row);
887 
888  // Merges all tables from filename listed at column <ColumnName> into a
889  // single output table.
890  void addMergeTform(StringRef ColumnName);
891 
892  static bool classof(const Action *A) {
893  return A->getKind() == FileTableTformJobClass;
894  }
895 
896  const ArrayRef<Tform> getTforms() const { return Tforms; }
897 
898  types::ID getTrueType() const { return TrueOutputType; }
899 
900 private:
901  types::ID TrueOutputType;
902  SmallVector<Tform, 2> Tforms; // transformation actions requested
903 
904  // column to copy single file from if requested
905  std::string CopySingleFileColumnName;
906 };
907 
909  void anchor() override;
910 
911 public:
913 
914  static bool classof(const Action *A) {
915  return A->getKind() == AppendFooterJobClass;
916  }
917 };
918 
920  void anchor() override;
921 
922 public:
924 
925  static bool classof(const Action *A) {
926  return A->getKind() == SpirvToIrWrapperJobClass;
927  }
928 };
929 
931  void anchor() override;
932 
933 public:
935 
936  static bool classof(const Action *A) {
937  return A->getKind() == LinkerWrapperJobClass;
938  }
939 };
940 
942  void anchor() override;
943 
944 public:
946 
947  static bool classof(const Action *A) {
948  return A->getKind() == StaticLibJobClass;
949  }
950 };
951 
952 /// Wrap all jobs performed between TFormInput (excluded) and Job (included)
953 /// behind a `llvm-foreach` call.
954 ///
955 /// Assumptions:
956 /// - No change of toolchain, boundarch and offloading kind should occur
957 /// within the sub-region;
958 /// - No job should produce multiple outputs;
959 /// - Results of action within the sub-region should not be used outside the
960 /// wrapped region.
961 /// Note: this doesn't bind to a tool directly and this need special casing
962 /// anyhow. Hence why this is an Action and not a JobAction, even if there is a
963 /// command behind.
965 public:
966  ForEachWrappingAction(JobAction *TFormInput, JobAction *Job);
967 
968  JobAction *getTFormInput() const;
969  JobAction *getJobAction() const;
970 
971  static bool classof(const Action *A) {
972  return A->getKind() == ForEachWrappingClass;
973  }
974 
975  void addSerialAction(const Action *A) { SerialActions.insert(A); }
977  return SerialActions;
978  }
979 
980 private:
982 };
983 
985  void anchor() override;
986 
987 public:
989 
990  static bool classof(const Action *A) {
991  return A->getKind() == BinaryAnalyzeJobClass;
992  }
993 };
994 
995 } // namespace driver
996 } // namespace clang
997 
998 #endif // LLVM_CLANG_DRIVER_ACTION_H
int Id
Definition: ASTDiff.cpp:190
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
llvm::MachO::Target Target
Definition: MachO.h:50
The base class of the type hierarchy.
Definition: Type.h:1813
Action - Represent an abstract compilation step to perform.
Definition: Action.h:49
void setHostOffloadInfo(unsigned OKinds, const char *OArch)
Definition: Action.h:209
input_const_iterator input_begin() const
Definition: Action.h:170
OffloadKind OffloadingDeviceKind
Offloading kind of the device.
Definition: Action.h:138
Action(ActionClass Kind, types::ID Type)
Definition: Action.h:146
size_type size() const
Definition: Action.h:165
bool isCollapsingWithNextDependentActionLegal() const
Return true if this function can be collapsed with others.
Definition: Action.h:182
types::ID getType() const
Definition: Action.h:160
void setCannotBeCollapsedWithNextDependentAction()
Mark this action as not legal to collapse.
Definition: Action.h:177
std::string getOffloadingKindPrefix() const
Return a string containing the offload kind of the action.
Definition: Action.cpp:122
ActionList::size_type size_type
Definition: Action.h:51
void propagateDeviceOffloadInfo(OffloadKind OKind, const char *OArch, const ToolChain *OToolChain)
Set the device offload info of this action and propagate it to its dependences.
Definition: Action.cpp:76
input_iterator input_end()
Definition: Action.h:168
const ToolChain * OffloadingToolChain
The Offloading toolchain associated with this device action.
Definition: Action.h:144
Action(ActionClass Kind, Action *Input, types::ID Type)
Definition: Action.h:147
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...
Definition: Action.cpp:165
Action(ActionClass Kind, Action *Input)
Definition: Action.h:149
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...
Definition: Action.cpp:113
ActionClass getKind() const
Definition: Action.h:159
ActionList::iterator input_iterator
Definition: Action.h:52
static StringRef GetOffloadKindName(OffloadKind Kind)
Return a string containing a offload kind name.
Definition: Action.cpp:181
input_const_range inputs() const
Definition: Action.h:172
OffloadKind getOffloadingDeviceKind() const
Definition: Action.h:222
input_const_iterator input_end() const
Definition: Action.h:171
const ActionList & getInputs() const
Definition: Action.h:163
input_iterator input_begin()
Definition: Action.h:167
void propagateHostOffloadInfo(unsigned OKinds, const char *OArch)
Append the host offload info of this action and propagate it to its dependences.
Definition: Action.cpp:99
const ToolChain * getOffloadingToolChain() const
Definition: Action.h:224
unsigned ActiveOffloadKindMask
Offload information.
Definition: Action.h:135
input_range inputs()
Definition: Action.h:169
Action(ActionClass Kind, const ActionList &Inputs, types::ID Type)
Definition: Action.h:151
bool isHostOffloading(unsigned int OKind) const
Check if this action have any offload kinds.
Definition: Action.h:230
bool isDeviceOffloading(OffloadKind OKind) const
Definition: Action.h:233
ActionList::const_iterator input_const_iterator
Definition: Action.h:53
const char * getClassName() const
Definition: Action.h:157
const char * OffloadingArch
The Offloading architecture associated with this action.
Definition: Action.h:141
ActionList & getInputs()
Definition: Action.h:162
const char * getOffloadingArch() const
Definition: Action.h:223
llvm::iterator_range< input_iterator > input_range
Definition: Action.h:54
llvm::iterator_range< input_const_iterator > input_const_range
Definition: Action.h:55
unsigned getOffloadingHostActiveKinds() const
Definition: Action.h:218
bool isOffloading(OffloadKind OKind) const
Definition: Action.h:236
static bool classof(const Action *A)
Definition: Action.h:469
AnalyzeJobAction(Action *Input, types::ID OutputType)
Definition: Action.cpp:394
AppendFooterJobAction(Action *Input, types::ID Type)
Definition: Action.cpp:575
static bool classof(const Action *A)
Definition: Action.h:914
AssembleJobAction(Action *Input, types::ID OutputType)
Definition: Action.cpp:414
static bool classof(const Action *A)
Definition: Action.h:513
static bool classof(const Action *A)
Definition: Action.h:825
BackendCompileJobAction(ActionList &Inputs, types::ID OutputType)
Definition: Action.cpp:519
static bool classof(const Action *A)
Definition: Action.h:502
BackendJobAction(Action *Input, types::ID OutputType)
Definition: Action.cpp:409
static bool classof(const Action *A)
Definition: Action.h:990
BinaryAnalyzeJobAction(Action *Input, types::ID Type)
Definition: Action.cpp:608
static bool classof(const Action *A)
Definition: Action.h:272
StringRef getArchName() const
Definition: Action.h:270
BindArchAction(Action *Input, StringRef ArchName)
Definition: Action.cpp:208
static bool classof(const Action *A)
Definition: Action.h:491
CompileJobAction(Action *Input, types::ID OutputType)
Definition: Action.cpp:404
DsymutilJobAction(ActionList &Inputs, types::ID Type)
Definition: Action.cpp:434
static bool classof(const Action *A)
Definition: Action.h:557
static bool classof(const Action *A)
Definition: Action.h:456
ExtractAPIJobAction(Action *Input, types::ID OutputType)
Definition: Action.cpp:389
void addHeaderInput(Action *Input)
Definition: Action.h:460
static constexpr const char * COL_SYM_AND_PROPS
Definition: Action.h:840
void addExtractColumnTform(StringRef ColumnName, bool WithColTitle=true)
Definition: Action.cpp:541
static constexpr const char * COL_CODE
Definition: Action.h:838
void addRenameColumnTform(StringRef From, StringRef To)
Definition: Action.cpp:558
const ArrayRef< Tform > getTforms() const
Definition: Action.h:896
static bool classof(const Action *A)
Definition: Action.h:892
void addReplaceCellTform(StringRef ColumnName, int Row)
Definition: Action.cpp:552
static constexpr const char * COL_ZERO
Definition: Action.h:839
void addReplaceColumnTform(StringRef From, StringRef To)
Definition: Action.cpp:547
void addCopySingleFileTform(StringRef ColumnName, int Row)
Definition: Action.cpp:563
void addMergeTform(StringRef ColumnName)
Definition: Action.cpp:569
FileTableTformJobAction(Action *Input, types::ID ShadowOutputType, types::ID TrueOutputType)
Definition: Action.cpp:529
Wrap all jobs performed between TFormInput (excluded) and Job (included) behind a llvm-foreach call.
Definition: Action.h:964
void addSerialAction(const Action *A)
Definition: Action.h:975
const llvm::SmallSetVector< const Action *, 2 > & getSerialActions() const
Definition: Action.h:976
ForEachWrappingAction(JobAction *TFormInput, JobAction *Job)
Definition: Action.cpp:595
static bool classof(const Action *A)
Definition: Action.h:971
JobAction * getJobAction() const
Definition: Action.cpp:603
JobAction * getTFormInput() const
Definition: Action.cpp:599
static bool classof(const Action *A)
Definition: Action.h:524
IfsMergeJobAction(ActionList &Inputs, types::ID Type)
Definition: Action.cpp:419
void setId(StringRef _Id)
Definition: Action.h:252
InputAction(const llvm::opt::Arg &Input, types::ID Type, StringRef Id=StringRef())
Definition: Action.cpp:203
const llvm::opt::Arg & getInputArg() const
Definition: Action.h:250
static bool classof(const Action *A)
Definition: Action.h:255
StringRef getId() const
Definition: Action.h:253
static bool classof(const Action *A)
Definition: Action.h:419
JobAction(ActionClass Kind, Action *Input, types::ID Type)
Definition: Action.cpp:365
static bool classof(const Action *A)
Definition: Action.h:535
LinkJobAction(ActionList &Inputs, types::ID Type)
Definition: Action.cpp:424
static bool classof(const Action *A)
Definition: Action.h:936
LinkerWrapperJobAction(ActionList &Inputs, types::ID Type)
Definition: Action.cpp:580
static bool classof(const Action *A)
Definition: Action.h:546
LipoJobAction(ActionList &Inputs, types::ID Type)
Definition: Action.cpp:429
static bool classof(const Action *A)
Definition: Action.h:480
MigrateJobAction(Action *Input, types::ID OutputType)
Definition: Action.cpp:399
Type used to communicate device actions.
Definition: Action.h:286
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.
Definition: Action.cpp:333
const BoundArchList & getBoundArchs() const
Definition: Action.h:324
const OffloadKindList & getOffloadKinds() const
Definition: Action.h:325
const ActionList & getActions() const
Get each of the individual arrays.
Definition: Action.h:322
const ToolChainList & getToolChains() const
Definition: Action.h:323
Type used to communicate host actions.
Definition: Action.h:332
HostDependence(Action &A, const ToolChain &TC, const char *BoundArch, const unsigned OffloadKinds)
Definition: Action.h:346
const ToolChain * getToolChain() const
Definition: Action.h:356
An offload action combines host or/and device actions according to the programming model implementati...
Definition: Action.h:280
void doOnEachDependence(const OffloadActionWorkTy &Work) const
Execute the work specified in Work on each dependence.
Definition: Action.cpp:296
Action * getSingleDeviceDependence(bool DoNotConsiderHostActions=false) const
Return the single device dependence of this action.
Definition: Action.cpp:325
bool hasSingleDeviceDependence(bool DoNotConsiderHostActions=false) const
Return true if the action has a single device dependence.
Definition: Action.cpp:317
Action * getHostDependence() const
Return the host dependence of this action.
Definition: Action.cpp:311
llvm::function_ref< void(Action *, const ToolChain *, const char *)> OffloadActionWorkTy
Definition: Action.h:362
void doOnEachDeviceDependence(const OffloadActionWorkTy &Work) const
Execute the work specified in Work on each device dependence.
Definition: Action.cpp:274
bool hasHostDependence() const
Return true if the action has a host dependence.
Definition: Action.cpp:309
static bool classof(const Action *A)
Definition: Action.h:408
void doOnHostDependence(const OffloadActionWorkTy &Work) const
Execute the work specified in Work on the host dependence.
Definition: Action.cpp:266
OffloadAction(const HostDependence &HDep)
Definition: Action.cpp:213
static bool classof(const Action *A)
Definition: Action.h:603
OffloadBundlingJobAction(ActionList &Inputs)
Definition: Action.cpp:459
static bool classof(const Action *A)
Definition: Action.h:773
void registerDependentActionInfo(const ToolChain *TC, StringRef BoundArch, OffloadKind Kind)
Register information about a dependent action.
Definition: Action.h:761
ArrayRef< DependentActionInfo > getDependentActionsInfo() const
Return the information about all depending actions.
Definition: Action.h:767
OffloadDepsJobAction(const OffloadAction::HostDependence &HDep, types::ID Type)
Definition: Action.cpp:493
const ToolChain * getHostTC() const
Definition: Action.h:771
OffloadPackagerJobAction(ActionList &Inputs, types::ID Type)
Definition: Action.cpp:487
static bool classof(const Action *A)
Definition: Action.h:719
void setDependentType(types::ID Type)
Set the dependent type.
Definition: Action.h:671
std::string getTargetString() const
Definition: Action.h:637
static bool classof(const Action *A)
Definition: Action.h:666
void registerDependentActionInfo(const ToolChain *TC, StringRef BoundArch, OffloadKind Kind)
Register information about a dependent action.
Definition: Action.h:656
void setTargetString(std::string Target)
Allow for a complete override of the target to unbundle.
Definition: Action.h:635
ArrayRef< DependentActionInfo > getDependentActionsInfo() const
Return the information about all depending actions.
Definition: Action.h:662
types::ID getDependentType() const
Get the dependent type.
Definition: Action.h:674
OffloadKind getOffloadKind() const
Definition: Action.h:706
static bool classof(const Action *A)
Definition: Action.h:689
void setCompileStep(bool SetValue)
Definition: Action.h:696
void setOffloadKind(OffloadKind SetKind)
Definition: Action.h:703
OffloadWrapperJobAction(ActionList &Inputs, types::ID Type)
Definition: Action.cpp:477
static bool classof(const Action *A)
Definition: Action.h:445
PrecompileJobAction(ActionClass Kind, Action *Input, types::ID OutputType)
Definition: Action.cpp:381
static bool classof(const Action *A)
Definition: Action.h:431
PreprocessJobAction(Action *Input, types::ID OutputType)
Definition: Action.cpp:373
static bool classof(const Action *A)
Definition: Action.h:784
SPIRVTranslatorJobAction(Action *Input, types::ID OutputType)
Definition: Action.cpp:505
static bool classof(const Action *A)
Definition: Action.h:803
void setRTSetsSpecConstants(bool Val)
Definition: Action.h:807
SYCLPostLinkJobAction(Action *Input, types::ID ShadowOutputType, types::ID TrueOutputType)
Definition: Action.cpp:511
types::ID getTrueType() const
Definition: Action.h:811
SpirvToIrWrapperJobAction(Action *Input, types::ID Type)
Definition: Action.cpp:591
static bool classof(const Action *A)
Definition: Action.h:925
StaticLibJobAction(ActionList &Inputs, types::ID Type)
Definition: Action.cpp:586
static bool classof(const Action *A)
Definition: Action.h:947
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:92
VerifyDebugInfoJobAction(Action *Input, types::ID Type)
Definition: Action.cpp:448
static bool classof(const Action *A)
Definition: Action.h:580
VerifyJobAction(ActionClass Kind, Action *Input, types::ID Type)
Definition: Action.cpp:439
static bool classof(const Action *A)
Definition: Action.h:568
static bool classof(const Action *A)
Definition: Action.h:591
VerifyPCHJobAction(Action *Input, types::ID Type)
Definition: Action.cpp:454
The JSON file list parser is used to communicate input to InstallAPI.
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
Tform(Kind K, std::initializer_list< StringRef > Args)
Definition: Action.h:854
SmallVector< std::string, 2 > TheArgs
Definition: Action.h:860
Type that provides information about the actions that depend on this offload deps action.
Definition: Action.h:730
DependentActionInfo(const ToolChain *DependentToolChain, StringRef DependentBoundArch, const OffloadKind DependentOffloadKind)
Definition: Action.h:740
const ToolChain * DependentToolChain
The tool chain of the dependent action.
Definition: Action.h:732
StringRef DependentBoundArch
The bound architecture of the dependent action.
Definition: Action.h:735
const OffloadKind DependentOffloadKind
The offload kind of the dependent action.
Definition: Action.h:738
Type that provides information about the actions that depend on this unbundling action.
Definition: Action.h:614
const OffloadKind DependentOffloadKind
The offload kind of the dependent action.
Definition: Action.h:622
DependentActionInfo(const ToolChain *DependentToolChain, StringRef DependentBoundArch, const OffloadKind DependentOffloadKind)
Definition: Action.h:624
StringRef DependentBoundArch
The bound architecture of the dependent action.
Definition: Action.h:619
const ToolChain * DependentToolChain
The tool chain of the dependent action.
Definition: Action.h:616