clang 19.0.0git
Enumerations | Functions | Variables
Driver.cpp File Reference
#include "clang/Driver/Driver.h"
#include "ToolChains/AIX.h"
#include "ToolChains/AMDGPU.h"
#include "ToolChains/AMDGPUOpenMP.h"
#include "ToolChains/AVR.h"
#include "ToolChains/Arch/RISCV.h"
#include "ToolChains/BareMetal.h"
#include "ToolChains/CSKYToolChain.h"
#include "ToolChains/Clang.h"
#include "ToolChains/CrossWindows.h"
#include "ToolChains/Cuda.h"
#include "ToolChains/Darwin.h"
#include "ToolChains/DragonFly.h"
#include "ToolChains/FreeBSD.h"
#include "ToolChains/Fuchsia.h"
#include "ToolChains/Gnu.h"
#include "ToolChains/HIPAMD.h"
#include "ToolChains/HIPSPV.h"
#include "ToolChains/HLSL.h"
#include "ToolChains/Haiku.h"
#include "ToolChains/Hexagon.h"
#include "ToolChains/Hurd.h"
#include "ToolChains/Lanai.h"
#include "ToolChains/Linux.h"
#include "ToolChains/MSP430.h"
#include "ToolChains/MSVC.h"
#include "ToolChains/MinGW.h"
#include "ToolChains/MipsLinux.h"
#include "ToolChains/NaCl.h"
#include "ToolChains/NetBSD.h"
#include "ToolChains/OHOS.h"
#include "ToolChains/OpenBSD.h"
#include "ToolChains/PPCFreeBSD.h"
#include "ToolChains/PPCLinux.h"
#include "ToolChains/PS4CPU.h"
#include "ToolChains/RISCVToolchain.h"
#include "ToolChains/SPIRV.h"
#include "ToolChains/Solaris.h"
#include "ToolChains/TCE.h"
#include "ToolChains/VEToolchain.h"
#include "ToolChains/WebAssembly.h"
#include "ToolChains/XCore.h"
#include "ToolChains/ZOS.h"
#include "clang/Basic/DiagnosticDriver.h"
#include "clang/Basic/TargetID.h"
#include "clang/Basic/Version.h"
#include "clang/Config/config.h"
#include "clang/Driver/Action.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/DriverDiagnostic.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Job.h"
#include "clang/Driver/Options.h"
#include "clang/Driver/Phases.h"
#include "clang/Driver/SanitizerArgs.h"
#include "clang/Driver/Tool.h"
#include "clang/Driver/ToolChain.h"
#include "clang/Driver/Types.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/OptSpecifier.h"
#include "llvm/Option/OptTable.h"
#include "llvm/Option/Option.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ExitCodes.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/MD5.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/StringSaver.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TargetParser/Host.h"
#include "llvm/TargetParser/RISCVISAInfo.h"
#include <cstdlib>
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <utility>

Go to the source code of this file.

Enumerations

enum  { TopLevelAction = 0 , HeadSibAction = 1 , OtherSibAction = 2 }
 

Functions

static std::optional< llvm::Triple > getOffloadTargetTriple (const Driver &D, const ArgList &Args)
 
static std::optional< llvm::Triple > getNVIDIAOffloadTargetTriple (const Driver &D, const ArgList &Args, const llvm::Triple &HostTriple)
 
static std::optional< llvm::Triple > getHIPOffloadTargetTriple (const Driver &D, const ArgList &Args)
 
static Arg * MakeInputArg (DerivedArgList &Args, const OptTable &Opts, StringRef Value, bool Claim=true)
 
static llvm::Triple computeTargetTriple (const Driver &D, StringRef TargetTriple, const ArgList &Args, StringRef DarwinArchName="")
 Compute target triple from args.
 
static driver::LTOKind parseLTOMode (Driver &D, const llvm::opt::ArgList &Args, OptSpecifier OptEq, OptSpecifier OptNeg)
 
static void appendOneArg (InputArgList &Args, const Arg *Opt, const Arg *BaseArg)
 
static void printArgList (raw_ostream &OS, const llvm::opt::ArgList &Args)
 
static void PrintDiagnosticCategories (raw_ostream &OS)
 PrintDiagnosticCategories - Implement the –print-diagnostic-categories option.
 
static unsigned PrintActions1 (const Compilation &C, Action *A, std::map< Action *, unsigned > &Ids, Twine Indent={}, int Kind=TopLevelAction)
 
static bool ContainsCompileOrAssembleAction (const Action *A)
 Check whether the given input tree contains any compilation or assembly actions.
 
static types::ID CXXHeaderUnitType (ModuleHeaderMode HM)
 
static StringRef getCanonicalArchString (Compilation &C, const llvm::opt::DerivedArgList &Args, StringRef ArchStr, const llvm::Triple &Triple, bool SuppressError=false)
 Returns the canonical name for the offloading architecture when using a HIP or CUDA architecture.
 
