[llvm] 850adc1 - [JITLink][RISCV] Homogenize immediate handling
Jonas Hahnfeld via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 3 08:19:39 PST 2023
Author: Jonas Hahnfeld
Date: 2023-01-03T17:18:39+01:00
New Revision: 850adc1ddc41c626ecdfc89a083518343ad2fbf6
URL: https://github.com/llvm/llvm-project/commit/850adc1ddc41c626ecdfc89a083518343ad2fbf6
DIFF: https://github.com/llvm/llvm-project/commit/850adc1ddc41c626ecdfc89a083518343ad2fbf6.diff
LOG: [JITLink][RISCV] Homogenize immediate handling
Name the variables based on which part of the immediate value is
extracted, as it was already done for R_RISCV_JAL. This makes it
much easier to compare the logic with the spec.
Differential Revision: https://reviews.llvm.org/D140820
Added:
Modified:
llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
Removed:
################################################################################
diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
index 3fcc45eab255..79e3be60af69 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
@@ -205,12 +205,13 @@ class ELFJITLinker_riscv : public JITLinker<ELFJITLinker_riscv> {
return makeTargetOutOfRangeError(G, B, E);
if (LLVM_UNLIKELY(!isAlignmentCorrect(Value, 2)))
return makeAlignmentError(FixupAddress, Value, 2, E);
- uint32_t Imm31_25 =
- extractBits(Value, 5, 6) << 25 | extractBits(Value, 12, 1) << 31;
- uint32_t Imm11_7 =
- extractBits(Value, 1, 4) << 8 | extractBits(Value, 11, 1) << 7;
+ uint32_t Imm12 = extractBits(Value, 12, 1) << 31;
+ uint32_t Imm10_5 = extractBits(Value, 5, 6) << 25;
+ uint32_t Imm4_1 = extractBits(Value, 1, 4) << 8;
+ uint32_t Imm11 = extractBits(Value, 11, 1) << 7;
uint32_t RawInstr = *(little32_t *)FixupPtr;
- *(little32_t *)FixupPtr = (RawInstr & 0x1FFF07F) | Imm31_25 | Imm11_7;
+ *(little32_t *)FixupPtr =
+ (RawInstr & 0x1FFF07F) | Imm12 | Imm10_5 | Imm4_1 | Imm11;
break;
}
case R_RISCV_JAL: {
@@ -280,11 +281,11 @@ class ELFJITLinker_riscv : public JITLinker<ELFJITLinker_riscv> {
int64_t Value = RelHI20->getTarget().getAddress() +
RelHI20->getAddend() - E.getTarget().getAddress();
int64_t Lo = Value & 0xFFF;
- uint32_t Imm31_25 = extractBits(Lo, 5, 7) << 25;
- uint32_t Imm11_7 = extractBits(Lo, 0, 5) << 7;
+ uint32_t Imm11_5 = extractBits(Lo, 5, 7) << 25;
+ uint32_t Imm4_0 = extractBits(Lo, 0, 5) << 7;
uint32_t RawInstr = *(little32_t *)FixupPtr;
- *(little32_t *)FixupPtr = (RawInstr & 0x1FFF07F) | Imm31_25 | Imm11_7;
+ *(little32_t *)FixupPtr = (RawInstr & 0x1FFF07F) | Imm11_5 | Imm4_0;
break;
}
case R_RISCV_HI20: {
@@ -312,10 +313,10 @@ class ELFJITLinker_riscv : public JITLinker<ELFJITLinker_riscv> {
// with current relocation R_RISCV_LO12_S. So here may need a check.
int64_t Value = (E.getTarget().getAddress() + E.getAddend()).getValue();
int64_t Lo = Value & 0xFFF;
- uint32_t Imm31_25 = extractBits(Lo, 5, 7) << 25;
- uint32_t Imm11_7 = extractBits(Lo, 0, 5) << 7;
+ uint32_t Imm11_5 = extractBits(Lo, 5, 7) << 25;
+ uint32_t Imm4_0 = extractBits(Lo, 0, 5) << 7;
uint32_t RawInstr = *(little32_t *)FixupPtr;
- *(little32_t *)FixupPtr = (RawInstr & 0x1FFF07F) | Imm31_25 | Imm11_7;
+ *(little32_t *)FixupPtr = (RawInstr & 0x1FFF07F) | Imm11_5 | Imm4_0;
break;
}
case R_RISCV_ADD8: {
More information about the llvm-commits
mailing list