Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 43 additions & 21 deletions clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,40 +394,62 @@ void ModuleDepCollector::addModuleMapFiles(
if (Service.shouldEagerLoadModules())
return; // Only pcm is needed for eager load.

// Preallocate memory to avoid multiple allocations
CI.getFrontendOpts().ModuleMapFiles.reserve(
CI.getFrontendOpts().ModuleMapFiles.size() + ClangModuleDeps.size());

for (const ModuleID &MID : ClangModuleDeps) {
ModuleDeps *MD = ModuleDepsByID.lookup(MID);
assert(MD && "Inconsistent dependency info");
CI.getFrontendOpts().ModuleMapFiles.push_back(MD->ClangModuleMapFile);

if (ModuleDeps *MD = ModuleDepsByID.lookup(MID)) { // Single lookup
assert(MD && "Inconsistent dependency info");
CI.getFrontendOpts().ModuleMapFiles.emplace_back(MD->ClangModuleMapFile);
}
}
}

void ModuleDepCollector::addModuleFiles(
CompilerInvocation &CI, ArrayRef<ModuleID> ClangModuleDeps) const {

// Preallocate memory if eager load is enabled
if (Service.shouldEagerLoadModules()) {
CI.getFrontendOpts().ModuleFiles.reserve(
CI.getFrontendOpts().ModuleFiles.size() + ClangModuleDeps.size());
}
for (const ModuleID &MID : ClangModuleDeps) {
ModuleDeps *MD = ModuleDepsByID.lookup(MID);
std::string PCMPath =
Controller.lookupModuleOutput(*MD, ModuleOutputKind::ModuleFile);

if (Service.shouldEagerLoadModules())
CI.getFrontendOpts().ModuleFiles.push_back(std::move(PCMPath));
else
CI.getHeaderSearchOpts().PrebuiltModuleFiles.insert(
{MID.ModuleName, std::move(PCMPath)});
if (ModuleDeps *MD = ModuleDepsByID.lookup(MID)) {
std::string PCMPath =
Controller.lookupModuleOutput(*MD, ModuleOutputKind::ModuleFile);

if (Service.shouldEagerLoadModules()) {
CI.getFrontendOpts().ModuleFiles.emplace_back(std::move(PCMPath));
} else {
CI.getHeaderSearchOpts().PrebuiltModuleFiles.try_emplace(
MID.ModuleName, std::move(PCMPath));
}
}
}
}

void ModuleDepCollector::addModuleFiles(
CowCompilerInvocation &CI, ArrayRef<ModuleID> ClangModuleDeps) const {
for (const ModuleID &MID : ClangModuleDeps) {
ModuleDeps *MD = ModuleDepsByID.lookup(MID);
std::string PCMPath =
Controller.lookupModuleOutput(*MD, ModuleOutputKind::ModuleFile);

if (Service.shouldEagerLoadModules())
CI.getMutFrontendOpts().ModuleFiles.push_back(std::move(PCMPath));
else
CI.getMutHeaderSearchOpts().PrebuiltModuleFiles.insert(
{MID.ModuleName, std::move(PCMPath)});
// Preallocation
if (Service.shouldEagerLoadModules()) {
CI.getMutFrontendOpts().ModuleFiles.reserve(
CI.getMutFrontendOpts().ModuleFiles.size() + ClangModuleDeps.size());
}
for (const ModuleID &MID : ClangModuleDeps) {
if (ModuleDeps *MD = ModuleDepsByID.lookup(MID)) {
std::string PCMPath =
Controller.lookupModuleOutput(*MD, ModuleOutputKind::ModuleFile);

if (EagerLoad) {
CI.getMutFrontendOpts().ModuleFiles.emplace_back(std::move(PCMPath));
} else {
CI.getMutHeaderSearchOpts().PrebuiltModuleFiles.try_emplace(
MID.ModuleName, std::move(PCMPath));
}
}
}
}

Expand Down