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