[PATCH] D27991: Optimize objdump -objc-meta-data
Dave Lee via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 20 09:52:27 PST 2016
kastiglione created this revision.
kastiglione added a reviewer: compnerd.
kastiglione added a subscriber: llvm-commits.
Running a Debug build of `objdump -objc-meta-data` with a large Mach-O file is currently unnecessarily slow.
With some local test input, this change reduces the run time from 75-85s down to 15-20s.
The two changes are:
1. Assert on pointer equality not array equality
2. Replace vector<pair<address, symbol>> with DenseMap<address, symbol>
https://reviews.llvm.org/D27991
Files:
lib/Object/MachOObjectFile.cpp
tools/llvm-objdump/MachODump.cpp
Index: tools/llvm-objdump/MachODump.cpp
===================================================================
--- tools/llvm-objdump/MachODump.cpp
+++ tools/llvm-objdump/MachODump.cpp
@@ -1780,10 +1780,6 @@
llvm_unreachable("Input object can't be invalid at this point");
}
-typedef std::pair<uint64_t, const char *> BindInfoEntry;
-typedef std::vector<BindInfoEntry> BindTable;
-typedef BindTable::iterator bind_table_iterator;
-
// The block of info used by the Symbolizer call backs.
struct DisassembleInfo {
bool verbose;
@@ -1797,7 +1793,7 @@
char *demangled_name;
uint64_t adrp_addr;
uint32_t adrp_inst;
- BindTable *bindtable;
+ SymbolAddressMap *bindtable;
uint32_t depth;
};
@@ -9427,29 +9423,19 @@
static const char *get_dyld_bind_info_symbolname(uint64_t ReferenceValue,
struct DisassembleInfo *info) {
if (info->bindtable == nullptr) {
- info->bindtable = new (BindTable);
+ info->bindtable = new (SymbolAddressMap);
SegInfo sectionTable(info->O);
for (const llvm::object::MachOBindEntry &Entry : info->O->bindTable()) {
uint32_t SegIndex = Entry.segmentIndex();
uint64_t OffsetInSeg = Entry.segmentOffset();
if (!sectionTable.isValidSegIndexAndOffset(SegIndex, OffsetInSeg))
continue;
uint64_t Address = sectionTable.address(SegIndex, OffsetInSeg);
- const char *SymbolName = nullptr;
StringRef name = Entry.symbolName();
if (!name.empty())
- SymbolName = name.data();
- info->bindtable->push_back(std::make_pair(Address, SymbolName));
+ (*info->bindtable)[Address] = name;
}
}
- for (bind_table_iterator BI = info->bindtable->begin(),
- BE = info->bindtable->end();
- BI != BE; ++BI) {
- uint64_t Address = BI->first;
- if (ReferenceValue == Address) {
- const char *SymbolName = BI->second;
- return SymbolName;
- }
- }
- return nullptr;
+ auto name = info->bindtable->lookup(ReferenceValue);
+ return !name.empty() ? name.data() : nullptr;
}
Index: lib/Object/MachOObjectFile.cpp
===================================================================
--- lib/Object/MachOObjectFile.cpp
+++ lib/Object/MachOObjectFile.cpp
@@ -2823,7 +2823,9 @@
}
bool MachORebaseEntry::operator==(const MachORebaseEntry &Other) const {
- assert(Opcodes == Other.Opcodes && "compare iterators of different files");
+ assert(
+ (Opcodes.begin() == Other.Opcodes.begin() || Opcodes == Other.Opcodes) &&
+ "compare iterators of different files");
return (Ptr == Other.Ptr) &&
(RemainingLoopCount == Other.RemainingLoopCount) &&
(Done == Other.Done);
@@ -3073,7 +3075,9 @@
int MachOBindEntry::ordinal() const { return Ordinal; }
bool MachOBindEntry::operator==(const MachOBindEntry &Other) const {
- assert(Opcodes == Other.Opcodes && "compare iterators of different files");
+ assert(
+ (Opcodes.begin() == Other.Opcodes.begin() || Opcodes == Other.Opcodes) &&
+ "compare iterators of different files");
return (Ptr == Other.Ptr) &&
(RemainingLoopCount == Other.RemainingLoopCount) &&
(Done == Other.Done);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27991.82117.patch
Type: text/x-patch
Size: 3212 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161220/19aa47c8/attachment.bin>
More information about the llvm-commits
mailing list