Skip to content

Commit c7500a2

Browse files
committed
RISCVAsmBackend: Simplify relaxDwarfLineAddr and remove getRelocPairForSize
Instead of creating two separate fixups, create a single one. Leverage RISCVAsmBackend::addReloc to generate ADD/SUB relocation pairs. In a future change MCFragment::setVarFixup may be restricted to a single fixup.
1 parent a585d57 commit c7500a2

File tree

2 files changed

+8
-40
lines changed

2 files changed

+8
-40
lines changed

llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -331,15 +331,13 @@ bool RISCVAsmBackend::relaxDwarfLineAddr(MCFragment &F,
331331

332332
int64_t LineDelta = F.getDwarfLineDelta();
333333
const MCExpr &AddrDelta = F.getDwarfAddrDelta();
334-
SmallVector<MCFixup, 1> Fixups;
335334
size_t OldSize = F.getVarSize();
336335

337336
int64_t Value;
338337
[[maybe_unused]] bool IsAbsolute =
339338
AddrDelta.evaluateKnownAbsolute(Value, *Asm);
340339
assert(IsAbsolute && "CFA with invalid expression");
341340

342-
Fixups.clear();
343341
SmallVector<char> Data;
344342
raw_svector_ostream OS(Data);
345343

@@ -349,33 +347,23 @@ bool RISCVAsmBackend::relaxDwarfLineAddr(MCFragment &F,
349347
encodeSLEB128(LineDelta, OS);
350348
}
351349

352-
unsigned Offset;
353-
std::pair<MCFixupKind, MCFixupKind> Fixup;
354-
355350
// According to the DWARF specification, the `DW_LNS_fixed_advance_pc` opcode
356351
// takes a single unsigned half (unencoded) operand. The maximum encodable
357352
// value is therefore 65535. Set a conservative upper bound for relaxation.
353+
unsigned PCBytes;
358354
if (Value > 60000) {
359355
unsigned PtrSize = C.getAsmInfo()->getCodePointerSize();
360-
361-
OS << uint8_t(dwarf::DW_LNS_extended_op);
362-
encodeULEB128(PtrSize + 1, OS);
363-
364-
OS << uint8_t(dwarf::DW_LNE_set_address);
365-
Offset = OS.tell();
366356
assert((PtrSize == 4 || PtrSize == 8) && "Unexpected pointer size");
367-
Fixup = RISCV::getRelocPairForSize(PtrSize);
357+
PCBytes = PtrSize;
358+
OS << uint8_t(dwarf::DW_LNS_extended_op) << uint8_t(PtrSize + 1)
359+
<< uint8_t(dwarf::DW_LNE_set_address);
368360
OS.write_zeros(PtrSize);
369361
} else {
362+
PCBytes = 2;
370363
OS << uint8_t(dwarf::DW_LNS_fixed_advance_pc);
371-
Offset = OS.tell();
372-
Fixup = RISCV::getRelocPairForSize(2);
373364
support::endian::write<uint16_t>(OS, 0, llvm::endianness::little);
374365
}
375-
376-
const MCBinaryExpr &MBE = cast<MCBinaryExpr>(AddrDelta);
377-
Fixups.push_back(MCFixup::create(Offset, MBE.getLHS(), std::get<0>(Fixup)));
378-
Fixups.push_back(MCFixup::create(Offset, MBE.getRHS(), std::get<1>(Fixup)));
366+
auto Offset = OS.tell() - PCBytes;
379367

380368
if (LineDelta == INT64_MAX) {
381369
OS << uint8_t(dwarf::DW_LNS_extended_op);
@@ -386,7 +374,8 @@ bool RISCVAsmBackend::relaxDwarfLineAddr(MCFragment &F,
386374
}
387375

388376
F.setVarContents(Data);
389-
F.setVarFixups(Fixups);
377+
F.setVarFixups({MCFixup::create(Offset, &AddrDelta,
378+
MCFixup::getDataKindForSize(PCBytes))});
390379
WasRelaxed = OldSize != Data.size();
391380
return true;
392381
}

llvm/lib/Target/RISCV/MCTargetDesc/RISCVFixupKinds.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,6 @@ enum Fixups {
6868
fixup_riscv_invalid,
6969
NumTargetFixupKinds = fixup_riscv_invalid - FirstTargetFixupKind
7070
};
71-
72-
static inline std::pair<MCFixupKind, MCFixupKind>
73-
getRelocPairForSize(unsigned Size) {
74-
switch (Size) {
75-
default:
76-
llvm_unreachable("unsupported fixup size");
77-
case 1:
78-
return std::make_pair(FirstLiteralRelocationKind + ELF::R_RISCV_ADD8,
79-
FirstLiteralRelocationKind + ELF::R_RISCV_SUB8);
80-
case 2:
81-
return std::make_pair(FirstLiteralRelocationKind + ELF::R_RISCV_ADD16,
82-
FirstLiteralRelocationKind + ELF::R_RISCV_SUB16);
83-
case 4:
84-
return std::make_pair(FirstLiteralRelocationKind + ELF::R_RISCV_ADD32,
85-
FirstLiteralRelocationKind + ELF::R_RISCV_SUB32);
86-
case 8:
87-
return std::make_pair(FirstLiteralRelocationKind + ELF::R_RISCV_ADD64,
88-
FirstLiteralRelocationKind + ELF::R_RISCV_SUB64);
89-
}
90-
}
91-
9271
} // end namespace llvm::RISCV
9372

9473
#endif

0 commit comments

Comments
 (0)