Changeset View
Changeset View
Standalone View
Standalone View
include/clang/Driver/Action.h
Show All 26 Lines | |||||
/// | /// | ||||
/// An action represents an edge in the compilation graph; typically | /// An action represents an edge in the compilation graph; typically | ||||
/// it is a job to transform an input using some tool. | /// it is a job to transform an input using some tool. | ||||
/// | /// | ||||
/// The current driver is hard wired to expect actions which produce a | /// The current driver is hard wired to expect actions which produce a | ||||
/// single primary output, at least in terms of controlling the | /// single primary output, at least in terms of controlling the | ||||
/// compilation. Actions can produce auxiliary files, but can only | /// compilation. Actions can produce auxiliary files, but can only | ||||
/// produce a single output to feed into subsequent actions. | /// produce a single output to feed into subsequent actions. | ||||
/// | |||||
/// An Action keeps a std::shared_ptr to each of its inputs (in an | |||||
tra: There's no API to pass ownership to Compilation explicitly, so the only way for an Action to be… | |||||
Not Done ReplyInline ActionsUpdated the comment. jlebar: Updated the comment. | |||||
/// ActionList). Using shared_ptrs lets us manage graphs of Actions that | |||||
/// are DAGs. | |||||
class Action { | class Action { | ||||
public: | public: | ||||
typedef ActionList::size_type size_type; | typedef ActionList::size_type size_type; | ||||
typedef ActionList::iterator iterator; | typedef ActionList::iterator iterator; | ||||
typedef ActionList::const_iterator const_iterator; | typedef ActionList::const_iterator const_iterator; | ||||
enum ActionClass { | enum ActionClass { | ||||
InputClass = 0, | InputClass = 0, | ||||
Show All 22 Lines | |||||
private: | private: | ||||
ActionClass Kind; | ActionClass Kind; | ||||
/// The output type of this action. | /// The output type of this action. | ||||
types::ID Type; | types::ID Type; | ||||
ActionList Inputs; | ActionList Inputs; | ||||
unsigned OwnsInputs : 1; | |||||
protected: | protected: | ||||
Action(ActionClass Kind, types::ID Type) | Action(ActionClass Kind, types::ID Type) : Action(Kind, ActionList(), Type) {} | ||||
: Kind(Kind), Type(Type), OwnsInputs(true) {} | Action(ActionClass Kind, std::shared_ptr<Action> Input, types::ID Type) | ||||
Action(ActionClass Kind, std::unique_ptr<Action> Input, types::ID Type) | : Action(Kind, ActionList({Input}), Type) {} | ||||
: Kind(Kind), Type(Type), Inputs(1, Input.release()), OwnsInputs(true) { | Action(ActionClass Kind, std::shared_ptr<Action> Input) | ||||
} | : Action(Kind, ActionList({Input}), Input->getType()) {} | ||||
Action(ActionClass Kind, std::unique_ptr<Action> Input) | |||||
: Kind(Kind), Type(Input->getType()), Inputs(1, Input.release()), | |||||
OwnsInputs(true) {} | |||||
Action(ActionClass Kind, const ActionList &Inputs, types::ID Type) | Action(ActionClass Kind, const ActionList &Inputs, types::ID Type) | ||||
: Kind(Kind), Type(Type), Inputs(Inputs), OwnsInputs(true) {} | : Kind(Kind), Type(Type), Inputs(Inputs) {} | ||||
public: | public: | ||||
virtual ~Action(); | virtual ~Action(); | ||||
const char *getClassName() const { return Action::getClassName(getKind()); } | const char *getClassName() const { return Action::getClassName(getKind()); } | ||||
bool getOwnsInputs() { return OwnsInputs; } | |||||
void setOwnsInputs(bool Value) { OwnsInputs = Value; } | |||||
ActionClass getKind() const { return Kind; } | ActionClass getKind() const { return Kind; } | ||||
types::ID getType() const { return Type; } | types::ID getType() const { return Type; } | ||||
ActionList &getInputs() { return Inputs; } | ActionList &getInputs() { return Inputs; } | ||||
const ActionList &getInputs() const { return Inputs; } | const ActionList &getInputs() const { return Inputs; } | ||||
size_type size() const { return Inputs.size(); } | size_type size() const { return Inputs.size(); } | ||||
Show All 19 Lines | |||||
class BindArchAction : public Action { | class BindArchAction : public Action { | ||||
virtual void anchor(); | virtual void anchor(); | ||||
/// The architecture to bind, or 0 if the default architecture | /// The architecture to bind, or 0 if the default architecture | ||||
/// should be bound. | /// should be bound. | ||||
const char *ArchName; | const char *ArchName; | ||||
public: | public: | ||||
BindArchAction(std::unique_ptr<Action> Input, const char *ArchName); | BindArchAction(std::shared_ptr<Action> Input, const char *ArchName); | ||||
const char *getArchName() const { return ArchName; } | const char *getArchName() const { return ArchName; } | ||||
static bool classof(const Action *A) { | static bool classof(const Action *A) { | ||||
return A->getKind() == BindArchClass; | return A->getKind() == BindArchClass; | ||||
} | } | ||||
}; | }; | ||||
class CudaDeviceAction : public Action { | class CudaDeviceAction : public Action { | ||||
virtual void anchor(); | virtual void anchor(); | ||||
/// GPU architecture to bind -- e.g 'sm_35'. | /// GPU architecture to bind -- e.g 'sm_35'. | ||||
const char *GpuArchName; | const char *GpuArchName; | ||||
/// True when action results are not consumed by the host action (e.g when | /// True when action results are not consumed by the host action (e.g when | ||||
/// -fsyntax-only or --cuda-device-only options are used). | /// -fsyntax-only or --cuda-device-only options are used). | ||||
bool AtTopLevel; | bool AtTopLevel; | ||||
public: | public: | ||||
CudaDeviceAction(std::unique_ptr<Action> Input, const char *ArchName, | CudaDeviceAction(std::shared_ptr<Action> Input, const char *ArchName, | ||||
bool AtTopLevel); | bool AtTopLevel); | ||||
const char *getGpuArchName() const { return GpuArchName; } | const char *getGpuArchName() const { return GpuArchName; } | ||||
bool isAtTopLevel() const { return AtTopLevel; } | bool isAtTopLevel() const { return AtTopLevel; } | ||||
static bool classof(const Action *A) { | static bool classof(const Action *A) { | ||||
return A->getKind() == CudaDeviceClass; | return A->getKind() == CudaDeviceClass; | ||||
} | } | ||||
}; | }; | ||||
class CudaHostAction : public Action { | class CudaHostAction : public Action { | ||||
virtual void anchor(); | virtual void anchor(); | ||||
ActionList DeviceActions; | ActionList DeviceActions; | ||||
public: | public: | ||||
CudaHostAction(std::unique_ptr<Action> Input, | CudaHostAction(std::shared_ptr<Action> Input, | ||||
const ActionList &DeviceActions); | const ActionList &DeviceActions); | ||||
~CudaHostAction() override; | |||||
const ActionList &getDeviceActions() const { return DeviceActions; } | const ActionList &getDeviceActions() const { return DeviceActions; } | ||||
static bool classof(const Action *A) { return A->getKind() == CudaHostClass; } | static bool classof(const Action *A) { return A->getKind() == CudaHostClass; } | ||||
}; | }; | ||||
class JobAction : public Action { | class JobAction : public Action { | ||||
virtual void anchor(); | virtual void anchor(); | ||||
protected: | protected: | ||||
JobAction(ActionClass Kind, std::unique_ptr<Action> Input, types::ID Type); | JobAction(ActionClass Kind, std::shared_ptr<Action> Input, types::ID Type); | ||||
JobAction(ActionClass Kind, const ActionList &Inputs, types::ID Type); | JobAction(ActionClass Kind, const ActionList &Inputs, types::ID Type); | ||||
public: | public: | ||||
static bool classof(const Action *A) { | static bool classof(const Action *A) { | ||||
return (A->getKind() >= JobClassFirst && | return (A->getKind() >= JobClassFirst && | ||||
A->getKind() <= JobClassLast); | A->getKind() <= JobClassLast); | ||||
} | } | ||||
}; | }; | ||||
class PreprocessJobAction : public JobAction { | class PreprocessJobAction : public JobAction { | ||||
void anchor() override; | void anchor() override; | ||||
public: | public: | ||||
PreprocessJobAction(std::unique_ptr<Action> Input, types::ID OutputType); | PreprocessJobAction(std::shared_ptr<Action> Input, types::ID OutputType); | ||||
static bool classof(const Action *A) { | static bool classof(const Action *A) { | ||||
return A->getKind() == PreprocessJobClass; | return A->getKind() == PreprocessJobClass; | ||||
} | } | ||||
}; | }; | ||||
class PrecompileJobAction : public JobAction { | class PrecompileJobAction : public JobAction { | ||||
void anchor() override; | void anchor() override; | ||||
public: | public: | ||||
PrecompileJobAction(std::unique_ptr<Action> Input, types::ID OutputType); | PrecompileJobAction(std::shared_ptr<Action> Input, types::ID OutputType); | ||||
static bool classof(const Action *A) { | static bool classof(const Action *A) { | ||||
return A->getKind() == PrecompileJobClass; | return A->getKind() == PrecompileJobClass; | ||||
} | } | ||||
}; | }; | ||||
class AnalyzeJobAction : public JobAction { | class AnalyzeJobAction : public JobAction { | ||||
void anchor() override; | void anchor() override; | ||||
public: | public: | ||||
AnalyzeJobAction(std::unique_ptr<Action> Input, types::ID OutputType); | AnalyzeJobAction(std::shared_ptr<Action> Input, types::ID OutputType); | ||||
static bool classof(const Action *A) { | static bool classof(const Action *A) { | ||||
return A->getKind() == AnalyzeJobClass; | return A->getKind() == AnalyzeJobClass; | ||||
} | } | ||||
}; | }; | ||||
class MigrateJobAction : public JobAction { | class MigrateJobAction : public JobAction { | ||||
void anchor() override; | void anchor() override; | ||||
public: | public: | ||||
MigrateJobAction(std::unique_ptr<Action> Input, types::ID OutputType); | MigrateJobAction(std::shared_ptr<Action> Input, types::ID OutputType); | ||||
static bool classof(const Action *A) { | static bool classof(const Action *A) { | ||||
return A->getKind() == MigrateJobClass; | return A->getKind() == MigrateJobClass; | ||||
} | } | ||||
}; | }; | ||||
class CompileJobAction : public JobAction { | class CompileJobAction : public JobAction { | ||||
void anchor() override; | void anchor() override; | ||||
public: | public: | ||||
CompileJobAction(std::unique_ptr<Action> Input, types::ID OutputType); | CompileJobAction(std::shared_ptr<Action> Input, types::ID OutputType); | ||||
static bool classof(const Action *A) { | static bool classof(const Action *A) { | ||||
return A->getKind() == CompileJobClass; | return A->getKind() == CompileJobClass; | ||||
} | } | ||||
}; | }; | ||||
class BackendJobAction : public JobAction { | class BackendJobAction : public JobAction { | ||||
void anchor() override; | void anchor() override; | ||||
public: | public: | ||||
BackendJobAction(std::unique_ptr<Action> Input, types::ID OutputType); | BackendJobAction(std::shared_ptr<Action> Input, types::ID OutputType); | ||||
static bool classof(const Action *A) { | static bool classof(const Action *A) { | ||||
return A->getKind() == BackendJobClass; | return A->getKind() == BackendJobClass; | ||||
} | } | ||||
}; | }; | ||||
class AssembleJobAction : public JobAction { | class AssembleJobAction : public JobAction { | ||||
void anchor() override; | void anchor() override; | ||||
public: | public: | ||||
AssembleJobAction(std::unique_ptr<Action> Input, types::ID OutputType); | AssembleJobAction(std::shared_ptr<Action> Input, types::ID OutputType); | ||||
static bool classof(const Action *A) { | static bool classof(const Action *A) { | ||||
return A->getKind() == AssembleJobClass; | return A->getKind() == AssembleJobClass; | ||||
} | } | ||||
}; | }; | ||||
class LinkJobAction : public JobAction { | class LinkJobAction : public JobAction { | ||||
void anchor() override; | void anchor() override; | ||||
Show All 23 Lines | public: | ||||
static bool classof(const Action *A) { | static bool classof(const Action *A) { | ||||
return A->getKind() == DsymutilJobClass; | return A->getKind() == DsymutilJobClass; | ||||
} | } | ||||
}; | }; | ||||
class VerifyJobAction : public JobAction { | class VerifyJobAction : public JobAction { | ||||
void anchor() override; | void anchor() override; | ||||
public: | public: | ||||
VerifyJobAction(ActionClass Kind, std::unique_ptr<Action> Input, | VerifyJobAction(ActionClass Kind, std::shared_ptr<Action> Input, | ||||
types::ID Type); | types::ID Type); | ||||
static bool classof(const Action *A) { | static bool classof(const Action *A) { | ||||
return A->getKind() == VerifyDebugInfoJobClass || | return A->getKind() == VerifyDebugInfoJobClass || | ||||
A->getKind() == VerifyPCHJobClass; | A->getKind() == VerifyPCHJobClass; | ||||
} | } | ||||
}; | }; | ||||
class VerifyDebugInfoJobAction : public VerifyJobAction { | class VerifyDebugInfoJobAction : public VerifyJobAction { | ||||
void anchor() override; | void anchor() override; | ||||
public: | public: | ||||
VerifyDebugInfoJobAction(std::unique_ptr<Action> Input, types::ID Type); | VerifyDebugInfoJobAction(std::shared_ptr<Action> Input, types::ID Type); | ||||
static bool classof(const Action *A) { | static bool classof(const Action *A) { | ||||
return A->getKind() == VerifyDebugInfoJobClass; | return A->getKind() == VerifyDebugInfoJobClass; | ||||
} | } | ||||
}; | }; | ||||
class VerifyPCHJobAction : public VerifyJobAction { | class VerifyPCHJobAction : public VerifyJobAction { | ||||
void anchor() override; | void anchor() override; | ||||
public: | public: | ||||
VerifyPCHJobAction(std::unique_ptr<Action> Input, types::ID Type); | VerifyPCHJobAction(std::shared_ptr<Action> Input, types::ID Type); | ||||
static bool classof(const Action *A) { | static bool classof(const Action *A) { | ||||
return A->getKind() == VerifyPCHJobClass; | return A->getKind() == VerifyPCHJobClass; | ||||
} | } | ||||
}; | }; | ||||
} // end namespace driver | } // end namespace driver | ||||
} // end namespace clang | } // end namespace clang | ||||
#endif | #endif |
There's no API to pass ownership to Compilation explicitly, so the only way for an Action to be owned by Compilation is to create it with MakeAction.
Perhaps "Actions created with MakeAction<>() are owned by Compilation"
BTW, should we (can we?) make MakeAction<>() the only way to create actions?