xref: /llvm-project/llvm/test/CodeGen/BPF/CORE/intrinsic-fieldinfo-byte-size-4.ll (revision 60228733726e25d011b1f9221e005732191cc077)
1; RUN: opt -O2 %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; Source code:
5;   typedef struct s1 { int a1; int a2:4; int a3;} __s1;
6;   enum { FIELD_BYTE_SIZE = 1, };
7;   int test(__s1 *arg) {
8;     return __builtin_preserve_field_info(arg->a2, FIELD_BYTE_SIZE);
9;   }
10; Compilation flag:
11;   clang -target bpf -O2 -g -S -emit-llvm -Xclang -disable-llvm-passes test.c
12
13target triple = "bpf"
14
15%struct.s1 = type { i32, i8, i32 }
16
17; Function Attrs: nounwind readnone
18define dso_local i32 @test(ptr readnone %arg) local_unnamed_addr #0 !dbg !11 {
19entry:
20  call void @llvm.dbg.value(metadata ptr %arg, metadata !23, metadata !DIExpression()), !dbg !24
21  %0 = tail call ptr @llvm.preserve.struct.access.index.p0.p0.s1s(ptr elementtype(%struct.s1) %arg, i32 1, i32 1), !dbg !25, !llvm.preserve.access.index !17
22  %1 = tail call i32 @llvm.bpf.preserve.field.info.p0(ptr %0, i64 1), !dbg !26
23  ret i32 %1, !dbg !27
24}
25
26; CHECK:             r0 = 4
27; CHECK:             exit
28
29; CHECK:             .long   6                       # BTF_KIND_STRUCT(id = 3)
30
31; CHECK:             .ascii  "s1"                    # string offset=6
32; CHECK:             .ascii  ".text"                 # string offset=31
33; CHECK:             .ascii  "0:1"                   # string offset=37
34
35; CHECK:             .long   16                      # FieldReloc
36; CHECK-NEXT:        .long   31                      # Field reloc section string offset=31
37; CHECK-NEXT:        .long   1
38; CHECK-NEXT:        .long   .Ltmp{{[0-9]+}}
39; CHECK-NEXT:        .long   3
40; CHECK-NEXT:        .long   37
41; CHECK-NEXT:        .long   1
42
43; Function Attrs: nounwind readnone
44declare ptr @llvm.preserve.struct.access.index.p0.p0.s1s(ptr, i32, i32) #1
45
46; Function Attrs: nounwind readnone
47declare i32 @llvm.bpf.preserve.field.info.p0(ptr, i64) #1
48
49; Function Attrs: nounwind readnone speculatable
50declare void @llvm.dbg.value(metadata, metadata, metadata) #2
51
52attributes #0 = { nounwind readnone "correctly-rounded-divide-sqrt-fp-math"="false" "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"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
53attributes #1 = { nounwind readnone }
54attributes #2 = { nounwind readnone speculatable }
55
56!llvm.dbg.cu = !{!0}
57!llvm.module.flags = !{!7, !8, !9}
58!llvm.ident = !{!10}
59
60!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0 (https://github.com/llvm/llvm-project.git 6c63b5d6a1cb84a75807804337c855a41c976260)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
61!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core")
62!2 = !{!3}
63!3 = !DICompositeType(tag: DW_TAG_enumeration_type, file: !1, line: 2, baseType: !4, size: 32, elements: !5)
64!4 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
65!5 = !{!6}
66!6 = !DIEnumerator(name: "FIELD_BYTE_SIZE", value: 1, isUnsigned: true)
67!7 = !{i32 2, !"Dwarf Version", i32 4}
68!8 = !{i32 2, !"Debug Info Version", i32 3}
69!9 = !{i32 1, !"wchar_size", i32 4}
70!10 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project.git 6c63b5d6a1cb84a75807804337c855a41c976260)"}
71!11 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 3, type: !12, scopeLine: 3, flags: DIFlagPrototyped, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !22)
72!12 = !DISubroutineType(types: !13)
73!13 = !{!14, !15}
74!14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
75!15 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !16, size: 64)
76!16 = !DIDerivedType(tag: DW_TAG_typedef, name: "__s1", file: !1, line: 1, baseType: !17)
77!17 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s1", file: !1, line: 1, size: 96, elements: !18)
78!18 = !{!19, !20, !21}
79!19 = !DIDerivedType(tag: DW_TAG_member, name: "a1", scope: !17, file: !1, line: 1, baseType: !14, size: 32)
80!20 = !DIDerivedType(tag: DW_TAG_member, name: "a2", scope: !17, file: !1, line: 1, baseType: !14, size: 4, offset: 32, flags: DIFlagBitField, extraData: i64 32)
81!21 = !DIDerivedType(tag: DW_TAG_member, name: "a3", scope: !17, file: !1, line: 1, baseType: !14, size: 32, offset: 64)
82!22 = !{!23}
83!23 = !DILocalVariable(name: "arg", arg: 1, scope: !11, file: !1, line: 3, type: !15)
84!24 = !DILocation(line: 0, scope: !11)
85!25 = !DILocation(line: 4, column: 45, scope: !11)
86!26 = !DILocation(line: 4, column: 10, scope: !11)
87!27 = !DILocation(line: 4, column: 3, scope: !11)
88