@@ -257,6 +257,19 @@ static DbgValueLoc getDebugLocValue(const MachineInstr *MI) {
257
257
return DbgValueLoc (Expr, DbgValueLocEntries, IsVariadic);
258
258
}
259
259
260
+ static uint64_t getFragmentOffsetInBits (const DIExpression &Expr) {
261
+ std::optional<DIExpression::FragmentInfo> Fragment = Expr.getFragmentInfo ();
262
+ return Fragment ? Fragment->OffsetInBits : 0 ;
263
+ }
264
+
265
+ bool FrameIndexExpr::operator <(const FrameIndexExpr &Other) const {
266
+ return getFragmentOffsetInBits (*Expr) < getFragmentOffsetInBits (*Other.Expr );
267
+ }
268
+
269
+ bool EntryValueInfo::operator <(const EntryValueInfo &Other) const {
270
+ return getFragmentOffsetInBits (Expr) < getFragmentOffsetInBits (Other.Expr );
271
+ }
272
+
260
273
Loc::Single::Single (DbgValueLoc ValueLoc)
261
274
: ValueLoc(std::make_unique<DbgValueLoc>(ValueLoc)),
262
275
Expr(ValueLoc.getExpression()) {
@@ -267,42 +280,15 @@ Loc::Single::Single(DbgValueLoc ValueLoc)
267
280
Loc::Single::Single (const MachineInstr *DbgValue)
268
281
: Single(getDebugLocValue(DbgValue)) {}
269
282
270
- ArrayRef<FrameIndexExpr> Loc::MMI::getFrameIndexExprs () const {
271
- if (FrameIndexExprs.size () == 1 )
272
- return FrameIndexExprs;
273
-
274
- assert (llvm::all_of (
275
- FrameIndexExprs,
276
- [](const FrameIndexExpr &A) { return A.Expr ->isFragment (); }) &&
277
- " multiple FI expressions without DW_OP_LLVM_fragment" );
278
- llvm::sort (FrameIndexExprs,
279
- [](const FrameIndexExpr &A, const FrameIndexExpr &B) -> bool {
280
- return A.Expr ->getFragmentInfo ()->OffsetInBits <
281
- B.Expr ->getFragmentInfo ()->OffsetInBits ;
282
- });
283
-
283
+ const std::set<FrameIndexExpr> &Loc::MMI::getFrameIndexExprs () const {
284
284
return FrameIndexExprs;
285
285
}
286
286
287
287
void Loc::MMI::addFrameIndexExpr (const DIExpression *Expr, int FI) {
288
- // FIXME: This logic should not be necessary anymore, as we now have proper
289
- // deduplication. However, without it, we currently run into the assertion
290
- // below, which means that we are likely dealing with broken input, i.e. two
291
- // non-fragment entries for the same variable at different frame indices.
292
- if (FrameIndexExprs.size ()) {
293
- auto *Expr = FrameIndexExprs.back ().Expr ;
294
- if (!Expr || !Expr->isFragment ())
295
- return ;
296
- }
297
-
298
- if (llvm::none_of (FrameIndexExprs, [&](const FrameIndexExpr &Other) {
299
- return FI == Other.FI && Expr == Other.Expr ;
300
- }))
301
- FrameIndexExprs.push_back ({FI, Expr});
302
-
288
+ FrameIndexExprs.insert ({FI, Expr});
303
289
assert ((FrameIndexExprs.size () == 1 ||
304
290
llvm::all_of (FrameIndexExprs,
305
- [](FrameIndexExpr &FIE) {
291
+ [](const FrameIndexExpr &FIE) {
306
292
return FIE.Expr && FIE.Expr ->isFragment ();
307
293
})) &&
308
294
" conflicting locations for variable" );
0 commit comments