15#ifndef LLVM_CODEGEN_SCHEDULEDAG_H
16#define LLVM_CODEGEN_SCHEDULEDAG_H
33template <
class GraphType>
struct GraphTraits;
34template<
class Graph>
class GraphWriter;
37class MachineRegisterInfo;
39struct MCSchedClassDesc;
44class TargetRegisterClass;
45class TargetRegisterInfo;
96 unsigned Latency = 0u;
105 : Dep(S, kind), Contents() {
112 "SDep::Anti and SDep::Output must use a non-zero Reg!");
125 Contents.OrdKind = kind;
220 "getReg called on non-register dependence edge!");
230 "setReg called on non-register dependence edge!");
232 "SDep::Anti edge cannot use the zero register!");
234 "SDep::Output edge cannot use the zero register!");
244 enum :
unsigned { BoundaryID = ~0u };
306 bool isDepthCurrent : 1;
307 bool isHeightCurrent : 1;
314 "not enough bits in bitfield");
363 assert(!isInst &&
"Setting SDNode of SUnit with MachineInstr!");
372 "Reading SDNode of SUnit without SDNode!");
383 assert(!isNode &&
"Setting MachineInstr of SUnit with SDNode!");
392 "Reading MachineInstr of SUnit without MachineInstr!");
404 unsigned TrueMemOrderLatency =
418 const_cast<SUnit *
>(
this)->ComputeDepth();
425 if (!isHeightCurrent)
426 const_cast<SUnit *
>(
this)->ComputeHeight();
451 if (Pred.getSUnit() ==
N)
459 if (Succ.getSUnit() ==
N)
479 void ComputeHeight();
484 if (Dep !=
Other.Dep)
486 switch (Dep.getInt()) {
490 return Contents.Reg ==
Other.Contents.Reg;
492 return Contents.OrdKind ==
Other.Contents.OrdKind;
515 virtual void anchor();
517 unsigned CurCycle = 0;
539 assert(!HasReadyFilter &&
"The ready filter must override isReady()");
546 for (
SUnit *SU : Nodes)
609 return getNodeDesc(SU->
getNode());
657 return Operand == x.Operand;
662 return Node->Preds[Operand].getSUnit();
690 return Node->Preds[Operand];
722 std::vector<SUnit> &SUnits;
732 std::vector<int> Index2Node;
734 std::vector<int> Node2Index;
741 void DFS(
const SUnit *SU,
int UpperBound,
bool& HasLoop);
745 void Shift(
BitVector& Visited,
int LowerBound,
int UpperBound);
748 void Allocate(
int n,
int index);
This file implements the BitVector class.
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
unsigned const TargetRegisterInfo * TRI
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
This file defines the PointerIntPair class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
This file describes how to lower LLVM code to machine code.
This class represents an Operation in the Expression.
A possibly irreducible generalization of a Loop.
Describe properties that are true of each instruction in the target description file.
Representation of each machine instruction.
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
PointerIntPair - This class implements a pair of a pointer and small integer.
Represents one node in the SelectionDAG.
bool overlaps(const SDep &Other) const
Returns true if the specified SDep is equivalent except for latency.
Kind getKind() const
Returns an enum value representing the kind of the dependence.
Kind
These are the different kinds of scheduling dependencies.
@ Output
A register output-dependence (aka WAW).
@ Order
Any other ordering dependency.
@ Anti
A register anti-dependence (aka WAR).
@ Data
Regular data dependence (aka true-dependence).
void setLatency(unsigned Lat)
Sets the latency for this edge.
bool isWeak() const
Tests if this a weak dependence.
@ Cluster
Weak DAG edge linking a chain of clustered instrs.
@ Barrier
An unknown scheduling barrier.
@ Artificial
Arbitrary strong DAG edge (no real dependence).
@ MayAliasMem
Nonvolatile load/Store instructions that may alias.
@ Weak
Arbitrary weak DAG edge.
@ MustAliasMem
Nonvolatile load/Store instructions that must alias.
unsigned OrdKind
Additional information about Order dependencies.
unsigned getLatency() const
Returns the latency value for this edge, which roughly means the minimum number of cycles that must e...
bool isAssignedRegDep() const
Tests if this is a Data dependence that is associated with a register.
bool isNormalMemory() const
Tests if this is an Order dependence between two memory accesses where both sides of the dependence a...
bool isArtificial() const
Tests if this is an Order dependence that is marked as "artificial", meaning it isn't necessary for c...
bool operator==(const SDep &Other) const
bool isCtrl() const
Shorthand for getKind() != SDep::Data.
unsigned getReg() const
Returns the register associated with this edge.
SDep(SUnit *S, OrderKind kind)
SDep()
Constructs a null SDep.
bool operator!=(const SDep &Other) const
unsigned Reg
For Data, Anti, and Output dependencies, the associated register.
bool isCluster() const
Tests if this is an Order dependence that is marked as "cluster", meaning it is artificial and wants ...
void dump(const TargetRegisterInfo *TRI=nullptr) const
void setReg(unsigned Reg)
Assigns the associated register for this edge.
bool isBarrier() const
Tests if this is an Order dependence that is marked as a barrier.
bool isNormalMemoryOrBarrier() const
Tests if this is could be any kind of memory dependence.
SDep(SUnit *S, Kind kind, unsigned Reg)
Constructs an SDep with the specified values.
bool isMustAlias() const
Tests if this is an Order dependence that is marked as "must alias", meaning that the SUnits at eithe...
const SUnit * getNode() const
std::forward_iterator_tag iterator_category
unsigned getOperand() const
static SUnitIterator end(SUnit *N)
pointer operator*() const
SUnitIterator operator++(int)
static SUnitIterator begin(SUnit *N)
SUnitIterator & operator++()
pointer operator->() const
bool operator==(const SUnitIterator &x) const
const SDep & getSDep() const
bool operator!=(const SUnitIterator &x) const
bool isArtificialDep() const
bool isCtrlDep() const
Tests if this is not an SDep::Data dependence.
std::ptrdiff_t difference_type
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 setHeightToAtLeast(unsigned NewHeight)
If NewHeight is greater than this node's height value, set it to be the new height value.
bool addPredBarrier(SUnit *SU)
Adds a barrier edge to SU by calling addPred(), with latency 0 generally or latency 1 for a store fol...
void setNode(SDNode *N)
Assigns the representative SDNode for this SUnit.
unsigned NodeQueueId
Queue id of node.
bool isInstr() const
Returns true if this SUnit refers to a machine instruction as opposed to an SDNode.
unsigned TopReadyCycle
Cycle relative to start when node is ready.
SmallVectorImpl< SDep >::const_iterator const_succ_iterator
const MCSchedClassDesc * SchedClass
nullptr or resolved SchedClass.
unsigned NodeNum
Entry # of node in the node vector.
bool hasPhysRegClobbers
Has any physreg defs, used or not.
void biasCriticalPath()
Orders this node's predecessor edges such that the critical path edge occurs first.
bool isUnbuffered
Uses an unbuffered resource.
bool isCallOp
Is a function call operand.
const TargetRegisterClass * CopyDstRC
Is a special copy node if != nullptr.
SUnit(MachineInstr *instr, unsigned nodenum)
Constructs an SUnit for post-regalloc scheduling to represent a MachineInstr.
SmallVectorImpl< SDep >::const_iterator const_pred_iterator
unsigned getHeight() const
Returns the height of this node, which is the length of the maximum path down to any node which has n...
void setInstr(MachineInstr *MI)
Assigns the instruction for the SUnit.
void setHeightDirty()
Sets a flag in this node to indicate that its stored Height value will require recomputation the next...
bool isSucc(const SUnit *N) const
Tests if node N is a successor of this node.
void removePred(const SDep &D)
Removes the specified edge as a pred of the current node if it exists.
bool isPred(const SUnit *N) const
Tests if node N is a predecessor of this node.
unsigned short Latency
Node latency.
SmallVectorImpl< SDep >::iterator pred_iterator
bool isBoundaryNode() const
Boundary nodes are placeholders for the boundary of the scheduling region.
unsigned short NumRegDefsLeft
bool isScheduleHigh
True if preferable to schedule high.
bool isPending
True once pending.
unsigned getDepth() const
Returns the depth of this node, which is the length of the maximum path up to any node which has no p...
bool isScheduled
True once scheduled.
bool isAvailable
True once available.
bool isScheduleLow
True if preferable to schedule low.
bool hasPhysRegDefs
Has physreg defs that are being used.
unsigned BotReadyCycle
Cycle relative to end when node is ready.
void dumpAttributes() const
SmallVector< SDep, 4 > Succs
All sunit successors.
Sched::Preference SchedulingPref
Scheduling preference.
SUnit(SDNode *node, unsigned nodenum)
Constructs an SUnit for pre-regalloc scheduling to represent an SDNode and any nodes flagged to it.
bool hasReservedResource
Uses a reserved resource.
const TargetRegisterClass * CopySrcRC
bool isBottomReady() const
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.
SUnit()
Constructs a placeholder SUnit.
SDNode * Node
Representative node.
bool hasPhysRegUses
Has physreg uses.
void setDepthDirty()
Sets a flag in this node to indicate that its stored Depth value will require recomputation the next ...
MachineInstr * Instr
Alternatively, a MachineInstr.
SmallVector< SDep, 4 > Preds
All sunit predecessors.
SmallVectorImpl< SDep >::iterator succ_iterator
void setDepthToAtLeast(unsigned NewDepth)
If NewDepth is greater than this node's depth value, sets it to be the new depth value.
SUnit * OrigNode
If not this, the node from which this node was cloned.
bool addPred(const SDep &D, bool Required=true)
Adds the specified edge as a pred of the current node if not already.
MachineInstr * getInstr() const
Returns the representative MachineInstr for this SUnit.
This class can compute a topological ordering for SUnits and provides methods for dynamically updatin...
void RemovePred(SUnit *M, SUnit *N)
Updates the topological ordering to accommodate an edge to be removed from the specified node N from ...
bool WillCreateCycle(SUnit *TargetSU, SUnit *SU)
Returns true if addPred(TargetSU, SU) creates a cycle.
void MarkDirty()
Mark the ordering as temporarily broken, after a new node has been added.
void AddSUnitWithoutPredecessors(const SUnit *SU)
Add a SUnit without predecessors to the end of the topological order.
const_reverse_iterator rbegin() const
std::vector< int >::reverse_iterator reverse_iterator
std::vector< int > GetSubGraph(const SUnit &StartSU, const SUnit &TargetSU, bool &Success)
Returns an array of SUs that are both in the successor subtree of StartSU and in the predecessor subt...
const_iterator end() const
void InitDAGTopologicalSorting()
Creates the initial topological ordering from the DAG to be scheduled.
void AddPred(SUnit *Y, SUnit *X)
Updates the topological ordering to accommodate an edge to be added from SUnit X to SUnit Y.
std::vector< int >::const_iterator const_iterator
std::vector< int >::iterator iterator
const_reverse_iterator rend() const
const_iterator begin() const
reverse_iterator rbegin()
bool IsReachable(const SUnit *SU, const SUnit *TargetSU)
Checks if SU is reachable from TargetSU.
void AddPredQueued(SUnit *Y, SUnit *X)
Queues an update to the topological ordering to accommodate an edge to be added from SUnit X to SUnit...
std::vector< int >::const_reverse_iterator const_reverse_iterator
const MCInstrDesc * getInstrDesc(const SUnit *SU) const
Returns the MCInstrDesc of this SUnit.
MachineRegisterInfo & MRI
Virtual/real register map.
void clearDAG()
Clears the DAG state (between regions).
virtual std::string getGraphNodeLabel(const SUnit *SU) const =0
Returns a label for an SUnit node in a visualization of the ScheduleDAG.
const TargetInstrInfo * TII
Target instruction information.
virtual std::string getDAGName() const =0
Returns a label for the region of code covered by the DAG.
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 & operator=(const ScheduleDAG &)=delete
virtual void dump() const =0
virtual void viewGraph()
Out-of-line implementation with no arguments is handy for gdb.
ScheduleDAG(const ScheduleDAG &)=delete
void dumpNodeAll(const SUnit &SU) const
const TargetMachine & TM
Target processor.
unsigned VerifyScheduledDAG(bool isBottomUp)
Verifies that all SUnits were scheduled and that their state is consistent.
virtual void addCustomGraphFeatures(GraphWriter< ScheduleDAG * > &) const
Adds custom features for a visualization of the ScheduleDAG.
virtual void dumpNode(const SUnit &SU) const =0
void dumpNodeName(const SUnit &SU) const
SUnit ExitSU
Special node for the region exit.
This interface is used to plug different priorities computation algorithms into the list scheduler.
void setCurCycle(unsigned Cycle)
SchedulingPriorityQueue(bool rf=false)
virtual void remove(SUnit *SU)=0
virtual bool isBottomUp() const =0
virtual void releaseState()=0
virtual void scheduledNode(SUnit *)
As each node is scheduled, this method is invoked.
virtual bool isReady(SUnit *) const
virtual bool tracksRegPressure() const
virtual void dump(ScheduleDAG *) const
bool hasReadyFilter() const
virtual void initNodes(std::vector< SUnit > &SUnits)=0
virtual ~SchedulingPriorityQueue()=default
virtual bool empty() const =0
virtual void unscheduledNode(SUnit *)
void push_all(const std::vector< SUnit * > &Nodes)
virtual void addNode(const SUnit *SU)=0
unsigned getCurCycle() const
virtual void updateNode(const SUnit *SU)=0
virtual void push(SUnit *U)=0
typename SuperClass::const_iterator const_iterator
typename SuperClass::iterator iterator
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.
Primary interface to the complete machine description for the target machine.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
SUnitIterator ChildIteratorType
static ChildIteratorType child_begin(NodeRef N)
static NodeRef getEntryNode(SUnit *N)
static ChildIteratorType child_end(NodeRef N)
static nodes_iterator nodes_begin(ScheduleDAG *G)
static nodes_iterator nodes_end(ScheduleDAG *G)
pointer_iterator< std::vector< SUnit >::iterator > nodes_iterator
Summarize the scheduling resources required for an instruction of a particular scheduling class.