From bbe8cd13335300958b04db5318c31ff52714f96f Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Mon, 31 Jul 2023 11:32:11 -0700 Subject: [LTO] Remove module id from summary index The module paths string table mapped to both an id sequentially assigned during LTO linking, and the module hash. The former is leftover from before the module hash was added for caching and subsequently replaced use of the module id when renaming promoted symbols (to avoid affects due to link order changes). The sequentially assigned module id was not removed, however, as it was still a convenience when serializing to/from bitcode and assembly. This patch removes the module id from this table, since it isn't strictly needed and can lead to confusion on when it is appropriate to use (e.g. see fix in D156525). It also takes a (likely not significant) amount of overhead. Where an integer module id is needed (e.g. bitcode writing), one is assigned on the fly. There are a couple of test changes since the paths are now sorted alphanumerically when assigning ids on the fly during assembly writing, in order to ensure deterministic behavior. Differential Revision: https://reviews.llvm.org/D156730 --- llvm/lib/IR/ModuleSummaryIndex.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'llvm/lib/IR/ModuleSummaryIndex.cpp') diff --git a/llvm/lib/IR/ModuleSummaryIndex.cpp b/llvm/lib/IR/ModuleSummaryIndex.cpp index 15fe342..198c730 100644 --- a/llvm/lib/IR/ModuleSummaryIndex.cpp +++ b/llvm/lib/IR/ModuleSummaryIndex.cpp @@ -554,6 +554,17 @@ void ModuleSummaryIndex::exportToDot( std::map ModuleToDefinedGVS; collectDefinedGVSummariesPerModule(ModuleToDefinedGVS); + // Assign an id to each module path for use in graph labels. Since the + // StringMap iteration order isn't guaranteed, order by path string before + // assigning ids. + std::vector ModulePaths; + for (auto &[ModPath, _] : modulePaths()) + ModulePaths.push_back(ModPath); + llvm::sort(ModulePaths); + DenseMap ModuleIdMap; + for (auto &ModPath : ModulePaths) + ModuleIdMap.try_emplace(ModPath, ModuleIdMap.size()); + // Get node identifier in form MXXX_. The MXXX prefix is required, // because we may have multiple linkonce functions summaries. auto NodeId = [](uint64_t ModId, GlobalValue::GUID Id) { @@ -589,7 +600,10 @@ void ModuleSummaryIndex::exportToDot( OS << "digraph Summary {\n"; for (auto &ModIt : ModuleToDefinedGVS) { - auto ModId = getModuleId(ModIt.first); + // Will be empty for a just built per-module index, which doesn't setup a + // module paths table. In that case use 0 as the module id. + assert(ModuleIdMap.count(ModIt.first) || ModuleIdMap.empty()); + auto ModId = ModuleIdMap.empty() ? 0 : ModuleIdMap[ModIt.first]; OS << " // Module: " << ModIt.first << "\n"; OS << " subgraph cluster_" << std::to_string(ModId) << " {\n"; OS << " style = filled;\n"; -- cgit v1.1