10 changes: 9 additions & 1 deletion llvm/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,24 @@ class StringRef;
class raw_ostream;
class raw_pwrite_stream;

extern Target TheBPFleTarget;
extern Target TheBPFbeTarget;
extern Target TheBPFTarget;

MCCodeEmitter *createBPFMCCodeEmitter(const MCInstrInfo &MCII,
const MCRegisterInfo &MRI,
MCContext &Ctx);
MCCodeEmitter *createBPFbeMCCodeEmitter(const MCInstrInfo &MCII,
const MCRegisterInfo &MRI,
MCContext &Ctx);

MCAsmBackend *createBPFAsmBackend(const Target &T, const MCRegisterInfo &MRI,
StringRef TT, StringRef CPU);
MCAsmBackend *createBPFbeAsmBackend(const Target &T, const MCRegisterInfo &MRI,
StringRef TT, StringRef CPU);

MCObjectWriter *createBPFELFObjectWriter(raw_pwrite_stream &OS, uint8_t OSABI);
MCObjectWriter *createBPFELFObjectWriter(raw_pwrite_stream &OS,
uint8_t OSABI, bool IsLittleEndian);
}

// Defines symbolic names for BPF registers. This defines a mapping from
Expand Down
14 changes: 12 additions & 2 deletions llvm/lib/Target/BPF/TargetInfo/BPFTargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,18 @@
#include "llvm/Support/TargetRegistry.h"
using namespace llvm;

Target llvm::TheBPFTarget;
namespace llvm {
Target TheBPFleTarget;
Target TheBPFbeTarget;
Target TheBPFTarget;
}

extern "C" void LLVMInitializeBPFTargetInfo() {
RegisterTarget<Triple::bpf, /*HasJIT=*/true> X(TheBPFTarget, "bpf", "BPF");
TargetRegistry::RegisterTarget(TheBPFTarget, "bpf",
"BPF (host endian)",
[](Triple::ArchType) { return false; }, true);
RegisterTarget<Triple::bpf_le, /*HasJIT=*/true> X(
TheBPFleTarget, "bpf_le", "BPF (little endian)");
RegisterTarget<Triple::bpf_be, /*HasJIT=*/true> Y(
TheBPFbeTarget, "bpf_be", "BPF (big endian)");
}
3 changes: 1 addition & 2 deletions llvm/test/CodeGen/BPF/alu8.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
; RUN: llc -march=bpf -show-mc-encoding < %s | FileCheck %s
; test little endian only for now
; RUN: llc -march=bpf_le -show-mc-encoding < %s | FileCheck %s

define i8 @mov(i8 %a, i8 %b) nounwind {
; CHECK-LABEL: mov:
Expand Down
3 changes: 1 addition & 2 deletions llvm/test/CodeGen/BPF/atomics.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
; RUN: llc < %s -march=bpf -verify-machineinstrs -show-mc-encoding | FileCheck %s
; test little endian only for now
; RUN: llc < %s -march=bpf_le -verify-machineinstrs -show-mc-encoding | FileCheck %s

; CHECK-LABEL: test_load_add_32
; CHECK: xadd32
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/BPF/basictest.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: llc < %s -march=bpf | FileCheck %s
; RUN: llc < %s -march=bpf_le | FileCheck %s

define i32 @test0(i32 %X) {
%tmp.1 = add i32 %X, 1
Expand Down
3 changes: 1 addition & 2 deletions llvm/test/CodeGen/BPF/cc_args.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
; RUN: llc < %s -march=bpf -show-mc-encoding | FileCheck %s
; test little endian only for now
; RUN: llc < %s -march=bpf_le -show-mc-encoding | FileCheck %s

define void @test() #0 {
entry:
Expand Down
96 changes: 96 additions & 0 deletions llvm/test/CodeGen/BPF/cc_args_be.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
; RUN: llc < %s -march=bpf_be -show-mc-encoding | FileCheck %s
; test big endian

define void @test() #0 {
entry:
; CHECK: test:

; CHECK: mov r1, 123 # encoding: [0xb7,0x10,0x00,0x00,0x00,0x00,0x00,0x7b]
; CHECK: call f_i16
call void @f_i16(i16 123)

; CHECK: mov r1, 12345678 # encoding: [0xb7,0x10,0x00,0x00,0x00,0xbc,0x61,0x4e]
; CHECK: call f_i32
call void @f_i32(i32 12345678)

; CHECK: ld_64 r1, 72623859790382856 # encoding: [0x18,0x10,0x00,0x00,0x05,0x06,0x07,0x08,0x00,0x00,0x00,0x00,0x01,0x02,0x03,0x04]
; CHECK: call f_i64
call void @f_i64(i64 72623859790382856)

; CHECK: mov r1, 1234
; CHECK: mov r2, 5678
; CHECK: call f_i32_i32
call void @f_i32_i32(i32 1234, i32 5678)

; CHECK: mov r1, 2
; CHECK: mov r2, 3
; CHECK: mov r3, 4
; CHECK: call f_i16_i32_i16
call void @f_i16_i32_i16(i16 2, i32 3, i16 4)

; CHECK: mov r1, 5
; CHECK: ld_64 r2, 7262385979038285
; CHECK: mov r3, 6
; CHECK: call f_i16_i64_i16
call void @f_i16_i64_i16(i16 5, i64 7262385979038285, i16 6)

ret void
}

@g_i16 = common global i16 0, align 2
@g_i32 = common global i32 0, align 2
@g_i64 = common global i64 0, align 4

define void @f_i16(i16 %a) #0 {
; CHECK: f_i16:
; CHECK: sth 0(r2), r1 # encoding: [0x6b,0x21,0x00,0x00,0x00,0x00,0x00,0x00]
store volatile i16 %a, i16* @g_i16, align 2
ret void
}

