clang  3.8.0
Action.h
Go to the documentation of this file.
1 //===--- Action.h - Abstract compilation steps ------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_CLANG_DRIVER_ACTION_H
11 #define LLVM_CLANG_DRIVER_ACTION_H
12 
13 #include "clang/Driver/Types.h"
14 #include "clang/Driver/Util.h"
15 #include "llvm/ADT/SmallVector.h"
16 
17 namespace llvm {
18 
19 class StringRef;
20 
21 namespace opt {
22  class Arg;
23 }
24 }
25 
26 namespace clang {
27 namespace driver {
28 
29 /// Action - Represent an abstract compilation step to perform.
30 ///
31 /// An action represents an edge in the compilation graph; typically
32 /// it is a job to transform an input using some tool.
33 ///
34 /// The current driver is hard wired to expect actions which produce a
35 /// single primary output, at least in terms of controlling the
36 /// compilation. Actions can produce auxiliary files, but can only
37 /// produce a single output to feed into subsequent actions.
38 ///
39 /// Actions are usually owned by a Compilation, which creates new
40 /// actions via MakeAction().
41 class Action {
42 public:
43  typedef ActionList::size_type size_type;
45  typedef ActionList::const_iterator const_iterator;
46 
47  enum ActionClass {
64 
67  };
68 
69  static const char *getClassName(ActionClass AC);
70 
71 private:
73 
74  /// The output type of this action.
76 
77  ActionList Inputs;
78 
79 protected:
82  : Action(Kind, ActionList({Input}), Type) {}
84  : Action(Kind, ActionList({Input}), Input->getType()) {}
85  Action(ActionClass Kind, const ActionList &Inputs, types::ID Type)
86  : Kind(Kind), Type(Type), Inputs(Inputs) {}
87 
88 public:
89  virtual ~Action();
90 
91  const char *getClassName() const { return Action::getClassName(getKind()); }
92 
93  ActionClass getKind() const { return Kind; }
94  types::ID getType() const { return Type; }
95 
96  ActionList &getInputs() { return Inputs; }
97  const ActionList &getInputs() const { return Inputs; }
98 
99  size_type size() const { return Inputs.size(); }
100 
101  iterator begin() { return Inputs.begin(); }
102  iterator end() { return Inputs.end(); }
103  const_iterator begin() const { return Inputs.begin(); }
104  const_iterator end() const { return Inputs.end(); }
105 };
106 
107 class InputAction : public Action {
108  virtual void anchor();
109  const llvm::opt::Arg &Input;
110 
111 public:
112  InputAction(const llvm::opt::Arg &Input, types::ID Type);
113 
114  const llvm::opt::Arg &getInputArg() const { return Input; }
115 
116  static bool classof(const Action *A) {
117  return A->getKind() == InputClass;
118  }
119 };
120 
121 class BindArchAction : public Action {
122  virtual void anchor();
123  /// The architecture to bind, or 0 if the default architecture
124  /// should be bound.
125  const char *ArchName;
126 
127 public:
128  BindArchAction(Action *Input, const char *ArchName);
129 
130  const char *getArchName() const { return ArchName; }
131 
132  static bool classof(const Action *A) {
133  return A->getKind() == BindArchClass;
134  }
135 };
136 
137 class CudaDeviceAction : public Action {
138  virtual void anchor();
139  /// GPU architecture to bind. Always of the form /sm_\d+/.
140  const char *GpuArchName;
141  /// True when action results are not consumed by the host action (e.g when
142  /// -fsyntax-only or --cuda-device-only options are used).
143  bool AtTopLevel;
144 
145 public:
146  CudaDeviceAction(Action *Input, const char *ArchName, bool AtTopLevel);
147 
148  const char *getGpuArchName() const { return GpuArchName; }
149 
150  /// Gets the compute_XX that corresponds to getGpuArchName().
151  const char *getComputeArchName() const;
152 
153  bool isAtTopLevel() const { return AtTopLevel; }
154 
155  static bool IsValidGpuArchName(llvm::StringRef ArchName);
156 
157  static bool classof(const Action *A) {
158  return A->getKind() == CudaDeviceClass;
159  }
160 };
161 
162 class CudaHostAction : public Action {
163  virtual void anchor();
164  ActionList DeviceActions;
165 
166 public:
167  CudaHostAction(Action *Input, const ActionList &DeviceActions);
168 
169  const ActionList &getDeviceActions() const { return DeviceActions; }
170 
171  static bool classof(const Action *A) { return A->getKind() == CudaHostClass; }
172 };
173 
174 class JobAction : public Action {
175  virtual void anchor();
176 protected:
178  JobAction(ActionClass Kind, const ActionList &Inputs, types::ID Type);
179 
180 public:
181  static bool classof(const Action *A) {
182  return (A->getKind() >= JobClassFirst &&
183  A->getKind() <= JobClassLast);
184  }
185 };
186 
188  void anchor() override;
189 public:
191 
192  static bool classof(const Action *A) {
193  return A->getKind() == PreprocessJobClass;
194  }
195 };
196 
198  void anchor() override;
199 public:
201 
202  static bool classof(const Action *A) {
203  return A->getKind() == PrecompileJobClass;
204  }
205 };
206 
207 class AnalyzeJobAction : public JobAction {
208  void anchor() override;
209 public:
210  AnalyzeJobAction(Action *Input, types::ID OutputType);
211 
212  static bool classof(const Action *A) {
213  return A->getKind() == AnalyzeJobClass;
214  }
215 };
216 
217 class MigrateJobAction : public JobAction {
218  void anchor() override;
219 public:
220  MigrateJobAction(Action *Input, types::ID OutputType);
221 
222  static bool classof(const Action *A) {
223  return A->getKind() == MigrateJobClass;
224  }
225 };
226 
227 class CompileJobAction : public JobAction {
228  void anchor() override;
229 public:
230  CompileJobAction(Action *Input, types::ID OutputType);
231 
232  static bool classof(const Action *A) {
233  return A->getKind() == CompileJobClass;
234  }
235 };
236 
237 class BackendJobAction : public JobAction {
238  void anchor() override;
239 public:
240  BackendJobAction(Action *Input, types::ID OutputType);
241 
242  static bool classof(const Action *A) {
243  return A->getKind() == BackendJobClass;
244  }
245 };
246 
247 class AssembleJobAction : public JobAction {
248  void anchor() override;
249 public:
250  AssembleJobAction(Action *Input, types::ID OutputType);
251 
252  static bool classof(const Action *A) {
253  return A->getKind() == AssembleJobClass;
254  }
255 };
256 
257 class LinkJobAction : public JobAction {
258  void anchor() override;
259 public:
261 
262  static bool classof(const Action *A) {
263  return A->getKind() == LinkJobClass;
264  }
265 };
266 
267 class LipoJobAction : public JobAction {
268  void anchor() override;
269 public:
271 
272  static bool classof(const Action *A) {
273  return A->getKind() == LipoJobClass;
274  }
275 };
276 
277 class DsymutilJobAction : public JobAction {
278  void anchor() override;
279 public:
281 
282  static bool classof(const Action *A) {
283  return A->getKind() == DsymutilJobClass;
284  }
285 };
286 
287 class VerifyJobAction : public JobAction {
288  void anchor() override;
289 public:
291  static bool classof(const Action *A) {
292  return A->getKind() == VerifyDebugInfoJobClass ||
293  A->getKind() == VerifyPCHJobClass;
294  }
295 };
296 
298  void anchor() override;
299 public:
301  static bool classof(const Action *A) {
302  return A->getKind() == VerifyDebugInfoJobClass;
303  }
304 };
305 
307  void anchor() override;
308 public:
310  static bool classof(const Action *A) {
311  return A->getKind() == VerifyPCHJobClass;
312  }
313 };
314 
315 } // end namespace driver
316 } // end namespace clang
317 
318 #endif
AssembleJobAction(Action *Input, types::ID OutputType)
Definition: Action.cpp:135
PrecompileJobAction(Action *Input, types::ID OutputType)
Definition: Action.cpp:110
BackendJobAction(Action *Input, types::ID OutputType)
Definition: Action.cpp:130
static bool classof(const Action *A)
Definition: Action.h:192
Action(ActionClass Kind, Action *Input, types::ID Type)
Definition: Action.h:81
bool isAtTopLevel() const
Definition: Action.h:153
const char * getGpuArchName() const
Definition: Action.h:148
MigrateJobAction(Action *Input, types::ID OutputType)
Definition: Action.cpp:120
size_type size() const
Definition: Action.h:99
static bool classof(const Action *A)
Definition: Action.h:116
static bool classof(const Action *A)
Definition: Action.h:157
const ActionList & getDeviceActions() const
Definition: Action.h:169
The base class of the type hierarchy.
Definition: Type.h:1249
static bool classof(const Action *A)
Definition: Action.h:232
LinkJobAction(ActionList &Inputs, types::ID Type)
Definition: Action.cpp:140
Action(ActionClass Kind, types::ID Type)
Definition: Action.h:80
ActionList::iterator iterator
Definition: Action.h:44
iterator begin()
Definition: Action.h:101
InputAction(const llvm::opt::Arg &Input, types::ID Type)
Definition: Action.cpp:45
types::ID getType() const
Definition: Action.h:94
VerifyJobAction(ActionClass Kind, Action *Input, types::ID Type)
Definition: Action.cpp:158
const char * getComputeArchName() const
Gets the compute_XX that corresponds to getGpuArchName().
Definition: Action.cpp:81
VerifyDebugInfoJobAction(Action *Input, types::ID Type)
Definition: Action.cpp:167
CompileJobAction(Action *Input, types::ID OutputType)
Definition: Action.cpp:125
CudaDeviceAction(Action *Input, const char *ArchName, bool AtTopLevel)
Definition: Action.cpp:74
JobAction(ActionClass Kind, Action *Input, types::ID Type)
Definition: Action.cpp:96
ActionList & getInputs()
Definition: Action.h:96
LipoJobAction(ActionList &Inputs, types::ID Type)
Definition: Action.cpp:146
static bool classof(const Action *A)
Definition: Action.h:282
const_iterator end() const
Definition: Action.h:104
ActionClass getKind() const
Definition: Action.h:93
Action - Represent an abstract compilation step to perform.
Definition: Action.h:41
static bool classof(const Action *A)
Definition: Action.h:181
static bool IsValidGpuArchName(llvm::StringRef ArchName)
Definition: Action.cpp:85
static bool classof(const Action *A)
Definition: Action.h:262
ActionList::size_type size_type
Definition: Action.h:43
DsymutilJobAction(ActionList &Inputs, types::ID Type)
Definition: Action.cpp:152
PreprocessJobAction(Action *Input, types::ID OutputType)
Definition: Action.cpp:105
static bool classof(const Action *A)
Definition: Action.h:301
static bool classof(const Action *A)
Definition: Action.h:202
virtual ~Action()
Definition: Action.cpp:18
static bool classof(const Action *A)
Definition: Action.h:242
VerifyPCHJobAction(Action *Input, types::ID Type)
Definition: Action.cpp:173
static bool classof(const Action *A)
Definition: Action.h:310
const llvm::opt::Arg & getInputArg() const
Definition: Action.h:114
CudaHostAction(Action *Input, const ActionList &DeviceActions)
Definition: Action.cpp:91
iterator end()
Definition: Action.h:102
ActionList::const_iterator const_iterator
Definition: Action.h:45
const ActionList & getInputs() const
Definition: Action.h:97
Kind
const TemplateArgument * iterator
Definition: Type.h:4070
static bool classof(const Action *A)
Definition: Action.h:252
AnalyzeJobAction(Action *Input, types::ID OutputType)
Definition: Action.cpp:115
const char * getArchName() const
Definition: Action.h:130
SmallVector< Action *, 3 > ActionList
ActionList - Type used for lists of actions.
Definition: Util.h:27
static bool classof(const Action *A)
Definition: Action.h:272
const char * getClassName() const
Definition: Action.h:91
const_iterator begin() const
Definition: Action.h:103
BindArchAction(Action *Input, const char *ArchName)
Definition: Action.cpp:51
static bool classof(const Action *A)
Definition: Action.h:212
const StringRef Input
static bool classof(const Action *A)
Definition: Action.h:171
static bool classof(const Action *A)
Definition: Action.h:222
static bool classof(const Action *A)
Definition: Action.h:132
static bool classof(const Action *A)
Definition: Action.h:291