aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/IR/ModuleSummaryIndex.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-12-18 20:30:12 +0000
committerDimitry Andric <dim@FreeBSD.org>2024-04-19 21:12:03 +0000
commitc9157d925c489f07ba9c0b2ce47e5149b75969a5 (patch)
tree08bc4a3d9cad3f9ebffa558ddf140b9d9257b219 /contrib/llvm-project/llvm/lib/IR/ModuleSummaryIndex.cpp
parent2a66844f606a35d68ad8a8061f4bea204274b3bc (diff)
Diffstat (limited to 'contrib/llvm-project/llvm/lib/IR/ModuleSummaryIndex.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/IR/ModuleSummaryIndex.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/contrib/llvm-project/llvm/lib/IR/ModuleSummaryIndex.cpp b/contrib/llvm-project/llvm/lib/IR/ModuleSummaryIndex.cpp
index 15fe342969d6..198c730418c7 100644
--- a/contrib/llvm-project/llvm/lib/IR/ModuleSummaryIndex.cpp
+++ b/contrib/llvm-project/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";