blob: 477c1ffe65d3daf4d5e78d23f4a32e1232bd7cfe [file] [log] [blame]
Dan Gohman343f0c02008-11-19 23:18:57 +00001//===--- 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 Chenga8efe282010-03-14 19:56:39 +000016#include "SDNodeDbgValue.h"
Dan Gohman84fbac52009-02-06 17:22:58 +000017#include "ScheduleDAGSDNodes.h"
Dan Gohmanbcea8592009-10-10 01:32:21 +000018#include "InstrEmitter.h"
Dan Gohman343f0c02008-11-19 23:18:57 +000019#include "llvm/CodeGen/SelectionDAG.h"
20#include "llvm/Target/TargetMachine.h"
21#include "llvm/Target/TargetInstrInfo.h"
Evan Cheng1cc39842010-05-20 23:26:43 +000022#include "llvm/Target/TargetLowering.h"
Dan Gohman343f0c02008-11-19 23:18:57 +000023#include "llvm/Target/TargetRegisterInfo.h"
David Goodwin71046162009-08-13 16:05:04 +000024#include "llvm/Target/TargetSubtarget.h"
Evan Chengc589e032010-01-22 03:36:51 +000025#include "llvm/ADT/DenseMap.h"
26#include "llvm/ADT/SmallPtrSet.h"
Evan Chengbfcb3052010-03-25 01:38:16 +000027#include "llvm/ADT/SmallSet.h"
Evan Chengc589e032010-01-22 03:36:51 +000028#include "llvm/ADT/SmallVector.h"
29#include "llvm/ADT/Statistic.h"
Dan Gohman343f0c02008-11-19 23:18:57 +000030#include "llvm/Support/Debug.h"
31#include "llvm/Support/raw_ostream.h"
32using namespace llvm;
33
Evan Chengc589e032010-01-22 03:36:51 +000034STATISTIC(LoadsClustered, "Number of loads clustered together");
35
Dan Gohman79ce2762009-01-15 19:20:50 +000036ScheduleDAGSDNodes::ScheduleDAGSDNodes(MachineFunction &mf)
Evan Cheng3ef1c872010-09-10 01:29:16 +000037 : ScheduleDAG(mf),
38 InstrItins(mf.getTarget().getInstrItineraryData()) {}
Dan Gohman343f0c02008-11-19 23:18:57 +000039
Dan Gohman47ac0f02009-02-11 04:27:20 +000040/// Run - perform scheduling.
41///
42void ScheduleDAGSDNodes::Run(SelectionDAG *dag, MachineBasicBlock *bb,
43 MachineBasicBlock::iterator insertPos) {
44 DAG = dag;
45 ScheduleDAG::Run(bb, insertPos);
46}
47
Evan Cheng1cc39842010-05-20 23:26:43 +000048/// NewSUnit - Creates a new SUnit and return a ptr to it.
49///
50SUnit *ScheduleDAGSDNodes::NewSUnit(SDNode *N) {
51#ifndef NDEBUG
52 const SUnit *Addr = 0;
53 if (!SUnits.empty())
54 Addr = &SUnits[0];
55#endif
56 SUnits.push_back(SUnit(N, (unsigned)SUnits.size()));
57 assert((Addr == 0 || Addr == &SUnits[0]) &&
58 "SUnits std::vector reallocated on the fly!");
59 SUnits.back().OrigNode = &SUnits.back();
60 SUnit *SU = &SUnits.back();
61 const TargetLowering &TLI = DAG->getTargetLoweringInfo();
Evan Chengc120af42010-08-10 02:39:45 +000062 if (!N ||
63 (N->isMachineOpcode() &&
64 N->getMachineOpcode() == TargetOpcode::IMPLICIT_DEF))
Evan Cheng046fa3f2010-05-28 23:26:21 +000065 SU->SchedulingPref = Sched::None;
66 else
67 SU->SchedulingPref = TLI.getSchedulingPreference(N);
Evan Cheng1cc39842010-05-20 23:26:43 +000068 return SU;
69}
70
Dan Gohman343f0c02008-11-19 23:18:57 +000071SUnit *ScheduleDAGSDNodes::Clone(SUnit *Old) {
72 SUnit *SU = NewSUnit(Old->getNode());
73 SU->OrigNode = Old->OrigNode;
74 SU->Latency = Old->Latency;
Evan Cheng8239daf2010-11-03 00:45:17 +000075 SU->isCall = Old->isCall;
Dan Gohman343f0c02008-11-19 23:18:57 +000076 SU->isTwoAddress = Old->isTwoAddress;
77 SU->isCommutable = Old->isCommutable;
78 SU->hasPhysRegDefs = Old->hasPhysRegDefs;
Dan Gohman39746672009-03-23 16:10:52 +000079 SU->hasPhysRegClobbers = Old->hasPhysRegClobbers;
Evan Cheng1cc39842010-05-20 23:26:43 +000080 SU->SchedulingPref = Old->SchedulingPref;
Evan Chenge57187c2009-01-16 20:57:18 +000081 Old->isCloned = true;
Dan Gohman343f0c02008-11-19 23:18:57 +000082 return SU;
83}
84
85/// CheckForPhysRegDependency - Check if the dependency between def and use of
86/// a specified operand is a physical register dependency. If so, returns the
Evan Chengc29a56d2009-01-12 03:19:55 +000087/// register and the cost of copying the register.
Dan Gohman343f0c02008-11-19 23:18:57 +000088static void CheckForPhysRegDependency(SDNode *Def, SDNode *User, unsigned Op,
Andrew Trickcd5af072011-02-03 23:00:17 +000089 const TargetRegisterInfo *TRI,
Dan Gohman343f0c02008-11-19 23:18:57 +000090 const TargetInstrInfo *TII,
Evan Chengc29a56d2009-01-12 03:19:55 +000091 unsigned &PhysReg, int &Cost) {
Dan Gohman343f0c02008-11-19 23:18:57 +000092 if (Op != 2 || User->getOpcode() != ISD::CopyToReg)
93 return;
94
95 unsigned Reg = cast<RegisterSDNode>(User->getOperand(1))->getReg();
96 if (TargetRegisterInfo::isVirtualRegister(Reg))
97 return;
98
99 unsigned ResNo = User->getOperand(2).getResNo();
100 if (Def->isMachineOpcode()) {
101 const TargetInstrDesc &II = TII->get(Def->getMachineOpcode());
102 if (ResNo >= II.getNumDefs() &&
Evan Chengc29a56d2009-01-12 03:19:55 +0000103 II.ImplicitDefs[ResNo - II.getNumDefs()] == Reg) {
Dan Gohman343f0c02008-11-19 23:18:57 +0000104 PhysReg = Reg;
Evan Chengc29a56d2009-01-12 03:19:55 +0000105 const TargetRegisterClass *RC =
Rafael Espindolad31f9722010-06-29 14:02:34 +0000106 TRI->getMinimalPhysRegClass(Reg, Def->getValueType(ResNo));
Evan Chengc29a56d2009-01-12 03:19:55 +0000107 Cost = RC->getCopyCost();
108 }
Dan Gohman343f0c02008-11-19 23:18:57 +0000109 }
110}
111
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000112static void AddGlue(SDNode *N, SDValue Glue, bool AddGlue, SelectionDAG *DAG) {
Evan Chengc589e032010-01-22 03:36:51 +0000113 SmallVector<EVT, 4> VTs;
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000114 SDNode *GlueDestNode = Glue.getNode();
Bill Wendling151d26d2010-06-23 18:16:24 +0000115
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000116 // Don't add glue from a node to itself.
117 if (GlueDestNode == N) return;
Bill Wendling10707f32010-06-24 22:00:37 +0000118
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000119 // Don't add glue to something which already has glue.
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +0000120 if (N->getValueType(N->getNumValues() - 1) == MVT::Glue) return;
Bill Wendling10707f32010-06-24 22:00:37 +0000121
122 for (unsigned I = 0, E = N->getNumValues(); I != E; ++I)
123 VTs.push_back(N->getValueType(I));
Bill Wendling151d26d2010-06-23 18:16:24 +0000124
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000125 if (AddGlue)
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +0000126 VTs.push_back(MVT::Glue);
Bill Wendling151d26d2010-06-23 18:16:24 +0000127
Evan Chengc589e032010-01-22 03:36:51 +0000128 SmallVector<SDValue, 4> Ops;
Bill Wendling10707f32010-06-24 22:00:37 +0000129 for (unsigned I = 0, E = N->getNumOperands(); I != E; ++I)
130 Ops.push_back(N->getOperand(I));
Bill Wendling151d26d2010-06-23 18:16:24 +0000131
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000132 if (GlueDestNode)
133 Ops.push_back(Glue);
Bill Wendling151d26d2010-06-23 18:16:24 +0000134
Evan Chengc589e032010-01-22 03:36:51 +0000135 SDVTList VTList = DAG->getVTList(&VTs[0], VTs.size());
Bill Wendling151d26d2010-06-23 18:16:24 +0000136 MachineSDNode::mmo_iterator Begin = 0, End = 0;
137 MachineSDNode *MN = dyn_cast<MachineSDNode>(N);
138
139 // Store memory references.
140 if (MN) {
141 Begin = MN->memoperands_begin();
142 End = MN->memoperands_end();
143 }
144
Evan Chengc589e032010-01-22 03:36:51 +0000145 DAG->MorphNodeTo(N, N->getOpcode(), VTList, &Ops[0], Ops.size());
Bill Wendling151d26d2010-06-23 18:16:24 +0000146
147 // Reset the memory references
148 if (MN)
149 MN->setMemRefs(Begin, End);
Evan Chengc589e032010-01-22 03:36:51 +0000150}
151
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000152/// ClusterNeighboringLoads - Force nearby loads together by "gluing" them.
Evan Chengc589e032010-01-22 03:36:51 +0000153/// This function finds loads of the same base and different offsets. If the
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +0000154/// offsets are not far apart (target specific), it add MVT::Glue inputs and
Evan Chengc589e032010-01-22 03:36:51 +0000155/// outputs to ensure they are scheduled together and in order. This
156/// optimization may benefit some targets by improving cache locality.
Evan Cheng302ef832010-06-10 02:09:31 +0000157void ScheduleDAGSDNodes::ClusterNeighboringLoads(SDNode *Node) {
158 SDNode *Chain = 0;
159 unsigned NumOps = Node->getNumOperands();
160 if (Node->getOperand(NumOps-1).getValueType() == MVT::Other)
161 Chain = Node->getOperand(NumOps-1).getNode();
162 if (!Chain)
163 return;
164
165 // Look for other loads of the same chain. Find loads that are loading from
166 // the same base pointer and different offsets.
Evan Chengc589e032010-01-22 03:36:51 +0000167 SmallPtrSet<SDNode*, 16> Visited;
168 SmallVector<int64_t, 4> Offsets;
169 DenseMap<long long, SDNode*> O2SMap; // Map from offset to SDNode.
Evan Cheng302ef832010-06-10 02:09:31 +0000170 bool Cluster = false;
171 SDNode *Base = Node;
Evan Cheng302ef832010-06-10 02:09:31 +0000172 for (SDNode::use_iterator I = Chain->use_begin(), E = Chain->use_end();
173 I != E; ++I) {
174 SDNode *User = *I;
175 if (User == Node || !Visited.insert(User))
176 continue;
177 int64_t Offset1, Offset2;
178 if (!TII->areLoadsFromSameBasePtr(Base, User, Offset1, Offset2) ||
179 Offset1 == Offset2)
180 // FIXME: Should be ok if they addresses are identical. But earlier
181 // optimizations really should have eliminated one of the loads.
182 continue;
183 if (O2SMap.insert(std::make_pair(Offset1, Base)).second)
184 Offsets.push_back(Offset1);
185 O2SMap.insert(std::make_pair(Offset2, User));
186 Offsets.push_back(Offset2);
Duncan Sandsb447c4e2010-06-25 14:48:39 +0000187 if (Offset2 < Offset1)
Evan Cheng302ef832010-06-10 02:09:31 +0000188 Base = User;
Evan Cheng302ef832010-06-10 02:09:31 +0000189 Cluster = true;
190 }
191
192 if (!Cluster)
193 return;
194
195 // Sort them in increasing order.
196 std::sort(Offsets.begin(), Offsets.end());
197
198 // Check if the loads are close enough.
199 SmallVector<SDNode*, 4> Loads;
200 unsigned NumLoads = 0;
201 int64_t BaseOff = Offsets[0];
202 SDNode *BaseLoad = O2SMap[BaseOff];
203 Loads.push_back(BaseLoad);
204 for (unsigned i = 1, e = Offsets.size(); i != e; ++i) {
205 int64_t Offset = Offsets[i];
206 SDNode *Load = O2SMap[Offset];
207 if (!TII->shouldScheduleLoadsNear(BaseLoad, Load, BaseOff, Offset,NumLoads))
208 break; // Stop right here. Ignore loads that are further away.
209 Loads.push_back(Load);
210 ++NumLoads;
211 }
212
213 if (NumLoads == 0)
214 return;
215
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +0000216 // Cluster loads by adding MVT::Glue outputs and inputs. This also
Evan Cheng302ef832010-06-10 02:09:31 +0000217 // ensure they are scheduled in order of increasing addresses.
218 SDNode *Lead = Loads[0];
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000219 AddGlue(Lead, SDValue(0, 0), true, DAG);
Bill Wendling151d26d2010-06-23 18:16:24 +0000220
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000221 SDValue InGlue = SDValue(Lead, Lead->getNumValues() - 1);
Bill Wendling10707f32010-06-24 22:00:37 +0000222 for (unsigned I = 1, E = Loads.size(); I != E; ++I) {
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000223 bool OutGlue = I < E - 1;
Bill Wendling10707f32010-06-24 22:00:37 +0000224 SDNode *Load = Loads[I];
225
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000226 AddGlue(Load, InGlue, OutGlue, DAG);
Bill Wendling151d26d2010-06-23 18:16:24 +0000227
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000228 if (OutGlue)
229 InGlue = SDValue(Load, Load->getNumValues() - 1);
Bill Wendling151d26d2010-06-23 18:16:24 +0000230
Evan Cheng302ef832010-06-10 02:09:31 +0000231 ++LoadsClustered;
232 }
233}
234
235/// ClusterNodes - Cluster certain nodes which should be scheduled together.
236///
237void ScheduleDAGSDNodes::ClusterNodes() {
Evan Chengc589e032010-01-22 03:36:51 +0000238 for (SelectionDAG::allnodes_iterator NI = DAG->allnodes_begin(),
239 E = DAG->allnodes_end(); NI != E; ++NI) {
240 SDNode *Node = &*NI;
241 if (!Node || !Node->isMachineOpcode())
242 continue;
243
244 unsigned Opc = Node->getMachineOpcode();
245 const TargetInstrDesc &TID = TII->get(Opc);
Evan Cheng302ef832010-06-10 02:09:31 +0000246 if (TID.mayLoad())
247 // Cluster loads from "near" addresses into combined SUnits.
248 ClusterNeighboringLoads(Node);
Evan Chengc589e032010-01-22 03:36:51 +0000249 }
250}
251
Dan Gohman343f0c02008-11-19 23:18:57 +0000252void ScheduleDAGSDNodes::BuildSchedUnits() {
Dan Gohmane1dfc7d2008-12-23 17:24:50 +0000253 // During scheduling, the NodeId field of SDNode is used to map SDNodes
254 // to their associated SUnits by holding SUnits table indices. A value
255 // of -1 means the SDNode does not yet have an associated SUnit.
256 unsigned NumNodes = 0;
257 for (SelectionDAG::allnodes_iterator NI = DAG->allnodes_begin(),
258 E = DAG->allnodes_end(); NI != E; ++NI) {
259 NI->setNodeId(-1);
260 ++NumNodes;
261 }
262
Dan Gohman343f0c02008-11-19 23:18:57 +0000263 // Reserve entries in the vector for each of the SUnits we are creating. This
264 // ensure that reallocation of the vector won't happen, so SUnit*'s won't get
265 // invalidated.
Dan Gohman89b64bd2008-12-17 04:30:46 +0000266 // FIXME: Multiply by 2 because we may clone nodes during scheduling.
267 // This is a temporary workaround.
Dan Gohmane1dfc7d2008-12-23 17:24:50 +0000268 SUnits.reserve(NumNodes * 2);
Andrew Trickcd5af072011-02-03 23:00:17 +0000269
Chris Lattner736a6ea2010-02-24 06:11:37 +0000270 // Add all nodes in depth first order.
271 SmallVector<SDNode*, 64> Worklist;
272 SmallPtrSet<SDNode*, 64> Visited;
273 Worklist.push_back(DAG->getRoot().getNode());
274 Visited.insert(DAG->getRoot().getNode());
Andrew Trickcd5af072011-02-03 23:00:17 +0000275
Chris Lattner736a6ea2010-02-24 06:11:37 +0000276 while (!Worklist.empty()) {
277 SDNode *NI = Worklist.pop_back_val();
Andrew Trickcd5af072011-02-03 23:00:17 +0000278
Chris Lattner736a6ea2010-02-24 06:11:37 +0000279 // Add all operands to the worklist unless they've already been added.
280 for (unsigned i = 0, e = NI->getNumOperands(); i != e; ++i)
281 if (Visited.insert(NI->getOperand(i).getNode()))
282 Worklist.push_back(NI->getOperand(i).getNode());
Andrew Trickcd5af072011-02-03 23:00:17 +0000283
Dan Gohman343f0c02008-11-19 23:18:57 +0000284 if (isPassiveNode(NI)) // Leaf node, e.g. a TargetImmediate.
285 continue;
Andrew Trickcd5af072011-02-03 23:00:17 +0000286
Dan Gohman343f0c02008-11-19 23:18:57 +0000287 // If this node has already been processed, stop now.
288 if (NI->getNodeId() != -1) continue;
Andrew Trickcd5af072011-02-03 23:00:17 +0000289
Dan Gohman343f0c02008-11-19 23:18:57 +0000290 SUnit *NodeSUnit = NewSUnit(NI);
Andrew Trickcd5af072011-02-03 23:00:17 +0000291
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000292 // See if anything is glued to this node, if so, add them to glued
293 // nodes. Nodes can have at most one glue input and one glue output. Glue
294 // is required to be the last operand and result of a node.
Andrew Trickcd5af072011-02-03 23:00:17 +0000295
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000296 // Scan up to find glued preds.
Dan Gohman343f0c02008-11-19 23:18:57 +0000297 SDNode *N = NI;
Dan Gohmandb95fa12009-03-20 20:42:23 +0000298 while (N->getNumOperands() &&
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +0000299 N->getOperand(N->getNumOperands()-1).getValueType() == MVT::Glue) {
Dan Gohmandb95fa12009-03-20 20:42:23 +0000300 N = N->getOperand(N->getNumOperands()-1).getNode();
301 assert(N->getNodeId() == -1 && "Node already inserted!");
302 N->setNodeId(NodeSUnit->NodeNum);
Evan Cheng8239daf2010-11-03 00:45:17 +0000303 if (N->isMachineOpcode() && TII->get(N->getMachineOpcode()).isCall())
304 NodeSUnit->isCall = true;
Dan Gohman343f0c02008-11-19 23:18:57 +0000305 }
Andrew Trickcd5af072011-02-03 23:00:17 +0000306
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000307 // Scan down to find any glued succs.
Dan Gohman343f0c02008-11-19 23:18:57 +0000308 N = NI;
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +0000309 while (N->getValueType(N->getNumValues()-1) == MVT::Glue) {
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000310 SDValue GlueVal(N, N->getNumValues()-1);
Andrew Trickcd5af072011-02-03 23:00:17 +0000311
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000312 // There are either zero or one users of the Glue result.
313 bool HasGlueUse = false;
Andrew Trickcd5af072011-02-03 23:00:17 +0000314 for (SDNode::use_iterator UI = N->use_begin(), E = N->use_end();
Dan Gohman343f0c02008-11-19 23:18:57 +0000315 UI != E; ++UI)
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000316 if (GlueVal.isOperandOf(*UI)) {
317 HasGlueUse = true;
Dan Gohman343f0c02008-11-19 23:18:57 +0000318 assert(N->getNodeId() == -1 && "Node already inserted!");
319 N->setNodeId(NodeSUnit->NodeNum);
320 N = *UI;
Evan Cheng8239daf2010-11-03 00:45:17 +0000321 if (N->isMachineOpcode() && TII->get(N->getMachineOpcode()).isCall())
322 NodeSUnit->isCall = true;
Dan Gohman343f0c02008-11-19 23:18:57 +0000323 break;
324 }
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000325 if (!HasGlueUse) break;
Dan Gohman343f0c02008-11-19 23:18:57 +0000326 }
Andrew Trickcd5af072011-02-03 23:00:17 +0000327
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000328 // If there are glue operands involved, N is now the bottom-most node
329 // of the sequence of nodes that are glued together.
Dan Gohman343f0c02008-11-19 23:18:57 +0000330 // Update the SUnit.
331 NodeSUnit->setNode(N);
332 assert(N->getNodeId() == -1 && "Node already inserted!");
333 N->setNodeId(NodeSUnit->NodeNum);
334
Andrew Trick92e94662011-02-04 03:18:17 +0000335 // Compute NumRegDefsLeft. This must be done before AddSchedEdges.
336 InitNumRegDefsLeft(NodeSUnit);
337
Dan Gohman787782f2008-11-21 01:44:51 +0000338 // Assign the Latency field of NodeSUnit using target-provided information.
Evan Chenge1631682010-05-19 22:42:23 +0000339 ComputeLatency(NodeSUnit);
Dan Gohman343f0c02008-11-19 23:18:57 +0000340 }
Dan Gohmanc9a5b9e2008-12-23 18:36:58 +0000341}
342
343void ScheduleDAGSDNodes::AddSchedEdges() {
David Goodwin71046162009-08-13 16:05:04 +0000344 const TargetSubtarget &ST = TM.getSubtarget<TargetSubtarget>();
345
David Goodwindc4bdcd2009-08-19 16:08:58 +0000346 // Check to see if the scheduler cares about latencies.
347 bool UnitLatencies = ForceUnitLatencies();
348
Dan Gohman343f0c02008-11-19 23:18:57 +0000349 // Pass 2: add the preds, succs, etc.
350 for (unsigned su = 0, e = SUnits.size(); su != e; ++su) {
351 SUnit *SU = &SUnits[su];
352 SDNode *MainNode = SU->getNode();
Andrew Trickcd5af072011-02-03 23:00:17 +0000353
Dan Gohman343f0c02008-11-19 23:18:57 +0000354 if (MainNode->isMachineOpcode()) {
355 unsigned Opc = MainNode->getMachineOpcode();
356 const TargetInstrDesc &TID = TII->get(Opc);
357 for (unsigned i = 0; i != TID.getNumOperands(); ++i) {
358 if (TID.getOperandConstraint(i, TOI::TIED_TO) != -1) {
359 SU->isTwoAddress = true;
360 break;
361 }
362 }
363 if (TID.isCommutable())
364 SU->isCommutable = true;
365 }
Andrew Trickcd5af072011-02-03 23:00:17 +0000366
Dan Gohman343f0c02008-11-19 23:18:57 +0000367 // Find all predecessors and successors of the group.
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000368 for (SDNode *N = SU->getNode(); N; N = N->getGluedNode()) {
Dan Gohman343f0c02008-11-19 23:18:57 +0000369 if (N->isMachineOpcode() &&
Dan Gohman39746672009-03-23 16:10:52 +0000370 TII->get(N->getMachineOpcode()).getImplicitDefs()) {
371 SU->hasPhysRegClobbers = true;
Dan Gohmanbcea8592009-10-10 01:32:21 +0000372 unsigned NumUsed = InstrEmitter::CountResults(N);
Dan Gohman8cccf0e2009-03-23 17:39:36 +0000373 while (NumUsed != 0 && !N->hasAnyUseOfValue(NumUsed - 1))
374 --NumUsed; // Skip over unused values at the end.
375 if (NumUsed > TII->get(N->getMachineOpcode()).getNumDefs())
Dan Gohman39746672009-03-23 16:10:52 +0000376 SU->hasPhysRegDefs = true;
377 }
Andrew Trickcd5af072011-02-03 23:00:17 +0000378
Dan Gohman343f0c02008-11-19 23:18:57 +0000379 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
380 SDNode *OpN = N->getOperand(i).getNode();
381 if (isPassiveNode(OpN)) continue; // Not scheduled.
382 SUnit *OpSU = &SUnits[OpN->getNodeId()];
383 assert(OpSU && "Node has no SUnit!");
384 if (OpSU == SU) continue; // In the same group.
385
Owen Andersone50ed302009-08-10 22:56:29 +0000386 EVT OpVT = N->getOperand(i).getValueType();
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000387 assert(OpVT != MVT::Glue && "Glued nodes should be in same sunit!");
Owen Anderson825b72b2009-08-11 20:47:22 +0000388 bool isChain = OpVT == MVT::Other;
Dan Gohman343f0c02008-11-19 23:18:57 +0000389
390 unsigned PhysReg = 0;
Evan Chengc29a56d2009-01-12 03:19:55 +0000391 int Cost = 1;
Dan Gohman343f0c02008-11-19 23:18:57 +0000392 // Determine if this is a physical register dependency.
Evan Chengc29a56d2009-01-12 03:19:55 +0000393 CheckForPhysRegDependency(OpN, N, i, TRI, TII, PhysReg, Cost);
Dan Gohman54e4c362008-12-09 22:54:47 +0000394 assert((PhysReg == 0 || !isChain) &&
395 "Chain dependence via physreg data?");
Evan Chengc29a56d2009-01-12 03:19:55 +0000396 // FIXME: See ScheduleDAGSDNodes::EmitCopyFromReg. For now, scheduler
397 // emits a copy from the physical register to a virtual register unless
398 // it requires a cross class copy (cost < 0). That means we are only
399 // treating "expensive to copy" register dependency as physical register
400 // dependency. This may change in the future though.
401 if (Cost >= 0)
402 PhysReg = 0;
David Goodwin71046162009-08-13 16:05:04 +0000403
Evan Cheng046fa3f2010-05-28 23:26:21 +0000404 // If this is a ctrl dep, latency is 1.
405 unsigned OpLatency = isChain ? 1 : OpSU->Latency;
406 const SDep &dep = SDep(OpSU, isChain ? SDep::Order : SDep::Data,
407 OpLatency, PhysReg);
David Goodwindc4bdcd2009-08-19 16:08:58 +0000408 if (!isChain && !UnitLatencies) {
Evan Cheng15a16de2010-05-20 06:13:19 +0000409 ComputeOperandLatency(OpN, N, i, const_cast<SDep &>(dep));
Dan Gohman3fb150a2010-04-17 17:42:52 +0000410 ST.adjustSchedDependency(OpSU, SU, const_cast<SDep &>(dep));
David Goodwindc4bdcd2009-08-19 16:08:58 +0000411 }
David Goodwin71046162009-08-13 16:05:04 +0000412
Andrew Trick92e94662011-02-04 03:18:17 +0000413 if (!SU->addPred(dep) && !dep.isCtrl() && OpSU->NumRegDefsLeft > 0) {
414 // Multiple register uses are combined in the same SUnit. For example,
415 // we could have a set of glued nodes with all their defs consumed by
416 // another set of glued nodes. Register pressure tracking sees this as
417 // a single use, so to keep pressure balanced we reduce the defs.
418 --OpSU->NumRegDefsLeft;
419 }
Dan Gohman343f0c02008-11-19 23:18:57 +0000420 }
421 }
422 }
423}
424
Dan Gohmanc9a5b9e2008-12-23 18:36:58 +0000425/// BuildSchedGraph - Build the SUnit graph from the selection dag that we
426/// are input. This SUnit graph is similar to the SelectionDAG, but
427/// excludes nodes that aren't interesting to scheduling, and represents
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000428/// glued together nodes with a single SUnit.
Dan Gohman98976e42009-10-09 23:33:48 +0000429void ScheduleDAGSDNodes::BuildSchedGraph(AliasAnalysis *AA) {
Evan Cheng302ef832010-06-10 02:09:31 +0000430 // Cluster certain nodes which should be scheduled together.
431 ClusterNodes();
Dan Gohmanc9a5b9e2008-12-23 18:36:58 +0000432 // Populate the SUnits array.
433 BuildSchedUnits();
434 // Compute all the scheduling dependencies between nodes.
435 AddSchedEdges();
436}
437
Andrew Trick92e94662011-02-04 03:18:17 +0000438// Initialize NumNodeDefs for the current Node's opcode.
439void ScheduleDAGSDNodes::RegDefIter::InitNodeNumDefs() {
440 if (!Node->isMachineOpcode()) {
441 if (Node->getOpcode() == ISD::CopyFromReg)
442 NodeNumDefs = 1;
443 else
444 NodeNumDefs = 0;
445 return;
446 }
447 unsigned POpc = Node->getMachineOpcode();
448 if (POpc == TargetOpcode::IMPLICIT_DEF) {
449 // No register need be allocated for this.
450 NodeNumDefs = 0;
451 return;
452 }
453 unsigned NRegDefs = SchedDAG->TII->get(Node->getMachineOpcode()).getNumDefs();
454 // Some instructions define regs that are not represented in the selection DAG
455 // (e.g. unused flags). See tMOVi8. Make sure we don't access past NumValues.
456 NodeNumDefs = std::min(Node->getNumValues(), NRegDefs);
457 DefIdx = 0;
458}
459
460// Construct a RegDefIter for this SUnit and find the first valid value.
461ScheduleDAGSDNodes::RegDefIter::RegDefIter(const SUnit *SU,
462 const ScheduleDAGSDNodes *SD)
463 : SchedDAG(SD), Node(SU->getNode()), DefIdx(0), NodeNumDefs(0) {
464 InitNodeNumDefs();
465 Advance();
466}
467
468// Advance to the next valid value defined by the SUnit.
469void ScheduleDAGSDNodes::RegDefIter::Advance() {
470 for (;Node;) { // Visit all glued nodes.
471 for (;DefIdx < NodeNumDefs; ++DefIdx) {
472 if (!Node->hasAnyUseOfValue(DefIdx))
473 continue;
474 if (Node->isMachineOpcode() &&
475 Node->getMachineOpcode() == TargetOpcode::EXTRACT_SUBREG) {
476 // Propagate the incoming (full-register) type. I doubt it's needed.
477 ValueType = Node->getOperand(0).getValueType();
478 }
479 else {
480 ValueType = Node->getValueType(DefIdx);
481 }
482 ++DefIdx;
483 return; // Found a normal regdef.
484 }
485 Node = Node->getGluedNode();
486 if (Node == NULL) {
487 return; // No values left to visit.
488 }
489 InitNodeNumDefs();
490 }
491}
492
493void ScheduleDAGSDNodes::InitNumRegDefsLeft(SUnit *SU) {
494 assert(SU->NumRegDefsLeft == 0 && "expect a new node");
495 for (RegDefIter I(SU, this); I.IsValid(); I.Advance()) {
496 assert(SU->NumRegDefsLeft < USHRT_MAX && "overflow is ok but unexpected");
497 ++SU->NumRegDefsLeft;
498 }
499}
500
Dan Gohman343f0c02008-11-19 23:18:57 +0000501void ScheduleDAGSDNodes::ComputeLatency(SUnit *SU) {
Evan Chenge1631682010-05-19 22:42:23 +0000502 // Check to see if the scheduler cares about latencies.
503 if (ForceUnitLatencies()) {
504 SU->Latency = 1;
505 return;
506 }
507
Evan Cheng3ef1c872010-09-10 01:29:16 +0000508 if (!InstrItins || InstrItins->isEmpty()) {
Evan Cheng15a16de2010-05-20 06:13:19 +0000509 SU->Latency = 1;
510 return;
511 }
Andrew Trickcd5af072011-02-03 23:00:17 +0000512
Dan Gohman343f0c02008-11-19 23:18:57 +0000513 // Compute the latency for the node. We use the sum of the latencies for
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000514 // all nodes glued together into this SUnit.
Dan Gohman343f0c02008-11-19 23:18:57 +0000515 SU->Latency = 0;
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000516 for (SDNode *N = SU->getNode(); N; N = N->getGluedNode())
Evan Cheng8239daf2010-11-03 00:45:17 +0000517 if (N->isMachineOpcode())
518 SU->Latency += TII->getInstrLatency(InstrItins, N);
Dan Gohman343f0c02008-11-19 23:18:57 +0000519}
520
Evan Cheng15a16de2010-05-20 06:13:19 +0000521void ScheduleDAGSDNodes::ComputeOperandLatency(SDNode *Def, SDNode *Use,
522 unsigned OpIdx, SDep& dep) const{
523 // Check to see if the scheduler cares about latencies.
524 if (ForceUnitLatencies())
525 return;
526
Evan Cheng15a16de2010-05-20 06:13:19 +0000527 if (dep.getKind() != SDep::Data)
528 return;
529
530 unsigned DefIdx = Use->getOperand(OpIdx).getResNo();
Evan Cheng7e2fe912010-10-28 06:47:08 +0000531 if (Use->isMachineOpcode())
532 // Adjust the use operand index by num of defs.
533 OpIdx += TII->get(Use->getMachineOpcode()).getNumDefs();
Evan Chenga0792de2010-10-06 06:27:31 +0000534 int Latency = TII->getOperandLatency(InstrItins, Def, DefIdx, Use, OpIdx);
Evan Cheng08975152010-10-29 18:09:28 +0000535 if (Latency > 1 && Use->getOpcode() == ISD::CopyToReg &&
536 !BB->succ_empty()) {
537 unsigned Reg = cast<RegisterSDNode>(Use->getOperand(1))->getReg();
538 if (TargetRegisterInfo::isVirtualRegister(Reg))
539 // This copy is a liveout value. It is likely coalesced, so reduce the
540 // latency so not to penalize the def.
541 // FIXME: need target specific adjustment here?
542 Latency = (Latency > 1) ? Latency - 1 : 1;
543 }
Evan Cheng3881cb72010-09-29 22:42:35 +0000544 if (Latency >= 0)
545 dep.setLatency(Latency);
Evan Cheng15a16de2010-05-20 06:13:19 +0000546}
547
Dan Gohman343f0c02008-11-19 23:18:57 +0000548void ScheduleDAGSDNodes::dumpNode(const SUnit *SU) const {
Evan Chengc29a56d2009-01-12 03:19:55 +0000549 if (!SU->getNode()) {
David Greene84fa8222010-01-05 01:25:11 +0000550 dbgs() << "PHYS REG COPY\n";
Evan Chengc29a56d2009-01-12 03:19:55 +0000551 return;
552 }
553
554 SU->getNode()->dump(DAG);
David Greene84fa8222010-01-05 01:25:11 +0000555 dbgs() << "\n";
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000556 SmallVector<SDNode *, 4> GluedNodes;
557 for (SDNode *N = SU->getNode()->getGluedNode(); N; N = N->getGluedNode())
558 GluedNodes.push_back(N);
559 while (!GluedNodes.empty()) {
David Greene84fa8222010-01-05 01:25:11 +0000560 dbgs() << " ";
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000561 GluedNodes.back()->dump(DAG);
David Greene84fa8222010-01-05 01:25:11 +0000562 dbgs() << "\n";
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000563 GluedNodes.pop_back();
Dan Gohman343f0c02008-11-19 23:18:57 +0000564 }
565}
Dan Gohmanbcea8592009-10-10 01:32:21 +0000566
Evan Chengbfcb3052010-03-25 01:38:16 +0000567namespace {
568 struct OrderSorter {
569 bool operator()(const std::pair<unsigned, MachineInstr*> &A,
570 const std::pair<unsigned, MachineInstr*> &B) {
571 return A.first < B.first;
572 }
573 };
574}
575
Devang Patel55d20e82011-01-26 18:20:04 +0000576/// ProcessSDDbgValues - Process SDDbgValues assoicated with this node.
Andrew Trickcd5af072011-02-03 23:00:17 +0000577static void ProcessSDDbgValues(SDNode *N, SelectionDAG *DAG,
Devang Patel55d20e82011-01-26 18:20:04 +0000578 InstrEmitter &Emitter,
579 SmallVector<std::pair<unsigned, MachineInstr*>, 32> &Orders,
580 DenseMap<SDValue, unsigned> &VRBaseMap,
581 unsigned Order) {
582 if (!N->getHasDebugValue())
583 return;
584
585 // Opportunistically insert immediate dbg_value uses, i.e. those with source
586 // order number right after the N.
587 MachineBasicBlock *BB = Emitter.getBlock();
588 MachineBasicBlock::iterator InsertPos = Emitter.getInsertPos();
589 SmallVector<SDDbgValue*,2> &DVs = DAG->GetDbgValues(N);
590 for (unsigned i = 0, e = DVs.size(); i != e; ++i) {
591 if (DVs[i]->isInvalidated())
592 continue;
593 unsigned DVOrder = DVs[i]->getOrder();
594 if (!Order || DVOrder == ++Order) {
595 MachineInstr *DbgMI = Emitter.EmitDbgValue(DVs[i], VRBaseMap);
596 if (DbgMI) {
597 Orders.push_back(std::make_pair(DVOrder, DbgMI));
598 BB->insert(InsertPos, DbgMI);
599 }
600 DVs[i]->setIsInvalidated();
601 }
602 }
603}
604
Evan Chengbfcb3052010-03-25 01:38:16 +0000605// ProcessSourceNode - Process nodes with source order numbers. These are added
Jim Grosbachd27946d2010-06-30 21:27:56 +0000606// to a vector which EmitSchedule uses to determine how to insert dbg_value
Evan Chengbfcb3052010-03-25 01:38:16 +0000607// instructions in the right order.
608static void ProcessSourceNode(SDNode *N, SelectionDAG *DAG,
609 InstrEmitter &Emitter,
Evan Chengbfcb3052010-03-25 01:38:16 +0000610 DenseMap<SDValue, unsigned> &VRBaseMap,
611 SmallVector<std::pair<unsigned, MachineInstr*>, 32> &Orders,
612 SmallSet<unsigned, 8> &Seen) {
613 unsigned Order = DAG->GetOrdering(N);
Devang Patel39078a82011-01-27 00:13:27 +0000614 if (!Order || !Seen.insert(Order)) {
615 // Process any valid SDDbgValues even if node does not have any order
616 // assigned.
617 ProcessSDDbgValues(N, DAG, Emitter, Orders, VRBaseMap, 0);
Evan Chengbfcb3052010-03-25 01:38:16 +0000618 return;
Devang Patel39078a82011-01-27 00:13:27 +0000619 }
Evan Chengbfcb3052010-03-25 01:38:16 +0000620
621 MachineBasicBlock *BB = Emitter.getBlock();
Dan Gohman84023e02010-07-10 09:00:22 +0000622 if (Emitter.getInsertPos() == BB->begin() || BB->back().isPHI()) {
Evan Chengbfcb3052010-03-25 01:38:16 +0000623 // Did not insert any instruction.
624 Orders.push_back(std::make_pair(Order, (MachineInstr*)0));
625 return;
626 }
627
Dan Gohman84023e02010-07-10 09:00:22 +0000628 Orders.push_back(std::make_pair(Order, prior(Emitter.getInsertPos())));
Devang Patel55d20e82011-01-26 18:20:04 +0000629 ProcessSDDbgValues(N, DAG, Emitter, Orders, VRBaseMap, Order);
Evan Chengbfcb3052010-03-25 01:38:16 +0000630}
631
632
Dan Gohmanbcea8592009-10-10 01:32:21 +0000633/// EmitSchedule - Emit the machine code in scheduled order.
Dan Gohmanaf1d8ca2010-05-01 00:01:06 +0000634MachineBasicBlock *ScheduleDAGSDNodes::EmitSchedule() {
Dan Gohmanbcea8592009-10-10 01:32:21 +0000635 InstrEmitter Emitter(BB, InsertPos);
636 DenseMap<SDValue, unsigned> VRBaseMap;
637 DenseMap<SUnit*, unsigned> CopyVRBaseMap;
Evan Chengbfcb3052010-03-25 01:38:16 +0000638 SmallVector<std::pair<unsigned, MachineInstr*>, 32> Orders;
639 SmallSet<unsigned, 8> Seen;
640 bool HasDbg = DAG->hasDebugValues();
Dale Johannesenbfdf7f32010-03-10 22:13:47 +0000641
Dale Johannesenfdb42fa2010-04-26 20:06:49 +0000642 // If this is the first BB, emit byval parameter dbg_value's.
643 if (HasDbg && BB->getParent()->begin() == MachineFunction::iterator(BB)) {
644 SDDbgInfo::DbgIterator PDI = DAG->ByvalParmDbgBegin();
645 SDDbgInfo::DbgIterator PDE = DAG->ByvalParmDbgEnd();
646 for (; PDI != PDE; ++PDI) {
Dan Gohman891ff8f2010-04-30 19:35:33 +0000647 MachineInstr *DbgMI= Emitter.EmitDbgValue(*PDI, VRBaseMap);
Dale Johannesenfdb42fa2010-04-26 20:06:49 +0000648 if (DbgMI)
Dan Gohman84023e02010-07-10 09:00:22 +0000649 BB->insert(InsertPos, DbgMI);
Dale Johannesenfdb42fa2010-04-26 20:06:49 +0000650 }
651 }
652
Dan Gohmanbcea8592009-10-10 01:32:21 +0000653 for (unsigned i = 0, e = Sequence.size(); i != e; i++) {
654 SUnit *SU = Sequence[i];
655 if (!SU) {
656 // Null SUnit* is a noop.
657 EmitNoop();
658 continue;
659 }
660
661 // For pre-regalloc scheduling, create instructions corresponding to the
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000662 // SDNode and any glued SDNodes and append them to the block.
Dan Gohmanbcea8592009-10-10 01:32:21 +0000663 if (!SU->getNode()) {
664 // Emit a copy.
665 EmitPhysRegCopy(SU, CopyVRBaseMap);
666 continue;
667 }
668
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000669 SmallVector<SDNode *, 4> GluedNodes;
670 for (SDNode *N = SU->getNode()->getGluedNode(); N;
671 N = N->getGluedNode())
672 GluedNodes.push_back(N);
673 while (!GluedNodes.empty()) {
674 SDNode *N = GluedNodes.back();
675 Emitter.EmitNode(GluedNodes.back(), SU->OrigNode != SU, SU->isCloned,
Dan Gohmanaf1d8ca2010-05-01 00:01:06 +0000676 VRBaseMap);
Dale Johannesenfdb42fa2010-04-26 20:06:49 +0000677 // Remember the source order of the inserted instruction.
Evan Chengbfcb3052010-03-25 01:38:16 +0000678 if (HasDbg)
Dan Gohman891ff8f2010-04-30 19:35:33 +0000679 ProcessSourceNode(N, DAG, Emitter, VRBaseMap, Orders, Seen);
Chris Lattner29d8f0c2010-12-23 17:24:32 +0000680 GluedNodes.pop_back();
Dan Gohmanbcea8592009-10-10 01:32:21 +0000681 }
682 Emitter.EmitNode(SU->getNode(), SU->OrigNode != SU, SU->isCloned,
Dan Gohmanaf1d8ca2010-05-01 00:01:06 +0000683 VRBaseMap);
Dale Johannesenfdb42fa2010-04-26 20:06:49 +0000684 // Remember the source order of the inserted instruction.
Evan Chengbfcb3052010-03-25 01:38:16 +0000685 if (HasDbg)
Dan Gohman891ff8f2010-04-30 19:35:33 +0000686 ProcessSourceNode(SU->getNode(), DAG, Emitter, VRBaseMap, Orders,
Evan Chengbfcb3052010-03-25 01:38:16 +0000687 Seen);
688 }
689
Dale Johannesenfdb42fa2010-04-26 20:06:49 +0000690 // Insert all the dbg_values which have not already been inserted in source
Evan Chengbfcb3052010-03-25 01:38:16 +0000691 // order sequence.
692 if (HasDbg) {
Dan Gohman84023e02010-07-10 09:00:22 +0000693 MachineBasicBlock::iterator BBBegin = BB->getFirstNonPHI();
Evan Chengbfcb3052010-03-25 01:38:16 +0000694
695 // Sort the source order instructions and use the order to insert debug
696 // values.
697 std::sort(Orders.begin(), Orders.end(), OrderSorter());
698
699 SDDbgInfo::DbgIterator DI = DAG->DbgBegin();
700 SDDbgInfo::DbgIterator DE = DAG->DbgEnd();
701 // Now emit the rest according to source order.
702 unsigned LastOrder = 0;
Evan Chengbfcb3052010-03-25 01:38:16 +0000703 for (unsigned i = 0, e = Orders.size(); i != e && DI != DE; ++i) {
704 unsigned Order = Orders[i].first;
705 MachineInstr *MI = Orders[i].second;
706 // Insert all SDDbgValue's whose order(s) are before "Order".
707 if (!MI)
708 continue;
Evan Chengbfcb3052010-03-25 01:38:16 +0000709 for (; DI != DE &&
710 (*DI)->getOrder() >= LastOrder && (*DI)->getOrder() < Order; ++DI) {
711 if ((*DI)->isInvalidated())
712 continue;
Dan Gohman891ff8f2010-04-30 19:35:33 +0000713 MachineInstr *DbgMI = Emitter.EmitDbgValue(*DI, VRBaseMap);
Evan Cheng962021b2010-04-26 07:38:55 +0000714 if (DbgMI) {
715 if (!LastOrder)
716 // Insert to start of the BB (after PHIs).
717 BB->insert(BBBegin, DbgMI);
718 else {
Dan Gohmana8dab362010-07-10 22:42:31 +0000719 // Insert at the instruction, which may be in a different
720 // block, if the block was split by a custom inserter.
Evan Cheng962021b2010-04-26 07:38:55 +0000721 MachineBasicBlock::iterator Pos = MI;
Dan Gohmana8dab362010-07-10 22:42:31 +0000722 MI->getParent()->insert(llvm::next(Pos), DbgMI);
Evan Cheng962021b2010-04-26 07:38:55 +0000723 }
Evan Chengbfcb3052010-03-25 01:38:16 +0000724 }
Dale Johannesenbfdf7f32010-03-10 22:13:47 +0000725 }
Evan Chengbfcb3052010-03-25 01:38:16 +0000726 LastOrder = Order;
Evan Chengbfcb3052010-03-25 01:38:16 +0000727 }
728 // Add trailing DbgValue's before the terminator. FIXME: May want to add
729 // some of them before one or more conditional branches?
730 while (DI != DE) {
731 MachineBasicBlock *InsertBB = Emitter.getBlock();
732 MachineBasicBlock::iterator Pos= Emitter.getBlock()->getFirstTerminator();
733 if (!(*DI)->isInvalidated()) {
Dan Gohman891ff8f2010-04-30 19:35:33 +0000734 MachineInstr *DbgMI= Emitter.EmitDbgValue(*DI, VRBaseMap);
Evan Cheng962021b2010-04-26 07:38:55 +0000735 if (DbgMI)
736 InsertBB->insert(Pos, DbgMI);
Evan Chengbfcb3052010-03-25 01:38:16 +0000737 }
738 ++DI;
739 }
Dan Gohmanbcea8592009-10-10 01:32:21 +0000740 }
741
742 BB = Emitter.getBlock();
743 InsertPos = Emitter.getInsertPos();
744 return BB;
745}