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