Skip to content

Commit 95f983f

Browse files
committed
[MC] Change Subsection parameters from const MCExpr * to uint32_t
Follow-up to 05ba5c0. uint32_t is preferred over const MCExpr * in the section stack uses because it should only be evaluated once. Change the paramter type to match.
1 parent b37a4b9 commit 95f983f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+95
-142
lines changed

llvm/include/llvm/MC/MCContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ class MCContext {
600600
unsigned EntrySize);
601601

602602
MCSectionGOFF *getGOFFSection(StringRef Section, SectionKind Kind,
603-
MCSection *Parent, const MCExpr *SubsectionId);
603+
MCSection *Parent, uint32_t Subsection = 0);
604604

605605
MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
606606
StringRef COMDATSymName, int Selection,

llvm/include/llvm/MC/MCELFStreamer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class MCELFStreamer : public MCObjectStreamer {
4646
/// @{
4747

4848
void initSections(bool NoExecStack, const MCSubtargetInfo &STI) override;
49-
void changeSection(MCSection *Section, const MCExpr *Subsection) override;
49+
void changeSection(MCSection *Section, uint32_t Subsection) override;
5050
void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
5151
void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCDataFragment &F,
5252
uint64_t Offset) override;

llvm/include/llvm/MC/MCObjectStreamer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class MCObjectStreamer : public MCStreamer {
101101
MCDataFragment *getOrCreateDataFragment(const MCSubtargetInfo* STI = nullptr);
102102

103103
protected:
104-
bool changeSectionImpl(MCSection *Section, const MCExpr *Subsection);
104+
bool changeSectionImpl(MCSection *Section, uint32_t Subsection);
105105

106106
public:
107107
void visitUsedSymbol(const MCSymbol &Sym) override;
@@ -122,7 +122,7 @@ class MCObjectStreamer : public MCStreamer {
122122
void emitULEB128Value(const MCExpr *Value) override;
123123
void emitSLEB128Value(const MCExpr *Value) override;
124124
void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
125-
void changeSection(MCSection *Section, const MCExpr *Subsection) override;
125+
void changeSection(MCSection *Section, uint32_t Subsection) override;
126126
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
127127

128128
/// Emit an instruction to a special fragment, because this instruction

llvm/include/llvm/MC/MCSection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class MCSection {
211211

212212
virtual void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
213213
raw_ostream &OS,
214-
const MCExpr *Subsection) const = 0;
214+
uint32_t Subsection) const = 0;
215215

216216
/// Return true if a .align directive should use "optimized nops" to fill
217217
/// instead of 0s.

llvm/include/llvm/MC/MCSectionCOFF.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class MCSectionCOFF final : public MCSection {
7373

7474
void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
7575
raw_ostream &OS,
76-
const MCExpr *Subsection) const override;
76+
uint32_t Subsection) const override;
7777
bool useCodeAlign() const override;
7878
bool isVirtualSection() const override;
7979
StringRef getVirtualSectionKind() const override;

llvm/include/llvm/MC/MCSectionDXContainer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class MCSectionDXContainer final : public MCSection {
2828

2929
public:
3030
void printSwitchToSection(const MCAsmInfo &, const Triple &, raw_ostream &,
31-
const MCExpr *) const override;
31+
uint32_t) const override;
3232
bool useCodeAlign() const override { return false; }
3333
bool isVirtualSection() const override { return false; }
3434
};

llvm/include/llvm/MC/MCSectionELF.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class MCSectionELF final : public MCSection {
7979

8080
void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
8181
raw_ostream &OS,
82-
const MCExpr *Subsection) const override;
82+
uint32_t Subsection) const override;
8383
bool useCodeAlign() const override;
8484
bool isVirtualSection() const override;
8585
StringRef getVirtualSectionKind() const override;

