Skip to content

Commit c330585

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

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,14 @@ bool LoongArchAsmBackend::relaxDwarfLineAddr(MCFragment &F,
273273

274274
int64_t LineDelta = F.getDwarfLineDelta();
275275
const MCExpr &AddrDelta = F.getDwarfAddrDelta();
276-
SmallVector<MCFixup, 1> Fixups;
277276
size_t OldSize = F.getVarSize();
278277

279278
int64_t Value;
280279
if (AddrDelta.evaluateAsAbsolute(Value, *Asm))
281280
return false;
282-
bool IsAbsolute = AddrDelta.evaluateKnownAbsolute(Value, *Asm);
283-
assert(IsAbsolute && "CFA with invalid expression");
284-
(void)IsAbsolute;
281+
[[maybe_unused]] bool IsAbsolute =
282+
AddrDelta.evaluateKnownAbsolute(Value, *Asm);
283+
assert(IsAbsolute);
285284

286285
SmallVector<char> Data;
287286
raw_svector_ostream OS(Data);
@@ -292,33 +291,23 @@ bool LoongArchAsmBackend::relaxDwarfLineAddr(MCFragment &F,
292291
encodeSLEB128(LineDelta, OS);
293292
}
294293

295-
unsigned Offset;
296-
std::pair<MCFixupKind, MCFixupKind> FK;
297-
298294
// According to the DWARF specification, the `DW_LNS_fixed_advance_pc` opcode
299295
// takes a single unsigned half (unencoded) operand. The maximum encodable
300296
// value is therefore 65535. Set a conservative upper bound for relaxation.
297+
unsigned PCBytes;
301298
if (Value > 60000) {
302299
unsigned PtrSize = C.getAsmInfo()->getCodePointerSize();
303-
304-
OS << uint8_t(dwarf::DW_LNS_extended_op);
305-
encodeULEB128(PtrSize + 1, OS);
306-
307-
OS << uint8_t(dwarf::DW_LNE_set_address);
308-
Offset = OS.tell();
309300
assert((PtrSize == 4 || PtrSize == 8) && "Unexpected pointer size");
310-
FK = getRelocPairForSize(PtrSize == 4 ? 32 : 64);
301+
PCBytes = PtrSize;
302+
OS << uint8_t(dwarf::DW_LNS_extended_op) << uint8_t(PtrSize + 1)
303+
<< uint8_t(dwarf::DW_LNE_set_address);
311304
OS.write_zeros(PtrSize);
312305
} else {
306+
PCBytes = 2;
313307
OS << uint8_t(dwarf::DW_LNS_fixed_advance_pc);
314-
Offset = OS.tell();
315-
FK = getRelocPairForSize(16);
316308
support::endian::write<uint16_t>(OS, 0, llvm::endianness::little);
317309
}
318-
319-
const MCBinaryExpr &MBE = cast<MCBinaryExpr>(AddrDelta);
320-
Fixups.push_back(MCFixup::create(Offset, MBE.getLHS(), std::get<0>(FK)));
321-
Fixups.push_back(MCFixup::create(Offset, MBE.getRHS(), std::get<1>(FK)));
310+
auto Offset = OS.tell() - PCBytes;
322311

323312
if (LineDelta == INT64_MAX) {
324313
OS << uint8_t(dwarf::DW_LNS_extended_op);
@@ -329,7 +318,8 @@ bool LoongArchAsmBackend::relaxDwarfLineAddr(MCFragment &F,
329318
}
330319

331320
F.setVarContents(Data);
332-
F.setVarFixups(Fixups);
321+
F.setVarFixups({MCFixup::create(Offset, &AddrDelta,
322+
MCFixup::getDataKindForSize(PCBytes))});
333323
WasRelaxed = OldSize != Data.size();
334324
return true;
335325
}

0 commit comments

Comments
 (0)