[PATCH] D132323: [LoongArch] Port over minimal applyFixup from RISCV

Lu Weining via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 26 02:39:13 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG23b2fbf9ecf6: [LoongArch] Port over minimal applyFixup from RISCV (authored by WANG Xuerui <git at xen0n.name>, committed by SixWeining).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132323/new/

https://reviews.llvm.org/D132323

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


Index: llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
===================================================================
--- llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
+++ llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
@@ -73,8 +73,27 @@
                                      MutableArrayRef<char> Data, uint64_t Value,
                                      bool IsResolved,
                                      const MCSubtargetInfo *STI) const {
-  // TODO: Apply the Value for given Fixup into the provided data fragment.
-  return;
+  if (!Value)
+    return; // Doesn't change encoding.
+
+  MCFixupKind Kind = Fixup.getKind();
+  if (Kind >= FirstLiteralRelocationKind)
+    return;
+  MCFixupKindInfo Info = getFixupKindInfo(Kind);
+  // TODO: Apply any target-specific value adjustments.
+
+  // Shift the value into position.
+  Value <<= Info.TargetOffset;
+
+  unsigned Offset = Fixup.getOffset();
+  unsigned NumBytes = alignTo(Info.TargetSize + Info.TargetOffset, 8) / 8;
+
+  assert(Offset + NumBytes <= Data.size() && "Invalid fixup offset!");
+  // For each byte of the fragment that the fixup touches, mask in the
+  // bits from the fixup value.
+  for (unsigned I = 0; I != NumBytes; ++I) {
+    Data[Offset + I] |= uint8_t((Value >> (I * 8)) & 0xff);
+  }
 }
 
 bool LoongArchAsmBackend::shouldForceRelocation(const MCAssembler &Asm,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132323.455838.patch
Type: text/x-patch
Size: 1408 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220826/cba3cf06/attachment.bin>


More information about the llvm-commits mailing list