@@ -1080,6 +1080,29 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs,
1080
1080
return newFunction;
1081
1081
}
1082
1082
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
+
1083
1106
// / Erase lifetime.start markers which reference inputs to the extraction
1084
1107
// / region, and insert the referenced memory into \p LifetimesStart.
1085
1108
// /
@@ -1792,24 +1815,7 @@ CodeExtractor::extractCodeRegion(const CodeExtractorAnalysisCache &CEAC,
1792
1815
newFuncRoot->IsNewDbgInfoFormat = oldFunction->IsNewDbgInfoFormat ;
1793
1816
1794
1817
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);
1813
1819
BranchI->insertInto (newFuncRoot, newFuncRoot->end ());
1814
1820
1815
1821
ValueSet SinkingCands, HoistingCands;
0 commit comments