diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp @@ -210,7 +210,7 @@ } unsigned Offset; - std::pair Fixup; + std::pair Fixup; // According to the DWARF specification, the `DW_LNS_fixed_advance_pc` opcode // takes a single unsigned half (unencoded) operand. The maximum encodable @@ -223,23 +223,19 @@ OS << uint8_t(dwarf::DW_LNE_set_address); Offset = OS.tell(); - Fixup = PtrSize == 4 ? std::make_pair(RISCV::fixup_riscv_add_32, - RISCV::fixup_riscv_sub_32) - : std::make_pair(RISCV::fixup_riscv_add_64, - RISCV::fixup_riscv_sub_64); + assert((PtrSize == 4 || PtrSize == 8) && "Unexpected pointer size"); + Fixup = RISCV::getRelocPairForSize(PtrSize); OS.write_zeros(PtrSize); } else { OS << uint8_t(dwarf::DW_LNS_fixed_advance_pc); Offset = OS.tell(); - Fixup = {RISCV::fixup_riscv_add_16, RISCV::fixup_riscv_sub_16}; + Fixup = RISCV::getRelocPairForSize(2); support::endian::write(OS, 0, support::little); } const MCBinaryExpr &MBE = cast(AddrDelta); - Fixups.push_back(MCFixup::create( - Offset, MBE.getLHS(), static_cast(std::get<0>(Fixup)))); - Fixups.push_back(MCFixup::create( - Offset, MBE.getRHS(), static_cast(std::get<1>(Fixup)))); + Fixups.push_back(MCFixup::create(Offset, MBE.getLHS(), std::get<0>(Fixup))); + Fixups.push_back(MCFixup::create(Offset, MBE.getRHS(), std::get<1>(Fixup))); if (LineDelta == INT64_MAX) { OS << uint8_t(dwarf::DW_LNS_extended_op); diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h @@ -15,7 +15,6 @@ using namespace llvm; class RISCVELFStreamer : public MCELFStreamer { - static std::pair getRelocPairForSize(unsigned Size); static bool requiresFixups(MCContext &C, const MCExpr *Value, const MCExpr *&LHS, const MCExpr *&RHS); void reset() override; diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp @@ -192,22 +192,6 @@ cast(Symbol).setOther(ELF::STO_RISCV_VARIANT_CC); } -std::pair -RISCVELFStreamer::getRelocPairForSize(unsigned Size) { - switch (Size) { - default: - llvm_unreachable("unsupported fixup size"); - case 1: - return std::make_pair(RISCV::fixup_riscv_add_8, RISCV::fixup_riscv_sub_8); - case 2: - return std::make_pair(RISCV::fixup_riscv_add_16, RISCV::fixup_riscv_sub_16); - case 4: - return std::make_pair(RISCV::fixup_riscv_add_32, RISCV::fixup_riscv_sub_32); - case 8: - return std::make_pair(RISCV::fixup_riscv_add_64, RISCV::fixup_riscv_sub_64); - } -} - bool RISCVELFStreamer::requiresFixups(MCContext &C, const MCExpr *Value, const MCExpr *&LHS, const MCExpr *&RHS) { const auto *MBE = dyn_cast(Value); @@ -261,13 +245,13 @@ flushPendingLabels(DF, DF->getContents().size()); MCDwarfLineEntry::make(this, getCurrentSectionOnly()); - unsigned Add, Sub; - std::tie(Add, Sub) = getRelocPairForSize(Size); + MCFixupKind Add, Sub; + std::tie(Add, Sub) = RISCV::getRelocPairForSize(Size); - DF->getFixups().push_back(MCFixup::create( - DF->getContents().size(), A, static_cast(Add), Loc)); - DF->getFixups().push_back(MCFixup::create( - DF->getContents().size(), B, static_cast(Sub), Loc)); + DF->getFixups().push_back( + MCFixup::create(DF->getContents().size(), A, Add, Loc)); + DF->getFixups().push_back( + MCFixup::create(DF->getContents().size(), B, Sub, Loc)); DF->getContents().resize(DF->getContents().size() + Size, 0); } diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVFixupKinds.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVFixupKinds.h --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVFixupKinds.h +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVFixupKinds.h @@ -10,6 +10,7 @@ #define LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVFIXUPKINDS_H #include "llvm/MC/MCFixup.h" +#include #undef RISCV @@ -108,6 +109,27 @@ fixup_riscv_invalid, NumTargetFixupKinds = fixup_riscv_invalid - FirstTargetFixupKind }; + +static inline std::pair +getRelocPairForSize(unsigned Size) { + switch (Size) { + default: + llvm_unreachable("unsupported fixup size"); + case 1: + return std::make_pair(MCFixupKind(RISCV::fixup_riscv_add_8), + MCFixupKind(RISCV::fixup_riscv_sub_8)); + case 2: + return std::make_pair(MCFixupKind(RISCV::fixup_riscv_add_16), + MCFixupKind(RISCV::fixup_riscv_sub_16)); + case 4: + return std::make_pair(MCFixupKind(RISCV::fixup_riscv_add_32), + MCFixupKind(RISCV::fixup_riscv_sub_32)); + case 8: + return std::make_pair(MCFixupKind(RISCV::fixup_riscv_add_64), + MCFixupKind(RISCV::fixup_riscv_sub_64)); + } +} + } // end namespace llvm::RISCV #endif