9#ifndef LLVM_CLANG_DRIVER_DRIVER_H
10#define LLVM_CLANG_DRIVER_DRIVER_H
24#include "llvm/ADT/ArrayRef.h"
25#include "llvm/ADT/STLFunctionalExtras.h"
26#include "llvm/ADT/StringMap.h"
27#include "llvm/ADT/StringRef.h"
28#include "llvm/Option/Arg.h"
29#include "llvm/Option/ArgList.h"
30#include "llvm/Support/StringSaver.h"
43class ExpansionContext;
81 std::string
getCUID(StringRef InputFile,
82 llvm::opt::DerivedArgList &Args)
const;
115 enum BitcodeEmbedMode {
132 bool ModulesModeCXX20;
160 return Diags.Report(DiagID);
228 bool CCCIsCC()
const {
return Mode == GCCMode; }
241 LLVM_PREFERRED_TYPE(
bool)
246 LLVM_PREFERRED_TYPE(
bool)
268 LLVM_PREFERRED_TYPE(
bool)
272 LLVM_PREFERRED_TYPE(
bool)
277 LLVM_PREFERRED_TYPE(
bool)
282 LLVM_PREFERRED_TYPE(
bool)
295 std::
string TargetTriple;
298 std::
string CCCGenericGCCName;
301 std::vector<
std::
string> ConfigFiles;
304 llvm::BumpPtrAllocator Alloc;
307 llvm::StringSaver Saver;
310 std::unique_ptr<
llvm::
opt::InputArgList> CfgOptionsHead;
313 std::unique_ptr<
llvm::
opt::InputArgList> CfgOptionsTail;
316 std::unique_ptr<
llvm::
opt::InputArgList> CLOptions;
322 const
char *PrependArg;
326 std::
string PreferredLinker;
330 LLVM_PREFERRED_TYPE(
bool)
331 unsigned CheckInputsExist : 1;
334 LLVM_PREFERRED_TYPE(
bool)
335 unsigned ProbePrecompiled : 1;
344 llvm::
opt::Arg **FinalPhaseArg =
nullptr) const;
351 LLVM_PREFERRED_TYPE(
bool)
352 unsigned SuppressMissingInputWarning : 1;
365 TranslateInputArgs(const
llvm::
opt::InputArgList &Args) const;
375 void generatePrefixedToolNames(StringRef
Tool, const
ToolChain &TC,
389 bool getCrashDiagnosticFile(StringRef ReproCrashFilename,
411 llvm::vfs::FileSystem &
getVFS()
const {
return *VFS; }
435 PreferredLinker = std::move(
Value);
478 bool &ContainsError)
const;
520 const InputTy &Input, StringRef CUID,
522 ActionList *HIPAsmBundleDeviceOut =
nullptr)
const;
536 bool TypoCorrect)
const;
564 StringRef AdditionalInformation =
"",
582 const Command &FailingCommand, StringRef AdditionalInformation =
"",
584 if (
static_cast<int>(CS) >
static_cast<int>(Level))
587 Diags.Report(diag::err_drv_force_crash)
588 << !::getenv(
"FORCE_CLANG_DIAGNOSTICS_CRASH");
590 Diags.setLastDiagnosticIgnored(
false);
663 bool AtTopLevel,
bool MultipleArchs,
const char *LinkingOutput,
664 std::map<std::pair<const Action *, std::string>,
InputInfoList>
681 bool MultipleArchs =
false,
682 StringRef BoundArchStr = {},
683 bool NeedUniqueDirectory =
false)
const;
699 bool AtTopLevel,
bool MultipleArchs,
700 StringRef NormalizedTriple)
const;
713 std::string
GetClPchPath(Compilation &
C, StringRef BaseName)
const;
740 bool loadConfigFiles();
746 bool loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx);
751 bool loadZOSCustomizationFile(llvm::cl::ExpansionContext &);
758 bool readConfigFile(StringRef
FileName, llvm::cl::ExpansionContext &ExpCtx);
762 void setDriverMode(StringRef DriverModeValue);
768 const ToolChain &getToolChain(
const llvm::opt::ArgList &Args,
769 const llvm::Triple &
Target)
const;
775 const ToolChain &getOffloadToolChain(
const llvm::opt::ArgList &Args,
777 const llvm::Triple &
Target,
778 const llvm::Triple &AuxTarget)
const;
782 llvm::opt::Visibility
783 getOptionVisibilityMask(
bool UseDriverMode =
true)
const;
790 bool AtTopLevel,
bool MultipleArchs,
const char *LinkingOutput,
791 std::map<std::pair<const Action *, std::string>,
InputInfoList>
796 static const char *getExecutableForDriverMode(DriverMode Mode);
807 unsigned &Micro,
bool &HadExtra);
846 bool ClangCLMode, llvm::BumpPtrAllocator &Alloc,
847 llvm::vfs::FileSystem *FS =
nullptr);
852 const char *OverrideOpts,
853 llvm::StringSet<> &SavedStrings, StringRef EnvVar,
854 raw_ostream *OS =
nullptr);
865 const llvm::opt::OptTable &Opts, StringRef
Value,
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.
Action - Represent an abstract compilation step to perform.
Options for specifying CUID used by CUDA/HIP for uniquely identifying compilation units.
std::string getCUID(StringRef InputFile, llvm::opt::DerivedArgList &Args) const
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...
llvm::SmallVector< BoundArch > 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.
const CUIDOptions & getCUIDOpts() const
Get the CUID option.
std::string SysRoot
sysroot, if present
std::string CCPrintInternalStatReportFilename
The file to log CC_PRINT_INTERNAL_STAT_FILE output to, if enabled.
std::string UserConfigDir
User directory for config files.
void BuildUniversalActions(Compilation &C, const ToolChain &TC, const InputList &BAInputs) const
BuildUniversalActions - Construct the list of actions to perform for the given arguments,...
void PrintHelp(bool ShowHidden) const
PrintHelp - Print the help text.
bool offloadDeviceOnly() const
bool isSaveTempsEnabled() const
void BuildJobs(Compilation &C) const
BuildJobs - Bind actions to concrete tools and translate arguments to form the list of jobs to run.
std::string GetFilePath(StringRef Name, const ToolChain &TC) const
GetFilePath - Lookup Name in the list of file search paths.
void setPreferredLinker(std::string Value)
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.
void setFlangF128MathLibrary(std::string name)
std::string CCPrintOptionsFilename
The file to log CC_PRINT_OPTIONS output to, if enabled.
llvm::Expected< std::unique_ptr< llvm::MemoryBuffer > > executeProgram(llvm::ArrayRef< llvm::StringRef > Args) const
const char * getPrependArg() const
Action * BuildOffloadingActions(Compilation &C, llvm::opt::DerivedArgList &Args, const InputTy &Input, StringRef CUID, Action *HostAction, ActionList *HIPAsmBundleDeviceOut=nullptr) const
BuildOffloadingActions - Construct the list of actions to perform for the offloading toolchain that w...
Action * ConstructPhaseAction(Compilation &C, const llvm::opt::ArgList &Args, phases::ID Phase, Action *Input, Action::OffloadKind TargetDeviceOffloadKind=Action::OFK_None, LTOKind TargetLTOMode=LTOK_None) const
ConstructAction - Construct the appropriate action to do for Phase on the Input, taking in to account...
OpenMPRuntimeKind getOpenMPRuntime(const llvm::opt::ArgList &Args) const
Compute the desired OpenMP runtime from the flags provided.
const char * GetNamedOutputPath(Compilation &C, const JobAction &JA, const char *BaseInput, BoundArch BA, bool AtTopLevel, bool MultipleArchs, StringRef NormalizedTriple) const
GetNamedOutputPath - Return the name to use for the output of the action JA.
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").
llvm::function_ref< int(SmallVectorImpl< const char * > &ArgV)> CC1ToolFunc
Pointer to the ExecuteCC1Tool function, if available.
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...
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.
Driver(StringRef DriverExecutable, StringRef TargetTriple, DiagnosticsEngine &Diags, std::string Title="clang LLVM compiler", IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS=nullptr)
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.
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.
InputInfoList BuildJobsForAction(Compilation &C, const Action *A, const ToolChain *TC, BoundArch BA, 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...
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.
const std::string & getTitle()
bool DiagnoseInputExistence(StringRef Value, types::ID Ty, bool TypoCorrect) const
Check that the file referenced by Value exists.
const char * getDriverProgramPath() const
Get the path to the main driver executable.
bool embedBitcodeEnabled() const
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.
const char * CreateTempFile(Compilation &C, StringRef Prefix, StringRef Suffix, bool MultipleArchs=false, StringRef BoundArchStr={}, bool NeedUniqueDirectory=false) const
Creates a temp file.
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.
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)
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++.
std::string DriverExecutable
The original path to the driver executable.
bool embedBitcodeInObject() const
std::string CCPrintStatReportFilename
The file to log CC_PRINT_PROC_STAT_FILE output to, if enabled.
llvm::opt::InputArgList ParseArgStrings(ArrayRef< const char * > Args, bool UseDriverMode, bool &ContainsError) const
ParseArgStrings - Parse the given list of strings into an ArgList.
bool CCCIsCPP() const
Whether the driver is just the preprocessor.
StringRef getPreferredLinker() const
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...
void applyOverrideOptions(SmallVectorImpl< const char * > &Args, const char *OverrideOpts, llvm::StringSet<> &SavedStrings, StringRef EnvVar, raw_ostream *OS=nullptr)
Apply a space separated list of edits to the input argument lists.
LTOKind
Describes the kind of LTO mode selected via -f(no-)?lto(=.*)? options.
ModuleHeaderMode
Whether headers used to construct C++20 module units should be looked up by the path supplied on the ...
llvm::opt::Arg * makeInputArg(llvm::opt::DerivedArgList &Args, const llvm::opt::OptTable &Opts, StringRef Value, bool Claim=true)
Creates and adds a synthesized input argument.
SmallVector< InputInfo, 4 > InputInfoList
std::pair< types::ID, const llvm::opt::Arg * > InputTy
A list of inputs and their types for the given arguments.
SmallVector< Action *, 3 > ActionList
ActionList - Type used for lists of actions.
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.
llvm::SmallVector< InputTy, 16 > InputList
A list of inputs and their types for the given arguments.
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.
const llvm::opt::OptTable & getDriverOptTable()
HeaderIncludeFormatKind
The format in which header information is emitted.
Diagnostic wrappers for TextAPI types for error reporting.
Represents a bound architecture for offload / multiple architecture compilation.
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...