clang 19.0.0git
Enumerations | Functions
CommonArgs.cpp File Reference
#include "CommonArgs.h"
#include "Arch/AArch64.h"
#include "Arch/ARM.h"
#include "Arch/CSKY.h"
#include "Arch/LoongArch.h"
#include "Arch/M68k.h"
#include "Arch/Mips.h"
#include "Arch/PPC.h"
#include "Arch/RISCV.h"
#include "Arch/Sparc.h"
#include "Arch/SystemZ.h"
#include "Arch/VE.h"
#include "Arch/X86.h"
#include "HIPAMD.h"
#include "Hexagon.h"
#include "MSP430.h"
#include "Solaris.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Basic/CodeGenOptions.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/ObjCRuntime.h"
#include "clang/Basic/Version.h"
#include "clang/Config/config.h"
#include "clang/Driver/Action.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/DriverDiagnostic.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Job.h"
#include "clang/Driver/Options.h"
#include "clang/Driver/SanitizerArgs.h"
#include "clang/Driver/ToolChain.h"
#include "clang/Driver/Util.h"
#include "clang/Driver/XRayArgs.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Twine.h"
#include "llvm/BinaryFormat/Magic.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/Option.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/Compression.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/ScopedPrinter.h"
#include "llvm/Support/Threading.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/YAMLParser.h"
#include "llvm/TargetParser/Host.h"
#include "llvm/TargetParser/TargetParser.h"
#include <optional>

Go to the source code of this file.

Enumerations

enum class  LibGccType { UnspecifiedLibGcc , StaticLibGcc , SharedLibGcc }
 

Functions

