llvm.org GIT mirror llvm / 960c80d
Rename PBQP RegAllocSolver local variables to conform to LLVM coding style. No functional change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204022 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 6 years ago
1 changed file(s) with 95 addition(s) and 95 deletion(s). Raw diff Collapse all Expand all
3434 /// Keeps track of the number of infinities in each row and column.
3535 class MatrixMetadata {
3636 private:
37 MatrixMetadata(const MatrixMetadata&);
38 void operator=(const MatrixMetadata&);
37 MatrixMetadata(const MatrixMetadata&) = delete;
38 void operator=(const MatrixMetadata&) = delete;
3939 public:
40 MatrixMetadata(const PBQP::Matrix& m)
41 : worstRow(0), worstCol(0),
42 unsafeRows(new bool[m.getRows() - 1]()),
43 unsafeCols(new bool[m.getCols() - 1]()) {
44
45 unsigned* colCounts = new unsigned[m.getCols() - 1]();
46
47 for (unsigned i = 1; i < m.getRows(); ++i) {
48 unsigned rowCount = 0;
49 for (unsigned j = 1; j < m.getCols(); ++j) {
50 if (m[i][j] == std::numeric_limits::infinity()) {
51 ++rowCount;
52 ++colCounts[j - 1];
53 unsafeRows[i - 1] = true;
54 unsafeCols[j - 1] = true;
40 MatrixMetadata(const PBQP::Matrix& M)
41 : WorstRow(0), WorstCol(0),
42 UnsafeRows(new bool[M.getRows() - 1]()),
43 UnsafeCols(new bool[M.getCols() - 1]()) {
44
45 unsigned* ColCounts = new unsigned[M.getCols() - 1]();
46
47 for (unsigned i = 1; i < M.getRows(); ++i) {
48 unsigned RowCount = 0;
49 for (unsigned j = 1; j < M.getCols(); ++j) {
50 if (M[i][j] == std::numeric_limits::infinity()) {
51 ++RowCount;
52 ++ColCounts[j - 1];
53 UnsafeRows[i - 1] = true;
54 UnsafeCols[j - 1] = true;
5555 }
5656 }
57 worstRow = std::max(worstRow, rowCount);
58 }
59 unsigned worstColCountForCurRow =
60 *std::max_element(colCounts, colCounts + m.getCols() - 1);
61 worstCol = std::max(worstCol, worstColCountForCurRow);
62 delete[] colCounts;
57 WorstRow = std::max(WorstRow, RowCount);
58 }
59 unsigned WorstColCountForCurRow =
60 *std::max_element(ColCounts, ColCounts + M.getCols() - 1);
61 WorstCol = std::max(WorstCol, WorstColCountForCurRow);
62 delete[] ColCounts;
6363 }
6464
6565 ~MatrixMetadata() {
66 delete[] unsafeRows;
67 delete[] unsafeCols;
68 }
69
70 unsigned getWorstRow() const { return worstRow; }
71 unsigned getWorstCol() const { return worstCol; }
72 const bool* getUnsafeRows() const { return unsafeRows; }
73 const bool* getUnsafeCols() const { return unsafeCols; }
74
75 private:
76 unsigned worstRow, worstCol;
77 bool* unsafeRows;
78 bool* unsafeCols;
66 delete[] UnsafeRows;
67 delete[] UnsafeCols;
68 }
69
70 unsigned getWorstRow() const { return WorstRow; }
71 unsigned getWorstCol() const { return WorstCol; }
72 const bool* getUnsafeRows() const { return UnsafeRows; }
73 const bool* getUnsafeCols() const { return UnsafeCols; }
74
75 private:
76 unsigned WorstRow, WorstCol;
77 bool* UnsafeRows;
78 bool* UnsafeCols;
7979 };
8080
8181 class NodeMetadata {
8585 ConservativelyAllocatable,
8686 NotProvablyAllocatable } ReductionState;
8787
88 NodeMetadata() : rs(Unprocessed), deniedOpts(0), optUnsafeEdges(0) {}
89 ~NodeMetadata() { delete[] optUnsafeEdges; }
90
91 void setup(const Vector& costs) {
92 numOpts = costs.getLength() - 1;
93 optUnsafeEdges = new unsigned[numOpts]();
94 }
95
96 ReductionState getReductionState() const { return rs; }
97 void setReductionState(ReductionState rs) { this->rs = rs; }
98
99 void handleAddEdge(const MatrixMetadata& md, bool transpose) {
100 deniedOpts += transpose ? md.getWorstCol() : md.getWorstRow();
101 const bool* unsafeOpts =
102 transpose ? md.getUnsafeCols() : md.getUnsafeRows();
103 for (unsigned i = 0; i < numOpts; ++i)
104 optUnsafeEdges[i] += unsafeOpts[i];
105 }
106
107 void handleRemoveEdge(const MatrixMetadata& md, bool transpose) {
108 deniedOpts -= transpose ? md.getWorstCol() : md.getWorstRow();
109 const bool* unsafeOpts =
110 transpose ? md.getUnsafeCols() : md.getUnsafeRows();
111 for (unsigned i = 0; i < numOpts; ++i)
112 optUnsafeEdges[i] -= unsafeOpts[i];
88 NodeMetadata() : RS(Unprocessed), DeniedOpts(0), OptUnsafeEdges(0) {}
89 ~NodeMetadata() { delete[] OptUnsafeEdges; }
90
91 void setup(const Vector& Costs) {
92 NumOpts = Costs.getLength() - 1;
93 OptUnsafeEdges = new unsigned[NumOpts]();
94 }
95
96 ReductionState getReductionState() const { return RS; }
97 void setReductionState(ReductionState RS) { this->RS = RS; }
98
99 void handleAddEdge(const MatrixMetadata& MD, bool Transpose) {
100 DeniedOpts += Transpose ? MD.getWorstCol() : MD.getWorstRow();
101 const bool* UnsafeOpts =
102 Transpose ? MD.getUnsafeCols() : MD.getUnsafeRows();
103 for (unsigned i = 0; i < NumOpts; ++i)
104 OptUnsafeEdges[i] += UnsafeOpts[i];
105 }
106
107 void handleRemoveEdge(const MatrixMetadata& MD, bool Transpose) {
108 DeniedOpts -= Transpose ? MD.getWorstCol() : MD.getWorstRow();
109 const bool* UnsafeOpts =
110 Transpose ? MD.getUnsafeCols() : MD.getUnsafeRows();
111 for (unsigned i = 0; i < NumOpts; ++i)
112 OptUnsafeEdges[i] -= UnsafeOpts[i];
113113 }
114114
115115 bool isConservativelyAllocatable() const {
116 return (deniedOpts < numOpts) ||
117 (std::find(optUnsafeEdges, optUnsafeEdges + numOpts, 0) !=
118 optUnsafeEdges + numOpts);
119 }
120
121 private:
122 ReductionState rs;
123 unsigned numOpts;
124 unsigned deniedOpts;
125 unsigned* optUnsafeEdges;
116 return (DeniedOpts < NumOpts) ||
117 (std::find(OptUnsafeEdges, OptUnsafeEdges + NumOpts, 0) !=
118 OptUnsafeEdges + NumOpts);
119 }
120
121 private:
122 ReductionState RS;
123 unsigned NumOpts;
124 unsigned DeniedOpts;
125 unsigned* OptUnsafeEdges;
126126 };
127127
128128 class RegAllocSolverImpl {
174174 }
175175
176176 void handleDisconnectEdge(EdgeId EId, NodeId NId) {
177 NodeMetadata& nMd = G.getNodeMetadata(NId);
178 const MatrixMetadata& mMd = G.getEdgeCosts(EId).getMetadata();
179 nMd.handleRemoveEdge(mMd, NId == G.getEdgeNode2Id(EId));
177 NodeMetadata& NMd = G.getNodeMetadata(NId);
178 const MatrixMetadata& MMd = G.getEdgeCosts(EId).getMetadata();
179 NMd.handleRemoveEdge(MMd, NId == G.getEdgeNode2Id(EId));
180180 if (G.getNodeDegree(NId) == 3) {
181181 // This node is becoming optimally reducible.
182182 moveToOptimallyReducibleNodes(NId);
183 } else if (nMd.getReductionState() ==
183 } else if (NMd.getReductionState() ==
184184 NodeMetadata::NotProvablyAllocatable &&
185 nMd.isConservativelyAllocatable()) {
185 NMd.isConservativelyAllocatable()) {
186186 // This node just became conservatively allocatable.
187187 moveToConservativelyAllocatableNodes(NId);
188188 }
189189 }
190190
191191 void handleReconnectEdge(EdgeId EId, NodeId NId) {
192 NodeMetadata& nMd = G.getNodeMetadata(NId);
193 const MatrixMetadata& mMd = G.getEdgeCosts(EId).getMetadata();
194 nMd.handleAddEdge(mMd, NId == G.getEdgeNode2Id(EId));
192 NodeMetadata& NMd = G.getNodeMetadata(NId);
193 const MatrixMetadata& MMd = G.getEdgeCosts(EId).getMetadata();
194 NMd.handleAddEdge(MMd, NId == G.getEdgeNode2Id(EId));
195195 }
196196
197197 void handleSetEdgeCosts(EdgeId EId, const Matrix& NewCosts) {
198198 handleRemoveEdge(EId);
199199
200 NodeId n1Id = G.getEdgeNode1Id(EId);
201 NodeId n2Id = G.getEdgeNode2Id(EId);
202 NodeMetadata& n1Md = G.getNodeMetadata(n1Id);
203 NodeMetadata& n2Md = G.getNodeMetadata(n2Id);
204 const MatrixMetadata& mMd = NewCosts.getMetadata();
205 n1Md.handleAddEdge(mMd, n1Id != G.getEdgeNode1Id(EId));
206 n2Md.handleAddEdge(mMd, n2Id != G.getEdgeNode1Id(EId));
200 NodeId N1Id = G.getEdgeNode1Id(EId);
201 NodeId N2Id = G.getEdgeNode2Id(EId);
202 NodeMetadata& N1Md = G.getNodeMetadata(N1Id);
203 NodeMetadata& N2Md = G.getNodeMetadata(N2Id);
204 const MatrixMetadata& MMd = NewCosts.getMetadata();
205 N1Md.handleAddEdge(MMd, N1Id != G.getEdgeNode1Id(EId));
206 N2Md.handleAddEdge(MMd, N2Id != G.getEdgeNode1Id(EId));
207207 }
208208
209209 private:
280280 // Consume worklists.
281281 while (true) {
282282 if (!OptimallyReducibleNodes.empty()) {
283 NodeSet::iterator nItr = OptimallyReducibleNodes.begin();
284 NodeId NId = *nItr;
285 OptimallyReducibleNodes.erase(nItr);
283 NodeSet::iterator NItr = OptimallyReducibleNodes.begin();
284 NodeId NId = *NItr;
285 OptimallyReducibleNodes.erase(NItr);
286286 NodeStack.push_back(NId);
287287 switch (G.getNodeDegree(NId)) {
288288 case 0:
302302 // would be better to push nodes with lower 'expected' or worst-case
303303 // register costs first (since early nodes are the most
304304 // constrained).
305 NodeSet::iterator nItr = ConservativelyAllocatableNodes.begin();
306 NodeId NId = *nItr;
307 ConservativelyAllocatableNodes.erase(nItr);
305 NodeSet::iterator NItr = ConservativelyAllocatableNodes.begin();
306 NodeId NId = *NItr;
307 ConservativelyAllocatableNodes.erase(NItr);
308308 NodeStack.push_back(NId);
309309 G.disconnectAllNeighborsFromNode(NId);
310310
311311 } else if (!NotProvablyAllocatableNodes.empty()) {
312 NodeSet::iterator nItr =
312 NodeSet::iterator NItr =
313313 std::min_element(NotProvablyAllocatableNodes.begin(),
314314 NotProvablyAllocatableNodes.end(),
315315 SpillCostComparator(G));
316 NodeId NId = *nItr;
317 NotProvablyAllocatableNodes.erase(nItr);
316 NodeId NId = *NItr;
317 NotProvablyAllocatableNodes.erase(NItr);
318318 NodeStack.push_back(NId);
319319 G.disconnectAllNeighborsFromNode(NId);
320320 } else