forked from OSchip/llvm-project
Transforms: Use the new DebugLoc API, NFC
Update lib/Analysis and lib/Transforms to use the new `DebugLoc` API. llvm-svn: 233587
This commit is contained in:
parent
e50adcb6b1
commit
ec819c096b
|
@ -464,23 +464,20 @@ public:
|
|||
/// cannot find a terminating instruction with location information,
|
||||
/// it returns an unknown location.
|
||||
DebugLoc getStartLoc() const {
|
||||
DebugLoc StartLoc;
|
||||
BasicBlock *HeadBB;
|
||||
|
||||
// Try the pre-header first.
|
||||
if ((HeadBB = getLoopPreheader()) != nullptr) {
|
||||
StartLoc = HeadBB->getTerminator()->getDebugLoc();
|
||||
if (!StartLoc.isUnknown())
|
||||
return StartLoc;
|
||||
}
|
||||
if ((HeadBB = getLoopPreheader()) != nullptr)
|
||||
if (DebugLoc DL = HeadBB->getTerminator()->getDebugLoc())
|
||||
return DL;
|
||||
|
||||
// If we have no pre-header or there are no instructions with debug
|
||||
// info in it, try the header.
|
||||
HeadBB = getHeader();
|
||||
if (HeadBB)
|
||||
StartLoc = HeadBB->getTerminator()->getDebugLoc();
|
||||
return HeadBB->getTerminator()->getDebugLoc();
|
||||
|
||||
return StartLoc;
|
||||
return DebugLoc();
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -2723,7 +2723,7 @@ bool InstCombiner::run() {
|
|||
DEBUG(dbgs() << "IC: Old = " << *I << '\n'
|
||||
<< " New = " << *Result << '\n');
|
||||
|
||||
if (!I->getDebugLoc().isUnknown())
|
||||
if (I->getDebugLoc())
|
||||
Result->setDebugLoc(I->getDebugLoc());
|
||||
// Everything uses the new instruction now.
|
||||
I->replaceAllUsesWith(Result);
|
||||
|
|
|
@ -466,7 +466,8 @@ static bool functionHasLines(Function *F) {
|
|||
if (isa<DbgInfoIntrinsic>(I)) continue;
|
||||
|
||||
const DebugLoc &Loc = I->getDebugLoc();
|
||||
if (Loc.isUnknown()) continue;
|
||||
if (!Loc)
|
||||
continue;
|
||||
|
||||
// Artificial lines such as calls to the global constructors.
|
||||
if (Loc.getLine() == 0) continue;
|
||||
|
@ -536,14 +537,16 @@ void GCOVProfiler::emitProfileNotes() {
|
|||
if (isa<DbgInfoIntrinsic>(I)) continue;
|
||||
|
||||
const DebugLoc &Loc = I->getDebugLoc();
|
||||
if (Loc.isUnknown()) continue;
|
||||
if (!Loc)
|
||||
continue;
|
||||
|
||||
// Artificial lines such as calls to the global constructors.
|
||||
if (Loc.getLine() == 0) continue;
|
||||
|
||||
if (Line == Loc.getLine()) continue;
|
||||
Line = Loc.getLine();
|
||||
if (SP != getDISubprogram(Loc.getScope(*Ctx))) continue;
|
||||
if (SP != getDISubprogram(Loc.getScope()))
|
||||
continue;
|
||||
|
||||
GCOVLines &Lines = Block.getFile(SP.getFilename());
|
||||
Lines.addLine(Loc.getLine());
|
||||
|
|
|
@ -366,8 +366,8 @@ void SanitizerCoverageModule::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
|
|||
}
|
||||
|
||||
bool IsEntryBB = &BB == &F.getEntryBlock();
|
||||
DebugLoc EntryLoc = IsEntryBB && !IP->getDebugLoc().isUnknown()
|
||||
? IP->getDebugLoc().getFnDebugLoc(*C)
|
||||
DebugLoc EntryLoc = IsEntryBB && IP->getDebugLoc()
|
||||
? IP->getDebugLoc().getFnDebugLoc()
|
||||
: IP->getDebugLoc();
|
||||
IRBuilder<> IRB(IP);
|
||||
IRB.SetCurrentDebugLocation(EntryLoc);
|
||||
|
|
|
@ -217,14 +217,14 @@ void SampleProfileLoader::printBlockWeight(raw_ostream &OS, BasicBlock *BB) {
|
|||
/// \returns The profiled weight of I.
|
||||
unsigned SampleProfileLoader::getInstWeight(Instruction &Inst) {
|
||||
DebugLoc DLoc = Inst.getDebugLoc();
|
||||
if (DLoc.isUnknown())
|
||||
if (!DLoc)
|
||||
return 0;
|
||||
|
||||
unsigned Lineno = DLoc.getLine();
|
||||
if (Lineno < HeaderLineno)
|
||||
return 0;
|
||||
|
||||
DILocation DIL(DLoc.getAsMDNode(*Ctx));
|
||||
DILocation DIL = DLoc.get();
|
||||
int LOffset = Lineno - HeaderLineno;
|
||||
unsigned Discriminator = DIL.getDiscriminator();
|
||||
unsigned Weight = Samples->samplesAt(LOffset, Discriminator);
|
||||
|
|
|
@ -174,16 +174,16 @@ bool AddDiscriminators::runOnFunction(Function &F) {
|
|||
for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
|
||||
BasicBlock *B = I;
|
||||
TerminatorInst *Last = B->getTerminator();
|
||||
DebugLoc LastLoc = Last->getDebugLoc();
|
||||
if (LastLoc.isUnknown()) continue;
|
||||
DILocation LastDIL(LastLoc.getAsMDNode(Ctx));
|
||||
DILocation LastDIL = Last->getDebugLoc().get();
|
||||
if (!LastDIL)
|
||||
continue;
|
||||
|
||||
for (unsigned I = 0; I < Last->getNumSuccessors(); ++I) {
|
||||
BasicBlock *Succ = Last->getSuccessor(I);
|
||||
Instruction *First = Succ->getFirstNonPHIOrDbgOrLifetime();
|
||||
DebugLoc FirstLoc = First->getDebugLoc();
|
||||
if (FirstLoc.isUnknown()) continue;
|
||||
DILocation FirstDIL(FirstLoc.getAsMDNode(Ctx));
|
||||
DILocation FirstDIL = First->getDebugLoc().get();
|
||||
if (!FirstDIL)
|
||||
continue;
|
||||
|
||||
// If the first instruction (First) of Succ is at the same file
|
||||
// location as B's last instruction (Last), add a new
|
||||
|
@ -199,13 +199,14 @@ bool AddDiscriminators::runOnFunction(Function &F) {
|
|||
DILexicalBlockFile NewScope =
|
||||
Builder.createLexicalBlockFile(Scope, File, Discriminator);
|
||||
DILocation NewDIL = FirstDIL.copyWithNewScope(Ctx, NewScope);
|
||||
DebugLoc newDebugLoc = DebugLoc::getFromDILocation(NewDIL);
|
||||
DebugLoc newDebugLoc = NewDIL.get();
|
||||
|
||||
// Attach this new debug location to First and every
|
||||
// instruction following First that shares the same location.
|
||||
for (BasicBlock::iterator I1(*First), E1 = Succ->end(); I1 != E1;
|
||||
++I1) {
|
||||
if (I1->getDebugLoc() != FirstLoc) break;
|
||||
if (I1->getDebugLoc().get() != FirstDIL)
|
||||
break;
|
||||
I1->setDebugLoc(newDebugLoc);
|
||||
DEBUG(dbgs() << NewDIL.getFilename() << ":" << NewDIL.getLineNumber()
|
||||
<< ":" << NewDIL.getColumnNumber() << ":"
|
||||
|
|
|
@ -835,11 +835,10 @@ updateInlinedAtInfo(DebugLoc DL, MDLocation *InlinedAtNode,
|
|||
DenseMap<const MDLocation *, MDLocation *> &IANodes) {
|
||||
SmallVector<MDLocation*, 3> InlinedAtLocations;
|
||||
MDLocation *Last = InlinedAtNode;
|
||||
DebugLoc CurInlinedAt = DL;
|
||||
MDLocation *CurInlinedAt = DL;
|
||||
|
||||
// Gather all the inlined-at nodes
|
||||
while (MDLocation *IA =
|
||||
cast_or_null<MDLocation>(CurInlinedAt.getInlinedAt(Ctx))) {
|
||||
while (MDLocation *IA = CurInlinedAt->getInlinedAt()) {
|
||||
// Skip any we've already built nodes for
|
||||
if (MDLocation *Found = IANodes[IA]) {
|
||||
Last = Found;
|
||||
|
@ -847,7 +846,7 @@ updateInlinedAtInfo(DebugLoc DL, MDLocation *InlinedAtNode,
|
|||
}
|
||||
|
||||
InlinedAtLocations.push_back(IA);
|
||||
CurInlinedAt = DebugLoc::getFromDILocation(IA);
|
||||
CurInlinedAt = IA;
|
||||
}
|
||||
|
||||
// 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
|
||||
// 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
|
||||
|
@ -870,11 +869,11 @@ updateInlinedAtInfo(DebugLoc DL, MDLocation *InlinedAtNode,
|
|||
static void fixupLineNumbers(Function *Fn, Function::iterator FI,
|
||||
Instruction *TheCall) {
|
||||
DebugLoc TheCallDL = TheCall->getDebugLoc();
|
||||
if (TheCallDL.isUnknown())
|
||||
if (!TheCallDL)
|
||||
return;
|
||||
|
||||
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
|
||||
// same location.
|
||||
|
@ -891,7 +890,7 @@ static void fixupLineNumbers(Function *Fn, Function::iterator FI,
|
|||
for (BasicBlock::iterator BI = FI->begin(), BE = FI->end();
|
||||
BI != BE; ++BI) {
|
||||
DebugLoc DL = BI->getDebugLoc();
|
||||
if (DL.isUnknown()) {
|
||||
if (!DL) {
|
||||
// If the inlined instruction has no line number, make it look as if it
|
||||
// originates from the call location. This is important for
|
||||
// ((__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));
|
||||
if (DbgValueInst *DVI = dyn_cast<DbgValueInst>(BI)) {
|
||||
LLVMContext &Ctx = BI->getContext();
|
||||
MDNode *InlinedAt = BI->getDebugLoc().getInlinedAt(Ctx);
|
||||
MDNode *InlinedAt = BI->getDebugLoc().getInlinedAt();
|
||||
DVI->setOperand(2, MetadataAsValue::get(
|
||||
Ctx, createInlinedVariable(DVI->getVariable(),
|
||||
InlinedAt, Ctx)));
|
||||
} else if (DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(BI)) {
|
||||
LLVMContext &Ctx = BI->getContext();
|
||||
MDNode *InlinedAt = BI->getDebugLoc().getInlinedAt(Ctx);
|
||||
MDNode *InlinedAt = BI->getDebugLoc().getInlinedAt();
|
||||
DDI->setOperand(1, MetadataAsValue::get(
|
||||
Ctx, createInlinedVariable(DDI->getVariable(),
|
||||
InlinedAt, Ctx)));
|
||||
|
|
|
@ -504,8 +504,7 @@ static std::string getDebugLocString(const Loop *L) {
|
|||
std::string Result;
|
||||
if (L) {
|
||||
raw_string_ostream OS(Result);
|
||||
const DebugLoc LoopDbgLoc = L->getStartLoc();
|
||||
if (!LoopDbgLoc.isUnknown())
|
||||
if (const DebugLoc LoopDbgLoc = L->getStartLoc())
|
||||
LoopDbgLoc.print(OS);
|
||||
else
|
||||
// Just print the module name.
|
||||
|
|
Loading…
Reference in New Issue