diff --git a/llvm/lib/Target/BPF/BPF.h b/llvm/lib/Target/BPF/BPF.h --- a/llvm/lib/Target/BPF/BPF.h +++ b/llvm/lib/Target/BPF/BPF.h @@ -46,11 +46,15 @@ public: BPFAbstractMemberAccessPass(BPFTargetMachine *TM) : TM(TM) {} PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); + + static bool isRequired() { return true; } }; class BPFPreserveDITypePass : public PassInfoMixin { public: PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); + + static bool isRequired() { return true; } }; } // namespace llvm diff --git a/llvm/test/CodeGen/BPF/CORE/store-addr-optnone.ll b/llvm/test/CodeGen/BPF/CORE/store-addr-optnone.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/BPF/CORE/store-addr-optnone.ll @@ -0,0 +1,112 @@ +; RUN: opt -passes='default' %s | llvm-dis > %t1 +; RUN: llc -filetype=asm -o - %t1 | FileCheck %s +; RUN: llc -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck %s +; TODO: add -O0 RUN when it properly runs pipeline EP callbacks. + +; Source code: +; struct t { +; int a; +; } __attribute__((preserve_access_index)); +; int foo(void *); +; int test(struct t *arg) { +; long param[1]; +; param[0] = (long)&arg->a; +; return foo(param); +; } +; Compiler flag to generate IR: +; clang -target bpf -S -O2 -g -emit-llvm -Xclang -disable-llvm-passes test.c + +target triple = "bpf" + +%struct.t = type { i32 } + +; Function Attrs: nounwind +define dso_local i32 @test(%struct.t* %arg) local_unnamed_addr #0 !dbg !14 { +entry: + %param = alloca [1 x i64], align 8 + call void @llvm.dbg.value(metadata %struct.t* %arg, metadata !22, metadata !DIExpression()), !dbg !27 + %0 = bitcast [1 x i64]* %param to i8*, !dbg !28 + call void @llvm.lifetime.start.p0i8(i64 8, i8* nonnull %0) #5, !dbg !28 + call void @llvm.dbg.declare(metadata [1 x i64]* %param, metadata !23, metadata !DIExpression()), !dbg !29 + %1 = tail call i32* @llvm.preserve.struct.access.index.p0i32.p0s_struct.ts(%struct.t* %arg, i32 0, i32 0), !dbg !30, !llvm.preserve.access.index !18 + %2 = ptrtoint i32* %1 to i64, !dbg !31 + %arrayidx = getelementptr inbounds [1 x i64], [1 x i64]* %param, i64 0, i64 0, !dbg !32 + store i64 %2, i64* %arrayidx, align 8, !dbg !33, !tbaa !34 + %call = call i32 @foo(i8* nonnull %0) #5, !dbg !38 + call void @llvm.lifetime.end.p0i8(i64 8, i8* nonnull %0) #5, !dbg !39 + ret i32 %call, !dbg !40 +} + +; CHECK: r[[OFFSET:[0-9]+]] = 0 +; CHECK: r1 += r[[OFFSET]] +; CHECK: *(u64 *)(r10 - 8) = r1 + +; Function Attrs: nounwind readnone speculatable +declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 + +; Function Attrs: argmemonly nounwind +declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #2 + +; Function Attrs: nounwind readnone +declare i32* @llvm.preserve.struct.access.index.p0i32.p0s_struct.ts(%struct.t*, i32, i32) #3 + +declare !dbg !5 dso_local i32 @foo(i8*) local_unnamed_addr #4 + +; Function Attrs: argmemonly nounwind +declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #2 + +; Function Attrs: nounwind readnone speculatable +declare void @llvm.dbg.value(metadata, metadata, metadata) #1 + +attributes #0 = { optnone noinline nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { nounwind readnone speculatable } +attributes #2 = { argmemonly nounwind } +attributes #3 = { nounwind readnone } +attributes #4 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #5 = { nounwind } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!10, !11, !12} +!llvm.ident = !{!13} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 11.0.0 (https://github.com/llvm/llvm-project.git 4f995959a05ae94cc4f9cc80035f7e4b3ecd2d88)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, splitDebugInlining: false, nameTableKind: None) +!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core") +!2 = !{} +!3 = !{!4, !5} +!4 = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed) +!5 = !DISubprogram(name: "foo", scope: !1, file: !1, line: 4, type: !6, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2) +!6 = !DISubroutineType(types: !7) +!7 = !{!8, !9} +!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64) +!10 = !{i32 7, !"Dwarf Version", i32 4} +!11 = !{i32 2, !"Debug Info Version", i32 3} +!12 = !{i32 1, !"wchar_size", i32 4} +!13 = !{!"clang version 11.0.0 (https://github.com/llvm/llvm-project.git 4f995959a05ae94cc4f9cc80035f7e4b3ecd2d88)"} +!14 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 5, type: !15, scopeLine: 5, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !21) +!15 = !DISubroutineType(types: !16) +!16 = !{!8, !17} +!17 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !18, size: 64) +!18 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t", file: !1, line: 1, size: 32, elements: !19) +!19 = !{!20} +!20 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !18, file: !1, line: 2, baseType: !8, size: 32) +!21 = !{!22, !23} +!22 = !DILocalVariable(name: "arg", arg: 1, scope: !14, file: !1, line: 5, type: !17) +!23 = !DILocalVariable(name: "param", scope: !14, file: !1, line: 6, type: !24) +!24 = !DICompositeType(tag: DW_TAG_array_type, baseType: !4, size: 64, elements: !25) +!25 = !{!26} +!26 = !DISubrange(count: 1) +!27 = !DILocation(line: 0, scope: !14) +!28 = !DILocation(line: 6, column: 5, scope: !14) +!29 = !DILocation(line: 6, column: 10, scope: !14) +!30 = !DILocation(line: 7, column: 28, scope: !14) +!31 = !DILocation(line: 7, column: 16, scope: !14) +!32 = !DILocation(line: 7, column: 5, scope: !14) +!33 = !DILocation(line: 7, column: 14, scope: !14) +!34 = !{!35, !35, i64 0} +!35 = !{!"long", !36, i64 0} +!36 = !{!"omnipotent char", !37, i64 0} +!37 = !{!"Simple C/C++ TBAA"} +!38 = !DILocation(line: 8, column: 12, scope: !14) +!39 = !DILocation(line: 9, column: 1, scope: !14) +!40 = !DILocation(line: 8, column: 5, scope: !14) diff --git a/llvm/test/CodeGen/BPF/optnone-2.ll b/llvm/test/CodeGen/BPF/optnone-2.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/BPF/optnone-2.ll @@ -0,0 +1,40 @@ +; RUN: opt < %s -passes='default' | llc -march=bpfel -filetype=asm -o /dev/null - +; TODO: add -O0 once that's supported + +; IR generated by +; $ clang -target bpf -g -S -emit-llvm t.c -Xclang -disable-llvm-passes +; `int foo() { return __builtin_btf_type_id(0, 0); }` + +target triple = "bpf" + +; Function Attrs: noinline nounwind optnone +define dso_local i32 @foo() #0 !dbg !9 { +entry: + %0 = call i32 @llvm.bpf.btf.type.id(i32 0, i64 0), !dbg !12, !llvm.preserve.access.index !4 + ret i32 %0, !dbg !13 +} + +; Function Attrs: nounwind readnone +declare i32 @llvm.bpf.btf.type.id(i32, i64) #1 + +attributes #0 = { noinline nounwind optnone "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { nounwind readnone } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!5, !6, !7} +!llvm.ident = !{!8} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 12.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, splitDebugInlining: false, nameTableKind: None) +!1 = !DIFile(filename: "C:/src/tmp\\a.c", directory: "C:\\src\\llvm-project") +!2 = !{} +!3 = !{!4} +!4 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!5 = !{i32 7, !"Dwarf Version", i32 4} +!6 = !{i32 2, !"Debug Info Version", i32 3} +!7 = !{i32 1, !"wchar_size", i32 4} +!8 = !{!"clang version 12.0.0"} +!9 = distinct !DISubprogram(name: "foo", scope: !10, file: !10, line: 1, type: !11, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) +!10 = !DIFile(filename: "C:/src/tmp/a.c", directory: "") +!11 = !DISubroutineType(types: !3) +!12 = !DILocation(line: 1, column: 20, scope: !9) +!13 = !DILocation(line: 1, column: 13, scope: !9)