LLVM 24.0.0git
ResourcePriorityQueue.h
Go to the documentation of this file.
1//===----- ResourcePriorityQueue.h - A DFA-oriented priority queue -------===//
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 file implements the ResourcePriorityQueue class, which is a
10// SchedulingPriorityQueue that schedules using DFA state to
11// reduce the length of the critical path through the basic block
12// on VLIW platforms.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_CODEGEN_RESOURCEPRIORITYQUEUE_H
17#define LLVM_CODEGEN_RESOURCEPRIORITYQUEUE_H
18
20
21namespace llvm {
22 class DFAPacketizer;
25 class SelectionDAGISel;
26 struct SelectionDAGOptions;
27 class TargetInstrInfo;
29
30 /// Sorting functions for the Available queue.
33 explicit resource_sort(ResourcePriorityQueue *pq) : PQ(pq) {}
34
35 LLVM_ABI bool operator()(const SUnit *LHS, const SUnit *RHS) const;
36 };
37
39 /// SUnits - The SUnits for the current graph.
40 std::vector<SUnit> *SUnits;
41
42 /// NumNodesSolelyBlocking - This vector contains, for every node in the
43 /// Queue, the number of nodes that the node is the sole unscheduled
44 /// predecessor for. This is used as a tie-breaker heuristic for better
45 /// mobility.
46 std::vector<unsigned> NumNodesSolelyBlocking;
47
48 /// Queue - The queue.
49 std::vector<SUnit*> Queue;
50
51 /// RegPressure - Tracking current reg pressure per register class.
52 ///
53 std::vector<unsigned> RegPressure;
54
55 /// RegLimit - Tracking the number of allocatable registers per register
56 /// class.
57 std::vector<unsigned> RegLimit;
58
59 resource_sort Picker;
60 const TargetRegisterInfo *TRI;
61 const TargetLowering *TLI;
62 const TargetInstrInfo *TII;
63 const SelectionDAGOptions *Opts;
64 const InstrItineraryData* InstrItins;
65 /// ResourcesModel - Represents VLIW state.
66 /// Not limited to VLIW targets per say, but assumes
67 /// definition of DFA by a target.
68 std::unique_ptr<DFAPacketizer> ResourcesModel;
69
70 /// Resource model - packet/bundle model. Purely
71 /// internal at the time.
72 std::vector<SUnit*> Packet;
73
74 /// Heuristics for estimating register pressure.
75 unsigned ParallelLiveRanges;
76 int HorizontalVerticalBalance;
77
78 public:
81
82 bool isBottomUp() const override { return false; }
83
84 void initNodes(std::vector<SUnit> &sunits) override;
85
86 void addNode(const SUnit *SU) override {
87 NumNodesSolelyBlocking.resize(SUnits->size(), 0);
88 }
89
90 void updateNode(const SUnit *SU) override {}
91
92 void releaseState() override {
93 SUnits = nullptr;
94 }
95
96 unsigned getLatency(unsigned NodeNum) const {
97 assert(NodeNum < (*SUnits).size());
98 return (*SUnits)[NodeNum].getHeight();
99 }
100
101 unsigned getNumSolelyBlockNodes(unsigned NodeNum) const {
102 assert(NodeNum < NumNodesSolelyBlocking.size());
103 return NumNodesSolelyBlocking[NodeNum];
104 }
105
106 /// Single cost function reflecting benefit of scheduling SU
107 /// in the current cycle.
108 int SUSchedulingCost (SUnit *SU);
109
110 /// InitNumRegDefsLeft - Determine the # of regs defined by this node.
111 ///
112 void initNumRegDefsLeft(SUnit *SU);
113 int regPressureDelta(SUnit *SU, bool RawPressure = false);
114 int rawRegPressureDelta (SUnit *SU, unsigned RCId);
115
116 bool empty() const override { return Queue.empty(); }
117
118 void push(SUnit *U) override;
119
120 SUnit *pop() override;
121
122 void remove(SUnit *SU) override;
123
124 /// scheduledNode - Main resource tracking point.
125 void scheduledNode(SUnit *SU) override;
126 bool isResourceAvailable(SUnit *SU);
127 void reserveResources(SUnit *SU);
128
129private:
130 void adjustPriorityOfUnscheduledPreds(SUnit *SU);
131 SUnit *getSingleUnscheduledPred(SUnit *SU);
132 unsigned numberRCValPredInSU (SUnit *SU, unsigned RCId);
133 unsigned numberRCValSuccInSU (SUnit *SU, unsigned RCId);
134 };
135}
136
137#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition Compiler.h:211
Value * RHS
Value * LHS
Itinerary data supplied by a subtarget to be used by a target.
ResourcePriorityQueue(SelectionDAGISel *IS)
unsigned getLatency(unsigned NodeNum) const
void updateNode(const SUnit *SU) override
unsigned getNumSolelyBlockNodes(unsigned NodeNum) const
void addNode(const SUnit *SU) override
Scheduling unit. This is a node in the scheduling DAG.
SchedulingPriorityQueue(bool rf=false)
SelectionDAGISel - This is the common base class used for SelectionDAG-based pattern-matching instruc...
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...
This is an optimization pass for GlobalISel generic memory operations.
Sorting functions for the Available queue.
LLVM_ABI bool operator()(const SUnit *LHS, const SUnit *RHS) const
This heuristic is used if DFA scheduling is not desired for some VLIW platform.
ResourcePriorityQueue * PQ
resource_sort(ResourcePriorityQueue *pq)