Transforms: Use the new DebugLoc API, NFC

Update lib/Analysis and lib/Transforms to use the new `DebugLoc` API.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233587 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith 2015-03-30 19:49:49 +00:00
parent 39acf8f243
commit f175439a2b
8 changed files with 35 additions and 36 deletions

View File

@ -464,23 +464,20 @@ public:
/// cannot find a terminating instruction with location information, /// cannot find a terminating instruction with location information,
/// it returns an unknown location. /// it returns an unknown location.
DebugLoc getStartLoc() const { DebugLoc getStartLoc() const {
DebugLoc StartLoc;
BasicBlock *HeadBB; BasicBlock *HeadBB;
// Try the pre-header first. // Try the pre-header first.
if ((HeadBB = getLoopPreheader()) != nullptr) { if ((HeadBB = getLoopPreheader()) != nullptr)
StartLoc = HeadBB->getTerminator()->getDebugLoc(); if (DebugLoc DL = HeadBB->getTerminator()->getDebugLoc())
if (!StartLoc.isUnknown()) return DL;
return StartLoc;
}
// If we have no pre-header or there are no instructions with debug // If we have no pre-header or there are no instructions with debug
// info in it, try the header. // info in it, try the header.
HeadBB = getHeader(); HeadBB = getHeader();
if (HeadBB) if (HeadBB)
StartLoc = HeadBB->getTerminator()->getDebugLoc(); return HeadBB->getTerminator()->getDebugLoc();
return StartLoc; return DebugLoc();
} }
private: private:

View File

