Skip to content

Commit 135227a

Browse files
committed
Pass in something sensible for the debug ___location information when creating the
initial PHI nodes of the machine function. llvm-svn: 63598
1 parent fa4e35a commit 135227a

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ FunctionLoweringInfo::FunctionLoweringInfo(TargetLowering &tli)
271271
}
272272

273273
void FunctionLoweringInfo::set(Function &fn, MachineFunction &mf,
274+
SelectionDAG &DAG,
274275
bool EnableFastISel) {
275276
Fn = &fn;
276277
MF = &mf;
@@ -320,8 +321,53 @@ void FunctionLoweringInfo::set(Function &fn, MachineFunction &mf,
320321
// Create Machine PHI nodes for LLVM PHI nodes, lowering them as
321322
// appropriate.
322323
PHINode *PN;
323-
for (BasicBlock::iterator I = BB->begin();(PN = dyn_cast<PHINode>(I)); ++I){
324-
if (PN->use_empty()) continue;
324+
DebugLoc DL;
325+
for (BasicBlock::iterator
326+
I = BB->begin(), E = BB->end(); I != E; ++I) {
327+
if (CallInst *CI = dyn_cast<CallInst>(I)) {
328+
if (Function *F = CI->getCalledFunction()) {
329+
switch (F->getIntrinsicID()) {
330+
default: break;
331+
case Intrinsic::dbg_stoppoint: {
332+
DwarfWriter *DW = DAG.getDwarfWriter();
333+
DbgStopPointInst *SPI = cast<DbgStopPointInst>(I);
334+
335+
if (DW && DW->ValidDebugInfo(SPI->getContext())) {
336+
DICompileUnit CU(cast<GlobalVariable>(SPI->getContext()));
337+
unsigned SrcFile = DW->RecordSource(CU.getDirectory(),
338+
CU.getFilename());
339+
unsigned idx = MF->getOrCreateDebugLocID(SrcFile,
340+
SPI->getLine(),
341+
SPI->getColumn());
342+
DL = DebugLoc::get(idx);
343+
}
344+
345+
break;
346+
}
347+
case Intrinsic::dbg_func_start: {
348+
DwarfWriter *DW = DAG.getDwarfWriter();
349+
if (DW) {
350+
DbgFuncStartInst *FSI = cast<DbgFuncStartInst>(I);
351+
Value *SP = FSI->getSubprogram();
352+
353+
if (DW->ValidDebugInfo(SP)) {
354+
DISubprogram Subprogram(cast<GlobalVariable>(SP));
355+
DICompileUnit CU(Subprogram.getCompileUnit());
356+
unsigned SrcFile = DW->RecordSource(CU.getDirectory(),
357+
CU.getFilename());
358+
unsigned Line = Subprogram.getLineNumber();
359+
DL = DebugLoc::get(MF->getOrCreateDebugLocID(SrcFile, Line, 0));
360+
}
361+
}
362+
363+
break;
364+
}
365+
}
366+
}
367+
}
368+
369+
PN = dyn_cast<PHINode>(I);
370+
if (!PN || PN->use_empty()) continue;
325371

326372
unsigned PHIReg = ValueMap[PN];
327373
assert(PHIReg && "PHI node does not have an assigned virtual register!");
@@ -333,8 +379,7 @@ void FunctionLoweringInfo::set(Function &fn, MachineFunction &mf,
333379
unsigned NumRegisters = TLI.getNumRegisters(VT);
334380
const TargetInstrInfo *TII = MF->getTarget().getInstrInfo();
335381
for (unsigned i = 0; i != NumRegisters; ++i)
336-
BuildMI(MBB, DebugLoc::getUnknownLoc(),
337-
TII->get(TargetInstrInfo::PHI), PHIReg + i);
382+
BuildMI(MBB, DL, TII->get(TargetInstrInfo::PHI), PHIReg + i);
338383
PHIReg += NumRegisters;
339384
}
340385
}

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuild.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ class FunctionLoweringInfo {
9595
/// set - Initialize this FunctionLoweringInfo with the given Function
9696
/// and its associated MachineFunction.
9797
///
98-
void set(Function &Fn, MachineFunction &MF, bool EnableFastISel);
98+
void set(Function &Fn, MachineFunction &MF, SelectionDAG &DAG,
99+
bool EnableFastISel);
99100

100101
/// MBBMap - A mapping from LLVM basic blocks to their machine code entry.
101102
DenseMap<const BasicBlock*, MachineBasicBlock *> MBBMap;

llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ bool SelectionDAGISel::runOnFunction(Function &Fn) {
313313
RegInfo = &MF->getRegInfo();
314314
DOUT << "\n\n\n=== " << Fn.getName() << "\n";
315315

316-
FuncInfo->set(Fn, *MF, EnableFastISel);
316+
FuncInfo->set(Fn, *MF, *CurDAG, EnableFastISel);
317317
MachineModuleInfo *MMI = getAnalysisIfAvailable<MachineModuleInfo>();
318318
DwarfWriter *DW = getAnalysisIfAvailable<DwarfWriter>();
319319
CurDAG->init(*MF, MMI, DW);

0 commit comments

Comments
 (0)