Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 1 | //===--- ScheduleDAGSDNodes.cpp - Implement the ScheduleDAGSDNodes class --===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This implements the ScheduleDAG class, which is a base class used by |
| 11 | // scheduling implementation classes. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #define DEBUG_TYPE "pre-RA-sched" |
Evan Cheng | a8efe28 | 2010-03-14 19:56:39 +0000 | [diff] [blame] | 16 | #include "SDNodeDbgValue.h" |
Dan Gohman | 84fbac5 | 2009-02-06 17:22:58 +0000 | [diff] [blame] | 17 | #include "ScheduleDAGSDNodes.h" |
Dan Gohman | bcea859 | 2009-10-10 01:32:21 +0000 | [diff] [blame] | 18 | #include "InstrEmitter.h" |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/SelectionDAG.h" |
Evan Cheng | ab8be96 | 2011-06-29 01:14:12 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCInstrItineraries.h" |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetMachine.h" |
| 22 | #include "llvm/Target/TargetInstrInfo.h" |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 23 | #include "llvm/Target/TargetLowering.h" |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 24 | #include "llvm/Target/TargetRegisterInfo.h" |
Evan Cheng | 5b1b4489 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 25 | #include "llvm/Target/TargetSubtargetInfo.h" |
Evan Cheng | c589e03 | 2010-01-22 03:36:51 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/DenseMap.h" |
| 27 | #include "llvm/ADT/SmallPtrSet.h" |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/SmallSet.h" |
Evan Cheng | c589e03 | 2010-01-22 03:36:51 +0000 | [diff] [blame] | 29 | #include "llvm/ADT/SmallVector.h" |
| 30 | #include "llvm/ADT/Statistic.h" |
Andrew Trick | e0ef509 | 2011-03-05 08:00:22 +0000 | [diff] [blame] | 31 | #include "llvm/Support/CommandLine.h" |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 32 | #include "llvm/Support/Debug.h" |
| 33 | #include "llvm/Support/raw_ostream.h" |
| 34 | using namespace llvm; |
| 35 | |
Evan Cheng | c589e03 | 2010-01-22 03:36:51 +0000 | [diff] [blame] | 36 | STATISTIC(LoadsClustered, "Number of loads clustered together"); |
| 37 | |
Andrew Trick | e0ef509 | 2011-03-05 08:00:22 +0000 | [diff] [blame] | 38 | // This allows latency based scheduler to notice high latency instructions |
| 39 | // without a target itinerary. The choise if number here has more to do with |
| 40 | // balancing scheduler heursitics than with the actual machine latency. |
| 41 | static cl::opt<int> HighLatencyCycles( |
| 42 | "sched-high-latency-cycles", cl::Hidden, cl::init(10), |
| 43 | cl::desc("Roughly estimate the number of cycles that 'long latency'" |
| 44 | "instructions take for targets with no itinerary")); |
| 45 | |
Dan Gohman | 79ce276 | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 46 | ScheduleDAGSDNodes::ScheduleDAGSDNodes(MachineFunction &mf) |
Evan Cheng | 3ef1c87 | 2010-09-10 01:29:16 +0000 | [diff] [blame] | 47 | : ScheduleDAG(mf), |
| 48 | InstrItins(mf.getTarget().getInstrItineraryData()) {} |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 49 | |
Dan Gohman | 47ac0f0 | 2009-02-11 04:27:20 +0000 | [diff] [blame] | 50 | /// Run - perform scheduling. |
| 51 | /// |
| 52 | void ScheduleDAGSDNodes::Run(SelectionDAG *dag, MachineBasicBlock *bb, |
| 53 | MachineBasicBlock::iterator insertPos) { |
| 54 | DAG = dag; |
| 55 | ScheduleDAG::Run(bb, insertPos); |
| 56 | } |
| 57 | |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 58 | /// NewSUnit - Creates a new SUnit and return a ptr to it. |
| 59 | /// |
| 60 | SUnit *ScheduleDAGSDNodes::NewSUnit(SDNode *N) { |
| 61 | #ifndef NDEBUG |
| 62 | const SUnit *Addr = 0; |
| 63 | if (!SUnits.empty()) |
| 64 | Addr = &SUnits[0]; |
| 65 | #endif |
| 66 | SUnits.push_back(SUnit(N, (unsigned)SUnits.size())); |
| 67 | assert((Addr == 0 || Addr == &SUnits[0]) && |
| 68 | "SUnits std::vector reallocated on the fly!"); |
| 69 | SUnits.back().OrigNode = &SUnits.back(); |
| 70 | SUnit *SU = &SUnits.back(); |
| 71 | const TargetLowering &TLI = DAG->getTargetLoweringInfo(); |
Evan Cheng | c120af4 | 2010-08-10 02:39:45 +0000 | [diff] [blame] | 72 | if (!N || |
| 73 | (N->isMachineOpcode() && |
| 74 | N->getMachineOpcode() == TargetOpcode::IMPLICIT_DEF)) |
Evan Cheng | 046fa3f | 2010-05-28 23:26:21 +0000 | [diff] [blame] | 75 | SU->SchedulingPref = Sched::None; |
| 76 | else |
| 77 | SU->SchedulingPref = TLI.getSchedulingPreference(N); |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 78 | return SU; |
| 79 | } |
| 80 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 81 | SUnit *ScheduleDAGSDNodes::Clone(SUnit *Old) { |
| 82 | SUnit *SU = NewSUnit(Old->getNode()); |
| 83 | SU->OrigNode = Old->OrigNode; |
| 84 | SU->Latency = Old->Latency; |
Andrew Trick | 5469976 | 2011-04-07 19:54:57 +0000 | [diff] [blame] | 85 | SU->isVRegCycle = Old->isVRegCycle; |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 86 | SU->isCall = Old->isCall; |
Evan Cheng | 554daa6 | 2011-04-26 21:31:35 +0000 | [diff] [blame] | 87 | SU->isCallOp = Old->isCallOp; |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 88 | SU->isTwoAddress = Old->isTwoAddress; |
| 89 | SU->isCommutable = Old->isCommutable; |
| 90 | SU->hasPhysRegDefs = Old->hasPhysRegDefs; |
Dan Gohman | 3974667 | 2009-03-23 16:10:52 +0000 | [diff] [blame] | 91 | SU->hasPhysRegClobbers = Old->hasPhysRegClobbers; |
Andrew Trick | 12f0dc6 | 2011-04-14 05:15:06 +0000 | [diff] [blame] | 92 | SU->isScheduleHigh = Old->isScheduleHigh; |
| 93 | SU->isScheduleLow = Old->isScheduleLow; |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 94 | SU->SchedulingPref = Old->SchedulingPref; |
Evan Cheng | e57187c | 2009-01-16 20:57:18 +0000 | [diff] [blame] | 95 | Old->isCloned = true; |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 96 | return SU; |
| 97 | } |
| 98 | |
| 99 | /// CheckForPhysRegDependency - Check if the dependency between def and use of |
| 100 | /// a specified operand is a physical register dependency. If so, returns the |
Evan Cheng | c29a56d | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 101 | /// register and the cost of copying the register. |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 102 | static void CheckForPhysRegDependency(SDNode *Def, SDNode *User, unsigned Op, |
Andrew Trick | cd5af07 | 2011-02-03 23:00:17 +0000 | [diff] [blame] | 103 | const TargetRegisterInfo *TRI, |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 104 | const TargetInstrInfo *TII, |
Evan Cheng | c29a56d | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 105 | unsigned &PhysReg, int &Cost) { |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 106 | if (Op != 2 || User->getOpcode() != ISD::CopyToReg) |
| 107 | return; |
| 108 | |
| 109 | unsigned Reg = cast<RegisterSDNode>(User->getOperand(1))->getReg(); |
| 110 | if (TargetRegisterInfo::isVirtualRegister(Reg)) |
| 111 | return; |
| 112 | |
| 113 | unsigned ResNo = User->getOperand(2).getResNo(); |
| 114 | if (Def->isMachineOpcode()) { |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 115 | const MCInstrDesc &II = TII->get(Def->getMachineOpcode()); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 116 | if (ResNo >= II.getNumDefs() && |
Evan Cheng | c29a56d | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 117 | II.ImplicitDefs[ResNo - II.getNumDefs()] == Reg) { |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 118 | PhysReg = Reg; |
Evan Cheng | c29a56d | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 119 | const TargetRegisterClass *RC = |
Rafael Espindola | d31f972 | 2010-06-29 14:02:34 +0000 | [diff] [blame] | 120 | TRI->getMinimalPhysRegClass(Reg, Def->getValueType(ResNo)); |
Evan Cheng | c29a56d | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 121 | Cost = RC->getCopyCost(); |
| 122 | } |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 126 | static void AddGlue(SDNode *N, SDValue Glue, bool AddGlue, SelectionDAG *DAG) { |
Evan Cheng | c589e03 | 2010-01-22 03:36:51 +0000 | [diff] [blame] | 127 | SmallVector<EVT, 4> VTs; |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 128 | SDNode *GlueDestNode = Glue.getNode(); |
Bill Wendling | 151d26d | 2010-06-23 18:16:24 +0000 | [diff] [blame] | 129 | |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 130 | // Don't add glue from a node to itself. |
| 131 | if (GlueDestNode == N) return; |
Bill Wendling | 10707f3 | 2010-06-24 22:00:37 +0000 | [diff] [blame] | 132 | |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 133 | // Don't add glue to something which already has glue. |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 134 | if (N->getValueType(N->getNumValues() - 1) == MVT::Glue) return; |
Bill Wendling | 10707f3 | 2010-06-24 22:00:37 +0000 | [diff] [blame] | 135 | |
| 136 | for (unsigned I = 0, E = N->getNumValues(); I != E; ++I) |
| 137 | VTs.push_back(N->getValueType(I)); |
Bill Wendling | 151d26d | 2010-06-23 18:16:24 +0000 | [diff] [blame] | 138 | |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 139 | if (AddGlue) |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 140 | VTs.push_back(MVT::Glue); |
Bill Wendling | 151d26d | 2010-06-23 18:16:24 +0000 | [diff] [blame] | 141 | |
Evan Cheng | c589e03 | 2010-01-22 03:36:51 +0000 | [diff] [blame] | 142 | SmallVector<SDValue, 4> Ops; |
Bill Wendling | 10707f3 | 2010-06-24 22:00:37 +0000 | [diff] [blame] | 143 | for (unsigned I = 0, E = N->getNumOperands(); I != E; ++I) |
| 144 | Ops.push_back(N->getOperand(I)); |
Bill Wendling | 151d26d | 2010-06-23 18:16:24 +0000 | [diff] [blame] | 145 | |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 146 | if (GlueDestNode) |
| 147 | Ops.push_back(Glue); |
Bill Wendling | 151d26d | 2010-06-23 18:16:24 +0000 | [diff] [blame] | 148 | |
Evan Cheng | c589e03 | 2010-01-22 03:36:51 +0000 | [diff] [blame] | 149 | SDVTList VTList = DAG->getVTList(&VTs[0], VTs.size()); |
Bill Wendling | 151d26d | 2010-06-23 18:16:24 +0000 | [diff] [blame] | 150 | MachineSDNode::mmo_iterator Begin = 0, End = 0; |
| 151 | MachineSDNode *MN = dyn_cast<MachineSDNode>(N); |
| 152 | |
| 153 | // Store memory references. |
| 154 | if (MN) { |
| 155 | Begin = MN->memoperands_begin(); |
| 156 | End = MN->memoperands_end(); |
| 157 | } |
| 158 | |
Evan Cheng | c589e03 | 2010-01-22 03:36:51 +0000 | [diff] [blame] | 159 | DAG->MorphNodeTo(N, N->getOpcode(), VTList, &Ops[0], Ops.size()); |
Bill Wendling | 151d26d | 2010-06-23 18:16:24 +0000 | [diff] [blame] | 160 | |
| 161 | // Reset the memory references |
| 162 | if (MN) |
| 163 | MN->setMemRefs(Begin, End); |
Evan Cheng | c589e03 | 2010-01-22 03:36:51 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 166 | /// ClusterNeighboringLoads - Force nearby loads together by "gluing" them. |
Evan Cheng | c589e03 | 2010-01-22 03:36:51 +0000 | [diff] [blame] | 167 | /// This function finds loads of the same base and different offsets. If the |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 168 | /// offsets are not far apart (target specific), it add MVT::Glue inputs and |
Evan Cheng | c589e03 | 2010-01-22 03:36:51 +0000 | [diff] [blame] | 169 | /// outputs to ensure they are scheduled together and in order. This |
| 170 | /// optimization may benefit some targets by improving cache locality. |
Evan Cheng | 302ef83 | 2010-06-10 02:09:31 +0000 | [diff] [blame] | 171 | void ScheduleDAGSDNodes::ClusterNeighboringLoads(SDNode *Node) { |
| 172 | SDNode *Chain = 0; |
| 173 | unsigned NumOps = Node->getNumOperands(); |
| 174 | if (Node->getOperand(NumOps-1).getValueType() == MVT::Other) |
| 175 | Chain = Node->getOperand(NumOps-1).getNode(); |
| 176 | if (!Chain) |
| 177 | return; |
| 178 | |
| 179 | // Look for other loads of the same chain. Find loads that are loading from |
| 180 | // the same base pointer and different offsets. |
Evan Cheng | c589e03 | 2010-01-22 03:36:51 +0000 | [diff] [blame] | 181 | SmallPtrSet<SDNode*, 16> Visited; |
| 182 | SmallVector<int64_t, 4> Offsets; |
| 183 | DenseMap<long long, SDNode*> O2SMap; // Map from offset to SDNode. |
Evan Cheng | 302ef83 | 2010-06-10 02:09:31 +0000 | [diff] [blame] | 184 | bool Cluster = false; |
| 185 | SDNode *Base = Node; |
Evan Cheng | 302ef83 | 2010-06-10 02:09:31 +0000 | [diff] [blame] | 186 | for (SDNode::use_iterator I = Chain->use_begin(), E = Chain->use_end(); |
| 187 | I != E; ++I) { |
| 188 | SDNode *User = *I; |
| 189 | if (User == Node || !Visited.insert(User)) |
| 190 | continue; |
| 191 | int64_t Offset1, Offset2; |
| 192 | if (!TII->areLoadsFromSameBasePtr(Base, User, Offset1, Offset2) || |
| 193 | Offset1 == Offset2) |
| 194 | // FIXME: Should be ok if they addresses are identical. But earlier |
| 195 | // optimizations really should have eliminated one of the loads. |
| 196 | continue; |
| 197 | if (O2SMap.insert(std::make_pair(Offset1, Base)).second) |
| 198 | Offsets.push_back(Offset1); |
| 199 | O2SMap.insert(std::make_pair(Offset2, User)); |
| 200 | Offsets.push_back(Offset2); |
Duncan Sands | b447c4e | 2010-06-25 14:48:39 +0000 | [diff] [blame] | 201 | if (Offset2 < Offset1) |
Evan Cheng | 302ef83 | 2010-06-10 02:09:31 +0000 | [diff] [blame] | 202 | Base = User; |
Evan Cheng | 302ef83 | 2010-06-10 02:09:31 +0000 | [diff] [blame] | 203 | Cluster = true; |
| 204 | } |
| 205 | |
| 206 | if (!Cluster) |
| 207 | return; |
| 208 | |
| 209 | // Sort them in increasing order. |
| 210 | std::sort(Offsets.begin(), Offsets.end()); |
| 211 | |
| 212 | // Check if the loads are close enough. |
| 213 | SmallVector<SDNode*, 4> Loads; |
| 214 | unsigned NumLoads = 0; |
| 215 | int64_t BaseOff = Offsets[0]; |
| 216 | SDNode *BaseLoad = O2SMap[BaseOff]; |
| 217 | Loads.push_back(BaseLoad); |
| 218 | for (unsigned i = 1, e = Offsets.size(); i != e; ++i) { |
| 219 | int64_t Offset = Offsets[i]; |
| 220 | SDNode *Load = O2SMap[Offset]; |
| 221 | if (!TII->shouldScheduleLoadsNear(BaseLoad, Load, BaseOff, Offset,NumLoads)) |
| 222 | break; // Stop right here. Ignore loads that are further away. |
| 223 | Loads.push_back(Load); |
| 224 | ++NumLoads; |
| 225 | } |
| 226 | |
| 227 | if (NumLoads == 0) |
| 228 | return; |
| 229 | |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 230 | // Cluster loads by adding MVT::Glue outputs and inputs. This also |
Evan Cheng | 302ef83 | 2010-06-10 02:09:31 +0000 | [diff] [blame] | 231 | // ensure they are scheduled in order of increasing addresses. |
| 232 | SDNode *Lead = Loads[0]; |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 233 | AddGlue(Lead, SDValue(0, 0), true, DAG); |
Bill Wendling | 151d26d | 2010-06-23 18:16:24 +0000 | [diff] [blame] | 234 | |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 235 | SDValue InGlue = SDValue(Lead, Lead->getNumValues() - 1); |
Bill Wendling | 10707f3 | 2010-06-24 22:00:37 +0000 | [diff] [blame] | 236 | for (unsigned I = 1, E = Loads.size(); I != E; ++I) { |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 237 | bool OutGlue = I < E - 1; |
Bill Wendling | 10707f3 | 2010-06-24 22:00:37 +0000 | [diff] [blame] | 238 | SDNode *Load = Loads[I]; |
| 239 | |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 240 | AddGlue(Load, InGlue, OutGlue, DAG); |
Bill Wendling | 151d26d | 2010-06-23 18:16:24 +0000 | [diff] [blame] | 241 | |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 242 | if (OutGlue) |
| 243 | InGlue = SDValue(Load, Load->getNumValues() - 1); |
Bill Wendling | 151d26d | 2010-06-23 18:16:24 +0000 | [diff] [blame] | 244 | |
Evan Cheng | 302ef83 | 2010-06-10 02:09:31 +0000 | [diff] [blame] | 245 | ++LoadsClustered; |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | /// ClusterNodes - Cluster certain nodes which should be scheduled together. |
| 250 | /// |
| 251 | void ScheduleDAGSDNodes::ClusterNodes() { |
Evan Cheng | c589e03 | 2010-01-22 03:36:51 +0000 | [diff] [blame] | 252 | for (SelectionDAG::allnodes_iterator NI = DAG->allnodes_begin(), |
| 253 | E = DAG->allnodes_end(); NI != E; ++NI) { |
| 254 | SDNode *Node = &*NI; |
| 255 | if (!Node || !Node->isMachineOpcode()) |
| 256 | continue; |
| 257 | |
| 258 | unsigned Opc = Node->getMachineOpcode(); |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 259 | const MCInstrDesc &MCID = TII->get(Opc); |
| 260 | if (MCID.mayLoad()) |
Evan Cheng | 302ef83 | 2010-06-10 02:09:31 +0000 | [diff] [blame] | 261 | // Cluster loads from "near" addresses into combined SUnits. |
| 262 | ClusterNeighboringLoads(Node); |
Evan Cheng | c589e03 | 2010-01-22 03:36:51 +0000 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 266 | void ScheduleDAGSDNodes::BuildSchedUnits() { |
Dan Gohman | e1dfc7d | 2008-12-23 17:24:50 +0000 | [diff] [blame] | 267 | // During scheduling, the NodeId field of SDNode is used to map SDNodes |
| 268 | // to their associated SUnits by holding SUnits table indices. A value |
| 269 | // of -1 means the SDNode does not yet have an associated SUnit. |
| 270 | unsigned NumNodes = 0; |
| 271 | for (SelectionDAG::allnodes_iterator NI = DAG->allnodes_begin(), |
| 272 | E = DAG->allnodes_end(); NI != E; ++NI) { |
| 273 | NI->setNodeId(-1); |
| 274 | ++NumNodes; |
| 275 | } |
| 276 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 277 | // Reserve entries in the vector for each of the SUnits we are creating. This |
| 278 | // ensure that reallocation of the vector won't happen, so SUnit*'s won't get |
| 279 | // invalidated. |
Dan Gohman | 89b64bd | 2008-12-17 04:30:46 +0000 | [diff] [blame] | 280 | // FIXME: Multiply by 2 because we may clone nodes during scheduling. |
| 281 | // This is a temporary workaround. |
Dan Gohman | e1dfc7d | 2008-12-23 17:24:50 +0000 | [diff] [blame] | 282 | SUnits.reserve(NumNodes * 2); |
Andrew Trick | cd5af07 | 2011-02-03 23:00:17 +0000 | [diff] [blame] | 283 | |
Chris Lattner | 736a6ea | 2010-02-24 06:11:37 +0000 | [diff] [blame] | 284 | // Add all nodes in depth first order. |
| 285 | SmallVector<SDNode*, 64> Worklist; |
| 286 | SmallPtrSet<SDNode*, 64> Visited; |
| 287 | Worklist.push_back(DAG->getRoot().getNode()); |
| 288 | Visited.insert(DAG->getRoot().getNode()); |
Andrew Trick | cd5af07 | 2011-02-03 23:00:17 +0000 | [diff] [blame] | 289 | |
Evan Cheng | 554daa6 | 2011-04-26 21:31:35 +0000 | [diff] [blame] | 290 | SmallVector<SUnit*, 8> CallSUnits; |
Chris Lattner | 736a6ea | 2010-02-24 06:11:37 +0000 | [diff] [blame] | 291 | while (!Worklist.empty()) { |
| 292 | SDNode *NI = Worklist.pop_back_val(); |
Andrew Trick | cd5af07 | 2011-02-03 23:00:17 +0000 | [diff] [blame] | 293 | |
Chris Lattner | 736a6ea | 2010-02-24 06:11:37 +0000 | [diff] [blame] | 294 | // Add all operands to the worklist unless they've already been added. |
| 295 | for (unsigned i = 0, e = NI->getNumOperands(); i != e; ++i) |
| 296 | if (Visited.insert(NI->getOperand(i).getNode())) |
| 297 | Worklist.push_back(NI->getOperand(i).getNode()); |
Andrew Trick | cd5af07 | 2011-02-03 23:00:17 +0000 | [diff] [blame] | 298 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 299 | if (isPassiveNode(NI)) // Leaf node, e.g. a TargetImmediate. |
| 300 | continue; |
Andrew Trick | cd5af07 | 2011-02-03 23:00:17 +0000 | [diff] [blame] | 301 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 302 | // If this node has already been processed, stop now. |
| 303 | if (NI->getNodeId() != -1) continue; |
Andrew Trick | cd5af07 | 2011-02-03 23:00:17 +0000 | [diff] [blame] | 304 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 305 | SUnit *NodeSUnit = NewSUnit(NI); |
Andrew Trick | cd5af07 | 2011-02-03 23:00:17 +0000 | [diff] [blame] | 306 | |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 307 | // See if anything is glued to this node, if so, add them to glued |
| 308 | // nodes. Nodes can have at most one glue input and one glue output. Glue |
| 309 | // is required to be the last operand and result of a node. |
Andrew Trick | cd5af07 | 2011-02-03 23:00:17 +0000 | [diff] [blame] | 310 | |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 311 | // Scan up to find glued preds. |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 312 | SDNode *N = NI; |
Dan Gohman | db95fa1 | 2009-03-20 20:42:23 +0000 | [diff] [blame] | 313 | while (N->getNumOperands() && |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 314 | N->getOperand(N->getNumOperands()-1).getValueType() == MVT::Glue) { |
Dan Gohman | db95fa1 | 2009-03-20 20:42:23 +0000 | [diff] [blame] | 315 | N = N->getOperand(N->getNumOperands()-1).getNode(); |
| 316 | assert(N->getNodeId() == -1 && "Node already inserted!"); |
| 317 | N->setNodeId(NodeSUnit->NodeNum); |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 318 | if (N->isMachineOpcode() && TII->get(N->getMachineOpcode()).isCall()) |
| 319 | NodeSUnit->isCall = true; |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 320 | } |
Andrew Trick | cd5af07 | 2011-02-03 23:00:17 +0000 | [diff] [blame] | 321 | |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 322 | // Scan down to find any glued succs. |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 323 | N = NI; |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 324 | while (N->getValueType(N->getNumValues()-1) == MVT::Glue) { |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 325 | SDValue GlueVal(N, N->getNumValues()-1); |
Andrew Trick | cd5af07 | 2011-02-03 23:00:17 +0000 | [diff] [blame] | 326 | |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 327 | // There are either zero or one users of the Glue result. |
| 328 | bool HasGlueUse = false; |
Andrew Trick | cd5af07 | 2011-02-03 23:00:17 +0000 | [diff] [blame] | 329 | for (SDNode::use_iterator UI = N->use_begin(), E = N->use_end(); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 330 | UI != E; ++UI) |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 331 | if (GlueVal.isOperandOf(*UI)) { |
| 332 | HasGlueUse = true; |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 333 | assert(N->getNodeId() == -1 && "Node already inserted!"); |
| 334 | N->setNodeId(NodeSUnit->NodeNum); |
| 335 | N = *UI; |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 336 | if (N->isMachineOpcode() && TII->get(N->getMachineOpcode()).isCall()) |
| 337 | NodeSUnit->isCall = true; |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 338 | break; |
| 339 | } |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 340 | if (!HasGlueUse) break; |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 341 | } |
Andrew Trick | cd5af07 | 2011-02-03 23:00:17 +0000 | [diff] [blame] | 342 | |
Evan Cheng | 554daa6 | 2011-04-26 21:31:35 +0000 | [diff] [blame] | 343 | if (NodeSUnit->isCall) |
| 344 | CallSUnits.push_back(NodeSUnit); |
| 345 | |
Andrew Trick | 12f0dc6 | 2011-04-14 05:15:06 +0000 | [diff] [blame] | 346 | // Schedule zero-latency TokenFactor below any nodes that may increase the |
| 347 | // schedule height. Otherwise, ancestors of the TokenFactor may appear to |
| 348 | // have false stalls. |
| 349 | if (NI->getOpcode() == ISD::TokenFactor) |
| 350 | NodeSUnit->isScheduleLow = true; |
| 351 | |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 352 | // If there are glue operands involved, N is now the bottom-most node |
| 353 | // of the sequence of nodes that are glued together. |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 354 | // Update the SUnit. |
| 355 | NodeSUnit->setNode(N); |
| 356 | assert(N->getNodeId() == -1 && "Node already inserted!"); |
| 357 | N->setNodeId(NodeSUnit->NodeNum); |
| 358 | |
Andrew Trick | 92e9466 | 2011-02-04 03:18:17 +0000 | [diff] [blame] | 359 | // Compute NumRegDefsLeft. This must be done before AddSchedEdges. |
| 360 | InitNumRegDefsLeft(NodeSUnit); |
| 361 | |
Dan Gohman | 787782f | 2008-11-21 01:44:51 +0000 | [diff] [blame] | 362 | // Assign the Latency field of NodeSUnit using target-provided information. |
Evan Cheng | e163168 | 2010-05-19 22:42:23 +0000 | [diff] [blame] | 363 | ComputeLatency(NodeSUnit); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 364 | } |
Evan Cheng | 554daa6 | 2011-04-26 21:31:35 +0000 | [diff] [blame] | 365 | |
| 366 | // Find all call operands. |
| 367 | while (!CallSUnits.empty()) { |
| 368 | SUnit *SU = CallSUnits.pop_back_val(); |
| 369 | for (const SDNode *SUNode = SU->getNode(); SUNode; |
| 370 | SUNode = SUNode->getGluedNode()) { |
| 371 | if (SUNode->getOpcode() != ISD::CopyToReg) |
| 372 | continue; |
| 373 | SDNode *SrcN = SUNode->getOperand(2).getNode(); |
| 374 | if (isPassiveNode(SrcN)) continue; // Not scheduled. |
| 375 | SUnit *SrcSU = &SUnits[SrcN->getNodeId()]; |
| 376 | SrcSU->isCallOp = true; |
| 377 | } |
| 378 | } |
Dan Gohman | c9a5b9e | 2008-12-23 18:36:58 +0000 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | void ScheduleDAGSDNodes::AddSchedEdges() { |
Evan Cheng | 5b1b4489 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 382 | const TargetSubtargetInfo &ST = TM.getSubtarget<TargetSubtargetInfo>(); |
David Goodwin | 7104616 | 2009-08-13 16:05:04 +0000 | [diff] [blame] | 383 | |
David Goodwin | dc4bdcd | 2009-08-19 16:08:58 +0000 | [diff] [blame] | 384 | // Check to see if the scheduler cares about latencies. |
| 385 | bool UnitLatencies = ForceUnitLatencies(); |
| 386 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 387 | // Pass 2: add the preds, succs, etc. |
| 388 | for (unsigned su = 0, e = SUnits.size(); su != e; ++su) { |
| 389 | SUnit *SU = &SUnits[su]; |
| 390 | SDNode *MainNode = SU->getNode(); |
Andrew Trick | cd5af07 | 2011-02-03 23:00:17 +0000 | [diff] [blame] | 391 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 392 | if (MainNode->isMachineOpcode()) { |
| 393 | unsigned Opc = MainNode->getMachineOpcode(); |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 394 | const MCInstrDesc &MCID = TII->get(Opc); |
| 395 | for (unsigned i = 0; i != MCID.getNumOperands(); ++i) { |
| 396 | if (MCID.getOperandConstraint(i, MCOI::TIED_TO) != -1) { |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 397 | SU->isTwoAddress = true; |
| 398 | break; |
| 399 | } |
| 400 | } |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 401 | if (MCID.isCommutable()) |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 402 | SU->isCommutable = true; |
| 403 | } |
Andrew Trick | cd5af07 | 2011-02-03 23:00:17 +0000 | [diff] [blame] | 404 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 405 | // Find all predecessors and successors of the group. |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 406 | for (SDNode *N = SU->getNode(); N; N = N->getGluedNode()) { |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 407 | if (N->isMachineOpcode() && |
Dan Gohman | 3974667 | 2009-03-23 16:10:52 +0000 | [diff] [blame] | 408 | TII->get(N->getMachineOpcode()).getImplicitDefs()) { |
| 409 | SU->hasPhysRegClobbers = true; |
Dan Gohman | bcea859 | 2009-10-10 01:32:21 +0000 | [diff] [blame] | 410 | unsigned NumUsed = InstrEmitter::CountResults(N); |
Dan Gohman | 8cccf0e | 2009-03-23 17:39:36 +0000 | [diff] [blame] | 411 | while (NumUsed != 0 && !N->hasAnyUseOfValue(NumUsed - 1)) |
| 412 | --NumUsed; // Skip over unused values at the end. |
| 413 | if (NumUsed > TII->get(N->getMachineOpcode()).getNumDefs()) |
Dan Gohman | 3974667 | 2009-03-23 16:10:52 +0000 | [diff] [blame] | 414 | SU->hasPhysRegDefs = true; |
| 415 | } |
Andrew Trick | cd5af07 | 2011-02-03 23:00:17 +0000 | [diff] [blame] | 416 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 417 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
| 418 | SDNode *OpN = N->getOperand(i).getNode(); |
| 419 | if (isPassiveNode(OpN)) continue; // Not scheduled. |
| 420 | SUnit *OpSU = &SUnits[OpN->getNodeId()]; |
| 421 | assert(OpSU && "Node has no SUnit!"); |
| 422 | if (OpSU == SU) continue; // In the same group. |
| 423 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 424 | EVT OpVT = N->getOperand(i).getValueType(); |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 425 | assert(OpVT != MVT::Glue && "Glued nodes should be in same sunit!"); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 426 | bool isChain = OpVT == MVT::Other; |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 427 | |
| 428 | unsigned PhysReg = 0; |
Evan Cheng | c29a56d | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 429 | int Cost = 1; |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 430 | // Determine if this is a physical register dependency. |
Evan Cheng | c29a56d | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 431 | CheckForPhysRegDependency(OpN, N, i, TRI, TII, PhysReg, Cost); |
Dan Gohman | 54e4c36 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 432 | assert((PhysReg == 0 || !isChain) && |
| 433 | "Chain dependence via physreg data?"); |
Evan Cheng | c29a56d | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 434 | // FIXME: See ScheduleDAGSDNodes::EmitCopyFromReg. For now, scheduler |
| 435 | // emits a copy from the physical register to a virtual register unless |
| 436 | // it requires a cross class copy (cost < 0). That means we are only |
| 437 | // treating "expensive to copy" register dependency as physical register |
| 438 | // dependency. This may change in the future though. |
Andrew Trick | 4cb971c | 2011-06-15 17:16:12 +0000 | [diff] [blame] | 439 | if (Cost >= 0 && !StressSched) |
Evan Cheng | c29a56d | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 440 | PhysReg = 0; |
David Goodwin | 7104616 | 2009-08-13 16:05:04 +0000 | [diff] [blame] | 441 | |
Evan Cheng | 046fa3f | 2010-05-28 23:26:21 +0000 | [diff] [blame] | 442 | // If this is a ctrl dep, latency is 1. |
Andrew Trick | c558bf3 | 2011-04-12 20:14:07 +0000 | [diff] [blame] | 443 | unsigned OpLatency = isChain ? 1 : OpSU->Latency; |
Andrew Trick | 87896d9 | 2011-04-13 00:38:32 +0000 | [diff] [blame] | 444 | // Special-case TokenFactor chains as zero-latency. |
| 445 | if(isChain && OpN->getOpcode() == ISD::TokenFactor) |
| 446 | OpLatency = 0; |
| 447 | |
Evan Cheng | 046fa3f | 2010-05-28 23:26:21 +0000 | [diff] [blame] | 448 | const SDep &dep = SDep(OpSU, isChain ? SDep::Order : SDep::Data, |
| 449 | OpLatency, PhysReg); |
David Goodwin | dc4bdcd | 2009-08-19 16:08:58 +0000 | [diff] [blame] | 450 | if (!isChain && !UnitLatencies) { |
Evan Cheng | 15a16de | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 451 | ComputeOperandLatency(OpN, N, i, const_cast<SDep &>(dep)); |
Dan Gohman | 3fb150a | 2010-04-17 17:42:52 +0000 | [diff] [blame] | 452 | ST.adjustSchedDependency(OpSU, SU, const_cast<SDep &>(dep)); |
David Goodwin | dc4bdcd | 2009-08-19 16:08:58 +0000 | [diff] [blame] | 453 | } |
David Goodwin | 7104616 | 2009-08-13 16:05:04 +0000 | [diff] [blame] | 454 | |
Andrew Trick | 4bbf467 | 2011-03-09 19:12:43 +0000 | [diff] [blame] | 455 | if (!SU->addPred(dep) && !dep.isCtrl() && OpSU->NumRegDefsLeft > 1) { |
Andrew Trick | 92e9466 | 2011-02-04 03:18:17 +0000 | [diff] [blame] | 456 | // Multiple register uses are combined in the same SUnit. For example, |
| 457 | // we could have a set of glued nodes with all their defs consumed by |
| 458 | // another set of glued nodes. Register pressure tracking sees this as |
| 459 | // a single use, so to keep pressure balanced we reduce the defs. |
Andrew Trick | 4bbf467 | 2011-03-09 19:12:43 +0000 | [diff] [blame] | 460 | // |
| 461 | // We can't tell (without more book-keeping) if this results from |
| 462 | // glued nodes or duplicate operands. As long as we don't reduce |
| 463 | // NumRegDefsLeft to zero, we handle the common cases well. |
Andrew Trick | 92e9466 | 2011-02-04 03:18:17 +0000 | [diff] [blame] | 464 | --OpSU->NumRegDefsLeft; |
| 465 | } |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 466 | } |
| 467 | } |
| 468 | } |
| 469 | } |
| 470 | |
Dan Gohman | c9a5b9e | 2008-12-23 18:36:58 +0000 | [diff] [blame] | 471 | /// BuildSchedGraph - Build the SUnit graph from the selection dag that we |
| 472 | /// are input. This SUnit graph is similar to the SelectionDAG, but |
| 473 | /// excludes nodes that aren't interesting to scheduling, and represents |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 474 | /// glued together nodes with a single SUnit. |
Dan Gohman | 98976e4 | 2009-10-09 23:33:48 +0000 | [diff] [blame] | 475 | void ScheduleDAGSDNodes::BuildSchedGraph(AliasAnalysis *AA) { |
Evan Cheng | 302ef83 | 2010-06-10 02:09:31 +0000 | [diff] [blame] | 476 | // Cluster certain nodes which should be scheduled together. |
| 477 | ClusterNodes(); |
Dan Gohman | c9a5b9e | 2008-12-23 18:36:58 +0000 | [diff] [blame] | 478 | // Populate the SUnits array. |
| 479 | BuildSchedUnits(); |
| 480 | // Compute all the scheduling dependencies between nodes. |
| 481 | AddSchedEdges(); |
| 482 | } |
| 483 | |
Andrew Trick | 92e9466 | 2011-02-04 03:18:17 +0000 | [diff] [blame] | 484 | // Initialize NumNodeDefs for the current Node's opcode. |
| 485 | void ScheduleDAGSDNodes::RegDefIter::InitNodeNumDefs() { |
Eric Christopher | 2944944 | 2011-03-08 19:35:47 +0000 | [diff] [blame] | 486 | // Check for phys reg copy. |
| 487 | if (!Node) |
| 488 | return; |
| 489 | |
Andrew Trick | 92e9466 | 2011-02-04 03:18:17 +0000 | [diff] [blame] | 490 | if (!Node->isMachineOpcode()) { |
| 491 | if (Node->getOpcode() == ISD::CopyFromReg) |
| 492 | NodeNumDefs = 1; |
| 493 | else |
| 494 | NodeNumDefs = 0; |
| 495 | return; |
| 496 | } |
| 497 | unsigned POpc = Node->getMachineOpcode(); |
| 498 | if (POpc == TargetOpcode::IMPLICIT_DEF) { |
| 499 | // No register need be allocated for this. |
| 500 | NodeNumDefs = 0; |
| 501 | return; |
| 502 | } |
| 503 | unsigned NRegDefs = SchedDAG->TII->get(Node->getMachineOpcode()).getNumDefs(); |
| 504 | // Some instructions define regs that are not represented in the selection DAG |
| 505 | // (e.g. unused flags). See tMOVi8. Make sure we don't access past NumValues. |
| 506 | NodeNumDefs = std::min(Node->getNumValues(), NRegDefs); |
| 507 | DefIdx = 0; |
| 508 | } |
| 509 | |
| 510 | // Construct a RegDefIter for this SUnit and find the first valid value. |
| 511 | ScheduleDAGSDNodes::RegDefIter::RegDefIter(const SUnit *SU, |
| 512 | const ScheduleDAGSDNodes *SD) |
| 513 | : SchedDAG(SD), Node(SU->getNode()), DefIdx(0), NodeNumDefs(0) { |
| 514 | InitNodeNumDefs(); |
| 515 | Advance(); |
| 516 | } |
| 517 | |
| 518 | // Advance to the next valid value defined by the SUnit. |
| 519 | void ScheduleDAGSDNodes::RegDefIter::Advance() { |
| 520 | for (;Node;) { // Visit all glued nodes. |
| 521 | for (;DefIdx < NodeNumDefs; ++DefIdx) { |
| 522 | if (!Node->hasAnyUseOfValue(DefIdx)) |
| 523 | continue; |
Andrew Trick | 4ef4c17 | 2011-06-27 18:01:20 +0000 | [diff] [blame] | 524 | ValueType = Node->getValueType(DefIdx); |
Andrew Trick | 92e9466 | 2011-02-04 03:18:17 +0000 | [diff] [blame] | 525 | ++DefIdx; |
| 526 | return; // Found a normal regdef. |
| 527 | } |
| 528 | Node = Node->getGluedNode(); |
| 529 | if (Node == NULL) { |
| 530 | return; // No values left to visit. |
| 531 | } |
| 532 | InitNodeNumDefs(); |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | void ScheduleDAGSDNodes::InitNumRegDefsLeft(SUnit *SU) { |
| 537 | assert(SU->NumRegDefsLeft == 0 && "expect a new node"); |
| 538 | for (RegDefIter I(SU, this); I.IsValid(); I.Advance()) { |
| 539 | assert(SU->NumRegDefsLeft < USHRT_MAX && "overflow is ok but unexpected"); |
| 540 | ++SU->NumRegDefsLeft; |
| 541 | } |
| 542 | } |
| 543 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 544 | void ScheduleDAGSDNodes::ComputeLatency(SUnit *SU) { |
Andrew Trick | 87896d9 | 2011-04-13 00:38:32 +0000 | [diff] [blame] | 545 | SDNode *N = SU->getNode(); |
| 546 | |
| 547 | // TokenFactor operands are considered zero latency, and some schedulers |
| 548 | // (e.g. Top-Down list) may rely on the fact that operand latency is nonzero |
| 549 | // whenever node latency is nonzero. |
| 550 | if (N && N->getOpcode() == ISD::TokenFactor) { |
| 551 | SU->Latency = 0; |
| 552 | return; |
| 553 | } |
| 554 | |
Evan Cheng | e163168 | 2010-05-19 22:42:23 +0000 | [diff] [blame] | 555 | // Check to see if the scheduler cares about latencies. |
| 556 | if (ForceUnitLatencies()) { |
| 557 | SU->Latency = 1; |
| 558 | return; |
| 559 | } |
| 560 | |
Evan Cheng | 3ef1c87 | 2010-09-10 01:29:16 +0000 | [diff] [blame] | 561 | if (!InstrItins || InstrItins->isEmpty()) { |
Andrew Trick | 5e84e3c | 2011-03-05 09:18:16 +0000 | [diff] [blame] | 562 | if (N && N->isMachineOpcode() && |
| 563 | TII->isHighLatencyDef(N->getMachineOpcode())) |
Andrew Trick | e0ef509 | 2011-03-05 08:00:22 +0000 | [diff] [blame] | 564 | SU->Latency = HighLatencyCycles; |
| 565 | else |
| 566 | SU->Latency = 1; |
Evan Cheng | 15a16de | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 567 | return; |
| 568 | } |
Andrew Trick | cd5af07 | 2011-02-03 23:00:17 +0000 | [diff] [blame] | 569 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 570 | // Compute the latency for the node. We use the sum of the latencies for |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 571 | // all nodes glued together into this SUnit. |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 572 | SU->Latency = 0; |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 573 | for (SDNode *N = SU->getNode(); N; N = N->getGluedNode()) |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 574 | if (N->isMachineOpcode()) |
| 575 | SU->Latency += TII->getInstrLatency(InstrItins, N); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 576 | } |
| 577 | |
Evan Cheng | 15a16de | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 578 | void ScheduleDAGSDNodes::ComputeOperandLatency(SDNode *Def, SDNode *Use, |
| 579 | unsigned OpIdx, SDep& dep) const{ |
| 580 | // Check to see if the scheduler cares about latencies. |
| 581 | if (ForceUnitLatencies()) |
| 582 | return; |
| 583 | |
Evan Cheng | 15a16de | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 584 | if (dep.getKind() != SDep::Data) |
| 585 | return; |
| 586 | |
| 587 | unsigned DefIdx = Use->getOperand(OpIdx).getResNo(); |
Evan Cheng | 7e2fe91 | 2010-10-28 06:47:08 +0000 | [diff] [blame] | 588 | if (Use->isMachineOpcode()) |
| 589 | // Adjust the use operand index by num of defs. |
| 590 | OpIdx += TII->get(Use->getMachineOpcode()).getNumDefs(); |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 591 | int Latency = TII->getOperandLatency(InstrItins, Def, DefIdx, Use, OpIdx); |
Evan Cheng | 0897515 | 2010-10-29 18:09:28 +0000 | [diff] [blame] | 592 | if (Latency > 1 && Use->getOpcode() == ISD::CopyToReg && |
| 593 | !BB->succ_empty()) { |
| 594 | unsigned Reg = cast<RegisterSDNode>(Use->getOperand(1))->getReg(); |
| 595 | if (TargetRegisterInfo::isVirtualRegister(Reg)) |
| 596 | // This copy is a liveout value. It is likely coalesced, so reduce the |
| 597 | // latency so not to penalize the def. |
| 598 | // FIXME: need target specific adjustment here? |
| 599 | Latency = (Latency > 1) ? Latency - 1 : 1; |
| 600 | } |
Evan Cheng | 3881cb7 | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 601 | if (Latency >= 0) |
| 602 | dep.setLatency(Latency); |
Evan Cheng | 15a16de | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 603 | } |
| 604 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 605 | void ScheduleDAGSDNodes::dumpNode(const SUnit *SU) const { |
Evan Cheng | c29a56d | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 606 | if (!SU->getNode()) { |
David Greene | 84fa822 | 2010-01-05 01:25:11 +0000 | [diff] [blame] | 607 | dbgs() << "PHYS REG COPY\n"; |
Evan Cheng | c29a56d | 2009-01-12 03:19:55 +0000 | [diff] [blame] | 608 | return; |
| 609 | } |
| 610 | |
| 611 | SU->getNode()->dump(DAG); |
David Greene | 84fa822 | 2010-01-05 01:25:11 +0000 | [diff] [blame] | 612 | dbgs() << "\n"; |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 613 | SmallVector<SDNode *, 4> GluedNodes; |
| 614 | for (SDNode *N = SU->getNode()->getGluedNode(); N; N = N->getGluedNode()) |
| 615 | GluedNodes.push_back(N); |
| 616 | while (!GluedNodes.empty()) { |
David Greene | 84fa822 | 2010-01-05 01:25:11 +0000 | [diff] [blame] | 617 | dbgs() << " "; |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 618 | GluedNodes.back()->dump(DAG); |
David Greene | 84fa822 | 2010-01-05 01:25:11 +0000 | [diff] [blame] | 619 | dbgs() << "\n"; |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 620 | GluedNodes.pop_back(); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 621 | } |
| 622 | } |
Dan Gohman | bcea859 | 2009-10-10 01:32:21 +0000 | [diff] [blame] | 623 | |
Andrew Trick | 73ba69b | 2012-03-07 05:21:40 +0000 | [diff] [blame^] | 624 | void ScheduleDAGSDNodes::dumpSchedule() const { |
| 625 | for (unsigned i = 0, e = Sequence.size(); i != e; i++) { |
| 626 | if (SUnit *SU = Sequence[i]) |
| 627 | SU->dump(this); |
| 628 | else |
| 629 | dbgs() << "**** NOOP ****\n"; |
| 630 | } |
| 631 | } |
| 632 | |
Andrew Trick | 4c72720 | 2012-03-07 05:21:36 +0000 | [diff] [blame] | 633 | #ifndef NDEBUG |
| 634 | /// VerifyScheduledSequence - Verify that all SUnits were scheduled and that |
| 635 | /// their state is consistent with the nodes listed in Sequence. |
| 636 | /// |
| 637 | void ScheduleDAGSDNodes::VerifyScheduledSequence(bool isBottomUp) { |
| 638 | unsigned ScheduledNodes = ScheduleDAG::VerifyScheduledDAG(isBottomUp); |
| 639 | unsigned Noops = 0; |
| 640 | for (unsigned i = 0, e = Sequence.size(); i != e; ++i) |
| 641 | if (!Sequence[i]) |
| 642 | ++Noops; |
| 643 | assert(Sequence.size() - Noops == ScheduledNodes && |
| 644 | "The number of nodes scheduled doesn't match the expected number!"); |
| 645 | } |
| 646 | #endif // NDEBUG |
| 647 | |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 648 | namespace { |
| 649 | struct OrderSorter { |
| 650 | bool operator()(const std::pair<unsigned, MachineInstr*> &A, |
| 651 | const std::pair<unsigned, MachineInstr*> &B) { |
| 652 | return A.first < B.first; |
| 653 | } |
| 654 | }; |
| 655 | } |
| 656 | |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 657 | /// ProcessSDDbgValues - Process SDDbgValues associated with this node. |
Andrew Trick | cd5af07 | 2011-02-03 23:00:17 +0000 | [diff] [blame] | 658 | static void ProcessSDDbgValues(SDNode *N, SelectionDAG *DAG, |
Devang Patel | 55d20e8 | 2011-01-26 18:20:04 +0000 | [diff] [blame] | 659 | InstrEmitter &Emitter, |
| 660 | SmallVector<std::pair<unsigned, MachineInstr*>, 32> &Orders, |
| 661 | DenseMap<SDValue, unsigned> &VRBaseMap, |
| 662 | unsigned Order) { |
| 663 | if (!N->getHasDebugValue()) |
| 664 | return; |
| 665 | |
| 666 | // Opportunistically insert immediate dbg_value uses, i.e. those with source |
| 667 | // order number right after the N. |
| 668 | MachineBasicBlock *BB = Emitter.getBlock(); |
| 669 | MachineBasicBlock::iterator InsertPos = Emitter.getInsertPos(); |
Benjamin Kramer | 22a54c1 | 2011-06-18 13:13:44 +0000 | [diff] [blame] | 670 | ArrayRef<SDDbgValue*> DVs = DAG->GetDbgValues(N); |
Devang Patel | 55d20e8 | 2011-01-26 18:20:04 +0000 | [diff] [blame] | 671 | for (unsigned i = 0, e = DVs.size(); i != e; ++i) { |
| 672 | if (DVs[i]->isInvalidated()) |
| 673 | continue; |
| 674 | unsigned DVOrder = DVs[i]->getOrder(); |
| 675 | if (!Order || DVOrder == ++Order) { |
| 676 | MachineInstr *DbgMI = Emitter.EmitDbgValue(DVs[i], VRBaseMap); |
| 677 | if (DbgMI) { |
| 678 | Orders.push_back(std::make_pair(DVOrder, DbgMI)); |
| 679 | BB->insert(InsertPos, DbgMI); |
| 680 | } |
| 681 | DVs[i]->setIsInvalidated(); |
| 682 | } |
| 683 | } |
| 684 | } |
| 685 | |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 686 | // ProcessSourceNode - Process nodes with source order numbers. These are added |
Jim Grosbach | d27946d | 2010-06-30 21:27:56 +0000 | [diff] [blame] | 687 | // to a vector which EmitSchedule uses to determine how to insert dbg_value |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 688 | // instructions in the right order. |
| 689 | static void ProcessSourceNode(SDNode *N, SelectionDAG *DAG, |
| 690 | InstrEmitter &Emitter, |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 691 | DenseMap<SDValue, unsigned> &VRBaseMap, |
| 692 | SmallVector<std::pair<unsigned, MachineInstr*>, 32> &Orders, |
| 693 | SmallSet<unsigned, 8> &Seen) { |
| 694 | unsigned Order = DAG->GetOrdering(N); |
Devang Patel | 39078a8 | 2011-01-27 00:13:27 +0000 | [diff] [blame] | 695 | if (!Order || !Seen.insert(Order)) { |
| 696 | // Process any valid SDDbgValues even if node does not have any order |
| 697 | // assigned. |
| 698 | ProcessSDDbgValues(N, DAG, Emitter, Orders, VRBaseMap, 0); |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 699 | return; |
Devang Patel | 39078a8 | 2011-01-27 00:13:27 +0000 | [diff] [blame] | 700 | } |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 701 | |
| 702 | MachineBasicBlock *BB = Emitter.getBlock(); |
Dan Gohman | 84023e0 | 2010-07-10 09:00:22 +0000 | [diff] [blame] | 703 | if (Emitter.getInsertPos() == BB->begin() || BB->back().isPHI()) { |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 704 | // Did not insert any instruction. |
| 705 | Orders.push_back(std::make_pair(Order, (MachineInstr*)0)); |
| 706 | return; |
| 707 | } |
| 708 | |
Dan Gohman | 84023e0 | 2010-07-10 09:00:22 +0000 | [diff] [blame] | 709 | Orders.push_back(std::make_pair(Order, prior(Emitter.getInsertPos()))); |
Devang Patel | 55d20e8 | 2011-01-26 18:20:04 +0000 | [diff] [blame] | 710 | ProcessSDDbgValues(N, DAG, Emitter, Orders, VRBaseMap, Order); |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | |
Dan Gohman | bcea859 | 2009-10-10 01:32:21 +0000 | [diff] [blame] | 714 | /// EmitSchedule - Emit the machine code in scheduled order. |
Dan Gohman | af1d8ca | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 715 | MachineBasicBlock *ScheduleDAGSDNodes::EmitSchedule() { |
Dan Gohman | bcea859 | 2009-10-10 01:32:21 +0000 | [diff] [blame] | 716 | InstrEmitter Emitter(BB, InsertPos); |
| 717 | DenseMap<SDValue, unsigned> VRBaseMap; |
| 718 | DenseMap<SUnit*, unsigned> CopyVRBaseMap; |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 719 | SmallVector<std::pair<unsigned, MachineInstr*>, 32> Orders; |
| 720 | SmallSet<unsigned, 8> Seen; |
| 721 | bool HasDbg = DAG->hasDebugValues(); |
Dale Johannesen | bfdf7f3 | 2010-03-10 22:13:47 +0000 | [diff] [blame] | 722 | |
Dale Johannesen | fdb42fa | 2010-04-26 20:06:49 +0000 | [diff] [blame] | 723 | // If this is the first BB, emit byval parameter dbg_value's. |
| 724 | if (HasDbg && BB->getParent()->begin() == MachineFunction::iterator(BB)) { |
| 725 | SDDbgInfo::DbgIterator PDI = DAG->ByvalParmDbgBegin(); |
| 726 | SDDbgInfo::DbgIterator PDE = DAG->ByvalParmDbgEnd(); |
| 727 | for (; PDI != PDE; ++PDI) { |
Dan Gohman | 891ff8f | 2010-04-30 19:35:33 +0000 | [diff] [blame] | 728 | MachineInstr *DbgMI= Emitter.EmitDbgValue(*PDI, VRBaseMap); |
Dale Johannesen | fdb42fa | 2010-04-26 20:06:49 +0000 | [diff] [blame] | 729 | if (DbgMI) |
Dan Gohman | 84023e0 | 2010-07-10 09:00:22 +0000 | [diff] [blame] | 730 | BB->insert(InsertPos, DbgMI); |
Dale Johannesen | fdb42fa | 2010-04-26 20:06:49 +0000 | [diff] [blame] | 731 | } |
| 732 | } |
| 733 | |
Dan Gohman | bcea859 | 2009-10-10 01:32:21 +0000 | [diff] [blame] | 734 | for (unsigned i = 0, e = Sequence.size(); i != e; i++) { |
| 735 | SUnit *SU = Sequence[i]; |
| 736 | if (!SU) { |
| 737 | // Null SUnit* is a noop. |
| 738 | EmitNoop(); |
| 739 | continue; |
| 740 | } |
| 741 | |
| 742 | // For pre-regalloc scheduling, create instructions corresponding to the |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 743 | // SDNode and any glued SDNodes and append them to the block. |
Dan Gohman | bcea859 | 2009-10-10 01:32:21 +0000 | [diff] [blame] | 744 | if (!SU->getNode()) { |
| 745 | // Emit a copy. |
| 746 | EmitPhysRegCopy(SU, CopyVRBaseMap); |
| 747 | continue; |
| 748 | } |
| 749 | |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 750 | SmallVector<SDNode *, 4> GluedNodes; |
| 751 | for (SDNode *N = SU->getNode()->getGluedNode(); N; |
| 752 | N = N->getGluedNode()) |
| 753 | GluedNodes.push_back(N); |
| 754 | while (!GluedNodes.empty()) { |
| 755 | SDNode *N = GluedNodes.back(); |
| 756 | Emitter.EmitNode(GluedNodes.back(), SU->OrigNode != SU, SU->isCloned, |
Dan Gohman | af1d8ca | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 757 | VRBaseMap); |
Dale Johannesen | fdb42fa | 2010-04-26 20:06:49 +0000 | [diff] [blame] | 758 | // Remember the source order of the inserted instruction. |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 759 | if (HasDbg) |
Dan Gohman | 891ff8f | 2010-04-30 19:35:33 +0000 | [diff] [blame] | 760 | ProcessSourceNode(N, DAG, Emitter, VRBaseMap, Orders, Seen); |
Chris Lattner | 29d8f0c | 2010-12-23 17:24:32 +0000 | [diff] [blame] | 761 | GluedNodes.pop_back(); |
Dan Gohman | bcea859 | 2009-10-10 01:32:21 +0000 | [diff] [blame] | 762 | } |
| 763 | Emitter.EmitNode(SU->getNode(), SU->OrigNode != SU, SU->isCloned, |
Dan Gohman | af1d8ca | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 764 | VRBaseMap); |
Dale Johannesen | fdb42fa | 2010-04-26 20:06:49 +0000 | [diff] [blame] | 765 | // Remember the source order of the inserted instruction. |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 766 | if (HasDbg) |
Dan Gohman | 891ff8f | 2010-04-30 19:35:33 +0000 | [diff] [blame] | 767 | ProcessSourceNode(SU->getNode(), DAG, Emitter, VRBaseMap, Orders, |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 768 | Seen); |
| 769 | } |
| 770 | |
Dale Johannesen | fdb42fa | 2010-04-26 20:06:49 +0000 | [diff] [blame] | 771 | // Insert all the dbg_values which have not already been inserted in source |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 772 | // order sequence. |
| 773 | if (HasDbg) { |
Dan Gohman | 84023e0 | 2010-07-10 09:00:22 +0000 | [diff] [blame] | 774 | MachineBasicBlock::iterator BBBegin = BB->getFirstNonPHI(); |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 775 | |
| 776 | // Sort the source order instructions and use the order to insert debug |
| 777 | // values. |
| 778 | std::sort(Orders.begin(), Orders.end(), OrderSorter()); |
| 779 | |
| 780 | SDDbgInfo::DbgIterator DI = DAG->DbgBegin(); |
| 781 | SDDbgInfo::DbgIterator DE = DAG->DbgEnd(); |
| 782 | // Now emit the rest according to source order. |
| 783 | unsigned LastOrder = 0; |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 784 | for (unsigned i = 0, e = Orders.size(); i != e && DI != DE; ++i) { |
| 785 | unsigned Order = Orders[i].first; |
| 786 | MachineInstr *MI = Orders[i].second; |
| 787 | // Insert all SDDbgValue's whose order(s) are before "Order". |
| 788 | if (!MI) |
| 789 | continue; |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 790 | for (; DI != DE && |
| 791 | (*DI)->getOrder() >= LastOrder && (*DI)->getOrder() < Order; ++DI) { |
| 792 | if ((*DI)->isInvalidated()) |
| 793 | continue; |
Dan Gohman | 891ff8f | 2010-04-30 19:35:33 +0000 | [diff] [blame] | 794 | MachineInstr *DbgMI = Emitter.EmitDbgValue(*DI, VRBaseMap); |
Evan Cheng | 962021b | 2010-04-26 07:38:55 +0000 | [diff] [blame] | 795 | if (DbgMI) { |
| 796 | if (!LastOrder) |
| 797 | // Insert to start of the BB (after PHIs). |
| 798 | BB->insert(BBBegin, DbgMI); |
| 799 | else { |
Dan Gohman | a8dab36 | 2010-07-10 22:42:31 +0000 | [diff] [blame] | 800 | // Insert at the instruction, which may be in a different |
| 801 | // block, if the block was split by a custom inserter. |
Evan Cheng | 962021b | 2010-04-26 07:38:55 +0000 | [diff] [blame] | 802 | MachineBasicBlock::iterator Pos = MI; |
Dan Gohman | a8dab36 | 2010-07-10 22:42:31 +0000 | [diff] [blame] | 803 | MI->getParent()->insert(llvm::next(Pos), DbgMI); |
Evan Cheng | 962021b | 2010-04-26 07:38:55 +0000 | [diff] [blame] | 804 | } |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 805 | } |
Dale Johannesen | bfdf7f3 | 2010-03-10 22:13:47 +0000 | [diff] [blame] | 806 | } |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 807 | LastOrder = Order; |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 808 | } |
| 809 | // Add trailing DbgValue's before the terminator. FIXME: May want to add |
| 810 | // some of them before one or more conditional branches? |
| 811 | while (DI != DE) { |
| 812 | MachineBasicBlock *InsertBB = Emitter.getBlock(); |
| 813 | MachineBasicBlock::iterator Pos= Emitter.getBlock()->getFirstTerminator(); |
| 814 | if (!(*DI)->isInvalidated()) { |
Dan Gohman | 891ff8f | 2010-04-30 19:35:33 +0000 | [diff] [blame] | 815 | MachineInstr *DbgMI= Emitter.EmitDbgValue(*DI, VRBaseMap); |
Evan Cheng | 962021b | 2010-04-26 07:38:55 +0000 | [diff] [blame] | 816 | if (DbgMI) |
| 817 | InsertBB->insert(Pos, DbgMI); |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 818 | } |
| 819 | ++DI; |
| 820 | } |
Dan Gohman | bcea859 | 2009-10-10 01:32:21 +0000 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | BB = Emitter.getBlock(); |
| 824 | InsertPos = Emitter.getInsertPos(); |
| 825 | return BB; |
| 826 | } |
Andrew Trick | 56b94c5 | 2012-03-07 00:18:22 +0000 | [diff] [blame] | 827 | |
| 828 | /// Return the basic block label. |
| 829 | std::string ScheduleDAGSDNodes::getDAGName() const { |
| 830 | return "sunit-dag." + BB->getFullName(); |
| 831 | } |