clang 24.0.0git
clang::driver::Compilation Class Reference

Compilation - A set of tasks to perform for a single driver invocation. More...

#include "clang/Driver/Compilation.h"

Public Types

using const_offload_toolchains_iterator
 Iterator that visits device toolchains of a given kind.
using const_offload_toolchains_range

Public Member Functions

 Compilation (const Driver &D, const ToolChain &DefaultToolChain, llvm::opt::InputArgList *Args, llvm::opt::DerivedArgList *TranslatedArgs, bool ContainsError)
 ~Compilation ()
const Driver & getDriver () const
const ToolChain & getDefaultToolChain () const
unsigned isOffloadingHostKind (Action::OffloadKind Kind) const
unsigned getActiveOffloadKinds () const
template<Action::OffloadKind Kind>
const_offload_toolchains_range getOffloadToolChains () const
const_offload_toolchains_range getOffloadToolChains (Action::OffloadKind Kind) const
template<Action::OffloadKind Kind>
bool hasOffloadToolChain () const
 Return true if an offloading tool chain of a given kind exists.
template<Action::OffloadKind Kind>
const ToolChain * getSingleOffloadToolChain () const
 Return an offload toolchain of the provided kind.
void addOffloadDeviceToolChain (const ToolChain *DeviceToolChain, Action::OffloadKind OffloadKind)
const llvm::opt::InputArgList & getInputArgs () const
const llvm::opt::DerivedArgList & getArgs () const
llvm::opt::DerivedArgList & getArgs ()
ActionList & getActions ()
const ActionList & getActions () const
template<typename T, typename... Args>
T * MakeAction (Args &&... Arg)
 Creates a new Action owned by this Compilation.
JobList & getJobs ()
const JobList & getJobs () const
void addCommand (std::unique_ptr< Command > Cmd)
BoundArch getCurrentBoundArch () const
void setCurrentBoundArch (BoundArch BA)
llvm::opt::ArgStringList & getTempFiles ()
const llvm::opt::ArgStringList & getTempFiles () const
const ArgStringMap & getResultFiles () const
const ArgStringMap & getFailureResultFiles () const
void setPostCallback (const std::function< void(const Command &, int)> &CB)
 Installs a handler that is executed when a compilation job is finished.
StringRef getSysRoot () const
 Returns the sysroot path.
const llvm::opt::DerivedArgList & getArgsForToolChain (const ToolChain *TC, BoundArch BA, Action::OffloadKind DeviceOffloadKind)
 getArgsForToolChain - Return the derived argument list for the tool chain TC (or the default tool chain, if TC is not specified).
void addIGCADevice (const ToolChain *TC, StringRef Target, StringRef Device)
 Add the Intel GPU Device to the GPUs of the IGCA target Target for the device toolchain TC.
ArrayRef< StringRef > getIGCADevices (const ToolChain *TC, StringRef Target) const
const char * addTempFile (const char *Name)
 addTempFile - Add a file to remove on exit, and returns its argument.
const char * addResultFile (const char *Name, const JobAction *JA)
 addResultFile - Add a file to remove on failure, and returns its argument.
const char * addFailureResultFile (const char *Name, const JobAction *JA)
 addFailureResultFile - Add a file to remove if we crash, and returns its argument.
const char * getTimeTraceFile (const JobAction *JA) const
void addTimeTraceFile (const char *Name, const JobAction *JA)
bool CleanupFile (const char *File, bool IssueErrors=false) const
 CleanupFile - Delete a given file.
bool CleanupFileList (const llvm::opt::ArgStringList &Files, bool IssueErrors=false) const
 CleanupFileList - Remove the files in the given list.
bool CleanupFileMap (const ArgStringMap &Files, const JobAction *JA, bool IssueErrors=false) const
 CleanupFileMap - Remove the files in the given map.
int ExecuteCommand (const Command &C, const Command *&FailingCommand, bool LogOnly=false) const
 ExecuteCommand - Execute an actual command.
void ExecuteJobs (const JobList &Jobs, SmallVectorImpl< std::pair< int, const Command * > > &FailingCommands, bool LogOnly=false) const
 ExecuteJob - Execute a single job.
void initCompilationForDiagnostics ()
 initCompilationForDiagnostics - Remove stale state and suppress output so compilation can be reexecuted to generate additional diagnostic information (e.g., preprocessed source(s)).
bool isForDiagnostics () const
 Return true if we're compiling for diagnostics.
bool containsError () const
 Return whether an error during the parsing of the input args.
void setContainsError ()
 Force driver to fail before toolchain is created.
