aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/ModuleSummaryIndex.cpp
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2023-07-31 11:32:11 -0700
committerTeresa Johnson <tejohnson@google.com>2023-09-01 13:43:08 -0700
commitbbe8cd13335300958b04db5318c31ff52714f96f (patch)
tree52d3291f070d9f991fd61a73645978be27cef97e /llvm/lib/IR/ModuleSummaryIndex.cpp
parentb0b3f82dd3c00cdba891f1ff6ba63abd419d0f18 (diff)
downloadllvm-bbe8cd13335300958b04db5318c31ff52714f96f.zip
llvm-bbe8cd13335300958b04db5318c31ff52714f96f.tar.gz
llvm-bbe8cd13335300958b04db5318c31ff52714f96f.tar.bz2
[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
Diffstat (limited to 'llvm/lib/IR/ModuleSummaryIndex.cpp')
-rw-r--r--llvm/lib/IR/ModuleSummaryIndex.cpp16
1 files changed, 15 insertions, 1 deletions
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<StringRef, GVSOrderedMapTy> 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<StringRef> ModulePaths;
+ for (auto &[ModPath, _] : modulePaths())
+ ModulePaths.push_back(ModPath);
+ llvm::sort(ModulePaths);
+ DenseMap<StringRef, uint64_t> ModuleIdMap;
+ for (auto &ModPath : ModulePaths)
+ ModuleIdMap.try_emplace(ModPath, ModuleIdMap.size());
+
// Get node identifier in form MXXX_<GUID>. 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";