Go to the documentation of this file.
9 #ifndef LLVM_CLANG_DRIVER_DRIVER_H
10 #define LLVM_CLANG_DRIVER_DRIVER_H
22 #include "llvm/ADT/StringMap.h"
23 #include "llvm/ADT/StringRef.h"
24 #include "llvm/Option/Arg.h"
25 #include "llvm/Option/ArgList.h"
26 #include "llvm/Support/StringSaver.h"
92 enum BitcodeEmbedMode {
109 bool ModulesModeCXX20;
140 return Diags.
Report(DiagID);
202 using InputTy = std::pair<types::ID, const llvm::opt::Arg *>;
214 bool CCCIsCC()
const {
return Mode == GCCMode; }
267 llvm::BumpPtrAllocator Alloc;
270 llvm::StringSaver Saver;
273 std::unique_ptr<llvm::opt::InputArgList> CfgOptions;
276 std::unique_ptr<llvm::opt::InputArgList> CLOptions;
280 unsigned CheckInputsExist : 1;
283 unsigned ProbePrecompiled : 1;
292 llvm::opt::Arg **FinalPhaseArg =
nullptr)
const;
296 unsigned SuppressMissingInputWarning : 1;
303 mutable llvm::StringMap<std::unique_ptr<ToolChain>> ToolChains;
308 llvm::DenseMap<const ToolChain *, llvm::DenseSet<llvm::StringRef>> KnownArchs;
313 llvm::opt::DerivedArgList *
314 TranslateInputArgs(
const llvm::opt::InputArgList &Args)
const;
318 void handleArguments(
Compilation &C, llvm::opt::DerivedArgList &Args,
324 void generatePrefixedToolNames(StringRef
Tool,
const ToolChain &TC,
338 bool getCrashDiagnosticFile(StringRef ReproCrashFilename,
346 StringRef CustomResourceDir =
"");
364 llvm::vfs::FileSystem &
getVFS()
const {
return *VFS; }
428 bool &ContainsError);
465 llvm::opt::DerivedArgList &Args,
467 Action *HostAction)
const;
482 bool TypoCorrect)
const;
510 StringRef AdditionalInformation =
"",
528 const Command &FailingCommand, StringRef AdditionalInformation =
"",
530 if (
static_cast<int>(CS) >
static_cast<int>(
Level))
533 Diags.
Report(diag::err_drv_force_crash)
534 << !::getenv(
"FORCE_CLANG_DIAGNOSTICS_CRASH");
597 bool AtTopLevel,
bool MultipleArchs,
const char *LinkingOutput,
598 std::map<std::pair<const Action *, std::string>,
InputInfoList>
618 const char *BaseInput, StringRef BoundArch,
619 bool AtTopLevel,
bool MultipleArchs,
620 StringRef NormalizedTriple)
const;
659 return IsOffload ? OffloadLTOMode : LTOMode;
667 bool loadConfigFile();
673 bool readConfigFile(StringRef FileName);
677 void setDriverMode(StringRef DriverModeValue);
681 void setLTOMode(
const llvm::opt::ArgList &Args);
687 const ToolChain &getToolChain(
const llvm::opt::ArgList &Args,
688 const llvm::Triple &Target)
const;
702 const ToolChain &getOffloadingDeviceToolChain(
703 const llvm::opt::ArgList &Args,
const llvm::Triple &Target,
709 std::pair<unsigned, unsigned> getIncludeExcludeOptionFlagMasks(
bool IsClCompatMode)
const;
716 bool AtTopLevel,
bool MultipleArchs,
const char *LinkingOutput,
717 std::map<std::pair<const Action *, std::string>,
InputInfoList>
730 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)
llvm::DenseSet< StringRef > getOffloadArchs(Compilation &C, const llvm::opt::DerivedArgList &Args, Action::OffloadKind Kind, const ToolChain *TC) const
Returns the set of bound architectures active for this offload kind.
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 ...
const std::string & getConfigFile() const
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
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.
unsigned CCPrintHeaders
Set CC_PRINT_HEADERS mode, which causes the frontend to log header include information to CCPrintHead...
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.
JobList - A sequence of jobs to perform.
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").
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
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.
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]+)(.
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.
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.