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"
42 class ExpansionContext;
99 enum BitcodeEmbedMode {
116 bool ModulesModeCXX20;
147 return Diags.
Report(DiagID);
209 using InputTy = std::pair<types::ID, const llvm::opt::Arg *>;
221 bool CCCIsCC()
const {
return Mode == GCCMode; }
234 LLVM_PREFERRED_TYPE(
bool)
239 LLVM_PREFERRED_TYPE(
bool)
261 LLVM_PREFERRED_TYPE(
bool)
265 LLVM_PREFERRED_TYPE(
bool)
270 LLVM_PREFERRED_TYPE(
bool)
275 LLVM_PREFERRED_TYPE(
bool)
288 std::
string TargetTriple;
291 std::
string CCCGenericGCCName;
294 std::vector<
std::
string> ConfigFiles;
297 llvm::BumpPtrAllocator Alloc;
300 llvm::StringSaver Saver;
303 std::unique_ptr<
llvm::opt::InputArgList> CfgOptions;
306 std::unique_ptr<
llvm::opt::InputArgList> CLOptions;
312 const
char *PrependArg;
316 LLVM_PREFERRED_TYPE(
bool)
317 unsigned CheckInputsExist : 1;
320 LLVM_PREFERRED_TYPE(
bool)
321 unsigned ProbePrecompiled : 1;
330 llvm::opt::Arg **FinalPhaseArg =
nullptr) const;
334 LLVM_PREFERRED_TYPE(
bool)
335 unsigned SuppressMissingInputWarning : 1;
352 llvm::opt::DerivedArgList *
353 TranslateInputArgs(const
llvm::opt::InputArgList &Args) const;
363 void generatePrefixedToolNames(StringRef
Tool, const
ToolChain &TC,
377 bool getCrashDiagnosticFile(StringRef ReproCrashFilename,
385 StringRef CustomResourceDir = "");
405 llvm::vfs::FileSystem &
getVFS()
const {
return *VFS; }
471 bool &ContainsError);
508 llvm::opt::DerivedArgList &Args,
510 Action *HostAction)
const;
518 bool SuppressError =
false)
const;
526 bool TypoCorrect)
const;
554 StringRef AdditionalInformation =
"",
572 const Command &FailingCommand, StringRef AdditionalInformation =
"",
574 if (
static_cast<int>(CS) >
static_cast<int>(
Level))
577 Diags.
Report(diag::err_drv_force_crash)
578 << !::getenv(
"FORCE_CLANG_DIAGNOSTICS_CRASH");
658 bool AtTopLevel,
bool MultipleArchs,
const char *LinkingOutput,
659 std::map<std::pair<const Action *, std::string>,
InputInfoList>
676 bool MultipleArchs =
false,
677 StringRef BoundArch = {},
679 bool NeedUniqueDirectory =
false)
const;
694 const char *BaseInput, StringRef BoundArch,
695 bool AtTopLevel,
bool MultipleArchs,
696 StringRef NormalizedTriple)
const;
707 std::string
GetUniquePath(StringRef BaseName, StringRef Ext)
const;
714 std::string
GetClPchPath(Compilation &C, StringRef BaseName)
const;
740 return IsOffload ? OffloadLTOMode : LTOMode;
767 bool loadConfigFiles();
773 bool loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx);
780 bool readConfigFile(StringRef FileName, llvm::cl::ExpansionContext &ExpCtx);
784 void setDriverMode(StringRef DriverModeValue);
787 void setResourceDirectory();
791 void setLTOMode(
const llvm::opt::ArgList &Args);
797 const ToolChain &getToolChain(
const llvm::opt::ArgList &Args,
798 const llvm::Triple &
Target)
const;
812 const ToolChain &getOffloadingDeviceToolChain(
813 const llvm::opt::ArgList &Args,
const llvm::Triple &
Target,
820 getOptionVisibilityMask(
bool UseDriverMode =
true)
const;
827 bool AtTopLevel,
bool MultipleArchs,
const char *LinkingOutput,
828 std::map<std::pair<const Action *, std::string>,
InputInfoList>
833 bool OffloadStaticLibSeen =
false;
835 void setOffloadStaticLibSeen() { OffloadStaticLibSeen =
true; }
838 bool UseNewOffloadingDriver =
false;
839 void setUseNewOffloadingDriver() { UseNewOffloadingDriver =
true; }
846 bool SYCLDefaultTripleImplied =
false;
847 void setSYCLDefaultTriple(
bool IsDefaultImplied) {
848 SYCLDefaultTripleImplied = IsDefaultImplied;
853 bool checkForSYCLDefaultDevice(Compilation &C,
854 llvm::opt::DerivedArgList &Args)
const;
857 bool checkForOffloadStaticLib(Compilation &C,
858 llvm::opt::DerivedArgList &Args)
const;
861 void checkForOffloadMismatch(Compilation &C,
862 llvm::opt::DerivedArgList &Args)
const;
865 mutable llvm::StringMap<const std::string> FPGATempDepFiles;
870 mutable llvm::StringMap<const std::pair<StringRef, StringRef>>
876 mutable llvm::StringMap<StringRef> SYCLUniqueIDList;
881 mutable std::vector<std::string> SYCLTargetMacroArgs;
886 mutable llvm::opt::ArgStringList SYCLDeviceTraitsMacrosArgs;
889 static const char *getExecutableForDriverMode(DriverMode Mode);
900 unsigned &Micro,
bool &HadExtra);
909 MutableArrayRef<unsigned> Digits);
922 const std::string &FileName)
const {
923 FPGATempDepFiles.insert({
FileName, DepName});
938 StringRef FileName)
const {
939 IntegrationFileList.insert(
940 {
FileName, std::make_pair(IntHeaderName, IntFooterName)});
944 return IntegrationFileList[
FileName].first;
948 return IntegrationFileList[
FileName].second;
952 const llvm::opt::ArgList &Args)
const;
957 StringRef Macro)
const {
958 SYCLTargetMacroArgs.push_back(Args.MakeArgString(Macro));
962 return SYCLTargetMacroArgs;
968 SYCLUniqueIDList.insert({
FileName, UniqueID});
978 StringRef Macro)
const {
979 SYCLDeviceTraitsMacrosArgs.push_back(Args.MakeArgString(Macro));
982 return SYCLDeviceTraitsMacrosArgs;
1017 llvm::vfs::FileSystem *FS =
nullptr);
1022 const char *OverrideOpts,
1023 llvm::StringSet<> &SavedStrings,
1024 raw_ostream *OS =
nullptr);
Defines the Diagnostic-related interfaces.
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,...
The base class of the type hierarchy.
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...
llvm::Triple MakeSYCLDeviceTriple(StringRef TargetArch="spir64") const
MakeSYCLDeviceTriple - Returns the SYCL device triple for the specified subarch.
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.
void addSYCLDeviceTraitsMacroArg(const llvm::opt::ArgList &Args, StringRef Macro) const
SYCLDeviceTraitMacroArg - Add the given macro to the vector of args to be added to the device compila...
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,...
const char * CreateTempFile(Compilation &C, StringRef Prefix, StringRef Suffix, bool MultipleArchs=false, StringRef BoundArch={}, types::ID Type=types::TY_Nothing, bool NeedUniqueDirectory=false) const
Creates a temp file.
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
void addSYCLTargetMacroArg(const llvm::opt::ArgList &Args, StringRef Macro) const
addSYCLTargetMacroArg - Add the given macro to the vector of args to be added to the host compilation...
const std::string & getCCCGenericGCCName() const
Name to use when invoking gcc/g++.
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...
StringRef getIntegrationFooter(StringRef FileName) const
getIntegrationFooter - Get the integration footer file
std::string GetFilePath(StringRef Name, const ToolChain &TC) const
GetFilePath - Lookup Name in the list of file search paths.
void PrintSYCLToolHelp(const Compilation &C) const
PrintSYCLToolHelp - Print help text from offline compiler tools.
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...
const char * getPrependArg() 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::vfs::FileSystem & getVFS() 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.
void addFPGATempDepFile(const std::string &DepName, const std::string &FileName) const
addFPGATempDepFile - Add a file to be added to the bundling step of an FPGA object.
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...
StringRef getSYCLUniqueID(StringRef FileName) const
getSYCLUniqueID - Get the Unique ID associated with the file.
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.
llvm::ArrayRef< std::string > getSYCLTargetMacroArgs() const
getSYCLTargetMacroArgs - return the previously gathered macro target args.
void addIntegrationFiles(StringRef IntHeaderName, StringRef IntFooterName, StringRef FileName) const
addIntegrationFiles - Add the integration files that will be populated by the device compilation and ...
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]+)(.
bool isSYCLDefaultTripleImplied() const
isSYCLDefaultTripleImplied - The default SYCL triple (spir64) has been added or should be added given...
std::string Name
The name the driver was invoked as.
bool getOffloadStaticLibSeen() const
phases::ID getFinalPhase(const llvm::opt::DerivedArgList &DAL, llvm::opt::Arg **FinalPhaseArg=nullptr) const
const std::string & getTitle()
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.
StringRef getIntegrationHeader(StringRef FileName) const
getIntegrationHeader - Get the integration header file
void setPrependArg(const char *Value)
StringRef getFlangF128MathLibrary() const
llvm::ArrayRef< std::string > getConfigFiles() 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
void addSYCLUniqueID(StringRef UniqueID, StringRef FileName) const
setSYCLUniqueID - set the Unique ID that is used for all FE invocations when performing compilations ...
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 createAppendedFooterInput(Action *&Input, Compilation &C, const llvm::opt::ArgList &Args) const
createAppendedFooterInput - Create new source file.
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 getUseNewOffloadingDriver() const
getUseNewOffloadingDriver - use the new offload driver for OpenMP.
bool HandleImmediateArgs(const Compilation &C)
HandleImmediateArgs - Handle any arguments which should be treated before building actions or binding...
DeviceMode getOffloadCompileMode()
std::pair< types::ID, const llvm::opt::Arg * > InputTy
An input type and its arguments.
llvm::opt::ArgStringList getDeviceTraitsMacrosArgs() const
const std::string getFPGATempDepFile(const std::string &FileName) const
getFPGATempDepFile - Get a file to be added to the bundling step of an FPGA object.
bool embedBitcodeEnabled() const
bool IsFPGAHWMode() const
DiagnosticsEngine & getDiags() 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 GetUniquePath(StringRef BaseName, StringRef Ext) const
GetUniquePath = Return the pathname of a unique file to use as part of compilation.
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,...
const llvm::opt::OptTable & getOpts() const
std::string ResourceDir
The path to the compiler resource directory.
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.
bool isDumpDeviceCodeEnabled() const
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.
bool IsFPGAEmulationMode() const
const char * getClangProgramPath() const
Get the path to the main clang executable.
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.
void setOffloadCompileMode(DeviceMode ModeValue)
enum clang::driver::Driver::DeviceMode OffloadCompileMode
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 isStaticArchiveFile(const StringRef &FileName)
bool isObjectFile(std::string FileName)
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.
HeaderIncludeFormatKind
The format in which header information is emitted.
Visibility
Describes the different kinds of visibility that a declaration may have.
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...