Dan Gohman | 23785a1 | 2008-08-12 17:42:33 +0000 | [diff] [blame] | 1 | //===----- ScheduleDAGRRList.cpp - Reg pressure reduction list scheduler --===// |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This implements bottom-up and top-down register pressure reduction list |
| 11 | // schedulers, using standard algorithms. The basic approach uses a priority |
| 12 | // queue of available nodes to schedule. One at a time, nodes are taken from |
| 13 | // the priority queue (thus in priority order), checked for legality to |
| 14 | // schedule, and emitted if legal. |
| 15 | // |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | |
Dale Johannesen | 2182f06 | 2007-07-13 17:13:54 +0000 | [diff] [blame] | 18 | #define DEBUG_TYPE "pre-RA-sched" |
Dan Gohman | 483377c | 2009-02-06 17:22:58 +0000 | [diff] [blame] | 19 | #include "ScheduleDAGSDNodes.h" |
Jim Laskey | 29e635d | 2006-08-02 12:30:23 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/SchedulerRegistry.h" |
Dan Gohman | 619ef48 | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/SelectionDAGISel.h" |
Dan Gohman | 3a4be0f | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 22 | #include "llvm/Target/TargetRegisterInfo.h" |
Owen Anderson | 8c2c1e9 | 2006-05-12 06:33:49 +0000 | [diff] [blame] | 23 | #include "llvm/Target/TargetData.h" |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 24 | #include "llvm/Target/TargetMachine.h" |
| 25 | #include "llvm/Target/TargetInstrInfo.h" |
| 26 | #include "llvm/Support/Debug.h" |
Chris Lattner | 3d27be1 | 2006-08-27 12:54:02 +0000 | [diff] [blame] | 27 | #include "llvm/Support/Compiler.h" |
Torok Edwin | 56d0659 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 28 | #include "llvm/Support/ErrorHandling.h" |
Dan Gohman | a4db335 | 2008-06-21 18:35:25 +0000 | [diff] [blame] | 29 | #include "llvm/ADT/PriorityQueue.h" |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/SmallSet.h" |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/Statistic.h" |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 32 | #include "llvm/ADT/STLExtras.h" |
Chris Lattner | 4dc3edd | 2009-08-23 06:35:02 +0000 | [diff] [blame^] | 33 | #include "llvm/Support/raw_ostream.h" |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 34 | #include <climits> |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 35 | using namespace llvm; |
| 36 | |
Dan Gohman | fd227e9 | 2008-03-25 17:10:29 +0000 | [diff] [blame] | 37 | STATISTIC(NumBacktracks, "Number of times scheduler backtracked"); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 38 | STATISTIC(NumUnfolds, "Number of nodes unfolded"); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 39 | STATISTIC(NumDups, "Number of duplicated nodes"); |
Evan Cheng | b2c42c6 | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 40 | STATISTIC(NumPRCopies, "Number of physical register copies"); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 41 | |
Jim Laskey | 95eda5b | 2006-08-01 14:21:23 +0000 | [diff] [blame] | 42 | static RegisterScheduler |
| 43 | burrListDAGScheduler("list-burr", |
Dan Gohman | 9c4b7d5 | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 44 | "Bottom-up register reduction list scheduling", |
Jim Laskey | 95eda5b | 2006-08-01 14:21:23 +0000 | [diff] [blame] | 45 | createBURRListDAGScheduler); |
| 46 | static RegisterScheduler |
| 47 | tdrListrDAGScheduler("list-tdrr", |
Dan Gohman | 9c4b7d5 | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 48 | "Top-down register reduction list scheduling", |
Jim Laskey | 95eda5b | 2006-08-01 14:21:23 +0000 | [diff] [blame] | 49 | createTDRRListDAGScheduler); |
| 50 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 51 | namespace { |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 52 | //===----------------------------------------------------------------------===// |
| 53 | /// ScheduleDAGRRList - The actual register reduction list scheduler |
| 54 | /// implementation. This supports both top-down and bottom-up scheduling. |
| 55 | /// |
Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 56 | class VISIBILITY_HIDDEN ScheduleDAGRRList : public ScheduleDAGSDNodes { |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 57 | private: |
| 58 | /// isBottomUp - This is true if the scheduling problem is bottom-up, false if |
| 59 | /// it is top-down. |
| 60 | bool isBottomUp; |
Evan Cheng | 2c97731 | 2008-07-01 18:05:03 +0000 | [diff] [blame] | 61 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 62 | /// AvailableQueue - The priority queue to use for the available SUnits. |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 63 | SchedulingPriorityQueue *AvailableQueue; |
| 64 | |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 65 | /// LiveRegDefs - A set of physical registers and their definition |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 66 | /// that are "live". These nodes must be scheduled before any other nodes that |
| 67 | /// modifies the registers can be scheduled. |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 68 | unsigned NumLiveRegs; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 69 | std::vector<SUnit*> LiveRegDefs; |
| 70 | std::vector<unsigned> LiveRegCycles; |
| 71 | |
Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 72 | /// Topo - A topological ordering for SUnits which permits fast IsReachable |
| 73 | /// and similar queries. |
| 74 | ScheduleDAGTopologicalSort Topo; |
| 75 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 76 | public: |
Dan Gohman | 619ef48 | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 77 | ScheduleDAGRRList(MachineFunction &mf, |
| 78 | bool isbottomup, |
Evan Cheng | 2c97731 | 2008-07-01 18:05:03 +0000 | [diff] [blame] | 79 | SchedulingPriorityQueue *availqueue) |
Dan Gohman | 619ef48 | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 80 | : ScheduleDAGSDNodes(mf), isBottomUp(isbottomup), |
Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 81 | AvailableQueue(availqueue), Topo(SUnits) { |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | ~ScheduleDAGRRList() { |
| 85 | delete AvailableQueue; |
| 86 | } |
| 87 | |
| 88 | void Schedule(); |
| 89 | |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 90 | /// IsReachable - Checks if SU is reachable from TargetSU. |
Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 91 | bool IsReachable(const SUnit *SU, const SUnit *TargetSU) { |
| 92 | return Topo.IsReachable(SU, TargetSU); |
| 93 | } |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 94 | |
Dan Gohman | 60d6844 | 2009-01-29 19:49:27 +0000 | [diff] [blame] | 95 | /// WillCreateCycle - Returns true if adding an edge from SU to TargetSU will |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 96 | /// create a cycle. |
Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 97 | bool WillCreateCycle(SUnit *SU, SUnit *TargetSU) { |
| 98 | return Topo.WillCreateCycle(SU, TargetSU); |
| 99 | } |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 100 | |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 101 | /// AddPred - adds a predecessor edge to SUnit SU. |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 102 | /// This returns true if this is a new predecessor. |
| 103 | /// Updates the topological ordering if required. |
Dan Gohman | 17214e6 | 2008-12-16 01:00:55 +0000 | [diff] [blame] | 104 | void AddPred(SUnit *SU, const SDep &D) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 105 | Topo.AddPred(SU, D.getSUnit()); |
Dan Gohman | 17214e6 | 2008-12-16 01:00:55 +0000 | [diff] [blame] | 106 | SU->addPred(D); |
Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 107 | } |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 108 | |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 109 | /// RemovePred - removes a predecessor edge from SUnit SU. |
| 110 | /// This returns true if an edge was removed. |
| 111 | /// Updates the topological ordering if required. |
Dan Gohman | 17214e6 | 2008-12-16 01:00:55 +0000 | [diff] [blame] | 112 | void RemovePred(SUnit *SU, const SDep &D) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 113 | Topo.RemovePred(SU, D.getSUnit()); |
Dan Gohman | 17214e6 | 2008-12-16 01:00:55 +0000 | [diff] [blame] | 114 | SU->removePred(D); |
Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 115 | } |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 116 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 117 | private: |
Dan Gohman | 60d6844 | 2009-01-29 19:49:27 +0000 | [diff] [blame] | 118 | void ReleasePred(SUnit *SU, const SDep *PredEdge); |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 119 | void ReleasePredecessors(SUnit *SU, unsigned CurCycle); |
Dan Gohman | 60d6844 | 2009-01-29 19:49:27 +0000 | [diff] [blame] | 120 | void ReleaseSucc(SUnit *SU, const SDep *SuccEdge); |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 121 | void ReleaseSuccessors(SUnit *SU); |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 122 | void CapturePred(SDep *PredEdge); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 123 | void ScheduleNodeBottomUp(SUnit*, unsigned); |
| 124 | void ScheduleNodeTopDown(SUnit*, unsigned); |
| 125 | void UnscheduleNodeBottomUp(SUnit*); |
| 126 | void BacktrackBottomUp(SUnit*, unsigned, unsigned&); |
| 127 | SUnit *CopyAndMoveSuccessors(SUnit*); |
Evan Cheng | b2c42c6 | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 128 | void InsertCopiesAndMoveSuccs(SUnit*, unsigned, |
| 129 | const TargetRegisterClass*, |
| 130 | const TargetRegisterClass*, |
| 131 | SmallVector<SUnit*, 2>&); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 132 | bool DelayForLiveRegsBottomUp(SUnit*, SmallVector<unsigned, 4>&); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 133 | void ListScheduleTopDown(); |
| 134 | void ListScheduleBottomUp(); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 135 | |
| 136 | |
| 137 | /// CreateNewSUnit - Creates a new SUnit and returns a pointer to it. |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 138 | /// Updates the topological ordering if required. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 139 | SUnit *CreateNewSUnit(SDNode *N) { |
Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 140 | unsigned NumSUnits = SUnits.size(); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 141 | SUnit *NewNode = NewSUnit(N); |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 142 | // Update the topological ordering. |
Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 143 | if (NewNode->NodeNum >= NumSUnits) |
| 144 | Topo.InitDAGTopologicalSorting(); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 145 | return NewNode; |
| 146 | } |
| 147 | |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 148 | /// CreateClone - Creates a new SUnit from an existing one. |
| 149 | /// Updates the topological ordering if required. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 150 | SUnit *CreateClone(SUnit *N) { |
Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 151 | unsigned NumSUnits = SUnits.size(); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 152 | SUnit *NewNode = Clone(N); |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 153 | // Update the topological ordering. |
Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 154 | if (NewNode->NodeNum >= NumSUnits) |
| 155 | Topo.InitDAGTopologicalSorting(); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 156 | return NewNode; |
| 157 | } |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 158 | |
| 159 | /// ForceUnitLatencies - Return true, since register-pressure-reducing |
| 160 | /// scheduling doesn't need actual latency information. |
| 161 | bool ForceUnitLatencies() const { return true; } |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 162 | }; |
| 163 | } // end anonymous namespace |
| 164 | |
| 165 | |
| 166 | /// Schedule - Schedule the DAG using list scheduling. |
| 167 | void ScheduleDAGRRList::Schedule() { |
Chris Lattner | 4dc3edd | 2009-08-23 06:35:02 +0000 | [diff] [blame^] | 168 | DEBUG(errs() << "********** List Scheduling **********\n"); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 169 | |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 170 | NumLiveRegs = 0; |
Dan Gohman | 3a4be0f | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 171 | LiveRegDefs.resize(TRI->getNumRegs(), NULL); |
| 172 | LiveRegCycles.resize(TRI->getNumRegs(), 0); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 173 | |
Dan Gohman | 04543e7 | 2008-12-23 18:36:58 +0000 | [diff] [blame] | 174 | // Build the scheduling graph. |
| 175 | BuildSchedGraph(); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 176 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 177 | DEBUG(for (unsigned su = 0, e = SUnits.size(); su != e; ++su) |
Dan Gohman | 22d07b1 | 2008-11-18 02:06:40 +0000 | [diff] [blame] | 178 | SUnits[su].dumpAll(this)); |
Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 179 | Topo.InitDAGTopologicalSorting(); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 180 | |
Dan Gohman | 46520a2 | 2008-06-21 19:18:17 +0000 | [diff] [blame] | 181 | AvailableQueue->initNodes(SUnits); |
Dan Gohman | 54a187e | 2007-08-20 19:28:38 +0000 | [diff] [blame] | 182 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 183 | // Execute the actual scheduling loop Top-Down or Bottom-Up as appropriate. |
| 184 | if (isBottomUp) |
| 185 | ListScheduleBottomUp(); |
| 186 | else |
| 187 | ListScheduleTopDown(); |
| 188 | |
| 189 | AvailableQueue->releaseState(); |
Evan Cheng | afed73e | 2006-05-12 01:58:24 +0000 | [diff] [blame] | 190 | } |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 191 | |
| 192 | //===----------------------------------------------------------------------===// |
| 193 | // Bottom-Up Scheduling |
| 194 | //===----------------------------------------------------------------------===// |
| 195 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 196 | /// ReleasePred - Decrement the NumSuccsLeft count of a predecessor. Add it to |
Dan Gohman | 54a187e | 2007-08-20 19:28:38 +0000 | [diff] [blame] | 197 | /// the AvailableQueue if the count reaches zero. Also update its cycle bound. |
Dan Gohman | 60d6844 | 2009-01-29 19:49:27 +0000 | [diff] [blame] | 198 | void ScheduleDAGRRList::ReleasePred(SUnit *SU, const SDep *PredEdge) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 199 | SUnit *PredSU = PredEdge->getSUnit(); |
Evan Cheng | 038dcc5 | 2007-09-28 19:24:24 +0000 | [diff] [blame] | 200 | --PredSU->NumSuccsLeft; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 201 | |
| 202 | #ifndef NDEBUG |
Evan Cheng | 038dcc5 | 2007-09-28 19:24:24 +0000 | [diff] [blame] | 203 | if (PredSU->NumSuccsLeft < 0) { |
Dan Gohman | 5ebdb98 | 2008-11-18 00:38:59 +0000 | [diff] [blame] | 204 | cerr << "*** Scheduling failed! ***\n"; |
Dan Gohman | 22d07b1 | 2008-11-18 02:06:40 +0000 | [diff] [blame] | 205 | PredSU->dump(this); |
Bill Wendling | 22e978a | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 206 | cerr << " has been released too many times!\n"; |
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 207 | llvm_unreachable(0); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 208 | } |
| 209 | #endif |
| 210 | |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 211 | // If all the node's successors are scheduled, this node is ready |
| 212 | // to be scheduled. Ignore the special EntrySU node. |
| 213 | if (PredSU->NumSuccsLeft == 0 && PredSU != &EntrySU) { |
Dan Gohman | 4370f26 | 2008-04-15 01:22:18 +0000 | [diff] [blame] | 214 | PredSU->isAvailable = true; |
| 215 | AvailableQueue->push(PredSU); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 219 | void ScheduleDAGRRList::ReleasePredecessors(SUnit *SU, unsigned CurCycle) { |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 220 | // Bottom up: release predecessors |
Chris Lattner | d86418a | 2006-08-17 00:09:56 +0000 | [diff] [blame] | 221 | for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 222 | I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 223 | ReleasePred(SU, &*I); |
| 224 | if (I->isAssignedRegDep()) { |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 225 | // This is a physical register dependency and it's impossible or |
| 226 | // expensive to copy the register. Make sure nothing that can |
| 227 | // clobber the register is scheduled between the predecessor and |
| 228 | // this node. |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 229 | if (!LiveRegDefs[I->getReg()]) { |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 230 | ++NumLiveRegs; |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 231 | LiveRegDefs[I->getReg()] = I->getSUnit(); |
| 232 | LiveRegCycles[I->getReg()] = CurCycle; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | } |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | /// ScheduleNodeBottomUp - Add the node to the schedule. Decrement the pending |
| 239 | /// count of its predecessors. If a predecessor pending count is zero, add it to |
| 240 | /// the Available queue. |
| 241 | void ScheduleDAGRRList::ScheduleNodeBottomUp(SUnit *SU, unsigned CurCycle) { |
Chris Lattner | 4dc3edd | 2009-08-23 06:35:02 +0000 | [diff] [blame^] | 242 | DEBUG(errs() << "*** Scheduling [" << CurCycle << "]: "); |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 243 | DEBUG(SU->dump(this)); |
| 244 | |
| 245 | assert(CurCycle >= SU->getHeight() && "Node scheduled below its height!"); |
| 246 | SU->setHeightToAtLeast(CurCycle); |
| 247 | Sequence.push_back(SU); |
| 248 | |
| 249 | ReleasePredecessors(SU, CurCycle); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 250 | |
| 251 | // Release all the implicit physical register defs that are live. |
| 252 | for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 253 | I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 254 | if (I->isAssignedRegDep()) { |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 255 | if (LiveRegCycles[I->getReg()] == I->getSUnit()->getHeight()) { |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 256 | assert(NumLiveRegs > 0 && "NumLiveRegs is already zero!"); |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 257 | assert(LiveRegDefs[I->getReg()] == SU && |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 258 | "Physical register dependency violated?"); |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 259 | --NumLiveRegs; |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 260 | LiveRegDefs[I->getReg()] = NULL; |
| 261 | LiveRegCycles[I->getReg()] = 0; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | } |
| 265 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 266 | SU->isScheduled = true; |
Dan Gohman | 6e58726 | 2008-11-18 21:22:20 +0000 | [diff] [blame] | 267 | AvailableQueue->ScheduledNode(SU); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 270 | /// CapturePred - This does the opposite of ReleasePred. Since SU is being |
| 271 | /// unscheduled, incrcease the succ left count of its predecessors. Remove |
| 272 | /// them from AvailableQueue if necessary. |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 273 | void ScheduleDAGRRList::CapturePred(SDep *PredEdge) { |
| 274 | SUnit *PredSU = PredEdge->getSUnit(); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 275 | if (PredSU->isAvailable) { |
| 276 | PredSU->isAvailable = false; |
| 277 | if (!PredSU->isPending) |
| 278 | AvailableQueue->remove(PredSU); |
| 279 | } |
| 280 | |
Evan Cheng | 038dcc5 | 2007-09-28 19:24:24 +0000 | [diff] [blame] | 281 | ++PredSU->NumSuccsLeft; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | /// UnscheduleNodeBottomUp - Remove the node from the schedule, update its and |
| 285 | /// its predecessor states to reflect the change. |
| 286 | void ScheduleDAGRRList::UnscheduleNodeBottomUp(SUnit *SU) { |
Chris Lattner | 4dc3edd | 2009-08-23 06:35:02 +0000 | [diff] [blame^] | 287 | DEBUG(errs() << "*** Unscheduling [" << SU->getHeight() << "]: "); |
Dan Gohman | 22d07b1 | 2008-11-18 02:06:40 +0000 | [diff] [blame] | 288 | DEBUG(SU->dump(this)); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 289 | |
| 290 | AvailableQueue->UnscheduledNode(SU); |
| 291 | |
| 292 | for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
| 293 | I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 294 | CapturePred(&*I); |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 295 | if (I->isAssignedRegDep() && SU->getHeight() == LiveRegCycles[I->getReg()]) { |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 296 | assert(NumLiveRegs > 0 && "NumLiveRegs is already zero!"); |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 297 | assert(LiveRegDefs[I->getReg()] == I->getSUnit() && |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 298 | "Physical register dependency violated?"); |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 299 | --NumLiveRegs; |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 300 | LiveRegDefs[I->getReg()] = NULL; |
| 301 | LiveRegCycles[I->getReg()] = 0; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | |
| 305 | for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 306 | I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 307 | if (I->isAssignedRegDep()) { |
| 308 | if (!LiveRegDefs[I->getReg()]) { |
| 309 | LiveRegDefs[I->getReg()] = SU; |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 310 | ++NumLiveRegs; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 311 | } |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 312 | if (I->getSUnit()->getHeight() < LiveRegCycles[I->getReg()]) |
| 313 | LiveRegCycles[I->getReg()] = I->getSUnit()->getHeight(); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 317 | SU->setHeightDirty(); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 318 | SU->isScheduled = false; |
| 319 | SU->isAvailable = true; |
| 320 | AvailableQueue->push(SU); |
| 321 | } |
| 322 | |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 323 | /// BacktrackBottomUp - Backtrack scheduling to a previous cycle specified in |
Dan Gohman | 60d6844 | 2009-01-29 19:49:27 +0000 | [diff] [blame] | 324 | /// BTCycle in order to schedule a specific node. |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 325 | void ScheduleDAGRRList::BacktrackBottomUp(SUnit *SU, unsigned BtCycle, |
| 326 | unsigned &CurCycle) { |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 327 | SUnit *OldSU = NULL; |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 328 | while (CurCycle > BtCycle) { |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 329 | OldSU = Sequence.back(); |
| 330 | Sequence.pop_back(); |
| 331 | if (SU->isSucc(OldSU)) |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 332 | // Don't try to remove SU from AvailableQueue. |
| 333 | SU->isAvailable = false; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 334 | UnscheduleNodeBottomUp(OldSU); |
| 335 | --CurCycle; |
| 336 | } |
| 337 | |
Dan Gohman | 60d6844 | 2009-01-29 19:49:27 +0000 | [diff] [blame] | 338 | assert(!SU->isSucc(OldSU) && "Something is wrong!"); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 339 | |
| 340 | ++NumBacktracks; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 341 | } |
| 342 | |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 343 | /// CopyAndMoveSuccessors - Clone the specified node and move its scheduled |
| 344 | /// successors to the newly created node. |
| 345 | SUnit *ScheduleDAGRRList::CopyAndMoveSuccessors(SUnit *SU) { |
Dan Gohman | 072734e | 2008-11-13 23:24:17 +0000 | [diff] [blame] | 346 | if (SU->getNode()->getFlaggedNode()) |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 347 | return NULL; |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 348 | |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 349 | SDNode *N = SU->getNode(); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 350 | if (!N) |
| 351 | return NULL; |
| 352 | |
| 353 | SUnit *NewSU; |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 354 | bool TryUnfold = false; |
Evan Cheng | 84d0ebc | 2007-10-05 01:42:35 +0000 | [diff] [blame] | 355 | for (unsigned i = 0, e = N->getNumValues(); i != e; ++i) { |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 356 | EVT VT = N->getValueType(i); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 357 | if (VT == MVT::Flag) |
Evan Cheng | 84d0ebc | 2007-10-05 01:42:35 +0000 | [diff] [blame] | 358 | return NULL; |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 359 | else if (VT == MVT::Other) |
Evan Cheng | 84d0ebc | 2007-10-05 01:42:35 +0000 | [diff] [blame] | 360 | TryUnfold = true; |
| 361 | } |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 362 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 363 | const SDValue &Op = N->getOperand(i); |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 364 | EVT VT = Op.getNode()->getValueType(Op.getResNo()); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 365 | if (VT == MVT::Flag) |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 366 | return NULL; |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | if (TryUnfold) { |
Dan Gohman | e6e1348 | 2008-06-21 15:52:51 +0000 | [diff] [blame] | 370 | SmallVector<SDNode*, 2> NewNodes; |
Dan Gohman | 5a390b9 | 2008-11-13 21:21:28 +0000 | [diff] [blame] | 371 | if (!TII->unfoldMemoryOperand(*DAG, N, NewNodes)) |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 372 | return NULL; |
| 373 | |
Chris Lattner | 4dc3edd | 2009-08-23 06:35:02 +0000 | [diff] [blame^] | 374 | DEBUG(errs() << "Unfolding SU # " << SU->NodeNum << "\n"); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 375 | assert(NewNodes.size() == 2 && "Expected a load folding node!"); |
| 376 | |
| 377 | N = NewNodes[1]; |
| 378 | SDNode *LoadNode = NewNodes[0]; |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 379 | unsigned NumVals = N->getNumValues(); |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 380 | unsigned OldNumVals = SU->getNode()->getNumValues(); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 381 | for (unsigned i = 0; i != NumVals; ++i) |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 382 | DAG->ReplaceAllUsesOfValueWith(SDValue(SU->getNode(), i), SDValue(N, i)); |
| 383 | DAG->ReplaceAllUsesOfValueWith(SDValue(SU->getNode(), OldNumVals-1), |
Dan Gohman | 5a390b9 | 2008-11-13 21:21:28 +0000 | [diff] [blame] | 384 | SDValue(LoadNode, 1)); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 385 | |
Dan Gohman | e52e089 | 2008-11-11 21:34:44 +0000 | [diff] [blame] | 386 | // LoadNode may already exist. This can happen when there is another |
| 387 | // load from the same location and producing the same type of value |
| 388 | // but it has different alignment or volatileness. |
| 389 | bool isNewLoad = true; |
| 390 | SUnit *LoadSU; |
| 391 | if (LoadNode->getNodeId() != -1) { |
| 392 | LoadSU = &SUnits[LoadNode->getNodeId()]; |
| 393 | isNewLoad = false; |
| 394 | } else { |
| 395 | LoadSU = CreateNewSUnit(LoadNode); |
| 396 | LoadNode->setNodeId(LoadSU->NodeNum); |
Dan Gohman | e52e089 | 2008-11-11 21:34:44 +0000 | [diff] [blame] | 397 | ComputeLatency(LoadSU); |
| 398 | } |
| 399 | |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 400 | SUnit *NewSU = CreateNewSUnit(N); |
Dan Gohman | 46520a2 | 2008-06-21 19:18:17 +0000 | [diff] [blame] | 401 | assert(N->getNodeId() == -1 && "Node already inserted!"); |
| 402 | N->setNodeId(NewSU->NodeNum); |
Dan Gohman | e6e1348 | 2008-06-21 15:52:51 +0000 | [diff] [blame] | 403 | |
Dan Gohman | 1705968 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 404 | const TargetInstrDesc &TID = TII->get(N->getMachineOpcode()); |
Dan Gohman | 856c012 | 2008-02-16 00:25:40 +0000 | [diff] [blame] | 405 | for (unsigned i = 0; i != TID.getNumOperands(); ++i) { |
Chris Lattner | fd2e338 | 2008-01-07 06:47:00 +0000 | [diff] [blame] | 406 | if (TID.getOperandConstraint(i, TOI::TIED_TO) != -1) { |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 407 | NewSU->isTwoAddress = true; |
| 408 | break; |
| 409 | } |
| 410 | } |
Chris Lattner | fd2e338 | 2008-01-07 06:47:00 +0000 | [diff] [blame] | 411 | if (TID.isCommutable()) |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 412 | NewSU->isCommutable = true; |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 413 | ComputeLatency(NewSU); |
| 414 | |
Dan Gohman | ed0e8d4 | 2009-03-23 20:20:43 +0000 | [diff] [blame] | 415 | // Record all the edges to and from the old SU, by category. |
Dan Gohman | 15af552 | 2009-03-06 02:23:01 +0000 | [diff] [blame] | 416 | SmallVector<SDep, 4> ChainPreds; |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 417 | SmallVector<SDep, 4> ChainSuccs; |
| 418 | SmallVector<SDep, 4> LoadPreds; |
| 419 | SmallVector<SDep, 4> NodePreds; |
| 420 | SmallVector<SDep, 4> NodeSuccs; |
| 421 | for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
| 422 | I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 423 | if (I->isCtrl()) |
Dan Gohman | 15af552 | 2009-03-06 02:23:01 +0000 | [diff] [blame] | 424 | ChainPreds.push_back(*I); |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 425 | else if (I->getSUnit()->getNode() && |
| 426 | I->getSUnit()->getNode()->isOperandOf(LoadNode)) |
| 427 | LoadPreds.push_back(*I); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 428 | else |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 429 | NodePreds.push_back(*I); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 430 | } |
| 431 | for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 432 | I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 433 | if (I->isCtrl()) |
| 434 | ChainSuccs.push_back(*I); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 435 | else |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 436 | NodeSuccs.push_back(*I); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 437 | } |
| 438 | |
Dan Gohman | ed0e8d4 | 2009-03-23 20:20:43 +0000 | [diff] [blame] | 439 | // Now assign edges to the newly-created nodes. |
Dan Gohman | 15af552 | 2009-03-06 02:23:01 +0000 | [diff] [blame] | 440 | for (unsigned i = 0, e = ChainPreds.size(); i != e; ++i) { |
| 441 | const SDep &Pred = ChainPreds[i]; |
| 442 | RemovePred(SU, Pred); |
Dan Gohman | 4370f26 | 2008-04-15 01:22:18 +0000 | [diff] [blame] | 443 | if (isNewLoad) |
Dan Gohman | 15af552 | 2009-03-06 02:23:01 +0000 | [diff] [blame] | 444 | AddPred(LoadSU, Pred); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 445 | } |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 446 | for (unsigned i = 0, e = LoadPreds.size(); i != e; ++i) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 447 | const SDep &Pred = LoadPreds[i]; |
| 448 | RemovePred(SU, Pred); |
Dan Gohman | 15af552 | 2009-03-06 02:23:01 +0000 | [diff] [blame] | 449 | if (isNewLoad) |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 450 | AddPred(LoadSU, Pred); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 451 | } |
| 452 | for (unsigned i = 0, e = NodePreds.size(); i != e; ++i) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 453 | const SDep &Pred = NodePreds[i]; |
| 454 | RemovePred(SU, Pred); |
| 455 | AddPred(NewSU, Pred); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 456 | } |
| 457 | for (unsigned i = 0, e = NodeSuccs.size(); i != e; ++i) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 458 | SDep D = NodeSuccs[i]; |
| 459 | SUnit *SuccDep = D.getSUnit(); |
| 460 | D.setSUnit(SU); |
| 461 | RemovePred(SuccDep, D); |
| 462 | D.setSUnit(NewSU); |
| 463 | AddPred(SuccDep, D); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 464 | } |
| 465 | for (unsigned i = 0, e = ChainSuccs.size(); i != e; ++i) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 466 | SDep D = ChainSuccs[i]; |
| 467 | SUnit *SuccDep = D.getSUnit(); |
| 468 | D.setSUnit(SU); |
| 469 | RemovePred(SuccDep, D); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 470 | if (isNewLoad) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 471 | D.setSUnit(LoadSU); |
| 472 | AddPred(SuccDep, D); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 473 | } |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 474 | } |
Dan Gohman | ed0e8d4 | 2009-03-23 20:20:43 +0000 | [diff] [blame] | 475 | |
| 476 | // Add a data dependency to reflect that NewSU reads the value defined |
| 477 | // by LoadSU. |
| 478 | AddPred(NewSU, SDep(LoadSU, SDep::Data, LoadSU->Latency)); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 479 | |
Evan Cheng | 91e0fc9 | 2007-12-18 08:42:10 +0000 | [diff] [blame] | 480 | if (isNewLoad) |
| 481 | AvailableQueue->addNode(LoadSU); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 482 | AvailableQueue->addNode(NewSU); |
| 483 | |
| 484 | ++NumUnfolds; |
| 485 | |
| 486 | if (NewSU->NumSuccsLeft == 0) { |
| 487 | NewSU->isAvailable = true; |
| 488 | return NewSU; |
Evan Cheng | 91e0fc9 | 2007-12-18 08:42:10 +0000 | [diff] [blame] | 489 | } |
| 490 | SU = NewSU; |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 491 | } |
| 492 | |
Chris Lattner | 4dc3edd | 2009-08-23 06:35:02 +0000 | [diff] [blame^] | 493 | DEBUG(errs() << "Duplicating SU # " << SU->NodeNum << "\n"); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 494 | NewSU = CreateClone(SU); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 495 | |
| 496 | // New SUnit has the exact same predecessors. |
| 497 | for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
| 498 | I != E; ++I) |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 499 | if (!I->isArtificial()) |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 500 | AddPred(NewSU, *I); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 501 | |
| 502 | // Only copy scheduled successors. Cut them from old node's successor |
| 503 | // list and move them over. |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 504 | SmallVector<std::pair<SUnit *, SDep>, 4> DelDeps; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 505 | for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 506 | I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 507 | if (I->isArtificial()) |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 508 | continue; |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 509 | SUnit *SuccSU = I->getSUnit(); |
| 510 | if (SuccSU->isScheduled) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 511 | SDep D = *I; |
| 512 | D.setSUnit(NewSU); |
| 513 | AddPred(SuccSU, D); |
| 514 | D.setSUnit(SU); |
| 515 | DelDeps.push_back(std::make_pair(SuccSU, D)); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 516 | } |
| 517 | } |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 518 | for (unsigned i = 0, e = DelDeps.size(); i != e; ++i) |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 519 | RemovePred(DelDeps[i].first, DelDeps[i].second); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 520 | |
| 521 | AvailableQueue->updateNode(SU); |
| 522 | AvailableQueue->addNode(NewSU); |
| 523 | |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 524 | ++NumDups; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 525 | return NewSU; |
| 526 | } |
| 527 | |
Evan Cheng | b2c42c6 | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 528 | /// InsertCopiesAndMoveSuccs - Insert register copies and move all |
| 529 | /// scheduled successors of the given SUnit to the last copy. |
| 530 | void ScheduleDAGRRList::InsertCopiesAndMoveSuccs(SUnit *SU, unsigned Reg, |
| 531 | const TargetRegisterClass *DestRC, |
| 532 | const TargetRegisterClass *SrcRC, |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 533 | SmallVector<SUnit*, 2> &Copies) { |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 534 | SUnit *CopyFromSU = CreateNewSUnit(NULL); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 535 | CopyFromSU->CopySrcRC = SrcRC; |
| 536 | CopyFromSU->CopyDstRC = DestRC; |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 537 | |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 538 | SUnit *CopyToSU = CreateNewSUnit(NULL); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 539 | CopyToSU->CopySrcRC = DestRC; |
| 540 | CopyToSU->CopyDstRC = SrcRC; |
| 541 | |
| 542 | // Only copy scheduled successors. Cut them from old node's successor |
| 543 | // list and move them over. |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 544 | SmallVector<std::pair<SUnit *, SDep>, 4> DelDeps; |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 545 | for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 546 | I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 547 | if (I->isArtificial()) |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 548 | continue; |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 549 | SUnit *SuccSU = I->getSUnit(); |
| 550 | if (SuccSU->isScheduled) { |
| 551 | SDep D = *I; |
| 552 | D.setSUnit(CopyToSU); |
| 553 | AddPred(SuccSU, D); |
| 554 | DelDeps.push_back(std::make_pair(SuccSU, *I)); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 555 | } |
| 556 | } |
Evan Cheng | b2c42c6 | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 557 | for (unsigned i = 0, e = DelDeps.size(); i != e; ++i) |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 558 | RemovePred(DelDeps[i].first, DelDeps[i].second); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 559 | |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 560 | AddPred(CopyFromSU, SDep(SU, SDep::Data, SU->Latency, Reg)); |
| 561 | AddPred(CopyToSU, SDep(CopyFromSU, SDep::Data, CopyFromSU->Latency, 0)); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 562 | |
| 563 | AvailableQueue->updateNode(SU); |
| 564 | AvailableQueue->addNode(CopyFromSU); |
| 565 | AvailableQueue->addNode(CopyToSU); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 566 | Copies.push_back(CopyFromSU); |
| 567 | Copies.push_back(CopyToSU); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 568 | |
Evan Cheng | b2c42c6 | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 569 | ++NumPRCopies; |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | /// getPhysicalRegisterVT - Returns the ValueType of the physical register |
| 573 | /// definition of the specified node. |
| 574 | /// FIXME: Move to SelectionDAG? |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 575 | static EVT getPhysicalRegisterVT(SDNode *N, unsigned Reg, |
Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 576 | const TargetInstrInfo *TII) { |
Dan Gohman | 1705968 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 577 | const TargetInstrDesc &TID = TII->get(N->getMachineOpcode()); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 578 | assert(TID.ImplicitDefs && "Physical reg def must be in implicit def list!"); |
Chris Lattner | b0d06b4 | 2008-01-07 03:13:06 +0000 | [diff] [blame] | 579 | unsigned NumRes = TID.getNumDefs(); |
| 580 | for (const unsigned *ImpDef = TID.getImplicitDefs(); *ImpDef; ++ImpDef) { |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 581 | if (Reg == *ImpDef) |
| 582 | break; |
| 583 | ++NumRes; |
| 584 | } |
| 585 | return N->getValueType(NumRes); |
| 586 | } |
| 587 | |
Evan Cheng | b8905c4 | 2009-03-04 01:41:49 +0000 | [diff] [blame] | 588 | /// CheckForLiveRegDef - Return true and update live register vector if the |
| 589 | /// specified register def of the specified SUnit clobbers any "live" registers. |
| 590 | static bool CheckForLiveRegDef(SUnit *SU, unsigned Reg, |
| 591 | std::vector<SUnit*> &LiveRegDefs, |
| 592 | SmallSet<unsigned, 4> &RegAdded, |
| 593 | SmallVector<unsigned, 4> &LRegs, |
| 594 | const TargetRegisterInfo *TRI) { |
| 595 | bool Added = false; |
| 596 | if (LiveRegDefs[Reg] && LiveRegDefs[Reg] != SU) { |
| 597 | if (RegAdded.insert(Reg)) { |
| 598 | LRegs.push_back(Reg); |
| 599 | Added = true; |
| 600 | } |
| 601 | } |
| 602 | for (const unsigned *Alias = TRI->getAliasSet(Reg); *Alias; ++Alias) |
| 603 | if (LiveRegDefs[*Alias] && LiveRegDefs[*Alias] != SU) { |
| 604 | if (RegAdded.insert(*Alias)) { |
| 605 | LRegs.push_back(*Alias); |
| 606 | Added = true; |
| 607 | } |
| 608 | } |
| 609 | return Added; |
| 610 | } |
| 611 | |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 612 | /// DelayForLiveRegsBottomUp - Returns true if it is necessary to delay |
| 613 | /// scheduling of the given node to satisfy live physical register dependencies. |
| 614 | /// If the specific node is the last one that's available to schedule, do |
| 615 | /// whatever is necessary (i.e. backtracking or cloning) to make it possible. |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 616 | bool ScheduleDAGRRList::DelayForLiveRegsBottomUp(SUnit *SU, |
| 617 | SmallVector<unsigned, 4> &LRegs){ |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 618 | if (NumLiveRegs == 0) |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 619 | return false; |
| 620 | |
Evan Cheng | e6f9225 | 2007-09-27 18:46:06 +0000 | [diff] [blame] | 621 | SmallSet<unsigned, 4> RegAdded; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 622 | // If this node would clobber any "live" register, then it's not ready. |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 623 | for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
| 624 | I != E; ++I) { |
Evan Cheng | b8905c4 | 2009-03-04 01:41:49 +0000 | [diff] [blame] | 625 | if (I->isAssignedRegDep()) |
| 626 | CheckForLiveRegDef(I->getSUnit(), I->getReg(), LiveRegDefs, |
| 627 | RegAdded, LRegs, TRI); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 628 | } |
| 629 | |
Dan Gohman | 072734e | 2008-11-13 23:24:17 +0000 | [diff] [blame] | 630 | for (SDNode *Node = SU->getNode(); Node; Node = Node->getFlaggedNode()) { |
Evan Cheng | b8905c4 | 2009-03-04 01:41:49 +0000 | [diff] [blame] | 631 | if (Node->getOpcode() == ISD::INLINEASM) { |
| 632 | // Inline asm can clobber physical defs. |
| 633 | unsigned NumOps = Node->getNumOperands(); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 634 | if (Node->getOperand(NumOps-1).getValueType() == MVT::Flag) |
Evan Cheng | b8905c4 | 2009-03-04 01:41:49 +0000 | [diff] [blame] | 635 | --NumOps; // Ignore the flag operand. |
| 636 | |
| 637 | for (unsigned i = 2; i != NumOps;) { |
| 638 | unsigned Flags = |
| 639 | cast<ConstantSDNode>(Node->getOperand(i))->getZExtValue(); |
Evan Cheng | 2e55923 | 2009-03-20 18:03:34 +0000 | [diff] [blame] | 640 | unsigned NumVals = (Flags & 0xffff) >> 3; |
Evan Cheng | b8905c4 | 2009-03-04 01:41:49 +0000 | [diff] [blame] | 641 | |
| 642 | ++i; // Skip the ID value. |
| 643 | if ((Flags & 7) == 2 || (Flags & 7) == 6) { |
| 644 | // Check for def of register or earlyclobber register. |
| 645 | for (; NumVals; --NumVals, ++i) { |
| 646 | unsigned Reg = cast<RegisterSDNode>(Node->getOperand(i))->getReg(); |
| 647 | if (TargetRegisterInfo::isPhysicalRegister(Reg)) |
| 648 | CheckForLiveRegDef(SU, Reg, LiveRegDefs, RegAdded, LRegs, TRI); |
| 649 | } |
| 650 | } else |
| 651 | i += NumVals; |
| 652 | } |
| 653 | continue; |
| 654 | } |
| 655 | |
Dan Gohman | 072734e | 2008-11-13 23:24:17 +0000 | [diff] [blame] | 656 | if (!Node->isMachineOpcode()) |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 657 | continue; |
Dan Gohman | 1705968 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 658 | const TargetInstrDesc &TID = TII->get(Node->getMachineOpcode()); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 659 | if (!TID.ImplicitDefs) |
| 660 | continue; |
Evan Cheng | b8905c4 | 2009-03-04 01:41:49 +0000 | [diff] [blame] | 661 | for (const unsigned *Reg = TID.ImplicitDefs; *Reg; ++Reg) |
| 662 | CheckForLiveRegDef(SU, *Reg, LiveRegDefs, RegAdded, LRegs, TRI); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 663 | } |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 664 | return !LRegs.empty(); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 665 | } |
| 666 | |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 667 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 668 | /// ListScheduleBottomUp - The main loop of list scheduling for bottom-up |
| 669 | /// schedulers. |
| 670 | void ScheduleDAGRRList::ListScheduleBottomUp() { |
| 671 | unsigned CurCycle = 0; |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 672 | |
| 673 | // Release any predecessors of the special Exit node. |
| 674 | ReleasePredecessors(&ExitSU, CurCycle); |
| 675 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 676 | // Add root to Available queue. |
Dan Gohman | 4370f26 | 2008-04-15 01:22:18 +0000 | [diff] [blame] | 677 | if (!SUnits.empty()) { |
Dan Gohman | 5a390b9 | 2008-11-13 21:21:28 +0000 | [diff] [blame] | 678 | SUnit *RootSU = &SUnits[DAG->getRoot().getNode()->getNodeId()]; |
Dan Gohman | 4370f26 | 2008-04-15 01:22:18 +0000 | [diff] [blame] | 679 | assert(RootSU->Succs.empty() && "Graph root shouldn't have successors!"); |
| 680 | RootSU->isAvailable = true; |
| 681 | AvailableQueue->push(RootSU); |
| 682 | } |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 683 | |
| 684 | // While Available queue is not empty, grab the node with the highest |
Dan Gohman | 54a187e | 2007-08-20 19:28:38 +0000 | [diff] [blame] | 685 | // priority. If it is not ready put it back. Schedule the node. |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 686 | SmallVector<SUnit*, 4> NotReady; |
Dan Gohman | fa63cc4 | 2008-06-23 21:15:00 +0000 | [diff] [blame] | 687 | DenseMap<SUnit*, SmallVector<unsigned, 4> > LRegsMap; |
Dan Gohman | e6e1348 | 2008-06-21 15:52:51 +0000 | [diff] [blame] | 688 | Sequence.reserve(SUnits.size()); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 689 | while (!AvailableQueue->empty()) { |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 690 | bool Delayed = false; |
Dan Gohman | fa63cc4 | 2008-06-23 21:15:00 +0000 | [diff] [blame] | 691 | LRegsMap.clear(); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 692 | SUnit *CurSU = AvailableQueue->pop(); |
| 693 | while (CurSU) { |
Dan Gohman | 63be531 | 2008-11-21 01:30:54 +0000 | [diff] [blame] | 694 | SmallVector<unsigned, 4> LRegs; |
| 695 | if (!DelayForLiveRegsBottomUp(CurSU, LRegs)) |
| 696 | break; |
| 697 | Delayed = true; |
| 698 | LRegsMap.insert(std::make_pair(CurSU, LRegs)); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 699 | |
| 700 | CurSU->isPending = true; // This SU is not in AvailableQueue right now. |
| 701 | NotReady.push_back(CurSU); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 702 | CurSU = AvailableQueue->pop(); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 703 | } |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 704 | |
| 705 | // All candidates are delayed due to live physical reg dependencies. |
| 706 | // Try backtracking, code duplication, or inserting cross class copies |
| 707 | // to resolve it. |
| 708 | if (Delayed && !CurSU) { |
| 709 | for (unsigned i = 0, e = NotReady.size(); i != e; ++i) { |
| 710 | SUnit *TrySU = NotReady[i]; |
| 711 | SmallVector<unsigned, 4> &LRegs = LRegsMap[TrySU]; |
| 712 | |
| 713 | // Try unscheduling up to the point where it's safe to schedule |
| 714 | // this node. |
| 715 | unsigned LiveCycle = CurCycle; |
| 716 | for (unsigned j = 0, ee = LRegs.size(); j != ee; ++j) { |
| 717 | unsigned Reg = LRegs[j]; |
| 718 | unsigned LCycle = LiveRegCycles[Reg]; |
| 719 | LiveCycle = std::min(LiveCycle, LCycle); |
| 720 | } |
| 721 | SUnit *OldSU = Sequence[LiveCycle]; |
| 722 | if (!WillCreateCycle(TrySU, OldSU)) { |
| 723 | BacktrackBottomUp(TrySU, LiveCycle, CurCycle); |
| 724 | // Force the current node to be scheduled before the node that |
| 725 | // requires the physical reg dep. |
| 726 | if (OldSU->isAvailable) { |
| 727 | OldSU->isAvailable = false; |
| 728 | AvailableQueue->remove(OldSU); |
| 729 | } |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 730 | AddPred(TrySU, SDep(OldSU, SDep::Order, /*Latency=*/1, |
| 731 | /*Reg=*/0, /*isNormalMemory=*/false, |
| 732 | /*isMustAlias=*/false, /*isArtificial=*/true)); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 733 | // If one or more successors has been unscheduled, then the current |
| 734 | // node is no longer avaialable. Schedule a successor that's now |
| 735 | // available instead. |
| 736 | if (!TrySU->isAvailable) |
| 737 | CurSU = AvailableQueue->pop(); |
| 738 | else { |
| 739 | CurSU = TrySU; |
| 740 | TrySU->isPending = false; |
| 741 | NotReady.erase(NotReady.begin()+i); |
| 742 | } |
| 743 | break; |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | if (!CurSU) { |
Evan Cheng | b2c42c6 | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 748 | // Can't backtrack. If it's too expensive to copy the value, then try |
| 749 | // duplicate the nodes that produces these "too expensive to copy" |
| 750 | // values to break the dependency. In case even that doesn't work, |
| 751 | // insert cross class copies. |
| 752 | // If it's not too expensive, i.e. cost != -1, issue copies. |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 753 | SUnit *TrySU = NotReady[0]; |
| 754 | SmallVector<unsigned, 4> &LRegs = LRegsMap[TrySU]; |
| 755 | assert(LRegs.size() == 1 && "Can't handle this yet!"); |
| 756 | unsigned Reg = LRegs[0]; |
| 757 | SUnit *LRDef = LiveRegDefs[Reg]; |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 758 | EVT VT = getPhysicalRegisterVT(LRDef->getNode(), Reg, TII); |
Evan Cheng | b2c42c6 | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 759 | const TargetRegisterClass *RC = |
| 760 | TRI->getPhysicalRegisterRegClass(Reg, VT); |
| 761 | const TargetRegisterClass *DestRC = TRI->getCrossCopyRegClass(RC); |
| 762 | |
| 763 | // If cross copy register class is null, then it must be possible copy |
| 764 | // the value directly. Do not try duplicate the def. |
| 765 | SUnit *NewDef = 0; |
| 766 | if (DestRC) |
| 767 | NewDef = CopyAndMoveSuccessors(LRDef); |
| 768 | else |
| 769 | DestRC = RC; |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 770 | if (!NewDef) { |
Evan Cheng | b2c42c6 | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 771 | // Issue copies, these can be expensive cross register class copies. |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 772 | SmallVector<SUnit*, 2> Copies; |
Evan Cheng | b2c42c6 | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 773 | InsertCopiesAndMoveSuccs(LRDef, Reg, DestRC, RC, Copies); |
Chris Lattner | 4dc3edd | 2009-08-23 06:35:02 +0000 | [diff] [blame^] | 774 | DEBUG(errs() << "Adding an edge from SU #" << TrySU->NodeNum |
| 775 | << " to SU #" << Copies.front()->NodeNum << "\n"); |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 776 | AddPred(TrySU, SDep(Copies.front(), SDep::Order, /*Latency=*/1, |
Dan Gohman | bf8e520 | 2009-01-06 01:28:56 +0000 | [diff] [blame] | 777 | /*Reg=*/0, /*isNormalMemory=*/false, |
| 778 | /*isMustAlias=*/false, |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 779 | /*isArtificial=*/true)); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 780 | NewDef = Copies.back(); |
| 781 | } |
| 782 | |
Chris Lattner | 4dc3edd | 2009-08-23 06:35:02 +0000 | [diff] [blame^] | 783 | DEBUG(errs() << "Adding an edge from SU #" << NewDef->NodeNum |
| 784 | << " to SU #" << TrySU->NodeNum << "\n"); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 785 | LiveRegDefs[Reg] = NewDef; |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 786 | AddPred(NewDef, SDep(TrySU, SDep::Order, /*Latency=*/1, |
Dan Gohman | bf8e520 | 2009-01-06 01:28:56 +0000 | [diff] [blame] | 787 | /*Reg=*/0, /*isNormalMemory=*/false, |
| 788 | /*isMustAlias=*/false, |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 789 | /*isArtificial=*/true)); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 790 | TrySU->isAvailable = false; |
| 791 | CurSU = NewDef; |
| 792 | } |
| 793 | |
Dan Gohman | 60d6844 | 2009-01-29 19:49:27 +0000 | [diff] [blame] | 794 | assert(CurSU && "Unable to resolve live physical register dependencies!"); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 795 | } |
| 796 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 797 | // Add the nodes that aren't ready back onto the available list. |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 798 | for (unsigned i = 0, e = NotReady.size(); i != e; ++i) { |
| 799 | NotReady[i]->isPending = false; |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 800 | // May no longer be available due to backtracking. |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 801 | if (NotReady[i]->isAvailable) |
| 802 | AvailableQueue->push(NotReady[i]); |
| 803 | } |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 804 | NotReady.clear(); |
| 805 | |
Dan Gohman | c602dd4 | 2008-11-21 00:10:42 +0000 | [diff] [blame] | 806 | if (CurSU) |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 807 | ScheduleNodeBottomUp(CurSU, CurCycle); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 808 | ++CurCycle; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 809 | } |
| 810 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 811 | // Reverse the order if it is bottom up. |
| 812 | std::reverse(Sequence.begin(), Sequence.end()); |
| 813 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 814 | #ifndef NDEBUG |
Dan Gohman | 4ce15e1 | 2008-11-20 01:26:25 +0000 | [diff] [blame] | 815 | VerifySchedule(isBottomUp); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 816 | #endif |
| 817 | } |
| 818 | |
| 819 | //===----------------------------------------------------------------------===// |
| 820 | // Top-Down Scheduling |
| 821 | //===----------------------------------------------------------------------===// |
| 822 | |
| 823 | /// ReleaseSucc - Decrement the NumPredsLeft count of a successor. Add it to |
Dan Gohman | 54a187e | 2007-08-20 19:28:38 +0000 | [diff] [blame] | 824 | /// the AvailableQueue if the count reaches zero. Also update its cycle bound. |
Dan Gohman | 60d6844 | 2009-01-29 19:49:27 +0000 | [diff] [blame] | 825 | void ScheduleDAGRRList::ReleaseSucc(SUnit *SU, const SDep *SuccEdge) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 826 | SUnit *SuccSU = SuccEdge->getSUnit(); |
Evan Cheng | 038dcc5 | 2007-09-28 19:24:24 +0000 | [diff] [blame] | 827 | --SuccSU->NumPredsLeft; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 828 | |
| 829 | #ifndef NDEBUG |
Evan Cheng | 038dcc5 | 2007-09-28 19:24:24 +0000 | [diff] [blame] | 830 | if (SuccSU->NumPredsLeft < 0) { |
Dan Gohman | 5ebdb98 | 2008-11-18 00:38:59 +0000 | [diff] [blame] | 831 | cerr << "*** Scheduling failed! ***\n"; |
Dan Gohman | 22d07b1 | 2008-11-18 02:06:40 +0000 | [diff] [blame] | 832 | SuccSU->dump(this); |
Bill Wendling | 22e978a | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 833 | cerr << " has been released too many times!\n"; |
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 834 | llvm_unreachable(0); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 835 | } |
| 836 | #endif |
| 837 | |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 838 | // If all the node's predecessors are scheduled, this node is ready |
| 839 | // to be scheduled. Ignore the special ExitSU node. |
| 840 | if (SuccSU->NumPredsLeft == 0 && SuccSU != &ExitSU) { |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 841 | SuccSU->isAvailable = true; |
| 842 | AvailableQueue->push(SuccSU); |
| 843 | } |
| 844 | } |
| 845 | |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 846 | void ScheduleDAGRRList::ReleaseSuccessors(SUnit *SU) { |
| 847 | // Top down: release successors |
| 848 | for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 849 | I != E; ++I) { |
| 850 | assert(!I->isAssignedRegDep() && |
| 851 | "The list-tdrr scheduler doesn't yet support physreg dependencies!"); |
| 852 | |
| 853 | ReleaseSucc(SU, &*I); |
| 854 | } |
| 855 | } |
| 856 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 857 | /// ScheduleNodeTopDown - Add the node to the schedule. Decrement the pending |
| 858 | /// count of its successors. If a successor pending count is zero, add it to |
| 859 | /// the Available queue. |
Evan Cheng | d12c97d | 2006-05-30 18:05:39 +0000 | [diff] [blame] | 860 | void ScheduleDAGRRList::ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle) { |
Chris Lattner | 4dc3edd | 2009-08-23 06:35:02 +0000 | [diff] [blame^] | 861 | DEBUG(errs() << "*** Scheduling [" << CurCycle << "]: "); |
Dan Gohman | 22d07b1 | 2008-11-18 02:06:40 +0000 | [diff] [blame] | 862 | DEBUG(SU->dump(this)); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 863 | |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 864 | assert(CurCycle >= SU->getDepth() && "Node scheduled above its depth!"); |
| 865 | SU->setDepthToAtLeast(CurCycle); |
Dan Gohman | 92a36d7 | 2008-11-17 21:31:02 +0000 | [diff] [blame] | 866 | Sequence.push_back(SU); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 867 | |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 868 | ReleaseSuccessors(SU); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 869 | SU->isScheduled = true; |
Dan Gohman | 92a36d7 | 2008-11-17 21:31:02 +0000 | [diff] [blame] | 870 | AvailableQueue->ScheduledNode(SU); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 871 | } |
| 872 | |
Dan Gohman | 54a187e | 2007-08-20 19:28:38 +0000 | [diff] [blame] | 873 | /// ListScheduleTopDown - The main loop of list scheduling for top-down |
| 874 | /// schedulers. |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 875 | void ScheduleDAGRRList::ListScheduleTopDown() { |
| 876 | unsigned CurCycle = 0; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 877 | |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 878 | // Release any successors of the special Entry node. |
| 879 | ReleaseSuccessors(&EntrySU); |
| 880 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 881 | // All leaves to Available queue. |
| 882 | for (unsigned i = 0, e = SUnits.size(); i != e; ++i) { |
| 883 | // It is available if it has no predecessors. |
Dan Gohman | 4370f26 | 2008-04-15 01:22:18 +0000 | [diff] [blame] | 884 | if (SUnits[i].Preds.empty()) { |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 885 | AvailableQueue->push(&SUnits[i]); |
| 886 | SUnits[i].isAvailable = true; |
| 887 | } |
| 888 | } |
| 889 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 890 | // While Available queue is not empty, grab the node with the highest |
Dan Gohman | 54a187e | 2007-08-20 19:28:38 +0000 | [diff] [blame] | 891 | // priority. If it is not ready put it back. Schedule the node. |
Dan Gohman | e6e1348 | 2008-06-21 15:52:51 +0000 | [diff] [blame] | 892 | Sequence.reserve(SUnits.size()); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 893 | while (!AvailableQueue->empty()) { |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 894 | SUnit *CurSU = AvailableQueue->pop(); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 895 | |
Dan Gohman | c602dd4 | 2008-11-21 00:10:42 +0000 | [diff] [blame] | 896 | if (CurSU) |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 897 | ScheduleNodeTopDown(CurSU, CurCycle); |
Dan Gohman | 4370f26 | 2008-04-15 01:22:18 +0000 | [diff] [blame] | 898 | ++CurCycle; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 899 | } |
| 900 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 901 | #ifndef NDEBUG |
Dan Gohman | 4ce15e1 | 2008-11-20 01:26:25 +0000 | [diff] [blame] | 902 | VerifySchedule(isBottomUp); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 903 | #endif |
| 904 | } |
| 905 | |
| 906 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 907 | //===----------------------------------------------------------------------===// |
| 908 | // RegReductionPriorityQueue Implementation |
| 909 | //===----------------------------------------------------------------------===// |
| 910 | // |
| 911 | // This is a SchedulingPriorityQueue that schedules using Sethi Ullman numbers |
| 912 | // to reduce register pressure. |
| 913 | // |
| 914 | namespace { |
| 915 | template<class SF> |
| 916 | class RegReductionPriorityQueue; |
| 917 | |
| 918 | /// Sorting functions for the Available queue. |
| 919 | struct bu_ls_rr_sort : public std::binary_function<SUnit*, SUnit*, bool> { |
| 920 | RegReductionPriorityQueue<bu_ls_rr_sort> *SPQ; |
| 921 | bu_ls_rr_sort(RegReductionPriorityQueue<bu_ls_rr_sort> *spq) : SPQ(spq) {} |
| 922 | bu_ls_rr_sort(const bu_ls_rr_sort &RHS) : SPQ(RHS.SPQ) {} |
| 923 | |
| 924 | bool operator()(const SUnit* left, const SUnit* right) const; |
| 925 | }; |
| 926 | |
| 927 | struct td_ls_rr_sort : public std::binary_function<SUnit*, SUnit*, bool> { |
| 928 | RegReductionPriorityQueue<td_ls_rr_sort> *SPQ; |
| 929 | td_ls_rr_sort(RegReductionPriorityQueue<td_ls_rr_sort> *spq) : SPQ(spq) {} |
| 930 | td_ls_rr_sort(const td_ls_rr_sort &RHS) : SPQ(RHS.SPQ) {} |
| 931 | |
| 932 | bool operator()(const SUnit* left, const SUnit* right) const; |
| 933 | }; |
| 934 | } // end anonymous namespace |
| 935 | |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 936 | /// CalcNodeSethiUllmanNumber - Compute Sethi Ullman number. |
| 937 | /// Smaller number is the higher priority. |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 938 | static unsigned |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 939 | CalcNodeSethiUllmanNumber(const SUnit *SU, std::vector<unsigned> &SUNumbers) { |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 940 | unsigned &SethiUllmanNumber = SUNumbers[SU->NodeNum]; |
| 941 | if (SethiUllmanNumber != 0) |
| 942 | return SethiUllmanNumber; |
| 943 | |
| 944 | unsigned Extra = 0; |
| 945 | for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
| 946 | I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 947 | if (I->isCtrl()) continue; // ignore chain preds |
| 948 | SUnit *PredSU = I->getSUnit(); |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 949 | unsigned PredSethiUllman = CalcNodeSethiUllmanNumber(PredSU, SUNumbers); |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 950 | if (PredSethiUllman > SethiUllmanNumber) { |
| 951 | SethiUllmanNumber = PredSethiUllman; |
| 952 | Extra = 0; |
Evan Cheng | 3a14efa | 2009-02-12 08:59:45 +0000 | [diff] [blame] | 953 | } else if (PredSethiUllman == SethiUllmanNumber) |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 954 | ++Extra; |
| 955 | } |
| 956 | |
| 957 | SethiUllmanNumber += Extra; |
| 958 | |
| 959 | if (SethiUllmanNumber == 0) |
| 960 | SethiUllmanNumber = 1; |
| 961 | |
| 962 | return SethiUllmanNumber; |
| 963 | } |
| 964 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 965 | namespace { |
| 966 | template<class SF> |
Chris Lattner | 996795b | 2006-06-28 23:17:24 +0000 | [diff] [blame] | 967 | class VISIBILITY_HIDDEN RegReductionPriorityQueue |
| 968 | : public SchedulingPriorityQueue { |
Dan Gohman | a4db335 | 2008-06-21 18:35:25 +0000 | [diff] [blame] | 969 | PriorityQueue<SUnit*, std::vector<SUnit*>, SF> Queue; |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 970 | unsigned currentQueueId; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 971 | |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 972 | protected: |
| 973 | // SUnits - The SUnits for the current graph. |
| 974 | std::vector<SUnit> *SUnits; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 975 | |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 976 | const TargetInstrInfo *TII; |
| 977 | const TargetRegisterInfo *TRI; |
| 978 | ScheduleDAGRRList *scheduleDAG; |
| 979 | |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 980 | // SethiUllmanNumbers - The SethiUllman number for each node. |
| 981 | std::vector<unsigned> SethiUllmanNumbers; |
| 982 | |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 983 | public: |
| 984 | RegReductionPriorityQueue(const TargetInstrInfo *tii, |
| 985 | const TargetRegisterInfo *tri) : |
| 986 | Queue(SF(this)), currentQueueId(0), |
| 987 | TII(tii), TRI(tri), scheduleDAG(NULL) {} |
| 988 | |
| 989 | void initNodes(std::vector<SUnit> &sunits) { |
| 990 | SUnits = &sunits; |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 991 | // Add pseudo dependency edges for two-address nodes. |
| 992 | AddPseudoTwoAddrDeps(); |
Dan Gohman | 9a658d7 | 2009-03-24 00:49:12 +0000 | [diff] [blame] | 993 | // Reroute edges to nodes with multiple uses. |
| 994 | PrescheduleNodesWithMultipleUses(); |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 995 | // Calculate node priorities. |
| 996 | CalculateSethiUllmanNumbers(); |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 997 | } |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 998 | |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 999 | void addNode(const SUnit *SU) { |
| 1000 | unsigned SUSize = SethiUllmanNumbers.size(); |
| 1001 | if (SUnits->size() > SUSize) |
| 1002 | SethiUllmanNumbers.resize(SUSize*2, 0); |
| 1003 | CalcNodeSethiUllmanNumber(SU, SethiUllmanNumbers); |
| 1004 | } |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1005 | |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1006 | void updateNode(const SUnit *SU) { |
| 1007 | SethiUllmanNumbers[SU->NodeNum] = 0; |
| 1008 | CalcNodeSethiUllmanNumber(SU, SethiUllmanNumbers); |
| 1009 | } |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1010 | |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1011 | void releaseState() { |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 1012 | SUnits = 0; |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1013 | SethiUllmanNumbers.clear(); |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 1014 | } |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1015 | |
| 1016 | unsigned getNodePriority(const SUnit *SU) const { |
| 1017 | assert(SU->NodeNum < SethiUllmanNumbers.size()); |
| 1018 | unsigned Opc = SU->getNode() ? SU->getNode()->getOpcode() : 0; |
Dan Gohman | 261ee6b | 2009-01-07 22:30:55 +0000 | [diff] [blame] | 1019 | if (Opc == ISD::TokenFactor || Opc == ISD::CopyToReg) |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1020 | // CopyToReg should be close to its uses to facilitate coalescing and |
| 1021 | // avoid spilling. |
| 1022 | return 0; |
Dan Gohman | 261ee6b | 2009-01-07 22:30:55 +0000 | [diff] [blame] | 1023 | if (Opc == TargetInstrInfo::EXTRACT_SUBREG || |
Dan Gohman | 3027bb6 | 2009-04-16 20:57:10 +0000 | [diff] [blame] | 1024 | Opc == TargetInstrInfo::SUBREG_TO_REG || |
Dan Gohman | 261ee6b | 2009-01-07 22:30:55 +0000 | [diff] [blame] | 1025 | Opc == TargetInstrInfo::INSERT_SUBREG) |
Dan Gohman | 3027bb6 | 2009-04-16 20:57:10 +0000 | [diff] [blame] | 1026 | // EXTRACT_SUBREG, INSERT_SUBREG, and SUBREG_TO_REG nodes should be |
| 1027 | // close to their uses to facilitate coalescing. |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1028 | return 0; |
Dan Gohman | 6571ef3 | 2009-02-11 21:29:39 +0000 | [diff] [blame] | 1029 | if (SU->NumSuccs == 0 && SU->NumPreds != 0) |
| 1030 | // If SU does not have a register use, i.e. it doesn't produce a value |
| 1031 | // that would be consumed (e.g. store), then it terminates a chain of |
| 1032 | // computation. Give it a large SethiUllman number so it will be |
| 1033 | // scheduled right before its predecessors that it doesn't lengthen |
| 1034 | // their live ranges. |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1035 | return 0xffff; |
Dan Gohman | 6571ef3 | 2009-02-11 21:29:39 +0000 | [diff] [blame] | 1036 | if (SU->NumPreds == 0 && SU->NumSuccs != 0) |
| 1037 | // If SU does not have a register def, schedule it close to its uses |
| 1038 | // because it does not lengthen any live ranges. |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1039 | return 0; |
Dan Gohman | 261ee6b | 2009-01-07 22:30:55 +0000 | [diff] [blame] | 1040 | return SethiUllmanNumbers[SU->NodeNum]; |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1041 | } |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1042 | |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1043 | unsigned size() const { return Queue.size(); } |
| 1044 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1045 | bool empty() const { return Queue.empty(); } |
| 1046 | |
| 1047 | void push(SUnit *U) { |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 1048 | assert(!U->NodeQueueId && "Node in the queue already"); |
| 1049 | U->NodeQueueId = ++currentQueueId; |
Dan Gohman | a4db335 | 2008-06-21 18:35:25 +0000 | [diff] [blame] | 1050 | Queue.push(U); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1051 | } |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 1052 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1053 | void push_all(const std::vector<SUnit *> &Nodes) { |
| 1054 | for (unsigned i = 0, e = Nodes.size(); i != e; ++i) |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 1055 | push(Nodes[i]); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | SUnit *pop() { |
Evan Cheng | d12c97d | 2006-05-30 18:05:39 +0000 | [diff] [blame] | 1059 | if (empty()) return NULL; |
Dan Gohman | a4db335 | 2008-06-21 18:35:25 +0000 | [diff] [blame] | 1060 | SUnit *V = Queue.top(); |
| 1061 | Queue.pop(); |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 1062 | V->NodeQueueId = 0; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1063 | return V; |
| 1064 | } |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1065 | |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1066 | void remove(SUnit *SU) { |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 1067 | assert(!Queue.empty() && "Queue is empty!"); |
Dan Gohman | a4db335 | 2008-06-21 18:35:25 +0000 | [diff] [blame] | 1068 | assert(SU->NodeQueueId != 0 && "Not in queue!"); |
| 1069 | Queue.erase_one(SU); |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 1070 | SU->NodeQueueId = 0; |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1071 | } |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 1072 | |
| 1073 | void setScheduleDAG(ScheduleDAGRRList *scheduleDag) { |
| 1074 | scheduleDAG = scheduleDag; |
| 1075 | } |
| 1076 | |
| 1077 | protected: |
| 1078 | bool canClobber(const SUnit *SU, const SUnit *Op); |
| 1079 | void AddPseudoTwoAddrDeps(); |
Dan Gohman | 9a658d7 | 2009-03-24 00:49:12 +0000 | [diff] [blame] | 1080 | void PrescheduleNodesWithMultipleUses(); |
Evan Cheng | 6730f03 | 2007-01-08 23:55:53 +0000 | [diff] [blame] | 1081 | void CalculateSethiUllmanNumbers(); |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1082 | }; |
| 1083 | |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1084 | typedef RegReductionPriorityQueue<bu_ls_rr_sort> |
| 1085 | BURegReductionPriorityQueue; |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1086 | |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1087 | typedef RegReductionPriorityQueue<td_ls_rr_sort> |
| 1088 | TDRegReductionPriorityQueue; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1089 | } |
| 1090 | |
Evan Cheng | b9e3db6 | 2007-03-14 22:43:40 +0000 | [diff] [blame] | 1091 | /// closestSucc - Returns the scheduled cycle of the successor which is |
Dan Gohman | a19c662 | 2009-03-12 23:55:10 +0000 | [diff] [blame] | 1092 | /// closest to the current cycle. |
Evan Cheng | 2874855 | 2007-03-13 23:25:11 +0000 | [diff] [blame] | 1093 | static unsigned closestSucc(const SUnit *SU) { |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 1094 | unsigned MaxHeight = 0; |
Evan Cheng | 2874855 | 2007-03-13 23:25:11 +0000 | [diff] [blame] | 1095 | for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
Evan Cheng | b9e3db6 | 2007-03-14 22:43:40 +0000 | [diff] [blame] | 1096 | I != E; ++I) { |
Evan Cheng | ce3bbe5 | 2009-02-10 08:30:11 +0000 | [diff] [blame] | 1097 | if (I->isCtrl()) continue; // ignore chain succs |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 1098 | unsigned Height = I->getSUnit()->getHeight(); |
Evan Cheng | b9e3db6 | 2007-03-14 22:43:40 +0000 | [diff] [blame] | 1099 | // If there are bunch of CopyToRegs stacked up, they should be considered |
| 1100 | // to be at the same position. |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 1101 | if (I->getSUnit()->getNode() && |
| 1102 | I->getSUnit()->getNode()->getOpcode() == ISD::CopyToReg) |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 1103 | Height = closestSucc(I->getSUnit())+1; |
| 1104 | if (Height > MaxHeight) |
| 1105 | MaxHeight = Height; |
Evan Cheng | b9e3db6 | 2007-03-14 22:43:40 +0000 | [diff] [blame] | 1106 | } |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 1107 | return MaxHeight; |
Evan Cheng | 2874855 | 2007-03-13 23:25:11 +0000 | [diff] [blame] | 1108 | } |
| 1109 | |
Evan Cheng | 61bc51e | 2007-12-20 02:22:36 +0000 | [diff] [blame] | 1110 | /// calcMaxScratches - Returns an cost estimate of the worse case requirement |
Evan Cheng | 3a14efa | 2009-02-12 08:59:45 +0000 | [diff] [blame] | 1111 | /// for scratch registers, i.e. number of data dependencies. |
Evan Cheng | 61bc51e | 2007-12-20 02:22:36 +0000 | [diff] [blame] | 1112 | static unsigned calcMaxScratches(const SUnit *SU) { |
| 1113 | unsigned Scratches = 0; |
| 1114 | for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
Evan Cheng | b570499 | 2009-02-12 09:52:13 +0000 | [diff] [blame] | 1115 | I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 1116 | if (I->isCtrl()) continue; // ignore chain preds |
Evan Cheng | b570499 | 2009-02-12 09:52:13 +0000 | [diff] [blame] | 1117 | Scratches++; |
| 1118 | } |
Evan Cheng | 61bc51e | 2007-12-20 02:22:36 +0000 | [diff] [blame] | 1119 | return Scratches; |
| 1120 | } |
| 1121 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1122 | // Bottom up |
| 1123 | bool bu_ls_rr_sort::operator()(const SUnit *left, const SUnit *right) const { |
Evan Cheng | 6730f03 | 2007-01-08 23:55:53 +0000 | [diff] [blame] | 1124 | unsigned LPriority = SPQ->getNodePriority(left); |
| 1125 | unsigned RPriority = SPQ->getNodePriority(right); |
Evan Cheng | 73bdf04 | 2008-03-01 00:39:47 +0000 | [diff] [blame] | 1126 | if (LPriority != RPriority) |
| 1127 | return LPriority > RPriority; |
| 1128 | |
| 1129 | // Try schedule def + use closer when Sethi-Ullman numbers are the same. |
| 1130 | // e.g. |
| 1131 | // t1 = op t2, c1 |
| 1132 | // t3 = op t4, c2 |
| 1133 | // |
| 1134 | // and the following instructions are both ready. |
| 1135 | // t2 = op c3 |
| 1136 | // t4 = op c4 |
| 1137 | // |
| 1138 | // Then schedule t2 = op first. |
| 1139 | // i.e. |
| 1140 | // t4 = op c4 |
| 1141 | // t2 = op c3 |
| 1142 | // t1 = op t2, c1 |
| 1143 | // t3 = op t4, c2 |
| 1144 | // |
| 1145 | // This creates more short live intervals. |
| 1146 | unsigned LDist = closestSucc(left); |
| 1147 | unsigned RDist = closestSucc(right); |
| 1148 | if (LDist != RDist) |
| 1149 | return LDist < RDist; |
| 1150 | |
Evan Cheng | 3a14efa | 2009-02-12 08:59:45 +0000 | [diff] [blame] | 1151 | // How many registers becomes live when the node is scheduled. |
Evan Cheng | 73bdf04 | 2008-03-01 00:39:47 +0000 | [diff] [blame] | 1152 | unsigned LScratch = calcMaxScratches(left); |
| 1153 | unsigned RScratch = calcMaxScratches(right); |
| 1154 | if (LScratch != RScratch) |
| 1155 | return LScratch > RScratch; |
| 1156 | |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 1157 | if (left->getHeight() != right->getHeight()) |
| 1158 | return left->getHeight() > right->getHeight(); |
Evan Cheng | 73bdf04 | 2008-03-01 00:39:47 +0000 | [diff] [blame] | 1159 | |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 1160 | if (left->getDepth() != right->getDepth()) |
| 1161 | return left->getDepth() < right->getDepth(); |
Evan Cheng | 73bdf04 | 2008-03-01 00:39:47 +0000 | [diff] [blame] | 1162 | |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 1163 | assert(left->NodeQueueId && right->NodeQueueId && |
| 1164 | "NodeQueueId cannot be zero"); |
| 1165 | return (left->NodeQueueId > right->NodeQueueId); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1166 | } |
| 1167 | |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 1168 | template<class SF> |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1169 | bool |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 1170 | RegReductionPriorityQueue<SF>::canClobber(const SUnit *SU, const SUnit *Op) { |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1171 | if (SU->isTwoAddress) { |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1172 | unsigned Opc = SU->getNode()->getMachineOpcode(); |
Chris Lattner | 03ad885 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 1173 | const TargetInstrDesc &TID = TII->get(Opc); |
Chris Lattner | fd2e338 | 2008-01-07 06:47:00 +0000 | [diff] [blame] | 1174 | unsigned NumRes = TID.getNumDefs(); |
Dan Gohman | 0340d1e | 2008-02-15 20:50:13 +0000 | [diff] [blame] | 1175 | unsigned NumOps = TID.getNumOperands() - NumRes; |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1176 | for (unsigned i = 0; i != NumOps; ++i) { |
Chris Lattner | fd2e338 | 2008-01-07 06:47:00 +0000 | [diff] [blame] | 1177 | if (TID.getOperandConstraint(i+NumRes, TOI::TIED_TO) != -1) { |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1178 | SDNode *DU = SU->getNode()->getOperand(i).getNode(); |
Dan Gohman | 46520a2 | 2008-06-21 19:18:17 +0000 | [diff] [blame] | 1179 | if (DU->getNodeId() != -1 && |
| 1180 | Op->OrigNode == &(*SUnits)[DU->getNodeId()]) |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1181 | return true; |
| 1182 | } |
| 1183 | } |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1184 | } |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1185 | return false; |
| 1186 | } |
| 1187 | |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1188 | |
Evan Cheng | a5e595d | 2007-09-28 22:32:30 +0000 | [diff] [blame] | 1189 | /// hasCopyToRegUse - Return true if SU has a value successor that is a |
| 1190 | /// CopyToReg node. |
Dan Gohman | e955c48 | 2008-08-05 14:45:15 +0000 | [diff] [blame] | 1191 | static bool hasCopyToRegUse(const SUnit *SU) { |
Evan Cheng | a5e595d | 2007-09-28 22:32:30 +0000 | [diff] [blame] | 1192 | for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 1193 | I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 1194 | if (I->isCtrl()) continue; |
| 1195 | const SUnit *SuccSU = I->getSUnit(); |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1196 | if (SuccSU->getNode() && SuccSU->getNode()->getOpcode() == ISD::CopyToReg) |
Evan Cheng | a5e595d | 2007-09-28 22:32:30 +0000 | [diff] [blame] | 1197 | return true; |
| 1198 | } |
| 1199 | return false; |
| 1200 | } |
| 1201 | |
Evan Cheng | f989141 | 2007-12-20 09:25:31 +0000 | [diff] [blame] | 1202 | /// canClobberPhysRegDefs - True if SU would clobber one of SuccSU's |
Dan Gohman | ea04520 | 2008-06-21 22:05:24 +0000 | [diff] [blame] | 1203 | /// physical register defs. |
Dan Gohman | e955c48 | 2008-08-05 14:45:15 +0000 | [diff] [blame] | 1204 | static bool canClobberPhysRegDefs(const SUnit *SuccSU, const SUnit *SU, |
Evan Cheng | f989141 | 2007-12-20 09:25:31 +0000 | [diff] [blame] | 1205 | const TargetInstrInfo *TII, |
Dan Gohman | 3a4be0f | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 1206 | const TargetRegisterInfo *TRI) { |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1207 | SDNode *N = SuccSU->getNode(); |
Dan Gohman | 1705968 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 1208 | unsigned NumDefs = TII->get(N->getMachineOpcode()).getNumDefs(); |
| 1209 | const unsigned *ImpDefs = TII->get(N->getMachineOpcode()).getImplicitDefs(); |
Dan Gohman | ea04520 | 2008-06-21 22:05:24 +0000 | [diff] [blame] | 1210 | assert(ImpDefs && "Caller should check hasPhysRegDefs"); |
Dan Gohman | a366da1 | 2009-03-23 16:23:01 +0000 | [diff] [blame] | 1211 | for (const SDNode *SUNode = SU->getNode(); SUNode; |
| 1212 | SUNode = SUNode->getFlaggedNode()) { |
| 1213 | if (!SUNode->isMachineOpcode()) |
Evan Cheng | f989141 | 2007-12-20 09:25:31 +0000 | [diff] [blame] | 1214 | continue; |
Dan Gohman | a366da1 | 2009-03-23 16:23:01 +0000 | [diff] [blame] | 1215 | const unsigned *SUImpDefs = |
| 1216 | TII->get(SUNode->getMachineOpcode()).getImplicitDefs(); |
| 1217 | if (!SUImpDefs) |
| 1218 | return false; |
| 1219 | for (unsigned i = NumDefs, e = N->getNumValues(); i != e; ++i) { |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1220 | EVT VT = N->getValueType(i); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1221 | if (VT == MVT::Flag || VT == MVT::Other) |
Dan Gohman | a366da1 | 2009-03-23 16:23:01 +0000 | [diff] [blame] | 1222 | continue; |
| 1223 | if (!N->hasAnyUseOfValue(i)) |
| 1224 | continue; |
| 1225 | unsigned Reg = ImpDefs[i - NumDefs]; |
| 1226 | for (;*SUImpDefs; ++SUImpDefs) { |
| 1227 | unsigned SUReg = *SUImpDefs; |
| 1228 | if (TRI->regsOverlap(Reg, SUReg)) |
| 1229 | return true; |
| 1230 | } |
Evan Cheng | f989141 | 2007-12-20 09:25:31 +0000 | [diff] [blame] | 1231 | } |
| 1232 | } |
| 1233 | return false; |
| 1234 | } |
| 1235 | |
Dan Gohman | 9a658d7 | 2009-03-24 00:49:12 +0000 | [diff] [blame] | 1236 | /// PrescheduleNodesWithMultipleUses - Nodes with multiple uses |
| 1237 | /// are not handled well by the general register pressure reduction |
| 1238 | /// heuristics. When presented with code like this: |
| 1239 | /// |
| 1240 | /// N |
| 1241 | /// / | |
| 1242 | /// / | |
| 1243 | /// U store |
| 1244 | /// | |
| 1245 | /// ... |
| 1246 | /// |
| 1247 | /// the heuristics tend to push the store up, but since the |
| 1248 | /// operand of the store has another use (U), this would increase |
| 1249 | /// the length of that other use (the U->N edge). |
| 1250 | /// |
| 1251 | /// This function transforms code like the above to route U's |
| 1252 | /// dependence through the store when possible, like this: |
| 1253 | /// |
| 1254 | /// N |
| 1255 | /// || |
| 1256 | /// || |
| 1257 | /// store |
| 1258 | /// | |
| 1259 | /// U |
| 1260 | /// | |
| 1261 | /// ... |
| 1262 | /// |
| 1263 | /// This results in the store being scheduled immediately |
| 1264 | /// after N, which shortens the U->N live range, reducing |
| 1265 | /// register pressure. |
| 1266 | /// |
| 1267 | template<class SF> |
| 1268 | void RegReductionPriorityQueue<SF>::PrescheduleNodesWithMultipleUses() { |
| 1269 | // Visit all the nodes in topological order, working top-down. |
| 1270 | for (unsigned i = 0, e = SUnits->size(); i != e; ++i) { |
| 1271 | SUnit *SU = &(*SUnits)[i]; |
| 1272 | // For now, only look at nodes with no data successors, such as stores. |
| 1273 | // These are especially important, due to the heuristics in |
| 1274 | // getNodePriority for nodes with no data successors. |
| 1275 | if (SU->NumSuccs != 0) |
| 1276 | continue; |
| 1277 | // For now, only look at nodes with exactly one data predecessor. |
| 1278 | if (SU->NumPreds != 1) |
| 1279 | continue; |
| 1280 | // Avoid prescheduling copies to virtual registers, which don't behave |
| 1281 | // like other nodes from the perspective of scheduling heuristics. |
| 1282 | if (SDNode *N = SU->getNode()) |
| 1283 | if (N->getOpcode() == ISD::CopyToReg && |
| 1284 | TargetRegisterInfo::isVirtualRegister |
| 1285 | (cast<RegisterSDNode>(N->getOperand(1))->getReg())) |
| 1286 | continue; |
| 1287 | |
| 1288 | // Locate the single data predecessor. |
| 1289 | SUnit *PredSU = 0; |
| 1290 | for (SUnit::const_pred_iterator II = SU->Preds.begin(), |
| 1291 | EE = SU->Preds.end(); II != EE; ++II) |
| 1292 | if (!II->isCtrl()) { |
| 1293 | PredSU = II->getSUnit(); |
| 1294 | break; |
| 1295 | } |
| 1296 | assert(PredSU); |
| 1297 | |
| 1298 | // Don't rewrite edges that carry physregs, because that requires additional |
| 1299 | // support infrastructure. |
| 1300 | if (PredSU->hasPhysRegDefs) |
| 1301 | continue; |
| 1302 | // Short-circuit the case where SU is PredSU's only data successor. |
| 1303 | if (PredSU->NumSuccs == 1) |
| 1304 | continue; |
| 1305 | // Avoid prescheduling to copies from virtual registers, which don't behave |
| 1306 | // like other nodes from the perspective of scheduling // heuristics. |
| 1307 | if (SDNode *N = SU->getNode()) |
| 1308 | if (N->getOpcode() == ISD::CopyFromReg && |
| 1309 | TargetRegisterInfo::isVirtualRegister |
| 1310 | (cast<RegisterSDNode>(N->getOperand(1))->getReg())) |
| 1311 | continue; |
| 1312 | |
| 1313 | // Perform checks on the successors of PredSU. |
| 1314 | for (SUnit::const_succ_iterator II = PredSU->Succs.begin(), |
| 1315 | EE = PredSU->Succs.end(); II != EE; ++II) { |
| 1316 | SUnit *PredSuccSU = II->getSUnit(); |
| 1317 | if (PredSuccSU == SU) continue; |
| 1318 | // If PredSU has another successor with no data successors, for |
| 1319 | // now don't attempt to choose either over the other. |
| 1320 | if (PredSuccSU->NumSuccs == 0) |
| 1321 | goto outer_loop_continue; |
| 1322 | // Don't break physical register dependencies. |
| 1323 | if (SU->hasPhysRegClobbers && PredSuccSU->hasPhysRegDefs) |
| 1324 | if (canClobberPhysRegDefs(PredSuccSU, SU, TII, TRI)) |
| 1325 | goto outer_loop_continue; |
| 1326 | // Don't introduce graph cycles. |
| 1327 | if (scheduleDAG->IsReachable(SU, PredSuccSU)) |
| 1328 | goto outer_loop_continue; |
| 1329 | } |
| 1330 | |
| 1331 | // Ok, the transformation is safe and the heuristics suggest it is |
| 1332 | // profitable. Update the graph. |
Chris Lattner | 4dc3edd | 2009-08-23 06:35:02 +0000 | [diff] [blame^] | 1333 | DEBUG(errs() << "Prescheduling SU # " << SU->NodeNum |
| 1334 | << " next to PredSU # " << PredSU->NodeNum |
| 1335 | << " to guide scheduling in the presence of multiple uses\n"); |
Dan Gohman | 9a658d7 | 2009-03-24 00:49:12 +0000 | [diff] [blame] | 1336 | for (unsigned i = 0; i != PredSU->Succs.size(); ++i) { |
| 1337 | SDep Edge = PredSU->Succs[i]; |
| 1338 | assert(!Edge.isAssignedRegDep()); |
| 1339 | SUnit *SuccSU = Edge.getSUnit(); |
| 1340 | if (SuccSU != SU) { |
| 1341 | Edge.setSUnit(PredSU); |
| 1342 | scheduleDAG->RemovePred(SuccSU, Edge); |
| 1343 | scheduleDAG->AddPred(SU, Edge); |
| 1344 | Edge.setSUnit(SU); |
| 1345 | scheduleDAG->AddPred(SuccSU, Edge); |
| 1346 | --i; |
| 1347 | } |
| 1348 | } |
| 1349 | outer_loop_continue:; |
| 1350 | } |
| 1351 | } |
| 1352 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1353 | /// AddPseudoTwoAddrDeps - If two nodes share an operand and one of them uses |
| 1354 | /// it as a def&use operand. Add a pseudo control edge from it to the other |
| 1355 | /// node (if it won't create a cycle) so the two-address one will be scheduled |
Evan Cheng | a5e595d | 2007-09-28 22:32:30 +0000 | [diff] [blame] | 1356 | /// first (lower in the schedule). If both nodes are two-address, favor the |
| 1357 | /// one that has a CopyToReg use (more likely to be a loop induction update). |
| 1358 | /// If both are two-address, but one is commutable while the other is not |
| 1359 | /// commutable, favor the one that's not commutable. |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 1360 | template<class SF> |
| 1361 | void RegReductionPriorityQueue<SF>::AddPseudoTwoAddrDeps() { |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1362 | for (unsigned i = 0, e = SUnits->size(); i != e; ++i) { |
Dan Gohman | e955c48 | 2008-08-05 14:45:15 +0000 | [diff] [blame] | 1363 | SUnit *SU = &(*SUnits)[i]; |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1364 | if (!SU->isTwoAddress) |
| 1365 | continue; |
| 1366 | |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1367 | SDNode *Node = SU->getNode(); |
Dan Gohman | 072734e | 2008-11-13 23:24:17 +0000 | [diff] [blame] | 1368 | if (!Node || !Node->isMachineOpcode() || SU->getNode()->getFlaggedNode()) |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1369 | continue; |
| 1370 | |
Dan Gohman | 1705968 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 1371 | unsigned Opc = Node->getMachineOpcode(); |
Chris Lattner | 03ad885 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 1372 | const TargetInstrDesc &TID = TII->get(Opc); |
Chris Lattner | fd2e338 | 2008-01-07 06:47:00 +0000 | [diff] [blame] | 1373 | unsigned NumRes = TID.getNumDefs(); |
Dan Gohman | 0340d1e | 2008-02-15 20:50:13 +0000 | [diff] [blame] | 1374 | unsigned NumOps = TID.getNumOperands() - NumRes; |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1375 | for (unsigned j = 0; j != NumOps; ++j) { |
Dan Gohman | 82016c2 | 2008-11-19 02:00:32 +0000 | [diff] [blame] | 1376 | if (TID.getOperandConstraint(j+NumRes, TOI::TIED_TO) == -1) |
| 1377 | continue; |
| 1378 | SDNode *DU = SU->getNode()->getOperand(j).getNode(); |
| 1379 | if (DU->getNodeId() == -1) |
| 1380 | continue; |
| 1381 | const SUnit *DUSU = &(*SUnits)[DU->getNodeId()]; |
| 1382 | if (!DUSU) continue; |
| 1383 | for (SUnit::const_succ_iterator I = DUSU->Succs.begin(), |
| 1384 | E = DUSU->Succs.end(); I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 1385 | if (I->isCtrl()) continue; |
| 1386 | SUnit *SuccSU = I->getSUnit(); |
Dan Gohman | 82016c2 | 2008-11-19 02:00:32 +0000 | [diff] [blame] | 1387 | if (SuccSU == SU) |
Evan Cheng | 1bf16631 | 2007-11-09 01:27:11 +0000 | [diff] [blame] | 1388 | continue; |
Dan Gohman | 82016c2 | 2008-11-19 02:00:32 +0000 | [diff] [blame] | 1389 | // Be conservative. Ignore if nodes aren't at roughly the same |
| 1390 | // depth and height. |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 1391 | if (SuccSU->getHeight() < SU->getHeight() && |
| 1392 | (SU->getHeight() - SuccSU->getHeight()) > 1) |
Dan Gohman | 82016c2 | 2008-11-19 02:00:32 +0000 | [diff] [blame] | 1393 | continue; |
Dan Gohman | eefba6b | 2009-04-16 20:59:02 +0000 | [diff] [blame] | 1394 | // Skip past COPY_TO_REGCLASS nodes, so that the pseudo edge |
| 1395 | // constrains whatever is using the copy, instead of the copy |
| 1396 | // itself. In the case that the copy is coalesced, this |
| 1397 | // preserves the intent of the pseudo two-address heurietics. |
| 1398 | while (SuccSU->Succs.size() == 1 && |
| 1399 | SuccSU->getNode()->isMachineOpcode() && |
| 1400 | SuccSU->getNode()->getMachineOpcode() == |
| 1401 | TargetInstrInfo::COPY_TO_REGCLASS) |
| 1402 | SuccSU = SuccSU->Succs.front().getSUnit(); |
| 1403 | // Don't constrain non-instruction nodes. |
Dan Gohman | 82016c2 | 2008-11-19 02:00:32 +0000 | [diff] [blame] | 1404 | if (!SuccSU->getNode() || !SuccSU->getNode()->isMachineOpcode()) |
| 1405 | continue; |
| 1406 | // Don't constrain nodes with physical register defs if the |
| 1407 | // predecessor can clobber them. |
Dan Gohman | f3746cb | 2009-03-24 00:50:07 +0000 | [diff] [blame] | 1408 | if (SuccSU->hasPhysRegDefs && SU->hasPhysRegClobbers) { |
Dan Gohman | 82016c2 | 2008-11-19 02:00:32 +0000 | [diff] [blame] | 1409 | if (canClobberPhysRegDefs(SuccSU, SU, TII, TRI)) |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1410 | continue; |
Dan Gohman | 82016c2 | 2008-11-19 02:00:32 +0000 | [diff] [blame] | 1411 | } |
Dan Gohman | 3027bb6 | 2009-04-16 20:57:10 +0000 | [diff] [blame] | 1412 | // Don't constrain EXTRACT_SUBREG, INSERT_SUBREG, and SUBREG_TO_REG; |
| 1413 | // these may be coalesced away. We want them close to their uses. |
Dan Gohman | 82016c2 | 2008-11-19 02:00:32 +0000 | [diff] [blame] | 1414 | unsigned SuccOpc = SuccSU->getNode()->getMachineOpcode(); |
| 1415 | if (SuccOpc == TargetInstrInfo::EXTRACT_SUBREG || |
Dan Gohman | 3027bb6 | 2009-04-16 20:57:10 +0000 | [diff] [blame] | 1416 | SuccOpc == TargetInstrInfo::INSERT_SUBREG || |
| 1417 | SuccOpc == TargetInstrInfo::SUBREG_TO_REG) |
Dan Gohman | 82016c2 | 2008-11-19 02:00:32 +0000 | [diff] [blame] | 1418 | continue; |
| 1419 | if ((!canClobber(SuccSU, DUSU) || |
| 1420 | (hasCopyToRegUse(SU) && !hasCopyToRegUse(SuccSU)) || |
| 1421 | (!SU->isCommutable && SuccSU->isCommutable)) && |
| 1422 | !scheduleDAG->IsReachable(SuccSU, SU)) { |
Chris Lattner | 4dc3edd | 2009-08-23 06:35:02 +0000 | [diff] [blame^] | 1423 | DEBUG(errs() << "Adding a pseudo-two-addr edge from SU # " |
| 1424 | << SU->NodeNum << " to SU #" << SuccSU->NodeNum << "\n"); |
Dan Gohman | 79c3516 | 2009-01-06 01:19:04 +0000 | [diff] [blame] | 1425 | scheduleDAG->AddPred(SU, SDep(SuccSU, SDep::Order, /*Latency=*/0, |
Dan Gohman | bf8e520 | 2009-01-06 01:28:56 +0000 | [diff] [blame] | 1426 | /*Reg=*/0, /*isNormalMemory=*/false, |
| 1427 | /*isMustAlias=*/false, |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 1428 | /*isArtificial=*/true)); |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1429 | } |
| 1430 | } |
| 1431 | } |
| 1432 | } |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1433 | } |
| 1434 | |
Evan Cheng | 6730f03 | 2007-01-08 23:55:53 +0000 | [diff] [blame] | 1435 | /// CalculateSethiUllmanNumbers - Calculate Sethi-Ullman numbers of all |
| 1436 | /// scheduling units. |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1437 | template<class SF> |
| 1438 | void RegReductionPriorityQueue<SF>::CalculateSethiUllmanNumbers() { |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1439 | SethiUllmanNumbers.assign(SUnits->size(), 0); |
| 1440 | |
| 1441 | for (unsigned i = 0, e = SUnits->size(); i != e; ++i) |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1442 | CalcNodeSethiUllmanNumber(&(*SUnits)[i], SethiUllmanNumbers); |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1443 | } |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1444 | |
Roman Levenstein | 30d0951 | 2008-03-27 09:44:37 +0000 | [diff] [blame] | 1445 | /// LimitedSumOfUnscheduledPredsOfSuccs - Compute the sum of the unscheduled |
Roman Levenstein | bc67450 | 2008-03-27 09:14:57 +0000 | [diff] [blame] | 1446 | /// predecessors of the successors of the SUnit SU. Stop when the provided |
| 1447 | /// limit is exceeded. |
Roman Levenstein | bc67450 | 2008-03-27 09:14:57 +0000 | [diff] [blame] | 1448 | static unsigned LimitedSumOfUnscheduledPredsOfSuccs(const SUnit *SU, |
| 1449 | unsigned Limit) { |
| 1450 | unsigned Sum = 0; |
| 1451 | for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 1452 | I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 1453 | const SUnit *SuccSU = I->getSUnit(); |
Roman Levenstein | bc67450 | 2008-03-27 09:14:57 +0000 | [diff] [blame] | 1454 | for (SUnit::const_pred_iterator II = SuccSU->Preds.begin(), |
| 1455 | EE = SuccSU->Preds.end(); II != EE; ++II) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 1456 | SUnit *PredSU = II->getSUnit(); |
Evan Cheng | 16d7207 | 2008-03-29 18:34:22 +0000 | [diff] [blame] | 1457 | if (!PredSU->isScheduled) |
| 1458 | if (++Sum > Limit) |
| 1459 | return Sum; |
Roman Levenstein | bc67450 | 2008-03-27 09:14:57 +0000 | [diff] [blame] | 1460 | } |
| 1461 | } |
| 1462 | return Sum; |
| 1463 | } |
| 1464 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1465 | |
| 1466 | // Top down |
| 1467 | bool td_ls_rr_sort::operator()(const SUnit *left, const SUnit *right) const { |
Evan Cheng | 6730f03 | 2007-01-08 23:55:53 +0000 | [diff] [blame] | 1468 | unsigned LPriority = SPQ->getNodePriority(left); |
| 1469 | unsigned RPriority = SPQ->getNodePriority(right); |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1470 | bool LIsTarget = left->getNode() && left->getNode()->isMachineOpcode(); |
| 1471 | bool RIsTarget = right->getNode() && right->getNode()->isMachineOpcode(); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1472 | bool LIsFloater = LIsTarget && left->NumPreds == 0; |
| 1473 | bool RIsFloater = RIsTarget && right->NumPreds == 0; |
Roman Levenstein | bc67450 | 2008-03-27 09:14:57 +0000 | [diff] [blame] | 1474 | unsigned LBonus = (LimitedSumOfUnscheduledPredsOfSuccs(left,1) == 1) ? 2 : 0; |
| 1475 | unsigned RBonus = (LimitedSumOfUnscheduledPredsOfSuccs(right,1) == 1) ? 2 : 0; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1476 | |
| 1477 | if (left->NumSuccs == 0 && right->NumSuccs != 0) |
| 1478 | return false; |
| 1479 | else if (left->NumSuccs != 0 && right->NumSuccs == 0) |
| 1480 | return true; |
| 1481 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1482 | if (LIsFloater) |
| 1483 | LBonus -= 2; |
| 1484 | if (RIsFloater) |
| 1485 | RBonus -= 2; |
| 1486 | if (left->NumSuccs == 1) |
| 1487 | LBonus += 2; |
| 1488 | if (right->NumSuccs == 1) |
| 1489 | RBonus += 2; |
| 1490 | |
Evan Cheng | 73bdf04 | 2008-03-01 00:39:47 +0000 | [diff] [blame] | 1491 | if (LPriority+LBonus != RPriority+RBonus) |
| 1492 | return LPriority+LBonus < RPriority+RBonus; |
Anton Korobeynikov | 035eaac | 2008-02-20 11:10:28 +0000 | [diff] [blame] | 1493 | |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 1494 | if (left->getDepth() != right->getDepth()) |
| 1495 | return left->getDepth() < right->getDepth(); |
Evan Cheng | 73bdf04 | 2008-03-01 00:39:47 +0000 | [diff] [blame] | 1496 | |
| 1497 | if (left->NumSuccsLeft != right->NumSuccsLeft) |
| 1498 | return left->NumSuccsLeft > right->NumSuccsLeft; |
| 1499 | |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 1500 | assert(left->NodeQueueId && right->NodeQueueId && |
| 1501 | "NodeQueueId cannot be zero"); |
| 1502 | return (left->NodeQueueId > right->NodeQueueId); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1505 | //===----------------------------------------------------------------------===// |
| 1506 | // Public Constructor Functions |
| 1507 | //===----------------------------------------------------------------------===// |
| 1508 | |
Dan Gohman | dfaf646 | 2009-02-11 04:27:20 +0000 | [diff] [blame] | 1509 | llvm::ScheduleDAGSDNodes * |
Bill Wendling | 026e5d7 | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 1510 | llvm::createBURRListDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level) { |
Dan Gohman | 619ef48 | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 1511 | const TargetMachine &TM = IS->TM; |
| 1512 | const TargetInstrInfo *TII = TM.getInstrInfo(); |
| 1513 | const TargetRegisterInfo *TRI = TM.getRegisterInfo(); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 1514 | |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1515 | BURegReductionPriorityQueue *PQ = new BURegReductionPriorityQueue(TII, TRI); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 1516 | |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1517 | ScheduleDAGRRList *SD = |
Dan Gohman | 619ef48 | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 1518 | new ScheduleDAGRRList(*IS->MF, true, PQ); |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1519 | PQ->setScheduleDAG(SD); |
| 1520 | return SD; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1521 | } |
| 1522 | |
Dan Gohman | dfaf646 | 2009-02-11 04:27:20 +0000 | [diff] [blame] | 1523 | llvm::ScheduleDAGSDNodes * |
Bill Wendling | 026e5d7 | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 1524 | llvm::createTDRRListDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level) { |
Dan Gohman | 619ef48 | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 1525 | const TargetMachine &TM = IS->TM; |
| 1526 | const TargetInstrInfo *TII = TM.getInstrInfo(); |
| 1527 | const TargetRegisterInfo *TRI = TM.getRegisterInfo(); |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 1528 | |
| 1529 | TDRegReductionPriorityQueue *PQ = new TDRegReductionPriorityQueue(TII, TRI); |
| 1530 | |
Dan Gohman | 619ef48 | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 1531 | ScheduleDAGRRList *SD = |
| 1532 | new ScheduleDAGRRList(*IS->MF, false, PQ); |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 1533 | PQ->setScheduleDAG(SD); |
| 1534 | return SD; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1535 | } |