diff options
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 2 | ||||
-rw-r--r-- | lib/CodeGen/DebugLoc.cpp | 38 | ||||
-rw-r--r-- | lib/CodeGen/MachineFunction.cpp | 18 | ||||
-rw-r--r-- | lib/CodeGen/SelectionDAG/FastISel.cpp | 38 | ||||
-rw-r--r-- | lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp | 53 | ||||
-rw-r--r-- | lib/CodeGen/SelectionDAG/SelectionDAGBuild.h | 2 |
6 files changed, 124 insertions, 27 deletions
diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 45462da0d2..438ba035ba 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1311,7 +1311,7 @@ void AsmPrinter::PrintSpecial(const MachineInstr *MI, const char *Code) const { void AsmPrinter::processDebugLoc(DebugLoc DL) { if (TAI->doesSupportDebugInformation() && DW->ShouldEmitDwarfDebug()) { if (!DL.isUnknown()) { - static DebugLocTuple PrevDLT(0, ~0U, ~0U); + static DebugLocTuple PrevDLT(0, DebugScope::getInvalid(), ~0U, ~0U); DebugLocTuple CurDLT = MF->getDebugLocTuple(DL); if (CurDLT.CompileUnit != 0 && PrevDLT != CurDLT) diff --git a/lib/CodeGen/DebugLoc.cpp b/lib/CodeGen/DebugLoc.cpp new file mode 100644 index 0000000000..bc1a5b1340 --- /dev/null +++ b/lib/CodeGen/DebugLoc.cpp @@ -0,0 +1,38 @@ +//===-- DebugLoc.cpp ------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Implementation for DebugScopeTracker. +// +//===----------------------------------------------------------------------===// + +#include "llvm/CodeGen/DebugLoc.h" +#include "llvm/CodeGen/MachineFunction.h" +using namespace llvm; + +/// EnterDebugScope - Start a new debug scope. ScopeGV can be a DISubprogram +/// or a DIBlock. +void DebugScopeTracker::EnterDebugScope(GlobalVariable *ScopeGV, + MachineFunction &MF) { + assert(ScopeGV && "GlobalVariable for scope is null!"); + CurScope = MF.CreateDebugScope(ScopeGV, CurScope); +} + +/// ExitDebugScope - "Pop" a DISubprogram or a DIBlock. +void DebugScopeTracker::ExitDebugScope(GlobalVariable *ScopeGV, + MachineFunction &MF) { + assert(ScopeGV && "GlobalVariable for scope is null!"); + assert(!CurScope.isInvalid() && "Mismatched region.end ?"); + // We may have skipped a region.end because it was in an unreachable block. + // Go up the scope chain until we reach the scope that ScopeGV points to. + DebugScopeInfo DSI; + do { + DSI = MF.getDebugScopeInfo(CurScope); + CurScope = DSI.Parent; + } while (!DSI.Parent.isInvalid() && DSI.GV != ScopeGV); +} diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index cacfed1d9f..d1d782c825 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -403,8 +403,9 @@ unsigned MachineFunction::addLiveIn(unsigned PReg, /// source file, line, and column. If none currently exists, create a new /// DebugLocTuple, and insert it into the DebugIdMap. unsigned MachineFunction::getOrCreateDebugLocID(GlobalVariable *CompileUnit, + DebugScope Scope, unsigned Line, unsigned Col) { - DebugLocTuple Tuple(CompileUnit, Line, Col); + DebugLocTuple Tuple(CompileUnit, Scope, Line, Col); DenseMap<DebugLocTuple, unsigned>::iterator II = DebugLocInfo.DebugIdMap.find(Tuple); if (II != DebugLocInfo.DebugIdMap.end()) @@ -424,6 +425,21 @@ DebugLocTuple MachineFunction::getDebugLocTuple(DebugLoc DL) const { return DebugLocInfo.DebugLocations[Idx]; } +/// CreateDebugScope - Create a new debug scope. +DebugScope MachineFunction::CreateDebugScope(GlobalVariable *ScopeGV, + DebugScope Parent) { + DbgScopeInfos.push_back(DebugScopeInfo(ScopeGV, Parent)); + return DebugScope::get(DbgScopeInfos.size() - 1); +} + +/// getDebugScopeInfo - Get the DebugScopeInfo for a given DebugScope object. +const DebugScopeInfo &MachineFunction::getDebugScopeInfo(DebugScope DS) const { + unsigned Idx = DS.getIndex(); + assert(Idx < DbgScopeInfos.size() && "Invalid index into debug scopes!"); + return DbgScopeInfos[Idx]; +} + + //===----------------------------------------------------------------------===// // MachineFrameInfo implementation //===----------------------------------------------------------------------===// diff --git a/lib/CodeGen/SelectionDAG/FastISel.cpp b/lib/CodeGen/SelectionDAG/FastISel.cpp index 367cf4cd5c..1c05b0a6ce 100644 --- a/lib/CodeGen/SelectionDAG/FastISel.cpp +++ b/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -331,17 +331,22 @@ bool FastISel::SelectCall(User *I) { DICompileUnit CU(cast<GlobalVariable>(SPI->getContext())); unsigned Line = SPI->getLine(); unsigned Col = SPI->getColumn(); - unsigned Idx = MF.getOrCreateDebugLocID(CU.getGV(), Line, Col); + unsigned Idx = MF.getOrCreateDebugLocID(CU.getGV(), + DbgScopeTrack.getCurScope(), + Line, Col); setCurDebugLoc(DebugLoc::get(Idx)); } return true; } case Intrinsic::dbg_region_start: { DbgRegionStartInst *RSI = cast<DbgRegionStartInst>(I); - if (DIDescriptor::ValidDebugInfo(RSI->getContext(), CodeGenOpt::None) && - DW && DW->ShouldEmitDwarfDebug()) { - unsigned ID = - DW->RecordRegionStart(cast<GlobalVariable>(RSI->getContext())); + if (!DIDescriptor::ValidDebugInfo(RSI->getContext(), CodeGenOpt::None)) + return true; + + GlobalVariable *Rgn = cast<GlobalVariable>(RSI->getContext()); + DbgScopeTrack.EnterDebugScope(Rgn, MF); + if (DW && DW->ShouldEmitDwarfDebug()) { + unsigned ID = DW->RecordRegionStart(Rgn); const TargetInstrDesc &II = TII.get(TargetInstrInfo::DBG_LABEL); BuildMI(MBB, DL, II).addImm(ID); } @@ -349,10 +354,14 @@ bool FastISel::SelectCall(User *I) { } case Intrinsic::dbg_region_end: { DbgRegionEndInst *REI = cast<DbgRegionEndInst>(I); - if (DIDescriptor::ValidDebugInfo(REI->getContext(), CodeGenOpt::None) && - DW && DW->ShouldEmitDwarfDebug()) { + if (!DIDescriptor::ValidDebugInfo(REI->getContext(), CodeGenOpt::None)) + return true; + + GlobalVariable *Rgn = cast<GlobalVariable>(REI->getContext()); + DbgScopeTrack.ExitDebugScope(Rgn, MF); + if (DW && DW->ShouldEmitDwarfDebug()) { unsigned ID = 0; - DISubprogram Subprogram(cast<GlobalVariable>(REI->getContext())); + DISubprogram Subprogram(Rgn); if (!Subprogram.isNull() && !Subprogram.describes(MF.getFunction())) { // This is end of an inlined function. const TargetInstrDesc &II = TII.get(TargetInstrInfo::DBG_LABEL); @@ -382,6 +391,7 @@ bool FastISel::SelectCall(User *I) { DebugLoc PrevLoc = DL; DISubprogram Subprogram(cast<GlobalVariable>(SP)); DICompileUnit CompileUnit = Subprogram.getCompileUnit(); + DbgScopeTrack.EnterDebugScope(Subprogram.getGV(), MF); if (!Subprogram.describes(MF.getFunction())) { // This is a beginning of an inlined function. @@ -393,8 +403,10 @@ bool FastISel::SelectCall(User *I) { return true; // Record the source line. unsigned Line = Subprogram.getLineNumber(); - setCurDebugLoc(DebugLoc::get(MF.getOrCreateDebugLocID( - CompileUnit.getGV(), Line, 0))); + setCurDebugLoc( + DebugLoc::get(MF.getOrCreateDebugLocID(CompileUnit.getGV(), + DbgScopeTrack.getCurScope(), + Line, 0))); if (DW && DW->ShouldEmitDwarfDebug()) { DebugLocTuple PrevLocTpl = MF.getDebugLocTuple(PrevLoc); @@ -408,8 +420,10 @@ bool FastISel::SelectCall(User *I) { } else { // Record the source line. unsigned Line = Subprogram.getLineNumber(); - MF.setDefaultDebugLoc(DebugLoc::get(MF.getOrCreateDebugLocID( - CompileUnit.getGV(), Line, 0))); + MF.setDefaultDebugLoc( + DebugLoc::get(MF.getOrCreateDebugLocID(CompileUnit.getGV(), + DbgScopeTrack.getCurScope(), + Line, 0))); if (DW && DW->ShouldEmitDwarfDebug()) { // llvm.dbg.func_start also defines beginning of function scope. DW->RecordRegionStart(cast<GlobalVariable>(FSI->getSubprogram())); diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp index 430dcfd286..f0b1ec8a27 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp @@ -312,6 +312,17 @@ void FunctionLoweringInfo::set(Function &fn, MachineFunction &mf, !StaticAllocaMap.count(cast<AllocaInst>(I))) InitializeRegForValue(I); + // FIXME: PHI instructions currently get an invalid scope. This is because + // tracking of debug scopes is done through a simple mechanism where + // "entering" a scope implies that the scope is entered for the first time. + // If we keep track of debug scopes for the following loop, the PHI + // instructions would get scopes that will not be used again later by the + // instruction selectors. + // Either provide a mechanism to re-enter a previously created scope or wait + // for when the DebugLoc is retrieved from Instruction, in which case the + // current debug scope tracking mechanism will be obsolete. + DebugScope DbgScope; + // Create an initial MachineBasicBlock for each LLVM BasicBlock in F. This // also creates the initial PHI MachineInstrs, though none of the input // operands are populated. @@ -337,6 +348,7 @@ void FunctionLoweringInfo::set(Function &fn, MachineFunction &mf, CodeGenOpt::Default)) { DICompileUnit CU(cast<GlobalVariable>(SPI->getContext())); unsigned idx = MF->getOrCreateDebugLocID(CU.getGV(), + DbgScope, SPI->getLine(), SPI->getColumn()); DL = DebugLoc::get(idx); @@ -352,7 +364,7 @@ void FunctionLoweringInfo::set(Function &fn, MachineFunction &mf, DISubprogram Subprogram(cast<GlobalVariable>(SP)); DICompileUnit CU(Subprogram.getCompileUnit()); unsigned Line = Subprogram.getLineNumber(); - DL = DebugLoc::get(MF->getOrCreateDebugLocID(CU.getGV(), + DL = DebugLoc::get(MF->getOrCreateDebugLocID(CU.getGV(), DbgScope, Line, 0)); } @@ -3909,7 +3921,9 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) { MachineFunction &MF = DAG.getMachineFunction(); DICompileUnit CU(cast<GlobalVariable>(SPI.getContext())); DebugLoc Loc = DebugLoc::get(MF.getOrCreateDebugLocID(CU.getGV(), - SPI.getLine(), SPI.getColumn())); + DbgScopeTrack.getCurScope(), + SPI.getLine(), + SPI.getColumn())); setCurDebugLoc(Loc); if (OptLevel == CodeGenOpt::None) @@ -3923,11 +3937,14 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) { case Intrinsic::dbg_region_start: { DwarfWriter *DW = DAG.getDwarfWriter(); DbgRegionStartInst &RSI = cast<DbgRegionStartInst>(I); + if (!DIDescriptor::ValidDebugInfo(RSI.getContext(), OptLevel)) + return 0; - if (DIDescriptor::ValidDebugInfo(RSI.getContext(), OptLevel) && - DW && DW->ShouldEmitDwarfDebug()) { - unsigned LabelID = - DW->RecordRegionStart(cast<GlobalVariable>(RSI.getContext())); + MachineFunction &MF = DAG.getMachineFunction(); + GlobalVariable *Rgn = cast<GlobalVariable>(RSI.getContext()); + DbgScopeTrack.EnterDebugScope(Rgn, MF); + if (DW && DW->ShouldEmitDwarfDebug()) { + unsigned LabelID = DW->RecordRegionStart(Rgn); DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getCurDebugLoc(), getRoot(), LabelID)); } @@ -3937,11 +3954,14 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) { case Intrinsic::dbg_region_end: { DwarfWriter *DW = DAG.getDwarfWriter(); DbgRegionEndInst &REI = cast<DbgRegionEndInst>(I); + if (!DIDescriptor::ValidDebugInfo(REI.getContext(), OptLevel)) + return 0; - if (DIDescriptor::ValidDebugInfo(REI.getContext(), OptLevel) && - DW && DW->ShouldEmitDwarfDebug()) { - MachineFunction &MF = DAG.getMachineFunction(); - DISubprogram Subprogram(cast<GlobalVariable>(REI.getContext())); + MachineFunction &MF = DAG.getMachineFunction(); + GlobalVariable *Rgn = cast<GlobalVariable>(REI.getContext()); + DbgScopeTrack.ExitDebugScope(Rgn, MF); + if (DW && DW->ShouldEmitDwarfDebug()) { + DISubprogram Subprogram(Rgn); if (Subprogram.isNull() || Subprogram.describes(MF.getFunction())) { unsigned LabelID = @@ -3974,6 +3994,7 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) { return 0; MachineFunction &MF = DAG.getMachineFunction(); + DbgScopeTrack.EnterDebugScope(cast<GlobalVariable>(SP), MF); if (OptLevel == CodeGenOpt::None) { // llvm.dbg.func.start implicitly defines a dbg_stoppoint which is what // (most?) gdb expects. @@ -3993,7 +4014,9 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) { // Record the source line. unsigned Line = Subprogram.getLineNumber(); setCurDebugLoc(DebugLoc::get( - MF.getOrCreateDebugLocID(CompileUnit.getGV(), Line, 0))); + MF.getOrCreateDebugLocID(CompileUnit.getGV(), + DbgScopeTrack.getCurScope(), + Line, 0))); if (DW && DW->ShouldEmitDwarfDebug()) { DebugLocTuple PrevLocTpl = MF.getDebugLocTuple(PrevLoc); @@ -4008,7 +4031,9 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) { // Record the source line. unsigned Line = Subprogram.getLineNumber(); MF.setDefaultDebugLoc(DebugLoc::get( - MF.getOrCreateDebugLocID(CompileUnit.getGV(), Line, 0))); + MF.getOrCreateDebugLocID(CompileUnit.getGV(), + DbgScopeTrack.getCurScope(), + Line, 0))); if (DW && DW->ShouldEmitDwarfDebug()) { // llvm.dbg.func_start also defines beginning of function scope. DW->RecordRegionStart(cast<GlobalVariable>(FSI.getSubprogram())); @@ -4035,7 +4060,9 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) { // create a label if this is a beginning of inlined function. unsigned Line = Subprogram.getLineNumber(); setCurDebugLoc(DebugLoc::get( - MF.getOrCreateDebugLocID(CompileUnit.getGV(), Line, 0))); + MF.getOrCreateDebugLocID(CompileUnit.getGV(), + DbgScopeTrack.getCurScope(), + Line, 0))); // FIXME - Start new region because llvm.dbg.func_start also defines // beginning of function scope. } diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.h b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.h index 578aa591ce..0c9b317b5d 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.h +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.h @@ -169,6 +169,8 @@ class SelectionDAGLowering { /// CurDebugLoc - current file + line number. Changes as we build the DAG. DebugLoc CurDebugLoc; + DebugScopeTracker DbgScopeTrack; + DenseMap<const Value*, SDValue> NodeMap; /// PendingLoads - Loads are not emitted to the program immediately. We bunch |