@@ -57,15 +57,29 @@ void SystemZPreRASchedStrategy::initializePrioRegClasses(
5757 }
5858}
5959
60- void SystemZPreRASchedStrategy::VRegSet::dump (std::string Msg) {
61- dbgs () << Msg.c_str ();
60+ void SystemZPreRASchedStrategy::VRegSet::insert (Register Reg) {
61+ assert (Reg.isVirtual ());
62+ Regs.insert (Reg);
63+ }
64+
65+ void SystemZPreRASchedStrategy::VRegSet::erase (Register Reg) {
66+ assert (Reg.isVirtual ());
67+ Regs.erase (Reg);
68+ }
69+
70+ bool SystemZPreRASchedStrategy::VRegSet::count (Register Reg) const {
71+ assert (Reg.isVirtual ());
72+ return Regs.count (Reg);
73+ }
74+
75+ void SystemZPreRASchedStrategy::VRegSet::dump () const {
6276 bool First = true ;
63- for (auto R : * this ) {
77+ for (auto R : Regs ) {
6478 if (!First)
6579 dbgs () << " , " ;
6680 else
6781 First = false ;
68- dbgs () << " % " << R. virtRegIndex ( );
82+ dbgs () << printReg (R );
6983 }
7084 dbgs () << " \n " ;
7185}
@@ -109,8 +123,8 @@ void SystemZPreRASchedStrategy::initializeStoresGroup() {
109123 return ;
110124 if (IsStore)
111125 StoresGroup.insert (SU);
112- }
113- else if (IsStore && !StoresGroup. empty () && SU->getDepth () == CurrMaxDepth) {
126+ } else if (IsStore && !StoresGroup. empty () &&
127+ SU->getDepth () == CurrMaxDepth) {
114128 // The group members should all have the same opcode.
115129 if ((*StoresGroup.begin ())->getInstr ()->getOpcode () != MI->getOpcode ()) {
116130 StoresGroup.clear ();
@@ -142,9 +156,8 @@ static int biasPhysRegExtra(const SUnit *SU) {
142156 return 0 ;
143157}
144158
145- int SystemZPreRASchedStrategy::
146- computeSULivenessScore (SchedCandidate &C, ScheduleDAGMILive *DAG,
147- SchedBoundary *Zone) const {
159+ int SystemZPreRASchedStrategy::computeSULivenessScore (
160+ SchedCandidate &C, ScheduleDAGMILive *DAG, SchedBoundary *Zone) const {
148161 // Not all data deps are modelled around the SUnit - some data edges near
149162 // boundaries are missing: Look directly at the MI operands instead.
150163 const SUnit *SU = C.SU ;
@@ -246,22 +259,24 @@ bool SystemZPreRASchedStrategy::tryCandidate(SchedCandidate &Cand,
246259 return TryCand.Reason != NoCand;
247260
248261 // Don't extend the scheduled latency.
249- if (ShouldReduceLatency && TryCand.SU ->getHeight () != Cand.SU ->getHeight () &&
262+ if (ShouldReduceLatency &&
263+ TryCand.SU ->getHeight () != Cand.SU ->getHeight () &&
250264 (std::max (TryCand.SU ->getHeight (), Cand.SU ->getHeight ()) >
251265 Zone->getScheduledLatency ())) {
252- unsigned HigherSUDepth = TryCand.SU ->getHeight () < Cand.SU ->getHeight () ?
253- Cand.SU ->getDepth () : TryCand.SU ->getDepth ();
266+ unsigned HigherSUDepth = TryCand.SU ->getHeight () < Cand.SU ->getHeight ()
267+ ? Cand.SU ->getDepth ()
268+ : TryCand.SU ->getDepth ();
254269 if (HigherSUDepth != getRemLat (Zone) &&
255- tryLess (TryCand.SU ->getHeight (), Cand.SU ->getHeight (),
256- TryCand, Cand, GenericSchedulerBase::BotHeightReduce)) {
270+ tryLess (TryCand.SU ->getHeight (), Cand.SU ->getHeight (), TryCand, Cand,
271+ GenericSchedulerBase::BotHeightReduce)) {
257272 return TryCand.Reason != NoCand;
258273 }
259274 }
260275 }
261276
262277 // Weak edges are for clustering and other constraints.
263- if (tryLess (TryCand.SU ->WeakSuccsLeft , Cand.SU ->WeakSuccsLeft ,
264- TryCand, Cand, Weak))
278+ if (tryLess (TryCand.SU ->WeakSuccsLeft , Cand.SU ->WeakSuccsLeft , TryCand, Cand,
279+ Weak))
265280 return TryCand.Reason != NoCand;
266281
267282 // Fall through to original instruction order.
@@ -361,17 +376,22 @@ void SystemZPreRASchedStrategy::initialize(ScheduleDAGMI *dag) {
361376 LLVM_DEBUG (if (ShouldReduceLatency) dbgs () << " Latency scheduling enabled.\n " ;
362377 else dbgs () << " Latency scheduling disabled.\n " ;);
363378
364- // Find the registers that are live at the bottom, before scheduling .
379+ // Find the registers used in the region that are live out .
365380 LiveRegs.clear ();
366- for (unsigned I = 0 , E = DAG->MRI .getNumVirtRegs (); I != E; ++I) {
367- Register VirtReg = Register::index2VirtReg (I);
368- const LiveInterval &LI = DAG->getLIS ()->getInterval (VirtReg);
369- LiveQueryResult LRQ = LI.Query (
370- DAG->getLIS ()->getInstructionIndex (*DAG->SUnits .back ().getInstr ()));
371- if (LRQ.valueOut ())
372- LiveRegs.insert (VirtReg);
381+ std::set<Register> Visited;
382+ for (unsigned Idx = 0 , End = DAG->SUnits .size (); Idx != End; ++Idx) {
383+ const MachineInstr *MI = DAG->SUnits [Idx].getInstr ();
384+ for (auto &MO : MI->explicit_operands ())
385+ if (MO.isReg () && MO.getReg ().isVirtual () &&
386+ Visited.insert (MO.getReg ()).second ) {
387+ const LiveInterval &LI = DAG->getLIS ()->getInterval (MO.getReg ());
388+ LiveQueryResult LRQ = LI.Query (
389+ DAG->getLIS ()->getInstructionIndex (*DAG->SUnits .back ().getInstr ()));
390+ if (LRQ.valueOut ())
391+ LiveRegs.insert (MO.getReg ());
392+ }
373393 }
374- LLVM_DEBUG (LiveRegs. dump ( " Live out at bottom: " ););
394+ LLVM_DEBUG (dbgs () << " Live out at bottom: " ; LiveRegs. dump ( ););
375395
376396 // If MI uses the register it defines, record it one time here.
377397 IsRedefining = std::vector<bool >(DAG->SUnits .size (), false );
@@ -395,7 +415,7 @@ void SystemZPreRASchedStrategy::schedNode(SUnit *SU, bool IsTopNode) {
395415 if (TinyRegion)
396416 return ;
397417
398- LLVM_DEBUG (LiveRegs. dump ( " Live regs was: " ););
418+ LLVM_DEBUG (dbgs () << " Live regs was: " ; LiveRegs. dump ( ););
399419
400420 if (!FirstStoreInGroupScheduled && StoresGroup.count (SU))
401421 FirstStoreInGroupScheduled = true ;
0 commit comments