[PATCH] D137902: [M68k][MC] Make immediate operands relocatable
Min-Yih Hsu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 12 21:28:42 PST 2022
myhsu created this revision.
myhsu added reviewers: RKSimon, 0x59616e, ricky26, craig.topper.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
myhsu requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Sometimes memory addresses are treated as immediate values. Thus immediate operands have to be relocatable.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D137902
Files:
llvm/lib/Target/M68k/M68kInstrFormats.td
llvm/test/MC/M68k/Relocations/data-abs.s
Index: llvm/test/MC/M68k/Relocations/data-abs.s
===================================================================
--- llvm/test/MC/M68k/Relocations/data-abs.s
+++ llvm/test/MC/M68k/Relocations/data-abs.s
@@ -7,3 +7,20 @@
; INSTR: move.l dst, %d0
; FIXUP: fixup A - offset: 2, value: dst, kind: FK_Data_4
move.l dst, %d0
+
+; Relocating immediate values
+
+; RELOC: R_68K_8 str8 0x0
+; INSTR: move.b #str8, (4,%sp)
+; FIXUP: fixup A - offset: 3, value: str8, kind: FK_Data_1
+move.b #str8, (4,%sp)
+
+; RELOC: R_68K_16 str16 0x0
+; INSTR: move.w #str16, (4,%sp)
+; FIXUP: fixup A - offset: 2, value: str16, kind: FK_Data_2
+move.w #str16, (4,%sp)
+
+; RELOC: R_68K_32 str32 0x0
+; INSTR: move.l #str32, (4,%sp)
+; FIXUP: fixup A - offset: 2, value: str32, kind: FK_Data_4
+move.l #str32, (4,%sp)
Index: llvm/lib/Target/M68k/M68kInstrFormats.td
===================================================================
--- llvm/lib/Target/M68k/M68kInstrFormats.td
+++ llvm/lib/Target/M68k/M68kInstrFormats.td
@@ -324,13 +324,13 @@
/*REGISTER*/0b100);
// Immediate
- let Supplement =
- !cond(
- !eq(size, 8) : (descend 0b00000000, (operand "$"#opnd_name, 8)),
- !eq(size, 16) : (operand "$"#opnd_name, 16),
- !eq(size, 32) : (ascend (slice "$"#opnd_name, 31, 16),
- (slice "$"#opnd_name, 15, 0))
- );
+ let Supplement = !if(!eq(size, 8),
+ // 8-bit
+ (descend 0b00000000, (operand "$"#opnd_name, size,
+ (encoder "encodeRelocImm<"#size#">"))),
+ // 16 and 32-bit
+ (operand "$"#opnd_name, size,
+ (encoder "encodeRelocImm<"#size#">")));
}
// abs.W -> size_w_l = false
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137902.474980.patch
Type: text/x-patch
Size: 1800 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221113/f184ecdb/attachment.bin>
More information about the llvm-commits
mailing list