9#ifndef LLVM_CLANG_DRIVER_DRIVER_H
10#define LLVM_CLANG_DRIVER_DRIVER_H
23#include "llvm/ADT/ArrayRef.h"
24#include "llvm/ADT/STLFunctionalExtras.h"
25#include "llvm/ADT/StringMap.h"
26#include "llvm/ADT/StringRef.h"
27#include "llvm/Option/Arg.h"
28#include "llvm/Option/ArgList.h"
29#include "llvm/Support/StringSaver.h"
42class ExpansionContext;
97 enum BitcodeEmbedMode {
114 bool ModulesModeCXX20;
145 return Diags.
Report(DiagID);
210 using InputTy = std::pair<types::ID, const llvm::opt::Arg *>;
222 bool CCCIsCC()
const {
return Mode == GCCMode; }
278 std::string TargetTriple;
281 std::string CCCGenericGCCName;
284 std::vector<std::string> ConfigFiles;
287 llvm::BumpPtrAllocator Alloc;
290 llvm::StringSaver Saver;
293 std::unique_ptr<llvm::opt::InputArgList> CfgOptions;
296 std::unique_ptr<llvm::opt::InputArgList> CLOptions;
302 const char *PrependArg;
306 unsigned CheckInputsExist : 1;
309 unsigned ProbePrecompiled : 1;
318 llvm::opt::Arg **FinalPhaseArg =
nullptr)
const;
322 unsigned SuppressMissingInputWarning : 1;
329 mutable llvm::StringMap<std::unique_ptr<ToolChain>> ToolChains;
334 llvm::DenseMap<const ToolChain *, llvm::DenseSet<llvm::StringRef>> KnownArchs;
339 llvm::opt::DerivedArgList *
340 TranslateInputArgs(
const llvm::opt::InputArgList &Args)
const;
344 void handleArguments(
Compilation &
C, llvm::opt::DerivedArgList &Args,
350 void generatePrefixedToolNames(StringRef
Tool,
const ToolChain &TC,
364 bool getCrashDiagnosticFile(StringRef ReproCrashFilename,
372 StringRef CustomResourceDir =
"");
392 llvm::vfs::FileSystem &
getVFS()
const {
return *VFS; }
459 bool &ContainsError);
496 llvm::opt::DerivedArgList &Args,
498 Action *HostAction)
const;
506 bool SuppressError =
false)
const;
514 bool TypoCorrect)
const;
542 StringRef AdditionalInformation =
"",
560 const Command &FailingCommand, StringRef AdditionalInformation =
"",
562 if (
static_cast<int>(CS) >
static_cast<int>(Level))
565 Diags.
Report(diag::err_drv_force_crash)
566 << !::getenv(
"FORCE_CLANG_DIAGNOSTICS_CRASH");
629 bool AtTopLevel,
bool MultipleArchs,
const char *LinkingOutput,
630 std::map<std::pair<const Action *, std::string>,
InputInfoList>
647 bool MultipleArchs =
false,
648 StringRef BoundArch = {},
649 bool NeedUniqueDirectory =
false)
const;
664 const char *BaseInput, StringRef BoundArch,
665 bool AtTopLevel,
bool MultipleArchs,
666 StringRef NormalizedTriple)
const;
679 std::string
GetClPchPath(Compilation &
C, StringRef BaseName)
const;
705 return IsOffload ? OffloadLTOMode : LTOMode;
713 bool loadConfigFiles();
719 bool loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx);
726 bool readConfigFile(StringRef FileName, llvm::cl::ExpansionContext &ExpCtx);
730 void setDriverMode(StringRef DriverModeValue);
734 void setLTOMode(
const llvm::opt::ArgList &Args);
740 const ToolChain &getToolChain(
const llvm::opt::ArgList &Args,
741 const llvm::Triple &
Target)
const;
755 const ToolChain &getOffloadingDeviceToolChain(
756 const llvm::opt::ArgList &Args,
const llvm::Triple &
Target,
762 llvm::opt::Visibility
763 getOptionVisibilityMask(
bool UseDriverMode =
true)
const;
770 bool AtTopLevel,
bool MultipleArchs,
const char *LinkingOutput,
771 std::map<std::pair<const Action *, std::string>,
InputInfoList>
776 static const char *getExecutableForDriverMode(DriverMode Mode);
787 unsigned &Micro,
bool &HadExtra);
827 llvm::vfs::FileSystem *FS =
nullptr);
Defines the Diagnostic-related interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
A little helper class used to produce diagnostics.
Concrete class used by the front-end to report problems and issues.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
void setLastDiagnosticIgnored(bool Ignored)
Pretend that the last diagnostic issued was ignored, so any subsequent notes will be suppressed,...
Action - Represent an abstract compilation step to perform.
Command - An executable path/name and argument vector to execute.
Compilation - A set of tasks to perform for a single driver invocation.
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
std::string SysRoot
sysroot, if present
std::string CCPrintInternalStatReportFilename
The file to log CC_PRINT_INTERNAL_STAT_FILE output to, if enabled.
SmallVector< InputTy, 16 > InputList
A list of inputs and their types for the given arguments.
std::string UserConfigDir
User directory for config files.
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...
void BuildUniversalActions(Compilation &C, const ToolChain &TC, const InputList &BAInputs) const
BuildUniversalActions - Construct the list of actions to perform for the given arguments,...
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...
void PrintHelp(bool ShowHidden) const
PrintHelp - Print the help text.
bool offloadDeviceOnly() const
bool isSaveTempsEnabled() const
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.
void BuildJobs(Compilation &C) const
BuildJobs - Bind actions to concrete tools and translate arguments to form the list of jobs to run.
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 GetFilePath(StringRef Name, const ToolChain &TC) const
GetFilePath - Lookup Name in the list of file search paths.
void setCheckInputsExist(bool Value)
unsigned CCPrintProcessStats
Set CC_PRINT_PROC_STAT mode, which causes the driver to dump performance report to CC_PRINT_PROC_STAT...
DiagnosticsEngine & getDiags() const
void PrintActions(const Compilation &C) const
PrintActions - Print the list of actions.
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.
std::string CCPrintOptionsFilename
The file to log CC_PRINT_OPTIONS output to, if enabled.
const char * getPrependArg() const
OpenMPRuntimeKind getOpenMPRuntime(const llvm::opt::ArgList &Args) const
Compute the desired OpenMP runtime from the flags provided.
std::string GetTemporaryDirectory(StringRef Prefix) const
GetTemporaryDirectory - Return the pathname of a temporary directory to use as part of compilation; t...
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").
bool IsCLMode() const
Whether the driver should follow cl.exe like behavior.
std::string DyldPrefix
Dynamic loader prefix, if present.
bool ShouldEmitStaticLibrary(const llvm::opt::ArgList &Args) const
ShouldEmitStaticLibrary - Should the linker emit a static library.
std::string DriverTitle
Driver title to use with help.
void setInstalledDir(StringRef Value)
unsigned CCCPrintBindings
Only print tool bindings, don't build any jobs.
unsigned CCLogDiagnostics
Set CC_LOG_DIAGNOSTICS mode, which causes the frontend to log diagnostics to CCLogDiagnosticsFilename...
llvm::ArrayRef< std::string > getConfigFiles() 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 getDefaultModuleCachePath(SmallVectorImpl< char > &Result)
Compute the default -fmodule-cache-path.
unsigned CCGenDiagnostics
Whether the driver is generating diagnostics for debugging purposes.
const char * getClangProgramPath() const
Get the path to the main clang executable.
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...
DiagnosticBuilder Diag(unsigned DiagID) const
std::string SystemConfigDir
System directory for config files.
ParsedClangName ClangNameParts
Target and driver mode components extracted from clang executable name.
unsigned CCPrintInternalStats
Set CC_PRINT_INTERNAL_STAT mode, which causes the driver to dump internal performance report to CC_PR...
static bool GetReleaseVersion(StringRef Str, unsigned &Major, unsigned &Minor, unsigned &Micro, bool &HadExtra)
GetReleaseVersion - Parse (([0-9]+)(.
std::string Name
The name the driver was invoked as.
phases::ID getFinalPhase(const llvm::opt::DerivedArgList &DAL, llvm::opt::Arg **FinalPhaseArg=nullptr) const
std::string GetClPchPath(Compilation &C, StringRef BaseName) const
Return the pathname of the pch file in clang-cl mode.
std::string ClangExecutable
The original path to the clang executable.
const char * CreateTempFile(Compilation &C, StringRef Prefix, StringRef Suffix, bool MultipleArchs=false, StringRef BoundArch={}, bool NeedUniqueDirectory=false) const
Creates a temp file.
void setPrependArg(const char *Value)
const llvm::opt::OptTable & getOpts() const
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 ...
bool offloadHostOnly() const
ModuleHeaderMode getModuleHeaderMode() const
Get the mode for handling headers as set by fmodule-header{=}.
void generateCompilationDiagnostics(Compilation &C, const Command &FailingCommand, StringRef AdditionalInformation="", CompilationDiagnosticReport *GeneratedReport=nullptr)
generateCompilationDiagnostics - Generate diagnostics information including preprocessed source file(...
bool hasHeaderMode() const
Returns true if the user has indicated a C++20 header unit mode.
SmallVector< std::string, 4 > prefix_list
A prefix directory used to emulate a limited subset of GCC's '-Bprefix' functionality.
void PrintVersion(const Compilation &C, raw_ostream &OS) const
PrintVersion - Print the driver version.
bool ShouldUseFlangCompiler(const JobAction &JA) const
ShouldUseFlangCompiler - Should the flang compiler be used to handle this action.
LTOKind getLTOMode(bool IsOffload=false) const
Get the specific kind of LTO being performed.
bool DiagnoseInputExistence(const llvm::opt::DerivedArgList &Args, StringRef Value, types::ID Ty, bool TypoCorrect) const
Check that the file referenced by Value exists.
bool HandleImmediateArgs(const Compilation &C)
HandleImmediateArgs - Handle any arguments which should be treated before building actions or binding...
const std::string & getTitle()
std::pair< types::ID, const llvm::opt::Arg * > InputTy
An input type and its arguments.
std::string InstalledDir
The path to the installed clang directory, if any.
bool embedBitcodeEnabled() const
llvm::opt::InputArgList ParseArgStrings(ArrayRef< const char * > Args, bool UseDriverMode, bool &ContainsError)
ParseArgStrings - Parse the given list of strings into an ArgList.
void CreateOffloadingDeviceToolChains(Compilation &C, InputList &Inputs)
CreateOffloadingDeviceToolChains - create all the toolchains required to support offloading devices g...
std::string GetProgramPath(StringRef Name, const ToolChain &TC) const
GetProgramPath - Lookup Name in the list of program search paths.
std::string CCLogDiagnosticsFilename
The file to log CC_LOG_DIAGNOSTICS output to, if enabled.
bool isSaveTempsObj() const
std::string CCPrintHeadersFilename
The file to log CC_PRINT_HEADERS output to, if enabled.
void HandleAutocompletions(StringRef PassedFlags) const
HandleAutocompletions - Handle –autocomplete by searching and printing possible flags,...
std::string ResourceDir
The path to the compiler resource directory.
const char * getInstalledDir() const
Get the path to where the clang executable was installed.
llvm::vfs::FileSystem & getVFS() const
unsigned CCPrintOptions
Set CC_PRINT_OPTIONS mode, which is like -v but logs the commands to CCPrintOptionsFilename or to std...
bool ShouldUseClangCompiler(const JobAction &JA) const
ShouldUseClangCompiler - Should the clang compiler be used to handle this action.
bool isUsingLTO(bool IsOffload=false) const
Returns true if we are performing any kind of LTO.
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...
void setProbePrecompiled(bool Value)
std::string Dir
The path the driver executable was in, as invoked from the command line.
bool maybeGenerateCompilationDiagnostics(CommandStatus CS, ReproLevel Level, Compilation &C, const Command &FailingCommand, StringRef AdditionalInformation="", CompilationDiagnosticReport *GeneratedReport=nullptr)
@ OMPRT_IOMP5
The legacy name for the LLVM OpenMP runtime from when it was the Intel OpenMP runtime.
@ OMPRT_OMP
The LLVM OpenMP runtime.
@ OMPRT_Unknown
An unknown OpenMP runtime.
@ OMPRT_GOMP
The GNU OpenMP runtime.
std::string HostBits
Information about the host which can be overridden by the user.
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...
HeaderIncludeFormatKind CCPrintHeadersFormat
The format of the header information that is emitted.
std::string getTargetTriple() const
bool getCheckInputsExist() const
bool CCCIsCC() const
Whether the driver should follow gcc like behavior.
void setTargetAndMode(const ParsedClangName &TM)
bool IsFlangMode() const
Whether the driver should invoke flang for fortran inputs.
bool embedBitcodeMarkerOnly() const
void setTitle(std::string Value)
llvm::function_ref< int(SmallVectorImpl< const char * > &ArgV)> CC1ToolFunc
Pointer to the ExecuteCC1Tool function, if available.
Compilation * BuildCompilation(ArrayRef< const char * > Args)
BuildCompilation - Construct a compilation object for a command line argument vector.
HeaderIncludeFilteringKind CCPrintHeadersFiltering
This flag determines whether clang should filter the header information that is emitted.
const std::string & getCCCGenericGCCName() const
Name to use when invoking gcc/g++.
bool embedBitcodeInObject() const
std::string CCPrintStatReportFilename
The file to log CC_PRINT_PROC_STAT_FILE output to, if enabled.
bool CCCIsCPP() const
Whether the driver is just the preprocessor.
bool CCCIsCXX() const
Whether the driver should follow g++ like behavior.
bool getProbePrecompiled() const
ID
ID - Ordered values for successive stages in the compilation process which interact with user options...
ModuleHeaderMode
Whether headers used to construct C++20 module units should be looked up by the path supplied on the ...
LTOKind
Describes the kind of LTO mode selected via -f(no-)?lto(=.*)? options.
SmallVector< InputInfo, 4 > InputInfoList
bool isOptimizationLevelFast(const llvm::opt::ArgList &Args)
llvm::StringRef getDriverMode(StringRef ProgName, ArrayRef< const char * > Args)
Returns the driver mode option's value, i.e.
llvm::Error expandResponseFiles(SmallVectorImpl< const char * > &Args, bool ClangCLMode, llvm::BumpPtrAllocator &Alloc, llvm::vfs::FileSystem *FS=nullptr)
Expand response files from a clang driver or cc1 invocation.
const llvm::opt::OptTable & getDriverOptTable()
bool willEmitRemarks(const llvm::opt::ArgList &Args)
bool IsClangCL(StringRef DriverMode)
Checks whether the value produced by getDriverMode is for CL mode.
HeaderIncludeFilteringKind
Whether header information is filtered or not.
@ C
Languages that the frontend can parse and compile.
@ Result
The result type of a method or function.
HeaderIncludeFormatKind
The format in which header information is emitted.
YAML serialization mapping.
Contains the files in the compilation diagnostic report generated by generateCompilationDiagnostics.
llvm::SmallVector< std::string, 4 > TemporaryFiles
Helper structure used to pass information extracted from clang executable name such as i686-linux-and...