1515
1616#include " llvm/ADT/BitVector.h"
1717#include " llvm/ADT/DenseMapInfo.h"
18+ #include " llvm/ADT/DenseSet.h"
1819#include " llvm/ADT/GraphTraits.h"
1920#include " llvm/ADT/SparseBitVector.h"
2021#include " llvm/ADT/ilist.h"
@@ -175,12 +176,7 @@ class MachineBasicBlock
175176 std::optional<uint64_t > IrrLoopHeaderWeight;
176177
177178 // / Keep track of the physical registers that are livein of the basicblock.
178- using LiveInVector = std::vector<RegisterMaskPair>;
179- LiveInVector LiveIns;
180-
181- // / Keeps track of live register units for those physical registers which
182- // / are livein of the basicblock.
183- BitVector LiveInRegUnits;
179+ DenseSet<MCRegister> LiveIns;
184180
185181 // / Alignment of the basic block. One if the basic block does not need to be
186182 // / aligned.
@@ -466,34 +462,17 @@ class MachineBasicBlock
466462
467463 // LiveIn management methods.
468464
469- // / Adds the specified register as a live in. Note that it is an error to add
470- // / the same register to the same set more than once unless the intention is
471- // / to call sortUniqueLiveIns after all registers are added.
465+ // / Adds the live regUnits(both of its roots registers) as the live in, based
466+ // / on the LaneMask.
472467 void addLiveIn (MCRegister PhysReg,
473- LaneBitmask LaneMask = LaneBitmask::getAll()) {
474- LiveIns.push_back (RegisterMaskPair (PhysReg, LaneMask));
475- addLiveInRegUnit (PhysReg, LaneMask);
476- }
477- void addLiveIn (const RegisterMaskPair &RegMaskPair) {
478- LiveIns.push_back (RegMaskPair);
479- addLiveInRegUnit (RegMaskPair.PhysReg , RegMaskPair.LaneMask );
480- }
481-
482- // Sets the register units for Reg based on the LaneMask in the
483- // LiveInRegUnits.
484- void addLiveInRegUnit (MCRegister Reg, LaneBitmask LaneMask);
485-
486- // / Sorts and uniques the LiveIns vector. It can be significantly faster to do
487- // / this than repeatedly calling isLiveIn before calling addLiveIn for every
488- // / LiveIn insertion.
489- void sortUniqueLiveIns ();
468+ LaneBitmask LaneMask = LaneBitmask::getAll());
490469
491470 // / Clear live in list.
492471 void clearLiveIns ();
493472
494473 // / Clear the live in list, and return the removed live in's in \p OldLiveIns.
495474 // / Requires that the vector \p OldLiveIns is empty.
496- void clearLiveIns (std::vector<RegisterMaskPair > &OldLiveIns);
475+ void clearLiveIns (DenseSet<MCRegister > &OldLiveIns);
497476
498477 // / Add PhysReg as live in to this block, and ensure that there is a copy of
499478 // / PhysReg to a virtual register of class RC. Return the virtual register
@@ -504,16 +483,13 @@ class MachineBasicBlock
504483 void removeLiveIn (MCRegister Reg,
505484 LaneBitmask LaneMask = LaneBitmask::getAll());
506485
507- // / Resets the register units from LiveInRegUnits for the specified regsiters.
508- void removeLiveInRegUnit (MCRegister Reg);
509-
510486 // / Return true if the specified register is in the live in set.
511487 bool isLiveIn (MCRegister Reg,
512488 LaneBitmask LaneMask = LaneBitmask::getAll()) const ;
513489
514490 // Iteration support for live in sets. These sets are kept in sorted
515491 // order by their register number.
516- using livein_iterator = LiveInVector ::const_iterator;
492+ using livein_iterator = DenseSet<MCRegister> ::const_iterator;
517493
518494 // / Unlike livein_begin, this method does not check that the liveness
519495 // / information is accurate. Still for debug purposes it may be useful
@@ -534,15 +510,15 @@ class MachineBasicBlock
534510 // / Remove entry from the livein set and return iterator to the next.
535511 livein_iterator removeLiveIn (livein_iterator I);
536512
537- const std::vector<RegisterMaskPair > &getLiveIns () const { return LiveIns; }
513+ const DenseSet<MCRegister > &getLiveIns () const { return LiveIns; }
538514
539515 class liveout_iterator {
540516 public:
541517 using iterator_category = std::input_iterator_tag;
542518 using difference_type = std::ptrdiff_t ;
543- using value_type = RegisterMaskPair ;
544- using pointer = const RegisterMaskPair *;
545- using reference = const RegisterMaskPair &;
519+ using value_type = MCRegister ;
520+ using pointer = const MCRegister *;
521+ using reference = const MCRegister &;
546522
547523 liveout_iterator (const MachineBasicBlock &MBB, MCPhysReg ExceptionPointer,
548524 MCPhysReg ExceptionSelector, bool End)
@@ -555,8 +531,7 @@ class MachineBasicBlock
555531 LiveRegI = (*BlockI)->livein_begin ();
556532 if (!advanceToValidPosition ())
557533 return ;
558- if (LiveRegI->PhysReg == ExceptionPointer ||
559- LiveRegI->PhysReg == ExceptionSelector)
534+ if (*LiveRegI == ExceptionPointer || *LiveRegI == ExceptionSelector)
560535 ++(*this );
561536 }
562537 }
@@ -566,9 +541,8 @@ class MachineBasicBlock
566541 ++LiveRegI;
567542 if (!advanceToValidPosition ())
568543 return *this ;
569- } while ((*BlockI)->isEHPad () &&
570- (LiveRegI->PhysReg == ExceptionPointer ||
571- LiveRegI->PhysReg == ExceptionSelector));
544+ } while ((*BlockI)->isEHPad () && (*LiveRegI == ExceptionPointer ||
545+ *LiveRegI == ExceptionSelector));
572546 return *this ;
573547 }
574548
0 commit comments