@ -2723,7 +2723,7 @@ bool InstCombiner::run() {
DEBUG(dbgs() << "IC: Old = " << *I << '\n' DEBUG(dbgs() << "IC: Old = " << *I << '\n'
<< " New = " << *Result << '\n'); << " New = " << *Result << '\n');
if (!I->getDebugLoc().isUnknown()) if (I->getDebugLoc())
Result->setDebugLoc(I->getDebugLoc()); Result->setDebugLoc(I->getDebugLoc());
// Everything uses the new instruction now. // Everything uses the new instruction now.
I->replaceAllUsesWith(Result); I->replaceAllUsesWith(Result);

View File

@ -466,7 +466,8 @@ static bool functionHasLines(Function *F) {
if (isa<DbgInfoIntrinsic>(I)) continue; if (isa<DbgInfoIntrinsic>(I)) continue;
const DebugLoc &Loc = I->getDebugLoc(); const DebugLoc &Loc = I->getDebugLoc();
if (Loc.isUnknown()) continue; if (!Loc)
continue;
// Artificial lines such as calls to the global constructors. // Artificial lines such as calls to the global constructors.
if (Loc.getLine() == 0) continue; if (Loc.getLine() == 0) continue;
@ -536,14 +537,16 @@ void GCOVProfiler::emitProfileNotes() {
if (isa<DbgInfoIntrinsic>(I)) continue; if (isa<DbgInfoIntrinsic>(I)) continue;
const DebugLoc &Loc = I->getDebugLoc(); const DebugLoc &Loc = I->getDebugLoc();
if (Loc.isUnknown()) continue; if (!Loc)
continue;
// Artificial lines such as calls to the global constructors. // Artificial lines such as calls to the global constructors.
if (Loc.getLine() == 0) continue; if (Loc.getLine() == 0) continue;
if (Line == Loc.getLine()) continue; if (Line == Loc.getLine()) continue;
Line = Loc.getLine(); Line = Loc.getLine();
if (SP != getDISubprogram(Loc.getScope(*Ctx))) continue; if (SP != getDISubprogram(Loc.getScope()))
continue;
GCOVLines &Lines = Block.getFile(SP.getFilename()); GCOVLines &Lines = Block.getFile(SP.getFilename());
Lines.addLine(Loc.getLine()); Lines.addLine(Loc.getLine());

View File

@ -366,8 +366,8 @@ void SanitizerCoverageModule::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
} }
bool IsEntryBB = &BB == &F.getEntryBlock(); bool IsEntryBB = &BB == &F.getEntryBlock();
DebugLoc EntryLoc = IsEntryBB && !IP->getDebugLoc().isUnknown() DebugLoc EntryLoc = IsEntryBB && IP->getDebugLoc()
? IP->getDebugLoc().getFnDebugLoc(*C) ? IP->getDebugLoc().getFnDebugLoc()
: IP->getDebugLoc(); : IP->getDebugLoc();
IRBuilder<> IRB(IP); IRBuilder<> IRB(IP);
IRB.SetCurrentDebugLocation(EntryLoc); IRB.SetCurrentDebugLocation(EntryLoc);

View File

@ -217,14 +217,14 @@ void SampleProfileLoader::printBlockWeight(raw_ostream &OS, BasicBlock *BB) {
/// \returns The profiled weight of I. /// \returns The profiled weight of I.
unsigned SampleProfileLoader::getInstWeight(Instruction &Inst) { unsigned SampleProfileLoader::getInstWeight(Instruction &Inst) {
DebugLoc DLoc = Inst.getDebugLoc(); DebugLoc DLoc = Inst.getDebugLoc();
if (DLoc.isUnknown()) if (!DLoc)
return 0; return 0;
unsigned Lineno = DLoc.getLine(); unsigned Lineno = DLoc.getLine();
if (Lineno < HeaderLineno) if (Lineno < HeaderLineno)
return 0; return 0;
DILocation DIL(DLoc.getAsMDNode(*Ctx)); DILocation DIL = DLoc.get();
int LOffset = Lineno - HeaderLineno; int LOffset = Lineno - HeaderLineno;
unsigned Discriminator = DIL.getDiscriminator(); unsigned Discriminator = DIL.getDiscriminator();
unsigned Weight = Samples->samplesAt(LOffset, Discriminator); unsigned Weight = Samples->samplesAt(LOffset, Discriminator);

View File

@ -174,16 +174,16 @@ bool AddDiscriminators::runOnFunction(Function &F) {
for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) { for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
BasicBlock *B = I; BasicBlock *B = I;
TerminatorInst *Last = B->getTerminator(); TerminatorInst *Last = B->getTerminator();
DebugLoc LastLoc = Last->getDebugLoc(); DILocation LastDIL = Last->getDebugLoc().get();
if (LastLoc.isUnknown()) continue; if (!LastDIL)
DILocation LastDIL(LastLoc.getAsMDNode(Ctx)); continue;
for (unsigned I = 0; I < Last->getNumSuccessors(); ++I) { for (unsigned I = 0; I < Last->getNumSuccessors(); ++I) {
BasicBlock *Succ = Last->getSuccessor(I); BasicBlock *Succ = Last->getSuccessor(I);
Instruction *First = Succ->getFirstNonPHIOrDbgOrLifetime(); Instruction *First = Succ->getFirstNonPHIOrDbgOrLifetime();
DebugLoc FirstLoc = First->getDebugLoc(); DILocation FirstDIL = First->getDebugLoc().get();
if (FirstLoc.isUnknown()) continue; if (!FirstDIL)
DILocation FirstDIL(FirstLoc.getAsMDNode(Ctx)); continue;
// If the first instruction (First) of Succ is at the same file // If the first instruction (First) of Succ is at the same file
// location as B's last instruction (Last), add a new // location as B's last instruction (Last), add a new
@ -199,13 +199,14 @@ bool AddDiscriminators::runOnFunction(Function &F) {
DILexicalBlockFile NewScope = DILexicalBlockFile NewScope =
Builder.createLexicalBlockFile(Scope, File, Discriminator); Builder.createLexicalBlockFile(Scope, File, Discriminator);
DILocation NewDIL = FirstDIL.copyWithNewScope(Ctx, NewScope); DILocation NewDIL = FirstDIL.copyWithNewScope(Ctx, NewScope);
DebugLoc newDebugLoc = DebugLoc::getFromDILocation(NewDIL); DebugLoc newDebugLoc = NewDIL.get();
// Attach this new debug location to First and every // Attach this new debug location to First and every
// instruction following First that shares the same location. // instruction following First that shares the same location.
for (BasicBlock::iterator I1(*First), E1 = Succ->end(); I1 != E1; for (BasicBlock::iterator I1(*First), E1 = Succ->end(); I1 != E1;
++I1) { ++I1) {
if (I1->getDebugLoc() != FirstLoc) break; if (I1->getDebugLoc().get() != FirstDIL)
break;
I1->setDebugLoc(newDebugLoc); I1->setDebugLoc(newDebugLoc);
DEBUG(dbgs() << NewDIL.getFilename() << ":" << NewDIL.getLineNumber() DEBUG(dbgs() << NewDIL.getFilename() << ":" << NewDIL.getLineNumber()
<< ":" << NewDIL.getColumnNumber() << ":" << ":" << NewDIL.getColumnNumber() << ":"

View File

@ -835,11 +835,10 @@ updateInlinedAtInfo(DebugLoc DL, MDLocation *InlinedAtNode,
DenseMap<const MDLocation *, MDLocation *> &IANodes) { DenseMap<const MDLocation *, MDLocation *> &IANodes) {
SmallVector<MDLocation*, 3> InlinedAtLocations; SmallVector<MDLocation*, 3> InlinedAtLocations;
MDLocation *Last = InlinedAtNode; MDLocation *Last = InlinedAtNode;
DebugLoc CurInlinedAt = DL; MDLocation *CurInlinedAt = DL;
// Gather all the inlined-at nodes // Gather all the inlined-at nodes
while (MDLocation *IA = while (MDLocation *IA = CurInlinedAt->getInlinedAt()) {
cast_or_null<MDLocation>(CurInlinedAt.getInlinedAt(Ctx))) {
// Skip any we've already built nodes for // Skip any we've already built nodes for
if (MDLocation *Found = IANodes[IA]) { if (MDLocation *Found = IANodes[IA]) {
Last = Found; Last = Found;
@ -847,7 +846,7 @@ updateInlinedAtInfo(DebugLoc DL, MDLocation *InlinedAtNode,
} }
InlinedAtLocations.push_back(IA); InlinedAtLocations.push_back(IA);
CurInlinedAt = DebugLoc::getFromDILocation(IA); CurInlinedAt = IA;
} }
// Starting from the top, rebuild the nodes to point to the new inlined-at // Starting from the top, rebuild the nodes to point to the new inlined-at
@ -862,7 +861,7 @@ updateInlinedAtInfo(DebugLoc DL, MDLocation *InlinedAtNode,
// And finally create the normal location for this instruction, referring to // And finally create the normal location for this instruction, referring to
// the new inlined-at chain. // the new inlined-at chain.
return DebugLoc::get(DL.getLine(), DL.getCol(), DL.getScope(Ctx), Last); return DebugLoc::get(DL.getLine(), DL.getCol(), DL.getScope(), Last);
} }
/// Update inlined instructions' line numbers to /// Update inlined instructions' line numbers to
@ -870,11 +869,11 @@ updateInlinedAtInfo(DebugLoc DL, MDLocation *InlinedAtNode,
static void fixupLineNumbers(Function *Fn, Function::iterator FI, static void fixupLineNumbers(Function *Fn, Function::iterator FI,
Instruction *TheCall) { Instruction *TheCall) {
DebugLoc TheCallDL = TheCall->getDebugLoc(); DebugLoc TheCallDL = TheCall->getDebugLoc();
if (TheCallDL.isUnknown()) if (!TheCallDL)
return; return;
auto &Ctx = Fn->getContext(); auto &Ctx = Fn->getContext();
auto *InlinedAtNode = cast<MDLocation>(TheCallDL.getAsMDNode(Ctx)); MDLocation *InlinedAtNode = TheCallDL;
// Create a unique call site, not to be confused with any other call from the // Create a unique call site, not to be confused with any other call from the
// same location. // same location.
@ -891,7 +890,7 @@ static void fixupLineNumbers(Function *Fn, Function::iterator FI,
for (BasicBlock::iterator BI = FI->begin(), BE = FI->end(); for (BasicBlock::iterator BI = FI->begin(), BE = FI->end();
BI != BE; ++BI) { BI != BE; ++BI) {
DebugLoc DL = BI->getDebugLoc(); DebugLoc DL = BI->getDebugLoc();
if (DL.isUnknown()) { if (!DL) {
// If the inlined instruction has no line number, make it look as if it // If the inlined instruction has no line number, make it look as if it
// originates from the call location. This is important for // originates from the call location. This is important for
// ((__always_inline__, __nodebug__)) functions which must use caller // ((__always_inline__, __nodebug__)) functions which must use caller
@ -907,13 +906,13 @@ static void fixupLineNumbers(Function *Fn, Function::iterator FI,
BI->setDebugLoc(updateInlinedAtInfo(DL, InlinedAtNode, BI->getContext(), IANodes)); BI->setDebugLoc(updateInlinedAtInfo(DL, InlinedAtNode, BI->getContext(), IANodes));
if (DbgValueInst *DVI = dyn_cast<DbgValueInst>(BI)) { if (DbgValueInst *DVI = dyn_cast<DbgValueInst>(BI)) {
LLVMContext &Ctx = BI->getContext(); LLVMContext &Ctx = BI->getContext();
MDNode *InlinedAt = BI->getDebugLoc().getInlinedAt(Ctx); MDNode *InlinedAt = BI->getDebugLoc().getInlinedAt();
DVI->setOperand(2, MetadataAsValue::get( DVI->setOperand(2, MetadataAsValue::get(
Ctx, createInlinedVariable(DVI->getVariable(), Ctx, createInlinedVariable(DVI->getVariable(),
InlinedAt, Ctx))); InlinedAt, Ctx)));
} else if (DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(BI)) { } else if (DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(BI)) {
LLVMContext &Ctx = BI->getContext(); LLVMContext &Ctx = BI->getContext();
MDNode *InlinedAt = BI->getDebugLoc().getInlinedAt(Ctx); MDNode *InlinedAt = BI->getDebugLoc().getInlinedAt();
DDI->setOperand(1, MetadataAsValue::get( DDI->setOperand(1, MetadataAsValue::get(
Ctx, createInlinedVariable(DDI->getVariable(), Ctx, createInlinedVariable(DDI->getVariable(),
InlinedAt, Ctx))); InlinedAt, Ctx)));

View File

@ -504,8 +504,7 @@ static std::string getDebugLocString(const Loop *L) {
std::string Result; std::string Result;
if (L) { if (L) {
raw_string_ostream OS(Result); raw_string_ostream OS(Result);
const DebugLoc LoopDbgLoc = L->getStartLoc(); if (const DebugLoc LoopDbgLoc = L->getStartLoc())
if (!LoopDbgLoc.isUnknown())
LoopDbgLoc.print(OS); LoopDbgLoc.print(OS);
else else
// Just print the module name. // Just print the module name.