Skip to content

Commit 11ebe3d

Browse files
committed
[RISCV] relaxDwarfCallFrameFragment: remove unneeded relocations for relaxation
If `evaluateAsAbsolute(Value, Layout.getAssembler())` returns true, we know the address delta is a constant and can suppress relocations (usually SET6/SUB6). While here, replace two evaluateKnownAbsolute calls (subtle; avoid if possible) with evaluateAsAbsolute.
1 parent 07b9e6e commit 11ebe3d

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed

llvm/lib/MC/MCAssembler.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,16 +1110,17 @@ bool MCAssembler::relaxDwarfCallFrameFragment(MCAsmLayout &Layout,
11101110
return WasRelaxed;
11111111

11121112
MCContext &Context = Layout.getAssembler().getContext();
1113-
uint64_t OldSize = DF.getContents().size();
1114-
int64_t AddrDelta;
1115-
bool Abs = DF.getAddrDelta().evaluateKnownAbsolute(AddrDelta, Layout);
1116-
assert(Abs && "We created call frame with an invalid expression");
1117-
(void) Abs;
1113+
int64_t Value;
1114+
bool Abs = DF.getAddrDelta().evaluateAsAbsolute(Value, Layout);
1115+
assert(Abs && "CFA with invalid expression");
1116+
(void)Abs;
1117+
11181118
SmallVectorImpl<char> &Data = DF.getContents();
1119+
uint64_t OldSize = Data.size();
11191120
Data.clear();
11201121
DF.getFixups().clear();
11211122

1122-
MCDwarfFrameEmitter::encodeAdvanceLoc(Context, AddrDelta, Data);
1123+
MCDwarfFrameEmitter::encodeAdvanceLoc(Context, Value, Data);
11231124
return OldSize != Data.size();
11241125
}
11251126

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,15 @@ bool RISCVAsmBackend::relaxDwarfLineAddr(MCDwarfLineAddrFragment &DF,
273273
bool RISCVAsmBackend::relaxDwarfCFA(MCDwarfCallFrameFragment &DF,
274274
MCAsmLayout &Layout,
275275
bool &WasRelaxed) const {
276-
277276
const MCExpr &AddrDelta = DF.getAddrDelta();
278277
SmallVectorImpl<char> &Data = DF.getContents();
279278
SmallVectorImpl<MCFixup> &Fixups = DF.getFixups();
280279
size_t OldSize = Data.size();
281280

282281
int64_t Value;
283-
bool IsAbsolute = AddrDelta.evaluateKnownAbsolute(Value, Layout);
282+
if (AddrDelta.evaluateAsAbsolute(Value, Layout.getAssembler()))
283+
return false;
284+
bool IsAbsolute = AddrDelta.evaluateAsAbsolute(Value, Layout);
284285
assert(IsAbsolute && "CFA with invalid expression");
285286
(void)IsAbsolute;
286287

llvm/test/DebugInfo/RISCV/relax-debug-frame.ll

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,29 @@
77
; RELAX-NEXT: 0x1C R_RISCV_32_PCREL - 0x0
88
; RELAX-NEXT: 0x20 R_RISCV_ADD32 - 0x0
99
; RELAX-NEXT: 0x20 R_RISCV_SUB32 - 0x0
10-
; RELAX-NOT: }
11-
; RELAX: 0x39 R_RISCV_SET6 - 0x0
12-
; RELAX-NEXT: 0x39 R_RISCV_SUB6 - 0x0
13-
;
10+
; RELAX-NEXT: 0x30 R_RISCV_32_PCREL - 0x0
11+
; RELAX-NEXT: 0x34 R_RISCV_ADD32 - 0x0
12+
; RELAX-NEXT: 0x34 R_RISCV_SUB32 - 0x0
13+
; RELAX-NEXT: 0x44 R_RISCV_32_PCREL - 0x0
14+
; RELAX-NEXT: 0x48 R_RISCV_ADD32 - 0x0
15+
; RELAX-NEXT: 0x48 R_RISCV_SUB32 - 0x0
16+
; RELAX-NEXT: }
17+
1418
; RELAX-DWARFDUMP-NOT: error: failed to compute relocation
15-
; RELAX-DWARFDUMP: CIE
16-
; RELAX-DWARFDUMP: DW_CFA_advance_loc
17-
; RELAX-DWARFDUMP: DW_CFA_def_cfa_offset
18-
; RELAX-DWARFDUMP: DW_CFA_offset
19+
; RELAX-DWARFDUMP: FDE
20+
; RELAX-DWARFDUMP-NEXT: Format:
21+
; RELAX-DWARFDUMP: DW_CFA_advance_loc: 4
22+
; RELAX-DWARFDUMP-NEXT: DW_CFA_def_cfa_offset: +16
23+
; RELAX-DWARFDUMP-EMPTY:
24+
25+
; RELAX-DWARFDUMP: FDE
26+
; RELAX-DWARFDUMP: Format:
27+
; RELAX-DWARFDUMP-NEXT: DW_CFA_advance_loc: 4
28+
; RELAX-DWARFDUMP-NEXT: DW_CFA_def_cfa_offset: +16
29+
; RELAX-DWARFDUMP-NEXT: DW_CFA_advance_loc: 4
30+
; RELAX-DWARFDUMP-NEXT: DW_CFA_offset: X1 -4
31+
; RELAX-DWARFDUMP-NEXT: DW_CFA_nop
32+
; RELAX-DWARFDUMP-EMPTY:
1933
source_filename = "frame.c"
2034

2135
; Function Attrs: noinline nounwind optnone

llvm/test/MC/ELF/RISCV/gen-dwarf.s

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
# RELOC-NEXT: 0x20 R_RISCV_SUB32 - 0x0
4646
# RELOC-NEXT: 0x25 R_RISCV_SET6 - 0x0
4747
# RELOC-NEXT: 0x25 R_RISCV_SUB6 - 0x0
48-
# RELOC-NEXT: 0x28 R_RISCV_SET6 - 0x0
49-
# RELOC-NEXT: 0x28 R_RISCV_SUB6 - 0x0
5048
# RELOC-NEXT: 0x34 R_RISCV_32_PCREL - 0x0
5149
# RELOC-NEXT: 0x38 R_RISCV_ADD32 - 0x0
5250
# RELOC-NEXT: 0x38 R_RISCV_SUB32 - 0x0

0 commit comments

Comments
 (0)