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);
207 using InputTy = std::pair<types::ID, const llvm::opt::Arg *>;
219 bool CCCIsCC()
const {
return Mode == GCCMode; }
232 LLVM_PREFERRED_TYPE(
bool)
237 LLVM_PREFERRED_TYPE(
bool)
259 LLVM_PREFERRED_TYPE(
bool)
263 LLVM_PREFERRED_TYPE(
bool)
268 LLVM_PREFERRED_TYPE(
bool)
273 LLVM_PREFERRED_TYPE(
bool)
286 std::
string TargetTriple;
289 std::
string CCCGenericGCCName;
292 std::vector<
std::
string> ConfigFiles;
295 llvm::BumpPtrAllocator Alloc;
298 llvm::StringSaver Saver;
301 std::unique_ptr<
llvm::opt::InputArgList> CfgOptions;
304 std::unique_ptr<
llvm::opt::InputArgList> CLOptions;
310 const
char *PrependArg;
314 LLVM_PREFERRED_TYPE(
bool)
315 unsigned CheckInputsExist : 1;
318 LLVM_PREFERRED_TYPE(
bool)
319 unsigned ProbePrecompiled : 1;
328 llvm::opt::Arg **FinalPhaseArg =
nullptr) const;
332 LLVM_PREFERRED_TYPE(
bool)
333 unsigned SuppressMissingInputWarning : 1;
350 llvm::opt::DerivedArgList *
351 TranslateInputArgs(const
llvm::opt::InputArgList &Args) const;
361 void generatePrefixedToolNames(StringRef
Tool, const
ToolChain &TC,
375 bool getCrashDiagnosticFile(StringRef ReproCrashFilename,
383 StringRef CustomResourceDir = "");
403 llvm::vfs::FileSystem &
getVFS()
const {
return *VFS; }
467 bool &ContainsError);
504 llvm::opt::DerivedArgList &Args,
506 Action *HostAction)
const;
514 bool SuppressError =
false)
const;
522 bool TypoCorrect)
const;
550 StringRef AdditionalInformation =
"",
568 const Command &FailingCommand, StringRef AdditionalInformation =
"",
570 if (
static_cast<int>(CS) >
static_cast<int>(Level))
573 Diags.
Report(diag::err_drv_force_crash)
574 << !::getenv(
"FORCE_CLANG_DIAGNOSTICS_CRASH");
648 bool AtTopLevel,
bool MultipleArchs,
const char *LinkingOutput,
649 std::map<std::pair<const Action *, std::string>,
InputInfoList>
666 bool MultipleArchs =
false,
667 StringRef BoundArch = {},
668 bool NeedUniqueDirectory =
false)
const;
683 const char *BaseInput, StringRef BoundArch,
684 bool AtTopLevel,
bool MultipleArchs,
685 StringRef NormalizedTriple)
const;
698 std::string
GetClPchPath(Compilation &
C, StringRef BaseName)
const;
734 bool loadConfigFiles();
740 bool loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx);
747 bool readConfigFile(StringRef
FileName, llvm::cl::ExpansionContext &ExpCtx);
751 void setDriverMode(StringRef DriverModeValue);
755 void setLTOMode(
const llvm::opt::ArgList &Args);
761 const ToolChain &getToolChain(
const llvm::opt::ArgList &Args,
762 const llvm::Triple &
Target)
const;
776 const ToolChain &getOffloadingDeviceToolChain(
777 const llvm::opt::ArgList &Args,
const llvm::Triple &
Target,
783 llvm::opt::Visibility
784 getOptionVisibilityMask(
bool UseDriverMode =
true)
const;
791 bool AtTopLevel,
bool MultipleArchs,
const char *LinkingOutput,
792 std::map<std::pair<const Action *, std::string>,
InputInfoList>
797 static const char *getExecutableForDriverMode(DriverMode Mode);
808 unsigned &Micro,
bool &HadExtra);
848 llvm::vfs::FileSystem *FS =
nullptr);
853 const char *OverrideOpts,
854 llvm::StringSet<> &SavedStrings,
855 raw_ostream *OS =
nullptr);
Defines the Diagnostic-related interfaces.
enum clang::sema::@1658::IndirectLocalPathEntry::EntryKind Kind
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
llvm::MachO::Target Target
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.
void setFlangF128MathLibrary(std::string name)
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.
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.
bool HandleImmediateArgs(Compilation &C)
HandleImmediateArgs - Handle any arguments which should be treated before building actions or binding...
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)
StringRef getFlangF128MathLibrary() const
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.
bool DiagnoseInputExistence(const llvm::opt::DerivedArgList &Args, StringRef Value, types::ID Ty, bool TypoCorrect) const
Check that the file referenced by Value exists.
const std::string & getTitle()
std::pair< types::ID, const llvm::opt::Arg * > InputTy
An input type and its arguments.
LTOKind getOffloadLTOMode() const
Get the specific kind of offload LTO being performed.
bool isUsingOffloadLTO() const
Returns true if we are performing any kind of offload LTO.
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.
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.
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.
bool isUsingLTO() const
Returns true if we are performing any kind of LTO.
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)
std::string GetStdModuleManifestPath(const Compilation &C, const ToolChain &TC) const
Lookup the path to the Standard library module manifest.
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++.
LTOKind getLTOMode() const
Get the specific kind of LTO being performed.
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
std::string FlangF128MathLibrary
Name of the library that provides implementations of IEEE-754 128-bit float math functions used by Fo...
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)
void applyOverrideOptions(SmallVectorImpl< const char * > &Args, const char *OverrideOpts, llvm::StringSet<> &SavedStrings, raw_ostream *OS=nullptr)
Apply a space separated list of edits to the input argument lists.
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.
The JSON file list parser is used to communicate input to InstallAPI.
HeaderIncludeFilteringKind
Whether header information is filtered or not.
@ Result
The result type of a method or function.
HeaderIncludeFormatKind
The format in which header information is emitted.
Diagnostic wrappers for TextAPI types for error reporting.
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...