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; };
8 ; int foo(struct s1 *arg) { return __builtin_btf_type_id(*arg, 0); }
9 ; int bar(struct s1 *arg) { return __builtin_btf_type_id(*arg, 0); }
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 = call i64 @llvm.bpf.btf.type.id(i32 0, i64 0), !dbg !23, !llvm.preserve.access.index !12
22 %conv = trunc i64 %0 to i32, !dbg !23
23 ret i32 %conv, !dbg !24
26 ; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
27 declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
29 ; Function Attrs: nounwind readnone
30 declare i64 @llvm.bpf.btf.type.id(i32, i64) #2
32 ; Function Attrs: nounwind
33 define dso_local i32 @bar(ptr %arg) #0 !dbg !25 {
35 %arg.addr = alloca ptr, align 8
36 store ptr %arg, ptr %arg.addr, align 8, !tbaa !18
37 call void @llvm.dbg.declare(metadata ptr %arg.addr, metadata !27, metadata !DIExpression()), !dbg !28
38 %0 = call i64 @llvm.bpf.btf.type.id(i32 1, i64 0), !dbg !29, !llvm.preserve.access.index !12
39 %conv = trunc i64 %0 to i32, !dbg !29
40 ret i32 %conv, !dbg !30
43 ; CHECK: .long 1 # BTF_KIND_STRUCT(id = 2)
45 ; CHECK: .ascii "s1" # string offset=1
46 ; CHECK: .ascii ".text" # string offset=20
47 ; CHECK: .byte 48 # string offset=26
49 ; CHECK: .long 16 # FieldReloc
50 ; CHECK-NEXT: .long 20 # Field reloc section string offset=20
52 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
54 ; CHECK-NEXT: .long 26
56 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
58 ; CHECK-NEXT: .long 26
61 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" }
62 attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
63 attributes #2 = { nounwind readnone }
66 !llvm.module.flags = !{!3, !4, !5}
69 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 12.0.0 (https://github.com/llvm/llvm-project.git c1c153c3c70641a23c4a9540a897ff2d4eb4c5b2)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
70 !1 = !DIFile(filename: "test.c", directory: "/home/yhs/work/tests/dup")
72 !3 = !{i32 7, !"Dwarf Version", i32 4}
73 !4 = !{i32 2, !"Debug Info Version", i32 3}
74 !5 = !{i32 1, !"wchar_size", i32 4}
75 !6 = !{!"clang version 12.0.0 (https://github.com/llvm/llvm-project.git c1c153c3c70641a23c4a9540a897ff2d4eb4c5b2)"}
76 !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)
77 !8 = !DISubroutineType(types: !9)
79 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
80 !11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
81 !12 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s1", file: !1, line: 1, size: 64, elements: !13)
83 !14 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !12, file: !1, line: 1, baseType: !10, size: 32)
84 !15 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !12, file: !1, line: 1, baseType: !10, size: 32, offset: 32)
86 !17 = !DILocalVariable(name: "arg", arg: 1, scope: !7, file: !1, line: 2, type: !11)
87 !18 = !{!19, !19, i64 0}
88 !19 = !{!"any pointer", !20, i64 0}
89 !20 = !{!"omnipotent char", !21, i64 0}
90 !21 = !{!"Simple C/C++ TBAA"}
91 !22 = !DILocation(line: 2, column: 20, scope: !7)
92 !23 = !DILocation(line: 2, column: 34, scope: !7)
93 !24 = !DILocation(line: 2, column: 27, scope: !7)
94 !25 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 3, type: !8, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !26)
96 !27 = !DILocalVariable(name: "arg", arg: 1, scope: !25, file: !1, line: 3, type: !11)
97 !28 = !DILocation(line: 3, column: 20, scope: !25)
98 !29 = !DILocation(line: 3, column: 34, scope: !25)
99 !30 = !DILocation(line: 3, column: 27, scope: !25)