[llvm] [MC][DWARF][NFC] Drop CIEKey map (PR #96075)
Alexis Engelke via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 26 01:34:03 PDT 2024
https://github.com/aengelke updated https://github.com/llvm/llvm-project/pull/96075
>From e88e749c77de4aec74ae462aaf2dcbfcfcebb6b4 Mon Sep 17 00:00:00 2001
From: Alexis Engelke <engelke at in.tum.de>
Date: Wed, 19 Jun 2024 15:29:54 +0200
Subject: [PATCH 1/2] [MC][DWARF][NFC] Drop CIEKey map
We already sort frames by their CIEKey, so we know that we only need to
update the CIE symbol when the CIE key changes. No need for a DenseMap.
---
llvm/lib/MC/MCDwarf.cpp | 84 +++++++++++++----------------------------
1 file changed, 26 insertions(+), 58 deletions(-)
diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp
index 9ada21669be34..30f72bced450e 100644
--- a/llvm/lib/MC/MCDwarf.cpp
+++ b/llvm/lib/MC/MCDwarf.cpp
@@ -1777,23 +1777,7 @@ void FrameEmitterImpl::EmitFDE(const MCSymbol &cieStart,
namespace {
struct CIEKey {
- static const CIEKey getEmptyKey() {
- return CIEKey(nullptr, 0, -1, false, false, static_cast<unsigned>(INT_MAX),
- false, false);
- }
-
- static const CIEKey getTombstoneKey() {
- return CIEKey(nullptr, -1, 0, false, false, static_cast<unsigned>(INT_MAX),
- false, false);
- }
-
- CIEKey(const MCSymbol *Personality, unsigned PersonalityEncoding,
- unsigned LSDAEncoding, bool IsSignalFrame, bool IsSimple,
- unsigned RAReg, bool IsBKeyFrame, bool IsMTETaggedFrame)
- : Personality(Personality), PersonalityEncoding(PersonalityEncoding),
- LsdaEncoding(LSDAEncoding), IsSignalFrame(IsSignalFrame),
- IsSimple(IsSimple), RAReg(RAReg), IsBKeyFrame(IsBKeyFrame),
- IsMTETaggedFrame(IsMTETaggedFrame) {}
+ CIEKey() {}
explicit CIEKey(const MCDwarfFrameInfo &Frame)
: Personality(Frame.Personality),
@@ -1819,44 +1803,28 @@ struct CIEKey {
Other.IsMTETaggedFrame);
}
- const MCSymbol *Personality;
- unsigned PersonalityEncoding;
- unsigned LsdaEncoding;
- bool IsSignalFrame;
- bool IsSimple;
- unsigned RAReg;
- bool IsBKeyFrame;
- bool IsMTETaggedFrame;
+ bool operator==(const CIEKey &Other) const {
+ return Personality == Other.Personality &&
+ PersonalityEncoding == Other.PersonalityEncoding &&
+ LsdaEncoding == Other.LsdaEncoding &&
+ IsSignalFrame == Other.IsSignalFrame && IsSimple == Other.IsSimple &&
+ RAReg == Other.RAReg && IsBKeyFrame == Other.IsBKeyFrame &&
+ IsMTETaggedFrame == Other.IsMTETaggedFrame;
+ }
+ bool operator!=(const CIEKey &Other) const { return !(*this == Other); }
+
+ const MCSymbol *Personality = nullptr;
+ unsigned PersonalityEncoding = 0;
+ unsigned LsdaEncoding = -1;
+ bool IsSignalFrame = false;
+ bool IsSimple = false;
+ unsigned RAReg = static_cast<unsigned>(INT_MAX);
+ bool IsBKeyFrame = false;
+ bool IsMTETaggedFrame = false;
};
} // end anonymous namespace
-namespace llvm {
-
-template <> struct DenseMapInfo<CIEKey> {
- static CIEKey getEmptyKey() { return CIEKey::getEmptyKey(); }
- static CIEKey getTombstoneKey() { return CIEKey::getTombstoneKey(); }
-
- static unsigned getHashValue(const CIEKey &Key) {
- return static_cast<unsigned>(
- hash_combine(Key.Personality, Key.PersonalityEncoding, Key.LsdaEncoding,
- Key.IsSignalFrame, Key.IsSimple, Key.RAReg,
- Key.IsBKeyFrame, Key.IsMTETaggedFrame));
- }
-
- static bool isEqual(const CIEKey &LHS, const CIEKey &RHS) {
- return LHS.Personality == RHS.Personality &&
- LHS.PersonalityEncoding == RHS.PersonalityEncoding &&
- LHS.LsdaEncoding == RHS.LsdaEncoding &&
- LHS.IsSignalFrame == RHS.IsSignalFrame &&
- LHS.IsSimple == RHS.IsSimple && LHS.RAReg == RHS.RAReg &&
- LHS.IsBKeyFrame == RHS.IsBKeyFrame &&
- LHS.IsMTETaggedFrame == RHS.IsMTETaggedFrame;
- }
-};
-
-} // end namespace llvm
-
void MCDwarfFrameEmitter::Emit(MCObjectStreamer &Streamer, MCAsmBackend *MAB,
bool IsEH) {
MCContext &Context = Streamer.getContext();
@@ -1898,9 +1866,6 @@ void MCDwarfFrameEmitter::Emit(MCObjectStreamer &Streamer, MCAsmBackend *MAB,
MCSymbol *SectionStart = Context.createTempSymbol();
Streamer.emitLabel(SectionStart);
- DenseMap<CIEKey, const MCSymbol *> CIEStarts;
-
- const MCSymbol *DummyDebugKey = nullptr;
bool CanOmitDwarf = MOFI->getOmitDwarfIfHaveCompactUnwind();
// Sort the FDEs by their corresponding CIE before we emit them.
// This isn't technically necessary according to the DWARF standard,
@@ -1911,6 +1876,8 @@ void MCDwarfFrameEmitter::Emit(MCObjectStreamer &Streamer, MCAsmBackend *MAB,
[](const MCDwarfFrameInfo &X, const MCDwarfFrameInfo &Y) {
return CIEKey(X) < CIEKey(Y);
});
+ CIEKey LastKey;
+ const MCSymbol *LastCIEStart = nullptr;
for (auto I = FrameArrayX.begin(), E = FrameArrayX.end(); I != E;) {
const MCDwarfFrameInfo &Frame = *I;
++I;
@@ -1925,11 +1892,12 @@ void MCDwarfFrameEmitter::Emit(MCObjectStreamer &Streamer, MCAsmBackend *MAB,
continue;
CIEKey Key(Frame);
- const MCSymbol *&CIEStart = IsEH ? CIEStarts[Key] : DummyDebugKey;
- if (!CIEStart)
- CIEStart = &Emitter.EmitCIE(Frame);
+ if (!LastCIEStart || (IsEH && Key != LastKey)) {
+ LastKey = Key;
+ LastCIEStart = &Emitter.EmitCIE(Frame);
+ }
- Emitter.EmitFDE(*CIEStart, Frame, I == E, *SectionStart);
+ Emitter.EmitFDE(*LastCIEStart, Frame, I == E, *SectionStart);
}
}
>From 764bd800fae188840473c714d4309d66a3638932 Mon Sep 17 00:00:00 2001
From: Alexis Engelke <engelke at in.tum.de>
Date: Tue, 25 Jun 2024 16:41:55 +0000
Subject: [PATCH 2/2] address comments
---
llvm/lib/MC/MCDwarf.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp
index 30f72bced450e..321a66ee5abc4 100644
--- a/llvm/lib/MC/MCDwarf.cpp
+++ b/llvm/lib/MC/MCDwarf.cpp
@@ -1777,7 +1777,7 @@ void FrameEmitterImpl::EmitFDE(const MCSymbol &cieStart,
namespace {
struct CIEKey {
- CIEKey() {}
+ CIEKey() = default;
explicit CIEKey(const MCDwarfFrameInfo &Frame)
: Personality(Frame.Personality),
@@ -1818,7 +1818,7 @@ struct CIEKey {
unsigned LsdaEncoding = -1;
bool IsSignalFrame = false;
bool IsSimple = false;
- unsigned RAReg = static_cast<unsigned>(INT_MAX);
+ unsigned RAReg = static_cast<unsigned>(UINT_MAX);
bool IsBKeyFrame = false;
bool IsMTETaggedFrame = false;
};
More information about the llvm-commits
mailing list