diff --git a/llvm/lib/CodeGen/MachineScheduler.cpp b/llvm/lib/CodeGen/MachineScheduler.cpp index 52855ceb42809..a148a891a8689 100644 --- a/llvm/lib/CodeGen/MachineScheduler.cpp +++ b/llvm/lib/CodeGen/MachineScheduler.cpp @@ -1598,10 +1598,8 @@ void BaseMemOpClusterMutation::clusterNeighboringMemOps( /// Callback from DAG postProcessing to create cluster edges for loads. void BaseMemOpClusterMutation::apply(ScheduleDAGInstrs *DAG) { - // Map DAG NodeNum to store chain ID. - DenseMap StoreChainIDs; - // Map each store chain to a set of dependent MemOps. - SmallVector, 32> StoreChainDependents; + // Map DAG NodeNum to a set of dependent MemOps in store chain. + DenseMap> StoreChains; for (SUnit &SU : DAG->SUnits) { if ((IsLoad && !SU.getInstr()->mayLoad()) || (!IsLoad && !SU.getInstr()->mayStore())) @@ -1614,19 +1612,14 @@ void BaseMemOpClusterMutation::apply(ScheduleDAGInstrs *DAG) { break; } } - // Check if this chain-like pred has been seen - // before. ChainPredID==MaxNodeID at the top of the schedule. - unsigned NumChains = StoreChainDependents.size(); - std::pair::iterator, bool> Result = - StoreChainIDs.insert(std::make_pair(ChainPredID, NumChains)); - if (Result.second) - StoreChainDependents.resize(NumChains + 1); - StoreChainDependents[Result.first->second].push_back(&SU); + // Insert the SU to corresponding store chain. + auto &Chain = StoreChains.FindAndConstruct(ChainPredID).second; + Chain.push_back(&SU); } // Iterate over the store chains. - for (auto &SCD : StoreChainDependents) - clusterNeighboringMemOps(SCD, DAG); + for (auto &SCD : StoreChains) + clusterNeighboringMemOps(SCD.second, DAG); } //===----------------------------------------------------------------------===//