define void @f_i32(i32 %a) #0 {
; CHECK: f_i32:
; CHECK: sth 2(r2), r1 # encoding: [0x6b,0x21,0x00,0x02,0x00,0x00,0x00,0x00]
; CHECK: sth 0(r2), r1 # encoding: [0x6b,0x21,0x00,0x00,0x00,0x00,0x00,0x00]
store volatile i32 %a, i32* @g_i32, align 2
ret void
}

define void @f_i64(i64 %a) #0 {
; CHECK: f_i64:
; CHECK: stw 4(r2), r1 # encoding: [0x63,0x21,0x00,0x04,0x00,0x00,0x00,0x00]
; CHECK: stw 0(r2), r1
store volatile i64 %a, i64* @g_i64, align 2
ret void
}

define void @f_i32_i32(i32 %a, i32 %b) #0 {
; CHECK: f_i32_i32:
; CHECK: stw 0(r3), r1
store volatile i32 %a, i32* @g_i32, align 4
; CHECK: stw 0(r3), r2
store volatile i32 %b, i32* @g_i32, align 4
ret void
}

define void @f_i16_i32_i16(i16 %a, i32 %b, i16 %c) #0 {
; CHECK: f_i16_i32_i16:
; CHECK: sth 0(r4), r1
store volatile i16 %a, i16* @g_i16, align 2
; CHECK: stw 0(r1), r2
store volatile i32 %b, i32* @g_i32, align 4
; CHECK: sth 0(r4), r3
store volatile i16 %c, i16* @g_i16, align 2
ret void
}

define void @f_i16_i64_i16(i16 %a, i64 %b, i16 %c) #0 {
; CHECK: f_i16_i64_i16:
; CHECK: sth 0(r4), r1
store volatile i16 %a, i16* @g_i16, align 2
; CHECK: std 0(r1), r2 # encoding: [0x7b,0x12,0x00,0x00,0x00,0x00,0x00,0x00]
store volatile i64 %b, i64* @g_i64, align 8
; CHECK: sth 0(r4), r3
store volatile i16 %c, i16* @g_i16, align 2
ret void
}
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/BPF/cc_ret.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: llc < %s -march=bpf | FileCheck %s
; RUN: llc < %s -march=bpf_le | FileCheck %s

define void @test() #0 {
entry:
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/BPF/ex1.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: llc < %s -march=bpf | FileCheck %s
; RUN: llc < %s -march=bpf_le | FileCheck %s

%struct.bpf_context = type { i64, i64, i64, i64, i64, i64, i64 }
%struct.sk_buff = type { i64, i64, i64, i64, i64, i64, i64 }
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/BPF/intrinsics.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: llc < %s -march=bpf -show-mc-encoding | FileCheck %s
; RUN: llc < %s -march=bpf_le -show-mc-encoding | FileCheck %s

; Function Attrs: nounwind uwtable
define i32 @ld_b(i64 %foo, i64* nocapture %bar, i8* %ctx, i8* %ctx2) #0 {
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/BPF/load.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: llc < %s -march=bpf | FileCheck %s
; RUN: llc < %s -march=bpf_le | FileCheck %s

define i16 @am1(i16* %a) nounwind {
%1 = load i16, i16* %a
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/BPF/loops.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: llc < %s -march=bpf | FileCheck %s
; RUN: llc < %s -march=bpf_le | FileCheck %s

define zeroext i16 @add(i16* nocapture %a, i16 zeroext %n) nounwind readonly {
entry:
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/BPF/sanity.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: llc < %s -march=bpf | FileCheck %s
; RUN: llc < %s -march=bpf_le | FileCheck %s

@foo_printf.fmt = private unnamed_addr constant [9 x i8] c"hello \0A\00", align 1

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/BPF/setcc.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: llc -march=bpf < %s | FileCheck %s
; RUN: llc -march=bpf_le < %s | FileCheck %s

define i16 @sccweqand(i16 %a, i16 %b) nounwind {
%t1 = and i16 %a, %b
Expand Down
3 changes: 1 addition & 2 deletions llvm/test/CodeGen/BPF/shifts.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
; RUN: llc < %s -march=bpf -show-mc-encoding | FileCheck %s
; test little endian only for now
; RUN: llc < %s -march=bpf_le -show-mc-encoding | FileCheck %s

define zeroext i8 @lshr8(i8 zeroext %a, i8 zeroext %cnt) nounwind readnone {
entry:
Expand Down
3 changes: 1 addition & 2 deletions llvm/test/CodeGen/BPF/sockex2.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
; RUN: llc < %s -march=bpf -show-mc-encoding | FileCheck %s
; test little endian only for now
; RUN: llc < %s -march=bpf_le -show-mc-encoding | FileCheck %s

%struct.bpf_map_def = type { i32, i32, i32, i32 }
%struct.sk_buff = type opaque
Expand Down