aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCStreamer.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2024-06-22 21:48:11 -0700
committerFangrui Song <i@maskray.me>2024-06-22 21:48:11 -0700
commit95f983f8239c071712cc42d0d54d3ebfa7c32a22 (patch)
tree262a817f9c5d7517e8f9b2ee70ce45bc91819b1c /llvm/lib/MC/MCStreamer.cpp
parentb37a4b9991a0a669594b53caa0eb75f489211d69 (diff)
downloadllvm-95f983f8239c071712cc42d0d54d3ebfa7c32a22.zip
llvm-95f983f8239c071712cc42d0d54d3ebfa7c32a22.tar.gz
llvm-95f983f8239c071712cc42d0d54d3ebfa7c32a22.tar.bz2
[MC] Change Subsection parameters from const MCExpr * to uint32_t
Follow-up to 05ba5c0648ae5e80d5afce270495bf3b1eef9af4. 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.
Diffstat (limited to 'llvm/lib/MC/MCStreamer.cpp')
-rw-r--r--llvm/lib/MC/MCStreamer.cpp65
1 files changed, 24 insertions, 41 deletions
diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp
index 4b86bc2..582b3a6 100644
--- a/llvm/lib/MC/MCStreamer.cpp
+++ b/llvm/lib/MC/MCStreamer.cpp
@@ -57,8 +57,7 @@ void MCTargetStreamer::finish() {}
void MCTargetStreamer::emitConstantPools() {}
void MCTargetStreamer::changeSection(const MCSection *CurSection,
- MCSection *Section,
- const MCExpr *Subsection,
+ MCSection *Section, uint32_t Subsection,
raw_ostream &OS) {
Section->printSwitchToSection(*Streamer.getContext().getAsmInfo(),
Streamer.getContext().getTargetTriple(), OS,
@@ -1218,7 +1217,7 @@ void MCStreamer::emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Align ByteAlignment) {}
void MCStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
uint64_t Size, Align ByteAlignment) {}
-void MCStreamer::changeSection(MCSection *, const MCExpr *) {}
+void MCStreamer::changeSection(MCSection *, uint32_t) {}
void MCStreamer::emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {}
void MCStreamer::emitBytes(StringRef Data) {}
void MCStreamer::emitBinaryData(StringRef Data) { emitBytes(Data); }
@@ -1252,47 +1251,18 @@ bool MCStreamer::popSection() {
MCSectionSubPair NewSec = I->first;
if (NewSec.first && OldSec != NewSec)
- changeSection(NewSec.first, NewSec.second ? MCConstantExpr::create(
- NewSec.second, getContext())
- : nullptr);
+ changeSection(NewSec.first, NewSec.second);
SectionStack.pop_back();
return true;
}
-bool MCStreamer::subSection(const MCExpr *SubsecExpr) {
- if (SectionStack.empty())
- return true;
-
- int64_t Subsec;
- if (!SubsecExpr->evaluateAsAbsolute(Subsec, getAssemblerPtr())) {
- getContext().reportError(SubsecExpr->getLoc(),
- "cannot evaluate subsection number");
- return true;
- }
- if (!isUInt<31>(Subsec)) {
- getContext().reportError(SubsecExpr->getLoc(),
- "subsection number " + Twine(Subsec) +
- " is not within [0,2147483647]");
- return true;
- }
-
- MCSectionSubPair CurPair = SectionStack.back().first;
- SectionStack.back().second = CurPair;
- SectionStack.back().first.second = Subsec;
- changeSection(CurPair.first, SubsecExpr);
- return false;
-}
-
-void MCStreamer::switchSection(MCSection *Section, const MCExpr *SubsecExpr) {
+void MCStreamer::switchSection(MCSection *Section, uint32_t Subsection) {
assert(Section && "Cannot switch to a null section!");
MCSectionSubPair curSection = SectionStack.back().first;
SectionStack.back().second = curSection;
- uint32_t Subsec = 0;
- if (SubsecExpr)
- Subsec = cast<MCConstantExpr>(SubsecExpr)->getValue();
- if (MCSectionSubPair(Section, Subsec) != curSection) {
- changeSection(Section, SubsecExpr);
- SectionStack.back().first = MCSectionSubPair(Section, Subsec);
+ if (MCSectionSubPair(Section, Subsection) != curSection) {
+ changeSection(Section, Subsection);
+ SectionStack.back().first = MCSectionSubPair(Section, Subsection);
assert(!Section->hasEnded() && "Section already ended");
MCSymbol *Sym = Section->getBeginSymbol();
if (Sym && !Sym->isInSection())
@@ -1300,10 +1270,23 @@ void MCStreamer::switchSection(MCSection *Section, const MCExpr *SubsecExpr) {
}
}
-void MCStreamer::switchSection(MCSection *Section, uint32_t Subsec) {
- switchSection(Section, Subsec == 0
- ? nullptr
- : MCConstantExpr::create(Subsec, getContext()));
+bool MCStreamer::switchSection(MCSection *Section, const MCExpr *SubsecExpr) {
+ int64_t Subsec = 0;
+ if (SubsecExpr) {
+ if (!SubsecExpr->evaluateAsAbsolute(Subsec, getAssemblerPtr())) {
+ getContext().reportError(SubsecExpr->getLoc(),
+ "cannot evaluate subsection number");
+ return true;
+ }
+ if (!isUInt<31>(Subsec)) {
+ getContext().reportError(SubsecExpr->getLoc(),
+ "subsection number " + Twine(Subsec) +
+ " is not within [0,2147483647]");
+ return true;
+ }
+ }
+ switchSection(Section, Subsec);
+ return false;
}
MCSymbol *MCStreamer::endSection(MCSection *Section) {