llvm-project/llvm/lib/MC
Graydon Hoare 54fe208a5f [Support] Make line-number cache robust against access patterns.
Summary:
The LLVM SourceMgr class (which is used indirectly by Swift, though not Clang)
has a routine for looking up line numbers of SMLocs. This routine uses a
shared, special-purpose cache that handles exactly one access pattern
efficiently: looking up the line number of an SMLoc that points into the same
buffer as the last query made to the SourceMgr, at a location in the buffer at
or ahead of the last query.

When this works it's fine, but when it fails it's catastrophic for performancer:
one recent out-of-order access from a Swift utility routine ran for tens of
seconds, spending 99% of its time repeatedly scanning buffers for '\n'.

This change removes the shared cache from the SourceMgr and installs a new
cache in each SrcBuffer. The per-SrcBuffer caches are also "full", in the sense
that rather than caching a single last-query pointer, they cache _all_ the
line-ending offsets, in a binary-searchable array, such that once it's
populated (on first access), all subsequent access patterns run at the same
speed.

Performance measurements I've done show this is actually a little bit faster on
real codebases (though only a couple fractions of a percent). Memory usage is
up by a few tens to hundreds of bytes per SrcBuffer that has a line lookup done
on it; I've attempted to minimize this by using dynamic selection of integer
sized when storing offset arrays. But the main motive here is to
make-impossible the cases we don't always see, that show up by surprise when
there is an out-of-order access pattern.

Reviewers: jordan_rose

Reviewed By: jordan_rose

Subscribers: probinson, llvm-commits

Differential Revision: https://reviews.llvm.org/D45003

