Index: include/llvm/CodeGen/Passes.h =================================================================== --- include/llvm/CodeGen/Passes.h +++ include/llvm/CodeGen/Passes.h @@ -639,6 +639,9 @@ /// the intrinsic for later emission to the StackMap. extern char &StackMapLivenessID; + /// ExtendDebugRangeLocation pass + extern char &ExtendDebugRangeLocationID; + /// createJumpInstrTables - This pass creates jump-instruction tables. ModulePass *createJumpInstrTablesPass(); Index: include/llvm/InitializePasses.h =================================================================== --- include/llvm/InitializePasses.h +++ include/llvm/InitializePasses.h @@ -289,6 +289,7 @@ void initializeMachineFunctionPrinterPassPass(PassRegistry&); void initializeMIRPrintingPassPass(PassRegistry&); void initializeStackMapLivenessPass(PassRegistry&); +void initializeExtendDebugRangeLocationPass(PassRegistry&); void initializeMachineCombinerPass(PassRegistry &); void initializeLoadCombinePass(PassRegistry&); void initializeRewriteSymbolsPass(PassRegistry&); Index: lib/CodeGen/CMakeLists.txt =================================================================== --- lib/CodeGen/CMakeLists.txt +++ lib/CodeGen/CMakeLists.txt @@ -20,6 +20,7 @@ ExecutionDepsFix.cpp ExpandISelPseudos.cpp ExpandPostRAPseudos.cpp + ExtendDebugRangeLocation.cpp FaultMaps.cpp GCMetadata.cpp GCMetadataPrinter.cpp Index: lib/CodeGen/CodeGen.cpp =================================================================== --- lib/CodeGen/CodeGen.cpp +++ lib/CodeGen/CodeGen.cpp @@ -66,6 +66,7 @@ initializeSlotIndexesPass(Registry); initializeStackColoringPass(Registry); initializeStackMapLivenessPass(Registry); + initializeExtendDebugRangeLocationPass(Registry); initializeStackProtectorPass(Registry); initializeStackSlotColoringPass(Registry); initializeTailDuplicatePassPass(Registry); Index: lib/CodeGen/ExtendDebugRangeLocation.cpp =================================================================== --- /dev/null +++ lib/CodeGen/ExtendDebugRangeLocation.cpp @@ -0,0 +1,382 @@ +//===-- ExtendDebugRangeLocation.cpp - Fixup Debug Value MIs --------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// +/// This pass implements a data flow analysis that propagates debug location +/// information by inserting additional DBG_VALUE instructions into the machine +/// instruction stream. The pass internally builds debug location liveness +/// ranges to determine the points where additional DBG_VALUEs need to be +/// inserted. +/// +/// This is a separate pass from DbgValueHistoryCalculator to facilitate +/// testing and improve modularity. +/// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/Statistic.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/CodeGen/MachineFunction.h" +#include "llvm/CodeGen/MachineFunctionPass.h" +#include "llvm/CodeGen/MachineInstrBuilder.h" +#include "llvm/CodeGen/Passes.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Target/TargetRegisterInfo.h" +#include "llvm/Target/TargetInstrInfo.h" +#include "llvm/Target/TargetSubtargetInfo.h" +#include +#include + +using namespace llvm; + +#define DEBUG_TYPE "extend-dbg-range-loc" + +STATISTIC(NumInserted, "Number of DBG_VALUE instructions inserted"); + +namespace { + +class ExtendDebugRangeLocation : public MachineFunctionPass { + +public: + static char ID; + + /// Default construct and initialize the pass. + ExtendDebugRangeLocation(); + + /// Tell the pass manager which passes we depend on and what + /// information we preserve. + void getAnalysisUsage(AnalysisUsage &AU) const override; + + /// Print to ostream with a message + void print(const char *msg, raw_ostream &Out) const; + + /// Calculate the liveness information for the given machine function. + bool runOnMachineFunction(MachineFunction &MF) override; + +private: + const TargetRegisterInfo *TRI; + const TargetInstrInfo *TII; + + typedef std::pair + InlinedVariable; + + /// Member variables and functions for Range Extension across basic blocks + struct VarLoc { + const MachineBasicBlock *MBB; + InlinedVariable Var; + const MachineInstr *MI; // MachineInstr should be a DBG_VALUE instr + + VarLoc(const MachineBasicBlock *_mbb, InlinedVariable _var, + const MachineInstr *_mi) + : MBB(_mbb), Var(_var), MI(_mi) {} + }; + typedef std::list VarLocList; + + VarLocList OpenRanges; // Ranges that are open until end of bb + VarLocList OutgoingLocs; // Ranges that exist beyond bb + + bool OLChanged; // OutgoingLocs got changed for this bb + bool MBBJoined; // The MBB was joined + + void transferDebugValue(MachineInstr &MI); + void transferRegisterDef(MachineInstr &MI); + void transferTerminatorInst(MachineInstr &MI); + void transfer(MachineInstr &MI); + + void join(MachineBasicBlock &MBB); + + void ExtendRanges(MachineFunction &MF); + + void clearExtendDebugRangeLocationData(); +}; +} // namespace + +//===----------------------------------------------------------------------===// +// Implementation +//===----------------------------------------------------------------------===// + +char ExtendDebugRangeLocation::ID = 0; +char &llvm::ExtendDebugRangeLocationID = ExtendDebugRangeLocation::ID; +INITIALIZE_PASS(ExtendDebugRangeLocation, "extend-dbg-range-loc", + "Extend DBG_VALUE Range and Location Pass", false, false) + +/// Default construct and initialize the pass. +ExtendDebugRangeLocation::ExtendDebugRangeLocation() : MachineFunctionPass(ID) { + initializeExtendDebugRangeLocationPass(*PassRegistry::getPassRegistry()); +} + +/// Tell the pass manager which passes we depend on and what information we +/// preserve. +void ExtendDebugRangeLocation::getAnalysisUsage(AnalysisUsage &AU) const { + MachineFunctionPass::getAnalysisUsage(AU); +} + +void ExtendDebugRangeLocation::clearExtendDebugRangeLocationData() { + OLChanged = MBBJoined = false; + OpenRanges.clear(); + OutgoingLocs.clear(); +} + +// \brief If @MI is a DBG_VALUE with debug value described by a +// defined register, returns the number of this register. +// In the other case, returns 0. +static unsigned isDescribedByReg(const MachineInstr &MI) { + assert(MI.isDebugValue()); + assert(MI.getNumOperands() == 4); + // If location of variable is described using a register (directly or + // indirecltly), this register is always a first operand. + return MI.getOperand(0).isReg() ? MI.getOperand(0).getReg() : 0; +} + +// \brief This function takes two DBG_VALUE instructions and returns true +// if their offsets are equal; otherwise returns false. +static bool areOffsetsEqual(const MachineInstr &MI1, const MachineInstr &MI2) { + assert(MI1.isDebugValue()); + assert(MI1.getNumOperands() == 4); + + assert(MI2.isDebugValue()); + assert(MI2.getNumOperands() == 4); + + if (!MI1.isIndirectDebugValue() && !MI2.isIndirectDebugValue()) + return true; + + // Check if both MIs are indirect and they are equal + if (MI1.isIndirectDebugValue() && MI2.isIndirectDebugValue()) + return MI1.getOperand(1).getImm() == MI2.getOperand(1).getImm(); + + return false; +} + +//===----------------------------------------------------------------------===// +// Debug Range Extension Implementation +//===----------------------------------------------------------------------===// + +/// Print OpenRanges and OutgoingLocs +void ExtendDebugRangeLocation::print(const char *msg, raw_ostream &Out) const { + Out << "\nPrint " << msg << "\n"; + Out << "Printing OpenRanges:\n"; + for (const auto &OR : OpenRanges) { + Out << "MBB: " << OR.MBB->getName() << " Var: " << OR.Var.first->getName(); + Out << " MI: "; + (*OR.MI).dump(); + Out << "\n"; + } + Out << "Printing OutgoingLocs:\n"; + for (const auto &OL : OutgoingLocs) { + Out << "MBB: " << OL.MBB->getName() << " Var: " << OL.Var.first->getName(); + Out << " MI: "; + (*OL.MI).dump(); + Out << "\n"; + } + Out << "\n"; +} + +/// End all previous ranges related to @MI and start a new range from @MI +/// if it is a DBG_VALUE instr. +void ExtendDebugRangeLocation::transferDebugValue(MachineInstr &MI) { + if (MI.isDebugValue()) { + const DILocalVariable *RawVar = MI.getDebugVariable(); + assert(RawVar->isValidLocationForIntrinsic(MI.getDebugLoc()) && + "Expected inlined-at fields to agree"); + InlinedVariable Var(RawVar, MI.getDebugLoc()->getInlinedAt()); + + // End all previous ranges of Var + VarLocList::iterator ORi = OpenRanges.begin(), ORe = OpenRanges.end(); + while (ORi != ORe) { + VarLocList::iterator ORiSave = ORi; + ORi++; + if (Var == ORiSave->Var) { + OpenRanges.erase(ORiSave); + ORi = OpenRanges.begin(), ORe = OpenRanges.end(); + } + } + // Add Var to OpenRanges from this DBG_VALUE + // TODO: Currently handles DBG_VALUE which has only reg as location + if (isDescribedByReg(MI)) { + VarLoc V(MI.getParent(), Var, &MI); + OpenRanges.push_back(std::move(V)); + } + } +} + +/// A definition of a register may mark the end of a range +void ExtendDebugRangeLocation::transferRegisterDef(MachineInstr &MI) { + for (const MachineOperand &MO : MI.operands()) { + // Old register clobbering equivalent code + if (MO.isReg() && MO.isDef() && MO.getReg()) { + // Remove ranges of all aliased registers + for (MCRegAliasIterator RAI(MO.getReg(), TRI, true); RAI.isValid(); + ++RAI) { + VarLocList::iterator ORi = OpenRanges.begin(), ORe = OpenRanges.end(); + while (ORi != ORe) { + VarLocList::iterator ORiSave = ORi; + ORi++; + if (*RAI == isDescribedByReg(*ORiSave->MI)) { + OpenRanges.erase(ORiSave); + ORi = OpenRanges.begin(), ORe = OpenRanges.end(); + } + } + } + } + } +} + +/// Terminate all open ranges at the end of the current basic block +void ExtendDebugRangeLocation::transferTerminatorInst(MachineInstr &MI) { + if (MI.isTerminator() || (&MI == &MI.getParent()->instr_back())) { + VarLocList::iterator ORi = OpenRanges.begin(), ORe = OpenRanges.end(); + while (ORi != ORe) { + // Copy OpenRanges to OutgoingLocs, if not already present + if (std::find_if(OutgoingLocs.begin(), OutgoingLocs.end(), + [&](const VarLoc &O) { + return ((O.MBB == ORi->MBB) && (O.Var == ORi->Var) && + (O.MI == ORi->MI)); + }) == OutgoingLocs.end()) { + assert(ORi->MI->isDebugValue()); + DEBUG(dbgs() << "Add to OutgoingLocs: "; ORi->MI->dump();); + VarLoc V(ORi->MBB, ORi->Var, ORi->MI); + OutgoingLocs.push_back(std::move(V)); + OLChanged = true; + } + + // Delete this open range + OpenRanges.erase(ORi); + ORi = OpenRanges.begin(), ORe = OpenRanges.end(); + } + } +} + +/// This routine creates OpenRanges and OutgoingLocs +void ExtendDebugRangeLocation::transfer(MachineInstr &MI) { + + DEBUG(dbgs() << "transfer MI: "; MI.dump()); + + transferDebugValue(MI); + transferRegisterDef(MI); + transferTerminatorInst(MI); +} + +/// This routine joins the analysis results of all incoming edges in @MBB by +/// inserting a new DBG_VALUE instruction at the start of the @MBB - if the same +/// source variable in all the predecessors of @MBB reside in the same location. +void ExtendDebugRangeLocation::join(MachineBasicBlock &MBB) { + DEBUG(dbgs() << "join MBB: " << MBB.getName() << "\n"); + + MBBJoined = false; + if (MBB.pred_size() == 0 || MBB.pred_size() > 2) + return; + + if (MBB.pred_size() == 1) { + // Propagate all OutgoingLocs into the current MBB + for (auto &OL : OutgoingLocs) { + if (OL.MBB == *MBB.pred_begin()) { + const MachineInstr *DMI = OL.MI; + MachineInstr *MI = + BuildMI(MBB, MBB.instr_begin(), DMI->getDebugLoc(), DMI->getDesc(), + DMI->isIndirectDebugValue(), DMI->getOperand(0).getReg(), 0, + DMI->getDebugVariable(), DMI->getDebugExpression()); + if (DMI->isIndirectDebugValue()) + MI->getOperand(1).setImm(DMI->getOperand(1).getImm()); + DEBUG(dbgs() << "Inserted: "; MI->dump();); + ++NumInserted; + MBBJoined = true; + } + } + return; + } + + MachineBasicBlock *pred1 = *MBB.pred_begin(); + MachineBasicBlock *pred2 = *(++MBB.pred_begin()); + + // Search through OutgoingLocs to match 2 entries: + // and + for (auto OLo = OutgoingLocs.begin(), OLoe = OutgoingLocs.end(); + OLo != OLoe; OLo++) { // outer loop + for (auto OLi = OutgoingLocs.begin(), OLie = OutgoingLocs.end(); + OLi != OLie; OLi++) { // inner loop + // Check for equality of the 2 entries + if ((OLo != OLi) && (OLo->MBB == pred1 && OLi->MBB == pred2) && + (OLo->Var == OLi->Var)) { + // Now the two locations should be same - reg and offset + if ((isDescribedByReg(*OLo->MI) == isDescribedByReg(*OLi->MI)) && + (areOffsetsEqual((*OLo->MI), (*OLi->MI)))) { + // A new range is started for the var from the bb's + // beginning by inserting a new DBG_VALUE. + // transfer() will end this range however appropriate. + const MachineInstr *DMI = OLo->MI; + MachineInstr *MI = BuildMI( + MBB, MBB.instr_begin(), DMI->getDebugLoc(), DMI->getDesc(), + DMI->isIndirectDebugValue(), DMI->getOperand(0).getReg(), 0, + DMI->getDebugVariable(), DMI->getDebugExpression()); + if (DMI->isIndirectDebugValue()) + MI->getOperand(1).setImm(DMI->getOperand(1).getImm()); + DEBUG(dbgs() << "Inserted: "; MI->dump(); dbgs() << "\n";); + ++NumInserted; + MBBJoined = true; // Rerun transfer() function + } + } + } + } +} + +/// Calculate the liveness information for the given machine function and +/// extend ranges across basic blocks +void ExtendDebugRangeLocation::ExtendRanges(MachineFunction &MF) { + + DEBUG(dbgs() << "\nDebug Range Extension\n"); + + clearExtendDebugRangeLocationData(); + + std::deque BBWorklist; + + // Initialize every mbb with OutgoingLocs + for (auto &MBB : MF) + for (auto &MI : MBB) + transfer(MI); + DEBUG(print("After OutgoingLocs Initialize", dbgs())); + + // Construct a worklist of MBBs + for (auto &MBB : MF) + BBWorklist.push_back(&MBB); + + // Perform join() and transfer() using the worklist until the ranges converge + // Ranges have converged when the worklist is empty + while (!BBWorklist.empty()) { + MachineBasicBlock *MBB = BBWorklist.front(); + BBWorklist.pop_front(); + + join(*MBB); + + if (MBBJoined) { + for (auto &MI : *MBB) + transfer(MI); + DEBUG(print("After propagating joined MBB", dbgs())); + + if (OLChanged) { + OLChanged = false; + for (MachineBasicBlock::const_succ_iterator si = MBB->succ_begin(), + se = MBB->succ_end(); + si != se; ++si) + if (std::find(BBWorklist.begin(), BBWorklist.end(), *si) == + BBWorklist.end()) // add if not already present + BBWorklist.push_back(*si); + } + } + } + DEBUG(print("Final OutgoingLocs", dbgs())); +} + +bool ExtendDebugRangeLocation::runOnMachineFunction(MachineFunction &MF) { + TRI = MF.getSubtarget().getRegisterInfo(); + TII = MF.getSubtarget().getInstrInfo(); + + ExtendRanges(MF); + + return true; +} Index: lib/CodeGen/Passes.cpp =================================================================== --- lib/CodeGen/Passes.cpp +++ lib/CodeGen/Passes.cpp @@ -581,6 +581,7 @@ addPreEmitPass(); addPass(&StackMapLivenessID, false); + addPass(&ExtendDebugRangeLocationID); AddingMachinePasses = false; } Index: test/DebugInfo/MIR/X86/extend-debug-range.mir =================================================================== --- /dev/null +++ test/DebugInfo/MIR/X86/extend-debug-range.mir @@ -0,0 +1,260 @@ +# RUN: llc -run-pass=extend-dbg-range-loc -march=x86-64 -o /dev/null %s | FileCheck %s + +# Test the extension of debug ranges from predecessors. +# Generated from the source file ExtendDebugRange.c: +# #include +# int m; +# extern int inc(int n); +# extern int change(int n); +# extern int modify(int n); +# int main(int argc, char **argv) { +# int n; +# if (argc != 2) +# n = 2; +# else +# n = atoi(argv[1]); +# n = change(n); +# if (n > 10) { +# m = modify(n); +# m = m + n; // var `m' doesn't has a dbg.value +# } +# else +# m = inc(n); // var `m' doesn't has a dbg.value +# printf("m(main): %d\n", m); +# return 0; +# } +# with clang -g -emit-llvm ExtendDebugRange.c -c -o edr.bc +# then opt -O3 -S -o extend-debug-range.ll edr.bc +# then llc -stop-after stackmap-liveness extend-debug-range.ll -o /dev/null > extend-debug-range.mir +# This case will also produce multiple locations but only the debug range +# extension is tested here. This test case is tested with DWARF information under +# llvm/test/DebugInfo/extend-debug-range.ll and present here for testing under +# MIR->MIR serialization. + +# DBG_VALUE for variable "n" is extended into BB#5 from its predecessors BB#3 +# and BB#4. +# CHECK: bb.5.if.end.7: +# CHECK: DBG_VALUE debug-use %rsi, debug-use _, !19, !17, debug-location !20 +# CHECK-NEXT: DBG_VALUE debug-use %ebx, debug-use _, !26, !17, debug-location !27 + + +--- | + ; ModuleID = 'extend-debug-range.ll' + target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" + target triple = "x86_64-unknown-linux-gnu" + + @m = common global i32 0, align 4 + @.str = private unnamed_addr constant [13 x i8] c"m(main): %d\0A\00", align 1 + + ; Function Attrs: nounwind uwtable + define i32 @main(i32 %argc, i8** nocapture readonly %argv) #0 { + entry: + tail call void @llvm.dbg.value(metadata i32 %argc, i64 0, metadata !16, metadata !17), !dbg !18 + tail call void @llvm.dbg.value(metadata i8** %argv, i64 0, metadata !19, metadata !17), !dbg !20 + %cmp = icmp eq i32 %argc, 2, !dbg !21 + br i1 %cmp, label %if.else, label %if.end, !dbg !23 + + if.else: ; preds = %entry + %arrayidx = getelementptr inbounds i8*, i8** %argv, i64 1, !dbg !24 + %0 = load i8*, i8** %arrayidx, align 8, !dbg !24 + %call = tail call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %0) #4, !dbg !25 + tail call void @llvm.dbg.value(metadata i32 %call, i64 0, metadata !26, metadata !17), !dbg !27 + br label %if.end + + if.end: ; preds = %if.else, %entry + %n.0 = phi i32 [ %call, %if.else ], [ 2, %entry ] + %call1 = tail call i32 @change(i32 %n.0) #4, !dbg !28 + tail call void @llvm.dbg.value(metadata i32 %call1, i64 0, metadata !26, metadata !17), !dbg !27 + %cmp2 = icmp sgt i32 %call1, 10, !dbg !29 + br i1 %cmp2, label %if.then.3, label %if.else.5, !dbg !31 + + if.then.3: ; preds = %if.end + %call4 = tail call i32 @modify(i32 %call1) #4, !dbg !32 + %add = add nsw i32 %call4, %call1, !dbg !34 + br label %if.end.7, !dbg !35 + + if.else.5: ; preds = %if.end + %call6 = tail call i32 @inc(i32 %call1) #4, !dbg !36 + br label %if.end.7 + + if.end.7: ; preds = %if.else.5, %if.then.3 + %storemerge = phi i32 [ %call6, %if.else.5 ], [ %add, %if.then.3 ] + store i32 %storemerge, i32* @m, align 4, !dbg !37 + %call8 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %storemerge) #4, !dbg !38 + ret i32 0, !dbg !39 + } + + declare i32 @atoi(...) #1 + + declare i32 @change(i32) #1 + + declare i32 @modify(i32) #1 + + declare i32 @inc(i32) #1 + + ; Function Attrs: nounwind + declare i32 @printf(i8* nocapture readonly, ...) #2 + + ; Function Attrs: nounwind readnone + declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #3 + + attributes #0 = { nounwind uwtable } + attributes #2 = { nounwind } + attributes #3 = { nounwind readnone } + attributes #4 = { nounwind } + + !llvm.dbg.cu = !{!0} + !llvm.module.flags = !{!13, !14} + !llvm.ident = !{!15} + + !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.8.0 (trunk 243841)", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3, globals: !11) + !1 = !DIFile(filename: "ExtendDebugRange.c", directory: "/home/vt/julia/test/vikram") + !2 = !{} + !3 = !{!4} + !4 = !DISubprogram(name: "main", scope: !1, file: !1, line: 6, type: !5, isLocal: false, isDefinition: true, scopeLine: 6, flags: DIFlagPrototyped, isOptimized: false, function: i32 (i32, i8**)* @main, variables: !2) + !5 = !DISubroutineType(types: !6) + !6 = !{!7, !7, !8} + !7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) + !8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64, align: 64) + !9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 64, align: 64) + !10 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char) + !11 = !{!12} + !12 = !DIGlobalVariable(name: "m", scope: !0, file: !1, line: 2, type: !7, isLocal: false, isDefinition: true, variable: i32* @m) + !13 = !{i32 2, !"Dwarf Version", i32 4} + !14 = !{i32 2, !"Debug Info Version", i32 3} + !15 = !{!"clang version 3.8.0 (trunk 243841)"} + !16 = !DILocalVariable(name: "argc", arg: 1, scope: !4, file: !1, line: 6, type: !7) + !17 = !DIExpression() + !18 = !DILocation(line: 6, column: 14, scope: !4) + !19 = !DILocalVariable(name: "argv", arg: 2, scope: !4, file: !1, line: 6, type: !8) + !20 = !DILocation(line: 6, column: 27, scope: !4) + !21 = !DILocation(line: 8, column: 12, scope: !22) + !22 = distinct !DILexicalBlock(scope: !4, file: !1, line: 8, column: 7) + !23 = !DILocation(line: 8, column: 7, scope: !4) + !24 = !DILocation(line: 11, column: 14, scope: !22) + !25 = !DILocation(line: 11, column: 9, scope: !22) + !26 = !DILocalVariable(name: "n", scope: !4, file: !1, line: 7, type: !7) + !27 = !DILocation(line: 7, column: 7, scope: !4) + !28 = !DILocation(line: 13, column: 7, scope: !4) + !29 = !DILocation(line: 14, column: 9, scope: !30) + !30 = distinct !DILexicalBlock(scope: !4, file: !1, line: 14, column: 7) + !31 = !DILocation(line: 14, column: 7, scope: !4) + !32 = !DILocation(line: 15, column: 9, scope: !33) + !33 = distinct !DILexicalBlock(scope: !30, file: !1, line: 14, column: 15) + !34 = !DILocation(line: 16, column: 11, scope: !33) + !35 = !DILocation(line: 17, column: 3, scope: !33) + !36 = !DILocation(line: 19, column: 9, scope: !30) + !37 = !DILocation(line: 16, column: 7, scope: !33) + !38 = !DILocation(line: 20, column: 3, scope: !4) + !39 = !DILocation(line: 22, column: 3, scope: !4) + +... +--- +name: main +alignment: 4 +exposesReturnsTwice: false +hasInlineAsm: false +isSSA: false +tracksRegLiveness: true +tracksSubRegLiveness: false +liveins: + - { reg: '%edi' } + - { reg: '%rsi' } +calleeSavedRegisters: [ '%bh', '%bl', '%bp', '%bpl', '%bx', '%ebp', '%ebx', + '%rbp', '%rbx', '%r12', '%r13', '%r14', '%r15', + '%r12b', '%r13b', '%r14b', '%r15b', '%r12d', '%r13d', + '%r14d', '%r15d', '%r12w', '%r13w', '%r14w', '%r15w' ] +frameInfo: + isFrameAddressTaken: false + isReturnAddressTaken: false + hasStackMap: false + hasPatchPoint: false + stackSize: 24 + offsetAdjustment: -8 + maxAlignment: 0 + adjustsStack: true + hasCalls: true + maxCallFrameSize: 0 + hasOpaqueSPAdjustment: false + hasVAStart: false + hasMustTailInVarArgFunc: false +fixedStack: + - { id: 0, type: spill-slot, offset: -24, size: 8, alignment: 8, callee-saved-register: '%rbx' } + - { id: 1, type: spill-slot, offset: -16, size: 8, alignment: 16 } +body: | + bb.0.entry: + successors: %bb.1.if.else(16), %bb.2.if.end(16) + liveins: %edi, %rsi, %rbx, %rbx, %rbp + + frame-setup PUSH64r killed %rbp, implicit-def %rsp, implicit %rsp + CFI_INSTRUCTION .cfi_def_cfa_offset 16 + CFI_INSTRUCTION .cfi_offset %rbp, -16 + %rbp = frame-setup MOV64rr %rsp + CFI_INSTRUCTION .cfi_def_cfa_register %rbp + frame-setup PUSH64r killed %rbx, implicit-def %rsp, implicit %rsp + frame-setup PUSH64r undef %rax, implicit-def %rsp, implicit %rsp + CFI_INSTRUCTION .cfi_offset %rbx, -24 + DBG_VALUE debug-use %edi, debug-use _, !16, !17, debug-location !18 + DBG_VALUE debug-use %rsi, debug-use _, !19, !17, debug-location !20 + %eax = MOV32rr %edi + DBG_VALUE debug-use %eax, debug-use _, !16, !17, debug-location !18 + %edi = MOV32ri 2 + CMP32ri8 killed %eax, 2, implicit-def %eflags, debug-location !23 + JNE_1 %bb.2.if.end, implicit %eflags + + bb.1.if.else: + successors: %bb.2.if.end + liveins: %rsi, %rbp + + DBG_VALUE debug-use %rsi, debug-use _, !19, !17, debug-location !20 + %rdi = MOV64rm killed %rsi, 1, _, 8, _, debug-location !24 :: (load 8 from %ir.arrayidx) + dead %eax = XOR32rr undef %eax, undef %eax, implicit-def dead %eflags, implicit-def %al, debug-location !25 + CALL64pcrel32 @atoi, csr_64, implicit %rsp, implicit %rdi, implicit %al, implicit-def %rsp, implicit-def %eax, debug-location !25 + %edi = MOV32rr %eax, debug-location !25 + DBG_VALUE debug-use %edi, debug-use _, !26, !17, debug-location !27 + + bb.2.if.end: + successors: %bb.3.if.then.3(16), %bb.4.if.else.5(16) + liveins: %edi, %rbp + + CALL64pcrel32 @change, csr_64, implicit %rsp, implicit %edi, implicit-def %rsp, implicit-def %eax, debug-location !28 + %ebx = MOV32rr %eax, debug-location !28 + DBG_VALUE debug-use %ebx, debug-use _, !26, !17, debug-location !27 + CMP32ri8 %ebx, 11, implicit-def %eflags, debug-location !31 + JL_1 %bb.4.if.else.5, implicit killed %eflags, debug-location !31 + + bb.3.if.then.3: + successors: %bb.5.if.end.7 + liveins: %ebx, %rbp + + DBG_VALUE debug-use %ebx, debug-use _, !26, !17, debug-location !27 + %edi = MOV32rr %ebx, debug-location !32 + CALL64pcrel32 @modify, csr_64, implicit %rsp, implicit %edi, implicit-def %rsp, implicit-def %eax, debug-location !32 + %ecx = MOV32rr %eax, debug-location !32 + %ecx = ADD32rr killed %ecx, killed %ebx, implicit-def dead %eflags, debug-location !34 + JMP_1 %bb.5.if.end.7 + + bb.4.if.else.5: + successors: %bb.5.if.end.7 + liveins: %ebx, %rbp + + DBG_VALUE debug-use %ebx, debug-use _, !26, !17, debug-location !27 + %edi = MOV32rr killed %ebx, debug-location !36 + CALL64pcrel32 @inc, csr_64, implicit %rsp, implicit %edi, implicit-def %rsp, implicit-def %eax, debug-location !36 + %ecx = MOV32rr %eax, debug-location !36 + + bb.5.if.end.7: + liveins: %ecx, %rbp + + MOV32mr %rip, 1, _, @m, _, %ecx, debug-location !37 :: (store 4 into @m) + dead undef %edi = MOV32ri64 @.str, implicit-def %rdi, debug-location !38 + dead %eax = XOR32rr undef %eax, undef %eax, implicit-def dead %eflags, implicit-def %al, debug-location !39 + %esi = MOV32rr killed %ecx, debug-location !38 + CALL64pcrel32 @printf, csr_64, implicit %rsp, implicit %rdi, implicit %esi, implicit %al, implicit-def %rsp, implicit-def dead %eax, debug-location !38 + %eax = XOR32rr undef %eax, undef %eax, implicit-def dead %eflags, debug-location !39 + %rsp = ADD64ri8 %rsp, 8, implicit-def dead %eflags, debug-location !39 + %rbx = POP64r implicit-def %rsp, implicit %rsp, debug-location !39 + %rbp = POP64r implicit-def %rsp, implicit %rsp, debug-location !39 + RETQ %eax, debug-location !39 + +... Index: test/DebugInfo/MIR/X86/lit.local.cfg =================================================================== --- /dev/null +++ test/DebugInfo/MIR/X86/lit.local.cfg @@ -0,0 +1,2 @@ +if not 'X86' in config.root.targets: + config.unsupported = True Index: test/DebugInfo/MIR/lit.local.cfg =================================================================== --- /dev/null +++ test/DebugInfo/MIR/lit.local.cfg @@ -0,0 +1,2 @@ +config.suffixes = ['.mir'] + Index: test/DebugInfo/X86/array.ll =================================================================== --- test/DebugInfo/X86/array.ll +++ test/DebugInfo/X86/array.ll @@ -17,6 +17,8 @@ ; rdar://problem/14874886 ; ; CHECK: ##DEBUG_VALUE: main:array <- [R{{.*}}+0] +; CHECK: ##DEBUG_VALUE: main:array <- [R{{.*}}+0] +; CHECK: ##DEBUG_VALUE: main:array <- [R{{.*}}+0] ; CHECK-NOT: ##DEBUG_VALUE: main:array <- R{{.*}} target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-apple-macosx10.9.0" Index: test/DebugInfo/X86/fission-ranges.ll =================================================================== --- test/DebugInfo/X86/fission-ranges.ll +++ test/DebugInfo/X86/fission-ranges.ll @@ -29,16 +29,16 @@ ; CHECK-NEXT: Location description: 11 00 ; CHECK-NEXT: {{^$}} ; CHECK-NEXT: Beginning address index: 3 -; CHECK-NEXT: Length: 21 +; CHECK-NEXT: Length: 25 ; CHECK-NEXT: Location description: 50 93 04 ; CHECK: [[E]]: Beginning address index: 4 -; CHECK-NEXT: Length: 19 +; CHECK-NEXT: Length: 23 ; CHECK-NEXT: Location description: 50 93 04 ; CHECK: [[B]]: Beginning address index: 5 -; CHECK-NEXT: Length: 17 +; CHECK-NEXT: Length: 21 ; CHECK-NEXT: Location description: 50 93 04 ; CHECK: [[D]]: Beginning address index: 6 -; CHECK-NEXT: Length: 17 +; CHECK-NEXT: Length: 21 ; CHECK-NEXT: Location description: 50 93 04 ; Make sure we don't produce any relocations in any .dwo section (though in particular, debug_info.dwo) Index: test/DebugInfo/X86/pieces-3.ll =================================================================== --- test/DebugInfo/X86/pieces-3.ll +++ test/DebugInfo/X86/pieces-3.ll @@ -26,7 +26,7 @@ ; CHECK: .debug_loc ; CHECK: [[LOC]]: ; CHECK: Beginning address offset: 0x0000000000000000 -; CHECK: Ending address offset: 0x0000000000000004 +; CHECK: Ending address offset: 0x0000000000000008 ; rdi, piece 0x00000008, piece 0x00000004, rsi, piece 0x00000004 ; CHECK: Location description: 55 93 08 93 04 54 93 04 ; Index: test/DebugInfo/X86/sret.ll =================================================================== --- test/DebugInfo/X86/sret.ll +++ test/DebugInfo/X86/sret.ll @@ -3,8 +3,8 @@ ; Based on the debuginfo-tests/sret.cpp code. -; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8] (0x51ac5644b1937aa1) -; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8] (0x51ac5644b1937aa1) +; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8] ([[ADDR:0x[0-9a-z]*]]) +; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8] ([[ADDR]]) %class.A = type { i32 (...)**, i32 } %class.B = type { i8 } Index: test/DebugInfo/extend-debug-range.ll =================================================================== --- /dev/null +++ test/DebugInfo/extend-debug-range.ll @@ -0,0 +1,145 @@ +; RUN: llc -filetype=asm %s -o - | FileCheck %s + +; Test the extension of debug ranges from predecessors. +; Generated from the source file ExtendDebugRange.c: +; #include +; int m; +; extern int inc(int n); +; extern int change(int n); +; extern int modify(int n); +; int main(int argc, char **argv) { +; int n; +; if (argc != 2) +; n = 2; +; else +; n = atoi(argv[1]); +; n = change(n); +; if (n > 10) { +; m = modify(n); +; m = m + n; // var `m' doesn't has a dbg.value +; } +; else +; m = inc(n); // var `m' doesn't has a dbg.value +; printf("m(main): %d\n", m); +; return 0; +; } +; with clang -g -emit-llvm ExtendDebugRange.c -c -o edr.bc +; then opt -O3 -S -o extend-debug-range.ll edr.bc +; This case will also produce multiple locations but only the debug range +; extension is tested here. + +; DBG_VALUE for variable "n" is extended into BB#5 from its predecessors BB#3 +; and BB#4. +; CHECK: .LBB0_5: +; CHECK-NEXT: #DEBUG_VALUE: main:argv <- RSI +; CHECK-NEXT: #DEBUG_VALUE: main:n <- EBX + + +; ModuleID = 'edr.bc' +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@m = common global i32 0, align 4 +@.str = private unnamed_addr constant [13 x i8] c"m(main): %d\0A\00", align 1 + +; Function Attrs: nounwind uwtable +define i32 @main(i32 %argc, i8** nocapture readonly %argv) #0 { +entry: + tail call void @llvm.dbg.value(metadata i32 %argc, i64 0, metadata !16, metadata !17), !dbg !18 + tail call void @llvm.dbg.value(metadata i8** %argv, i64 0, metadata !19, metadata !17), !dbg !20 + %cmp = icmp eq i32 %argc, 2, !dbg !21 + br i1 %cmp, label %if.else, label %if.end, !dbg !23 + +if.else: ; preds = %entry + %arrayidx = getelementptr inbounds i8*, i8** %argv, i64 1, !dbg !24 + %0 = load i8*, i8** %arrayidx, align 8, !dbg !24 + %call = tail call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %0) #4, !dbg !25 + tail call void @llvm.dbg.value(metadata i32 %call, i64 0, metadata !26, metadata !17), !dbg !27 + br label %if.end + +if.end: ; preds = %entry, %if.else + %n.0 = phi i32 [ %call, %if.else ], [ 2, %entry ] + %call1 = tail call i32 @change(i32 %n.0) #4, !dbg !28 + tail call void @llvm.dbg.value(metadata i32 %call1, i64 0, metadata !26, metadata !17), !dbg !27 + %cmp2 = icmp sgt i32 %call1, 10, !dbg !29 + br i1 %cmp2, label %if.then.3, label %if.else.5, !dbg !31 + +if.then.3: ; preds = %if.end + %call4 = tail call i32 @modify(i32 %call1) #4, !dbg !32 + %add = add nsw i32 %call4, %call1, !dbg !34 + br label %if.end.7, !dbg !35 + +if.else.5: ; preds = %if.end + %call6 = tail call i32 @inc(i32 %call1) #4, !dbg !36 + br label %if.end.7 + +if.end.7: ; preds = %if.else.5, %if.then.3 + %storemerge = phi i32 [ %call6, %if.else.5 ], [ %add, %if.then.3 ] + store i32 %storemerge, i32* @m, align 4, !dbg !37 + %call8 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %storemerge) #4, !dbg !38 + ret i32 0, !dbg !39 +} + +declare i32 @atoi(...) #1 + +declare i32 @change(i32) #1 + +declare i32 @modify(i32) #1 + +declare i32 @inc(i32) #1 + +; Function Attrs: nounwind +declare i32 @printf(i8* nocapture readonly, ...) #2 + +; Function Attrs: nounwind readnone +declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #3 + +attributes #0 = { nounwind uwtable } +attributes #2 = { nounwind } +attributes #3 = { nounwind readnone } +attributes #4 = { nounwind } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!13, !14} +!llvm.ident = !{!15} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.8.0 (trunk 243841)", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3, globals: !11) +!1 = !DIFile(filename: "ExtendDebugRanges.c", directory: "/home/vt/vikram/newTests") +!2 = !{} +!3 = !{!4} +!4 = !DISubprogram(name: "main", scope: !1, file: !1, line: 6, type: !5, isLocal: false, isDefinition: true, scopeLine: 6, flags: DIFlagPrototyped, isOptimized: false, function: i32 (i32, i8**)* @main, variables: !2) +!5 = !DISubroutineType(types: !6) +!6 = !{!7, !7, !8} +!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) +!8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64, align: 64) +!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 64, align: 64) +!10 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char) +!11 = !{!12} +!12 = !DIGlobalVariable(name: "m", scope: !0, file: !1, line: 2, type: !7, isLocal: false, isDefinition: true, variable: i32* @m) +!13 = !{i32 2, !"Dwarf Version", i32 4} +!14 = !{i32 2, !"Debug Info Version", i32 3} +!15 = !{!"clang version 3.8.0 (trunk 243841)"} +!16 = !DILocalVariable(name: "argc", arg: 1, scope: !4, file: !1, line: 6, type: !7) +!17 = !DIExpression() +!18 = !DILocation(line: 6, column: 14, scope: !4) +!19 = !DILocalVariable(name: "argv", arg: 2, scope: !4, file: !1, line: 6, type: !8) +!20 = !DILocation(line: 6, column: 27, scope: !4) +!21 = !DILocation(line: 8, column: 12, scope: !22) +!22 = distinct !DILexicalBlock(scope: !4, file: !1, line: 8, column: 7) +!23 = !DILocation(line: 8, column: 7, scope: !4) +!24 = !DILocation(line: 11, column: 14, scope: !22) +!25 = !DILocation(line: 11, column: 9, scope: !22) +!26 = !DILocalVariable(name: "n", scope: !4, file: !1, line: 7, type: !7) +!27 = !DILocation(line: 7, column: 7, scope: !4) +!28 = !DILocation(line: 12, column: 7, scope: !4) +!29 = !DILocation(line: 13, column: 9, scope: !30) +!30 = distinct !DILexicalBlock(scope: !4, file: !1, line: 13, column: 7) +!31 = !DILocation(line: 13, column: 7, scope: !4) +!32 = !DILocation(line: 14, column: 9, scope: !33) +!33 = distinct !DILexicalBlock(scope: !30, file: !1, line: 13, column: 15) +!34 = !DILocation(line: 15, column: 11, scope: !33) +!35 = !DILocation(line: 16, column: 3, scope: !33) +!36 = !DILocation(line: 18, column: 9, scope: !30) +!37 = !DILocation(line: 15, column: 7, scope: !33) +!38 = !DILocation(line: 19, column: 3, scope: !4) +!39 = !DILocation(line: 20, column: 3, scope: !4)