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