aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR
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
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')
-rw-r--r--llvm/lib/IR/AsmWriter.cpp22
-rw-r--r--llvm/lib/IR/ModuleSummaryIndex.cpp16
2 files changed, 26 insertions, 12 deletions
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index be4a3ed..e190d82 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -1069,12 +1069,13 @@ int SlotTracker::processIndex() {
// The first block of slots are just the module ids, which start at 0 and are
// assigned consecutively. Since the StringMap iteration order isn't
- // guaranteed, use a std::map to order by module ID before assigning slots.
- std::map<uint64_t, StringRef> ModuleIdToPathMap;
- for (auto &[ModPath, ModId] : TheIndex->modulePaths())
- ModuleIdToPathMap[ModId.first] = ModPath;
- for (auto &ModPair : ModuleIdToPathMap)
- CreateModulePathSlot(ModPair.second);
+ // guaranteed, order by path string before assigning slots.
+ std::vector<StringRef> ModulePaths;
+ for (auto &[ModPath, _] : TheIndex->modulePaths())
+ ModulePaths.push_back(ModPath);
+ llvm::sort(ModulePaths.begin(), ModulePaths.end());
+ for (auto &ModPath : ModulePaths)
+ CreateModulePathSlot(ModPath);
// Start numbering the GUIDs after the module ids.
GUIDNext = ModulePathNext;
@@ -2890,12 +2891,11 @@ void AssemblyWriter::printModuleSummaryIndex() {
std::string RegularLTOModuleName =
ModuleSummaryIndex::getRegularLTOModuleName();
moduleVec.resize(TheIndex->modulePaths().size());
- for (auto &[ModPath, ModId] : TheIndex->modulePaths())
+ for (auto &[ModPath, ModHash] : TheIndex->modulePaths())
moduleVec[Machine.getModulePathSlot(ModPath)] = std::make_pair(
- // A module id of -1 is a special entry for a regular LTO module created
- // during the thin link.
- ModId.first == -1u ? RegularLTOModuleName : std::string(ModPath),
- ModId.second);
+ // An empty module path is a special entry for a regular LTO module
+ // created during the thin link.
+ ModPath.empty() ? RegularLTOModuleName : std::string(ModPath), ModHash);
unsigned i = 0;
for (auto &ModPair : moduleVec) {
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";