[llvm] r233396 - [bpf] add support for bpf pseudo instruction

Alexei Starovoitov alexei.starovoitov at gmail.com
Fri Mar 27 11:51:42 PDT 2015


Author: ast
Date: Fri Mar 27 13:51:42 2015
New Revision: 233396

URL: http://llvm.org/viewvc/llvm-project?rev=233396&view=rev
Log:
[bpf] add support for bpf pseudo instruction

Expose bpf pseudo load instruction via intrinsic. It is used by front-ends that
can encode file descriptors directly into IR instead of relying on relocations.

Modified:
    llvm/trunk/include/llvm/IR/IntrinsicsBPF.td
    llvm/trunk/lib/Target/BPF/BPFInstrInfo.td
    llvm/trunk/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp
    llvm/trunk/test/CodeGen/BPF/intrinsics.ll

Modified: llvm/trunk/include/llvm/IR/IntrinsicsBPF.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/IntrinsicsBPF.td?rev=233396&r1=233395&r2=233396&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/IntrinsicsBPF.td (original)
+++ llvm/trunk/include/llvm/IR/IntrinsicsBPF.td Fri Mar 27 13:51:42 2015
@@ -19,4 +19,6 @@ let TargetPrefix = "bpf" in {  // All in
               Intrinsic<[llvm_i64_ty], [llvm_ptr_ty, llvm_i64_ty], [IntrReadMem]>;
   def int_bpf_load_word : GCCBuiltin<"__builtin_bpf_load_word">,
               Intrinsic<[llvm_i64_ty], [llvm_ptr_ty, llvm_i64_ty], [IntrReadMem]>;
+  def int_bpf_pseudo : GCCBuiltin<"__builtin_bpf_pseudo">,
+              Intrinsic<[llvm_i64_ty], [llvm_i64_ty, llvm_i64_ty]>;
 }

Modified: llvm/trunk/lib/Target/BPF/BPFInstrInfo.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/BPF/BPFInstrInfo.td?rev=233396&r1=233395&r2=233396&view=diff
==============================================================================
--- llvm/trunk/lib/Target/BPF/BPFInstrInfo.td (original)
+++ llvm/trunk/lib/Target/BPF/BPFInstrInfo.td Fri Mar 27 13:51:42 2015
@@ -257,6 +257,29 @@ class LD_IMM64<bits<4> Pseudo, string Op
 }
 def LD_imm64 : LD_IMM64<0, "ld_64">;
 
+def LD_pseudo
+    : InstBPF<(outs GPR:$dst), (ins i64imm:$pseudo, u64imm:$imm),
+              "ld_pseudo\t$dst, $pseudo, $imm",
+              [(set GPR:$dst, (int_bpf_pseudo imm:$pseudo, imm:$imm))]> {
+
+  bits<3> mode;
+  bits<2> size;
+  bits<4> dst;
+  bits<64> imm;
+  bits<4> pseudo;
+
+  let Inst{63-61} = mode;
+  let Inst{60-59} = size;
+  let Inst{51-48} = dst;
+  let Inst{55-52} = pseudo;
+  let Inst{47-32} = 0;
+  let Inst{31-0} = imm{31-0};
+
+  let mode = 0;     // BPF_IMM
+  let size = 3;     // BPF_DW
+  let BPFClass = 0; // BPF_LD
+}
+
 // STORE instructions
 class STORE<bits<2> SizeOp, string OpcodeStr, list<dag> Pattern>
     : InstBPF<(outs), (ins GPR:$src, MEMri:$addr),

Modified: llvm/trunk/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp?rev=233396&r1=233395&r2=233396&view=diff
==============================================================================
--- llvm/trunk/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp (original)
+++ llvm/trunk/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp Fri Mar 27 13:51:42 2015
@@ -125,7 +125,7 @@ void BPFMCCodeEmitter::EncodeInstruction
   // Keep track of the current byte being emitted
   unsigned CurByte = 0;
 
-  if (Opcode == BPF::LD_imm64) {
+  if (Opcode == BPF::LD_imm64 || Opcode == BPF::LD_pseudo) {
     uint64_t Value = getBinaryCodeForInstr(MI, Fixups, STI);
     EmitByte(Value >> 56, CurByte, OS);
     EmitByte(((Value >> 48) & 0xff), CurByte, OS);

Modified: llvm/trunk/test/CodeGen/BPF/intrinsics.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/BPF/intrinsics.ll?rev=233396&r1=233395&r2=233396&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/BPF/intrinsics.ll (original)
+++ llvm/trunk/test/CodeGen/BPF/intrinsics.ll Fri Mar 27 13:51:42 2015
@@ -1,4 +1,4 @@
-; RUN: llc < %s -march=bpf | FileCheck %s
+; RUN: llc < %s -march=bpf -show-mc-encoding | FileCheck %s
 
 ; Function Attrs: nounwind uwtable
 define i32 @ld_b(i64 %foo, i64* nocapture %bar, i8* %ctx, i8* %ctx2) #0 {
@@ -48,3 +48,16 @@ define i32 @ld_w(i8* %ctx, i8* %ctx2, i3
 }
 
 declare i64 @llvm.bpf.load.word(i8*, i64) #1
+
+define i32 @ld_pseudo() #0 {
+entry:
+  %call = tail call i64 @llvm.bpf.pseudo(i64 2, i64 3)
+  tail call void @bar(i64 %call, i32 4) #2
+  ret i32 0
+; CHECK-LABEL: ld_pseudo:
+; CHECK: ld_pseudo r1, 2, 3 # encoding: [0x18,0x21,0x00,0x00,0x03,0x00
+}
+
+declare void @bar(i64, i32) #1
+
+declare i64 @llvm.bpf.pseudo(i64, i64) #2





More information about the llvm-commits mailing list