-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[MC] Replace MCContext::GenericSectionID with MCSection::NonUniqueID #126202
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
They have same semantics. NonUniqueID is more friendly for isUnique implementation in MCSectionELF.
@llvm/pr-subscribers-backend-webassembly @llvm/pr-subscribers-mc Author: Haohai Wen (HaohaiWen) ChangesThey have same semantics. NonUniqueID is more friendly for isUnique Full diff: https://github.com/llvm/llvm-project/pull/126202.diff 6 Files Affected:
diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h
index 57ba40f7ac26fcc..e97c890ce91358a 100644
--- a/llvm/include/llvm/MC/MCContext.h
+++ b/llvm/include/llvm/MC/MCContext.h
@@ -527,13 +527,6 @@ class MCContext {
/// \name Section Management
/// @{
- enum : unsigned {
- /// Pass this value as the UniqueID during section creation to get the
- /// generic section with the given name and characteristics. The usual
- /// sections such as .text use this ID.
- GenericSectionID = ~0U
- };
-
/// Return the MCSection for the specified mach-o section. This requires
/// the operands to be valid.
MCSectionMachO *getMachOSection(StringRef Segment, StringRef Section,
@@ -611,7 +604,7 @@ class MCContext {
MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
StringRef COMDATSymName, int Selection,
- unsigned UniqueID = GenericSectionID);
+ unsigned UniqueID = MCSection::NonUniqueID);
MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics);
@@ -621,7 +614,7 @@ class MCContext {
/// as Sec and the function symbol as KeySym.
MCSectionCOFF *
getAssociativeCOFFSection(MCSectionCOFF *Sec, const MCSymbol *KeySym,
- unsigned UniqueID = GenericSectionID);
+ unsigned UniqueID = MCSection::NonUniqueID);
MCSectionSPIRV *getSPIRVSection();
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 6cbc4b9776a1b0f..9f44f8b1c0f5698 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -758,7 +758,7 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName,
if (!SupportsUnique) {
Flags &= ~ELF::SHF_MERGE;
EntrySize = 0;
- return MCContext::GenericSectionID;
+ return MCSection::NonUniqueID;
}
const bool SymbolMergeable = Flags & ELF::SHF_MERGE;
@@ -770,7 +770,7 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName,
if (TM.getSeparateNamedSections())
return NextUniqueID++;
else
- return MCContext::GenericSectionID;
+ return MCSection::NonUniqueID;
}
// Symbols must be placed into sections with compatible entry sizes. Generate
@@ -778,8 +778,8 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName,
// sections.
const auto PreviousID =
Ctx.getELFUniqueIDForEntsize(SectionName, Flags, EntrySize);
- if (PreviousID && (!TM.getSeparateNamedSections() ||
- *PreviousID == MCContext::GenericSectionID))
+ if (PreviousID &&
+ (!TM.getSeparateNamedSections() || *PreviousID == MCSection::NonUniqueID))
return *PreviousID;
// If the user has specified the same section name as would be created
@@ -791,7 +791,7 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName,
if (SymbolMergeable &&
Ctx.isELFImplicitMergeableSectionNamePrefix(SectionName) &&
SectionName.starts_with(ImplicitSectionNameStem))
- return MCContext::GenericSectionID;
+ return MCSection::NonUniqueID;
// We have seen this section name before, but with different flags or entity
// size. Create a new unique ID.
@@ -903,7 +903,7 @@ static MCSectionELF *selectELFSectionForGlobal(
unsigned EntrySize = getEntrySizeForKind(Kind);
bool UniqueSectionName = false;
- unsigned UniqueID = MCContext::GenericSectionID;
+ unsigned UniqueID = MCSection::NonUniqueID;
if (EmitUniqueSection) {
if (TM.getUniqueSectionNames()) {
UniqueSectionName = true;
@@ -1073,7 +1073,7 @@ MCSection *TargetLoweringObjectFileELF::getSectionForMachineBasicBlock(
const Function &F, const MachineBasicBlock &MBB,
const TargetMachine &TM) const {
assert(MBB.isBeginSection() && "Basic block does not start a section!");
- unsigned UniqueID = MCContext::GenericSectionID;
+ unsigned UniqueID = MCSection::NonUniqueID;
// For cold sections use the .text.split. prefix along with the parent
// function name. All cold blocks for the same function go to the same
@@ -1774,7 +1774,7 @@ MCSection *TargetLoweringObjectFileCOFF::SelectSectionForGlobal(
else
ComdatGV = GO;
- unsigned UniqueID = MCContext::GenericSectionID;
+ unsigned UniqueID = MCSection::NonUniqueID;
if (EmitUniquedSection)
UniqueID = NextUniqueID++;
@@ -2220,8 +2220,8 @@ MCSection *TargetLoweringObjectFileWasm::getExplicitSectionGlobal(
}
unsigned Flags = getWasmSectionFlags(Kind, Used.count(GO));
- MCSectionWasm *Section = getContext().getWasmSection(
- Name, Kind, Flags, Group, MCContext::GenericSectionID);
+ MCSectionWasm *Section = getContext().getWasmSection(Name, Kind, Flags, Group,
+ MCSection::NonUniqueID);
return Section;
}
@@ -2249,7 +2249,7 @@ selectWasmSectionForGlobal(MCContext &Ctx, const GlobalObject *GO,
Name.push_back('.');
TM.getNameWithPrefix(Name, GO, Mang, true);
}
- unsigned UniqueID = MCContext::GenericSectionID;
+ unsigned UniqueID = MCSection::NonUniqueID;
if (EmitUniqueSection && !UniqueSectionNames) {
UniqueID = *NextUniqueID;
(*NextUniqueID)++;
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index 335febde3687c5f..09d4b518cc1c59f 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -636,7 +636,7 @@ void MCContext::recordELFMergeableSectionInfo(StringRef SectionName,
unsigned Flags, unsigned UniqueID,
unsigned EntrySize) {
bool IsMergeable = Flags & ELF::SHF_MERGE;
- if (UniqueID == GenericSectionID) {
+ if (UniqueID == MCSection::NonUniqueID) {
ELFSeenGenericMergeableSections.insert(SectionName);
// Minor performance optimization: avoid hash map lookup in
// isELFGenericMergeableSection, which will return true for SectionName.
@@ -727,14 +727,15 @@ MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,
MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,
unsigned Characteristics) {
- return getCOFFSection(Section, Characteristics, "", 0, GenericSectionID);
+ return getCOFFSection(Section, Characteristics, "", 0,
+ MCSection::NonUniqueID);
}
MCSectionCOFF *MCContext::getAssociativeCOFFSection(MCSectionCOFF *Sec,
const MCSymbol *KeySym,
unsigned UniqueID) {
// Return the normal section if we don't have to be associative or unique.
- if (!KeySym && UniqueID == GenericSectionID)
+ if (!KeySym && UniqueID == MCSection::NonUniqueID)
return Sec;
// If we have a key symbol, make an associative section with the same name and
diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp
index 150e38a94db6a67..ab7552ca01061ad 100644
--- a/llvm/lib/MC/MCObjectFileInfo.cpp
+++ b/llvm/lib/MC/MCObjectFileInfo.cpp
@@ -1066,7 +1066,7 @@ MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name,
utostr(Hash), /*IsComdat=*/true);
case Triple::Wasm:
return Ctx->getWasmSection(Name, SectionKind::getMetadata(), 0,
- utostr(Hash), MCContext::GenericSectionID);
+ utostr(Hash), MCSection::NonUniqueID);
case Triple::MachO:
case Triple::COFF:
case Triple::GOFF:
diff --git a/llvm/lib/MC/MCParser/WasmAsmParser.cpp b/llvm/lib/MC/MCParser/WasmAsmParser.cpp
index d8ab30f296c3cba..a3c40d619460713 100644
--- a/llvm/lib/MC/MCParser/WasmAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/WasmAsmParser.cpp
@@ -193,7 +193,7 @@ class WasmAsmParser : public MCAsmParserExtension {
// TODO: Parse UniqueID
MCSectionWasm *WS = getContext().getWasmSection(
- Name, *Kind, Flags, GroupName, MCContext::GenericSectionID);
+ Name, *Kind, Flags, GroupName, MCSection::NonUniqueID);
if (WS->getSegmentFlags() != Flags)
Parser->Error(loc, "changed section flags for " + Name +
diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
index f693ef3dbf962bb..2a4e2c897b18ddc 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -1246,7 +1246,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
if (Group)
WasmSym->setComdat(true);
auto *WS = getContext().getWasmSection(SecName, SectionKind::getText(), 0,
- Group, MCContext::GenericSectionID);
+ Group, MCSection::NonUniqueID);
getStreamer().switchSection(WS);
// Also generate DWARF for this section if requested.
if (getContext().getGenDwarfForAssembly())
|
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.
History: 97837b7 (2016) added support for unique IDs in sections and added GenericSectionID
. Later, 1dc16c7 (2020/@MaskRay) added NonUniqueID
.
I agree that MCSection::NonUniqueID is nicer and the more logical place; it also avoids pulling in MCContext.h into MCSectionELF.h.
LGTM (unless @MaskRay has concerns).
Thanks for the archaeology. The information would be nice to be included into the PR description. |
…lvm#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.
…lvm#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.
…lvm#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.
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.