[llvm] 8727248 - [UpdateTestChecks] Add basic BPF triple handling
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 12 07:58:11 PDT 2022
Author: Simon Pilgrim
Date: 2022-10-12T15:57:52+01:00
New Revision: 8727248b7989a81fb73ea187831f55c61a7e2c8d
URL: https://github.com/llvm/llvm-project/commit/8727248b7989a81fb73ea187831f55c61a7e2c8d
DIFF: https://github.com/llvm/llvm-project/commit/8727248b7989a81fb73ea187831f55c61a7e2c8d.diff
LOG: [UpdateTestChecks] Add basic BPF triple handling
Working on Issue #57872 - its really useful to be able to autogenerate checks
Added:
Modified:
llvm/test/CodeGen/BPF/sanity.ll
llvm/utils/UpdateTestChecks/asm.py
Removed:
################################################################################
diff --git a/llvm/test/CodeGen/BPF/sanity.ll b/llvm/test/CodeGen/BPF/sanity.ll
index c1171df259fba..3974b426fb51d 100644
--- a/llvm/test/CodeGen/BPF/sanity.ll
+++ b/llvm/test/CodeGen/BPF/sanity.ll
@@ -1,70 +1,109 @@
-; RUN: llc < %s -march=bpfel | FileCheck %s
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=bpfel-- | FileCheck %s
@foo_printf.fmt = private unnamed_addr constant [9 x i8] c"hello \0A\00", align 1
; Function Attrs: nounwind readnone uwtable
define i32 @foo_int(i32 %a, i32 %b) #0 {
+; CHECK-LABEL: foo_int:
+; CHECK: # %bb.0:
+; CHECK-NEXT: r0 = r2
+; CHECK-NEXT: r0 += r1
+; CHECK-NEXT: exit
%1 = add nsw i32 %b, %a
ret i32 %1
-; CHECK-LABEL: foo_int:
-; CHECK: r0 += r1
}
; Function Attrs: nounwind readnone uwtable
define signext i8 @foo_char(i8 signext %a, i8 signext %b) #0 {
+; CHECK-LABEL: foo_char:
+; CHECK: # %bb.0:
+; CHECK-NEXT: r0 = r2
+; CHECK-NEXT: r0 += r1
+; CHECK-NEXT: r0 <<= 56
+; CHECK-NEXT: r0 s>>= 56
+; CHECK-NEXT: exit
%1 = add i8 %b, %a
ret i8 %1
-; CHECK-LABEL: foo_char:
-; CHECK: r0 += r1
-; CHECK: r0 <<= 56
-; CHECK: r0 s>>= 56
}
; Function Attrs: nounwind readnone uwtable
define i64 @foo_ll(i64 %a, i64 %b, i64 %c) #0 {
+; CHECK-LABEL: foo_ll:
+; CHECK: # %bb.0:
+; CHECK-NEXT: r0 = r2
+; CHECK-NEXT: r0 += r1
+; CHECK-NEXT: r0 -= r3
+; CHECK-NEXT: exit
%1 = add nsw i64 %b, %a
%2 = sub i64 %1, %c
ret i64 %2
-; CHECK-LABEL: foo_ll:
-; CHECK: r0 = r2
-; CHECK: r0 += r1
-; CHECK: r0 -= r3
}
; Function Attrs: nounwind uwtable
define void @foo_call2(i32 %a, i32 %b) #1 {
+; CHECK-LABEL: foo_call2:
+; CHECK: # %bb.0:
+; CHECK-NEXT: r3 = r1
+; CHECK-NEXT: r2 <<= 56
+; CHECK-NEXT: r2 s>>= 56
+; CHECK-NEXT: r1 = r2
+; CHECK-NEXT: r2 = r3
+; CHECK-NEXT: call foo_2arg
+; CHECK-NEXT: exit
%1 = trunc i32 %b to i8
tail call void @foo_2arg(i8 signext %1, i32 %a) #3
ret void
-; CHECK-LABEL: foo_call2:
-; CHECK: r2 <<= 56
-; CHECK: r2 s>>= 56
-; CHECK: r1 = r2
}
declare void @foo_2arg(i8 signext, i32) #2
; Function Attrs: nounwind uwtable
define i32 @foo_call5(i8 signext %a, i16 signext %b, i32 %c, i64 %d) #1 {
+; CHECK-LABEL: foo_call5:
+; CHECK: # %bb.0:
+; CHECK-NEXT: call bar
+; CHECK-NEXT: r0 = 0
+; CHECK-NEXT: exit
%1 = tail call i32 @bar(i8 signext %a, i16 signext %b, i32 %c, i64 %d) #3
ret i32 0
-; CHECK-LABEL: foo_call5:
-; CHECK: call bar
}
declare i32 @bar(i8 signext, i16 signext, i32, i64) #2
; Function Attrs: nounwind readnone uwtable
define signext i8 @foo_cmp(i8 signext %a, i8 signext %b) #0 {
+; CHECK-LABEL: foo_cmp:
+; CHECK: # %bb.0:
+; CHECK-NEXT: r0 = r1
+; CHECK-NEXT: if r2 s> r0 goto LBB5_2
+; CHECK-NEXT: # %bb.1:
+; CHECK-NEXT: r0 = r2
+; CHECK-NEXT: LBB5_2:
+; CHECK-NEXT: exit
%1 = icmp slt i8 %a, %b
%a.b = select i1 %1, i8 %a, i8 %b
ret i8 %a.b
-; CHECK-LABEL: foo_cmp:
-; CHECK: if r2 s> r0
}
; Function Attrs: nounwind readnone uwtable
define i32 @foo_muldiv(i8 signext %a, i16 signext %b, i32 %c, i64 %d) #0 {
+; CHECK-LABEL: foo_muldiv:
+; CHECK: # %bb.0:
+; CHECK-NEXT: r0 = r2
+; CHECK-NEXT: if r1 == 0 goto LBB6_2
+; CHECK-NEXT: # %bb.1:
+; CHECK-NEXT: r0 *= r3
+; CHECK-NEXT: goto LBB6_3
+; CHECK-NEXT: LBB6_2:
+; CHECK-NEXT: r3 <<= 32
+; CHECK-NEXT: r3 >>= 32
+; CHECK-NEXT: r4 <<= 32
+; CHECK-NEXT: r4 >>= 32
+; CHECK-NEXT: r4 /= r3
+; CHECK-NEXT: r0 = r4
+; CHECK-NEXT: LBB6_3:
+; CHECK-NEXT: exit
%1 = icmp eq i8 %a, 0
br i1 %1, label %5, label %2
@@ -81,31 +120,40 @@ define i32 @foo_muldiv(i8 signext %a, i16 signext %b, i32 %c, i64 %d) #0 {
; <label>:8 ; preds = %5, %2
%.0 = phi i32 [ %4, %2 ], [ %7, %5 ]
ret i32 %.0
-; CHECK-LABEL: foo_muldiv:
-; CHECK: r0 *= r3
}
; Function Attrs: nounwind uwtable
define i32 @foo_optimized() #1 {
+; CHECK-LABEL: foo_optimized:
+; CHECK: # %bb.0:
+; CHECK-NEXT: r1 = 1
+; CHECK-NEXT: r2 = 2
+; CHECK-NEXT: r3 = 3
+; CHECK-NEXT: r4 = 4
+; CHECK-NEXT: r5 = 5
+; CHECK-NEXT: call manyarg
+; CHECK-NEXT: exit
%1 = tail call i32 @manyarg(i32 1, i32 2, i32 3, i32 4, i32 5) #3
ret i32 %1
-; CHECK-LABEL: foo_optimized:
-; CHECK: r1 = 1
-; CHECK: r2 = 2
-; CHECK: r3 = 3
-; CHECK: r4 = 4
-; CHECK: r5 = 5
}
declare i32 @manyarg(i32, i32, i32, i32, i32) #2
; Function Attrs: nounwind uwtable
define void @foo_printf() #1 {
+; CHECK-LABEL: foo_printf:
+; CHECK: # %bb.0:
+; CHECK-NEXT: r1 = 0
+; CHECK-NEXT: *(u8 *)(r10 - 8) = r1
+; CHECK-NEXT: r1 = 729618802566522216 ll
+; CHECK-NEXT: *(u64 *)(r10 - 16) = r1
+; CHECK-NEXT: r1 = r10
+; CHECK-NEXT: r1 += -16
+; CHECK-NEXT: call printf
+; CHECK-NEXT: exit
%fmt = alloca [9 x i8], align 1
%1 = getelementptr inbounds [9 x i8], [9 x i8]* %fmt, i64 0, i64 0
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @foo_printf.fmt, i64 0, i64 0), i64 9, i1 false)
-; CHECK-LABEL: foo_printf:
-; CHECK: r1 = 729618802566522216 ll
%2 = call i32 (i8*, ...) @printf(i8* %1) #3
ret void
}
diff --git a/llvm/utils/UpdateTestChecks/asm.py b/llvm/utils/UpdateTestChecks/asm.py
index 3bf1244b0bb19..d420d96abf3c6 100644
--- a/llvm/utils/UpdateTestChecks/asm.py
+++ b/llvm/utils/UpdateTestChecks/asm.py
@@ -47,6 +47,13 @@ class string:
r'^\s*(\.Lfunc_end[0-9]+:\n|\.section)',
flags=(re.M | re.S))
+ASM_FUNCTION_BPF_RE = re.compile(
+ r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@"?(?P=func)"?\n'
+ r'(?:[ \t]+.cfi_startproc\n|.seh_proc[^\n]+\n)?' # drop optional cfi
+ r'(?P<body>.*?)\s*'
+ r'.Lfunc_end[0-9]+:\n',
+ flags=(re.M | re.S))
+
ASM_FUNCTION_HEXAGON_RE = re.compile(
r'^_?(?P<func>[^:]+):[ \t]*//[ \t]*@"?(?P=func)"?\n[^:]*?'
r'(?P<body>.*?)\n' # (body of the function)
@@ -292,6 +299,16 @@ def scrub_asm_arm_eabi(asm, args):
asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm)
return asm
+def scrub_asm_bpf(asm, args):
+ # Scrub runs of whitespace out of the assembly, but leave the leading
+ # whitespace in place.
+ asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm)
+ # Expand the tabs used for indentation.
+ asm = string.expandtabs(asm, 2)
+ # Strip trailing whitespace.
+ asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm)
+ return asm
+
def scrub_asm_hexagon(asm, args):
# Scrub runs of whitespace out of the assembly, but leave the leading
# whitespace in place.
@@ -461,6 +478,9 @@ def get_run_handler(triple):
'aarch64': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_RE),
'aarch64-apple-darwin': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE),
'aarch64-apple-ios': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE),
+ 'bpf': (scrub_asm_bpf, ASM_FUNCTION_BPF_RE),
+ 'bpfel': (scrub_asm_bpf, ASM_FUNCTION_BPF_RE),
+ 'bpfeb': (scrub_asm_bpf, ASM_FUNCTION_BPF_RE),
'hexagon': (scrub_asm_hexagon, ASM_FUNCTION_HEXAGON_RE),
'r600': (scrub_asm_amdgpu, ASM_FUNCTION_AMDGPU_RE),
'amdgcn': (scrub_asm_amdgpu, ASM_FUNCTION_AMDGPU_RE),
More information about the llvm-commits
mailing list