Index: llvm/lib/Target/RISCV/RISCVInstrInfo.cpp =================================================================== --- llvm/lib/Target/RISCV/RISCVInstrInfo.cpp +++ llvm/lib/Target/RISCV/RISCVInstrInfo.cpp @@ -456,10 +456,6 @@ Register SrcReg, bool IsKill, int FI, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const { - DebugLoc DL; - if (I != MBB.end()) - DL = I->getDebugLoc(); - MachineFunction *MF = MBB.getParent(); MachineFrameInfo &MFI = MF->getFrameInfo(); @@ -522,7 +518,7 @@ MemoryLocation::UnknownSize, MFI.getObjectAlign(FI)); MFI.setStackID(FI, TargetStackID::ScalableVector); - auto MIB = BuildMI(MBB, I, DL, get(Opcode)) + auto MIB = BuildMI(MBB, I, DebugLoc(), get(Opcode)) .addReg(SrcReg, getKillRegState(IsKill)) .addFrameIndex(FI) .addMemOperand(MMO); @@ -537,7 +533,7 @@ MachinePointerInfo::getFixedStack(*MF, FI), MachineMemOperand::MOStore, MFI.getObjectSize(FI), MFI.getObjectAlign(FI)); - BuildMI(MBB, I, DL, get(Opcode)) + BuildMI(MBB, I, DebugLoc(), get(Opcode)) .addReg(SrcReg, getKillRegState(IsKill)) .addFrameIndex(FI) .addImm(0) @@ -550,10 +546,6 @@ Register DstReg, int FI, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const { - DebugLoc DL; - if (I != MBB.end()) - DL = I->getDebugLoc(); - MachineFunction *MF = MBB.getParent(); MachineFrameInfo &MFI = MF->getFrameInfo(); @@ -616,7 +608,7 @@ MemoryLocation::UnknownSize, MFI.getObjectAlign(FI)); MFI.setStackID(FI, TargetStackID::ScalableVector); - auto MIB = BuildMI(MBB, I, DL, get(Opcode), DstReg) + auto MIB = BuildMI(MBB, I, DebugLoc(), get(Opcode), DstReg) .addFrameIndex(FI) .addMemOperand(MMO); if (IsZvlsseg) { @@ -630,7 +622,7 @@ MachinePointerInfo::getFixedStack(*MF, FI), MachineMemOperand::MOLoad, MFI.getObjectSize(FI), MFI.getObjectAlign(FI)); - BuildMI(MBB, I, DL, get(Opcode), DstReg) + BuildMI(MBB, I, DebugLoc(), get(Opcode), DstReg) .addFrameIndex(FI) .addImm(0) .addMemOperand(MMO); Index: llvm/test/DebugInfo/RISCV/rv32-dbg-prolog-end.ll =================================================================== --- /dev/null +++ llvm/test/DebugInfo/RISCV/rv32-dbg-prolog-end.ll @@ -0,0 +1,104 @@ +; RUN: llc -filetype=obj -mtriple=riscv32 -O0 -frame-pointer=all -o %t.o < %s +; RUN: llvm-dwarfdump --debug-line %t.o | FileCheck %s --check-prefix=RV32-DWARF +; RUN: llvm-objdump -d %t.o | FileCheck %s --check-prefixes=RV32-DASM + +@global_a = global i32 10, align 4, !dbg !0 + +; PE is placed at the end of the function prologue +; RV32-DWARF: 0x0000000000000010 3 11 1 0 0 is_stmt prologue_end +; RV32-DWARF: 0x0000000000000050 9 11 1 0 0 is_stmt prologue_end + +; RV32-DASM: 00000000 : +; RV32-DASM: 0: 13 01 01 ff addi sp, sp, -16 +; RV32-DASM: 4: 23 26 11 00 sw ra, 12(sp) +; RV32-DASM: 8: 23 24 81 00 sw s0, 8(sp) +; RV32-DASM: c: 13 04 01 01 addi s0, sp, 16 +; RV32-DASM: 10: 37 05 00 00 lui a0, 0 +; RV32-DASM: 14: 03 25 05 00 lw a0, 0(a0) +; RV32-DASM: 18: 23 2a a4 fe sw a0, -12(s0) +; RV32-DASM: 1c: 93 05 a0 00 addi a1, zero, 10 +; RV32-DASM: 20: 23 28 b4 fe sw a1, -16(s0) +; RV32-DASM: 24: 13 05 a5 00 addi a0, a0, 10 +; RV32-DASM: 28: 83 20 c1 00 lw ra, 12(sp) +; RV32-DASM: 2c: 03 24 81 00 lw s0, 8(sp) +; RV32-DASM: 30: 13 01 01 01 addi sp, sp, 16 +; RV32-DASM: 34: 67 80 00 00 ret +; RV32-DASM: 00000038
: +; RV32-DASM: 38: 13 01 01 ff addi sp, sp, -16 +; RV32-DASM: 3c: 23 26 11 00 sw ra, 12(sp) +; RV32-DASM: 40: 23 24 81 00 sw s0, 8(sp) +; RV32-DASM: 44: 13 04 01 01 addi s0, sp, 16 +; RV32-DASM: 48: 13 05 00 00 mv a0, zero +; RV32-DASM: 4c: 23 2a a4 fe sw a0, -12(s0) +; RV32-DASM: 50: 97 00 00 00 auipc ra, 0 +; RV32-DASM: 54: e7 80 00 00 jalr ra +; RV32-DASM: 58: 23 28 a4 fe sw a0, -16(s0) +; RV32-DASM: 5c: 83 20 c1 00 lw ra, 12(sp) +; RV32-DASM: 60: 03 24 81 00 lw s0, 8(sp) +; RV32-DASM: 64: 13 01 01 01 addi sp, sp, 16 +; RV32-DASM: 68: 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) Index: llvm/test/DebugInfo/RISCV/rv64-dbg-prolog-end.ll =================================================================== --- /dev/null +++ llvm/test/DebugInfo/RISCV/rv64-dbg-prolog-end.ll @@ -0,0 +1,103 @@ +; RUN: llc -filetype=obj -mtriple=riscv64 -O0 -frame-pointer=all -o %t.o < %s +; RUN: llvm-dwarfdump --debug-line %t.o | FileCheck %s --check-prefix=RV64-DWARF +; RUN: llvm-objdump -d %t.o | FileCheck %s --check-prefixes=RV64-DASM + +; PE is placed at the end of the function prologue +; RV64-DWARF: 0x0000000000000010 3 11 1 0 0 is_stmt prologue_end +; RV64-DWARF: 0x0000000000000050 9 11 1 0 0 is_stmt prologue_end + +; RV64-DASM: 0000000000000000 : +; RV64-DASM: 0: 13 01 01 fe addi sp, sp, -32 +; RV64-DASM: 4: 23 3c 11 00 sd ra, 24(sp) +; RV64-DASM: 8: 23 38 81 00 sd s0, 16(sp) +; RV64-DASM: c: 13 04 01 02 addi s0, sp, 32 +; RV64-DASM: 10: 37 05 00 00 lui a0, 0 +; RV64-DASM: 14: 03 25 05 00 lw a0, 0(a0) +; RV64-DASM: 18: 23 26 a4 fe sw a0, -20(s0) +; RV64-DASM: 1c: 93 05 a0 00 addi a1, zero, 10 +; RV64-DASM: 20: 23 24 b4 fe sw a1, -24(s0) +; RV64-DASM: 24: 1b 05 a5 00 addiw a0, a0, 10 +; RV64-DASM: 28: 83 30 81 01 ld ra, 24(sp) +; RV64-DASM: 2c: 03 34 01 01 ld s0, 16(sp) +; RV64-DASM: 30: 13 01 01 02 addi sp, sp, 32 +; RV64-DASM: 34: 67 80 00 00 ret +; RV64-DASM: 0000000000000038
: +; RV64-DASM: 38: 13 01 01 fe addi sp, sp, -32 +; RV64-DASM: 3c: 23 3c 11 00 sd ra, 24(sp) +; RV64-DASM: 40: 23 38 81 00 sd s0, 16(sp) +; RV64-DASM: 44: 13 04 01 02 addi s0, sp, 32 +; RV64-DASM: 48: 13 05 00 00 mv a0, zero +; RV64-DASM: 4c: 23 26 a4 fe sw a0, -20(s0) +; RV64-DASM: 50: 97 00 00 00 auipc ra, 0 +; RV64-DASM: 54: e7 80 00 00 jalr ra +; RV64-DASM: 58: 23 24 a4 fe sw a0, -24(s0) +; RV64-DASM: 5c: 83 30 81 01 ld ra, 24(sp) +; RV64-DASM: 60: 03 34 01 01 ld s0, 16(sp) +; RV64-DASM: 64: 13 01 01 02 addi sp, sp, 32 +; RV64-DASM: 68: 67 80 00 00 ret + + +@global_a = global i32 10, align 4, !dbg !0 + +define signext i32 @foo() !dbg !13 { + %1 = alloca i32, align 4 + %2 = alloca i32, align 4 + call void @llvm.dbg.declare(metadata i32* %1, metadata !16, metadata !DIExpression()), !dbg !17 + %3 = load i32, i32* @global_a, align 4, !dbg !18 + store i32 %3, i32* %1, align 4, !dbg !17 + call void @llvm.dbg.declare(metadata i32* %2, metadata !19, metadata !DIExpression()), !dbg !20 + store i32 10, i32* %2, align 4, !dbg !20 + %4 = load i32, i32* %1, align 4, !dbg !21 + %5 = load i32, i32* %2, align 4, !dbg !22 + %6 = add nsw i32 %4, %5, !dbg !23 + ret i32 %6, !dbg !24 +} + +declare void @llvm.dbg.declare(metadata, metadata, metadata) + +define signext i32 @main() !dbg !25 { + %1 = alloca i32, align 4 + %2 = alloca i32, align 4 + store i32 0, i32* %1, align 4 + call void @llvm.dbg.declare(metadata i32* %2, metadata !26, metadata !DIExpression()), !dbg !27 + %3 = call signext i32 @foo(), !dbg !28 + store i32 %3, i32* %2, align 4, !dbg !27 + %4 = load i32, i32* %2, align 4, !dbg !29 + ret i32 %4, !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 2644387954d3fae3e183887739853161ed80af9f)", 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", !"lp64"} +!11 = !{i32 1, !"SmallDataLimit", i32 8} +!12 = !{!"clang version 12.0.1 (git@code.streamcomputing.com:toolchain/llvm-12.git 2644387954d3fae3e183887739853161ed80af9f)"} +!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)