1 ; RUN: opt -O2 -mtriple=bpf-pc-linux %s | llvm-dis > %t1
2 ; RUN: llc -o - %t1 | FileCheck %s
3 ; RUN: opt -passes='default<O2>' -mtriple=bpf-pc-linux %s | llvm-dis > %t1
4 ; RUN: llc -o - %t1 | FileCheck %s
7 ; struct s1 { int a; int b; } __attribute__((preserve_access_index));
8 ; int foo(struct s1 *arg) { return arg->a; }
9 ; int bar(struct s1 *arg) { return arg->a; }
11 ; clang -target bpf -O2 -S -emit-llvm -g -Xclang -disable-llvm-passes test.c
13 %struct.s1 = type { i32, i32 }
15 ; Function Attrs: nounwind
16 define dso_local i32 @foo(ptr %arg) #0 !dbg !7 {
18 %arg.addr = alloca ptr, align 8
19 store ptr %arg, ptr %arg.addr, align 8, !tbaa !18
20 call void @llvm.dbg.declare(metadata ptr %arg.addr, metadata !17, metadata !DIExpression()), !dbg !22
21 %0 = load ptr, ptr %arg.addr, align 8, !dbg !23, !tbaa !18
22 %1 = call ptr @llvm.preserve.struct.access.index.p0.p0.s1s(ptr elementtype(%struct.s1) %0, i32 0, i32 0), !dbg !24, !llvm.preserve.access.index !12
23 %2 = load i32, ptr %1, align 4, !dbg !24, !tbaa !25
27 ; Function Attrs: nounwind readnone speculatable willreturn
28 declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
30 ; Function Attrs: nounwind readnone
31 declare ptr @llvm.preserve.struct.access.index.p0.p0.s1s(ptr, i32 immarg, i32 immarg) #2
33 ; Function Attrs: nounwind
34 define dso_local i32 @bar(ptr %arg) #0 !dbg !29 {
36 %arg.addr = alloca ptr, align 8
37 store ptr %arg, ptr %arg.addr, align 8, !tbaa !18
38 call void @llvm.dbg.declare(metadata ptr %arg.addr, metadata !31, metadata !DIExpression()), !dbg !32
39 %0 = load ptr, ptr %arg.addr, align 8, !dbg !33, !tbaa !18
40 %1 = call ptr @llvm.preserve.struct.access.index.p0.p0.s1s(ptr elementtype(%struct.s1) %0, i32 0, i32 0), !dbg !34, !llvm.preserve.access.index !12
41 %2 = load i32, ptr %1, align 4, !dbg !34, !tbaa !25
45 ; CHECK: .long 1 # BTF_KIND_STRUCT(id = 2)
47 ; CHECK: .ascii "s1" # string offset=1
48 ; CHECK: .ascii ".text" # string offset=20
49 ; CHECK: .ascii "0:0" # string offset=26
51 ; CHECK: .long 16 # FieldReloc
52 ; CHECK-NEXT: .long 20 # Field reloc section string offset=20
54 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
56 ; CHECK-NEXT: .long 26
58 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
60 ; CHECK-NEXT: .long 26
63 attributes #0 = { nounwind "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
64 attributes #1 = { nounwind readnone speculatable willreturn }
65 attributes #2 = { nounwind readnone }
68 !llvm.module.flags = !{!3, !4, !5}
71 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 12.0.0 (https://github.com/llvm/llvm-project.git 2f40e20613758b3e11a15494c09f4b6973673d6b)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
72 !1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core")
74 !3 = !{i32 7, !"Dwarf Version", i32 4}
75 !4 = !{i32 2, !"Debug Info Version", i32 3}
76 !5 = !{i32 1, !"wchar_size", i32 4}
77 !6 = !{!"clang version 12.0.0 (https://github.com/llvm/llvm-project.git 2f40e20613758b3e11a15494c09f4b6973673d6b)"}
78 !7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !8, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !16)
79 !8 = !DISubroutineType(types: !9)
81 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
82 !11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
83 !12 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s1", file: !1, line: 1, size: 64, elements: !13)
85 !14 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !12, file: !1, line: 1, baseType: !10, size: 32)
86 !15 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !12, file: !1, line: 1, baseType: !10, size: 32, offset: 32)
88 !17 = !DILocalVariable(name: "arg", arg: 1, scope: !7, file: !1, line: 2, type: !11)
89 !18 = !{!19, !19, i64 0}
90 !19 = !{!"any pointer", !20, i64 0}
91 !20 = !{!"omnipotent char", !21, i64 0}
92 !21 = !{!"Simple C/C++ TBAA"}
93 !22 = !DILocation(line: 2, column: 20, scope: !7)
94 !23 = !DILocation(line: 2, column: 34, scope: !7)
95 !24 = !DILocation(line: 2, column: 39, scope: !7)
96 !25 = !{!26, !27, i64 0}
97 !26 = !{!"s1", !27, i64 0, !27, i64 4}
98 !27 = !{!"int", !20, i64 0}
99 !28 = !DILocation(line: 2, column: 27, scope: !7)
100 !29 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 3, type: !8, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !30)
102 !31 = !DILocalVariable(name: "arg", arg: 1, scope: !29, file: !1, line: 3, type: !11)
103 !32 = !DILocation(line: 3, column: 20, scope: !29)
104 !33 = !DILocation(line: 3, column: 34, scope: !29)
105 !34 = !DILocation(line: 3, column: 39, scope: !29)
106 !35 = !DILocation(line: 3, column: 27, scope: !29)