208 lines · plain
1; RUN: opt -O2 %s | llvm-dis > %t12; RUN: llc -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK %s3; RUN: llc -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK %s4; Source code:5; struct sk_buff {6; int i;7; struct {8; int dev_id;9; int others;10; } dev[10];11; };12; #define _(x) (__builtin_preserve_access_index(x))13; static int (*bpf_probe_read)(ptr dst, int size, ptr unsafe_ptr)14; = (ptr) 4;15;16; int bpf_prog(struct sk_buff *ctx) {17; int dev_id;18; bpf_probe_read(&dev_id, sizeof(int), _(&ctx->dev[5].dev_id));19; return dev_id;20; }21; Compilation flag:22; clang -target bpf -O2 -g -S -emit-llvm -Xclang -disable-llvm-passes test.c23 24target triple = "bpf"25 26%struct.sk_buff = type { i32, [10 x %struct.anon] }27%struct.anon = type { i32, i32 }28 29; Function Attrs: nounwind30define dso_local i32 @bpf_prog(ptr) local_unnamed_addr !dbg !15 {31 %2 = alloca i32, align 432 call void @llvm.dbg.value(metadata ptr %0, metadata !31, metadata !DIExpression()), !dbg !3333 call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2), !dbg !3434 %3 = tail call ptr @llvm.preserve.struct.access.index.p0.anons.p0.sk_buffs(ptr elementtype(%struct.sk_buff) %0, i32 1, i32 1), !dbg !35, !llvm.preserve.access.index !1935 %4 = tail call ptr @llvm.preserve.array.access.index.p0.anons.p0.anons(ptr elementtype([10 x %struct.anon]) %3, i32 1, i32 5), !dbg !35, !llvm.preserve.access.index !2336 %5 = tail call ptr @llvm.preserve.struct.access.index.p0.p0.anons(ptr elementtype(%struct.anon) %4, i32 0, i32 0), !dbg !35, !llvm.preserve.access.index !2437 %6 = call i32 inttoptr (i64 4 to ptr)(ptr nonnull %2, i32 4, ptr %5), !dbg !3638 %7 = load i32, ptr %2, align 4, !dbg !37, !tbaa !3839 call void @llvm.dbg.value(metadata i32 %7, metadata !32, metadata !DIExpression()), !dbg !3340 call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2), !dbg !4241 ret i32 %7, !dbg !4342}43 44; CHECK: .section .BTF,"",@progbits45; CHECK-NEXT: .short 60319 # 0xeb9f46; CHECK-NEXT: .byte 147; CHECK-NEXT: .byte 048; CHECK-NEXT: .long 2449; CHECK-NEXT: .long 050; CHECK-NEXT: .long 17251; CHECK-NEXT: .long 17252; CHECK-NEXT: .long 11753; CHECK-NEXT: .long 0 # BTF_KIND_PTR(id = 1)54; CHECK-NEXT: .long 33554432 # 0x200000055; CHECK-NEXT: .long 256; CHECK-NEXT: .long 1 # BTF_KIND_STRUCT(id = 2)57; CHECK-NEXT: .long 67108866 # 0x400000258; CHECK-NEXT: .long 8459; CHECK-NEXT: .long 960; CHECK-NEXT: .long 361; CHECK-NEXT: .long 0 # 0x062; CHECK-NEXT: .long 1163; CHECK-NEXT: .long 564; CHECK-NEXT: .long 32 # 0x2065; CHECK-NEXT: .long 15 # BTF_KIND_INT(id = 3)66; CHECK-NEXT: .long 16777216 # 0x100000067; CHECK-NEXT: .long 468; CHECK-NEXT: .long 16777248 # 0x100002069; CHECK-NEXT: .long 0 # BTF_KIND_STRUCT(id = 4)70; CHECK-NEXT: .long 67108866 # 0x400000271; CHECK-NEXT: .long 872; CHECK-NEXT: .long 1973; CHECK-NEXT: .long 374; CHECK-NEXT: .long 0 # 0x075; CHECK-NEXT: .long 2676; CHECK-NEXT: .long 377; CHECK-NEXT: .long 32 # 0x2078; CHECK-NEXT: .long 0 # BTF_KIND_ARRAY(id = 5)79; CHECK-NEXT: .long 50331648 # 0x300000080; CHECK-NEXT: .long 081; CHECK-NEXT: .long 482; CHECK-NEXT: .long 683; CHECK-NEXT: .long 1084; CHECK-NEXT: .long 33 # BTF_KIND_INT(id = 6)85; CHECK-NEXT: .long 16777216 # 0x100000086; CHECK-NEXT: .long 487; CHECK-NEXT: .long 32 # 0x2088; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 7)89; CHECK-NEXT: .long 218103809 # 0xd00000190; CHECK-NEXT: .long 391; CHECK-NEXT: .long 5392; CHECK-NEXT: .long 193; CHECK-NEXT: .long 57 # BTF_KIND_FUNC(id = 8)94; CHECK-NEXT: .long 201326593 # 0xc00000195; CHECK-NEXT: .long 796; CHECK-NEXT: .byte 0 # string offset=097; CHECK-NEXT: .ascii "sk_buff" # string offset=198; CHECK-NEXT: .byte 099; CHECK-NEXT: .byte 105 # string offset=9100; CHECK-NEXT: .byte 0101; CHECK-NEXT: .ascii "dev" # string offset=11102; CHECK-NEXT: .byte 0103; CHECK-NEXT: .ascii "int" # string offset=15104; CHECK-NEXT: .byte 0105; CHECK-NEXT: .ascii "dev_id" # string offset=19106; CHECK-NEXT: .byte 0107; CHECK-NEXT: .ascii "others" # string offset=26108; CHECK-NEXT: .byte 0109; CHECK-NEXT: .ascii "__ARRAY_SIZE_TYPE__" # string offset=33110; CHECK-NEXT: .byte 0111; CHECK-NEXT: .ascii "ctx" # string offset=53112; CHECK-NEXT: .byte 0113; CHECK-NEXT: .ascii "bpf_prog" # string offset=57114; CHECK-NEXT: .byte 0115; CHECK-NEXT: .ascii ".text" # string offset=66116; CHECK-NEXT: .byte 0117; CHECK-NEXT: .ascii "/tmp/home/yhs/work/tests/llvm/test.c" # string offset=72118; CHECK-NEXT: .byte 0119; CHECK-NEXT: .ascii "0:1:5:0" # string offset=109120; CHECK-NEXT: .byte 0121; CHECK-NEXT: .section .BTF.ext,"",@progbits122; CHECK-NEXT: .short 60319 # 0xeb9f123; CHECK-NEXT: .byte 1124; CHECK-NEXT: .byte 0125; CHECK-NEXT: .long 32126; CHECK-NEXT: .long 0127; CHECK-NEXT: .long 20128; CHECK-NEXT: .long 20129; CHECK-NEXT: .long {{[0-9]+}}130; CHECK-NEXT: .long {{[0-9]+}}131; CHECK-NEXT: .long 28132; CHECK-NEXT: .long 8 # FuncInfo133 134; CHECK: .long 16 # FieldReloc135; CHECK-NEXT: .long 66 # Field reloc section string offset=66136; CHECK-NEXT: .long 1137; CHECK-NEXT: .long .Ltmp{{[0-9]+}}138; CHECK-NEXT: .long 2139; CHECK-NEXT: .long 109140; CHECK-NEXT: .long 0141 142; Function Attrs: argmemonly nounwind143declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture)144 145; Function Attrs: nounwind readnone146declare ptr @llvm.preserve.struct.access.index.p0.anons.p0.sk_buffs(ptr, i32 immarg, i32 immarg)147 148; Function Attrs: nounwind readnone149declare ptr @llvm.preserve.array.access.index.p0.anons.p0.anons(ptr, i32 immarg, i32 immarg)150 151; Function Attrs: nounwind readnone152declare ptr @llvm.preserve.struct.access.index.p0.p0.anons(ptr, i32 immarg, i32 immarg)153 154; Function Attrs: argmemonly nounwind155declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture)156 157; Function Attrs: nounwind readnone speculatable158declare void @llvm.dbg.value(metadata, metadata, metadata)159 160!llvm.dbg.cu = !{!0}161!llvm.module.flags = !{!11, !12, !13}162!llvm.ident = !{!14}163 164!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (trunk 360739) (llvm/trunk 360747)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3, nameTableKind: None)165!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/llvm")166!2 = !{}167!3 = !{!4}168!4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression())169!5 = distinct !DIGlobalVariable(name: "bpf_probe_read", scope: !0, file: !1, line: 9, type: !6, isLocal: true, isDefinition: true)170!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64)171!7 = !DISubroutineType(types: !8)172!8 = !{!9, !10, !9, !10}173!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)174!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)175!11 = !{i32 2, !"Dwarf Version", i32 4}176!12 = !{i32 2, !"Debug Info Version", i32 3}177!13 = !{i32 1, !"wchar_size", i32 4}178!14 = !{!"clang version 9.0.0 (trunk 360739) (llvm/trunk 360747)"}179!15 = distinct !DISubprogram(name: "bpf_prog", scope: !1, file: !1, line: 12, type: !16, scopeLine: 12, flags: DIFlagPrototyped, isLocal: false, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !30)180!16 = !DISubroutineType(types: !17)181!17 = !{!9, !18}182!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)183!19 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "sk_buff", file: !1, line: 1, size: 672, elements: !20)184!20 = !{!21, !22}185!21 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !19, file: !1, line: 2, baseType: !9, size: 32)186!22 = !DIDerivedType(tag: DW_TAG_member, name: "dev", scope: !19, file: !1, line: 6, baseType: !23, size: 640, offset: 32)187!23 = !DICompositeType(tag: DW_TAG_array_type, baseType: !24, size: 640, elements: !28)188!24 = distinct !DICompositeType(tag: DW_TAG_structure_type, scope: !19, file: !1, line: 3, size: 64, elements: !25)189!25 = !{!26, !27}190!26 = !DIDerivedType(tag: DW_TAG_member, name: "dev_id", scope: !24, file: !1, line: 4, baseType: !9, size: 32)191!27 = !DIDerivedType(tag: DW_TAG_member, name: "others", scope: !24, file: !1, line: 5, baseType: !9, size: 32, offset: 32)192!28 = !{!29}193!29 = !DISubrange(count: 10)194!30 = !{!31, !32}195!31 = !DILocalVariable(name: "ctx", arg: 1, scope: !15, file: !1, line: 12, type: !18)196!32 = !DILocalVariable(name: "dev_id", scope: !15, file: !1, line: 13, type: !9)197!33 = !DILocation(line: 0, scope: !15)198!34 = !DILocation(line: 13, column: 3, scope: !15)199!35 = !DILocation(line: 14, column: 40, scope: !15)200!36 = !DILocation(line: 14, column: 3, scope: !15)201!37 = !DILocation(line: 15, column: 10, scope: !15)202!38 = !{!39, !39, i64 0}203!39 = !{!"int", !40, i64 0}204!40 = !{!"omnipotent char", !41, i64 0}205!41 = !{!"Simple C/C++ TBAA"}206!42 = !DILocation(line: 16, column: 1, scope: !15)207!43 = !DILocation(line: 15, column: 3, scope: !15)208