Index: lib/CodeGen/SelectionDAG/ScheduleDAGFast.cpp =================================================================== --- lib/CodeGen/SelectionDAG/ScheduleDAGFast.cpp +++ lib/CodeGen/SelectionDAG/ScheduleDAGFast.cpp @@ -14,6 +14,7 @@ #include "llvm/CodeGen/SchedulerRegistry.h" #include "InstrEmitter.h" #include "ScheduleDAGSDNodes.h" +#include "SDNodeDbgValue.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/Statistic.h" @@ -776,12 +777,24 @@ dbgs() << "\n*** Final schedule ***\n"; }); - // FIXME: Handle dbg_values. unsigned NumNodes = Sequence.size(); + MachineBasicBlock *BB = Emitter.getBlock(); for (unsigned i = 0; i != NumNodes; ++i) { SDNode *N = Sequence[NumNodes-i-1]; DEBUG(N->dump(DAG)); Emitter.EmitNode(N, false, false, VRBaseMap); + + // Emit any debug values associated with the node. + if (N->getHasDebugValue()) { + MachineBasicBlock::iterator InsertPos = Emitter.getInsertPos(); + for (auto DV : DAG->GetDbgValues(N)) { + if (DV->isInvalidated()) + continue; + if (auto *DbgMI = Emitter.EmitDbgValue(DV, VRBaseMap)) + BB->insert(InsertPos, DbgMI); + DV->setIsInvalidated(); + } + } } DEBUG(dbgs() << '\n'); Index: test/CodeGen/Generic/linear-dbg-value.ll =================================================================== --- /dev/null +++ test/CodeGen/Generic/linear-dbg-value.ll @@ -0,0 +1,93 @@ +; RUN: llc -stop-before=expand-isel-pseudos -pre-RA-sched=linearize < %s | FileCheck %s + +; Function Attrs: nounwind readonly uwtable +define i32 @foo(i32* nocapture readonly %a, i32 %N) local_unnamed_addr #0 !dbg !6 { +entry: + tail call void @llvm.dbg.value(metadata i32* %a, i64 0, metadata !12, metadata !17), !dbg !18 + tail call void @llvm.dbg.value(metadata i32 %N, i64 0, metadata !13, metadata !17), !dbg !19 + tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !14, metadata !17), !dbg !20 + tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !15, metadata !17), !dbg !21 + tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !15, metadata !17), !dbg !21 + tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !14, metadata !17), !dbg !20 + %cmp6 = icmp sgt i32 %N, 0, !dbg !22 + br i1 %cmp6, label %for.body.preheader, label %for.cond.cleanup, !dbg !25 + +for.body.preheader: ; preds = %entry + %wide.trip.count = zext i32 %N to i64 + br label %for.body, !dbg !27 + +for.cond.cleanup.loopexit: ; preds = %for.body + br label %for.cond.cleanup, !dbg !29 + +for.cond.cleanup: ; preds = %for.cond.cleanup.loopexit, %entry + %x.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.cond.cleanup.loopexit ] + ret i32 %x.0.lcssa, !dbg !29 + +for.body: ; preds = %for.body.preheader, %for.body +; CHECK-LABEL: bb.3.for.body: +; CHECK: DBG_VALUE +; CHECK-SAME: !14, !17, +; CHECK: DBG_VALUE +; CHECK-SAME: !14, !17, + %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %for.body.preheader ] + %x.07 = phi i32 [ %add, %for.body ], [ 0, %for.body.preheader ] + %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv, !dbg !27 + %0 = load i32, i32* %arrayidx, align 4, !dbg !27, !tbaa !30 + %add = add nsw i32 %0, %x.07, !dbg !34 + tail call void @llvm.dbg.value(metadata i32 %add, i64 0, metadata !14, metadata !17), !dbg !20 + %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !35 + tail call void @llvm.dbg.value(metadata i32 %add, i64 0, metadata !14, metadata !17), !dbg !20 + %exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count, !dbg !22 + br i1 %exitcond, label %for.cond.cleanup.loopexit, label %for.body, !dbg !25, !llvm.loop !37 +} + +; Function Attrs: nounwind readnone +declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1 + +attributes #0 = { nounwind readonly uwtable } +attributes #1 = { nounwind readnone } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4} +!llvm.ident = !{!5} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 4.0.1 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) +!1 = !DIFile(filename: "foo.c", directory: "/tmp") +!2 = !{} +!3 = !{i32 2, !"Dwarf Version", i32 4} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{!"clang version 4.0.1 "} +!6 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !7, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !11) +!7 = !DISubroutineType(types: !8) +!8 = !{!9, !10, !9} +!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64) +!11 = !{!12, !13, !14, !15} +!12 = !DILocalVariable(name: "a", arg: 1, scope: !6, file: !1, line: 2, type: !10) +!13 = !DILocalVariable(name: "N", arg: 2, scope: !6, file: !1, line: 2, type: !9) +!14 = !DILocalVariable(name: "x", scope: !6, file: !1, line: 3, type: !9) +!15 = !DILocalVariable(name: "i", scope: !16, file: !1, line: 4, type: !9) +!16 = distinct !DILexicalBlock(scope: !6, file: !1, line: 4, column: 3) +!17 = !DIExpression() +!18 = !DILocation(line: 2, column: 14, scope: !6) +!19 = !DILocation(line: 2, column: 21, scope: !6) +!20 = !DILocation(line: 3, column: 7, scope: !6) +!21 = !DILocation(line: 4, column: 12, scope: !16) +!22 = !DILocation(line: 4, column: 21, scope: !23) +!23 = !DILexicalBlockFile(scope: !24, file: !1, discriminator: 1) +!24 = distinct !DILexicalBlock(scope: !16, file: !1, line: 4, column: 3) +!25 = !DILocation(line: 4, column: 3, scope: !26) +!26 = !DILexicalBlockFile(scope: !16, file: !1, discriminator: 1) +!27 = !DILocation(line: 5, column: 10, scope: !28) +!28 = distinct !DILexicalBlock(scope: !24, file: !1, line: 4, column: 31) +!29 = !DILocation(line: 7, column: 3, scope: !6) +!30 = !{!31, !31, i64 0} +!31 = !{!"int", !32, i64 0} +!32 = !{!"omnipotent char", !33, i64 0} +!33 = !{!"Simple C/C++ TBAA"} +!34 = !DILocation(line: 5, column: 7, scope: !28) +!35 = !DILocation(line: 4, column: 27, scope: !36) +!36 = !DILexicalBlockFile(scope: !24, file: !1, discriminator: 3) +!37 = distinct !{!37, !38, !39} +!38 = !DILocation(line: 4, column: 3, scope: !16) +!39 = !DILocation(line: 6, column: 3, scope: !16)