@@ -1724,16 +1724,19 @@ void llvm::ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
1724
1724
SI->getIterator ());
1725
1725
}
1726
1726
1727
+ namespace llvm {
1727
1728
// RemoveDIs: duplicate the getDebugValueLoc method using DPValues instead of
1728
- // dbg.value intrinsics.
1729
- static DebugLoc getDebugValueLocDPV (DPValue *DPV) {
1729
+ // dbg.value intrinsics. In llvm namespace so that it overloads the
1730
+ // DbgVariableIntrinsic version.
1731
+ static DebugLoc getDebugValueLoc (DPValue *DPV) {
1730
1732
// Original dbg.declare must have a location.
1731
1733
const DebugLoc &DeclareLoc = DPV->getDebugLoc ();
1732
1734
MDNode *Scope = DeclareLoc.getScope ();
1733
1735
DILocation *InlinedAt = DeclareLoc.getInlinedAt ();
1734
1736
// Produce an unknown location with the correct scope / inlinedAt fields.
1735
1737
return DILocation::get (DPV->getContext (), 0 , 0 , Scope, InlinedAt);
1736
1738
}
1739
+ } // namespace llvm
1737
1740
1738
1741
// / Inserts a llvm.dbg.value intrinsic before a load of an alloca'd value
1739
1742
// / that has an associated llvm.dbg.declare intrinsic.
@@ -1770,7 +1773,7 @@ void llvm::ConvertDebugDeclareToDebugValue(DPValue *DPV, StoreInst *SI,
1770
1773
auto *DIExpr = DPV->getExpression ();
1771
1774
Value *DV = SI->getValueOperand ();
1772
1775
1773
- DebugLoc NewLoc = getDebugValueLocDPV (DPV);
1776
+ DebugLoc NewLoc = getDebugValueLoc (DPV);
1774
1777
1775
1778
if (!valueCoversEntireFragment (DV->getType (), DPV)) {
1776
1779
// FIXME: If storing to a part of the variable described by the dbg.declare,
@@ -1842,7 +1845,7 @@ void llvm::ConvertDebugDeclareToDebugValue(DPValue *DPV, LoadInst *LI,
1842
1845
return ;
1843
1846
}
1844
1847
1845
- DebugLoc NewLoc = getDebugValueLocDPV (DPV);
1848
+ DebugLoc NewLoc = getDebugValueLoc (DPV);
1846
1849
1847
1850
// We are now tracking the loaded value instead of the address. In the
1848
1851
// future if multi-location support is added to the IR, it might be
@@ -1887,7 +1890,7 @@ void llvm::ConvertDebugDeclareToDebugValue(DPValue *DPV, PHINode *APN,
1887
1890
BasicBlock *BB = APN->getParent ();
1888
1891
auto InsertionPt = BB->getFirstInsertionPt ();
1889
1892
1890
- DebugLoc NewLoc = getDebugValueLocDPV (DPV);
1893
+ DebugLoc NewLoc = getDebugValueLoc (DPV);
1891
1894
1892
1895
// The block may be a catchswitch block, which does not have a valid
1893
1896
// insertion point.
@@ -1903,25 +1906,32 @@ bool llvm::LowerDbgDeclare(Function &F) {
1903
1906
bool Changed = false ;
1904
1907
DIBuilder DIB (*F.getParent (), /* AllowUnresolved*/ false );
1905
1908
SmallVector<DbgDeclareInst *, 4 > Dbgs;
1906
- for (auto &FI : F)
1907
- for (Instruction &BI : FI)
1908
- if (auto DDI = dyn_cast<DbgDeclareInst>(&BI))
1909
+ SmallVector<DPValue *> DPVs;
1910
+ for (auto &FI : F) {
1911
+ for (Instruction &BI : FI) {
1912
+ if (auto *DDI = dyn_cast<DbgDeclareInst>(&BI))
1909
1913
Dbgs.push_back (DDI);
1914
+ for (DPValue &DPV : BI.getDbgValueRange ()) {
1915
+ if (DPV.getType () == DPValue::LocationType::Declare)
1916
+ DPVs.push_back (&DPV);
1917
+ }
1918
+ }
1919
+ }
1910
1920
1911
- if (Dbgs.empty ())
1921
+ if (Dbgs.empty () && DPVs. empty () )
1912
1922
return Changed;
1913
1923
1914
- for ( auto &I : Dbgs ) {
1915
- DbgDeclareInst *DDI = I;
1916
- AllocaInst *AI = dyn_cast_or_null<AllocaInst>(DDI->getAddress ( ));
1924
+ auto LowerOne = [&]( auto *DDI ) {
1925
+ AllocaInst *AI =
1926
+ dyn_cast_or_null<AllocaInst>(DDI->getVariableLocationOp ( 0 ));
1917
1927
// If this is an alloca for a scalar variable, insert a dbg.value
1918
1928
// at each load and store to the alloca and erase the dbg.declare.
1919
1929
// The dbg.values allow tracking a variable even if it is not
1920
1930
// stored on the stack, while the dbg.declare can only describe
1921
1931
// the stack slot (and at a lexical-scope granularity). Later
1922
1932
// passes will attempt to elide the stack slot.
1923
1933
if (!AI || isArray (AI) || isStructure (AI))
1924
- continue ;
1934
+ return ;
1925
1935
1926
1936
// A volatile load/store means that the alloca can't be elided anyway.
1927
1937
if (llvm::any_of (AI->users (), [](User *U) -> bool {
@@ -1931,7 +1941,7 @@ bool llvm::LowerDbgDeclare(Function &F) {
1931
1941
return SI->isVolatile ();
1932
1942
return false ;
1933
1943
}))
1934
- continue ;
1944
+ return ;
1935
1945
1936
1946
SmallVector<const Value *, 8 > WorkList;
1937
1947
WorkList.push_back (AI);
@@ -1963,11 +1973,14 @@ bool llvm::LowerDbgDeclare(Function &F) {
1963
1973
}
1964
1974
DDI->eraseFromParent ();
1965
1975
Changed = true ;
1966
- }
1976
+ };
1977
+
1978
+ for_each (Dbgs, LowerOne);
1979
+ for_each (DPVs, LowerOne);
1967
1980
1968
1981
if (Changed)
1969
- for (BasicBlock &BB : F)
1970
- RemoveRedundantDbgInstrs (&BB);
1982
+ for (BasicBlock &BB : F)
1983
+ RemoveRedundantDbgInstrs (&BB);
1971
1984
1972
1985
return Changed;
1973
1986
}
0 commit comments