Index: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h =================================================================== --- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h +++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h @@ -217,11 +217,12 @@ CaseBlock(ISD::CondCode cc, const Value *cmplhs, const Value *cmprhs, const Value *cmpmiddle, MachineBasicBlock *truebb, MachineBasicBlock *falsebb, MachineBasicBlock *me, + SDLoc dl, BranchProbability trueprob = BranchProbability::getUnknown(), BranchProbability falseprob = BranchProbability::getUnknown()) : CC(cc), CmpLHS(cmplhs), CmpMHS(cmpmiddle), CmpRHS(cmprhs), - TrueBB(truebb), FalseBB(falsebb), ThisBB(me), TrueProb(trueprob), - FalseProb(falseprob) {} + TrueBB(truebb), FalseBB(falsebb), ThisBB(me), DL(dl), + TrueProb(trueprob), FalseProb(falseprob) {} // CC - the condition code to use for the case block's setcc node ISD::CondCode CC; @@ -237,6 +238,10 @@ // ThisBB - the block into which to emit the code for the setcc and branches MachineBasicBlock *ThisBB; + /// The debug location of the instruction this CaseBlock was + /// produced from. + SDLoc DL; + // TrueProb/FalseProb - branch weights. BranchProbability TrueProb, FalseProb; }; Index: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp =================================================================== --- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -1657,7 +1657,7 @@ } CaseBlock CB(Condition, BOp->getOperand(0), BOp->getOperand(1), nullptr, - TBB, FBB, CurBB, TProb, FProb); + TBB, FBB, CurBB, getCurSDLoc(), TProb, FProb); SwitchCases.push_back(CB); return; } @@ -1666,7 +1666,7 @@ // Create a CaseBlock record representing this branch. ISD::CondCode Opc = InvertCond ? ISD::SETNE : ISD::SETEQ; CaseBlock CB(Opc, Cond, ConstantInt::getTrue(*DAG.getContext()), - nullptr, TBB, FBB, CurBB, TProb, FProb); + nullptr, TBB, FBB, CurBB, getCurSDLoc(), TProb, FProb); SwitchCases.push_back(CB); } @@ -1905,7 +1905,7 @@ // Create a CaseBlock record representing this branch. CaseBlock CB(ISD::SETEQ, CondVal, ConstantInt::getTrue(*DAG.getContext()), - nullptr, Succ0MBB, Succ1MBB, BrMBB); + nullptr, Succ0MBB, Succ1MBB, BrMBB, getCurSDLoc()); // Use visitSwitchCase to actually insert the fast branch sequence for this // cond branch. @@ -1918,7 +1918,7 @@ MachineBasicBlock *SwitchBB) { SDValue Cond; SDValue CondLHS = getValue(CB.CmpLHS); - SDLoc dl = getCurSDLoc(); + SDLoc dl = CB.DL; // Build the setcc now. if (!CB.CmpMHS) { @@ -9571,8 +9571,8 @@ } // The false probability is the sum of all unhandled cases. - CaseBlock CB(CC, LHS, RHS, MHS, I->MBB, Fallthrough, CurMBB, I->Prob, - UnhandledProbs); + CaseBlock CB(CC, LHS, RHS, MHS, I->MBB, Fallthrough, CurMBB, + getCurSDLoc(), I->Prob, UnhandledProbs); if (CurMBB == SwitchMBB) visitSwitchCase(CB, SwitchMBB); @@ -9723,7 +9723,7 @@ // Create the CaseBlock record that will be used to lower the branch. CaseBlock CB(ISD::SETLT, Cond, Pivot, nullptr, LeftMBB, RightMBB, W.MBB, - LeftProb, RightProb); + getCurSDLoc(), LeftProb, RightProb); if (W.MBB == SwitchMBB) visitSwitchCase(CB, SwitchMBB); Index: llvm/trunk/test/CodeGen/X86/debugloc-no-line-0.ll =================================================================== --- llvm/trunk/test/CodeGen/X86/debugloc-no-line-0.ll +++ llvm/trunk/test/CodeGen/X86/debugloc-no-line-0.ll @@ -0,0 +1,51 @@ +; RUN: llc -O0 -mtriple=x86_64-unknown-linux-gnu -stop-before="regallocfast" -o - %s | FileCheck %s +; +; We check that all the instructions in bb4 now have a debug-location +; annotation, and that the annotation is identical to the one on e.g., +; the jmp to bb4. +; +; CHECK: JMP{{.*}}%bb.4.entry, debug-location ![[JUMPLOC:[0-9]+]] +; CHECK: bb.4.entry: +; CHECK: successors: +; CHECK-NOT: : +; CHECK: JE{{.*}}debug-location ![[JUMPLOC]] +; CHECK-NOT: : +; CHECK: JMP{{.*}}debug-location ![[JUMPLOC]] + +define i32 @main() !dbg !12 { +entry: + %add = add nsw i32 undef, 1, !dbg !16 + switch i32 %add, label %sw.epilog [ + i32 1, label %sw.bb + i32 2, label %sw.bb2 + ], !dbg !17 + +sw.bb: ; preds = %entry + br label %sw.epilog, !dbg !20 + +sw.bb2: ; preds = %entry + br label %sw.epilog, !dbg !22 + +sw.epilog: ; preds = %sw.bb2, %sw.bb, %entry + ret i32 4711, !dbg !23 +} +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!8, !9} +!llvm.ident = !{!11} + +!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, emissionKind: FullDebug, enums: !4) +!3 = !DIFile(filename: "foo.c", directory: ".") +!4 = !{} +!7 = !DIBasicType(name: "int", size: 16, encoding: DW_ATE_signed) +!8 = !{i32 2, !"Dwarf Version", i32 4} +!9 = !{i32 2, !"Debug Info Version", i32 3} +!11 = !{!"clang"} +!12 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 4, type: !13, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: false, unit: !2, variables: !4) +!13 = !DISubroutineType(types: !14) +!14 = !{!7} +!16 = !DILocation(line: 6, column: 13, scope: !12) +!17 = !DILocation(line: 6, column: 3, scope: !12) +!19 = distinct !DILexicalBlock(scope: !12, file: !3, line: 7, column: 5) +!20 = !DILocation(line: 10, column: 7, scope: !19) +!22 = !DILocation(line: 13, column: 7, scope: !19) +!23 = !DILocation(line: 24, column: 1, scope: !12)