Skip to content

Commit e640ca8

Browse files
committed
MCSymbolELF: 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 5570ce5 commit e640ca8

File tree

16 files changed

+44
-37
lines changed

16 files changed

+44
-37
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4702,7 +4702,7 @@ void AsmPrinter::emitXRayTable() {
47024702
const Triple &TT = TM.getTargetTriple();
47034703
// Use PC-relative addresses on all targets.
47044704
if (TT.isOSBinFormatELF()) {
4705-
auto LinkedToSym = cast<MCSymbolELF>(CurrentFnSym);
4705+
auto LinkedToSym = static_cast<const MCSymbolELF *>(CurrentFnSym);
47064706
auto Flags = ELF::SHF_ALLOC | ELF::SHF_LINK_ORDER;
47074707
StringRef GroupName;
47084708
if (F.hasComdat()) {
@@ -4825,7 +4825,7 @@ void AsmPrinter::emitPatchableFunctionEntries() {
48254825
Flags |= ELF::SHF_GROUP;
48264826
GroupName = F.getComdat()->getName();
48274827
}
4828-
LinkedToSym = cast<MCSymbolELF>(CurrentFnSym);
4828+
LinkedToSym = static_cast<const MCSymbolELF *>(CurrentFnSym);
48294829
}
48304830
OutStreamer->switchSection(OutContext.getELFSection(
48314831
SectionName, ELF::SHT_PROGBITS, Flags, 0, GroupName, F.hasComdat(),

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@ void TargetLoweringObjectFileELF::emitPersonalityValue(
402402
const MachineModuleInfo *MMI) const {
403403
SmallString<64> NameData("DW.ref.");
404404
NameData += Sym->getName();
405-
MCSymbolELF *Label =
406-
cast<MCSymbolELF>(getContext().getOrCreateSymbol(NameData));
405+
auto *Label =
406+
static_cast<MCSymbolELF *>(getContext().getOrCreateSymbol(NameData));
407407
Streamer.emitSymbolAttribute(Label, MCSA_Hidden);
408408
Streamer.emitSymbolAttribute(Label, MCSA_Weak);
409409
unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE | ELF::SHF_GROUP;

llvm/lib/MC/MCELFStreamer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void MCELFStreamer::initSections(bool NoExecStack, const MCSubtargetInfo &STI) {
5959
}
6060

6161
void MCELFStreamer::emitLabel(MCSymbol *S, SMLoc Loc) {
62-
auto *Symbol = cast<MCSymbolELF>(S);
62+
auto *Symbol = static_cast<MCSymbolELF *>(S);
6363
MCObjectStreamer::emitLabel(Symbol, Loc);
6464

6565
const MCSectionELF &Section =
@@ -70,7 +70,7 @@ void MCELFStreamer::emitLabel(MCSymbol *S, SMLoc Loc) {
7070

7171
void MCELFStreamer::emitLabelAtPos(MCSymbol *S, SMLoc Loc, MCFragment &F,
7272
uint64_t Offset) {
73-
auto *Symbol = cast<MCSymbolELF>(S);
73+
auto *Symbol = static_cast<MCSymbolELF *>(S);
7474
MCObjectStreamer::emitLabelAtPos(Symbol, Loc, F, Offset);
7575

7676
const MCSectionELF &Section =
@@ -95,7 +95,7 @@ void MCELFStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
9595
}
9696

9797
void MCELFStreamer::emitWeakReference(MCSymbol *Alias, const MCSymbol *Target) {
98-
auto *A = cast<MCSymbolELF>(Alias);
98+
auto *A = static_cast<MCSymbolELF *>(Alias);
9999
if (A->isDefined()) {
100100
getContext().reportError(getStartTokLoc(), "symbol '" + A->getName() +
101101
"' is already defined");
@@ -126,7 +126,7 @@ static unsigned CombineSymbolTypes(unsigned T1, unsigned T2) {
126126
}
127127

128128
bool MCELFStreamer::emitSymbolAttribute(MCSymbol *S, MCSymbolAttr Attribute) {
129-
auto *Symbol = cast<MCSymbolELF>(S);
129+
auto *Symbol = static_cast<MCSymbolELF *>(S);
130130

131131
// Adding a symbol attribute always introduces the symbol, note that an
132132
// important side effect of calling registerSymbol here is to register
@@ -247,7 +247,7 @@ bool MCELFStreamer::emitSymbolAttribute(MCSymbol *S, MCSymbolAttr Attribute) {
247247

248248
void MCELFStreamer::emitCommonSymbol(MCSymbol *S, uint64_t Size,
249249
Align ByteAlignment) {
250-
auto *Symbol = cast<MCSymbolELF>(S);
250+
auto *Symbol = static_cast<MCSymbolELF *>(S);
251251
getAssembler().registerSymbol(*Symbol);
252252

253253
if (!Symbol->isBindingSet())
@@ -289,7 +289,7 @@ void MCELFStreamer::emitELFSymverDirective(const MCSymbol *OriginalSym,
289289

290290
void MCELFStreamer::emitLocalCommonSymbol(MCSymbol *S, uint64_t Size,
291291
Align ByteAlignment) {
292-
auto *Symbol = cast<MCSymbolELF>(S);
292+
auto *Symbol = static_cast<MCSymbolELF *>(S);
293293
// FIXME: Should this be caught and done earlier?
294294
getAssembler().registerSymbol(*Symbol);
295295
Symbol->setBinding(ELF::STB_LOCAL);

llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,8 @@ class AArch64ELFStreamer : public MCELFStreamer {
418418
}
419419

420420
MCSymbol *emitMappingSymbol(StringRef Name) {
421-
auto *Symbol = cast<MCSymbolELF>(getContext().createLocalSymbol(Name));
421+
auto *Symbol =
422+
static_cast<MCSymbolELF *>(getContext().createLocalSymbol(Name));
422423
emitLabel(Symbol);
423424
return Symbol;
424425
}
@@ -541,7 +542,7 @@ void AArch64TargetELFStreamer::finish() {
541542

542543
MCSectionELF *MemtagSec = nullptr;
543544
for (const MCSymbol &Symbol : Asm.symbols()) {
544-
const auto &Sym = cast<MCSymbolELF>(Symbol);
545+
auto &Sym = static_cast<const MCSymbolELF &>(Symbol);
545546
if (Sym.isMemtag()) {
546547
MemtagSec = Ctx.getELFSection(".memtag.globals.static",
547548
ELF::SHT_AARCH64_MEMTAG_GLOBALS_STATIC, 0);
@@ -556,7 +557,7 @@ void AArch64TargetELFStreamer::finish() {
556557
S.switchSection(MemtagSec);
557558
const auto *Zero = MCConstantExpr::create(0, Ctx);
558559
for (const MCSymbol &Symbol : Asm.symbols()) {
559-
const auto &Sym = cast<MCSymbolELF>(Symbol);
560+
auto &Sym = static_cast<const MCSymbolELF &>(Symbol);
560561
if (!Sym.isMemtag())
561562
continue;
562563
auto *SRE = MCSymbolRefExpr::create(&Sym, Ctx);

llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -872,14 +872,14 @@ void AMDGPUTargetELFStreamer::EmitAMDKernelCodeT(AMDGPUMCKernelCodeT &Header) {
872872

873873
void AMDGPUTargetELFStreamer::EmitAMDGPUSymbolType(StringRef SymbolName,
874874
unsigned Type) {
875-
MCSymbolELF *Symbol = cast<MCSymbolELF>(
875+
auto *Symbol = static_cast<MCSymbolELF *>(
876876
getStreamer().getContext().getOrCreateSymbol(SymbolName));
877877
Symbol->setType(Type);
878878
}
879879

880880
void AMDGPUTargetELFStreamer::emitAMDGPULDS(MCSymbol *Symbol, unsigned Size,
881881
Align Alignment) {
882-
MCSymbolELF *SymbolELF = cast<MCSymbolELF>(Symbol);
882+
auto *SymbolELF = static_cast<MCSymbolELF *>(Symbol);
883883
SymbolELF->setType(ELF::STT_OBJECT);
884884

885885
if (!SymbolELF->isBindingSet())
@@ -974,9 +974,9 @@ void AMDGPUTargetELFStreamer::EmitAmdhsaKernelDescriptor(
974974
auto &Streamer = getStreamer();
975975
auto &Context = Streamer.getContext();
976976

977-
MCSymbolELF *KernelCodeSymbol = cast<MCSymbolELF>(
978-
Context.getOrCreateSymbol(Twine(KernelName)));
979-
MCSymbolELF *KernelDescriptorSymbol = cast<MCSymbolELF>(
977+
auto *KernelCodeSymbol =
978+
static_cast<MCSymbolELF *>(Context.getOrCreateSymbol(Twine(KernelName)));
979+
auto *KernelDescriptorSymbol = static_cast<MCSymbolELF *>(
980980
Context.getOrCreateSymbol(Twine(KernelName) + Twine(".kd")));
981981

982982
// Copy kernel descriptor symbol's binding, other and visibility from the

llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ static bool needsInterworking(const MCAssembler &Asm, const MCSymbol *Sym,
298298
// different execution mode in ELF binaries.
299299
if (!Sym || !Asm.getContext().isELF())
300300
return false;
301-
unsigned Type = cast<MCSymbolELF>(Sym)->getType();
301+
unsigned Type = static_cast<const MCSymbolELF *>(Sym)->getType();
302302
if ((Type == ELF::STT_FUNC || Type == ELF::STT_GNU_IFUNC)) {
303303
if (Asm.isThumbFunc(Sym) && (FixupKind == ARM::fixup_arm_uncondbranch))
304304
return true;

llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ class ARMELFStreamer : public MCELFStreamer {
614614
if (!IsThumb)
615615
return Val;
616616

617-
unsigned Type = cast<MCSymbolELF>(Symbol)->getType();
617+
unsigned Type = static_cast<MCSymbolELF *>(Symbol)->getType();
618618
if ((Type == ELF::STT_FUNC || Type == ELF::STT_GNU_IFUNC) &&
619619
Symbol->isDefined())
620620
getAssembler().setIsThumbFunc(Symbol);
@@ -679,15 +679,17 @@ class ARMELFStreamer : public MCELFStreamer {
679679
}
680680

681681
void EmitMappingSymbol(StringRef Name) {
682-
auto *Symbol = cast<MCSymbolELF>(getContext().createLocalSymbol(Name));
682+
auto *Symbol =
683+
static_cast<MCSymbolELF *>(getContext().createLocalSymbol(Name));
683684
emitLabel(Symbol);
684685

685686
Symbol->setType(ELF::STT_NOTYPE);
686687
Symbol->setBinding(ELF::STB_LOCAL);
687688
}
688689

689690
void emitMappingSymbol(StringRef Name, MCFragment &F, uint64_t Offset) {
690-
auto *Symbol = cast<MCSymbolELF>(getContext().createLocalSymbol(Name));
691+
auto *Symbol =
692+
static_cast<MCSymbolELF *>(getContext().createLocalSymbol(Name));
691693
emitLabelAtPos(Symbol, SMLoc(), F, Offset);
692694
Symbol->setType(ELF::STT_NOTYPE);
693695
Symbol->setBinding(ELF::STB_LOCAL);
@@ -1088,7 +1090,7 @@ void ARMTargetELFStreamer::emitLabel(MCSymbol *Symbol) {
10881090
return;
10891091

10901092
Streamer.getAssembler().registerSymbol(*Symbol);
1091-
unsigned Type = cast<MCSymbolELF>(Symbol)->getType();
1093+
unsigned Type = static_cast<MCSymbolELF *>(Symbol)->getType();
10921094
if (Type == ELF::STT_FUNC || Type == ELF::STT_GNU_IFUNC)
10931095
emitThumbFunc(Symbol);
10941096
}

llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFStreamer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ void CSKYELFStreamer::EmitMappingSymbol(StringRef Name) {
169169

170170
State = (Name == "$t" ? EMS_Text : EMS_Data);
171171

172-
auto *Symbol = cast<MCSymbolELF>(getContext().createLocalSymbol(Name));
172+
auto *Symbol =
173+
static_cast<MCSymbolELF *>(getContext().createLocalSymbol(Name));
173174
emitLabel(Symbol);
174175

175176
Symbol->setType(ELF::STT_NOTYPE);

llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void MipsELFStreamer::createPendingLabelRelocs() {
7676
// FIXME: Also mark labels when in MIPS16 mode.
7777
if (ELFTargetStreamer->isMicroMipsEnabled()) {
7878
for (auto *L : Labels) {
79-
auto *Label = cast<MCSymbolELF>(L);
79+
auto *Label = static_cast<MCSymbolELF *>(L);
8080
getAssembler().registerSymbol(*Label);
8181
Label->setOther(ELF::STO_MIPS_MICROMIPS);
8282
}

llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ MipsTargetELFStreamer::MipsTargetELFStreamer(MCStreamer &S,
931931
}
932932

933933
void MipsTargetELFStreamer::emitLabel(MCSymbol *S) {
934-
auto *Symbol = cast<MCSymbolELF>(S);
934+
auto *Symbol = static_cast<MCSymbolELF *>(S);
935935
getStreamer().getAssembler().registerSymbol(*Symbol);
936936
uint8_t Type = Symbol->getType();
937937
if (Type != ELF::STT_FUNC)
@@ -1015,11 +1015,11 @@ void MipsTargetELFStreamer::finish() {
10151015
}
10161016

10171017
void MipsTargetELFStreamer::emitAssignment(MCSymbol *S, const MCExpr *Value) {
1018-
auto *Symbol = cast<MCSymbolELF>(S);
1018+
auto *Symbol = static_cast<MCSymbolELF *>(S);
10191019
// If on rhs is micromips symbol then mark Symbol as microMips.
10201020
if (Value->getKind() != MCExpr::SymbolRef)
10211021
return;
1022-
const auto &RhsSym = cast<MCSymbolELF>(
1022+
auto &RhsSym = static_cast<const MCSymbolELF &>(
10231023
static_cast<const MCSymbolRefExpr *>(Value)->getSymbol());
10241024

10251025
if (!(RhsSym.getOther() & ELF::STO_MIPS_MICROMIPS))

0 commit comments

Comments
 (0)