[llvm] b0cb5cb - [RISCV] Move RISCVELFStreamer::getRelocPairForSize to RISCVFixUpKinds.h and reuse it. NFC
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 31 13:14:35 PST 2023
Author: Craig Topper
Date: 2023-01-31T13:10:13-08:00
New Revision: b0cb5cb64d639a7829443ed3063b55802e4a879d
URL: https://github.com/llvm/llvm-project/commit/b0cb5cb64d639a7829443ed3063b55802e4a879d
DIFF: https://github.com/llvm/llvm-project/commit/b0cb5cb64d639a7829443ed3063b55802e4a879d.diff
LOG: [RISCV] Move RISCVELFStreamer::getRelocPairForSize to RISCVFixUpKinds.h and reuse it. NFC
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
Added:
Modified:
llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h
llvm/lib/Target/RISCV/MCTargetDesc/RISCVFixupKinds.h
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
index 892c406f1e684..56c2a0de5bcd1 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
@@ -210,7 +210,7 @@ bool RISCVAsmBackend::relaxDwarfLineAddr(MCDwarfLineAddrFragment &DF,
}
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
@@ -223,23 +223,19 @@ bool RISCVAsmBackend::relaxDwarfLineAddr(MCDwarfLineAddrFragment &DF,
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);
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
index 379aaa713a00b..f69fc7cb24f72 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
@@ -192,22 +192,6 @@ void RISCVTargetELFStreamer::emitDirectiveVariantCC(MCSymbol &Symbol) {
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);
@@ -261,13 +245,13 @@ void RISCVELFStreamer::emitValueImpl(const MCExpr *Value, unsigned Size,
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);
}
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h
index 7331894f637df..80b8be2ddc2cf 100644
--- 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<unsigned, unsigned> 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/RISCVFixupKinds.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVFixupKinds.h
index 67841d2c8f8cc..d254f3a06e264 100644
--- 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 <utility>
#undef RISCV
@@ -108,6 +109,27 @@ enum Fixups {
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
More information about the llvm-commits
mailing list