Skip to content

Commit 8104d41

Browse files
HaohaiWenflovent
authored andcommitted
[MC] Replace MCContext::GenericSectionID with MCSection::NonUniqueID (llvm#126202)
They have same semantics. NonUniqueID is more friendly for isUnique implementation in MCSectionELF. History: 97837b7 added support for unique IDs in sections and added GenericSectionID. Later, 1dc16c7 added NonUniqueID.
1 parent ccb3f7b commit 8104d41

File tree

6 files changed

+20
-26
lines changed

6 files changed

+20
-26
lines changed

llvm/include/llvm/MC/MCContext.h

+2-9
Original file line numberDiff line numberDiff line change
@@ -527,13 +527,6 @@ class MCContext {
527527
/// \name Section Management
528528
/// @{
529529

530-
enum : unsigned {
531-
/// Pass this value as the UniqueID during section creation to get the
532-
/// generic section with the given name and characteristics. The usual
533-
/// sections such as .text use this ID.
534-
GenericSectionID = ~0U
535-
};
536-
537530
/// Return the MCSection for the specified mach-o section. This requires
538531
/// the operands to be valid.
539532
MCSectionMachO *getMachOSection(StringRef Segment, StringRef Section,
@@ -611,7 +604,7 @@ class MCContext {
611604

612605
MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
613606
StringRef COMDATSymName, int Selection,
614-
unsigned UniqueID = GenericSectionID);
607+
unsigned UniqueID = MCSection::NonUniqueID);
615608

616609
MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics);
617610

@@ -621,7 +614,7 @@ class MCContext {
621614
/// as Sec and the function symbol as KeySym.
622615
MCSectionCOFF *
623616
getAssociativeCOFFSection(MCSectionCOFF *Sec, const MCSymbol *KeySym,
624-
unsigned UniqueID = GenericSectionID);
617+
unsigned UniqueID = MCSection::NonUniqueID);
625618

626619
MCSectionSPIRV *getSPIRVSection();
627620

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName,
758758
if (!SupportsUnique) {
759759
Flags &= ~ELF::SHF_MERGE;
760760
EntrySize = 0;
761-
return MCContext::GenericSectionID;
761+
return MCSection::NonUniqueID;
762762
}
763763

764764
const bool SymbolMergeable = Flags & ELF::SHF_MERGE;
@@ -770,16 +770,16 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName,
770770
if (TM.getSeparateNamedSections())
771771
return NextUniqueID++;
772772
else
773-
return MCContext::GenericSectionID;
773+
return MCSection::NonUniqueID;
774774
}
775775

776776
// Symbols must be placed into sections with compatible entry sizes. Generate
777777
// unique sections for symbols that have not been assigned to compatible
778778
// sections.
779779
const auto PreviousID =
780780
Ctx.getELFUniqueIDForEntsize(SectionName, Flags, EntrySize);
781-
if (PreviousID && (!TM.getSeparateNamedSections() ||
782-
*PreviousID == MCContext::GenericSectionID))
781+
if (PreviousID &&
782+
(!TM.getSeparateNamedSections() || *PreviousID == MCSection::NonUniqueID))
783783
return *PreviousID;
784784

785785
// If the user has specified the same section name as would be created
@@ -791,7 +791,7 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName,
791791
if (SymbolMergeable &&
792792
Ctx.isELFImplicitMergeableSectionNamePrefix(SectionName) &&
793793
SectionName.starts_with(ImplicitSectionNameStem))
794-
return MCContext::GenericSectionID;
794+
return MCSection::NonUniqueID;
795795

