brintos

brintos / llvm-project-archived public Read only

0
0
Text · 9.4 KiB · cf75909 Raw
192 lines · plain
1; RUN: opt -O2 %s | llvm-dis > %t12; RUN: llc -mcpu=v1 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK64 %s3; RUN: llc -mcpu=v1 -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK32 %s4; Source code:5;   struct s {6;     int a;7;     int b1:9;8;     int b2:4;9;   };10;   enum {11;       FIELD_BYTE_OFFSET = 0,12;       FIELD_BYTE_SIZE,13;       FIELD_EXISTENCE,14;       FIELD_SIGNEDNESS,15;       FIELD_LSHIFT_U64,16;       FIELD_RSHIFT_U64,17;   };18;   void bpf_probe_read(ptr, unsigned, const ptr);19;   int field_read(struct s *arg) {20;     unsigned long long ull;21;     unsigned offset = __builtin_preserve_field_info(arg->b2, FIELD_BYTE_OFFSET);22;     unsigned size = __builtin_preserve_field_info(arg->b2, FIELD_BYTE_SIZE);23;     unsigned lshift;24;25;     bpf_probe_read(&ull, size, (const ptr)arg + offset);26;     lshift = __builtin_preserve_field_info(arg->b2, FIELD_LSHIFT_U64);27;   #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__28;     lshift = lshift + (size << 3) - 64;29;   #endif30;     ull <<= lshift;31;     if (__builtin_preserve_field_info(arg->b2, FIELD_SIGNEDNESS))32;       return (long long)ull >> __builtin_preserve_field_info(arg->b2, FIELD_RSHIFT_U64);33;     return ull >> __builtin_preserve_field_info(arg->b2, FIELD_RSHIFT_U64);34;   }35; Compilation flag:36;   clang -target bpfel -O2 -g -S -emit-llvm -Xclang -disable-llvm-passes test.c37 38target triple = "bpfel"39 40%struct.s = type { i32, i16 }41 42; Function Attrs: nounwind43define dso_local i32 @field_read(ptr %arg) local_unnamed_addr !dbg !20 {44entry:45  %ull = alloca i64, align 846  call void @llvm.dbg.value(metadata ptr %arg, metadata !31, metadata !DIExpression()), !dbg !3747  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %ull), !dbg !3848  %0 = tail call ptr @llvm.preserve.struct.access.index.p0.p0.ss(ptr elementtype(%struct.s) %arg, i32 1, i32 2), !dbg !39, !llvm.preserve.access.index !2549  %1 = tail call i32 @llvm.bpf.preserve.field.info.p0(ptr %0, i64 0), !dbg !4050  call void @llvm.dbg.value(metadata i32 %1, metadata !34, metadata !DIExpression()), !dbg !3751  %2 = tail call i32 @llvm.bpf.preserve.field.info.p0(ptr %0, i64 1), !dbg !4152  call void @llvm.dbg.value(metadata i32 %2, metadata !35, metadata !DIExpression()), !dbg !3753  %idx.ext = zext i32 %1 to i64, !dbg !4354  %add.ptr = getelementptr i8, ptr %arg, i64 %idx.ext, !dbg !4355  call void @bpf_probe_read(ptr nonnull %ull, i32 %2, ptr %add.ptr), !dbg !4456  %3 = call i32 @llvm.bpf.preserve.field.info.p0(ptr %0, i64 4), !dbg !4557  call void @llvm.dbg.value(metadata i32 %3, metadata !36, metadata !DIExpression()), !dbg !3758  %4 = load i64, ptr %ull, align 8, !dbg !46, !tbaa !4759  call void @llvm.dbg.value(metadata i64 %4, metadata !32, metadata !DIExpression()), !dbg !3760  %sh_prom = zext i32 %3 to i64, !dbg !4661  %shl = shl i64 %4, %sh_prom, !dbg !4662  call void @llvm.dbg.value(metadata i64 %shl, metadata !32, metadata !DIExpression()), !dbg !3763  %5 = call i32 @llvm.bpf.preserve.field.info.p0(ptr %0, i64 3), !dbg !5164  %tobool = icmp eq i32 %5, 0, !dbg !5165  %6 = call i32 @llvm.bpf.preserve.field.info.p0(ptr %0, i64 5), !dbg !3766  %sh_prom1 = zext i32 %6 to i64, !dbg !3767  %shr = ashr i64 %shl, %sh_prom1, !dbg !5368  %shr3 = lshr i64 %shl, %sh_prom1, !dbg !5369  %retval.0.in = select i1 %tobool, i64 %shr3, i64 %shr, !dbg !5370  %retval.0 = trunc i64 %retval.0.in to i32, !dbg !3771  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %ull), !dbg !5472  ret i32 %retval.0, !dbg !5473}74 75; CHECK:             r{{[0-9]+}} = 476; CHECK:             r{{[0-9]+}} = 477; CHECK:             r{{[0-9]+}} <<= 5178; CHECK64:           r{{[0-9]+}} s>>= 6079; CHECK64:           r{{[0-9]+}} >>= 6080; CHECK32:           r{{[0-9]+}} >>= 6081; CHECK32:           r{{[0-9]+}} s>>= 6082; CHECK:             r{{[0-9]+}} = 183 84; CHECK:             .byte   115                     # string offset=185; CHECK:             .ascii  ".text"                 # string offset=3086; CHECK:             .ascii  "0:2"                   # string offset=7387 88; CHECK:             .long   16                      # FieldReloc89; CHECK-NEXT:        .long   30                      # Field reloc section string offset=3090; CHECK-NEXT:        .long   691; CHECK-NEXT:        .long   .Ltmp{{[0-9]+}}92; CHECK-NEXT:        .long   293; CHECK-NEXT:        .long   7394; CHECK-NEXT:        .long   095; CHECK-NEXT:        .long   .Ltmp{{[0-9]+}}96; CHECK-NEXT:        .long   297; CHECK-NEXT:        .long   7398; CHECK-NEXT:        .long   199; CHECK-NEXT:        .long   .Ltmp{{[0-9]+}}100; CHECK-NEXT:        .long   2101; CHECK-NEXT:        .long   73102; CHECK-NEXT:        .long   4103; CHECK-NEXT:        .long   .Ltmp{{[0-9]+}}104; CHECK-NEXT:        .long   2105; CHECK-NEXT:        .long   73106; CHECK-NEXT:        .long   5107; CHECK-NEXT:        .long   .Ltmp{{[0-9]+}}108; CHECK-NEXT:        .long   2109; CHECK-NEXT:        .long   73110; CHECK-NEXT:        .long   5111; CHECK-NEXT:        .long   .Ltmp{{[0-9]+}}112; CHECK-NEXT:        .long   2113; CHECK-NEXT:        .long   73114; CHECK-NEXT:        .long   3115 116; Function Attrs: argmemonly nounwind willreturn117declare void @llvm.lifetime.start.p0(i64, ptr nocapture)118 119; Function Attrs: nounwind readnone120declare ptr @llvm.preserve.struct.access.index.p0.p0.ss(ptr, i32, i32)121 122; Function Attrs: nounwind readnone123declare i32 @llvm.bpf.preserve.field.info.p0(ptr, i64)124 125declare dso_local void @bpf_probe_read(ptr, i32, ptr) local_unnamed_addr126 127; Function Attrs: argmemonly nounwind willreturn128declare void @llvm.lifetime.end.p0(i64, ptr nocapture)129 130; Function Attrs: nounwind readnone speculatable willreturn131declare void @llvm.dbg.value(metadata, metadata, metadata)132 133!llvm.dbg.cu = !{!0}134!llvm.module.flags = !{!16, !17, !18}135!llvm.ident = !{!19}136 137!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0 (https://github.com/llvm/llvm-project.git 923aa0ce806f7739b754167239fee2c9a15e2f31)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !12, nameTableKind: None)138!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core")139!2 = !{!3}140!3 = !DICompositeType(tag: DW_TAG_enumeration_type, file: !1, line: 6, baseType: !4, size: 32, elements: !5)141!4 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)142!5 = !{!6, !7, !8, !9, !10, !11}143!6 = !DIEnumerator(name: "FIELD_BYTE_OFFSET", value: 0, isUnsigned: true)144!7 = !DIEnumerator(name: "FIELD_BYTE_SIZE", value: 1, isUnsigned: true)145!8 = !DIEnumerator(name: "FIELD_EXISTENCE", value: 2, isUnsigned: true)146!9 = !DIEnumerator(name: "FIELD_SIGNEDNESS", value: 3, isUnsigned: true)147!10 = !DIEnumerator(name: "FIELD_LSHIFT_U64", value: 4, isUnsigned: true)148!11 = !DIEnumerator(name: "FIELD_RSHIFT_U64", value: 5, isUnsigned: true)149!12 = !{!13, !15}150!13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 64)151!14 = !DIDerivedType(tag: DW_TAG_const_type, baseType: null)152!15 = !DIBasicType(name: "long long int", size: 64, encoding: DW_ATE_signed)153!16 = !{i32 2, !"Dwarf Version", i32 4}154!17 = !{i32 2, !"Debug Info Version", i32 3}155!18 = !{i32 1, !"wchar_size", i32 4}156!19 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project.git 923aa0ce806f7739b754167239fee2c9a15e2f31)"}157!20 = distinct !DISubprogram(name: "field_read", scope: !1, file: !1, line: 15, type: !21, scopeLine: 15, flags: DIFlagPrototyped, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !30)158!21 = !DISubroutineType(types: !22)159!22 = !{!23, !24}160!23 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)161!24 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !25, size: 64)162!25 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s", file: !1, line: 1, size: 64, elements: !26)163!26 = !{!27, !28, !29}164!27 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !25, file: !1, line: 2, baseType: !23, size: 32)165!28 = !DIDerivedType(tag: DW_TAG_member, name: "b1", scope: !25, file: !1, line: 3, baseType: !23, size: 9, offset: 32, flags: DIFlagBitField, extraData: i64 32)166!29 = !DIDerivedType(tag: DW_TAG_member, name: "b2", scope: !25, file: !1, line: 4, baseType: !23, size: 4, offset: 41, flags: DIFlagBitField, extraData: i64 32)167!30 = !{!31, !32, !34, !35, !36}168!31 = !DILocalVariable(name: "arg", arg: 1, scope: !20, file: !1, line: 15, type: !24)169!32 = !DILocalVariable(name: "ull", scope: !20, file: !1, line: 16, type: !33)170!33 = !DIBasicType(name: "long long unsigned int", size: 64, encoding: DW_ATE_unsigned)171!34 = !DILocalVariable(name: "offset", scope: !20, file: !1, line: 17, type: !4)172!35 = !DILocalVariable(name: "size", scope: !20, file: !1, line: 18, type: !4)173!36 = !DILocalVariable(name: "lshift", scope: !20, file: !1, line: 19, type: !4)174!37 = !DILocation(line: 0, scope: !20)175!38 = !DILocation(line: 16, column: 3, scope: !20)176!39 = !DILocation(line: 17, column: 56, scope: !20)177!40 = !DILocation(line: 17, column: 21, scope: !20)178!41 = !DILocation(line: 18, column: 19, scope: !20)179!42 = !DILocation(line: 21, column: 30, scope: !20)180!43 = !DILocation(line: 21, column: 48, scope: !20)181!44 = !DILocation(line: 21, column: 3, scope: !20)182!45 = !DILocation(line: 22, column: 12, scope: !20)183!46 = !DILocation(line: 26, column: 7, scope: !20)184!47 = !{!48, !48, i64 0}185!48 = !{!"long long", !49, i64 0}186!49 = !{!"omnipotent char", !50, i64 0}187!50 = !{!"Simple C/C++ TBAA"}188!51 = !DILocation(line: 27, column: 7, scope: !52)189!52 = distinct !DILexicalBlock(scope: !20, file: !1, line: 27, column: 7)190!53 = !DILocation(line: 27, column: 7, scope: !20)191!54 = !DILocation(line: 30, column: 1, scope: !20)192