@@ -195,6 +195,7 @@ bool updateSuccLatency(SDep &SuccEdge, SUnit &PredSU, int Latency) {
195195// The initial graph will have ordering edges induced by hasSideEffects of the
196196// locks/DONE.
197197class LockDelays : public ScheduleDAGMutation {
198+ bool ExactLatencies = true ;
198199 void apply (ScheduleDAGInstrs *DAG) override {
199200 const auto *TII = static_cast <const AIEBaseInstrInfo *>(DAG->TII );
200201 const int CoreStallCycle = TII->getCoreStallCycleAfterLock ();
@@ -218,22 +219,31 @@ class LockDelays : public ScheduleDAGMutation {
218219 continue ;
219220 }
220221 // Ensure memory operation happens before the core stalls
221- int Delay = *TII->getLastMemoryCycle (LdSt->getDesc ().SchedClass ) -
222- CoreStallCycle + 1 ;
222+ auto OptLastMemCycle =
223+ TII->getLastMemoryCycle (LdSt->getDesc ().SchedClass );
224+ assert (!ExactLatencies || OptLastMemCycle);
225+ const int LastMemCycle = OptLastMemCycle.value_or (7 );
226+ const int Delay = LastMemCycle - CoreStallCycle + 1 ;
223227 updatePredLatency (PredEdge, SU, Delay);
224228 }
225229 for (auto &SuccEdge : SU.Succs ) {
226230 MachineInstr *LdSt = SuccEdge.getSUnit ()->getInstr ();
227231 if (SuccEdge.getKind () != SDep::Order || !LdSt->mayLoadOrStore ()) {
228232 continue ;
229233 }
234+ auto OptFirstMemCycle =
235+ TII->getFirstMemoryCycle (LdSt->getDesc ().SchedClass );
236+ assert (!ExactLatencies || OptFirstMemCycle);
237+ const int FirstMemCycle = OptFirstMemCycle.value_or (4 );
230238 // Ensure memory operation happens after the core resumes
231- int Delay = CoreResumeCycle -
232- *TII->getFirstMemoryCycle (LdSt->getDesc ().SchedClass ) + 1 ;
239+ const int Delay = CoreResumeCycle - FirstMemCycle + 1 ;
233240 updateSuccLatency (SuccEdge, SU, Delay);
234241 }
235242 }
236- };
243+ }
244+
245+ public:
246+ LockDelays (bool ExactLatencies) : ExactLatencies(ExactLatencies) {};
237247};
238248
239249#undef DEBUG_TYPE
@@ -649,6 +659,7 @@ class PropagateIncomingLatencies : public ScheduleDAGMutation {
649659// / fix the latencies to preserve the ordering.
650660// / E.g. in AIE2: VST.SRS stores in E7, while VLDA reads in E5.
651661class MemoryEdges : public ScheduleDAGMutation {
662+ bool ExactLatencies = true ;
652663 void apply (ScheduleDAGInstrs *DAG) override {
653664 const auto *TII = static_cast <const AIEBaseInstrInfo *>(DAG->TII );
654665 // Run over all instructions that may load or store, and correct the
@@ -677,16 +688,22 @@ class MemoryEdges : public ScheduleDAGMutation {
677688 // Get the correct latency from the Sched model.
678689 std::optional<int > MemLat = TII->getMemoryLatency (
679690 SrcMI.getDesc ().getSchedClass (), MI.getDesc ().getSchedClass ());
680- if (!MemLat.has_value ()) {
691+ int Latency = 1 ;
692+ if (MemLat.has_value ()) {
693+ Latency = *MemLat;
694+ } else if (ExactLatencies) {
681695 LLVM_DEBUG (llvm::dbgs ()
682696 << " Error: no memory latency info for dependency\n from: "
683697 << SrcMI << " to: " << MI);
684698 report_fatal_error (" Missing memory latency info." );
685699 }
686- updatePredLatency (PredEdge, SU, *MemLat );
700+ updatePredLatency (PredEdge, SU, Latency );
687701 }
688702 }
689- };
703+ }
704+
705+ public:
706+ MemoryEdges (bool ExactLatencies) : ExactLatencies(ExactLatencies) {};
690707};
691708
692709void dumpDependencies (ScheduleDAGInstrs *DAG, SDep::Kind depType,
@@ -865,12 +882,12 @@ class WAWStickyRegistersEdges : public ScheduleDAGMutation {
865882std::vector<std::unique_ptr<ScheduleDAGMutation>>
866883AIEBaseSubtarget::getPostRAMutationsImpl (const Triple &TT) {
867884 std::vector<std::unique_ptr<ScheduleDAGMutation>> Mutations;
868- Mutations.emplace_back (std::make_unique<LockDelays>());
885+ Mutations.emplace_back (std::make_unique<LockDelays>(true ));
869886 if (!TT.isAIE1 ()) {
870887 if (EnableWAWStickyRegisters)
871888 Mutations.emplace_back (std::make_unique<WAWStickyRegistersEdges>());
872889 Mutations.emplace_back (std::make_unique<RegionEndEdges>());
873- Mutations.emplace_back (std::make_unique<MemoryEdges>());
890+ Mutations.emplace_back (std::make_unique<MemoryEdges>(true ));
874891 Mutations.emplace_back (std::make_unique<MachineSchedWAWEdges>());
875892 Mutations.emplace_back (std::make_unique<BiasDepth>());
876893 Mutations.emplace_back (std::make_unique<EmitFixedSUnits>());
@@ -880,12 +897,12 @@ AIEBaseSubtarget::getPostRAMutationsImpl(const Triple &TT) {
880897
881898// List the Mutations that apply to the interblock DAG construction.
882899std::vector<std::unique_ptr<ScheduleDAGMutation>>
883- AIEBaseSubtarget::getInterBlockMutationsImpl (const Triple &TT) {
900+ AIEBaseSubtarget::getDDGMutationsImpl (const Triple &TT, bool ExactLatencies ) {
884901 std::vector<std::unique_ptr<ScheduleDAGMutation>> Mutations;
885- Mutations.emplace_back (std::make_unique<LockDelays>());
902+ Mutations.emplace_back (std::make_unique<LockDelays>(ExactLatencies ));
886903 if (!TT.isAIE1 ()) {
887904 Mutations.emplace_back (std::make_unique<RegionEndEdges>());
888- Mutations.emplace_back (std::make_unique<MemoryEdges>());
905+ Mutations.emplace_back (std::make_unique<MemoryEdges>(ExactLatencies ));
889906 Mutations.emplace_back (std::make_unique<MachineSchedWAWEdges>());
890907 }
891908 return Mutations;
0 commit comments