Skip to content

Commit c4fb64e

Browse files
committed
[llvm-objdump] Replace std::unordered_multimap with llvm::MapVector
1 parent 71d057a commit c4fb64e

File tree

2 files changed

+36
-31
lines changed

2 files changed

+36
-31
lines changed

llvm/tools/llvm-objdump/SourcePrinter.cpp

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ void LiveElementPrinter::addInlinedFunction(DWARFDie FuncDie,
126126
InlinedFuncName, U, FuncDie, InlinedFuncDie, Range));
127127
// Map the element's low address (LowPC) to its pointer for fast range start
128128
// lookup.
129-
LiveElementsByAddress.emplace(FuncLowPC, LiveElements.back().get());
129+
LiveElementsByAddress[FuncLowPC].push_back(LiveElements.back().get());
130130
// Map the element's high address (HighPC) to its pointer for fast range end
131131
// lookup.
132-
LiveElementsByEndAddress.emplace(FuncHighPC, LiveElements.back().get());
132+
LiveElementsByEndAddress[FuncHighPC].push_back(LiveElements.back().get());
133133
// Map the pointer to its DWARF discovery index (ElementIdx) for deterministic
134134
// ordering.
135135
ElementPtrToIndex[LiveElements.back().get()] = LiveElements.size() - 1;
@@ -175,10 +175,10 @@ void LiveElementPrinter::addVariable(DWARFDie FuncDie, DWARFDie VarDie) {
175175
ElementPtrToIndex.emplace(CurrentVar, LiveElements.size() - 1);
176176
if (CurrentVar->getLocExpr().Range) {
177177
// Add the variable to address-based maps.
178-
LiveElementsByAddress.emplace(CurrentVar->getLocExpr().Range->LowPC,
179-
CurrentVar);
180-
LiveElementsByEndAddress.emplace(CurrentVar->getLocExpr().Range->HighPC,
181-
CurrentVar);
178+
LiveElementsByAddress[CurrentVar->getLocExpr().Range->LowPC].push_back(
179+
CurrentVar);
180+
LiveElementsByEndAddress[CurrentVar->getLocExpr().Range->HighPC]
181+
.push_back(CurrentVar);
182182
}
183183
}
184184
}
@@ -345,12 +345,13 @@ void LiveElementPrinter::update(object::SectionedAddress ThisAddr,
345345
if (IncludeDefinedVars) {
346346
// Collect all elements starting at ThisAddr and NextAddr.
347347
std::vector<std::pair<unsigned, LiveElement *>> NewLiveElements;
348-
// Process elements from a map range and add them to NewLiveElements.
349-
auto CollectNewElements = [&](const auto &Range) {
350-
for (auto it = Range.first; it != Range.second; ++it) {
351-
LiveElement *LE = it->second;
348+
auto CollectNewElements = [&](const auto &It) {
349+
if (It == LiveElementsByAddress.end())
350+
return;
352351

353-
// Get the ElementIdx for sorting and column management.
352+
const std::vector<LiveElement *> &ElementList = It->second;
353+
// Get the ElementIdx for sorting and column management.
354+
for (LiveElement *LE : ElementList) {
354355
auto IndexIt = ElementPtrToIndex.find(LE);
355356
if (IndexIt == ElementPtrToIndex.end()) {
356357
LLVM_DEBUG(
@@ -374,10 +375,10 @@ void LiveElementPrinter::update(object::SectionedAddress ThisAddr,
374375
};
375376

376377
// Collect elements starting at ThisAddr.
377-
CollectNewElements(LiveElementsByAddress.equal_range(ThisAddr.Address));
378-
// Collect elements starting at NextAddr (the address immediately following
379-
// the instruction).
380-
CollectNewElements(LiveElementsByAddress.equal_range(NextAddr.Address));
378+
CollectNewElements(LiveElementsByAddress.find(ThisAddr.Address));
379+
// Collect elements starting at NextAddr (the address immediately
380+
// following the instruction).
381+
CollectNewElements(LiveElementsByAddress.find(NextAddr.Address));
381382
// Sort elements by DWARF discovery order (ElementIdx) for deterministic
382383
// column assignment.
383384
llvm::stable_sort(NewLiveElements, [](const auto &A, const auto &B) {
@@ -573,14 +574,15 @@ void LiveElementPrinter::printStartLine(formatted_raw_ostream &OS,
573574
return;
574575

575576
// Use the map to find all elements that start at the given address.
576-
auto Range = LiveElementsByAddress.equal_range(Addr.Address);
577577
std::vector<unsigned> ElementIndices;
578-
for (auto it = Range.first; it != Range.second; ++it) {
579-
LiveElement *LE = it->second;
580-
// Look up the ElementIdx from the pointer.
581-
auto IndexIt = ElementPtrToIndex.find(LE);
582-
if (IndexIt != ElementPtrToIndex.end())
583-
ElementIndices.push_back(IndexIt->second);
578+
auto It = LiveElementsByAddress.find(Addr.Address);
579+
if (It != LiveElementsByAddress.end()) {
580+
for (LiveElement *LE : It->second) {
581+
// Look up the ElementIdx from the pointer.
582+
auto IndexIt = ElementPtrToIndex.find(LE);
583+
if (IndexIt != ElementPtrToIndex.end())
584+
ElementIndices.push_back(IndexIt->second);
585+
}
584586
}
585587

586588
// Sort the indices to ensure deterministic output order (by DWARF discovery
@@ -601,14 +603,15 @@ void LiveElementPrinter::printEndLine(formatted_raw_ostream &OS,
601603
return;
602604

603605
// Use the map to find elements that end at the given address.
604-
auto Range = LiveElementsByEndAddress.equal_range(Addr.Address);
605606
std::vector<unsigned> ElementIndices;
606-
for (auto it = Range.first; it != Range.second; ++it) {
607-
LiveElement *LE = it->second;
608-
// Look up the ElementIdx from the pointer.
609-
auto IndexIt = ElementPtrToIndex.find(LE);
610-
if (IndexIt != ElementPtrToIndex.end())
611-
ElementIndices.push_back(IndexIt->second);
607+
auto It = LiveElementsByEndAddress.find(Addr.Address);
608+
if (It != LiveElementsByEndAddress.end()) {
609+
for (LiveElement *LE : It->second) {
610+
// Look up the ElementIdx from the pointer.
611+
auto IndexIt = ElementPtrToIndex.find(LE);
612+
if (IndexIt != ElementPtrToIndex.end())
613+
ElementIndices.push_back(IndexIt->second);
614+
}
612615
}
613616

614617
// Sort the indices to ensure deterministic output order (by DWARF discovery

llvm/tools/llvm-objdump/SourcePrinter.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLVM_TOOLS_LLVM_OBJDUMP_SOURCEPRINTER_H
1111

1212
#include "llvm/ADT/IndexedMap.h"
13+
#include "llvm/ADT/MapVector.h"
1314
#include "llvm/ADT/StringSet.h"
1415
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
1516
#include "llvm/DebugInfo/Symbolize/Symbolize.h"
@@ -101,9 +102,10 @@ class LiveElementPrinter {
101102
// Vector that owns all LiveElement objects for memory management.
102103
std::vector<std::unique_ptr<LiveElement>> LiveElements;
103104
// Map for fast lookup of live elements by their starting address (LowPC).
104-
std::unordered_multimap<uint64_t, LiveElement *> LiveElementsByAddress;
105+
llvm::MapVector<uint64_t, std::vector<LiveElement *>> LiveElementsByAddress;
105106
// Map for fast lookup of live elements by their ending address (HighPC).
106-
std::unordered_multimap<uint64_t, LiveElement *> LiveElementsByEndAddress;
107+
llvm::MapVector<uint64_t, std::vector<LiveElement *>>
108+
LiveElementsByEndAddress;
107109
// Map from a LiveElement pointer to its index in the LiveElements vector.
108110
std::unordered_map<LiveElement *, unsigned> ElementPtrToIndex;
109111
// Map from a live element index to column index for efficient lookup.

0 commit comments

Comments
 (0)