aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Bitcode/Writer/BitcodeWriter.cpp2
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp6
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp3
-rw-r--r--llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp25
-rw-r--r--llvm/lib/IR/AsmWriter.cpp2
-rw-r--r--llvm/lib/IR/RuntimeLibcalls.cpp55
-rw-r--r--llvm/lib/MC/ELFObjectWriter.cpp32
-rw-r--r--llvm/lib/MC/GOFFObjectWriter.cpp2
-rw-r--r--llvm/lib/MC/MCAsmBackend.cpp5
-rw-r--r--llvm/lib/MC/MCAsmStreamer.cpp17
-rw-r--r--llvm/lib/MC/MCCodeView.cpp9
-rw-r--r--llvm/lib/MC/MCContext.cpp32
-rw-r--r--llvm/lib/MC/MCELFStreamer.cpp18
-rw-r--r--llvm/lib/MC/MCMachOStreamer.cpp14
-rw-r--r--llvm/lib/MC/MCObjectFileInfo.cpp42
-rw-r--r--llvm/lib/MC/MCObjectStreamer.cpp14
-rw-r--r--llvm/lib/MC/MCParser/AsmParser.cpp5
-rw-r--r--llvm/lib/MC/MCParser/COFFMasmParser.cpp3
-rw-r--r--llvm/lib/MC/MCParser/ELFAsmParser.cpp4
-rw-r--r--llvm/lib/MC/MCParser/WasmAsmParser.cpp8
-rw-r--r--llvm/lib/MC/MCWasmStreamer.cpp9
-rw-r--r--llvm/lib/MC/MCWinCOFFStreamer.cpp25
-rw-r--r--llvm/lib/MC/MCXCOFFStreamer.cpp11
-rw-r--r--llvm/lib/MC/MachObjectWriter.cpp25
-rw-r--r--llvm/lib/MC/WasmObjectWriter.cpp33
-rw-r--r--llvm/lib/MC/WinCOFFObjectWriter.cpp13
-rw-r--r--llvm/lib/MC/XCOFFObjectWriter.cpp9
-rw-r--r--llvm/lib/Support/BalancedPartitioning.cpp2
-rw-r--r--llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp7
-rw-r--r--llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp9
-rw-r--r--llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp2
-rw-r--r--llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp10
-rw-r--r--llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp4
-rw-r--r--llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp4
-rw-r--r--llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp10
-rw-r--r--llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp2
-rw-r--r--llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFObjectWriter.cpp4
-rw-r--r--llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFStreamer.cpp3
-rw-r--r--llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp2
-rw-r--r--llvm/lib/Target/Hexagon/MCTargetDesc/HexagonELFObjectWriter.cpp4
-rw-r--r--llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.cpp4
-rw-r--r--llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp4
-rw-r--r--llvm/lib/Target/M68k/MCTargetDesc/M68kELFObjectWriter.cpp4
-rw-r--r--llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp7
-rw-r--r--llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp9
-rw-r--r--llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp2
-rw-r--r--llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp6
-rw-r--r--llvm/lib/Target/Mips/MipsAsmPrinter.cpp3
-rw-r--r--llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp2
-rw-r--r--llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp8
-rw-r--r--llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp7
-rw-r--r--llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp2
-rw-r--r--llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp10
-rw-r--r--llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp20
-rw-r--r--llvm/lib/Target/PowerPC/PPCISelLowering.cpp4
-rw-r--r--llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp2
-rw-r--r--llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp4
-rw-r--r--llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp5
-rw-r--r--llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp19
-rw-r--r--llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp5
-rw-r--r--llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp4
-rw-r--r--llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp4
-rw-r--r--llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp4
-rw-r--r--llvm/lib/Target/VE/MCTargetDesc/VEELFObjectWriter.cpp4
-rw-r--r--llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp29
-rw-r--r--llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp6
-rw-r--r--llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp2
-rw-r--r--llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp6
-rw-r--r--llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp2
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp21
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp14
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyUtilities.cpp8
-rw-r--r--llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp5
-rw-r--r--llvm/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp4
-rw-r--r--llvm/lib/Transforms/Scalar/GVNSink.cpp2
-rw-r--r--llvm/lib/Transforms/Utils/ProfileVerify.cpp30
76 files changed, 393 insertions, 365 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 7e0d81f..05680fa 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -610,7 +610,7 @@ public:
std::vector<StringRef> ModulePaths;
for (auto &[ModPath, _] : Index.modulePaths())
ModulePaths.push_back(ModPath);
- llvm::sort(ModulePaths.begin(), ModulePaths.end());
+ llvm::sort(ModulePaths);
for (auto &ModPath : ModulePaths)
Callback(*Index.modulePaths().find(ModPath));
}
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 1641c3e..c72b6e8 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -3194,7 +3194,7 @@ void AsmPrinter::emitJumpTableSizesSection(const MachineJumpTableInfo &MJTI,
return;
if (isElf) {
- MCSymbolELF *LinkedToSym = dyn_cast<MCSymbolELF>(CurrentFnSym);
+ auto *LinkedToSym = static_cast<MCSymbolELF *>(CurrentFnSym);
int Flags = F.hasComdat() ? static_cast<int>(ELF::SHF_GROUP) : 0;
JumpTableSizesSection = OutContext.getELFSection(
@@ -4702,7 +4702,7 @@ void AsmPrinter::emitXRayTable() {
const Triple &TT = TM.getTargetTriple();
// Use PC-relative addresses on all targets.
if (TT.isOSBinFormatELF()) {
- auto LinkedToSym = cast<MCSymbolELF>(CurrentFnSym);
+ auto LinkedToSym = static_cast<const MCSymbolELF *>(CurrentFnSym);
auto Flags = ELF::SHF_ALLOC | ELF::SHF_LINK_ORDER;
StringRef GroupName;
if (F.hasComdat()) {
@@ -4825,7 +4825,7 @@ void AsmPrinter::emitPatchableFunctionEntries() {
Flags |= ELF::SHF_GROUP;
GroupName = F.getComdat()->getName();
}
- LinkedToSym = cast<MCSymbolELF>(CurrentFnSym);
+ LinkedToSym = static_cast<const MCSymbolELF *>(CurrentFnSym);
}
OutStreamer->switchSection(OutContext.getELFSection(
SectionName, ELF::SHT_PROGBITS, Flags, 0, GroupName, F.hasComdat(),
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
index 5577a7d..f9d7e76 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -508,7 +508,8 @@ void DwarfCompileUnit::addWasmRelocBaseGlobal(DIELoc *Loc, StringRef GlobalName,
// don't want to depend on target specific headers in this code?
const unsigned TI_GLOBAL_RELOC = 3;
unsigned PointerSize = Asm->getDataLayout().getPointerSize();
- auto *Sym = cast<MCSymbolWasm>(Asm->GetExternalSymbolSymbol(GlobalName));
+ auto *Sym =
+ static_cast<MCSymbolWasm *>(Asm->GetExternalSymbolSymbol(GlobalName));
// FIXME: this repeats what WebAssemblyMCInstLower::
// GetExternalSymbolSymbol does, since if there's no code that
// refers to this symbol, we have to set it here.
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index e9172f4..d19ef92 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -402,8 +402,8 @@ void TargetLoweringObjectFileELF::emitPersonalityValue(
const MachineModuleInfo *MMI) const {
SmallString<64> NameData("DW.ref.");
NameData += Sym->getName();
- MCSymbolELF *Label =
- cast<MCSymbolELF>(getContext().getOrCreateSymbol(NameData));
+ auto *Label =
+ static_cast<MCSymbolELF *>(getContext().getOrCreateSymbol(NameData));
Streamer.emitSymbolAttribute(Label, MCSA_Hidden);
Streamer.emitSymbolAttribute(Label, MCSA_Weak);
unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE | ELF::SHF_GROUP;
@@ -581,7 +581,8 @@ static const MCSymbolELF *getLinkedToSymbol(const GlobalObject *GO,
auto *VM = cast<ValueAsMetadata>(MD->getOperand(0).get());
auto *OtherGV = dyn_cast<GlobalValue>(VM->getValue());
- return OtherGV ? dyn_cast<MCSymbolELF>(TM.getSymbol(OtherGV)) : nullptr;
+ return OtherGV ? static_cast<const MCSymbolELF *>(TM.getSymbol(OtherGV))
+ : nullptr;
}
static unsigned getEntrySizeForKind(SectionKind Kind) {
@@ -1011,7 +1012,7 @@ MCSection *TargetLoweringObjectFileELF::getSectionForLSDA(
(getContext().getAsmInfo()->useIntegratedAssembler() &&
getContext().getAsmInfo()->binutilsIsAtLeast(2, 36))) {
Flags |= ELF::SHF_LINK_ORDER;
- LinkedToSym = cast<MCSymbolELF>(&FnSym);
+ LinkedToSym = static_cast<const MCSymbolELF *>(&FnSym);
}
// Append the function name as the suffix like GCC, assuming
@@ -2370,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;
}
@@ -2510,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;
@@ -2713,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.
@@ -2737,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/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index e5a4e1e..dc6d599 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -1163,7 +1163,7 @@ int SlotTracker::processIndex() {
std::vector<StringRef> ModulePaths;
for (auto &[ModPath, _] : TheIndex->modulePaths())
ModulePaths.push_back(ModPath);
- llvm::sort(ModulePaths.begin(), ModulePaths.end());
+ llvm::sort(ModulePaths);
for (auto &ModPath : ModulePaths)
CreateModulePathSlot(ModPath);
diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp
index 1ca5878..bfe2a3d 100644
--- a/llvm/lib/IR/RuntimeLibcalls.cpp
+++ b/llvm/lib/IR/RuntimeLibcalls.cpp
@@ -8,6 +8,9 @@
#include "llvm/IR/RuntimeLibcalls.h"
#include "llvm/ADT/StringTable.h"
+#include "llvm/Support/Debug.h"
+
+#define DEBUG_TYPE "runtime-libcalls-info"
using namespace llvm;
using namespace RTLIB;
@@ -62,12 +65,6 @@ static void setARMLibcallNames(RuntimeLibcallsInfo &Info, const Triple &TT,
Info.setLibcallImplCallingConv(Impl, CallingConv::ARM_AAPCS);
}
-void RTLIB::RuntimeLibcallsInfo::initDefaultLibCallImpls() {
- std::memcpy(LibcallImpls, DefaultLibcallImpls, sizeof(LibcallImpls));
- static_assert(sizeof(LibcallImpls) == sizeof(DefaultLibcallImpls),
- "libcall array size should match");
-}
-
/// Set default libcall names. If a target wants to opt-out of a libcall it
/// should be placed here.
void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
@@ -76,63 +73,19 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
EABI EABIVersion, StringRef ABIName) {
setTargetRuntimeLibcallSets(TT, FloatABI);
- // Early exit for targets that have fully ported to tablegen.
- if (TT.isAMDGPU() || TT.isNVPTX() || TT.isWasm())
- return;
-
if (TT.isX86() || TT.isVE() || TT.isARM() || TT.isThumb()) {
if (ExceptionModel == ExceptionHandling::SjLj)
setLibcallImpl(RTLIB::UNWIND_RESUME, RTLIB::_Unwind_SjLj_Resume);
}
- // A few names are different on particular architectures or environments.
- if (TT.isOSDarwin()) {
- // For f16/f32 conversions, Darwin uses the standard naming scheme,
- // instead of the gnueabi-style __gnu_*_ieee.
- // FIXME: What about other targets?
- setLibcallImpl(RTLIB::FPEXT_F16_F32, RTLIB::__extendhfsf2);
- setLibcallImpl(RTLIB::FPROUND_F32_F16, RTLIB::__truncsfhf2);
-
- if (!darwinHasExp10(TT)) {
- setLibcallImpl(RTLIB::EXP10_F32, RTLIB::Unsupported);
- setLibcallImpl(RTLIB::EXP10_F64, RTLIB::Unsupported);
- }
- }
-
- if (TT.isOSOpenBSD()) {
- setLibcallImpl(RTLIB::STACKPROTECTOR_CHECK_FAIL, RTLIB::Unsupported);
+ if (TT.isOSOpenBSD())
setLibcallImpl(RTLIB::STACK_SMASH_HANDLER, RTLIB::__stack_smash_handler);
- }
-
- // Skip default manual processing for targets that have been mostly ported to
- // tablegen for now. Eventually the rest of this should be deleted.
- if (TT.isX86() || TT.isAArch64() || TT.isWasm() || TT.isPPC())
- return;
if (TT.isARM() || TT.isThumb()) {
setARMLibcallNames(*this, TT, FloatABI, EABIVersion);
return;
}
- if (hasSinCos(TT)) {
- setLibcallImpl(RTLIB::SINCOS_F32, RTLIB::sincosf);
- setLibcallImpl(RTLIB::SINCOS_F64, RTLIB::sincos);
- setLibcallImpl(RTLIB::SINCOS_F128, RTLIB::sincos_f128);
- }
-
- setLibcallImpl(RTLIB::EXP10_F32, RTLIB::exp10f);
- setLibcallImpl(RTLIB::EXP10_F64, RTLIB::exp10);
- setLibcallImpl(RTLIB::EXP10_F128, RTLIB::exp10l_f128);
-
- // These libcalls are only available in compiler-rt, not libgcc.
- if (TT.isArch64Bit()) {
- setLibcallImpl(RTLIB::SHL_I128, RTLIB::__ashlti3);
- setLibcallImpl(RTLIB::SRL_I128, RTLIB::__lshrti3);
- setLibcallImpl(RTLIB::SRA_I128, RTLIB::__ashrti3);
- setLibcallImpl(RTLIB::MUL_I128, RTLIB::__multi3);
- setLibcallImpl(RTLIB::MULO_I64, RTLIB::__mulodi4);
- }
-
if (TT.getArch() == Triple::ArchType::msp430) {
setLibcallImplCallingConv(RTLIB::__mspabi_mpyll,
CallingConv::MSP430_BUILTIN);
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index ae8dffc..8f3814a 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -401,16 +401,15 @@ static bool isIFunc(const MCSymbolELF *Symbol) {
mergeTypeForSet(Symbol->getType(), ELF::STT_GNU_IFUNC) !=
ELF::STT_GNU_IFUNC)
return false;
- Symbol = &cast<MCSymbolELF>(Value->getSymbol());
+ Symbol = &static_cast<const MCSymbolELF &>(Value->getSymbol());
}
return true;
}
void ELFWriter::writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex,
ELFSymbolData &MSD) {
- const auto &Symbol = cast<MCSymbolELF>(*MSD.Symbol);
- const MCSymbolELF *Base =
- cast_or_null<MCSymbolELF>(Asm.getBaseSymbol(Symbol));
+ auto &Symbol = static_cast<const MCSymbolELF &>(*MSD.Symbol);
+ auto *Base = static_cast<const MCSymbolELF *>(Asm.getBaseSymbol(Symbol));
// This has to be in sync with when computeSymbolTable uses SHN_ABS or
// SHN_COMMON.
@@ -446,7 +445,7 @@ void ELFWriter::writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex,
const MCSymbolELF *Sym = &Symbol;
while (Sym->isVariable()) {
if (auto *Expr = dyn_cast<MCSymbolRefExpr>(Sym->getVariableValue())) {
- Sym = cast<MCSymbolELF>(&Expr->getSymbol());
+ Sym = static_cast<const MCSymbolELF *>(&Expr->getSymbol());
if (!Sym->getSize())
continue;
ESize = Sym->getSize();
@@ -523,7 +522,7 @@ void ELFWriter::computeSymbolTable(const RevGroupMapTy &RevGroupMap) {
// Add the data for the symbols.
bool HasLargeSectionIndex = false;
for (auto It : llvm::enumerate(Asm.symbols())) {
- const auto &Symbol = cast<MCSymbolELF>(It.value());
+ auto &Symbol = static_cast<const MCSymbolELF &>(It.value());
if (!isInSymtab(Symbol))
continue;
@@ -533,7 +532,7 @@ void ELFWriter::computeSymbolTable(const RevGroupMapTy &RevGroupMap) {
}
ELFSymbolData MSD;
- MSD.Symbol = cast<MCSymbolELF>(&Symbol);
+ MSD.Symbol = static_cast<const MCSymbolELF *>(&Symbol);
MSD.Order = It.index();
bool Local = Symbol.getBinding() == ELF::STB_LOCAL;
@@ -1175,7 +1174,7 @@ void ELFObjectWriter::executePostLayoutBinding() {
// versions declared with @@@ to be renamed.
for (const Symver &S : Symvers) {
StringRef AliasName = S.Name;
- const auto &Symbol = cast<MCSymbolELF>(*S.Sym);
+ auto &Symbol = static_cast<const MCSymbolELF &>(*S.Sym);
size_t Pos = AliasName.find('@');
assert(Pos != StringRef::npos);
@@ -1185,8 +1184,8 @@ void ELFObjectWriter::executePostLayoutBinding() {
if (Rest.starts_with("@@@"))
Tail = Rest.substr(Symbol.isUndefined() ? 2 : 1);
- auto *Alias =
- cast<MCSymbolELF>(Asm->getContext().getOrCreateSymbol(Prefix + Tail));
+ auto *Alias = static_cast<MCSymbolELF *>(
+ Asm->getContext().getOrCreateSymbol(Prefix + Tail));
Asm->registerSymbol(*Alias);
const MCExpr *Value = MCSymbolRefExpr::create(&Symbol, Asm->getContext());
Alias->setVariableValue(Value);
@@ -1218,7 +1217,8 @@ void ELFObjectWriter::executePostLayoutBinding() {
}
for (const MCSymbol *&Sym : AddrsigSyms) {
- if (const MCSymbol *R = Renames.lookup(cast<MCSymbolELF>(Sym)))
+ if (const MCSymbol *R =
+ Renames.lookup(static_cast<const MCSymbolELF *>(Sym)))
Sym = R;
if (Sym->isInSection() && Sym->getName().starts_with(".L"))
Sym = Sym->getSection().getBeginSymbol();
@@ -1234,7 +1234,7 @@ void ELFObjectWriter::executePostLayoutBinding() {
continue;
auto *Expr = Alias->getVariableValue();
if (const auto *Inner = dyn_cast<MCSymbolRefExpr>(Expr)) {
- auto &Sym = cast<MCSymbolELF>(Inner->getSymbol());
+ auto &Sym = static_cast<const MCSymbolELF &>(Inner->getSymbol());
if (Asm->registerSymbol(Sym))
Sym.setBinding(ELF::STB_WEAK);
}
@@ -1316,7 +1316,7 @@ void ELFObjectWriter::recordRelocation(const MCFragment &F,
auto &Section = static_cast<const MCSectionELF &>(*F.getParent());
MCContext &Ctx = getContext();
- const auto *SymA = cast_or_null<MCSymbolELF>(Target.getAddSym());
+ auto *SymA = static_cast<const MCSymbolELF *>(Target.getAddSym());
const MCSectionELF *SecA =
(SymA && SymA->isInSection())
? static_cast<const MCSectionELF *>(&SymA->getSection())
@@ -1328,7 +1328,7 @@ void ELFObjectWriter::recordRelocation(const MCFragment &F,
uint64_t FixupOffset = Asm->getFragmentOffset(F) + Fixup.getOffset();
uint64_t Addend = Target.getConstant();
if (auto *RefB = Target.getSubSym()) {
- const auto &SymB = cast<MCSymbolELF>(*RefB);
+ auto &SymB = static_cast<const MCSymbolELF &>(*RefB);
if (SymB.isUndefined()) {
Ctx.reportError(Fixup.getLoc(),
Twine("symbol '") + SymB.getName() +
@@ -1363,7 +1363,7 @@ void ELFObjectWriter::recordRelocation(const MCFragment &F,
!mc::isRelocRelocation(Fixup.getKind());
if (UseSectionSym && useSectionSymbol(Target, SymA, Addend, Type)) {
Addend += Asm->getSymbolOffset(*SymA);
- SymA = cast<MCSymbolELF>(SecA->getBeginSymbol());
+ SymA = static_cast<const MCSymbolELF *>(SecA->getBeginSymbol());
} else if (const MCSymbolELF *R = Renames.lookup(SymA)) {
SymA = R;
}
@@ -1383,7 +1383,7 @@ bool ELFObjectWriter::usesRela(const MCTargetOptions *TO,
bool ELFObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
const MCSymbol &SA, const MCFragment &FB, bool InSet, bool IsPCRel) const {
- const auto &SymA = cast<MCSymbolELF>(SA);
+ auto &SymA = static_cast<const MCSymbolELF &>(SA);
if (IsPCRel) {
assert(!InSet);
if (SymA.getBinding() != ELF::STB_LOCAL ||
diff --git a/llvm/lib/MC/GOFFObjectWriter.cpp b/llvm/lib/MC/GOFFObjectWriter.cpp
index 88188f3..3b629cd 100644
--- a/llvm/lib/MC/GOFFObjectWriter.cpp
+++ b/llvm/lib/MC/GOFFObjectWriter.cpp
@@ -345,7 +345,7 @@ void GOFFWriter::defineSymbols() {
for (const MCSymbol &Sym : Asm.symbols()) {
if (Sym.isTemporary())
continue;
- auto &Symbol = cast<MCSymbolGOFF>(Sym);
+ auto &Symbol = static_cast<const MCSymbolGOFF &>(Sym);
if (Symbol.hasLDAttributes()) {
Symbol.setIndex(++Ordinal);
defineLabel(Symbol);
diff --git a/llvm/lib/MC/MCAsmBackend.cpp b/llvm/lib/MC/MCAsmBackend.cpp
index 828d9cf..55ec4a6 100644
--- a/llvm/lib/MC/MCAsmBackend.cpp
+++ b/llvm/lib/MC/MCAsmBackend.cpp
@@ -8,6 +8,7 @@
#include "llvm/MC/MCAsmBackend.h"
#include "llvm/MC/MCAssembler.h"
+#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDXContainerWriter.h"
#include "llvm/MC/MCELFObjectWriter.h"
#include "llvm/MC/MCGOFFObjectWriter.h"
@@ -122,14 +123,12 @@ void MCAsmBackend::maybeAddReloc(const MCFragment &F, const MCFixup &Fixup,
}
bool MCAsmBackend::isDarwinCanonicalPersonality(const MCSymbol *Sym) const {
+ assert(getContext().isMachO());
// Consider a NULL personality (ie., no personality encoding) to be canonical
// because it's always at 0.
if (!Sym)
return true;
- if (!Sym->isMachO())
- llvm_unreachable("Expected MachO symbols only");
-
StringRef name = Sym->getName();
// XXX: We intentionally leave out "___gcc_personality_v0" because, despite
// being system-defined like these two, it is not very commonly-used.
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index da51da4..93614cd 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,
@@ -1070,9 +1069,11 @@ void MCAsmStreamer::emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
// Print symbol's rename (original name contains invalid character(s)) if
// there is one.
- MCSymbolXCOFF *XSym = dyn_cast<MCSymbolXCOFF>(Symbol);
- if (XSym && XSym->hasRename())
- emitXCOFFRenameDirective(XSym, XSym->getSymbolTableName());
+ if (getContext().isXCOFF()) {
+ auto *XSym = static_cast<MCSymbolXCOFF *>(Symbol);
+ if (XSym && XSym->hasRename())
+ emitXCOFFRenameDirective(XSym, XSym->getSymbolTableName());
+ }
}
void MCAsmStreamer::emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
diff --git a/llvm/lib/MC/MCCodeView.cpp b/llvm/lib/MC/MCCodeView.cpp
index 3a5f01c..335934a7 100644
--- a/llvm/lib/MC/MCCodeView.cpp
+++ b/llvm/lib/MC/MCCodeView.cpp
@@ -436,12 +436,11 @@ void CodeViewContext::emitInlineLineTableForFunction(MCObjectStreamer &OS,
const MCSymbol *FnEndSym) {
// Create and insert a fragment into the current section that will be encoded
// later.
- auto *F = MCCtx->allocFragment<MCCVInlineLineTableFragment>(
+ OS.newSpecialFragment<MCCVInlineLineTableFragment>(
PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym, FnEndSym);
- OS.insert(F);
}
-MCFragment *CodeViewContext::emitDefRange(
+void CodeViewContext::emitDefRange(
MCObjectStreamer &OS,
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
StringRef FixedSizePortion) {
@@ -451,9 +450,7 @@ MCFragment *CodeViewContext::emitDefRange(
auto &Saved = DefRangeStorage.emplace_back(Ranges.begin(), Ranges.end());
// Create and insert a fragment into the current section that will be encoded
// later.
- auto *F = MCCtx->allocFragment<MCCVDefRangeFragment>(Saved, FixedSizePortion);
- OS.insert(F);
- return F;
+ OS.newSpecialFragment<MCCVDefRangeFragment>(Saved, FixedSizePortion);
}
static unsigned computeLabelDiff(const MCAssembler &Asm, const MCSymbol *Begin,
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index 39bf628..5e364e9 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -153,15 +153,12 @@ void MCContext::reset() {
SPIRVAllocator.DestroyAll();
WasmSignatureAllocator.DestroyAll();
- // ~CodeViewContext may destroy a MCFragment outside of sections and need to
- // be reset before FragmentAllocator.
CVContext.reset();
MCSubtargetAllocator.DestroyAll();
InlineAsmUsedLabelNames.clear();
Symbols.clear();
Allocator.Reset();
- FragmentAllocator.Reset();
Instances.clear();
CompilationDir.clear();
MainFileName.clear();
@@ -297,11 +294,9 @@ MCSymbol *MCContext::createSymbolImpl(const MCSymbolTableEntry *Name,
case MCContext::IsDXContainer:
break;
case MCContext::IsSPIRV:
- return new (Name, *this)
- MCSymbol(MCSymbol::SymbolKindUnset, Name, IsTemporary);
+ return new (Name, *this) MCSymbol(Name, IsTemporary);
}
- return new (Name, *this)
- MCSymbol(MCSymbol::SymbolKindUnset, Name, IsTemporary);
+ return new (Name, *this) MCSymbol(Name, IsTemporary);
}
MCSymbol *MCContext::cloneSymbol(MCSymbol &Sym) {
@@ -309,13 +304,16 @@ MCSymbol *MCContext::cloneSymbol(MCSymbol &Sym) {
auto Name = Sym.getNameEntryPtr();
switch (getObjectFileType()) {
case MCContext::IsCOFF:
- NewSym = new (Name, *this) MCSymbolCOFF(cast<MCSymbolCOFF>(Sym));
+ NewSym =
+ new (Name, *this) MCSymbolCOFF(static_cast<const MCSymbolCOFF &>(Sym));
break;
case MCContext::IsELF:
- NewSym = new (Name, *this) MCSymbolELF(cast<MCSymbolELF>(Sym));
+ NewSym =
+ new (Name, *this) MCSymbolELF(static_cast<const MCSymbolELF &>(Sym));
break;
case MCContext::IsMachO:
- NewSym = new (Name, *this) MCSymbolMachO(cast<MCSymbolMachO>(Sym));
+ NewSym = new (Name, *this)
+ MCSymbolMachO(static_cast<const MCSymbolMachO &>(Sym));
break;
default:
reportFatalUsageError(".set redefinition is not supported");
@@ -446,7 +444,7 @@ Symbol *MCContext::getOrCreateSectionSymbol(StringRef Section) {
// Use the symbol's index to track if it has been used as a section symbol.
// Set to -1 to catch potential bugs if misused as a symbol index.
if (Sym && Sym->getIndex() != -1u) {
- R = cast<Symbol>(Sym);
+ R = static_cast<Symbol *>(Sym);
} else {
SymEntry.second.Used = true;
R = new (&SymEntry, *this) Symbol(&SymEntry, /*isTemporary=*/false);
@@ -586,7 +584,7 @@ MCContext::createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags,
return createELFSectionImpl(
I->getKey(), Type, Flags, EntrySize, Group, true, true,
- cast<MCSymbolELF>(RelInfoSection->getBeginSymbol()));
+ static_cast<const MCSymbolELF *>(RelInfoSection->getBeginSymbol()));
}
MCSectionELF *MCContext::getELFNamedSection(const Twine &Prefix,
@@ -604,7 +602,7 @@ MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type,
const MCSymbolELF *LinkedToSym) {
MCSymbolELF *GroupSym = nullptr;
if (!Group.isTriviallyEmpty() && !Group.str().empty())
- GroupSym = cast<MCSymbolELF>(getOrCreateSymbol(Group));
+ GroupSym = static_cast<MCSymbolELF *>(getOrCreateSymbol(Group));
return getELFSection(Section, Type, Flags, EntrySize, GroupSym, IsComdat,
UniqueID, LinkedToSym);
@@ -817,7 +815,7 @@ MCSectionWasm *MCContext::getWasmSection(const Twine &Section, SectionKind K,
unsigned UniqueID) {
MCSymbolWasm *GroupSym = nullptr;
if (!Group.isTriviallyEmpty() && !Group.str().empty()) {
- GroupSym = cast<MCSymbolWasm>(getOrCreateSymbol(Group));
+ GroupSym = static_cast<MCSymbolWasm *>(getOrCreateSymbol(Group));
GroupSym->setComdat(true);
if (K.isMetadata() && !GroupSym->getType().has_value()) {
// Comdat group symbol associated with a custom section is a section
@@ -848,7 +846,7 @@ MCSectionWasm *MCContext::getWasmSection(const Twine &Section, SectionKind Kind,
MCSymbol *Begin = createRenamableSymbol(CachedName, true, false);
// Begin always has a different name than CachedName... see #48596.
getSymbolTableEntry(Begin->getName()).second.Symbol = Begin;
- cast<MCSymbolWasm>(Begin)->setType(wasm::WASM_SYMBOL_TYPE_SECTION);
+ static_cast<MCSymbolWasm *>(Begin)->setType(wasm::WASM_SYMBOL_TYPE_SECTION);
MCSectionWasm *Result = new (WasmAllocator.Allocate())
MCSectionWasm(CachedName, Kind, Flags, GroupSym, UniqueID, Begin);
@@ -889,9 +887,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/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp
index 38744a0..275e76e 100644
--- a/llvm/lib/MC/MCELFStreamer.cpp
+++ b/llvm/lib/MC/MCELFStreamer.cpp
@@ -59,7 +59,7 @@ void MCELFStreamer::initSections(bool NoExecStack, const MCSubtargetInfo &STI) {
}
void MCELFStreamer::emitLabel(MCSymbol *S, SMLoc Loc) {
- auto *Symbol = cast<MCSymbolELF>(S);
+ auto *Symbol = static_cast<MCSymbolELF *>(S);
MCObjectStreamer::emitLabel(Symbol, Loc);
const MCSectionELF &Section =
@@ -70,7 +70,7 @@ void MCELFStreamer::emitLabel(MCSymbol *S, SMLoc Loc) {
void MCELFStreamer::emitLabelAtPos(MCSymbol *S, SMLoc Loc, MCFragment &F,
uint64_t Offset) {
- auto *Symbol = cast<MCSymbolELF>(S);
+ auto *Symbol = static_cast<MCSymbolELF *>(S);
MCObjectStreamer::emitLabelAtPos(Symbol, Loc, F, Offset);
const MCSectionELF &Section =
@@ -95,7 +95,7 @@ void MCELFStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
}
void MCELFStreamer::emitWeakReference(MCSymbol *Alias, const MCSymbol *Target) {
- auto *A = cast<MCSymbolELF>(Alias);
+ auto *A = static_cast<MCSymbolELF *>(Alias);
if (A->isDefined()) {
getContext().reportError(getStartTokLoc(), "symbol '" + A->getName() +
"' is already defined");
@@ -126,7 +126,7 @@ static unsigned CombineSymbolTypes(unsigned T1, unsigned T2) {
}
bool MCELFStreamer::emitSymbolAttribute(MCSymbol *S, MCSymbolAttr Attribute) {
- auto *Symbol = cast<MCSymbolELF>(S);
+ auto *Symbol = static_cast<MCSymbolELF *>(S);
// Adding a symbol attribute always introduces the symbol, note that an
// important side effect of calling registerSymbol here is to register
@@ -247,7 +247,7 @@ bool MCELFStreamer::emitSymbolAttribute(MCSymbol *S, MCSymbolAttr Attribute) {
void MCELFStreamer::emitCommonSymbol(MCSymbol *S, uint64_t Size,
Align ByteAlignment) {
- auto *Symbol = cast<MCSymbolELF>(S);
+ auto *Symbol = static_cast<MCSymbolELF *>(S);
getAssembler().registerSymbol(*Symbol);
if (!Symbol->isBindingSet())
@@ -272,12 +272,12 @@ void MCELFStreamer::emitCommonSymbol(MCSymbol *S, uint64_t Size,
" redeclared as different type");
}
- cast<MCSymbolELF>(Symbol)
- ->setSize(MCConstantExpr::create(Size, getContext()));
+ static_cast<MCSymbolELF *>(Symbol)->setSize(
+ MCConstantExpr::create(Size, getContext()));
}
void MCELFStreamer::emitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
- cast<MCSymbolELF>(Symbol)->setSize(Value);
+ static_cast<MCSymbolELF *>(Symbol)->setSize(Value);
}
void MCELFStreamer::emitELFSymverDirective(const MCSymbol *OriginalSym,
@@ -289,7 +289,7 @@ void MCELFStreamer::emitELFSymverDirective(const MCSymbol *OriginalSym,
void MCELFStreamer::emitLocalCommonSymbol(MCSymbol *S, uint64_t Size,
Align ByteAlignment) {
- auto *Symbol = cast<MCSymbolELF>(S);
+ auto *Symbol = static_cast<MCSymbolELF *>(S);
// FIXME: Should this be caught and done earlier?
getAssembler().registerSymbol(*Symbol);
Symbol->setBinding(ELF::STB_LOCAL);
diff --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp
index a214513..6226b02 100644
--- a/llvm/lib/MC/MCMachOStreamer.cpp
+++ b/llvm/lib/MC/MCMachOStreamer.cpp
@@ -147,7 +147,7 @@ void MCMachOStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
void MCMachOStreamer::emitEHSymAttributes(const MCSymbol *Symbol,
MCSymbol *EHSymbol) {
- auto *Sym = cast<MCSymbolMachO>(Symbol);
+ auto *Sym = static_cast<const MCSymbolMachO *>(Symbol);
getAssembler().registerSymbol(*Symbol);
if (Symbol->isExternal())
emitSymbolAttribute(EHSymbol, MCSA_Global);
@@ -160,7 +160,7 @@ void MCMachOStreamer::emitEHSymAttributes(const MCSymbol *Symbol,
void MCMachOStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
// We have to create a new fragment if this is an atom defining symbol,
// fragments cannot span atoms.
- if (cast<MCSymbolMachO>(Symbol)->isSymbolLinkerVisible())
+ if (static_cast<MCSymbolMachO *>(Symbol)->isSymbolLinkerVisible())
newFragment();
MCObjectStreamer::emitLabel(Symbol, Loc);
@@ -172,7 +172,7 @@ void MCMachOStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
//
// FIXME: Cleanup this code, these bits should be emitted based on semantic
// properties, not on the order of definition, etc.
- cast<MCSymbolMachO>(Symbol)->clearReferenceType();
+ static_cast<MCSymbolMachO *>(Symbol)->clearReferenceType();
}
void MCMachOStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
@@ -182,7 +182,7 @@ void MCMachOStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
if (const auto *SymA = Res.getAddSym()) {
if (!Res.getSubSym() &&
(SymA->getName().empty() || Res.getConstant() != 0))
- cast<MCSymbolMachO>(Symbol)->setAltEntry();
+ static_cast<MCSymbolMachO *>(Symbol)->setAltEntry();
}
}
MCObjectStreamer::emitAssignment(Symbol, Value);
@@ -256,7 +256,7 @@ void MCMachOStreamer::emitDarwinTargetVariantBuildVersion(
bool MCMachOStreamer::emitSymbolAttribute(MCSymbol *Sym,
MCSymbolAttr Attribute) {
- MCSymbolMachO *Symbol = cast<MCSymbolMachO>(Sym);
+ auto *Symbol = static_cast<MCSymbolMachO *>(Sym);
// Indirect symbols are handled differently, to match how 'as' handles
// them. This makes writing matching .o files easier.
@@ -367,7 +367,7 @@ bool MCMachOStreamer::emitSymbolAttribute(MCSymbol *Sym,
void MCMachOStreamer::emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
// Encode the 'desc' value into the lowest implementation defined bits.
getAssembler().registerSymbol(*Symbol);
- cast<MCSymbolMachO>(Symbol)->setDesc(DescValue);
+ static_cast<MCSymbolMachO *>(Symbol)->setDesc(DescValue);
}
void MCMachOStreamer::emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
@@ -430,7 +430,7 @@ void MCMachOStreamer::finishImpl() {
// defining symbols.
DenseMap<const MCFragment *, const MCSymbol *> DefiningSymbolMap;
for (const MCSymbol &Symbol : getAssembler().symbols()) {
- auto &Sym = cast<MCSymbolMachO>(Symbol);
+ auto &Sym = static_cast<const MCSymbolMachO &>(Symbol);
if (Sym.isSymbolLinkerVisible() && Sym.isInSection() && !Sym.isVariable() &&
!Sym.isAltEntry()) {
// An atom defining symbol should never be internal to a fragment.
diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp
index 393eed1..4ac73ab 100644
--- a/llvm/lib/MC/MCObjectFileInfo.cpp
+++ b/llvm/lib/MC/MCObjectFileInfo.cpp
@@ -1135,9 +1135,10 @@ MCObjectFileInfo::getCallGraphSection(const MCSection &TextSec) const {
Flags |= ELF::SHF_GROUP;
}
- return Ctx->getELFSection(".callgraph", ELF::SHT_PROGBITS, Flags, 0,
- GroupName, true, ElfSec.getUniqueID(),
- cast<MCSymbolELF>(TextSec.getBeginSymbol()));
+ return Ctx->getELFSection(
+ ".callgraph", ELF::SHT_PROGBITS, Flags, 0, GroupName, true,
+ ElfSec.getUniqueID(),
+ static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
}
MCSection *
@@ -1154,9 +1155,10 @@ MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const {
Flags |= ELF::SHF_GROUP;
}
- return Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, Flags, 0,
- GroupName, true, ElfSec.getUniqueID(),
- cast<MCSymbolELF>(TextSec.getBeginSymbol()));
+ return Ctx->getELFSection(
+ ".stack_sizes", ELF::SHT_PROGBITS, Flags, 0, GroupName, true,
+ ElfSec.getUniqueID(),
+ static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
}
MCSection *
@@ -1174,9 +1176,10 @@ MCObjectFileInfo::getBBAddrMapSection(const MCSection &TextSec) const {
// Use the text section's begin symbol and unique ID to create a separate
// .llvm_bb_addr_map section associated with every unique text section.
- return Ctx->getELFSection(".llvm_bb_addr_map", ELF::SHT_LLVM_BB_ADDR_MAP,
- Flags, 0, GroupName, true, ElfSec.getUniqueID(),
- cast<MCSymbolELF>(TextSec.getBeginSymbol()));
+ return Ctx->getELFSection(
+ ".llvm_bb_addr_map", ELF::SHT_LLVM_BB_ADDR_MAP, Flags, 0, GroupName, true,
+ ElfSec.getUniqueID(),
+ static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
}
MCSection *
@@ -1192,10 +1195,10 @@ MCObjectFileInfo::getKCFITrapSection(const MCSection &TextSec) const {
Flags |= ELF::SHF_GROUP;
}
- return Ctx->getELFSection(".kcfi_traps", ELF::SHT_PROGBITS, Flags, 0,
- GroupName,
- /*IsComdat=*/true, ElfSec.getUniqueID(),
- cast<MCSymbolELF>(TextSec.getBeginSymbol()));
+ return Ctx->getELFSection(
+ ".kcfi_traps", ELF::SHT_PROGBITS, Flags, 0, GroupName,
+ /*IsComdat=*/true, ElfSec.getUniqueID(),
+ static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
}
MCSection *
@@ -1211,9 +1214,10 @@ MCObjectFileInfo::getPseudoProbeSection(const MCSection &TextSec) const {
Flags |= ELF::SHF_GROUP;
}
- return Ctx->getELFSection(PseudoProbeSection->getName(), ELF::SHT_PROGBITS,
- Flags, 0, GroupName, true, ElfSec.getUniqueID(),
- cast<MCSymbolELF>(TextSec.getBeginSymbol()));
+ return Ctx->getELFSection(
+ PseudoProbeSection->getName(), ELF::SHT_PROGBITS, Flags, 0, GroupName,
+ true, ElfSec.getUniqueID(),
+ static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
}
MCSection *
@@ -1261,7 +1265,7 @@ MCSection *MCObjectFileInfo::getPCSection(StringRef Name,
GroupName = Group->getName();
Flags |= ELF::SHF_GROUP;
}
- return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, Flags, 0, GroupName, true,
- ElfSec.getUniqueID(),
- cast<MCSymbolELF>(TextSec->getBeginSymbol()));
+ return Ctx->getELFSection(
+ Name, ELF::SHT_PROGBITS, Flags, 0, GroupName, true, ElfSec.getUniqueID(),
+ static_cast<const MCSymbolELF *>(TextSec->getBeginSymbol()));
}
diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
index 200e29a..bcc77c0 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -84,7 +84,7 @@ void MCObjectStreamer::ensureHeadroom(size_t Headroom) {
addFragment(F);
}
-void MCObjectStreamer::insert(MCFragment *Frag) {
+void MCObjectStreamer::addSpecialFragment(MCFragment *Frag) {
assert(Frag->getKind() != MCFragment::FT_Data &&
"F should have a variable-size tail");
// Frag is not connected to FragSpace. Before modifying CurFrag with
@@ -173,6 +173,7 @@ void MCObjectStreamer::reset() {
EmitDebugFrame = false;
FragStorage.clear();
FragSpace = 0;
+ SpecialFragAllocator.Reset();
MCStreamer::reset();
}
@@ -649,7 +650,7 @@ void MCObjectStreamer::emitCodeAlignment(Align Alignment,
void MCObjectStreamer::emitValueToOffset(const MCExpr *Offset,
unsigned char Value,
SMLoc Loc) {
- insert(getContext().allocFragment<MCOrgFragment>(*Offset, Value, Loc));
+ newSpecialFragment<MCOrgFragment>(*Offset, Value, Loc);
}
void MCObjectStreamer::emitRelocDirective(const MCExpr &Offset, StringRef Name,
@@ -681,8 +682,7 @@ void MCObjectStreamer::emitRelocDirective(const MCExpr &Offset, StringRef Name,
void MCObjectStreamer::emitFill(const MCExpr &NumBytes, uint64_t FillValue,
SMLoc Loc) {
assert(getCurrentSectionOnly() && "need a section");
- insert(
- getContext().allocFragment<MCFillFragment>(FillValue, 1, NumBytes, Loc));
+ newSpecialFragment<MCFillFragment>(FillValue, 1, NumBytes, Loc);
}
void MCObjectStreamer::emitFill(const MCExpr &NumValues, int64_t Size,
@@ -709,15 +709,13 @@ void MCObjectStreamer::emitFill(const MCExpr &NumValues, int64_t Size,
// Otherwise emit as fragment.
assert(getCurrentSectionOnly() && "need a section");
- insert(
- getContext().allocFragment<MCFillFragment>(Expr, Size, NumValues, Loc));
+ newSpecialFragment<MCFillFragment>(Expr, Size, NumValues, Loc);
}
void MCObjectStreamer::emitNops(int64_t NumBytes, int64_t ControlledNopLength,
SMLoc Loc, const MCSubtargetInfo &STI) {
assert(getCurrentSectionOnly() && "need a section");
- insert(getContext().allocFragment<MCNopsFragment>(
- NumBytes, ControlledNopLength, Loc, STI));
+ newSpecialFragment<MCNopsFragment>(NumBytes, ControlledNopLength, Loc, STI);
}
void MCObjectStreamer::emitFileDirective(StringRef Filename) {
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index 9f64a98..7782dc1 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -1865,7 +1865,7 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info,
}
if (MAI.hasSubsectionsViaSymbols() && CFIStartProcLoc &&
- Sym->isExternal() && !cast<MCSymbolMachO>(Sym)->isAltEntry())
+ Sym->isExternal() && !static_cast<MCSymbolMachO *>(Sym)->isAltEntry())
return Error(StartTokLoc, "non-private labels cannot appear between "
".cfi_startproc / .cfi_endproc pairs") &&
Error(*CFIStartProcLoc, "previous .cfi_startproc was here");
@@ -6273,7 +6273,8 @@ bool parseAssignmentExpression(StringRef Name, bool allow_redef,
// used as a symbol, or it is an absolute symbol).
Sym = Parser.getContext().lookupSymbol(Name);
if (Sym) {
- if (!Sym->isUnset() && (!allow_redef || !Sym->isRedefinable()))
+ if ((Sym->isVariable() || Sym->isDefined()) &&
+ (!allow_redef || !Sym->isRedefinable()))
return Parser.Error(EqualLoc, "redefinition of '" + Name + "'");
// If the symbol is redefinable, clone it and update the symbol table
// to the new symbol. Existing references to the original symbol remain
diff --git a/llvm/lib/MC/MCParser/COFFMasmParser.cpp b/llvm/lib/MC/MCParser/COFFMasmParser.cpp
index 282f22f..229b0b8 100644
--- a/llvm/lib/MC/MCParser/COFFMasmParser.cpp
+++ b/llvm/lib/MC/MCParser/COFFMasmParser.cpp
@@ -460,7 +460,8 @@ bool COFFMasmParser::parseDirectiveProc(StringRef Directive, SMLoc Loc) {
nextLoc = getTok().getLoc();
}
}
- MCSymbolCOFF *Sym = cast<MCSymbolCOFF>(getContext().getOrCreateSymbol(Label));
+ auto *Sym =
+ static_cast<MCSymbolCOFF *>(getContext().getOrCreateSymbol(Label));
// Define symbol as simple external function
Sym->setExternal(true);
diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
index 2e251cc..6782c4b 100644
--- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
@@ -200,7 +200,7 @@ bool ELFAsmParser::parseDirectiveSize(StringRef, SMLoc) {
StringRef Name;
if (getParser().parseIdentifier(Name))
return TokError("expected identifier");
- MCSymbolELF *Sym = cast<MCSymbolELF>(getContext().getOrCreateSymbol(Name));
+ auto *Sym = static_cast<MCSymbolELF *>(getContext().getOrCreateSymbol(Name));
if (getLexer().isNot(AsmToken::Comma))
return TokError("expected comma");
@@ -466,7 +466,7 @@ bool ELFAsmParser::parseLinkedToSym(MCSymbolELF *&LinkedToSym) {
}
return TokError("invalid linked-to symbol");
}
- LinkedToSym = dyn_cast_or_null<MCSymbolELF>(getContext().lookupSymbol(Name));
+ LinkedToSym = static_cast<MCSymbolELF *>(getContext().lookupSymbol(Name));
if (!LinkedToSym || !LinkedToSym->isInSection())
return Error(StartLoc, "linked-to symbol is not in a section: " + Name);
return false;
diff --git a/llvm/lib/MC/MCParser/WasmAsmParser.cpp b/llvm/lib/MC/MCParser/WasmAsmParser.cpp
index d97f4f5..6c2d241 100644
--- a/llvm/lib/MC/MCParser/WasmAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/WasmAsmParser.cpp
@@ -224,7 +224,7 @@ public:
return true;
if (expect(AsmToken::EndOfStatement, "eol"))
return true;
- auto WasmSym = cast<MCSymbolWasm>(Sym);
+ auto WasmSym = static_cast<const MCSymbolWasm *>(Sym);
if (WasmSym->isFunction()) {
// Ignore .size directives for function symbols. They get their size
// set automatically based on their content.
@@ -241,9 +241,9 @@ public:
if (!Lexer->is(AsmToken::Identifier))
return error("Expected label after .type directive, got: ",
Lexer->getTok());
- auto WasmSym = cast<MCSymbolWasm>(
- getStreamer().getContext().getOrCreateSymbol(
- Lexer->getTok().getString()));
+ auto *WasmSym = static_cast<MCSymbolWasm *>(
+ getStreamer().getContext().getOrCreateSymbol(
+ Lexer->getTok().getString()));
Lex();
if (!(isNext(AsmToken::Comma) && isNext(AsmToken::At) &&
Lexer->is(AsmToken::Identifier)))
diff --git a/llvm/lib/MC/MCWasmStreamer.cpp b/llvm/lib/MC/MCWasmStreamer.cpp
index e3ef111..9c8b224 100644
--- a/llvm/lib/MC/MCWasmStreamer.cpp
+++ b/llvm/lib/MC/MCWasmStreamer.cpp
@@ -36,7 +36,7 @@ using namespace llvm;
MCWasmStreamer::~MCWasmStreamer() = default; // anchor.
void MCWasmStreamer::emitLabel(MCSymbol *S, SMLoc Loc) {
- auto *Symbol = cast<MCSymbolWasm>(S);
+ auto *Symbol = static_cast<MCSymbolWasm *>(S);
MCObjectStreamer::emitLabel(Symbol, Loc);
const MCSectionWasm &Section =
@@ -47,7 +47,7 @@ void MCWasmStreamer::emitLabel(MCSymbol *S, SMLoc Loc) {
void MCWasmStreamer::emitLabelAtPos(MCSymbol *S, SMLoc Loc, MCFragment &F,
uint64_t Offset) {
- auto *Symbol = cast<MCSymbolWasm>(S);
+ auto *Symbol = static_cast<MCSymbolWasm *>(S);
MCObjectStreamer::emitLabelAtPos(Symbol, Loc, F, Offset);
const MCSectionWasm &Section =
@@ -69,8 +69,7 @@ void MCWasmStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
bool MCWasmStreamer::emitSymbolAttribute(MCSymbol *S, MCSymbolAttr Attribute) {
assert(Attribute != MCSA_IndirectSymbol && "indirect symbols not supported");
-
- auto *Symbol = cast<MCSymbolWasm>(S);
+ auto *Symbol = static_cast<MCSymbolWasm *>(S);
// Adding a symbol attribute always introduces the symbol; note that an
// important side effect of calling registerSymbol here is to register the
@@ -135,7 +134,7 @@ void MCWasmStreamer::emitCommonSymbol(MCSymbol *S, uint64_t Size,
}
void MCWasmStreamer::emitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
- cast<MCSymbolWasm>(Symbol)->setSize(Value);
+ static_cast<MCSymbolWasm *>(Symbol)->setSize(Value);
}
void MCWasmStreamer::emitLocalCommonSymbol(MCSymbol *S, uint64_t Size,
diff --git a/llvm/lib/MC/MCWinCOFFStreamer.cpp b/llvm/lib/MC/MCWinCOFFStreamer.cpp
index 8be5054..a45936b 100644
--- a/llvm/lib/MC/MCWinCOFFStreamer.cpp
+++ b/llvm/lib/MC/MCWinCOFFStreamer.cpp
@@ -163,13 +163,13 @@ void MCWinCOFFStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
}
void MCWinCOFFStreamer::emitLabel(MCSymbol *S, SMLoc Loc) {
- auto *Symbol = cast<MCSymbolCOFF>(S);
+ auto *Symbol = static_cast<MCSymbolCOFF *>(S);
MCObjectStreamer::emitLabel(Symbol, Loc);
}
bool MCWinCOFFStreamer::emitSymbolAttribute(MCSymbol *S,
MCSymbolAttr Attribute) {
- auto *Symbol = cast<MCSymbolCOFF>(S);
+ auto *Symbol = static_cast<MCSymbolCOFF *>(S);
getAssembler().registerSymbol(*Symbol);
switch (Attribute) {
@@ -199,11 +199,10 @@ void MCWinCOFFStreamer::emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
}
void MCWinCOFFStreamer::beginCOFFSymbolDef(MCSymbol const *S) {
- auto *Symbol = cast<MCSymbolCOFF>(S);
if (CurSymbol)
Error("starting a new symbol definition without completing the "
"previous one");
- CurSymbol = Symbol;
+ CurSymbol = static_cast<MCSymbolCOFF *>(const_cast<MCSymbol *>(S));
}
void MCWinCOFFStreamer::emitCOFFSymbolStorageClass(int StorageClass) {
@@ -219,7 +218,7 @@ void MCWinCOFFStreamer::emitCOFFSymbolStorageClass(int StorageClass) {
}
getAssembler().registerSymbol(*CurSymbol);
- cast<MCSymbolCOFF>(CurSymbol)->setClass((uint16_t)StorageClass);
+ static_cast<MCSymbolCOFF *>(CurSymbol)->setClass((uint16_t)StorageClass);
}
void MCWinCOFFStreamer::emitCOFFSymbolType(int Type) {
@@ -234,7 +233,7 @@ void MCWinCOFFStreamer::emitCOFFSymbolType(int Type) {
}
getAssembler().registerSymbol(*CurSymbol);
- cast<MCSymbolCOFF>(CurSymbol)->setType((uint16_t)Type);
+ static_cast<const MCSymbolCOFF *>(CurSymbol)->setType((uint16_t)Type);
}
void MCWinCOFFStreamer::endCOFFSymbolDef() {
@@ -249,7 +248,7 @@ void MCWinCOFFStreamer::emitCOFFSafeSEH(MCSymbol const *Symbol) {
if (getContext().getTargetTriple().getArch() != Triple::x86)
return;
- const MCSymbolCOFF *CSymbol = cast<MCSymbolCOFF>(Symbol);
+ auto *CSymbol = static_cast<const MCSymbolCOFF *>(Symbol);
if (CSymbol->isSafeSEH())
return;
@@ -258,7 +257,7 @@ void MCWinCOFFStreamer::emitCOFFSafeSEH(MCSymbol const *Symbol) {
switchSection(SXData);
SXData->ensureMinAlignment(Align(4));
- insert(getContext().allocFragment<MCSymbolIdFragment>(Symbol));
+ newSpecialFragment<MCSymbolIdFragment>(Symbol);
getAssembler().registerSymbol(*Symbol);
CSymbol->setIsSafeSEH();
@@ -273,7 +272,7 @@ void MCWinCOFFStreamer::emitCOFFSymbolIndex(MCSymbol const *Symbol) {
MCSection *Sec = getCurrentSectionOnly();
Sec->ensureMinAlignment(Align(4));
- insert(getContext().allocFragment<MCSymbolIdFragment>(Symbol));
+ newSpecialFragment<MCSymbolIdFragment>(Symbol);
getAssembler().registerSymbol(*Symbol);
}
@@ -340,7 +339,7 @@ void MCWinCOFFStreamer::emitCOFFSecOffset(MCSymbol const *Symbol) {
void MCWinCOFFStreamer::emitCommonSymbol(MCSymbol *S, uint64_t Size,
Align ByteAlignment) {
- auto *Symbol = cast<MCSymbolCOFF>(S);
+ auto *Symbol = static_cast<MCSymbolCOFF *>(S);
const Triple &T = getContext().getTargetTriple();
if (T.isWindowsMSVCEnvironment()) {
@@ -372,7 +371,7 @@ void MCWinCOFFStreamer::emitCommonSymbol(MCSymbol *S, uint64_t Size,
void MCWinCOFFStreamer::emitLocalCommonSymbol(MCSymbol *S, uint64_t Size,
Align ByteAlignment) {
- auto *Symbol = cast<MCSymbolCOFF>(S);
+ auto *Symbol = static_cast<MCSymbolCOFF *>(S);
MCSection *Section = getContext().getObjectFileInfo()->getBSSSection();
pushSection();
@@ -387,7 +386,7 @@ void MCWinCOFFStreamer::emitLocalCommonSymbol(MCSymbol *S, uint64_t Size,
// Hack: Used by llvm-ml to implement the alias directive.
void MCWinCOFFStreamer::emitWeakReference(MCSymbol *AliasS,
const MCSymbol *Symbol) {
- auto *Alias = cast<MCSymbolCOFF>(AliasS);
+ auto *Alias = static_cast<MCSymbolCOFF *>(AliasS);
emitSymbolAttribute(Alias, MCSA_Weak);
Alias->setIsWeakExternal(true);
@@ -415,7 +414,7 @@ void MCWinCOFFStreamer::emitCGProfileEntry(const MCSymbolRefExpr *From,
void MCWinCOFFStreamer::finalizeCGProfileEntry(const MCSymbolRefExpr *&SRE) {
const MCSymbol *S = &SRE->getSymbol();
if (getAssembler().registerSymbol(*S))
- cast<MCSymbolCOFF>(S)->setExternal(true);
+ static_cast<const MCSymbolCOFF *>(S)->setExternal(true);
}
void MCWinCOFFStreamer::finishImpl() {
diff --git a/llvm/lib/MC/MCXCOFFStreamer.cpp b/llvm/lib/MC/MCXCOFFStreamer.cpp
index 26f45ce..a0e3dba 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) {
@@ -109,7 +109,7 @@ void MCXCOFFStreamer::emitXCOFFRefDirective(const MCSymbol *Symbol) {
void MCXCOFFStreamer::emitXCOFFRenameDirective(const MCSymbol *Name,
StringRef Rename) {
- const MCSymbolXCOFF *Symbol = cast<const MCSymbolXCOFF>(Name);
+ auto *Symbol = static_cast<const MCSymbolXCOFF *>(Name);
if (!Symbol->hasRename())
report_fatal_error("Only explicit .rename is supported for XCOFF.");
}
@@ -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/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp
index e87696a..eb59e39 100644
--- a/llvm/lib/MC/MachObjectWriter.cpp
+++ b/llvm/lib/MC/MachObjectWriter.cpp
@@ -72,7 +72,7 @@ bool MachObjectWriter::doesSymbolRequireExternRelocation(const MCSymbol &S) {
// References to weak definitions require external relocation entries; the
// definition may not always be the one in the same object file.
- if (cast<MCSymbolMachO>(S).isWeakDefinition())
+ if (static_cast<const MCSymbolMachO &>(S).isWeakDefinition())
return true;
// Otherwise, we can use an internal relocation.
@@ -383,15 +383,16 @@ const MCSymbol &MachObjectWriter::findAliasedSymbol(const MCSymbol &Sym) const {
}
void MachObjectWriter::writeNlist(MachSymbolData &MSD, const MCAssembler &Asm) {
- const MCSymbol *Symbol = MSD.Symbol;
- const auto &Data = cast<MCSymbolMachO>(*Symbol);
- const MCSymbol *AliasedSymbol = &findAliasedSymbol(*Symbol);
+ auto *Symbol = static_cast<const MCSymbolMachO *>(MSD.Symbol);
+ const auto &Data = static_cast<const MCSymbolMachO &>(*Symbol);
+ auto *AliasedSymbol =
+ static_cast<const MCSymbolMachO *>(&findAliasedSymbol(*Symbol));
uint8_t SectionIndex = MSD.SectionIndex;
uint8_t Type = 0;
uint64_t Address = 0;
bool IsAlias = Symbol != AliasedSymbol;
- const MCSymbol &OrigSymbol = *Symbol;
+ const MCSymbolMachO &OrigSymbol = *Symbol;
MachSymbolData *AliaseeInfo;
if (IsAlias) {
AliaseeInfo = findSymbolData(*AliasedSymbol);
@@ -441,9 +442,8 @@ void MachObjectWriter::writeNlist(MachSymbolData &MSD, const MCAssembler &Asm) {
// The Mach-O streamer uses the lowest 16-bits of the flags for the 'desc'
// value.
- bool EncodeAsAltEntry =
- IsAlias && cast<MCSymbolMachO>(OrigSymbol).isAltEntry();
- W.write<uint16_t>(cast<MCSymbolMachO>(Symbol)->getEncodedFlags(EncodeAsAltEntry));
+ bool EncodeAsAltEntry = IsAlias && OrigSymbol.isAltEntry();
+ W.write<uint16_t>(Symbol->getEncodedFlags(EncodeAsAltEntry));
if (is64Bit())
W.write<uint64_t>(Address);
else
@@ -570,7 +570,8 @@ void MachObjectWriter::bindIndirectSymbols(MCAssembler &Asm) {
//
// FIXME: Do not hardcode.
if (Asm.registerSymbol(*ISD.Symbol))
- cast<MCSymbolMachO>(ISD.Symbol)->setReferenceTypeUndefinedLazy(true);
+ static_cast<MCSymbolMachO *>(ISD.Symbol)
+ ->setReferenceTypeUndefinedLazy(true);
}
}
@@ -588,7 +589,7 @@ void MachObjectWriter::computeSymbolTable(
// Build the string table.
for (const MCSymbol &Symbol : Asm.symbols()) {
- if (!cast<MCSymbolMachO>(Symbol).isSymbolLinkerVisible())
+ if (!static_cast<const MCSymbolMachO &>(Symbol).isSymbolLinkerVisible())
continue;
StringTable.add(Symbol.getName());
@@ -602,7 +603,7 @@ void MachObjectWriter::computeSymbolTable(
// important for letting us diff .o files.
for (const MCSymbol &Symbol : Asm.symbols()) {
// Ignore non-linker visible symbols.
- if (!cast<MCSymbolMachO>(Symbol).isSymbolLinkerVisible())
+ if (!static_cast<const MCSymbolMachO &>(Symbol).isSymbolLinkerVisible())
continue;
if (!Symbol.isExternal() && !Symbol.isUndefined())
@@ -628,7 +629,7 @@ void MachObjectWriter::computeSymbolTable(
// Now add the data for local symbols.
for (const MCSymbol &Symbol : Asm.symbols()) {
// Ignore non-linker visible symbols.
- if (!cast<MCSymbolMachO>(Symbol).isSymbolLinkerVisible())
+ if (!static_cast<const MCSymbolMachO &>(Symbol).isSymbolLinkerVisible())
continue;
if (Symbol.isExternal() || Symbol.isUndefined())
diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp
index bfd6334..af009a4 100644
--- a/llvm/lib/MC/WasmObjectWriter.cpp
+++ b/llvm/lib/MC/WasmObjectWriter.cpp
@@ -487,7 +487,7 @@ void WasmObjectWriter::recordRelocation(const MCFragment &F,
bool IsLocRel = false;
if (const auto *RefB = Target.getSubSym()) {
- const auto &SymB = cast<MCSymbolWasm>(*RefB);
+ auto &SymB = static_cast<const MCSymbolWasm &>(*RefB);
if (FixupSection.isText()) {
Ctx.reportError(Fixup.getLoc(),
@@ -515,7 +515,7 @@ void WasmObjectWriter::recordRelocation(const MCFragment &F,
}
// We either rejected the fixup or folded B into C at this point.
- const auto *SymA = cast<MCSymbolWasm>(Target.getAddSym());
+ auto *SymA = static_cast<const MCSymbolWasm *>(Target.getAddSym());
// The .init_array isn't translated as data, so don't do relocations in it.
if (FixupSection.getName().starts_with(".init_array")) {
@@ -561,7 +561,7 @@ void WasmObjectWriter::recordRelocation(const MCFragment &F,
report_fatal_error("section symbol is required for relocation");
C += Asm->getSymbolOffset(*SymA);
- SymA = cast<MCSymbolWasm>(SectionSymbol);
+ SymA = static_cast<const MCSymbolWasm *>(SectionSymbol);
}
if (Type == wasm::R_WASM_TABLE_INDEX_REL_SLEB ||
@@ -573,7 +573,7 @@ void WasmObjectWriter::recordRelocation(const MCFragment &F,
// TABLE_INDEX relocs implicitly use the default indirect function table.
// We require the function table to have already been defined.
auto TableName = "__indirect_function_table";
- MCSymbolWasm *Sym = cast_or_null<MCSymbolWasm>(Ctx.lookupSymbol(TableName));
+ auto *Sym = static_cast<MCSymbolWasm *>(Ctx.lookupSymbol(TableName));
if (!Sym) {
report_fatal_error("missing indirect function table symbol");
} else {
@@ -631,8 +631,8 @@ WasmObjectWriter::getProvisionalValue(const MCAssembler &Asm,
case wasm::R_WASM_TABLE_INDEX_I32:
case wasm::R_WASM_TABLE_INDEX_I64: {
// Provisional value is table address of the resolved symbol itself
- const MCSymbolWasm *Base =
- cast<MCSymbolWasm>(Asm.getBaseSymbol(*RelEntry.Symbol));
+ auto *Base =
+ static_cast<const MCSymbolWasm *>(Asm.getBaseSymbol(*RelEntry.Symbol));
assert(Base->isFunction());
if (RelEntry.Type == wasm::R_WASM_TABLE_INDEX_REL_SLEB ||
RelEntry.Type == wasm::R_WASM_TABLE_INDEX_REL_SLEB64)
@@ -1342,11 +1342,11 @@ void WasmObjectWriter::prepareImports(
// Register types for all functions, including those with private linkage
// (because wasm always needs a type signature).
if (WS.isFunction()) {
- const auto *BS = Asm.getBaseSymbol(S);
+ auto *BS = static_cast<const MCSymbolWasm *>(Asm.getBaseSymbol(S));
if (!BS)
report_fatal_error(Twine(S.getName()) +
": absolute addressing not supported!");
- registerFunctionType(*cast<MCSymbolWasm>(BS));
+ registerFunctionType(*BS);
}
if (WS.isTag())
@@ -1516,10 +1516,10 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
// For user-defined custom sections, strip the prefix
Name.consume_front(".custom_section.");
- MCSymbol *Begin = Sec.getBeginSymbol();
+ auto *Begin = static_cast<MCSymbolWasm *>(Sec.getBeginSymbol());
if (Begin) {
- assert(WasmIndices.count(cast<MCSymbolWasm>(Begin)) == 0);
- WasmIndices[cast<MCSymbolWasm>(Begin)] = CustomSections.size();
+ assert(WasmIndices.count(Begin) == 0);
+ WasmIndices[Begin] = CustomSections.size();
}
// Separate out the producers and target features sections
@@ -1719,7 +1719,7 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
if (!BS)
report_fatal_error(Twine(S.getName()) +
": absolute addressing not supported!");
- const MCSymbolWasm *Base = cast<MCSymbolWasm>(BS);
+ const MCSymbolWasm *Base = static_cast<const MCSymbolWasm *>(BS);
// Find the target symbol of this weak alias and export that index
const auto &WS = static_cast<const MCSymbolWasm &>(S);
@@ -1829,8 +1829,8 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
Rel.Type != wasm::R_WASM_TABLE_INDEX_REL_SLEB64)
return;
assert(Rel.Symbol->isFunction());
- const MCSymbolWasm *Base =
- cast<MCSymbolWasm>(Asm.getBaseSymbol(*Rel.Symbol));
+ auto *Base =
+ static_cast<const MCSymbolWasm *>(Asm.getBaseSymbol(*Rel.Symbol));
uint32_t FunctionIndex = WasmIndices.find(Base)->second;
uint32_t TableIndex = TableElems.size() + InitialTableOffset;
if (TableIndices.try_emplace(Base, TableIndex).second) {
@@ -1880,7 +1880,8 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
if (!SymRef)
report_fatal_error(
"fixups in .init_array should be symbol references");
- const auto &TargetSym = cast<const MCSymbolWasm>(SymRef->getSymbol());
+ auto &TargetSym =
+ static_cast<const MCSymbolWasm &>(SymRef->getSymbol());
if (TargetSym.getIndex() == InvalidIndex)
report_fatal_error("symbols in .init_array should exist in symtab");
if (!TargetSym.isFunction())
@@ -1905,7 +1906,7 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
writeExportSection(Exports);
const MCSymbol *IndirectFunctionTable =
getContext().lookupSymbol("__indirect_function_table");
- writeElemSection(cast_or_null<const MCSymbolWasm>(IndirectFunctionTable),
+ writeElemSection(static_cast<const MCSymbolWasm *>(IndirectFunctionTable),
TableElems);
writeDataCountSection();
diff --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp
index 856850d..0cc5ff5 100644
--- a/llvm/lib/MC/WinCOFFObjectWriter.cpp
+++ b/llvm/lib/MC/WinCOFFObjectWriter.cpp
@@ -382,7 +382,8 @@ void WinCOFFWriter::defineSymbol(const MCSymbol &MCSym) {
COFFSymbol *Sym = GetOrCreateCOFFSymbol(&MCSym);
COFFSymbol *Local = nullptr;
- if (cast<MCSymbolCOFF>(MCSym).getWeakExternalCharacteristics()) {
+ if (static_cast<const MCSymbolCOFF &>(MCSym)
+ .getWeakExternalCharacteristics()) {
Sym->Data.StorageClass = COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL;
Sym->Section = nullptr;
@@ -406,7 +407,8 @@ void WinCOFFWriter::defineSymbol(const MCSymbol &MCSym) {
Sym->Aux[0].AuxType = ATWeakExternal;
Sym->Aux[0].Aux.WeakExternal.TagIndex = 0; // Filled in later
Sym->Aux[0].Aux.WeakExternal.Characteristics =
- cast<MCSymbolCOFF>(MCSym).getWeakExternalCharacteristics();
+ static_cast<const MCSymbolCOFF &>(MCSym)
+ .getWeakExternalCharacteristics();
} else {
if (!Base)
Sym->Data.SectionNumber = COFF::IMAGE_SYM_ABSOLUTE;
@@ -418,7 +420,7 @@ void WinCOFFWriter::defineSymbol(const MCSymbol &MCSym) {
if (Local) {
Local->Data.Value = getSymbolValue(MCSym, *Asm);
- const MCSymbolCOFF &SymbolCOFF = cast<MCSymbolCOFF>(MCSym);
+ auto &SymbolCOFF = static_cast<const MCSymbolCOFF &>(MCSym);
Local->Data.Type = SymbolCOFF.getType();
Local->Data.StorageClass = SymbolCOFF.getClass();
@@ -821,7 +823,8 @@ void WinCOFFWriter::executePostLayoutBinding() {
for (const MCSymbol &Symbol : Asm->symbols())
// Define non-temporary or temporary static (private-linkage) symbols
if (!Symbol.isTemporary() ||
- cast<MCSymbolCOFF>(Symbol).getClass() == COFF::IMAGE_SYM_CLASS_STATIC)
+ static_cast<const MCSymbolCOFF &>(Symbol).getClass() ==
+ COFF::IMAGE_SYM_CLASS_STATIC)
defineSymbol(Symbol);
UseBigObj = Sections.size() > COFF::MaxNumberOfSections16;
@@ -1188,7 +1191,7 @@ bool WinCOFFObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
// point to thunks, and the /GUARD:CF flag assumes that it can use relocations
// to approximate the set of all address taken functions. LLD's implementation
// of /GUARD:CF also relies on the existance of these relocations.
- uint16_t Type = cast<MCSymbolCOFF>(SymA).getType();
+ uint16_t Type = static_cast<const MCSymbolCOFF &>(SymA).getType();
if ((Type >> COFF::SCT_COMPLEX_TYPE_SHIFT) == COFF::IMAGE_SYM_DTYPE_FUNCTION)
return false;
return &SymA.getSection() == FB.getParent();
diff --git a/llvm/lib/MC/XCOFFObjectWriter.cpp b/llvm/lib/MC/XCOFFObjectWriter.cpp
index 65f543b..13917ba 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())
@@ -690,7 +690,8 @@ void XCOFFWriter::recordRelocation(const MCFragment &F, const MCFixup &Fixup,
std::tie(Type, SignAndSize) = TargetObjectWriter->getRelocTypeAndSignSize(
Target, Fixup, Fixup.isPCRel());
- const MCSectionXCOFF *SymASec = getContainingCsect(cast<MCSymbolXCOFF>(SymA));
+ const MCSectionXCOFF *SymASec =
+ getContainingCsect(static_cast<const MCSymbolXCOFF *>(SymA));
assert(SectionMap.contains(SymASec) &&
"Expected containing csect to exist in map.");
@@ -773,13 +774,13 @@ void XCOFFWriter::recordRelocation(const MCFragment &F, const MCFixup &Fixup,
"Expected containing csect to exist in map.");
SectionMap[RelocationSec]->Relocations.push_back(Reloc);
- const MCSymbol *const SymB = Target.getSubSym();
+ auto SymB = static_cast<const MCSymbolXCOFF *>(Target.getSubSym());
if (!SymB)
return;
if (SymA == SymB)
report_fatal_error("relocation for opposite term is not yet supported");
- const MCSectionXCOFF *SymBSec = getContainingCsect(cast<MCSymbolXCOFF>(SymB));
+ const MCSectionXCOFF *SymBSec = getContainingCsect(SymB);
assert(SectionMap.contains(SymBSec) &&
"Expected containing csect to exist in map.");
if (SymASec == SymBSec)
diff --git a/llvm/lib/Support/BalancedPartitioning.cpp b/llvm/lib/Support/BalancedPartitioning.cpp
index ed3b149..1914f4c 100644
--- a/llvm/lib/Support/BalancedPartitioning.cpp
+++ b/llvm/lib/Support/BalancedPartitioning.cpp
@@ -306,7 +306,7 @@ void BalancedPartitioning::split(const FunctionNodeRange Nodes,
unsigned NumNodes = std::distance(Nodes.begin(), Nodes.end());
auto NodesMid = Nodes.begin() + (NumNodes + 1) / 2;
- llvm::sort(Nodes.begin(), Nodes.end(), [](auto &L, auto &R) {
+ llvm::sort(Nodes, [](auto &L, auto &R) {
return L.InputOrderIndex < R.InputOrderIndex;
});
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
index 7618a57..45ac023 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
@@ -96,8 +96,8 @@ unsigned AArch64ELFObjectWriter::getRelocType(const MCFixup &Fixup,
case AArch64::S_TPREL:
case AArch64::S_TLSDESC:
case AArch64::S_TLSDESC_AUTH:
- if (auto *SA = Target.getAddSym())
- cast<MCSymbolELF>(SA)->setType(ELF::STT_TLS);
+ if (auto *SA = const_cast<MCSymbol *>(Target.getAddSym()))
+ static_cast<MCSymbolELF *>(SA)->setType(ELF::STT_TLS);
break;
default:
break;
@@ -488,7 +488,8 @@ bool AArch64ELFObjectWriter::needsRelocateWithSymbol(const MCValue &Val,
// this global needs to be tagged. In addition, the linker needs to know
// whether to emit a special addend when relocating `end` symbols, and this
// can only be determined by the attributes of the symbol itself.
- if (Val.getAddSym() && cast<MCSymbolELF>(Val.getAddSym())->isMemtag())
+ if (Val.getAddSym() &&
+ static_cast<const MCSymbolELF *>(Val.getAddSym())->isMemtag())
return true;
if ((Val.getSpecifier() & AArch64::S_GOT) == AArch64::S_GOT)
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp
index 6257e99..14547e3 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp
@@ -418,7 +418,8 @@ private:
}
MCSymbol *emitMappingSymbol(StringRef Name) {
- auto *Symbol = cast<MCSymbolELF>(getContext().createLocalSymbol(Name));
+ auto *Symbol =
+ static_cast<MCSymbolELF *>(getContext().createLocalSymbol(Name));
emitLabel(Symbol);
return Symbol;
}
@@ -455,7 +456,7 @@ void AArch64TargetELFStreamer::emitInst(uint32_t Inst) {
void AArch64TargetELFStreamer::emitDirectiveVariantPCS(MCSymbol *Symbol) {
getStreamer().getAssembler().registerSymbol(*Symbol);
- cast<MCSymbolELF>(Symbol)->setOther(ELF::STO_AARCH64_VARIANT_PCS);
+ static_cast<MCSymbolELF *>(Symbol)->setOther(ELF::STO_AARCH64_VARIANT_PCS);
}
void AArch64TargetELFStreamer::finish() {
@@ -541,7 +542,7 @@ void AArch64TargetELFStreamer::finish() {
MCSectionELF *MemtagSec = nullptr;
for (const MCSymbol &Symbol : Asm.symbols()) {
- const auto &Sym = cast<MCSymbolELF>(Symbol);
+ auto &Sym = static_cast<const MCSymbolELF &>(Symbol);
if (Sym.isMemtag()) {
MemtagSec = Ctx.getELFSection(".memtag.globals.static",
ELF::SHT_AARCH64_MEMTAG_GLOBALS_STATIC, 0);
@@ -556,7 +557,7 @@ void AArch64TargetELFStreamer::finish() {
S.switchSection(MemtagSec);
const auto *Zero = MCConstantExpr::create(0, Ctx);
for (const MCSymbol &Symbol : Asm.symbols()) {
- const auto &Sym = cast<MCSymbolELF>(Symbol);
+ auto &Sym = static_cast<const MCSymbolELF &>(Symbol);
if (!Sym.isMemtag())
continue;
auto *SRE = MCSymbolRefExpr::create(&Sym, Ctx);
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
index d443f4e..2d8f259 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
@@ -236,7 +236,7 @@ cl::opt<LoweringKind> LoweringKindLoc(
"Lower via mixture of above strategies")));
template <typename T> std::vector<T> sortByName(std::vector<T> &&V) {
- llvm::sort(V.begin(), V.end(), [](const auto *L, const auto *R) {
+ llvm::sort(V, [](const auto *L, const auto *R) {
return L->getName() < R->getName();
});
return {std::move(V)};
diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp
index 43ca548..68302f0 100644
--- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp
+++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp
@@ -872,14 +872,14 @@ void AMDGPUTargetELFStreamer::EmitAMDKernelCodeT(AMDGPUMCKernelCodeT &Header) {
void AMDGPUTargetELFStreamer::EmitAMDGPUSymbolType(StringRef SymbolName,
unsigned Type) {
- MCSymbolELF *Symbol = cast<MCSymbolELF>(
+ auto *Symbol = static_cast<MCSymbolELF *>(
getStreamer().getContext().getOrCreateSymbol(SymbolName));
Symbol->setType(Type);
}
void AMDGPUTargetELFStreamer::emitAMDGPULDS(MCSymbol *Symbol, unsigned Size,
Align Alignment) {
- MCSymbolELF *SymbolELF = cast<MCSymbolELF>(Symbol);
+ auto *SymbolELF = static_cast<MCSymbolELF *>(Symbol);
SymbolELF->setType(ELF::STT_OBJECT);
if (!SymbolELF->isBindingSet())
@@ -974,9 +974,9 @@ void AMDGPUTargetELFStreamer::EmitAmdhsaKernelDescriptor(
auto &Streamer = getStreamer();
auto &Context = Streamer.getContext();
- MCSymbolELF *KernelCodeSymbol = cast<MCSymbolELF>(
- Context.getOrCreateSymbol(Twine(KernelName)));
- MCSymbolELF *KernelDescriptorSymbol = cast<MCSymbolELF>(
+ auto *KernelCodeSymbol =
+ static_cast<MCSymbolELF *>(Context.getOrCreateSymbol(Twine(KernelName)));
+ auto *KernelDescriptorSymbol = static_cast<MCSymbolELF *>(
Context.getOrCreateSymbol(Twine(KernelName) + Twine(".kd")));
// Copy kernel descriptor symbol's binding, other and visibility from the
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
index c221d22..cc1c79b 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
@@ -296,9 +296,9 @@ static bool needsInterworking(const MCAssembler &Asm, const MCSymbol *Sym,
unsigned FixupKind) {
// Create relocations for unconditional branches to function symbols with
// different execution mode in ELF binaries.
- if (!Sym || !Sym->isELF())
+ if (!Sym || !Asm.getContext().isELF())
return false;
- unsigned Type = cast<MCSymbolELF>(Sym)->getType();
+ unsigned Type = static_cast<const MCSymbolELF *>(Sym)->getType();
if ((Type == ELF::STT_FUNC || Type == ELF::STT_GNU_IFUNC)) {
if (Asm.isThumbFunc(Sym) && (FixupKind == ARM::fixup_arm_uncondbranch))
return true;
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
index 50e9ca1..d914f6e 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
@@ -97,8 +97,8 @@ unsigned ARMELFObjectWriter::getRelocType(const MCFixup &Fixup,
case ARM::S_TLSLDM_FDPIC:
case ARM::S_TLSLDO:
case ARM::S_TPOFF:
- if (auto *SA = Target.getAddSym())
- cast<MCSymbolELF>(SA)->setType(ELF::STT_TLS);
+ if (auto *SA = const_cast<MCSymbol *>(Target.getAddSym()))
+ static_cast<MCSymbolELF *>(SA)->setType(ELF::STT_TLS);
break;
default:
break;
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
index 6dfe846..0796746 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
@@ -614,7 +614,7 @@ public:
if (!IsThumb)
return Val;
- unsigned Type = cast<MCSymbolELF>(Symbol)->getType();
+ unsigned Type = static_cast<MCSymbolELF *>(Symbol)->getType();
if ((Type == ELF::STT_FUNC || Type == ELF::STT_GNU_IFUNC) &&
Symbol->isDefined())
getAssembler().setIsThumbFunc(Symbol);
@@ -679,7 +679,8 @@ private:
}
void EmitMappingSymbol(StringRef Name) {
- auto *Symbol = cast<MCSymbolELF>(getContext().createLocalSymbol(Name));
+ auto *Symbol =
+ static_cast<MCSymbolELF *>(getContext().createLocalSymbol(Name));
emitLabel(Symbol);
Symbol->setType(ELF::STT_NOTYPE);
@@ -687,7 +688,8 @@ private:
}
void emitMappingSymbol(StringRef Name, MCFragment &F, uint64_t Offset) {
- auto *Symbol = cast<MCSymbolELF>(getContext().createLocalSymbol(Name));
+ auto *Symbol =
+ static_cast<MCSymbolELF *>(getContext().createLocalSymbol(Name));
emitLabelAtPos(Symbol, SMLoc(), F, Offset);
Symbol->setType(ELF::STT_NOTYPE);
Symbol->setBinding(ELF::STB_LOCAL);
@@ -1088,7 +1090,7 @@ void ARMTargetELFStreamer::emitLabel(MCSymbol *Symbol) {
return;
Streamer.getAssembler().registerSymbol(*Symbol);
- unsigned Type = cast<MCSymbolELF>(Symbol)->getType();
+ unsigned Type = static_cast<MCSymbolELF *>(Symbol)->getType();
if (Type == ELF::STT_FUNC || Type == ELF::STT_GNU_IFUNC)
emitThumbFunc(Symbol);
}
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
index 354de8f..8ee3a2d 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
@@ -505,7 +505,7 @@ public:
// Remember that the function is a thumb function. Fixup and relocation
// values will need adjusted.
getStreamer().getAssembler().setIsThumbFunc(Symbol);
- cast<MCSymbolMachO>(Symbol)->setThumbFunc();
+ static_cast<MCSymbolMachO *>(Symbol)->setThumbFunc();
}
};
} // namespace
diff --git a/llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFObjectWriter.cpp b/llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFObjectWriter.cpp
index d042d26..4667975f 100644
--- a/llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFObjectWriter.cpp
+++ b/llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFObjectWriter.cpp
@@ -48,8 +48,8 @@ unsigned CSKYELFObjectWriter::getRelocType(const MCFixup &Fixup,
case CSKY::S_TLSGD:
case CSKY::S_TLSLDM:
case CSKY::S_TLSLDO:
- if (auto *SA = Target.getAddSym())
- cast<MCSymbolELF>(SA)->setType(ELF::STT_TLS);
+ if (auto *SA = const_cast<MCSymbol *>(Target.getAddSym()))
+ static_cast<MCSymbolELF *>(SA)->setType(ELF::STT_TLS);
break;
default:
break;
diff --git a/llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFStreamer.cpp b/llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFStreamer.cpp
index 346b123..397cf16 100644
--- a/llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFStreamer.cpp
+++ b/llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFStreamer.cpp
@@ -169,7 +169,8 @@ void CSKYELFStreamer::EmitMappingSymbol(StringRef Name) {
State = (Name == "$t" ? EMS_Text : EMS_Data);
- auto *Symbol = cast<MCSymbolELF>(getContext().createLocalSymbol(Name));
+ auto *Symbol =
+ static_cast<MCSymbolELF *>(getContext().createLocalSymbol(Name));
emitLabel(Symbol);
Symbol->setType(ELF::STT_NOTYPE);
diff --git a/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp b/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp
index 52fa678..613048b 100644
--- a/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp
@@ -1987,7 +1987,7 @@ SmallVector<uint32_t, 8> HvxSelector::getPerfectCompletions(ShuffleMask SM,
// times). In such cases it will be impossible to complete this to a
// perfect shuffle.
SmallVector<uint32_t, 8> Sorted(Worklist);
- llvm::sort(Sorted.begin(), Sorted.end());
+ llvm::sort(Sorted);
for (unsigned I = 0, E = Sorted.size(); I != E;) {
unsigned P = Sorted[I], Count = 1;
diff --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonELFObjectWriter.cpp b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonELFObjectWriter.cpp
index 9752f3a..af97ea2 100644
--- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonELFObjectWriter.cpp
+++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonELFObjectWriter.cpp
@@ -50,8 +50,8 @@ unsigned HexagonELFObjectWriter::getRelocType(const MCFixup &Fixup,
case HexagonMCExpr::VK_IE:
case HexagonMCExpr::VK_IE_GOT:
case HexagonMCExpr::VK_TPREL:
- if (auto *SA = Target.getAddSym())
- cast<MCSymbolELF>(SA)->setType(ELF::STT_TLS);
+ if (auto *SA = const_cast<MCSymbol *>(Target.getAddSym()))
+ static_cast<MCSymbolELF *>(SA)->setType(ELF::STT_TLS);
break;
default:
break;
diff --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.cpp b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.cpp
index 13ecc23..039ef4f 100644
--- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.cpp
+++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.cpp
@@ -96,7 +96,7 @@ void HexagonMCELFStreamer::HexagonMCEmitCommonSymbol(MCSymbol *Symbol,
getAssembler().registerSymbol(*Symbol);
StringRef sbss[4] = {".sbss.1", ".sbss.2", ".sbss.4", ".sbss.8"};
- auto ELFSymbol = cast<MCSymbolELF>(Symbol);
+ auto ELFSymbol = static_cast<MCSymbolELF *>(Symbol);
if (!ELFSymbol->isBindingSet())
ELFSymbol->setBinding(ELF::STB_GLOBAL);
@@ -143,7 +143,7 @@ void HexagonMCELFStreamer::HexagonMCEmitLocalCommonSymbol(MCSymbol *Symbol,
Align ByteAlignment,
unsigned AccessSize) {
getAssembler().registerSymbol(*Symbol);
- auto ELFSymbol = cast<MCSymbolELF>(Symbol);
+ auto ELFSymbol = static_cast<const MCSymbolELF *>(Symbol);
ELFSymbol->setBinding(ELF::STB_LOCAL);
ELFSymbol->setExternal(false);
HexagonMCEmitCommonSymbol(Symbol, Size, ByteAlignment, AccessSize);
diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp
index fb741af..7e021e4 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp
@@ -61,8 +61,8 @@ unsigned LoongArchELFObjectWriter::getRelocType(const MCFixup &Fixup,
case ELF::R_LARCH_TLS_LD_PCREL20_S2:
case ELF::R_LARCH_TLS_GD_PCREL20_S2:
case ELF::R_LARCH_TLS_DESC_PCREL20_S2:
- if (auto *SA = Target.getAddSym())
- cast<MCSymbolELF>(SA)->setType(ELF::STT_TLS);
+ if (auto *SA = const_cast<MCSymbol *>(Target.getAddSym()))
+ static_cast<MCSymbolELF *>(SA)->setType(ELF::STT_TLS);
break;
default:
break;
diff --git a/llvm/lib/Target/M68k/MCTargetDesc/M68kELFObjectWriter.cpp b/llvm/lib/Target/M68k/MCTargetDesc/M68kELFObjectWriter.cpp
index ca94a47..d070409 100644
--- a/llvm/lib/Target/M68k/MCTargetDesc/M68kELFObjectWriter.cpp
+++ b/llvm/lib/Target/M68k/MCTargetDesc/M68kELFObjectWriter.cpp
@@ -70,8 +70,8 @@ unsigned M68kELFObjectWriter::getRelocType(const MCFixup &Fixup,
case M68k::S_TLSLD:
case M68k::S_TLSLDM:
case M68k::S_TPOFF:
- if (auto *SA = Target.getAddSym())
- cast<MCSymbolELF>(SA)->setType(ELF::STT_TLS);
+ if (auto *SA = const_cast<MCSymbol *>(Target.getAddSym()))
+ static_cast<MCSymbolELF *>(SA)->setType(ELF::STT_TLS);
break;
default:
break;
diff --git a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
index 259b71b..7b2ee83 100644
--- a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
+++ b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
@@ -2948,8 +2948,9 @@ bool MipsAsmParser::loadAndAddSymbolAddress(const MCExpr *SymExpr,
bool IsPtr64 = ABI.ArePtrs64bit();
bool IsLocalSym =
Res.getAddSym()->isInSection() || Res.getAddSym()->isTemporary() ||
- (Res.getAddSym()->isELF() &&
- cast<MCSymbolELF>(Res.getAddSym())->getBinding() == ELF::STB_LOCAL);
+ (getContext().isELF() &&
+ static_cast<const MCSymbolELF *>(Res.getAddSym())->getBinding() ==
+ ELF::STB_LOCAL);
// For O32, "$"-prefixed symbols are recognized as temporary while
// .L-prefixed symbols are not (PrivateGlobalPrefix is "$"). Recognize ".L"
// manually.
@@ -6653,7 +6654,7 @@ bool MipsAsmParser::searchSymbolAlias(OperandVector &Operands) {
llvm_unreachable("Should never fail");
}
}
- } else if (Sym->isUnset()) {
+ } else if (Sym->isUndefined()) {
// If symbol is unset, it might be created in the `parseSetAssignment`
// routine as an alias for a numeric register name.
// Lookup in the aliases list.
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
index 7abe9c9..16247bd 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
@@ -166,8 +166,8 @@ unsigned MipsELFObjectWriter::getRelocType(const MCFixup &Fixup,
case Mips::S_GOTTPREL:
case Mips::S_TPREL_HI:
case Mips::S_TPREL_LO:
- if (auto *SA = Target.getAddSym())
- cast<MCSymbolELF>(SA)->setType(ELF::STT_TLS);
+ if (auto *SA = const_cast<MCSymbol *>(Target.getAddSym()))
+ static_cast<MCSymbolELF *>(SA)->setType(ELF::STT_TLS);
break;
default:
break;
@@ -450,6 +450,7 @@ bool MipsELFObjectWriter::needsRelocateWithSymbol(const MCValue &V,
needsRelocateWithSymbol(V, (Type >> 8) & 0xff) ||
needsRelocateWithSymbol(V, (Type >> 16) & 0xff);
+ auto *Sym = static_cast<const MCSymbolELF *>(V.getAddSym());
switch (Type) {
default:
errs() << Type << "\n";
@@ -481,7 +482,7 @@ bool MipsELFObjectWriter::needsRelocateWithSymbol(const MCValue &V,
// FIXME: It should be safe to return false for the STO_MIPS_MICROMIPS but
// we neglect to handle the adjustment to the LSB of the addend that
// it causes in applyFixup() and similar.
- if (cast<MCSymbolELF>(V.getAddSym())->getOther() & ELF::STO_MIPS_MICROMIPS)
+ if (Sym->getOther() & ELF::STO_MIPS_MICROMIPS)
return true;
return false;
@@ -492,7 +493,7 @@ bool MipsELFObjectWriter::needsRelocateWithSymbol(const MCValue &V,
case ELF::R_MIPS_16:
case ELF::R_MIPS_32:
case ELF::R_MIPS_GPREL32:
- if (cast<MCSymbolELF>(V.getAddSym())->getOther() & ELF::STO_MIPS_MICROMIPS)
+ if (Sym->getOther() & ELF::STO_MIPS_MICROMIPS)
return true;
[[fallthrough]];
case ELF::R_MIPS_26:
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp
index e8b9746..feeadc5e 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp
@@ -76,7 +76,7 @@ void MipsELFStreamer::createPendingLabelRelocs() {
// FIXME: Also mark labels when in MIPS16 mode.
if (ELFTargetStreamer->isMicroMipsEnabled()) {
for (auto *L : Labels) {
- auto *Label = cast<MCSymbolELF>(L);
+ auto *Label = static_cast<MCSymbolELF *>(L);
getAssembler().registerSymbol(*Label);
Label->setOther(ELF::STO_MIPS_MICROMIPS);
}
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
index 7a8395a..5df70c4 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
@@ -931,7 +931,7 @@ MipsTargetELFStreamer::MipsTargetELFStreamer(MCStreamer &S,
}
void MipsTargetELFStreamer::emitLabel(MCSymbol *S) {
- auto *Symbol = cast<MCSymbolELF>(S);
+ auto *Symbol = static_cast<MCSymbolELF *>(S);
getStreamer().getAssembler().registerSymbol(*Symbol);
uint8_t Type = Symbol->getType();
if (Type != ELF::STT_FUNC)
@@ -1015,11 +1015,11 @@ void MipsTargetELFStreamer::finish() {
}
void MipsTargetELFStreamer::emitAssignment(MCSymbol *S, const MCExpr *Value) {
- auto *Symbol = cast<MCSymbolELF>(S);
+ auto *Symbol = static_cast<MCSymbolELF *>(S);
// If on rhs is micromips symbol then mark Symbol as microMips.
if (Value->getKind() != MCExpr::SymbolRef)
return;
- const auto &RhsSym = cast<MCSymbolELF>(
+ auto &RhsSym = static_cast<const MCSymbolELF &>(
static_cast<const MCSymbolRefExpr *>(Value)->getSymbol());
if (!(RhsSym.getOther() & ELF::STO_MIPS_MICROMIPS))
diff --git a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
index a2e48ab..4530fc6 100644
--- a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
+++ b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
@@ -1052,8 +1052,7 @@ void MipsAsmPrinter::EmitFPCallStub(
// __call_stub_fp_xxxx:
//
std::string x = "__call_stub_fp_" + std::string(Symbol);
- MCSymbolELF *Stub =
- cast<MCSymbolELF>(OutContext.getOrCreateSymbol(StringRef(x)));
+ MCSymbol *Stub = OutContext.getOrCreateSymbol(StringRef(x));
TS.emitDirectiveEnt(*Stub);
MCSymbol *MType =
OutContext.getOrCreateSymbol("__call_stub_fp_" + Twine(Symbol));
diff --git a/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp b/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
index 58766b1..1fc475d 100644
--- a/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
+++ b/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
@@ -1756,7 +1756,7 @@ bool PPCAsmParser::parseDirectiveLocalEntry(SMLoc L) {
if (getParser().parseIdentifier(Name))
return Error(L, "expected identifier in '.localentry' directive");
- MCSymbolELF *Sym = cast<MCSymbolELF>(getContext().getOrCreateSymbol(Name));
+ auto *Sym = static_cast<MCSymbolELF *>(getContext().getOrCreateSymbol(Name));
const MCExpr *Expr;
if (parseToken(AsmToken::Comma) ||
diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
index ec97e2e..04b886a 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
@@ -13,6 +13,7 @@
#include "llvm/BinaryFormat/MachO.h"
#include "llvm/MC/MCAsmBackend.h"
#include "llvm/MC/MCAssembler.h"
+#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCELFObjectWriter.h"
#include "llvm/MC/MCMachObjectWriter.h"
#include "llvm/MC/MCObjectWriter.h"
@@ -112,14 +113,15 @@ public:
// to resolve the fixup directly. Emit a relocation and leave
// resolution of the final target address to the linker.
if (const auto *A = Target.getAddSym()) {
- if (const auto *S = dyn_cast<MCSymbolELF>(A)) {
+ if (getContext().isELF()) {
// The "other" values are stored in the last 6 bits of the second
// byte. The traditional defines for STO values assume the full byte
// and thus the shift to pack it.
- unsigned Other = S->getOther() << 2;
+ unsigned Other = static_cast<const MCSymbolELF *>(A)->getOther() << 2;
if ((Other & ELF::STO_PPC64_LOCAL_MASK) != 0)
return true;
- } else if (const auto *S = dyn_cast<MCSymbolXCOFF>(A)) {
+ } else if (getContext().isXCOFF()) {
+ auto *S = static_cast<const MCSymbolXCOFF *>(A);
return !Target.isAbsolute() && S->isExternal() &&
S->getStorageClass() == XCOFF::C_WEAKEXT;
}
diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
index a5d3be4..329ad6e 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
@@ -86,8 +86,8 @@ unsigned PPCELFObjectWriter::getRelocType(const MCFixup &Fixup,
case PPC::S_TPREL_HIGHEST:
case PPC::S_TPREL_HIGHESTA:
case PPC::S_TPREL_LO:
- if (auto *SA = Target.getAddSym())
- cast<MCSymbolELF>(SA)->setType(ELF::STT_TLS);
+ if (auto *SA = const_cast<MCSymbol *>(Target.getAddSym()))
+ static_cast<MCSymbolELF *>(SA)->setType(ELF::STT_TLS);
break;
default:
break;
@@ -499,7 +499,8 @@ bool PPCELFObjectWriter::needsRelocateWithSymbol(const MCValue &V,
// The "other" values are stored in the last 6 bits of the second byte.
// The traditional defines for STO values assume the full byte and thus
// the shift to pack it.
- unsigned Other = cast<MCSymbolELF>(V.getAddSym())->getOther() << 2;
+ unsigned Other =
+ static_cast<const MCSymbolELF *>(V.getAddSym())->getOther() << 2;
return (Other & ELF::STO_PPC64_LOCAL_MASK) != 0;
}
diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp
index 2dbc31f..132d5a4 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp
@@ -65,7 +65,7 @@ void PPCELFStreamer::emitPrefixedInstruction(const MCInst &Inst,
MCFragment *InstructionFragment = getCurrentFragment();
SMLoc InstLoc = Inst.getLoc();
// Check if there was a last label emitted.
- if (LastLabel && !LastLabel->isUnset() && LastLabelLoc.isValid() &&
+ if (LastLabel && LastLabel->isDefined() && LastLabelLoc.isValid() &&
InstLoc.isValid()) {
const SourceMgr *SourceManager = getContext().getSourceManager();
unsigned InstLine = SourceManager->FindLineNumber(InstLoc);
diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp
index 3dad0e8..d856c3f 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp
@@ -211,7 +211,7 @@ public:
: PPCTargetStreamer(S), OS(OS) {}
void emitTCEntry(const MCSymbol &S, PPCMCExpr::Specifier Kind) override {
- if (const MCSymbolXCOFF *XSym = dyn_cast<MCSymbolXCOFF>(&S)) {
+ if (getContext().isXCOFF()) {
MCSymbolXCOFF *TCSym =
static_cast<const MCSectionXCOFF *>(Streamer.getCurrentSectionOnly())
->getQualNameSymbol();
@@ -225,10 +225,10 @@ public:
if (Kind == PPC::S_AIX_TLSGD || Kind == PPC::S_AIX_TLSGDM ||
Kind == PPC::S_AIX_TLSIE || Kind == PPC::S_AIX_TLSLE ||
Kind == PPC::S_AIX_TLSLD || Kind == PPC::S_AIX_TLSML)
- OS << "\t.tc " << TCSym->getName() << "," << XSym->getName() << "@"
+ OS << "\t.tc " << TCSym->getName() << "," << S.getName() << "@"
<< getContext().getAsmInfo()->getSpecifierName(Kind) << '\n';
else
- OS << "\t.tc " << TCSym->getName() << "," << XSym->getName() << '\n';
+ OS << "\t.tc " << TCSym->getName() << "," << S.getName() << '\n';
if (TCSym->hasRename())
Streamer.emitXCOFFRenameDirective(TCSym, TCSym->getSymbolTableName());
@@ -308,7 +308,7 @@ public:
}
void emitAssignment(MCSymbol *S, const MCExpr *Value) override {
- auto *Symbol = cast<MCSymbolELF>(S);
+ auto *Symbol = static_cast<MCSymbolELF *>(S);
// When encoding an assignment to set symbol A to symbol B, also copy
// the st_other bits encoding the local entry point offset.
@@ -335,7 +335,7 @@ private:
auto *Ref = dyn_cast<const MCSymbolRefExpr>(S);
if (!Ref)
return false;
- const auto &RhsSym = cast<MCSymbolELF>(Ref->getSymbol());
+ auto &RhsSym = static_cast<const MCSymbolELF &>(Ref->getSymbol());
unsigned Other = D->getOther();
Other &= ~ELF::STO_PPC64_LOCAL_MASK;
Other |= RhsSym.getOther() & ELF::STO_PPC64_LOCAL_MASK;
diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
index ce1d51a..2ab2c14 100644
--- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -2155,7 +2155,8 @@ void PPCLinuxAsmPrinter::emitFunctionBodyStart() {
PPCTargetStreamer *TS =
static_cast<PPCTargetStreamer *>(OutStreamer->getTargetStreamer());
- TS->emitLocalEntry(cast<MCSymbolELF>(CurrentFnSym), LocalOffsetExp);
+ TS->emitLocalEntry(static_cast<MCSymbolELF *>(CurrentFnSym),
+ LocalOffsetExp);
} else if (Subtarget->isUsingPCRelativeCalls()) {
// When generating the entry point for a function we have a few scenarios
// based on whether or not that function uses R2 and whether or not that
@@ -2182,7 +2183,7 @@ void PPCLinuxAsmPrinter::emitFunctionBodyStart() {
MF->hasInlineAsm() || (!PPCFI->usesTOCBasePtr() && UsesX2OrR2)) {
PPCTargetStreamer *TS =
static_cast<PPCTargetStreamer *>(OutStreamer->getTargetStreamer());
- TS->emitLocalEntry(cast<MCSymbolELF>(CurrentFnSym),
+ TS->emitLocalEntry(static_cast<MCSymbolELF *>(CurrentFnSym),
MCConstantExpr::create(1, OutContext));
}
}
@@ -2766,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);
@@ -2859,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()])
@@ -2994,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));
@@ -3112,7 +3114,7 @@ bool PPCAIXAsmPrinter::doInitialization(Module &M) {
setCsectAlignment(&G);
std::optional<CodeModel::Model> OptionalCodeModel = G.getCodeModel();
if (OptionalCodeModel)
- setOptionalCodeModel(cast<MCSymbolXCOFF>(getSymbol(&G)),
+ setOptionalCodeModel(static_cast<MCSymbolXCOFF *>(getSymbol(&G)),
*OptionalCodeModel);
}
@@ -3139,7 +3141,7 @@ bool PPCAIXAsmPrinter::doInitialization(Module &M) {
if (GVar) {
std::optional<CodeModel::Model> OptionalCodeModel = GVar->getCodeModel();
if (OptionalCodeModel)
- setOptionalCodeModel(cast<MCSymbolXCOFF>(getSymbol(&Alias)),
+ setOptionalCodeModel(static_cast<MCSymbolXCOFF *>(getSymbol(&Alias)),
*OptionalCodeModel);
}
@@ -3190,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);
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
index eb7460e..95ec42f 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
@@ -743,7 +743,7 @@ std::optional<bool> RISCVAsmBackend::evaluateFixup(const MCFragment &,
if (!AUIPCTarget.getAddSym())
return false;
- const MCSymbolELF &SA = cast<MCSymbolELF>(*AUIPCTarget.getAddSym());
+ auto &SA = static_cast<const MCSymbolELF &>(*AUIPCTarget.getAddSym());
if (SA.isUndefined())
return false;
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
index 9bf7896..2885e3c 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
@@ -55,8 +55,8 @@ unsigned RISCVELFObjectWriter::getRelocType(const MCFixup &Fixup,
case ELF::R_RISCV_TLS_GOT_HI20:
case ELF::R_RISCV_TLS_GD_HI20:
case ELF::R_RISCV_TLSDESC_HI20:
- if (auto *SA = Target.getAddSym())
- cast<MCSymbolELF>(SA)->setType(ELF::STT_TLS);
+ if (auto *SA = const_cast<MCSymbol *>(Target.getAddSym()))
+ static_cast<MCSymbolELF *>(SA)->setType(ELF::STT_TLS);
break;
case ELF::R_RISCV_PLT32:
case ELF::R_RISCV_GOT32_PCREL:
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
index c654fd2b..543c4c5 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
@@ -117,7 +117,7 @@ void RISCVTargetELFStreamer::reset() {
void RISCVTargetELFStreamer::emitDirectiveVariantCC(MCSymbol &Symbol) {
getStreamer().getAssembler().registerSymbol(Symbol);
- cast<MCSymbolELF>(Symbol).setOther(ELF::STO_RISCV_VARIANT_CC);
+ static_cast<MCSymbolELF &>(Symbol).setOther(ELF::STO_RISCV_VARIANT_CC);
}
void RISCVELFStreamer::reset() {
@@ -142,7 +142,8 @@ void RISCVELFStreamer::emitInstructionsMappingSymbol() {
}
void RISCVELFStreamer::emitMappingSymbol(StringRef Name) {
- auto *Symbol = cast<MCSymbolELF>(getContext().createLocalSymbol(Name));
+ auto *Symbol =
+ static_cast<MCSymbolELF *>(getContext().createLocalSymbol(Name));
emitLabel(Symbol);
Symbol->setType(ELF::STT_NOTYPE);
Symbol->setBinding(ELF::STB_LOCAL);
diff --git a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
index 947b574..9f55330 100644
--- a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
@@ -1458,6 +1458,24 @@ static void createSaturatedConversionDecoration(Instruction *I,
createDecorationIntrinsic(I, SaturatedConversionNode, B);
}
+static void addSaturatedDecorationToIntrinsic(Instruction *I, IRBuilder<> &B) {
+ if (auto *CI = dyn_cast<CallInst>(I)) {
+ if (Function *Fu = CI->getCalledFunction()) {
+ if (Fu->isIntrinsic()) {
+ unsigned const int IntrinsicId = Fu->getIntrinsicID();
+ switch (IntrinsicId) {
+ case Intrinsic::fptosi_sat:
+ case Intrinsic::fptoui_sat:
+ createSaturatedConversionDecoration(I, B);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ }
+}
+
Instruction *SPIRVEmitIntrinsics::visitCallInst(CallInst &Call) {
if (!Call.isInlineAsm())
return &Call;
@@ -2640,6 +2658,7 @@ bool SPIRVEmitIntrinsics::runOnFunction(Function &Func) {
if (isConvergenceIntrinsic(I))
continue;
+ addSaturatedDecorationToIntrinsic(I, B);
processInstrAfterVisit(I, B);
}
diff --git a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
index d4fa62a..e9f5ffa 100644
--- a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
@@ -665,6 +665,11 @@ bool SPIRVInstructionSelector::spvSelect(Register ResVReg,
case TargetOpcode::G_FPTOUI:
return selectUnOp(ResVReg, ResType, I, SPIRV::OpConvertFToU);
+ case TargetOpcode::G_FPTOSI_SAT:
+ return selectUnOp(ResVReg, ResType, I, SPIRV::OpConvertFToS);
+ case TargetOpcode::G_FPTOUI_SAT:
+ return selectUnOp(ResVReg, ResType, I, SPIRV::OpConvertFToU);
+
case TargetOpcode::G_SITOFP:
return selectIToF(ResVReg, ResType, I, true, SPIRV::OpConvertSToF);
case TargetOpcode::G_UITOFP:
diff --git a/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp b/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp
index 1995e0f..170bddd 100644
--- a/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp
@@ -203,6 +203,10 @@ SPIRVLegalizerInfo::SPIRVLegalizerInfo(const SPIRVSubtarget &ST) {
.legalForCartesianProduct(allIntScalarsAndVectors,
allFloatScalarsAndVectors);
+ getActionDefinitionsBuilder({G_FPTOSI_SAT, G_FPTOUI_SAT})
+ .legalForCartesianProduct(allIntScalarsAndVectors,
+ allFloatScalarsAndVectors);
+
getActionDefinitionsBuilder({G_SITOFP, G_UITOFP})
.legalForCartesianProduct(allFloatScalarsAndVectors,
allScalarsAndVectors);
diff --git a/llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp b/llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp
index a95c4ff..d2071c3 100644
--- a/llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp
+++ b/llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp
@@ -58,8 +58,8 @@ unsigned SparcELFObjectWriter::getRelocType(const MCFixup &Fixup,
case ELF::R_SPARC_TLS_IE_ADD:
case ELF::R_SPARC_TLS_LE_HIX22:
case ELF::R_SPARC_TLS_LE_LOX10:
- if (auto *SA = Target.getAddSym())
- cast<MCSymbolELF>(SA)->setType(ELF::STT_TLS);
+ if (auto *SA = const_cast<MCSymbol *>(Target.getAddSym()))
+ static_cast<MCSymbolELF *>(SA)->setType(ELF::STT_TLS);
break;
default:
break;
diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp
index 8b5587a..1bca5c7 100644
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp
@@ -111,8 +111,8 @@ unsigned SystemZELFObjectWriter::getRelocType(const MCFixup &Fixup,
case SystemZ::S_TLSLD:
case SystemZ::S_TLSLDM:
case SystemZ::S_DTPOFF:
- if (auto *SA = Target.getAddSym())
- cast<MCSymbolELF>(SA)->setType(ELF::STT_TLS);
+ if (auto *SA = const_cast<MCSymbol *>(Target.getAddSym()))
+ static_cast<MCSymbolELF *>(SA)->setType(ELF::STT_TLS);
break;
default:
break;
diff --git a/llvm/lib/Target/VE/MCTargetDesc/VEELFObjectWriter.cpp b/llvm/lib/Target/VE/MCTargetDesc/VEELFObjectWriter.cpp
index 41f31eb..c702064 100644
--- a/llvm/lib/Target/VE/MCTargetDesc/VEELFObjectWriter.cpp
+++ b/llvm/lib/Target/VE/MCTargetDesc/VEELFObjectWriter.cpp
@@ -44,8 +44,8 @@ unsigned VEELFObjectWriter::getRelocType(const MCFixup &Fixup,
case VE::S_TLS_GD_LO32:
case VE::S_TPOFF_HI32:
case VE::S_TPOFF_LO32:
- if (auto *SA = Target.getAddSym())
- cast<MCSymbolELF>(SA)->setType(ELF::STT_TLS);
+ if (auto *SA = const_cast<MCSymbol *>(Target.getAddSym()))
+ static_cast<MCSymbolELF *>(SA)->setType(ELF::STT_TLS);
break;
default:
break;
diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
index 6ae69a4..80df4ed 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -212,12 +212,12 @@ static wasm::WasmLimits defaultLimits() {
static MCSymbolWasm *getOrCreateFunctionTableSymbol(MCContext &Ctx,
const StringRef &Name,
bool Is64) {
- MCSymbolWasm *Sym = cast_or_null<MCSymbolWasm>(Ctx.lookupSymbol(Name));
+ auto *Sym = static_cast<MCSymbolWasm *>(Ctx.lookupSymbol(Name));
if (Sym) {
if (!Sym->isFunctionTable())
Ctx.reportError(SMLoc(), "symbol is not a wasm funcref table");
} else {
- Sym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(Name));
+ Sym = static_cast<MCSymbolWasm *>(Ctx.getOrCreateSymbol(Name));
Sym->setFunctionTable(Is64);
// The default function table is synthesized by the linker.
Sym->setUndefined();
@@ -703,7 +703,7 @@ public:
ExpectBlockType = false;
// The "true" here will cause this to be a nameless symbol.
MCSymbol *Sym = Ctx.createTempSymbol("typeindex", true);
- auto *WasmSym = cast<MCSymbolWasm>(Sym);
+ auto *WasmSym = static_cast<MCSymbolWasm *>(Sym);
WasmSym->setSignature(Signature);
WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);
const MCExpr *Expr =
@@ -949,7 +949,8 @@ public:
return error("Unknown type in .globaltype modifier: ", TypeTok);
}
// Now set this symbol with the correct type.
- auto *WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
+ auto *WasmSym =
+ static_cast<MCSymbolWasm *>(Ctx.getOrCreateSymbol(SymName));
WasmSym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL);
WasmSym->setGlobalType(wasm::WasmGlobalType{uint8_t(*Type), Mutable});
// And emit the directive again.
@@ -980,7 +981,8 @@ public:
// Now that we have the name and table type, we can actually create the
// symbol
- auto *WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
+ auto *WasmSym =
+ static_cast<MCSymbolWasm *>(Ctx.getOrCreateSymbol(SymName));
WasmSym->setType(wasm::WASM_SYMBOL_TYPE_TABLE);
if (Is64) {
Limits.Flags |= wasm::WASM_LIMITS_FLAG_IS_64;
@@ -1000,7 +1002,8 @@ public:
auto SymName = expectIdent();
if (SymName.empty())
return ParseStatus::Failure;
- auto *WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
+ auto *WasmSym =
+ static_cast<MCSymbolWasm *>(Ctx.getOrCreateSymbol(SymName));
if (WasmSym->isDefined()) {
// We push 'Function' either when a label is parsed or a .functype
// directive is parsed. The reason it is not easy to do this uniformly
@@ -1042,7 +1045,8 @@ public:
auto ExportName = expectIdent();
if (ExportName.empty())
return ParseStatus::Failure;
- auto *WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
+ auto *WasmSym =
+ static_cast<MCSymbolWasm *>(Ctx.getOrCreateSymbol(SymName));
WasmSym->setExportName(Ctx.allocateString(ExportName));
TOut.emitExportName(WasmSym, ExportName);
return expect(AsmToken::EndOfStatement, "EOL");
@@ -1057,7 +1061,8 @@ public:
auto ImportModule = expectIdent();
if (ImportModule.empty())
return ParseStatus::Failure;
- auto *WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
+ auto *WasmSym =
+ static_cast<MCSymbolWasm *>(Ctx.getOrCreateSymbol(SymName));
WasmSym->setImportModule(Ctx.allocateString(ImportModule));
TOut.emitImportModule(WasmSym, ImportModule);
return expect(AsmToken::EndOfStatement, "EOL");
@@ -1072,7 +1077,8 @@ public:
auto ImportName = expectIdent();
if (ImportName.empty())
return ParseStatus::Failure;
- auto *WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
+ auto *WasmSym =
+ static_cast<MCSymbolWasm *>(Ctx.getOrCreateSymbol(SymName));
WasmSym->setImportName(Ctx.allocateString(ImportName));
TOut.emitImportName(WasmSym, ImportName);
return expect(AsmToken::EndOfStatement, "EOL");
@@ -1082,7 +1088,8 @@ public:
auto SymName = expectIdent();
if (SymName.empty())
return ParseStatus::Failure;
- auto *WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
+ auto *WasmSym =
+ static_cast<MCSymbolWasm *>(Ctx.getOrCreateSymbol(SymName));
auto *Signature = Ctx.createWasmSignature();
if (parseRegTypeList(Signature->Params))
return ParseStatus::Failure;
@@ -1224,7 +1231,7 @@ public:
if (!CWS->isText())
return;
- auto *WasmSym = cast<MCSymbolWasm>(Symbol);
+ auto *WasmSym = static_cast<MCSymbolWasm *>(Symbol);
// Unlike other targets, we don't allow data in text sections (labels
// declared with .type @object).
if (WasmSym->getType() == wasm::WASM_SYMBOL_TYPE_DATA) {
diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
index 4a305ab..6943888 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
@@ -258,7 +258,7 @@ bool WebAssemblyAsmTypeCheck::getGlobal(SMLoc ErrorLoc,
const MCSymbolRefExpr *SymRef;
if (getSymRef(ErrorLoc, GlobalOp, SymRef))
return true;
- const auto *WasmSym = cast<MCSymbolWasm>(&SymRef->getSymbol());
+ auto *WasmSym = static_cast<const MCSymbolWasm *>(&SymRef->getSymbol());
switch (WasmSym->getType().value_or(wasm::WASM_SYMBOL_TYPE_DATA)) {
case wasm::WASM_SYMBOL_TYPE_GLOBAL:
Type = static_cast<wasm::ValType>(WasmSym->getGlobalType().Type);
@@ -286,7 +286,7 @@ bool WebAssemblyAsmTypeCheck::getTable(SMLoc ErrorLoc, const MCOperand &TableOp,
const MCSymbolRefExpr *SymRef;
if (getSymRef(ErrorLoc, TableOp, SymRef))
return true;
- const auto *WasmSym = cast<MCSymbolWasm>(&SymRef->getSymbol());
+ auto *WasmSym = static_cast<const MCSymbolWasm *>(&SymRef->getSymbol());
if (WasmSym->getType().value_or(wasm::WASM_SYMBOL_TYPE_DATA) !=
wasm::WASM_SYMBOL_TYPE_TABLE)
return typeError(ErrorLoc, StringRef("symbol ") + WasmSym->getName() +
@@ -302,7 +302,7 @@ bool WebAssemblyAsmTypeCheck::getSignature(SMLoc ErrorLoc,
const MCSymbolRefExpr *SymRef = nullptr;
if (getSymRef(ErrorLoc, SigOp, SymRef))
return true;
- const auto *WasmSym = cast<MCSymbolWasm>(&SymRef->getSymbol());
+ auto *WasmSym = static_cast<const MCSymbolWasm *>(&SymRef->getSymbol());
Sig = WasmSym->getSignature();
if (!Sig || WasmSym->getType() != Type) {
diff --git a/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp b/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
index 0f7b27b..2a398d4 100644
--- a/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
+++ b/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
@@ -237,7 +237,7 @@ MCDisassembler::DecodeStatus WebAssemblyDisassembler::getInstruction(
} else {
// We don't have access to the signature, so create a symbol without one
MCSymbol *Sym = getContext().createTempSymbol("typeindex", true);
- auto *WasmSym = cast<MCSymbolWasm>(Sym);
+ auto *WasmSym = static_cast<MCSymbolWasm *>(Sym);
WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);
const MCExpr *Expr = MCSymbolRefExpr::create(
WasmSym, WebAssembly::S_TYPEINDEX, getContext());
diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp
index 2e97215..d8bfed9 100644
--- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp
+++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp
@@ -380,7 +380,7 @@ void WebAssemblyInstPrinter::printWebAssemblySignatureOperand(const MCInst *MI,
O << WebAssembly::anyTypeToString(Imm);
} else {
auto Expr = cast<MCSymbolRefExpr>(Op.getExpr());
- auto *Sym = cast<MCSymbolWasm>(&Expr->getSymbol());
+ auto *Sym = static_cast<const MCSymbolWasm *>(&Expr->getSymbol());
if (Sym->getSignature()) {
O << WebAssembly::signatureToString(Sym->getSignature());
} else {
@@ -398,10 +398,10 @@ void WebAssemblyInstPrinter::printCatchList(const MCInst *MI, unsigned OpNo,
auto PrintTagOp = [&](const MCOperand &Op) {
const MCSymbolRefExpr *TagExpr = nullptr;
- const MCSymbolWasm *TagSym = nullptr;
+ const MCSymbol *TagSym = nullptr;
if (Op.isExpr()) {
TagExpr = cast<MCSymbolRefExpr>(Op.getExpr());
- TagSym = cast<MCSymbolWasm>(&TagExpr->getSymbol());
+ TagSym = &TagExpr->getSymbol();
O << TagSym->getName() << " ";
} else {
// When instructions are parsed from the disassembler, we have an
diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
index 2cf4bec..ffbc7e1 100644
--- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
+++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
@@ -66,7 +66,7 @@ static const MCSection *getTargetSection(const MCExpr *Expr) {
unsigned WebAssemblyWasmObjectWriter::getRelocType(
const MCValue &Target, const MCFixup &Fixup,
const MCSectionWasm &FixupSection, bool IsLocRel) const {
- auto &SymA = cast<MCSymbolWasm>(*Target.getAddSym());
+ auto &SymA = static_cast<const MCSymbolWasm &>(*Target.getAddSym());
auto Spec = WebAssembly::Specifier(Target.getSpecifier());
switch (Spec) {
case WebAssembly::S_GOT:
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
index 1bf070e..db832bc 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
@@ -171,10 +171,10 @@ MCSymbolWasm *WebAssemblyAsmPrinter::getMCSymbolForFunction(
WebAssembly::signatureToString(Sig);
report_fatal_error(Twine(Msg));
}
- WasmSym = cast<MCSymbolWasm>(
+ WasmSym = static_cast<MCSymbolWasm *>(
GetExternalSymbolSymbol(getEmscriptenInvokeSymbolName(Sig)));
} else {
- WasmSym = cast<MCSymbolWasm>(getSymbol(F));
+ WasmSym = static_cast<MCSymbolWasm *>(getSymbol(F));
}
return WasmSym;
}
@@ -186,9 +186,7 @@ void WebAssemblyAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
}
assert(!GV->isThreadLocal());
-
- MCSymbolWasm *Sym = cast<MCSymbolWasm>(getSymbol(GV));
-
+ auto *Sym = static_cast<MCSymbolWasm *>(getSymbol(GV));
if (!Sym->getType()) {
SmallVector<MVT, 1> VTs;
Type *GlobalVT = GV->getValueType();
@@ -218,8 +216,7 @@ void WebAssemblyAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
}
MCSymbol *WebAssemblyAsmPrinter::getOrCreateWasmSymbol(StringRef Name) {
- auto *WasmSym = cast<MCSymbolWasm>(GetExternalSymbolSymbol(Name));
-
+ auto *WasmSym = static_cast<MCSymbolWasm *>(GetExternalSymbolSymbol(Name));
// May be called multiple times, so early out.
if (WasmSym->getType())
return WasmSym;
@@ -312,7 +309,7 @@ void WebAssemblyAsmPrinter::emitDecls(const Module &M) {
// not be found here.
MachineModuleInfoWasm &MMIW = MMI->getObjFileInfo<MachineModuleInfoWasm>();
for (StringRef Name : MMIW.MachineSymbolsUsed) {
- auto *WasmSym = cast<MCSymbolWasm>(getOrCreateWasmSymbol(Name));
+ auto *WasmSym = static_cast<MCSymbolWasm *>(getOrCreateWasmSymbol(Name));
if (WasmSym->isFunction()) {
// TODO(wvo): is there any case where this overlaps with the call to
// emitFunctionType in the loop below?
@@ -324,7 +321,7 @@ void WebAssemblyAsmPrinter::emitDecls(const Module &M) {
// Emit .globaltype, .tagtype, or .tabletype declarations for extern
// declarations, i.e. those that have only been declared (but not defined)
// in the current module
- auto Sym = cast_or_null<MCSymbolWasm>(It.getValue().Symbol);
+ auto Sym = static_cast<MCSymbolWasm *>(It.getValue().Symbol);
if (Sym && !Sym->isDefined())
emitSymbolType(Sym);
}
@@ -381,7 +378,7 @@ void WebAssemblyAsmPrinter::emitDecls(const Module &M) {
}
if (F.hasFnAttribute("wasm-export-name")) {
- auto *Sym = cast<MCSymbolWasm>(getSymbol(&F));
+ auto *Sym = static_cast<MCSymbolWasm *>(getSymbol(&F));
StringRef Name = F.getFnAttribute("wasm-export-name").getValueAsString();
Sym->setExportName(OutContext.allocateString(Name));
getTargetStreamer()->emitExportName(Sym, Name);
@@ -581,7 +578,7 @@ void WebAssemblyAsmPrinter::EmitFunctionAttributes(Module &M) {
auto *GV = cast<GlobalVariable>(CS->getOperand(1)->stripPointerCasts());
StringRef AnnotationString;
getConstantStringInfo(GV, AnnotationString);
- auto *Sym = cast<MCSymbolWasm>(getSymbol(F));
+ auto *Sym = static_cast<MCSymbolWasm *>(getSymbol(F));
CustomSections[AnnotationString].push_back(Sym);
}
@@ -618,7 +615,7 @@ void WebAssemblyAsmPrinter::emitFunctionBodyStart() {
computeSignatureVTs(F.getFunctionType(), &F, F, TM, ParamVTs, ResultVTs);
auto Signature = signatureFromMVTs(OutContext, ResultVTs, ParamVTs);
- auto *WasmSym = cast<MCSymbolWasm>(CurrentFnSym);
+ auto *WasmSym = static_cast<MCSymbolWasm *>(CurrentFnSym);
WasmSym->setSignature(Signature);
WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
index 4613fcb..e48283a 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
@@ -52,7 +52,7 @@ MCSymbol *
WebAssemblyMCInstLower::GetGlobalAddressSymbol(const MachineOperand &MO) const {
const GlobalValue *Global = MO.getGlobal();
if (!isa<Function>(Global)) {
- auto *WasmSym = cast<MCSymbolWasm>(Printer.getSymbol(Global));
+ auto *WasmSym = static_cast<MCSymbolWasm *>(Printer.getSymbol(Global));
// If the symbol doesn't have an explicit WasmSymbolType yet and the
// GlobalValue is actually a WebAssembly global, then ensure the symbol is a
// WASM_SYMBOL_TYPE_GLOBAL.
@@ -123,7 +123,7 @@ MCOperand WebAssemblyMCInstLower::lowerSymbolOperand(const MachineOperand &MO,
const MCExpr *Expr = MCSymbolRefExpr::create(Sym, Spec, Ctx);
if (MO.getOffset() != 0) {
- const auto *WasmSym = cast<MCSymbolWasm>(Sym);
+ const auto *WasmSym = static_cast<const MCSymbolWasm *>(Sym);
if (TargetFlags == WebAssemblyII::MO_GOT)
report_fatal_error("GOT symbol references do not support offsets");
if (WasmSym->isFunction())
@@ -148,12 +148,12 @@ MCOperand WebAssemblyMCInstLower::lowerTypeIndexOperand(
auto Signature = Ctx.createWasmSignature();
Signature->Returns = std::move(Returns);
Signature->Params = std::move(Params);
- MCSymbol *Sym = Printer.createTempSymbol("typeindex");
- auto *WasmSym = cast<MCSymbolWasm>(Sym);
- WasmSym->setSignature(Signature);
- WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);
+ auto *Sym =
+ static_cast<MCSymbolWasm *>(Printer.createTempSymbol("typeindex"));
+ Sym->setSignature(Signature);
+ Sym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);
const MCExpr *Expr =
- MCSymbolRefExpr::create(WasmSym, WebAssembly::S_TYPEINDEX, Ctx);
+ MCSymbolRefExpr::create(Sym, WebAssembly::S_TYPEINDEX, Ctx);
return MCOperand::createExpr(Expr);
}
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyUtilities.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyUtilities.cpp
index 747ef18..42d1271 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyUtilities.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyUtilities.cpp
@@ -104,13 +104,13 @@ const MachineOperand &WebAssembly::getCalleeOp(const MachineInstr &MI) {
MCSymbolWasm *WebAssembly::getOrCreateFunctionTableSymbol(
MCContext &Ctx, const WebAssemblySubtarget *Subtarget) {
StringRef Name = "__indirect_function_table";
- MCSymbolWasm *Sym = cast_or_null<MCSymbolWasm>(Ctx.lookupSymbol(Name));
+ auto *Sym = static_cast<MCSymbolWasm *>(Ctx.lookupSymbol(Name));
if (Sym) {
if (!Sym->isFunctionTable())
Ctx.reportError(SMLoc(), "symbol is not a wasm funcref table");
} else {
bool is64 = Subtarget && Subtarget->getTargetTriple().isArch64Bit();
- Sym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(Name));
+ Sym = static_cast<MCSymbolWasm *>(Ctx.getOrCreateSymbol(Name));
Sym->setFunctionTable(is64);
// The default function table is synthesized by the linker.
Sym->setUndefined();
@@ -124,12 +124,12 @@ MCSymbolWasm *WebAssembly::getOrCreateFunctionTableSymbol(
MCSymbolWasm *WebAssembly::getOrCreateFuncrefCallTableSymbol(
MCContext &Ctx, const WebAssemblySubtarget *Subtarget) {
StringRef Name = "__funcref_call_table";
- MCSymbolWasm *Sym = cast_or_null<MCSymbolWasm>(Ctx.lookupSymbol(Name));
+ auto *Sym = static_cast<MCSymbolWasm *>(Ctx.lookupSymbol(Name));
if (Sym) {
if (!Sym->isFunctionTable())
Ctx.reportError(SMLoc(), "symbol is not a wasm funcref table");
} else {
- Sym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(Name));
+ Sym = static_cast<MCSymbolWasm *>(Ctx.getOrCreateSymbol(Name));
// Setting Weak ensure only one table is left after linking when multiple
// modules define the table.
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
index 1f02e56..56a4cc3 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
@@ -511,9 +511,8 @@ void X86AsmBackend::emitInstructionBegin(MCObjectStreamer &OS,
isFirstMacroFusibleInst(Inst, *MCII))) {
// If we meet a unfused branch or the first instuction in a fusiable pair,
// insert a BoundaryAlign fragment.
- PendingBA = OS.getContext().allocFragment<MCBoundaryAlignFragment>(
- AlignBoundary, STI);
- OS.insert(PendingBA);
+ PendingBA =
+ OS.newSpecialFragment<MCBoundaryAlignFragment>(AlignBoundary, STI);
}
}
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp
index 3323b38..ea0abdd 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp
@@ -349,8 +349,8 @@ unsigned X86ELFObjectWriter::getRelocType(const MCFixup &Fixup,
case X86::S_TLSLDM:
case X86::S_TPOFF:
case X86::S_DTPOFF:
- if (auto *S = Target.getAddSym())
- cast<MCSymbolELF>(S)->setType(ELF::STT_TLS);
+ if (auto *S = const_cast<MCSymbol *>(Target.getAddSym()))
+ static_cast<MCSymbolELF *>(S)->setType(ELF::STT_TLS);
break;
default:
break;
diff --git a/llvm/lib/Transforms/Scalar/GVNSink.cpp b/llvm/lib/Transforms/Scalar/GVNSink.cpp
index a5fc0b4..1c88532 100644
--- a/llvm/lib/Transforms/Scalar/GVNSink.cpp
+++ b/llvm/lib/Transforms/Scalar/GVNSink.cpp
@@ -308,7 +308,7 @@ public:
for (auto &U : I->uses())
op_push_back(U.getUser());
- llvm::sort(op_begin(), op_end());
+ llvm::sort(operands());
}
void setMemoryUseOrder(unsigned MUO) { MemoryUseOrder = MUO; }
diff --git a/llvm/lib/Transforms/Utils/ProfileVerify.cpp b/llvm/lib/Transforms/Utils/ProfileVerify.cpp
index b972132..d67192f 100644
--- a/llvm/lib/Transforms/Utils/ProfileVerify.cpp
+++ b/llvm/lib/Transforms/Utils/ProfileVerify.cpp
@@ -20,8 +20,12 @@
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/ProfDataUtils.h"
#include "llvm/Support/BranchProbability.h"
+#include "llvm/Support/CommandLine.h"
using namespace llvm;
+static cl::opt<int64_t>
+ DefaultFunctionEntryCount("profcheck-default-function-entry-count",
+ cl::init(1000));
namespace {
class ProfileInjector {
Function &F;
@@ -63,6 +67,19 @@ bool ProfileInjector::inject() {
// will get the same BPI it does if the injector wasn't running.
auto &BPI = FAM.getResult<BranchProbabilityAnalysis>(F);
+ // Inject a function count if there's none. It's reasonable for a pass to
+ // want to clear the MD_prof of a function with zero entry count. If the
+ // original profile (iFDO or AFDO) is empty for a function, it's simpler to
+ // require assigning it the 0-entry count explicitly than to mark every branch
+ // as cold (we do want some explicit information in the spirit of what this
+ // verifier wants to achieve - make dropping / corrupting MD_prof
+ // unit-testable)
+ if (!F.getEntryCount(/*AllowSynthetic=*/true))
+ F.setEntryCount(DefaultFunctionEntryCount);
+ // If there is an entry count that's 0, then don't bother injecting. We won't
+ // verify these either.
+ if (F.getEntryCount(/*AllowSynthetic=*/true)->getCount() == 0)
+ return false;
bool Changed = false;
for (auto &BB : F) {
auto *Term = getTerminatorBenefitingFromMDProf(BB);
@@ -119,11 +136,20 @@ PreservedAnalyses ProfileInjectorPass::run(Function &F,
PreservedAnalyses ProfileVerifierPass::run(Function &F,
FunctionAnalysisManager &FAM) {
+ const auto EntryCount = F.getEntryCount(/*AllowSynthetic=*/true);
+ if (!EntryCount) {
+ F.getContext().emitError("Profile verification failed: function entry "
+ "count missing (set to 0 if cold)");
+ return PreservedAnalyses::all();
+ }
+ if (EntryCount->getCount() == 0)
+ return PreservedAnalyses::all();
for (const auto &BB : F)
if (const auto *Term =
ProfileInjector::getTerminatorBenefitingFromMDProf(BB))
if (!Term->getMetadata(LLVMContext::MD_prof))
- F.getContext().emitError("Profile verification failed");
+ F.getContext().emitError(
+ "Profile verification failed: branch annotation missing");
- return PreservedAnalyses::none();
+ return PreservedAnalyses::all();
}