129 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 { char a1 [5][5]; } __s1;6; union u1 { int b1; __s1 b2; };7; enum { FIELD_RSHIFT_U64 = 5, };8; int test(union u1 *arg) {9; unsigned r1 = __builtin_preserve_field_info(arg->b2.a1[3], FIELD_RSHIFT_U64);10; unsigned r2 = __builtin_preserve_field_info(arg->b2.a1[3][3], FIELD_RSHIFT_U64);11; /* r1 : 24, r2 : 56 */12; return r1 + r2;13; }14; Compilation flag:15; clang -target bpf -O2 -g -S -emit-llvm -Xclang -disable-llvm-passes test.c16 17target triple = "bpf"18 19%union.u1 = type { i32, [24 x i8] }20%struct.s1 = type { [5 x [5 x i8]] }21 22; Function Attrs: nounwind readnone23define dso_local i32 @test(ptr %arg) local_unnamed_addr !dbg !18 {24entry:25 call void @llvm.dbg.value(metadata ptr %arg, metadata !32, metadata !DIExpression()), !dbg !3526 %0 = tail call ptr @llvm.preserve.union.access.index.p0.u1s.p0.u1s(ptr %arg, i32 1), !dbg !36, !llvm.preserve.access.index !2327 %1 = tail call ptr @llvm.preserve.struct.access.index.p0.p0.s1s(ptr elementtype(%struct.s1) %0, i32 0, i32 0), !dbg !37, !llvm.preserve.access.index !2828 %2 = tail call ptr @llvm.preserve.array.access.index.p0.p0(ptr elementtype([5 x [5 x i8]]) %1, i32 1, i32 3), !dbg !38, !llvm.preserve.access.index !829 %3 = tail call i32 @llvm.bpf.preserve.field.info.p0(ptr %2, i64 5), !dbg !3930 call void @llvm.dbg.value(metadata i32 %3, metadata !33, metadata !DIExpression()), !dbg !3531 %4 = tail call ptr @llvm.preserve.array.access.index.p0.p0(ptr elementtype([5 x i8]) %2, i32 1, i32 3), !dbg !40, !llvm.preserve.access.index !1232 %5 = tail call i32 @llvm.bpf.preserve.field.info.p0(ptr %4, i64 5), !dbg !4133 call void @llvm.dbg.value(metadata i32 %5, metadata !34, metadata !DIExpression()), !dbg !3534 %add = add i32 %5, %3, !dbg !4235 ret i32 %add, !dbg !4336}37 38; CHECK: r1 = 2439; CHECK: r0 = 5640; CHECK-ALU64: r0 += r141; CHECK-ALU32: w0 += w142; CHECK: exit43 44; CHECK: .long 1 # BTF_KIND_UNION(id = 2)45; CHECK: .ascii "u1" # string offset=146; CHECK: .ascii ".text" # string offset=5947; CHECK: .ascii "0:1:0:3" # string offset=6548; CHECK: .ascii "0:1:0:3:3" # string offset=11049 50; CHECK: .long 16 # FieldReloc51; CHECK-NEXT: .long 59 # Field reloc section string offset=5952; CHECK-NEXT: .long 253; CHECK-NEXT: .long .Ltmp{{[0-9]+}}54; CHECK-NEXT: .long 255; CHECK-NEXT: .long 6556; CHECK-NEXT: .long 557; CHECK-NEXT: .long .Ltmp{{[0-9]+}}58; CHECK-NEXT: .long 259; CHECK-NEXT: .long 11060; CHECK-NEXT: .long 561 62; Function Attrs: nounwind readnone63declare ptr @llvm.preserve.union.access.index.p0.u1s.p0.u1s(ptr, i32)64 65; Function Attrs: nounwind readnone66declare ptr @llvm.preserve.struct.access.index.p0.p0.s1s(ptr, i32, i32)67 68; Function Attrs: nounwind readnone69declare ptr @llvm.preserve.array.access.index.p0.p0(ptr, i32, i32)70 71; Function Attrs: nounwind readnone72declare i32 @llvm.bpf.preserve.field.info.p0(ptr, i64)73 74; Function Attrs: nounwind readnone75 76; Function Attrs: nounwind readnone77 78; Function Attrs: nounwind readnone speculatable willreturn79declare void @llvm.dbg.value(metadata, metadata, metadata)80 81!llvm.dbg.cu = !{!0}82!llvm.module.flags = !{!14, !15, !16}83!llvm.ident = !{!17}84 85!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)86!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core")87!2 = !{!3}88!3 = !DICompositeType(tag: DW_TAG_enumeration_type, file: !1, line: 3, baseType: !4, size: 32, elements: !5)89!4 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)90!5 = !{!6}91!6 = !DIEnumerator(name: "FIELD_RSHIFT_U64", value: 5, isUnsigned: true)92!7 = !{!8, !12}93!8 = !DICompositeType(tag: DW_TAG_array_type, baseType: !9, size: 200, elements: !10)94!9 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)95!10 = !{!11, !11}96!11 = !DISubrange(count: 5)97!12 = !DICompositeType(tag: DW_TAG_array_type, baseType: !9, size: 40, elements: !13)98!13 = !{!11}99!14 = !{i32 2, !"Dwarf Version", i32 4}100!15 = !{i32 2, !"Debug Info Version", i32 3}101!16 = !{i32 1, !"wchar_size", i32 4}102!17 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project.git c1e02f16f1105ffaf1c35ee8bc38b7d6db5c6ea9)"}103!18 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 4, type: !19, scopeLine: 4, flags: DIFlagPrototyped, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !31)104!19 = !DISubroutineType(types: !20)105!20 = !{!21, !22}106!21 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)107!22 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !23, size: 64)108!23 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "u1", file: !1, line: 2, size: 224, elements: !24)109!24 = !{!25, !26}110!25 = !DIDerivedType(tag: DW_TAG_member, name: "b1", scope: !23, file: !1, line: 2, baseType: !21, size: 32)111!26 = !DIDerivedType(tag: DW_TAG_member, name: "b2", scope: !23, file: !1, line: 2, baseType: !27, size: 200)112!27 = !DIDerivedType(tag: DW_TAG_typedef, name: "__s1", file: !1, line: 1, baseType: !28)113!28 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s1", file: !1, line: 1, size: 200, elements: !29)114!29 = !{!30}115!30 = !DIDerivedType(tag: DW_TAG_member, name: "a1", scope: !28, file: !1, line: 1, baseType: !8, size: 200)116!31 = !{!32, !33, !34}117!32 = !DILocalVariable(name: "arg", arg: 1, scope: !18, file: !1, line: 4, type: !22)118!33 = !DILocalVariable(name: "r1", scope: !18, file: !1, line: 5, type: !4)119!34 = !DILocalVariable(name: "r2", scope: !18, file: !1, line: 6, type: !4)120!35 = !DILocation(line: 0, scope: !18)121!36 = !DILocation(line: 5, column: 52, scope: !18)122!37 = !DILocation(line: 5, column: 55, scope: !18)123!38 = !DILocation(line: 5, column: 47, scope: !18)124!39 = !DILocation(line: 5, column: 17, scope: !18)125!40 = !DILocation(line: 6, column: 47, scope: !18)126!41 = !DILocation(line: 6, column: 17, scope: !18)127!42 = !DILocation(line: 8, column: 13, scope: !18)128!43 = !DILocation(line: 8, column: 3, scope: !18)129