[PATCH] D118041: [Dwarf] Optimize getOrCreateSourceID() for repeated calls on same file (NFCI)
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 24 06:28:20 PST 2022
nikic created this revision.
Herald added a subscriber: hiraditya.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
`DwarfCompileUnit::getOrCreateSourceID()` is often called many times in sequence with the same `DIFile`. This is currently very expensive, because it involves creating a string from directory and file name and looking it up in a string map. This patch remembers the last DIFile and its ID and directly returns that.
This gives a geomean -1.3% compile-time improvement on `O0-g`: http://llvm-compile-time-tracker.com/compare.php?from=0d1308a7b77c9ed87386c22a728a6c97e2fb4887&to=0524863ab347cbb6f897844203d066869b8bee31&stat=instructions
Disclaimer: I'm not familiar with the area, but this kind of caching looks legal to me.
https://reviews.llvm.org/D118041
Files:
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
Index: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
+++ llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
@@ -86,6 +86,9 @@
/// DWO ID for correlating skeleton and split units.
uint64_t DWOId = 0;
+ const DIFile *LastFile = nullptr;
+ unsigned LastFileID;
+
/// Construct a DIE for the given DbgVariable without initializing the
/// DbgVariable's DIE reference.
DIE *constructVariableDIEImpl(const DbgVariable &DV, bool Abstract);
Index: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -127,9 +127,14 @@
if (!File)
return Asm->OutStreamer->emitDwarfFileDirective(0, "", "", None, None,
CUID);
- return Asm->OutStreamer->emitDwarfFileDirective(
- 0, File->getDirectory(), File->getFilename(), DD->getMD5AsBytes(File),
- File->getSource(), CUID);
+
+ if (LastFile != File) {
+ LastFile = File;
+ LastFileID = Asm->OutStreamer->emitDwarfFileDirective(
+ 0, File->getDirectory(), File->getFilename(), DD->getMD5AsBytes(File),
+ File->getSource(), CUID);
+ }
+ return LastFileID;
}
DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118041.402500.patch
Type: text/x-patch
Size: 1444 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220124/722cfe01/attachment.bin>
More information about the llvm-commits
mailing list