llvm.org GIT mirror llvm / b0b7c84
[BPF] add unit tests for preserve_{array,union,struct}_access_index intrinsics This is a followup patch for https://reviews.llvm.org/D61810/new/, which adds new intrinsics preserve_{array,union,struct}_access_index. Currently, only BPF backend utilizes preserve_{array,union,struct}_access_index intrinsics, so all tests are compiled with BPF target. https://reviews.llvm.org/D61524 already added some tests for these intrinsics, but some of them pretty complex. This patch added a few unit test cases focusing on individual intrinsic functions. Also made a few clarification on language reference for these intrinsics. Differential Revision: https://reviews.llvm.org/D64606 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366038 91177308-0d34-0410-b5e6-96231b3b80d8 Yonghong Song a month ago
4 changed file(s) with 242 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
1733117331 """""""
1733217332 ::
1733317333
17334 declare <type2>
17334 declare <ret_type>
1733517335 @llvm.preserve.array.access.index.p0s_union.anons.p0a10s_union.anons( base,
1733617336 i32 dim,
1733717337 i32 index)
1734117341
1734217342 The '``llvm.preserve.array.access.index``' intrinsic returns the getelementptr address
1734317343 based on array base ``base``, array dimension ``dim`` and the last access index ``index``
17344 into the array.
17344 into the array. The return type ``ret_type`` is a pointer type to the array element.
17345 The array ``dim`` and ``index`` are preserved which is more robust than
17346 getelementptr instruction which may be subject to compiler transformation.
1734517347
1734617348 Arguments:
1734717349 """"""""""
1737417376 ``di_index`` and returns the ``base`` address.
1737517377 The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction
1737617378 to provide union debuginfo type.
17379 The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``.
17380 The return type ``type`` is the same as the ``base`` type.
1737717381
1737817382 Arguments:
1737917383 """"""""""
1739217396 """""""
1739317397 ::
1739417398
17395 declare <type2>
17399 declare <ret_type>
1739617400 @llvm.preserve.struct.access.index.p0i8.p0s_struct.anon.0s( base,
1739717401 i32 gep_index,
1739817402 i32 di_index)
1740417408 based on struct base ``base`` and IR struct member index ``gep_index``.
1740517409 The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction
1740617410 to provide struct debuginfo type.
17411 The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``.
17412 The return type ``ret_type`` is a pointer type to the structure member.
1740717413
1740817414 Arguments:
1740917415 """"""""""
0 ; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck %s
1 ;
2 ; Source code:
3 ; #define _(x) (__builtin_preserve_access_index(x))
4 ; struct s { int a; int b; };
5 ; int get_value(const void *addr);
6 ; int test(struct s *arg) { return get_value(_(&arg[2].b)); }
7 ; Compiler flag to generate IR:
8 ; clang -target bpf -S -O2 -g -emit-llvm test.c
9
10 %struct.s = type { i32, i32 }
11
12 ; Function Attrs: nounwind
13 define dso_local i32 @test(%struct.s* %arg) local_unnamed_addr #0 !dbg !7 {
14 entry:
15 call void @llvm.dbg.value(metadata %struct.s* %arg, metadata !17, metadata !DIExpression()), !dbg !18
16 %0 = tail call %struct.s* @llvm.preserve.array.access.index.p0s_struct.ss.p0s_struct.ss(%struct.s* %arg, i32 0, i32 2), !dbg !19
17 %1 = tail call i32* @llvm.preserve.struct.access.index.p0i32.p0s_struct.ss(%struct.s* %0, i32 1, i32 1), !dbg !19, !llvm.preserve.access.index !12
18 %2 = bitcast i32* %1 to i8*, !dbg !19
19 %call = tail call i32 @get_value(i8* %2) #4, !dbg !20
20 ret i32 %call, !dbg !21
21 }
22 ; CHECK-LABEL: test
23 ; CHECK: [[RELOC:.Ltmp[0-9]+]]
24 ; CHECK: r2 = 20
25 ; CHECK: r1 += r2
26 ; CHECK: call get_value
27 ; CHECK: exit
28 ;
29 ; CHECK: .section .BTF.ext,"",@progbits
30 ; CHECK: .long 12 # OffsetReloc
31 ; CHECK-NEXT: .long 20 # Offset reloc section string offset=20
32 ; CHECK-NEXT: .long 1
33 ; CHECK-NEXT: .long [[RELOC]]
34 ; CHECK-NEXT: .long 2
35 ; CHECK-NEXT: .long 26
36
37 declare dso_local i32 @get_value(i8*) local_unnamed_addr #1
38
39 ; Function Attrs: nounwind readnone
40 declare %struct.s* @llvm.preserve.array.access.index.p0s_struct.ss.p0s_struct.ss(%struct.s*, i32 immarg, i32 immarg) #2
41
42 ; Function Attrs: nounwind readnone
43 declare i32* @llvm.preserve.struct.access.index.p0i32.p0s_struct.ss(%struct.s*, i32 immarg, i32 immarg) #2
44
45 ; Function Attrs: nounwind readnone speculatable
46 declare void @llvm.dbg.value(metadata, metadata, metadata) #3
47
48 attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
49 attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
50 attributes #2 = { nounwind readnone }
51 attributes #3 = { nounwind readnone speculatable }
52 attributes #4 = { nounwind }
53
54 !llvm.dbg.cu = !{!0}
55 !llvm.module.flags = !{!3, !4, !5}
56 !llvm.ident = !{!6}
57
58 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (trunk 365789)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
59 !1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core")
60 !2 = !{}
61 !3 = !{i32 2, !"Dwarf Version", i32 4}
62 !4 = !{i32 2, !"Debug Info Version", i32 3}
63 !5 = !{i32 1, !"wchar_size", i32 4}
64 !6 = !{!"clang version 9.0.0 (trunk 365789)"}
65 !7 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 4, type: !8, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !16)
66 !8 = !DISubroutineType(types: !9)
67 !9 = !{!10, !11}
68 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
69 !11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
70 !12 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s", file: !1, line: 2, size: 64, elements: !13)
71 !13 = !{!14, !15}
72 !14 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !12, file: !1, line: 2, baseType: !10, size: 32)
73 !15 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !12, file: !1, line: 2, baseType: !10, size: 32, offset: 32)
74 !16 = !{!17}
75 !17 = !DILocalVariable(name: "arg", arg: 1, scope: !7, file: !1, line: 4, type: !11)
76 !18 = !DILocation(line: 0, scope: !7)
77 !19 = !DILocation(line: 4, column: 44, scope: !7)
78 !20 = !DILocation(line: 4, column: 34, scope: !7)
79 !21 = !DILocation(line: 4, column: 27, scope: !7)
0 ; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck %s
1 ;
2 ; Source code:
3 ; struct s { int a; int b; };
4 ; #define _(x) (__builtin_preserve_access_index(x))
5 ; int get_value(const void *addr);
6 ; int test(struct s *arg) { return get_value(_(&arg->b)); }
7 ; Compiler flag to generate IR:
8 ; clang -target bpf -S -O2 -g -emit-llvm test.c
9
10 %struct.s = type { i32, i32 }
11
12 ; Function Attrs: nounwind
13 define dso_local i32 @test(%struct.s* %arg) local_unnamed_addr #0 !dbg !7 {
14 entry:
15 call void @llvm.dbg.value(metadata %struct.s* %arg, metadata !17, metadata !DIExpression()), !dbg !18
16 %0 = tail call i32* @llvm.preserve.struct.access.index.p0i32.p0s_struct.ss(%struct.s* %arg, i32 1, i32 1), !dbg !19, !llvm.preserve.access.index !12
17 %1 = bitcast i32* %0 to i8*, !dbg !19
18 %call = tail call i32 @get_value(i8* %1) #4, !dbg !20
19 ret i32 %call, !dbg !21
20 }
21
22 ; CHECK-LABEL: test
23 ; CHECK: [[RELOC:.Ltmp[0-9]+]]
24 ; CHECK: r2 = 4
25 ; CHECK: r1 += r2
26 ; CHECK: call get_value
27 ; CHECK: exit
28 ;
29 ; CHECK: .section .BTF.ext,"",@progbits
30 ; CHECK: .long 12 # OffsetReloc
31 ; CHECK-NEXT: .long 20 # Offset reloc section string offset=20
32 ; CHECK-NEXT: .long 1
33 ; CHECK-NEXT: .long [[RELOC]]
34 ; CHECK-NEXT: .long 2
35 ; CHECK-NEXT: .long 26
36
37 declare dso_local i32 @get_value(i8*) local_unnamed_addr #1
38
39 ; Function Attrs: nounwind readnone
40 declare i32* @llvm.preserve.struct.access.index.p0i32.p0s_struct.ss(%struct.s*, i32 immarg, i32 immarg) #2
41
42 ; Function Attrs: nounwind readnone speculatable
43 declare void @llvm.dbg.value(metadata, metadata, metadata) #3
44
45 attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
46 attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
47 attributes #2 = { nounwind readnone }
48 attributes #3 = { nounwind readnone speculatable }
49 attributes #4 = { nounwind }
50
51 !llvm.dbg.cu = !{!0}
52 !llvm.module.flags = !{!3, !4, !5}
53 !llvm.ident = !{!6}
54
55 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (trunk 365789)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
56 !1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core")
57 !2 = !{}
58 !3 = !{i32 2, !"Dwarf Version", i32 4}
59 !4 = !{i32 2, !"Debug Info Version", i32 3}
60 !5 = !{i32 1, !"wchar_size", i32 4}
61 !6 = !{!"clang version 9.0.0 (trunk 365789)"}
62 !7 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 4, type: !8, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !16)
63 !8 = !DISubroutineType(types: !9)
64 !9 = !{!10, !11}
65 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
66 !11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
67 !12 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s", file: !1, line: 1, size: 64, elements: !13)
68 !13 = !{!14, !15}
69 !14 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !12, file: !1, line: 1, baseType: !10, size: 32)
70 !15 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !12, file: !1, line: 1, baseType: !10, size: 32, offset: 32)
71 !16 = !{!17}
72 !17 = !DILocalVariable(name: "arg", arg: 1, scope: !7, file: !1, line: 4, type: !11)
73 !18 = !DILocation(line: 0, scope: !7)
74 !19 = !DILocation(line: 4, column: 44, scope: !7)
75 !20 = !DILocation(line: 4, column: 34, scope: !7)
76 !21 = !DILocation(line: 4, column: 27, scope: !7)
0 ; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck %s
1 ;
2 ; Source code:
3 ; union u { int a; int b; };
4 ; #define _(x) (__builtin_preserve_access_index(x))
5 ; int get_value(const void *addr);
6 ; int test(union u *arg) { return get_value(_(&arg->b)); }
7 ; Compiler flag to generate IR:
8 ; clang -target bpf -S -O2 -g -emit-llvm test.c
9
10 %union.u = type { i32 }
11
12 ; Function Attrs: nounwind
13 define dso_local i32 @test(%union.u* %arg) local_unnamed_addr #0 !dbg !7 {
14 entry:
15 call void @llvm.dbg.value(metadata %union.u* %arg, metadata !17, metadata !DIExpression()), !dbg !18
16 %0 = tail call %union.u* @llvm.preserve.union.access.index.p0s_union.us.p0s_union.us(%union.u* %arg, i32 1), !dbg !19, !llvm.preserve.access.index !12
17 %1 = bitcast %union.u* %0 to i8*, !dbg !19
18 %call = tail call i32 @get_value(i8* %1) #4, !dbg !20
19 ret i32 %call, !dbg !21
20 }
21 ; CHECK-LABEL: test
22 ; CHECK: [[RELOC:.Ltmp[0-9]+]]
23 ; CHECK: r2 = 0
24 ; CHECK: r1 += r2
25 ; CHECK: call get_value
26 ; CHECK: exit
27
28 ; CHECK: .section .BTF.ext,"",@progbits
29 ; CHECK: .long 12 # OffsetReloc
30 ; CHECK-NEXT: .long 20 # Offset reloc section string offset=20
31 ; CHECK-NEXT: .long 1
32 ; CHECK-NEXT: .long [[RELOC]]
33 ; CHECK-NEXT: .long 2
34 ; CHECK-NEXT: .long 26
35
36 declare dso_local i32 @get_value(i8*) local_unnamed_addr #1
37
38 ; Function Attrs: nounwind readnone
39 declare %union.u* @llvm.preserve.union.access.index.p0s_union.us.p0s_union.us(%union.u*, i32 immarg) #2
40
41 ; Function Attrs: nounwind readnone speculatable
42 declare void @llvm.dbg.value(metadata, metadata, metadata) #3
43
44 attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
45 attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
46 attributes #2 = { nounwind readnone }
47 attributes #3 = { nounwind readnone speculatable }
48 attributes #4 = { nounwind }
49
50 !llvm.dbg.cu = !{!0}
51 !llvm.module.flags = !{!3, !4, !5}
52 !llvm.ident = !{!6}
53
54 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (trunk 365789)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
55 !1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core")
56 !2 = !{}
57 !3 = !{i32 2, !"Dwarf Version", i32 4}
58 !4 = !{i32 2, !"Debug Info Version", i32 3}
59 !5 = !{i32 1, !"wchar_size", i32 4}
60 !6 = !{!"clang version 9.0.0 (trunk 365789)"}
61 !7 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 4, type: !8, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !16)
62 !8 = !DISubroutineType(types: !9)
63 !9 = !{!10, !11}
64 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
65 !11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
66 !12 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "u", file: !1, line: 1, size: 32, elements: !13)
67 !13 = !{!14, !15}
68 !14 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !12, file: !1, line: 1, baseType: !10, size: 32)
69 !15 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !12, file: !1, line: 1, baseType: !10, size: 32)
70 !16 = !{!17}
71 !17 = !DILocalVariable(name: "arg", arg: 1, scope: !7, file: !1, line: 4, type: !11)
72 !18 = !DILocation(line: 0, scope: !7)
73 !19 = !DILocation(line: 4, column: 43, scope: !7)
74 !20 = !DILocation(line: 4, column: 33, scope: !7)
75 !21 = !DILocation(line: 4, column: 26, scope: !7)