llvm/include/llvm/MC/MCSectionGOFF.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ class MCExpr;
2626
class MCSectionGOFF final : public MCSection {
2727
private:
2828
MCSection *Parent;
29-
const MCExpr *SubsectionId;
29+
uint32_t Subsection;
3030

3131
friend class MCContext;
32-
MCSectionGOFF(StringRef Name, SectionKind K, MCSection *P, const MCExpr *Sub)
32+
MCSectionGOFF(StringRef Name, SectionKind K, MCSection *P, uint32_t Sub)
3333
: MCSection(SV_GOFF, Name, K.isText(), nullptr), Parent(P),
34-
SubsectionId(Sub) {}
34+
Subsection(Sub) {}
3535

3636
public:
3737
void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
3838
raw_ostream &OS,
39-
const MCExpr *Subsection) const override {
39+
uint32_t /*Subsection*/) const override {
4040
OS << "\t.section\t\"" << getName() << "\"\n";
4141
}
4242

@@ -45,7 +45,7 @@ class MCSectionGOFF final : public MCSection {
4545
bool isVirtualSection() const override { return false; }
4646

4747
MCSection *getParent() const { return Parent; }
48-
const MCExpr *getSubsectionId() const { return SubsectionId; }
48+
uint32_t getSubsection() const { return Subsection; }
4949

5050
static bool classof(const MCSection *S) { return S->getVariant() == SV_GOFF; }
5151
};

llvm/include/llvm/MC/MCSectionMachO.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class MCSectionMachO final : public MCSection {
7373

7474
void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
7575
raw_ostream &OS,
76-
const MCExpr *Subsection) const override;
76+
uint32_t Subsection) const override;
7777
bool useCodeAlign() const override;
7878
bool isVirtualSection() const override;
7979

llvm/include/llvm/MC/MCSectionSPIRV.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class MCSectionSPIRV final : public MCSection {
3131
~MCSectionSPIRV() = default;
3232
void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
3333
raw_ostream &OS,
34-
const MCExpr *Subsection) const override {}
34+
uint32_t Subsection) const override {}
3535
bool useCodeAlign() const override { return false; }
3636
bool isVirtualSection() const override { return false; }
3737
};

llvm/include/llvm/MC/MCSectionWasm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class MCSectionWasm final : public MCSection {
6565

6666
void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
6767
raw_ostream &OS,
68-
const MCExpr *Subsection) const override;
68+
uint32_t Subsection) const override;
6969
bool useCodeAlign() const override;
7070
bool isVirtualSection() const override;
7171

llvm/include/llvm/MC/MCSectionXCOFF.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class MCSectionXCOFF final : public MCSection {
112112

113113
void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
114114
raw_ostream &OS,
115-
const MCExpr *Subsection) const override;
115+
uint32_t Subsection) const override;
116116
bool useCodeAlign() const override;
117117
bool isVirtualSection() const override;
118118
StringRef getSymbolTableName() const { return SymbolTableName; }

llvm/include/llvm/MC/MCStreamer.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class MCTargetStreamer {
116116
/// This is called by popSection and switchSection, if the current
117117
/// section changes.
118118
virtual void changeSection(const MCSection *CurSection, MCSection *Section,
119-
const MCExpr *SubSection, raw_ostream &OS);
119+
uint32_t SubSection, raw_ostream &OS);
120120

121121
virtual void emitValue(const MCExpr *Value);
122122

