Skip to content

Commit 644a9a4

Browse files
authored
[CodeExtractor][NFC] Refactor-out applyFirstDebugLoc. (#115358)
Split-off from #114419
1 parent 107af4a commit 644a9a4

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

llvm/lib/Transforms/Utils/CodeExtractor.cpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,29 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs,
10801080
return newFunction;
10811081
}
10821082

1083+
/// If the original function has debug info, we have to add a debug location
1084+
/// to the new branch instruction from the artificial entry block.
1085+
/// We use the debug location of the first instruction in the extracted
1086+
/// blocks, as there is no other equivalent line in the source code.
1087+
static void applyFirstDebugLoc(Function *oldFunction,
1088+
ArrayRef<BasicBlock *> Blocks,
1089+
Instruction *BranchI) {
1090+
if (oldFunction->getSubprogram()) {
1091+
any_of(Blocks, [&BranchI](const BasicBlock *BB) {
1092+
return any_of(*BB, [&BranchI](const Instruction &I) {
1093+
if (!I.getDebugLoc())
1094+
return false;
1095+
// Don't use source locations attached to debug-intrinsics: they could
1096+
// be from completely unrelated scopes.
1097+
if (isa<DbgInfoIntrinsic>(I))
1098+
return false;
1099+
BranchI->setDebugLoc(I.getDebugLoc());
1100+
return true;
1101+
});
1102+
});
1103+
}
1104+
}
1105+
10831106
/// Erase lifetime.start markers which reference inputs to the extraction
10841107
/// region, and insert the referenced memory into \p LifetimesStart.
10851108
///
@@ -1792,24 +1815,7 @@ CodeExtractor::extractCodeRegion(const CodeExtractorAnalysisCache &CEAC,
17921815
newFuncRoot->IsNewDbgInfoFormat = oldFunction->IsNewDbgInfoFormat;
17931816

17941817
auto *BranchI = BranchInst::Create(header);
1795-
// If the original function has debug info, we have to add a debug location
1796-
// to the new branch instruction from the artificial entry block.
1797-
// We use the debug location of the first instruction in the extracted
1798-
// blocks, as there is no other equivalent line in the source code.
1799-
if (oldFunction->getSubprogram()) {
1800-
any_of(Blocks, [&BranchI](const BasicBlock *BB) {
1801-
return any_of(*BB, [&BranchI](const Instruction &I) {
1802-
if (!I.getDebugLoc())
1803-
return false;
1804-
// Don't use source locations attached to debug-intrinsics: they could
1805-
// be from completely unrelated scopes.
1806-
if (isa<DbgInfoIntrinsic>(I))
1807-
return false;
1808-
BranchI->setDebugLoc(I.getDebugLoc());
1809-
return true;
1810-
});
1811-
});
1812-
}
1818+
applyFirstDebugLoc(oldFunction, Blocks.getArrayRef(), BranchI);
18131819
BranchI->insertInto(newFuncRoot, newFuncRoot->end());
18141820

18151821
ValueSet SinkingCands, HoistingCands;

0 commit comments

Comments
 (0)