Skip to content

Commit f79ab21

Browse files
committed
[BPF] Define set of BPF libcalls
1 parent eb5297e commit f79ab21

File tree

3 files changed

+40
-39
lines changed

3 files changed

+40
-39
lines changed

llvm/include/llvm/IR/RuntimeLibcalls.td

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2808,6 +2808,23 @@ def WasmSystemLibrary
28082808
emscripten_return_address,
28092809
__stack_chk_fail, __stack_chk_guard)>;
28102810

2811+
//===----------------------------------------------------------------------===//
2812+
// BPF Runtime Libcalls
2813+
//===----------------------------------------------------------------------===//
2814+
2815+
def isBPF : RuntimeLibcallPredicate<"TT.isBPF()">;
2816+
2817+
def BPFSystemLibrary
2818+
: SystemRuntimeLibrary<isBPF,
2819+
(add (sub DefaultRuntimeLibcallImpls,
2820+
// i128 operations should be lowered by LLVM for BPF
2821+
__divti3,
2822+
__udivti3,
2823+
__modti3,
2824+
__umodti3,
2825+
__clzti2
2826+
))>;
2827+
28112828
//===----------------------------------------------------------------------===//
28122829
// Legacy Default Runtime Libcalls
28132830
//===----------------------------------------------------------------------===//

llvm/test/CodeGen/BPF/builtin_calls.ll

Lines changed: 0 additions & 39 deletions
This file was deleted.

llvm/test/CodeGen/BPF/i128_math.ll

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; RUN: llc -march=bpfel < %s | FileCheck %s
2+
;
3+
; C code for this test case:
4+
;
5+
; long func(long a, long b) {
6+
; long x;
7+
; return __builtin_mul_overflow(a, b, &x);
8+
; }
9+
10+
11+
declare { i64, i1 } @llvm.smul.with.overflow.i64(i64, i64)
12+
13+
define noundef range(i64 0, 2) i64 @func(i64 noundef %a, i64 noundef %b) local_unnamed_addr {
14+
entry:
15+
%0 = tail call { i64, i1 } @llvm.smul.with.overflow.i64(i64 %a, i64 %b)
16+
%1 = extractvalue { i64, i1 } %0, 1
17+
%conv = zext i1 %1 to i64
18+
ret i64 %conv
19+
}
20+
21+
; CHECK-LABEL: func
22+
; CHECK-NOT: call __multi3
23+
; CHECK: exit

0 commit comments

Comments
 (0)