147 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; enum A { AA = -1, AB = 0, };6; enum B { BA = 0, BB = 1, };7; typedef enum A __A;8; typedef enum B __B;9; typedef struct s1 { __A a1[10]; __B a2[10][10]; } __s1;10; union u1 { int b1; __s1 b2; };11; enum { FIELD_SIGNEDNESS = 3, };12; int test(union u1 *arg) {13; unsigned r1 = __builtin_preserve_field_info(arg->b2.a1[5], FIELD_SIGNEDNESS);14; unsigned r2 = __builtin_preserve_field_info(arg->b2.a2[5][5], FIELD_SIGNEDNESS);15; /* r1 : 1, r2 : 0 */16; return r1 + r2;17; }18; Compilation flag:19; clang -target bpf -O2 -g -S -emit-llvm -Xclang -disable-llvm-passes test.c20 21target triple = "bpf"22 23%union.u1 = type { %struct.s1 }24%struct.s1 = type { [10 x i32], [10 x [10 x i32]] }25 26; Function Attrs: nounwind readnone27define dso_local i32 @test(ptr %arg) local_unnamed_addr !dbg !29 {28entry:29 call void @llvm.dbg.value(metadata ptr %arg, metadata !43, metadata !DIExpression()), !dbg !4630 %0 = tail call ptr @llvm.preserve.union.access.index.p0.u1s.p0.u1s(ptr %arg, i32 1), !dbg !47, !llvm.preserve.access.index !3331 %1 = tail call ptr @llvm.preserve.struct.access.index.p0.p0.s1s(ptr elementtype(%struct.s1) %0, i32 0, i32 0), !dbg !48, !llvm.preserve.access.index !3832 %2 = tail call ptr @llvm.preserve.array.access.index.p0.p0(ptr elementtype([10 x i32]) %1, i32 1, i32 5), !dbg !49, !llvm.preserve.access.index !1733 %3 = tail call i32 @llvm.bpf.preserve.field.info.p0(ptr %2, i64 3), !dbg !5034 call void @llvm.dbg.value(metadata i32 %3, metadata !44, metadata !DIExpression()), !dbg !4635 %4 = tail call ptr @llvm.preserve.struct.access.index.p0.p0.s1s(ptr elementtype(%struct.s1) %0, i32 1, i32 1), !dbg !51, !llvm.preserve.access.index !3836 %5 = tail call ptr @llvm.preserve.array.access.index.p0.p0(ptr elementtype([10 x [10 x i32]]) %4, i32 1, i32 5), !dbg !52, !llvm.preserve.access.index !2137 %6 = tail call ptr @llvm.preserve.array.access.index.p0.p0(ptr elementtype([10 x i32]) %5, i32 1, i32 5), !dbg !52, !llvm.preserve.access.index !2438 %7 = tail call i32 @llvm.bpf.preserve.field.info.p0(ptr %6, i64 3), !dbg !5339 call void @llvm.dbg.value(metadata i32 %7, metadata !45, metadata !DIExpression()), !dbg !4640 %add = add i32 %7, %3, !dbg !5441 ret i32 %add, !dbg !5542}43 44; CHECK: r1 = 145; CHECK: r0 = 046; CHECK-ALU64: r0 += r147; CHECK-ALU32: w0 += w148; CHECK: exit49 50; CHECK: .long 1 # BTF_KIND_UNION(id = 2)51; CHECK: .ascii "u1" # string offset=152; CHECK: .ascii ".text" # string offset=8153; CHECK: .ascii "0:1:0:5" # string offset=8754; CHECK: .ascii "0:1:1:5:5" # string offset=13255 56; CHECK: .long 16 # FieldReloc57; CHECK-NEXT: .long 81 # Field reloc section string offset=8158; CHECK-NEXT: .long 259; CHECK-NEXT: .long .Ltmp{{[0-9]+}}60; CHECK-NEXT: .long 261; CHECK-NEXT: .long 8762; CHECK-NEXT: .long 363; CHECK-NEXT: .long .Ltmp{{[0-9]+}}64; CHECK-NEXT: .long 265; CHECK-NEXT: .long 13266; CHECK-NEXT: .long 367 68; Function Attrs: nounwind readnone69declare ptr @llvm.preserve.union.access.index.p0.u1s.p0.u1s(ptr, i32)70 71; Function Attrs: nounwind readnone72declare ptr @llvm.preserve.struct.access.index.p0.p0.s1s(ptr, i32, i32)73 74; Function Attrs: nounwind readnone75declare ptr @llvm.preserve.array.access.index.p0.p0(ptr, i32, i32)76 77; Function Attrs: nounwind readnone78declare i32 @llvm.bpf.preserve.field.info.p0(ptr, i64)79 80; Function Attrs: nounwind readnone81 82; Function Attrs: nounwind readnone83 84; Function Attrs: nounwind readnone speculatable willreturn85declare void @llvm.dbg.value(metadata, metadata, metadata)86 87!llvm.dbg.cu = !{!0}88!llvm.module.flags = !{!25, !26, !27}89!llvm.ident = !{!28}90 91!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: !16, nameTableKind: None)92!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core")93!2 = !{!3, !8, !13}94!3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "A", file: !1, line: 1, baseType: !4, size: 32, elements: !5)95!4 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)96!5 = !{!6, !7}97!6 = !DIEnumerator(name: "AA", value: -1)98!7 = !DIEnumerator(name: "AB", value: 0)99!8 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "B", file: !1, line: 2, baseType: !9, size: 32, elements: !10)100!9 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)101!10 = !{!11, !12}102!11 = !DIEnumerator(name: "BA", value: 0, isUnsigned: true)103!12 = !DIEnumerator(name: "BB", value: 1, isUnsigned: true)104!13 = !DICompositeType(tag: DW_TAG_enumeration_type, file: !1, line: 7, baseType: !9, size: 32, elements: !14)105!14 = !{!15}106!15 = !DIEnumerator(name: "FIELD_SIGNEDNESS", value: 3, isUnsigned: true)107!16 = !{!17, !21, !24}108!17 = !DICompositeType(tag: DW_TAG_array_type, baseType: !18, size: 320, elements: !19)109!18 = !DIDerivedType(tag: DW_TAG_typedef, name: "__A", file: !1, line: 3, baseType: !3)110!19 = !{!20}111!20 = !DISubrange(count: 10)112!21 = !DICompositeType(tag: DW_TAG_array_type, baseType: !22, size: 3200, elements: !23)113!22 = !DIDerivedType(tag: DW_TAG_typedef, name: "__B", file: !1, line: 4, baseType: !8)114!23 = !{!20, !20}115!24 = !DICompositeType(tag: DW_TAG_array_type, baseType: !22, size: 320, elements: !19)116!25 = !{i32 2, !"Dwarf Version", i32 4}117!26 = !{i32 2, !"Debug Info Version", i32 3}118!27 = !{i32 1, !"wchar_size", i32 4}119!28 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project.git c1e02f16f1105ffaf1c35ee8bc38b7d6db5c6ea9)"}120!29 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 8, type: !30, scopeLine: 8, flags: DIFlagPrototyped, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !42)121!30 = !DISubroutineType(types: !31)122!31 = !{!4, !32}123!32 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !33, size: 64)124!33 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "u1", file: !1, line: 6, size: 3520, elements: !34)125!34 = !{!35, !36}126!35 = !DIDerivedType(tag: DW_TAG_member, name: "b1", scope: !33, file: !1, line: 6, baseType: !4, size: 32)127!36 = !DIDerivedType(tag: DW_TAG_member, name: "b2", scope: !33, file: !1, line: 6, baseType: !37, size: 3520)128!37 = !DIDerivedType(tag: DW_TAG_typedef, name: "__s1", file: !1, line: 5, baseType: !38)129!38 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s1", file: !1, line: 5, size: 3520, elements: !39)130!39 = !{!40, !41}131!40 = !DIDerivedType(tag: DW_TAG_member, name: "a1", scope: !38, file: !1, line: 5, baseType: !17, size: 320)132!41 = !DIDerivedType(tag: DW_TAG_member, name: "a2", scope: !38, file: !1, line: 5, baseType: !21, size: 3200, offset: 320)133!42 = !{!43, !44, !45}134!43 = !DILocalVariable(name: "arg", arg: 1, scope: !29, file: !1, line: 8, type: !32)135!44 = !DILocalVariable(name: "r1", scope: !29, file: !1, line: 9, type: !9)136!45 = !DILocalVariable(name: "r2", scope: !29, file: !1, line: 10, type: !9)137!46 = !DILocation(line: 0, scope: !29)138!47 = !DILocation(line: 9, column: 52, scope: !29)139!48 = !DILocation(line: 9, column: 55, scope: !29)140!49 = !DILocation(line: 9, column: 47, scope: !29)141!50 = !DILocation(line: 9, column: 17, scope: !29)142!51 = !DILocation(line: 10, column: 55, scope: !29)143!52 = !DILocation(line: 10, column: 47, scope: !29)144!53 = !DILocation(line: 10, column: 17, scope: !29)145!54 = !DILocation(line: 12, column: 13, scope: !29)146!55 = !DILocation(line: 12, column: 3, scope: !29)147