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" |
Chris Lattner | 3b9f02a | 2010-04-07 05:20:54 +0000 | [diff] [blame] | 20 | #include "llvm/InlineAsm.h" |
Jim Laskey | 29e635d | 2006-08-02 12:30:23 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/SchedulerRegistry.h" |
Dan Gohman | 619ef48 | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/SelectionDAGISel.h" |
Dan Gohman | 3a4be0f | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 23 | #include "llvm/Target/TargetRegisterInfo.h" |
Owen Anderson | 8c2c1e9 | 2006-05-12 06:33:49 +0000 | [diff] [blame] | 24 | #include "llvm/Target/TargetData.h" |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 25 | #include "llvm/Target/TargetMachine.h" |
| 26 | #include "llvm/Target/TargetInstrInfo.h" |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 27 | #include "llvm/Target/TargetLowering.h" |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/SmallSet.h" |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 29 | #include "llvm/ADT/Statistic.h" |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/STLExtras.h" |
Chris Lattner | 3b9f02a | 2010-04-07 05:20:54 +0000 | [diff] [blame] | 31 | #include "llvm/Support/Debug.h" |
| 32 | #include "llvm/Support/ErrorHandling.h" |
Chris Lattner | 4dc3edd | 2009-08-23 06:35:02 +0000 | [diff] [blame] | 33 | #include "llvm/Support/raw_ostream.h" |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 34 | #include <climits> |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 35 | using namespace llvm; |
| 36 | |
Dan Gohman | fd227e9 | 2008-03-25 17:10:29 +0000 | [diff] [blame] | 37 | STATISTIC(NumBacktracks, "Number of times scheduler backtracked"); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 38 | STATISTIC(NumUnfolds, "Number of nodes unfolded"); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 39 | STATISTIC(NumDups, "Number of duplicated nodes"); |
Evan Cheng | b2c42c6 | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 40 | STATISTIC(NumPRCopies, "Number of physical register copies"); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 41 | |
Jim Laskey | 95eda5b | 2006-08-01 14:21:23 +0000 | [diff] [blame] | 42 | static RegisterScheduler |
| 43 | burrListDAGScheduler("list-burr", |
Dan Gohman | 9c4b7d5 | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 44 | "Bottom-up register reduction list scheduling", |
Jim Laskey | 95eda5b | 2006-08-01 14:21:23 +0000 | [diff] [blame] | 45 | createBURRListDAGScheduler); |
| 46 | static RegisterScheduler |
| 47 | tdrListrDAGScheduler("list-tdrr", |
Dan Gohman | 9c4b7d5 | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 48 | "Top-down register reduction list scheduling", |
Jim Laskey | 95eda5b | 2006-08-01 14:21:23 +0000 | [diff] [blame] | 49 | createTDRRListDAGScheduler); |
Bill Wendling | 8cbc25d | 2010-01-23 10:26:57 +0000 | [diff] [blame] | 50 | static RegisterScheduler |
| 51 | sourceListDAGScheduler("source", |
| 52 | "Similar to list-burr but schedules in source " |
| 53 | "order when possible", |
| 54 | createSourceListDAGScheduler); |
Jim Laskey | 95eda5b | 2006-08-01 14:21:23 +0000 | [diff] [blame] | 55 | |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 56 | static RegisterScheduler |
Evan Cheng | 725211e | 2010-05-21 00:42:32 +0000 | [diff] [blame] | 57 | hybridListDAGScheduler("list-hybrid", |
Evan Cheng | 37b740c | 2010-07-24 00:39:05 +0000 | [diff] [blame] | 58 | "Bottom-up register pressure aware list scheduling " |
| 59 | "which tries to balance latency and register pressure", |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 60 | createHybridListDAGScheduler); |
| 61 | |
Evan Cheng | 37b740c | 2010-07-24 00:39:05 +0000 | [diff] [blame] | 62 | static RegisterScheduler |
| 63 | ILPListDAGScheduler("list-ilp", |
| 64 | "Bottom-up register pressure aware list scheduling " |
| 65 | "which tries to balance ILP and register pressure", |
| 66 | createILPListDAGScheduler); |
| 67 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 68 | namespace { |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 69 | //===----------------------------------------------------------------------===// |
| 70 | /// ScheduleDAGRRList - The actual register reduction list scheduler |
| 71 | /// implementation. This supports both top-down and bottom-up scheduling. |
| 72 | /// |
Nick Lewycky | 02d5f77 | 2009-10-25 06:33:48 +0000 | [diff] [blame] | 73 | class ScheduleDAGRRList : public ScheduleDAGSDNodes { |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 74 | private: |
| 75 | /// isBottomUp - This is true if the scheduling problem is bottom-up, false if |
| 76 | /// it is top-down. |
| 77 | bool isBottomUp; |
Evan Cheng | 2c97731 | 2008-07-01 18:05:03 +0000 | [diff] [blame] | 78 | |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 79 | /// NeedLatency - True if the scheduler will make use of latency information. |
| 80 | /// |
| 81 | bool NeedLatency; |
| 82 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 83 | /// AvailableQueue - The priority queue to use for the available SUnits. |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 84 | SchedulingPriorityQueue *AvailableQueue; |
| 85 | |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 86 | /// LiveRegDefs - A set of physical registers and their definition |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 87 | /// that are "live". These nodes must be scheduled before any other nodes that |
| 88 | /// modifies the registers can be scheduled. |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 89 | unsigned NumLiveRegs; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 90 | std::vector<SUnit*> LiveRegDefs; |
| 91 | std::vector<unsigned> LiveRegCycles; |
| 92 | |
Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 93 | /// Topo - A topological ordering for SUnits which permits fast IsReachable |
| 94 | /// and similar queries. |
| 95 | ScheduleDAGTopologicalSort Topo; |
| 96 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 97 | public: |
Dan Gohman | 619ef48 | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 98 | ScheduleDAGRRList(MachineFunction &mf, |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 99 | bool isbottomup, bool needlatency, |
Evan Cheng | 2c97731 | 2008-07-01 18:05:03 +0000 | [diff] [blame] | 100 | SchedulingPriorityQueue *availqueue) |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 101 | : ScheduleDAGSDNodes(mf), isBottomUp(isbottomup), NeedLatency(needlatency), |
Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 102 | AvailableQueue(availqueue), Topo(SUnits) { |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | ~ScheduleDAGRRList() { |
| 106 | delete AvailableQueue; |
| 107 | } |
| 108 | |
| 109 | void Schedule(); |
| 110 | |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 111 | /// IsReachable - Checks if SU is reachable from TargetSU. |
Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 112 | bool IsReachable(const SUnit *SU, const SUnit *TargetSU) { |
| 113 | return Topo.IsReachable(SU, TargetSU); |
| 114 | } |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 115 | |
Dan Gohman | 60d6844 | 2009-01-29 19:49:27 +0000 | [diff] [blame] | 116 | /// WillCreateCycle - Returns true if adding an edge from SU to TargetSU will |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 117 | /// create a cycle. |
Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 118 | bool WillCreateCycle(SUnit *SU, SUnit *TargetSU) { |
| 119 | return Topo.WillCreateCycle(SU, TargetSU); |
| 120 | } |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 121 | |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 122 | /// AddPred - adds a predecessor edge to SUnit SU. |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 123 | /// This returns true if this is a new predecessor. |
| 124 | /// Updates the topological ordering if required. |
Dan Gohman | 17214e6 | 2008-12-16 01:00:55 +0000 | [diff] [blame] | 125 | void AddPred(SUnit *SU, const SDep &D) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 126 | Topo.AddPred(SU, D.getSUnit()); |
Dan Gohman | 17214e6 | 2008-12-16 01:00:55 +0000 | [diff] [blame] | 127 | SU->addPred(D); |
Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 128 | } |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 129 | |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 130 | /// RemovePred - removes a predecessor edge from SUnit SU. |
| 131 | /// This returns true if an edge was removed. |
| 132 | /// Updates the topological ordering if required. |
Dan Gohman | 17214e6 | 2008-12-16 01:00:55 +0000 | [diff] [blame] | 133 | void RemovePred(SUnit *SU, const SDep &D) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 134 | Topo.RemovePred(SU, D.getSUnit()); |
Dan Gohman | 17214e6 | 2008-12-16 01:00:55 +0000 | [diff] [blame] | 135 | SU->removePred(D); |
Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 136 | } |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 137 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 138 | private: |
Dan Gohman | 60d6844 | 2009-01-29 19:49:27 +0000 | [diff] [blame] | 139 | void ReleasePred(SUnit *SU, const SDep *PredEdge); |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 140 | void ReleasePredecessors(SUnit *SU, unsigned CurCycle); |
Dan Gohman | 60d6844 | 2009-01-29 19:49:27 +0000 | [diff] [blame] | 141 | void ReleaseSucc(SUnit *SU, const SDep *SuccEdge); |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 142 | void ReleaseSuccessors(SUnit *SU); |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 143 | void CapturePred(SDep *PredEdge); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 144 | void ScheduleNodeBottomUp(SUnit*, unsigned); |
| 145 | void ScheduleNodeTopDown(SUnit*, unsigned); |
| 146 | void UnscheduleNodeBottomUp(SUnit*); |
| 147 | void BacktrackBottomUp(SUnit*, unsigned, unsigned&); |
| 148 | SUnit *CopyAndMoveSuccessors(SUnit*); |
Evan Cheng | b2c42c6 | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 149 | void InsertCopiesAndMoveSuccs(SUnit*, unsigned, |
| 150 | const TargetRegisterClass*, |
| 151 | const TargetRegisterClass*, |
| 152 | SmallVector<SUnit*, 2>&); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 153 | bool DelayForLiveRegsBottomUp(SUnit*, SmallVector<unsigned, 4>&); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 154 | void ListScheduleTopDown(); |
| 155 | void ListScheduleBottomUp(); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 156 | |
| 157 | |
| 158 | /// CreateNewSUnit - Creates a new SUnit and returns a pointer to it. |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 159 | /// Updates the topological ordering if required. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 160 | SUnit *CreateNewSUnit(SDNode *N) { |
Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 161 | unsigned NumSUnits = SUnits.size(); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 162 | SUnit *NewNode = NewSUnit(N); |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 163 | // Update the topological ordering. |
Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 164 | if (NewNode->NodeNum >= NumSUnits) |
| 165 | Topo.InitDAGTopologicalSorting(); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 166 | return NewNode; |
| 167 | } |
| 168 | |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 169 | /// CreateClone - Creates a new SUnit from an existing one. |
| 170 | /// Updates the topological ordering if required. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 171 | SUnit *CreateClone(SUnit *N) { |
Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 172 | unsigned NumSUnits = SUnits.size(); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 173 | SUnit *NewNode = Clone(N); |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 174 | // Update the topological ordering. |
Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 175 | if (NewNode->NodeNum >= NumSUnits) |
| 176 | Topo.InitDAGTopologicalSorting(); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 177 | return NewNode; |
| 178 | } |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 179 | |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 180 | /// ForceUnitLatencies - Register-pressure-reducing scheduling doesn't |
| 181 | /// need actual latency information but the hybrid scheduler does. |
| 182 | bool ForceUnitLatencies() const { |
| 183 | return !NeedLatency; |
| 184 | } |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 185 | }; |
| 186 | } // end anonymous namespace |
| 187 | |
| 188 | |
| 189 | /// Schedule - Schedule the DAG using list scheduling. |
| 190 | void ScheduleDAGRRList::Schedule() { |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 191 | DEBUG(dbgs() |
| 192 | << "********** List Scheduling BB#" << BB->getNumber() |
Evan Cheng | 6c1414f | 2010-10-29 18:09:28 +0000 | [diff] [blame] | 193 | << " '" << BB->getName() << "' **********\n"); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 194 | |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 195 | NumLiveRegs = 0; |
Dan Gohman | 3a4be0f | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 196 | LiveRegDefs.resize(TRI->getNumRegs(), NULL); |
| 197 | LiveRegCycles.resize(TRI->getNumRegs(), 0); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 198 | |
Dan Gohman | 04543e7 | 2008-12-23 18:36:58 +0000 | [diff] [blame] | 199 | // Build the scheduling graph. |
Dan Gohman | 918ec53 | 2009-10-09 23:33:48 +0000 | [diff] [blame] | 200 | BuildSchedGraph(NULL); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 201 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 202 | DEBUG(for (unsigned su = 0, e = SUnits.size(); su != e; ++su) |
Dan Gohman | 22d07b1 | 2008-11-18 02:06:40 +0000 | [diff] [blame] | 203 | SUnits[su].dumpAll(this)); |
Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 204 | Topo.InitDAGTopologicalSorting(); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 205 | |
Dan Gohman | 46520a2 | 2008-06-21 19:18:17 +0000 | [diff] [blame] | 206 | AvailableQueue->initNodes(SUnits); |
Dan Gohman | 54a187e | 2007-08-20 19:28:38 +0000 | [diff] [blame] | 207 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 208 | // Execute the actual scheduling loop Top-Down or Bottom-Up as appropriate. |
| 209 | if (isBottomUp) |
| 210 | ListScheduleBottomUp(); |
| 211 | else |
| 212 | ListScheduleTopDown(); |
| 213 | |
| 214 | AvailableQueue->releaseState(); |
Evan Cheng | afed73e | 2006-05-12 01:58:24 +0000 | [diff] [blame] | 215 | } |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 216 | |
| 217 | //===----------------------------------------------------------------------===// |
| 218 | // Bottom-Up Scheduling |
| 219 | //===----------------------------------------------------------------------===// |
| 220 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 221 | /// ReleasePred - Decrement the NumSuccsLeft count of a predecessor. Add it to |
Dan Gohman | 54a187e | 2007-08-20 19:28:38 +0000 | [diff] [blame] | 222 | /// the AvailableQueue if the count reaches zero. Also update its cycle bound. |
Dan Gohman | 60d6844 | 2009-01-29 19:49:27 +0000 | [diff] [blame] | 223 | void ScheduleDAGRRList::ReleasePred(SUnit *SU, const SDep *PredEdge) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 224 | SUnit *PredSU = PredEdge->getSUnit(); |
Reid Kleckner | cea8dab | 2009-09-30 20:43:07 +0000 | [diff] [blame] | 225 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 226 | #ifndef NDEBUG |
Reid Kleckner | cea8dab | 2009-09-30 20:43:07 +0000 | [diff] [blame] | 227 | if (PredSU->NumSuccsLeft == 0) { |
David Greene | f34d7ac | 2010-01-05 01:24:54 +0000 | [diff] [blame] | 228 | dbgs() << "*** Scheduling failed! ***\n"; |
Dan Gohman | 22d07b1 | 2008-11-18 02:06:40 +0000 | [diff] [blame] | 229 | PredSU->dump(this); |
David Greene | f34d7ac | 2010-01-05 01:24:54 +0000 | [diff] [blame] | 230 | dbgs() << " has been released too many times!\n"; |
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 231 | llvm_unreachable(0); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 232 | } |
| 233 | #endif |
Reid Kleckner | cea8dab | 2009-09-30 20:43:07 +0000 | [diff] [blame] | 234 | --PredSU->NumSuccsLeft; |
| 235 | |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 236 | if (!ForceUnitLatencies()) { |
| 237 | // Updating predecessor's height. This is now the cycle when the |
| 238 | // predecessor can be scheduled without causing a pipeline stall. |
| 239 | PredSU->setHeightToAtLeast(SU->getHeight() + PredEdge->getLatency()); |
| 240 | } |
| 241 | |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 242 | // If all the node's successors are scheduled, this node is ready |
| 243 | // to be scheduled. Ignore the special EntrySU node. |
| 244 | if (PredSU->NumSuccsLeft == 0 && PredSU != &EntrySU) { |
Dan Gohman | 4370f26 | 2008-04-15 01:22:18 +0000 | [diff] [blame] | 245 | PredSU->isAvailable = true; |
| 246 | AvailableQueue->push(PredSU); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 250 | void ScheduleDAGRRList::ReleasePredecessors(SUnit *SU, unsigned CurCycle) { |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 251 | // Bottom up: release predecessors |
Chris Lattner | d86418a | 2006-08-17 00:09:56 +0000 | [diff] [blame] | 252 | for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 253 | I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 254 | ReleasePred(SU, &*I); |
| 255 | if (I->isAssignedRegDep()) { |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 256 | // This is a physical register dependency and it's impossible or |
| 257 | // expensive to copy the register. Make sure nothing that can |
| 258 | // clobber the register is scheduled between the predecessor and |
| 259 | // this node. |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 260 | if (!LiveRegDefs[I->getReg()]) { |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 261 | ++NumLiveRegs; |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 262 | LiveRegDefs[I->getReg()] = I->getSUnit(); |
| 263 | LiveRegCycles[I->getReg()] = CurCycle; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | } |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | /// ScheduleNodeBottomUp - Add the node to the schedule. Decrement the pending |
| 270 | /// count of its predecessors. If a predecessor pending count is zero, add it to |
| 271 | /// the Available queue. |
| 272 | void ScheduleDAGRRList::ScheduleNodeBottomUp(SUnit *SU, unsigned CurCycle) { |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 273 | DEBUG(dbgs() << "\n*** Scheduling [" << CurCycle << "]: "); |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 274 | DEBUG(SU->dump(this)); |
| 275 | |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 276 | #ifndef NDEBUG |
| 277 | if (CurCycle < SU->getHeight()) |
| 278 | DEBUG(dbgs() << " Height [" << SU->getHeight() << "] pipeline stall!\n"); |
| 279 | #endif |
| 280 | |
| 281 | // FIXME: Handle noop hazard. |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 282 | SU->setHeightToAtLeast(CurCycle); |
| 283 | Sequence.push_back(SU); |
| 284 | |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 285 | AvailableQueue->ScheduledNode(SU); |
Chris Lattner | 981afd2 | 2010-12-20 00:55:43 +0000 | [diff] [blame^] | 286 | |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 287 | ReleasePredecessors(SU, CurCycle); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 288 | |
| 289 | // Release all the implicit physical register defs that are live. |
| 290 | for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 291 | I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 292 | if (I->isAssignedRegDep()) { |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 293 | if (LiveRegCycles[I->getReg()] == I->getSUnit()->getHeight()) { |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 294 | assert(NumLiveRegs > 0 && "NumLiveRegs is already zero!"); |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 295 | assert(LiveRegDefs[I->getReg()] == SU && |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 296 | "Physical register dependency violated?"); |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 297 | --NumLiveRegs; |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 298 | LiveRegDefs[I->getReg()] = NULL; |
| 299 | LiveRegCycles[I->getReg()] = 0; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | } |
| 303 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 304 | SU->isScheduled = true; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 307 | /// CapturePred - This does the opposite of ReleasePred. Since SU is being |
| 308 | /// unscheduled, incrcease the succ left count of its predecessors. Remove |
| 309 | /// them from AvailableQueue if necessary. |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 310 | void ScheduleDAGRRList::CapturePred(SDep *PredEdge) { |
| 311 | SUnit *PredSU = PredEdge->getSUnit(); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 312 | if (PredSU->isAvailable) { |
| 313 | PredSU->isAvailable = false; |
| 314 | if (!PredSU->isPending) |
| 315 | AvailableQueue->remove(PredSU); |
| 316 | } |
| 317 | |
Reid Kleckner | 8ff5c19 | 2009-09-30 20:15:38 +0000 | [diff] [blame] | 318 | assert(PredSU->NumSuccsLeft < UINT_MAX && "NumSuccsLeft will overflow!"); |
Evan Cheng | 038dcc5 | 2007-09-28 19:24:24 +0000 | [diff] [blame] | 319 | ++PredSU->NumSuccsLeft; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | /// UnscheduleNodeBottomUp - Remove the node from the schedule, update its and |
| 323 | /// its predecessor states to reflect the change. |
| 324 | void ScheduleDAGRRList::UnscheduleNodeBottomUp(SUnit *SU) { |
David Greene | f34d7ac | 2010-01-05 01:24:54 +0000 | [diff] [blame] | 325 | DEBUG(dbgs() << "*** Unscheduling [" << SU->getHeight() << "]: "); |
Dan Gohman | 22d07b1 | 2008-11-18 02:06:40 +0000 | [diff] [blame] | 326 | DEBUG(SU->dump(this)); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 327 | |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 328 | for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
| 329 | I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 330 | CapturePred(&*I); |
Evan Cheng | cc2efe1 | 2010-05-28 23:26:21 +0000 | [diff] [blame] | 331 | if (I->isAssignedRegDep() && SU->getHeight() == LiveRegCycles[I->getReg()]){ |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 332 | assert(NumLiveRegs > 0 && "NumLiveRegs is already zero!"); |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 333 | assert(LiveRegDefs[I->getReg()] == I->getSUnit() && |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 334 | "Physical register dependency violated?"); |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 335 | --NumLiveRegs; |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 336 | LiveRegDefs[I->getReg()] = NULL; |
| 337 | LiveRegCycles[I->getReg()] = 0; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 338 | } |
| 339 | } |
| 340 | |
| 341 | for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 342 | I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 343 | if (I->isAssignedRegDep()) { |
| 344 | if (!LiveRegDefs[I->getReg()]) { |
| 345 | LiveRegDefs[I->getReg()] = SU; |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 346 | ++NumLiveRegs; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 347 | } |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 348 | if (I->getSUnit()->getHeight() < LiveRegCycles[I->getReg()]) |
| 349 | LiveRegCycles[I->getReg()] = I->getSUnit()->getHeight(); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 353 | SU->setHeightDirty(); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 354 | SU->isScheduled = false; |
| 355 | SU->isAvailable = true; |
| 356 | AvailableQueue->push(SU); |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 357 | AvailableQueue->UnscheduledNode(SU); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 360 | /// BacktrackBottomUp - Backtrack scheduling to a previous cycle specified in |
Dan Gohman | 60d6844 | 2009-01-29 19:49:27 +0000 | [diff] [blame] | 361 | /// BTCycle in order to schedule a specific node. |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 362 | void ScheduleDAGRRList::BacktrackBottomUp(SUnit *SU, unsigned BtCycle, |
| 363 | unsigned &CurCycle) { |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 364 | SUnit *OldSU = NULL; |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 365 | while (CurCycle > BtCycle) { |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 366 | OldSU = Sequence.back(); |
| 367 | Sequence.pop_back(); |
| 368 | if (SU->isSucc(OldSU)) |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 369 | // Don't try to remove SU from AvailableQueue. |
| 370 | SU->isAvailable = false; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 371 | UnscheduleNodeBottomUp(OldSU); |
| 372 | --CurCycle; |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 373 | AvailableQueue->setCurCycle(CurCycle); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 374 | } |
| 375 | |
Dan Gohman | 60d6844 | 2009-01-29 19:49:27 +0000 | [diff] [blame] | 376 | assert(!SU->isSucc(OldSU) && "Something is wrong!"); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 377 | |
| 378 | ++NumBacktracks; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 379 | } |
| 380 | |
Evan Cheng | 3b24587 | 2010-02-05 01:27:11 +0000 | [diff] [blame] | 381 | static bool isOperandOf(const SUnit *SU, SDNode *N) { |
| 382 | for (const SDNode *SUNode = SU->getNode(); SUNode; |
| 383 | SUNode = SUNode->getFlaggedNode()) { |
| 384 | if (SUNode->isOperandOf(N)) |
| 385 | return true; |
| 386 | } |
| 387 | return false; |
| 388 | } |
| 389 | |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 390 | /// CopyAndMoveSuccessors - Clone the specified node and move its scheduled |
| 391 | /// successors to the newly created node. |
| 392 | SUnit *ScheduleDAGRRList::CopyAndMoveSuccessors(SUnit *SU) { |
Dan Gohman | 072734e | 2008-11-13 23:24:17 +0000 | [diff] [blame] | 393 | if (SU->getNode()->getFlaggedNode()) |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 394 | return NULL; |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 395 | |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 396 | SDNode *N = SU->getNode(); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 397 | if (!N) |
| 398 | return NULL; |
| 399 | |
| 400 | SUnit *NewSU; |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 401 | bool TryUnfold = false; |
Evan Cheng | 84d0ebc | 2007-10-05 01:42:35 +0000 | [diff] [blame] | 402 | for (unsigned i = 0, e = N->getNumValues(); i != e; ++i) { |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 403 | EVT VT = N->getValueType(i); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 404 | if (VT == MVT::Flag) |
Evan Cheng | 84d0ebc | 2007-10-05 01:42:35 +0000 | [diff] [blame] | 405 | return NULL; |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 406 | else if (VT == MVT::Other) |
Evan Cheng | 84d0ebc | 2007-10-05 01:42:35 +0000 | [diff] [blame] | 407 | TryUnfold = true; |
| 408 | } |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 409 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 410 | const SDValue &Op = N->getOperand(i); |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 411 | EVT VT = Op.getNode()->getValueType(Op.getResNo()); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 412 | if (VT == MVT::Flag) |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 413 | return NULL; |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | if (TryUnfold) { |
Dan Gohman | e6e1348 | 2008-06-21 15:52:51 +0000 | [diff] [blame] | 417 | SmallVector<SDNode*, 2> NewNodes; |
Dan Gohman | 5a390b9 | 2008-11-13 21:21:28 +0000 | [diff] [blame] | 418 | if (!TII->unfoldMemoryOperand(*DAG, N, NewNodes)) |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 419 | return NULL; |
| 420 | |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 421 | DEBUG(dbgs() << "Unfolding SU #" << SU->NodeNum << "\n"); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 422 | assert(NewNodes.size() == 2 && "Expected a load folding node!"); |
| 423 | |
| 424 | N = NewNodes[1]; |
| 425 | SDNode *LoadNode = NewNodes[0]; |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 426 | unsigned NumVals = N->getNumValues(); |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 427 | unsigned OldNumVals = SU->getNode()->getNumValues(); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 428 | for (unsigned i = 0; i != NumVals; ++i) |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 429 | DAG->ReplaceAllUsesOfValueWith(SDValue(SU->getNode(), i), SDValue(N, i)); |
| 430 | DAG->ReplaceAllUsesOfValueWith(SDValue(SU->getNode(), OldNumVals-1), |
Dan Gohman | 5a390b9 | 2008-11-13 21:21:28 +0000 | [diff] [blame] | 431 | SDValue(LoadNode, 1)); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 432 | |
Dan Gohman | e52e089 | 2008-11-11 21:34:44 +0000 | [diff] [blame] | 433 | // LoadNode may already exist. This can happen when there is another |
| 434 | // load from the same location and producing the same type of value |
| 435 | // but it has different alignment or volatileness. |
| 436 | bool isNewLoad = true; |
| 437 | SUnit *LoadSU; |
| 438 | if (LoadNode->getNodeId() != -1) { |
| 439 | LoadSU = &SUnits[LoadNode->getNodeId()]; |
| 440 | isNewLoad = false; |
| 441 | } else { |
| 442 | LoadSU = CreateNewSUnit(LoadNode); |
| 443 | LoadNode->setNodeId(LoadSU->NodeNum); |
Dan Gohman | e52e089 | 2008-11-11 21:34:44 +0000 | [diff] [blame] | 444 | ComputeLatency(LoadSU); |
| 445 | } |
| 446 | |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 447 | SUnit *NewSU = CreateNewSUnit(N); |
Dan Gohman | 46520a2 | 2008-06-21 19:18:17 +0000 | [diff] [blame] | 448 | assert(N->getNodeId() == -1 && "Node already inserted!"); |
| 449 | N->setNodeId(NewSU->NodeNum); |
Dan Gohman | e6e1348 | 2008-06-21 15:52:51 +0000 | [diff] [blame] | 450 | |
Dan Gohman | 1705968 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 451 | const TargetInstrDesc &TID = TII->get(N->getMachineOpcode()); |
Dan Gohman | 856c012 | 2008-02-16 00:25:40 +0000 | [diff] [blame] | 452 | for (unsigned i = 0; i != TID.getNumOperands(); ++i) { |
Chris Lattner | fd2e338 | 2008-01-07 06:47:00 +0000 | [diff] [blame] | 453 | if (TID.getOperandConstraint(i, TOI::TIED_TO) != -1) { |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 454 | NewSU->isTwoAddress = true; |
| 455 | break; |
| 456 | } |
| 457 | } |
Chris Lattner | fd2e338 | 2008-01-07 06:47:00 +0000 | [diff] [blame] | 458 | if (TID.isCommutable()) |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 459 | NewSU->isCommutable = true; |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 460 | ComputeLatency(NewSU); |
| 461 | |
Dan Gohman | ed0e8d4 | 2009-03-23 20:20:43 +0000 | [diff] [blame] | 462 | // Record all the edges to and from the old SU, by category. |
Dan Gohman | 15af552 | 2009-03-06 02:23:01 +0000 | [diff] [blame] | 463 | SmallVector<SDep, 4> ChainPreds; |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 464 | SmallVector<SDep, 4> ChainSuccs; |
| 465 | SmallVector<SDep, 4> LoadPreds; |
| 466 | SmallVector<SDep, 4> NodePreds; |
| 467 | SmallVector<SDep, 4> NodeSuccs; |
| 468 | for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
| 469 | I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 470 | if (I->isCtrl()) |
Dan Gohman | 15af552 | 2009-03-06 02:23:01 +0000 | [diff] [blame] | 471 | ChainPreds.push_back(*I); |
Evan Cheng | 3b24587 | 2010-02-05 01:27:11 +0000 | [diff] [blame] | 472 | else if (isOperandOf(I->getSUnit(), LoadNode)) |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 473 | LoadPreds.push_back(*I); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 474 | else |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 475 | NodePreds.push_back(*I); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 476 | } |
| 477 | for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 478 | I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 479 | if (I->isCtrl()) |
| 480 | ChainSuccs.push_back(*I); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 481 | else |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 482 | NodeSuccs.push_back(*I); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 483 | } |
| 484 | |
Dan Gohman | ed0e8d4 | 2009-03-23 20:20:43 +0000 | [diff] [blame] | 485 | // Now assign edges to the newly-created nodes. |
Dan Gohman | 15af552 | 2009-03-06 02:23:01 +0000 | [diff] [blame] | 486 | for (unsigned i = 0, e = ChainPreds.size(); i != e; ++i) { |
| 487 | const SDep &Pred = ChainPreds[i]; |
| 488 | RemovePred(SU, Pred); |
Dan Gohman | 4370f26 | 2008-04-15 01:22:18 +0000 | [diff] [blame] | 489 | if (isNewLoad) |
Dan Gohman | 15af552 | 2009-03-06 02:23:01 +0000 | [diff] [blame] | 490 | AddPred(LoadSU, Pred); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 491 | } |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 492 | for (unsigned i = 0, e = LoadPreds.size(); i != e; ++i) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 493 | const SDep &Pred = LoadPreds[i]; |
| 494 | RemovePred(SU, Pred); |
Dan Gohman | 15af552 | 2009-03-06 02:23:01 +0000 | [diff] [blame] | 495 | if (isNewLoad) |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 496 | AddPred(LoadSU, Pred); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 497 | } |
| 498 | for (unsigned i = 0, e = NodePreds.size(); i != e; ++i) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 499 | const SDep &Pred = NodePreds[i]; |
| 500 | RemovePred(SU, Pred); |
| 501 | AddPred(NewSU, Pred); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 502 | } |
| 503 | for (unsigned i = 0, e = NodeSuccs.size(); i != e; ++i) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 504 | SDep D = NodeSuccs[i]; |
| 505 | SUnit *SuccDep = D.getSUnit(); |
| 506 | D.setSUnit(SU); |
| 507 | RemovePred(SuccDep, D); |
| 508 | D.setSUnit(NewSU); |
| 509 | AddPred(SuccDep, D); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 510 | } |
| 511 | for (unsigned i = 0, e = ChainSuccs.size(); i != e; ++i) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 512 | SDep D = ChainSuccs[i]; |
| 513 | SUnit *SuccDep = D.getSUnit(); |
| 514 | D.setSUnit(SU); |
| 515 | RemovePred(SuccDep, D); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 516 | if (isNewLoad) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 517 | D.setSUnit(LoadSU); |
| 518 | AddPred(SuccDep, D); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 519 | } |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 520 | } |
Dan Gohman | ed0e8d4 | 2009-03-23 20:20:43 +0000 | [diff] [blame] | 521 | |
| 522 | // Add a data dependency to reflect that NewSU reads the value defined |
| 523 | // by LoadSU. |
| 524 | AddPred(NewSU, SDep(LoadSU, SDep::Data, LoadSU->Latency)); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 525 | |
Evan Cheng | 91e0fc9 | 2007-12-18 08:42:10 +0000 | [diff] [blame] | 526 | if (isNewLoad) |
| 527 | AvailableQueue->addNode(LoadSU); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 528 | AvailableQueue->addNode(NewSU); |
| 529 | |
| 530 | ++NumUnfolds; |
| 531 | |
| 532 | if (NewSU->NumSuccsLeft == 0) { |
| 533 | NewSU->isAvailable = true; |
| 534 | return NewSU; |
Evan Cheng | 91e0fc9 | 2007-12-18 08:42:10 +0000 | [diff] [blame] | 535 | } |
| 536 | SU = NewSU; |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 537 | } |
| 538 | |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 539 | DEBUG(dbgs() << " Duplicating SU #" << SU->NodeNum << "\n"); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 540 | NewSU = CreateClone(SU); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 541 | |
| 542 | // New SUnit has the exact same predecessors. |
| 543 | for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
| 544 | I != E; ++I) |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 545 | if (!I->isArtificial()) |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 546 | AddPred(NewSU, *I); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 547 | |
| 548 | // Only copy scheduled successors. Cut them from old node's successor |
| 549 | // list and move them over. |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 550 | SmallVector<std::pair<SUnit *, SDep>, 4> DelDeps; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 551 | for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 552 | I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 553 | if (I->isArtificial()) |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 554 | continue; |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 555 | SUnit *SuccSU = I->getSUnit(); |
| 556 | if (SuccSU->isScheduled) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 557 | SDep D = *I; |
| 558 | D.setSUnit(NewSU); |
| 559 | AddPred(SuccSU, D); |
| 560 | D.setSUnit(SU); |
| 561 | DelDeps.push_back(std::make_pair(SuccSU, D)); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 562 | } |
| 563 | } |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 564 | for (unsigned i = 0, e = DelDeps.size(); i != e; ++i) |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 565 | RemovePred(DelDeps[i].first, DelDeps[i].second); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 566 | |
| 567 | AvailableQueue->updateNode(SU); |
| 568 | AvailableQueue->addNode(NewSU); |
| 569 | |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 570 | ++NumDups; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 571 | return NewSU; |
| 572 | } |
| 573 | |
Evan Cheng | b2c42c6 | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 574 | /// InsertCopiesAndMoveSuccs - Insert register copies and move all |
| 575 | /// scheduled successors of the given SUnit to the last copy. |
| 576 | void ScheduleDAGRRList::InsertCopiesAndMoveSuccs(SUnit *SU, unsigned Reg, |
| 577 | const TargetRegisterClass *DestRC, |
| 578 | const TargetRegisterClass *SrcRC, |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 579 | SmallVector<SUnit*, 2> &Copies) { |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 580 | SUnit *CopyFromSU = CreateNewSUnit(NULL); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 581 | CopyFromSU->CopySrcRC = SrcRC; |
| 582 | CopyFromSU->CopyDstRC = DestRC; |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 583 | |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 584 | SUnit *CopyToSU = CreateNewSUnit(NULL); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 585 | CopyToSU->CopySrcRC = DestRC; |
| 586 | CopyToSU->CopyDstRC = SrcRC; |
| 587 | |
| 588 | // Only copy scheduled successors. Cut them from old node's successor |
| 589 | // list and move them over. |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 590 | SmallVector<std::pair<SUnit *, SDep>, 4> DelDeps; |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 591 | for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 592 | I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 593 | if (I->isArtificial()) |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 594 | continue; |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 595 | SUnit *SuccSU = I->getSUnit(); |
| 596 | if (SuccSU->isScheduled) { |
| 597 | SDep D = *I; |
| 598 | D.setSUnit(CopyToSU); |
| 599 | AddPred(SuccSU, D); |
| 600 | DelDeps.push_back(std::make_pair(SuccSU, *I)); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 601 | } |
| 602 | } |
Evan Cheng | b2c42c6 | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 603 | for (unsigned i = 0, e = DelDeps.size(); i != e; ++i) |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 604 | RemovePred(DelDeps[i].first, DelDeps[i].second); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 605 | |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 606 | AddPred(CopyFromSU, SDep(SU, SDep::Data, SU->Latency, Reg)); |
| 607 | AddPred(CopyToSU, SDep(CopyFromSU, SDep::Data, CopyFromSU->Latency, 0)); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 608 | |
| 609 | AvailableQueue->updateNode(SU); |
| 610 | AvailableQueue->addNode(CopyFromSU); |
| 611 | AvailableQueue->addNode(CopyToSU); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 612 | Copies.push_back(CopyFromSU); |
| 613 | Copies.push_back(CopyToSU); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 614 | |
Evan Cheng | b2c42c6 | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 615 | ++NumPRCopies; |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | /// getPhysicalRegisterVT - Returns the ValueType of the physical register |
| 619 | /// definition of the specified node. |
| 620 | /// FIXME: Move to SelectionDAG? |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 621 | static EVT getPhysicalRegisterVT(SDNode *N, unsigned Reg, |
Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 622 | const TargetInstrInfo *TII) { |
Dan Gohman | 1705968 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 623 | const TargetInstrDesc &TID = TII->get(N->getMachineOpcode()); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 624 | assert(TID.ImplicitDefs && "Physical reg def must be in implicit def list!"); |
Chris Lattner | b0d06b4 | 2008-01-07 03:13:06 +0000 | [diff] [blame] | 625 | unsigned NumRes = TID.getNumDefs(); |
| 626 | for (const unsigned *ImpDef = TID.getImplicitDefs(); *ImpDef; ++ImpDef) { |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 627 | if (Reg == *ImpDef) |
| 628 | break; |
| 629 | ++NumRes; |
| 630 | } |
| 631 | return N->getValueType(NumRes); |
| 632 | } |
| 633 | |
Evan Cheng | b8905c4 | 2009-03-04 01:41:49 +0000 | [diff] [blame] | 634 | /// CheckForLiveRegDef - Return true and update live register vector if the |
| 635 | /// specified register def of the specified SUnit clobbers any "live" registers. |
Chris Lattner | 0cfe884 | 2010-12-20 00:51:56 +0000 | [diff] [blame] | 636 | static void CheckForLiveRegDef(SUnit *SU, unsigned Reg, |
Evan Cheng | b8905c4 | 2009-03-04 01:41:49 +0000 | [diff] [blame] | 637 | std::vector<SUnit*> &LiveRegDefs, |
| 638 | SmallSet<unsigned, 4> &RegAdded, |
| 639 | SmallVector<unsigned, 4> &LRegs, |
| 640 | const TargetRegisterInfo *TRI) { |
Evan Cheng | b8905c4 | 2009-03-04 01:41:49 +0000 | [diff] [blame] | 641 | if (LiveRegDefs[Reg] && LiveRegDefs[Reg] != SU) { |
Chris Lattner | 0cfe884 | 2010-12-20 00:51:56 +0000 | [diff] [blame] | 642 | if (RegAdded.insert(Reg)) |
Evan Cheng | b8905c4 | 2009-03-04 01:41:49 +0000 | [diff] [blame] | 643 | LRegs.push_back(Reg); |
Evan Cheng | b8905c4 | 2009-03-04 01:41:49 +0000 | [diff] [blame] | 644 | } |
| 645 | for (const unsigned *Alias = TRI->getAliasSet(Reg); *Alias; ++Alias) |
| 646 | if (LiveRegDefs[*Alias] && LiveRegDefs[*Alias] != SU) { |
Chris Lattner | 0cfe884 | 2010-12-20 00:51:56 +0000 | [diff] [blame] | 647 | if (RegAdded.insert(*Alias)) |
Evan Cheng | b8905c4 | 2009-03-04 01:41:49 +0000 | [diff] [blame] | 648 | LRegs.push_back(*Alias); |
Evan Cheng | b8905c4 | 2009-03-04 01:41:49 +0000 | [diff] [blame] | 649 | } |
Evan Cheng | b8905c4 | 2009-03-04 01:41:49 +0000 | [diff] [blame] | 650 | } |
| 651 | |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 652 | /// DelayForLiveRegsBottomUp - Returns true if it is necessary to delay |
| 653 | /// scheduling of the given node to satisfy live physical register dependencies. |
| 654 | /// If the specific node is the last one that's available to schedule, do |
| 655 | /// whatever is necessary (i.e. backtracking or cloning) to make it possible. |
Chris Lattner | 0cfe884 | 2010-12-20 00:51:56 +0000 | [diff] [blame] | 656 | bool ScheduleDAGRRList:: |
| 657 | DelayForLiveRegsBottomUp(SUnit *SU, SmallVector<unsigned, 4> &LRegs) { |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 658 | if (NumLiveRegs == 0) |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 659 | return false; |
| 660 | |
Evan Cheng | e6f9225 | 2007-09-27 18:46:06 +0000 | [diff] [blame] | 661 | SmallSet<unsigned, 4> RegAdded; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 662 | // 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] | 663 | for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
| 664 | I != E; ++I) { |
Evan Cheng | b8905c4 | 2009-03-04 01:41:49 +0000 | [diff] [blame] | 665 | if (I->isAssignedRegDep()) |
| 666 | CheckForLiveRegDef(I->getSUnit(), I->getReg(), LiveRegDefs, |
| 667 | RegAdded, LRegs, TRI); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 668 | } |
| 669 | |
Dan Gohman | 072734e | 2008-11-13 23:24:17 +0000 | [diff] [blame] | 670 | for (SDNode *Node = SU->getNode(); Node; Node = Node->getFlaggedNode()) { |
Evan Cheng | b8905c4 | 2009-03-04 01:41:49 +0000 | [diff] [blame] | 671 | if (Node->getOpcode() == ISD::INLINEASM) { |
| 672 | // Inline asm can clobber physical defs. |
| 673 | unsigned NumOps = Node->getNumOperands(); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 674 | if (Node->getOperand(NumOps-1).getValueType() == MVT::Flag) |
Evan Cheng | b8905c4 | 2009-03-04 01:41:49 +0000 | [diff] [blame] | 675 | --NumOps; // Ignore the flag operand. |
| 676 | |
Chris Lattner | 3b9f02a | 2010-04-07 05:20:54 +0000 | [diff] [blame] | 677 | for (unsigned i = InlineAsm::Op_FirstOperand; i != NumOps;) { |
Evan Cheng | b8905c4 | 2009-03-04 01:41:49 +0000 | [diff] [blame] | 678 | unsigned Flags = |
| 679 | cast<ConstantSDNode>(Node->getOperand(i))->getZExtValue(); |
Chris Lattner | 3b9f02a | 2010-04-07 05:20:54 +0000 | [diff] [blame] | 680 | unsigned NumVals = InlineAsm::getNumOperandRegisters(Flags); |
Evan Cheng | b8905c4 | 2009-03-04 01:41:49 +0000 | [diff] [blame] | 681 | |
| 682 | ++i; // Skip the ID value. |
Chris Lattner | 3b9f02a | 2010-04-07 05:20:54 +0000 | [diff] [blame] | 683 | if (InlineAsm::isRegDefKind(Flags) || |
| 684 | InlineAsm::isRegDefEarlyClobberKind(Flags)) { |
Evan Cheng | b8905c4 | 2009-03-04 01:41:49 +0000 | [diff] [blame] | 685 | // Check for def of register or earlyclobber register. |
| 686 | for (; NumVals; --NumVals, ++i) { |
| 687 | unsigned Reg = cast<RegisterSDNode>(Node->getOperand(i))->getReg(); |
| 688 | if (TargetRegisterInfo::isPhysicalRegister(Reg)) |
| 689 | CheckForLiveRegDef(SU, Reg, LiveRegDefs, RegAdded, LRegs, TRI); |
| 690 | } |
| 691 | } else |
| 692 | i += NumVals; |
| 693 | } |
| 694 | continue; |
| 695 | } |
| 696 | |
Dan Gohman | 072734e | 2008-11-13 23:24:17 +0000 | [diff] [blame] | 697 | if (!Node->isMachineOpcode()) |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 698 | continue; |
Dan Gohman | 1705968 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 699 | const TargetInstrDesc &TID = TII->get(Node->getMachineOpcode()); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 700 | if (!TID.ImplicitDefs) |
| 701 | continue; |
Evan Cheng | b8905c4 | 2009-03-04 01:41:49 +0000 | [diff] [blame] | 702 | for (const unsigned *Reg = TID.ImplicitDefs; *Reg; ++Reg) |
| 703 | CheckForLiveRegDef(SU, *Reg, LiveRegDefs, RegAdded, LRegs, TRI); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 704 | } |
Chris Lattner | 0cfe884 | 2010-12-20 00:51:56 +0000 | [diff] [blame] | 705 | |
| 706 | |
Chris Lattner | 981afd2 | 2010-12-20 00:55:43 +0000 | [diff] [blame^] | 707 | // Okay, we now know all of the live registers that are defined by an |
| 708 | // immediate predecessor. It is ok to kill these registers if we are also |
| 709 | // using it. |
| 710 | for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 711 | I != E; ++I) { |
| 712 | if (I->isAssignedRegDep() && |
| 713 | LiveRegCycles[I->getReg()] == I->getSUnit()->getHeight()) { |
| 714 | unsigned Reg = I->getReg(); |
| 715 | if (RegAdded.erase(Reg)) |
| 716 | LRegs.erase(std::find(LRegs.begin(), LRegs.end(), Reg)); |
| 717 | } |
| 718 | } |
| 719 | |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 720 | return !LRegs.empty(); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 721 | } |
| 722 | |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 723 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 724 | /// ListScheduleBottomUp - The main loop of list scheduling for bottom-up |
| 725 | /// schedulers. |
| 726 | void ScheduleDAGRRList::ListScheduleBottomUp() { |
| 727 | unsigned CurCycle = 0; |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 728 | |
| 729 | // Release any predecessors of the special Exit node. |
| 730 | ReleasePredecessors(&ExitSU, CurCycle); |
| 731 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 732 | // Add root to Available queue. |
Dan Gohman | 4370f26 | 2008-04-15 01:22:18 +0000 | [diff] [blame] | 733 | if (!SUnits.empty()) { |
Dan Gohman | 5a390b9 | 2008-11-13 21:21:28 +0000 | [diff] [blame] | 734 | SUnit *RootSU = &SUnits[DAG->getRoot().getNode()->getNodeId()]; |
Dan Gohman | 4370f26 | 2008-04-15 01:22:18 +0000 | [diff] [blame] | 735 | assert(RootSU->Succs.empty() && "Graph root shouldn't have successors!"); |
| 736 | RootSU->isAvailable = true; |
| 737 | AvailableQueue->push(RootSU); |
| 738 | } |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 739 | |
| 740 | // While Available queue is not empty, grab the node with the highest |
Dan Gohman | 54a187e | 2007-08-20 19:28:38 +0000 | [diff] [blame] | 741 | // priority. If it is not ready put it back. Schedule the node. |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 742 | SmallVector<SUnit*, 4> NotReady; |
Dan Gohman | fa63cc4 | 2008-06-23 21:15:00 +0000 | [diff] [blame] | 743 | DenseMap<SUnit*, SmallVector<unsigned, 4> > LRegsMap; |
Dan Gohman | e6e1348 | 2008-06-21 15:52:51 +0000 | [diff] [blame] | 744 | Sequence.reserve(SUnits.size()); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 745 | while (!AvailableQueue->empty()) { |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 746 | bool Delayed = false; |
Dan Gohman | fa63cc4 | 2008-06-23 21:15:00 +0000 | [diff] [blame] | 747 | LRegsMap.clear(); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 748 | SUnit *CurSU = AvailableQueue->pop(); |
| 749 | while (CurSU) { |
Dan Gohman | 63be531 | 2008-11-21 01:30:54 +0000 | [diff] [blame] | 750 | SmallVector<unsigned, 4> LRegs; |
| 751 | if (!DelayForLiveRegsBottomUp(CurSU, LRegs)) |
| 752 | break; |
| 753 | Delayed = true; |
| 754 | LRegsMap.insert(std::make_pair(CurSU, LRegs)); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 755 | |
| 756 | CurSU->isPending = true; // This SU is not in AvailableQueue right now. |
| 757 | NotReady.push_back(CurSU); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 758 | CurSU = AvailableQueue->pop(); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 759 | } |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 760 | |
| 761 | // All candidates are delayed due to live physical reg dependencies. |
| 762 | // Try backtracking, code duplication, or inserting cross class copies |
| 763 | // to resolve it. |
| 764 | if (Delayed && !CurSU) { |
| 765 | for (unsigned i = 0, e = NotReady.size(); i != e; ++i) { |
| 766 | SUnit *TrySU = NotReady[i]; |
| 767 | SmallVector<unsigned, 4> &LRegs = LRegsMap[TrySU]; |
| 768 | |
| 769 | // Try unscheduling up to the point where it's safe to schedule |
| 770 | // this node. |
| 771 | unsigned LiveCycle = CurCycle; |
| 772 | for (unsigned j = 0, ee = LRegs.size(); j != ee; ++j) { |
| 773 | unsigned Reg = LRegs[j]; |
| 774 | unsigned LCycle = LiveRegCycles[Reg]; |
| 775 | LiveCycle = std::min(LiveCycle, LCycle); |
| 776 | } |
| 777 | SUnit *OldSU = Sequence[LiveCycle]; |
| 778 | if (!WillCreateCycle(TrySU, OldSU)) { |
| 779 | BacktrackBottomUp(TrySU, LiveCycle, CurCycle); |
| 780 | // Force the current node to be scheduled before the node that |
| 781 | // requires the physical reg dep. |
| 782 | if (OldSU->isAvailable) { |
| 783 | OldSU->isAvailable = false; |
| 784 | AvailableQueue->remove(OldSU); |
| 785 | } |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 786 | AddPred(TrySU, SDep(OldSU, SDep::Order, /*Latency=*/1, |
| 787 | /*Reg=*/0, /*isNormalMemory=*/false, |
| 788 | /*isMustAlias=*/false, /*isArtificial=*/true)); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 789 | // If one or more successors has been unscheduled, then the current |
| 790 | // node is no longer avaialable. Schedule a successor that's now |
| 791 | // available instead. |
| 792 | if (!TrySU->isAvailable) |
| 793 | CurSU = AvailableQueue->pop(); |
| 794 | else { |
| 795 | CurSU = TrySU; |
| 796 | TrySU->isPending = false; |
| 797 | NotReady.erase(NotReady.begin()+i); |
| 798 | } |
| 799 | break; |
| 800 | } |
| 801 | } |
| 802 | |
| 803 | if (!CurSU) { |
Evan Cheng | b2c42c6 | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 804 | // Can't backtrack. If it's too expensive to copy the value, then try |
| 805 | // duplicate the nodes that produces these "too expensive to copy" |
| 806 | // values to break the dependency. In case even that doesn't work, |
| 807 | // insert cross class copies. |
| 808 | // If it's not too expensive, i.e. cost != -1, issue copies. |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 809 | SUnit *TrySU = NotReady[0]; |
| 810 | SmallVector<unsigned, 4> &LRegs = LRegsMap[TrySU]; |
| 811 | assert(LRegs.size() == 1 && "Can't handle this yet!"); |
| 812 | unsigned Reg = LRegs[0]; |
| 813 | SUnit *LRDef = LiveRegDefs[Reg]; |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 814 | EVT VT = getPhysicalRegisterVT(LRDef->getNode(), Reg, TII); |
Evan Cheng | b2c42c6 | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 815 | const TargetRegisterClass *RC = |
Rafael Espindola | 38a7d7c | 2010-06-29 14:02:34 +0000 | [diff] [blame] | 816 | TRI->getMinimalPhysRegClass(Reg, VT); |
Evan Cheng | b2c42c6 | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 817 | const TargetRegisterClass *DestRC = TRI->getCrossCopyRegClass(RC); |
| 818 | |
| 819 | // If cross copy register class is null, then it must be possible copy |
| 820 | // the value directly. Do not try duplicate the def. |
| 821 | SUnit *NewDef = 0; |
| 822 | if (DestRC) |
| 823 | NewDef = CopyAndMoveSuccessors(LRDef); |
| 824 | else |
| 825 | DestRC = RC; |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 826 | if (!NewDef) { |
Evan Cheng | b2c42c6 | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 827 | // Issue copies, these can be expensive cross register class copies. |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 828 | SmallVector<SUnit*, 2> Copies; |
Evan Cheng | b2c42c6 | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 829 | InsertCopiesAndMoveSuccs(LRDef, Reg, DestRC, RC, Copies); |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 830 | DEBUG(dbgs() << " Adding an edge from SU #" << TrySU->NodeNum |
Chris Lattner | 4dc3edd | 2009-08-23 06:35:02 +0000 | [diff] [blame] | 831 | << " to SU #" << Copies.front()->NodeNum << "\n"); |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 832 | AddPred(TrySU, SDep(Copies.front(), SDep::Order, /*Latency=*/1, |
Dan Gohman | bf8e520 | 2009-01-06 01:28:56 +0000 | [diff] [blame] | 833 | /*Reg=*/0, /*isNormalMemory=*/false, |
| 834 | /*isMustAlias=*/false, |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 835 | /*isArtificial=*/true)); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 836 | NewDef = Copies.back(); |
| 837 | } |
| 838 | |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 839 | DEBUG(dbgs() << " Adding an edge from SU #" << NewDef->NodeNum |
Chris Lattner | 4dc3edd | 2009-08-23 06:35:02 +0000 | [diff] [blame] | 840 | << " to SU #" << TrySU->NodeNum << "\n"); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 841 | LiveRegDefs[Reg] = NewDef; |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 842 | AddPred(NewDef, SDep(TrySU, SDep::Order, /*Latency=*/1, |
Dan Gohman | bf8e520 | 2009-01-06 01:28:56 +0000 | [diff] [blame] | 843 | /*Reg=*/0, /*isNormalMemory=*/false, |
| 844 | /*isMustAlias=*/false, |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 845 | /*isArtificial=*/true)); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 846 | TrySU->isAvailable = false; |
| 847 | CurSU = NewDef; |
| 848 | } |
| 849 | |
Dan Gohman | 60d6844 | 2009-01-29 19:49:27 +0000 | [diff] [blame] | 850 | assert(CurSU && "Unable to resolve live physical register dependencies!"); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 851 | } |
| 852 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 853 | // Add the nodes that aren't ready back onto the available list. |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 854 | for (unsigned i = 0, e = NotReady.size(); i != e; ++i) { |
| 855 | NotReady[i]->isPending = false; |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 856 | // May no longer be available due to backtracking. |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 857 | if (NotReady[i]->isAvailable) |
| 858 | AvailableQueue->push(NotReady[i]); |
| 859 | } |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 860 | NotReady.clear(); |
| 861 | |
Dan Gohman | c602dd4 | 2008-11-21 00:10:42 +0000 | [diff] [blame] | 862 | if (CurSU) |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 863 | ScheduleNodeBottomUp(CurSU, CurCycle); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 864 | ++CurCycle; |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 865 | AvailableQueue->setCurCycle(CurCycle); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 866 | } |
| 867 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 868 | // Reverse the order if it is bottom up. |
| 869 | std::reverse(Sequence.begin(), Sequence.end()); |
| 870 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 871 | #ifndef NDEBUG |
Dan Gohman | 4ce15e1 | 2008-11-20 01:26:25 +0000 | [diff] [blame] | 872 | VerifySchedule(isBottomUp); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 873 | #endif |
| 874 | } |
| 875 | |
| 876 | //===----------------------------------------------------------------------===// |
| 877 | // Top-Down Scheduling |
| 878 | //===----------------------------------------------------------------------===// |
| 879 | |
| 880 | /// ReleaseSucc - Decrement the NumPredsLeft count of a successor. Add it to |
Dan Gohman | 54a187e | 2007-08-20 19:28:38 +0000 | [diff] [blame] | 881 | /// the AvailableQueue if the count reaches zero. Also update its cycle bound. |
Dan Gohman | 60d6844 | 2009-01-29 19:49:27 +0000 | [diff] [blame] | 882 | void ScheduleDAGRRList::ReleaseSucc(SUnit *SU, const SDep *SuccEdge) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 883 | SUnit *SuccSU = SuccEdge->getSUnit(); |
Reid Kleckner | 8ff5c19 | 2009-09-30 20:15:38 +0000 | [diff] [blame] | 884 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 885 | #ifndef NDEBUG |
Reid Kleckner | 8ff5c19 | 2009-09-30 20:15:38 +0000 | [diff] [blame] | 886 | if (SuccSU->NumPredsLeft == 0) { |
David Greene | f34d7ac | 2010-01-05 01:24:54 +0000 | [diff] [blame] | 887 | dbgs() << "*** Scheduling failed! ***\n"; |
Dan Gohman | 22d07b1 | 2008-11-18 02:06:40 +0000 | [diff] [blame] | 888 | SuccSU->dump(this); |
David Greene | f34d7ac | 2010-01-05 01:24:54 +0000 | [diff] [blame] | 889 | dbgs() << " has been released too many times!\n"; |
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 890 | llvm_unreachable(0); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 891 | } |
| 892 | #endif |
Reid Kleckner | 8ff5c19 | 2009-09-30 20:15:38 +0000 | [diff] [blame] | 893 | --SuccSU->NumPredsLeft; |
| 894 | |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 895 | // If all the node's predecessors are scheduled, this node is ready |
| 896 | // to be scheduled. Ignore the special ExitSU node. |
| 897 | if (SuccSU->NumPredsLeft == 0 && SuccSU != &ExitSU) { |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 898 | SuccSU->isAvailable = true; |
| 899 | AvailableQueue->push(SuccSU); |
| 900 | } |
| 901 | } |
| 902 | |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 903 | void ScheduleDAGRRList::ReleaseSuccessors(SUnit *SU) { |
| 904 | // Top down: release successors |
| 905 | for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 906 | I != E; ++I) { |
| 907 | assert(!I->isAssignedRegDep() && |
| 908 | "The list-tdrr scheduler doesn't yet support physreg dependencies!"); |
| 909 | |
| 910 | ReleaseSucc(SU, &*I); |
| 911 | } |
| 912 | } |
| 913 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 914 | /// ScheduleNodeTopDown - Add the node to the schedule. Decrement the pending |
| 915 | /// count of its successors. If a successor pending count is zero, add it to |
| 916 | /// the Available queue. |
Evan Cheng | d12c97d | 2006-05-30 18:05:39 +0000 | [diff] [blame] | 917 | void ScheduleDAGRRList::ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle) { |
David Greene | f34d7ac | 2010-01-05 01:24:54 +0000 | [diff] [blame] | 918 | DEBUG(dbgs() << "*** Scheduling [" << CurCycle << "]: "); |
Dan Gohman | 22d07b1 | 2008-11-18 02:06:40 +0000 | [diff] [blame] | 919 | DEBUG(SU->dump(this)); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 920 | |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 921 | assert(CurCycle >= SU->getDepth() && "Node scheduled above its depth!"); |
| 922 | SU->setDepthToAtLeast(CurCycle); |
Dan Gohman | 92a36d7 | 2008-11-17 21:31:02 +0000 | [diff] [blame] | 923 | Sequence.push_back(SU); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 924 | |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 925 | ReleaseSuccessors(SU); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 926 | SU->isScheduled = true; |
Dan Gohman | 92a36d7 | 2008-11-17 21:31:02 +0000 | [diff] [blame] | 927 | AvailableQueue->ScheduledNode(SU); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 928 | } |
| 929 | |
Dan Gohman | 54a187e | 2007-08-20 19:28:38 +0000 | [diff] [blame] | 930 | /// ListScheduleTopDown - The main loop of list scheduling for top-down |
| 931 | /// schedulers. |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 932 | void ScheduleDAGRRList::ListScheduleTopDown() { |
| 933 | unsigned CurCycle = 0; |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 934 | AvailableQueue->setCurCycle(CurCycle); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 935 | |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 936 | // Release any successors of the special Entry node. |
| 937 | ReleaseSuccessors(&EntrySU); |
| 938 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 939 | // All leaves to Available queue. |
| 940 | for (unsigned i = 0, e = SUnits.size(); i != e; ++i) { |
| 941 | // It is available if it has no predecessors. |
Dan Gohman | 4370f26 | 2008-04-15 01:22:18 +0000 | [diff] [blame] | 942 | if (SUnits[i].Preds.empty()) { |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 943 | AvailableQueue->push(&SUnits[i]); |
| 944 | SUnits[i].isAvailable = true; |
| 945 | } |
| 946 | } |
| 947 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 948 | // While Available queue is not empty, grab the node with the highest |
Dan Gohman | 54a187e | 2007-08-20 19:28:38 +0000 | [diff] [blame] | 949 | // priority. If it is not ready put it back. Schedule the node. |
Dan Gohman | e6e1348 | 2008-06-21 15:52:51 +0000 | [diff] [blame] | 950 | Sequence.reserve(SUnits.size()); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 951 | while (!AvailableQueue->empty()) { |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 952 | SUnit *CurSU = AvailableQueue->pop(); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 953 | |
Dan Gohman | c602dd4 | 2008-11-21 00:10:42 +0000 | [diff] [blame] | 954 | if (CurSU) |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 955 | ScheduleNodeTopDown(CurSU, CurCycle); |
Dan Gohman | 4370f26 | 2008-04-15 01:22:18 +0000 | [diff] [blame] | 956 | ++CurCycle; |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 957 | AvailableQueue->setCurCycle(CurCycle); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 958 | } |
| 959 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 960 | #ifndef NDEBUG |
Dan Gohman | 4ce15e1 | 2008-11-20 01:26:25 +0000 | [diff] [blame] | 961 | VerifySchedule(isBottomUp); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 962 | #endif |
| 963 | } |
| 964 | |
| 965 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 966 | //===----------------------------------------------------------------------===// |
| 967 | // RegReductionPriorityQueue Implementation |
| 968 | //===----------------------------------------------------------------------===// |
| 969 | // |
| 970 | // This is a SchedulingPriorityQueue that schedules using Sethi Ullman numbers |
| 971 | // to reduce register pressure. |
| 972 | // |
| 973 | namespace { |
| 974 | template<class SF> |
| 975 | class RegReductionPriorityQueue; |
| 976 | |
Evan Cheng | 8ae3eca | 2010-07-25 18:59:43 +0000 | [diff] [blame] | 977 | /// bu_ls_rr_sort - Priority function for bottom up register pressure |
| 978 | // reduction scheduler. |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 979 | struct bu_ls_rr_sort : public std::binary_function<SUnit*, SUnit*, bool> { |
| 980 | RegReductionPriorityQueue<bu_ls_rr_sort> *SPQ; |
| 981 | bu_ls_rr_sort(RegReductionPriorityQueue<bu_ls_rr_sort> *spq) : SPQ(spq) {} |
| 982 | bu_ls_rr_sort(const bu_ls_rr_sort &RHS) : SPQ(RHS.SPQ) {} |
| 983 | |
| 984 | bool operator()(const SUnit* left, const SUnit* right) const; |
| 985 | }; |
| 986 | |
Evan Cheng | 8ae3eca | 2010-07-25 18:59:43 +0000 | [diff] [blame] | 987 | // td_ls_rr_sort - Priority function for top down register pressure reduction |
| 988 | // scheduler. |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 989 | struct td_ls_rr_sort : public std::binary_function<SUnit*, SUnit*, bool> { |
| 990 | RegReductionPriorityQueue<td_ls_rr_sort> *SPQ; |
| 991 | td_ls_rr_sort(RegReductionPriorityQueue<td_ls_rr_sort> *spq) : SPQ(spq) {} |
| 992 | td_ls_rr_sort(const td_ls_rr_sort &RHS) : SPQ(RHS.SPQ) {} |
| 993 | |
| 994 | bool operator()(const SUnit* left, const SUnit* right) const; |
| 995 | }; |
Bill Wendling | 8cbc25d | 2010-01-23 10:26:57 +0000 | [diff] [blame] | 996 | |
Evan Cheng | 8ae3eca | 2010-07-25 18:59:43 +0000 | [diff] [blame] | 997 | // src_ls_rr_sort - Priority function for source order scheduler. |
Bill Wendling | 8cbc25d | 2010-01-23 10:26:57 +0000 | [diff] [blame] | 998 | struct src_ls_rr_sort : public std::binary_function<SUnit*, SUnit*, bool> { |
| 999 | RegReductionPriorityQueue<src_ls_rr_sort> *SPQ; |
| 1000 | src_ls_rr_sort(RegReductionPriorityQueue<src_ls_rr_sort> *spq) |
| 1001 | : SPQ(spq) {} |
| 1002 | src_ls_rr_sort(const src_ls_rr_sort &RHS) |
| 1003 | : SPQ(RHS.SPQ) {} |
| 1004 | |
| 1005 | bool operator()(const SUnit* left, const SUnit* right) const; |
| 1006 | }; |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 1007 | |
Evan Cheng | 8ae3eca | 2010-07-25 18:59:43 +0000 | [diff] [blame] | 1008 | // hybrid_ls_rr_sort - Priority function for hybrid scheduler. |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 1009 | struct hybrid_ls_rr_sort : public std::binary_function<SUnit*, SUnit*, bool> { |
| 1010 | RegReductionPriorityQueue<hybrid_ls_rr_sort> *SPQ; |
| 1011 | hybrid_ls_rr_sort(RegReductionPriorityQueue<hybrid_ls_rr_sort> *spq) |
| 1012 | : SPQ(spq) {} |
| 1013 | hybrid_ls_rr_sort(const hybrid_ls_rr_sort &RHS) |
| 1014 | : SPQ(RHS.SPQ) {} |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1015 | |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 1016 | bool operator()(const SUnit* left, const SUnit* right) const; |
| 1017 | }; |
Evan Cheng | 37b740c | 2010-07-24 00:39:05 +0000 | [diff] [blame] | 1018 | |
Evan Cheng | 8ae3eca | 2010-07-25 18:59:43 +0000 | [diff] [blame] | 1019 | // ilp_ls_rr_sort - Priority function for ILP (instruction level parallelism) |
| 1020 | // scheduler. |
Evan Cheng | 37b740c | 2010-07-24 00:39:05 +0000 | [diff] [blame] | 1021 | struct ilp_ls_rr_sort : public std::binary_function<SUnit*, SUnit*, bool> { |
| 1022 | RegReductionPriorityQueue<ilp_ls_rr_sort> *SPQ; |
| 1023 | ilp_ls_rr_sort(RegReductionPriorityQueue<ilp_ls_rr_sort> *spq) |
| 1024 | : SPQ(spq) {} |
| 1025 | ilp_ls_rr_sort(const ilp_ls_rr_sort &RHS) |
| 1026 | : SPQ(RHS.SPQ) {} |
| 1027 | |
| 1028 | bool operator()(const SUnit* left, const SUnit* right) const; |
| 1029 | }; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1030 | } // end anonymous namespace |
| 1031 | |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1032 | /// CalcNodeSethiUllmanNumber - Compute Sethi Ullman number. |
| 1033 | /// Smaller number is the higher priority. |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1034 | static unsigned |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1035 | CalcNodeSethiUllmanNumber(const SUnit *SU, std::vector<unsigned> &SUNumbers) { |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1036 | unsigned &SethiUllmanNumber = SUNumbers[SU->NodeNum]; |
| 1037 | if (SethiUllmanNumber != 0) |
| 1038 | return SethiUllmanNumber; |
| 1039 | |
| 1040 | unsigned Extra = 0; |
| 1041 | for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
| 1042 | I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 1043 | if (I->isCtrl()) continue; // ignore chain preds |
| 1044 | SUnit *PredSU = I->getSUnit(); |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1045 | unsigned PredSethiUllman = CalcNodeSethiUllmanNumber(PredSU, SUNumbers); |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1046 | if (PredSethiUllman > SethiUllmanNumber) { |
| 1047 | SethiUllmanNumber = PredSethiUllman; |
| 1048 | Extra = 0; |
Evan Cheng | 3a14efa | 2009-02-12 08:59:45 +0000 | [diff] [blame] | 1049 | } else if (PredSethiUllman == SethiUllmanNumber) |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1050 | ++Extra; |
| 1051 | } |
| 1052 | |
| 1053 | SethiUllmanNumber += Extra; |
| 1054 | |
| 1055 | if (SethiUllmanNumber == 0) |
| 1056 | SethiUllmanNumber = 1; |
| 1057 | |
| 1058 | return SethiUllmanNumber; |
| 1059 | } |
| 1060 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1061 | namespace { |
| 1062 | template<class SF> |
Nick Lewycky | 02d5f77 | 2009-10-25 06:33:48 +0000 | [diff] [blame] | 1063 | class RegReductionPriorityQueue : public SchedulingPriorityQueue { |
Dan Gohman | 52c2738 | 2010-05-26 18:52:00 +0000 | [diff] [blame] | 1064 | std::vector<SUnit*> Queue; |
| 1065 | SF Picker; |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 1066 | unsigned CurQueueId; |
Evan Cheng | bf32e54 | 2010-07-22 06:24:48 +0000 | [diff] [blame] | 1067 | bool TracksRegPressure; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1068 | |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 1069 | protected: |
| 1070 | // SUnits - The SUnits for the current graph. |
| 1071 | std::vector<SUnit> *SUnits; |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1072 | |
| 1073 | MachineFunction &MF; |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 1074 | const TargetInstrInfo *TII; |
| 1075 | const TargetRegisterInfo *TRI; |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1076 | const TargetLowering *TLI; |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 1077 | ScheduleDAGRRList *scheduleDAG; |
| 1078 | |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1079 | // SethiUllmanNumbers - The SethiUllman number for each node. |
| 1080 | std::vector<unsigned> SethiUllmanNumbers; |
| 1081 | |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1082 | /// RegPressure - Tracking current reg pressure per register class. |
| 1083 | /// |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1084 | std::vector<unsigned> RegPressure; |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1085 | |
| 1086 | /// RegLimit - Tracking the number of allocatable registers per register |
| 1087 | /// class. |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1088 | std::vector<unsigned> RegLimit; |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1089 | |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 1090 | public: |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1091 | RegReductionPriorityQueue(MachineFunction &mf, |
Evan Cheng | bf32e54 | 2010-07-22 06:24:48 +0000 | [diff] [blame] | 1092 | bool tracksrp, |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1093 | const TargetInstrInfo *tii, |
| 1094 | const TargetRegisterInfo *tri, |
| 1095 | const TargetLowering *tli) |
Evan Cheng | bf32e54 | 2010-07-22 06:24:48 +0000 | [diff] [blame] | 1096 | : Picker(this), CurQueueId(0), TracksRegPressure(tracksrp), |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1097 | MF(mf), TII(tii), TRI(tri), TLI(tli), scheduleDAG(NULL) { |
Evan Cheng | bf32e54 | 2010-07-22 06:24:48 +0000 | [diff] [blame] | 1098 | if (TracksRegPressure) { |
| 1099 | unsigned NumRC = TRI->getNumRegClasses(); |
| 1100 | RegLimit.resize(NumRC); |
| 1101 | RegPressure.resize(NumRC); |
| 1102 | std::fill(RegLimit.begin(), RegLimit.end(), 0); |
| 1103 | std::fill(RegPressure.begin(), RegPressure.end(), 0); |
| 1104 | for (TargetRegisterInfo::regclass_iterator I = TRI->regclass_begin(), |
| 1105 | E = TRI->regclass_end(); I != E; ++I) |
Evan Cheng | df907f4 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 1106 | RegLimit[(*I)->getID()] = tli->getRegPressureLimit(*I, MF); |
Evan Cheng | bf32e54 | 2010-07-22 06:24:48 +0000 | [diff] [blame] | 1107 | } |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1108 | } |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 1109 | |
| 1110 | void initNodes(std::vector<SUnit> &sunits) { |
| 1111 | SUnits = &sunits; |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1112 | // Add pseudo dependency edges for two-address nodes. |
| 1113 | AddPseudoTwoAddrDeps(); |
Dan Gohman | 9a658d7 | 2009-03-24 00:49:12 +0000 | [diff] [blame] | 1114 | // Reroute edges to nodes with multiple uses. |
| 1115 | PrescheduleNodesWithMultipleUses(); |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1116 | // Calculate node priorities. |
| 1117 | CalculateSethiUllmanNumbers(); |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 1118 | } |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1119 | |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1120 | void addNode(const SUnit *SU) { |
| 1121 | unsigned SUSize = SethiUllmanNumbers.size(); |
| 1122 | if (SUnits->size() > SUSize) |
| 1123 | SethiUllmanNumbers.resize(SUSize*2, 0); |
| 1124 | CalcNodeSethiUllmanNumber(SU, SethiUllmanNumbers); |
| 1125 | } |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1126 | |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1127 | void updateNode(const SUnit *SU) { |
| 1128 | SethiUllmanNumbers[SU->NodeNum] = 0; |
| 1129 | CalcNodeSethiUllmanNumber(SU, SethiUllmanNumbers); |
| 1130 | } |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1131 | |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1132 | void releaseState() { |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 1133 | SUnits = 0; |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1134 | SethiUllmanNumbers.clear(); |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1135 | std::fill(RegPressure.begin(), RegPressure.end(), 0); |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 1136 | } |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1137 | |
| 1138 | unsigned getNodePriority(const SUnit *SU) const { |
| 1139 | assert(SU->NodeNum < SethiUllmanNumbers.size()); |
| 1140 | unsigned Opc = SU->getNode() ? SU->getNode()->getOpcode() : 0; |
Dan Gohman | 261ee6b | 2009-01-07 22:30:55 +0000 | [diff] [blame] | 1141 | if (Opc == ISD::TokenFactor || Opc == ISD::CopyToReg) |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1142 | // CopyToReg should be close to its uses to facilitate coalescing and |
| 1143 | // avoid spilling. |
| 1144 | return 0; |
Chris Lattner | b06015a | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 1145 | if (Opc == TargetOpcode::EXTRACT_SUBREG || |
| 1146 | Opc == TargetOpcode::SUBREG_TO_REG || |
| 1147 | Opc == TargetOpcode::INSERT_SUBREG) |
Dan Gohman | 3027bb6 | 2009-04-16 20:57:10 +0000 | [diff] [blame] | 1148 | // EXTRACT_SUBREG, INSERT_SUBREG, and SUBREG_TO_REG nodes should be |
| 1149 | // close to their uses to facilitate coalescing. |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1150 | return 0; |
Dan Gohman | 6571ef3 | 2009-02-11 21:29:39 +0000 | [diff] [blame] | 1151 | if (SU->NumSuccs == 0 && SU->NumPreds != 0) |
| 1152 | // If SU does not have a register use, i.e. it doesn't produce a value |
| 1153 | // that would be consumed (e.g. store), then it terminates a chain of |
| 1154 | // computation. Give it a large SethiUllman number so it will be |
| 1155 | // scheduled right before its predecessors that it doesn't lengthen |
| 1156 | // their live ranges. |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1157 | return 0xffff; |
Dan Gohman | 6571ef3 | 2009-02-11 21:29:39 +0000 | [diff] [blame] | 1158 | if (SU->NumPreds == 0 && SU->NumSuccs != 0) |
| 1159 | // If SU does not have a register def, schedule it close to its uses |
| 1160 | // because it does not lengthen any live ranges. |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1161 | return 0; |
Dan Gohman | 261ee6b | 2009-01-07 22:30:55 +0000 | [diff] [blame] | 1162 | return SethiUllmanNumbers[SU->NodeNum]; |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1163 | } |
Bill Wendling | 0a7056f | 2010-01-05 23:48:12 +0000 | [diff] [blame] | 1164 | |
| 1165 | unsigned getNodeOrdering(const SUnit *SU) const { |
| 1166 | return scheduleDAG->DAG->GetOrdering(SU->getNode()); |
| 1167 | } |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 1168 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1169 | bool empty() const { return Queue.empty(); } |
| 1170 | |
| 1171 | void push(SUnit *U) { |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 1172 | assert(!U->NodeQueueId && "Node in the queue already"); |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 1173 | U->NodeQueueId = ++CurQueueId; |
Dan Gohman | 52c2738 | 2010-05-26 18:52:00 +0000 | [diff] [blame] | 1174 | Queue.push_back(U); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1175 | } |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 1176 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1177 | SUnit *pop() { |
Evan Cheng | d12c97d | 2006-05-30 18:05:39 +0000 | [diff] [blame] | 1178 | if (empty()) return NULL; |
Dan Gohman | 52c2738 | 2010-05-26 18:52:00 +0000 | [diff] [blame] | 1179 | std::vector<SUnit *>::iterator Best = Queue.begin(); |
Oscar Fuentes | a97311f | 2010-05-30 13:14:21 +0000 | [diff] [blame] | 1180 | for (std::vector<SUnit *>::iterator I = llvm::next(Queue.begin()), |
Dan Gohman | 52c2738 | 2010-05-26 18:52:00 +0000 | [diff] [blame] | 1181 | E = Queue.end(); I != E; ++I) |
| 1182 | if (Picker(*Best, *I)) |
| 1183 | Best = I; |
| 1184 | SUnit *V = *Best; |
| 1185 | if (Best != prior(Queue.end())) |
| 1186 | std::swap(*Best, Queue.back()); |
| 1187 | Queue.pop_back(); |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 1188 | V->NodeQueueId = 0; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1189 | return V; |
| 1190 | } |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1191 | |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1192 | void remove(SUnit *SU) { |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 1193 | assert(!Queue.empty() && "Queue is empty!"); |
Dan Gohman | a4db335 | 2008-06-21 18:35:25 +0000 | [diff] [blame] | 1194 | assert(SU->NodeQueueId != 0 && "Not in queue!"); |
Dan Gohman | 52c2738 | 2010-05-26 18:52:00 +0000 | [diff] [blame] | 1195 | std::vector<SUnit *>::iterator I = std::find(Queue.begin(), Queue.end(), |
| 1196 | SU); |
| 1197 | if (I != prior(Queue.end())) |
| 1198 | std::swap(*I, Queue.back()); |
| 1199 | Queue.pop_back(); |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 1200 | SU->NodeQueueId = 0; |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1201 | } |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 1202 | |
Evan Cheng | e6d6c5d | 2010-07-26 21:49:07 +0000 | [diff] [blame] | 1203 | bool HighRegPressure(const SUnit *SU) const { |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1204 | if (!TLI) |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1205 | return false; |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1206 | |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1207 | for (SUnit::const_pred_iterator I = SU->Preds.begin(),E = SU->Preds.end(); |
| 1208 | I != E; ++I) { |
| 1209 | if (I->isCtrl()) |
| 1210 | continue; |
| 1211 | SUnit *PredSU = I->getSUnit(); |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1212 | const SDNode *PN = PredSU->getNode(); |
| 1213 | if (!PN->isMachineOpcode()) { |
Evan Cheng | df907f4 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 1214 | if (PN->getOpcode() == ISD::CopyFromReg) { |
| 1215 | EVT VT = PN->getValueType(0); |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1216 | unsigned RCId = TLI->getRepRegClassFor(VT)->getID(); |
| 1217 | unsigned Cost = TLI->getRepRegClassCostFor(VT); |
Evan Cheng | e6d6c5d | 2010-07-26 21:49:07 +0000 | [diff] [blame] | 1218 | if ((RegPressure[RCId] + Cost) >= RegLimit[RCId]) |
| 1219 | return true; |
Evan Cheng | df907f4 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 1220 | } |
| 1221 | continue; |
| 1222 | } |
| 1223 | unsigned POpc = PN->getMachineOpcode(); |
| 1224 | if (POpc == TargetOpcode::IMPLICIT_DEF) |
| 1225 | continue; |
| 1226 | if (POpc == TargetOpcode::EXTRACT_SUBREG) { |
| 1227 | EVT VT = PN->getOperand(0).getValueType(); |
| 1228 | unsigned RCId = TLI->getRepRegClassFor(VT)->getID(); |
| 1229 | unsigned Cost = TLI->getRepRegClassCostFor(VT); |
| 1230 | // Check if this increases register pressure of the specific register |
| 1231 | // class to the point where it would cause spills. |
Evan Cheng | e6d6c5d | 2010-07-26 21:49:07 +0000 | [diff] [blame] | 1232 | if ((RegPressure[RCId] + Cost) >= RegLimit[RCId]) |
| 1233 | return true; |
Evan Cheng | df907f4 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 1234 | continue; |
| 1235 | } else if (POpc == TargetOpcode::INSERT_SUBREG || |
| 1236 | POpc == TargetOpcode::SUBREG_TO_REG) { |
| 1237 | EVT VT = PN->getValueType(0); |
| 1238 | unsigned RCId = TLI->getRepRegClassFor(VT)->getID(); |
| 1239 | unsigned Cost = TLI->getRepRegClassCostFor(VT); |
| 1240 | // Check if this increases register pressure of the specific register |
| 1241 | // class to the point where it would cause spills. |
Evan Cheng | e6d6c5d | 2010-07-26 21:49:07 +0000 | [diff] [blame] | 1242 | if ((RegPressure[RCId] + Cost) >= RegLimit[RCId]) |
| 1243 | return true; |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1244 | continue; |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1245 | } |
| 1246 | unsigned NumDefs = TII->get(PN->getMachineOpcode()).getNumDefs(); |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1247 | for (unsigned i = 0; i != NumDefs; ++i) { |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1248 | EVT VT = PN->getValueType(i); |
Evan Cheng | e6d6c5d | 2010-07-26 21:49:07 +0000 | [diff] [blame] | 1249 | unsigned RCId = TLI->getRepRegClassFor(VT)->getID(); |
| 1250 | if (RegPressure[RCId] >= RegLimit[RCId]) |
| 1251 | return true; // Reg pressure already high. |
| 1252 | unsigned Cost = TLI->getRepRegClassCostFor(VT); |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1253 | if (!PN->hasAnyUseOfValue(i)) |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1254 | continue; |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1255 | // Check if this increases register pressure of the specific register |
| 1256 | // class to the point where it would cause spills. |
Evan Cheng | e6d6c5d | 2010-07-26 21:49:07 +0000 | [diff] [blame] | 1257 | if ((RegPressure[RCId] + Cost) >= RegLimit[RCId]) |
| 1258 | return true; |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1259 | } |
| 1260 | } |
| 1261 | |
Evan Cheng | e6d6c5d | 2010-07-26 21:49:07 +0000 | [diff] [blame] | 1262 | return false; |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1263 | } |
| 1264 | |
Evan Cheng | bf32e54 | 2010-07-22 06:24:48 +0000 | [diff] [blame] | 1265 | void ScheduledNode(SUnit *SU) { |
| 1266 | if (!TracksRegPressure) |
| 1267 | return; |
| 1268 | |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1269 | const SDNode *N = SU->getNode(); |
Evan Cheng | df907f4 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 1270 | if (!N->isMachineOpcode()) { |
| 1271 | if (N->getOpcode() != ISD::CopyToReg) |
| 1272 | return; |
| 1273 | } else { |
| 1274 | unsigned Opc = N->getMachineOpcode(); |
| 1275 | if (Opc == TargetOpcode::EXTRACT_SUBREG || |
| 1276 | Opc == TargetOpcode::INSERT_SUBREG || |
| 1277 | Opc == TargetOpcode::SUBREG_TO_REG || |
| 1278 | Opc == TargetOpcode::REG_SEQUENCE || |
| 1279 | Opc == TargetOpcode::IMPLICIT_DEF) |
| 1280 | return; |
| 1281 | } |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1282 | |
| 1283 | for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
| 1284 | I != E; ++I) { |
| 1285 | if (I->isCtrl()) |
| 1286 | continue; |
| 1287 | SUnit *PredSU = I->getSUnit(); |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1288 | if (PredSU->NumSuccsLeft != PredSU->NumSuccs) |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1289 | continue; |
| 1290 | const SDNode *PN = PredSU->getNode(); |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1291 | if (!PN->isMachineOpcode()) { |
Evan Cheng | df907f4 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 1292 | if (PN->getOpcode() == ISD::CopyFromReg) { |
| 1293 | EVT VT = PN->getValueType(0); |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1294 | unsigned RCId = TLI->getRepRegClassFor(VT)->getID(); |
| 1295 | RegPressure[RCId] += TLI->getRepRegClassCostFor(VT); |
| 1296 | } |
| 1297 | continue; |
| 1298 | } |
| 1299 | unsigned POpc = PN->getMachineOpcode(); |
| 1300 | if (POpc == TargetOpcode::IMPLICIT_DEF) |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1301 | continue; |
Evan Cheng | df907f4 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 1302 | if (POpc == TargetOpcode::EXTRACT_SUBREG) { |
| 1303 | EVT VT = PN->getOperand(0).getValueType(); |
| 1304 | unsigned RCId = TLI->getRepRegClassFor(VT)->getID(); |
| 1305 | RegPressure[RCId] += TLI->getRepRegClassCostFor(VT); |
| 1306 | continue; |
| 1307 | } else if (POpc == TargetOpcode::INSERT_SUBREG || |
| 1308 | POpc == TargetOpcode::SUBREG_TO_REG) { |
| 1309 | EVT VT = PN->getValueType(0); |
| 1310 | unsigned RCId = TLI->getRepRegClassFor(VT)->getID(); |
| 1311 | RegPressure[RCId] += TLI->getRepRegClassCostFor(VT); |
| 1312 | continue; |
| 1313 | } |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1314 | unsigned NumDefs = TII->get(PN->getMachineOpcode()).getNumDefs(); |
| 1315 | for (unsigned i = 0; i != NumDefs; ++i) { |
| 1316 | EVT VT = PN->getValueType(i); |
| 1317 | if (!PN->hasAnyUseOfValue(i)) |
| 1318 | continue; |
| 1319 | unsigned RCId = TLI->getRepRegClassFor(VT)->getID(); |
| 1320 | RegPressure[RCId] += TLI->getRepRegClassCostFor(VT); |
| 1321 | } |
| 1322 | } |
| 1323 | |
Evan Cheng | 8ae3eca | 2010-07-25 18:59:43 +0000 | [diff] [blame] | 1324 | // Check for isMachineOpcode() as PrescheduleNodesWithMultipleUses() |
| 1325 | // may transfer data dependencies to CopyToReg. |
| 1326 | if (SU->NumSuccs && N->isMachineOpcode()) { |
Evan Cheng | df907f4 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 1327 | unsigned NumDefs = TII->get(N->getMachineOpcode()).getNumDefs(); |
| 1328 | for (unsigned i = 0; i != NumDefs; ++i) { |
| 1329 | EVT VT = N->getValueType(i); |
| 1330 | if (!N->hasAnyUseOfValue(i)) |
| 1331 | continue; |
| 1332 | unsigned RCId = TLI->getRepRegClassFor(VT)->getID(); |
| 1333 | if (RegPressure[RCId] < TLI->getRepRegClassCostFor(VT)) |
| 1334 | // Register pressure tracking is imprecise. This can happen. |
| 1335 | RegPressure[RCId] = 0; |
| 1336 | else |
| 1337 | RegPressure[RCId] -= TLI->getRepRegClassCostFor(VT); |
| 1338 | } |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1339 | } |
Evan Cheng | bf32e54 | 2010-07-22 06:24:48 +0000 | [diff] [blame] | 1340 | |
| 1341 | dumpRegPressure(); |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1342 | } |
| 1343 | |
Evan Cheng | bf32e54 | 2010-07-22 06:24:48 +0000 | [diff] [blame] | 1344 | void UnscheduledNode(SUnit *SU) { |
| 1345 | if (!TracksRegPressure) |
| 1346 | return; |
| 1347 | |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1348 | const SDNode *N = SU->getNode(); |
Evan Cheng | df907f4 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 1349 | if (!N->isMachineOpcode()) { |
| 1350 | if (N->getOpcode() != ISD::CopyToReg) |
| 1351 | return; |
Evan Cheng | 37b740c | 2010-07-24 00:39:05 +0000 | [diff] [blame] | 1352 | } else { |
| 1353 | unsigned Opc = N->getMachineOpcode(); |
| 1354 | if (Opc == TargetOpcode::EXTRACT_SUBREG || |
| 1355 | Opc == TargetOpcode::INSERT_SUBREG || |
| 1356 | Opc == TargetOpcode::SUBREG_TO_REG || |
| 1357 | Opc == TargetOpcode::REG_SEQUENCE || |
| 1358 | Opc == TargetOpcode::IMPLICIT_DEF) |
| 1359 | return; |
Evan Cheng | df907f4 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 1360 | } |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1361 | |
| 1362 | for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
| 1363 | I != E; ++I) { |
| 1364 | if (I->isCtrl()) |
| 1365 | continue; |
| 1366 | SUnit *PredSU = I->getSUnit(); |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1367 | if (PredSU->NumSuccsLeft != PredSU->NumSuccs) |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1368 | continue; |
| 1369 | const SDNode *PN = PredSU->getNode(); |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1370 | if (!PN->isMachineOpcode()) { |
Evan Cheng | df907f4 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 1371 | if (PN->getOpcode() == ISD::CopyFromReg) { |
| 1372 | EVT VT = PN->getValueType(0); |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1373 | unsigned RCId = TLI->getRepRegClassFor(VT)->getID(); |
| 1374 | RegPressure[RCId] += TLI->getRepRegClassCostFor(VT); |
| 1375 | } |
| 1376 | continue; |
| 1377 | } |
| 1378 | unsigned POpc = PN->getMachineOpcode(); |
| 1379 | if (POpc == TargetOpcode::IMPLICIT_DEF) |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1380 | continue; |
Evan Cheng | df907f4 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 1381 | if (POpc == TargetOpcode::EXTRACT_SUBREG) { |
| 1382 | EVT VT = PN->getOperand(0).getValueType(); |
| 1383 | unsigned RCId = TLI->getRepRegClassFor(VT)->getID(); |
| 1384 | RegPressure[RCId] += TLI->getRepRegClassCostFor(VT); |
| 1385 | continue; |
| 1386 | } else if (POpc == TargetOpcode::INSERT_SUBREG || |
| 1387 | POpc == TargetOpcode::SUBREG_TO_REG) { |
| 1388 | EVT VT = PN->getValueType(0); |
| 1389 | unsigned RCId = TLI->getRepRegClassFor(VT)->getID(); |
| 1390 | RegPressure[RCId] += TLI->getRepRegClassCostFor(VT); |
| 1391 | continue; |
| 1392 | } |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1393 | unsigned NumDefs = TII->get(PN->getMachineOpcode()).getNumDefs(); |
| 1394 | for (unsigned i = 0; i != NumDefs; ++i) { |
| 1395 | EVT VT = PN->getValueType(i); |
| 1396 | if (!PN->hasAnyUseOfValue(i)) |
| 1397 | continue; |
| 1398 | unsigned RCId = TLI->getRepRegClassFor(VT)->getID(); |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1399 | if (RegPressure[RCId] < TLI->getRepRegClassCostFor(VT)) |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1400 | // Register pressure tracking is imprecise. This can happen. |
| 1401 | RegPressure[RCId] = 0; |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1402 | else |
| 1403 | RegPressure[RCId] -= TLI->getRepRegClassCostFor(VT); |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1404 | } |
| 1405 | } |
| 1406 | |
Evan Cheng | 8ae3eca | 2010-07-25 18:59:43 +0000 | [diff] [blame] | 1407 | // Check for isMachineOpcode() as PrescheduleNodesWithMultipleUses() |
| 1408 | // may transfer data dependencies to CopyToReg. |
| 1409 | if (SU->NumSuccs && N->isMachineOpcode()) { |
Evan Cheng | df907f4 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 1410 | unsigned NumDefs = TII->get(N->getMachineOpcode()).getNumDefs(); |
| 1411 | for (unsigned i = NumDefs, e = N->getNumValues(); i != e; ++i) { |
| 1412 | EVT VT = N->getValueType(i); |
| 1413 | if (VT == MVT::Flag || VT == MVT::Other) |
| 1414 | continue; |
| 1415 | if (!N->hasAnyUseOfValue(i)) |
| 1416 | continue; |
| 1417 | unsigned RCId = TLI->getRepRegClassFor(VT)->getID(); |
| 1418 | RegPressure[RCId] += TLI->getRepRegClassCostFor(VT); |
| 1419 | } |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1420 | } |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1421 | |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1422 | dumpRegPressure(); |
| 1423 | } |
| 1424 | |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 1425 | void setScheduleDAG(ScheduleDAGRRList *scheduleDag) { |
| 1426 | scheduleDAG = scheduleDag; |
| 1427 | } |
| 1428 | |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1429 | void dumpRegPressure() const { |
| 1430 | for (TargetRegisterInfo::regclass_iterator I = TRI->regclass_begin(), |
| 1431 | E = TRI->regclass_end(); I != E; ++I) { |
| 1432 | const TargetRegisterClass *RC = *I; |
| 1433 | unsigned Id = RC->getID(); |
| 1434 | unsigned RP = RegPressure[Id]; |
| 1435 | if (!RP) continue; |
| 1436 | DEBUG(dbgs() << RC->getName() << ": " << RP << " / " << RegLimit[Id] |
| 1437 | << '\n'); |
| 1438 | } |
| 1439 | } |
| 1440 | |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 1441 | protected: |
| 1442 | bool canClobber(const SUnit *SU, const SUnit *Op); |
| 1443 | void AddPseudoTwoAddrDeps(); |
Dan Gohman | 9a658d7 | 2009-03-24 00:49:12 +0000 | [diff] [blame] | 1444 | void PrescheduleNodesWithMultipleUses(); |
Evan Cheng | 6730f03 | 2007-01-08 23:55:53 +0000 | [diff] [blame] | 1445 | void CalculateSethiUllmanNumbers(); |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1446 | }; |
| 1447 | |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1448 | typedef RegReductionPriorityQueue<bu_ls_rr_sort> |
| 1449 | BURegReductionPriorityQueue; |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1450 | |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1451 | typedef RegReductionPriorityQueue<td_ls_rr_sort> |
| 1452 | TDRegReductionPriorityQueue; |
Bill Wendling | 8cbc25d | 2010-01-23 10:26:57 +0000 | [diff] [blame] | 1453 | |
| 1454 | typedef RegReductionPriorityQueue<src_ls_rr_sort> |
| 1455 | SrcRegReductionPriorityQueue; |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 1456 | |
| 1457 | typedef RegReductionPriorityQueue<hybrid_ls_rr_sort> |
| 1458 | HybridBURRPriorityQueue; |
Evan Cheng | 37b740c | 2010-07-24 00:39:05 +0000 | [diff] [blame] | 1459 | |
| 1460 | typedef RegReductionPriorityQueue<ilp_ls_rr_sort> |
| 1461 | ILPBURRPriorityQueue; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
Evan Cheng | b9e3db6 | 2007-03-14 22:43:40 +0000 | [diff] [blame] | 1464 | /// closestSucc - Returns the scheduled cycle of the successor which is |
Dan Gohman | a19c662 | 2009-03-12 23:55:10 +0000 | [diff] [blame] | 1465 | /// closest to the current cycle. |
Evan Cheng | 2874855 | 2007-03-13 23:25:11 +0000 | [diff] [blame] | 1466 | static unsigned closestSucc(const SUnit *SU) { |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 1467 | unsigned MaxHeight = 0; |
Evan Cheng | 2874855 | 2007-03-13 23:25:11 +0000 | [diff] [blame] | 1468 | 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] | 1469 | I != E; ++I) { |
Evan Cheng | ce3bbe5 | 2009-02-10 08:30:11 +0000 | [diff] [blame] | 1470 | if (I->isCtrl()) continue; // ignore chain succs |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 1471 | unsigned Height = I->getSUnit()->getHeight(); |
Evan Cheng | b9e3db6 | 2007-03-14 22:43:40 +0000 | [diff] [blame] | 1472 | // If there are bunch of CopyToRegs stacked up, they should be considered |
| 1473 | // to be at the same position. |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 1474 | if (I->getSUnit()->getNode() && |
| 1475 | I->getSUnit()->getNode()->getOpcode() == ISD::CopyToReg) |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 1476 | Height = closestSucc(I->getSUnit())+1; |
| 1477 | if (Height > MaxHeight) |
| 1478 | MaxHeight = Height; |
Evan Cheng | b9e3db6 | 2007-03-14 22:43:40 +0000 | [diff] [blame] | 1479 | } |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 1480 | return MaxHeight; |
Evan Cheng | 2874855 | 2007-03-13 23:25:11 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
Evan Cheng | 61bc51e | 2007-12-20 02:22:36 +0000 | [diff] [blame] | 1483 | /// calcMaxScratches - Returns an cost estimate of the worse case requirement |
Evan Cheng | 3a14efa | 2009-02-12 08:59:45 +0000 | [diff] [blame] | 1484 | /// for scratch registers, i.e. number of data dependencies. |
Evan Cheng | 61bc51e | 2007-12-20 02:22:36 +0000 | [diff] [blame] | 1485 | static unsigned calcMaxScratches(const SUnit *SU) { |
| 1486 | unsigned Scratches = 0; |
| 1487 | 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] | 1488 | I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 1489 | if (I->isCtrl()) continue; // ignore chain preds |
Evan Cheng | b570499 | 2009-02-12 09:52:13 +0000 | [diff] [blame] | 1490 | Scratches++; |
| 1491 | } |
Evan Cheng | 61bc51e | 2007-12-20 02:22:36 +0000 | [diff] [blame] | 1492 | return Scratches; |
| 1493 | } |
| 1494 | |
Evan Cheng | 6c1414f | 2010-10-29 18:09:28 +0000 | [diff] [blame] | 1495 | /// hasOnlyLiveOutUse - Return true if SU has a single value successor that is a |
| 1496 | /// CopyToReg to a virtual register. This SU def is probably a liveout and |
| 1497 | /// it has no other use. It should be scheduled closer to the terminator. |
| 1498 | static bool hasOnlyLiveOutUses(const SUnit *SU) { |
| 1499 | bool RetVal = false; |
| 1500 | for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 1501 | I != E; ++I) { |
| 1502 | if (I->isCtrl()) continue; |
| 1503 | const SUnit *SuccSU = I->getSUnit(); |
| 1504 | if (SuccSU->getNode() && SuccSU->getNode()->getOpcode() == ISD::CopyToReg) { |
| 1505 | unsigned Reg = |
| 1506 | cast<RegisterSDNode>(SuccSU->getNode()->getOperand(1))->getReg(); |
| 1507 | if (TargetRegisterInfo::isVirtualRegister(Reg)) { |
| 1508 | RetVal = true; |
| 1509 | continue; |
| 1510 | } |
| 1511 | } |
| 1512 | return false; |
| 1513 | } |
| 1514 | return RetVal; |
| 1515 | } |
| 1516 | |
| 1517 | /// UnitsSharePred - Return true if the two scheduling units share a common |
| 1518 | /// data predecessor. |
| 1519 | static bool UnitsSharePred(const SUnit *left, const SUnit *right) { |
| 1520 | SmallSet<const SUnit*, 4> Preds; |
| 1521 | for (SUnit::const_pred_iterator I = left->Preds.begin(),E = left->Preds.end(); |
| 1522 | I != E; ++I) { |
| 1523 | if (I->isCtrl()) continue; // ignore chain preds |
| 1524 | Preds.insert(I->getSUnit()); |
| 1525 | } |
| 1526 | for (SUnit::const_pred_iterator I = right->Preds.begin(),E = right->Preds.end(); |
| 1527 | I != E; ++I) { |
| 1528 | if (I->isCtrl()) continue; // ignore chain preds |
| 1529 | if (Preds.count(I->getSUnit())) |
| 1530 | return true; |
| 1531 | } |
| 1532 | return false; |
| 1533 | } |
| 1534 | |
Bill Wendling | 8cbc25d | 2010-01-23 10:26:57 +0000 | [diff] [blame] | 1535 | template <typename RRSort> |
| 1536 | static bool BURRSort(const SUnit *left, const SUnit *right, |
| 1537 | const RegReductionPriorityQueue<RRSort> *SPQ) { |
Evan Cheng | 6730f03 | 2007-01-08 23:55:53 +0000 | [diff] [blame] | 1538 | unsigned LPriority = SPQ->getNodePriority(left); |
| 1539 | unsigned RPriority = SPQ->getNodePriority(right); |
Evan Cheng | 73bdf04 | 2008-03-01 00:39:47 +0000 | [diff] [blame] | 1540 | if (LPriority != RPriority) |
| 1541 | return LPriority > RPriority; |
| 1542 | |
| 1543 | // Try schedule def + use closer when Sethi-Ullman numbers are the same. |
| 1544 | // e.g. |
| 1545 | // t1 = op t2, c1 |
| 1546 | // t3 = op t4, c2 |
| 1547 | // |
| 1548 | // and the following instructions are both ready. |
| 1549 | // t2 = op c3 |
| 1550 | // t4 = op c4 |
| 1551 | // |
| 1552 | // Then schedule t2 = op first. |
| 1553 | // i.e. |
| 1554 | // t4 = op c4 |
| 1555 | // t2 = op c3 |
| 1556 | // t1 = op t2, c1 |
| 1557 | // t3 = op t4, c2 |
| 1558 | // |
| 1559 | // This creates more short live intervals. |
| 1560 | unsigned LDist = closestSucc(left); |
| 1561 | unsigned RDist = closestSucc(right); |
| 1562 | if (LDist != RDist) |
| 1563 | return LDist < RDist; |
| 1564 | |
Evan Cheng | 3a14efa | 2009-02-12 08:59:45 +0000 | [diff] [blame] | 1565 | // How many registers becomes live when the node is scheduled. |
Evan Cheng | 73bdf04 | 2008-03-01 00:39:47 +0000 | [diff] [blame] | 1566 | unsigned LScratch = calcMaxScratches(left); |
| 1567 | unsigned RScratch = calcMaxScratches(right); |
| 1568 | if (LScratch != RScratch) |
| 1569 | return LScratch > RScratch; |
| 1570 | |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 1571 | if (left->getHeight() != right->getHeight()) |
| 1572 | return left->getHeight() > right->getHeight(); |
Evan Cheng | 73bdf04 | 2008-03-01 00:39:47 +0000 | [diff] [blame] | 1573 | |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 1574 | if (left->getDepth() != right->getDepth()) |
| 1575 | return left->getDepth() < right->getDepth(); |
Evan Cheng | 73bdf04 | 2008-03-01 00:39:47 +0000 | [diff] [blame] | 1576 | |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 1577 | assert(left->NodeQueueId && right->NodeQueueId && |
| 1578 | "NodeQueueId cannot be zero"); |
| 1579 | return (left->NodeQueueId > right->NodeQueueId); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1580 | } |
| 1581 | |
Bill Wendling | 8cbc25d | 2010-01-23 10:26:57 +0000 | [diff] [blame] | 1582 | // Bottom up |
| 1583 | bool bu_ls_rr_sort::operator()(const SUnit *left, const SUnit *right) const { |
| 1584 | return BURRSort(left, right, SPQ); |
| 1585 | } |
| 1586 | |
| 1587 | // Source order, otherwise bottom up. |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 1588 | bool src_ls_rr_sort::operator()(const SUnit *left, const SUnit *right) const { |
Bill Wendling | 8cbc25d | 2010-01-23 10:26:57 +0000 | [diff] [blame] | 1589 | unsigned LOrder = SPQ->getNodeOrdering(left); |
| 1590 | unsigned ROrder = SPQ->getNodeOrdering(right); |
| 1591 | |
| 1592 | // Prefer an ordering where the lower the non-zero order number, the higher |
| 1593 | // the preference. |
| 1594 | if ((LOrder || ROrder) && LOrder != ROrder) |
| 1595 | return LOrder != 0 && (LOrder < ROrder || ROrder == 0); |
| 1596 | |
| 1597 | return BURRSort(left, right, SPQ); |
| 1598 | } |
| 1599 | |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 1600 | bool hybrid_ls_rr_sort::operator()(const SUnit *left, const SUnit *right) const{ |
Evan Cheng | debf9c5 | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 1601 | if (left->isCall || right->isCall) |
| 1602 | // No way to compute latency of calls. |
| 1603 | return BURRSort(left, right, SPQ); |
| 1604 | |
Evan Cheng | e6d6c5d | 2010-07-26 21:49:07 +0000 | [diff] [blame] | 1605 | bool LHigh = SPQ->HighRegPressure(left); |
| 1606 | bool RHigh = SPQ->HighRegPressure(right); |
Evan Cheng | 37b740c | 2010-07-24 00:39:05 +0000 | [diff] [blame] | 1607 | // Avoid causing spills. If register pressure is high, schedule for |
| 1608 | // register pressure reduction. |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1609 | if (LHigh && !RHigh) |
| 1610 | return true; |
| 1611 | else if (!LHigh && RHigh) |
| 1612 | return false; |
Evan Cheng | e6d6c5d | 2010-07-26 21:49:07 +0000 | [diff] [blame] | 1613 | else if (!LHigh && !RHigh) { |
Evan Cheng | 6c1414f | 2010-10-29 18:09:28 +0000 | [diff] [blame] | 1614 | // If the two nodes share an operand and one of them has a single |
| 1615 | // use that is a live out copy, favor the one that is live out. Otherwise |
| 1616 | // it will be difficult to eliminate the copy if the instruction is a |
| 1617 | // loop induction variable update. e.g. |
| 1618 | // BB: |
| 1619 | // sub r1, r3, #1 |
| 1620 | // str r0, [r2, r3] |
| 1621 | // mov r3, r1 |
| 1622 | // cmp |
| 1623 | // bne BB |
| 1624 | bool SharePred = UnitsSharePred(left, right); |
| 1625 | // FIXME: Only adjust if BB is a loop back edge. |
| 1626 | // FIXME: What's the cost of a copy? |
| 1627 | int LBonus = (SharePred && hasOnlyLiveOutUses(left)) ? 1 : 0; |
| 1628 | int RBonus = (SharePred && hasOnlyLiveOutUses(right)) ? 1 : 0; |
| 1629 | int LHeight = (int)left->getHeight() - LBonus; |
| 1630 | int RHeight = (int)right->getHeight() - RBonus; |
| 1631 | |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1632 | // Low register pressure situation, schedule for latency if possible. |
| 1633 | bool LStall = left->SchedulingPref == Sched::Latency && |
Evan Cheng | 6c1414f | 2010-10-29 18:09:28 +0000 | [diff] [blame] | 1634 | (int)SPQ->getCurCycle() < LHeight; |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1635 | bool RStall = right->SchedulingPref == Sched::Latency && |
Evan Cheng | 6c1414f | 2010-10-29 18:09:28 +0000 | [diff] [blame] | 1636 | (int)SPQ->getCurCycle() < RHeight; |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1637 | // If scheduling one of the node will cause a pipeline stall, delay it. |
| 1638 | // If scheduling either one of the node will cause a pipeline stall, sort |
| 1639 | // them according to their height. |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1640 | if (LStall) { |
| 1641 | if (!RStall) |
| 1642 | return true; |
Evan Cheng | 6c1414f | 2010-10-29 18:09:28 +0000 | [diff] [blame] | 1643 | if (LHeight != RHeight) |
| 1644 | return LHeight > RHeight; |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1645 | } else if (RStall) |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 1646 | return false; |
Evan Cheng | cc2efe1 | 2010-05-28 23:26:21 +0000 | [diff] [blame] | 1647 | |
Evan Cheng | 6c1414f | 2010-10-29 18:09:28 +0000 | [diff] [blame] | 1648 | // If either node is scheduling for latency, sort them by height |
| 1649 | // and latency. |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1650 | if (left->SchedulingPref == Sched::Latency || |
| 1651 | right->SchedulingPref == Sched::Latency) { |
Evan Cheng | 6c1414f | 2010-10-29 18:09:28 +0000 | [diff] [blame] | 1652 | if (LHeight != RHeight) |
| 1653 | return LHeight > RHeight; |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1654 | if (left->Latency != right->Latency) |
| 1655 | return left->Latency > right->Latency; |
| 1656 | } |
Evan Cheng | cc2efe1 | 2010-05-28 23:26:21 +0000 | [diff] [blame] | 1657 | } |
| 1658 | |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 1659 | return BURRSort(left, right, SPQ); |
| 1660 | } |
| 1661 | |
Evan Cheng | 37b740c | 2010-07-24 00:39:05 +0000 | [diff] [blame] | 1662 | bool ilp_ls_rr_sort::operator()(const SUnit *left, |
| 1663 | const SUnit *right) const { |
Evan Cheng | debf9c5 | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 1664 | if (left->isCall || right->isCall) |
| 1665 | // No way to compute latency of calls. |
| 1666 | return BURRSort(left, right, SPQ); |
| 1667 | |
Evan Cheng | e6d6c5d | 2010-07-26 21:49:07 +0000 | [diff] [blame] | 1668 | bool LHigh = SPQ->HighRegPressure(left); |
| 1669 | bool RHigh = SPQ->HighRegPressure(right); |
Evan Cheng | 37b740c | 2010-07-24 00:39:05 +0000 | [diff] [blame] | 1670 | // Avoid causing spills. If register pressure is high, schedule for |
| 1671 | // register pressure reduction. |
| 1672 | if (LHigh && !RHigh) |
| 1673 | return true; |
| 1674 | else if (!LHigh && RHigh) |
| 1675 | return false; |
Evan Cheng | e6d6c5d | 2010-07-26 21:49:07 +0000 | [diff] [blame] | 1676 | else if (!LHigh && !RHigh) { |
Evan Cheng | 8ae3eca | 2010-07-25 18:59:43 +0000 | [diff] [blame] | 1677 | // Low register pressure situation, schedule to maximize instruction level |
| 1678 | // parallelism. |
Evan Cheng | 37b740c | 2010-07-24 00:39:05 +0000 | [diff] [blame] | 1679 | if (left->NumPreds > right->NumPreds) |
| 1680 | return false; |
| 1681 | else if (left->NumPreds < right->NumPreds) |
| 1682 | return false; |
| 1683 | } |
| 1684 | |
| 1685 | return BURRSort(left, right, SPQ); |
| 1686 | } |
| 1687 | |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 1688 | template<class SF> |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1689 | bool |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 1690 | RegReductionPriorityQueue<SF>::canClobber(const SUnit *SU, const SUnit *Op) { |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1691 | if (SU->isTwoAddress) { |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1692 | unsigned Opc = SU->getNode()->getMachineOpcode(); |
Chris Lattner | 03ad885 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 1693 | const TargetInstrDesc &TID = TII->get(Opc); |
Chris Lattner | fd2e338 | 2008-01-07 06:47:00 +0000 | [diff] [blame] | 1694 | unsigned NumRes = TID.getNumDefs(); |
Dan Gohman | 0340d1e | 2008-02-15 20:50:13 +0000 | [diff] [blame] | 1695 | unsigned NumOps = TID.getNumOperands() - NumRes; |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1696 | for (unsigned i = 0; i != NumOps; ++i) { |
Chris Lattner | fd2e338 | 2008-01-07 06:47:00 +0000 | [diff] [blame] | 1697 | if (TID.getOperandConstraint(i+NumRes, TOI::TIED_TO) != -1) { |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1698 | SDNode *DU = SU->getNode()->getOperand(i).getNode(); |
Dan Gohman | 46520a2 | 2008-06-21 19:18:17 +0000 | [diff] [blame] | 1699 | if (DU->getNodeId() != -1 && |
| 1700 | Op->OrigNode == &(*SUnits)[DU->getNodeId()]) |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1701 | return true; |
| 1702 | } |
| 1703 | } |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1704 | } |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1705 | return false; |
| 1706 | } |
| 1707 | |
Evan Cheng | f989141 | 2007-12-20 09:25:31 +0000 | [diff] [blame] | 1708 | /// canClobberPhysRegDefs - True if SU would clobber one of SuccSU's |
Dan Gohman | ea04520 | 2008-06-21 22:05:24 +0000 | [diff] [blame] | 1709 | /// physical register defs. |
Dan Gohman | e955c48 | 2008-08-05 14:45:15 +0000 | [diff] [blame] | 1710 | static bool canClobberPhysRegDefs(const SUnit *SuccSU, const SUnit *SU, |
Evan Cheng | f989141 | 2007-12-20 09:25:31 +0000 | [diff] [blame] | 1711 | const TargetInstrInfo *TII, |
Dan Gohman | 3a4be0f | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 1712 | const TargetRegisterInfo *TRI) { |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1713 | SDNode *N = SuccSU->getNode(); |
Dan Gohman | 1705968 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 1714 | unsigned NumDefs = TII->get(N->getMachineOpcode()).getNumDefs(); |
| 1715 | const unsigned *ImpDefs = TII->get(N->getMachineOpcode()).getImplicitDefs(); |
Dan Gohman | ea04520 | 2008-06-21 22:05:24 +0000 | [diff] [blame] | 1716 | assert(ImpDefs && "Caller should check hasPhysRegDefs"); |
Dan Gohman | a366da1 | 2009-03-23 16:23:01 +0000 | [diff] [blame] | 1717 | for (const SDNode *SUNode = SU->getNode(); SUNode; |
| 1718 | SUNode = SUNode->getFlaggedNode()) { |
| 1719 | if (!SUNode->isMachineOpcode()) |
Evan Cheng | f989141 | 2007-12-20 09:25:31 +0000 | [diff] [blame] | 1720 | continue; |
Dan Gohman | a366da1 | 2009-03-23 16:23:01 +0000 | [diff] [blame] | 1721 | const unsigned *SUImpDefs = |
| 1722 | TII->get(SUNode->getMachineOpcode()).getImplicitDefs(); |
| 1723 | if (!SUImpDefs) |
| 1724 | return false; |
| 1725 | for (unsigned i = NumDefs, e = N->getNumValues(); i != e; ++i) { |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1726 | EVT VT = N->getValueType(i); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1727 | if (VT == MVT::Flag || VT == MVT::Other) |
Dan Gohman | a366da1 | 2009-03-23 16:23:01 +0000 | [diff] [blame] | 1728 | continue; |
| 1729 | if (!N->hasAnyUseOfValue(i)) |
| 1730 | continue; |
| 1731 | unsigned Reg = ImpDefs[i - NumDefs]; |
| 1732 | for (;*SUImpDefs; ++SUImpDefs) { |
| 1733 | unsigned SUReg = *SUImpDefs; |
| 1734 | if (TRI->regsOverlap(Reg, SUReg)) |
| 1735 | return true; |
| 1736 | } |
Evan Cheng | f989141 | 2007-12-20 09:25:31 +0000 | [diff] [blame] | 1737 | } |
| 1738 | } |
| 1739 | return false; |
| 1740 | } |
| 1741 | |
Dan Gohman | 9a658d7 | 2009-03-24 00:49:12 +0000 | [diff] [blame] | 1742 | /// PrescheduleNodesWithMultipleUses - Nodes with multiple uses |
| 1743 | /// are not handled well by the general register pressure reduction |
| 1744 | /// heuristics. When presented with code like this: |
| 1745 | /// |
| 1746 | /// N |
| 1747 | /// / | |
| 1748 | /// / | |
| 1749 | /// U store |
| 1750 | /// | |
| 1751 | /// ... |
| 1752 | /// |
| 1753 | /// the heuristics tend to push the store up, but since the |
| 1754 | /// operand of the store has another use (U), this would increase |
| 1755 | /// the length of that other use (the U->N edge). |
| 1756 | /// |
| 1757 | /// This function transforms code like the above to route U's |
| 1758 | /// dependence through the store when possible, like this: |
| 1759 | /// |
| 1760 | /// N |
| 1761 | /// || |
| 1762 | /// || |
| 1763 | /// store |
| 1764 | /// | |
| 1765 | /// U |
| 1766 | /// | |
| 1767 | /// ... |
| 1768 | /// |
| 1769 | /// This results in the store being scheduled immediately |
| 1770 | /// after N, which shortens the U->N live range, reducing |
| 1771 | /// register pressure. |
| 1772 | /// |
| 1773 | template<class SF> |
| 1774 | void RegReductionPriorityQueue<SF>::PrescheduleNodesWithMultipleUses() { |
| 1775 | // Visit all the nodes in topological order, working top-down. |
| 1776 | for (unsigned i = 0, e = SUnits->size(); i != e; ++i) { |
| 1777 | SUnit *SU = &(*SUnits)[i]; |
| 1778 | // For now, only look at nodes with no data successors, such as stores. |
| 1779 | // These are especially important, due to the heuristics in |
| 1780 | // getNodePriority for nodes with no data successors. |
| 1781 | if (SU->NumSuccs != 0) |
| 1782 | continue; |
| 1783 | // For now, only look at nodes with exactly one data predecessor. |
| 1784 | if (SU->NumPreds != 1) |
| 1785 | continue; |
| 1786 | // Avoid prescheduling copies to virtual registers, which don't behave |
| 1787 | // like other nodes from the perspective of scheduling heuristics. |
| 1788 | if (SDNode *N = SU->getNode()) |
| 1789 | if (N->getOpcode() == ISD::CopyToReg && |
| 1790 | TargetRegisterInfo::isVirtualRegister |
| 1791 | (cast<RegisterSDNode>(N->getOperand(1))->getReg())) |
| 1792 | continue; |
| 1793 | |
| 1794 | // Locate the single data predecessor. |
| 1795 | SUnit *PredSU = 0; |
| 1796 | for (SUnit::const_pred_iterator II = SU->Preds.begin(), |
| 1797 | EE = SU->Preds.end(); II != EE; ++II) |
| 1798 | if (!II->isCtrl()) { |
| 1799 | PredSU = II->getSUnit(); |
| 1800 | break; |
| 1801 | } |
| 1802 | assert(PredSU); |
| 1803 | |
| 1804 | // Don't rewrite edges that carry physregs, because that requires additional |
| 1805 | // support infrastructure. |
| 1806 | if (PredSU->hasPhysRegDefs) |
| 1807 | continue; |
| 1808 | // Short-circuit the case where SU is PredSU's only data successor. |
| 1809 | if (PredSU->NumSuccs == 1) |
| 1810 | continue; |
| 1811 | // Avoid prescheduling to copies from virtual registers, which don't behave |
| 1812 | // like other nodes from the perspective of scheduling // heuristics. |
| 1813 | if (SDNode *N = SU->getNode()) |
| 1814 | if (N->getOpcode() == ISD::CopyFromReg && |
| 1815 | TargetRegisterInfo::isVirtualRegister |
| 1816 | (cast<RegisterSDNode>(N->getOperand(1))->getReg())) |
| 1817 | continue; |
| 1818 | |
| 1819 | // Perform checks on the successors of PredSU. |
| 1820 | for (SUnit::const_succ_iterator II = PredSU->Succs.begin(), |
| 1821 | EE = PredSU->Succs.end(); II != EE; ++II) { |
| 1822 | SUnit *PredSuccSU = II->getSUnit(); |
| 1823 | if (PredSuccSU == SU) continue; |
| 1824 | // If PredSU has another successor with no data successors, for |
| 1825 | // now don't attempt to choose either over the other. |
| 1826 | if (PredSuccSU->NumSuccs == 0) |
| 1827 | goto outer_loop_continue; |
| 1828 | // Don't break physical register dependencies. |
| 1829 | if (SU->hasPhysRegClobbers && PredSuccSU->hasPhysRegDefs) |
| 1830 | if (canClobberPhysRegDefs(PredSuccSU, SU, TII, TRI)) |
| 1831 | goto outer_loop_continue; |
| 1832 | // Don't introduce graph cycles. |
| 1833 | if (scheduleDAG->IsReachable(SU, PredSuccSU)) |
| 1834 | goto outer_loop_continue; |
| 1835 | } |
| 1836 | |
| 1837 | // Ok, the transformation is safe and the heuristics suggest it is |
| 1838 | // profitable. Update the graph. |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 1839 | DEBUG(dbgs() << " Prescheduling SU #" << SU->NodeNum |
| 1840 | << " next to PredSU #" << PredSU->NodeNum |
Chris Lattner | 4dc3edd | 2009-08-23 06:35:02 +0000 | [diff] [blame] | 1841 | << " to guide scheduling in the presence of multiple uses\n"); |
Dan Gohman | 9a658d7 | 2009-03-24 00:49:12 +0000 | [diff] [blame] | 1842 | for (unsigned i = 0; i != PredSU->Succs.size(); ++i) { |
| 1843 | SDep Edge = PredSU->Succs[i]; |
| 1844 | assert(!Edge.isAssignedRegDep()); |
| 1845 | SUnit *SuccSU = Edge.getSUnit(); |
| 1846 | if (SuccSU != SU) { |
| 1847 | Edge.setSUnit(PredSU); |
| 1848 | scheduleDAG->RemovePred(SuccSU, Edge); |
| 1849 | scheduleDAG->AddPred(SU, Edge); |
| 1850 | Edge.setSUnit(SU); |
| 1851 | scheduleDAG->AddPred(SuccSU, Edge); |
| 1852 | --i; |
| 1853 | } |
| 1854 | } |
| 1855 | outer_loop_continue:; |
| 1856 | } |
| 1857 | } |
| 1858 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1859 | /// AddPseudoTwoAddrDeps - If two nodes share an operand and one of them uses |
| 1860 | /// it as a def&use operand. Add a pseudo control edge from it to the other |
| 1861 | /// 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] | 1862 | /// first (lower in the schedule). If both nodes are two-address, favor the |
| 1863 | /// one that has a CopyToReg use (more likely to be a loop induction update). |
| 1864 | /// If both are two-address, but one is commutable while the other is not |
| 1865 | /// commutable, favor the one that's not commutable. |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 1866 | template<class SF> |
| 1867 | void RegReductionPriorityQueue<SF>::AddPseudoTwoAddrDeps() { |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1868 | for (unsigned i = 0, e = SUnits->size(); i != e; ++i) { |
Dan Gohman | e955c48 | 2008-08-05 14:45:15 +0000 | [diff] [blame] | 1869 | SUnit *SU = &(*SUnits)[i]; |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1870 | if (!SU->isTwoAddress) |
| 1871 | continue; |
| 1872 | |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1873 | SDNode *Node = SU->getNode(); |
Dan Gohman | 072734e | 2008-11-13 23:24:17 +0000 | [diff] [blame] | 1874 | if (!Node || !Node->isMachineOpcode() || SU->getNode()->getFlaggedNode()) |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1875 | continue; |
| 1876 | |
Evan Cheng | 6c1414f | 2010-10-29 18:09:28 +0000 | [diff] [blame] | 1877 | bool isLiveOut = hasOnlyLiveOutUses(SU); |
Dan Gohman | 1705968 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 1878 | unsigned Opc = Node->getMachineOpcode(); |
Chris Lattner | 03ad885 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 1879 | const TargetInstrDesc &TID = TII->get(Opc); |
Chris Lattner | fd2e338 | 2008-01-07 06:47:00 +0000 | [diff] [blame] | 1880 | unsigned NumRes = TID.getNumDefs(); |
Dan Gohman | 0340d1e | 2008-02-15 20:50:13 +0000 | [diff] [blame] | 1881 | unsigned NumOps = TID.getNumOperands() - NumRes; |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1882 | for (unsigned j = 0; j != NumOps; ++j) { |
Dan Gohman | 82016c2 | 2008-11-19 02:00:32 +0000 | [diff] [blame] | 1883 | if (TID.getOperandConstraint(j+NumRes, TOI::TIED_TO) == -1) |
| 1884 | continue; |
| 1885 | SDNode *DU = SU->getNode()->getOperand(j).getNode(); |
| 1886 | if (DU->getNodeId() == -1) |
| 1887 | continue; |
| 1888 | const SUnit *DUSU = &(*SUnits)[DU->getNodeId()]; |
| 1889 | if (!DUSU) continue; |
| 1890 | for (SUnit::const_succ_iterator I = DUSU->Succs.begin(), |
| 1891 | E = DUSU->Succs.end(); I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 1892 | if (I->isCtrl()) continue; |
| 1893 | SUnit *SuccSU = I->getSUnit(); |
Dan Gohman | 82016c2 | 2008-11-19 02:00:32 +0000 | [diff] [blame] | 1894 | if (SuccSU == SU) |
Evan Cheng | 1bf16631 | 2007-11-09 01:27:11 +0000 | [diff] [blame] | 1895 | continue; |
Dan Gohman | 82016c2 | 2008-11-19 02:00:32 +0000 | [diff] [blame] | 1896 | // Be conservative. Ignore if nodes aren't at roughly the same |
| 1897 | // depth and height. |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 1898 | if (SuccSU->getHeight() < SU->getHeight() && |
| 1899 | (SU->getHeight() - SuccSU->getHeight()) > 1) |
Dan Gohman | 82016c2 | 2008-11-19 02:00:32 +0000 | [diff] [blame] | 1900 | continue; |
Dan Gohman | eefba6b | 2009-04-16 20:59:02 +0000 | [diff] [blame] | 1901 | // Skip past COPY_TO_REGCLASS nodes, so that the pseudo edge |
| 1902 | // constrains whatever is using the copy, instead of the copy |
| 1903 | // itself. In the case that the copy is coalesced, this |
| 1904 | // preserves the intent of the pseudo two-address heurietics. |
| 1905 | while (SuccSU->Succs.size() == 1 && |
| 1906 | SuccSU->getNode()->isMachineOpcode() && |
| 1907 | SuccSU->getNode()->getMachineOpcode() == |
Chris Lattner | b06015a | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 1908 | TargetOpcode::COPY_TO_REGCLASS) |
Dan Gohman | eefba6b | 2009-04-16 20:59:02 +0000 | [diff] [blame] | 1909 | SuccSU = SuccSU->Succs.front().getSUnit(); |
| 1910 | // Don't constrain non-instruction nodes. |
Dan Gohman | 82016c2 | 2008-11-19 02:00:32 +0000 | [diff] [blame] | 1911 | if (!SuccSU->getNode() || !SuccSU->getNode()->isMachineOpcode()) |
| 1912 | continue; |
| 1913 | // Don't constrain nodes with physical register defs if the |
| 1914 | // predecessor can clobber them. |
Dan Gohman | f3746cb | 2009-03-24 00:50:07 +0000 | [diff] [blame] | 1915 | if (SuccSU->hasPhysRegDefs && SU->hasPhysRegClobbers) { |
Dan Gohman | 82016c2 | 2008-11-19 02:00:32 +0000 | [diff] [blame] | 1916 | if (canClobberPhysRegDefs(SuccSU, SU, TII, TRI)) |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1917 | continue; |
Dan Gohman | 82016c2 | 2008-11-19 02:00:32 +0000 | [diff] [blame] | 1918 | } |
Dan Gohman | 3027bb6 | 2009-04-16 20:57:10 +0000 | [diff] [blame] | 1919 | // Don't constrain EXTRACT_SUBREG, INSERT_SUBREG, and SUBREG_TO_REG; |
| 1920 | // these may be coalesced away. We want them close to their uses. |
Dan Gohman | 82016c2 | 2008-11-19 02:00:32 +0000 | [diff] [blame] | 1921 | unsigned SuccOpc = SuccSU->getNode()->getMachineOpcode(); |
Chris Lattner | b06015a | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 1922 | if (SuccOpc == TargetOpcode::EXTRACT_SUBREG || |
| 1923 | SuccOpc == TargetOpcode::INSERT_SUBREG || |
| 1924 | SuccOpc == TargetOpcode::SUBREG_TO_REG) |
Dan Gohman | 82016c2 | 2008-11-19 02:00:32 +0000 | [diff] [blame] | 1925 | continue; |
| 1926 | if ((!canClobber(SuccSU, DUSU) || |
Evan Cheng | 6c1414f | 2010-10-29 18:09:28 +0000 | [diff] [blame] | 1927 | (isLiveOut && !hasOnlyLiveOutUses(SuccSU)) || |
Dan Gohman | 82016c2 | 2008-11-19 02:00:32 +0000 | [diff] [blame] | 1928 | (!SU->isCommutable && SuccSU->isCommutable)) && |
| 1929 | !scheduleDAG->IsReachable(SuccSU, SU)) { |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 1930 | DEBUG(dbgs() << " Adding a pseudo-two-addr edge from SU #" |
Chris Lattner | 4dc3edd | 2009-08-23 06:35:02 +0000 | [diff] [blame] | 1931 | << SU->NodeNum << " to SU #" << SuccSU->NodeNum << "\n"); |
Dan Gohman | 79c3516 | 2009-01-06 01:19:04 +0000 | [diff] [blame] | 1932 | scheduleDAG->AddPred(SU, SDep(SuccSU, SDep::Order, /*Latency=*/0, |
Dan Gohman | bf8e520 | 2009-01-06 01:28:56 +0000 | [diff] [blame] | 1933 | /*Reg=*/0, /*isNormalMemory=*/false, |
| 1934 | /*isMustAlias=*/false, |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 1935 | /*isArtificial=*/true)); |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1936 | } |
| 1937 | } |
| 1938 | } |
| 1939 | } |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1940 | } |
| 1941 | |
Evan Cheng | 6730f03 | 2007-01-08 23:55:53 +0000 | [diff] [blame] | 1942 | /// CalculateSethiUllmanNumbers - Calculate Sethi-Ullman numbers of all |
| 1943 | /// scheduling units. |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1944 | template<class SF> |
| 1945 | void RegReductionPriorityQueue<SF>::CalculateSethiUllmanNumbers() { |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1946 | SethiUllmanNumbers.assign(SUnits->size(), 0); |
| 1947 | |
| 1948 | for (unsigned i = 0, e = SUnits->size(); i != e; ++i) |
Dan Gohman | 186f65d | 2008-11-20 03:30:37 +0000 | [diff] [blame] | 1949 | CalcNodeSethiUllmanNumber(&(*SUnits)[i], SethiUllmanNumbers); |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1950 | } |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1951 | |
Roman Levenstein | 30d0951 | 2008-03-27 09:44:37 +0000 | [diff] [blame] | 1952 | /// LimitedSumOfUnscheduledPredsOfSuccs - Compute the sum of the unscheduled |
Roman Levenstein | bc67450 | 2008-03-27 09:14:57 +0000 | [diff] [blame] | 1953 | /// predecessors of the successors of the SUnit SU. Stop when the provided |
| 1954 | /// limit is exceeded. |
Roman Levenstein | bc67450 | 2008-03-27 09:14:57 +0000 | [diff] [blame] | 1955 | static unsigned LimitedSumOfUnscheduledPredsOfSuccs(const SUnit *SU, |
| 1956 | unsigned Limit) { |
| 1957 | unsigned Sum = 0; |
| 1958 | for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 1959 | I != E; ++I) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 1960 | const SUnit *SuccSU = I->getSUnit(); |
Roman Levenstein | bc67450 | 2008-03-27 09:14:57 +0000 | [diff] [blame] | 1961 | for (SUnit::const_pred_iterator II = SuccSU->Preds.begin(), |
| 1962 | EE = SuccSU->Preds.end(); II != EE; ++II) { |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 1963 | SUnit *PredSU = II->getSUnit(); |
Evan Cheng | 16d7207 | 2008-03-29 18:34:22 +0000 | [diff] [blame] | 1964 | if (!PredSU->isScheduled) |
| 1965 | if (++Sum > Limit) |
| 1966 | return Sum; |
Roman Levenstein | bc67450 | 2008-03-27 09:14:57 +0000 | [diff] [blame] | 1967 | } |
| 1968 | } |
| 1969 | return Sum; |
| 1970 | } |
| 1971 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1972 | |
| 1973 | // Top down |
| 1974 | 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] | 1975 | unsigned LPriority = SPQ->getNodePriority(left); |
| 1976 | unsigned RPriority = SPQ->getNodePriority(right); |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1977 | bool LIsTarget = left->getNode() && left->getNode()->isMachineOpcode(); |
| 1978 | bool RIsTarget = right->getNode() && right->getNode()->isMachineOpcode(); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1979 | bool LIsFloater = LIsTarget && left->NumPreds == 0; |
| 1980 | bool RIsFloater = RIsTarget && right->NumPreds == 0; |
Roman Levenstein | bc67450 | 2008-03-27 09:14:57 +0000 | [diff] [blame] | 1981 | unsigned LBonus = (LimitedSumOfUnscheduledPredsOfSuccs(left,1) == 1) ? 2 : 0; |
| 1982 | unsigned RBonus = (LimitedSumOfUnscheduledPredsOfSuccs(right,1) == 1) ? 2 : 0; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1983 | |
| 1984 | if (left->NumSuccs == 0 && right->NumSuccs != 0) |
| 1985 | return false; |
| 1986 | else if (left->NumSuccs != 0 && right->NumSuccs == 0) |
| 1987 | return true; |
| 1988 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1989 | if (LIsFloater) |
| 1990 | LBonus -= 2; |
| 1991 | if (RIsFloater) |
| 1992 | RBonus -= 2; |
| 1993 | if (left->NumSuccs == 1) |
| 1994 | LBonus += 2; |
| 1995 | if (right->NumSuccs == 1) |
| 1996 | RBonus += 2; |
| 1997 | |
Evan Cheng | 73bdf04 | 2008-03-01 00:39:47 +0000 | [diff] [blame] | 1998 | if (LPriority+LBonus != RPriority+RBonus) |
| 1999 | return LPriority+LBonus < RPriority+RBonus; |
Anton Korobeynikov | 035eaac | 2008-02-20 11:10:28 +0000 | [diff] [blame] | 2000 | |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 2001 | if (left->getDepth() != right->getDepth()) |
| 2002 | return left->getDepth() < right->getDepth(); |
Evan Cheng | 73bdf04 | 2008-03-01 00:39:47 +0000 | [diff] [blame] | 2003 | |
| 2004 | if (left->NumSuccsLeft != right->NumSuccsLeft) |
| 2005 | return left->NumSuccsLeft > right->NumSuccsLeft; |
| 2006 | |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 2007 | assert(left->NodeQueueId && right->NodeQueueId && |
| 2008 | "NodeQueueId cannot be zero"); |
| 2009 | return (left->NodeQueueId > right->NodeQueueId); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 2010 | } |
| 2011 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 2012 | //===----------------------------------------------------------------------===// |
| 2013 | // Public Constructor Functions |
| 2014 | //===----------------------------------------------------------------------===// |
| 2015 | |
Dan Gohman | dfaf646 | 2009-02-11 04:27:20 +0000 | [diff] [blame] | 2016 | llvm::ScheduleDAGSDNodes * |
Bill Wendling | 026e5d7 | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 2017 | llvm::createBURRListDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level) { |
Dan Gohman | 619ef48 | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 2018 | const TargetMachine &TM = IS->TM; |
| 2019 | const TargetInstrInfo *TII = TM.getInstrInfo(); |
| 2020 | const TargetRegisterInfo *TRI = TM.getRegisterInfo(); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 2021 | |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 2022 | BURegReductionPriorityQueue *PQ = |
Evan Cheng | bf32e54 | 2010-07-22 06:24:48 +0000 | [diff] [blame] | 2023 | new BURegReductionPriorityQueue(*IS->MF, false, TII, TRI, 0); |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 2024 | ScheduleDAGRRList *SD = new ScheduleDAGRRList(*IS->MF, true, false, PQ); |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 2025 | PQ->setScheduleDAG(SD); |
| 2026 | return SD; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 2027 | } |
| 2028 | |
Dan Gohman | dfaf646 | 2009-02-11 04:27:20 +0000 | [diff] [blame] | 2029 | llvm::ScheduleDAGSDNodes * |
Bill Wendling | 026e5d7 | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 2030 | llvm::createTDRRListDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level) { |
Dan Gohman | 619ef48 | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 2031 | const TargetMachine &TM = IS->TM; |
| 2032 | const TargetInstrInfo *TII = TM.getInstrInfo(); |
| 2033 | const TargetRegisterInfo *TRI = TM.getRegisterInfo(); |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 2034 | |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 2035 | TDRegReductionPriorityQueue *PQ = |
| 2036 | new TDRegReductionPriorityQueue(*IS->MF, false, TII, TRI, 0); |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 2037 | ScheduleDAGRRList *SD = new ScheduleDAGRRList(*IS->MF, false, false, PQ); |
Dan Gohman | 3f656df | 2008-11-20 02:45:51 +0000 | [diff] [blame] | 2038 | PQ->setScheduleDAG(SD); |
| 2039 | return SD; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 2040 | } |
Bill Wendling | 8cbc25d | 2010-01-23 10:26:57 +0000 | [diff] [blame] | 2041 | |
| 2042 | llvm::ScheduleDAGSDNodes * |
| 2043 | llvm::createSourceListDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level) { |
| 2044 | const TargetMachine &TM = IS->TM; |
| 2045 | const TargetInstrInfo *TII = TM.getInstrInfo(); |
| 2046 | const TargetRegisterInfo *TRI = TM.getRegisterInfo(); |
| 2047 | |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 2048 | SrcRegReductionPriorityQueue *PQ = |
Evan Cheng | bf32e54 | 2010-07-22 06:24:48 +0000 | [diff] [blame] | 2049 | new SrcRegReductionPriorityQueue(*IS->MF, false, TII, TRI, 0); |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 2050 | ScheduleDAGRRList *SD = new ScheduleDAGRRList(*IS->MF, true, false, PQ); |
| 2051 | PQ->setScheduleDAG(SD); |
| 2052 | return SD; |
| 2053 | } |
| 2054 | |
| 2055 | llvm::ScheduleDAGSDNodes * |
| 2056 | llvm::createHybridListDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level) { |
| 2057 | const TargetMachine &TM = IS->TM; |
| 2058 | const TargetInstrInfo *TII = TM.getInstrInfo(); |
| 2059 | const TargetRegisterInfo *TRI = TM.getRegisterInfo(); |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 2060 | const TargetLowering *TLI = &IS->getTargetLowering(); |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 2061 | |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 2062 | HybridBURRPriorityQueue *PQ = |
Evan Cheng | df907f4 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 2063 | new HybridBURRPriorityQueue(*IS->MF, true, TII, TRI, TLI); |
Evan Cheng | bdd062d | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 2064 | ScheduleDAGRRList *SD = new ScheduleDAGRRList(*IS->MF, true, true, PQ); |
Bill Wendling | 8cbc25d | 2010-01-23 10:26:57 +0000 | [diff] [blame] | 2065 | PQ->setScheduleDAG(SD); |
| 2066 | return SD; |
| 2067 | } |
Evan Cheng | 37b740c | 2010-07-24 00:39:05 +0000 | [diff] [blame] | 2068 | |
| 2069 | llvm::ScheduleDAGSDNodes * |
| 2070 | llvm::createILPListDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level) { |
| 2071 | const TargetMachine &TM = IS->TM; |
| 2072 | const TargetInstrInfo *TII = TM.getInstrInfo(); |
| 2073 | const TargetRegisterInfo *TRI = TM.getRegisterInfo(); |
| 2074 | const TargetLowering *TLI = &IS->getTargetLowering(); |
| 2075 | |
| 2076 | ILPBURRPriorityQueue *PQ = |
| 2077 | new ILPBURRPriorityQueue(*IS->MF, true, TII, TRI, TLI); |
| 2078 | ScheduleDAGRRList *SD = new ScheduleDAGRRList(*IS->MF, true, true, PQ); |
| 2079 | PQ->setScheduleDAG(SD); |
| 2080 | return SD; |
| 2081 | } |