-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[MC][DWARF][NFC] Drop CIEKey map #96075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-mc @llvm/pr-subscribers-debuginfo Author: None (aengelke) ChangesWe 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. This is a very minor performance improvement, but I want to get this out of my profile. :) Full diff: https://github.com/llvm/llvm-project/pull/96075.diff 1 Files Affected:
diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp
index 5032592b3861a..d74de4a8d565a 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();
@@ -1906,9 +1874,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,
@@ -1919,6 +1884,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;
@@ -1933,11 +1900,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);
}
}
|
llvm/lib/MC/MCDwarf.cpp
Outdated
unsigned LsdaEncoding = -1; | ||
bool IsSignalFrame = false; | ||
bool IsSimple = false; | ||
unsigned RAReg = static_cast<unsigned>(INT_MAX); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why INT_MAX instead of UINT_MAX?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just re-used the values from the previous getEmptyKey()
. But agreed, UINT_MAX makes more sense.
llvm/lib/MC/MCDwarf.cpp
Outdated
LsdaEncoding(LSDAEncoding), IsSignalFrame(IsSignalFrame), | ||
IsSimple(IsSimple), RAReg(RAReg), IsBKeyFrame(IsBKeyFrame), | ||
IsMTETaggedFrame(IsMTETaggedFrame) {} | ||
CIEKey() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
= default
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.
1d18e31
to
764bd80
Compare
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.
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.
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.
This is a very minor performance improvement, but I want to get this out of my profile. :)