Skip to content

Commit dad5caa

Browse files
committed
Revert "Reapply "[DebugInfo] Use variadic debug values to salvage BinOps and GEP instrs with non-const operands""
This change causes an assert / segmentation fault in LTO builds. This reverts commit f2e4f3e.
1 parent c362179 commit dad5caa

File tree

17 files changed

+132
-399
lines changed

17 files changed

+132
-399
lines changed

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,16 +2594,6 @@ class DIExpression : public MDNode {
25942594
// return it's sign information.
25952595
llvm::Optional<SignedOrUnsignedConstant> isConstant() const;
25962596

2597-
/// Return the number of unique location operands referred to (via
2598-
/// DW_OP_LLVM_arg) in this expression; this is not necessarily the number of
2599-
/// instances of DW_OP_LLVM_arg within the expression.
2600-
/// For example, for the expression:
2601-
/// (DW_OP_LLVM_arg 0, DW_OP_LLVM_arg 1, DW_OP_plus,
2602-
/// DW_OP_LLVM_arg 0, DW_OP_mul)
2603-
/// This function would return 2, as there are two unique location operands
2604-
/// (0 and 1).
2605-
uint64_t getNumLocationOperands() const;
2606-
26072597
using element_iterator = ArrayRef<uint64_t>::iterator;
26082598

26092599
element_iterator elements_begin() const { return getElements().begin(); }
@@ -2751,10 +2741,6 @@ class DIExpression : public MDNode {
27512741
/// return true with an offset of zero.
27522742
bool extractIfOffset(int64_t &Offset) const;
27532743

2754-
/// Returns true iff this DIExpression contains at least one instance of
2755-
/// `DW_OP_LLVM_arg, n` for all n in [0, N).
2756-
bool hasAllLocationOps(unsigned N) const;
2757-
27582744
/// Checks if the last 4 elements of the expression are DW_OP_constu <DWARF
27592745
/// Address Space> DW_OP_swap DW_OP_xderef and extracts the <DWARF Address
27602746
/// Space>.

llvm/include/llvm/IR/Instructions.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,9 +1122,7 @@ class GetElementPtrInst : public Instruction {
11221122
/// must be at least as wide as the IntPtr type for the address space of
11231123
/// the base GEP pointer.
11241124
bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const;
1125-
bool collectOffset(const DataLayout &DL, unsigned BitWidth,
1126-
SmallDenseMap<Value *, APInt, 8> &VariableOffsets,
1127-
APInt &ConstantOffset) const;
1125+
11281126
// Methods for support type inquiry through isa, cast, and dyn_cast:
11291127
static bool classof(const Instruction *I) {
11301128
return (I->getOpcode() == Instruction::GetElementPtr);

llvm/include/llvm/IR/IntrinsicInst.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,6 @@ class DbgVariableIntrinsic : public DbgInfoIntrinsic {
204204

205205
void replaceVariableLocationOp(Value *OldValue, Value *NewValue);
206206
void replaceVariableLocationOp(unsigned OpIdx, Value *NewValue);
207-
/// Adding a new location operand will always result in this intrinsic using
208-
/// an ArgList, and must always be accompanied by a new expression that uses
209-
/// the new operand.
210-
void addVariableLocationOps(ArrayRef<Value *> NewValues,
211-
DIExpression *NewExpr);
212207

213208
void setVariable(DILocalVariable *NewVar) {
214209
setArgOperand(1, MetadataAsValue::get(NewVar->getContext(), NewVar));

llvm/include/llvm/IR/Operator.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -576,12 +576,6 @@ class GEPOperator
576576
Type *SourceType, ArrayRef<const Value *> Index, const DataLayout &DL,
577577
APInt &Offset,
578578
function_ref<bool(Value &, APInt &)> ExternalAnalysis = nullptr);
579-
580-
/// Collect the offset of this GEP as a map of Values to their associated
581-
/// APInt multipliers, as well as a total Constant Offset.
582-
bool collectOffset(const DataLayout &DL, unsigned BitWidth,
583-
SmallDenseMap<Value *, APInt, 8> &VariableOffsets,
584-
APInt &ConstantOffset) const;
585579
};
586580

587581
class PtrToIntOperator

llvm/include/llvm/Transforms/Utils/Local.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,7 @@ void salvageDebugInfoForDbgValues(Instruction &I,
314314
/// appended to the expression. \p LocNo: the index of the location operand to
315315
/// which \p I applies, should be 0 for debug info without a DIArgList.
316316
DIExpression *salvageDebugInfoImpl(Instruction &I, DIExpression *DIExpr,
317-
bool StackVal, unsigned LocNo,
318-
SmallVectorImpl<Value *> &AdditionalValues);
317+
bool StackVal, unsigned LocNo);
319318

320319
/// Point debug users of \p From to \p To or salvage them. Use this function
321320
/// only when replacing all uses of \p From with \p To, with a guarantee that

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,10 +1238,6 @@ void SelectionDAGBuilder::resolveDanglingDebugInfo(const Value *V,
12381238
}
12391239

12401240
void SelectionDAGBuilder::salvageUnresolvedDbgValue(DanglingDebugInfo &DDI) {
1241-
// TODO: For the variadic implementation, instead of only checking the fail
1242-
// state of `handleDebugValue`, we need know specifically which values were
1243-
// invalid, so that we attempt to salvage only those values when processing
1244-
// a DIArgList.
12451241
assert(!DDI.getDI()->hasArgList() &&
12461242
"Not implemented for variadic dbg_values");
12471243
Value *V = DDI.getDI()->getValue(0);
@@ -1265,21 +1261,16 @@ void SelectionDAGBuilder::salvageUnresolvedDbgValue(DanglingDebugInfo &DDI) {
12651261
while (isa<Instruction>(V)) {
12661262
Instruction &VAsInst = *cast<Instruction>(V);
12671263
// Temporary "0", awaiting real implementation.
1268-
SmallVector<Value *, 4> AdditionalValues;
1269-
DIExpression *SalvagedExpr =
1270-
salvageDebugInfoImpl(VAsInst, Expr, StackValue, 0, AdditionalValues);
1264+
DIExpression *NewExpr = salvageDebugInfoImpl(VAsInst, Expr, StackValue, 0);
12711265

12721266
// If we cannot salvage any further, and haven't yet found a suitable debug
12731267
// expression, bail out.
1274-
// TODO: If AdditionalValues isn't empty, then the salvage can only be
1275-
// represented with a DBG_VALUE_LIST, so we give up. When we have support
1276-
// here for variadic dbg_values, remove that condition.
1277-
if (!SalvagedExpr || !AdditionalValues.empty())
1268+
if (!NewExpr)
12781269
break;
12791270

12801271
// New value and expr now represent this debuginfo.
12811272
V = VAsInst.getOperand(0);
1282-
Expr = SalvagedExpr;
1273+
Expr = NewExpr;
12831274

12841275
// Some kind of simplification occurred: check whether the operand of the
12851276
// salvaged debug expression can be encoded in this DAG.

llvm/lib/IR/DebugInfoMetadata.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,17 +1244,6 @@ bool DIExpression::extractIfOffset(int64_t &Offset) const {
12441244
return false;
12451245
}
12461246

1247-
bool DIExpression::hasAllLocationOps(unsigned N) const {
1248-
SmallDenseSet<uint64_t, 4> SeenOps;
1249-
for (auto ExprOp : expr_ops())
1250-
if (ExprOp.getOp() == dwarf::DW_OP_LLVM_arg)
1251-
SeenOps.insert(ExprOp.getArg(0));
1252-
for (uint64_t Idx = 0; Idx < N; ++Idx)
1253-
if (!is_contained(SeenOps, Idx))
1254-
return false;
1255-
return true;
1256-
}
1257-
12581247
const DIExpression *DIExpression::extractAddressClass(const DIExpression *Expr,
12591248
unsigned &AddrClass) {
12601249
// FIXME: This seems fragile. Nothing that verifies that these elements
@@ -1469,16 +1458,6 @@ Optional<DIExpression *> DIExpression::createFragmentExpression(
14691458
return DIExpression::get(Expr->getContext(), Ops);
14701459
}
14711460

1472-
uint64_t DIExpression::getNumLocationOperands() const {
1473-
uint64_t Result = 0;
1474-
for (auto ExprOp : expr_ops())
1475-
if (ExprOp.getOp() == dwarf::DW_OP_LLVM_arg)
1476-
Result = std::max(Result, ExprOp.getArg(0) + 1);
1477-
assert(hasAllLocationOps(Result) &&
1478-
"Expression is missing one or more location operands.");
1479-
return Result;
1480-
}
1481-
14821461
llvm::Optional<DIExpression::SignedOrUnsignedConstant>
14831462
DIExpression::isConstant() const {
14841463

llvm/lib/IR/Instructions.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,15 +1806,6 @@ bool GetElementPtrInst::accumulateConstantOffset(const DataLayout &DL,
18061806
return cast<GEPOperator>(this)->accumulateConstantOffset(DL, Offset);
18071807
}
18081808

1809-
bool GetElementPtrInst::collectOffset(
1810-
const DataLayout &DL, unsigned BitWidth,
1811-
SmallDenseMap<Value *, APInt, 8> &VariableOffsets,
1812-
APInt &ConstantOffset) const {
1813-
// Delegate to the generic GEPOperator implementation.
1814-
return cast<GEPOperator>(this)->collectOffset(DL, BitWidth, VariableOffsets,
1815-
ConstantOffset);
1816-
}
1817-
18181809
//===----------------------------------------------------------------------===//
18191810
// ExtractElementInst Implementation
18201811
//===----------------------------------------------------------------------===//

llvm/lib/IR/IntrinsicInst.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -118,23 +118,6 @@ void DbgVariableIntrinsic::replaceVariableLocationOp(unsigned OpIdx,
118118
0, MetadataAsValue::get(getContext(), DIArgList::get(getContext(), MDs)));
119119
}
120120

121-
void DbgVariableIntrinsic::addVariableLocationOps(ArrayRef<Value *> NewValues,
122-
DIExpression *NewExpr) {
123-
assert(NewExpr->hasAllLocationOps(getNumVariableLocationOps() +
124-
NewValues.size()) &&
125-
"NewExpr for debug variable intrinsic does not reference every "
126-
"location operand.");
127-
assert(!is_contained(NewValues, nullptr) && "New values must be non-null");
128-
setArgOperand(2, MetadataAsValue::get(getContext(), NewExpr));
129-
SmallVector<ValueAsMetadata *, 4> MDs;
130-
for (auto *VMD : location_ops())
131-
MDs.push_back(getAsMetadata(VMD));
132-
for (auto *VMD : NewValues)
133-
MDs.push_back(getAsMetadata(VMD));
134-
setArgOperand(
135-
0, MetadataAsValue::get(getContext(), DIArgList::get(getContext(), MDs)));
136-
}
137-
138121
Optional<uint64_t> DbgVariableIntrinsic::getFragmentSizeInBits() const {
139122
if (auto Fragment = getExpression()->getFragmentInfo())
140123
return Fragment->SizeInBits;

llvm/lib/IR/Operator.cpp

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -142,61 +142,4 @@ bool GEPOperator::accumulateConstantOffset(
142142
}
143143
return true;
144144
}
145-
146-
bool GEPOperator::collectOffset(
147-
const DataLayout &DL, unsigned BitWidth,
148-
SmallDenseMap<Value *, APInt, 8> &VariableOffsets,
149-
APInt &ConstantOffset) const {
150-
assert(BitWidth == DL.getIndexSizeInBits(getPointerAddressSpace()) &&
151-
"The offset bit width does not match DL specification.");
152-
153-
auto CollectConstantOffset = [&](APInt Index, uint64_t Size) {
154-
Index = Index.sextOrTrunc(BitWidth);
155-
APInt IndexedSize = APInt(BitWidth, Size);
156-
ConstantOffset += Index * IndexedSize;
157-
};
158-
159-
for (gep_type_iterator GTI = gep_type_begin(this), GTE = gep_type_end(this);
160-
GTI != GTE; ++GTI) {
161-
// Scalable vectors are multiplied by a runtime constant.
162-
bool ScalableType = isa<ScalableVectorType>(GTI.getIndexedType());
163-
164-
Value *V = GTI.getOperand();
165-
StructType *STy = GTI.getStructTypeOrNull();
166-
// Handle ConstantInt if possible.
167-
if (auto ConstOffset = dyn_cast<ConstantInt>(V)) {
168-
if (ConstOffset->isZero())
169-
continue;
170-
// If the type is scalable and the constant is not zero (vscale * n * 0 =
171-
// 0) bailout.
172-
// TODO: If the runtime value is accessible at any point before DWARF
173-
// emission, then we could potentially keep a forward reference to it
174-
// in the debug value to be filled in later.
175-
if (ScalableType)
176-
return false;
177-
// Handle a struct index, which adds its field offset to the pointer.
178-
if (STy) {
179-
unsigned ElementIdx = ConstOffset->getZExtValue();
180-
const StructLayout *SL = DL.getStructLayout(STy);
181-
// Element offset is in bytes.
182-
CollectConstantOffset(APInt(BitWidth, SL->getElementOffset(ElementIdx)),
183-
1);
184-
continue;
185-
}
186-
CollectConstantOffset(ConstOffset->getValue(),
187-
DL.getTypeAllocSize(GTI.getIndexedType()));
188-
continue;
189-
}
190-
191-
if (STy || ScalableType)
192-
return false;
193-
// Insert an initial offset of 0 for V iff none exists already, then
194-
// increment the offset by IndexedSize.
195-
VariableOffsets.try_emplace(V, BitWidth, 0);
196-
APInt IndexedSize =
197-
APInt(BitWidth, DL.getTypeAllocSize(GTI.getIndexedType()));
198-
VariableOffsets[V] += IndexedSize;
199-
}
200-
return true;
201-
}
202145
} // namespace llvm

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,15 +2101,10 @@ void coro::salvageDebugInfo(
21012101
} else if (auto *StInst = dyn_cast<StoreInst>(Storage)) {
21022102
Storage = StInst->getOperand(0);
21032103
} else if (auto *GEPInst = dyn_cast<GetElementPtrInst>(Storage)) {
2104-
SmallVector<Value *> AdditionalValues;
2105-
DIExpression *SalvagedExpr = llvm::salvageDebugInfoImpl(
2106-
*GEPInst, Expr,
2107-
/*WithStackValue=*/false, 0, AdditionalValues);
2108-
// Debug declares cannot currently handle additional location
2109-
// operands.
2110-
if (!SalvagedExpr || !AdditionalValues.empty())
2111-
break;
2112-
Expr = SalvagedExpr;
2104+
Expr = llvm::salvageDebugInfoImpl(*GEPInst, Expr,
2105+
/*WithStackValue=*/false, 0);
2106+
if (!Expr)
2107+
return;
21132108
Storage = GEPInst->getOperand(0);
21142109
} else if (auto *BCInst = dyn_cast<llvm::BitCastInst>(Storage))
21152110
Storage = BCInst->getOperand(0);

0 commit comments

Comments
 (0)