Skip to content

Commit d6c2e53

Browse files
committed
MCSymbolXCOFF: Migrate away from classof
The object file format specific derived classes are used in context where the type is statically known. We don't use isa/dyn_cast and we want to eliminate MCSymbol::Kind in the base class.
1 parent 85f0070 commit d6c2e53

File tree

7 files changed

+28
-27
lines changed

7 files changed

+28
-27
lines changed

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,9 +2371,10 @@ bool TargetLoweringObjectFileXCOFF::ShouldSetSSPCanaryBitInTB(
23712371

23722372
MCSymbol *
23732373
TargetLoweringObjectFileXCOFF::getEHInfoTableSymbol(const MachineFunction *MF) {
2374-
MCSymbol *EHInfoSym = MF->getContext().getOrCreateSymbol(
2375-
"__ehinfo." + Twine(MF->getFunctionNumber()));
2376-
cast<MCSymbolXCOFF>(EHInfoSym)->setEHInfo();
2374+
auto *EHInfoSym =
2375+
static_cast<MCSymbolXCOFF *>(MF->getContext().getOrCreateSymbol(
2376+
"__ehinfo." + Twine(MF->getFunctionNumber())));
2377+
EHInfoSym->setEHInfo();
23772378
return EHInfoSym;
23782379
}
23792380

@@ -2511,7 +2512,8 @@ MCSection *TargetLoweringObjectFileXCOFF::SelectSectionForGlobal(
25112512

25122513
if (Kind.isText()) {
25132514
if (TM.getFunctionSections()) {
2514-
return cast<MCSymbolXCOFF>(getFunctionEntryPointSymbol(GO, TM))
2515+
return static_cast<const MCSymbolXCOFF *>(
2516+
getFunctionEntryPointSymbol(GO, TM))
25152517
->getRepresentedCsect();
25162518
}
25172519
return TextSection;
@@ -2714,7 +2716,7 @@ MCSection *TargetLoweringObjectFileXCOFF::getSectionForTOCEntry(
27142716
const MCSymbol *Sym, const TargetMachine &TM) const {
27152717
const XCOFF::StorageMappingClass SMC = [](const MCSymbol *Sym,
27162718
const TargetMachine &TM) {
2717-
const MCSymbolXCOFF *XSym = cast<MCSymbolXCOFF>(Sym);
2719+
auto *XSym = static_cast<const MCSymbolXCOFF *>(Sym);
27182720

27192721
// The "_$TLSML" symbol for TLS local-dynamic mode requires XMC_TC,
27202722
// otherwise the AIX assembler will complain.
@@ -2738,8 +2740,8 @@ MCSection *TargetLoweringObjectFileXCOFF::getSectionForTOCEntry(
27382740
}(Sym, TM);
27392741

27402742
return getContext().getXCOFFSection(
2741-
cast<MCSymbolXCOFF>(Sym)->getSymbolTableName(), SectionKind::getData(),
2742-
XCOFF::CsectProperties(SMC, XCOFF::XTY_SD));
2743+
static_cast<const MCSymbolXCOFF *>(Sym)->getSymbolTableName(),
2744+
SectionKind::getData(), XCOFF::CsectProperties(SMC, XCOFF::XTY_SD));
27432745
}
27442746

27452747
MCSection *TargetLoweringObjectFileXCOFF::getSectionForLSDA(

llvm/lib/MC/MCAsmStreamer.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -897,14 +897,14 @@ void MCAsmStreamer::emitXCOFFLocalCommonSymbol(MCSymbol *LabelSym,
897897

898898
// Print symbol's rename (original name contains invalid character(s)) if
899899
// there is one.
900-
MCSymbolXCOFF *XSym = cast<MCSymbolXCOFF>(CsectSym);
900+
auto *XSym = static_cast<MCSymbolXCOFF *>(CsectSym);
901901
if (XSym->hasRename())
902902
emitXCOFFRenameDirective(XSym, XSym->getSymbolTableName());
903903
}
904904

905905
void MCAsmStreamer::emitXCOFFSymbolLinkageWithVisibility(
906906
MCSymbol *Symbol, MCSymbolAttr Linkage, MCSymbolAttr Visibility) {
907-
907+
auto &Sym = static_cast<MCSymbolXCOFF &>(*Symbol);
908908
switch (Linkage) {
909909
case MCSA_Global:
910910
OS << MAI->getGlobalDirective();
@@ -944,9 +944,8 @@ void MCAsmStreamer::emitXCOFFSymbolLinkageWithVisibility(
944944

945945
// Print symbol's rename (original name contains invalid character(s)) if
946946
// there is one.
947-
if (cast<MCSymbolXCOFF>(Symbol)->hasRename())
948-
emitXCOFFRenameDirective(Symbol,
949-
cast<MCSymbolXCOFF>(Symbol)->getSymbolTableName());
947+
if (Sym.hasRename())
948+
emitXCOFFRenameDirective(&Sym, Sym.getSymbolTableName());
950949
}
951950

952951
void MCAsmStreamer::emitXCOFFRenameDirective(const MCSymbol *Name,

llvm/lib/MC/MCContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -889,9 +889,9 @@ MCSectionXCOFF *MCContext::getXCOFFSection(
889889
MCSymbolXCOFF *QualName = nullptr;
890890
// Debug section don't have storage class attribute.
891891
if (IsDwarfSec)
892-
QualName = cast<MCSymbolXCOFF>(getOrCreateSymbol(CachedName));
892+
QualName = static_cast<MCSymbolXCOFF *>(getOrCreateSymbol(CachedName));
893893
else
894-
QualName = cast<MCSymbolXCOFF>(getOrCreateSymbol(
894+
QualName = static_cast<MCSymbolXCOFF *>(getOrCreateSymbol(
895895
CachedName + "[" +
896896
XCOFF::getMappingClassString(CsectProp->MappingClass) + "]"));
897897

llvm/lib/MC/MCXCOFFStreamer.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void MCXCOFFStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
5252

5353
bool MCXCOFFStreamer::emitSymbolAttribute(MCSymbol *Sym,
5454
MCSymbolAttr Attribute) {
55-
auto *Symbol = cast<MCSymbolXCOFF>(Sym);
55+
auto *Symbol = static_cast<MCSymbolXCOFF *>(Sym);
5656
getAssembler().registerSymbol(*Symbol);
5757

5858
switch (Attribute) {
@@ -129,15 +129,14 @@ void MCXCOFFStreamer::emitXCOFFCInfoSym(StringRef Name, StringRef Metadata) {
129129

130130
void MCXCOFFStreamer::emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
131131
Align ByteAlignment) {
132+
auto *Sym = static_cast<MCSymbolXCOFF *>(Symbol);
132133
getAssembler().registerSymbol(*Symbol);
133-
Symbol->setExternal(cast<MCSymbolXCOFF>(Symbol)->getStorageClass() !=
134-
XCOFF::C_HIDEXT);
134+
Symbol->setExternal(Sym->getStorageClass() != XCOFF::C_HIDEXT);
135135
Symbol->setCommon(Size, ByteAlignment);
136136

137137
// Default csect align is 4, but common symbols have explicit alignment values
138138
// and we should honor it.
139-
cast<MCSymbolXCOFF>(Symbol)->getRepresentedCsect()->setAlignment(
140-
ByteAlignment);
139+
Sym->getRepresentedCsect()->setAlignment(ByteAlignment);
141140

142141
// Emit the alignment and storage for the variable to the section.
143142
emitValueToAlignment(ByteAlignment);

llvm/lib/MC/XCOFFObjectWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ void XCOFFWriter::executePostLayoutBinding() {
591591
if (S.isTemporary())
592592
continue;
593593

594-
const MCSymbolXCOFF *XSym = cast<MCSymbolXCOFF>(&S);
594+
auto *XSym = static_cast<const MCSymbolXCOFF *>(&S);
595595
const MCSectionXCOFF *ContainingCsect = getContainingCsect(XSym);
596596

597597
if (ContainingCsect->isDwarfSect())

llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2767,7 +2767,7 @@ void PPCAIXAsmPrinter::emitGlobalVariableHelper(const GlobalVariable *GV) {
27672767
if (GV->hasComdat())
27682768
report_fatal_error("COMDAT not yet supported by AIX.");
27692769

2770-
MCSymbolXCOFF *GVSym = cast<MCSymbolXCOFF>(getSymbol(GV));
2770+
auto *GVSym = static_cast<MCSymbolXCOFF *>(getSymbol(GV));
27712771

27722772
if (GV->isDeclarationForLinker()) {
27732773
emitLinkage(GV, GVSym);
@@ -2860,7 +2860,7 @@ void PPCAIXAsmPrinter::emitFunctionDescriptor() {
28602860
MCSectionSubPair Current = OutStreamer->getCurrentSection();
28612861
// Emit function descriptor.
28622862
OutStreamer->switchSection(
2863-
cast<MCSymbolXCOFF>(CurrentFnDescSym)->getRepresentedCsect());
2863+
static_cast<MCSymbolXCOFF *>(CurrentFnDescSym)->getRepresentedCsect());
28642864

28652865
// Emit aliasing label for function descriptor csect.
28662866
for (const GlobalAlias *Alias : GOAliasMap[&MF->getFunction()])
@@ -2995,7 +2995,8 @@ void PPCAIXAsmPrinter::emitEndOfAsmFile(Module &M) {
29952995
SmallString<128> Name;
29962996
StringRef Prefix = ".";
29972997
Name += Prefix;
2998-
Name += cast<MCSymbolXCOFF>(I.first.first)->getSymbolTableName();
2998+
Name += static_cast<const MCSymbolXCOFF *>(I.first.first)
2999+
->getSymbolTableName();
29993000
MCSymbol *S = OutContext.getOrCreateSymbol(Name);
30003001
TCEntry = static_cast<MCSectionXCOFF *>(
30013002
getObjFileLowering().getSectionForTOCEntry(S, TM));
@@ -3191,8 +3192,8 @@ void PPCAIXAsmPrinter::emitInstruction(const MachineInstr *MI) {
31913192
case PPC::BL_NOP: {
31923193
const MachineOperand &MO = MI->getOperand(0);
31933194
if (MO.isSymbol()) {
3194-
MCSymbolXCOFF *S =
3195-
cast<MCSymbolXCOFF>(OutContext.getOrCreateSymbol(MO.getSymbolName()));
3195+
auto *S = static_cast<MCSymbolXCOFF *>(
3196+
OutContext.getOrCreateSymbol(MO.getSymbolName()));
31963197
ExtSymSDNodeSymbols.insert(S);
31973198
}
31983199
} break;

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5540,8 +5540,8 @@ static SDValue transformCallee(const SDValue &Callee, SelectionDAG &DAG,
55405540
const auto getAIXFuncEntryPointSymbolSDNode = [&](const GlobalValue *GV) {
55415541
const TargetMachine &TM = Subtarget.getTargetMachine();
55425542
const TargetLoweringObjectFile *TLOF = TM.getObjFileLowering();
5543-
MCSymbolXCOFF *S =
5544-
cast<MCSymbolXCOFF>(TLOF->getFunctionEntryPointSymbol(GV, TM));
5543+
auto *S =
5544+
static_cast<MCSymbolXCOFF *>(TLOF->getFunctionEntryPointSymbol(GV, TM));
55455545

55465546
MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(DAG.getDataLayout());
55475547
return DAG.getMCSymbol(S, PtrVT);

0 commit comments

Comments
 (0)