static std::optional< std::pair< llvm::StringRef, llvm::StringRef > > getConflictOffloadArchCombination (const llvm::DenseSet< StringRef > &Archs, llvm::Triple Triple)
 Checks if the set offloading architectures does not conflict.
 
static std::string GetTriplePlusArchString (const ToolChain *TC, StringRef BoundArch, Action::OffloadKind OffloadKind)
 Return a string that uniquely identifies the result of a job.
 
static void handleTimeTrace (Compilation &C, const ArgList &Args, const JobAction *JA, const char *BaseInput, const InputInfo &Result)
 
static const char * MakeCLOutputFilename (const ArgList &Args, StringRef ArgValue, StringRef BaseName, types::ID FileType)
 Create output filename based on ArgValue, which could either be a full filename, filename without extension, or a directory.
 
static bool HasPreprocessOutput (const Action &JA)
 
static const char * GetModuleOutputPath (Compilation &C, const JobAction &JA, const char *BaseInput)
 
static bool ScanDirForExecutable (SmallString< 128 > &Dir, StringRef Name)
 
static const char * GetStableCStr (llvm::StringSet<> &SavedStrings, StringRef S)
 
static void applyOneOverrideOption (raw_ostream &OS, SmallVectorImpl< const char * > &Args, StringRef Edit, llvm::StringSet<> &SavedStrings)
 Apply a list of edits to the input argument lists.
 

Variables

static const char BugReporMsg []
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
TopLevelAction 
HeadSibAction 
OtherSibAction 

Definition at line 2333 of file Driver.cpp.

Function Documentation

◆ appendOneArg()

static void appendOneArg ( InputArgList &  Args,
const Arg *  Opt,
const Arg *  BaseArg 
)
static

Definition at line 990 of file Driver.cpp.

References clang::Copy.

Referenced by clang::driver::Driver::BuildCompilation().

◆ applyOneOverrideOption()

static void applyOneOverrideOption ( raw_ostream &  OS,
SmallVectorImpl< const char * > &  Args,
StringRef  Edit,
llvm::StringSet<> &  SavedStrings 
)
static

Apply a list of edits to the input argument lists.

The input string is a space separated list of edits to perform, they are applied in order to the input argument lists. Edits should be one of the following forms:

'#': Silence information about the changes to the command line arguments.

'^': Add FOO as a new argument at the beginning of the command line.

'+': Add FOO as a new argument at the end of the command line.

's/XXX/YYY/': Substitute the regular expression XXX with YYY in the command line.

'xOPTION': Removes all instances of the literal argument OPTION.

'XOPTION': Removes all instances of the literal argument OPTION, and the following argument.

'Ox': Removes all flags matching 'O' or 'O[sz0-9]' and adds 'Ox' at the end of the command line.

Parameters
OS- The stream to write edit information to.
Args- The vector of command line arguments.
Edit- The override command to perform.
SavedStrings- Set to use for storing string representations.

Definition at line 6792 of file Driver.cpp.

References GetStableCStr().

Referenced by clang::driver::applyOverrideOptions().

◆ computeTargetTriple()

static llvm::Triple computeTargetTriple ( const Driver D,
StringRef  TargetTriple,
const ArgList &  Args,
StringRef  DarwinArchName = "" 
)
static

Compute target triple from args.

This routine provides the logic to compute a target triple from various args passed to the driver and the default triple string.

Definition at line 526 of file Driver.cpp.

References clang::driver::Driver::Diag(), clang::driver::toolchains::MinGW::fixTripleArch(), clang::driver::tools::riscv::getRISCVArch(), clang::driver::tools::darwin::setTripleTypeForMachOArchName(), clang::T, and clang::Target.

Referenced by clang::driver::Driver::BuildCompilation().

◆ ContainsCompileOrAssembleAction()

static bool ContainsCompileOrAssembleAction ( const Action A)
static

Check whether the given input tree contains any compilation or assembly actions.

Definition at line 2437 of file Driver.cpp.

References ContainsCompileOrAssembleAction(), and clang::driver::Action::inputs().

Referenced by clang::driver::Driver::BuildUniversalActions(), and ContainsCompileOrAssembleAction().

◆ CXXHeaderUnitType()

static types::ID CXXHeaderUnitType ( ModuleHeaderMode  HM)
static

◆ getCanonicalArchString()

static StringRef getCanonicalArchString ( Compilation C,
const llvm::opt::DerivedArgList &  Args,
StringRef  ArchStr,
const llvm::Triple &  Triple,
bool  SuppressError = false 
)
static

◆ getConflictOffloadArchCombination()

static std::optional< std::pair< llvm::StringRef, llvm::StringRef > > getConflictOffloadArchCombination ( const llvm::DenseSet< StringRef > &  Archs,
llvm::Triple  Triple 
)
static

Checks if the set offloading architectures does not conflict.

Returns the incompatible pair if a conflict occurs.

Definition at line 4435 of file Driver.cpp.

References clang::getConflictTargetIDCombination().

