9#ifndef LLVM_CLANG_DRIVER_COMPILATION_H
10#define LLVM_CLANG_DRIVER_COMPILATION_H
16#include "llvm/ADT/ArrayRef.h"
17#include "llvm/ADT/DenseMap.h"
18#include "llvm/ADT/StringRef.h"
19#include "llvm/Option/Option.h"
54 unsigned ActiveOffloadMask = 0;
60 std::multimap<Action::OffloadKind, const ToolChain *>
61 OrderedOffloadingToolchains;
64 llvm::opt::InputArgList *Args;
68 llvm::opt::DerivedArgList *TranslatedArgs;
72 std::vector<std::unique_ptr<Action>> AllActions;
83 struct TCArgsKey final {
88 TCArgsKey(
const ToolChain *TC, StringRef BoundArch,
90 : TC(TC), BoundArch(BoundArch), DeviceOffloadKind(DeviceOffloadKind) {}
92 bool operator<(
const TCArgsKey &K)
const {
95 else if (TC == K.TC && BoundArch < K.BoundArch)
97 else if (TC == K.TC && BoundArch == K.BoundArch &&
98 DeviceOffloadKind < K.DeviceOffloadKind)
103 std::map<TCArgsKey, llvm::opt::DerivedArgList *> TCArgs;
106 llvm::opt::ArgStringList TempFiles;
119 std::vector<std::optional<StringRef>> Redirects;
124 std::function<void(
const Command &,
int)> PostCallback;
127 bool ForDiagnostics =
false;
133 bool ForceKeepTempFiles =
false;
137 llvm::opt::InputArgList *Args,
138 llvm::opt::DerivedArgList *TranslatedArgs,
bool ContainsError);
146 return ActiveOffloadMask &
Kind;
159 template <Action::OffloadKind Kind>
161 return OrderedOffloadingToolchains.equal_range(
Kind);
166 return OrderedOffloadingToolchains.equal_range(
Kind);
171 return OrderedOffloadingToolchains.find(
Kind) !=
172 OrderedOffloadingToolchains.end();
177 template <Action::OffloadKind Kind>
179 auto TCs = getOffloadToolChains<Kind>();
181 assert(TCs.first != TCs.second &&
182 "No tool chains of the selected kind exist!");
183 assert(std::next(TCs.first) == TCs.second &&
184 "More than one tool chain of the this kind exist.");
185 return TCs.first->second;
191 "This is not a device tool chain!");
194 ActiveOffloadMask |= OffloadKind;
195 OrderedOffloadingToolchains.insert(
196 std::make_pair(OffloadKind, DeviceToolChain));
201 const llvm::opt::DerivedArgList &
getArgs()
const {
return *TranslatedArgs; }
203 llvm::opt::DerivedArgList &
getArgs() {
return *TranslatedArgs; }
211 template <
typename T,
typename... Args>
T *
MakeAction(Args &&... Arg) {
212 T *RawPtr =
new T(std::forward<Args>(Arg)...);
213 AllActions.push_back(std::unique_ptr<Action>(RawPtr));
223 const llvm::opt::ArgStringList &
getTempFiles()
const {
return TempFiles; }
228 return FailureResultFiles;
250 const llvm::opt::DerivedArgList &
257 TempFiles.push_back(Name);
264 ResultFiles[JA] = Name;
271 FailureResultFiles[JA] = Name;
276 return TimeTraceFiles.lookup(JA);
279 assert(!TimeTraceFiles.contains(JA));
280 TimeTraceFiles[JA] = Name;
294 bool IssueErrors =
false)
const;
304 bool IssueErrors =
false)
const;
314 bool LogOnly =
false)
const;
325 bool LogOnly =
false)
const;
enum clang::sema::@1655::IndirectLocalPathEntry::EntryKind Kind
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Command - An executable path/name and argument vector to execute.
Compilation - A set of tasks to perform for a single driver invocation.
bool hasOffloadToolChain() const
Return true if an offloading tool chain of a given kind exists.
const llvm::opt::DerivedArgList & getArgsForToolChain(const ToolChain *TC, StringRef BoundArch, Action::OffloadKind DeviceOffloadKind)
getArgsForToolChain - Return the derived argument list for the tool chain TC (or the default tool cha...
const JobList & getJobs() const
int ExecuteCommand(const Command &C, const Command *&FailingCommand, bool LogOnly=false) const
ExecuteCommand - Execute an actual command.
llvm::opt::ArgStringList & getTempFiles()
bool CleanupFileMap(const ArgStringMap &Files, const JobAction *JA, bool IssueErrors=false) const
CleanupFileMap - Remove the files in the given map.
const ActionList & getActions() const
void setPostCallback(const std::function< void(const Command &, int)> &CB)
Installs a handler that is executed when a compilation job is finished.
ActionList & getActions()
const_offload_toolchains_range getOffloadToolChains(Action::OffloadKind Kind) const
bool CleanupFile(const char *File, bool IssueErrors=false) const
CleanupFile - Delete a given file.
const ArgStringMap & getFailureResultFiles() const
llvm::opt::DerivedArgList & getArgs()
const char * getTimeTraceFile(const JobAction *JA) const
unsigned isOffloadingHostKind(Action::OffloadKind Kind) const
T * MakeAction(Args &&... Arg)
Creates a new Action owned by this Compilation.
bool CleanupFileList(const llvm::opt::ArgStringList &Files, bool IssueErrors=false) const
CleanupFileList - Remove the files in the given list.
const ArgStringMap & getResultFiles() const
StringRef getSysRoot() const
Returns the sysroot path.
void setContainsError()
Force driver to fail before toolchain is created.
const_offload_toolchains_range getOffloadToolChains() const
unsigned getActiveOffloadKinds() const
const char * addFailureResultFile(const char *Name, const JobAction *JA)
addFailureResultFile - Add a file to remove if we crash, and returns its argument.
const std::multimap< Action::OffloadKind, const ToolChain * >::const_iterator const_offload_toolchains_iterator
Iterator that visits device toolchains of a given kind.
void Redirect(ArrayRef< std::optional< StringRef > > Redirects)
Redirect - Redirect output of this compilation.
const ToolChain & getDefaultToolChain() const
const char * addResultFile(const char *Name, const JobAction *JA)
addResultFile - Add a file to remove on failure, and returns its argument.
void addOffloadDeviceToolChain(const ToolChain *DeviceToolChain, Action::OffloadKind OffloadKind)
void initCompilationForDiagnostics()
initCompilationForDiagnostics - Remove stale state and suppress output so compilation can be reexecut...
void addCommand(std::unique_ptr< Command > C)
const char * addTempFile(const char *Name)
addTempFile - Add a file to remove on exit, and returns its argument.
const llvm::opt::InputArgList & getInputArgs() const
const llvm::opt::ArgStringList & getTempFiles() const
void addTimeTraceFile(const char *Name, const JobAction *JA)
const llvm::opt::DerivedArgList & getArgs() const
std::pair< const_offload_toolchains_iterator, const_offload_toolchains_iterator > const_offload_toolchains_range
void ExecuteJobs(const JobList &Jobs, SmallVectorImpl< std::pair< int, const Command * > > &FailingCommands, bool LogOnly=false) const
ExecuteJob - Execute a single job.
bool containsError() const
Return whether an error during the parsing of the input args.
bool isForDiagnostics() const
Return true if we're compiling for diagnostics.
const ToolChain * getSingleOffloadToolChain() const
Return an offload toolchain of the provided kind.
const Driver & getDriver() const
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
JobList - A sequence of jobs to perform.
void addJob(std::unique_ptr< Command > J)
Add a job to the list (taking ownership).
llvm::DenseMap< const JobAction *, const char * > ArgStringMap
ArgStringMap - Type used to map a JobAction to its result file.
The JSON file list parser is used to communicate input to InstallAPI.
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
const FunctionProtoType * T
Diagnostic wrappers for TextAPI types for error reporting.