aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineModuleInfo.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2025-03-29 11:12:40 -0700
committerGitHub <noreply@github.com>2025-03-29 11:12:40 -0700
commitb9b39db5d7677710f1d00dc8ff5844ad2abb269f (patch)
treeffee4dc30b27f117a0648adcb63f229f28b2ee9a /llvm/lib/CodeGen/MachineModuleInfo.cpp
parentfe6fb910df9d1b9a9e2e7a6e8228d020668e0129 (diff)
downloadllvm-b9b39db5d7677710f1d00dc8ff5844ad2abb269f.zip
llvm-b9b39db5d7677710f1d00dc8ff5844ad2abb269f.tar.gz
llvm-b9b39db5d7677710f1d00dc8ff5844ad2abb269f.tar.bz2
RISCVAsmParser: Don't treat operands with relocation specifier as parse-time constants
An immediate operand is encoded as an `MCExpr`, with `RISCVMCExpr` specifying an operand that includes a relocation specifier. When https://reviews.llvm.org/D23568 added initial fixup and relocation support in 2017, it adapted code from `PPCMCExpr` (for `@l` `@ha`) to evaluate the `RISCVMCExpr` operand. (PPCAsmParser had considerable technical debt, though I’ve recently streamlined it somewhat, e.g. 8560da28c69de481f3ad147722577e87b902facb) Evaluating RISCVMCExpr during parsing is unnecessary. For example, there's no need to treat `lui a0, %hi(2)` differently from `lui a0, %hi(foo)` when foo has not been defined yet. This evaluation introduces unnecessary complexity. For instance, parser functions require an extra check like `VK == RISCVMCExpr::VK_None`, as seen in these examples: ``` if (!evaluateConstantImm(getImm(), Imm, VK) || VK != RISCVMCExpr::VK_None) return IsConstantImm && isUInt<N>(Imm) && VK == RISCVMCExpr::VK_None; ``` This PR eliminates the parse-time evaluation of `RISCVMCExpr`, aligning it more closely with other targets. --- `abs = 0x12345; lui t3, %hi(abs)` now generates R_RISCV_HI20/R_RISCV_RELAX with linker relaxation. (Tested by test/MC/RISCV/linker-relaxation.s) (Notably, since commit ba2de8f22d0cac86d89c1806fb54ed3463349342 in lld/ELF, the linker can handle R_RISCV_HI relocations with a symbol index of 0 in -pie mode.) Pull Request: https://github.com/llvm/llvm-project/pull/133377
Diffstat (limited to 'llvm/lib/CodeGen/MachineModuleInfo.cpp')
0 files changed, 0 insertions, 0 deletions