119 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 unsigned __uint;6; struct s1 { int a1; __uint a2:9; __uint a3:4; };7; union u1 { int b1; struct s1 b2; };8; enum { FIELD_EXISTENCE = 2, };9; int test(union u1 *arg) {10; unsigned r1 = __builtin_preserve_field_info(arg->b2.a1, FIELD_EXISTENCE);11; unsigned r2 = __builtin_preserve_field_info(arg->b2.a3, FIELD_EXISTENCE);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 { %struct.s1 }20%struct.s1 = type { i32, i16 }21 22; Function Attrs: nounwind readnone23define dso_local i32 @test(ptr %arg) local_unnamed_addr !dbg !11 {24entry:25 call void @llvm.dbg.value(metadata ptr %arg, metadata !27, metadata !DIExpression()), !dbg !3026 %0 = tail call ptr @llvm.preserve.union.access.index.p0.u1s.p0.u1s(ptr %arg, i32 1), !dbg !31, !llvm.preserve.access.index !1627 %1 = tail call ptr @llvm.preserve.struct.access.index.p0.p0.s1s(ptr elementtype(%struct.s1) %0, i32 0, i32 0), !dbg !32, !llvm.preserve.access.index !2028 %2 = tail call i32 @llvm.bpf.preserve.field.info.p0(ptr %1, i64 2), !dbg !3329 call void @llvm.dbg.value(metadata i32 %2, metadata !28, metadata !DIExpression()), !dbg !3030 %3 = tail call ptr @llvm.preserve.struct.access.index.p0.p0.s1s(ptr elementtype(%struct.s1) %0, i32 1, i32 2), !dbg !34, !llvm.preserve.access.index !2031 %4 = tail call i32 @llvm.bpf.preserve.field.info.p0(ptr %3, i64 2), !dbg !3532 call void @llvm.dbg.value(metadata i32 %4, metadata !29, metadata !DIExpression()), !dbg !3033 %add = add i32 %4, %2, !dbg !3634 ret i32 %add, !dbg !3735}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=5546; CHECK: .ascii "0:1:0" # string offset=6147; CHECK: .ascii "0:1:2" # string offset=10448 49; CHECK: .long 16 # FieldReloc50; CHECK-NEXT: .long 55 # Field reloc section string offset=5551; CHECK-NEXT: .long 252; CHECK-NEXT: .long .Ltmp{{[0-9]+}}53; CHECK-NEXT: .long 254; CHECK-NEXT: .long 6155; CHECK-NEXT: .long 256; CHECK-NEXT: .long .Ltmp{{[0-9]+}}57; CHECK-NEXT: .long 258; CHECK-NEXT: .long 10459; 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 i32 @llvm.bpf.preserve.field.info.p0(ptr, i64)69 70; Function Attrs: nounwind readnone71 72; Function Attrs: nounwind readnone73 74; Function Attrs: nounwind readnone speculatable willreturn75declare void @llvm.dbg.value(metadata, metadata, metadata)76 77!llvm.dbg.cu = !{!0}78!llvm.module.flags = !{!7, !8, !9}79!llvm.ident = !{!10}80 81!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0 (https://github.com/llvm/llvm-project.git 4a60741b74384f14b21fdc0131ede326438840ab)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)82!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core")83!2 = !{!3}84!3 = !DICompositeType(tag: DW_TAG_enumeration_type, file: !1, line: 4, baseType: !4, size: 32, elements: !5)85!4 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)86!5 = !{!6}87!6 = !DIEnumerator(name: "FIELD_EXISTENCE", value: 2, isUnsigned: true)88!7 = !{i32 2, !"Dwarf Version", i32 4}89!8 = !{i32 2, !"Debug Info Version", i32 3}90!9 = !{i32 1, !"wchar_size", i32 4}91!10 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project.git 4a60741b74384f14b21fdc0131ede326438840ab)"}92!11 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 5, type: !12, scopeLine: 5, flags: DIFlagPrototyped, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !26)93!12 = !DISubroutineType(types: !13)94!13 = !{!14, !15}95!14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)96!15 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !16, size: 64)97!16 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "u1", file: !1, line: 3, size: 64, elements: !17)98!17 = !{!18, !19}99!18 = !DIDerivedType(tag: DW_TAG_member, name: "b1", scope: !16, file: !1, line: 3, baseType: !14, size: 32)100!19 = !DIDerivedType(tag: DW_TAG_member, name: "b2", scope: !16, file: !1, line: 3, baseType: !20, size: 64)101!20 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s1", file: !1, line: 2, size: 64, elements: !21)102!21 = !{!22, !23, !25}103!22 = !DIDerivedType(tag: DW_TAG_member, name: "a1", scope: !20, file: !1, line: 2, baseType: !14, size: 32)104!23 = !DIDerivedType(tag: DW_TAG_member, name: "a2", scope: !20, file: !1, line: 2, baseType: !24, size: 9, offset: 32, flags: DIFlagBitField, extraData: i64 32)105!24 = !DIDerivedType(tag: DW_TAG_typedef, name: "__uint", file: !1, line: 1, baseType: !4)106!25 = !DIDerivedType(tag: DW_TAG_member, name: "a3", scope: !20, file: !1, line: 2, baseType: !24, size: 4, offset: 41, flags: DIFlagBitField, extraData: i64 32)107!26 = !{!27, !28, !29}108!27 = !DILocalVariable(name: "arg", arg: 1, scope: !11, file: !1, line: 5, type: !15)109!28 = !DILocalVariable(name: "r1", scope: !11, file: !1, line: 6, type: !4)110!29 = !DILocalVariable(name: "r2", scope: !11, file: !1, line: 7, type: !4)111!30 = !DILocation(line: 0, scope: !11)112!31 = !DILocation(line: 6, column: 52, scope: !11)113!32 = !DILocation(line: 6, column: 55, scope: !11)114!33 = !DILocation(line: 6, column: 17, scope: !11)115!34 = !DILocation(line: 7, column: 55, scope: !11)116!35 = !DILocation(line: 7, column: 17, scope: !11)117!36 = !DILocation(line: 8, column: 13, scope: !11)118!37 = !DILocation(line: 8, column: 3, scope: !11)119