diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp --- a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp +++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp @@ -457,8 +457,6 @@ const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const { DebugLoc DL; - if (I != MBB.end()) - DL = I->getDebugLoc(); MachineFunction *MF = MBB.getParent(); MachineFrameInfo &MFI = MF->getFrameInfo(); diff --git a/llvm/test/DebugInfo/RISCV/dbg-prolog-end.ll b/llvm/test/DebugInfo/RISCV/dbg-prolog-end.ll new file mode 100644 --- /dev/null +++ b/llvm/test/DebugInfo/RISCV/dbg-prolog-end.ll @@ -0,0 +1,114 @@ +; RUN: llc -filetype=obj -mtriple=riscv32 -O0 -o %t.o < %s +; RUN: llvm-dwarfdump --debug-line %t.o | FileCheck %s --check-prefix=DWARF +; RUN: llvm-objdump -d %t.o | FileCheck %s --check-prefixes=DASM +target datalayout = "e-m:e-p:32:32-i64:64-n32-S128" +target triple = "riscv32" + +; the test, need use clang --target=riscv32 -g -S x.c -o x.s +; can see the assemble +; int global_a = 10; +; __attribute__((noinline)) int foo() { +; int a = global_a; +; int b = 10; +; return a + b; +; } +; +; int main() { +; int a = foo(); +; return a; +; } + +@global_a = global i32 10, align 4, !dbg !0 + + +; PE is placed at the end of the function prologue +; DWARF: 0x0000000000000004 3 11 1 0 0 is_stmt prologue_end +; DWARF: 0x0000000000000034 9 11 1 0 0 is_stmt prologue_end + +; DASM: 00000000 : +; DASM: 0: 13 01 01 ff addi sp, sp, -16 +; DASM: 4: 37 05 00 00 lui a0, 0 +; DASM: 8: 03 25 05 00 lw a0, 0(a0) +; DASM: c: 23 26 a1 00 sw a0, 12(sp) +; DASM: 10: 93 05 a0 00 addi a1, zero, 10 +; DASM: 14: 23 24 b1 00 sw a1, 8(sp) +; DASM: 18: 13 05 a5 00 addi a0, a0, 10 +; DASM: 1c: 13 01 01 01 addi sp, sp, 16 +; DASM: 20: 67 80 00 00 ret +; DASM: 00000024
: +; DASM: 24: 13 01 01 ff addi sp, sp, -16 +; DASM: 28: 23 26 11 00 sw ra, 12(sp) +; DASM: 2c: 13 05 00 00 mv a0, zero +; DASM: 30: 23 24 a1 00 sw a0, 8(sp) +; DASM: 34: 97 00 00 00 auipc ra, 0 +; DASM: 38: e7 80 00 00 jalr ra +; DASM: 3c: 23 22 a1 00 sw a0, 4(sp) +; DASM: 40: 83 20 c1 00 lw ra, 12(sp) +; DASM: 44: 13 01 01 01 addi sp, sp, 16 +; DASM: 48: 67 80 00 00 ret + +define i32 @foo() !dbg !13 { +entry: + %a = alloca i32, align 4 + %b = alloca i32, align 4 + call void @llvm.dbg.declare(metadata i32* %a, metadata !16, metadata !DIExpression()), !dbg !17 + %0 = load i32, i32* @global_a, align 4, !dbg !18 + store i32 %0, i32* %a, align 4, !dbg !17 + call void @llvm.dbg.declare(metadata i32* %b, metadata !19, metadata !DIExpression()), !dbg !20 + store i32 10, i32* %b, align 4, !dbg !20 + %1 = load i32, i32* %a, align 4, !dbg !21 + %2 = load i32, i32* %b, align 4, !dbg !22 + %add = add nsw i32 %1, %2, !dbg !23 + ret i32 %add, !dbg !24 +} + +declare void @llvm.dbg.declare(metadata, metadata, metadata) + +define i32 @main() !dbg !25 { +entry: + %retval = alloca i32, align 4 + %a = alloca i32, align 4 + store i32 0, i32* %retval, align 4 + call void @llvm.dbg.declare(metadata i32* %a, metadata !26, metadata !DIExpression()), !dbg !27 + %call = call i32 @foo(), !dbg !28 + store i32 %call, i32* %a, align 4, !dbg !27 + %0 = load i32, i32* %a, align 4, !dbg !29 + ret i32 %0, !dbg !30 +} + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!7, !8, !9, !10, !11} +!llvm.ident = !{!12} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "global_a", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true) +!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 12.0.1 (git@code.streamcomputing.com:toolchain/llvm-12.git c2154e7af9bc5f2e9d137a24c86b92a970fbd77b)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None) +!3 = !DIFile(filename: "dwarf.c", directory: "/home/wengliqin/test") +!4 = !{} +!5 = !{!0} +!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!7 = !{i32 7, !"Dwarf Version", i32 4} +!8 = !{i32 2, !"Debug Info Version", i32 3} +!9 = !{i32 1, !"wchar_size", i32 4} +!10 = !{i32 1, !"target-abi", !"ilp32"} +!11 = !{i32 1, !"SmallDataLimit", i32 8} +!12 = !{!"clang version 12.0.1 (git@code.streamcomputing.com:toolchain/llvm-12.git c2154e7af9bc5f2e9d137a24c86b92a970fbd77b)"} +!13 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 2, type: !14, scopeLine: 2, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !4) +!14 = !DISubroutineType(types: !15) +!15 = !{!6} +!16 = !DILocalVariable(name: "a", scope: !13, file: !3, line: 3, type: !6) +!17 = !DILocation(line: 3, column: 7, scope: !13) +!18 = !DILocation(line: 3, column: 11, scope: !13) +!19 = !DILocalVariable(name: "b", scope: !13, file: !3, line: 4, type: !6) +!20 = !DILocation(line: 4, column: 7, scope: !13) +!21 = !DILocation(line: 5, column: 10, scope: !13) +!22 = !DILocation(line: 5, column: 14, scope: !13) +!23 = !DILocation(line: 5, column: 12, scope: !13) +!24 = !DILocation(line: 5, column: 3, scope: !13) +!25 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 8, type: !14, scopeLine: 8, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !4) +!26 = !DILocalVariable(name: "a", scope: !25, file: !3, line: 9, type: !6) +!27 = !DILocation(line: 9, column: 7, scope: !25) +!28 = !DILocation(line: 9, column: 11, scope: !25) +!29 = !DILocation(line: 10, column: 10, scope: !25) +!30 = !DILocation(line: 10, column: 3, scope: !25) +