void Redirect (ArrayRef< std::optional< StringRef > > Redirects)
 Redirect - Redirect output of this compilation.

Detailed Description

Compilation - A set of tasks to perform for a single driver invocation.

Definition at line 47 of file Compilation.h.

Member Typedef Documentation

◆ const_offload_toolchains_iterator

Initial value:
const std::multimap<Action::OffloadKind,
ToolChain - Access to tools for a single platform.
Definition ToolChain.h:92

Iterator that visits device toolchains of a given kind.

Definition at line 159 of file Compilation.h.

◆ const_offload_toolchains_range

Initial value:
const std::multimap< Action::OffloadKind, const ToolChain * >::const_iterator const_offload_toolchains_iterator
Iterator that visits device toolchains of a given kind.

Definition at line 162 of file Compilation.h.

Constructor & Destructor Documentation

◆ Compilation()

Compilation::Compilation ( const Driver & D,
const ToolChain & DefaultToolChain,
llvm::opt::InputArgList * Args,
llvm::opt::DerivedArgList * TranslatedArgs,
bool ContainsError )

Definition at line 40 of file Compilation.cpp.

References clang::driver::Action::OFK_Host.

◆ ~Compilation()

Compilation::~Compilation ( )

Definition at line 50 of file Compilation.cpp.

References CleanupFileList().

Member Function Documentation

◆ addCommand()

void clang::driver::Compilation::addCommand ( std::unique_ptr< Command > Cmd)
inline

Definition at line 227 of file Compilation.h.

◆ addFailureResultFile()

const char * clang::driver::Compilation::addFailureResultFile ( const char * Name,
const JobAction * JA )
inline

addFailureResultFile - Add a file to remove if we crash, and returns its argument.

Definition at line 292 of file Compilation.h.

◆ addIGCADevice()

void Compilation::addIGCADevice ( const ToolChain * TC,
StringRef Target,
StringRef Device )

Add the Intel GPU Device to the GPUs of the IGCA target Target for the device toolchain TC.

Definition at line 124 of file Compilation.cpp.

References clang::Device, and clang::Target.

◆ addOffloadDeviceToolChain()

void clang::driver::Compilation::addOffloadDeviceToolChain ( const ToolChain * DeviceToolChain,
Action::OffloadKind OffloadKind )
inline

◆ addResultFile()

const char * clang::driver::Compilation::addResultFile ( const char * Name,
const JobAction * JA )
inline

addResultFile - Add a file to remove on failure, and returns its argument.

Definition at line 285 of file Compilation.h.

◆ addTempFile()

const char * clang::driver::Compilation::addTempFile ( const char * Name)
inline

addTempFile - Add a file to remove on exit, and returns its argument.

Definition at line 278 of file Compilation.h.

◆ addTimeTraceFile()

void clang::driver::Compilation::addTimeTraceFile ( const char * Name,
const JobAction * JA )
inline

Definition at line 300 of file Compilation.h.

◆ CleanupFile()

bool Compilation::CleanupFile ( const char * File,
bool IssueErrors = false ) const

CleanupFile - Delete a given file.

Parameters
IssueErrors- Report failures as errors.
Returns
Whether the file was removed successfully.

Definition at line 140 of file Compilation.cpp.

References clang::driver::Driver::Diag(), clang::File, and getDriver().

Referenced by CleanupFileList(), and CleanupFileMap().

◆ CleanupFileList()

bool Compilation::CleanupFileList ( const llvm::opt::ArgStringList & Files,
bool IssueErrors = false ) const

CleanupFileList - Remove the files in the given list.

Parameters
IssueErrors- Report failures as errors.
Returns
Whether all files were removed successfully.

Definition at line 170 of file Compilation.cpp.

References CleanupFile(), clang::File, and clang::Success.

Referenced by initCompilationForDiagnostics(), and ~Compilation().

◆ CleanupFileMap()

bool Compilation::CleanupFileMap ( const ArgStringMap & Files,
const JobAction * JA,
bool IssueErrors = false ) const

CleanupFileMap - Remove the files in the given map.

Parameters
JA- If specified, only delete the files associated with this JobAction. Otherwise, delete all files in the map.
IssueErrors- Report failures as errors.
Returns
Whether all files were removed successfully.

Definition at line 178 of file Compilation.cpp.

References CleanupFile(), clang::File, and clang::Success.

◆ containsError()

bool clang::driver::Compilation::containsError ( ) const
inline

Return whether an error during the parsing of the input args.

Definition at line 358 of file Compilation.h.

◆ ExecuteCommand()

