brintos

brintos / llvm-project-archived public Read only

0
0
Text · 12.3 KiB · d5b2d05 Raw
253 lines · plain
1; RUN: opt -O2 %s | llvm-dis > %t12; RUN: llc -mcpu=v1 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK-EB,CHECK64 %s3; RUN: llc -mcpu=v1 -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK-EB,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;   int field_read(struct s *arg) {19;     unsigned long long ull;20;     unsigned offset = __builtin_preserve_field_info(arg->b2, FIELD_BYTE_OFFSET);21;     unsigned size = __builtin_preserve_field_info(arg->b2, FIELD_BYTE_SIZE);22;     switch(size) {23;     case 1:24;       ull = *(unsigned char *)((ptr)arg + offset); break;25;     case 2:26;       ull = *(unsigned short *)((ptr)arg + offset); break;27;     case 4:28;       ull = *(unsigned int *)((ptr)arg + offset); break;29;     case 8:30;       ull = *(unsigned long long *)((ptr)arg + offset); break;31;     }32;     ull <<= __builtin_preserve_field_info(arg->b2, FIELD_LSHIFT_U64);33;     if (__builtin_preserve_field_info(arg->b2, FIELD_SIGNEDNESS))34;       return ((long long)ull) >>__builtin_preserve_field_info(arg->b2, FIELD_RSHIFT_U64);35;     return ull >> __builtin_preserve_field_info(arg->b2, FIELD_RSHIFT_U64);36;   }37; Compilation flag:38;   clang -target bpfeb -O2 -g -S -emit-llvm -Xclang -disable-llvm-passes test.c39 40target triple = "bpfeb"41 42%struct.s = type { i32, i16 }43 44; Function Attrs: nounwind readonly45define dso_local i32 @field_read(ptr %arg) local_unnamed_addr !dbg !26 {46entry:47  call void @llvm.dbg.value(metadata ptr %arg, metadata !37, metadata !DIExpression()), !dbg !4148  %0 = tail call ptr @llvm.preserve.struct.access.index.p0.p0.ss(ptr elementtype(%struct.s) %arg, i32 1, i32 2), !dbg !42, !llvm.preserve.access.index !3149  %1 = tail call i32 @llvm.bpf.preserve.field.info.p0(ptr %0, i64 0), !dbg !4350  call void @llvm.dbg.value(metadata i32 %1, metadata !39, metadata !DIExpression()), !dbg !4151  %2 = tail call i32 @llvm.bpf.preserve.field.info.p0(ptr %0, i64 1), !dbg !4452  call void @llvm.dbg.value(metadata i32 %2, metadata !40, metadata !DIExpression()), !dbg !4153  switch i32 %2, label %sw.epilog [54    i32 1, label %sw.bb55    i32 2, label %sw.bb156    i32 4, label %sw.bb557    i32 8, label %sw.bb958  ], !dbg !4559 60sw.bb:                                            ; preds = %entry61  %idx.ext = zext i32 %1 to i64, !dbg !4862  %add.ptr = getelementptr i8, ptr %arg, i64 %idx.ext, !dbg !4863  %3 = load i8, ptr %add.ptr, align 1, !dbg !49, !tbaa !5064  %conv = zext i8 %3 to i64, !dbg !4965  call void @llvm.dbg.value(metadata i64 %conv, metadata !38, metadata !DIExpression()), !dbg !4166  br label %sw.epilog, !dbg !5367 68sw.bb1:                                           ; preds = %entry69  %idx.ext2 = zext i32 %1 to i64, !dbg !5570  %add.ptr3 = getelementptr i8, ptr %arg, i64 %idx.ext2, !dbg !5571  %4 = load i16, ptr %add.ptr3, align 2, !dbg !57, !tbaa !5872  %conv4 = zext i16 %4 to i64, !dbg !5773  call void @llvm.dbg.value(metadata i64 %conv4, metadata !38, metadata !DIExpression()), !dbg !4174  br label %sw.epilog, !dbg !6075 76sw.bb5:                                           ; preds = %entry77  %idx.ext6 = zext i32 %1 to i64, !dbg !6278  %add.ptr7 = getelementptr i8, ptr %arg, i64 %idx.ext6, !dbg !6279  %5 = load i32, ptr %add.ptr7, align 4, !dbg !64, !tbaa !6580  %conv8 = zext i32 %5 to i64, !dbg !6481  call void @llvm.dbg.value(metadata i64 %conv8, metadata !38, metadata !DIExpression()), !dbg !4182  br label %sw.epilog, !dbg !6783 84sw.bb9:                                           ; preds = %entry85  %idx.ext10 = zext i32 %1 to i64, !dbg !6986  %add.ptr11 = getelementptr i8, ptr %arg, i64 %idx.ext10, !dbg !6987  %6 = load i64, ptr %add.ptr11, align 8, !dbg !71, !tbaa !7288  call void @llvm.dbg.value(metadata i64 %6, metadata !38, metadata !DIExpression()), !dbg !4189  br label %sw.epilog, !dbg !7490 91sw.epilog:                                        ; preds = %entry, %sw.bb9, %sw.bb5, %sw.bb1, %sw.bb92  %ull.0 = phi i64 [ undef, %entry ], [ %6, %sw.bb9 ], [ %conv8, %sw.bb5 ], [ %conv4, %sw.bb1 ], [ %conv, %sw.bb ]93  call void @llvm.dbg.value(metadata i64 %ull.0, metadata !38, metadata !DIExpression()), !dbg !4194  %7 = tail call i32 @llvm.bpf.preserve.field.info.p0(ptr %0, i64 4), !dbg !7595  %sh_prom = zext i32 %7 to i64, !dbg !7696  %shl = shl i64 %ull.0, %sh_prom, !dbg !7697  call void @llvm.dbg.value(metadata i64 %shl, metadata !38, metadata !DIExpression()), !dbg !4198  %8 = tail call i32 @llvm.bpf.preserve.field.info.p0(ptr %0, i64 3), !dbg !7799  %tobool = icmp eq i32 %8, 0, !dbg !77100  %9 = tail call i32 @llvm.bpf.preserve.field.info.p0(ptr %0, i64 5), !dbg !41101  %sh_prom12 = zext i32 %9 to i64, !dbg !41102  %shr = ashr i64 %shl, %sh_prom12, !dbg !79103  %shr15 = lshr i64 %shl, %sh_prom12, !dbg !79104  %retval.0.in = select i1 %tobool, i64 %shr15, i64 %shr, !dbg !79105  %retval.0 = trunc i64 %retval.0.in to i32, !dbg !41106  ret i32 %retval.0, !dbg !80107}108 109; CHECK:             r{{[0-9]+}} = 4110; CHECK:             r{{[0-9]+}} = 4111; CHECK-EB:          r{{[0-9]+}} <<= 41112; CHECK64:           r{{[0-9]+}} s>>= 60113; CHECK64:           r{{[0-9]+}} >>= 60114; CHECK32:           r{{[0-9]+}} >>= 60115; CHECK32:           r{{[0-9]+}} s>>= 60116; CHECK:             r{{[0-9]+}} = 1117 118; CHECK:             .long   1                       # BTF_KIND_STRUCT(id = 2)119; CHECK:             .byte   115                     # string offset=1120; CHECK:             .ascii  ".text"                 # string offset=30121; CHECK:             .ascii  "0:2"                   # string offset=36122 123; CHECK:             .long   16                      # FieldReloc124; CHECK-NEXT:        .long   30                      # Field reloc section string offset=30125; CHECK-NEXT:        .long   8126; CHECK-NEXT:        .long   .Ltmp{{[0-9]+}}127; CHECK-NEXT:        .long   2128; CHECK-NEXT:        .long   36129; CHECK-NEXT:        .long   1130; CHECK-NEXT:        .long   .Ltmp{{[0-9]+}}131; CHECK-NEXT:        .long   2132; CHECK-NEXT:        .long   36133; CHECK-NEXT:        .long   0134; CHECK-NEXT:        .long   .Ltmp{{[0-9]+}}135; CHECK-NEXT:        .long   2136; CHECK-NEXT:        .long   36137; CHECK-NEXT:        .long   0138; CHECK-NEXT:        .long   .Ltmp{{[0-9]+}}139; CHECK-NEXT:        .long   2140; CHECK-NEXT:        .long   36141; CHECK-NEXT:        .long   0142; CHECK-NEXT:        .long   .Ltmp{{[0-9]+}}143; CHECK-NEXT:        .long   2144; CHECK-NEXT:        .long   36145; CHECK-NEXT:        .long   4146; CHECK-NEXT:        .long   .Ltmp{{[0-9]+}}147; CHECK-NEXT:        .long   2148; CHECK-NEXT:        .long   36149; CHECK-NEXT:        .long   5150; CHECK-NEXT:        .long   .Ltmp{{[0-9]+}}151; CHECK-NEXT:        .long   2152; CHECK-NEXT:        .long   36153; CHECK-NEXT:        .long   5154; CHECK-NEXT:        .long   .Ltmp{{[0-9]+}}155; CHECK-NEXT:        .long   2156; CHECK-NEXT:        .long   36157; CHECK-NEXT:        .long   3158 159; Function Attrs: nounwind readnone160declare ptr @llvm.preserve.struct.access.index.p0.p0.ss(ptr, i32, i32)161 162; Function Attrs: nounwind readnone163declare i32 @llvm.bpf.preserve.field.info.p0(ptr, i64)164 165; Function Attrs: nounwind readnone speculatable willreturn166declare void @llvm.dbg.value(metadata, metadata, metadata)167 168!llvm.dbg.cu = !{!0}169!llvm.module.flags = !{!22, !23, !24}170!llvm.ident = !{!25}171 172!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)173!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core")174!2 = !{!3}175!3 = !DICompositeType(tag: DW_TAG_enumeration_type, file: !1, line: 6, baseType: !4, size: 32, elements: !5)176!4 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)177!5 = !{!6, !7, !8, !9, !10, !11}178!6 = !DIEnumerator(name: "FIELD_BYTE_OFFSET", value: 0, isUnsigned: true)179!7 = !DIEnumerator(name: "FIELD_BYTE_SIZE", value: 1, isUnsigned: true)180!8 = !DIEnumerator(name: "FIELD_EXISTENCE", value: 2, isUnsigned: true)181!9 = !DIEnumerator(name: "FIELD_SIGNEDNESS", value: 3, isUnsigned: true)182!10 = !DIEnumerator(name: "FIELD_LSHIFT_U64", value: 4, isUnsigned: true)183!11 = !DIEnumerator(name: "FIELD_RSHIFT_U64", value: 5, isUnsigned: true)184!12 = !{!13, !15, !16, !18, !19, !21}185!13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 64)186!14 = !DIBasicType(name: "unsigned char", size: 8, encoding: DW_ATE_unsigned_char)187!15 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)188!16 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !17, size: 64)189!17 = !DIBasicType(name: "unsigned short", size: 16, encoding: DW_ATE_unsigned)190!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !4, size: 64)191!19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64)192!20 = !DIBasicType(name: "long long unsigned int", size: 64, encoding: DW_ATE_unsigned)193!21 = !DIBasicType(name: "long long int", size: 64, encoding: DW_ATE_signed)194!22 = !{i32 2, !"Dwarf Version", i32 4}195!23 = !{i32 2, !"Debug Info Version", i32 3}196!24 = !{i32 1, !"wchar_size", i32 4}197!25 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project.git 923aa0ce806f7739b754167239fee2c9a15e2f31)"}198!26 = distinct !DISubprogram(name: "field_read", scope: !1, file: !1, line: 14, type: !27, scopeLine: 14, flags: DIFlagPrototyped, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !36)199!27 = !DISubroutineType(types: !28)200!28 = !{!29, !30}201!29 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)202!30 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !31, size: 64)203!31 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s", file: !1, line: 1, size: 64, elements: !32)204!32 = !{!33, !34, !35}205!33 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !31, file: !1, line: 2, baseType: !29, size: 32)206!34 = !DIDerivedType(tag: DW_TAG_member, name: "b1", scope: !31, file: !1, line: 3, baseType: !29, size: 9, offset: 32, flags: DIFlagBitField, extraData: i64 32)207!35 = !DIDerivedType(tag: DW_TAG_member, name: "b2", scope: !31, file: !1, line: 4, baseType: !29, size: 4, offset: 41, flags: DIFlagBitField, extraData: i64 32)208!36 = !{!37, !38, !39, !40}209!37 = !DILocalVariable(name: "arg", arg: 1, scope: !26, file: !1, line: 14, type: !30)210!38 = !DILocalVariable(name: "ull", scope: !26, file: !1, line: 15, type: !20)211!39 = !DILocalVariable(name: "offset", scope: !26, file: !1, line: 16, type: !4)212!40 = !DILocalVariable(name: "size", scope: !26, file: !1, line: 17, type: !4)213!41 = !DILocation(line: 0, scope: !26)214!42 = !DILocation(line: 16, column: 56, scope: !26)215!43 = !DILocation(line: 16, column: 21, scope: !26)216!44 = !DILocation(line: 17, column: 19, scope: !26)217!45 = !DILocation(line: 18, column: 3, scope: !26)218!46 = !DILocation(line: 20, column: 30, scope: !47)219!47 = distinct !DILexicalBlock(scope: !26, file: !1, line: 18, column: 16)220!48 = !DILocation(line: 20, column: 42, scope: !47)221!49 = !DILocation(line: 20, column: 11, scope: !47)222!50 = !{!51, !51, i64 0}223!51 = !{!"omnipotent char", !52, i64 0}224!52 = !{!"Simple C/C++ TBAA"}225!53 = !DILocation(line: 20, column: 53, scope: !47)226!54 = !DILocation(line: 22, column: 31, scope: !47)227!55 = !DILocation(line: 22, column: 43, scope: !47)228!56 = !DILocation(line: 22, column: 12, scope: !47)229!57 = !DILocation(line: 22, column: 11, scope: !47)230!58 = !{!59, !59, i64 0}231!59 = !{!"short", !51, i64 0}232!60 = !DILocation(line: 22, column: 54, scope: !47)233!61 = !DILocation(line: 24, column: 29, scope: !47)234!62 = !DILocation(line: 24, column: 41, scope: !47)235!63 = !DILocation(line: 24, column: 12, scope: !47)236!64 = !DILocation(line: 24, column: 11, scope: !47)237!65 = !{!66, !66, i64 0}238!66 = !{!"int", !51, i64 0}239!67 = !DILocation(line: 24, column: 52, scope: !47)240!68 = !DILocation(line: 26, column: 35, scope: !47)241!69 = !DILocation(line: 26, column: 47, scope: !47)242!70 = !DILocation(line: 26, column: 12, scope: !47)243!71 = !DILocation(line: 26, column: 11, scope: !47)244!72 = !{!73, !73, i64 0}245!73 = !{!"long long", !51, i64 0}246!74 = !DILocation(line: 26, column: 58, scope: !47)247!75 = !DILocation(line: 28, column: 11, scope: !26)248!76 = !DILocation(line: 28, column: 7, scope: !26)249!77 = !DILocation(line: 29, column: 7, scope: !78)250!78 = distinct !DILexicalBlock(scope: !26, file: !1, line: 29, column: 7)251!79 = !DILocation(line: 29, column: 7, scope: !26)252!80 = !DILocation(line: 32, column: 1, scope: !26)253