[PATCH] D138135: [lld][ELF] Support LoongArch
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 21 00:36:49 PDT 2023
MaskRay added inline comments.
================
Comment at: lld/ELF/Arch/LoongArch.cpp:88
+
+ // We must specially handle the cases when the low 12 bits of dest are seen
+ // as negative, because the instructions consuming it (ld, st, addi, etc.)
----------------
I was quite confused by the description, then I realized that I probably should just figure out the formula myself:)
I wonder whether it's clear if we remove these textual descriptions and focus on the deduction:
```
// We have to check if the higher 32 bits need adjustment too, due to
// the large code model access pattern:
//
// pcalau12i A, %foo_hi20(sym) // b in [0,0xfff]
// addi.d T, zero, %foo_lo12(sym) // pageoff in [0,0xfff]
// lu32i.d T, %foo64_lo20(sym) // c in [0,0xfffff]
// lu52i.d T, T, %foo64_hi12(sym) // d in [0,0xfff]
// {ldx,stx,add}.* A, A, T
//
// If we treat the immediates in the operands as unsigned, the adjusted page
// delta (return value) is b<<12 | c<<32 | d<<52.
// We have (pageoff<0x800?pageoff:pageoff-0x1000+0x100000000) + ((b<0x80000?b:b-0x100000)<<12) + (c<<32) + (d<<52) = dest - page(pc).
//
// When pageoff is 0xfff, its contribution to dest-page(pc) is effectively 0xfff-0x1000 + 0x100000000 as the high 32-bits are
// set by lu32i.d+lu52i.d, e.g.
//
// addi.d T, zero, -1 ; T = 0xfff'fffff'fffff'fff
// lu32i.d T, 1 ; T = 0x000'00001'fffff'fff
// lu52i.d T, T, -1 ; T = 0xfff'00001'fffff'fff
```
================
Comment at: lld/ELF/Arch/LoongArch.cpp:228
+
+static bool inputFileHasCode(const InputFile *f) {
+ for (auto *sec : f->getSections())
----------------
> We probably should change the parameter to a const reference.
Not done?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D138135/new/
https://reviews.llvm.org/D138135
More information about the llvm-commits
mailing list