static bool useFramePointerForTargetByDefault (const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
 
static bool mustUseNonLeafFramePointerForTarget (const llvm::Triple &Triple)
 
clang::CodeGenOptions::FramePointerKind getFramePointerKind (const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
 
static void renderRpassOptions (const ArgList &Args, ArgStringList &CmdArgs, const StringRef PluginOptPrefix)
 
static void renderRemarksOptions (const ArgList &Args, ArgStringList &CmdArgs, const llvm::Triple &Triple, const InputInfo &Input, const InputInfo &Output, const StringRef PluginOptPrefix)
 
static void renderRemarksHotnessOptions (const ArgList &Args, ArgStringList &CmdArgs, const StringRef PluginOptPrefix)
 
static bool shouldIgnoreUnsupportedTargetFeature (const Arg &TargetFeatureArg, llvm::Triple T, StringRef Processor)
 
static std::string getAMDGPUTargetGPU (const llvm::Triple &T, const ArgList &Args)
 Get the (LLVM) name of the AMDGPU gpu we are targeting.
 
static std::string getLanaiTargetCPU (const ArgList &Args)
 
static StringRef getWebAssemblyTargetCPU (const ArgList &Args)
 Get the (LLVM) name of the WebAssembly cpu we are targeting.
 
static void getWebAssemblyTargetFeatures (const Driver &D, const llvm::Triple &Triple, const ArgList &Args, std::vector< StringRef > &Features)
 
static void addOpenMPDeviceLibC (const Compilation &C, const ArgList &Args, ArgStringList &CmdArgs)
 Adds the '-lcgpu' and '-lmgpu' libraries to the compilation to include the LLVM C library for GPUs.
 
static bool isWholeArchivePresent (const ArgList &Args)
 Determines if –whole-archive is active in the list of arguments.
 
static bool isSharedLinkage (const ArgList &Args)
 Determine if driver is invoked to create a shared object library (-static)
 
static bool isStaticLinkage (const ArgList &Args)
 Determine if driver is invoked to create a static object library (-shared)
 
static void addFortranRuntimeLibsMSVC (const ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
 Add Fortran runtime libs for MSVC.
 
static void addFortranMain (const ToolChain &TC, const ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
 
static void addSanitizerRuntime (const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs, StringRef Sanitizer, bool IsShared, bool IsWhole)
 
static bool addSanitizerDynamicList (const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs, StringRef Sanitizer)
 
static void collectSanitizerRuntimes (const ToolChain &TC, const ArgList &Args, SmallVectorImpl< StringRef > &SharedRuntimes, SmallVectorImpl< StringRef > &StaticRuntimes, SmallVectorImpl< StringRef > &NonWholeStaticRuntimes, SmallVectorImpl< StringRef > &HelperStaticRuntimes, SmallVectorImpl< StringRef > &RequiredSymbols)
 
static unsigned ParseDebugDefaultVersion (const ToolChain &TC, const ArgList &Args)
 
static LibGccType getLibGccType (const ToolChain &TC, const Driver &D, const ArgList &Args)
 
static void AddUnwindLibrary (const ToolChain &TC, const Driver &D, ArgStringList &CmdArgs, const ArgList &Args)
 
static void AddLibgcc (const ToolChain &TC, const Driver &D, ArgStringList &CmdArgs, const ArgList &Args)
 
static bool SDLSearch (const Driver &D, const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const SmallVectorImpl< std::string > &LibraryPaths, StringRef Lib, StringRef Arch, StringRef Target, bool isBitCodeSDL)
 SDLSearch: Search for Static Device Library The search for SDL bitcode files is consistent with how static host libraries are discovered.
 
static void GetSDLFromOffloadArchive (Compilation &C, const Driver &D, const Tool &T, const JobAction &JA, const InputInfoList &Inputs, const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const SmallVectorImpl< std::string > &LibraryPaths, StringRef Lib, StringRef Arch, StringRef Target, bool isBitCodeSDL)
 Search if a user provided archive file lib<libname>.a exists in any of the library paths.
 
static llvm::opt::Arg * getAMDGPUCodeObjectArgument (const Driver &D, const llvm::opt::ArgList &Args)
 

Enumeration Type Documentation

◆ LibGccType

enum class LibGccType
strong
Enumerator
UnspecifiedLibGcc 
StaticLibGcc 
SharedLibGcc 

Definition at line 2145 of file CommonArgs.cpp.

Function Documentation

◆ addFortranMain()

static void addFortranMain ( const ToolChain TC,
const ArgList &  Args,
llvm::opt::ArgStringList &  CmdArgs 
)
static

◆ addFortranRuntimeLibsMSVC()

static void addFortranRuntimeLibsMSVC ( const ArgList &  Args,
llvm::opt::ArgStringList &  CmdArgs 
)
static

Add Fortran runtime libs for MSVC.

Definition at line 1222 of file CommonArgs.cpp.

Referenced by addFortranMain().

◆ AddLibgcc()

static void AddLibgcc ( const ToolChain TC,
const Driver D,
ArgStringList &  CmdArgs,
const ArgList &  Args 
)
static

◆ addOpenMPDeviceLibC()

static void addOpenMPDeviceLibC ( const Compilation C,
const ArgList &  Args,
ArgStringList &  CmdArgs 
)
static

Adds the '-lcgpu' and '-lmgpu' libraries to the compilation to include the LLVM C library for GPUs.

Definition at line 1079 of file CommonArgs.cpp.

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

◆ addSanitizerDynamicList()

static bool addSanitizerDynamicList ( const ToolChain TC,
const ArgList &  Args,
ArgStringList &  CmdArgs,
StringRef  Sanitizer 
)
static

◆ addSanitizerRuntime()

static void addSanitizerRuntime ( const ToolChain TC,
const ArgList &  Args,
ArgStringList &  CmdArgs,
StringRef  Sanitizer,
bool  IsShared,
bool  IsWhole 
)
static

◆ AddUnwindLibrary()

static void AddUnwindLibrary ( const ToolChain TC,
const Driver D,
ArgStringList &  CmdArgs,
const ArgList &  Args 
)
static

◆ collectSanitizerRuntimes()

static void collectSanitizerRuntimes ( const ToolChain TC,
const ArgList &  Args,
SmallVectorImpl< StringRef > &  SharedRuntimes,
SmallVectorImpl< StringRef > &  StaticRuntimes,
SmallVectorImpl< StringRef > &  NonWholeStaticRuntimes,
SmallVectorImpl< StringRef > &  HelperStaticRuntimes,
SmallVectorImpl< StringRef > &  RequiredSymbols 
)
static

◆ getAMDGPUCodeObjectArgument()

static llvm::opt::Arg * getAMDGPUCodeObjectArgument ( const Driver D,
const llvm::opt::ArgList &  Args 
)
static

◆ getAMDGPUTargetGPU()

static std::string getAMDGPUTargetGPU ( const llvm::Triple &  T,
const ArgList &  Args 
)
static

Get the (LLVM) name of the AMDGPU gpu we are targeting.

Definition at line 475 of file CommonArgs.cpp.

References clang::getProcessorFromTargetID(), and clang::T.

◆ getFramePointerKind()

clang::CodeGenOptions::FramePointerKind getFramePointerKind ( const llvm::opt::ArgList &  Args,
const llvm::Triple &  Triple 
)

◆ getLanaiTargetCPU()

static std::string getLanaiTargetCPU ( const ArgList &  Args)
static

Definition at line 495 of file CommonArgs.cpp.

◆ getLibGccType()

static LibGccType getLibGccType ( const ToolChain TC,
const Driver D,
const ArgList &  Args 
)
static

◆ GetSDLFromOffloadArchive()

static void GetSDLFromOffloadArchive ( Compilation C,
const Driver D,
const Tool T,
const JobAction JA,
const InputInfoList Inputs,
const llvm::opt::ArgList &  DriverArgs,
llvm::opt::ArgStringList &  CC1Args,
const SmallVectorImpl< std::string > &  LibraryPaths,
StringRef  Lib,
StringRef  Arch,
StringRef  Target,
bool  isBitCodeSDL 
)
static

Search if a user provided archive file lib<libname>.a exists in any of the library paths.

If so, add a new command to clang-offload-bundler to unbundle this archive and create a temporary device specific archive. Name of this SDL is passed to the llvm-link tool.

Definition at line 2466 of file CommonArgs.cpp.

References clang::driver::ResponseFileSupport::AtFileCurCP(), clang::C, clang::driver::Action::getOffloadingDeviceKind(), clang::driver::Action::GetOffloadKindName(), clang::driver::Driver::getTargetTriple(), clang::driver::Driver::GetTemporaryPath(), and clang::T.

Referenced by clang::driver::tools::AddStaticDeviceLibs().

◆ getWebAssemblyTargetCPU()

static StringRef getWebAssemblyTargetCPU ( const ArgList &  Args)
static

Get the (LLVM) name of the WebAssembly cpu we are targeting.

Definition at line 503 of file CommonArgs.cpp.

◆ getWebAssemblyTargetFeatures()

static void getWebAssemblyTargetFeatures ( const Driver D,
const llvm::Triple &  Triple,
const ArgList &  Args,
std::vector< StringRef > &  Features 
)
static

Definition at line 623 of file CommonArgs.cpp.

References clang::driver::tools::handleTargetFeaturesGroup().

◆ isSharedLinkage()

static bool isSharedLinkage ( const ArgList &  Args)
static

Determine if driver is invoked to create a shared object library (-static)

Definition at line 1212 of file CommonArgs.cpp.

Referenced by addFortranMain().

◆ isStaticLinkage()

static bool isStaticLinkage ( const ArgList &  Args)
static

Determine if driver is invoked to create a static object library (-shared)

Definition at line 1217 of file CommonArgs.cpp.

Referenced by addFortranMain().

◆ isWholeArchivePresent()

static bool isWholeArchivePresent ( const ArgList &  Args)
static

Determines if –whole-archive is active in the list of arguments.

Definition at line 1195 of file CommonArgs.cpp.

Referenced by addFortranMain().

◆ mustUseNonLeafFramePointerForTarget()

static bool mustUseNonLeafFramePointerForTarget ( const llvm::Triple &  Triple)
static

Definition at line 167 of file CommonArgs.cpp.

Referenced by getFramePointerKind().

◆ ParseDebugDefaultVersion()

static unsigned ParseDebugDefaultVersion ( const ToolChain TC,
const ArgList &  Args 
)
static

◆ renderRemarksHotnessOptions()

static void renderRemarksHotnessOptions ( const ArgList &  Args,
ArgStringList &  CmdArgs,
const StringRef  PluginOptPrefix 
)
static

Definition at line 260 of file CommonArgs.cpp.

◆ renderRemarksOptions()

static void renderRemarksOptions ( const ArgList &  Args,
ArgStringList &  CmdArgs,
const llvm::Triple &  Triple,
const InputInfo Input,
const InputInfo Output,
const StringRef  PluginOptPrefix 
)
static

◆ renderRpassOptions()

static void renderRpassOptions ( const ArgList &  Args,
ArgStringList &  CmdArgs,
const StringRef  PluginOptPrefix 
)
static

Definition at line 214 of file CommonArgs.cpp.

◆ SDLSearch()

static bool SDLSearch ( const Driver D,
const llvm::opt::ArgList &  DriverArgs,
llvm::opt::ArgStringList &  CC1Args,
const SmallVectorImpl< std::string > &  LibraryPaths,
StringRef  Lib,
StringRef  Arch,
StringRef  Target,
bool  isBitCodeSDL 
)
static

SDLSearch: Search for Static Device Library The search for SDL bitcode files is consistent with how static host libraries are discovered.

That is, the -l option triggers a search for files in a set of directories called the LINKPATH. The host library search procedure looks for a specific filename in the LINKPATH. The filename for a host library is lib<libname>.a or lib<libname>.so. For SDLs, there is an ordered-set of filenames that are searched. We call this ordered-set of filenames as SEARCH-ORDER. Since an SDL can either be device-type specific, architecture specific, or generic across all architectures, a naming convention and search order is used where the file name embeds the architecture name <arch-name> (nvptx or amdgcn) and the GPU device type <device-name> such as sm_30 and gfx906. <device-name> is absent in case of device-independent SDLs. To reduce congestion in host library directories, the search first looks for files in the “libdevice” subdirectory. SDLs that are bc files begin with the prefix “lib”.

Machine-code SDLs can also be managed as an archive (*.a file). The convention has been to use the prefix “lib”. To avoid confusion with host archive libraries, we use prefix "libbc-" for the bitcode SDL archives.

Definition at line 2388 of file CommonArgs.cpp.

Referenced by clang::driver::tools::AddStaticDeviceLibs().

◆ shouldIgnoreUnsupportedTargetFeature()

static bool shouldIgnoreUnsupportedTargetFeature ( const Arg &  TargetFeatureArg,
llvm::Triple  T,
StringRef  Processor 
)
static

Definition at line 275 of file CommonArgs.cpp.

References clang::T.

◆ useFramePointerForTargetByDefault()

static bool useFramePointerForTargetByDefault ( const llvm::opt::ArgList &  Args,
const llvm::Triple &  Triple 
)
static

Definition at line 75 of file CommonArgs.cpp.

References clang::driver::tools::areOptimizationsEnabled().

Referenced by getFramePointerKind().