1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00
llvm-mirror/lib/Support
Graydon Hoare cded1d3751 [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
..
Unix Remove HAVE_DIRENT_H. 2018-04-02 17:17:29 +00:00
Windows Windows needs the current codepage instead of utf8 sometimes 2018-04-07 00:32:59 +00:00
Allocator.cpp Recover some overzealously removed includes. 2017-12-13 22:21:02 +00:00
AMDGPUMetadata.cpp AMDGPU: Add num spilled s/vgprs to metadata 2017-11-28 17:51:08 +00:00
APFloat.cpp Fix APFloat from string conversion for Inf 2017-12-19 04:27:39 +00:00
APInt.cpp [ADT] Simplify getMemory. NFC 2018-03-23 17:26:12 +00:00
APSInt.cpp
ARMAttributeParser.cpp Test commit 2018-02-26 13:05:18 +00:00
ARMBuildAttrs.cpp
ARMWinEH.cpp
Atomic.cpp Fix llvm-for-windows-on-linux build after LLVM r272701. 2017-08-03 20:10:47 +00:00
BinaryStreamError.cpp
BinaryStreamReader.cpp
BinaryStreamRef.cpp [BinaryStream] Support growable streams. 2017-11-27 18:48:37 +00:00
BinaryStreamWriter.cpp [BinaryStream] Support growable streams. 2017-11-27 18:48:37 +00:00
BlockFrequency.cpp Remove redundant includes from lib/Support. 2017-12-13 21:30:58 +00:00
BranchProbability.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
CachePruning.cpp [ThinLTO][CachePruning] explicitly disable pruning 2017-12-22 18:32:15 +00:00
Chrono.cpp [Support][Chrono] Use explicit cast of text output of time values. 2017-11-06 23:01:46 +00:00
circular_raw_ostream.cpp
CMakeLists.txt [Support] Move syntax highlighting into support 2018-03-09 09:56:24 +00:00
CodeGenCoverage.cpp Fix use of config.h in public headers. 2017-11-18 22:42:26 +00:00
COM.cpp
CommandLine.cpp On Windows we need to be able to process response files with Windows-style 2018-03-05 19:34:33 +00:00
Compression.cpp
ConvertUTF.cpp
ConvertUTFWrapper.cpp
COPYRIGHT.regex
CrashRecoveryContext.cpp
DAGDeltaAlgorithm.cpp
DataExtractor.cpp
Debug.cpp
DebugCounter.cpp [DebugCounter] Make -debug-counter cl::Hidden. 2018-04-01 22:16:52 +00:00
DeltaAlgorithm.cpp
DJB.cpp Make llvm::djbHash an inline function. 2018-03-02 22:00:38 +00:00
DynamicLibrary.cpp Allow clients to specify search order of DynamicLibraries. 2017-07-12 21:22:45 +00:00
Errno.cpp
Error.cpp [Support] Make llvm::Error and Expected faster. 2017-11-09 19:31:52 +00:00
ErrorHandling.cpp Report fatal error in the case of out of memory 2018-02-17 10:21:33 +00:00
FileOutputBuffer.cpp Make helpers static. NFC. 2017-11-24 14:55:41 +00:00
FileUtilities.cpp
FoldingSet.cpp Revert r325224 "Report fatal error in the case of out of memory" 2018-02-15 09:45:59 +00:00
FormattedStream.cpp
FormatVariadic.cpp Remove unused variables. No functionality change. 2017-10-08 19:11:02 +00:00
GlobPattern.cpp [Support/GlobPattern] - Do not crash when pattern has characters with int value < 0. 2017-07-31 09:26:50 +00:00
GraphWriter.cpp Convenience/safety fix for llvm::sys::Execute(And|No)Wait 2017-09-13 17:03:37 +00:00
Hashing.cpp
Host.cpp [Support] Stop passing StringRefs by const reference in some of the getHostCPUname implementations. NFC 2018-03-07 17:53:16 +00:00
IntEqClasses.cpp
IntervalMap.cpp
JamCRC.cpp
KnownBits.cpp [KnownBits][ValueTracking] Move the math for calculating known bits for add/sub into a static method in KnownBits object 2017-08-08 16:29:35 +00:00
LEB128.cpp
LineIterator.cpp
LLVMBuild.txt
Locale.cpp
LockFileManager.cpp [Support] Replace hand-written scope_exit with make_scope_exit. 2018-02-18 16:05:40 +00:00
LowLevelType.cpp [GlobalISel] Enable legalizing non-power-of-2 sized types. 2017-11-07 10:34:34 +00:00
ManagedStatic.cpp
MathExtras.cpp
MD5.cpp Fix warnings. [-Wdocumentation] 2017-10-12 09:42:14 +00:00
Memory.cpp
MemoryBuffer.cpp Fix signed-unsigned comparison warning. 2018-03-08 20:57:37 +00:00
Mutex.cpp [Support] - Add bad alloc error handler for handling allocation malfunctions 2017-07-11 16:45:30 +00:00
NativeFormatting.cpp Support: Add missing #include. 2018-01-18 20:49:33 +00:00
Options.cpp
Parallel.cpp Bring r314809 back. 2017-10-04 20:27:01 +00:00
Path.cpp Changed createTemporaryFile without FD to actually create a file. 2018-03-19 14:19:58 +00:00
PluginLoader.cpp
PrettyStackTrace.cpp Add more initializers to quiet a clang warning 2018-01-30 16:02:32 +00:00
Process.cpp [llvm-rc] Use proper search algorithm for finding resources. 2017-10-11 20:12:09 +00:00
Program.cpp Convenience/safety fix for llvm::sys::Execute(And|No)Wait 2017-09-13 17:03:37 +00:00
RandomNumberGenerator.cpp Mark all library options as hidden. 2017-12-01 00:53:10 +00:00
raw_os_ostream.cpp
raw_ostream.cpp Remove HAVE_WRITEV that's unused after r255837. 2018-04-02 14:18:13 +00:00
README.txt.system
regcomp.c Attempt to heal bots after r328970. 2018-04-02 13:49:35 +00:00
regengine.inc
regerror.c
regex2.h Support/reg*.h: Make headers include their dependencies 2017-10-26 20:23:11 +00:00
regex_impl.h
Regex.cpp Fix compilation on Darwin with expensive checks. 2018-03-12 11:01:05 +00:00
regexec.c
regfree.c
regstrlcpy.c
regutils.h
RWMutex.cpp Report fatal error in the case of out of memory 2018-02-20 05:41:26 +00:00
ScaledNumber.cpp
ScopedPrinter.cpp Remove redundant includes from lib/Support. 2017-12-13 21:30:58 +00:00
SHA1.cpp Fix header comment on SHA1 code. 2018-03-09 00:23:35 +00:00
Signals.cpp Convenience/safety fix for llvm::sys::Execute(And|No)Wait 2017-09-13 17:03:37 +00:00
SmallPtrSet.cpp [SmallPtrSet] Add iterator epoch tracking. 2017-10-13 20:37:52 +00:00
SmallVector.cpp Support, IR, ADT: Check nullptr after allocation with malloc/realloc or calloc 2017-07-20 01:30:39 +00:00
SourceMgr.cpp [Support] Make line-number cache robust against access patterns. 2018-04-07 00:44:02 +00:00
SpecialCaseList.cpp Extend SpecialCaseList to allow users to blame matches on entries in the file. 2017-11-07 21:16:46 +00:00
Statistic.cpp Support resetting STATISTIC() values using llvm::ResetStatistics() 2018-03-08 02:36:25 +00:00
StringExtras.cpp [Support] Move PrintEscapedString into the library its declaration is in 2018-01-26 20:21:02 +00:00
StringMap.cpp Re-land: "[Support] Replace HashString with djbHash." 2018-02-26 15:16:42 +00:00
StringPool.cpp
StringRef.cpp Fix APFloat from string conversion for Inf 2017-12-19 04:27:39 +00:00
StringSaver.cpp
SystemUtils.cpp
TargetParser.cpp AArch64: Implement support for the shadowcallstack attribute. 2018-04-04 21:55:44 +00:00
TargetRegistry.cpp Add backend name to Target to enable runtime info to be fed back into TableGen 2017-11-15 23:55:44 +00:00
TarWriter.cpp [Support/TarWriter] - Don't allow TarWriter to add the same file more than once. 2017-12-05 10:09:59 +00:00
Threading.cpp Bring r314809 back. 2017-10-04 20:27:01 +00:00
ThreadLocal.cpp
ThreadPool.cpp Speculative build fix for lld on Linux after Michael's #include removals 2017-12-13 22:12:57 +00:00
Timer.cpp Make LLVM timer reprintable: that is, make more than one print action on the same timer feasible 2018-02-10 00:38:21 +00:00
ToolOutputFile.cpp [Support] Rename tool_output_file to ToolOutputFile, NFC 2017-09-23 01:03:17 +00:00
TrigramIndex.cpp
Triple.cpp [AMDGPU] Remove use of OpenCL triple environment and replace with function attribute for AMDGPU 2018-03-23 18:45:18 +00:00
Twine.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
Unicode.cpp
UnicodeCaseFold.cpp Resubmit r325107 (case folding DJB hash) 2018-02-21 22:36:31 +00:00
Valgrind.cpp
Watchdog.cpp
WithColor.cpp [Support] Move syntax highlighting into support 2018-03-09 09:56:24 +00:00
xxhash.cpp
YAMLParser.cpp [YAML] Escape non-printable multibyte UTF8 in Output::scalarString. 2018-03-27 19:52:45 +00:00
YAMLTraits.cpp [YAML] Escape non-printable multibyte UTF8 in Output::scalarString. 2018-03-27 19:52:45 +00:00

Design Of lib/System
====================

The software in this directory is designed to completely shield LLVM from any
and all operating system specific functionality. It is not intended to be a
complete operating system wrapper (such as ACE), but only to provide the
functionality necessary to support LLVM.

The software located here, of necessity, has very specific and stringent design
rules. Violation of these rules means that cracks in the shield could form and
the primary goal of the library is defeated. By consistently using this library,
LLVM becomes more easily ported to new platforms since the only thing requiring
porting is this library.

Complete documentation for the library can be found in the file:
  llvm/docs/SystemLibrary.html
or at this URL:
  http://llvm.org/docs/SystemLibrary.html

While we recommend that you read the more detailed documentation, for the
impatient, here's a high level summary of the library's requirements.

 1. No system header files are to be exposed through the interface.
 2. Std C++ and Std C header files are okay to be exposed through the interface.
 3. No exposed system-specific functions.
 4. No exposed system-specific data.
 5. Data in lib/System classes must use only simple C++ intrinsic types.
 6. Errors are handled by returning "true" and setting an optional std::string
 7. Library must not throw any exceptions, period.
 8. Interface functions must not have throw() specifications.
 9. No duplicate function impementations are permitted within an operating
    system class.

To accomplish these requirements, the library has numerous design criteria that
must be satisfied. Here's a high level summary of the library's design criteria:

 1. No unused functionality (only what LLVM needs)
 2. High-Level Interfaces
 3. Use Opaque Classes
 4. Common Implementations
 5. Multiple Implementations
 6. Minimize Memory Allocation
 7. No Virtual Methods