Referenced by clang::driver::Driver::getOffloadArchs().

◆ getHIPOffloadTargetTriple()

static std::optional< llvm::Triple > getHIPOffloadTargetTriple ( const Driver D,
const ArgList &  Args 
)
static

◆ GetModuleOutputPath()

static const char * GetModuleOutputPath ( Compilation C,
const JobAction JA,
const char *  BaseInput 
)
static

◆ getNVIDIAOffloadTargetTriple()

static std::optional< llvm::Triple > getNVIDIAOffloadTargetTriple ( const Driver D,
const ArgList &  Args,
const llvm::Triple &  HostTriple 
)
static

◆ getOffloadTargetTriple()

static std::optional< llvm::Triple > getOffloadTargetTriple ( const Driver D,
const ArgList &  Args 
)
static

Definition at line 110 of file Driver.cpp.

References clang::driver::Driver::Diag().

Referenced by getHIPOffloadTargetTriple(), and getNVIDIAOffloadTargetTriple().

◆ GetStableCStr()

static const char * GetStableCStr ( llvm::StringSet<> &  SavedStrings,
StringRef  S 
)
static

Definition at line 6761 of file Driver.cpp.

Referenced by applyOneOverrideOption().

◆ GetTriplePlusArchString()

static std::string GetTriplePlusArchString ( const ToolChain TC,
StringRef  BoundArch,
Action::OffloadKind  OffloadKind 
)
static

Return a string that uniquely identifies the result of a job.

The bound arch is not necessarily represented in the toolchain's triple – for example, armv7 and armv7s both map to the same triple – so we need both in our map. Also, we need to add the offloading device kind, as the same tool chain can be used for host and device for some programming models, e.g. OpenMP.

Definition at line 5387 of file Driver.cpp.

References clang::driver::Action::GetOffloadKindName(), and clang::driver::ToolChain::getTriple().

Referenced by clang::driver::Driver::BuildJobsForAction().

◆ handleTimeTrace()

static void handleTimeTrace ( Compilation C,
const ArgList &  Args,
const JobAction JA,
const char *  BaseInput,
const InputInfo Result 
)
static

Definition at line 5419 of file Driver.cpp.

References clang::C, and clang::Result.

◆ HasPreprocessOutput()

static bool HasPreprocessOutput ( const Action JA)
static

◆ MakeCLOutputFilename()

static const char * MakeCLOutputFilename ( const ArgList &  Args,
StringRef  ArgValue,
StringRef  BaseName,
types::ID  FileType 
)
static

Create output filename based on ArgValue, which could either be a full filename, filename without extension, or a directory.

If ArgValue does not provide a filename, then use BaseName, and use the extension suitable for FileType.

Definition at line 5746 of file Driver.cpp.

References Filename, and clang::driver::types::getTypeTempSuffix().

Referenced by clang::driver::Driver::GetNamedOutputPath().

◆ MakeInputArg()

static Arg * MakeInputArg ( DerivedArgList &  Args,
const OptTable &  Opts,
StringRef  Value,
bool  Claim = true 
)
static

Definition at line 404 of file Driver.cpp.

Referenced by clang::driver::Driver::BuildInputs().

◆ parseLTOMode()

static driver::LTOKind parseLTOMode ( Driver D,
const llvm::opt::ArgList &  Args,
OptSpecifier  OptEq,
OptSpecifier  OptNeg 
)
static

◆ PrintActions1()

static unsigned PrintActions1 ( const Compilation C,
Action A,
std::map< Action *, unsigned > &  Ids,
Twine  Indent = {},
int  Kind = TopLevelAction 
)
static

Definition at line 2342 of file Driver.cpp.

Referenced by clang::driver::Driver::PrintActions().

◆ printArgList()

static void printArgList ( raw_ostream &  OS,
const llvm::opt::ArgList &  Args 
)
static

Definition at line 1547 of file Driver.cpp.

Referenced by clang::driver::Driver::generateCompilationDiagnostics().

◆ PrintDiagnosticCategories()

static void PrintDiagnosticCategories ( raw_ostream &  OS)
static

PrintDiagnosticCategories - Implement the –print-diagnostic-categories option.

Definition at line 2036 of file Driver.cpp.

References clang::DiagnosticIDs::getCategoryNameFromID(), clang::DiagnosticIDs::getNumberOfCategories(), and max().

Referenced by clang::driver::Driver::HandleImmediateArgs().

◆ ScanDirForExecutable()

static bool ScanDirForExecutable ( SmallString< 128 > &  Dir,
StringRef  Name 
)
static

Definition at line 6173 of file Driver.cpp.

Referenced by clang::driver::Driver::GetProgramPath().

Variable Documentation

◆ BugReporMsg

const char BugReporMsg[]
static
Initial value:
=
"\n********************\n\n"
"PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\n"
"Preprocessed source(s) and associated run script(s) are located at:"

Definition at line 1655 of file Driver.cpp.

Referenced by clang::driver::Driver::generateCompilationDiagnostics().