diff options
| author | Fangrui Song <i@maskray.me> | 2025-08-03 18:18:43 -0700 |
|---|---|---|
| committer | Fangrui Song <i@maskray.me> | 2025-08-03 18:18:44 -0700 |
| commit | d6c2e531518e84d154f1f1dccdf4967dbe26b500 (patch) | |
| tree | 0e95a9ac1da0e62187eb95451ad70e5268f56599 | |
| parent | 85f00707dd651d6c09c25aab882dc568a1f32f52 (diff) | |
| download | llvm-d6c2e531518e84d154f1f1dccdf4967dbe26b500.zip llvm-d6c2e531518e84d154f1f1dccdf4967dbe26b500.tar.gz llvm-d6c2e531518e84d154f1f1dccdf4967dbe26b500.tar.bz2 | |
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.
| -rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 16 | ||||
| -rw-r--r-- | llvm/lib/MC/MCAsmStreamer.cpp | 9 | ||||
| -rw-r--r-- | llvm/lib/MC/MCContext.cpp | 4 | ||||
| -rw-r--r-- | llvm/lib/MC/MCXCOFFStreamer.cpp | 9 | ||||
| -rw-r--r-- | llvm/lib/MC/XCOFFObjectWriter.cpp | 2 | ||||
| -rw-r--r-- | llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp | 11 | ||||
| -rw-r--r-- | llvm/lib/Target/PowerPC/PPCISelLowering.cpp | 4 |
7 files changed, 28 insertions, 27 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 8ca1bb1..d19ef92 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -2371,9 +2371,10 @@ bool TargetLoweringObjectFileXCOFF::ShouldSetSSPCanaryBitInTB( MCSymbol * TargetLoweringObjectFileXCOFF::getEHInfoTableSymbol(const MachineFunction *MF) { - MCSymbol *EHInfoSym = MF->getContext().getOrCreateSymbol( - "__ehinfo." + Twine(MF->getFunctionNumber())); - cast<MCSymbolXCOFF>(EHInfoSym)->setEHInfo(); + auto *EHInfoSym = + static_cast<MCSymbolXCOFF *>(MF->getContext().getOrCreateSymbol( + "__ehinfo." + Twine(MF->getFunctionNumber()))); + EHInfoSym->setEHInfo(); return EHInfoSym; } @@ -2511,7 +2512,8 @@ MCSection *TargetLoweringObjectFileXCOFF::SelectSectionForGlobal( if (Kind.isText()) { if (TM.getFunctionSections()) { - return cast<MCSymbolXCOFF>(getFunctionEntryPointSymbol(GO, TM)) + return static_cast<const MCSymbolXCOFF *>( + getFunctionEntryPointSymbol(GO, TM)) ->getRepresentedCsect(); } return TextSection; @@ -2714,7 +2716,7 @@ MCSection *TargetLoweringObjectFileXCOFF::getSectionForTOCEntry( const MCSymbol *Sym, const TargetMachine &TM) const { const XCOFF::StorageMappingClass SMC = [](const MCSymbol *Sym, const TargetMachine &TM) { - const MCSymbolXCOFF *XSym = cast<MCSymbolXCOFF>(Sym); + auto *XSym = static_cast<const MCSymbolXCOFF *>(Sym); // The "_$TLSML" symbol for TLS local-dynamic mode requires XMC_TC, // otherwise the AIX assembler will complain. @@ -2738,8 +2740,8 @@ MCSection *TargetLoweringObjectFileXCOFF::getSectionForTOCEntry( }(Sym, TM); return getContext().getXCOFFSection( - cast<MCSymbolXCOFF>(Sym)->getSymbolTableName(), SectionKind::getData(), - XCOFF::CsectProperties(SMC, XCOFF::XTY_SD)); + static_cast<const MCSymbolXCOFF *>(Sym)->getSymbolTableName(), + SectionKind::getData(), XCOFF::CsectProperties(SMC, XCOFF::XTY_SD)); } MCSection *TargetLoweringObjectFileXCOFF::getSectionForLSDA( diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp index da51da4..269c5c8 100644 --- a/llvm/lib/MC/MCAsmStreamer.cpp +++ b/llvm/lib/MC/MCAsmStreamer.cpp @@ -897,14 +897,14 @@ void MCAsmStreamer::emitXCOFFLocalCommonSymbol(MCSymbol *LabelSym, // Print symbol's rename (original name contains invalid character(s)) if // there is one. - MCSymbolXCOFF *XSym = cast<MCSymbolXCOFF>(CsectSym); + auto *XSym = static_cast<MCSymbolXCOFF *>(CsectSym); if (XSym->hasRename()) emitXCOFFRenameDirective(XSym, XSym->getSymbolTableName()); } void MCAsmStreamer::emitXCOFFSymbolLinkageWithVisibility( MCSymbol *Symbol, MCSymbolAttr Linkage, MCSymbolAttr Visibility) { - + auto &Sym = static_cast<MCSymbolXCOFF &>(*Symbol); switch (Linkage) { case MCSA_Global: OS << MAI->getGlobalDirective(); @@ -944,9 +944,8 @@ void MCAsmStreamer::emitXCOFFSymbolLinkageWithVisibility( // Print symbol's rename (original name contains invalid character(s)) if // there is one. - if (cast<MCSymbolXCOFF>(Symbol)->hasRename()) - emitXCOFFRenameDirective(Symbol, - cast<MCSymbolXCOFF>(Symbol)->getSymbolTableName()); + if (Sym.hasRename()) + emitXCOFFRenameDirective(&Sym, Sym.getSymbolTableName()); } void MCAsmStreamer::emitXCOFFRenameDirective(const MCSymbol *Name, diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp index 2e1a286..80d69c5 100644 --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -889,9 +889,9 @@ MCSectionXCOFF *MCContext::getXCOFFSection( MCSymbolXCOFF *QualName = nullptr; // Debug section don't have storage class attribute. if (IsDwarfSec) - QualName = cast<MCSymbolXCOFF>(getOrCreateSymbol(CachedName)); + QualName = static_cast<MCSymbolXCOFF *>(getOrCreateSymbol(CachedName)); else - QualName = cast<MCSymbolXCOFF>(getOrCreateSymbol( + QualName = static_cast<MCSymbolXCOFF *>(getOrCreateSymbol( CachedName + "[" + XCOFF::getMappingClassString(CsectProp->MappingClass) + "]")); diff --git a/llvm/lib/MC/MCXCOFFStreamer.cpp b/llvm/lib/MC/MCXCOFFStreamer.cpp index 26f45ce..ad40be2 100644 --- a/llvm/lib/MC/MCXCOFFStreamer.cpp +++ b/llvm/lib/MC/MCXCOFFStreamer.cpp @@ -52,7 +52,7 @@ void MCXCOFFStreamer::changeSection(MCSection *Section, uint32_t Subsection) { bool MCXCOFFStreamer::emitSymbolAttribute(MCSymbol *Sym, MCSymbolAttr Attribute) { - auto *Symbol = cast<MCSymbolXCOFF>(Sym); + auto *Symbol = static_cast<MCSymbolXCOFF *>(Sym); getAssembler().registerSymbol(*Symbol); switch (Attribute) { @@ -129,15 +129,14 @@ void MCXCOFFStreamer::emitXCOFFCInfoSym(StringRef Name, StringRef Metadata) { void MCXCOFFStreamer::emitCommonSymbol(MCSymbol *Symbol, uint64_t Size, Align ByteAlignment) { + auto *Sym = static_cast<MCSymbolXCOFF *>(Symbol); getAssembler().registerSymbol(*Symbol); - Symbol->setExternal(cast<MCSymbolXCOFF>(Symbol)->getStorageClass() != - XCOFF::C_HIDEXT); + Symbol->setExternal(Sym->getStorageClass() != XCOFF::C_HIDEXT); Symbol->setCommon(Size, ByteAlignment); // Default csect align is 4, but common symbols have explicit alignment values // and we should honor it. - cast<MCSymbolXCOFF>(Symbol)->getRepresentedCsect()->setAlignment( - ByteAlignment); + Sym->getRepresentedCsect()->setAlignment(ByteAlignment); // Emit the alignment and storage for the variable to the section. emitValueToAlignment(ByteAlignment); diff --git a/llvm/lib/MC/XCOFFObjectWriter.cpp b/llvm/lib/MC/XCOFFObjectWriter.cpp index 65f543b..284d609 100644 --- a/llvm/lib/MC/XCOFFObjectWriter.cpp +++ b/llvm/lib/MC/XCOFFObjectWriter.cpp @@ -591,7 +591,7 @@ void XCOFFWriter::executePostLayoutBinding() { if (S.isTemporary()) continue; - const MCSymbolXCOFF *XSym = cast<MCSymbolXCOFF>(&S); + auto *XSym = static_cast<const MCSymbolXCOFF *>(&S); const MCSectionXCOFF *ContainingCsect = getContainingCsect(XSym); if (ContainingCsect->isDwarfSect()) diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp index 7a51e74..718ebb5 100644 --- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp +++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -2767,7 +2767,7 @@ void PPCAIXAsmPrinter::emitGlobalVariableHelper(const GlobalVariable *GV) { if (GV->hasComdat()) report_fatal_error("COMDAT not yet supported by AIX."); - MCSymbolXCOFF *GVSym = cast<MCSymbolXCOFF>(getSymbol(GV)); + auto *GVSym = static_cast<MCSymbolXCOFF *>(getSymbol(GV)); if (GV->isDeclarationForLinker()) { emitLinkage(GV, GVSym); @@ -2860,7 +2860,7 @@ void PPCAIXAsmPrinter::emitFunctionDescriptor() { MCSectionSubPair Current = OutStreamer->getCurrentSection(); // Emit function descriptor. OutStreamer->switchSection( - cast<MCSymbolXCOFF>(CurrentFnDescSym)->getRepresentedCsect()); + static_cast<MCSymbolXCOFF *>(CurrentFnDescSym)->getRepresentedCsect()); // Emit aliasing label for function descriptor csect. for (const GlobalAlias *Alias : GOAliasMap[&MF->getFunction()]) @@ -2995,7 +2995,8 @@ void PPCAIXAsmPrinter::emitEndOfAsmFile(Module &M) { SmallString<128> Name; StringRef Prefix = "."; Name += Prefix; - Name += cast<MCSymbolXCOFF>(I.first.first)->getSymbolTableName(); + Name += static_cast<const MCSymbolXCOFF *>(I.first.first) + ->getSymbolTableName(); MCSymbol *S = OutContext.getOrCreateSymbol(Name); TCEntry = static_cast<MCSectionXCOFF *>( getObjFileLowering().getSectionForTOCEntry(S, TM)); @@ -3191,8 +3192,8 @@ void PPCAIXAsmPrinter::emitInstruction(const MachineInstr *MI) { case PPC::BL_NOP: { const MachineOperand &MO = MI->getOperand(0); if (MO.isSymbol()) { - MCSymbolXCOFF *S = - cast<MCSymbolXCOFF>(OutContext.getOrCreateSymbol(MO.getSymbolName())); + auto *S = static_cast<MCSymbolXCOFF *>( + OutContext.getOrCreateSymbol(MO.getSymbolName())); ExtSymSDNodeSymbols.insert(S); } } break; diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp index f179873..fc99cb8 100644 --- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp +++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp @@ -5540,8 +5540,8 @@ static SDValue transformCallee(const SDValue &Callee, SelectionDAG &DAG, const auto getAIXFuncEntryPointSymbolSDNode = [&](const GlobalValue *GV) { const TargetMachine &TM = Subtarget.getTargetMachine(); const TargetLoweringObjectFile *TLOF = TM.getObjFileLowering(); - MCSymbolXCOFF *S = - cast<MCSymbolXCOFF>(TLOF->getFunctionEntryPointSymbol(GV, TM)); + auto *S = + static_cast<MCSymbolXCOFF *>(TLOF->getFunctionEntryPointSymbol(GV, TM)); MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(DAG.getDataLayout()); return DAG.getMCSymbol(S, PtrVT); |
