mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[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 llvm-svn: 366038
This commit is contained in:
parent
9732944946
commit
7ce6119bf4
@ -17332,7 +17332,7 @@ Syntax:
|
||||
"""""""
|
||||
::
|
||||
|
||||
declare <type2>
|
||||
declare <ret_type>
|
||||
@llvm.preserve.array.access.index.p0s_union.anons.p0a10s_union.anons(<type> base,
|
||||
i32 dim,
|
||||
i32 index)
|
||||
@ -17342,7 +17342,9 @@ Overview:
|
||||
|
||||
The '``llvm.preserve.array.access.index``' intrinsic returns the getelementptr address
|
||||
based on array base ``base``, array dimension ``dim`` and the last access index ``index``
|
||||
into the array.
|
||||
into the array. The return type ``ret_type`` is a pointer type to the array element.
|
||||
The array ``dim`` and ``index`` are preserved which is more robust than
|
||||
getelementptr instruction which may be subject to compiler transformation.
|
||||
|
||||
Arguments:
|
||||
""""""""""
|
||||
@ -17375,6 +17377,8 @@ The '``llvm.preserve.union.access.index``' intrinsic carries the debuginfo field
|
||||
``di_index`` and returns the ``base`` address.
|
||||
The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction
|
||||
to provide union debuginfo type.
|
||||
The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``.
|
||||
The return type ``type`` is the same as the ``base`` type.
|
||||
|
||||
Arguments:
|
||||
""""""""""
|
||||
@ -17393,7 +17397,7 @@ Syntax:
|
||||
"""""""
|
||||
::
|
||||
|
||||
declare <type2>
|
||||
declare <ret_type>
|
||||
@llvm.preserve.struct.access.index.p0i8.p0s_struct.anon.0s(<type> base,
|
||||
i32 gep_index,
|
||||
i32 di_index)
|
||||
@ -17405,6 +17409,8 @@ The '``llvm.preserve.struct.access.index``' intrinsic returns the getelementptr
|
||||
based on struct base ``base`` and IR struct member index ``gep_index``.
|
||||
The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction
|
||||
to provide struct debuginfo type.
|
||||
The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``.
|
||||
The return type ``ret_type`` is a pointer type to the structure member.
|
||||
|
||||
Arguments:
|
||||
""""""""""
|
||||
|
80
test/CodeGen/BPF/CORE/intrinsic-array.ll
Normal file
80
test/CodeGen/BPF/CORE/intrinsic-array.ll
Normal file
@ -0,0 +1,80 @@
|
||||
; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck %s
|
||||
;
|
||||
; Source code:
|
||||
; #define _(x) (__builtin_preserve_access_index(x))
|
||||
; struct s { int a; int b; };
|
||||
; int get_value(const void *addr);
|
||||
; int test(struct s *arg) { return get_value(_(&arg[2].b)); }
|
||||
; Compiler flag to generate IR:
|
||||
; clang -target bpf -S -O2 -g -emit-llvm test.c
|
||||
|
||||
%struct.s = type { i32, i32 }
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define dso_local i32 @test(%struct.s* %arg) local_unnamed_addr #0 !dbg !7 {
|
||||
entry:
|
||||
call void @llvm.dbg.value(metadata %struct.s* %arg, metadata !17, metadata !DIExpression()), !dbg !18
|
||||
%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
|
||||
%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
|
||||
%2 = bitcast i32* %1 to i8*, !dbg !19
|
||||
%call = tail call i32 @get_value(i8* %2) #4, !dbg !20
|
||||
ret i32 %call, !dbg !21
|
||||
}
|
||||
; CHECK-LABEL: test
|
||||
; CHECK: [[RELOC:.Ltmp[0-9]+]]
|
||||
; CHECK: r2 = 20
|
||||
; CHECK: r1 += r2
|
||||
; CHECK: call get_value
|
||||
; CHECK: exit
|
||||
;
|
||||
; CHECK: .section .BTF.ext,"",@progbits
|
||||
; CHECK: .long 12 # OffsetReloc
|
||||
; CHECK-NEXT: .long 20 # Offset reloc section string offset=20
|
||||
; CHECK-NEXT: .long 1
|
||||
; CHECK-NEXT: .long [[RELOC]]
|
||||
; CHECK-NEXT: .long 2
|
||||
; CHECK-NEXT: .long 26
|
||||
|
||||
declare dso_local i32 @get_value(i8*) local_unnamed_addr #1
|
||||
|
||||
; Function Attrs: nounwind readnone
|
||||
declare %struct.s* @llvm.preserve.array.access.index.p0s_struct.ss.p0s_struct.ss(%struct.s*, i32 immarg, i32 immarg) #2
|
||||
|
||||
; Function Attrs: nounwind readnone
|
||||
declare i32* @llvm.preserve.struct.access.index.p0i32.p0s_struct.ss(%struct.s*, i32 immarg, i32 immarg) #2
|
||||
|
||||
; Function Attrs: nounwind readnone speculatable
|
||||
declare void @llvm.dbg.value(metadata, metadata, metadata) #3
|
||||
|
||||
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" }
|
||||
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" }
|
||||
attributes #2 = { nounwind readnone }
|
||||
attributes #3 = { nounwind readnone speculatable }
|
||||
attributes #4 = { nounwind }
|
||||
|
||||
!llvm.dbg.cu = !{!0}
|
||||
!llvm.module.flags = !{!3, !4, !5}
|
||||
!llvm.ident = !{!6}
|
||||
|
||||
!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)
|
||||
!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core")
|
||||
!2 = !{}
|
||||
!3 = !{i32 2, !"Dwarf Version", i32 4}
|
||||
!4 = !{i32 2, !"Debug Info Version", i32 3}
|
||||
!5 = !{i32 1, !"wchar_size", i32 4}
|
||||
!6 = !{!"clang version 9.0.0 (trunk 365789)"}
|
||||
!7 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 4, type: !8, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !16)
|
||||
!8 = !DISubroutineType(types: !9)
|
||||
!9 = !{!10, !11}
|
||||
!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
|
||||
!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
|
||||
!12 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s", file: !1, line: 2, size: 64, elements: !13)
|
||||
!13 = !{!14, !15}
|
||||
!14 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !12, file: !1, line: 2, baseType: !10, size: 32)
|
||||
!15 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !12, file: !1, line: 2, baseType: !10, size: 32, offset: 32)
|
||||
!16 = !{!17}
|
||||
!17 = !DILocalVariable(name: "arg", arg: 1, scope: !7, file: !1, line: 4, type: !11)
|
||||
!18 = !DILocation(line: 0, scope: !7)
|
||||
!19 = !DILocation(line: 4, column: 44, scope: !7)
|
||||
!20 = !DILocation(line: 4, column: 34, scope: !7)
|
||||
!21 = !DILocation(line: 4, column: 27, scope: !7)
|
77
test/CodeGen/BPF/CORE/intrinsic-struct.ll
Normal file
77
test/CodeGen/BPF/CORE/intrinsic-struct.ll
Normal file
@ -0,0 +1,77 @@
|
||||
; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck %s
|
||||
;
|
||||
; Source code:
|
||||
; struct s { int a; int b; };
|
||||
; #define _(x) (__builtin_preserve_access_index(x))
|
||||
; int get_value(const void *addr);
|
||||
; int test(struct s *arg) { return get_value(_(&arg->b)); }
|
||||
; Compiler flag to generate IR:
|
||||
; clang -target bpf -S -O2 -g -emit-llvm test.c
|
||||
|
||||
%struct.s = type { i32, i32 }
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define dso_local i32 @test(%struct.s* %arg) local_unnamed_addr #0 !dbg !7 {
|
||||
entry:
|
||||
call void @llvm.dbg.value(metadata %struct.s* %arg, metadata !17, metadata !DIExpression()), !dbg !18
|
||||
%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
|
||||
%1 = bitcast i32* %0 to i8*, !dbg !19
|
||||
%call = tail call i32 @get_value(i8* %1) #4, !dbg !20
|
||||
ret i32 %call, !dbg !21
|
||||
}
|
||||
|
||||
; CHECK-LABEL: test
|
||||
; CHECK: [[RELOC:.Ltmp[0-9]+]]
|
||||
; CHECK: r2 = 4
|
||||
; CHECK: r1 += r2
|
||||
; CHECK: call get_value
|
||||
; CHECK: exit
|
||||
;
|
||||
; CHECK: .section .BTF.ext,"",@progbits
|
||||
; CHECK: .long 12 # OffsetReloc
|
||||
; CHECK-NEXT: .long 20 # Offset reloc section string offset=20
|
||||
; CHECK-NEXT: .long 1
|
||||
; CHECK-NEXT: .long [[RELOC]]
|
||||
; CHECK-NEXT: .long 2
|
||||
; CHECK-NEXT: .long 26
|
||||
|
||||
declare dso_local i32 @get_value(i8*) local_unnamed_addr #1
|
||||
|
||||
; Function Attrs: nounwind readnone
|
||||
declare i32* @llvm.preserve.struct.access.index.p0i32.p0s_struct.ss(%struct.s*, i32 immarg, i32 immarg) #2
|
||||
|
||||
; Function Attrs: nounwind readnone speculatable
|
||||
declare void @llvm.dbg.value(metadata, metadata, metadata) #3
|
||||
|
||||
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" }
|
||||
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" }
|
||||
attributes #2 = { nounwind readnone }
|
||||
attributes #3 = { nounwind readnone speculatable }
|
||||
attributes #4 = { nounwind }
|
||||
|
||||
!llvm.dbg.cu = !{!0}
|
||||
!llvm.module.flags = !{!3, !4, !5}
|
||||
!llvm.ident = !{!6}
|
||||
|
||||
!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)
|
||||
!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core")
|
||||
!2 = !{}
|
||||
!3 = !{i32 2, !"Dwarf Version", i32 4}
|
||||
!4 = !{i32 2, !"Debug Info Version", i32 3}
|
||||
!5 = !{i32 1, !"wchar_size", i32 4}
|
||||
!6 = !{!"clang version 9.0.0 (trunk 365789)"}
|
||||
!7 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 4, type: !8, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !16)
|
||||
!8 = !DISubroutineType(types: !9)
|
||||
!9 = !{!10, !11}
|
||||
!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
|
||||
!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
|
||||
!12 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s", file: !1, line: 1, size: 64, elements: !13)
|
||||
!13 = !{!14, !15}
|
||||
!14 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !12, file: !1, line: 1, baseType: !10, size: 32)
|
||||
!15 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !12, file: !1, line: 1, baseType: !10, size: 32, offset: 32)
|
||||
!16 = !{!17}
|
||||
!17 = !DILocalVariable(name: "arg", arg: 1, scope: !7, file: !1, line: 4, type: !11)
|
||||
!18 = !DILocation(line: 0, scope: !7)
|
||||
!19 = !DILocation(line: 4, column: 44, scope: !7)
|
||||
!20 = !DILocation(line: 4, column: 34, scope: !7)
|
||||
!21 = !DILocation(line: 4, column: 27, scope: !7)
|
76
test/CodeGen/BPF/CORE/intrinsic-union.ll
Normal file
76
test/CodeGen/BPF/CORE/intrinsic-union.ll
Normal file
@ -0,0 +1,76 @@
|
||||
; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck %s
|
||||
;
|
||||
; Source code:
|
||||
; union u { int a; int b; };
|
||||
; #define _(x) (__builtin_preserve_access_index(x))
|
||||
; int get_value(const void *addr);
|
||||
; int test(union u *arg) { return get_value(_(&arg->b)); }
|
||||
; Compiler flag to generate IR:
|
||||
; clang -target bpf -S -O2 -g -emit-llvm test.c
|
||||
|
||||
%union.u = type { i32 }
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define dso_local i32 @test(%union.u* %arg) local_unnamed_addr #0 !dbg !7 {
|
||||
entry:
|
||||
call void @llvm.dbg.value(metadata %union.u* %arg, metadata !17, metadata !DIExpression()), !dbg !18
|
||||
%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
|
||||
%1 = bitcast %union.u* %0 to i8*, !dbg !19
|
||||
%call = tail call i32 @get_value(i8* %1) #4, !dbg !20
|
||||
ret i32 %call, !dbg !21
|
||||
}
|
||||
; CHECK-LABEL: test
|
||||
; CHECK: [[RELOC:.Ltmp[0-9]+]]
|
||||
; CHECK: r2 = 0
|
||||
; CHECK: r1 += r2
|
||||
; CHECK: call get_value
|
||||
; CHECK: exit
|
||||
|
||||
; CHECK: .section .BTF.ext,"",@progbits
|
||||
; CHECK: .long 12 # OffsetReloc
|
||||
; CHECK-NEXT: .long 20 # Offset reloc section string offset=20
|
||||
; CHECK-NEXT: .long 1
|
||||
; CHECK-NEXT: .long [[RELOC]]
|
||||
; CHECK-NEXT: .long 2
|
||||
; CHECK-NEXT: .long 26
|
||||
|
||||
declare dso_local i32 @get_value(i8*) local_unnamed_addr #1
|
||||
|
||||
; Function Attrs: nounwind readnone
|
||||
declare %union.u* @llvm.preserve.union.access.index.p0s_union.us.p0s_union.us(%union.u*, i32 immarg) #2
|
||||
|
||||
; Function Attrs: nounwind readnone speculatable
|
||||
declare void @llvm.dbg.value(metadata, metadata, metadata) #3
|
||||
|
||||
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" }
|
||||
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" }
|
||||
attributes #2 = { nounwind readnone }
|
||||
attributes #3 = { nounwind readnone speculatable }
|
||||
attributes #4 = { nounwind }
|
||||
|
||||
!llvm.dbg.cu = !{!0}
|
||||
!llvm.module.flags = !{!3, !4, !5}
|
||||
!llvm.ident = !{!6}
|
||||
|
||||
!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)
|
||||
!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core")
|
||||
!2 = !{}
|
||||
!3 = !{i32 2, !"Dwarf Version", i32 4}
|
||||
!4 = !{i32 2, !"Debug Info Version", i32 3}
|
||||
!5 = !{i32 1, !"wchar_size", i32 4}
|
||||
!6 = !{!"clang version 9.0.0 (trunk 365789)"}
|
||||
!7 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 4, type: !8, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !16)
|
||||
!8 = !DISubroutineType(types: !9)
|
||||
!9 = !{!10, !11}
|
||||
!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
|
||||
!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
|
||||
!12 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "u", file: !1, line: 1, size: 32, elements: !13)
|
||||
!13 = !{!14, !15}
|
||||
!14 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !12, file: !1, line: 1, baseType: !10, size: 32)
|
||||
!15 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !12, file: !1, line: 1, baseType: !10, size: 32)
|
||||
!16 = !{!17}
|
||||
!17 = !DILocalVariable(name: "arg", arg: 1, scope: !7, file: !1, line: 4, type: !11)
|
||||
!18 = !DILocation(line: 0, scope: !7)
|
||||
!19 = !DILocation(line: 4, column: 43, scope: !7)
|
||||
!20 = !DILocation(line: 4, column: 33, scope: !7)
|
||||
!21 = !DILocation(line: 4, column: 26, scope: !7)
|
Loading…
x
Reference in New Issue
Block a user