Skip to content

Commit 1ea085b

Browse files
committed
MCSectionXCOFF: Remove classof
The object file format specific derived classes are used in context like MCStreamer and MCObjectTargetWriter where the type is statically known. We don't use isa/dyn_cast and we want to eliminate MCSection::SectionVariant in the base class.
1 parent 1669bd3 commit 1ea085b

File tree

7 files changed

+31
-33
lines changed

7 files changed

+31
-33
lines changed

llvm/include/llvm/MC/MCSectionXCOFF.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@ class MCSectionXCOFF final : public MCSection {
9595
public:
9696
~MCSectionXCOFF();
9797

98-
static bool classof(const MCSection *S) {
99-
return S->getVariant() == SV_XCOFF;
100-
}
101-
10298
XCOFF::StorageMappingClass getMappingClass() const {
10399
assert(isCsect() && "Only csect section has mapping class property!");
104100
return CsectProp->MappingClass;

llvm/lib/CodeGen/AsmPrinter/AIXException.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ void AIXException::emitExceptionInfoTable(const MCSymbol *LSDA,
3737
// unsigned long personality; /* Pointer to the personality routine */
3838
// }
3939

40-
auto *EHInfo =
41-
cast<MCSectionXCOFF>(Asm->getObjFileLowering().getCompactUnwindSection());
40+
auto *EHInfo = static_cast<MCSectionXCOFF *>(
41+
Asm->getObjFileLowering().getCompactUnwindSection());
4242
if (Asm->TM.getFunctionSections()) {
4343
// If option -ffunction-sections is on, append the function name to the
4444
// name of EH Info Table csect so that each function has its own EH Info

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2388,23 +2388,25 @@ TargetLoweringObjectFileXCOFF::getTargetSymbol(const GlobalValue *GV,
23882388
// here.
23892389
if (const GlobalObject *GO = dyn_cast<GlobalObject>(GV)) {
23902390
if (GO->isDeclarationForLinker())
2391-
return cast<MCSectionXCOFF>(getSectionForExternalReference(GO, TM))
2391+
return static_cast<const MCSectionXCOFF *>(
2392+
getSectionForExternalReference(GO, TM))
23922393
->getQualNameSymbol();
23932394

23942395
if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV))
23952396
if (GVar->hasAttribute("toc-data"))
2396-
return cast<MCSectionXCOFF>(
2397+
return static_cast<const MCSectionXCOFF *>(
23972398
SectionForGlobal(GVar, SectionKind::getData(), TM))
23982399
->getQualNameSymbol();
23992400

24002401
SectionKind GOKind = getKindForGlobal(GO, TM);
24012402
if (GOKind.isText())
2402-
return cast<MCSectionXCOFF>(
2403+
return static_cast<const MCSectionXCOFF *>(
24032404
getSectionForFunctionDescriptor(cast<Function>(GO), TM))
24042405
->getQualNameSymbol();
24052406
if ((TM.getDataSections() && !GO->hasSection()) || GO->hasCommonLinkage() ||
24062407
GOKind.isBSSLocal() || GOKind.isThreadBSSLocal())
2407-
return cast<MCSectionXCOFF>(SectionForGlobal(GO, GOKind, TM))
2408+
return static_cast<const MCSectionXCOFF *>(
2409+
SectionForGlobal(GO, GOKind, TM))
24082410
->getQualNameSymbol();
24092411
}
24102412

@@ -2740,7 +2742,7 @@ MCSection *TargetLoweringObjectFileXCOFF::getSectionForTOCEntry(
27402742

27412743
MCSection *TargetLoweringObjectFileXCOFF::getSectionForLSDA(
27422744
const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const {
2743-
auto *LSDA = cast<MCSectionXCOFF>(LSDASection);
2745+
auto *LSDA = static_cast<MCSectionXCOFF *>(LSDASection);
27442746
if (TM.getFunctionSections()) {
27452747
// If option -ffunction-sections is on, append the function name to the
27462748
// name of the LSDA csect so that each function has its own LSDA csect.

llvm/lib/MC/MCXCOFFStreamer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ XCOFFObjectWriter &MCXCOFFStreamer::getWriter() {
3838

3939
void MCXCOFFStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
4040
MCObjectStreamer::changeSection(Section, Subsection);
41-
auto *Sec = cast<MCSectionXCOFF>(Section);
41+
auto *Sec = static_cast<const MCSectionXCOFF *>(Section);
4242
// We might miss calculating the symbols difference as absolute value before
4343
// adding fixups when symbol_A without the fragment set is the csect itself
4444
// and symbol_B is in it.

llvm/lib/MC/XCOFFObjectWriter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,13 +550,13 @@ CsectGroup &XCOFFWriter::getCsectGroup(const MCSectionXCOFF *MCSec) {
550550

551551
static MCSectionXCOFF *getContainingCsect(const MCSymbolXCOFF *XSym) {
552552
if (XSym->isDefined())
553-
return cast<MCSectionXCOFF>(XSym->getFragment()->getParent());
553+
return static_cast<MCSectionXCOFF *>(XSym->getFragment()->getParent());
554554
return XSym->getRepresentedCsect();
555555
}
556556

557557
void XCOFFWriter::executePostLayoutBinding() {
558558
for (const auto &S : *Asm) {
559-
const auto *MCSec = cast<const MCSectionXCOFF>(&S);
559+
auto *MCSec = static_cast<const MCSectionXCOFF *>(&S);
560560
assert(!SectionMap.contains(MCSec) && "Cannot add a section twice.");
561561

562562
// If the name does not fit in the storage provided in the symbol table
@@ -747,7 +747,7 @@ void XCOFFWriter::recordRelocation(const MCFragment &F, const MCFixup &Fixup,
747747
FixedValue = TOCEntryOffset;
748748
}
749749
} else if (Type == XCOFF::RelocationType::R_RBR) {
750-
MCSectionXCOFF *ParentSec = cast<MCSectionXCOFF>(F.getParent());
750+
auto *ParentSec = static_cast<MCSectionXCOFF *>(F.getParent());
751751
assert((SymASec->getMappingClass() == XCOFF::XMC_PR &&
752752
ParentSec->getMappingClass() == XCOFF::XMC_PR) &&
753753
"Only XMC_PR csect may have the R_RBR relocation.");
@@ -768,7 +768,7 @@ void XCOFFWriter::recordRelocation(const MCFragment &F, const MCFixup &Fixup,
768768
}
769769

770770
XCOFFRelocation Reloc = {Index, FixupOffsetInCsect, SignAndSize, Type};
771-
MCSectionXCOFF *RelocationSec = cast<MCSectionXCOFF>(F.getParent());
771+
auto *RelocationSec = static_cast<MCSectionXCOFF *>(F.getParent());
772772
assert(SectionMap.contains(RelocationSec) &&
773773
"Expected containing csect to exist in map.");
774774
SectionMap[RelocationSec]->Relocations.push_back(Reloc);

llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class PPCTargetAsmStreamer : public PPCTargetStreamer {
213213
void emitTCEntry(const MCSymbol &S, PPCMCExpr::Specifier Kind) override {
214214
if (const MCSymbolXCOFF *XSym = dyn_cast<MCSymbolXCOFF>(&S)) {
215215
MCSymbolXCOFF *TCSym =
216-
cast<MCSectionXCOFF>(Streamer.getCurrentSectionOnly())
216+
static_cast<const MCSectionXCOFF *>(Streamer.getCurrentSectionOnly())
217217
->getQualNameSymbol();
218218
// On AIX, we have TLS variable offsets (symbol@({gd|ie|le|ld}) depending
219219
// on the TLS access method (or model). For the general-dynamic access

llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,9 +2274,9 @@ void PPCAIXAsmPrinter::emitLinkage(const GlobalValue *GV,
22742274

22752275
void PPCAIXAsmPrinter::SetupMachineFunction(MachineFunction &MF) {
22762276
// Setup CurrentFnDescSym and its containing csect.
2277-
MCSectionXCOFF *FnDescSec =
2278-
cast<MCSectionXCOFF>(getObjFileLowering().getSectionForFunctionDescriptor(
2279-
&MF.getFunction(), TM));
2277+
auto *FnDescSec = static_cast<MCSectionXCOFF *>(
2278+
getObjFileLowering().getSectionForFunctionDescriptor(&MF.getFunction(),
2279+
TM));
22802280
FnDescSec->setAlignment(Align(Subtarget->isPPC64() ? 8 : 4));
22812281

22822282
CurrentFnDescSym = FnDescSec->getQualNameSymbol();
@@ -2669,9 +2669,9 @@ void PPCAIXAsmPrinter::emitTracebackTable() {
26692669
MCSymbol *EHInfoSym =
26702670
TargetLoweringObjectFileXCOFF::getEHInfoTableSymbol(MF);
26712671
MCSymbol *TOCEntry = lookUpOrCreateTOCEntry(EHInfoSym, TOCType_EHBlock);
2672-
const MCSymbol *TOCBaseSym =
2673-
cast<MCSectionXCOFF>(getObjFileLowering().getTOCBaseSection())
2674-
->getQualNameSymbol();
2672+
const MCSymbol *TOCBaseSym = static_cast<const MCSectionXCOFF *>(
2673+
getObjFileLowering().getTOCBaseSection())
2674+
->getQualNameSymbol();
26752675
const MCExpr *Exp =
26762676
MCBinaryExpr::createSub(MCSymbolRefExpr::create(TOCEntry, Ctx),
26772677
MCSymbolRefExpr::create(TOCBaseSym, Ctx), Ctx);
@@ -2788,7 +2788,7 @@ void PPCAIXAsmPrinter::emitGlobalVariableHelper(const GlobalVariable *GV) {
27882788
}
27892789
}
27902790

2791-
MCSectionXCOFF *Csect = cast<MCSectionXCOFF>(
2791+
auto *Csect = static_cast<MCSectionXCOFF *>(
27922792
getObjFileLowering().SectionForGlobal(GV, GVKind, TM));
27932793

27942794
// Switch to the containing csect.
@@ -2869,9 +2869,9 @@ void PPCAIXAsmPrinter::emitFunctionDescriptor() {
28692869
OutStreamer->emitValue(MCSymbolRefExpr::create(CurrentFnSym, OutContext),
28702870
PointerSize);
28712871
// Emit TOC base address.
2872-
const MCSymbol *TOCBaseSym =
2873-
cast<MCSectionXCOFF>(getObjFileLowering().getTOCBaseSection())
2874-
->getQualNameSymbol();
2872+
const MCSymbol *TOCBaseSym = static_cast<const MCSectionXCOFF *>(
2873+
getObjFileLowering().getTOCBaseSection())
2874+
->getQualNameSymbol();
28752875
OutStreamer->emitValue(MCSymbolRefExpr::create(TOCBaseSym, OutContext),
28762876
PointerSize);
28772877
// Emit a null environment pointer.
@@ -2996,10 +2996,10 @@ void PPCAIXAsmPrinter::emitEndOfAsmFile(Module &M) {
29962996
Name += Prefix;
29972997
Name += cast<MCSymbolXCOFF>(I.first.first)->getSymbolTableName();
29982998
MCSymbol *S = OutContext.getOrCreateSymbol(Name);
2999-
TCEntry = cast<MCSectionXCOFF>(
2999+
TCEntry = static_cast<MCSectionXCOFF *>(
30003000
getObjFileLowering().getSectionForTOCEntry(S, TM));
30013001
} else {
3002-
TCEntry = cast<MCSectionXCOFF>(
3002+
TCEntry = static_cast<MCSectionXCOFF *>(
30033003
getObjFileLowering().getSectionForTOCEntry(I.first.first, TM));
30043004
}
30053005
OutStreamer->switchSection(TCEntry);
@@ -3054,7 +3054,7 @@ bool PPCAIXAsmPrinter::doInitialization(Module &M) {
30543054
return;
30553055

30563056
SectionKind GOKind = getObjFileLowering().getKindForGlobal(GO, TM);
3057-
MCSectionXCOFF *Csect = cast<MCSectionXCOFF>(
3057+
auto *Csect = static_cast<MCSectionXCOFF *>(
30583058
getObjFileLowering().SectionForGlobal(GO, GOKind, TM));
30593059

30603060
Align GOAlign = getGVAlignment(GO, GO->getDataLayout());
@@ -3316,9 +3316,9 @@ void PPCAIXAsmPrinter::emitTTypeReference(const GlobalValue *GV,
33163316
GlobalType = TOCType_GlobalExternal;
33173317
MCSymbol *TypeInfoSym = TM.getSymbol(GV);
33183318
MCSymbol *TOCEntry = lookUpOrCreateTOCEntry(TypeInfoSym, GlobalType);
3319-
const MCSymbol *TOCBaseSym =
3320-
cast<MCSectionXCOFF>(getObjFileLowering().getTOCBaseSection())
3321-
->getQualNameSymbol();
3319+
const MCSymbol *TOCBaseSym = static_cast<const MCSectionXCOFF *>(
3320+
getObjFileLowering().getTOCBaseSection())
3321+
->getQualNameSymbol();
33223322
auto &Ctx = OutStreamer->getContext();
33233323
const MCExpr *Exp =
33243324
MCBinaryExpr::createSub(MCSymbolRefExpr::create(TOCEntry, Ctx),

0 commit comments

Comments
 (0)