796796
// We have seen this section name before, but with different flags or entity
797797
// size. Create a new unique ID.
@@ -903,7 +903,7 @@ static MCSectionELF *selectELFSectionForGlobal(
903903
unsigned EntrySize = getEntrySizeForKind(Kind);
904904

905905
bool UniqueSectionName = false;
906-
unsigned UniqueID = MCContext::GenericSectionID;
906+
unsigned UniqueID = MCSection::NonUniqueID;
907907
if (EmitUniqueSection) {
908908
if (TM.getUniqueSectionNames()) {
909909
UniqueSectionName = true;
@@ -1073,7 +1073,7 @@ MCSection *TargetLoweringObjectFileELF::getSectionForMachineBasicBlock(
10731073
const Function &F, const MachineBasicBlock &MBB,
10741074
const TargetMachine &TM) const {
10751075
assert(MBB.isBeginSection() && "Basic block does not start a section!");
1076-
unsigned UniqueID = MCContext::GenericSectionID;
1076+
unsigned UniqueID = MCSection::NonUniqueID;
10771077

10781078
// For cold sections use the .text.split. prefix along with the parent
10791079
// function name. All cold blocks for the same function go to the same
@@ -1774,7 +1774,7 @@ MCSection *TargetLoweringObjectFileCOFF::SelectSectionForGlobal(
17741774
else
17751775
ComdatGV = GO;
17761776

1777-
unsigned UniqueID = MCContext::GenericSectionID;
1777+
unsigned UniqueID = MCSection::NonUniqueID;
17781778
if (EmitUniquedSection)
17791779
UniqueID = NextUniqueID++;
17801780

@@ -2220,8 +2220,8 @@ MCSection *TargetLoweringObjectFileWasm::getExplicitSectionGlobal(
22202220
}
22212221

22222222
unsigned Flags = getWasmSectionFlags(Kind, Used.count(GO));
2223-
MCSectionWasm *Section = getContext().getWasmSection(
2224-
Name, Kind, Flags, Group, MCContext::GenericSectionID);
2223+
MCSectionWasm *Section = getContext().getWasmSection(Name, Kind, Flags, Group,
2224+
MCSection::NonUniqueID);
22252225

22262226
return Section;
22272227
}
@@ -2249,7 +2249,7 @@ selectWasmSectionForGlobal(MCContext &Ctx, const GlobalObject *GO,
22492249
Name.push_back('.');
22502250
TM.getNameWithPrefix(Name, GO, Mang, true);
22512251
}
2252-
unsigned UniqueID = MCContext::GenericSectionID;
2252+
unsigned UniqueID = MCSection::NonUniqueID;
22532253
if (EmitUniqueSection && !UniqueSectionNames) {
22542254
UniqueID = *NextUniqueID;
22552255
(*NextUniqueID)++;

llvm/lib/MC/MCContext.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ void MCContext::recordELFMergeableSectionInfo(StringRef SectionName,
636636
unsigned Flags, unsigned UniqueID,
637637
unsigned EntrySize) {
638638
bool IsMergeable = Flags & ELF::SHF_MERGE;
639-
if (UniqueID == GenericSectionID) {
639+
if (UniqueID == MCSection::NonUniqueID) {
640640
ELFSeenGenericMergeableSections.insert(SectionName);
641641
// Minor performance optimization: avoid hash map lookup in
642642
// isELFGenericMergeableSection, which will return true for SectionName.
@@ -727,14 +727,15 @@ MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,
727727

728728
MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,
729729
unsigned Characteristics) {
730-
return getCOFFSection(Section, Characteristics, "", 0, GenericSectionID);
730+
return getCOFFSection(Section, Characteristics, "", 0,
731+
MCSection::NonUniqueID);
731732
}
732733

733734
MCSectionCOFF *MCContext::getAssociativeCOFFSection(MCSectionCOFF *Sec,
734735
const MCSymbol *KeySym,
735736
unsigned UniqueID) {
736737
// Return the normal section if we don't have to be associative or unique.
737-
if (!KeySym && UniqueID == GenericSectionID)
738+
if (!KeySym && UniqueID == MCSection::NonUniqueID)
738739
return Sec;
739740

740741
// If we have a key symbol, make an associative section with the same name and

llvm/lib/MC/MCObjectFileInfo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name,
10661066
utostr(Hash), /*IsComdat=*/true);
10671067
case Triple::Wasm:
10681068
return Ctx->getWasmSection(Name, SectionKind::getMetadata(), 0,
1069-
utostr(Hash), MCContext::GenericSectionID);
1069+
utostr(Hash), MCSection::NonUniqueID);
10701070
case Triple::MachO:
10711071
case Triple::COFF:
10721072
case Triple::GOFF:

llvm/lib/MC/MCParser/WasmAsmParser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class WasmAsmParser : public MCAsmParserExtension {
193193

194194
// TODO: Parse UniqueID
195195
MCSectionWasm *WS = getContext().getWasmSection(
196-
Name, *Kind, Flags, GroupName, MCContext::GenericSectionID);
196+
Name, *Kind, Flags, GroupName, MCSection::NonUniqueID);
197197

198198
if (WS->getSegmentFlags() != Flags)
199199
Parser->Error(loc, "changed section flags for " + Name +

llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
12461246
if (Group)
12471247
WasmSym->setComdat(true);
12481248
auto *WS = getContext().getWasmSection(SecName, SectionKind::getText(), 0,
1249-
Group, MCContext::GenericSectionID);
1249+
Group, MCSection::NonUniqueID);
12501250
getStreamer().switchSection(WS);
12511251
// Also generate DWARF for this section if requested.
12521252
if (getContext().getGenDwarfForAssembly())

0 commit comments

Comments
 (0)