LLVM 24.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 = TRI->getMinimalPhysRegClass(Reg);
134 Cost = RC->expensiveOrImpossibleToCopy() ? -1 : RC->getCopyCost();
135 }
136}
137
138// Helper for AddGlue to clone node operands.
140 SDValue ExtraOper = SDValue()) {
142 if (ExtraOper.getNode())
143 Ops.push_back(ExtraOper);
144
145 SDVTList VTList = DAG->getVTList(VTs);
147
148 // Store memory references.
150 if (MN)
151 MMOs.assign(MN->memoperands_begin(), MN->memoperands_end());
152
153 DAG->MorphNodeTo(N, N->getOpcode(), VTList, Ops);
154
155 // Reset the memory references
156 if (MN)
157 DAG->setNodeMemRefs(MN, MMOs);
158}
159
160static bool AddGlue(SDNode *N, SDValue Glue, bool AddGlue, SelectionDAG *DAG) {
161 SDNode *GlueDestNode = Glue.getNode();
162
163 // Don't add glue from a node to itself.
164 if (GlueDestNode == N) return false;
165
166 // Don't add a glue operand to something that already uses glue.
167 if (GlueDestNode &&
168 N->getOperand(N->getNumOperands()-1).getValueType() == MVT::Glue) {
169 return false;
170 }
171 // Don't add glue to something that already has a glue value.
172 if (N->getValueType(N->getNumValues() - 1) == MVT::Glue) return false;
173
174 SmallVector<EVT, 4> VTs(N->values());
175 if (AddGlue)
176 VTs.push_back(MVT::Glue);
177
178 CloneNodeWithValues(N, DAG, VTs, Glue);
179
180 return true;
181}
182
183// Cleanup after unsuccessful AddGlue. Use the standard method of morphing the
184// node even though simply shrinking the value list is sufficient.
186 assert((N->getValueType(N->getNumValues() - 1) == MVT::Glue &&
187 !N->hasAnyUseOfValue(N->getNumValues() - 1)) &&
188 "expected an unused glue value");
189
191 ArrayRef(N->value_begin(), N->getNumValues() - 1));
192}
193
194/// ClusterNeighboringLoads - Force nearby loads together by "gluing" them.
195/// This function finds loads of the same base and different offsets. If the
196/// offsets are not far apart (target specific), it add MVT::Glue inputs and
197/// outputs to ensure they are scheduled together and in order. This
198/// optimization may benefit some targets by improving cache locality.
199void ScheduleDAGSDNodes::ClusterNeighboringLoads(SDNode *Node) {
200 SDValue Chain;
201 unsigned NumOps = Node->getNumOperands();
202 if (Node->getOperand(NumOps-1).getValueType() == MVT::Other)
203 Chain = Node->getOperand(NumOps-1);
204 if (!Chain)
205 return;
206
207 // Skip any load instruction that has a tied input. There may be an additional
208 // dependency requiring a different order than by increasing offsets, and the
209 // added glue may introduce a cycle.
210 auto hasTiedInput = [this](const SDNode *N) {
211 const MCInstrDesc &MCID = TII->get(N->getMachineOpcode());
212 for (unsigned I = 0; I != MCID.getNumOperands(); ++I) {
213 if (MCID.getOperandConstraint(I, MCOI::TIED_TO) != -1)
214 return true;
215 }
216
217 return false;
218 };
219
220 // Look for other loads of the same chain. Find loads that are loading from
221 // the same base pointer and different offsets.
222 SmallPtrSet<SDNode*, 16> Visited;
224 DenseMap<long long, SDNode*> O2SMap; // Map from offset to SDNode.
225 bool Cluster = false;
226 SDNode *Base = Node;
227
228 if (hasTiedInput(Base))
229 return;
230
231 // This algorithm requires a reasonably low use count before finding a match
232 // to avoid uselessly blowing up compile time in large blocks.
233 unsigned UseCount = 0;
234 for (SDNode::user_iterator I = Chain->user_begin(), E = Chain->user_end();
235 I != E && UseCount < 100; ++I, ++UseCount) {
236 if (I.getUse().getResNo() != Chain.getResNo())
237 continue;
238
239 SDNode *User = *I;
240 if (User == Node || !Visited.insert(User).second)
241 continue;
242 int64_t Offset1, Offset2;
243 if (!TII->areLoadsFromSameBasePtr(Base, User, Offset1, Offset2) ||
244 Offset1 == Offset2 ||
245 hasTiedInput(User)) {
246 // FIXME: Should be ok if they addresses are identical. But earlier
247 // optimizations really should have eliminated one of the loads.
248 continue;
249 }
250 if (O2SMap.insert(std::make_pair(Offset1, Base)).second)
251 Offsets.push_back(Offset1);
252 O2SMap.insert(std::make_pair(Offset2, User));
253 Offsets.push_back(Offset2);
254 if (Offset2 < Offset1)
255 Base = User;
256 Cluster = true;
257 // Reset UseCount to allow more matches.
258 UseCount = 0;
259 }
260
261 if (!Cluster)
262 return;
263
264 // Sort them in increasing order.
265 llvm::sort(Offsets);
266
267 // Check if the loads are close enough.
269 unsigned NumLoads = 0;
270 int64_t BaseOff = Offsets[0];
271 SDNode *BaseLoad = O2SMap[BaseOff];
272 Loads.push_back(BaseLoad);
273 for (unsigned i = 1, e = Offsets.size(); i != e; ++i) {
274 int64_t Offset = Offsets[i];
275 SDNode *Load = O2SMap[Offset];
276 if (!TII->shouldScheduleLoadsNear(BaseLoad, Load, BaseOff, Offset,NumLoads))
277 break; // Stop right here. Ignore loads that are further away.
278 Loads.push_back(Load);
279 ++NumLoads;
280 }
281
282 if (NumLoads == 0)
283 return;
284
285 // Cluster loads by adding MVT::Glue outputs and inputs. This also
286 // ensure they are scheduled in order of increasing addresses.
287 SDNode *Lead = Loads[0];
288 SDValue InGlue;
289 if (AddGlue(Lead, InGlue, true, DAG))
290 InGlue = SDValue(Lead, Lead->getNumValues() - 1);
291 for (unsigned I = 1, E = Loads.size(); I != E; ++I) {
292 bool OutGlue = I < E - 1;
293 SDNode *Load = Loads[I];
294
295 // If AddGlue fails, we could leave an unsused glue value. This should not
296 // cause any
297 if (AddGlue(Load, InGlue, OutGlue, DAG)) {
298 if (OutGlue)
299 InGlue = SDValue(Load, Load->getNumValues() - 1);
300
301 ++LoadsClustered;
302 }
303 else if (!OutGlue && InGlue.getNode())
304 RemoveUnusedGlue(InGlue.getNode(), DAG);
305 }
306}
307
308/// ClusterNodes - Cluster certain nodes which should be scheduled together.
309///
310void ScheduleDAGSDNodes::ClusterNodes() {
311 for (SDNode &NI : DAG->allnodes()) {
312 SDNode *Node = &NI;
313 if (!Node || !Node->isMachineOpcode())
314 continue;
315
316 unsigned Opc = Node->getMachineOpcode();
317 const MCInstrDesc &MCID = TII->get(Opc);
318 if (MCID.mayLoad())
319 // Cluster loads from "near" addresses into combined SUnits.
320 ClusterNeighboringLoads(Node);
321 }
322}
323
324void ScheduleDAGSDNodes::BuildSchedUnits() {
325 // During scheduling, the NodeId field of SDNode is used to map SDNodes
326 // to their associated SUnits by holding SUnits table indices. A value
327 // of -1 means the SDNode does not yet have an associated SUnit.
328 unsigned NumNodes = 0;
329 for (SDNode &NI : DAG->allnodes()) {
330 NI.setNodeId(-1);
331 NI.setSchedulerWorklistVisited(false);
332 ++NumNodes;
333 }
334
335 // Reserve entries in the vector for each of the SUnits we are creating. This
336 // ensure that reallocation of the vector won't happen, so SUnit*'s won't get
337 // invalidated.
338 // FIXME: Multiply by 2 because we may clone nodes during scheduling.
339 // This is a temporary workaround.
340 SUnits.reserve(NumNodes * 2);
341
342 // Add all nodes in depth first order.
344 SmallPtrSet<SDNode*, 32> Visited;
345 Worklist.push_back(DAG->getRoot().getNode());
346 DAG->getRoot().getNode()->setSchedulerWorklistVisited(true);
347
348 SmallVector<SUnit*, 8> CallSUnits;
349 while (!Worklist.empty()) {
350 SDNode *NI = Worklist.pop_back_val();
351
352 // Add all operands to the worklist unless they've already been added.
353 for (const SDValue &Op : NI->op_values()) {
354 if (Op.getNode()->getSchedulerWorklistVisited())
355 continue;
356 Op.getNode()->setSchedulerWorklistVisited(true);
357 Worklist.push_back(Op.getNode());
358 }
359
360 if (isPassiveNode(NI)) // Leaf node, e.g. a TargetImmediate.
361 continue;
362
363 // If this node has already been processed, stop now.
364 if (NI->getNodeId() != -1) continue;
365
366 SUnit *NodeSUnit = newSUnit(NI);
367
368 // See if anything is glued to this node, if so, add them to glued
369 // nodes. Nodes can have at most one glue input and one glue output. Glue
370 // is required to be the last operand and result of a node.
371
372 // Scan up to find glued preds.
373 SDNode *N = NI;
374 while (N->getNumOperands() &&
375 N->getOperand(N->getNumOperands()-1).getValueType() == MVT::Glue) {
376 N = N->getOperand(N->getNumOperands()-1).getNode();
377 assert(N->getNodeId() == -1 && "Node already inserted!");
378 N->setNodeId(NodeSUnit->NodeNum);
379 if (N->isMachineOpcode() && TII->get(N->getMachineOpcode()).isCall())
380 NodeSUnit->isCall = true;
381 }
382
383 // Scan down to find any glued succs.
384 N = NI;
385 while (N->getValueType(N->getNumValues()-1) == MVT::Glue) {
386 SDValue GlueVal(N, N->getNumValues()-1);
387
388 // There are either zero or one users of the Glue result.
389 bool HasGlueUse = false;
390 for (SDNode *U : N->users())
391 if (GlueVal.isOperandOf(U)) {
392 HasGlueUse = true;
393 assert(N->getNodeId() == -1 && "Node already inserted!");
394 N->setNodeId(NodeSUnit->NodeNum);
395 N = U;
396 if (N->isMachineOpcode() && TII->get(N->getMachineOpcode()).isCall())
397 NodeSUnit->isCall = true;
398 break;
399 }
400 if (!HasGlueUse) break;
401 }
402
403 if (NodeSUnit->isCall)
404 CallSUnits.push_back(NodeSUnit);
405
406 // Schedule zero-latency TokenFactor below any nodes that may increase the
407 // schedule height. Otherwise, ancestors of the TokenFactor may appear to
408 // have false stalls.
409 if (NI->getOpcode() == ISD::TokenFactor)
410 NodeSUnit->isScheduleLow = true;
411
412 // If there are glue operands involved, N is now the bottom-most node
413 // of the sequence of nodes that are glued together.
414 // Update the SUnit.
415 NodeSUnit->setNode(N);
416 assert(N->getNodeId() == -1 && "Node already inserted!");
417 N->setNodeId(NodeSUnit->NodeNum);
418
419 // Compute NumRegDefsLeft. This must be done before AddSchedEdges.
420 InitNumRegDefsLeft(NodeSUnit);
421
422 // Assign the Latency field of NodeSUnit using target-provided information.
423 computeLatency(NodeSUnit);
424 }
425
426 // Find all call operands.
427 while (!CallSUnits.empty()) {
428 SUnit *SU = CallSUnits.pop_back_val();
429 for (const SDNode *SUNode = SU->getNode(); SUNode;
430 SUNode = SUNode->getGluedNode()) {
431 if (SUNode->getOpcode() != ISD::CopyToReg)
432 continue;
433 SDNode *SrcN = SUNode->getOperand(2).getNode();
434 if (isPassiveNode(SrcN)) continue; // Not scheduled.
435 SUnit *SrcSU = &SUnits[SrcN->getNodeId()];
436 SrcSU->isCallOp = true;
437 }
438 }
439}
440
441void ScheduleDAGSDNodes::AddSchedEdges() {
442 const TargetSubtargetInfo &ST = MF.getSubtarget();
443
444 // Check to see if the scheduler cares about latencies.
445 bool UnitLatencies = forceUnitLatencies();
446
447 // Pass 2: add the preds, succs, etc.
448 for (SUnit &SU : SUnits) {
449 SDNode *MainNode = SU.getNode();
450
451 if (MainNode->isMachineOpcode()) {
452 unsigned Opc = MainNode->getMachineOpcode();
453 const MCInstrDesc &MCID = TII->get(Opc);
454 for (unsigned i = 0; i != MCID.getNumOperands(); ++i) {
455 if (MCID.getOperandConstraint(i, MCOI::TIED_TO) != -1) {
456 SU.isTwoAddress = true;
457 break;
458 }
459 }
460 if (MCID.isCommutable())
461 SU.isCommutable = true;
462 }
463
464 // Find all predecessors and successors of the group.
465 for (SDNode *N = SU.getNode(); N; N = N->getGluedNode()) {
466 if (N->isMachineOpcode() &&
467 !TII->get(N->getMachineOpcode()).implicit_defs().empty()) {
468 const MCInstrDesc &MCID = TII->get(N->getMachineOpcode());
469 SU.hasPhysRegClobbers = true;
470 // Results beyond the explicit defs are physical register defs, unless
471 // the target models variadic results as virtual registers. This must
472 // match InstrEmitter::EmitMachineNode.
473 bool HasVRegVariadicDefs = !MF.getTarget().usesPhysRegsForValues() &&
474 MCID.isVariadic() &&
475 MCID.variadicOpsAreDefs();
476 unsigned NumUsed = InstrEmitter::CountResults(N);
477 while (NumUsed != 0 && !N->hasAnyUseOfValue(NumUsed - 1))
478 --NumUsed; // Skip over unused values at the end.
479 if (!HasVRegVariadicDefs && NumUsed > MCID.getNumDefs())
480 SU.hasPhysRegDefs = true;
481 }
482
483 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
484 SDNode *OpN = N->getOperand(i).getNode();
485 unsigned DefIdx = N->getOperand(i).getResNo();
486 if (isPassiveNode(OpN)) continue; // Not scheduled.
487 SUnit *OpSU = &SUnits[OpN->getNodeId()];
488 assert(OpSU && "Node has no SUnit!");
489 if (OpSU == &SU)
490 continue; // In the same group.
491
492 EVT OpVT = N->getOperand(i).getValueType();
493 assert(OpVT != MVT::Glue && "Glued nodes should be in same sunit!");
494 bool isChain = OpVT == MVT::Other;
495
496 MCRegister PhysReg;
497 int Cost = 1;
498 // Determine if this is a physical register dependency.
499 CheckForPhysRegDependency(OpN, N, i, TRI, TII, PhysReg, Cost);
500 assert((!PhysReg || !isChain) && "Chain dependence via physreg data?");
501 // FIXME: See ScheduleDAGSDNodes::EmitCopyFromReg. For now, scheduler
502 // emits a copy from the physical register to a virtual register unless
503 // it requires a cross class copy (cost < 0). That means we are only
504 // treating "expensive to copy" register dependency as physical register
505 // dependency. This may change in the future though.
506 if (Cost >= 0 && !StressSched)
507 PhysReg = MCRegister();
508
509 // If this is a ctrl dep, latency is 1.
510 unsigned OpLatency = isChain ? 1 : OpSU->Latency;
511 // Special-case TokenFactor chains as zero-latency.
512 if(isChain && OpN->getOpcode() == ISD::TokenFactor)
513 OpLatency = 0;
514
515 SDep Dep = isChain ? SDep(OpSU, SDep::Barrier)
516 : SDep(OpSU, SDep::Data, PhysReg);
517 Dep.setLatency(OpLatency);
518 if (!isChain && !UnitLatencies) {
519 computeOperandLatency(OpN, N, i, Dep);
520 ST.adjustSchedDependency(OpSU, DefIdx, &SU, i, Dep, nullptr);
521 }
522
523 if (!SU.addPred(Dep) && !Dep.isCtrl() && OpSU->NumRegDefsLeft > 1) {
524 // Multiple register uses are combined in the same SUnit. For example,
525 // we could have a set of glued nodes with all their defs consumed by
526 // another set of glued nodes. Register pressure tracking sees this as
527 // a single use, so to keep pressure balanced we reduce the defs.
528 //
529 // We can't tell (without more book-keeping) if this results from
530 // glued nodes or duplicate operands. As long as we don't reduce
531 // NumRegDefsLeft to zero, we handle the common cases well.
532 --OpSU->NumRegDefsLeft;
533 }
534 }
535 }
536 }
537}
538
539/// BuildSchedGraph - Build the SUnit graph from the selection dag that we
540/// are input. This SUnit graph is similar to the SelectionDAG, but
541/// excludes nodes that aren't interesting to scheduling, and represents
542/// glued together nodes with a single SUnit.
544 // Cluster certain nodes which should be scheduled together.
545 ClusterNodes();
546 // Populate the SUnits array.
547 BuildSchedUnits();
548 // Compute all the scheduling dependencies between nodes.
549 AddSchedEdges();
550}
551
552// Initialize NumNodeDefs for the current Node's opcode.
553void ScheduleDAGSDNodes::RegDefIter::InitNodeNumDefs() {
554 // Check for phys reg copy.
555 if (!Node)
556 return;
557
558 if (!Node->isMachineOpcode()) {
559 if (Node->getOpcode() == ISD::CopyFromReg)
560 NodeNumDefs = 1;
561 else
562 NodeNumDefs = 0;
563 return;
564 }
565 unsigned POpc = Node->getMachineOpcode();
566 if (POpc == TargetOpcode::IMPLICIT_DEF) {
567 // No register need be allocated for this.
568 NodeNumDefs = 0;
569 return;
570 }
571 if (POpc == TargetOpcode::PATCHPOINT &&
572 Node->getValueType(0) == MVT::Other) {
573 // PATCHPOINT is defined to have one result, but it might really have none
574 // if we're not using CallingConv::AnyReg. Don't mistake the chain for a
575 // real definition.
576 NodeNumDefs = 0;
577 return;
578 }
579 unsigned NRegDefs = SchedDAG->TII->get(Node->getMachineOpcode()).getNumDefs();
580 // Some instructions define regs that are not represented in the selection DAG
581 // (e.g. unused flags). See tMOVi8. Make sure we don't access past NumValues.
582 NodeNumDefs = std::min(Node->getNumValues(), NRegDefs);
583 DefIdx = 0;
584}
585
586// Construct a RegDefIter for this SUnit and find the first valid value.
588 const ScheduleDAGSDNodes *SD)
589 : SchedDAG(SD), Node(SU->getNode()) {
590 InitNodeNumDefs();
591 Advance();
592}
593
594// Advance to the next valid value defined by the SUnit.
596 for (;Node;) { // Visit all glued nodes.
597 for (;DefIdx < NodeNumDefs; ++DefIdx) {
598 if (!Node->hasAnyUseOfValue(DefIdx))
599 continue;
600 ValueType = Node->getSimpleValueType(DefIdx);
601 ++DefIdx;
602 return; // Found a normal regdef.
603 }
604 Node = Node->getGluedNode();
605 if (!Node) {
606 return; // No values left to visit.
607 }
608 InitNodeNumDefs();
609 }
610}
611
613 assert(SU->NumRegDefsLeft == 0 && "expect a new node");
614 for (RegDefIter I(SU, this); I.IsValid(); I.Advance()) {
615 assert(SU->NumRegDefsLeft < USHRT_MAX && "overflow is ok but unexpected");
616 ++SU->NumRegDefsLeft;
617 }
618}
619
621 SDNode *N = SU->getNode();
622
623 // TokenFactor operands are considered zero latency, and some schedulers
624 // (e.g. Top-Down list) may rely on the fact that operand latency is nonzero
625 // whenever node latency is nonzero.
626 if (N && N->getOpcode() == ISD::TokenFactor) {
627 SU->Latency = 0;
628 return;
629 }
630
631 // Check to see if the scheduler cares about latencies.
632 if (forceUnitLatencies()) {
633 SU->Latency = 1;
634 return;
635 }
636
637 if (!InstrItins || InstrItins->isEmpty()) {
638 if (N && N->isMachineOpcode() &&
639 TII->isHighLatencyDef(N->getMachineOpcode()))
641 else
642 SU->Latency = 1;
643 return;
644 }
645
646 // Compute the latency for the node. We use the sum of the latencies for
647 // all nodes glued together into this SUnit.
648 SU->Latency = 0;
649 for (SDNode *N = SU->getNode(); N; N = N->getGluedNode())
650 if (N->isMachineOpcode())
651 SU->Latency += TII->getInstrLatency(InstrItins, N);
652}
653
655 unsigned OpIdx, SDep& dep) const{
656 // Check to see if the scheduler cares about latencies.
657 if (forceUnitLatencies())
658 return;
659
660 if (dep.getKind() != SDep::Data)
661 return;
662
663 unsigned DefIdx = Use->getOperand(OpIdx).getResNo();
664 if (Use->isMachineOpcode())
665 // Adjust the use operand index by num of defs.
666 OpIdx += TII->get(Use->getMachineOpcode()).getNumDefs();
667 std::optional<unsigned> Latency =
668 TII->getOperandLatency(InstrItins, Def, DefIdx, Use, OpIdx);
669 if (Latency > 1U && Use->getOpcode() == ISD::CopyToReg &&
670 !BB->succ_empty()) {
671 Register Reg = cast<RegisterSDNode>(Use->getOperand(1))->getReg();
672 if (Reg.isVirtual())
673 // This copy is a liveout value. It is likely coalesced, so reduce the
674 // latency so not to penalize the def.
675 // FIXME: need target specific adjustment here?
676 Latency = *Latency - 1;
677 }
678 if (Latency)
679 dep.setLatency(*Latency);
680}
681
682void ScheduleDAGSDNodes::dumpNode(const SUnit &SU) const {
683#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
684 dumpNodeName(SU);
685 dbgs() << ": ";
686
687 if (!SU.getNode()) {
688 dbgs() << "PHYS REG COPY\n";
689 return;
690 }
691
692 SU.getNode()->dump(DAG);
693 dbgs() << "\n";
694 SmallVector<SDNode *, 4> GluedNodes;
695 for (SDNode *N = SU.getNode()->getGluedNode(); N; N = N->getGluedNode())
696 GluedNodes.push_back(N);
697 while (!GluedNodes.empty()) {
698 dbgs() << " ";
699 GluedNodes.back()->dump(DAG);
700 dbgs() << "\n";
701 GluedNodes.pop_back();
702 }
703#endif
704}
705
707#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
708 if (EntrySU.getNode() != nullptr)
710 for (const SUnit &SU : SUnits)
711 dumpNodeAll(SU);
712 if (ExitSU.getNode() != nullptr)
714#endif
715}
716
717#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
719 for (const SUnit *SU : Sequence) {
720 if (SU)
721 dumpNode(*SU);
722 else
723 dbgs() << "**** NOOP ****\n";
724 }
725}
726#endif
727
728#ifndef NDEBUG
729/// VerifyScheduledSequence - Verify that all SUnits were scheduled and that
730/// their state is consistent with the nodes listed in Sequence.
731///
733 unsigned ScheduledNodes = ScheduleDAG::VerifyScheduledDAG(isBottomUp);
734 unsigned Noops = llvm::count(Sequence, nullptr);
735 assert(Sequence.size() - Noops == ScheduledNodes &&
736 "The number of nodes scheduled doesn't match the expected number!");
737}
738#endif // NDEBUG
739
740/// ProcessSDDbgValues - Process SDDbgValues associated with this node.
741static void
743 SmallVectorImpl<std::pair<unsigned, MachineInstr*> > &Orders,
744 InstrEmitter::VRBaseMapType &VRBaseMap, unsigned Order) {
745 if (!N->getHasDebugValue())
746 return;
747
748 /// Returns true if \p DV has any VReg operand locations which don't exist in
749 /// VRBaseMap.
750 auto HasUnknownVReg = [&VRBaseMap](SDDbgValue *DV) {
751 for (const SDDbgOperand &L : DV->getLocationOps()) {
752 if (L.getKind() == SDDbgOperand::SDNODE &&
753 VRBaseMap.count({L.getSDNode(), L.getResNo()}) == 0)
754 return true;
755 }
756 return false;
757 };
758
759 // Opportunistically insert immediate dbg_value uses, i.e. those with the same
760 // source order number as N.
761 MachineBasicBlock *BB = Emitter.getBlock();
762 MachineBasicBlock::iterator InsertPos = Emitter.getInsertPos();
763 for (auto *DV : DAG->GetDbgValues(N)) {
764 if (DV->isEmitted())
765 continue;
766 unsigned DVOrder = DV->getOrder();
767 if (Order != 0 && DVOrder != Order)
768 continue;
769 // If DV has any VReg location operands which haven't been mapped then
770 // either that node is no longer available or we just haven't visited the
771 // node yet. In the former case we should emit an undef dbg_value, but we
772 // can do it later. And for the latter we'll want to wait until all
773 // dependent nodes have been visited.
774 if (!DV->isInvalidated() && HasUnknownVReg(DV))
775 continue;
776 MachineInstr *DbgMI = Emitter.EmitDbgValue(DV, VRBaseMap);
777 if (!DbgMI)
778 continue;
779 Orders.push_back({DVOrder, DbgMI});
780 BB->insert(InsertPos, DbgMI);
781 }
782}
783
784// ProcessSourceNode - Process nodes with source order numbers. These are added
785// to a vector which EmitSchedule uses to determine how to insert dbg_value
786// instructions in the right order.
787static void
790 SmallVectorImpl<std::pair<unsigned, MachineInstr *>> &Orders,
791 SmallSet<Register, 8> &Seen, MachineInstr *NewInsn) {
792 unsigned Order = N->getIROrder();
793 if (!Order || Seen.count(Order)) {
794 // Process any valid SDDbgValues even if node does not have any order
795 // assigned.
796 ProcessSDDbgValues(N, DAG, Emitter, Orders, VRBaseMap, 0);
797 return;
798 }
799
800 // If a new instruction was generated for this Order number, record it.
801 // Otherwise, leave this order number unseen: we will either find later
802 // instructions for it, or leave it unseen if there were no instructions at
803 // all.
804 if (NewInsn) {
805 Seen.insert(Order);
806 Orders.push_back({Order, NewInsn});
807 }
808
809 // Even if no instruction was generated, a Value may have become defined via
810 // earlier nodes. Try to process them now.
811 ProcessSDDbgValues(N, DAG, Emitter, Orders, VRBaseMap, Order);
812}
813
814void ScheduleDAGSDNodes::
815EmitPhysRegCopy(SUnit *SU, SmallDenseMap<SUnit *, Register, 16> &VRBaseMap,
816 MachineBasicBlock::iterator InsertPos) {
817 for (const SDep &Pred : SU->Preds) {
818 if (Pred.isCtrl())
819 continue; // ignore chain preds
820 if (Pred.getSUnit()->CopyDstRC) {
821 // Copy to physical register.
822 auto VRI = VRBaseMap.find(Pred.getSUnit());
823 assert(VRI != VRBaseMap.end() && "Node emitted out of order - late");
824 // Find the destination physical register.
826 for (const SDep &Succ : SU->Succs) {
827 if (Succ.isCtrl())
828 continue; // ignore chain preds
829 if (Succ.getReg()) {
830 Reg = Succ.getReg();
831 break;
832 }
833 }
834 BuildMI(*BB, InsertPos, DebugLoc(), TII->get(TargetOpcode::COPY), Reg)
835 .addReg(VRI->second);
836 } else {
837 // Copy from physical register.
838 assert(Pred.getReg() && "Unknown physical register!");
839 Register VRBase = MRI.createVirtualRegister(SU->CopyDstRC);
840 bool isNew = VRBaseMap.insert(std::make_pair(SU, VRBase)).second;
841 (void)isNew; // Silence compiler warning.
842 assert(isNew && "Node emitted out of order - early");
843 BuildMI(*BB, InsertPos, DebugLoc(), TII->get(TargetOpcode::COPY), VRBase)
844 .addReg(Pred.getReg());
845 }
846 break;
847 }
848}
849
850/// Mark physreg defs dead on \p MI, emitted for a cloned node \p SU. All copies
851/// share one SDNode, so InstrEmitter can't tell which copy lost its users. A
852/// live def of an expensive-to-copy physreg is carried on a scheduler edge by
853/// some copy, so it is dead if \p SU has no such edge.
855 const TargetRegisterInfo *TRI) {
856 for (MachineOperand &MO : MI.implicit_operands()) {
857 if (!MO.isReg() || !MO.isDef() || MO.isDead())
858 continue;
859 Register Reg = MO.getReg();
860 if (!TRI->getMinimalPhysRegClass(Reg)->expensiveOrImpossibleToCopy())
861 continue;
862 if (none_of(SU.Succs, [=](const SDep &Succ) {
863 return Succ.isAssignedRegDep() && Succ.getReg() == Reg;
864 }))
865 MO.setIsDead();
866 }
867}
868
869/// EmitSchedule - Emit the machine code in scheduled order. Return the new
870/// InsertPos and MachineBasicBlock that contains this insertion
871/// point. ScheduleDAGSDNodes holds a BB pointer for convenience, but this does
872/// not necessarily refer to returned BB. The emitter may split blocks.
875 InstrEmitter Emitter(DAG->getTarget(), BB, InsertPos);
880 bool HasDbg = DAG->hasDebugValues();
881
882 // Emit a node, and determine where its first instruction is for debuginfo.
883 // Zero, one, or multiple instructions can be created when emitting a node.
884 auto EmitNode =
885 [&](SDNode *Node, bool IsClone, bool IsCloned,
887 // Fetch instruction prior to this, or end() if nonexistant.
888 auto GetPrevInsn = [&](MachineBasicBlock::iterator I) {
889 if (I == BB->begin())
890 return BB->end();
891 else
892 return std::prev(Emitter.getInsertPos());
893 };
894
895 MachineBasicBlock::iterator Before = GetPrevInsn(Emitter.getInsertPos());
896 Emitter.EmitNode(Node, IsClone, IsCloned, VRBaseMap);
897 MachineBasicBlock::iterator After = GetPrevInsn(Emitter.getInsertPos());
898
899 // If the iterator did not change, no instructions were inserted.
900 if (Before == After)
901 return nullptr;
902
904 if (Before == BB->end()) {
905 // There were no prior instructions; the new ones must start at the
906 // beginning of the block.
907 MI = &Emitter.getBlock()->instr_front();
908 } else {
909 // Return first instruction after the pre-existing instructions.
910 MI = &*std::next(Before);
911 }
912
913 if (MI->isCandidateForAdditionalCallInfo()) {
914 if (DAG->getTarget().Options.EmitCallSiteInfo ||
915 DAG->getTarget().Options.EmitCallGraphSection)
916 MF.addCallSiteInfo(MI, DAG->getCallSiteInfo(Node));
917
918 if (auto CalledGlobal = DAG->getCalledGlobal(Node))
919 if (CalledGlobal->Callee)
920 MF.addCalledGlobal(MI, *CalledGlobal);
921 }
922
923 if (DAG->getNoMergeSiteInfo(Node)) {
925 }
926
927 if (MDNode *MD = DAG->getPCSections(Node))
928 MI->setPCSections(MF, MD);
929
930 // Set MMRAs on _all_ added instructions.
931 if (MDNode *MMRA = DAG->getMMRAMetadata(Node)) {
932 for (MachineBasicBlock::iterator It = MI->getIterator(),
933 End = std::next(After);
934 It != End; ++It)
935 It->setMMRAMetadata(MF, MMRA);
936 }
937
938 return MI;
939 };
940
941 // If this is the first BB, emit byval parameter dbg_value's.
942 if (HasDbg && BB->getParent()->begin() == MachineFunction::iterator(BB)) {
943 SDDbgInfo::DbgIterator PDI = DAG->ByvalParmDbgBegin();
944 SDDbgInfo::DbgIterator PDE = DAG->ByvalParmDbgEnd();
945 for (; PDI != PDE; ++PDI) {
946 MachineInstr *DbgMI= Emitter.EmitDbgValue(*PDI, VRBaseMap);
947 if (DbgMI) {
948 BB->insert(InsertPos, DbgMI);
949 // We re-emit the dbg_value closer to its use, too, after instructions
950 // are emitted to the BB.
951 (*PDI)->clearIsEmitted();
952 }
953 }
954 }
955
956 for (SUnit *SU : Sequence) {
957 if (!SU) {
958 // Null SUnit* is a noop.
959 TII->insertNoop(*Emitter.getBlock(), InsertPos);
960 continue;
961 }
962
963 // For pre-regalloc scheduling, create instructions corresponding to the
964 // SDNode and any glued SDNodes and append them to the block.
965 if (!SU->getNode()) {
966 // Emit a copy.
967 EmitPhysRegCopy(SU, CopyVRBaseMap, InsertPos);
968 continue;
969 }
970
971 SmallVector<SDNode *, 4> GluedNodes;
972 for (SDNode *N = SU->getNode()->getGluedNode(); N; N = N->getGluedNode())
973 GluedNodes.push_back(N);
974 while (!GluedNodes.empty()) {
975 SDNode *N = GluedNodes.back();
976 auto NewInsn = EmitNode(N, SU->OrigNode != SU, SU->isCloned, VRBaseMap);
977 // Remember the source order of the inserted instruction.
978 if (HasDbg)
979 ProcessSourceNode(N, DAG, Emitter, VRBaseMap, Orders, Seen, NewInsn);
980
981 if (MDNode *MD = DAG->getHeapAllocSite(N))
982 if (NewInsn && NewInsn->isCall())
983 NewInsn->setHeapAllocMarker(MF, MD);
984
985 GluedNodes.pop_back();
986 }
987 auto NewInsn =
988 EmitNode(SU->getNode(), SU->OrigNode != SU, SU->isCloned, VRBaseMap);
989 // Remember the source order of the inserted instruction.
990 if (HasDbg)
991 ProcessSourceNode(SU->getNode(), DAG, Emitter, VRBaseMap, Orders, Seen,
992 NewInsn);
993
994 if (MDNode *MD = DAG->getHeapAllocSite(SU->getNode())) {
995 if (NewInsn && NewInsn->isCall())
996 NewInsn->setHeapAllocMarker(MF, MD);
997 }
998
999 if (NewInsn && SU->OrigNode->isCloned)
1000 markClonedNodeDeadDefs(*SU, *NewInsn, TRI);
1001 }
1002
1003 // Insert all the dbg_values which have not already been inserted in source
1004 // order sequence.
1005 if (HasDbg) {
1006 MachineBasicBlock::iterator BBBegin = BB->getFirstNonPHI();
1007
1008 // Sort the source order instructions and use the order to insert debug
1009 // values. Use stable_sort so that DBG_VALUEs are inserted in the same order
1010 // regardless of the host's implementation fo std::sort.
1011 llvm::stable_sort(Orders, less_first());
1012 std::stable_sort(DAG->DbgBegin(), DAG->DbgEnd(),
1013 [](const SDDbgValue *LHS, const SDDbgValue *RHS) {
1014 return LHS->getOrder() < RHS->getOrder();
1015 });
1016
1017 SDDbgInfo::DbgIterator DI = DAG->DbgBegin();
1018 SDDbgInfo::DbgIterator DE = DAG->DbgEnd();
1019 // Now emit the rest according to source order.
1020 unsigned LastOrder = 0;
1021 for (unsigned i = 0, e = Orders.size(); i != e && DI != DE; ++i) {
1022 unsigned Order = Orders[i].first;
1023 MachineInstr *MI = Orders[i].second;
1024 // Insert all SDDbgValue's whose order(s) are before "Order".
1025 assert(MI);
1026 for (; DI != DE; ++DI) {
1027 if ((*DI)->getOrder() < LastOrder || (*DI)->getOrder() >= Order)
1028 break;
1029 if ((*DI)->isEmitted())
1030 continue;
1031
1032 MachineInstr *DbgMI = Emitter.EmitDbgValue(*DI, VRBaseMap);
1033 if (DbgMI) {
1034 if (!LastOrder)
1035 // Insert to start of the BB (after PHIs).
1036 BB->insert(BBBegin, DbgMI);
1037 else {
1038 // Insert at the instruction, which may be in a different
1039 // block, if the block was split by a custom inserter.
1041 MI->getParent()->insert(Pos, DbgMI);
1042 }
1043 }
1044 }
1045 LastOrder = Order;
1046 }
1047 // Add trailing DbgValue's before the terminator. FIXME: May want to add
1048 // some of them before one or more conditional branches?
1050 for (; DI != DE; ++DI) {
1051 if ((*DI)->isEmitted())
1052 continue;
1053 assert((*DI)->getOrder() >= LastOrder &&
1054 "emitting DBG_VALUE out of order");
1055 if (MachineInstr *DbgMI = Emitter.EmitDbgValue(*DI, VRBaseMap))
1056 DbgMIs.push_back(DbgMI);
1057 }
1058
1059 MachineBasicBlock *InsertBB = Emitter.getBlock();
1061 InsertBB->insert(Pos, DbgMIs.begin(), DbgMIs.end());
1062
1063 SDDbgInfo::DbgLabelIterator DLI = DAG->DbgLabelBegin();
1064 SDDbgInfo::DbgLabelIterator DLE = DAG->DbgLabelEnd();
1065 // Now emit the rest according to source order.
1066 LastOrder = 0;
1067 for (const auto &InstrOrder : Orders) {
1068 unsigned Order = InstrOrder.first;
1069 MachineInstr *MI = InstrOrder.second;
1070 if (!MI)
1071 continue;
1072
1073 // Insert all SDDbgLabel's whose order(s) are before "Order".
1074 for (; DLI != DLE &&
1075 (*DLI)->getOrder() >= LastOrder && (*DLI)->getOrder() < Order;
1076 ++DLI) {
1077 MachineInstr *DbgMI = Emitter.EmitDbgLabel(*DLI);
1078 if (DbgMI) {
1079 if (!LastOrder)
1080 // Insert to start of the BB (after PHIs).
1081 BB->insert(BBBegin, DbgMI);
1082 else {
1083 // Insert at the instruction, which may be in a different
1084 // block, if the block was split by a custom inserter.
1086 MI->getParent()->insert(Pos, DbgMI);
1087 }
1088 }
1089 }
1090 if (DLI == DLE)
1091 break;
1092
1093 LastOrder = Order;
1094 }
1095 }
1096
1097 InsertPos = Emitter.getInsertPos();
1098 // In some cases, DBG_VALUEs might be inserted after the first terminator,
1099 // which results in an invalid MBB. If that happens, move the DBG_VALUEs
1100 // before the first terminator.
1101 MachineBasicBlock *InsertBB = Emitter.getBlock();
1102 auto FirstTerm = InsertBB->getFirstTerminator();
1103 if (FirstTerm != InsertBB->end()) {
1104 assert(!FirstTerm->isDebugValue() &&
1105 "first terminator cannot be a debug value");
1107 make_range(std::next(FirstTerm), InsertBB->end()))) {
1108 // Only scan up to insertion point.
1109 if (&MI == InsertPos)
1110 break;
1111
1112 if (!MI.isDebugValue())
1113 continue;
1114
1115 // The DBG_VALUE was referencing a value produced by a terminator. By
1116 // moving the DBG_VALUE, the referenced value also needs invalidating.
1117 MI.getOperand(0).ChangeToRegister(0, false);
1118 MI.moveBefore(&*FirstTerm);
1119 }
1120 }
1121 return InsertBB;
1122}
1123
1124/// Return the basic block label.
1126 return "sunit-dag." + BB->getFullName();
1127}
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).
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 markClonedNodeDeadDefs(const SUnit &SU, MachineInstr &MI, const TargetRegisterInfo *TRI)
Mark physreg defs dead on MI, emitted for a cloned node SU.
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.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
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:762
iterator find(const_arg_type_t< KeyT > Val)
Definition DenseMap.h:766
iterator end()
Definition DenseMap.h:686
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition DenseMap.h:827
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.
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
bool variadicOpsAreDefs() const
Return true if variadic operands of this instruction are definitions.
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,...
bool isVariadic() const
Return true if this instruction can have a variable number of operands.
bool expensiveOrImpossibleToCopy() const
uint8_t getCopyCost() const
getCopyCost - Return the cost of copying a value between two registers in this class.
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
Metadata node.
Definition Metadata.h:1081
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.
MachineOperand class - Representation of each machine instruction operand.
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:54
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:58
void setLatency(unsigned Lat)
Sets the latency for this edge.
@ Barrier
An unknown scheduling barrier.
Definition ScheduleDAG.h:74
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...
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:232
@ CopyToReg
CopyToReg - This node has three operands: a chain, a register number to set to this value,...
Definition ISDOpcodes.h:226
@ TokenFactor
TokenFactor - This node takes multiple tokens as input and produces a single token result.
Definition ISDOpcodes.h:55
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:577
void stable_sort(R &&Range)
Definition STLExtras.h:2132
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
@ Load
The value being inserted comes from a load (InsertElement only).
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:649
void sort(IteratorTy Start, IteratorTy End)
Definition STLExtras.h:1652
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1769
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
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:2028
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
@ End
Run the machine verifier once, at the end of the pipeline.
Definition CodeGen.h:267
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
#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:1455