@@ -768,6 +768,7 @@ void CodeExtractor::severSplitPHINodesOfExits(
768
768
NewBB = BasicBlock::Create (ExitBB->getContext (),
769
769
ExitBB->getName () + " .split" ,
770
770
ExitBB->getParent (), ExitBB);
771
+ NewBB->IsNewDbgInfoFormat = ExitBB->IsNewDbgInfoFormat ;
771
772
SmallVector<BasicBlock *, 4 > Preds (predecessors (ExitBB));
772
773
for (BasicBlock *PredBB : Preds)
773
774
if (Blocks.count (PredBB))
@@ -889,6 +890,7 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs,
889
890
Function *newFunction = Function::Create (
890
891
funcType, GlobalValue::InternalLinkage, oldFunction->getAddressSpace (),
891
892
oldFunction->getName () + " ." + SuffixToUse, M);
893
+ newFunction->IsNewDbgInfoFormat = oldFunction->IsNewDbgInfoFormat ;
892
894
893
895
// Inherit all of the target dependent attributes and white-listed
894
896
// target independent attributes.
@@ -1505,10 +1507,14 @@ void CodeExtractor::calculateNewCallTerminatorWeights(
1505
1507
static void eraseDebugIntrinsicsWithNonLocalRefs (Function &F) {
1506
1508
for (Instruction &I : instructions (F)) {
1507
1509
SmallVector<DbgVariableIntrinsic *, 4 > DbgUsers;
1508
- findDbgUsers (DbgUsers, &I);
1510
+ SmallVector<DPValue *, 4 > DPValues;
1511
+ findDbgUsers (DbgUsers, &I, &DPValues);
1509
1512
for (DbgVariableIntrinsic *DVI : DbgUsers)
1510
1513
if (DVI->getFunction () != &F)
1511
1514
DVI->eraseFromParent ();
1515
+ for (DPValue *DPV : DPValues)
1516
+ if (DPV->getFunction () != &F)
1517
+ DPV->eraseFromParent ();
1512
1518
}
1513
1519
}
1514
1520
@@ -1544,6 +1550,16 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc,
1544
1550
/* LineNo=*/ 0 , SPType, /* ScopeLine=*/ 0 , DINode::FlagZero, SPFlags);
1545
1551
NewFunc.setSubprogram (NewSP);
1546
1552
1553
+ auto IsInvalidLocation = [&NewFunc](Value *Location) {
1554
+ // Location is invalid if it isn't a constant or an instruction, or is an
1555
+ // instruction but isn't in the new function.
1556
+ if (!Location ||
1557
+ (!isa<Constant>(Location) && !isa<Instruction>(Location)))
1558
+ return true ;
1559
+ Instruction *LocationInst = dyn_cast<Instruction>(Location);
1560
+ return LocationInst && LocationInst->getFunction () != &NewFunc;
1561
+ };
1562
+
1547
1563
// Debug intrinsics in the new function need to be updated in one of two
1548
1564
// ways:
1549
1565
// 1) They need to be deleted, because they describe a value in the old
@@ -1552,8 +1568,41 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc,
1552
1568
// point to a variable in the wrong scope.
1553
1569
SmallDenseMap<DINode *, DINode *> RemappedMetadata;
1554
1570
SmallVector<Instruction *, 4 > DebugIntrinsicsToDelete;
1571
+ SmallVector<DPValue *, 4 > DPVsToDelete;
1555
1572
DenseMap<const MDNode *, MDNode *> Cache;
1573
+
1574
+ auto GetUpdatedDIVariable = [&](DILocalVariable *OldVar) {
1575
+ DINode *&NewVar = RemappedMetadata[OldVar];
1576
+ if (!NewVar) {
1577
+ DILocalScope *NewScope = DILocalScope::cloneScopeForSubprogram (
1578
+ *OldVar->getScope (), *NewSP, Ctx, Cache);
1579
+ NewVar = DIB.createAutoVariable (
1580
+ NewScope, OldVar->getName (), OldVar->getFile (), OldVar->getLine (),
1581
+ OldVar->getType (), /* AlwaysPreserve=*/ false , DINode::FlagZero,
1582
+ OldVar->getAlignInBits ());
1583
+ }
1584
+ return cast<DILocalVariable>(NewVar);
1585
+ };
1586
+
1587
+ auto UpdateDPValuesOnInst = [&](Instruction &I) -> void {
1588
+ for (auto &DPV : I.getDbgValueRange ()) {
1589
+ // Apply the two updates that dbg.values get: invalid operands, and
1590
+ // variable metadata fixup.
1591
+ // FIXME: support dbg.assign form of DPValues.
1592
+ if (any_of (DPV.location_ops (), IsInvalidLocation)) {
1593
+ DPVsToDelete.push_back (&DPV);
1594
+ continue ;
1595
+ }
1596
+ if (!DPV.getDebugLoc ().getInlinedAt ())
1597
+ DPV.setVariable (GetUpdatedDIVariable (DPV.getVariable ()));
1598
+ DPV.setDebugLoc (DebugLoc::replaceInlinedAtSubprogram (DPV.getDebugLoc (),
1599
+ *NewSP, Ctx, Cache));
1600
+ }
1601
+ };
1602
+
1556
1603
for (Instruction &I : instructions (NewFunc)) {
1604
+ UpdateDPValuesOnInst (I);
1605
+
1557
1606
auto *DII = dyn_cast<DbgInfoIntrinsic>(&I);
1558
1607
if (!DII)
1559
1608
continue ;
@@ -1575,16 +1624,6 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc,
1575
1624
continue ;
1576
1625
}
1577
1626
1578
- auto IsInvalidLocation = [&NewFunc](Value *Location) {
1579
- // Location is invalid if it isn't a constant or an instruction, or is an
1580
- // instruction but isn't in the new function.
1581
- if (!Location ||
1582
- (!isa<Constant>(Location) && !isa<Instruction>(Location)))
1583
- return true ;
1584
- Instruction *LocationInst = dyn_cast<Instruction>(Location);
1585
- return LocationInst && LocationInst->getFunction () != &NewFunc;
1586
- };
1587
-
1588
1627
auto *DVI = cast<DbgVariableIntrinsic>(DII);
1589
1628
// If any of the used locations are invalid, delete the intrinsic.
1590
1629
if (any_of (DVI->location_ops (), IsInvalidLocation)) {
@@ -1599,23 +1638,14 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc,
1599
1638
}
1600
1639
// If the variable was in the scope of the old function, i.e. it was not
1601
1640
// inlined, point the intrinsic to a fresh variable within the new function.
1602
- if (!DVI->getDebugLoc ().getInlinedAt ()) {
1603
- DILocalVariable *OldVar = DVI->getVariable ();
1604
- DINode *&NewVar = RemappedMetadata[OldVar];
1605
- if (!NewVar) {
1606
- DILocalScope *NewScope = DILocalScope::cloneScopeForSubprogram (
1607
- *OldVar->getScope (), *NewSP, Ctx, Cache);
1608
- NewVar = DIB.createAutoVariable (
1609
- NewScope, OldVar->getName (), OldVar->getFile (), OldVar->getLine (),
1610
- OldVar->getType (), /* AlwaysPreserve=*/ false , DINode::FlagZero,
1611
- OldVar->getAlignInBits ());
1612
- }
1613
- DVI->setVariable (cast<DILocalVariable>(NewVar));
1614
- }
1641
+ if (!DVI->getDebugLoc ().getInlinedAt ())
1642
+ DVI->setVariable (GetUpdatedDIVariable (DVI->getVariable ()));
1615
1643
}
1616
1644
1617
1645
for (auto *DII : DebugIntrinsicsToDelete)
1618
1646
DII->eraseFromParent ();
1647
+ for (auto *DPV : DPVsToDelete)
1648
+ DPV->getMarker ()->MarkedInstr ->dropOneDbgValue (DPV);
1619
1649
DIB.finalizeSubprogram (NewSP);
1620
1650
1621
1651
// Fix up the scope information attached to the line locations in the new
@@ -1721,11 +1751,14 @@ CodeExtractor::extractCodeRegion(const CodeExtractorAnalysisCache &CEAC,
1721
1751
BasicBlock *codeReplacer = BasicBlock::Create (header->getContext (),
1722
1752
" codeRepl" , oldFunction,
1723
1753
header);
1754
+ codeReplacer->IsNewDbgInfoFormat = oldFunction->IsNewDbgInfoFormat ;
1724
1755
1725
1756
// The new function needs a root node because other nodes can branch to the
1726
1757
// head of the region, but the entry node of a function cannot have preds.
1727
1758
BasicBlock *newFuncRoot = BasicBlock::Create (header->getContext (),
1728
1759
" newFuncRoot" );
1760
+ newFuncRoot->IsNewDbgInfoFormat = oldFunction->IsNewDbgInfoFormat ;
1761
+
1729
1762
auto *BranchI = BranchInst::Create (header);
1730
1763
// If the original function has debug info, we have to add a debug location
1731
1764
// to the new branch instruction from the artificial entry block.
0 commit comments