127 lines · plain
1; RUN: opt -O2 %s | llvm-dis > %t12; RUN: llc -mcpu=v1 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK-ALU64 %s3; RUN: llc -mcpu=v1 -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK-ALU32 %s4; Source code:5; typedef struct s1 { int a1[10][10]; } __s1;6; union u1 { int b1; __s1 b2; };7; enum { FIELD_EXISTENCE = 2, };8; int test(union u1 *arg) {9; unsigned r1 = __builtin_preserve_field_info(arg->b2.a1[5], FIELD_EXISTENCE);10; unsigned r2 = __builtin_preserve_field_info(arg->b2.a1[5][5], FIELD_EXISTENCE);11; return r1 + r2;12; }13; Compilation flag:14; clang -target bpf -O2 -g -S -emit-llvm -Xclang -disable-llvm-passes test.c15 16target triple = "bpf"17 18%union.u1 = type { %struct.s1 }19%struct.s1 = type { [10 x [10 x i32]] }20 21; Function Attrs: nounwind readnone22define dso_local i32 @test(ptr %arg) local_unnamed_addr !dbg !18 {23entry:24 call void @llvm.dbg.value(metadata ptr %arg, metadata !31, metadata !DIExpression()), !dbg !3425 %0 = tail call ptr @llvm.preserve.union.access.index.p0.u1s.p0.u1s(ptr %arg, i32 1), !dbg !35, !llvm.preserve.access.index !2226 %1 = tail call ptr @llvm.preserve.struct.access.index.p0.p0.s1s(ptr elementtype(%struct.s1) %0, i32 0, i32 0), !dbg !36, !llvm.preserve.access.index !2727 %2 = tail call ptr @llvm.preserve.array.access.index.p0.p0(ptr elementtype([10 x [10 x i32]]) %1, i32 1, i32 5), !dbg !37, !llvm.preserve.access.index !828 %3 = tail call i32 @llvm.bpf.preserve.field.info.p0(ptr %2, i64 2), !dbg !3829 call void @llvm.dbg.value(metadata i32 %3, metadata !32, metadata !DIExpression()), !dbg !3430 %4 = tail call ptr @llvm.preserve.array.access.index.p0.p0(ptr elementtype([10 x i32]) %2, i32 1, i32 5), !dbg !39, !llvm.preserve.access.index !1231 %5 = tail call i32 @llvm.bpf.preserve.field.info.p0(ptr %4, i64 2), !dbg !4032 call void @llvm.dbg.value(metadata i32 %5, metadata !33, metadata !DIExpression()), !dbg !3433 %add = add i32 %5, %3, !dbg !4134 ret i32 %add, !dbg !4235}36 37; CHECK: r1 = 138; CHECK: r0 = 139; CHECK-ALU64: r0 += r140; CHECK-ALU32: w0 += w141; CHECK: exit42 43; CHECK: .long 1 # BTF_KIND_UNION(id = 2)44; CHECK: .ascii "u1" # string offset=145; CHECK: .ascii ".text" # string offset=5446; CHECK: .ascii "0:1:0:5" # string offset=6047; CHECK: .ascii "0:1:0:5:5" # string offset=10548 49; CHECK: .long 16 # FieldReloc50; CHECK-NEXT: .long 54 # Field reloc section string offset=5451; CHECK-NEXT: .long 252; CHECK-NEXT: .long .Ltmp{{[0-9]+}}53; CHECK-NEXT: .long 254; CHECK-NEXT: .long 6055; CHECK-NEXT: .long 256; CHECK-NEXT: .long .Ltmp{{[0-9]+}}57; CHECK-NEXT: .long 258; CHECK-NEXT: .long 10559; CHECK-NEXT: .long 260 61; Function Attrs: nounwind readnone62declare ptr @llvm.preserve.union.access.index.p0.u1s.p0.u1s(ptr, i32)63 64; Function Attrs: nounwind readnone65declare ptr @llvm.preserve.struct.access.index.p0.p0.s1s(ptr, i32, i32)66 67; Function Attrs: nounwind readnone68declare ptr @llvm.preserve.array.access.index.p0.p0(ptr, i32, i32)69 70; Function Attrs: nounwind readnone71declare i32 @llvm.bpf.preserve.field.info.p0(ptr, i64)72 73; Function Attrs: nounwind readnone74 75; Function Attrs: nounwind readnone76 77; Function Attrs: nounwind readnone speculatable willreturn78declare void @llvm.dbg.value(metadata, metadata, metadata)79 80!llvm.dbg.cu = !{!0}81!llvm.module.flags = !{!14, !15, !16}82!llvm.ident = !{!17}83 84!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0 (https://github.com/llvm/llvm-project.git c1e02f16f1105ffaf1c35ee8bc38b7d6db5c6ea9)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !7, nameTableKind: None)85!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core")86!2 = !{!3}87!3 = !DICompositeType(tag: DW_TAG_enumeration_type, file: !1, line: 3, baseType: !4, size: 32, elements: !5)88!4 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)89!5 = !{!6}90!6 = !DIEnumerator(name: "FIELD_EXISTENCE", value: 2, isUnsigned: true)91!7 = !{!8, !12}92!8 = !DICompositeType(tag: DW_TAG_array_type, baseType: !9, size: 3200, elements: !10)93!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)94!10 = !{!11, !11}95!11 = !DISubrange(count: 10)96!12 = !DICompositeType(tag: DW_TAG_array_type, baseType: !9, size: 320, elements: !13)97!13 = !{!11}98!14 = !{i32 2, !"Dwarf Version", i32 4}99!15 = !{i32 2, !"Debug Info Version", i32 3}100!16 = !{i32 1, !"wchar_size", i32 4}101!17 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project.git c1e02f16f1105ffaf1c35ee8bc38b7d6db5c6ea9)"}102!18 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 4, type: !19, scopeLine: 4, flags: DIFlagPrototyped, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !30)103!19 = !DISubroutineType(types: !20)104!20 = !{!9, !21}105!21 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !22, size: 64)106!22 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "u1", file: !1, line: 2, size: 3200, elements: !23)107!23 = !{!24, !25}108!24 = !DIDerivedType(tag: DW_TAG_member, name: "b1", scope: !22, file: !1, line: 2, baseType: !9, size: 32)109!25 = !DIDerivedType(tag: DW_TAG_member, name: "b2", scope: !22, file: !1, line: 2, baseType: !26, size: 3200)110!26 = !DIDerivedType(tag: DW_TAG_typedef, name: "__s1", file: !1, line: 1, baseType: !27)111!27 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s1", file: !1, line: 1, size: 3200, elements: !28)112!28 = !{!29}113!29 = !DIDerivedType(tag: DW_TAG_member, name: "a1", scope: !27, file: !1, line: 1, baseType: !8, size: 3200)114!30 = !{!31, !32, !33}115!31 = !DILocalVariable(name: "arg", arg: 1, scope: !18, file: !1, line: 4, type: !21)116!32 = !DILocalVariable(name: "r1", scope: !18, file: !1, line: 5, type: !4)117!33 = !DILocalVariable(name: "r2", scope: !18, file: !1, line: 6, type: !4)118!34 = !DILocation(line: 0, scope: !18)119!35 = !DILocation(line: 5, column: 52, scope: !18)120!36 = !DILocation(line: 5, column: 55, scope: !18)121!37 = !DILocation(line: 5, column: 47, scope: !18)122!38 = !DILocation(line: 5, column: 17, scope: !18)123!39 = !DILocation(line: 6, column: 47, scope: !18)124!40 = !DILocation(line: 6, column: 17, scope: !18)125!41 = !DILocation(line: 7, column: 13, scope: !18)126!42 = !DILocation(line: 7, column: 3, scope: !18)127