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)
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 = nullptr;
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
// debug behaviour set the line to 0.
if (const DebugLoc &DL = Inst.getDebugLoc())
EntryBuilder->setDebugLoc(
DebugLoc::get(0, 0, DL.getScope(), DL.getInlinedAt()));
EntryBuilder->setDebugLoc(DILocation::get(
Inst.getContext(), 0, 0, DL.getScope(), DL.getInlinedAt()));
else
EntryBuilder->setDebugLoc(DebugLoc());

View File

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

View File

@ -789,7 +789,8 @@ bool SafeStack::run() {
// Calls must always have a debug location, or else inlining breaks. So
// we explicitly set a artificial debug location here.
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) {
FunctionCallee Fn = F.getParent()->getOrInsertFunction(
"__safestack_pointer_address", StackPtrTy->getPointerTo(0));

View File

@ -652,7 +652,8 @@ bool llvm::stripNonLineTableDebugInfo(Module &M) {
MDNode *InlinedAt = DL.getInlinedAt();
Scope = remap(Scope);
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())
@ -712,12 +713,12 @@ void Instruction::dropLocation() {
// Set a line 0 location for calls to preserve scope information in case
// inlining occurs.
const DISubprogram *SP = getFunction()->getSubprogram();
DISubprogram *SP = getFunction()->getSubprogram();
if (SP)
// 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
// 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
// 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

View File

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

View File

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

View File

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

View File

@ -3105,7 +3105,8 @@ void FunctionStackPoisoner::processStaticAllocas() {
int StackMallocIdx = -1;
DebugLoc EntryDebugLocation;
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];
IRBuilder<> IRB(InsBefore);

View File

@ -883,7 +883,7 @@ void ModuleSanitizerCoverage::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
DebugLoc EntryLoc;
if (IsEntryBB) {
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
// if we aren't splitting the block, it's nice for allocas to be before
// calls.

View File

@ -1547,7 +1547,7 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc,
// function.
for (Instruction &I : instructions(NewFunc)) {
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.
auto updateLoopInfoLoc = [&Ctx,
@ -1558,7 +1558,7 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc,
updateLoopMetadataDebugLocations(I, updateLoopInfoLoc);
}
if (!TheCall.getDebugLoc())
TheCall.setDebugLoc(DebugLoc::get(0, 0, OldSP));
TheCall.setDebugLoc(DILocation::get(Ctx, 0, 0, OldSP));
eraseDebugIntrinsicsWithNonLocalRefs(NewFunc);
}

View File

@ -83,7 +83,7 @@ static bool runOnFunction(Function &F, bool PostInlining) {
if (!EntryFunc.empty()) {
DebugLoc DL;
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);
Changed = true;
@ -104,7 +104,7 @@ static bool runOnFunction(Function &F, bool PostInlining) {
if (DebugLoc TerminatorDL = T->getDebugLoc())
DL = TerminatorDL;
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);
Changed = true;

View File

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

View File

@ -1392,7 +1392,7 @@ static DebugLoc getDebugValueLoc(DbgVariableIntrinsic *DII, Instruction *Src) {
MDNode *Scope = DeclareLoc.getScope();
DILocation *InlinedAt = DeclareLoc.getInlinedAt();
// 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