Migrate deprecated DebugLoc::get to DILocation::get

This migrates all LLVM (except Kaleidoscope and
CodeGen/StackProtector.cpp) DebugLoc::get to DILocation::get.

The CodeGen/StackProtector.cpp usage may have a nullptr Scope
and can trigger an assertion failure, so I don't migrate it.

Reviewed By: #debug-info, dblaikie

Differential Revision: https://reviews.llvm.org/D93087
This commit is contained in:
Fangrui Song 2020-12-11 12:45:22 -08:00
parent 7ea37d2f94
commit b5ad32ef5c
14 changed files with 32 additions and 24 deletions

View File

@ -3959,7 +3959,8 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
if (!IA) if (!IA)
return error("Invalid record"); return error("Invalid record");
} }
LastLoc = DebugLoc::get(Line, Col, Scope, IA, isImplicitCode); LastLoc = DILocation::get(Scope->getContext(), Line, Col, Scope, IA,
isImplicitCode);
I->setDebugLoc(LastLoc); I->setDebugLoc(LastLoc);
I = nullptr; I = nullptr;
continue; continue;

View File

@ -2773,8 +2773,8 @@ bool IRTranslator::translate(const Instruction &Inst) {
// We only emit constants into the entry block from here. To prevent jumpy // We only emit constants into the entry block from here. To prevent jumpy
// debug behaviour set the line to 0. // debug behaviour set the line to 0.
if (const DebugLoc &DL = Inst.getDebugLoc()) if (const DebugLoc &DL = Inst.getDebugLoc())
EntryBuilder->setDebugLoc( EntryBuilder->setDebugLoc(DILocation::get(
DebugLoc::get(0, 0, DL.getScope(), DL.getInlinedAt())); Inst.getContext(), 0, 0, DL.getScope(), DL.getInlinedAt()));
else else
EntryBuilder->setDebugLoc(DebugLoc()); EntryBuilder->setDebugLoc(DebugLoc());

View File

@ -756,8 +756,9 @@ public:
/// just return the builder for it. /// just return the builder for it.
MachineInstrBuilder emitLoc(Optional<LocIdx> MLoc, const DebugVariable &Var, MachineInstrBuilder emitLoc(Optional<LocIdx> MLoc, const DebugVariable &Var,
const DbgValueProperties &Properties) { const DbgValueProperties &Properties) {
DebugLoc DL = DebugLoc DL = DILocation::get(Var.getVariable()->getContext(), 0, 0,
DebugLoc::get(0, 0, Var.getVariable()->getScope(), Var.getInlinedAt()); Var.getVariable()->getScope(),
const_cast<DILocation *>(Var.getInlinedAt()));
auto MIB = BuildMI(MF, DL, TII.get(TargetOpcode::DBG_VALUE)); auto MIB = BuildMI(MF, DL, TII.get(TargetOpcode::DBG_VALUE));
const DIExpression *Expr = Properties.DIExpr; const DIExpression *Expr = Properties.DIExpr;
@ -1280,8 +1281,9 @@ public:
MachineInstrBuilder emitMOLoc(const MachineOperand &MO, MachineInstrBuilder emitMOLoc(const MachineOperand &MO,
const DebugVariable &Var, const DebugVariable &Var,
const DbgValueProperties &Properties) { const DbgValueProperties &Properties) {
DebugLoc DL = DebugLoc DL = DILocation::get(Var.getVariable()->getContext(), 0, 0,
DebugLoc::get(0, 0, Var.getVariable()->getScope(), Var.getInlinedAt()); Var.getVariable()->getScope(),
const_cast<DILocation *>(Var.getInlinedAt()));
auto MIB = BuildMI(MF, DL, TII->get(TargetOpcode::DBG_VALUE)); auto MIB = BuildMI(MF, DL, TII->get(TargetOpcode::DBG_VALUE));
MIB.add(MO); MIB.add(MO);
if (Properties.Indirect) if (Properties.Indirect)

View File

@ -789,7 +789,8 @@ bool SafeStack::run() {
// Calls must always have a debug location, or else inlining breaks. So // Calls must always have a debug location, or else inlining breaks. So
// we explicitly set a artificial debug location here. // we explicitly set a artificial debug location here.
if (DISubprogram *SP = F.getSubprogram()) if (DISubprogram *SP = F.getSubprogram())
IRB.SetCurrentDebugLocation(DebugLoc::get(SP->getScopeLine(), 0, SP)); IRB.SetCurrentDebugLocation(
DILocation::get(SP->getContext(), SP->getScopeLine(), 0, SP));
if (SafeStackUsePointerAddress) { if (SafeStackUsePointerAddress) {
FunctionCallee Fn = F.getParent()->getOrInsertFunction( FunctionCallee Fn = F.getParent()->getOrInsertFunction(
"__safestack_pointer_address", StackPtrTy->getPointerTo(0)); "__safestack_pointer_address", StackPtrTy->getPointerTo(0));

View File

@ -652,7 +652,8 @@ bool llvm::stripNonLineTableDebugInfo(Module &M) {
MDNode *InlinedAt = DL.getInlinedAt(); MDNode *InlinedAt = DL.getInlinedAt();
Scope = remap(Scope); Scope = remap(Scope);
InlinedAt = remap(InlinedAt); InlinedAt = remap(InlinedAt);
return DebugLoc::get(DL.getLine(), DL.getCol(), Scope, InlinedAt); return DILocation::get(M.getContext(), DL.getLine(), DL.getCol(),
Scope, InlinedAt);
}; };
if (I.getDebugLoc() != DebugLoc()) if (I.getDebugLoc() != DebugLoc())
@ -712,12 +713,12 @@ void Instruction::dropLocation() {
// Set a line 0 location for calls to preserve scope information in case // Set a line 0 location for calls to preserve scope information in case
// inlining occurs. // inlining occurs.
const DISubprogram *SP = getFunction()->getSubprogram(); DISubprogram *SP = getFunction()->getSubprogram();
if (SP) if (SP)
// If a function scope is available, set it on the line 0 location. When // If a function scope is available, set it on the line 0 location. When
// hoisting a call to a predecessor block, using the function scope avoids // hoisting a call to a predecessor block, using the function scope avoids
// making it look like the callee was reached earlier than it should be. // making it look like the callee was reached earlier than it should be.
setDebugLoc(DebugLoc::get(0, 0, SP)); setDebugLoc(DILocation::get(getContext(), 0, 0, SP));
else else
// The parent function has no scope. Go ahead and drop the location. If // The parent function has no scope. Go ahead and drop the location. If
// the parent function is inlined, and the callee has a subprogram, the // the parent function is inlined, and the callee has a subprogram, the

View File

@ -50,7 +50,7 @@ DebugLoc DebugLoc::getFnDebugLoc() const {
// FIXME: Add a method on \a DILocation that does this work. // FIXME: Add a method on \a DILocation that does this work.
const MDNode *Scope = getInlinedAtScope(); const MDNode *Scope = getInlinedAtScope();
if (auto *SP = getDISubprogram(Scope)) if (auto *SP = getDISubprogram(Scope))
return DebugLoc::get(SP->getScopeLine(), 0, SP); return DILocation::get(SP->getContext(), SP->getScopeLine(), 0, SP);
return DebugLoc(); return DebugLoc();
} }

View File

@ -725,8 +725,10 @@ void MergeFunctions::writeThunk(Function *F, Function *G) {
if (MergeFunctionsPDI) { if (MergeFunctionsPDI) {
DISubprogram *DIS = G->getSubprogram(); DISubprogram *DIS = G->getSubprogram();
if (DIS) { if (DIS) {
DebugLoc CIDbgLoc = DebugLoc::get(DIS->getScopeLine(), 0, DIS); DebugLoc CIDbgLoc =
DebugLoc RIDbgLoc = DebugLoc::get(DIS->getScopeLine(), 0, DIS); DILocation::get(DIS->getContext(), DIS->getScopeLine(), 0, DIS);
DebugLoc RIDbgLoc =
DILocation::get(DIS->getContext(), DIS->getScopeLine(), 0, DIS);
CI->setDebugLoc(CIDbgLoc); CI->setDebugLoc(CIDbgLoc);
RI->setDebugLoc(RIDbgLoc); RI->setDebugLoc(RIDbgLoc);
} else { } else {

View File

@ -122,7 +122,7 @@ void SampleProfileProber::instrumentOneFunc(Function &F, TargetMachine *TM) {
"Expecting pseudo probe or call instructions"); "Expecting pseudo probe or call instructions");
if (!I->getDebugLoc()) { if (!I->getDebugLoc()) {
if (auto *SP = F.getSubprogram()) { if (auto *SP = F.getSubprogram()) {
auto DIL = DebugLoc::get(0, 0, SP); auto DIL = DILocation::get(SP->getContext(), 0, 0, SP);
I->setDebugLoc(DIL); I->setDebugLoc(DIL);
ArtificialDbgLine++; ArtificialDbgLine++;
LLVM_DEBUG({ LLVM_DEBUG({

View File

@ -3105,7 +3105,8 @@ void FunctionStackPoisoner::processStaticAllocas() {
int StackMallocIdx = -1; int StackMallocIdx = -1;
DebugLoc EntryDebugLocation; DebugLoc EntryDebugLocation;
if (auto SP = F.getSubprogram()) if (auto SP = F.getSubprogram())
EntryDebugLocation = DebugLoc::get(SP->getScopeLine(), 0, SP); EntryDebugLocation =
DILocation::get(SP->getContext(), SP->getScopeLine(), 0, SP);
Instruction *InsBefore = AllocaVec[0]; Instruction *InsBefore = AllocaVec[0];
IRBuilder<> IRB(InsBefore); IRBuilder<> IRB(InsBefore);

View File

@ -883,7 +883,7 @@ void ModuleSanitizerCoverage::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
DebugLoc EntryLoc; DebugLoc EntryLoc;
if (IsEntryBB) { if (IsEntryBB) {
if (auto SP = F.getSubprogram()) if (auto SP = F.getSubprogram())
EntryLoc = DebugLoc::get(SP->getScopeLine(), 0, SP); EntryLoc = DILocation::get(SP->getContext(), SP->getScopeLine(), 0, SP);
// Keep static allocas and llvm.localescape calls in the entry block. Even // Keep static allocas and llvm.localescape calls in the entry block. Even
// if we aren't splitting the block, it's nice for allocas to be before // if we aren't splitting the block, it's nice for allocas to be before
// calls. // calls.

View File

@ -1547,7 +1547,7 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc,
// function. // function.
for (Instruction &I : instructions(NewFunc)) { for (Instruction &I : instructions(NewFunc)) {
if (const DebugLoc &DL = I.getDebugLoc()) if (const DebugLoc &DL = I.getDebugLoc())
I.setDebugLoc(DebugLoc::get(DL.getLine(), DL.getCol(), NewSP)); I.setDebugLoc(DILocation::get(Ctx, DL.getLine(), DL.getCol(), NewSP));
// Loop info metadata may contain line locations. Fix them up. // Loop info metadata may contain line locations. Fix them up.
auto updateLoopInfoLoc = [&Ctx, auto updateLoopInfoLoc = [&Ctx,
@ -1558,7 +1558,7 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc,
updateLoopMetadataDebugLocations(I, updateLoopInfoLoc); updateLoopMetadataDebugLocations(I, updateLoopInfoLoc);
} }
if (!TheCall.getDebugLoc()) if (!TheCall.getDebugLoc())
TheCall.setDebugLoc(DebugLoc::get(0, 0, OldSP)); TheCall.setDebugLoc(DILocation::get(Ctx, 0, 0, OldSP));
eraseDebugIntrinsicsWithNonLocalRefs(NewFunc); eraseDebugIntrinsicsWithNonLocalRefs(NewFunc);
} }

View File

@ -83,7 +83,7 @@ static bool runOnFunction(Function &F, bool PostInlining) {
if (!EntryFunc.empty()) { if (!EntryFunc.empty()) {
DebugLoc DL; DebugLoc DL;
if (auto SP = F.getSubprogram()) if (auto SP = F.getSubprogram())
DL = DebugLoc::get(SP->getScopeLine(), 0, SP); DL = DILocation::get(SP->getContext(), SP->getScopeLine(), 0, SP);
insertCall(F, EntryFunc, &*F.begin()->getFirstInsertionPt(), DL); insertCall(F, EntryFunc, &*F.begin()->getFirstInsertionPt(), DL);
Changed = true; Changed = true;
@ -104,7 +104,7 @@ static bool runOnFunction(Function &F, bool PostInlining) {
if (DebugLoc TerminatorDL = T->getDebugLoc()) if (DebugLoc TerminatorDL = T->getDebugLoc())
DL = TerminatorDL; DL = TerminatorDL;
else if (auto SP = F.getSubprogram()) else if (auto SP = F.getSubprogram())
DL = DebugLoc::get(0, 0, SP); DL = DILocation::get(SP->getContext(), 0, 0, SP);
insertCall(F, ExitFunc, T, DL); insertCall(F, ExitFunc, T, DL);
Changed = true; Changed = true;

View File

@ -1443,8 +1443,8 @@ static DebugLoc inlineDebugLoc(DebugLoc OrigDL, DILocation *InlinedAt,
LLVMContext &Ctx, LLVMContext &Ctx,
DenseMap<const MDNode *, MDNode *> &IANodes) { DenseMap<const MDNode *, MDNode *> &IANodes) {
auto IA = DebugLoc::appendInlinedAt(OrigDL, InlinedAt, Ctx, IANodes); auto IA = DebugLoc::appendInlinedAt(OrigDL, InlinedAt, Ctx, IANodes);
return DebugLoc::get(OrigDL.getLine(), OrigDL.getCol(), OrigDL.getScope(), return DILocation::get(Ctx, OrigDL.getLine(), OrigDL.getCol(),
IA); OrigDL.getScope(), IA);
} }
/// Update inlined instructions' line numbers to /// Update inlined instructions' line numbers to

View File

@ -1392,7 +1392,7 @@ static DebugLoc getDebugValueLoc(DbgVariableIntrinsic *DII, Instruction *Src) {
MDNode *Scope = DeclareLoc.getScope(); MDNode *Scope = DeclareLoc.getScope();
DILocation *InlinedAt = DeclareLoc.getInlinedAt(); DILocation *InlinedAt = DeclareLoc.getInlinedAt();
// Produce an unknown location with the correct scope / inlinedAt fields. // Produce an unknown location with the correct scope / inlinedAt fields.
return DebugLoc::get(0, 0, Scope, InlinedAt); return DILocation::get(DII->getContext(), 0, 0, Scope, InlinedAt);
} }
/// Inserts a llvm.dbg.value intrinsic before a store to an alloca'd value /// Inserts a llvm.dbg.value intrinsic before a store to an alloca'd value