int Compilation::ExecuteCommand ( const Command & C,
const Command *& FailingCommand,
bool LogOnly = false ) const

ExecuteCommand - Execute an actual command.

Parameters
FailingCommand- For non-zero results, this will be set to the Command which failed, if any.
LogOnly- When true, only tries to log the command, not actually execute it.
Returns
The result code of the subprocess.

Definition at line 192 of file Compilation.cpp.

References clang::C, clang::driver::Driver::Diag(), clang::Error, getArgs(), and getDriver().

Referenced by ExecuteJobs().

◆ ExecuteJobs()

void Compilation::ExecuteJobs ( const JobList & Jobs,
SmallVectorImpl< std::pair< int, const Command * > > & FailingCommands,
bool LogOnly = false ) const

ExecuteJob - Execute a single job.

Parameters
FailingCommands- For non-zero results, this will be a vector of failing commands and their associated result code.
LogOnly- When true, only tries to log the command, not actually execute it.

Definition at line 388 of file Compilation.cpp.

References ActionFailed(), clang::driver::Driver::CCGenDiagnostics, clang::driver::Driver::CCPrintOptions, clang::driver::Driver::CCPrintProcessStats, ExecuteCommand(), getArgs(), getDriver(), clang::driver::Driver::IsCLMode(), and tryExecuteParallelOffloadJobGroup().

◆ getActions() [1/2]

ActionList & clang::driver::Compilation::getActions ( )
inline

Definition at line 212 of file Compilation.h.

Referenced by ignoreExtraCC1Commands().

◆ getActions() [2/2]

const ActionList & clang::driver::Compilation::getActions ( ) const
inline

Definition at line 213 of file Compilation.h.

◆ getActiveOffloadKinds()

unsigned clang::driver::Compilation::getActiveOffloadKinds ( ) const
inline

Definition at line 156 of file Compilation.h.

◆ getArgs() [1/2]

llvm::opt::DerivedArgList & clang::driver::Compilation::getArgs ( )
inline

Definition at line 210 of file Compilation.h.

◆ getArgs() [2/2]

const llvm::opt::DerivedArgList & clang::driver::Compilation::getArgs ( ) const
inline

Definition at line 208 of file Compilation.h.

Referenced by ExecuteCommand(), and ExecuteJobs().

◆ getArgsForToolChain()

const DerivedArgList & Compilation::getArgsForToolChain ( const ToolChain * TC,
BoundArch BA,
Action::OffloadKind DeviceOffloadKind )

getArgsForToolChain - Return the derived argument list for the tool chain TC (or the default tool chain, if TC is not specified).

If a device offloading kind is specified, a translation specific for that kind is performed, if any.

Parameters
BA- The bound architecture.
DeviceOffloadKind- The offload device kind that should be used in the translation, if any.

Definition at line 66 of file Compilation.cpp.

References getSingleOffloadToolChain(), clang::driver::ToolChain::getTriple(), clang::driver::Action::OFK_OpenMP, clang::driver::ToolChain::TranslateArgs(), clang::driver::ClangCLArgs::translateArgs(), clang::driver::ToolChain::TranslateOpenMPTargetArgs(), and clang::driver::ToolChain::TranslateXarchArgs().

◆ getCurrentBoundArch()

BoundArch clang::driver::Compilation::getCurrentBoundArch ( ) const
inline

Definition at line 232 of file Compilation.h.

◆ getDefaultToolChain()

const ToolChain & clang::driver::Compilation::getDefaultToolChain ( ) const
inline

Definition at line 150 of file Compilation.h.

◆ getDriver()

const Driver & clang::driver::Compilation::getDriver ( ) const
inline

Definition at line 148 of file Compilation.h.

Referenced by CleanupFile(), ExecuteCommand(), ExecuteJobs(), and getSysRoot().

◆ getFailureResultFiles()

const ArgStringMap & clang::driver::Compilation::getFailureResultFiles ( ) const
inline

Definition at line 240 of file Compilation.h.

◆ getIGCADevices()

ArrayRef< StringRef > Compilation::getIGCADevices ( const ToolChain * TC,
StringRef Target ) const
Returns
the Intel GPUs of the IGCA target Target for the device toolchain TC, sorted, or an empty list if there are none.

Definition at line 132 of file Compilation.cpp.

References clang::Target.

◆ getInputArgs()

const llvm::opt::InputArgList & clang::driver::Compilation::getInputArgs ( ) const
inline

Definition at line 206 of file Compilation.h.

◆ getJobs() [1/2]

JobList & clang::driver::Compilation::getJobs ( )
inline

