@@ -316,6 +316,13 @@ class TransferTracker {
316
316
bool isBest () const { return getQuality () == LocationQuality::Best; }
317
317
};
318
318
319
+ using ValueLocPair = std::pair<ValueIDNum, LocationAndQuality>;
320
+
321
+ static inline bool ValueToLocSort (const ValueLocPair &A,
322
+ const ValueLocPair &B) {
323
+ return A.first < B.first ;
324
+ };
325
+
319
326
// Returns the LocationQuality for the location L iff the quality of L is
320
327
// is strictly greater than the provided minimum quality.
321
328
std::optional<LocationQuality>
@@ -344,7 +351,7 @@ class TransferTracker {
344
351
// / \p DbgOpStore is the map containing the DbgOpID->DbgOp mapping needed to
345
352
// / determine the values used by Value.
346
353
void loadVarInloc (MachineBasicBlock &MBB, DbgOpIDMap &DbgOpStore,
347
- const DenseMap<ValueIDNum, LocationAndQuality > &ValueToLoc,
354
+ const SmallVectorImpl<ValueLocPair > &ValueToLoc,
348
355
DebugVariable Var, DbgValue Value) {
349
356
SmallVector<DbgOp> DbgOps;
350
357
SmallVector<ResolvedDbgOp> ResolvedDbgOps;
@@ -373,9 +380,17 @@ class TransferTracker {
373
380
continue ;
374
381
}
375
382
376
- // If the value has no location, we can't make a variable location.
383
+ // Search for the desired ValueIDNum, to examine the best location found
384
+ // for it. Use an empty ValueLocPair to search for an entry in ValueToLoc.
377
385
const ValueIDNum &Num = Op.ID ;
378
- auto ValuesPreferredLoc = ValueToLoc.find (Num);
386
+ ValueLocPair Probe (Num, LocationAndQuality ());
387
+ auto ValuesPreferredLoc = std::lower_bound (
388
+ ValueToLoc.begin (), ValueToLoc.end (), Probe, ValueToLocSort);
389
+
390
+ // There must be a legitimate entry found for Num.
391
+ assert (ValuesPreferredLoc != ValueToLoc.end () &&
392
+ ValuesPreferredLoc->first == Num);
393
+
379
394
if (ValuesPreferredLoc->second .isIllegal ()) {
380
395
// If it's a def that occurs in this block, register it as a
381
396
// use-before-def to be resolved as we step through the block.
@@ -439,17 +454,20 @@ class TransferTracker {
439
454
UseBeforeDefs.clear ();
440
455
UseBeforeDefVariables.clear ();
441
456
442
- // Map of the preferred location for each value.
443
- DenseMap<ValueIDNum, LocationAndQuality> ValueToLoc;
457
+ // Mapping of the preferred locations for each value. Collected into this
458
+ // vector then sorted for easy searching.
459
+ SmallVector<ValueLocPair, 16 > ValueToLoc;
444
460
445
461
// Initialized the preferred-location map with illegal locations, to be
446
462
// filled in later.
447
463
for (const auto &VLoc : VLocs)
448
464
if (VLoc.second .Kind == DbgValue::Def)
449
465
for (DbgOpID OpID : VLoc.second .getDbgOpIDs ())
450
466
if (!OpID.ID .IsConst )
451
- ValueToLoc.insert ({DbgOpStore.find (OpID).ID , LocationAndQuality ()});
467
+ ValueToLoc.push_back (
468
+ {DbgOpStore.find (OpID).ID , LocationAndQuality ()});
452
469
470
+ llvm::sort (ValueToLoc, ValueToLocSort);
453
471
ActiveMLocs.reserve (VLocs.size ());
454
472
ActiveVLocs.reserve (VLocs.size ());
455
473
@@ -464,8 +482,10 @@ class TransferTracker {
464
482
VarLocs.push_back (VNum);
465
483
466
484
// Is there a variable that wants a location for this value? If not, skip.
467
- auto VIt = ValueToLoc.find (VNum);
468
- if (VIt == ValueToLoc.end ())
485
+ ValueLocPair Probe (VNum, LocationAndQuality ());
486
+ auto VIt = std::lower_bound (ValueToLoc.begin (), ValueToLoc.end (), Probe,
487
+ ValueToLocSort);
488
+ if (VIt == ValueToLoc.end () || VIt->first != VNum)
469
489
continue ;
470
490
471
491
auto &Previous = VIt->second ;
0 commit comments