-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[MC] Make MCSection::isVirtualSection non-virtual #96920
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This method is called once per encoded instruction, but never changes throughout the lifetime of a section. Store this information as a bit flag in the MCSection instead.
@llvm/pr-subscribers-mc @llvm/pr-subscribers-backend-directx Author: Alexis Engelke (aengelke) ChangesThis method is called once per encoded instruction, but never changes throughout the lifetime of a section. Store this information as a bit flag in the MCSection instead. Full diff: https://github.com/llvm/llvm-project/pull/96920.diff 15 Files Affected:
diff --git a/llvm/include/llvm/MC/MCSection.h b/llvm/include/llvm/MC/MCSection.h
index 00cb64c4ac1db..22e5db3be1739 100644
--- a/llvm/include/llvm/MC/MCSection.h
+++ b/llvm/include/llvm/MC/MCSection.h
@@ -106,6 +106,8 @@ class MCSection {
bool IsText : 1;
+ bool IsVirtual : 1;
+
MCDummyFragment DummyFragment;
// Mapping from subsection number to fragment list. At layout time, the
@@ -127,7 +129,8 @@ class MCSection {
StringRef Name;
SectionVariant Variant;
- MCSection(SectionVariant V, StringRef Name, bool IsText, MCSymbol *Begin);
+ MCSection(SectionVariant V, StringRef Name, bool IsText, bool IsVirtual,
+ MCSymbol *Begin);
~MCSection();
public:
@@ -219,7 +222,7 @@ class MCSection {
/// Check whether this section is "virtual", that is has no actual object
/// file contents.
- virtual bool isVirtualSection() const = 0;
+ bool isVirtualSection() const { return IsVirtual; }
virtual StringRef getVirtualSectionKind() const;
diff --git a/llvm/include/llvm/MC/MCSectionCOFF.h b/llvm/include/llvm/MC/MCSectionCOFF.h
index 922ad10467ad9..97540d985dbd1 100644
--- a/llvm/include/llvm/MC/MCSectionCOFF.h
+++ b/llvm/include/llvm/MC/MCSectionCOFF.h
@@ -53,6 +53,7 @@ class MCSectionCOFF final : public MCSection {
MCSectionCOFF(StringRef Name, unsigned Characteristics,
MCSymbol *COMDATSymbol, int Selection, MCSymbol *Begin)
: MCSection(SV_COFF, Name, Characteristics & COFF::IMAGE_SCN_CNT_CODE,
+ Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA,
Begin),
Characteristics(Characteristics), COMDATSymbol(COMDATSymbol),
Selection(Selection) {
@@ -75,7 +76,6 @@ class MCSectionCOFF final : public MCSection {
raw_ostream &OS,
uint32_t Subsection) const override;
bool useCodeAlign() const override;
- bool isVirtualSection() const override;
StringRef getVirtualSectionKind() const override;
unsigned getOrAssignWinCFISectionID(unsigned *NextID) const {
diff --git a/llvm/include/llvm/MC/MCSectionDXContainer.h b/llvm/include/llvm/MC/MCSectionDXContainer.h
index 627b10c3a721b..723b4778a3ac9 100644
--- a/llvm/include/llvm/MC/MCSectionDXContainer.h
+++ b/llvm/include/llvm/MC/MCSectionDXContainer.h
@@ -24,13 +24,13 @@ class MCSectionDXContainer final : public MCSection {
friend class MCContext;
MCSectionDXContainer(StringRef Name, SectionKind K, MCSymbol *Begin)
- : MCSection(SV_DXContainer, Name, K.isText(), Begin) {}
+ : MCSection(SV_DXContainer, Name, K.isText(), /*IsVirtual=*/false,
+ Begin) {}
public:
void printSwitchToSection(const MCAsmInfo &, const Triple &, raw_ostream &,
uint32_t) const override;
bool useCodeAlign() const override { return false; }
- bool isVirtualSection() const override { return false; }
};
} // end namespace llvm
diff --git a/llvm/include/llvm/MC/MCSectionELF.h b/llvm/include/llvm/MC/MCSectionELF.h
index 59a8966bbf544..3d45d3da10ca1 100644
--- a/llvm/include/llvm/MC/MCSectionELF.h
+++ b/llvm/include/llvm/MC/MCSectionELF.h
@@ -54,8 +54,9 @@ class MCSectionELF final : public MCSection {
unsigned entrySize, const MCSymbolELF *group, bool IsComdat,
unsigned UniqueID, MCSymbol *Begin,
const MCSymbolELF *LinkedToSym)
- : MCSection(SV_ELF, Name, flags & ELF::SHF_EXECINSTR, Begin), Type(type),
- Flags(flags), UniqueID(UniqueID), EntrySize(entrySize),
+ : MCSection(SV_ELF, Name, flags & ELF::SHF_EXECINSTR,
+ type == ELF::SHT_NOBITS, Begin),
+ Type(type), Flags(flags), UniqueID(UniqueID), EntrySize(entrySize),
Group(group, IsComdat), LinkedToSym(LinkedToSym) {
if (Group.getPointer())
Group.getPointer()->setIsSignature();
@@ -81,7 +82,6 @@ class MCSectionELF final : public MCSection {
raw_ostream &OS,
uint32_t Subsection) const override;
bool useCodeAlign() const override;
- bool isVirtualSection() const override;
StringRef getVirtualSectionKind() const override;
bool isUnique() const { return UniqueID != NonUniqueID; }
diff --git a/llvm/include/llvm/MC/MCSectionGOFF.h b/llvm/include/llvm/MC/MCSectionGOFF.h
index abc379f1c87fa..11c0f95364037 100644
--- a/llvm/include/llvm/MC/MCSectionGOFF.h
+++ b/llvm/include/llvm/MC/MCSectionGOFF.h
@@ -30,8 +30,8 @@ class MCSectionGOFF final : public MCSection {
friend class MCContext;
MCSectionGOFF(StringRef Name, SectionKind K, MCSection *P, uint32_t Sub)
- : MCSection(SV_GOFF, Name, K.isText(), nullptr), Parent(P),
- Subsection(Sub) {}
+ : MCSection(SV_GOFF, Name, K.isText(), /*IsVirtual=*/false, nullptr),
+ Parent(P), Subsection(Sub) {}
public:
void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
@@ -42,8 +42,6 @@ class MCSectionGOFF final : public MCSection {
bool useCodeAlign() const override { return false; }
- bool isVirtualSection() const override { return false; }
-
MCSection *getParent() const { return Parent; }
uint32_t getSubsection() const { return Subsection; }
diff --git a/llvm/include/llvm/MC/MCSectionMachO.h b/llvm/include/llvm/MC/MCSectionMachO.h
index 9562db0f460c3..3b7623fd450e5 100644
--- a/llvm/include/llvm/MC/MCSectionMachO.h
+++ b/llvm/include/llvm/MC/MCSectionMachO.h
@@ -75,7 +75,6 @@ class MCSectionMachO final : public MCSection {
raw_ostream &OS,
uint32_t Subsection) const override;
bool useCodeAlign() const override;
- bool isVirtualSection() const override;
void allocAtoms();
const MCSymbol *getAtom(size_t I) const;
diff --git a/llvm/include/llvm/MC/MCSectionSPIRV.h b/llvm/include/llvm/MC/MCSectionSPIRV.h
index 9e93f1a66ba28..091114a04b5cf 100644
--- a/llvm/include/llvm/MC/MCSectionSPIRV.h
+++ b/llvm/include/llvm/MC/MCSectionSPIRV.h
@@ -24,7 +24,8 @@ class MCSectionSPIRV final : public MCSection {
friend class MCContext;
MCSectionSPIRV()
- : MCSection(SV_SPIRV, "", /*IsText=*/true, /*Begin=*/nullptr) {}
+ : MCSection(SV_SPIRV, "", /*IsText=*/true, /*IsVirtual=*/false,
+ /*Begin=*/nullptr) {}
// TODO: Add StringRef Name to MCSectionSPIRV.
public:
@@ -33,7 +34,6 @@ class MCSectionSPIRV final : public MCSection {
raw_ostream &OS,
uint32_t Subsection) const override {}
bool useCodeAlign() const override { return false; }
- bool isVirtualSection() const override { return false; }
};
} // end namespace llvm
diff --git a/llvm/include/llvm/MC/MCSectionWasm.h b/llvm/include/llvm/MC/MCSectionWasm.h
index 3e89e7d320f6a..452381819c4b3 100644
--- a/llvm/include/llvm/MC/MCSectionWasm.h
+++ b/llvm/include/llvm/MC/MCSectionWasm.h
@@ -51,8 +51,9 @@ class MCSectionWasm final : public MCSection {
friend class MCContext;
MCSectionWasm(StringRef Name, SectionKind K, unsigned SegmentFlags,
const MCSymbolWasm *Group, unsigned UniqueID, MCSymbol *Begin)
- : MCSection(SV_Wasm, Name, K.isText(), Begin), UniqueID(UniqueID),
- Group(Group), IsWasmData(K.isReadOnly() || K.isWriteable()),
+ : MCSection(SV_Wasm, Name, K.isText(), /*IsVirtual=*/false, Begin),
+ UniqueID(UniqueID), Group(Group),
+ IsWasmData(K.isReadOnly() || K.isWriteable()),
IsMetadata(K.isMetadata()), SegmentFlags(SegmentFlags) {}
public:
@@ -67,7 +68,6 @@ class MCSectionWasm final : public MCSection {
raw_ostream &OS,
uint32_t Subsection) const override;
bool useCodeAlign() const override;
- bool isVirtualSection() const override;
bool isWasmData() const { return IsWasmData; }
bool isMetadata() const { return IsMetadata; }
diff --git a/llvm/include/llvm/MC/MCSectionXCOFF.h b/llvm/include/llvm/MC/MCSectionXCOFF.h
index 15155160fafbd..499df6b5fcc87 100644
--- a/llvm/include/llvm/MC/MCSectionXCOFF.h
+++ b/llvm/include/llvm/MC/MCSectionXCOFF.h
@@ -41,11 +41,14 @@ class MCSectionXCOFF final : public MCSection {
static constexpr unsigned DefaultAlignVal = 4;
static constexpr unsigned DefaultTextAlignVal = 32;
+ // XTY_CM sections are virtual except for toc-data symbols.
MCSectionXCOFF(StringRef Name, XCOFF::StorageMappingClass SMC,
XCOFF::SymbolType ST, SectionKind K, MCSymbolXCOFF *QualName,
MCSymbol *Begin, StringRef SymbolTableName,
bool MultiSymbolsAllowed)
- : MCSection(SV_XCOFF, Name, K.isText(), Begin),
+ : MCSection(SV_XCOFF, Name, K.isText(),
+ /*IsVirtual=*/ST == XCOFF::XTY_CM && SMC != XCOFF::XMC_TD,
+ Begin),
CsectProp(XCOFF::CsectProperties(SMC, ST)), QualName(QualName),
SymbolTableName(SymbolTableName), DwarfSubtypeFlags(std::nullopt),
MultiSymbolsAllowed(MultiSymbolsAllowed), Kind(K) {
@@ -69,12 +72,14 @@ class MCSectionXCOFF final : public MCSection {
}
}
+ // DWARF sections are never virtual.
MCSectionXCOFF(StringRef Name, SectionKind K, MCSymbolXCOFF *QualName,
XCOFF::DwarfSectionSubtypeFlags DwarfSubtypeFlags,
MCSymbol *Begin, StringRef SymbolTableName,
bool MultiSymbolsAllowed)
- : MCSection(SV_XCOFF, Name, K.isText(), Begin), QualName(QualName),
- SymbolTableName(SymbolTableName), DwarfSubtypeFlags(DwarfSubtypeFlags),
+ : MCSection(SV_XCOFF, Name, K.isText(), /*IsVirtual=*/false, Begin),
+ QualName(QualName), SymbolTableName(SymbolTableName),
+ DwarfSubtypeFlags(DwarfSubtypeFlags),
MultiSymbolsAllowed(MultiSymbolsAllowed), Kind(K) {
assert(QualName != nullptr && "QualName is needed.");
@@ -114,7 +119,6 @@ class MCSectionXCOFF final : public MCSection {
raw_ostream &OS,
uint32_t Subsection) const override;
bool useCodeAlign() const override;
- bool isVirtualSection() const override;
StringRef getSymbolTableName() const { return SymbolTableName; }
void setSymbolTableName(StringRef STN) { SymbolTableName = STN; }
bool isMultiSymbolsAllowed() const { return MultiSymbolsAllowed; }
diff --git a/llvm/lib/MC/MCSection.cpp b/llvm/lib/MC/MCSection.cpp
index c209c9715f474..1e15b685ea4ab 100644
--- a/llvm/lib/MC/MCSection.cpp
+++ b/llvm/lib/MC/MCSection.cpp
@@ -21,10 +21,10 @@
using namespace llvm;
MCSection::MCSection(SectionVariant V, StringRef Name, bool IsText,
- MCSymbol *Begin)
+ bool IsVirtual, MCSymbol *Begin)
: Begin(Begin), BundleGroupBeforeFirstInst(false), HasInstructions(false),
- HasLayout(false), IsRegistered(false), IsText(IsText), Name(Name),
- Variant(V) {
+ HasLayout(false), IsRegistered(false), IsText(IsText),
+ IsVirtual(IsVirtual), Name(Name), Variant(V) {
DummyFragment.setParent(this);
// The initial subsection number is 0. Create a fragment list.
CurFragList = &Subsections.emplace_back(0u, FragList{}).second;
diff --git a/llvm/lib/MC/MCSectionCOFF.cpp b/llvm/lib/MC/MCSectionCOFF.cpp
index 9330c1c2e54df..1389772502802 100644
--- a/llvm/lib/MC/MCSectionCOFF.cpp
+++ b/llvm/lib/MC/MCSectionCOFF.cpp
@@ -108,10 +108,6 @@ void MCSectionCOFF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
bool MCSectionCOFF::useCodeAlign() const { return isText(); }
-bool MCSectionCOFF::isVirtualSection() const {
- return getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
-}
-
StringRef MCSectionCOFF::getVirtualSectionKind() const {
return "IMAGE_SCN_CNT_UNINITIALIZED_DATA";
}
diff --git a/llvm/lib/MC/MCSectionELF.cpp b/llvm/lib/MC/MCSectionELF.cpp
index 4f0b67bfd9c45..5cd6590fb626d 100644
--- a/llvm/lib/MC/MCSectionELF.cpp
+++ b/llvm/lib/MC/MCSectionELF.cpp
@@ -210,8 +210,4 @@ bool MCSectionELF::useCodeAlign() const {
return getFlags() & ELF::SHF_EXECINSTR;
}
-bool MCSectionELF::isVirtualSection() const {
- return getType() == ELF::SHT_NOBITS;
-}
-
StringRef MCSectionELF::getVirtualSectionKind() const { return "SHT_NOBITS"; }
diff --git a/llvm/lib/MC/MCSectionMachO.cpp b/llvm/lib/MC/MCSectionMachO.cpp
index 1ac21951ce33c..67453cea53a26 100644
--- a/llvm/lib/MC/MCSectionMachO.cpp
+++ b/llvm/lib/MC/MCSectionMachO.cpp
@@ -92,8 +92,9 @@ ENTRY("" /*FIXME*/, S_ATTR_LOC_RELOC)
MCSectionMachO::MCSectionMachO(StringRef Segment, StringRef Section,
unsigned TAA, unsigned reserved2, SectionKind K,
MCSymbol *Begin)
- : MCSection(SV_MachO, Section, K.isText(), Begin), TypeAndAttributes(TAA),
- Reserved2(reserved2) {
+ : MCSection(SV_MachO, Section, K.isText(),
+ MachO::isVirtualSection(TAA & MachO::SECTION_TYPE), Begin),
+ TypeAndAttributes(TAA), Reserved2(reserved2) {
assert(Segment.size() <= 16 && Section.size() <= 16 &&
"Segment or section string too long");
for (unsigned i = 0; i != 16; ++i) {
@@ -172,12 +173,6 @@ bool MCSectionMachO::useCodeAlign() const {
return hasAttribute(MachO::S_ATTR_PURE_INSTRUCTIONS);
}
-bool MCSectionMachO::isVirtualSection() const {
- return (getType() == MachO::S_ZEROFILL ||
- getType() == MachO::S_GB_ZEROFILL ||
- getType() == MachO::S_THREAD_LOCAL_ZEROFILL);
-}
-
/// ParseSectionSpecifier - Parse the section specifier indicated by "Spec".
/// This is a string that can appear after a .section directive in a mach-o
/// flavored .s file. If successful, this fills in the specified Out
diff --git a/llvm/lib/MC/MCSectionWasm.cpp b/llvm/lib/MC/MCSectionWasm.cpp
index d905f8ff320ed..e25af1c3133fd 100644
--- a/llvm/lib/MC/MCSectionWasm.cpp
+++ b/llvm/lib/MC/MCSectionWasm.cpp
@@ -99,5 +99,3 @@ void MCSectionWasm::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
}
bool MCSectionWasm::useCodeAlign() const { return false; }
-
-bool MCSectionWasm::isVirtualSection() const { return false; }
diff --git a/llvm/lib/MC/MCSectionXCOFF.cpp b/llvm/lib/MC/MCSectionXCOFF.cpp
index e63bc92ee82e2..00ca5d2067d58 100644
--- a/llvm/lib/MC/MCSectionXCOFF.cpp
+++ b/llvm/lib/MC/MCSectionXCOFF.cpp
@@ -132,14 +132,3 @@ void MCSectionXCOFF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
}
bool MCSectionXCOFF::useCodeAlign() const { return getKind().isText(); }
-
-bool MCSectionXCOFF::isVirtualSection() const {
- // DWARF sections are always not virtual.
- if (isDwarfSect())
- return false;
- assert(isCsect() &&
- "Handling for isVirtualSection not implemented for this section!");
- // XTY_CM sections are virtual except for toc-data symbols.
- return (XCOFF::XTY_CM == CsectProp->Type) &&
- (getMappingClass() != XCOFF::XMC_TD);
-}
|
MaskRay
approved these changes
Jun 27, 2024
lravenclaw
pushed a commit
to lravenclaw/llvm-project
that referenced
this pull request
Jul 3, 2024
This method is called once per encoded instruction, but never changes throughout the lifetime of a section. Store this information as a bit flag in the MCSection instead.
AlexisPerry
pushed a commit
to llvm-project-tlp/llvm-project
that referenced
this pull request
Jul 9, 2024
This method is called once per encoded instruction, but never changes throughout the lifetime of a section. Store this information as a bit flag in the MCSection instead.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This method is called once per encoded instruction, but never changes throughout the lifetime of a section. Store this information as a bit flag in the MCSection instead.