[PATCH] D139285: [LoongArch] Allow write unaligned nop sequence
wanglei via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 4 18:24:43 PST 2022
wangleiat created this revision.
wangleiat added reviewers: SixWeining, xen0n, xry111, MaskRay.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
wangleiat requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Use `zeros` padding for unaligned parts and `nops` for aligned parts.
This is consistent with gas behavior, and is necessary to compile the
Linux kernel with `LLVM IAS`.
Replace `support::endian::write` with `OS.write`. This looks simpler
and switches the bytes to not be dependant on the endianness, even
though we only have little endian.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D139285
Files:
llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
llvm/test/MC/LoongArch/Misc/unaligned-nops.s
Index: llvm/test/MC/LoongArch/Misc/unaligned-nops.s
===================================================================
--- llvm/test/MC/LoongArch/Misc/unaligned-nops.s
+++ llvm/test/MC/LoongArch/Misc/unaligned-nops.s
@@ -1,5 +1,8 @@
-# RUN: not --crash llvm-mc --filetype=obj --triple=loongarch64 %s -o %t
+# RUN: llvm-mc --triple=loongarch64 --filetype=obj %s -o %t
+# RUN: llvm-objdump -d %t | FileCheck %s
+
+# CHECK: 01 00 00 00 <unknown>
+# CHECK-NEXT: 00 00 40 03 nop
.byte 1
-# CHECK: LLVM ERROR: unable to write nop sequence of 3 bytes
-.p2align 2
+.p2align 3
foo:
Index: llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
===================================================================
--- llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
+++ llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
@@ -179,13 +179,14 @@
bool LoongArchAsmBackend::writeNopData(raw_ostream &OS, uint64_t Count,
const MCSubtargetInfo *STI) const {
- // Check for byte count not multiple of instruction word size
- if (Count % 4 != 0)
- return false;
+ // We mostly follow binutils' convention here: align to 4-byte boundary with a
+ // 0-fill padding.
+ OS.write_zeros(Count % 4);
- // The nop on LoongArch is andi r0, r0, 0.
+ // The remainder is now padded with 4-byte nops.
+ // nop: andi r0, r0, 0
for (; Count >= 4; Count -= 4)
- support::endian::write<uint32_t>(OS, 0x03400000, support::little);
+ OS.write("\0\0\x40\x03", 4);
return true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139285.479960.patch
Type: text/x-patch
Size: 1558 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221205/3ddd7532/attachment.bin>
More information about the llvm-commits
mailing list