brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.1 KiB · 8f83404 Raw
121 lines · plain
1; RUN: opt -O2 %s | llvm-dis > %t12; RUN: llc -mcpu=v1 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK-EB,CHECK-ALU64 %s3; RUN: llc -mcpu=v1 -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK-EB,CHECK-ALU32 %s4; Source code:5;   struct s {6;     char f1;7;     char bf1:6,8;          bf2:2,9;          bf3:5,10;          bf4:3;11;   };12;   enum {FIELD_TYPE_OFFSET = 0, FIELD_TYPE_SIZE = 1, FIELD_TYPE_LSHIFT_U64 = 4,};13;   int test(struct s *arg) {14;     return __builtin_preserve_field_info(arg->bf4, FIELD_TYPE_OFFSET) +15;            __builtin_preserve_field_info(arg->bf4, FIELD_TYPE_SIZE) +16;            __builtin_preserve_field_info(arg->bf4, FIELD_TYPE_LSHIFT_U64);17;   }18; For this case, the IR type has the same starting storage offset for fields19; bf1, bf1, bf3 and bf4 and the ABI alignment is 1 byte. So for bf4 access,20; the starting offset has to be at the beginning of field bf3.21; Compilation flag:22;   clang -target bpfeb -O2 -g -S -emit-llvm -Xclang -disable-llvm-passes test.c23 24target triple = "bpfeb"25 26%struct.s = type <{ i8, i16 }>27 28; Function Attrs: nounwind readnone29define dso_local i32 @test(ptr %arg) local_unnamed_addr !dbg !13 {30entry:31  call void @llvm.dbg.value(metadata ptr %arg, metadata !27, metadata !DIExpression()), !dbg !2832  %0 = tail call ptr @llvm.preserve.struct.access.index.p0.p0.ss(ptr elementtype(%struct.s) %arg, i32 1, i32 4), !dbg !29, !llvm.preserve.access.index !1833  %1 = tail call i32 @llvm.bpf.preserve.field.info.p0(ptr %0, i64 0), !dbg !3034  %2 = tail call i32 @llvm.bpf.preserve.field.info.p0(ptr %0, i64 1), !dbg !3135  %add = add i32 %2, %1, !dbg !3236  %3 = tail call i32 @llvm.bpf.preserve.field.info.p0(ptr %0, i64 4), !dbg !3337  %add1 = add i32 %add, %3, !dbg !3438  ret i32 %add1, !dbg !3539}40 41; CHECK:             r1 = 242; CHECK:             r0 = 143; CHECK-ALU64:       r0 += r144; CHECK-ALU32:       w0 += w145; CHECK-EB:          r1 = 6146; CHECK-ALU64:       r0 += r147; CHECK-ALU32:       w0 += w148; CHECK:             exit49 50; CHECK:             .long   1                       # BTF_KIND_STRUCT(id = 2)51 52; CHECK:             .byte   115                     # string offset=153; CHECK:             .ascii  ".text"                 # string offset=4054; CHECK:             .ascii  "0:4"                   # string offset=4655 56; CHECK:             .long   16                      # FieldReloc57; CHECK-NEXT:        .long   40                      # Field reloc section string offset=4058; CHECK-NEXT:        .long   359; CHECK-NEXT:        .long   .Ltmp{{[0-9]+}}60; CHECK-NEXT:        .long   261; CHECK-NEXT:        .long   4662; CHECK-NEXT:        .long   063; CHECK-NEXT:        .long   .Ltmp{{[0-9]+}}64; CHECK-NEXT:        .long   265; CHECK-NEXT:        .long   4666; CHECK-NEXT:        .long   167; CHECK-NEXT:        .long   .Ltmp{{[0-9]+}}68; CHECK-NEXT:        .long   269; CHECK-NEXT:        .long   4670; CHECK-NEXT:        .long   471 72; Function Attrs: nounwind readnone73declare ptr @llvm.preserve.struct.access.index.p0.p0.ss(ptr, i32, i32)74 75; Function Attrs: nounwind readnone76declare i32 @llvm.bpf.preserve.field.info.p0(ptr, i64)77 78; Function Attrs: nounwind readnone speculatable79declare void @llvm.dbg.value(metadata, metadata, metadata)80 81!llvm.dbg.cu = !{!0}82!llvm.module.flags = !{!9, !10, !11}83!llvm.ident = !{!12}84 85!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0 (https://github.com/llvm/llvm-project.git 630ca91834ecc06349cb3b4bd2982c1b85b5ad96)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, 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: 8, baseType: !4, size: 32, elements: !5)89!4 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)90!5 = !{!6, !7, !8}91!6 = !DIEnumerator(name: "FIELD_TYPE_OFFSET", value: 0, isUnsigned: true)92!7 = !DIEnumerator(name: "FIELD_TYPE_SIZE", value: 1, isUnsigned: true)93!8 = !DIEnumerator(name: "FIELD_TYPE_LSHIFT_U64", value: 4, isUnsigned: true)94!9 = !{i32 2, !"Dwarf Version", i32 4}95!10 = !{i32 2, !"Debug Info Version", i32 3}96!11 = !{i32 1, !"wchar_size", i32 4}97!12 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project.git 630ca91834ecc06349cb3b4bd2982c1b85b5ad96)"}98!13 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 9, type: !14, scopeLine: 9, flags: DIFlagPrototyped, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !26)99!14 = !DISubroutineType(types: !15)100!15 = !{!16, !17}101!16 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)102!17 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !18, size: 64)103!18 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s", file: !1, line: 1, size: 24, elements: !19)104!19 = !{!20, !22, !23, !24, !25}105!20 = !DIDerivedType(tag: DW_TAG_member, name: "f1", scope: !18, file: !1, line: 2, baseType: !21, size: 8)106!21 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)107!22 = !DIDerivedType(tag: DW_TAG_member, name: "bf1", scope: !18, file: !1, line: 3, baseType: !21, size: 6, offset: 8, flags: DIFlagBitField, extraData: i64 8)108!23 = !DIDerivedType(tag: DW_TAG_member, name: "bf2", scope: !18, file: !1, line: 4, baseType: !21, size: 2, offset: 14, flags: DIFlagBitField, extraData: i64 8)109!24 = !DIDerivedType(tag: DW_TAG_member, name: "bf3", scope: !18, file: !1, line: 5, baseType: !21, size: 5, offset: 16, flags: DIFlagBitField, extraData: i64 8)110!25 = !DIDerivedType(tag: DW_TAG_member, name: "bf4", scope: !18, file: !1, line: 6, baseType: !21, size: 3, offset: 21, flags: DIFlagBitField, extraData: i64 8)111!26 = !{!27}112!27 = !DILocalVariable(name: "arg", arg: 1, scope: !13, file: !1, line: 9, type: !17)113!28 = !DILocation(line: 0, scope: !13)114!29 = !DILocation(line: 10, column: 45, scope: !13)115!30 = !DILocation(line: 10, column: 10, scope: !13)116!31 = !DILocation(line: 11, column: 10, scope: !13)117!32 = !DILocation(line: 10, column: 69, scope: !13)118!33 = !DILocation(line: 12, column: 10, scope: !13)119!34 = !DILocation(line: 11, column: 67, scope: !13)120!35 = !DILocation(line: 10, column: 3, scope: !13)121