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;
80 std::string
getCUID(StringRef InputFile,
81 llvm::opt::DerivedArgList &Args)
const;
114 enum BitcodeEmbedMode {
131 bool ModulesModeCXX20;
159 return Diags.Report(DiagID);
227 bool CCCIsCC()
const {
return Mode == GCCMode; }
240 LLVM_PREFERRED_TYPE(
bool)
245 LLVM_PREFERRED_TYPE(
bool)
267 LLVM_PREFERRED_TYPE(
bool)
271 LLVM_PREFERRED_TYPE(
bool)
276 LLVM_PREFERRED_TYPE(
bool)
281 LLVM_PREFERRED_TYPE(
bool)
294 std::
string TargetTriple;
297 std::
string CCCGenericGCCName;
300 std::vector<
std::
string> ConfigFiles;
303 llvm::BumpPtrAllocator Alloc;
306 llvm::StringSaver Saver;
309 std::unique_ptr<
llvm::
opt::InputArgList> CfgOptionsHead;
312 std::unique_ptr<
llvm::
opt::InputArgList> CfgOptionsTail;
315 std::unique_ptr<
llvm::
opt::InputArgList> CLOptions;
321 const
char *PrependArg;
325 std::
string PreferredLinker;
329 LLVM_PREFERRED_TYPE(
bool)
330 unsigned CheckInputsExist : 1;
333 LLVM_PREFERRED_TYPE(
bool)
334 unsigned ProbePrecompiled : 1;
343 llvm::
opt::Arg **FinalPhaseArg =
nullptr) const;
350 LLVM_PREFERRED_TYPE(
bool)
351 unsigned SuppressMissingInputWarning : 1;
364 TranslateInputArgs(const
llvm::
opt::InputArgList &Args) const;
374 void generatePrefixedToolNames(StringRef
Tool, const
ToolChain &TC,
388 bool getCrashDiagnosticFile(StringRef ReproCrashFilename,
410 llvm::vfs::FileSystem &
getVFS()
const {
return *VFS; }
434 PreferredLinker = std::move(
Value);
477 bool &ContainsError)
const;
519 const InputTy &Input, StringRef CUID,
521 ActionList *HIPAsmBundleDeviceOut =
nullptr)
const;
535 bool TypoCorrect)
const;
563 StringRef AdditionalInformation =
"",
581 const Command &FailingCommand, StringRef AdditionalInformation =
"",
583 if (
static_cast<int>(CS) >
static_cast<int>(Level))
586 Diags.Report(diag::err_drv_force_crash)
587 << !::getenv(
"FORCE_CLANG_DIAGNOSTICS_CRASH");
589 Diags.setLastDiagnosticIgnored(
false);
662 bool AtTopLevel,
bool MultipleArchs,
const char *LinkingOutput,
663 std::map<std::pair<const Action *, std::string>,
InputInfoList>
680 bool MultipleArchs =
false,
681 StringRef BoundArch = {},
682 bool NeedUniqueDirectory =
false)
const;
697 const char *BaseInput, StringRef BoundArch,
698 bool AtTopLevel,
bool MultipleArchs,
699 StringRef NormalizedTriple)
const;
712 std::string
GetClPchPath(Compilation &
C, StringRef BaseName)
const;
739 bool loadConfigFiles();
745 bool loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx);
750 bool loadZOSCustomizationFile(llvm::cl::ExpansionContext &);
757 bool readConfigFile(StringRef
FileName, llvm::cl::ExpansionContext &ExpCtx);
761 void setDriverMode(StringRef DriverModeValue);
767 const ToolChain &getToolChain(
const llvm::opt::ArgList &Args,
768 const llvm::Triple &
Target)
const;
774 const ToolChain &getOffloadToolChain(
const llvm::opt::ArgList &Args,
776 const llvm::Triple &
Target,
777 const llvm::Triple &AuxTarget)
const;
781 llvm::opt::Visibility
782 getOptionVisibilityMask(
bool UseDriverMode =
true)
const;
789 bool AtTopLevel,
bool MultipleArchs,
const char *LinkingOutput,
790 std::map<std::pair<const Action *, std::string>,
InputInfoList>
795 static const char *getExecutableForDriverMode(DriverMode Mode);
806 unsigned &Micro,
bool &HadExtra);
845 bool ClangCLMode, llvm::BumpPtrAllocator &Alloc,
846 llvm::vfs::FileSystem *FS =
nullptr);
851 const char *OverrideOpts,
852 llvm::StringSet<> &SavedStrings, StringRef EnvVar,
853 raw_ostream *OS =
nullptr);
864 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...
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.
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 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.
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.
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.
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]+)(.
llvm::SmallVector< 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.
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.
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.
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.
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.
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...