diff options
author | Reid Kleckner <rnk@google.com> | 2025-06-25 06:23:11 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-25 05:23:11 -0700 |
commit | bb7242477c2f36195b53018b58a77f1dc12ffb06 (patch) | |
tree | f49010cf38489e972b4254c2709c9c489e5554c7 /llvm/tools/llvm-exegesis/lib/Analysis.cpp | |
parent | 8231dd71cb7dce489f4499a4e4f0ec149e858087 (diff) | |
download | llvm-bb7242477c2f36195b53018b58a77f1dc12ffb06.zip llvm-bb7242477c2f36195b53018b58a77f1dc12ffb06.tar.gz llvm-bb7242477c2f36195b53018b58a77f1dc12ffb06.tar.bz2 |
[MC] Use StringTable to reduce dynamic relocations (#144202)
Dynamic relocations are expensive on ELF/Linux platforms because they
are applied in userspace on process startup. Therefore, it is worth
optimizing them to make PIE and PIC dylib builds faster. In +asserts
builds (non-NDEBUG), nikic identified these schedule class name string
pointers as the leading source of dynamic relocations. [1]
This change uses llvm::StringTable and the StringToOffsetTable TableGen
helper to turn the string pointers into 32-bit offsets into a separate
character array.
The number of dynamic relocations is reduced by ~60%:
❯ llvm-readelf --dyn-relocations lib/libLLVM.so | wc -l
381376 # before
155156 # after
The test suite time is modestly affected, but I'm running on a shared
noisy workstation VM with a ton of cores:
https://gist.github.com/rnk/f38882c2fe2e63d0eb58b8fffeab69de
Testing Time: 100.88s # before
Testing Time: 78.50s. # after
Testing Time: 96.25s. # before again
I haven't used any fancy hyperfine/denoising tools, but I think the
result is clearly visible and we should ship it.
[1] https://gist.github.com/nikic/554f0a544ca15d5219788f1030f78c5a
Diffstat (limited to 'llvm/tools/llvm-exegesis/lib/Analysis.cpp')
-rw-r--r-- | llvm/tools/llvm-exegesis/lib/Analysis.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/llvm/tools/llvm-exegesis/lib/Analysis.cpp b/llvm/tools/llvm-exegesis/lib/Analysis.cpp index be10c32..fb84328 100644 --- a/llvm/tools/llvm-exegesis/lib/Analysis.cpp +++ b/llvm/tools/llvm-exegesis/lib/Analysis.cpp @@ -137,9 +137,9 @@ void Analysis::printInstructionRowCsv(const size_t PointId, std::tie(SchedClassId, std::ignore) = ResolvedSchedClass::resolveSchedClassId( State_.getSubtargetInfo(), State_.getInstrInfo(), MCI); #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) - const MCSchedClassDesc *const SCDesc = - State_.getSubtargetInfo().getSchedModel().getSchedClassDesc(SchedClassId); - writeEscaped<kEscapeCsv>(OS, SCDesc->Name); + StringRef SCDescName = + State_.getSubtargetInfo().getSchedModel().getSchedClassName(SchedClassId); + writeEscaped<kEscapeCsv>(OS, SCDescName); #else OS << SchedClassId; #endif @@ -563,7 +563,8 @@ Error Analysis::run<Analysis::PrintSchedClassInconsistencies>( OS << "<div class=\"inconsistency\"><p>Sched Class <span " "class=\"sched-class-name\">"; #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) - writeEscaped<kEscapeHtml>(OS, RSCAndPoints.RSC.SCDesc->Name); + writeEscaped<kEscapeHtml>(OS, SI.getSchedModel().getSchedClassName( + RSCAndPoints.RSC.SchedClassId)); #else OS << RSCAndPoints.RSC.SchedClassId; #endif |