Definition at line 224 of file Compilation.h.

Referenced by clang::tooling::getCC1Arguments(), and ignoreExtraCC1Commands().

◆ getJobs() [2/2]

const JobList & clang::driver::Compilation::getJobs ( ) const
inline

Definition at line 225 of file Compilation.h.

◆ getOffloadToolChains() [1/2]

template<Action::OffloadKind Kind>
const_offload_toolchains_range clang::driver::Compilation::getOffloadToolChains ( ) const
inline

Definition at line 167 of file Compilation.h.

Referenced by getSingleOffloadToolChain().

◆ getOffloadToolChains() [2/2]

const_offload_toolchains_range clang::driver::Compilation::getOffloadToolChains ( Action::OffloadKind Kind) const
inline

Definition at line 172 of file Compilation.h.

◆ getResultFiles()

const ArgStringMap & clang::driver::Compilation::getResultFiles ( ) const
inline

Definition at line 238 of file Compilation.h.

◆ getSingleOffloadToolChain()

template<Action::OffloadKind Kind>
const ToolChain * clang::driver::Compilation::getSingleOffloadToolChain ( ) const
inline

Return an offload toolchain of the provided kind.

Only one is expected to exist.

Definition at line 185 of file Compilation.h.

References getOffloadToolChains().

Referenced by getArgsForToolChain().

◆ getSysRoot()

StringRef Compilation::getSysRoot ( ) const

Returns the sysroot path.

Definition at line 471 of file Compilation.cpp.

References getDriver(), and clang::driver::Driver::SysRoot.

◆ getTempFiles() [1/2]

llvm::opt::ArgStringList & clang::driver::Compilation::getTempFiles ( )
inline

Definition at line 235 of file Compilation.h.

◆ getTempFiles() [2/2]

const llvm::opt::ArgStringList & clang::driver::Compilation::getTempFiles ( ) const
inline

Definition at line 236 of file Compilation.h.

◆ getTimeTraceFile()

const char * clang::driver::Compilation::getTimeTraceFile ( const JobAction * JA) const
inline

Definition at line 297 of file Compilation.h.

◆ hasOffloadToolChain()

template<Action::OffloadKind Kind>
bool clang::driver::Compilation::hasOffloadToolChain ( ) const
inline

Return true if an offloading tool chain of a given kind exists.

Definition at line 177 of file Compilation.h.

◆ initCompilationForDiagnostics()

void Compilation::initCompilationForDiagnostics ( )

initCompilationForDiagnostics - Remove stale state and suppress output so compilation can be reexecuted to generate additional diagnostic information (e.g., preprocessed source(s)).

Definition at line 428 of file Compilation.cpp.

References CleanupFileList().

◆ isForDiagnostics()

bool clang::driver::Compilation::isForDiagnostics ( ) const
inline

Return true if we're compiling for diagnostics.

Definition at line 355 of file Compilation.h.

◆ isOffloadingHostKind()

unsigned clang::driver::Compilation::isOffloadingHostKind ( Action::OffloadKind Kind) const
inline

Definition at line 152 of file Compilation.h.

◆ MakeAction()

template<typename T, typename... Args>
T * clang::driver::Compilation::MakeAction ( Args &&... Arg)
inline

Creates a new Action owned by this Compilation.

The new Action is not added to the list returned by getActions().

Definition at line 218 of file Compilation.h.

References clang::T.

◆ Redirect()

void Compilation::Redirect ( ArrayRef< std::optional< StringRef > > Redirects)

Redirect - Redirect output of this compilation.

Can only be done once.

Parameters
Redirects- array of optional paths. The array should have a size of three. The inferior process's stdin(0), stdout(1), and stderr(2) will be redirected to the corresponding paths, if provided (not std::nullopt).

Definition at line 475 of file Compilation.cpp.

◆ setContainsError()

void clang::driver::Compilation::setContainsError ( )
inline

Force driver to fail before toolchain is created.

This is necessary when error happens in action builder.

Definition at line 362 of file Compilation.h.

◆ setCurrentBoundArch()

void clang::driver::Compilation::setCurrentBoundArch ( BoundArch BA)
inline

Definition at line 233 of file Compilation.h.

◆ setPostCallback()

void clang::driver::Compilation::setPostCallback ( const std::function< void(const Command &, int)> & CB)
inline

Installs a handler that is executed when a compilation job is finished.

The arguments of the callback specify the compilation job as an instance of class Command and the exit status of the child process executed that job.

Definition at line 248 of file Compilation.h.

References std::function.


The documentation for this class was generated from the following files: