@@ -425,6 +425,8 @@ void dumpDependencies(ScheduleDAGInstrs *DAG, SDep::Kind depType,
425
425
// / live set of MBB, backtrack the DAG and update the live set. Whenever an edge
426
426
// / points to a non-live write, it is updated to the subsequent live write.
427
427
class WAWEdges : public ScheduleDAGMutation {
428
+
429
+ AIEPostRASchedStrategy *Scheduler = nullptr ;
428
430
// Collect all edges in a separate vector. This allows modifying SU.Preds
429
431
// without invalidating iterators.
430
432
SmallVector<SDep, 4 > getPreds (SUnit &SU) {
@@ -446,17 +448,41 @@ class WAWEdges : public ScheduleDAGMutation {
446
448
}
447
449
}
448
450
}
451
+
452
+ public:
453
+ void setScheduler (AIEPostRASchedStrategy *Scheduler) {
454
+ this ->Scheduler = Scheduler;
455
+ }
456
+
449
457
void apply (ScheduleDAGInstrs *DAG) override {
450
458
MachineFunction &MF = DAG->MF ;
451
459
MachineRegisterInfo &MRI = MF.getRegInfo ();
452
460
const TargetRegisterInfo *TRI = MF.getSubtarget ().getRegisterInfo ();
453
461
auto *RI = static_cast <const AIEBaseRegisterInfo *>(TRI);
454
462
LivePhysRegs LiveRegs;
455
463
LiveRegs.init (*TRI);
456
- // Reserved registers are considered always live
457
- for (MCPhysReg PhysReg : MRI.getReservedRegs ().set_bits ()) {
458
- if (RI->isSimplifiableReservedReg (PhysReg))
459
- LiveRegs.addReg (PhysReg);
464
+ bool AddReservedRegs = true ;
465
+ if (Scheduler) {
466
+ MachineBasicBlock *MBB = DAG->getBB ();
467
+ const BlockState &BS = Scheduler->getInterBlock ().getBlockState (MBB);
468
+ auto Region = BS.getCurrentRegion ();
469
+ auto BottomRegion = BS.getBottom ();
470
+ if (*Region.begin () == *BottomRegion.begin ()) {
471
+ // If the region is bottom region, liveouts of region are same as
472
+ // liveouts of the MBB
473
+ for (const MCPhysReg Reg : BS.LiveOuts ) {
474
+ LiveRegs.addReg (Reg);
475
+ }
476
+ AddReservedRegs = false ;
477
+ }
478
+ }
479
+
480
+ if (AddReservedRegs) {
481
+ // Reserved registers are considered always live
482
+ for (const MCPhysReg PhysReg : MRI.getReservedRegs ().set_bits ()) {
483
+ if (RI->isSimplifiableReservedReg (PhysReg))
484
+ LiveRegs.addReg (PhysReg);
485
+ }
460
486
}
461
487
// Stores latest live write of physical register.
462
488
std::map<Register, SUnit *> PhysRegWriters;
@@ -482,6 +508,26 @@ class WAWEdges : public ScheduleDAGMutation {
482
508
};
483
509
};
484
510
511
+ // Adds WAW edges for scheduling in the context of the Scheduler.
512
+ // This class extends WAWEdges to apply WAW edges using a Scheduler if available
513
+ // It overrides the apply method to retrieve the Scheduler from the DAG if a
514
+ // BasicBlock is present, otherwise, it uses nullptr.
515
+ class MachineSchedWAWEdges : public WAWEdges {
516
+ void apply (ScheduleDAGInstrs *DAG) override {
517
+ AIEPostRASchedStrategy *Scheduler =
518
+ DAG->getBB () ? static_cast <AIEScheduleDAGMI *>(DAG)->getSchedImpl ()
519
+ : nullptr ;
520
+ setScheduler (Scheduler);
521
+ WAWEdges::apply (DAG);
522
+ }
523
+ };
524
+
525
+ // This class extends WAWEdges to apply WAW edges without using a Scheduler.
526
+ // This is useful for scenarios where the SWP (Software Pipelining) is performed
527
+ // independently of the Scheduler.
528
+ class SWPWAWEdges : public WAWEdges {
529
+ void apply (ScheduleDAGInstrs *DAG) override { WAWEdges::apply (DAG); }
530
+ };
485
531
} // namespace
486
532
487
533
std::vector<std::unique_ptr<ScheduleDAGMutation>>
@@ -491,7 +537,7 @@ AIEBaseSubtarget::getPostRAMutationsImpl(const Triple &TT) {
491
537
if (!TT.isAIE1 ()) {
492
538
Mutations.emplace_back (std::make_unique<RegionEndEdges>());
493
539
Mutations.emplace_back (std::make_unique<MemoryEdges>());
494
- Mutations.emplace_back (std::make_unique<WAWEdges >());
540
+ Mutations.emplace_back (std::make_unique<MachineSchedWAWEdges >());
495
541
}
496
542
return Mutations;
497
543
}
@@ -504,7 +550,7 @@ AIEBaseSubtarget::getInterBlockMutationsImpl(const Triple &TT) {
504
550
if (!TT.isAIE1 ()) {
505
551
Mutations.emplace_back (std::make_unique<RegionEndEdges>());
506
552
Mutations.emplace_back (std::make_unique<MemoryEdges>());
507
- Mutations.emplace_back (std::make_unique<WAWEdges >());
553
+ Mutations.emplace_back (std::make_unique<MachineSchedWAWEdges >());
508
554
}
509
555
return Mutations;
510
556
}
@@ -523,7 +569,7 @@ std::vector<std::unique_ptr<ScheduleDAGMutation>>
523
569
AIEBaseSubtarget::getSMSMutationsImpl (const Triple &TT) {
524
570
std::vector<std::unique_ptr<ScheduleDAGMutation>> Mutations;
525
571
if (!TT.isAIE1 ()) {
526
- Mutations.emplace_back (std::make_unique<WAWEdges >());
572
+ Mutations.emplace_back (std::make_unique<SWPWAWEdges >());
527
573
if (EnablePipelinerSchedPropagateIncomingLatencies)
528
574
Mutations.emplace_back (std::make_unique<PropagateIncomingLatencies>());
529
575
}
0 commit comments