[PATCH] D81480: [BPF] generate proper code for __builtin_load_u32_to_ptr()
Yonghong Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 9 10:58:42 PDT 2020
yonghong-song updated this revision to Diff 269603.
yonghong-song added a comment.
generate code for LOAD_U32_TO_PTR through BPFInstrInfo.td specificaiton instead of rewrite at AsmPrint time.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D81480/new/
https://reviews.llvm.org/D81480
Files:
llvm/lib/Target/BPF/BPFInstrInfo.td
llvm/test/CodeGen/BPF/load_u32_to_ptr.ll
Index: llvm/test/CodeGen/BPF/load_u32_to_ptr.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/BPF/load_u32_to_ptr.ll
@@ -0,0 +1,18 @@
+; RUN: llc < %s -march=bpfel | FileCheck %s
+; RUN: llc < %s -march=bpfel -mattr=+alu32 | FileCheck %s
+
+%struct.t = type { i32, i32 }
+
+; Function Attrs: nounwind readonly
+define dso_local i8* @test(%struct.t* readonly %arg) local_unnamed_addr {
+entry:
+ %0 = bitcast %struct.t* %arg to i8*
+ %1 = tail call i8* @llvm.bpf.load.u32.to.ptr(i8* %0, i64 4)
+ ret i8* %1
+}
+
+; CHECK: r0 = *(u32 *)(r{{[0-9]+}} + 4)
+; CHECK-NEXT: exit
+
+; Function Attrs: nounwind readonly
+declare i8* @llvm.bpf.load.u32.to.ptr(i8*, i64) #1
Index: llvm/lib/Target/BPF/BPFInstrInfo.td
===================================================================
--- llvm/lib/Target/BPF/BPFInstrInfo.td
+++ llvm/lib/Target/BPF/BPFInstrInfo.td
@@ -392,6 +392,28 @@
let BPFClass = BPF_LD;
}
+class LOADU32<list<dag> Pattern>
+ : TYPE_LD_ST<BPF_MEM.Value, BPF_W.Value,
+ (outs GPR:$dst),
+ (ins GPR:$src, u64imm:$off),
+ "$dst = *(u32 *)($src + $off)",
+ Pattern> {
+ bits<4> src;
+ bits<4> dst;
+ bits<16> off;
+
+ let Inst{51-48} = dst;
+ let Inst{55-52} = src;
+ let Inst{47-32} = off;
+ let BPFClass = BPF_LDX;
+}
+
+// LOAD_U32_TO_PTR => LDW
+let isCodeGenOnly = 1 in {
+ def LOAD_U32_TO_PTR : LOADU32<[(set GPR:$dst,
+ (int_bpf_load_u32_to_ptr GPR:$src, imm:$off))]>;
+}
+
// STORE instructions
class STORE<BPFWidthModifer SizeOp, string OpcodeStr, list<dag> Pattern>
: TYPE_LD_ST<BPF_MEM.Value, SizeOp.Value,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81480.269603.patch
Type: text/x-patch
Size: 1715 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200609/45e50a6a/attachment.bin>
More information about the llvm-commits
mailing list