llvm-svn: 329470
2018-04-07 00:44:02 +00:00
..
MCDisassembler Shrink various scheduling tables by using narrower types. 2018-02-23 19:32:56 +00:00
MCParser [Support] Make line-number cache robust against access patterns. 2018-04-07 00:44:02 +00:00
CMakeLists.txt [Asm] Add debug printing for assembler macros 2018-03-06 14:07:01 +00:00
ConstantPools.cpp Re-apply r302416: [ARM] Clear the constant pool cache on explicit .ltorg directives 2017-05-22 09:42:07 +00:00
ELFObjectWriter.cpp Delay creating an alias for @@@. 2018-03-09 18:42:25 +00:00
LLVMBuild.txt Add a build dependency from libMC to libDebugInfoCodeView to match the reality of header dependencies here 2018-03-26 23:48:52 +00:00
MCAsmBackend.cpp [MC] Adding code padding for performance stability - infrastructure. NFC. 2017-10-24 06:16:03 +00:00
MCAsmInfo.cpp [DEBUGINFO] Add option that allows to disable emission of flags in .loc directives. 2018-04-03 17:28:55 +00:00
MCAsmInfoCOFF.cpp
MCAsmInfoDarwin.cpp Move Object format code to lib/BinaryFormat. 2017-06-07 03:48:56 +00:00
MCAsmInfoELF.cpp Move Object format code to lib/BinaryFormat. 2017-06-07 03:48:56 +00:00
MCAsmInfoWasm.cpp Remove redundant includes from lib/MC. 2017-12-13 21:30:54 +00:00
MCAsmMacro.cpp [Asm] Fix another layering violation in assmebly macro dumping 2018-03-06 16:51:17 +00:00
MCAsmStreamer.cpp [DEBUGINFO] Add option that allows to disable emission of flags in .loc directives. 2018-04-03 17:28:55 +00:00
MCAssembler.cpp [MC] Fix assembler infinite loop on EH table using LEB padding. 2018-02-01 00:25:19 +00:00
MCCodeEmitter.cpp
MCCodePadder.cpp [MC] Adding code padding for performance stability - infrastructure. NFC. 2017-10-24 06:16:03 +00:00
MCCodeView.cpp [CodeView] Add line numbers for inlined call sites 2018-01-18 22:55:43 +00:00
MCContext.cpp [DebugInfo] Support DWARF v5 source code embedding extension 2018-02-23 23:01:06 +00:00
MCDwarf.cpp Reapply "[DWARFv5] Emit file 0 to the line table." 2018-03-29 17:16:41 +00:00
MCELFObjectTargetWriter.cpp [mips] Do not pass redundant IsN64 flag to MCELFObjectTargetWriter. NFC 2017-09-21 14:04:47 +00:00
MCELFStreamer.cpp Delay creating an alias for @@@. 2018-03-09 18:42:25 +00:00
MCExpr.cpp [WebAssembly] Added initial AsmParser implementation. 2018-03-20 20:06:35 +00:00
MCFragment.cpp NFC: Rename MCSafeSEHFragment to MCSymbolIdFragment 2017-11-08 18:57:02 +00:00
MCInst.cpp [RISCV] Tablegen-driven Instruction Compression. 2018-04-06 21:07:05 +00:00
MCInstPrinter.cpp Sort the remaining #include lines in include/... and lib/.... 2017-06-06 11:49:48 +00:00
MCInstrAnalysis.cpp Sort the remaining #include lines in include/... and lib/.... 2017-06-06 11:49:48 +00:00
MCInstrDesc.cpp
MCLabel.cpp Reverting r315590; it did not include changes for llvm-tblgen, which is causing link errors for several people. 2017-10-15 14:32:27 +00:00
MCLinkerOptimizationHint.cpp
MCMachOStreamer.cpp Don't create MCFillFragment directly. 2018-01-09 21:55:10 +00:00
MCMachObjectTargetWriter.cpp
MCNullStreamer.cpp Remove redundant includes from lib/MC. 2017-12-13 21:30:54 +00:00
MCObjectFileInfo.cpp Re-commit r329179 after fixing build&test issues 2018-04-04 14:42:14 +00:00
MCObjectStreamer.cpp Re-land r327620 "[CodeView] Initial support for emitting S_BLOCK32 symbols for lexical scopes" 2018-03-15 21:24:04 +00:00
MCObjectWriter.cpp Sort the remaining #include lines in include/... and lib/.... 2017-06-06 11:49:48 +00:00
MCRegisterInfo.cpp [MC] Handle unknown literal register numbers in .cfi_* directives 2017-12-01 21:44:27 +00:00
MCSchedule.cpp [MC] Fix -Wmissing-field-initializer warning after r329067. 2018-04-03 13:52:26 +00:00
MCSection.cpp Reverting r315590; it did not include changes for llvm-tblgen, which is causing link errors for several people. 2017-10-15 14:32:27 +00:00
MCSectionCOFF.cpp Move Object format code to lib/BinaryFormat. 2017-06-07 03:48:56 +00:00
MCSectionELF.cpp CodeGen: support an extension to pass linker options on ELF 2018-01-30 16:29:29 +00:00
MCSectionMachO.cpp
MCSectionWasm.cpp Remove redundant includes from lib/MC. 2017-12-13 21:30:54 +00:00
MCStreamer.cpp Reapply "[DWARFv5] Emit file 0 to the line table." 2018-03-29 17:16:41 +00:00
MCSubtargetInfo.cpp [MC] fix documentation comments; NFC 2018-03-22 15:23:21 +00:00
MCSymbol.cpp Reverting r315590; it did not include changes for llvm-tblgen, which is causing link errors for several people. 2017-10-15 14:32:27 +00:00
MCSymbolELF.cpp Remove redundant includes from lib/MC. 2017-12-13 21:30:54 +00:00
MCTargetOptions.cpp Sort the remaining #include lines in include/... and lib/.... 2017-06-06 11:49:48 +00:00
MCValue.cpp Reverting r315590; it did not include changes for llvm-tblgen, which is causing link errors for several people. 2017-10-15 14:32:27 +00:00
MCWasmObjectTargetWriter.cpp [WebAssembly] Remove unused methods from MCWasmObjectTargetWriter 2017-06-06 16:38:59 +00:00
MCWasmStreamer.cpp [WebAssembly] Add first claass symbol table to wasm objects 2018-02-23 05:08:34 +00:00
MCWin64EH.cpp Remove redundant includes from lib/MC. 2017-12-13 21:30:54 +00:00
MCWinCOFFStreamer.cpp Reland "Emit Function IDs table for Control Flow Guard" 2018-01-09 23:49:30 +00:00
MCWinEH.cpp Move Object format code to lib/BinaryFormat. 2017-06-07 03:48:56 +00:00
MachObjectWriter.cpp [MC] Issue error message when data region is not terminated 2018-02-12 07:19:05 +00:00
StringTableBuilder.cpp [DWARFv5] Emit .debug_line_str (in a non-DWO file). 2018-02-06 20:29:21 +00:00
SubtargetFeature.cpp Reverting r315590; it did not include changes for llvm-tblgen, which is causing link errors for several people. 2017-10-15 14:32:27 +00:00
WasmObjectWriter.cpp [WebAssembly] Allow for the creation of user-defined custom sections 2018-04-05 17:01:39 +00:00
WinCOFFObjectWriter.cpp [MC] Always emit relocations for same-section function references 2018-03-14 19:24:32 +00:00