Reuse it for RISCVAsmBackend.cpp.
While there make the function return a pair of MCFixupKind to
remove static_casts elsewhere.
Reviewed By: reames
Differential Revision: https://reviews.llvm.org/D142955
}
unsigned Offset;
- std::pair<unsigned, unsigned> Fixup;
+ std::pair<MCFixupKind, MCFixupKind> Fixup;
// According to the DWARF specification, the `DW_LNS_fixed_advance_pc` opcode
// takes a single unsigned half (unencoded) operand. The maximum encodable
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<uint16_t>(OS, 0, support::little);
}
const MCBinaryExpr &MBE = cast<MCBinaryExpr>(AddrDelta);
- Fixups.push_back(MCFixup::create(
- Offset, MBE.getLHS(), static_cast<MCFixupKind>(std::get<0>(Fixup))));
- Fixups.push_back(MCFixup::create(
- Offset, MBE.getRHS(), static_cast<MCFixupKind>(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);
cast<MCSymbolELF>(Symbol).setOther(ELF::STO_RISCV_VARIANT_CC);
}
-std::pair<unsigned, unsigned>
-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<MCBinaryExpr>(Value);
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<MCFixupKind>(Add), Loc));
- DF->getFixups().push_back(MCFixup::create(
- DF->getContents().size(), B, static_cast<MCFixupKind>(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);
}
using namespace llvm;
class RISCVELFStreamer : public MCELFStreamer {
- static std::pair<unsigned, unsigned> getRelocPairForSize(unsigned Size);
static bool requiresFixups(MCContext &C, const MCExpr *Value,
const MCExpr *&LHS, const MCExpr *&RHS);
void reset() override;
#define LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVFIXUPKINDS_H
#include "llvm/MC/MCFixup.h"
+#include <utility>
#undef RISCV
fixup_riscv_invalid,
NumTargetFixupKinds = fixup_riscv_invalid - FirstTargetFixupKind
};
+
+static inline std::pair<MCFixupKind, MCFixupKind>
+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