| 1 |
; RUN: opt -O2 -mtriple=bpf-pc-linux %s | llvm-dis > %t1 |
| 2 |
; RUN: llc -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK %s |
| 3 |
; RUN: llc -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK %s |
| 4 |
; |
| 5 |
; Source code: |
| 6 |
; static int (*bpf_log)(unsigned long tid, ptr data, int data_size) = (ptr)999; |
| 7 |
; struct { |
| 8 |
; char f1[100]; |
| 9 |
; typeof(3) f2; |
| 10 |
; } tmp__abc = {1, 3}; |
| 11 |
; void prog1() { |
| 12 |
; bpf_log(__builtin_btf_type_id(tmp__abc, 0), &tmp__abc, sizeof(tmp__abc)); |
| 13 |
; } |
| 14 |
; void prog2() { |
| 15 |
; bpf_log(__builtin_btf_type_id(&tmp__abc, 0), &tmp__abc, sizeof(tmp__abc)); |
| 16 |
; } |
| 17 |
; void prog3() { |
| 18 |
; bpf_log(__builtin_btf_type_id(tmp__abc.f1[3], 1), &tmp__abc, sizeof(tmp__abc)); |
| 19 |
; } |
| 20 |
; Compilation flag: |
| 21 |
; clang -target bpf -O2 -g -S -emit-llvm -Xclang -disable-llvm-passes test.c |
| 22 |
|
| 23 |
@tmp__abc = dso_local global { <{ i8, i8, [98 x i8] }>, i32 } { <{ i8, i8, [98 x i8] }> <{ i8 1, i8 3, [98 x i8] zeroinitializer }>, i32 0 }, align 4, !dbg !0 |
| 24 |
@bpf_log = internal global ptr inttoptr (i64 999 to ptr), align 8, !dbg !17 |
| 25 |
|
| 26 |
; Function Attrs: nounwind |
| 27 |
define dso_local void @prog1() !dbg !28 { |
| 28 |
entry: |
| 29 |
%0 = load ptr, ptr @bpf_log, align 8, !dbg !31, !tbaa !32 |
| 30 |
%1 = call i64 @llvm.bpf.btf.type.id(i32 0, i64 0), !dbg !36, !llvm.preserve.access.index !7 |
| 31 |
%call = call i32 %0(i64 %1, ptr @tmp__abc, i32 104), !dbg !31 |
| 32 |
ret void, !dbg !37 |
| 33 |
} |
| 34 |
|
| 35 |
; Function Attrs: nounwind readnone |
| 36 |
declare i64 @llvm.bpf.btf.type.id(i32, i64) |
| 37 |
|
| 38 |
; Function Attrs: nounwind |
| 39 |
define dso_local void @prog2() !dbg !38 { |
| 40 |
entry: |
| 41 |
%0 = load ptr, ptr @bpf_log, align 8, !dbg !39, !tbaa !32 |
| 42 |
%1 = call i64 @llvm.bpf.btf.type.id(i32 1, i64 0), !dbg !40, !llvm.preserve.access.index !6 |
| 43 |
%call = call i32 %0(i64 %1, ptr @tmp__abc, i32 104), !dbg !39 |
| 44 |
ret void, !dbg !41 |
| 45 |
} |
| 46 |
|
| 47 |
; Function Attrs: nounwind |
| 48 |
define dso_local void @prog3() !dbg !42 { |
| 49 |
entry: |
| 50 |
%0 = load ptr, ptr @bpf_log, align 8, !dbg !43, !tbaa !32 |
| 51 |
%1 = call i64 @llvm.bpf.btf.type.id(i32 2, i64 1), !dbg !44, !llvm.preserve.access.index !11 |
| 52 |
%call = call i32 %0(i64 %1, ptr @tmp__abc, i32 104), !dbg !43 |
| 53 |
ret void, !dbg !45 |
| 54 |
} |
| 55 |
|
| 56 |
; CHECK-LABEL: prog1 |
| 57 |
; CHECK: r1 = 3 ll |
| 58 |
; CHECK-LABEL: prog2 |
| 59 |
; CHECK: r1 = 10 ll |
| 60 |
; CHECK-LABEL: prog3 |
| 61 |
; CHECK: r1 = 4 ll |
| 62 |
|
| 63 |
; CHECK: .long 0 # BTF_KIND_STRUCT(id = 3) |
| 64 |
; CHECK-NEXT: .long 67108866 # 0x4000002 |
| 65 |
; CHECK-NEXT: .long 104 |
| 66 |
; CHECK-NEXT: .long 13 |
| 67 |
; CHECK-NEXT: .long 5 |
| 68 |
; CHECK-NEXT: .long 0 # 0x0 |
| 69 |
; CHECK-NEXT: .long 16 |
| 70 |
; CHECK-NEXT: .long 7 |
| 71 |
; CHECK-NEXT: .long 800 # 0x320 |
| 72 |
; CHECK: .long 19 # BTF_KIND_INT(id = 4) |
| 73 |
; CHECK: .long 0 # BTF_KIND_PTR(id = 10) |
| 74 |
; CHECK-NEXT: .long 33554432 # 0x2000000 |
| 75 |
; CHECK-NEXT: .long 3 |
| 76 |
|
| 77 |
; CHECK: .ascii ".text" # string offset=7 |
| 78 |
; CHECK: .ascii "f1" # string offset=13 |
| 79 |
; CHECK: .ascii "f2" # string offset=16 |
| 80 |
; CHECK: .ascii "char" # string offset=19 |
| 81 |
; CHECK: .byte 48 # string offset=48 |
| 82 |
|
| 83 |
; CHECK: .long 16 # FieldReloc |
| 84 |
; CHECK-NEXT: .long 7 # Field reloc section string offset=7 |
| 85 |
; CHECK-NEXT: .long 3 |
| 86 |
; CHECK-NEXT: .long .Ltmp{{[0-9]+}} |
| 87 |
; CHECK-NEXT: .long 3 |
| 88 |
; CHECK-NEXT: .long 48 |
| 89 |
; CHECK-NEXT: .long 6 |
| 90 |
; CHECK-NEXT: .long .Ltmp{{[0-9]+}} |
| 91 |
; CHECK-NEXT: .long 10 |
| 92 |
; CHECK-NEXT: .long 48 |
| 93 |
; CHECK-NEXT: .long 6 |
| 94 |
; CHECK-NEXT: .long .Ltmp{{[0-9]+}} |
| 95 |
; CHECK-NEXT: .long 4 |
| 96 |
; CHECK-NEXT: .long 48 |
| 97 |
; CHECK-NEXT: .long 7 |
| 98 |
|
| 99 |
!llvm.dbg.cu = !{!2} |
| 100 |
!llvm.module.flags = !{!24, !25, !26} |
| 101 |
!llvm.ident = !{!27} |
| 102 |
|
| 103 |
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) |
| 104 |
!1 = distinct !DIGlobalVariable(name: "tmp__abc", scope: !2, file: !3, line: 5, type: !7, isLocal: false, isDefinition: true) |
| 105 |
!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 12.0.0 (https://github.com/llvm/llvm-project.git 630c2da0e967e27e2a4c678dfc6e452a74141880)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, retainedTypes: !5, globals: !16, splitDebugInlining: false, nameTableKind: None) |
| 106 |
!3 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core") |
| 107 |
!4 = !{} |
| 108 |
!5 = !{!6, !11} |
| 109 |
!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64) |
| 110 |
!7 = distinct !DICompositeType(tag: DW_TAG_structure_type, file: !3, line: 2, size: 832, elements: !8) |
| 111 |
!8 = !{!9, !14} |
| 112 |
!9 = !DIDerivedType(tag: DW_TAG_member, name: "f1", scope: !7, file: !3, line: 3, baseType: !10, size: 800) |
| 113 |
!10 = !DICompositeType(tag: DW_TAG_array_type, baseType: !11, size: 800, elements: !12) |
| 114 |
!11 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) |
| 115 |
!12 = !{!13} |
| 116 |
!13 = !DISubrange(count: 100) |
| 117 |
!14 = !DIDerivedType(tag: DW_TAG_member, name: "f2", scope: !7, file: !3, line: 4, baseType: !15, size: 32, offset: 800) |
| 118 |
!15 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) |
| 119 |
!16 = !{!0, !17} |
| 120 |
!17 = !DIGlobalVariableExpression(var: !18, expr: !DIExpression()) |
| 121 |
!18 = distinct !DIGlobalVariable(name: "bpf_log", scope: !2, file: !3, line: 1, type: !19, isLocal: true, isDefinition: true) |
| 122 |
!19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64) |
| 123 |
!20 = !DISubroutineType(types: !21) |
| 124 |
!21 = !{!15, !22, !23, !15} |
| 125 |
!22 = !DIBasicType(name: "long unsigned int", size: 64, encoding: DW_ATE_unsigned) |
| 126 |
!23 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64) |
| 127 |
!24 = !{i32 7, !"Dwarf Version", i32 4} |
| 128 |
!25 = !{i32 2, !"Debug Info Version", i32 3} |
| 129 |
!26 = !{i32 1, !"wchar_size", i32 4} |
| 130 |
!27 = !{!"clang version 12.0.0 (https://github.com/llvm/llvm-project.git 630c2da0e967e27e2a4c678dfc6e452a74141880)"} |
| 131 |
!28 = distinct !DISubprogram(name: "prog1", scope: !3, file: !3, line: 6, type: !29, scopeLine: 6, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !4) |
| 132 |
!29 = !DISubroutineType(types: !30) |
| 133 |
!30 = !{null} |
| 134 |
!31 = !DILocation(line: 7, column: 3, scope: !28) |
| 135 |
!32 = !{!33, !33, i64 0} |
| 136 |
!33 = !{!"any pointer", !34, i64 0} |
| 137 |
!34 = !{!"omnipotent char", !35, i64 0} |
| 138 |
!35 = !{!"Simple C/C++ TBAA"} |
| 139 |
!36 = !DILocation(line: 7, column: 11, scope: !28) |
| 140 |
!37 = !DILocation(line: 8, column: 1, scope: !28) |
| 141 |
!38 = distinct !DISubprogram(name: "prog2", scope: !3, file: !3, line: 9, type: !29, scopeLine: 9, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !4) |
| 142 |
!39 = !DILocation(line: 10, column: 3, scope: !38) |
| 143 |
!40 = !DILocation(line: 10, column: 11, scope: !38) |
| 144 |
!41 = !DILocation(line: 11, column: 1, scope: !38) |
| 145 |
!42 = distinct !DISubprogram(name: "prog3", scope: !3, file: !3, line: 12, type: !29, scopeLine: 12, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !4) |
| 146 |
!43 = !DILocation(line: 13, column: 3, scope: !42) |
| 147 |
!44 = !DILocation(line: 13, column: 11, scope: !42) |
| 148 |
!45 = !DILocation(line: 14, column: 1, scope: !42) |