LLVM 23.0.0git
ScheduleDAGSDNodes.cpp
Go to the documentation of this file.
1//===--- ScheduleDAGSDNodes.cpp - Implement the ScheduleDAGSDNodes class --===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This implements the ScheduleDAG class, which is a base class used by
10// scheduling implementation classes.
11//
12//===----------------------------------------------------------------------===//
13
14#include "ScheduleDAGSDNodes.h"
15#include "InstrEmitter.h"
16#include "SDNodeDbgValue.h"
17#include "llvm/ADT/DenseMap.h"
19#include "llvm/ADT/SmallSet.h"
21#include "llvm/ADT/Statistic.h"
29#include "llvm/Config/llvm-config.h"
33#include "llvm/Support/Debug.h"
36using namespace llvm;
37
38#define DEBUG_TYPE "pre-RA-sched"
39
40STATISTIC(LoadsClustered, "Number of loads clustered together");
41
42// This allows the latency-based scheduler to notice high latency instructions
43// without a target itinerary. The choice of number here has more to do with
44// balancing scheduler heuristics than with the actual machine latency.
46 "sched-high-latency-cycles", cl::Hidden, cl::init(10),
47 cl::desc("Roughly estimate the number of cycles that 'long latency' "
48 "instructions take for targets with no itinerary"));
49
51 : ScheduleDAG(mf), InstrItins(mf.getSubtarget().getInstrItineraryData()) {}
52
53/// Run - perform scheduling.
54///
56 BB = bb;
57 DAG = dag;
58
59 // Clear the scheduler's SUnit DAG.
61 Sequence.clear();
62
63 // Invoke the target's selection of scheduler.
64 Schedule();
65}
66
67/// NewSUnit - Creates a new SUnit and return a ptr to it.
68///
70#ifndef NDEBUG
71 const SUnit *Addr = nullptr;
72 if (!SUnits.empty())
73 Addr = &SUnits[0];
74#endif
75 SUnits.emplace_back(N, (unsigned)SUnits.size());
76 assert((Addr == nullptr || Addr == &SUnits[0]) &&
77 "SUnits std::vector reallocated on the fly!");
78 SUnits.back().OrigNode = &SUnits.back();
79 SUnit *SU = &SUnits.back();
80 const TargetLowering &TLI = DAG->getTargetLoweringInfo();
81 if (!N ||
82 (N->isMachineOpcode() &&
83 N->getMachineOpcode() == TargetOpcode::IMPLICIT_DEF))
85 else
87 return SU;
88}
89
91 SUnit *SU = newSUnit(Old->getNode());
92 SU->OrigNode = Old->OrigNode;
93 SU->Latency = Old->Latency;
94 SU->isVRegCycle = Old->isVRegCycle;
95 SU->isCall = Old->isCall;
96 SU->isCallOp = Old->isCallOp;
97 SU->isTwoAddress = Old->isTwoAddress;
98 SU->isCommutable = Old->isCommutable;
102 SU->isScheduleLow = Old->isScheduleLow;
104 Old->isCloned = true;
105 return SU;
106}
107
108/// CheckForPhysRegDependency - Check if the dependency between def and use of
109/// a specified operand is a physical register dependency. If so, returns the
110/// register and the cost of copying the register.
111static void CheckForPhysRegDependency(SDNode *Def, SDNode *User, unsigned Op,
112 const TargetRegisterInfo *TRI,
113 const TargetInstrInfo *TII,
114 MCRegister &PhysReg, int &Cost) {
115 if (Op != 2 || User->getOpcode() != ISD::CopyToReg)
116 return;
117
119 if (Reg.isVirtual())
120 return;
121
122 unsigned ResNo = User->getOperand(2).getResNo();
123 if (Def->getOpcode() == ISD::CopyFromReg &&
124 cast<RegisterSDNode>(Def->getOperand(1))->getReg() == Reg) {
125 PhysReg = Reg;
126 } else if (Def->isMachineOpcode()) {
127 const MCInstrDesc &II = TII->get(Def->getMachineOpcode());
128 if (ResNo >= II.getNumDefs() && II.hasImplicitDefOfPhysReg(Reg))
129 PhysReg = Reg;
130 }
131
132 if (PhysReg) {
133 const TargetRegisterClass *RC =
134 TRI->getMinimalPhysRegClass(Reg, Def->getSimpleValueType(ResNo));
135 Cost = RC->expensiveOrImpossibleToCopy() ? -1 : RC->getCopyCost();
136 }
137}
138
139// Helper for AddGlue to clone node operands.
141 SDValue ExtraOper = SDValue()) {
143 if (ExtraOper.getNode())
144 Ops.push_back(ExtraOper);
145
146 SDVTList VTList = DAG->getVTList(VTs);
148
149 // Store memory references.
151 if (MN)
152 MMOs.assign(MN->memoperands_begin(), MN->memoperands_end());
153
154 DAG->MorphNodeTo(N, N->getOpcode(), VTList, Ops);
155
156 // Reset the memory references
157 if (MN)
158 DAG->setNodeMemRefs(MN, MMOs);
159}
160
161static bool AddGlue(SDNode *N, SDValue Glue, bool AddGlue, SelectionDAG *DAG) {
162 SDNode *GlueDestNode = Glue.getNode();
163
164 // Don't add glue from a node to itself.
165 if (GlueDestNode == N) return false;
166
167 // Don't add a glue operand to something that already uses glue.
168 if (GlueDestNode &&
169 N->getOperand(N->getNumOperands()-1).getValueType() == MVT::Glue) {
170 return false;
171 }
172 // Don't add glue to something that already has a glue value.
173 if (N->getValueType(N->getNumValues() - 1) == MVT::Glue) return false;
174
175 SmallVector<EVT, 4> VTs(N->values());
176 if (AddGlue)
177 VTs.push_back(MVT::Glue);
178
179 CloneNodeWithValues(N, DAG, VTs, Glue);
180
181 return true;
182}
183
184// Cleanup after unsuccessful AddGlue. Use the standard method of morphing the
185// node even though simply shrinking the value list is sufficient.
187 assert((N->getValueType(N->getNumValues() - 1) == MVT::Glue &&
188 !N->hasAnyUseOfValue(N->getNumValues() - 1)) &&
189 "expected an unused glue value");
190
192 ArrayRef(N->value_begin(), N->getNumValues() - 1));
193}
194
195/// ClusterNeighboringLoads - Force nearby loads together by "gluing" them.
196/// This function finds loads of the same base and different offsets. If the
197/// offsets are not far apart (target specific), it add MVT::Glue inputs and
198/// outputs to ensure they are scheduled together and in order. This
199/// optimization may benefit some targets by improving cache locality.
200void ScheduleDAGSDNodes::ClusterNeighboringLoads(SDNode *Node) {
201 SDValue Chain;
202 unsigned NumOps = Node->getNumOperands();
203 if (Node->getOperand(NumOps-1).getValueType() == MVT::Other)
204 Chain = Node->getOperand(NumOps-1);
205 if (!Chain)
206 return;
207
208 // Skip any load instruction that has a tied input. There may be an additional
209 // dependency requiring a different order than by increasing offsets, and the
210 // added glue may introduce a cycle.
211 auto hasTiedInput = [this](const SDNode *N) {
212 const MCInstrDesc &MCID = TII->get(N->getMachineOpcode());
213 for (unsigned I = 0; I != MCID.getNumOperands(); ++I) {
214 if (MCID.getOperandConstraint(I, MCOI::TIED_TO) != -1)
215 return true;
216 }
217
218 return false;
219 };
220
221 // Look for other loads of the same chain. Find loads that are loading from
222 // the same base pointer and different offsets.
223 SmallPtrSet<SDNode*, 16> Visited;
225 DenseMap<long long, SDNode*> O2SMap; // Map from offset to SDNode.
226 bool Cluster = false;
227 SDNode *Base = Node;
228
229 if (hasTiedInput(Base))
230 return;
231
232 // This algorithm requires a reasonably low use count before finding a match
233 // to avoid uselessly blowing up compile time in large blocks.
234 unsigned UseCount = 0;
235 for (SDNode::user_iterator I = Chain->user_begin(), E = Chain->user_end();
236 I != E && UseCount < 100; ++I, ++UseCount) {
237 if (I.getUse().getResNo() != Chain.getResNo())
238 continue;
239
240 SDNode *User = *I;
241 if (User == Node || !Visited.insert(User).second)
242 continue;
243 int64_t Offset1, Offset2;
244 if (!TII->areLoadsFromSameBasePtr(Base, User, Offset1, Offset2) ||
245 Offset1 == Offset2 ||
246 hasTiedInput(User)) {
247 // FIXME: Should be ok if they addresses are identical. But earlier
248 // optimizations really should have eliminated one of the loads.
249 continue;
250 }
251 if (O2SMap.insert(std::make_pair(Offset1, Base)).second)
252 Offsets.push_back(Offset1);
253 O2SMap.insert(std::make_pair(Offset2, User));
254 Offsets.push_back(Offset2);
255 if (Offset2 < Offset1)
256 Base = User;
257 Cluster = true;
258 // Reset UseCount to allow more matches.
259 UseCount = 0;
260 }
261
262 if (!Cluster)
263 return;
264
265 // Sort them in increasing order.
266 llvm::sort(Offsets);
267
268 // Check if the loads are close enough.
270 unsigned NumLoads = 0;
271 int64_t BaseOff = Offsets[0];
272 SDNode *BaseLoad = O2SMap[BaseOff];
273 Loads.push_back(BaseLoad);
274 for (unsigned i = 1, e = Offsets.size(); i != e; ++i) {
275 int64_t Offset = Offsets[i];
276 SDNode *Load = O2SMap[Offset];
277 if (!TII->shouldScheduleLoadsNear(BaseLoad, Load, BaseOff, Offset,NumLoads))
278 break; // Stop right here. Ignore loads that are further away.
279 Loads.push_back(Load);
280 ++NumLoads;
281 }
282
283 if (NumLoads == 0)
284 return;
285
286 // Cluster loads by adding MVT::Glue outputs and inputs. This also
287 // ensure they are scheduled in order of increasing addresses.
288 SDNode *Lead = Loads[0];
289 SDValue InGlue;
290 if (AddGlue(Lead, InGlue, true, DAG))
291 InGlue = SDValue(Lead, Lead->getNumValues() - 1);
292 for (unsigned I = 1, E = Loads.size(); I != E; ++I) {
293 bool OutGlue = I < E - 1;
294 SDNode *Load = Loads[I];
295
296 // If AddGlue fails, we could leave an unsused glue value. This should not
297 // cause any
298 if (AddGlue(Load, InGlue, OutGlue, DAG)) {
299 if (OutGlue)
300 InGlue = SDValue(Load, Load->getNumValues() - 1);
301
302 ++LoadsClustered;
303 }
304 else if (!OutGlue && InGlue.getNode())
305 RemoveUnusedGlue(InGlue.getNode(), DAG);
306 }
307}
308
309/// ClusterNodes - Cluster certain nodes which should be scheduled together.
310///
311void ScheduleDAGSDNodes::ClusterNodes() {
312 for (SDNode &NI : DAG->allnodes()) {
313 SDNode *Node = &NI;
314 if (!Node || !Node->isMachineOpcode())
315 continue;
316
317 unsigned Opc = Node->getMachineOpcode();
318 const MCInstrDesc &MCID = TII->get(Opc);
319 if (MCID.mayLoad())
320 // Cluster loads from "near" addresses into combined SUnits.
321 ClusterNeighboringLoads(Node);
322 }
323}
324
325void ScheduleDAGSDNodes::BuildSchedUnits() {
326 // During scheduling, the NodeId field of SDNode is used to map SDNodes
327 // to their associated SUnits by holding SUnits table indices. A value
328 // of -1 means the SDNode does not yet have an associated SUnit.
329 unsigned NumNodes = 0;
330 for (SDNode &NI : DAG->allnodes()) {
331 NI.setNodeId(-1);
332 NI.setSchedulerWorklistVisited(false);
333 ++NumNodes;
334 }
335
336 // Reserve entries in the vector for each of the SUnits we are creating. This
337 // ensure that reallocation of the vector won't happen, so SUnit*'s won't get
338 // invalidated.
339 // FIXME: Multiply by 2 because we may clone nodes during scheduling.
340 // This is a temporary workaround.
341 SUnits.reserve(NumNodes * 2);
342
343 // Add all nodes in depth first order.
345 SmallPtrSet<SDNode*, 32> Visited;
346 Worklist.push_back(DAG->getRoot().getNode());
347 DAG->getRoot().getNode()->setSchedulerWorklistVisited(true);
348
349 SmallVector<SUnit*, 8> CallSUnits;
350 while (!Worklist.empty()) {
351 SDNode *NI = Worklist.pop_back_val();
352
353 // Add all operands to the worklist unless they've already been added.
354 for (const SDValue &Op : NI->op_values()) {
355 if (Op.getNode()->getSchedulerWorklistVisited())
356 continue;
357 Op.getNode()->setSchedulerWorklistVisited(true);
358 Worklist.push_back(Op.getNode());
359 }
360
361 if (isPassiveNode(NI)) // Leaf node, e.g. a TargetImmediate.
362 continue;
363
364 // If this node has already been processed, stop now.
365 if (NI->getNodeId() != -1) continue;
366
367 SUnit *NodeSUnit = newSUnit(NI);
368
369 // See if anything is glued to this node, if so, add them to glued
370 // nodes. Nodes can have at most one glue input and one glue output. Glue
371 // is required to be the last operand and result of a node.
372
373 // Scan up to find glued preds.
374 SDNode *N = NI;
375 while (N->getNumOperands() &&
376 N->getOperand(N->getNumOperands()-1).getValueType() == MVT::Glue) {
377 N = N->getOperand(N->getNumOperands()-1).getNode();
378 assert(N->getNodeId() == -1 && "Node already inserted!");
379 N->setNodeId(NodeSUnit->NodeNum);
380 if (N->isMachineOpcode() && TII->get(N->getMachineOpcode()).isCall())
381 NodeSUnit->isCall = true;
382 }
383
384 // Scan down to find any glued succs.
385 N = NI;
386 while (N->getValueType(N->getNumValues()-1) == MVT::Glue) {
387 SDValue GlueVal(N, N->getNumValues()-1);
388
389 // There are either zero or one users of the Glue result.
390 bool HasGlueUse = false;
391 for (SDNode *U : N->users())
392 if (GlueVal.isOperandOf(U)) {
393 HasGlueUse = true;
394 assert(N->getNodeId() == -1 && "Node already inserted!");
395 N->setNodeId(NodeSUnit->NodeNum);
396 N = U;
397 if (N->isMachineOpcode() && TII->get(N->getMachineOpcode()).isCall())
398 NodeSUnit->isCall = true;
399 break;
400 }
401 if (!HasGlueUse) break;
402 }
403
404 if (NodeSUnit->isCall)
405 CallSUnits.push_back(NodeSUnit);
406
407 // Schedule zero-latency TokenFactor below any nodes that may increase the
408 // schedule height. Otherwise, ancestors of the TokenFactor may appear to
409 // have false stalls.
410 if (NI->getOpcode() == ISD::TokenFactor)
411 NodeSUnit->isScheduleLow = true;
412
413 // If there are glue operands involved, N is now the bottom-most node
414 // of the sequence of nodes that are glued together.
415 // Update the SUnit.
416 NodeSUnit->setNode(N);
417 assert(N->getNodeId() == -1 && "Node already inserted!");
418 N->setNodeId(NodeSUnit->NodeNum);
419
420 // Compute NumRegDefsLeft. This must be done before AddSchedEdges.
421 InitNumRegDefsLeft(NodeSUnit);
422
423 // Assign the Latency field of NodeSUnit using target-provided information.
424 computeLatency(NodeSUnit);
425 }
426
427 // Find all call operands.
428 while (!CallSUnits.empty()) {
429 SUnit *SU = CallSUnits.pop_back_val();
430 for (const SDNode *SUNode = SU->getNode(); SUNode;
431 SUNode = SUNode->getGluedNode()) {
432 if (SUNode->getOpcode() != ISD::CopyToReg)
433 continue;
434 SDNode *SrcN = SUNode->getOperand(2).getNode();
435 if (isPassiveNode(SrcN)) continue; // Not scheduled.
436 SUnit *SrcSU = &SUnits[SrcN->getNodeId()];
437 SrcSU->isCallOp = true;
438 }
439 }
440}
441
442void ScheduleDAGSDNodes::AddSchedEdges() {
443 const TargetSubtargetInfo &ST = MF.getSubtarget();
444
445 // Check to see if the scheduler cares about latencies.
446 bool UnitLatencies = forceUnitLatencies();
447
448 // Pass 2: add the preds, succs, etc.
449 for (SUnit &SU : SUnits) {
450 SDNode *MainNode = SU.getNode();
451
452 if (MainNode->isMachineOpcode()) {
453 unsigned Opc = MainNode->getMachineOpcode();
454 const MCInstrDesc &MCID = TII->get(Opc);
455 for (unsigned i = 0; i != MCID.getNumOperands(); ++i) {
456 if (MCID.getOperandConstraint(i, MCOI::TIED_TO) != -1) {
457 SU.isTwoAddress = true;
458 break;
459 }
460 }
461 if (MCID.isCommutable())
462 SU.isCommutable = true;
463 }
464
465 // Find all predecessors and successors of the group.
466 for (SDNode *N = SU.getNode(); N; N = N->getGluedNode()) {
467 if (N->isMachineOpcode() &&
468 !TII->get(N->getMachineOpcode()).implicit_defs().empty()) {
469 SU.hasPhysRegClobbers = true;
470 unsigned NumUsed = InstrEmitter::CountResults(N);
471 while (NumUsed != 0 && !N->hasAnyUseOfValue(NumUsed - 1))
472 --NumUsed; // Skip over unused values at the end.
473 if (NumUsed > TII->get(N->getMachineOpcode()).getNumDefs())
474 SU.hasPhysRegDefs = true;
475 }
476
477 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
478 SDNode *OpN = N->getOperand(i).getNode();
479 unsigned DefIdx = N->getOperand(i).getResNo();
480 if (isPassiveNode(OpN)) continue; // Not scheduled.
481 SUnit *OpSU = &SUnits[OpN->getNodeId()];
482 assert(OpSU && "Node has no SUnit!");
483 if (OpSU == &SU)
484 continue; // In the same group.
485
486 EVT OpVT = N->getOperand(i).getValueType();
487 assert(OpVT != MVT::Glue && "Glued nodes should be in same sunit!");
488 bool isChain = OpVT == MVT::Other;
489
490 MCRegister PhysReg;
491 int Cost = 1;
492 // Determine if this is a physical register dependency.
493 CheckForPhysRegDependency(OpN, N, i, TRI, TII, PhysReg, Cost);
494 assert((!PhysReg || !isChain) && "Chain dependence via physreg data?");
495 // FIXME: See ScheduleDAGSDNodes::EmitCopyFromReg. For now, scheduler
496 // emits a copy from the physical register to a virtual register unless
497 // it requires a cross class copy (cost < 0). That means we are only
498 // treating "expensive to copy" register dependency as physical register
499 // dependency. This may change in the future though.
500 if (Cost >= 0 && !StressSched)
501 PhysReg = MCRegister();
502
503 // If this is a ctrl dep, latency is 1.
504 unsigned OpLatency = isChain ? 1 : OpSU->Latency;
505 // Special-case TokenFactor chains as zero-latency.
506 if(isChain && OpN->getOpcode() == ISD::TokenFactor)
507 OpLatency = 0;
508
509 SDep Dep = isChain ? SDep(OpSU, SDep::Barrier)
510 : SDep(OpSU, SDep::Data, PhysReg);
511 Dep.setLatency(OpLatency);
512 if (!isChain && !UnitLatencies) {
513 computeOperandLatency(OpN, N, i, Dep);
514 ST.adjustSchedDependency(OpSU, DefIdx, &SU, i, Dep, nullptr);
515 }
516
517 if (!SU.addPred(Dep) && !Dep.isCtrl() && OpSU->NumRegDefsLeft > 1) {
518 // Multiple register uses are combined in the same SUnit. For example,
519 // we could have a set of glued nodes with all their defs consumed by
520 // another set of glued nodes. Register pressure tracking sees this as
521 // a single use, so to keep pressure balanced we reduce the defs.
522 //
523 // We can't tell (without more book-keeping) if this results from
524 // glued nodes or duplicate operands. As long as we don't reduce
525 // NumRegDefsLeft to zero, we handle the common cases well.
526 --OpSU->NumRegDefsLeft;
527 }
528 }
529 }
530 }
531}
532
533/// BuildSchedGraph - Build the SUnit graph from the selection dag that we
534/// are input. This SUnit graph is similar to the SelectionDAG, but
535/// excludes nodes that aren't interesting to scheduling, and represents
536/// glued together nodes with a single SUnit.
538 // Cluster certain nodes which should be scheduled together.
539 ClusterNodes();
540 // Populate the SUnits array.
541 BuildSchedUnits();
542 // Compute all the scheduling dependencies between nodes.
543 AddSchedEdges();
544}
545
546// Initialize NumNodeDefs for the current Node's opcode.
547void ScheduleDAGSDNodes::RegDefIter::InitNodeNumDefs() {
548 // Check for phys reg copy.
549 if (!Node)
550 return;
551
552 if (!Node->isMachineOpcode()) {
553 if (Node->getOpcode() == ISD::CopyFromReg)
554 NodeNumDefs = 1;
555 else
556 NodeNumDefs = 0;
557 return;
558 }
559 unsigned POpc = Node->getMachineOpcode();
560 if (POpc == TargetOpcode::IMPLICIT_DEF) {
561 // No register need be allocated for this.
562 NodeNumDefs = 0;
563 return;
564 }
565 if (POpc == TargetOpcode::PATCHPOINT &&
566 Node->getValueType(0) == MVT::Other) {
567 // PATCHPOINT is defined to have one result, but it might really have none
568 // if we're not using CallingConv::AnyReg. Don't mistake the chain for a
569 // real definition.
570 NodeNumDefs = 0;
571 return;
572 }
573 unsigned NRegDefs = SchedDAG->TII->get(Node->getMachineOpcode()).getNumDefs();
574 // Some instructions define regs that are not represented in the selection DAG
575 // (e.g. unused flags). See tMOVi8. Make sure we don't access past NumValues.
576 NodeNumDefs = std::min(Node->getNumValues(), NRegDefs);
577 DefIdx = 0;
578}
579
580// Construct a RegDefIter for this SUnit and find the first valid value.
582 const ScheduleDAGSDNodes *SD)
583 : SchedDAG(SD), Node(SU->getNode()) {
584 InitNodeNumDefs();
585 Advance();
586}
587
588// Advance to the next valid value defined by the SUnit.
590 for (;Node;) { // Visit all glued nodes.
591 for (;DefIdx < NodeNumDefs; ++DefIdx) {
592 if (!Node->hasAnyUseOfValue(DefIdx))
593 continue;
594 ValueType = Node->getSimpleValueType(DefIdx);
595 ++DefIdx;
596 return; // Found a normal regdef.
597 }
598 Node = Node->getGluedNode();
599 if (!Node) {
600 return; // No values left to visit.
601 }
602 InitNodeNumDefs();
603 }
604}
605
607 assert(SU->NumRegDefsLeft == 0 && "expect a new node");
608 for (RegDefIter I(SU, this); I.IsValid(); I.Advance()) {
609 assert(SU->NumRegDefsLeft < USHRT_MAX && "overflow is ok but unexpected");
610 ++SU->NumRegDefsLeft;
611 }
612}
613
615 SDNode *N = SU->getNode();
616
617 // TokenFactor operands are considered zero latency, and some schedulers
618 // (e.g. Top-Down list) may rely on the fact that operand latency is nonzero
619 // whenever node latency is nonzero.
620 if (N && N->getOpcode() == ISD::TokenFactor) {
621 SU->Latency = 0;
622 return;
623 }
624
625 // Check to see if the scheduler cares about latencies.
626 if (forceUnitLatencies()) {
627 SU->Latency = 1;
628 return;
629 }
630
631 if (!InstrItins || InstrItins->isEmpty()) {
632 if (N && N->isMachineOpcode() &&
633 TII->isHighLatencyDef(N->getMachineOpcode()))
635 else
636 SU->Latency = 1;
637 return;
638 }
639
640 // Compute the latency for the node. We use the sum of the latencies for
641 // all nodes glued together into this SUnit.
642 SU->Latency = 0;
643 for (SDNode *N = SU->getNode(); N; N = N->getGluedNode())
644 if (N->isMachineOpcode())
645 SU->Latency += TII->getInstrLatency(InstrItins, N);
646}
647
649 unsigned OpIdx, SDep& dep) const{
650 // Check to see if the scheduler cares about latencies.
651 if (forceUnitLatencies())
652 return;
653
654 if (dep.getKind() != SDep::Data)
655 return;
656
657 unsigned DefIdx = Use->getOperand(OpIdx).getResNo();
658 if (Use->isMachineOpcode())
659 // Adjust the use operand index by num of defs.
660 OpIdx += TII->get(Use->getMachineOpcode()).getNumDefs();
661 std::optional<unsigned> Latency =
662 TII->getOperandLatency(InstrItins, Def, DefIdx, Use, OpIdx);
663 if (Latency > 1U && Use->getOpcode() == ISD::CopyToReg &&
664 !BB->succ_empty()) {
665 Register Reg = cast<RegisterSDNode>(Use->getOperand(1))->getReg();
666 if (Reg.isVirtual())
667 // This copy is a liveout value. It is likely coalesced, so reduce the
668 // latency so not to penalize the def.
669 // FIXME: need target specific adjustment here?
670 Latency = *Latency - 1;
671 }
672 if (Latency)
673 dep.setLatency(*Latency);
674}
675
676void ScheduleDAGSDNodes::dumpNode(const SUnit &SU) const {
677#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
678 dumpNodeName(SU);
679 dbgs() << ": ";
680
681 if (!SU.getNode()) {
682 dbgs() << "PHYS REG COPY\n";
683 return;
684 }
685
686 SU.getNode()->dump(DAG);
687 dbgs() << "\n";
688 SmallVector<SDNode *, 4> GluedNodes;
689 for (SDNode *N = SU.getNode()->getGluedNode(); N; N = N->getGluedNode())
690 GluedNodes.push_back(N);
691 while (!GluedNodes.empty()) {
692 dbgs() << " ";
693 GluedNodes.back()->dump(DAG);
694 dbgs() << "\n";
695 GluedNodes.pop_back();
696 }
697#endif
698}
699
701#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
702 if (EntrySU.getNode() != nullptr)
704 for (const SUnit &SU : SUnits)
705 dumpNodeAll(SU);
706 if (ExitSU.getNode() != nullptr)
708#endif
709}
710
711#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
713 for (const SUnit *SU : Sequence) {
714 if (SU)
715 dumpNode(*SU);
716 else
717 dbgs() << "**** NOOP ****\n";
718 }
719}
720#endif
721
722#ifndef NDEBUG
723/// VerifyScheduledSequence - Verify that all SUnits were scheduled and that
724/// their state is consistent with the nodes listed in Sequence.
725///
727 unsigned ScheduledNodes = ScheduleDAG::VerifyScheduledDAG(isBottomUp);
728 unsigned Noops = llvm::count(Sequence, nullptr);
729 assert(Sequence.size() - Noops == ScheduledNodes &&
730 "The number of nodes scheduled doesn't match the expected number!");
731}
732#endif // NDEBUG
733
734/// ProcessSDDbgValues - Process SDDbgValues associated with this node.
735static void
737 SmallVectorImpl<std::pair<unsigned, MachineInstr*> > &Orders,
738 InstrEmitter::VRBaseMapType &VRBaseMap, unsigned Order) {
739 if (!N->getHasDebugValue())
740 return;
741
742 /// Returns true if \p DV has any VReg operand locations which don't exist in
743 /// VRBaseMap.
744 auto HasUnknownVReg = [&VRBaseMap](SDDbgValue *DV) {
745 for (const SDDbgOperand &L : DV->getLocationOps()) {
746 if (L.getKind() == SDDbgOperand::SDNODE &&
747 VRBaseMap.count({L.getSDNode(), L.getResNo()}) == 0)
748 return true;
749 }
750 return false;
751 };
752
753 // Opportunistically insert immediate dbg_value uses, i.e. those with the same
754 // source order number as N.
755 MachineBasicBlock *BB = Emitter.getBlock();
756 MachineBasicBlock::iterator InsertPos = Emitter.getInsertPos();
757 for (auto *DV : DAG->GetDbgValues(N)) {
758 if (DV->isEmitted())
759 continue;
760 unsigned DVOrder = DV->getOrder();
761 if (Order != 0 && DVOrder != Order)
762 continue;
763 // If DV has any VReg location operands which haven't been mapped then
764 // either that node is no longer available or we just haven't visited the
765 // node yet. In the former case we should emit an undef dbg_value, but we
766 // can do it later. And for the latter we'll want to wait until all
767 // dependent nodes have been visited.
768 if (!DV->isInvalidated() && HasUnknownVReg(DV))
769 continue;
770 MachineInstr *DbgMI = Emitter.EmitDbgValue(DV, VRBaseMap);
771 if (!DbgMI)
772 continue;
773 Orders.push_back({DVOrder, DbgMI});
774 BB->insert(InsertPos, DbgMI);
775 }
776}
777
778// ProcessSourceNode - Process nodes with source order numbers. These are added
779// to a vector which EmitSchedule uses to determine how to insert dbg_value
780// instructions in the right order.
781static void
784 SmallVectorImpl<std::pair<unsigned, MachineInstr *>> &Orders,
785 SmallSet<Register, 8> &Seen, MachineInstr *NewInsn) {
786 unsigned Order = N->getIROrder();
787 if (!Order || Seen.count(Order)) {
788 // Process any valid SDDbgValues even if node does not have any order
789 // assigned.
790 ProcessSDDbgValues(N, DAG, Emitter, Orders, VRBaseMap, 0);
791 return;
792 }
793
794 // If a new instruction was generated for this Order number, record it.
795 // Otherwise, leave this order number unseen: we will either find later
796 // instructions for it, or leave it unseen if there were no instructions at
797 // all.
798 if (NewInsn) {
799 Seen.insert(Order);
800 Orders.push_back({Order, NewInsn});
801 }
802
803 // Even if no instruction was generated, a Value may have become defined via
804 // earlier nodes. Try to process them now.
805 ProcessSDDbgValues(N, DAG, Emitter, Orders, VRBaseMap, Order);
806}
807
808void ScheduleDAGSDNodes::
809EmitPhysRegCopy(SUnit *SU, SmallDenseMap<SUnit *, Register, 16> &VRBaseMap,
810 MachineBasicBlock::iterator InsertPos) {
811 for (const SDep &Pred : SU->Preds) {
812 if (Pred.isCtrl())
813 continue; // ignore chain preds
814 if (Pred.getSUnit()->CopyDstRC) {
815 // Copy to physical register.
817 VRBaseMap.find(Pred.getSUnit());
818 assert(VRI != VRBaseMap.end() && "Node emitted out of order - late");
819 // Find the destination physical register.
821 for (const SDep &Succ : SU->Succs) {
822 if (Succ.isCtrl())
823 continue; // ignore chain preds
824 if (Succ.getReg()) {
825 Reg = Succ.getReg();
826 break;
827 }
828 }
829 BuildMI(*BB, InsertPos, DebugLoc(), TII->get(TargetOpcode::COPY), Reg)
830 .addReg(VRI->second);
831 } else {
832 // Copy from physical register.
833 assert(Pred.getReg() && "Unknown physical register!");
834 Register VRBase = MRI.createVirtualRegister(SU->CopyDstRC);
835 bool isNew = VRBaseMap.insert(std::make_pair(SU, VRBase)).second;
836 (void)isNew; // Silence compiler warning.
837 assert(isNew && "Node emitted out of order - early");
838 BuildMI(*BB, InsertPos, DebugLoc(), TII->get(TargetOpcode::COPY), VRBase)
839 .addReg(Pred.getReg());
840 }
841 break;
842 }
843}
844
845/// EmitSchedule - Emit the machine code in scheduled order. Return the new
846/// InsertPos and MachineBasicBlock that contains this insertion
847/// point. ScheduleDAGSDNodes holds a BB pointer for convenience, but this does
848/// not necessarily refer to returned BB. The emitter may split blocks.
851 InstrEmitter Emitter(DAG->getTarget(), BB, InsertPos);
856 bool HasDbg = DAG->hasDebugValues();
857
858 // Emit a node, and determine where its first instruction is for debuginfo.
859 // Zero, one, or multiple instructions can be created when emitting a node.
860 auto EmitNode =
861 [&](SDNode *Node, bool IsClone, bool IsCloned,
863 // Fetch instruction prior to this, or end() if nonexistant.
864 auto GetPrevInsn = [&](MachineBasicBlock::iterator I) {
865 if (I == BB->begin())
866 return BB->end();
867 else
868 return std::prev(Emitter.getInsertPos());
869 };
870
871 MachineBasicBlock::iterator Before = GetPrevInsn(Emitter.getInsertPos());
872 Emitter.EmitNode(Node, IsClone, IsCloned, VRBaseMap);
873 MachineBasicBlock::iterator After = GetPrevInsn(Emitter.getInsertPos());
874
875 // If the iterator did not change, no instructions were inserted.
876 if (Before == After)
877 return nullptr;
878
880 if (Before == BB->end()) {
881 // There were no prior instructions; the new ones must start at the
882 // beginning of the block.
883 MI = &Emitter.getBlock()->instr_front();
884 } else {
885 // Return first instruction after the pre-existing instructions.
886 MI = &*std::next(Before);
887 }
888
889 if (MI->isCandidateForAdditionalCallInfo()) {
890 if (DAG->getTarget().Options.EmitCallSiteInfo ||
891 DAG->getTarget().Options.EmitCallGraphSection)
892 MF.addCallSiteInfo(MI, DAG->getCallSiteInfo(Node));
893
894 if (auto CalledGlobal = DAG->getCalledGlobal(Node))
895 if (CalledGlobal->Callee)
896 MF.addCalledGlobal(MI, *CalledGlobal);
897 }
898
899 if (DAG->getNoMergeSiteInfo(Node)) {
901 }
902
903 if (MDNode *MD = DAG->getPCSections(Node))
904 MI->setPCSections(MF, MD);
905
906 // Set MMRAs on _all_ added instructions.
907 if (MDNode *MMRA = DAG->getMMRAMetadata(Node)) {
908 for (MachineBasicBlock::iterator It = MI->getIterator(),
909 End = std::next(After);
910 It != End; ++It)
911 It->setMMRAMetadata(MF, MMRA);
912 }
913
914 return MI;
915 };
916
917 // If this is the first BB, emit byval parameter dbg_value's.
918 if (HasDbg && BB->getParent()->begin() == MachineFunction::iterator(BB)) {
919 SDDbgInfo::DbgIterator PDI = DAG->ByvalParmDbgBegin();
920 SDDbgInfo::DbgIterator PDE = DAG->ByvalParmDbgEnd();
921 for (; PDI != PDE; ++PDI) {
922 MachineInstr *DbgMI= Emitter.EmitDbgValue(*PDI, VRBaseMap);
923 if (DbgMI) {
924 BB->insert(InsertPos, DbgMI);
925 // We re-emit the dbg_value closer to its use, too, after instructions
926 // are emitted to the BB.
927 (*PDI)->clearIsEmitted();
928 }
929 }
930 }
931
932 for (SUnit *SU : Sequence) {
933 if (!SU) {
934 // Null SUnit* is a noop.
935 TII->insertNoop(*Emitter.getBlock(), InsertPos);
936 continue;
937 }
938
939 // For pre-regalloc scheduling, create instructions corresponding to the
940 // SDNode and any glued SDNodes and append them to the block.
941 if (!SU->getNode()) {
942 // Emit a copy.
943 EmitPhysRegCopy(SU, CopyVRBaseMap, InsertPos);
944 continue;
945 }
946
947 SmallVector<SDNode *, 4> GluedNodes;
948 for (SDNode *N = SU->getNode()->getGluedNode(); N; N = N->getGluedNode())
949 GluedNodes.push_back(N);
950 while (!GluedNodes.empty()) {
951 SDNode *N = GluedNodes.back();
952 auto NewInsn = EmitNode(N, SU->OrigNode != SU, SU->isCloned, VRBaseMap);
953 // Remember the source order of the inserted instruction.
954 if (HasDbg)
955 ProcessSourceNode(N, DAG, Emitter, VRBaseMap, Orders, Seen, NewInsn);
956
957 if (MDNode *MD = DAG->getHeapAllocSite(N))
958 if (NewInsn && NewInsn->isCall())
959 NewInsn->setHeapAllocMarker(MF, MD);
960
961 GluedNodes.pop_back();
962 }
963 auto NewInsn =
964 EmitNode(SU->getNode(), SU->OrigNode != SU, SU->isCloned, VRBaseMap);
965 // Remember the source order of the inserted instruction.
966 if (HasDbg)
967 ProcessSourceNode(SU->getNode(), DAG, Emitter, VRBaseMap, Orders, Seen,
968 NewInsn);
969
970 if (MDNode *MD = DAG->getHeapAllocSite(SU->getNode())) {
971 if (NewInsn && NewInsn->isCall())
972 NewInsn->setHeapAllocMarker(MF, MD);
973 }
974 }
975
976 // Insert all the dbg_values which have not already been inserted in source
977 // order sequence.
978 if (HasDbg) {
979 MachineBasicBlock::iterator BBBegin = BB->getFirstNonPHI();
980
981 // Sort the source order instructions and use the order to insert debug
982 // values. Use stable_sort so that DBG_VALUEs are inserted in the same order
983 // regardless of the host's implementation fo std::sort.
984 llvm::stable_sort(Orders, less_first());
985 std::stable_sort(DAG->DbgBegin(), DAG->DbgEnd(),
986 [](const SDDbgValue *LHS, const SDDbgValue *RHS) {
987 return LHS->getOrder() < RHS->getOrder();
988 });
989
990 SDDbgInfo::DbgIterator DI = DAG->DbgBegin();
991 SDDbgInfo::DbgIterator DE = DAG->DbgEnd();
992 // Now emit the rest according to source order.
993 unsigned LastOrder = 0;
994 for (unsigned i = 0, e = Orders.size(); i != e && DI != DE; ++i) {
995 unsigned Order = Orders[i].first;
996 MachineInstr *MI = Orders[i].second;
997 // Insert all SDDbgValue's whose order(s) are before "Order".
998 assert(MI);
999 for (; DI != DE; ++DI) {
1000 if ((*DI)->getOrder() < LastOrder || (*DI)->getOrder() >= Order)
1001 break;
1002 if ((*DI)->isEmitted())
1003 continue;
1004
1005 MachineInstr *DbgMI = Emitter.EmitDbgValue(*DI, VRBaseMap);
1006 if (DbgMI) {
1007 if (!LastOrder)
1008 // Insert to start of the BB (after PHIs).
1009 BB->insert(BBBegin, DbgMI);
1010 else {
1011 // Insert at the instruction, which may be in a different
1012 // block, if the block was split by a custom inserter.
1014 MI->getParent()->insert(Pos, DbgMI);
1015 }
1016 }
1017 }
1018 LastOrder = Order;
1019 }
1020 // Add trailing DbgValue's before the terminator. FIXME: May want to add
1021 // some of them before one or more conditional branches?
1023 for (; DI != DE; ++DI) {
1024 if ((*DI)->isEmitted())
1025 continue;
1026 assert((*DI)->getOrder() >= LastOrder &&
1027 "emitting DBG_VALUE out of order");
1028 if (MachineInstr *DbgMI = Emitter.EmitDbgValue(*DI, VRBaseMap))
1029 DbgMIs.push_back(DbgMI);
1030 }
1031
1032 MachineBasicBlock *InsertBB = Emitter.getBlock();
1034 InsertBB->insert(Pos, DbgMIs.begin(), DbgMIs.end());
1035
1036 SDDbgInfo::DbgLabelIterator DLI = DAG->DbgLabelBegin();
1037 SDDbgInfo::DbgLabelIterator DLE = DAG->DbgLabelEnd();
1038 // Now emit the rest according to source order.
1039 LastOrder = 0;
1040 for (const auto &InstrOrder : Orders) {
1041 unsigned Order = InstrOrder.first;
1042 MachineInstr *MI = InstrOrder.second;
1043 if (!MI)
1044 continue;
1045
1046 // Insert all SDDbgLabel's whose order(s) are before "Order".
1047 for (; DLI != DLE &&
1048 (*DLI)->getOrder() >= LastOrder && (*DLI)->getOrder() < Order;
1049 ++DLI) {
1050 MachineInstr *DbgMI = Emitter.EmitDbgLabel(*DLI);
1051 if (DbgMI) {
1052 if (!LastOrder)
1053 // Insert to start of the BB (after PHIs).
1054 BB->insert(BBBegin, DbgMI);
1055 else {
1056 // Insert at the instruction, which may be in a different
1057 // block, if the block was split by a custom inserter.
1059 MI->getParent()->insert(Pos, DbgMI);
1060 }
1061 }
1062 }
1063 if (DLI == DLE)
1064 break;
1065
1066 LastOrder = Order;
1067 }
1068 }
1069
1070 InsertPos = Emitter.getInsertPos();
1071 // In some cases, DBG_VALUEs might be inserted after the first terminator,
1072 // which results in an invalid MBB. If that happens, move the DBG_VALUEs
1073 // before the first terminator.
1074 MachineBasicBlock *InsertBB = Emitter.getBlock();
1075 auto FirstTerm = InsertBB->getFirstTerminator();
1076 if (FirstTerm != InsertBB->end()) {
1077 assert(!FirstTerm->isDebugValue() &&
1078 "first terminator cannot be a debug value");
1080 make_range(std::next(FirstTerm), InsertBB->end()))) {
1081 // Only scan up to insertion point.
1082 if (&MI == InsertPos)
1083 break;
1084
1085 if (!MI.isDebugValue())
1086 continue;
1087
1088 // The DBG_VALUE was referencing a value produced by a terminator. By
1089 // moving the DBG_VALUE, the referenced value also needs invalidating.
1090 MI.getOperand(0).ChangeToRegister(0, false);
1091 MI.moveBefore(&*FirstTerm);
1092 }
1093 }
1094 return InsertBB;
1095}
1096
1097/// Return the basic block label.
1099 return "sunit-dag." + BB->getFullName();
1100}
return SDValue()
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static msgpack::DocNode getNode(msgpack::DocNode DN, msgpack::Type Type, MCValue Val)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
dxil DXContainer Global Emitter
This file defines the DenseMap class.
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
This file provides utility for Memory Model Relaxation Annotations (MMRAs).
MachineInstr unsigned OpIdx
uint64_t IntrinsicInst * II
static void ProcessSourceNode(SDNode *N, SelectionDAG *DAG, InstrEmitter &Emitter, InstrEmitter::VRBaseMapType &VRBaseMap, SmallVectorImpl< std::pair< unsigned, MachineInstr * > > &Orders, SmallSet< Register, 8 > &Seen, MachineInstr *NewInsn)
static bool AddGlue(SDNode *N, SDValue Glue, bool AddGlue, SelectionDAG *DAG)
static void RemoveUnusedGlue(SDNode *N, SelectionDAG *DAG)
static cl::opt< int > HighLatencyCycles("sched-high-latency-cycles", cl::Hidden, cl::init(10), cl::desc("Roughly estimate the number of cycles that 'long latency' " "instructions take for targets with no itinerary"))
static void CheckForPhysRegDependency(SDNode *Def, SDNode *User, unsigned Op, const TargetRegisterInfo *TRI, const TargetInstrInfo *TII, MCRegister &PhysReg, int &Cost)
CheckForPhysRegDependency - Check if the dependency between def and use of a specified operand is a p...
static void ProcessSDDbgValues(SDNode *N, SelectionDAG *DAG, InstrEmitter &Emitter, SmallVectorImpl< std::pair< unsigned, MachineInstr * > > &Orders, InstrEmitter::VRBaseMapType &VRBaseMap, unsigned Order)
ProcessSDDbgValues - Process SDDbgValues associated with this node.
static void CloneNodeWithValues(SDNode *N, SelectionDAG *DAG, ArrayRef< EVT > VTs, SDValue ExtraOper=SDValue())
This file defines the SmallPtrSet class.
This file defines the SmallSet class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:171
This file describes how to lower LLVM code to machine code.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
iterator find(const_arg_type_t< KeyT > Val)
Definition DenseMap.h:178
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT > iterator
Definition DenseMap.h:74
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition DenseMap.h:174
iterator end()
Definition DenseMap.h:81
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition DenseMap.h:241
SmallDenseMap< SDValue, Register, 16 > VRBaseMapType
static unsigned CountResults(SDNode *Node)
CountResults - The results of target nodes have register or immediate operands first,...
Describe properties that are true of each instruction in the target description file.
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
bool mayLoad() const
Return true if this instruction could possibly read memory.
int getOperandConstraint(unsigned OpNum, MCOI::OperandConstraint Constraint) const
Returns the value of the specified operand constraint if it is present.
bool isCommutable() const
Return true if this may be a 2- or 3-address instruction (of the form "X = op Y, Z,...
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
Metadata node.
Definition Metadata.h:1080
LLVM_ABI instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
LLVM_ABI iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
MachineInstrBundleIterator< MachineInstr > iterator
BasicBlockListType::iterator iterator
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
An SDNode that represents everything that will be needed to construct a MachineInstr.
mmo_iterator memoperands_begin() const
mmo_iterator memoperands_end() const
Wrapper class representing virtual and physical registers.
Definition Register.h:20
SmallVectorImpl< SDDbgLabel * >::iterator DbgLabelIterator
SmallVectorImpl< SDDbgValue * >::iterator DbgIterator
Holds the information for a single machine location through SDISel; either an SDNode,...
@ SDNODE
Value is the result of an expression.
Holds the information from a dbg_value node through SDISel.
Represents one node in the SelectionDAG.
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode.
int getNodeId() const
Return the unique node id.
LLVM_ABI void dump() const
Dump this node, for debugging.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
iterator_range< value_op_iterator > op_values() const
unsigned getNumValues() const
Return the number of values defined/returned by this operator.
unsigned getMachineOpcode() const
This may only be called if isMachineOpcode returns true.
static user_iterator user_end()
user_iterator user_begin() const
Provide iteration support to walk over all users of an SDNode.
SDNode * getGluedNode() const
If this node has a glue operand, return the node to which the glue operand points.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
SDNode * getNode() const
get the SDNode which holds the desired result
unsigned getResNo() const
get the index which selects a specific result in the SDNode
Scheduling dependency.
Definition ScheduleDAG.h:51
SUnit * getSUnit() const
Kind getKind() const
Returns an enum value representing the kind of the dependence.
@ Data
Regular data dependence (aka true-dependence).
Definition ScheduleDAG.h:55
void setLatency(unsigned Lat)
Sets the latency for this edge.
@ Barrier
An unknown scheduling barrier.
Definition ScheduleDAG.h:71
bool isCtrl() const
Shorthand for getKind() != SDep::Data.
Register getReg() const
Returns the register associated with this edge.
Scheduling unit. This is a node in the scheduling DAG.
bool isCloned
True if this node has been cloned.
bool isCall
Is a function call.
void setNode(SDNode *N)
Assigns the representative SDNode for this SUnit.
unsigned NodeNum
Entry # of node in the node vector.
bool hasPhysRegClobbers
Has any physreg defs, used or not.
bool isCallOp
Is a function call operand.
const TargetRegisterClass * CopyDstRC
Is a special copy node if != nullptr.
unsigned short Latency
Node latency.
unsigned short NumRegDefsLeft
bool isScheduleHigh
True if preferable to schedule high.
bool isScheduleLow
True if preferable to schedule low.
bool hasPhysRegDefs
Has physreg defs that are being used.
SmallVector< SDep, 4 > Succs
All sunit successors.
Sched::Preference SchedulingPref
Scheduling preference.
SDNode * getNode() const
Returns the representative SDNode for this SUnit.
bool isTwoAddress
Is a two-address instruction.
bool isCommutable
Is a commutable instruction.
bool isVRegCycle
May use and def the same vreg.
SmallVector< SDep, 4 > Preds
All sunit predecessors.
SUnit * OrigNode
If not this, the node from which this node was cloned.
LLVM_ABI bool addPred(const SDep &D, bool Required=true)
Adds the specified edge as a pred of the current node if not already.
RegDefIter - In place iteration over the values defined by an SUnit.
RegDefIter(const SUnit *SU, const ScheduleDAGSDNodes *SD)
SUnit * newSUnit(SDNode *N)
NewSUnit - Creates a new SUnit and return a ptr to it.
void VerifyScheduledSequence(bool isBottomUp)
VerifyScheduledSequence - Verify that all SUnits are scheduled and consistent with the Sequence of sc...
virtual void Schedule()=0
Schedule - Order nodes according to selected style, filling in the Sequence member.
virtual void computeLatency(SUnit *SU)
computeLatency - Compute node latency.
std::string getDAGName() const override
Return the basic block label.
virtual MachineBasicBlock * EmitSchedule(MachineBasicBlock::iterator &InsertPos)
EmitSchedule - Insert MachineInstrs into the MachineBasicBlock according to the order specified in Se...
virtual bool forceUnitLatencies() const
ForceUnitLatencies - Return true if all scheduling edges should be given a latency value of one.
static bool isPassiveNode(SDNode *Node)
isPassiveNode - Return true if the node is a non-scheduled leaf.
const InstrItineraryData * InstrItins
void InitNumRegDefsLeft(SUnit *SU)
InitNumRegDefsLeft - Determine the # of regs defined by this node.
std::vector< SUnit * > Sequence
The schedule. Null SUnit*'s represent noop instructions.
void Run(SelectionDAG *dag, MachineBasicBlock *bb)
Run - perform scheduling.
void BuildSchedGraph()
BuildSchedGraph - Build the SUnit graph from the selection dag that we are input.
void dumpNode(const SUnit &SU) const override
SUnit * Clone(SUnit *Old)
Clone - Creates a clone of the specified SUnit.
ScheduleDAGSDNodes(MachineFunction &mf)
virtual void computeOperandLatency(SDNode *Def, SDNode *Use, unsigned OpIdx, SDep &dep) const
MachineRegisterInfo & MRI
Virtual/real register map.
void clearDAG()
Clears the DAG state (between regions).
const TargetInstrInfo * TII
Target instruction information.
std::vector< SUnit > SUnits
The scheduling units.
const TargetRegisterInfo * TRI
Target processor register info.
SUnit EntrySU
Special node for the region entry.
MachineFunction & MF
Machine function.
ScheduleDAG(const ScheduleDAG &)=delete
void dumpNodeAll(const SUnit &SU) const
unsigned VerifyScheduledDAG(bool isBottomUp)
Verifies that all SUnits were scheduled and that their state is consistent.
void dumpNodeName(const SUnit &SU) const
SUnit ExitSU
Special node for the region exit.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
LLVM_ABI SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
LLVM_ABI SDNode * MorphNodeTo(SDNode *N, unsigned Opc, SDVTList VTs, ArrayRef< SDValue > Ops)
This mutates the specified node to have the specified return type, opcode, and operands.
LLVM_ABI void setNodeMemRefs(MachineSDNode *N, ArrayRef< MachineMemOperand * > NewMemRefs)
Mutate the specified machine node's memory references to the provided list.
ArrayRef< SDDbgValue * > GetDbgValues(const SDNode *SD) const
Get the debug values which reference the given SDNode.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition SmallSet.h:134
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
Definition SmallSet.h:176
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition SmallSet.h:184
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetInstrInfo - Interface to description of machine instruction set.
Sched::Preference getSchedulingPreference() const
Return target scheduling preference.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
uint8_t getCopyCost() const
Return the cost of copying a value between two registers in this class.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
Value * getOperand(unsigned i) const
Definition User.h:207
@ CopyFromReg
CopyFromReg - This node indicates that the input value is a virtual or physical register that is defi...
Definition ISDOpcodes.h:230
@ CopyToReg
CopyToReg - This node has three operands: a chain, a register number to set to this value,...
Definition ISDOpcodes.h:224
@ TokenFactor
TokenFactor - This node takes multiple tokens as input and produces a single token result.
Definition ISDOpcodes.h:53
Offsets
Offsets in bytes from the start of the input buffer.
initializer< Ty > init(const Ty &Val)
@ User
could "use" a pointer
NodeAddr< NodeBase * > Node
Definition RDFGraph.h:381
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:532
void stable_sort(R &&Range)
Definition STLExtras.h:2116
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
InstructionCost Cost
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition STLExtras.h:634
void sort(IteratorTy Start, IteratorTy End)
Definition STLExtras.h:1636
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:221
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
Definition STLExtras.h:2012
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
#define N
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
Function object to check whether the first component of a container supported by std::get (like std::...
Definition STLExtras.h:1439