|
clang 23.0.0git
|
This file defines functionality to support driver managed builds for compilations which use Clang modules or standard C++20 named modules. More...
#include "clang/Driver/ModulesDriver.h"#include "clang/Basic/Diagnostic.h"#include "clang/Basic/LLVM.h"#include "clang/DependencyScanning/DependencyScanningUtils.h"#include "clang/Driver/Compilation.h"#include "clang/Driver/Driver.h"#include "clang/Driver/Job.h"#include "clang/Driver/Tool.h"#include "clang/Driver/ToolChain.h"#include "clang/Frontend/StandaloneDiagnostic.h"#include "llvm/ADT/DenseSet.h"#include "llvm/ADT/DepthFirstIterator.h"#include "llvm/ADT/DirectedGraph.h"#include "llvm/ADT/PostOrderIterator.h"#include "llvm/ADT/STLExtras.h"#include "llvm/ADT/SmallVectorExtras.h"#include "llvm/ADT/TypeSwitch.h"#include "llvm/ADT/iterator_range.h"#include "llvm/Option/ArgList.h"#include "llvm/Support/Casting.h"#include "llvm/Support/GraphWriter.h"#include "llvm/Support/JSON.h"#include "llvm/Support/Path.h"#include "llvm/Support/PrettyStackTrace.h"#include "llvm/Support/ThreadPool.h"#include "llvm/Support/VirtualFileSystem.h"#include <utility>Go to the source code of this file.
Classes | |
| struct | llvm::GraphTraits< CGNode * > |
| Non-const versions of the GraphTraits specializations for CompilationGraph. More... | |
| struct | llvm::GraphTraits< CompilationGraph * > |
| struct | llvm::GraphTraits< const CGNode * > |
| Const versions of the GraphTraits specializations for CompilationGraph. More... | |
| struct | llvm::GraphTraits< const CompilationGraph * > |
| struct | llvm::DOTGraphTraits< const CompilationGraph * > |
| class | llvm::GraphWriter< const CompilationGraph * > |
| GraphWriter specialization for CompilationGraph that emits a more human-readable DOT graph. More... | |
Namespaces | |
| namespace | clang |
| The JSON file list parser is used to communicate input to InstallAPI. | |
| namespace | clang::driver |
| namespace | clang::driver::modules |
| namespace | llvm |
| Diagnostic wrappers for TextAPI types for error reporting. | |
Typedefs | |
| using | ManifestEntryLookup |
| using | ModuleNameAndTriple = std::pair<StringRef, StringRef> |
Functions | |
| static bool | clang::driver::modules::fromJSON (const llvm::json::Value &Params, StdModuleManifest::Module::LocalArguments &LocalArgs, llvm::json::Path P) |
| static bool | clang::driver::modules::fromJSON (const llvm::json::Value &Params, StdModuleManifest::Module &ModuleEntry, llvm::json::Path P) |
| static bool | clang::driver::modules::fromJSON (const llvm::json::Value &Params, StdModuleManifest &Manifest, llvm::json::Path P) |
| static Expected< StdModuleManifest > | parseManifest (StringRef Buffer) |
Parses the Standard library module manifest from Buffer. | |
| static void | makeManifestPathsAbsolute (MutableArrayRef< StdModuleManifest::Module > ManifestEntries, StringRef ManifestPath) |
| Converts each file path in manifest from relative to absolute. | |
| static ManifestEntryLookup | buildManifestLookupMap (ArrayRef< StdModuleManifest::Module > ManifestEntries) |
| Builds a mapping from a module's source path to its entry in the manifest. | |
| static const StdModuleManifest::Module * | getManifestEntryForCommand (const Command &Job, const ManifestEntryLookup &ManifestEntryBySource) |
Returns the manifest entry corresponding to Job, or nullptr if none exists. | |
| static void | addSystemIncludeDirsFromManifest (Compilation &C, Command &Job, ArgStringList &CC1Args, ArrayRef< std::string > SystemIncludeDirs) |
Adds all SystemIncludeDirs to the CC1Args of Job. | |
| static bool | isCC1Job (const Command &Job) |
| static void | applyArgsForStdModuleManifestInputs (Compilation &C, const ManifestEntryLookup &ManifestEntryBySource, MutableArrayRef< std::unique_ptr< Command > > Jobs) |
| Apply command-line modifications specific for inputs originating from the Standard library module manifest. | |
| static std::optional< std::string > | getModuleCachePath (llvm::opt::DerivedArgList &Args) |
| Computes the -fmodule-cache-path for this compilation. | |
| static bool | isDependencyScannableJob (const Command &Job) |
Returns true if a dependency scan can be performed using Job. | |
| static std::pair< std::unique_ptr< llvm::ThreadPoolInterface >, std::unique_ptr< ScanningWorkerPool > > | createOptimalThreadAndWorkerPool (size_t NumScanInputs, bool HasStdlibModuleInputs, deps::DependencyScanningService &ScanningService) |
| static StringRef | getTriple (const Command &Job) |
| static void | reportAllScanDiagnostics (SmallVectorImpl< SmallVector< StandaloneDiagnostic, 0 > > &&AllScanDiags, DiagnosticsEngine &Diags) |
| Report the diagnostics collected during each dependency scan. | |
| static std::string | constructPCMPath (const deps::ModuleID &ID, StringRef OutputDir) |
| Construct a path for the explicitly built PCM. | |
| static InputDependencies | makeInputDeps (deps::TranslationUnitDeps &&TUDeps) |
| static SmallVector< std::string, 0 > | buildCommandLine (const Command &Job) |
Constructs the full command line, including the executable, for Job. | |
| static std::pair< std::optional< deps::TranslationUnitDeps >, SmallVector< StandaloneDiagnostic, 0 > > | scanDependenciesForJob (const Command &Job, ScanningWorkerPool &WorkerPool, StringRef WorkingDirectory, ModuleLookupController &LookupController) |
| Performs a dependency scan for a single job. | |
| static std::optional< DependencyScanResult > | scanDependencies (ArrayRef< std::unique_ptr< Command > > Jobs, llvm::DenseMap< StringRef, const StdModuleManifest::Module * > ManifestLookup, StringRef ModuleCachePath, StringRef WorkingDirectory, DiagnosticsEngine &Diags) |
Scans the compilations job list Jobs for module dependencies. | |
| static StringRef | getFirstInputFilename (const Command &Job) |
| static SmallVector< std::unique_ptr< Command > > | takeJobsAtIndices (SmallVectorImpl< std::unique_ptr< Command > > &Jobs, ArrayRef< size_t > Indices) |
| static void | createNodesForNonScannableJobs (CompilationGraph &Graph, SmallVectorImpl< std::unique_ptr< Command > > &&NonScannableJobs) |
| Creates nodes for all jobs that could not be scanned (e.g. image jobs, ...). | |
| static SmallVector< JobNode * > | createNodesForUnusedStdlibModuleJobs (CompilationGraph &Graph, SmallVectorImpl< std::unique_ptr< Command > > &&UnusedStdlibModuleJobs) |
| Creates nodes for the Standard library module jobs not discovered as dependencies. | |
| static std::unique_ptr< CC1Command > | createClangModulePrecompileJob (Compilation &C, const Command &ImportingJob, const deps::ModuleDeps &MD) |
Creates a job for the Clang module described by MD. | |
| static void | createClangModuleJobsAndNodes (CompilationGraph &Graph, Compilation &C, ArrayRef< std::unique_ptr< Command > > ImportingJobs, SmallVectorImpl< deps::ModuleDepsGraph > &&ModuleDepGraphsForScannedJobs) |
Creates a ClangModuleJobNode with associated job for each unique Clang module in ModuleDepGraphsForScannedJobs. | |
| static void | installScanCommandLines (Compilation &C, MutableArrayRef< std::unique_ptr< Command > > ScannedJobs, ArrayRef< InputDependencies > InputDepsForScannedJobs) |
Installs the command lines produced by the dependency scan into ScannedJobs. | |
| static void | createNodesForScannedJobs (CompilationGraph &Graph, SmallVectorImpl< std::unique_ptr< Command > > &&ScannedJobs, SmallVectorImpl< InputDependencies > &&InputDepsForScannedJobs) |
| Creates nodes for all jobs which were scanned for dependencies. | |
| template<typename LookupT, typename KeyRangeT> | |
| static void | connectEdgesViaLookup (CompilationGraph &Graph, CGNode &TgtNode, const LookupT &SrcNodeLookup, const KeyRangeT &SrcNodeLookupKeys, CGEdge::EdgeKind Kind) |
| static void | createRegularEdges (CompilationGraph &Graph) |
Create edges for regular (non-module) dependencies in Graph. | |
| static bool | createModuleDependencyEdges (CompilationGraph &Graph, DiagnosticsEngine &Diags) |
Create edges for module dependencies in Graph. | |
| static void | pruneUnusedStdlibModuleJobs (CompilationGraph &Graph, ArrayRef< JobNode * > UnusedStdlibModuleJobNodes) |
| Prunes the compilation graph of any jobs which build Standard library modules not required in this compilation. | |
| static void | createAndConnectRoot (CompilationGraph &Graph) |
| Creates the root node and connects it to all nodes with no incoming edges ensuring that every node in the graph is reachable from the root. | |
This file defines functionality to support driver managed builds for compilations which use Clang modules or standard C++20 named modules.
Definition in file ModulesDriver.cpp.
| using ManifestEntryLookup |
Definition at line 144 of file ModulesDriver.cpp.
| using ModuleNameAndTriple = std::pair<StringRef, StringRef> |
Definition at line 331 of file ModulesDriver.cpp.
|
static |
Adds all SystemIncludeDirs to the CC1Args of Job.
Definition at line 175 of file ModulesDriver.cpp.
References clang::driver::ToolChain::addSystemInclude(), clang::C, clang::driver::Command::getCreator(), clang::driver::Action::getOffloadingArch(), clang::driver::Action::getOffloadingDeviceKind(), clang::driver::Command::getSource(), and clang::driver::Tool::getToolChain().
Referenced by applyArgsForStdModuleManifestInputs().
|
static |
Apply command-line modifications specific for inputs originating from the Standard library module manifest.
Definition at line 193 of file ModulesDriver.cpp.
References addSystemIncludeDirsFromManifest(), clang::C, getManifestEntryForCommand(), and isCC1Job().
Referenced by clang::driver::modules::runModulesDriver().
|
static |
Constructs the full command line, including the executable, for Job.
Definition at line 534 of file ModulesDriver.cpp.
References clang::driver::Command::getArguments(), and clang::driver::Command::getExecutable().
Referenced by scanDependenciesForJob().
|
static |
Builds a mapping from a module's source path to its entry in the manifest.
Definition at line 149 of file ModulesDriver.cpp.
Referenced by clang::driver::modules::runModulesDriver().
|
static |
Definition at line 1324 of file ModulesDriver.cpp.
Referenced by createModuleDependencyEdges(), and createRegularEdges().
|
static |
Construct a path for the explicitly built PCM.
Definition at line 456 of file ModulesDriver.cpp.
|
static |
Creates the root node and connects it to all nodes with no incoming edges ensuring that every node in the graph is reachable from the root.
Definition at line 1483 of file ModulesDriver.cpp.
Referenced by clang::driver::modules::runModulesDriver().
|
static |
Creates a ClangModuleJobNode with associated job for each unique Clang module in ModuleDepGraphsForScannedJobs.
| ImportingJobs | Jobs whose module dependencies were scanned. |
| ModuleDepGraphsForScannedJobs | Full Clang module dependency graphs corresponding to ImportingJobs, in order. |
Definition at line 1259 of file ModulesDriver.cpp.
References clang::C, createClangModulePrecompileJob(), and clang::dependencies::ModuleDeps::ID.
Referenced by clang::driver::modules::runModulesDriver().
|
static |
Creates a job for the Clang module described by MD.
Definition at line 1227 of file ModulesDriver.cpp.
References clang::driver::ResponseFileSupport::AtFileUTF8(), clang::C, clang::dependencies::ModuleDeps::getBuildArguments(), clang::driver::Command::getCreator(), clang::driver::Command::getSource(), clang::driver::Tool::getToolChain(), clang::driver::makeInputArg(), and clang::driver::Action::propagateOffloadInfo().
Referenced by createClangModuleJobsAndNodes().
|
static |
Create edges for module dependencies in Graph.
Diags; otherwise returns true. Definition at line 1364 of file ModulesDriver.cpp.
References clang::cast(), clang::dependencies::ModuleDeps::ClangModuleDeps, connectEdgesViaLookup(), getFirstInputFilename(), getTriple(), clang::dependencies::ModuleDeps::ID, and clang::DiagnosticsEngine::Report().
Referenced by clang::driver::modules::runModulesDriver().
|
static |
Creates nodes for all jobs that could not be scanned (e.g. image jobs, ...).
Definition at line 1198 of file ModulesDriver.cpp.
Referenced by clang::driver::modules::runModulesDriver().
|
static |
Creates nodes for all jobs which were scanned for dependencies.
The updated command lines produced by the dependency scan are installed at a later point.
Definition at line 1308 of file ModulesDriver.cpp.
Referenced by clang::driver::modules::runModulesDriver().
|
static |
Creates nodes for the Standard library module jobs not discovered as dependencies.
These and any dependent (non-image) job nodes should be pruned from the graph later.
Definition at line 1214 of file ModulesDriver.cpp.
Referenced by clang::driver::modules::runModulesDriver().
|
static |
Definition at line 293 of file ModulesDriver.cpp.
Referenced by scanDependencies().
|
static |
Create edges for regular (non-module) dependencies in Graph.
Definition at line 1339 of file ModulesDriver.cpp.
References clang::cast(), and connectEdgesViaLookup().
Referenced by clang::driver::modules::runModulesDriver().
|
static |
Definition at line 958 of file ModulesDriver.cpp.
References clang::driver::Command::getInputInfos().
Referenced by createModuleDependencyEdges(), llvm::DOTGraphTraits< const CompilationGraph * >::getNodeIdentifier(), and llvm::DOTGraphTraits< const CompilationGraph * >::getNodeLabel().
|
static |
Returns the manifest entry corresponding to Job, or nullptr if none exists.
Definition at line 163 of file ModulesDriver.cpp.
References clang::driver::Command::getInputInfos().
Referenced by applyArgsForStdModuleManifestInputs(), and scanDependencies().
|
static |
Computes the -fmodule-cache-path for this compilation.
Definition at line 216 of file ModulesDriver.cpp.
References clang::driver::Driver::getDefaultModuleCachePath().
Referenced by clang::driver::modules::runModulesDriver().
|
static |
Definition at line 327 of file ModulesDriver.cpp.
References clang::driver::Command::getCreator(), clang::driver::Tool::getToolChain(), and clang::driver::ToolChain::getTriple().
Referenced by clang::driver::toolchains::MinGW::AddClangSystemIncludeArgs(), clang::driver::toolchains::PS4PS5Base::addClangTargetOptions(), clang::driver::tools::ClangAs::AddLoongArchTargetArgs(), clang::driver::toolchains::HIPSPVToolChain::buildLinker(), clang::Sema::BuildPointerType(), clang::Sema::BuildReferenceType(), clang::ASTContext::canBuiltinBeRedeclared(), clang::driver::tools::amdgpu::Linker::ConstructJob(), clang::driver::tools::AVR::Linker::ConstructJob(), clang::driver::tools::Clang::ConstructJob(), clang::driver::tools::darwin::Assembler::ConstructJob(), clang::driver::tools::darwin::Linker::ConstructJob(), clang::driver::tools::gcc::Common::ConstructJob(), clang::driver::tools::gnutools::Assembler::ConstructJob(), clang::driver::tools::gnutools::Linker::ConstructJob(), clang::driver::tools::NVPTX::Linker::ConstructJob(), createModuleDependencyEdges(), clang::driver::toolchains::ROCMToolChain::diagnoseUnsupportedOption(), clang::CodeGen::CodeGenFunction::EmitAMDGPUBuiltinExpr(), clang::CodeGen::CodeGenFunction::EmitAMDGPUDevicePrintfCallExpr(), clang::CodeGen::CodeGenFunction::EmitBuiltinExpr(), clang::CIRGen::CIRGenFunction::emitBuiltinExpr(), clang::CodeGen::CodeGenFunction::EmitCall(), clang::CodeGen::CodeGenFunction::EmitCallArgs(), clang::CodeGen::CodeGenFunction::EmitHLSLBuiltinExpr(), clang::CodeGen::CodeGenFunction::EmitMultiVersionResolver(), clang::CodeGen::CodeGenFunction::EmitNVPTXDevicePrintfCallExpr(), clang::CodeGen::CodeGenFunction::EmitPPCBuiltinExpr(), clang::CodeGen::CodeGenFunction::EmitRISCVMultiVersionResolver(), clang::CodeGen::CodeGenFunction::EmitTargetBuiltinExpr(), clang::CIRGen::CIRGenFunction::emitTargetBuiltinExpr(), clang::CodeGen::CodeGenFunction::EmitX86BuiltinExpr(), clang::CodeGen::CodeGenFunction::FinishFunction(), clang::targets::X86TargetInfo::getABI(), clang::driver::toolchains::HexagonToolChain::getBaseIncludeDir(), clang::targets::ARMTargetInfo::getBuiltinVaListKind(), clang::targets::HexagonTargetInfo::getBuiltinVaListKind(), clang::driver::toolchains::MSVCToolChain::getDefaultDebugFormat(), clang::driver::toolchains::HexagonToolChain::getDefaultLinker(), clang::driver::toolchains::HIPSPVToolChain::getDeviceLibs(), clang::driver::toolchains::HexagonToolChain::getEffectiveSysRoot(), clang::targets::DarwinTargetInfo< Target >::getExnObjectAlignment(), clang::driver::toolchains::HexagonToolChain::getLibraryDir(), clang::targets::AMDGPUTargetInfo::getMaxPointerWidth(), llvm::DOTGraphTraits< const CompilationGraph * >::getNodeIdentifier(), llvm::DOTGraphTraits< const CompilationGraph * >::getNodeLabel(), clang::ASTContext::getOpenMPDefaultSimdAlign(), clang::targets::AMDGPUTargetInfo::getPointerWidthV(), clang::targets::SystemZTargetInfo::getPointerWidthV(), clang::driver::toolchains::OpenBSD::getSupportedSanitizers(), clang::targets::AMDGPUTargetInfo::getTargetID(), clang::SemaX86::handleAnyInterruptAttr(), clang::targets::AMDGPUTargetInfo::handleTargetFeatures(), clang::targets::SystemZTargetInfo::handleTargetFeatures(), clang::targets::AMDGPUTargetInfo::hasBFloat16Type(), clang::TargetInfo::hasPS4DLLImportExport(), clang::driver::toolchains::Darwin::isMacosxVersionLT(), clang::driver::toolchains::MachO::IsObjCNonFragileABIDefault(), clang::TargetInfo::isSEHTrySupported(), clang::driver::toolchains::Generic_GCC::isTarget32Bit(), clang::driver::toolchains::Generic_GCC::isTarget64Bit(), clang::targets::AMDGPUTargetInfo::isValidCPUName(), clang::targets::X86TargetInfo::isValidCPUName(), clang::targets::PPC32TargetInfo::PPC32TargetInfo(), clang::CodeGen::CodeGenFunction::ProcessOrderScopeAMDGCN(), scanDependencies(), clang::targets::AMDGPUTargetInfo::setCPU(), clang::targets::X86TargetInfo::setCPU(), clang::targets::PPC64TargetInfo::setMaxAtomicWidth(), clang::targets::MipsTargetInfo::setN32N64ABITypes(), clang::targets::MipsTargetInfo::setN64ABITypes(), clang::targets::AMDGPUTargetInfo::setSupportedOpenCLOpts(), clang::TargetInfo::shouldDLLImportComdatSymbols(), clang::targets::SparcV8TargetInfo::SparcV8TargetInfo(), clang::targets::SparcV9TargetInfo::SparcV9TargetInfo(), clang::targets::SPIRTargetInfo::SPIRTargetInfo(), clang::targets::SPIRV32TargetInfo::SPIRV32TargetInfo(), clang::targets::SPIRV64AMDGCNTargetInfo::SPIRV64AMDGCNTargetInfo(), clang::targets::SPIRV64TargetInfo::SPIRV64TargetInfo(), clang::CodeGen::CodeGenFunction::StartFunction(), clang::targets::PPCTargetInfo::supportsCpuIs(), clang::targets::PPCTargetInfo::supportsCpuSupports(), clang::targets::X86TargetInfo::supportsExtendIntArgs(), clang::TargetInfo::supportsIFunc(), clang::TargetInfo::supportsMultiVersioning(), TargetOMPContext::TargetOMPContext(), clang::targets::WindowsX86_32TargetInfo::WindowsX86_32TargetInfo(), clang::targets::X86_64TargetInfo::X86_64TargetInfo(), and clang::targets::X86TargetInfo::X86TargetInfo().
|
static |
Installs the command lines produced by the dependency scan into ScannedJobs.
Definition at line 1282 of file ModulesDriver.cpp.
References clang::C.
Referenced by clang::driver::modules::runModulesDriver().
Definition at line 187 of file ModulesDriver.cpp.
References clang::driver::Command::getCreator(), and clang::driver::Tool::getName().
Referenced by applyArgsForStdModuleManifestInputs(), and isDependencyScannableJob().
Returns true if a dependency scan can be performed using Job.
Definition at line 227 of file ModulesDriver.cpp.
References clang::driver::Command::getInputInfos(), isCC1Job(), and clang::driver::types::isSrcFile().
Referenced by scanDependencies().
|
static |
Definition at line 522 of file ModulesDriver.cpp.
Referenced by scanDependencies().
|
static |
Converts each file path in manifest from relative to absolute.
Each file path in the manifest is expected to be relative the manifest's location ManifestPath itself.
Definition at line 94 of file ModulesDriver.cpp.
|
static |
Parses the Standard library module manifest from Buffer.
Definition at line 77 of file ModulesDriver.cpp.
References clang::driver::modules::fromJSON().
|
static |
Prunes the compilation graph of any jobs which build Standard library modules not required in this compilation.
Definition at line 1433 of file ModulesDriver.cpp.
References clang::cast().
Referenced by clang::driver::modules::runModulesDriver().
|
static |
Report the diagnostics collected during each dependency scan.
Definition at line 447 of file ModulesDriver.cpp.
Referenced by scanDependencies().
|
static |
Scans the compilations job list Jobs for module dependencies.
Standard library module jobs are scanned on demand if imported by any user-provided input.
Diags in both cases. Definition at line 597 of file ModulesDriver.cpp.
References createOptimalThreadAndWorkerPool(), std::function, getManifestEntryForCommand(), getTriple(), isDependencyScannableJob(), makeInputDeps(), reportAllScanDiagnostics(), and scanDependenciesForJob().
Referenced by clang::driver::modules::runModulesDriver().
|
static |
Performs a dependency scan for a single job.
Definition at line 550 of file ModulesDriver.cpp.
References buildCommandLine(), and clang::dependencies::FullDependencyConsumer::takeTranslationUnitDeps().
Referenced by scanDependencies().
|
static |
Definition at line 1187 of file ModulesDriver.cpp.
Referenced by clang::driver::modules::runModulesDriver().