Skip to content

Commit c541729

Browse files
committed
Fix key for hashmap and introduce union
1 parent 74e804c commit c541729

File tree

4 files changed

+46
-48
lines changed

4 files changed

+46
-48
lines changed

llvm/include/llvm/MC/MCContext.h

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -270,21 +270,6 @@ class MCContext {
270270
}
271271
};
272272

273-
struct GOFFSectionKey {
274-
std::string SectionName;
275-
GOFF::ESDSymbolType SymbolType;
276-
277-
GOFFSectionKey(StringRef SectionName, GOFF::ESDSymbolType SymbolType)
278-
: SectionName(SectionName), SymbolType(SymbolType) {}
279-
280-
bool operator<(const GOFFSectionKey &Other) const {
281-
if (SymbolType == Other.SymbolType) {
282-
return SectionName < Other.SectionName;
283-
}
284-
return SymbolType < Other.SymbolType;
285-
}
286-
};
287-
288273
struct WasmSectionKey {
289274
std::string SectionName;
290275
StringRef GroupName;
@@ -338,7 +323,7 @@ class MCContext {
338323
StringMap<MCSectionMachO *> MachOUniquingMap;
339324
std::map<COFFSectionKey, MCSectionCOFF *> COFFUniquingMap;
340325
StringMap<MCSectionELF *> ELFUniquingMap;
341-
std::map<GOFFSectionKey, MCSectionGOFF *> GOFFUniquingMap;
326+
std::map<std::string, MCSectionGOFF *> GOFFUniquingMap;
342327
std::map<WasmSectionKey, MCSectionWasm *> WasmUniquingMap;
343328
std::map<XCOFFSectionKey, MCSectionXCOFF *> XCOFFUniquingMap;
344329
StringMap<MCSectionDXContainer *> DXCUniquingMap;
@@ -616,11 +601,9 @@ class MCContext {
616601
unsigned EntrySize);
617602

618603
private:
619-
MCSectionGOFF *getGOFFSection(SectionKind Kind,
620-
GOFF::ESDSymbolType SymbolType, StringRef Name,
621-
GOFF::SDAttr SDAttributes,
622-
GOFF::EDAttr EDAttributes,
623-
GOFF::PRAttr PRAttributes, MCSection *Parent);
604+
template <typename TAttr>
605+
MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef Name,
606+
TAttr SDAttributes, MCSection *Parent);
624607

625608
public:
626609
MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef Name,

llvm/include/llvm/MC/MCSectionGOFF.h

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ class MCSectionGOFF final : public MCSection {
3030
MCSectionGOFF *Parent;
3131

3232
// The attributes of the GOFF symbols.
33-
GOFF::SDAttr SDAttributes;
34-
GOFF::EDAttr EDAttributes;
35-
GOFF::PRAttr PRAttributes;
33+
union {
34+
GOFF::SDAttr SDAttributes;
35+
GOFF::EDAttr EDAttributes;
36+
GOFF::PRAttr PRAttributes;
37+
};
3638

3739
// The type of this section.
3840
GOFF::ESDSymbolType SymbolType;
@@ -47,13 +49,27 @@ class MCSectionGOFF final : public MCSection {
4749

4850
friend class MCContext;
4951
friend class MCSymbolGOFF;
50-
MCSectionGOFF(StringRef Name, SectionKind K, GOFF::ESDSymbolType SymbolType,
51-
GOFF::SDAttr SDAttributes, GOFF::EDAttr EDAttributes,
52-
GOFF::PRAttr PRAttributes, MCSectionGOFF *Parent = nullptr)
52+
53+
MCSectionGOFF(StringRef Name, SectionKind K, GOFF::SDAttr SDAttributes,
54+
MCSectionGOFF *Parent)
55+
: MCSection(SV_GOFF, Name, K.isText(), /*IsVirtual=*/false, nullptr),
56+
Parent(Parent), SDAttributes(SDAttributes),
57+
SymbolType(GOFF::ESD_ST_SectionDefinition), RequiresNonZeroLength(0),
58+
Emitted(0) {}
59+
60+
MCSectionGOFF(StringRef Name, SectionKind K, GOFF::EDAttr EDAttributes,
61+
MCSectionGOFF *Parent)
62+
: MCSection(SV_GOFF, Name, K.isText(), /*IsVirtual=*/false, nullptr),
63+
Parent(Parent), EDAttributes(EDAttributes),
64+
SymbolType(GOFF::ESD_ST_ElementDefinition), RequiresNonZeroLength(0),
65+
Emitted(0) {}
66+
67+
MCSectionGOFF(StringRef Name, SectionKind K, GOFF::PRAttr PRAttributes,
68+
MCSectionGOFF *Parent)
5369
: MCSection(SV_GOFF, Name, K.isText(), /*IsVirtual=*/false, nullptr),
54-
Parent(Parent), SDAttributes(SDAttributes), EDAttributes(EDAttributes),
55-
PRAttributes(PRAttributes), SymbolType(SymbolType),
56-
RequiresNonZeroLength(0), Emitted(0) {}
70+
Parent(Parent), PRAttributes(PRAttributes),
71+
SymbolType(GOFF::ESD_ST_PartReference), RequiresNonZeroLength(0),
72+
Emitted(0) {}
5773

5874
public:
5975
void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,

llvm/lib/MC/MCContext.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -672,45 +672,44 @@ MCContext::getELFUniqueIDForEntsize(StringRef SectionName, unsigned Flags,
672672
: std::nullopt;
673673
}
674674

675-
MCSectionGOFF *
676-
MCContext::getGOFFSection(SectionKind Kind, GOFF::ESDSymbolType SymbolType,
677-
StringRef Name, GOFF::SDAttr SDAttributes,
678-
GOFF::EDAttr EDAttributes, GOFF::PRAttr PRAttributes,
679-
MCSection *Parent) {
680-
GOFFSectionKey T{Name, SymbolType};
675+
template <typename TAttr>
676+
MCSectionGOFF *MCContext::getGOFFSection(SectionKind Kind, StringRef Name,
677+
TAttr Attributes, MCSection *Parent) {
678+
std::string UniqueName(Name);
679+
if (Parent) {
680+
UniqueName.append("/").append(Parent->getName());
681+
if (auto *P = static_cast<MCSectionGOFF *>(Parent)->getParent())
682+
UniqueName.append("/").append(P->getName());
683+
}
681684
// Do the lookup. If we don't have a hit, return a new section.
682-
auto IterBool = GOFFUniquingMap.insert(std::make_pair(T, nullptr));
685+
auto IterBool = GOFFUniquingMap.insert(std::make_pair(UniqueName, nullptr));
683686
auto Iter = IterBool.first;
684687
if (!IterBool.second)
685688
return Iter->second;
686689

687-
StringRef CachedName = Iter->first.SectionName;
688-
MCSectionGOFF *GOFFSection = new (GOFFAllocator.Allocate())
689-
MCSectionGOFF(CachedName, Kind, SymbolType, SDAttributes, EDAttributes,
690-
PRAttributes, static_cast<MCSectionGOFF *>(Parent));
690+
StringRef CachedName = StringRef(Iter->first.c_str(), Name.size());
691+
MCSectionGOFF *GOFFSection = new (GOFFAllocator.Allocate()) MCSectionGOFF(
692+
CachedName, Kind, Attributes, static_cast<MCSectionGOFF *>(Parent));
691693
Iter->second = GOFFSection;
692694
allocInitialFragment(*GOFFSection);
693695
return GOFFSection;
694696
}
695697

696698
MCSectionGOFF *MCContext::getGOFFSection(SectionKind Kind, StringRef Name,
697699
GOFF::SDAttr SDAttributes) {
698-
return getGOFFSection(Kind, GOFF::ESD_ST_SectionDefinition, Name,
699-
SDAttributes, GOFF::EDAttr{}, GOFF::PRAttr{}, nullptr);
700+
return getGOFFSection<GOFF::SDAttr>(Kind, Name, SDAttributes, nullptr);
700701
}
701702

702703
MCSectionGOFF *MCContext::getGOFFSection(SectionKind Kind, StringRef Name,
703704
GOFF::EDAttr EDAttributes,
704705
MCSection *Parent) {
705-
return getGOFFSection(Kind, GOFF::ESD_ST_ElementDefinition, Name,
706-
GOFF::SDAttr{}, EDAttributes, GOFF::PRAttr{}, Parent);
706+
return getGOFFSection<GOFF::EDAttr>(Kind, Name, EDAttributes, Parent);
707707
}
708708

709709
MCSectionGOFF *MCContext::getGOFFSection(SectionKind Kind, StringRef Name,
710710
GOFF::PRAttr PRAttributes,
711711
MCSection *Parent) {
712-
return getGOFFSection(Kind, GOFF::ESD_ST_PartReference, Name, GOFF::SDAttr{},
713-
GOFF::EDAttr{}, PRAttributes, Parent);
712+
return getGOFFSection<GOFF::PRAttr>(Kind, Name, PRAttributes, Parent);
714713
}
715714

716715
MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,

llvm/test/CodeGen/SystemZ/zos-landingpad.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ lpad:
3838
; CHECK: LSDA location
3939
; Check that the exception table is emitted into .lsda section.
4040
; CHECK: stdin#C CSECT
41-
; CHECK: C_WSA64 CATTR ALIGN(2),DEFLOAD,RMODE(64),PART(.gcc_exception_table.test1)
41+
; CHECK: C_WSA64 CATTR ALIGN(2),RMODE(64),PART(.gcc_exception_table.test1)
4242
; CHECK: GCC_except_table0:

0 commit comments

Comments
 (0)