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 | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/ScheduleDAGSDNodes.h" |
Jim Laskey | 29e635d | 2006-08-02 12:30:23 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/SchedulerRegistry.h" |
Dan Gohman | 3a4be0f | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetRegisterInfo.h" |
Owen Anderson | 8c2c1e9 | 2006-05-12 06:33:49 +0000 | [diff] [blame] | 22 | #include "llvm/Target/TargetData.h" |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 23 | #include "llvm/Target/TargetMachine.h" |
| 24 | #include "llvm/Target/TargetInstrInfo.h" |
| 25 | #include "llvm/Support/Debug.h" |
Chris Lattner | 3d27be1 | 2006-08-27 12:54:02 +0000 | [diff] [blame] | 26 | #include "llvm/Support/Compiler.h" |
Dan Gohman | a4db335 | 2008-06-21 18:35:25 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/BitVector.h" |
| 28 | #include "llvm/ADT/PriorityQueue.h" |
Evan Cheng | e6f9225 | 2007-09-27 18:46:06 +0000 | [diff] [blame] | 29 | #include "llvm/ADT/SmallPtrSet.h" |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/SmallSet.h" |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/Statistic.h" |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 32 | #include "llvm/ADT/STLExtras.h" |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 33 | #include <climits> |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 34 | #include "llvm/Support/CommandLine.h" |
| 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"); |
| 40 | STATISTIC(NumCCCopies, "Number of cross class copies"); |
| 41 | |
Jim Laskey | 95eda5b | 2006-08-01 14:21:23 +0000 | [diff] [blame] | 42 | static RegisterScheduler |
| 43 | burrListDAGScheduler("list-burr", |
Dan Gohman | 9c4b7d5 | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 44 | "Bottom-up register reduction list scheduling", |
Jim Laskey | 95eda5b | 2006-08-01 14:21:23 +0000 | [diff] [blame] | 45 | createBURRListDAGScheduler); |
| 46 | static RegisterScheduler |
| 47 | tdrListrDAGScheduler("list-tdrr", |
Dan Gohman | 9c4b7d5 | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 48 | "Top-down register reduction list scheduling", |
Jim Laskey | 95eda5b | 2006-08-01 14:21:23 +0000 | [diff] [blame] | 49 | createTDRRListDAGScheduler); |
| 50 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 51 | namespace { |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 52 | //===----------------------------------------------------------------------===// |
| 53 | /// ScheduleDAGRRList - The actual register reduction list scheduler |
| 54 | /// implementation. This supports both top-down and bottom-up scheduling. |
| 55 | /// |
Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 56 | class VISIBILITY_HIDDEN ScheduleDAGRRList : public ScheduleDAGSDNodes { |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 57 | private: |
| 58 | /// isBottomUp - This is true if the scheduling problem is bottom-up, false if |
| 59 | /// it is top-down. |
| 60 | bool isBottomUp; |
Evan Cheng | 2c97731 | 2008-07-01 18:05:03 +0000 | [diff] [blame] | 61 | |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 62 | /// Fast - True if we are performing fast scheduling. |
| 63 | /// |
Evan Cheng | 2c97731 | 2008-07-01 18:05:03 +0000 | [diff] [blame] | 64 | bool Fast; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 65 | |
| 66 | /// AvailableQueue - The priority queue to use for the available SUnits. |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 67 | SchedulingPriorityQueue *AvailableQueue; |
| 68 | |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 69 | /// LiveRegDefs - A set of physical registers and their definition |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 70 | /// that are "live". These nodes must be scheduled before any other nodes that |
| 71 | /// modifies the registers can be scheduled. |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 72 | unsigned NumLiveRegs; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 73 | std::vector<SUnit*> LiveRegDefs; |
| 74 | std::vector<unsigned> LiveRegCycles; |
| 75 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 76 | public: |
Dan Gohman | 5a390b9 | 2008-11-13 21:21:28 +0000 | [diff] [blame] | 77 | ScheduleDAGRRList(SelectionDAG *dag, MachineBasicBlock *bb, |
Evan Cheng | 2c97731 | 2008-07-01 18:05:03 +0000 | [diff] [blame] | 78 | const TargetMachine &tm, bool isbottomup, bool f, |
| 79 | SchedulingPriorityQueue *availqueue) |
Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 80 | : ScheduleDAGSDNodes(dag, bb, tm), isBottomUp(isbottomup), Fast(f), |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 81 | AvailableQueue(availqueue) { |
| 82 | } |
| 83 | |
| 84 | ~ScheduleDAGRRList() { |
| 85 | delete AvailableQueue; |
| 86 | } |
| 87 | |
| 88 | void Schedule(); |
| 89 | |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 90 | /// IsReachable - Checks if SU is reachable from TargetSU. |
Dan Gohman | e955c48 | 2008-08-05 14:45:15 +0000 | [diff] [blame] | 91 | bool IsReachable(const SUnit *SU, const SUnit *TargetSU); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 92 | |
| 93 | /// willCreateCycle - Returns true if adding an edge from SU to TargetSU will |
| 94 | /// create a cycle. |
| 95 | bool WillCreateCycle(SUnit *SU, SUnit *TargetSU); |
| 96 | |
| 97 | /// AddPred - This adds the specified node X as a predecessor of |
| 98 | /// the current node Y if not already. |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 99 | /// This returns true if this is a new predecessor. |
| 100 | /// Updates the topological ordering if required. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 101 | bool AddPred(SUnit *Y, SUnit *X, bool isCtrl, bool isSpecial, |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 102 | unsigned PhyReg = 0, int Cost = 1); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 103 | |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 104 | /// RemovePred - This removes the specified node N from the predecessors of |
| 105 | /// the current node M. Updates the topological ordering if required. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 106 | bool RemovePred(SUnit *M, SUnit *N, bool isCtrl, bool isSpecial); |
| 107 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 108 | private: |
Dan Gohman | 5ebdb98 | 2008-11-18 00:38:59 +0000 | [diff] [blame] | 109 | void ReleasePred(SUnit *SU, SUnit *PredSU, bool isChain); |
| 110 | void ReleaseSucc(SUnit *SU, SUnit *SuccSU, bool isChain); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 111 | void CapturePred(SUnit*, SUnit*, bool); |
| 112 | void ScheduleNodeBottomUp(SUnit*, unsigned); |
| 113 | void ScheduleNodeTopDown(SUnit*, unsigned); |
| 114 | void UnscheduleNodeBottomUp(SUnit*); |
| 115 | void BacktrackBottomUp(SUnit*, unsigned, unsigned&); |
| 116 | SUnit *CopyAndMoveSuccessors(SUnit*); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 117 | void InsertCCCopiesAndMoveSuccs(SUnit*, unsigned, |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 118 | const TargetRegisterClass*, |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 119 | const TargetRegisterClass*, |
| 120 | SmallVector<SUnit*, 2>&); |
| 121 | bool DelayForLiveRegsBottomUp(SUnit*, SmallVector<unsigned, 4>&); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 122 | void ListScheduleTopDown(); |
| 123 | void ListScheduleBottomUp(); |
Evan Cheng | afed73e | 2006-05-12 01:58:24 +0000 | [diff] [blame] | 124 | void CommuteNodesToReducePressure(); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 125 | |
| 126 | |
| 127 | /// CreateNewSUnit - Creates a new SUnit and returns a pointer to it. |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 128 | /// Updates the topological ordering if required. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 129 | SUnit *CreateNewSUnit(SDNode *N) { |
| 130 | SUnit *NewNode = NewSUnit(N); |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 131 | // Update the topological ordering. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 132 | if (NewNode->NodeNum >= Node2Index.size()) |
| 133 | InitDAGTopologicalSorting(); |
| 134 | return NewNode; |
| 135 | } |
| 136 | |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 137 | /// CreateClone - Creates a new SUnit from an existing one. |
| 138 | /// Updates the topological ordering if required. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 139 | SUnit *CreateClone(SUnit *N) { |
| 140 | SUnit *NewNode = Clone(N); |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 141 | // Update the topological ordering. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 142 | if (NewNode->NodeNum >= Node2Index.size()) |
| 143 | InitDAGTopologicalSorting(); |
| 144 | return NewNode; |
| 145 | } |
| 146 | |
| 147 | /// Functions for preserving the topological ordering |
| 148 | /// even after dynamic insertions of new edges. |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 149 | /// This allows a very fast implementation of IsReachable. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 150 | |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 151 | /// InitDAGTopologicalSorting - create the initial topological |
| 152 | /// ordering from the DAG to be scheduled. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 153 | void InitDAGTopologicalSorting(); |
| 154 | |
| 155 | /// DFS - make a DFS traversal and mark all nodes affected by the |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 156 | /// edge insertion. These nodes will later get new topological indexes |
| 157 | /// by means of the Shift method. |
Dan Gohman | e955c48 | 2008-08-05 14:45:15 +0000 | [diff] [blame] | 158 | void DFS(const SUnit *SU, int UpperBound, bool& HasLoop); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 159 | |
| 160 | /// Shift - reassign topological indexes for the nodes in the DAG |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 161 | /// to preserve the topological ordering. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 162 | void Shift(BitVector& Visited, int LowerBound, int UpperBound); |
| 163 | |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 164 | /// Allocate - assign the topological index to the node n. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 165 | void Allocate(int n, int index); |
| 166 | |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 167 | /// Index2Node - Maps topological index to the node number. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 168 | std::vector<int> Index2Node; |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 169 | /// Node2Index - Maps the node number to its topological index. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 170 | std::vector<int> Node2Index; |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 171 | /// Visited - a set of nodes visited during a DFS traversal. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 172 | BitVector Visited; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 173 | }; |
| 174 | } // end anonymous namespace |
| 175 | |
| 176 | |
| 177 | /// Schedule - Schedule the DAG using list scheduling. |
| 178 | void ScheduleDAGRRList::Schedule() { |
Bill Wendling | 22e978a | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 179 | DOUT << "********** List Scheduling **********\n"; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 180 | |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 181 | NumLiveRegs = 0; |
Dan Gohman | 3a4be0f | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 182 | LiveRegDefs.resize(TRI->getNumRegs(), NULL); |
| 183 | LiveRegCycles.resize(TRI->getNumRegs(), 0); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 184 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 185 | // Build scheduling units. |
| 186 | BuildSchedUnits(); |
| 187 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 188 | DEBUG(for (unsigned su = 0, e = SUnits.size(); su != e; ++su) |
Dan Gohman | 22d07b1 | 2008-11-18 02:06:40 +0000 | [diff] [blame] | 189 | SUnits[su].dumpAll(this)); |
Evan Cheng | 2c97731 | 2008-07-01 18:05:03 +0000 | [diff] [blame] | 190 | if (!Fast) { |
| 191 | CalculateDepths(); |
| 192 | CalculateHeights(); |
| 193 | } |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 194 | InitDAGTopologicalSorting(); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 195 | |
Dan Gohman | 46520a2 | 2008-06-21 19:18:17 +0000 | [diff] [blame] | 196 | AvailableQueue->initNodes(SUnits); |
Dan Gohman | 54a187e | 2007-08-20 19:28:38 +0000 | [diff] [blame] | 197 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 198 | // Execute the actual scheduling loop Top-Down or Bottom-Up as appropriate. |
| 199 | if (isBottomUp) |
| 200 | ListScheduleBottomUp(); |
| 201 | else |
| 202 | ListScheduleTopDown(); |
| 203 | |
| 204 | AvailableQueue->releaseState(); |
Evan Cheng | 2c97731 | 2008-07-01 18:05:03 +0000 | [diff] [blame] | 205 | |
| 206 | if (!Fast) |
| 207 | CommuteNodesToReducePressure(); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 210 | /// CommuteNodesToReducePressure - If a node is two-address and commutable, and |
Evan Cheng | afed73e | 2006-05-12 01:58:24 +0000 | [diff] [blame] | 211 | /// it is not the last use of its first operand, add it to the CommuteSet if |
| 212 | /// possible. It will be commuted when it is translated to a MI. |
| 213 | void ScheduleDAGRRList::CommuteNodesToReducePressure() { |
Evan Cheng | e3c4419 | 2007-06-22 01:35:51 +0000 | [diff] [blame] | 214 | SmallPtrSet<SUnit*, 4> OperandSeen; |
Dan Gohman | 4370f26 | 2008-04-15 01:22:18 +0000 | [diff] [blame] | 215 | for (unsigned i = Sequence.size(); i != 0; ) { |
| 216 | --i; |
Evan Cheng | afed73e | 2006-05-12 01:58:24 +0000 | [diff] [blame] | 217 | SUnit *SU = Sequence[i]; |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 218 | if (!SU || !SU->getNode()) continue; |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 219 | if (SU->isCommutable) { |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 220 | unsigned Opc = SU->getNode()->getMachineOpcode(); |
Chris Lattner | 03ad885 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 221 | const TargetInstrDesc &TID = TII->get(Opc); |
Chris Lattner | fd2e338 | 2008-01-07 06:47:00 +0000 | [diff] [blame] | 222 | unsigned NumRes = TID.getNumDefs(); |
Dan Gohman | 0340d1e | 2008-02-15 20:50:13 +0000 | [diff] [blame] | 223 | unsigned NumOps = TID.getNumOperands() - NumRes; |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 224 | for (unsigned j = 0; j != NumOps; ++j) { |
Chris Lattner | fd2e338 | 2008-01-07 06:47:00 +0000 | [diff] [blame] | 225 | if (TID.getOperandConstraint(j+NumRes, TOI::TIED_TO) == -1) |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 226 | continue; |
| 227 | |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 228 | SDNode *OpN = SU->getNode()->getOperand(j).getNode(); |
Dan Gohman | 46520a2 | 2008-06-21 19:18:17 +0000 | [diff] [blame] | 229 | SUnit *OpSU = isPassiveNode(OpN) ? NULL : &SUnits[OpN->getNodeId()]; |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 230 | if (OpSU && OperandSeen.count(OpSU) == 1) { |
| 231 | // Ok, so SU is not the last use of OpSU, but SU is two-address so |
| 232 | // it will clobber OpSU. Try to commute SU if no other source operands |
| 233 | // are live below. |
| 234 | bool DoCommute = true; |
| 235 | for (unsigned k = 0; k < NumOps; ++k) { |
| 236 | if (k != j) { |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 237 | OpN = SU->getNode()->getOperand(k).getNode(); |
Dan Gohman | 46520a2 | 2008-06-21 19:18:17 +0000 | [diff] [blame] | 238 | OpSU = isPassiveNode(OpN) ? NULL : &SUnits[OpN->getNodeId()]; |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 239 | if (OpSU && OperandSeen.count(OpSU) == 1) { |
| 240 | DoCommute = false; |
| 241 | break; |
| 242 | } |
| 243 | } |
Evan Cheng | afed73e | 2006-05-12 01:58:24 +0000 | [diff] [blame] | 244 | } |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 245 | if (DoCommute) |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 246 | CommuteSet.insert(SU->getNode()); |
Evan Cheng | afed73e | 2006-05-12 01:58:24 +0000 | [diff] [blame] | 247 | } |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 248 | |
| 249 | // Only look at the first use&def node for now. |
| 250 | break; |
Evan Cheng | afed73e | 2006-05-12 01:58:24 +0000 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
Chris Lattner | d86418a | 2006-08-17 00:09:56 +0000 | [diff] [blame] | 254 | for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
| 255 | I != E; ++I) { |
Evan Cheng | 0effc3a | 2007-09-19 01:38:40 +0000 | [diff] [blame] | 256 | if (!I->isCtrl) |
Dan Gohman | e6e1348 | 2008-06-21 15:52:51 +0000 | [diff] [blame] | 257 | OperandSeen.insert(I->Dep->OrigNode); |
Evan Cheng | afed73e | 2006-05-12 01:58:24 +0000 | [diff] [blame] | 258 | } |
| 259 | } |
| 260 | } |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 261 | |
| 262 | //===----------------------------------------------------------------------===// |
| 263 | // Bottom-Up Scheduling |
| 264 | //===----------------------------------------------------------------------===// |
| 265 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 266 | /// ReleasePred - Decrement the NumSuccsLeft count of a predecessor. Add it to |
Dan Gohman | 54a187e | 2007-08-20 19:28:38 +0000 | [diff] [blame] | 267 | /// the AvailableQueue if the count reaches zero. Also update its cycle bound. |
Dan Gohman | 5ebdb98 | 2008-11-18 00:38:59 +0000 | [diff] [blame] | 268 | void ScheduleDAGRRList::ReleasePred(SUnit *SU, SUnit *PredSU, bool isChain) { |
Evan Cheng | 038dcc5 | 2007-09-28 19:24:24 +0000 | [diff] [blame] | 269 | --PredSU->NumSuccsLeft; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 270 | |
| 271 | #ifndef NDEBUG |
Evan Cheng | 038dcc5 | 2007-09-28 19:24:24 +0000 | [diff] [blame] | 272 | if (PredSU->NumSuccsLeft < 0) { |
Dan Gohman | 5ebdb98 | 2008-11-18 00:38:59 +0000 | [diff] [blame] | 273 | cerr << "*** Scheduling failed! ***\n"; |
Dan Gohman | 22d07b1 | 2008-11-18 02:06:40 +0000 | [diff] [blame] | 274 | PredSU->dump(this); |
Bill Wendling | 22e978a | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 275 | cerr << " has been released too many times!\n"; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 276 | assert(0); |
| 277 | } |
| 278 | #endif |
| 279 | |
Dan Gohman | 5ebdb98 | 2008-11-18 00:38:59 +0000 | [diff] [blame] | 280 | // Compute how many cycles it will be before this actually becomes |
| 281 | // available. This is the max of the start time of all predecessors plus |
| 282 | // their latencies. |
| 283 | // If this is a token edge, we don't need to wait for the latency of the |
| 284 | // preceeding instruction (e.g. a long-latency load) unless there is also |
| 285 | // some other data dependence. |
| 286 | unsigned PredDoneCycle = SU->Cycle; |
| 287 | if (!isChain) |
| 288 | PredDoneCycle += PredSU->Latency; |
| 289 | else if (SU->Latency) |
| 290 | PredDoneCycle += 1; |
| 291 | PredSU->CycleBound = std::max(PredSU->CycleBound, PredDoneCycle); |
| 292 | |
Evan Cheng | 038dcc5 | 2007-09-28 19:24:24 +0000 | [diff] [blame] | 293 | if (PredSU->NumSuccsLeft == 0) { |
Dan Gohman | 4370f26 | 2008-04-15 01:22:18 +0000 | [diff] [blame] | 294 | PredSU->isAvailable = true; |
| 295 | AvailableQueue->push(PredSU); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | |
| 299 | /// ScheduleNodeBottomUp - Add the node to the schedule. Decrement the pending |
| 300 | /// count of its predecessors. If a predecessor pending count is zero, add it to |
| 301 | /// the Available queue. |
Evan Cheng | d12c97d | 2006-05-30 18:05:39 +0000 | [diff] [blame] | 302 | void ScheduleDAGRRList::ScheduleNodeBottomUp(SUnit *SU, unsigned CurCycle) { |
Bill Wendling | 22e978a | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 303 | DOUT << "*** Scheduling [" << CurCycle << "]: "; |
Dan Gohman | 22d07b1 | 2008-11-18 02:06:40 +0000 | [diff] [blame] | 304 | DEBUG(SU->dump(this)); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 305 | |
Dan Gohman | 6e58726 | 2008-11-18 21:22:20 +0000 | [diff] [blame] | 306 | SU->Cycle = CurCycle; |
| 307 | Sequence.push_back(SU); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 308 | |
| 309 | // Bottom up: release predecessors |
Chris Lattner | d86418a | 2006-08-17 00:09:56 +0000 | [diff] [blame] | 310 | for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 311 | I != E; ++I) { |
Dan Gohman | 5ebdb98 | 2008-11-18 00:38:59 +0000 | [diff] [blame] | 312 | ReleasePred(SU, I->Dep, I->isCtrl); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 313 | if (I->Cost < 0) { |
| 314 | // This is a physical register dependency and it's impossible or |
| 315 | // expensive to copy the register. Make sure nothing that can |
| 316 | // clobber the register is scheduled between the predecessor and |
| 317 | // this node. |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 318 | if (!LiveRegDefs[I->Reg]) { |
| 319 | ++NumLiveRegs; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 320 | LiveRegDefs[I->Reg] = I->Dep; |
| 321 | LiveRegCycles[I->Reg] = CurCycle; |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | // Release all the implicit physical register defs that are live. |
| 327 | for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 328 | I != E; ++I) { |
| 329 | if (I->Cost < 0) { |
| 330 | if (LiveRegCycles[I->Reg] == I->Dep->Cycle) { |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 331 | assert(NumLiveRegs > 0 && "NumLiveRegs is already zero!"); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 332 | assert(LiveRegDefs[I->Reg] == SU && |
| 333 | "Physical register dependency violated?"); |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 334 | --NumLiveRegs; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 335 | LiveRegDefs[I->Reg] = NULL; |
| 336 | LiveRegCycles[I->Reg] = 0; |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 341 | SU->isScheduled = true; |
Dan Gohman | 6e58726 | 2008-11-18 21:22:20 +0000 | [diff] [blame] | 342 | AvailableQueue->ScheduledNode(SU); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 345 | /// CapturePred - This does the opposite of ReleasePred. Since SU is being |
| 346 | /// unscheduled, incrcease the succ left count of its predecessors. Remove |
| 347 | /// them from AvailableQueue if necessary. |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 348 | void ScheduleDAGRRList::CapturePred(SUnit *PredSU, SUnit *SU, bool isChain) { |
| 349 | unsigned CycleBound = 0; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 350 | for (SUnit::succ_iterator I = PredSU->Succs.begin(), E = PredSU->Succs.end(); |
| 351 | I != E; ++I) { |
| 352 | if (I->Dep == SU) |
| 353 | continue; |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 354 | CycleBound = std::max(CycleBound, |
| 355 | I->Dep->Cycle + PredSU->Latency); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | if (PredSU->isAvailable) { |
| 359 | PredSU->isAvailable = false; |
| 360 | if (!PredSU->isPending) |
| 361 | AvailableQueue->remove(PredSU); |
| 362 | } |
| 363 | |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 364 | PredSU->CycleBound = CycleBound; |
Evan Cheng | 038dcc5 | 2007-09-28 19:24:24 +0000 | [diff] [blame] | 365 | ++PredSU->NumSuccsLeft; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | /// UnscheduleNodeBottomUp - Remove the node from the schedule, update its and |
| 369 | /// its predecessor states to reflect the change. |
| 370 | void ScheduleDAGRRList::UnscheduleNodeBottomUp(SUnit *SU) { |
| 371 | DOUT << "*** Unscheduling [" << SU->Cycle << "]: "; |
Dan Gohman | 22d07b1 | 2008-11-18 02:06:40 +0000 | [diff] [blame] | 372 | DEBUG(SU->dump(this)); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 373 | |
| 374 | AvailableQueue->UnscheduledNode(SU); |
| 375 | |
| 376 | for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
| 377 | I != E; ++I) { |
| 378 | CapturePred(I->Dep, SU, I->isCtrl); |
| 379 | if (I->Cost < 0 && SU->Cycle == LiveRegCycles[I->Reg]) { |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 380 | assert(NumLiveRegs > 0 && "NumLiveRegs is already zero!"); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 381 | assert(LiveRegDefs[I->Reg] == I->Dep && |
| 382 | "Physical register dependency violated?"); |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 383 | --NumLiveRegs; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 384 | LiveRegDefs[I->Reg] = NULL; |
| 385 | LiveRegCycles[I->Reg] = 0; |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 390 | I != E; ++I) { |
| 391 | if (I->Cost < 0) { |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 392 | if (!LiveRegDefs[I->Reg]) { |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 393 | LiveRegDefs[I->Reg] = SU; |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 394 | ++NumLiveRegs; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 395 | } |
| 396 | if (I->Dep->Cycle < LiveRegCycles[I->Reg]) |
| 397 | LiveRegCycles[I->Reg] = I->Dep->Cycle; |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | SU->Cycle = 0; |
| 402 | SU->isScheduled = false; |
| 403 | SU->isAvailable = true; |
| 404 | AvailableQueue->push(SU); |
| 405 | } |
| 406 | |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 407 | /// IsReachable - Checks if SU is reachable from TargetSU. |
Dan Gohman | e955c48 | 2008-08-05 14:45:15 +0000 | [diff] [blame] | 408 | bool ScheduleDAGRRList::IsReachable(const SUnit *SU, const SUnit *TargetSU) { |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 409 | // If insertion of the edge SU->TargetSU would create a cycle |
| 410 | // then there is a path from TargetSU to SU. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 411 | int UpperBound, LowerBound; |
| 412 | LowerBound = Node2Index[TargetSU->NodeNum]; |
| 413 | UpperBound = Node2Index[SU->NodeNum]; |
| 414 | bool HasLoop = false; |
| 415 | // Is Ord(TargetSU) < Ord(SU) ? |
| 416 | if (LowerBound < UpperBound) { |
| 417 | Visited.reset(); |
| 418 | // There may be a path from TargetSU to SU. Check for it. |
| 419 | DFS(TargetSU, UpperBound, HasLoop); |
Evan Cheng | cfd5f82 | 2007-09-27 00:25:29 +0000 | [diff] [blame] | 420 | } |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 421 | return HasLoop; |
Evan Cheng | cfd5f82 | 2007-09-27 00:25:29 +0000 | [diff] [blame] | 422 | } |
| 423 | |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 424 | /// Allocate - assign the topological index to the node n. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 425 | inline void ScheduleDAGRRList::Allocate(int n, int index) { |
| 426 | Node2Index[n] = index; |
| 427 | Index2Node[index] = n; |
Evan Cheng | cfd5f82 | 2007-09-27 00:25:29 +0000 | [diff] [blame] | 428 | } |
| 429 | |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 430 | /// InitDAGTopologicalSorting - create the initial topological |
| 431 | /// ordering from the DAG to be scheduled. |
Evan Cheng | 2c97731 | 2008-07-01 18:05:03 +0000 | [diff] [blame] | 432 | |
| 433 | /// The idea of the algorithm is taken from |
| 434 | /// "Online algorithms for managing the topological order of |
| 435 | /// a directed acyclic graph" by David J. Pearce and Paul H.J. Kelly |
| 436 | /// This is the MNR algorithm, which was first introduced by |
| 437 | /// A. Marchetti-Spaccamela, U. Nanni and H. Rohnert in |
| 438 | /// "Maintaining a topological order under edge insertions". |
| 439 | /// |
| 440 | /// Short description of the algorithm: |
| 441 | /// |
| 442 | /// Topological ordering, ord, of a DAG maps each node to a topological |
| 443 | /// index so that for all edges X->Y it is the case that ord(X) < ord(Y). |
| 444 | /// |
| 445 | /// This means that if there is a path from the node X to the node Z, |
| 446 | /// then ord(X) < ord(Z). |
| 447 | /// |
| 448 | /// This property can be used to check for reachability of nodes: |
| 449 | /// if Z is reachable from X, then an insertion of the edge Z->X would |
| 450 | /// create a cycle. |
| 451 | /// |
| 452 | /// The algorithm first computes a topological ordering for the DAG by |
| 453 | /// initializing the Index2Node and Node2Index arrays and then tries to keep |
| 454 | /// the ordering up-to-date after edge insertions by reordering the DAG. |
| 455 | /// |
| 456 | /// On insertion of the edge X->Y, the algorithm first marks by calling DFS |
| 457 | /// the nodes reachable from Y, and then shifts them using Shift to lie |
| 458 | /// immediately after X in Index2Node. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 459 | void ScheduleDAGRRList::InitDAGTopologicalSorting() { |
| 460 | unsigned DAGSize = SUnits.size(); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 461 | std::vector<SUnit*> WorkList; |
| 462 | WorkList.reserve(DAGSize); |
Dan Gohman | 3a3a52d | 2008-08-27 16:29:48 +0000 | [diff] [blame] | 463 | |
| 464 | Index2Node.resize(DAGSize); |
| 465 | Node2Index.resize(DAGSize); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 466 | |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 467 | // Initialize the data structures. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 468 | for (unsigned i = 0, e = DAGSize; i != e; ++i) { |
| 469 | SUnit *SU = &SUnits[i]; |
| 470 | int NodeNum = SU->NodeNum; |
| 471 | unsigned Degree = SU->Succs.size(); |
Dan Gohman | 3a3a52d | 2008-08-27 16:29:48 +0000 | [diff] [blame] | 472 | // Temporarily use the Node2Index array as scratch space for degree counts. |
| 473 | Node2Index[NodeNum] = Degree; |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 474 | |
| 475 | // Is it a node without dependencies? |
| 476 | if (Degree == 0) { |
| 477 | assert(SU->Succs.empty() && "SUnit should have no successors"); |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 478 | // Collect leaf nodes. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 479 | WorkList.push_back(SU); |
| 480 | } |
| 481 | } |
| 482 | |
Dan Gohman | 3a3a52d | 2008-08-27 16:29:48 +0000 | [diff] [blame] | 483 | int Id = DAGSize; |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 484 | while (!WorkList.empty()) { |
| 485 | SUnit *SU = WorkList.back(); |
| 486 | WorkList.pop_back(); |
Dan Gohman | 3a3a52d | 2008-08-27 16:29:48 +0000 | [diff] [blame] | 487 | Allocate(SU->NodeNum, --Id); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 488 | for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
| 489 | I != E; ++I) { |
| 490 | SUnit *SU = I->Dep; |
Dan Gohman | 3a3a52d | 2008-08-27 16:29:48 +0000 | [diff] [blame] | 491 | if (!--Node2Index[SU->NodeNum]) |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 492 | // If all dependencies of the node are processed already, |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 493 | // then the node can be computed now. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 494 | WorkList.push_back(SU); |
| 495 | } |
| 496 | } |
| 497 | |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 498 | Visited.resize(DAGSize); |
| 499 | |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 500 | #ifndef NDEBUG |
| 501 | // Check correctness of the ordering |
| 502 | for (unsigned i = 0, e = DAGSize; i != e; ++i) { |
| 503 | SUnit *SU = &SUnits[i]; |
| 504 | for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
| 505 | I != E; ++I) { |
| 506 | assert(Node2Index[SU->NodeNum] > Node2Index[I->Dep->NodeNum] && |
| 507 | "Wrong topological sorting"); |
| 508 | } |
| 509 | } |
| 510 | #endif |
| 511 | } |
| 512 | |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 513 | /// AddPred - adds an edge from SUnit X to SUnit Y. |
| 514 | /// Updates the topological ordering if required. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 515 | bool ScheduleDAGRRList::AddPred(SUnit *Y, SUnit *X, bool isCtrl, bool isSpecial, |
| 516 | unsigned PhyReg, int Cost) { |
| 517 | int UpperBound, LowerBound; |
| 518 | LowerBound = Node2Index[Y->NodeNum]; |
| 519 | UpperBound = Node2Index[X->NodeNum]; |
| 520 | bool HasLoop = false; |
| 521 | // Is Ord(X) < Ord(Y) ? |
| 522 | if (LowerBound < UpperBound) { |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 523 | // Update the topological order. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 524 | Visited.reset(); |
| 525 | DFS(Y, UpperBound, HasLoop); |
| 526 | assert(!HasLoop && "Inserted edge creates a loop!"); |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 527 | // Recompute topological indexes. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 528 | Shift(Visited, LowerBound, UpperBound); |
| 529 | } |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 530 | // Now really insert the edge. |
| 531 | return Y->addPred(X, isCtrl, isSpecial, PhyReg, Cost); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 532 | } |
| 533 | |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 534 | /// RemovePred - This removes the specified node N from the predecessors of |
| 535 | /// the current node M. Updates the topological ordering if required. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 536 | bool ScheduleDAGRRList::RemovePred(SUnit *M, SUnit *N, |
| 537 | bool isCtrl, bool isSpecial) { |
| 538 | // InitDAGTopologicalSorting(); |
| 539 | return M->removePred(N, isCtrl, isSpecial); |
| 540 | } |
| 541 | |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 542 | /// DFS - Make a DFS traversal to mark all nodes reachable from SU and mark |
| 543 | /// all nodes affected by the edge insertion. These nodes will later get new |
| 544 | /// topological indexes by means of the Shift method. |
Dan Gohman | e955c48 | 2008-08-05 14:45:15 +0000 | [diff] [blame] | 545 | void ScheduleDAGRRList::DFS(const SUnit *SU, int UpperBound, bool& HasLoop) { |
| 546 | std::vector<const SUnit*> WorkList; |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 547 | WorkList.reserve(SUnits.size()); |
| 548 | |
| 549 | WorkList.push_back(SU); |
| 550 | while (!WorkList.empty()) { |
| 551 | SU = WorkList.back(); |
| 552 | WorkList.pop_back(); |
| 553 | Visited.set(SU->NodeNum); |
| 554 | for (int I = SU->Succs.size()-1; I >= 0; --I) { |
| 555 | int s = SU->Succs[I].Dep->NodeNum; |
| 556 | if (Node2Index[s] == UpperBound) { |
| 557 | HasLoop = true; |
| 558 | return; |
| 559 | } |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 560 | // Visit successors if not already and in affected region. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 561 | if (!Visited.test(s) && Node2Index[s] < UpperBound) { |
| 562 | WorkList.push_back(SU->Succs[I].Dep); |
| 563 | } |
| 564 | } |
| 565 | } |
| 566 | } |
| 567 | |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 568 | /// Shift - Renumber the nodes so that the topological ordering is |
| 569 | /// preserved. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 570 | void ScheduleDAGRRList::Shift(BitVector& Visited, int LowerBound, |
| 571 | int UpperBound) { |
| 572 | std::vector<int> L; |
| 573 | int shift = 0; |
| 574 | int i; |
| 575 | |
| 576 | for (i = LowerBound; i <= UpperBound; ++i) { |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 577 | // w is node at topological index i. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 578 | int w = Index2Node[i]; |
| 579 | if (Visited.test(w)) { |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 580 | // Unmark. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 581 | Visited.reset(w); |
| 582 | L.push_back(w); |
| 583 | shift = shift + 1; |
| 584 | } else { |
| 585 | Allocate(w, i - shift); |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | for (unsigned j = 0; j < L.size(); ++j) { |
| 590 | Allocate(L[j], i - shift); |
| 591 | i = i + 1; |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | |
Dan Gohman | fd227e9 | 2008-03-25 17:10:29 +0000 | [diff] [blame] | 596 | /// WillCreateCycle - Returns true if adding an edge from SU to TargetSU will |
Evan Cheng | cfd5f82 | 2007-09-27 00:25:29 +0000 | [diff] [blame] | 597 | /// create a cycle. |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 598 | bool ScheduleDAGRRList::WillCreateCycle(SUnit *SU, SUnit *TargetSU) { |
| 599 | if (IsReachable(TargetSU, SU)) |
Evan Cheng | cfd5f82 | 2007-09-27 00:25:29 +0000 | [diff] [blame] | 600 | return true; |
| 601 | for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
| 602 | I != E; ++I) |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 603 | if (I->Cost < 0 && IsReachable(TargetSU, I->Dep)) |
Evan Cheng | cfd5f82 | 2007-09-27 00:25:29 +0000 | [diff] [blame] | 604 | return true; |
| 605 | return false; |
| 606 | } |
| 607 | |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 608 | /// BacktrackBottomUp - Backtrack scheduling to a previous cycle specified in |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 609 | /// BTCycle in order to schedule a specific node. Returns the last unscheduled |
| 610 | /// SUnit. Also returns if a successor is unscheduled in the process. |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 611 | void ScheduleDAGRRList::BacktrackBottomUp(SUnit *SU, unsigned BtCycle, |
| 612 | unsigned &CurCycle) { |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 613 | SUnit *OldSU = NULL; |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 614 | while (CurCycle > BtCycle) { |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 615 | OldSU = Sequence.back(); |
| 616 | Sequence.pop_back(); |
| 617 | if (SU->isSucc(OldSU)) |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 618 | // Don't try to remove SU from AvailableQueue. |
| 619 | SU->isAvailable = false; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 620 | UnscheduleNodeBottomUp(OldSU); |
| 621 | --CurCycle; |
| 622 | } |
| 623 | |
| 624 | |
| 625 | if (SU->isSucc(OldSU)) { |
| 626 | assert(false && "Something is wrong!"); |
| 627 | abort(); |
| 628 | } |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 629 | |
| 630 | ++NumBacktracks; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 631 | } |
| 632 | |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 633 | /// CopyAndMoveSuccessors - Clone the specified node and move its scheduled |
| 634 | /// successors to the newly created node. |
| 635 | SUnit *ScheduleDAGRRList::CopyAndMoveSuccessors(SUnit *SU) { |
Dan Gohman | 072734e | 2008-11-13 23:24:17 +0000 | [diff] [blame] | 636 | if (SU->getNode()->getFlaggedNode()) |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 637 | return NULL; |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 638 | |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 639 | SDNode *N = SU->getNode(); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 640 | if (!N) |
| 641 | return NULL; |
| 642 | |
| 643 | SUnit *NewSU; |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 644 | bool TryUnfold = false; |
Evan Cheng | 84d0ebc | 2007-10-05 01:42:35 +0000 | [diff] [blame] | 645 | for (unsigned i = 0, e = N->getNumValues(); i != e; ++i) { |
Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 646 | MVT VT = N->getValueType(i); |
Evan Cheng | 84d0ebc | 2007-10-05 01:42:35 +0000 | [diff] [blame] | 647 | if (VT == MVT::Flag) |
| 648 | return NULL; |
| 649 | else if (VT == MVT::Other) |
| 650 | TryUnfold = true; |
| 651 | } |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 652 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 653 | const SDValue &Op = N->getOperand(i); |
Gabor Greif | f304a7a | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 654 | MVT VT = Op.getNode()->getValueType(Op.getResNo()); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 655 | if (VT == MVT::Flag) |
| 656 | return NULL; |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | if (TryUnfold) { |
Dan Gohman | e6e1348 | 2008-06-21 15:52:51 +0000 | [diff] [blame] | 660 | SmallVector<SDNode*, 2> NewNodes; |
Dan Gohman | 5a390b9 | 2008-11-13 21:21:28 +0000 | [diff] [blame] | 661 | if (!TII->unfoldMemoryOperand(*DAG, N, NewNodes)) |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 662 | return NULL; |
| 663 | |
| 664 | DOUT << "Unfolding SU # " << SU->NodeNum << "\n"; |
| 665 | assert(NewNodes.size() == 2 && "Expected a load folding node!"); |
| 666 | |
| 667 | N = NewNodes[1]; |
| 668 | SDNode *LoadNode = NewNodes[0]; |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 669 | unsigned NumVals = N->getNumValues(); |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 670 | unsigned OldNumVals = SU->getNode()->getNumValues(); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 671 | for (unsigned i = 0; i != NumVals; ++i) |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 672 | DAG->ReplaceAllUsesOfValueWith(SDValue(SU->getNode(), i), SDValue(N, i)); |
| 673 | DAG->ReplaceAllUsesOfValueWith(SDValue(SU->getNode(), OldNumVals-1), |
Dan Gohman | 5a390b9 | 2008-11-13 21:21:28 +0000 | [diff] [blame] | 674 | SDValue(LoadNode, 1)); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 675 | |
Dan Gohman | e52e089 | 2008-11-11 21:34:44 +0000 | [diff] [blame] | 676 | // LoadNode may already exist. This can happen when there is another |
| 677 | // load from the same location and producing the same type of value |
| 678 | // but it has different alignment or volatileness. |
| 679 | bool isNewLoad = true; |
| 680 | SUnit *LoadSU; |
| 681 | if (LoadNode->getNodeId() != -1) { |
| 682 | LoadSU = &SUnits[LoadNode->getNodeId()]; |
| 683 | isNewLoad = false; |
| 684 | } else { |
| 685 | LoadSU = CreateNewSUnit(LoadNode); |
| 686 | LoadNode->setNodeId(LoadSU->NodeNum); |
| 687 | |
| 688 | LoadSU->Depth = SU->Depth; |
| 689 | LoadSU->Height = SU->Height; |
| 690 | ComputeLatency(LoadSU); |
| 691 | } |
| 692 | |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 693 | SUnit *NewSU = CreateNewSUnit(N); |
Dan Gohman | 46520a2 | 2008-06-21 19:18:17 +0000 | [diff] [blame] | 694 | assert(N->getNodeId() == -1 && "Node already inserted!"); |
| 695 | N->setNodeId(NewSU->NodeNum); |
Dan Gohman | e6e1348 | 2008-06-21 15:52:51 +0000 | [diff] [blame] | 696 | |
Dan Gohman | 1705968 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 697 | const TargetInstrDesc &TID = TII->get(N->getMachineOpcode()); |
Dan Gohman | 856c012 | 2008-02-16 00:25:40 +0000 | [diff] [blame] | 698 | for (unsigned i = 0; i != TID.getNumOperands(); ++i) { |
Chris Lattner | fd2e338 | 2008-01-07 06:47:00 +0000 | [diff] [blame] | 699 | if (TID.getOperandConstraint(i, TOI::TIED_TO) != -1) { |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 700 | NewSU->isTwoAddress = true; |
| 701 | break; |
| 702 | } |
| 703 | } |
Chris Lattner | fd2e338 | 2008-01-07 06:47:00 +0000 | [diff] [blame] | 704 | if (TID.isCommutable()) |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 705 | NewSU->isCommutable = true; |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 706 | // FIXME: Calculate height / depth and propagate the changes? |
Evan Cheng | 91e0fc9 | 2007-12-18 08:42:10 +0000 | [diff] [blame] | 707 | NewSU->Depth = SU->Depth; |
| 708 | NewSU->Height = SU->Height; |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 709 | ComputeLatency(NewSU); |
| 710 | |
| 711 | SUnit *ChainPred = NULL; |
| 712 | SmallVector<SDep, 4> ChainSuccs; |
| 713 | SmallVector<SDep, 4> LoadPreds; |
| 714 | SmallVector<SDep, 4> NodePreds; |
| 715 | SmallVector<SDep, 4> NodeSuccs; |
| 716 | for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
| 717 | I != E; ++I) { |
| 718 | if (I->isCtrl) |
| 719 | ChainPred = I->Dep; |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 720 | else if (I->Dep->getNode() && I->Dep->getNode()->isOperandOf(LoadNode)) |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 721 | LoadPreds.push_back(SDep(I->Dep, I->Reg, I->Cost, false, false)); |
| 722 | else |
| 723 | NodePreds.push_back(SDep(I->Dep, I->Reg, I->Cost, false, false)); |
| 724 | } |
| 725 | for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 726 | I != E; ++I) { |
| 727 | if (I->isCtrl) |
| 728 | ChainSuccs.push_back(SDep(I->Dep, I->Reg, I->Cost, |
| 729 | I->isCtrl, I->isSpecial)); |
| 730 | else |
| 731 | NodeSuccs.push_back(SDep(I->Dep, I->Reg, I->Cost, |
| 732 | I->isCtrl, I->isSpecial)); |
| 733 | } |
| 734 | |
Dan Gohman | 4370f26 | 2008-04-15 01:22:18 +0000 | [diff] [blame] | 735 | if (ChainPred) { |
| 736 | RemovePred(SU, ChainPred, true, false); |
| 737 | if (isNewLoad) |
| 738 | AddPred(LoadSU, ChainPred, true, false); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 739 | } |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 740 | for (unsigned i = 0, e = LoadPreds.size(); i != e; ++i) { |
| 741 | SDep *Pred = &LoadPreds[i]; |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 742 | RemovePred(SU, Pred->Dep, Pred->isCtrl, Pred->isSpecial); |
| 743 | if (isNewLoad) { |
| 744 | AddPred(LoadSU, Pred->Dep, Pred->isCtrl, Pred->isSpecial, |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 745 | Pred->Reg, Pred->Cost); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 746 | } |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 747 | } |
| 748 | for (unsigned i = 0, e = NodePreds.size(); i != e; ++i) { |
| 749 | SDep *Pred = &NodePreds[i]; |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 750 | RemovePred(SU, Pred->Dep, Pred->isCtrl, Pred->isSpecial); |
| 751 | AddPred(NewSU, Pred->Dep, Pred->isCtrl, Pred->isSpecial, |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 752 | Pred->Reg, Pred->Cost); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 753 | } |
| 754 | for (unsigned i = 0, e = NodeSuccs.size(); i != e; ++i) { |
| 755 | SDep *Succ = &NodeSuccs[i]; |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 756 | RemovePred(Succ->Dep, SU, Succ->isCtrl, Succ->isSpecial); |
| 757 | AddPred(Succ->Dep, NewSU, Succ->isCtrl, Succ->isSpecial, |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 758 | Succ->Reg, Succ->Cost); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 759 | } |
| 760 | for (unsigned i = 0, e = ChainSuccs.size(); i != e; ++i) { |
| 761 | SDep *Succ = &ChainSuccs[i]; |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 762 | RemovePred(Succ->Dep, SU, Succ->isCtrl, Succ->isSpecial); |
| 763 | if (isNewLoad) { |
| 764 | AddPred(Succ->Dep, LoadSU, Succ->isCtrl, Succ->isSpecial, |
Roman Levenstein | 733a4d6 | 2008-03-26 11:23:38 +0000 | [diff] [blame] | 765 | Succ->Reg, Succ->Cost); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 766 | } |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 767 | } |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 768 | if (isNewLoad) { |
| 769 | AddPred(NewSU, LoadSU, false, false); |
| 770 | } |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 771 | |
Evan Cheng | 91e0fc9 | 2007-12-18 08:42:10 +0000 | [diff] [blame] | 772 | if (isNewLoad) |
| 773 | AvailableQueue->addNode(LoadSU); |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 774 | AvailableQueue->addNode(NewSU); |
| 775 | |
| 776 | ++NumUnfolds; |
| 777 | |
| 778 | if (NewSU->NumSuccsLeft == 0) { |
| 779 | NewSU->isAvailable = true; |
| 780 | return NewSU; |
Evan Cheng | 91e0fc9 | 2007-12-18 08:42:10 +0000 | [diff] [blame] | 781 | } |
| 782 | SU = NewSU; |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | DOUT << "Duplicating SU # " << SU->NodeNum << "\n"; |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 786 | NewSU = CreateClone(SU); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 787 | |
| 788 | // New SUnit has the exact same predecessors. |
| 789 | for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
| 790 | I != E; ++I) |
| 791 | if (!I->isSpecial) { |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 792 | AddPred(NewSU, I->Dep, I->isCtrl, false, I->Reg, I->Cost); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 793 | NewSU->Depth = std::max(NewSU->Depth, I->Dep->Depth+1); |
| 794 | } |
| 795 | |
| 796 | // Only copy scheduled successors. Cut them from old node's successor |
| 797 | // list and move them over. |
Evan Cheng | bde499b | 2007-09-27 07:29:27 +0000 | [diff] [blame] | 798 | SmallVector<std::pair<SUnit*, bool>, 4> DelDeps; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 799 | for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 800 | I != E; ++I) { |
| 801 | if (I->isSpecial) |
| 802 | continue; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 803 | if (I->Dep->isScheduled) { |
Evan Cheng | bde499b | 2007-09-27 07:29:27 +0000 | [diff] [blame] | 804 | NewSU->Height = std::max(NewSU->Height, I->Dep->Height+1); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 805 | AddPred(I->Dep, NewSU, I->isCtrl, false, I->Reg, I->Cost); |
Evan Cheng | bde499b | 2007-09-27 07:29:27 +0000 | [diff] [blame] | 806 | DelDeps.push_back(std::make_pair(I->Dep, I->isCtrl)); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 807 | } |
| 808 | } |
| 809 | for (unsigned i = 0, e = DelDeps.size(); i != e; ++i) { |
Evan Cheng | bde499b | 2007-09-27 07:29:27 +0000 | [diff] [blame] | 810 | SUnit *Succ = DelDeps[i].first; |
| 811 | bool isCtrl = DelDeps[i].second; |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 812 | RemovePred(Succ, SU, isCtrl, false); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | AvailableQueue->updateNode(SU); |
| 816 | AvailableQueue->addNode(NewSU); |
| 817 | |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 818 | ++NumDups; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 819 | return NewSU; |
| 820 | } |
| 821 | |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 822 | /// InsertCCCopiesAndMoveSuccs - Insert expensive cross register class copies |
| 823 | /// and move all scheduled successors of the given SUnit to the last copy. |
| 824 | void ScheduleDAGRRList::InsertCCCopiesAndMoveSuccs(SUnit *SU, unsigned Reg, |
| 825 | const TargetRegisterClass *DestRC, |
| 826 | const TargetRegisterClass *SrcRC, |
| 827 | SmallVector<SUnit*, 2> &Copies) { |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 828 | SUnit *CopyFromSU = CreateNewSUnit(NULL); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 829 | CopyFromSU->CopySrcRC = SrcRC; |
| 830 | CopyFromSU->CopyDstRC = DestRC; |
| 831 | CopyFromSU->Depth = SU->Depth; |
| 832 | CopyFromSU->Height = SU->Height; |
| 833 | |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 834 | SUnit *CopyToSU = CreateNewSUnit(NULL); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 835 | CopyToSU->CopySrcRC = DestRC; |
| 836 | CopyToSU->CopyDstRC = SrcRC; |
| 837 | |
| 838 | // Only copy scheduled successors. Cut them from old node's successor |
| 839 | // list and move them over. |
Evan Cheng | bde499b | 2007-09-27 07:29:27 +0000 | [diff] [blame] | 840 | SmallVector<std::pair<SUnit*, bool>, 4> DelDeps; |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 841 | for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 842 | I != E; ++I) { |
| 843 | if (I->isSpecial) |
| 844 | continue; |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 845 | if (I->Dep->isScheduled) { |
Evan Cheng | bde499b | 2007-09-27 07:29:27 +0000 | [diff] [blame] | 846 | CopyToSU->Height = std::max(CopyToSU->Height, I->Dep->Height+1); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 847 | AddPred(I->Dep, CopyToSU, I->isCtrl, false, I->Reg, I->Cost); |
Evan Cheng | bde499b | 2007-09-27 07:29:27 +0000 | [diff] [blame] | 848 | DelDeps.push_back(std::make_pair(I->Dep, I->isCtrl)); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 849 | } |
| 850 | } |
| 851 | for (unsigned i = 0, e = DelDeps.size(); i != e; ++i) { |
Evan Cheng | bde499b | 2007-09-27 07:29:27 +0000 | [diff] [blame] | 852 | SUnit *Succ = DelDeps[i].first; |
| 853 | bool isCtrl = DelDeps[i].second; |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 854 | RemovePred(Succ, SU, isCtrl, false); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 855 | } |
| 856 | |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 857 | AddPred(CopyFromSU, SU, false, false, Reg, -1); |
| 858 | AddPred(CopyToSU, CopyFromSU, false, false, Reg, 1); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 859 | |
| 860 | AvailableQueue->updateNode(SU); |
| 861 | AvailableQueue->addNode(CopyFromSU); |
| 862 | AvailableQueue->addNode(CopyToSU); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 863 | Copies.push_back(CopyFromSU); |
| 864 | Copies.push_back(CopyToSU); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 865 | |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 866 | ++NumCCCopies; |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | /// getPhysicalRegisterVT - Returns the ValueType of the physical register |
| 870 | /// definition of the specified node. |
| 871 | /// FIXME: Move to SelectionDAG? |
Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 872 | static MVT getPhysicalRegisterVT(SDNode *N, unsigned Reg, |
| 873 | const TargetInstrInfo *TII) { |
Dan Gohman | 1705968 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 874 | const TargetInstrDesc &TID = TII->get(N->getMachineOpcode()); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 875 | assert(TID.ImplicitDefs && "Physical reg def must be in implicit def list!"); |
Chris Lattner | b0d06b4 | 2008-01-07 03:13:06 +0000 | [diff] [blame] | 876 | unsigned NumRes = TID.getNumDefs(); |
| 877 | for (const unsigned *ImpDef = TID.getImplicitDefs(); *ImpDef; ++ImpDef) { |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 878 | if (Reg == *ImpDef) |
| 879 | break; |
| 880 | ++NumRes; |
| 881 | } |
| 882 | return N->getValueType(NumRes); |
| 883 | } |
| 884 | |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 885 | /// DelayForLiveRegsBottomUp - Returns true if it is necessary to delay |
| 886 | /// scheduling of the given node to satisfy live physical register dependencies. |
| 887 | /// If the specific node is the last one that's available to schedule, do |
| 888 | /// whatever is necessary (i.e. backtracking or cloning) to make it possible. |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 889 | bool ScheduleDAGRRList::DelayForLiveRegsBottomUp(SUnit *SU, |
| 890 | SmallVector<unsigned, 4> &LRegs){ |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 891 | if (NumLiveRegs == 0) |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 892 | return false; |
| 893 | |
Evan Cheng | e6f9225 | 2007-09-27 18:46:06 +0000 | [diff] [blame] | 894 | SmallSet<unsigned, 4> RegAdded; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 895 | // 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] | 896 | for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
| 897 | I != E; ++I) { |
| 898 | if (I->Cost < 0) { |
| 899 | unsigned Reg = I->Reg; |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 900 | if (LiveRegDefs[Reg] && LiveRegDefs[Reg] != I->Dep) { |
Evan Cheng | e6f9225 | 2007-09-27 18:46:06 +0000 | [diff] [blame] | 901 | if (RegAdded.insert(Reg)) |
| 902 | LRegs.push_back(Reg); |
| 903 | } |
Dan Gohman | 3a4be0f | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 904 | for (const unsigned *Alias = TRI->getAliasSet(Reg); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 905 | *Alias; ++Alias) |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 906 | if (LiveRegDefs[*Alias] && LiveRegDefs[*Alias] != I->Dep) { |
Evan Cheng | e6f9225 | 2007-09-27 18:46:06 +0000 | [diff] [blame] | 907 | if (RegAdded.insert(*Alias)) |
| 908 | LRegs.push_back(*Alias); |
| 909 | } |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 910 | } |
| 911 | } |
| 912 | |
Dan Gohman | 072734e | 2008-11-13 23:24:17 +0000 | [diff] [blame] | 913 | for (SDNode *Node = SU->getNode(); Node; Node = Node->getFlaggedNode()) { |
| 914 | if (!Node->isMachineOpcode()) |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 915 | continue; |
Dan Gohman | 1705968 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 916 | const TargetInstrDesc &TID = TII->get(Node->getMachineOpcode()); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 917 | if (!TID.ImplicitDefs) |
| 918 | continue; |
| 919 | for (const unsigned *Reg = TID.ImplicitDefs; *Reg; ++Reg) { |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 920 | if (LiveRegDefs[*Reg] && LiveRegDefs[*Reg] != SU) { |
Evan Cheng | e6f9225 | 2007-09-27 18:46:06 +0000 | [diff] [blame] | 921 | if (RegAdded.insert(*Reg)) |
| 922 | LRegs.push_back(*Reg); |
| 923 | } |
Dan Gohman | 3a4be0f | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 924 | for (const unsigned *Alias = TRI->getAliasSet(*Reg); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 925 | *Alias; ++Alias) |
Dan Gohman | c07f686 | 2008-09-23 18:50:48 +0000 | [diff] [blame] | 926 | if (LiveRegDefs[*Alias] && LiveRegDefs[*Alias] != SU) { |
Evan Cheng | e6f9225 | 2007-09-27 18:46:06 +0000 | [diff] [blame] | 927 | if (RegAdded.insert(*Alias)) |
| 928 | LRegs.push_back(*Alias); |
| 929 | } |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 930 | } |
| 931 | } |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 932 | return !LRegs.empty(); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 933 | } |
| 934 | |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 935 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 936 | /// ListScheduleBottomUp - The main loop of list scheduling for bottom-up |
| 937 | /// schedulers. |
| 938 | void ScheduleDAGRRList::ListScheduleBottomUp() { |
| 939 | unsigned CurCycle = 0; |
| 940 | // Add root to Available queue. |
Dan Gohman | 4370f26 | 2008-04-15 01:22:18 +0000 | [diff] [blame] | 941 | if (!SUnits.empty()) { |
Dan Gohman | 5a390b9 | 2008-11-13 21:21:28 +0000 | [diff] [blame] | 942 | SUnit *RootSU = &SUnits[DAG->getRoot().getNode()->getNodeId()]; |
Dan Gohman | 4370f26 | 2008-04-15 01:22:18 +0000 | [diff] [blame] | 943 | assert(RootSU->Succs.empty() && "Graph root shouldn't have successors!"); |
| 944 | RootSU->isAvailable = true; |
| 945 | AvailableQueue->push(RootSU); |
| 946 | } |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 947 | |
| 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. |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 950 | SmallVector<SUnit*, 4> NotReady; |
Dan Gohman | fa63cc4 | 2008-06-23 21:15:00 +0000 | [diff] [blame] | 951 | DenseMap<SUnit*, SmallVector<unsigned, 4> > LRegsMap; |
Dan Gohman | e6e1348 | 2008-06-21 15:52:51 +0000 | [diff] [blame] | 952 | Sequence.reserve(SUnits.size()); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 953 | while (!AvailableQueue->empty()) { |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 954 | bool Delayed = false; |
Dan Gohman | fa63cc4 | 2008-06-23 21:15:00 +0000 | [diff] [blame] | 955 | LRegsMap.clear(); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 956 | SUnit *CurSU = AvailableQueue->pop(); |
| 957 | while (CurSU) { |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 958 | if (CurSU->CycleBound <= CurCycle) { |
| 959 | SmallVector<unsigned, 4> LRegs; |
| 960 | if (!DelayForLiveRegsBottomUp(CurSU, LRegs)) |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 961 | break; |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 962 | Delayed = true; |
| 963 | LRegsMap.insert(std::make_pair(CurSU, LRegs)); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 964 | } |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 965 | |
| 966 | CurSU->isPending = true; // This SU is not in AvailableQueue right now. |
| 967 | NotReady.push_back(CurSU); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 968 | CurSU = AvailableQueue->pop(); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 969 | } |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 970 | |
| 971 | // All candidates are delayed due to live physical reg dependencies. |
| 972 | // Try backtracking, code duplication, or inserting cross class copies |
| 973 | // to resolve it. |
| 974 | if (Delayed && !CurSU) { |
| 975 | for (unsigned i = 0, e = NotReady.size(); i != e; ++i) { |
| 976 | SUnit *TrySU = NotReady[i]; |
| 977 | SmallVector<unsigned, 4> &LRegs = LRegsMap[TrySU]; |
| 978 | |
| 979 | // Try unscheduling up to the point where it's safe to schedule |
| 980 | // this node. |
| 981 | unsigned LiveCycle = CurCycle; |
| 982 | for (unsigned j = 0, ee = LRegs.size(); j != ee; ++j) { |
| 983 | unsigned Reg = LRegs[j]; |
| 984 | unsigned LCycle = LiveRegCycles[Reg]; |
| 985 | LiveCycle = std::min(LiveCycle, LCycle); |
| 986 | } |
| 987 | SUnit *OldSU = Sequence[LiveCycle]; |
| 988 | if (!WillCreateCycle(TrySU, OldSU)) { |
| 989 | BacktrackBottomUp(TrySU, LiveCycle, CurCycle); |
| 990 | // Force the current node to be scheduled before the node that |
| 991 | // requires the physical reg dep. |
| 992 | if (OldSU->isAvailable) { |
| 993 | OldSU->isAvailable = false; |
| 994 | AvailableQueue->remove(OldSU); |
| 995 | } |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 996 | AddPred(TrySU, OldSU, true, true); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 997 | // If one or more successors has been unscheduled, then the current |
| 998 | // node is no longer avaialable. Schedule a successor that's now |
| 999 | // available instead. |
| 1000 | if (!TrySU->isAvailable) |
| 1001 | CurSU = AvailableQueue->pop(); |
| 1002 | else { |
| 1003 | CurSU = TrySU; |
| 1004 | TrySU->isPending = false; |
| 1005 | NotReady.erase(NotReady.begin()+i); |
| 1006 | } |
| 1007 | break; |
| 1008 | } |
| 1009 | } |
| 1010 | |
| 1011 | if (!CurSU) { |
Dan Gohman | fd227e9 | 2008-03-25 17:10:29 +0000 | [diff] [blame] | 1012 | // Can't backtrack. Try duplicating the nodes that produces these |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 1013 | // "expensive to copy" values to break the dependency. In case even |
| 1014 | // that doesn't work, insert cross class copies. |
| 1015 | SUnit *TrySU = NotReady[0]; |
| 1016 | SmallVector<unsigned, 4> &LRegs = LRegsMap[TrySU]; |
| 1017 | assert(LRegs.size() == 1 && "Can't handle this yet!"); |
| 1018 | unsigned Reg = LRegs[0]; |
| 1019 | SUnit *LRDef = LiveRegDefs[Reg]; |
Evan Cheng | 79e9713 | 2007-10-05 01:39:18 +0000 | [diff] [blame] | 1020 | SUnit *NewDef = CopyAndMoveSuccessors(LRDef); |
| 1021 | if (!NewDef) { |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 1022 | // Issue expensive cross register class copies. |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1023 | MVT VT = getPhysicalRegisterVT(LRDef->getNode(), Reg, TII); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 1024 | const TargetRegisterClass *RC = |
Evan Cheng | e88a625 | 2008-03-11 07:19:34 +0000 | [diff] [blame] | 1025 | TRI->getPhysicalRegisterRegClass(Reg, VT); |
Dan Gohman | 3a4be0f | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 1026 | const TargetRegisterClass *DestRC = TRI->getCrossCopyRegClass(RC); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 1027 | if (!DestRC) { |
| 1028 | assert(false && "Don't know how to copy this physical register!"); |
| 1029 | abort(); |
| 1030 | } |
| 1031 | SmallVector<SUnit*, 2> Copies; |
| 1032 | InsertCCCopiesAndMoveSuccs(LRDef, Reg, DestRC, RC, Copies); |
| 1033 | DOUT << "Adding an edge from SU # " << TrySU->NodeNum |
| 1034 | << " to SU #" << Copies.front()->NodeNum << "\n"; |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 1035 | AddPred(TrySU, Copies.front(), true, true); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 1036 | NewDef = Copies.back(); |
| 1037 | } |
| 1038 | |
| 1039 | DOUT << "Adding an edge from SU # " << NewDef->NodeNum |
| 1040 | << " to SU #" << TrySU->NodeNum << "\n"; |
| 1041 | LiveRegDefs[Reg] = NewDef; |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 1042 | AddPred(NewDef, TrySU, true, true); |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 1043 | TrySU->isAvailable = false; |
| 1044 | CurSU = NewDef; |
| 1045 | } |
| 1046 | |
| 1047 | if (!CurSU) { |
| 1048 | assert(false && "Unable to resolve live physical register dependencies!"); |
| 1049 | abort(); |
| 1050 | } |
| 1051 | } |
| 1052 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1053 | // Add the nodes that aren't ready back onto the available list. |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1054 | for (unsigned i = 0, e = NotReady.size(); i != e; ++i) { |
| 1055 | NotReady[i]->isPending = false; |
Evan Cheng | 1ec79b4 | 2007-09-27 07:09:03 +0000 | [diff] [blame] | 1056 | // May no longer be available due to backtracking. |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1057 | if (NotReady[i]->isAvailable) |
| 1058 | AvailableQueue->push(NotReady[i]); |
| 1059 | } |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1060 | NotReady.clear(); |
| 1061 | |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1062 | if (!CurSU) |
| 1063 | Sequence.push_back(0); |
Dan Gohman | 6e58726 | 2008-11-18 21:22:20 +0000 | [diff] [blame] | 1064 | else |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1065 | ScheduleNodeBottomUp(CurSU, CurCycle); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1066 | ++CurCycle; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1069 | // Reverse the order if it is bottom up. |
| 1070 | std::reverse(Sequence.begin(), Sequence.end()); |
| 1071 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1072 | #ifndef NDEBUG |
Dan Gohman | 4ce15e1 | 2008-11-20 01:26:25 +0000 | [diff] [blame] | 1073 | VerifySchedule(isBottomUp); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1074 | #endif |
| 1075 | } |
| 1076 | |
| 1077 | //===----------------------------------------------------------------------===// |
| 1078 | // Top-Down Scheduling |
| 1079 | //===----------------------------------------------------------------------===// |
| 1080 | |
| 1081 | /// ReleaseSucc - Decrement the NumPredsLeft count of a successor. Add it to |
Dan Gohman | 54a187e | 2007-08-20 19:28:38 +0000 | [diff] [blame] | 1082 | /// the AvailableQueue if the count reaches zero. Also update its cycle bound. |
Dan Gohman | 5ebdb98 | 2008-11-18 00:38:59 +0000 | [diff] [blame] | 1083 | void ScheduleDAGRRList::ReleaseSucc(SUnit *SU, SUnit *SuccSU, bool isChain) { |
Evan Cheng | 038dcc5 | 2007-09-28 19:24:24 +0000 | [diff] [blame] | 1084 | --SuccSU->NumPredsLeft; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1085 | |
| 1086 | #ifndef NDEBUG |
Evan Cheng | 038dcc5 | 2007-09-28 19:24:24 +0000 | [diff] [blame] | 1087 | if (SuccSU->NumPredsLeft < 0) { |
Dan Gohman | 5ebdb98 | 2008-11-18 00:38:59 +0000 | [diff] [blame] | 1088 | cerr << "*** Scheduling failed! ***\n"; |
Dan Gohman | 22d07b1 | 2008-11-18 02:06:40 +0000 | [diff] [blame] | 1089 | SuccSU->dump(this); |
Bill Wendling | 22e978a | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 1090 | cerr << " has been released too many times!\n"; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1091 | assert(0); |
| 1092 | } |
| 1093 | #endif |
| 1094 | |
Dan Gohman | 5ebdb98 | 2008-11-18 00:38:59 +0000 | [diff] [blame] | 1095 | // Compute how many cycles it will be before this actually becomes |
| 1096 | // available. This is the max of the start time of all predecessors plus |
| 1097 | // their latencies. |
| 1098 | // If this is a token edge, we don't need to wait for the latency of the |
| 1099 | // preceeding instruction (e.g. a long-latency load) unless there is also |
| 1100 | // some other data dependence. |
| 1101 | unsigned PredDoneCycle = SU->Cycle; |
| 1102 | if (!isChain) |
| 1103 | PredDoneCycle += SU->Latency; |
| 1104 | else if (SU->Latency) |
| 1105 | PredDoneCycle += 1; |
| 1106 | SuccSU->CycleBound = std::max(SuccSU->CycleBound, PredDoneCycle); |
| 1107 | |
Evan Cheng | 038dcc5 | 2007-09-28 19:24:24 +0000 | [diff] [blame] | 1108 | if (SuccSU->NumPredsLeft == 0) { |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1109 | SuccSU->isAvailable = true; |
| 1110 | AvailableQueue->push(SuccSU); |
| 1111 | } |
| 1112 | } |
| 1113 | |
| 1114 | |
| 1115 | /// ScheduleNodeTopDown - Add the node to the schedule. Decrement the pending |
| 1116 | /// count of its successors. If a successor pending count is zero, add it to |
| 1117 | /// the Available queue. |
Evan Cheng | d12c97d | 2006-05-30 18:05:39 +0000 | [diff] [blame] | 1118 | void ScheduleDAGRRList::ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle) { |
Bill Wendling | 22e978a | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 1119 | DOUT << "*** Scheduling [" << CurCycle << "]: "; |
Dan Gohman | 22d07b1 | 2008-11-18 02:06:40 +0000 | [diff] [blame] | 1120 | DEBUG(SU->dump(this)); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1121 | |
Dan Gohman | 92a36d7 | 2008-11-17 21:31:02 +0000 | [diff] [blame] | 1122 | SU->Cycle = CurCycle; |
| 1123 | Sequence.push_back(SU); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1124 | |
| 1125 | // Top down: release successors |
Chris Lattner | d86418a | 2006-08-17 00:09:56 +0000 | [diff] [blame] | 1126 | for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 1127 | I != E; ++I) |
Dan Gohman | 5ebdb98 | 2008-11-18 00:38:59 +0000 | [diff] [blame] | 1128 | ReleaseSucc(SU, I->Dep, I->isCtrl); |
Dan Gohman | 92a36d7 | 2008-11-17 21:31:02 +0000 | [diff] [blame] | 1129 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1130 | SU->isScheduled = true; |
Dan Gohman | 92a36d7 | 2008-11-17 21:31:02 +0000 | [diff] [blame] | 1131 | AvailableQueue->ScheduledNode(SU); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1132 | } |
| 1133 | |
Dan Gohman | 54a187e | 2007-08-20 19:28:38 +0000 | [diff] [blame] | 1134 | /// ListScheduleTopDown - The main loop of list scheduling for top-down |
| 1135 | /// schedulers. |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1136 | void ScheduleDAGRRList::ListScheduleTopDown() { |
| 1137 | unsigned CurCycle = 0; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1138 | |
| 1139 | // All leaves to Available queue. |
| 1140 | for (unsigned i = 0, e = SUnits.size(); i != e; ++i) { |
| 1141 | // It is available if it has no predecessors. |
Dan Gohman | 4370f26 | 2008-04-15 01:22:18 +0000 | [diff] [blame] | 1142 | if (SUnits[i].Preds.empty()) { |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1143 | AvailableQueue->push(&SUnits[i]); |
| 1144 | SUnits[i].isAvailable = true; |
| 1145 | } |
| 1146 | } |
| 1147 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1148 | // While Available queue is not empty, grab the node with the highest |
Dan Gohman | 54a187e | 2007-08-20 19:28:38 +0000 | [diff] [blame] | 1149 | // priority. If it is not ready put it back. Schedule the node. |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1150 | std::vector<SUnit*> NotReady; |
Dan Gohman | e6e1348 | 2008-06-21 15:52:51 +0000 | [diff] [blame] | 1151 | Sequence.reserve(SUnits.size()); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1152 | while (!AvailableQueue->empty()) { |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1153 | SUnit *CurSU = AvailableQueue->pop(); |
| 1154 | while (CurSU && CurSU->CycleBound > CurCycle) { |
| 1155 | NotReady.push_back(CurSU); |
| 1156 | CurSU = AvailableQueue->pop(); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | // Add the nodes that aren't ready back onto the available list. |
| 1160 | AvailableQueue->push_all(NotReady); |
| 1161 | NotReady.clear(); |
| 1162 | |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1163 | if (!CurSU) |
| 1164 | Sequence.push_back(0); |
Dan Gohman | 6e58726 | 2008-11-18 21:22:20 +0000 | [diff] [blame] | 1165 | else |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1166 | ScheduleNodeTopDown(CurSU, CurCycle); |
Dan Gohman | 4370f26 | 2008-04-15 01:22:18 +0000 | [diff] [blame] | 1167 | ++CurCycle; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1168 | } |
| 1169 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1170 | #ifndef NDEBUG |
Dan Gohman | 4ce15e1 | 2008-11-20 01:26:25 +0000 | [diff] [blame] | 1171 | VerifySchedule(isBottomUp); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1172 | #endif |
| 1173 | } |
| 1174 | |
| 1175 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1176 | //===----------------------------------------------------------------------===// |
| 1177 | // RegReductionPriorityQueue Implementation |
| 1178 | //===----------------------------------------------------------------------===// |
| 1179 | // |
| 1180 | // This is a SchedulingPriorityQueue that schedules using Sethi Ullman numbers |
| 1181 | // to reduce register pressure. |
| 1182 | // |
| 1183 | namespace { |
| 1184 | template<class SF> |
| 1185 | class RegReductionPriorityQueue; |
| 1186 | |
| 1187 | /// Sorting functions for the Available queue. |
| 1188 | struct bu_ls_rr_sort : public std::binary_function<SUnit*, SUnit*, bool> { |
| 1189 | RegReductionPriorityQueue<bu_ls_rr_sort> *SPQ; |
| 1190 | bu_ls_rr_sort(RegReductionPriorityQueue<bu_ls_rr_sort> *spq) : SPQ(spq) {} |
| 1191 | bu_ls_rr_sort(const bu_ls_rr_sort &RHS) : SPQ(RHS.SPQ) {} |
| 1192 | |
| 1193 | bool operator()(const SUnit* left, const SUnit* right) const; |
| 1194 | }; |
| 1195 | |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1196 | struct bu_ls_rr_fast_sort : public std::binary_function<SUnit*, SUnit*, bool>{ |
| 1197 | RegReductionPriorityQueue<bu_ls_rr_fast_sort> *SPQ; |
| 1198 | bu_ls_rr_fast_sort(RegReductionPriorityQueue<bu_ls_rr_fast_sort> *spq) |
| 1199 | : SPQ(spq) {} |
| 1200 | bu_ls_rr_fast_sort(const bu_ls_rr_fast_sort &RHS) : SPQ(RHS.SPQ) {} |
| 1201 | |
| 1202 | bool operator()(const SUnit* left, const SUnit* right) const; |
| 1203 | }; |
| 1204 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1205 | struct td_ls_rr_sort : public std::binary_function<SUnit*, SUnit*, bool> { |
| 1206 | RegReductionPriorityQueue<td_ls_rr_sort> *SPQ; |
| 1207 | td_ls_rr_sort(RegReductionPriorityQueue<td_ls_rr_sort> *spq) : SPQ(spq) {} |
| 1208 | td_ls_rr_sort(const td_ls_rr_sort &RHS) : SPQ(RHS.SPQ) {} |
| 1209 | |
| 1210 | bool operator()(const SUnit* left, const SUnit* right) const; |
| 1211 | }; |
| 1212 | } // end anonymous namespace |
| 1213 | |
Evan Cheng | 961bbd3 | 2007-01-08 23:50:38 +0000 | [diff] [blame] | 1214 | static inline bool isCopyFromLiveIn(const SUnit *SU) { |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1215 | SDNode *N = SU->getNode(); |
Evan Cheng | 8e136a9 | 2007-09-26 21:36:17 +0000 | [diff] [blame] | 1216 | return N && N->getOpcode() == ISD::CopyFromReg && |
Evan Cheng | 961bbd3 | 2007-01-08 23:50:38 +0000 | [diff] [blame] | 1217 | N->getOperand(N->getNumOperands()-1).getValueType() != MVT::Flag; |
| 1218 | } |
| 1219 | |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1220 | /// CalcNodeBUSethiUllmanNumber - Compute Sethi Ullman number for bottom up |
| 1221 | /// scheduling. Smaller number is the higher priority. |
| 1222 | static unsigned |
| 1223 | CalcNodeBUSethiUllmanNumber(const SUnit *SU, std::vector<unsigned> &SUNumbers) { |
| 1224 | unsigned &SethiUllmanNumber = SUNumbers[SU->NodeNum]; |
| 1225 | if (SethiUllmanNumber != 0) |
| 1226 | return SethiUllmanNumber; |
| 1227 | |
| 1228 | unsigned Extra = 0; |
| 1229 | for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
| 1230 | I != E; ++I) { |
| 1231 | if (I->isCtrl) continue; // ignore chain preds |
| 1232 | SUnit *PredSU = I->Dep; |
| 1233 | unsigned PredSethiUllman = CalcNodeBUSethiUllmanNumber(PredSU, SUNumbers); |
| 1234 | if (PredSethiUllman > SethiUllmanNumber) { |
| 1235 | SethiUllmanNumber = PredSethiUllman; |
| 1236 | Extra = 0; |
| 1237 | } else if (PredSethiUllman == SethiUllmanNumber && !I->isCtrl) |
| 1238 | ++Extra; |
| 1239 | } |
| 1240 | |
| 1241 | SethiUllmanNumber += Extra; |
| 1242 | |
| 1243 | if (SethiUllmanNumber == 0) |
| 1244 | SethiUllmanNumber = 1; |
| 1245 | |
| 1246 | return SethiUllmanNumber; |
| 1247 | } |
| 1248 | |
| 1249 | /// CalcNodeTDSethiUllmanNumber - Compute Sethi Ullman number for top down |
| 1250 | /// scheduling. Smaller number is the higher priority. |
| 1251 | static unsigned |
| 1252 | CalcNodeTDSethiUllmanNumber(const SUnit *SU, std::vector<unsigned> &SUNumbers) { |
| 1253 | unsigned &SethiUllmanNumber = SUNumbers[SU->NodeNum]; |
| 1254 | if (SethiUllmanNumber != 0) |
| 1255 | return SethiUllmanNumber; |
| 1256 | |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1257 | unsigned Opc = SU->getNode() ? SU->getNode()->getOpcode() : 0; |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1258 | if (Opc == ISD::TokenFactor || Opc == ISD::CopyToReg) |
| 1259 | SethiUllmanNumber = 0xffff; |
| 1260 | else if (SU->NumSuccsLeft == 0) |
| 1261 | // If SU does not have a use, i.e. it doesn't produce a value that would |
| 1262 | // be consumed (e.g. store), then it terminates a chain of computation. |
| 1263 | // Give it a small SethiUllman number so it will be scheduled right before |
| 1264 | // its predecessors that it doesn't lengthen their live ranges. |
| 1265 | SethiUllmanNumber = 0; |
| 1266 | else if (SU->NumPredsLeft == 0 && |
| 1267 | (Opc != ISD::CopyFromReg || isCopyFromLiveIn(SU))) |
| 1268 | SethiUllmanNumber = 0xffff; |
| 1269 | else { |
| 1270 | int Extra = 0; |
| 1271 | for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
| 1272 | I != E; ++I) { |
| 1273 | if (I->isCtrl) continue; // ignore chain preds |
| 1274 | SUnit *PredSU = I->Dep; |
| 1275 | unsigned PredSethiUllman = CalcNodeTDSethiUllmanNumber(PredSU, SUNumbers); |
| 1276 | if (PredSethiUllman > SethiUllmanNumber) { |
| 1277 | SethiUllmanNumber = PredSethiUllman; |
| 1278 | Extra = 0; |
| 1279 | } else if (PredSethiUllman == SethiUllmanNumber && !I->isCtrl) |
| 1280 | ++Extra; |
| 1281 | } |
| 1282 | |
| 1283 | SethiUllmanNumber += Extra; |
| 1284 | } |
| 1285 | |
| 1286 | return SethiUllmanNumber; |
| 1287 | } |
| 1288 | |
| 1289 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1290 | namespace { |
| 1291 | template<class SF> |
Chris Lattner | 996795b | 2006-06-28 23:17:24 +0000 | [diff] [blame] | 1292 | class VISIBILITY_HIDDEN RegReductionPriorityQueue |
| 1293 | : public SchedulingPriorityQueue { |
Dan Gohman | a4db335 | 2008-06-21 18:35:25 +0000 | [diff] [blame] | 1294 | PriorityQueue<SUnit*, std::vector<SUnit*>, SF> Queue; |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 1295 | unsigned currentQueueId; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1296 | |
| 1297 | public: |
| 1298 | RegReductionPriorityQueue() : |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 1299 | Queue(SF(this)), currentQueueId(0) {} |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1300 | |
Dan Gohman | 50c76be | 2008-10-31 19:06:33 +0000 | [diff] [blame] | 1301 | virtual void initNodes(std::vector<SUnit> &sunits) = 0; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1302 | |
Dan Gohman | 50c76be | 2008-10-31 19:06:33 +0000 | [diff] [blame] | 1303 | virtual void addNode(const SUnit *SU) = 0; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1304 | |
Dan Gohman | 50c76be | 2008-10-31 19:06:33 +0000 | [diff] [blame] | 1305 | virtual void updateNode(const SUnit *SU) = 0; |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1306 | |
Dan Gohman | 50c76be | 2008-10-31 19:06:33 +0000 | [diff] [blame] | 1307 | virtual void releaseState() = 0; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1308 | |
Dan Gohman | 50c76be | 2008-10-31 19:06:33 +0000 | [diff] [blame] | 1309 | virtual unsigned getNodePriority(const SUnit *SU) const = 0; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1310 | |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1311 | unsigned size() const { return Queue.size(); } |
| 1312 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1313 | bool empty() const { return Queue.empty(); } |
| 1314 | |
| 1315 | void push(SUnit *U) { |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 1316 | assert(!U->NodeQueueId && "Node in the queue already"); |
| 1317 | U->NodeQueueId = ++currentQueueId; |
Dan Gohman | a4db335 | 2008-06-21 18:35:25 +0000 | [diff] [blame] | 1318 | Queue.push(U); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1319 | } |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 1320 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1321 | void push_all(const std::vector<SUnit *> &Nodes) { |
| 1322 | for (unsigned i = 0, e = Nodes.size(); i != e; ++i) |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 1323 | push(Nodes[i]); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | SUnit *pop() { |
Evan Cheng | d12c97d | 2006-05-30 18:05:39 +0000 | [diff] [blame] | 1327 | if (empty()) return NULL; |
Dan Gohman | a4db335 | 2008-06-21 18:35:25 +0000 | [diff] [blame] | 1328 | SUnit *V = Queue.top(); |
| 1329 | Queue.pop(); |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 1330 | V->NodeQueueId = 0; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1331 | return V; |
| 1332 | } |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1333 | |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1334 | void remove(SUnit *SU) { |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 1335 | assert(!Queue.empty() && "Queue is empty!"); |
Dan Gohman | a4db335 | 2008-06-21 18:35:25 +0000 | [diff] [blame] | 1336 | assert(SU->NodeQueueId != 0 && "Not in queue!"); |
| 1337 | Queue.erase_one(SU); |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 1338 | SU->NodeQueueId = 0; |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1339 | } |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1340 | }; |
| 1341 | |
Chris Lattner | 996795b | 2006-06-28 23:17:24 +0000 | [diff] [blame] | 1342 | class VISIBILITY_HIDDEN BURegReductionPriorityQueue |
Dan Gohman | 4b49be1 | 2008-06-21 01:08:22 +0000 | [diff] [blame] | 1343 | : public RegReductionPriorityQueue<bu_ls_rr_sort> { |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1344 | // SUnits - The SUnits for the current graph. |
Dan Gohman | e955c48 | 2008-08-05 14:45:15 +0000 | [diff] [blame] | 1345 | std::vector<SUnit> *SUnits; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1346 | |
| 1347 | // SethiUllmanNumbers - The SethiUllman number for each node. |
Evan Cheng | 961bbd3 | 2007-01-08 23:50:38 +0000 | [diff] [blame] | 1348 | std::vector<unsigned> SethiUllmanNumbers; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1349 | |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1350 | const TargetInstrInfo *TII; |
Dan Gohman | 3a4be0f | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 1351 | const TargetRegisterInfo *TRI; |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 1352 | ScheduleDAGRRList *scheduleDAG; |
Evan Cheng | 2c97731 | 2008-07-01 18:05:03 +0000 | [diff] [blame] | 1353 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1354 | public: |
Evan Cheng | f989141 | 2007-12-20 09:25:31 +0000 | [diff] [blame] | 1355 | explicit BURegReductionPriorityQueue(const TargetInstrInfo *tii, |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1356 | const TargetRegisterInfo *tri) |
| 1357 | : TII(tii), TRI(tri), scheduleDAG(NULL) {} |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1358 | |
Dan Gohman | 46520a2 | 2008-06-21 19:18:17 +0000 | [diff] [blame] | 1359 | void initNodes(std::vector<SUnit> &sunits) { |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1360 | SUnits = &sunits; |
| 1361 | // Add pseudo dependency edges for two-address nodes. |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1362 | AddPseudoTwoAddrDeps(); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1363 | // Calculate node priorities. |
Evan Cheng | 6730f03 | 2007-01-08 23:55:53 +0000 | [diff] [blame] | 1364 | CalculateSethiUllmanNumbers(); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1365 | } |
| 1366 | |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1367 | void addNode(const SUnit *SU) { |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1368 | unsigned SUSize = SethiUllmanNumbers.size(); |
| 1369 | if (SUnits->size() > SUSize) |
| 1370 | SethiUllmanNumbers.resize(SUSize*2, 0); |
| 1371 | CalcNodeBUSethiUllmanNumber(SU, SethiUllmanNumbers); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | void updateNode(const SUnit *SU) { |
| 1375 | SethiUllmanNumbers[SU->NodeNum] = 0; |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1376 | CalcNodeBUSethiUllmanNumber(SU, SethiUllmanNumbers); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1377 | } |
| 1378 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1379 | void releaseState() { |
| 1380 | SUnits = 0; |
| 1381 | SethiUllmanNumbers.clear(); |
| 1382 | } |
| 1383 | |
Evan Cheng | 6730f03 | 2007-01-08 23:55:53 +0000 | [diff] [blame] | 1384 | unsigned getNodePriority(const SUnit *SU) const { |
Evan Cheng | 961bbd3 | 2007-01-08 23:50:38 +0000 | [diff] [blame] | 1385 | assert(SU->NodeNum < SethiUllmanNumbers.size()); |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1386 | unsigned Opc = SU->getNode() ? SU->getNode()->getOpcode() : 0; |
Evan Cheng | 961bbd3 | 2007-01-08 23:50:38 +0000 | [diff] [blame] | 1387 | if (Opc == ISD::CopyFromReg && !isCopyFromLiveIn(SU)) |
| 1388 | // CopyFromReg should be close to its def because it restricts |
| 1389 | // allocation choices. But if it is a livein then perhaps we want it |
| 1390 | // closer to its uses so it can be coalesced. |
| 1391 | return 0xffff; |
| 1392 | else if (Opc == ISD::TokenFactor || Opc == ISD::CopyToReg) |
| 1393 | // CopyToReg should be close to its uses to facilitate coalescing and |
| 1394 | // avoid spilling. |
| 1395 | return 0; |
Evan Cheng | aa2d6ef | 2007-10-12 08:50:34 +0000 | [diff] [blame] | 1396 | else if (Opc == TargetInstrInfo::EXTRACT_SUBREG || |
| 1397 | Opc == TargetInstrInfo::INSERT_SUBREG) |
| 1398 | // EXTRACT_SUBREG / INSERT_SUBREG should be close to its use to |
| 1399 | // facilitate coalescing. |
| 1400 | return 0; |
Evan Cheng | 961bbd3 | 2007-01-08 23:50:38 +0000 | [diff] [blame] | 1401 | else if (SU->NumSuccs == 0) |
| 1402 | // If SU does not have a use, i.e. it doesn't produce a value that would |
| 1403 | // be consumed (e.g. store), then it terminates a chain of computation. |
| 1404 | // Give it a large SethiUllman number so it will be scheduled right |
| 1405 | // before its predecessors that it doesn't lengthen their live ranges. |
| 1406 | return 0xffff; |
| 1407 | else if (SU->NumPreds == 0) |
| 1408 | // If SU does not have a def, schedule it close to its uses because it |
| 1409 | // does not lengthen any live ranges. |
| 1410 | return 0; |
| 1411 | else |
| 1412 | return SethiUllmanNumbers[SU->NodeNum]; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1413 | } |
| 1414 | |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 1415 | void setScheduleDAG(ScheduleDAGRRList *scheduleDag) { |
| 1416 | scheduleDAG = scheduleDag; |
| 1417 | } |
| 1418 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1419 | private: |
Evan Cheng | 73bdf04 | 2008-03-01 00:39:47 +0000 | [diff] [blame] | 1420 | bool canClobber(const SUnit *SU, const SUnit *Op); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1421 | void AddPseudoTwoAddrDeps(); |
Evan Cheng | 6730f03 | 2007-01-08 23:55:53 +0000 | [diff] [blame] | 1422 | void CalculateSethiUllmanNumbers(); |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1423 | }; |
| 1424 | |
| 1425 | |
| 1426 | class VISIBILITY_HIDDEN BURegReductionFastPriorityQueue |
| 1427 | : public RegReductionPriorityQueue<bu_ls_rr_fast_sort> { |
| 1428 | // SUnits - The SUnits for the current graph. |
| 1429 | const std::vector<SUnit> *SUnits; |
| 1430 | |
| 1431 | // SethiUllmanNumbers - The SethiUllman number for each node. |
| 1432 | std::vector<unsigned> SethiUllmanNumbers; |
| 1433 | public: |
| 1434 | explicit BURegReductionFastPriorityQueue() {} |
| 1435 | |
| 1436 | void initNodes(std::vector<SUnit> &sunits) { |
| 1437 | SUnits = &sunits; |
| 1438 | // Calculate node priorities. |
| 1439 | CalculateSethiUllmanNumbers(); |
| 1440 | } |
| 1441 | |
| 1442 | void addNode(const SUnit *SU) { |
| 1443 | unsigned SUSize = SethiUllmanNumbers.size(); |
| 1444 | if (SUnits->size() > SUSize) |
| 1445 | SethiUllmanNumbers.resize(SUSize*2, 0); |
| 1446 | CalcNodeBUSethiUllmanNumber(SU, SethiUllmanNumbers); |
| 1447 | } |
| 1448 | |
| 1449 | void updateNode(const SUnit *SU) { |
| 1450 | SethiUllmanNumbers[SU->NodeNum] = 0; |
| 1451 | CalcNodeBUSethiUllmanNumber(SU, SethiUllmanNumbers); |
| 1452 | } |
| 1453 | |
| 1454 | void releaseState() { |
| 1455 | SUnits = 0; |
| 1456 | SethiUllmanNumbers.clear(); |
| 1457 | } |
| 1458 | |
| 1459 | unsigned getNodePriority(const SUnit *SU) const { |
| 1460 | return SethiUllmanNumbers[SU->NodeNum]; |
| 1461 | } |
| 1462 | |
| 1463 | private: |
| 1464 | void CalculateSethiUllmanNumbers(); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1465 | }; |
| 1466 | |
| 1467 | |
Dan Gohman | 54a187e | 2007-08-20 19:28:38 +0000 | [diff] [blame] | 1468 | class VISIBILITY_HIDDEN TDRegReductionPriorityQueue |
Dan Gohman | 4b49be1 | 2008-06-21 01:08:22 +0000 | [diff] [blame] | 1469 | : public RegReductionPriorityQueue<td_ls_rr_sort> { |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1470 | // SUnits - The SUnits for the current graph. |
| 1471 | const std::vector<SUnit> *SUnits; |
| 1472 | |
| 1473 | // SethiUllmanNumbers - The SethiUllman number for each node. |
Evan Cheng | 961bbd3 | 2007-01-08 23:50:38 +0000 | [diff] [blame] | 1474 | std::vector<unsigned> SethiUllmanNumbers; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1475 | |
| 1476 | public: |
| 1477 | TDRegReductionPriorityQueue() {} |
| 1478 | |
Dan Gohman | 46520a2 | 2008-06-21 19:18:17 +0000 | [diff] [blame] | 1479 | void initNodes(std::vector<SUnit> &sunits) { |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1480 | SUnits = &sunits; |
| 1481 | // Calculate node priorities. |
Evan Cheng | 6730f03 | 2007-01-08 23:55:53 +0000 | [diff] [blame] | 1482 | CalculateSethiUllmanNumbers(); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1483 | } |
| 1484 | |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1485 | void addNode(const SUnit *SU) { |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1486 | unsigned SUSize = SethiUllmanNumbers.size(); |
| 1487 | if (SUnits->size() > SUSize) |
| 1488 | SethiUllmanNumbers.resize(SUSize*2, 0); |
| 1489 | CalcNodeTDSethiUllmanNumber(SU, SethiUllmanNumbers); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1490 | } |
| 1491 | |
| 1492 | void updateNode(const SUnit *SU) { |
| 1493 | SethiUllmanNumbers[SU->NodeNum] = 0; |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1494 | CalcNodeTDSethiUllmanNumber(SU, SethiUllmanNumbers); |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1495 | } |
| 1496 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1497 | void releaseState() { |
| 1498 | SUnits = 0; |
| 1499 | SethiUllmanNumbers.clear(); |
| 1500 | } |
| 1501 | |
Evan Cheng | 6730f03 | 2007-01-08 23:55:53 +0000 | [diff] [blame] | 1502 | unsigned getNodePriority(const SUnit *SU) const { |
Evan Cheng | 961bbd3 | 2007-01-08 23:50:38 +0000 | [diff] [blame] | 1503 | assert(SU->NodeNum < SethiUllmanNumbers.size()); |
| 1504 | return SethiUllmanNumbers[SU->NodeNum]; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | private: |
Evan Cheng | 6730f03 | 2007-01-08 23:55:53 +0000 | [diff] [blame] | 1508 | void CalculateSethiUllmanNumbers(); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1509 | }; |
| 1510 | } |
| 1511 | |
Evan Cheng | b9e3db6 | 2007-03-14 22:43:40 +0000 | [diff] [blame] | 1512 | /// closestSucc - Returns the scheduled cycle of the successor which is |
| 1513 | /// closet to the current cycle. |
Evan Cheng | 2874855 | 2007-03-13 23:25:11 +0000 | [diff] [blame] | 1514 | static unsigned closestSucc(const SUnit *SU) { |
| 1515 | unsigned MaxCycle = 0; |
| 1516 | 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] | 1517 | I != E; ++I) { |
Evan Cheng | 0effc3a | 2007-09-19 01:38:40 +0000 | [diff] [blame] | 1518 | unsigned Cycle = I->Dep->Cycle; |
Evan Cheng | b9e3db6 | 2007-03-14 22:43:40 +0000 | [diff] [blame] | 1519 | // If there are bunch of CopyToRegs stacked up, they should be considered |
| 1520 | // to be at the same position. |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1521 | if (I->Dep->getNode() && I->Dep->getNode()->getOpcode() == ISD::CopyToReg) |
Evan Cheng | 0effc3a | 2007-09-19 01:38:40 +0000 | [diff] [blame] | 1522 | Cycle = closestSucc(I->Dep)+1; |
Evan Cheng | b9e3db6 | 2007-03-14 22:43:40 +0000 | [diff] [blame] | 1523 | if (Cycle > MaxCycle) |
| 1524 | MaxCycle = Cycle; |
| 1525 | } |
Evan Cheng | 2874855 | 2007-03-13 23:25:11 +0000 | [diff] [blame] | 1526 | return MaxCycle; |
| 1527 | } |
| 1528 | |
Evan Cheng | 61bc51e | 2007-12-20 02:22:36 +0000 | [diff] [blame] | 1529 | /// calcMaxScratches - Returns an cost estimate of the worse case requirement |
| 1530 | /// for scratch registers. Live-in operands and live-out results don't count |
| 1531 | /// since they are "fixed". |
| 1532 | static unsigned calcMaxScratches(const SUnit *SU) { |
| 1533 | unsigned Scratches = 0; |
| 1534 | for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
| 1535 | I != E; ++I) { |
| 1536 | if (I->isCtrl) continue; // ignore chain preds |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1537 | if (!I->Dep->getNode() || I->Dep->getNode()->getOpcode() != ISD::CopyFromReg) |
Evan Cheng | 61bc51e | 2007-12-20 02:22:36 +0000 | [diff] [blame] | 1538 | Scratches++; |
| 1539 | } |
| 1540 | for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 1541 | I != E; ++I) { |
| 1542 | if (I->isCtrl) continue; // ignore chain succs |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1543 | if (!I->Dep->getNode() || I->Dep->getNode()->getOpcode() != ISD::CopyToReg) |
Evan Cheng | 61bc51e | 2007-12-20 02:22:36 +0000 | [diff] [blame] | 1544 | Scratches += 10; |
| 1545 | } |
| 1546 | return Scratches; |
| 1547 | } |
| 1548 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1549 | // Bottom up |
| 1550 | bool bu_ls_rr_sort::operator()(const SUnit *left, const SUnit *right) const { |
Evan Cheng | 6730f03 | 2007-01-08 23:55:53 +0000 | [diff] [blame] | 1551 | unsigned LPriority = SPQ->getNodePriority(left); |
| 1552 | unsigned RPriority = SPQ->getNodePriority(right); |
Evan Cheng | 73bdf04 | 2008-03-01 00:39:47 +0000 | [diff] [blame] | 1553 | if (LPriority != RPriority) |
| 1554 | return LPriority > RPriority; |
| 1555 | |
| 1556 | // Try schedule def + use closer when Sethi-Ullman numbers are the same. |
| 1557 | // e.g. |
| 1558 | // t1 = op t2, c1 |
| 1559 | // t3 = op t4, c2 |
| 1560 | // |
| 1561 | // and the following instructions are both ready. |
| 1562 | // t2 = op c3 |
| 1563 | // t4 = op c4 |
| 1564 | // |
| 1565 | // Then schedule t2 = op first. |
| 1566 | // i.e. |
| 1567 | // t4 = op c4 |
| 1568 | // t2 = op c3 |
| 1569 | // t1 = op t2, c1 |
| 1570 | // t3 = op t4, c2 |
| 1571 | // |
| 1572 | // This creates more short live intervals. |
| 1573 | unsigned LDist = closestSucc(left); |
| 1574 | unsigned RDist = closestSucc(right); |
| 1575 | if (LDist != RDist) |
| 1576 | return LDist < RDist; |
| 1577 | |
| 1578 | // Intuitively, it's good to push down instructions whose results are |
| 1579 | // liveout so their long live ranges won't conflict with other values |
| 1580 | // which are needed inside the BB. Further prioritize liveout instructions |
| 1581 | // by the number of operands which are calculated within the BB. |
| 1582 | unsigned LScratch = calcMaxScratches(left); |
| 1583 | unsigned RScratch = calcMaxScratches(right); |
| 1584 | if (LScratch != RScratch) |
| 1585 | return LScratch > RScratch; |
| 1586 | |
| 1587 | if (left->Height != right->Height) |
| 1588 | return left->Height > right->Height; |
| 1589 | |
| 1590 | if (left->Depth != right->Depth) |
| 1591 | return left->Depth < right->Depth; |
| 1592 | |
| 1593 | if (left->CycleBound != right->CycleBound) |
| 1594 | return left->CycleBound > right->CycleBound; |
| 1595 | |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 1596 | assert(left->NodeQueueId && right->NodeQueueId && |
| 1597 | "NodeQueueId cannot be zero"); |
| 1598 | return (left->NodeQueueId > right->NodeQueueId); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1599 | } |
| 1600 | |
Dan Gohman | 4b49be1 | 2008-06-21 01:08:22 +0000 | [diff] [blame] | 1601 | bool |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1602 | bu_ls_rr_fast_sort::operator()(const SUnit *left, const SUnit *right) const { |
| 1603 | unsigned LPriority = SPQ->getNodePriority(left); |
| 1604 | unsigned RPriority = SPQ->getNodePriority(right); |
| 1605 | if (LPriority != RPriority) |
| 1606 | return LPriority > RPriority; |
| 1607 | assert(left->NodeQueueId && right->NodeQueueId && |
| 1608 | "NodeQueueId cannot be zero"); |
| 1609 | return (left->NodeQueueId > right->NodeQueueId); |
| 1610 | } |
| 1611 | |
| 1612 | bool |
Dan Gohman | 4b49be1 | 2008-06-21 01:08:22 +0000 | [diff] [blame] | 1613 | BURegReductionPriorityQueue::canClobber(const SUnit *SU, const SUnit *Op) { |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1614 | if (SU->isTwoAddress) { |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1615 | unsigned Opc = SU->getNode()->getMachineOpcode(); |
Chris Lattner | 03ad885 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 1616 | const TargetInstrDesc &TID = TII->get(Opc); |
Chris Lattner | fd2e338 | 2008-01-07 06:47:00 +0000 | [diff] [blame] | 1617 | unsigned NumRes = TID.getNumDefs(); |
Dan Gohman | 0340d1e | 2008-02-15 20:50:13 +0000 | [diff] [blame] | 1618 | unsigned NumOps = TID.getNumOperands() - NumRes; |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1619 | for (unsigned i = 0; i != NumOps; ++i) { |
Chris Lattner | fd2e338 | 2008-01-07 06:47:00 +0000 | [diff] [blame] | 1620 | if (TID.getOperandConstraint(i+NumRes, TOI::TIED_TO) != -1) { |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1621 | SDNode *DU = SU->getNode()->getOperand(i).getNode(); |
Dan Gohman | 46520a2 | 2008-06-21 19:18:17 +0000 | [diff] [blame] | 1622 | if (DU->getNodeId() != -1 && |
| 1623 | Op->OrigNode == &(*SUnits)[DU->getNodeId()]) |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1624 | return true; |
| 1625 | } |
| 1626 | } |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1627 | } |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1628 | return false; |
| 1629 | } |
| 1630 | |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1631 | |
Evan Cheng | a5e595d | 2007-09-28 22:32:30 +0000 | [diff] [blame] | 1632 | /// hasCopyToRegUse - Return true if SU has a value successor that is a |
| 1633 | /// CopyToReg node. |
Dan Gohman | e955c48 | 2008-08-05 14:45:15 +0000 | [diff] [blame] | 1634 | static bool hasCopyToRegUse(const SUnit *SU) { |
Evan Cheng | a5e595d | 2007-09-28 22:32:30 +0000 | [diff] [blame] | 1635 | for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 1636 | I != E; ++I) { |
| 1637 | if (I->isCtrl) continue; |
Dan Gohman | e955c48 | 2008-08-05 14:45:15 +0000 | [diff] [blame] | 1638 | const SUnit *SuccSU = I->Dep; |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1639 | if (SuccSU->getNode() && SuccSU->getNode()->getOpcode() == ISD::CopyToReg) |
Evan Cheng | a5e595d | 2007-09-28 22:32:30 +0000 | [diff] [blame] | 1640 | return true; |
| 1641 | } |
| 1642 | return false; |
| 1643 | } |
| 1644 | |
Evan Cheng | f989141 | 2007-12-20 09:25:31 +0000 | [diff] [blame] | 1645 | /// canClobberPhysRegDefs - True if SU would clobber one of SuccSU's |
Dan Gohman | ea04520 | 2008-06-21 22:05:24 +0000 | [diff] [blame] | 1646 | /// physical register defs. |
Dan Gohman | e955c48 | 2008-08-05 14:45:15 +0000 | [diff] [blame] | 1647 | static bool canClobberPhysRegDefs(const SUnit *SuccSU, const SUnit *SU, |
Evan Cheng | f989141 | 2007-12-20 09:25:31 +0000 | [diff] [blame] | 1648 | const TargetInstrInfo *TII, |
Dan Gohman | 3a4be0f | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 1649 | const TargetRegisterInfo *TRI) { |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1650 | SDNode *N = SuccSU->getNode(); |
Dan Gohman | 1705968 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 1651 | unsigned NumDefs = TII->get(N->getMachineOpcode()).getNumDefs(); |
| 1652 | const unsigned *ImpDefs = TII->get(N->getMachineOpcode()).getImplicitDefs(); |
Dan Gohman | ea04520 | 2008-06-21 22:05:24 +0000 | [diff] [blame] | 1653 | assert(ImpDefs && "Caller should check hasPhysRegDefs"); |
Chris Lattner | b0d06b4 | 2008-01-07 03:13:06 +0000 | [diff] [blame] | 1654 | const unsigned *SUImpDefs = |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1655 | TII->get(SU->getNode()->getMachineOpcode()).getImplicitDefs(); |
Evan Cheng | f989141 | 2007-12-20 09:25:31 +0000 | [diff] [blame] | 1656 | if (!SUImpDefs) |
| 1657 | return false; |
| 1658 | for (unsigned i = NumDefs, e = N->getNumValues(); i != e; ++i) { |
Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1659 | MVT VT = N->getValueType(i); |
Evan Cheng | f989141 | 2007-12-20 09:25:31 +0000 | [diff] [blame] | 1660 | if (VT == MVT::Flag || VT == MVT::Other) |
| 1661 | continue; |
Dan Gohman | 6ab52a8 | 2008-09-17 15:25:49 +0000 | [diff] [blame] | 1662 | if (!N->hasAnyUseOfValue(i)) |
| 1663 | continue; |
Evan Cheng | f989141 | 2007-12-20 09:25:31 +0000 | [diff] [blame] | 1664 | unsigned Reg = ImpDefs[i - NumDefs]; |
| 1665 | for (;*SUImpDefs; ++SUImpDefs) { |
| 1666 | unsigned SUReg = *SUImpDefs; |
Dan Gohman | 3a4be0f | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 1667 | if (TRI->regsOverlap(Reg, SUReg)) |
Evan Cheng | f989141 | 2007-12-20 09:25:31 +0000 | [diff] [blame] | 1668 | return true; |
| 1669 | } |
| 1670 | } |
| 1671 | return false; |
| 1672 | } |
| 1673 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1674 | /// AddPseudoTwoAddrDeps - If two nodes share an operand and one of them uses |
| 1675 | /// it as a def&use operand. Add a pseudo control edge from it to the other |
| 1676 | /// 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] | 1677 | /// first (lower in the schedule). If both nodes are two-address, favor the |
| 1678 | /// one that has a CopyToReg use (more likely to be a loop induction update). |
| 1679 | /// If both are two-address, but one is commutable while the other is not |
| 1680 | /// commutable, favor the one that's not commutable. |
Dan Gohman | 4b49be1 | 2008-06-21 01:08:22 +0000 | [diff] [blame] | 1681 | void BURegReductionPriorityQueue::AddPseudoTwoAddrDeps() { |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1682 | for (unsigned i = 0, e = SUnits->size(); i != e; ++i) { |
Dan Gohman | e955c48 | 2008-08-05 14:45:15 +0000 | [diff] [blame] | 1683 | SUnit *SU = &(*SUnits)[i]; |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1684 | if (!SU->isTwoAddress) |
| 1685 | continue; |
| 1686 | |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1687 | SDNode *Node = SU->getNode(); |
Dan Gohman | 072734e | 2008-11-13 23:24:17 +0000 | [diff] [blame] | 1688 | if (!Node || !Node->isMachineOpcode() || SU->getNode()->getFlaggedNode()) |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1689 | continue; |
| 1690 | |
Dan Gohman | 1705968 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 1691 | unsigned Opc = Node->getMachineOpcode(); |
Chris Lattner | 03ad885 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 1692 | const TargetInstrDesc &TID = TII->get(Opc); |
Chris Lattner | fd2e338 | 2008-01-07 06:47:00 +0000 | [diff] [blame] | 1693 | unsigned NumRes = TID.getNumDefs(); |
Dan Gohman | 0340d1e | 2008-02-15 20:50:13 +0000 | [diff] [blame] | 1694 | unsigned NumOps = TID.getNumOperands() - NumRes; |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1695 | for (unsigned j = 0; j != NumOps; ++j) { |
Dan Gohman | 82016c2 | 2008-11-19 02:00:32 +0000 | [diff] [blame] | 1696 | if (TID.getOperandConstraint(j+NumRes, TOI::TIED_TO) == -1) |
| 1697 | continue; |
| 1698 | SDNode *DU = SU->getNode()->getOperand(j).getNode(); |
| 1699 | if (DU->getNodeId() == -1) |
| 1700 | continue; |
| 1701 | const SUnit *DUSU = &(*SUnits)[DU->getNodeId()]; |
| 1702 | if (!DUSU) continue; |
| 1703 | for (SUnit::const_succ_iterator I = DUSU->Succs.begin(), |
| 1704 | E = DUSU->Succs.end(); I != E; ++I) { |
| 1705 | if (I->isCtrl) continue; |
| 1706 | SUnit *SuccSU = I->Dep; |
| 1707 | if (SuccSU == SU) |
Evan Cheng | 1bf16631 | 2007-11-09 01:27:11 +0000 | [diff] [blame] | 1708 | continue; |
Dan Gohman | 82016c2 | 2008-11-19 02:00:32 +0000 | [diff] [blame] | 1709 | // Be conservative. Ignore if nodes aren't at roughly the same |
| 1710 | // depth and height. |
| 1711 | if (SuccSU->Height < SU->Height && (SU->Height - SuccSU->Height) > 1) |
| 1712 | continue; |
| 1713 | if (!SuccSU->getNode() || !SuccSU->getNode()->isMachineOpcode()) |
| 1714 | continue; |
| 1715 | // Don't constrain nodes with physical register defs if the |
| 1716 | // predecessor can clobber them. |
| 1717 | if (SuccSU->hasPhysRegDefs) { |
| 1718 | if (canClobberPhysRegDefs(SuccSU, SU, TII, TRI)) |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 1719 | continue; |
Dan Gohman | 82016c2 | 2008-11-19 02:00:32 +0000 | [diff] [blame] | 1720 | } |
| 1721 | // Don't constraint extract_subreg / insert_subreg these may be |
| 1722 | // coalesced away. We don't them close to their uses. |
| 1723 | unsigned SuccOpc = SuccSU->getNode()->getMachineOpcode(); |
| 1724 | if (SuccOpc == TargetInstrInfo::EXTRACT_SUBREG || |
| 1725 | SuccOpc == TargetInstrInfo::INSERT_SUBREG) |
| 1726 | continue; |
| 1727 | if ((!canClobber(SuccSU, DUSU) || |
| 1728 | (hasCopyToRegUse(SU) && !hasCopyToRegUse(SuccSU)) || |
| 1729 | (!SU->isCommutable && SuccSU->isCommutable)) && |
| 1730 | !scheduleDAG->IsReachable(SuccSU, SU)) { |
| 1731 | DOUT << "Adding an edge from SU # " << SU->NodeNum |
| 1732 | << " to SU #" << SuccSU->NodeNum << "\n"; |
| 1733 | scheduleDAG->AddPred(SU, SuccSU, true, true); |
Evan Cheng | fd2c5dd | 2006-11-04 09:44:31 +0000 | [diff] [blame] | 1734 | } |
| 1735 | } |
| 1736 | } |
| 1737 | } |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1738 | } |
| 1739 | |
Evan Cheng | 6730f03 | 2007-01-08 23:55:53 +0000 | [diff] [blame] | 1740 | /// CalculateSethiUllmanNumbers - Calculate Sethi-Ullman numbers of all |
| 1741 | /// scheduling units. |
Dan Gohman | 4b49be1 | 2008-06-21 01:08:22 +0000 | [diff] [blame] | 1742 | void BURegReductionPriorityQueue::CalculateSethiUllmanNumbers() { |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1743 | SethiUllmanNumbers.assign(SUnits->size(), 0); |
| 1744 | |
| 1745 | for (unsigned i = 0, e = SUnits->size(); i != e; ++i) |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1746 | CalcNodeBUSethiUllmanNumber(&(*SUnits)[i], SethiUllmanNumbers); |
| 1747 | } |
| 1748 | void BURegReductionFastPriorityQueue::CalculateSethiUllmanNumbers() { |
| 1749 | SethiUllmanNumbers.assign(SUnits->size(), 0); |
| 1750 | |
| 1751 | for (unsigned i = 0, e = SUnits->size(); i != e; ++i) |
| 1752 | CalcNodeBUSethiUllmanNumber(&(*SUnits)[i], SethiUllmanNumbers); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1753 | } |
| 1754 | |
Roman Levenstein | 30d0951 | 2008-03-27 09:44:37 +0000 | [diff] [blame] | 1755 | /// LimitedSumOfUnscheduledPredsOfSuccs - Compute the sum of the unscheduled |
Roman Levenstein | bc67450 | 2008-03-27 09:14:57 +0000 | [diff] [blame] | 1756 | /// predecessors of the successors of the SUnit SU. Stop when the provided |
| 1757 | /// limit is exceeded. |
Roman Levenstein | bc67450 | 2008-03-27 09:14:57 +0000 | [diff] [blame] | 1758 | static unsigned LimitedSumOfUnscheduledPredsOfSuccs(const SUnit *SU, |
| 1759 | unsigned Limit) { |
| 1760 | unsigned Sum = 0; |
| 1761 | for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 1762 | I != E; ++I) { |
Dan Gohman | e955c48 | 2008-08-05 14:45:15 +0000 | [diff] [blame] | 1763 | const SUnit *SuccSU = I->Dep; |
Roman Levenstein | bc67450 | 2008-03-27 09:14:57 +0000 | [diff] [blame] | 1764 | for (SUnit::const_pred_iterator II = SuccSU->Preds.begin(), |
| 1765 | EE = SuccSU->Preds.end(); II != EE; ++II) { |
| 1766 | SUnit *PredSU = II->Dep; |
Evan Cheng | 16d7207 | 2008-03-29 18:34:22 +0000 | [diff] [blame] | 1767 | if (!PredSU->isScheduled) |
| 1768 | if (++Sum > Limit) |
| 1769 | return Sum; |
Roman Levenstein | bc67450 | 2008-03-27 09:14:57 +0000 | [diff] [blame] | 1770 | } |
| 1771 | } |
| 1772 | return Sum; |
| 1773 | } |
| 1774 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1775 | |
| 1776 | // Top down |
| 1777 | 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] | 1778 | unsigned LPriority = SPQ->getNodePriority(left); |
| 1779 | unsigned RPriority = SPQ->getNodePriority(right); |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 1780 | bool LIsTarget = left->getNode() && left->getNode()->isMachineOpcode(); |
| 1781 | bool RIsTarget = right->getNode() && right->getNode()->isMachineOpcode(); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1782 | bool LIsFloater = LIsTarget && left->NumPreds == 0; |
| 1783 | bool RIsFloater = RIsTarget && right->NumPreds == 0; |
Roman Levenstein | bc67450 | 2008-03-27 09:14:57 +0000 | [diff] [blame] | 1784 | unsigned LBonus = (LimitedSumOfUnscheduledPredsOfSuccs(left,1) == 1) ? 2 : 0; |
| 1785 | unsigned RBonus = (LimitedSumOfUnscheduledPredsOfSuccs(right,1) == 1) ? 2 : 0; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1786 | |
| 1787 | if (left->NumSuccs == 0 && right->NumSuccs != 0) |
| 1788 | return false; |
| 1789 | else if (left->NumSuccs != 0 && right->NumSuccs == 0) |
| 1790 | return true; |
| 1791 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1792 | if (LIsFloater) |
| 1793 | LBonus -= 2; |
| 1794 | if (RIsFloater) |
| 1795 | RBonus -= 2; |
| 1796 | if (left->NumSuccs == 1) |
| 1797 | LBonus += 2; |
| 1798 | if (right->NumSuccs == 1) |
| 1799 | RBonus += 2; |
| 1800 | |
Evan Cheng | 73bdf04 | 2008-03-01 00:39:47 +0000 | [diff] [blame] | 1801 | if (LPriority+LBonus != RPriority+RBonus) |
| 1802 | return LPriority+LBonus < RPriority+RBonus; |
Anton Korobeynikov | 035eaac | 2008-02-20 11:10:28 +0000 | [diff] [blame] | 1803 | |
Evan Cheng | 73bdf04 | 2008-03-01 00:39:47 +0000 | [diff] [blame] | 1804 | if (left->Depth != right->Depth) |
| 1805 | return left->Depth < right->Depth; |
| 1806 | |
| 1807 | if (left->NumSuccsLeft != right->NumSuccsLeft) |
| 1808 | return left->NumSuccsLeft > right->NumSuccsLeft; |
| 1809 | |
| 1810 | if (left->CycleBound != right->CycleBound) |
| 1811 | return left->CycleBound > right->CycleBound; |
| 1812 | |
Roman Levenstein | 6b37114 | 2008-04-29 09:07:59 +0000 | [diff] [blame] | 1813 | assert(left->NodeQueueId && right->NodeQueueId && |
| 1814 | "NodeQueueId cannot be zero"); |
| 1815 | return (left->NodeQueueId > right->NodeQueueId); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1816 | } |
| 1817 | |
Evan Cheng | 6730f03 | 2007-01-08 23:55:53 +0000 | [diff] [blame] | 1818 | /// CalculateSethiUllmanNumbers - Calculate Sethi-Ullman numbers of all |
| 1819 | /// scheduling units. |
Dan Gohman | 4b49be1 | 2008-06-21 01:08:22 +0000 | [diff] [blame] | 1820 | void TDRegReductionPriorityQueue::CalculateSethiUllmanNumbers() { |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1821 | SethiUllmanNumbers.assign(SUnits->size(), 0); |
| 1822 | |
| 1823 | for (unsigned i = 0, e = SUnits->size(); i != e; ++i) |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1824 | CalcNodeTDSethiUllmanNumber(&(*SUnits)[i], SethiUllmanNumbers); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | //===----------------------------------------------------------------------===// |
| 1828 | // Public Constructor Functions |
| 1829 | //===----------------------------------------------------------------------===// |
| 1830 | |
Jim Laskey | 03593f7 | 2006-08-01 18:29:48 +0000 | [diff] [blame] | 1831 | llvm::ScheduleDAG* llvm::createBURRListDAGScheduler(SelectionDAGISel *IS, |
| 1832 | SelectionDAG *DAG, |
Dan Gohman | 5499e89 | 2008-11-11 17:50:47 +0000 | [diff] [blame] | 1833 | const TargetMachine *TM, |
Evan Cheng | 2c97731 | 2008-07-01 18:05:03 +0000 | [diff] [blame] | 1834 | MachineBasicBlock *BB, |
| 1835 | bool Fast) { |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1836 | if (Fast) |
Dan Gohman | 5a390b9 | 2008-11-13 21:21:28 +0000 | [diff] [blame] | 1837 | return new ScheduleDAGRRList(DAG, BB, *TM, true, true, |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1838 | new BURegReductionFastPriorityQueue()); |
| 1839 | |
Dan Gohman | 5499e89 | 2008-11-11 17:50:47 +0000 | [diff] [blame] | 1840 | const TargetInstrInfo *TII = TM->getInstrInfo(); |
| 1841 | const TargetRegisterInfo *TRI = TM->getRegisterInfo(); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 1842 | |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1843 | BURegReductionPriorityQueue *PQ = new BURegReductionPriorityQueue(TII, TRI); |
Roman Levenstein | 7e71b4b | 2008-03-26 09:18:09 +0000 | [diff] [blame] | 1844 | |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1845 | ScheduleDAGRRList *SD = |
Dan Gohman | 5a390b9 | 2008-11-13 21:21:28 +0000 | [diff] [blame] | 1846 | new ScheduleDAGRRList(DAG, BB, *TM, true, false, PQ); |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1847 | PQ->setScheduleDAG(SD); |
| 1848 | return SD; |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1849 | } |
| 1850 | |
Jim Laskey | 03593f7 | 2006-08-01 18:29:48 +0000 | [diff] [blame] | 1851 | llvm::ScheduleDAG* llvm::createTDRRListDAGScheduler(SelectionDAGISel *IS, |
| 1852 | SelectionDAG *DAG, |
Dan Gohman | 5499e89 | 2008-11-11 17:50:47 +0000 | [diff] [blame] | 1853 | const TargetMachine *TM, |
Evan Cheng | 2c97731 | 2008-07-01 18:05:03 +0000 | [diff] [blame] | 1854 | MachineBasicBlock *BB, |
| 1855 | bool Fast) { |
Dan Gohman | 5a390b9 | 2008-11-13 21:21:28 +0000 | [diff] [blame] | 1856 | return new ScheduleDAGRRList(DAG, BB, *TM, false, Fast, |
Evan Cheng | 7e4abde | 2008-07-02 09:23:51 +0000 | [diff] [blame] | 1857 | new TDRegReductionPriorityQueue()); |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 1858 | } |