@@ -1752,20 +1752,26 @@ void llvm::salvageDebugInfoForDbgValues(
1752
1752
// must be updated in the DIExpression and potentially have additional
1753
1753
// values added; thus we call salvageDebugInfoImpl for each `I` instance in
1754
1754
// DIILocation.
1755
+ Value *Op0 = nullptr ;
1755
1756
DIExpression *SalvagedExpr = DII->getExpression ();
1756
1757
auto LocItr = find (DIILocation, &I);
1757
1758
while (SalvagedExpr && LocItr != DIILocation.end ()) {
1759
+ SmallVector<uint64_t , 16 > Ops;
1758
1760
unsigned LocNo = std::distance (DIILocation.begin (), LocItr);
1759
- SalvagedExpr = salvageDebugInfoImpl (I, SalvagedExpr, StackValue, LocNo,
1760
- AdditionalValues);
1761
+ uint64_t CurrentLocOps = SalvagedExpr->getNumLocationOperands ();
1762
+ Op0 = salvageDebugInfoImpl (I, CurrentLocOps, Ops, AdditionalValues);
1763
+ if (!Op0)
1764
+ break ;
1765
+ SalvagedExpr =
1766
+ DIExpression::appendOpsToArg (SalvagedExpr, Ops, LocNo, StackValue);
1761
1767
LocItr = std::find (++LocItr, DIILocation.end (), &I);
1762
1768
}
1763
1769
// salvageDebugInfoImpl should fail on examining the first element of
1764
1770
// DbgUsers, or none of them.
1765
- if (!SalvagedExpr )
1771
+ if (!Op0 )
1766
1772
break ;
1767
1773
1768
- DII->replaceVariableLocationOp (&I, I. getOperand ( 0 ) );
1774
+ DII->replaceVariableLocationOp (&I, Op0 );
1769
1775
if (AdditionalValues.empty ()) {
1770
1776
DII->setExpression (SalvagedExpr);
1771
1777
} else if (isa<DbgValueInst>(DII) &&
@@ -1793,16 +1799,16 @@ void llvm::salvageDebugInfoForDbgValues(
1793
1799
}
1794
1800
}
1795
1801
1796
- bool getSalvageOpsForGEP (GetElementPtrInst *GEP, const DataLayout &DL,
1797
- uint64_t CurrentLocOps,
1798
- SmallVectorImpl<uint64_t > &Opcodes,
1799
- SmallVectorImpl<Value *> &AdditionalValues) {
1802
+ Value * getSalvageOpsForGEP (GetElementPtrInst *GEP, const DataLayout &DL,
1803
+ uint64_t CurrentLocOps,
1804
+ SmallVectorImpl<uint64_t > &Opcodes,
1805
+ SmallVectorImpl<Value *> &AdditionalValues) {
1800
1806
unsigned BitWidth = DL.getIndexSizeInBits (GEP->getPointerAddressSpace ());
1801
1807
// Rewrite a GEP into a DIExpression.
1802
1808
MapVector<Value *, APInt> VariableOffsets;
1803
1809
APInt ConstantOffset (BitWidth, 0 );
1804
1810
if (!GEP->collectOffset (DL, BitWidth, VariableOffsets, ConstantOffset))
1805
- return false ;
1811
+ return nullptr ;
1806
1812
if (!VariableOffsets.empty () && !CurrentLocOps) {
1807
1813
Opcodes.insert (Opcodes.begin (), {dwarf::DW_OP_LLVM_arg, 0 });
1808
1814
CurrentLocOps = 1 ;
@@ -1816,7 +1822,7 @@ bool getSalvageOpsForGEP(GetElementPtrInst *GEP, const DataLayout &DL,
1816
1822
dwarf::DW_OP_plus});
1817
1823
}
1818
1824
DIExpression::appendOffset (Opcodes, ConstantOffset.getSExtValue ());
1819
- return true ;
1825
+ return GEP-> getOperand ( 0 ) ;
1820
1826
}
1821
1827
1822
1828
uint64_t getDwarfOpForBinOp (Instruction::BinaryOps Opcode) {
@@ -1849,14 +1855,14 @@ uint64_t getDwarfOpForBinOp(Instruction::BinaryOps Opcode) {
1849
1855
}
1850
1856
}
1851
1857
1852
- bool getSalvageOpsForBinOp (BinaryOperator *BI, uint64_t CurrentLocOps,
1853
- SmallVectorImpl<uint64_t > &Opcodes,
1854
- SmallVectorImpl<Value *> &AdditionalValues) {
1858
+ Value * getSalvageOpsForBinOp (BinaryOperator *BI, uint64_t CurrentLocOps,
1859
+ SmallVectorImpl<uint64_t > &Opcodes,
1860
+ SmallVectorImpl<Value *> &AdditionalValues) {
1855
1861
// Handle binary operations with constant integer operands as a special case.
1856
1862
auto *ConstInt = dyn_cast<ConstantInt>(BI->getOperand (1 ));
1857
1863
// Values wider than 64 bits cannot be represented within a DIExpression.
1858
1864
if (ConstInt && ConstInt->getBitWidth () > 64 )
1859
- return false ;
1865
+ return nullptr ;
1860
1866
1861
1867
Instruction::BinaryOps BinOpcode = BI->getOpcode ();
1862
1868
// Push any Constant Int operand onto the expression stack.
@@ -1867,7 +1873,7 @@ bool getSalvageOpsForBinOp(BinaryOperator *BI, uint64_t CurrentLocOps,
1867
1873
if (BinOpcode == Instruction::Add || BinOpcode == Instruction::Sub) {
1868
1874
uint64_t Offset = BinOpcode == Instruction::Add ? Val : -int64_t (Val);
1869
1875
DIExpression::appendOffset (Opcodes, Offset);
1870
- return true ;
1876
+ return BI-> getOperand ( 0 ) ;
1871
1877
}
1872
1878
Opcodes.append ({dwarf::DW_OP_constu, Val});
1873
1879
} else {
@@ -1883,61 +1889,43 @@ bool getSalvageOpsForBinOp(BinaryOperator *BI, uint64_t CurrentLocOps,
1883
1889
// representation in a DIExpression.
1884
1890
uint64_t DwarfBinOp = getDwarfOpForBinOp (BinOpcode);
1885
1891
if (!DwarfBinOp)
1886
- return false ;
1892
+ return nullptr ;
1887
1893
Opcodes.push_back (DwarfBinOp);
1888
-
1889
- return true ;
1894
+ return BI->getOperand (0 );
1890
1895
}
1891
1896
1892
- DIExpression *
1893
- llvm::salvageDebugInfoImpl (Instruction &I, DIExpression *SrcDIExpr,
1894
- bool WithStackValue, unsigned LocNo,
1895
- SmallVectorImpl<Value *> &AdditionalValues) {
1896
- uint64_t CurrentLocOps = SrcDIExpr->getNumLocationOperands ();
1897
+ Value *llvm::salvageDebugInfoImpl (Instruction &I, uint64_t CurrentLocOps,
1898
+ SmallVectorImpl<uint64_t > &Ops,
1899
+ SmallVectorImpl<Value *> &AdditionalValues) {
1897
1900
auto &M = *I.getModule ();
1898
1901
auto &DL = M.getDataLayout ();
1899
1902
1900
- // Apply a vector of opcodes to the source DIExpression.
1901
- auto doSalvage = [&](SmallVectorImpl<uint64_t > &Ops) -> DIExpression * {
1902
- DIExpression *DIExpr = SrcDIExpr;
1903
- if (!Ops.empty ()) {
1904
- DIExpr = DIExpression::appendOpsToArg (DIExpr, Ops, LocNo, WithStackValue);
1905
- }
1906
- return DIExpr;
1907
- };
1908
-
1909
- // initializer-list helper for applying operators to the source DIExpression.
1910
- auto applyOps = [&](ArrayRef<uint64_t > Opcodes) {
1911
- SmallVector<uint64_t , 8 > Ops (Opcodes.begin (), Opcodes.end ());
1912
- return doSalvage (Ops);
1913
- };
1914
-
1915
1903
if (auto *CI = dyn_cast<CastInst>(&I)) {
1904
+ Value *FromValue = CI->getOperand (0 );
1916
1905
// No-op casts are irrelevant for debug info.
1917
- if (CI->isNoopCast (DL))
1918
- return SrcDIExpr;
1906
+ if (CI->isNoopCast (DL)) {
1907
+ return FromValue;
1908
+ }
1919
1909
1920
1910
Type *Type = CI->getType ();
1921
1911
// Casts other than Trunc, SExt, or ZExt to scalar types cannot be salvaged.
1922
1912
if (Type->isVectorTy () ||
1923
1913
!(isa<TruncInst>(&I) || isa<SExtInst>(&I) || isa<ZExtInst>(&I)))
1924
1914
return nullptr ;
1925
1915
1926
- Value *FromValue = CI->getOperand (0 );
1927
1916
unsigned FromTypeBitSize = FromValue->getType ()->getScalarSizeInBits ();
1928
1917
unsigned ToTypeBitSize = Type->getScalarSizeInBits ();
1929
1918
1930
- return applyOps (DIExpression::getExtOps (FromTypeBitSize, ToTypeBitSize,
1931
- isa<SExtInst>(&I)));
1919
+ auto ExtOps = DIExpression::getExtOps (FromTypeBitSize, ToTypeBitSize,
1920
+ isa<SExtInst>(&I));
1921
+ Ops.append (ExtOps.begin (), ExtOps.end ());
1922
+ return FromValue;
1932
1923
}
1933
1924
1934
- SmallVector<uint64_t , 8 > Ops;
1935
- if (auto *GEP = dyn_cast<GetElementPtrInst>(&I)) {
1936
- if (getSalvageOpsForGEP (GEP, DL, CurrentLocOps, Ops, AdditionalValues))
1937
- return doSalvage (Ops);
1938
- } else if (auto *BI = dyn_cast<BinaryOperator>(&I)) {
1939
- if (getSalvageOpsForBinOp (BI, CurrentLocOps, Ops, AdditionalValues))
1940
- return doSalvage (Ops);
1925
+ if (auto *GEP = dyn_cast<GetElementPtrInst>(&I))
1926
+ return getSalvageOpsForGEP (GEP, DL, CurrentLocOps, Ops, AdditionalValues);
1927
+ else if (auto *BI = dyn_cast<BinaryOperator>(&I)) {
1928
+ return getSalvageOpsForBinOp (BI, CurrentLocOps, Ops, AdditionalValues);
1941
1929
}
1942
1930
// *Not* to do: we should not attempt to salvage load instructions,
1943
1931
// because the validity and lifetime of a dbg.value containing
0 commit comments