@@ -411,7 +411,7 @@ class MCStreamer {
411411
///
412412
/// This is called by popSection and switchSection, if the current
413413
/// section changes.
414-
virtual void changeSection(MCSection *, const MCExpr *);
414+
virtual void changeSection(MCSection *, uint32_t);
415415

416416
/// Save the current and previous section on the section stack.
417417
void pushSection() {
@@ -425,15 +425,12 @@ class MCStreamer {
425425
/// Returns false if the stack was empty.
426426
bool popSection();
427427

428-
bool subSection(const MCExpr *Subsection);
429-
430428
/// Set the current section where code is being emitted to \p Section. This
431429
/// is required to update CurSection.
432430
///
433431
/// This corresponds to assembler directives like .section, .text, etc.
434-
virtual void switchSection(MCSection *Section,
435-
const MCExpr *Subsection = nullptr);
436-
void switchSection(MCSection *Section, uint32_t Subsec);
432+
virtual void switchSection(MCSection *Section, uint32_t Subsec = 0);
433+
bool switchSection(MCSection *Section, const MCExpr *);
437434

438435
/// Set the current section where code is being emitted to \p Section.
439436
/// This is required to update CurSection. This version does not call

llvm/include/llvm/MC/MCWasmStreamer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class MCWasmStreamer : public MCObjectStreamer {
4040
/// \name MCStreamer Interface
4141
/// @{
4242

43-
void changeSection(MCSection *Section, const MCExpr *Subsection) override;
43+
void changeSection(MCSection *Section, uint32_t Subsection) override;
4444
void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
4545
void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCDataFragment &F,
4646
uint64_t Offset) override;

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2725,16 +2725,15 @@ MCSection *TargetLoweringObjectFileGOFF::getExplicitSectionGlobal(
27252725
MCSection *TargetLoweringObjectFileGOFF::getSectionForLSDA(
27262726
const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const {
27272727
std::string Name = ".gcc_exception_table." + F.getName().str();
2728-
return getContext().getGOFFSection(Name, SectionKind::getData(), nullptr,
2729-
nullptr);
2728+
return getContext().getGOFFSection(Name, SectionKind::getData(), nullptr, 0);
27302729
}
27312730

27322731
MCSection *TargetLoweringObjectFileGOFF::SelectSectionForGlobal(
27332732
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
27342733
auto *Symbol = TM.getSymbol(GO);
27352734
if (Kind.isBSS())
27362735
return getContext().getGOFFSection(Symbol->getName(), SectionKind::getBSS(),
2737-
nullptr, nullptr);
2736+
nullptr, 0);
27382737

27392738
return getContext().getObjectFileInfo()->getTextSection();
27402739
}

llvm/lib/MC/MCAsmStreamer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class MCAsmStreamer final : public MCStreamer {
144144
/// @name MCStreamer Interface
145145
/// @{
146146

147-
void changeSection(MCSection *Section, const MCExpr *Subsection) override;
147+
void changeSection(MCSection *Section, uint32_t Subsection) override;
148148

149149
void emitELFSymverDirective(const MCSymbol *OriginalSym, StringRef Name,
150150
bool KeepOriginalSym) override;
@@ -510,8 +510,7 @@ void MCAsmStreamer::emitExplicitComments() {
510510
ExplicitCommentToEmit.clear();
511511
}
512512

513-
void MCAsmStreamer::changeSection(MCSection *Section,
514-
const MCExpr *Subsection) {
513+
void MCAsmStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
515514
assert(Section && "Cannot switch to a null section!");
516515
if (MCTargetStreamer *TS = getTargetStreamer()) {
517516
TS->changeSection(getCurrentSectionOnly(), Section, Subsection, OS);

llvm/lib/MC/MCContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ MCContext::getELFUniqueIDForEntsize(StringRef SectionName, unsigned Flags,
660660

661661
MCSectionGOFF *MCContext::getGOFFSection(StringRef Section, SectionKind Kind,
662662
MCSection *Parent,
663-
const MCExpr *SubsectionId) {
663+
uint32_t Subsection) {
664664
// Do the lookup. If we don't have a hit, return a new section.
665665
auto IterBool =
666666
GOFFUniquingMap.insert(std::make_pair(Section.str(), nullptr));
@@ -670,7 +670,7 @@ MCSectionGOFF *MCContext::getGOFFSection(StringRef Section, SectionKind Kind,
670670

671671
StringRef CachedName = Iter->first;
672672
MCSectionGOFF *GOFFSection = new (GOFFAllocator.Allocate())
673-
MCSectionGOFF(CachedName, Kind, Parent, SubsectionId);
673+
MCSectionGOFF(CachedName, Kind, Parent, Subsection);
674674
Iter->second = GOFFSection;
675675

676676
return GOFFSection;

llvm/lib/MC/MCELFStreamer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ static void setSectionAlignmentForBundling(const MCAssembler &Assembler,
106106
Section->ensureMinAlignment(Align(Assembler.getBundleAlignSize()));
107107
}
108108

109-
void MCELFStreamer::changeSection(MCSection *Section,
110-
const MCExpr *Subsection) {
109+
void MCELFStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
111110
MCSection *CurSection = getCurrentSectionOnly();
112111
if (CurSection && isBundleLocked())
113112
report_fatal_error("Unterminated .bundle_lock when changing a section");

llvm/lib/MC/MCMachOStreamer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class MCMachOStreamer : public MCObjectStreamer {
8585
/// @name MCStreamer Interface
8686
/// @{
8787

88-
void changeSection(MCSection *Sect, const MCExpr *Subsect) override;
88+
void changeSection(MCSection *Sect, uint32_t Subsect) override;
8989
void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
9090
void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
9191
void emitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol) override;
@@ -163,8 +163,7 @@ static bool canGoAfterDWARF(const MCSectionMachO &MSec) {
163163
return false;
164164
}
165165

166-
void MCMachOStreamer::changeSection(MCSection *Section,
167-
const MCExpr *Subsection) {
166+
void MCMachOStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
168167
// Change the section normally.
169168
bool Created = changeSectionImpl(Section, Subsection);
170169
const MCSectionMachO &MSec = *cast<MCSectionMachO>(Section);

llvm/lib/MC/MCObjectFileInfo.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -546,25 +546,18 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
546546
}
547547

548548
void MCObjectFileInfo::initGOFFMCObjectFileInfo(const Triple &T) {
549-
TextSection =
550-
Ctx->getGOFFSection(".text", SectionKind::getText(), nullptr, nullptr);
551-
BSSSection =
552-
Ctx->getGOFFSection(".bss", SectionKind::getBSS(), nullptr, nullptr);
553-
PPA1Section =
554-
Ctx->getGOFFSection(".ppa1", SectionKind::getMetadata(), TextSection,
555-
MCConstantExpr::create(GOFF::SK_PPA1, *Ctx));
556-
PPA2Section =
557-
Ctx->getGOFFSection(".ppa2", SectionKind::getMetadata(), TextSection,
558-
MCConstantExpr::create(GOFF::SK_PPA2, *Ctx));
549+
TextSection = Ctx->getGOFFSection(".text", SectionKind::getText(), nullptr);
550+
BSSSection = Ctx->getGOFFSection(".bss", SectionKind::getBSS(), nullptr);
551+
PPA1Section = Ctx->getGOFFSection(".ppa1", SectionKind::getMetadata(),
552+
TextSection, GOFF::SK_PPA1);
553+
PPA2Section = Ctx->getGOFFSection(".ppa2", SectionKind::getMetadata(),
554+
TextSection, GOFF::SK_PPA2);
559555

560556
PPA2ListSection =
561-
Ctx->getGOFFSection(".ppa2list", SectionKind::getData(),
562-
nullptr, nullptr);
557+
Ctx->getGOFFSection(".ppa2list", SectionKind::getData(), nullptr);
563558

564-
ADASection =
565-
Ctx->getGOFFSection(".ada", SectionKind::getData(), nullptr, nullptr);
566-
IDRLSection =
567-
Ctx->getGOFFSection("B_IDRL", SectionKind::getData(), nullptr, nullptr);
559+
ADASection = Ctx->getGOFFSection(".ada", SectionKind::getData(), nullptr);
560+
IDRLSection = Ctx->getGOFFSection("B_IDRL", SectionKind::getData(), nullptr);
568561
}
569562

570563
void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {

llvm/lib/MC/MCObjectStreamer.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,22 +285,17 @@ void MCObjectStreamer::emitWeakReference(MCSymbol *Alias,
285285
report_fatal_error("This file format doesn't support weak aliases.");
286286
}
287287

288-
void MCObjectStreamer::changeSection(MCSection *Section,
289-
const MCExpr *Subsection) {
288+
void MCObjectStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
290289
changeSectionImpl(Section, Subsection);
291290
}
292291

293292
bool MCObjectStreamer::changeSectionImpl(MCSection *Section,
294-
const MCExpr *SubsecExpr) {
293+
uint32_t Subsection) {
295294
assert(Section && "Cannot switch to a null section!");
296295
getContext().clearDwarfLocSeen();
297296

298297
bool Created = getAssembler().registerSection(*Section);
299-
300-
int64_t Subsec = 0;
301-
if (SubsecExpr)
302-
(void)SubsecExpr->evaluateAsAbsolute(Subsec, getAssemblerPtr());
303-
CurSubsectionIdx = uint32_t(Subsec);
298+
CurSubsectionIdx = Subsection;
304299
Section->switchSubsection(CurSubsectionIdx);
305300
return Created;
306301
}

llvm/lib/MC/MCParser/ELFAsmParser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,8 @@ bool ELFAsmParser::ParseDirectiveSubsection(StringRef, SMLoc) {
927927

928928
Lex();
929929

930-
return getStreamer().subSection(Subsection);
930+
return getStreamer().switchSection(getStreamer().getCurrentSectionOnly(),
931+
Subsection);
931932
}
932933

933934
bool ELFAsmParser::ParseDirectiveCGProfile(StringRef S, SMLoc Loc) {

llvm/lib/MC/MCSectionCOFF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void MCSectionCOFF::setSelection(int Selection) const {
3636

3737
void MCSectionCOFF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
3838
raw_ostream &OS,
39-
const MCExpr *Subsection) const {
39+
uint32_t Subsection) const {
4040
// standard sections don't require the '.section'
4141
if (shouldOmitSectionDirective(getName(), MAI)) {
4242
OS << '\t' << getName() << '\n';

llvm/lib/MC/MCSectionDXContainer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ using namespace llvm;
1212

1313
void MCSectionDXContainer::printSwitchToSection(const MCAsmInfo &,
1414
const Triple &, raw_ostream &,
15-
const MCExpr *) const {}
15+
uint32_t) const {}

llvm/lib/MC/MCSectionELF.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,11 @@ static void printName(raw_ostream &OS, StringRef Name) {
5252

5353
void MCSectionELF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
5454
raw_ostream &OS,
55-
const MCExpr *Subsection) const {
55+
uint32_t Subsection) const {
5656
if (shouldOmitSectionDirective(getName(), MAI)) {
5757
OS << '\t' << getName();
58-
if (Subsection) {
59-
OS << '\t';
60-
Subsection->print(OS, &MAI);
61-
}
58+
if (Subsection)
59+
OS << '\t' << Subsection;
6260
OS << '\n';
6361
return;
6462
}
@@ -203,8 +201,7 @@ void MCSectionELF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
203201
OS << '\n';
204202

205203
if (Subsection) {
206-
OS << "\t.subsection\t";
207-
Subsection->print(OS, &MAI);
204+
OS << "\t.subsection\t" << Subsection;
208205
OS << '\n';
209206
}
210207
}

llvm/lib/MC/MCSectionMachO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ MCSectionMachO::MCSectionMachO(StringRef Segment, StringRef Section,
106106

107107
void MCSectionMachO::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
108108
raw_ostream &OS,
109-
const MCExpr *Subsection) const {
109+
uint32_t Subsection) const {
110110
OS << "\t.section\t" << getSegmentName() << ',' << getName();
111111

112112
// Get the section type and attributes.

0 commit comments

Comments
 (0)