Go to the documentation of this file.
9 #ifndef LLVM_CLANG_DRIVER_DRIVER_H
10 #define LLVM_CLANG_DRIVER_DRIVER_H
23 #include "llvm/ADT/ArrayRef.h"
24 #include "llvm/ADT/StringMap.h"
25 #include "llvm/ADT/StringRef.h"
26 #include "llvm/Option/Arg.h"
27 #include "llvm/Option/ArgList.h"
28 #include "llvm/Support/StringSaver.h"
41 class ExpansionContext;
96 enum BitcodeEmbedMode {
113 bool ModulesModeCXX20;
144 return Diags.
Report(DiagID);
206 using InputTy = std::pair<types::ID, const llvm::opt::Arg *>;
218 bool CCCIsCC()
const {
return Mode == GCCMode; }
275 std::vector<std::string> ConfigFiles;
278 llvm::BumpPtrAllocator Alloc;
281 llvm::StringSaver Saver;
284 std::unique_ptr<llvm::opt::InputArgList> CfgOptions;
287 std::unique_ptr<llvm::opt::InputArgList> CLOptions;
291 unsigned CheckInputsExist : 1;
294 unsigned ProbePrecompiled : 1;
303 llvm::opt::Arg **FinalPhaseArg =
nullptr)
const;
307 unsigned SuppressMissingInputWarning : 1;
314 mutable llvm::StringMap<std::unique_ptr<ToolChain>> ToolChains;
319 llvm::DenseMap<const ToolChain *, llvm::DenseSet<llvm::StringRef>> KnownArchs;
324 llvm::opt::DerivedArgList *
325 TranslateInputArgs(
const llvm::opt::InputArgList &Args)
const;
329 void handleArguments(
Compilation &C, llvm::opt::DerivedArgList &Args,
335 void generatePrefixedToolNames(StringRef
Tool,
const ToolChain &TC,
349 bool getCrashDiagnosticFile(StringRef ReproCrashFilename,
357 StringRef CustomResourceDir =
"");
377 llvm::vfs::FileSystem &
getVFS()
const {
return *VFS; }
441 bool &ContainsError);
478 llvm::opt::DerivedArgList &Args,
480 Action *HostAction)
const;
488 bool SuppressError =
false)
const;
496 bool TypoCorrect)
const;
524 StringRef AdditionalInformation =
"",
542 const Command &FailingCommand, StringRef AdditionalInformation =
"",
544 if (
static_cast<int>(CS) >
static_cast<int>(
Level))
547 Diags.
Report(diag::err_drv_force_crash)
548 << !::getenv(
"FORCE_CLANG_DIAGNOSTICS_CRASH");
611 bool AtTopLevel,
bool MultipleArchs,
const char *LinkingOutput,
612 std::map<std::pair<const Action *, std::string>,
InputInfoList>
621 bool MultipleArchs =
false,
622 StringRef BoundArch = {})
const;
637 const char *BaseInput, StringRef BoundArch,
638 bool AtTopLevel,
bool MultipleArchs,
639 StringRef NormalizedTriple)
const;
678 return IsOffload ? OffloadLTOMode : LTOMode;
686 bool loadConfigFiles();
692 bool loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx);
699 bool readConfigFile(StringRef FileName, llvm::cl::ExpansionContext &ExpCtx);
703 void setDriverMode(StringRef DriverModeValue);
707 void setLTOMode(
const llvm::opt::ArgList &Args);
713 const ToolChain &getToolChain(
const llvm::opt::ArgList &Args,
714 const llvm::Triple &Target)
const;
728 const ToolChain &getOffloadingDeviceToolChain(
729 const llvm::opt::ArgList &Args,
const llvm::Triple &Target,
735 std::pair<unsigned, unsigned> getIncludeExcludeOptionFlagMasks(
bool IsClCompatMode)
const;
742 bool AtTopLevel,
bool MultipleArchs,
const char *LinkingOutput,
743 std::map<std::pair<const Action *, std::string>,
InputInfoList>
748 static const char *getExecutableForDriverMode(DriverMode Mode);
759 unsigned &Micro,
bool &HadExtra);
SmallVector< InputTy, 16 > InputList
A list of inputs and their types for the given arguments.
bool embedBitcodeEnabled() const
InputInfoList BuildJobsForAction(Compilation &C, const Action *A, const ToolChain *TC, StringRef BoundArch, bool AtTopLevel, bool MultipleArchs, const char *LinkingOutput, std::map< std::pair< const Action *, std::string >, InputInfoList > &CachedResults, Action::OffloadKind TargetDeviceOffloadKind) const
BuildJobsForAction - Construct the jobs to perform for the action A and return an InputInfo for the r...
std::string GetProgramPath(StringRef Name, const ToolChain &TC) const
GetProgramPath - Lookup Name in the list of program search paths.
YAML serialization mapping.
bool isOptimizationLevelFast(const llvm::opt::ArgList &Args)
const char * GetNamedOutputPath(Compilation &C, const JobAction &JA, const char *BaseInput, StringRef BoundArch, bool AtTopLevel, bool MultipleArchs, StringRef NormalizedTriple) const
GetNamedOutputPath - Return the name to use for the output of the action JA.
A little helper class used to produce diagnostics.
Helper structure used to pass information extracted from clang executable name such as i686-linux-and...
bool getCheckInputsExist() const
Contains the files in the compilation diagnostic report generated by generateCompilationDiagnostics.
std::string Dir
The path the driver executable was in, as invoked from the command line.
bool DiagnoseInputExistence(const llvm::opt::DerivedArgList &Args, StringRef Value, types::ID Ty, bool TypoCorrect) const
Check that the file referenced by Value exists.
void PrintVersion(const Compilation &C, raw_ostream &OS) const
PrintVersion - Print the driver version.
bool IsCLMode() const
Whether the driver should follow cl.exe like behavior.
bool hasHeaderMode() const
Returns true if the user has indicated a C++20 header unit mode.
Action - Represent an abstract compilation step to perform.
bool maybeGenerateCompilationDiagnostics(CommandStatus CS, ReproLevel Level, Compilation &C, const Command &FailingCommand, StringRef AdditionalInformation="", CompilationDiagnosticReport *GeneratedReport=nullptr)
void generateCompilationDiagnostics(Compilation &C, const Command &FailingCommand, StringRef AdditionalInformation="", CompilationDiagnosticReport *GeneratedReport=nullptr)
generateCompilationDiagnostics - Generate diagnostics information including preprocessed source file(...
ModuleHeaderMode getModuleHeaderMode() const
Get the mode for handling headers as set by fmodule-header{=}.
Concrete class used by the front-end to report problems and issues.
ID
ID - Ordered values for successive stages in the compilation process which interact with user options...
bool embedBitcodeInObject() const
std::pair< types::ID, const llvm::opt::Arg * > InputTy
An input type and its arguments.
SmallVector< InputInfo, 4 > InputInfoList
std::string CCPrintOptionsFilename
The file to log CC_PRINT_OPTIONS output to, if enabled.
void BuildActions(Compilation &C, llvm::opt::DerivedArgList &Args, const InputList &Inputs, ActionList &Actions) const
BuildActions - Construct the list of actions to perform for the given arguments, which are only done ...
static bool getDefaultModuleCachePath(SmallVectorImpl< char > &Result)
Compute the default -fmodule-cache-path.
void setLastDiagnosticIgnored(bool Ignored)
Pretend that the last diagnostic issued was ignored, so any subsequent notes will be suppressed,...
OpenMPRuntimeKind getOpenMPRuntime(const llvm::opt::ArgList &Args) const
Compute the desired OpenMP runtime from the flags provided.
const llvm::opt::OptTable & getOpts() const
DiagnosticsEngine & getDiags() const
void PrintActions(const Compilation &C) const
PrintActions - Print the list of actions.
std::string InstalledDir
The path to the installed clang directory, if any.
std::string DriverTitle
Driver title to use with help.
bool isSaveTempsEnabled() const
LTOKind getLTOMode(bool IsOffload=false) const
Get the specific kind of LTO being performed.
DiagnosticBuilder Diag(unsigned DiagID) const
llvm::ArrayRef< std::string > getConfigFiles() const
unsigned CCCPrintBindings
Only print tool bindings, don't build any jobs.
const llvm::opt::OptTable & getDriverOptTable()
bool CCCIsCC() const
Whether the driver should follow gcc like behavior.
Action * ConstructPhaseAction(Compilation &C, const llvm::opt::ArgList &Args, phases::ID Phase, Action *Input, Action::OffloadKind TargetDeviceOffloadKind=Action::OFK_None) const
ConstructAction - Construct the appropriate action to do for Phase on the Input, taking in to account...
bool CCCIsCPP() const
Whether the driver is just the preprocessor.
unsigned CCPrintOptions
Set CC_PRINT_OPTIONS mode, which is like -v but logs the commands to CCPrintOptionsFilename or to std...
std::string Name
The name the driver was invoked as.
llvm::opt::InputArgList ParseArgStrings(ArrayRef< const char * > Args, bool IsClCompatMode, bool &ContainsError)
ParseArgStrings - Parse the given list of strings into an ArgList.
std::string HostBits
Information about the host which can be overridden by the user.
std::string SystemConfigDir
System directory for config files.
HeaderIncludeFormatKind CCPrintHeadersFormat
The format of the header information that is emitted.
Driver(StringRef ClangExecutable, StringRef TargetTriple, DiagnosticsEngine &Diags, std::string Title="clang LLVM compiler", IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS=nullptr)
Action * BuildOffloadingActions(Compilation &C, llvm::opt::DerivedArgList &Args, const InputTy &Input, Action *HostAction) const
BuildOffloadingActions - Construct the list of actions to perform for the offloading toolchain that w...
@ OMPRT_IOMP5
The legacy name for the LLVM OpenMP runtime from when it was the Intel OpenMP runtime.
std::string SysRoot
sysroot, if present
bool ShouldEmitStaticLibrary(const llvm::opt::ArgList &Args) const
ShouldEmitStaticLibrary - Should the linker emit a static library.
bool CCCIsCXX() const
Whether the driver should follow g++ like behavior.
@ OMPRT_OMP
The LLVM OpenMP runtime.
const std::string & getCCCGenericGCCName() const
Name to use when invoking gcc/g++.
const std::string & getTitle()
bool offloadDeviceOnly() const
unsigned CCLogDiagnostics
Set CC_LOG_DIAGNOSTICS mode, which causes the frontend to log diagnostics to CCLogDiagnosticsFilename...
int(* CC1ToolFunc)(SmallVectorImpl< const char * > &ArgV)
Pointer to the ExecuteCC1Tool function, if available.
std::string ResourceDir
The path to the compiler resource directory.
int ExecuteCompilation(Compilation &C, SmallVectorImpl< std::pair< int, const Command * > > &FailingCommands)
ExecuteCompilation - Execute the compilation according to the command line arguments and return an ap...
const char * getClangProgramPath() const
Get the path to the main clang executable.
phases::ID getFinalPhase(const llvm::opt::DerivedArgList &DAL, llvm::opt::Arg **FinalPhaseArg=nullptr) const
void CreateOffloadingDeviceToolChains(Compilation &C, InputList &Inputs)
CreateOffloadingDeviceToolChains - create all the toolchains required to support offloading devices g...
Command - An executable path/name and argument vector to execute.
bool embedBitcodeMarkerOnly() const
LTOKind
Describes the kind of LTO mode selected via -f(no-)?lto(=.*)? options.
std::string CCPrintStatReportFilename
The file to log CC_PRINT_PROC_STAT_FILE output to, if enabled.
bool isUsingLTO(bool IsOffload=false) const
Returns true if we are performing any kind of LTO.
ParsedClangName ClangNameParts
Target and driver mode components extracted from clang executable name.
bool ShouldUseFlangCompiler(const JobAction &JA) const
ShouldUseFlangCompiler - Should the flang compiler be used to handle this action.
bool isSaveTempsObj() const
std::string GetClPchPath(Compilation &C, StringRef BaseName) const
Return the pathname of the pch file in clang-cl mode.
std::string GetTemporaryPath(StringRef Prefix, StringRef Suffix) const
GetTemporaryPath - Return the pathname of a temporary file to use as part of compilation; the file wi...
bool IsDXCMode() const
Whether the driver should follow dxc.exe like behavior.
const char * getDefaultImageName() const
Returns the default name for linked images (e.g., "a.out").
const char * CreateTempFile(Compilation &C, StringRef Prefix, StringRef Suffix, bool MultipleArchs=false, StringRef BoundArch={}) const
SmallVector< std::string, 4 > prefix_list
A prefix directory used to emulate a limited subset of GCC's '-Bprefix' functionality.
std::string UserConfigDir
User directory for config files.
static std::string GetResourcesPath(StringRef BinaryPath, StringRef CustomResourceDir="")
Takes the path to a binary that's either in bin/ or lib/ and returns the path to clang's resource dir...
void setTargetAndMode(const ParsedClangName &TM)
void BuildJobs(Compilation &C) const
BuildJobs - Bind actions to concrete tools and translate arguments to form the list of jobs to run.
Compilation - A set of tasks to perform for a single driver invocation.
std::string CCLogDiagnosticsFilename
The file to log CC_LOG_DIAGNOSTICS output to, if enabled.
std::string GetFilePath(StringRef Name, const ToolChain &TC) const
GetFilePath - Lookup Name in the list of file search paths.
bool willEmitRemarks(const llvm::opt::ArgList &Args)
void setProbePrecompiled(bool Value)
llvm::SmallVector< std::string, 4 > TemporaryFiles
HeaderIncludeFilteringKind CCPrintHeadersFiltering
This flag determines whether clang should filter the header information that is emitted.
void setInstalledDir(StringRef Value)
ModuleHeaderMode
Whether headers used to construct C++20 module units should be looked up by the path supplied on the ...
bool offloadHostOnly() const
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
std::string getTargetTriple() const
bool ShouldUseClangCompiler(const JobAction &JA) const
ShouldUseClangCompiler - Should the clang compiler be used to handle this action.
std::string CCPrintHeadersFilename
The file to log CC_PRINT_HEADERS output to, if enabled.
@ OMPRT_Unknown
An unknown OpenMP runtime.
std::string GetTemporaryDirectory(StringRef Prefix) const
GetTemporaryDirectory - Return the pathname of a temporary directory to use as part of compilation; t...
bool IsClangCL(StringRef DriverMode)
Checks whether the value produced by getDriverMode is for CL mode.
llvm::vfs::FileSystem & getVFS() const
void setTitle(std::string Value)
bool HandleImmediateArgs(const Compilation &C)
HandleImmediateArgs - Handle any arguments which should be treated before building actions or binding...
llvm::StringRef getDriverMode(StringRef ProgName, ArrayRef< const char * > Args)
Returns the driver mode option's value, i.e.
void PrintHelp(bool ShowHidden) const
PrintHelp - Print the help text.
@ OMPRT_GOMP
The GNU OpenMP runtime.
llvm::DenseSet< StringRef > getOffloadArchs(Compilation &C, const llvm::opt::DerivedArgList &Args, Action::OffloadKind Kind, const ToolChain *TC, bool SuppressError=false) const
Returns the set of bound architectures active for this offload kind.
std::string DyldPrefix
Dynamic loader prefix, if present.
bool getProbePrecompiled() const
void BuildInputs(const ToolChain &TC, llvm::opt::DerivedArgList &Args, InputList &Inputs) const
BuildInputs - Construct the list of inputs and their types from the given arguments.
static bool GetReleaseVersion(StringRef Str, unsigned &Major, unsigned &Minor, unsigned &Micro, bool &HadExtra)
GetReleaseVersion - Parse (([0-9]+)(.
HeaderIncludeFormatKind
The format in which header information is emitted.
std::string ClangExecutable
The original path to the clang executable.
unsigned CCPrintProcessStats
Set CC_PRINT_PROC_STAT mode, which causes the driver to dump performance report to CC_PRINT_PROC_STAT...
void HandleAutocompletions(StringRef PassedFlags) const
HandleAutocompletions - Handle –autocomplete by searching and printing possible flags,...
const char * getInstalledDir() const
Get the path to where the clang executable was installed.
bool IsFlangMode() const
Whether the driver should invoke flang for fortran inputs.
void setCheckInputsExist(bool Value)
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
HeaderIncludeFilteringKind
Whether header information is filtered or not.
void BuildUniversalActions(Compilation &C, const ToolChain &TC, const InputList &BAInputs) const
BuildUniversalActions - Construct the list of actions to perform for the given arguments,...
Compilation * BuildCompilation(ArrayRef< const char * > Args)
BuildCompilation - Construct a compilation object for a command line argument vector.
unsigned CCGenDiagnostics
Whether the driver is generating diagnostics for debugging purposes.