blob: 11452fdb747ac92bcbf1d687924d3b52cf89f011 [file] [log] [blame]
Eugene Zelenkofb7f7922017-09-21 23:20:16 +00001//===- SpillPlacement.cpp - Optimal Spill Code Placement ------------------===//
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the spill code placement analysis.
10//
11// Each edge bundle corresponds to a node in a Hopfield network. Constraints on
12// basic blocks are weighted by the block frequency and added to become the node
13// bias.
14//
15// Transparent basic blocks have the variable live through, but don't care if it
16// is spilled or in a register. These blocks become connections in the Hopfield
17// network, again weighted by block frequency.
18//
19// The Hopfield network minimizes (possibly locally) its energy function:
20//
21// E = -sum_n V_n * ( B_n + sum_{n, m linked by b} V_m * F_b )
22//
23// The energy function represents the expected spill code execution frequency,
24// or the cost of spilling. This is a Lyapunov function which never increases
25// when a node is updated. It is guaranteed to converge to a local minimum.
26//
27//===----------------------------------------------------------------------===//
28
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +000029#include "SpillPlacement.h"
Eugene Zelenkofb7f7922017-09-21 23:20:16 +000030#include "llvm/ADT/ArrayRef.h"
Jakub Staszakb6970262013-03-18 23:45:45 +000031#include "llvm/ADT/BitVector.h"
Eugene Zelenkofb7f7922017-09-21 23:20:16 +000032#include "llvm/ADT/SmallVector.h"
33#include "llvm/ADT/SparseSet.h"
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +000034#include "llvm/CodeGen/EdgeBundles.h"
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +000035#include "llvm/CodeGen/MachineBasicBlock.h"
Benjamin Kramere2a1d892013-06-17 19:00:36 +000036#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +000037#include "llvm/CodeGen/MachineFunction.h"
38#include "llvm/CodeGen/MachineLoopInfo.h"
39#include "llvm/CodeGen/Passes.h"
Eugene Zelenkofb7f7922017-09-21 23:20:16 +000040#include "llvm/Pass.h"
41#include "llvm/Support/BlockFrequency.h"
42#include <algorithm>
43#include <cassert>
44#include <cstdint>
45#include <utility>
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +000046
47using namespace llvm;
48
Matthias Braun1527baa2017-05-25 21:26:32 +000049#define DEBUG_TYPE "spill-code-placement"
Chandler Carruth1b9dde02014-04-22 02:02:50 +000050
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +000051char SpillPlacement::ID = 0;
Eugene Zelenkofb7f7922017-09-21 23:20:16 +000052
53char &llvm::SpillPlacementID = SpillPlacement::ID;
54
Matthias Braun1527baa2017-05-25 21:26:32 +000055INITIALIZE_PASS_BEGIN(SpillPlacement, DEBUG_TYPE,
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +000056 "Spill Code Placement Analysis", true, true)
57INITIALIZE_PASS_DEPENDENCY(EdgeBundles)
58INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo)
Matthias Braun1527baa2017-05-25 21:26:32 +000059INITIALIZE_PASS_END(SpillPlacement, DEBUG_TYPE,
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +000060 "Spill Code Placement Analysis", true, true)
61
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +000062void SpillPlacement::getAnalysisUsage(AnalysisUsage &AU) const {
63 AU.setPreservesAll();
Benjamin Kramere2a1d892013-06-17 19:00:36 +000064 AU.addRequired<MachineBlockFrequencyInfo>();
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +000065 AU.addRequiredTransitive<EdgeBundles>();
66 AU.addRequiredTransitive<MachineLoopInfo>();
67 MachineFunctionPass::getAnalysisUsage(AU);
68}
69
70/// Node - Each edge bundle corresponds to a Hopfield node.
71///
72/// The node contains precomputed frequency data that only depends on the CFG,
73/// but Bias and Links are computed each time placeSpills is called.
74///
75/// The node Value is positive when the variable should be in a register. The
76/// value can change when linked nodes change, but convergence is very fast
77/// because all weights are positive.
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +000078struct SpillPlacement::Node {
Jakob Stoklund Olesenc5454ff2013-07-16 18:26:15 +000079 /// BiasN - Sum of blocks that prefer a spill.
80 BlockFrequency BiasN;
Eugene Zelenkofb7f7922017-09-21 23:20:16 +000081
Jakob Stoklund Olesenc5454ff2013-07-16 18:26:15 +000082 /// BiasP - Sum of blocks that prefer a register.
83 BlockFrequency BiasP;
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +000084
85 /// Value - Output value of this node computed from the Bias and links.
Jakob Stoklund Olesenc5454ff2013-07-16 18:26:15 +000086 /// This is always on of the values {-1, 0, 1}. A positive number means the
87 /// variable should go in a register through this bundle.
88 int Value;
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +000089
Eugene Zelenkofb7f7922017-09-21 23:20:16 +000090 using LinkVector = SmallVector<std::pair<BlockFrequency, unsigned>, 4>;
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +000091
92 /// Links - (Weight, BundleNo) for all transparent blocks connecting to other
Jakob Stoklund Olesenc5454ff2013-07-16 18:26:15 +000093 /// bundles. The weights are all positive block frequencies.
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +000094 LinkVector Links;
95
Jakob Stoklund Olesenc5454ff2013-07-16 18:26:15 +000096 /// SumLinkWeights - Cached sum of the weights of all links + ThresHold.
97 BlockFrequency SumLinkWeights;
98
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +000099 /// preferReg - Return true when this node prefers to be in a register.
100 bool preferReg() const {
101 // Undecided nodes (Value==0) go on the stack.
102 return Value > 0;
103 }
104
105 /// mustSpill - Return True if this node is so biased that it must spill.
106 bool mustSpill() const {
Jakob Stoklund Olesenc5454ff2013-07-16 18:26:15 +0000107 // We must spill if Bias < -sum(weights) or the MustSpill flag was set.
108 // BiasN is saturated when MustSpill is set, make sure this still returns
109 // true when the RHS saturates. Note that SumLinkWeights includes Threshold.
110 return BiasN >= BiasP + SumLinkWeights;
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000111 }
112
113 /// clear - Reset per-query data, but preserve frequencies that only depend on
Eugene Zelenkofb7f7922017-09-21 23:20:16 +0000114 /// the CFG.
Chandler Carruth7425c8c2014-10-02 22:23:14 +0000115 void clear(const BlockFrequency &Threshold) {
Jakob Stoklund Olesenc5454ff2013-07-16 18:26:15 +0000116 BiasN = BiasP = Value = 0;
Chandler Carruth7425c8c2014-10-02 22:23:14 +0000117 SumLinkWeights = Threshold;
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000118 Links.clear();
119 }
120
121 /// addLink - Add a link to bundle b with weight w.
Jakob Stoklund Olesenc5454ff2013-07-16 18:26:15 +0000122 void addLink(unsigned b, BlockFrequency w) {
123 // Update cached sum.
124 SumLinkWeights += w;
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000125
126 // There can be multiple links to the same bundle, add them up.
127 for (LinkVector::iterator I = Links.begin(), E = Links.end(); I != E; ++I)
128 if (I->second == b) {
129 I->first += w;
130 return;
131 }
132 // This must be the first link to b.
133 Links.push_back(std::make_pair(w, b));
134 }
135
Jakob Stoklund Olesenc5454ff2013-07-16 18:26:15 +0000136 /// addBias - Bias this node.
137 void addBias(BlockFrequency freq, BorderConstraint direction) {
138 switch (direction) {
139 default:
140 break;
141 case PrefReg:
142 BiasP += freq;
143 break;
144 case PrefSpill:
145 BiasN += freq;
146 break;
147 case MustSpill:
148 BiasN = BlockFrequency::getMaxFrequency();
149 break;
150 }
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000151 }
152
153 /// update - Recompute Value from Bias and Links. Return true when node
154 /// preference changes.
Chandler Carruth7425c8c2014-10-02 22:23:14 +0000155 bool update(const Node nodes[], const BlockFrequency &Threshold) {
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000156 // Compute the weighted sum of inputs.
Jakob Stoklund Olesenc5454ff2013-07-16 18:26:15 +0000157 BlockFrequency SumN = BiasN;
158 BlockFrequency SumP = BiasP;
159 for (LinkVector::iterator I = Links.begin(), E = Links.end(); I != E; ++I) {
160 if (nodes[I->second].Value == -1)
161 SumN += I->first;
162 else if (nodes[I->second].Value == 1)
163 SumP += I->first;
164 }
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000165
Jakob Stoklund Olesenc5454ff2013-07-16 18:26:15 +0000166 // Each weighted sum is going to be less than the total frequency of the
167 // bundle. Ideally, we should simply set Value = sign(SumP - SumN), but we
168 // will add a dead zone around 0 for two reasons:
169 //
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000170 // 1. It avoids arbitrary bias when all links are 0 as is possible during
171 // initial iterations.
172 // 2. It helps tame rounding errors when the links nominally sum to 0.
Jakob Stoklund Olesenc5454ff2013-07-16 18:26:15 +0000173 //
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000174 bool Before = preferReg();
Chandler Carruth7425c8c2014-10-02 22:23:14 +0000175 if (SumN >= SumP + Threshold)
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000176 Value = -1;
Chandler Carruth7425c8c2014-10-02 22:23:14 +0000177 else if (SumP >= SumN + Threshold)
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000178 Value = 1;
179 else
180 Value = 0;
181 return Before != preferReg();
182 }
Quentin Colombetb926bda2016-05-19 22:40:37 +0000183
184 void getDissentingNeighbors(SparseSet<unsigned> &List,
185 const Node nodes[]) const {
186 for (const auto &Elt : Links) {
187 unsigned n = Elt.second;
188 // Neighbors that already have the same value are not going to
189 // change because of this node changing.
190 if (Value != nodes[n].Value)
191 List.insert(n);
192 }
193 }
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000194};
195
196bool SpillPlacement::runOnMachineFunction(MachineFunction &mf) {
197 MF = &mf;
198 bundles = &getAnalysis<EdgeBundles>();
199 loops = &getAnalysis<MachineLoopInfo>();
200
201 assert(!nodes && "Leaking node array");
202 nodes = new Node[bundles->getNumBundles()];
Quentin Colombetb926bda2016-05-19 22:40:37 +0000203 TodoList.clear();
204 TodoList.setUniverse(bundles->getNumBundles());
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000205
206 // Compute total ingoing and outgoing block frequencies for all bundles.
Jakob Stoklund Olesenc5454ff2013-07-16 18:26:15 +0000207 BlockFrequencies.resize(mf.getNumBlockIDs());
Michael Gottesman092647b2013-12-14 00:25:47 +0000208 MBFI = &getAnalysis<MachineBlockFrequencyInfo>();
Duncan P. N. Exon Smitha5df8132014-04-08 19:18:56 +0000209 setThreshold(MBFI->getEntryFreq());
Duncan P. N. Exon Smithf1ff53e2015-10-09 22:56:24 +0000210 for (auto &I : mf) {
211 unsigned Num = I.getNumber();
212 BlockFrequencies[Num] = MBFI->getBlockFreq(&I);
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000213 }
214
215 // We never change the function.
216 return false;
217}
218
219void SpillPlacement::releaseMemory() {
220 delete[] nodes;
Craig Topperc0196b12014-04-14 00:51:57 +0000221 nodes = nullptr;
Quentin Colombetb926bda2016-05-19 22:40:37 +0000222 TodoList.clear();
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000223}
224
225/// activate - mark node n as active if it wasn't already.
226void SpillPlacement::activate(unsigned n) {
Quentin Colombetb926bda2016-05-19 22:40:37 +0000227 TodoList.insert(n);
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000228 if (ActiveNodes->test(n))
229 return;
230 ActiveNodes->set(n);
Chandler Carruth7425c8c2014-10-02 22:23:14 +0000231 nodes[n].clear(Threshold);
Jakob Stoklund Olesen29268b52012-05-21 03:11:23 +0000232
233 // Very large bundles usually come from big switches, indirect branches,
234 // landing pads, or loops with many 'continue' statements. It is difficult to
235 // allocate registers when so many different blocks are involved.
236 //
Jakob Stoklund Olesenc5454ff2013-07-16 18:26:15 +0000237 // Give a small negative bias to large bundles such that a substantial
238 // fraction of the connected blocks need to be interested before we consider
239 // expanding the region through the bundle. This helps compile time by
240 // limiting the number of blocks visited and the number of links in the
241 // Hopfield network.
242 if (bundles->getBlocks(n).size() > 100) {
243 nodes[n].BiasP = 0;
Michael Gottesman5e985ee2013-12-14 02:37:38 +0000244 nodes[n].BiasN = (MBFI->getEntryFreq() / 16);
Jakob Stoklund Olesenc5454ff2013-07-16 18:26:15 +0000245 }
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000246}
247
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000248/// Set the threshold for a given entry frequency.
Chandler Carruth7425c8c2014-10-02 22:23:14 +0000249///
250/// Set the threshold relative to \c Entry. Since the threshold is used as a
251/// bound on the open interval (-Threshold;Threshold), 1 is the minimum
252/// threshold.
253void SpillPlacement::setThreshold(const BlockFrequency &Entry) {
254 // Apparently 2 is a good threshold when Entry==2^14, but we need to scale
255 // it. Divide by 2^13, rounding as appropriate.
256 uint64_t Freq = Entry.getFrequency();
257 uint64_t Scaled = (Freq >> 13) + bool(Freq & (1 << 12));
258 Threshold = std::max(UINT64_C(1), Scaled);
259}
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000260
Jakob Stoklund Olesen36b5d8a2011-04-06 19:13:57 +0000261/// addConstraints - Compute node biases and weights from a set of constraints.
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000262/// Set a bit in NodeMask for each active node.
Jakob Stoklund Olesen36b5d8a2011-04-06 19:13:57 +0000263void SpillPlacement::addConstraints(ArrayRef<BlockConstraint> LiveBlocks) {
264 for (ArrayRef<BlockConstraint>::iterator I = LiveBlocks.begin(),
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000265 E = LiveBlocks.end(); I != E; ++I) {
Jakob Stoklund Olesenc5454ff2013-07-16 18:26:15 +0000266 BlockFrequency Freq = BlockFrequencies[I->Number];
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000267
268 // Live-in to block?
269 if (I->Entry != DontCare) {
Eugene Zelenkofb7f7922017-09-21 23:20:16 +0000270 unsigned ib = bundles->getBundle(I->Number, false);
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000271 activate(ib);
Jakob Stoklund Olesenc5454ff2013-07-16 18:26:15 +0000272 nodes[ib].addBias(Freq, I->Entry);
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000273 }
274
275 // Live-out from block?
276 if (I->Exit != DontCare) {
Eugene Zelenkofb7f7922017-09-21 23:20:16 +0000277 unsigned ob = bundles->getBundle(I->Number, true);
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000278 activate(ob);
Jakob Stoklund Olesenc5454ff2013-07-16 18:26:15 +0000279 nodes[ob].addBias(Freq, I->Exit);
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000280 }
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000281 }
282}
283
Jakob Stoklund Olesen0ab5d0e2011-07-23 03:10:19 +0000284/// addPrefSpill - Same as addConstraints(PrefSpill)
Jakob Stoklund Olesen86954522011-08-03 23:09:38 +0000285void SpillPlacement::addPrefSpill(ArrayRef<unsigned> Blocks, bool Strong) {
Jakob Stoklund Olesen0ab5d0e2011-07-23 03:10:19 +0000286 for (ArrayRef<unsigned>::iterator I = Blocks.begin(), E = Blocks.end();
287 I != E; ++I) {
Jakob Stoklund Olesenc5454ff2013-07-16 18:26:15 +0000288 BlockFrequency Freq = BlockFrequencies[*I];
Jakob Stoklund Olesen86954522011-08-03 23:09:38 +0000289 if (Strong)
290 Freq += Freq;
Eugene Zelenkofb7f7922017-09-21 23:20:16 +0000291 unsigned ib = bundles->getBundle(*I, false);
292 unsigned ob = bundles->getBundle(*I, true);
Jakob Stoklund Olesen0ab5d0e2011-07-23 03:10:19 +0000293 activate(ib);
294 activate(ob);
Jakob Stoklund Olesenc5454ff2013-07-16 18:26:15 +0000295 nodes[ib].addBias(Freq, PrefSpill);
296 nodes[ob].addBias(Freq, PrefSpill);
Jakob Stoklund Olesen0ab5d0e2011-07-23 03:10:19 +0000297 }
298}
299
Jakob Stoklund Olesen6d2bbc12011-04-07 17:27:46 +0000300void SpillPlacement::addLinks(ArrayRef<unsigned> Links) {
301 for (ArrayRef<unsigned>::iterator I = Links.begin(), E = Links.end(); I != E;
302 ++I) {
303 unsigned Number = *I;
Eugene Zelenkofb7f7922017-09-21 23:20:16 +0000304 unsigned ib = bundles->getBundle(Number, false);
305 unsigned ob = bundles->getBundle(Number, true);
Jakob Stoklund Olesen6d2bbc12011-04-07 17:27:46 +0000306
307 // Ignore self-loops.
308 if (ib == ob)
309 continue;
310 activate(ib);
311 activate(ob);
Jakob Stoklund Olesenc5454ff2013-07-16 18:26:15 +0000312 BlockFrequency Freq = BlockFrequencies[Number];
313 nodes[ib].addLink(ob, Freq);
314 nodes[ob].addLink(ib, Freq);
Jakob Stoklund Olesen6d2bbc12011-04-07 17:27:46 +0000315 }
316}
317
Jakob Stoklund Olesened47ed42011-04-09 02:59:09 +0000318bool SpillPlacement::scanActiveBundles() {
Jakob Stoklund Olesened47ed42011-04-09 02:59:09 +0000319 RecentPositive.clear();
Francis Visoiu Mistrihb52e0362017-05-17 01:07:53 +0000320 for (unsigned n : ActiveNodes->set_bits()) {
Quentin Colombetb926bda2016-05-19 22:40:37 +0000321 update(n);
Jakob Stoklund Olesened47ed42011-04-09 02:59:09 +0000322 // A node that must spill, or a node without any links is not going to
323 // change its value ever again, so exclude it from iterations.
324 if (nodes[n].mustSpill())
325 continue;
Jakob Stoklund Olesened47ed42011-04-09 02:59:09 +0000326 if (nodes[n].preferReg())
327 RecentPositive.push_back(n);
328 }
329 return !RecentPositive.empty();
330}
331
Quentin Colombetb926bda2016-05-19 22:40:37 +0000332bool SpillPlacement::update(unsigned n) {
333 if (!nodes[n].update(nodes, Threshold))
334 return false;
335 nodes[n].getDissentingNeighbors(TodoList, nodes);
336 return true;
337}
338
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000339/// iterate - Repeatedly update the Hopfield nodes until stability or the
340/// maximum number of iterations is reached.
Jakob Stoklund Olesened47ed42011-04-09 02:59:09 +0000341void SpillPlacement::iterate() {
Quentin Colombetb926bda2016-05-19 22:40:37 +0000342 // We do not need to push those node in the todolist.
343 // They are already been proceeded as part of the previous iteration.
344 RecentPositive.clear();
Jakob Stoklund Olesened47ed42011-04-09 02:59:09 +0000345
Quentin Colombetb926bda2016-05-19 22:40:37 +0000346 // Since the last iteration, the todolist have been augmented by calls
347 // to addConstraints, addLinks, and co.
348 // Update the network energy starting at this new frontier.
349 // The call to ::update will add the nodes that changed into the todolist.
350 unsigned Limit = bundles->getNumBundles() * 10;
351 while(Limit-- > 0 && !TodoList.empty()) {
352 unsigned n = TodoList.pop_back_val();
353 if (!update(n))
354 continue;
355 if (nodes[n].preferReg())
356 RecentPositive.push_back(n);
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000357 }
358}
359
Jakob Stoklund Olesen36b5d8a2011-04-06 19:13:57 +0000360void SpillPlacement::prepare(BitVector &RegBundles) {
Jakob Stoklund Olesened47ed42011-04-09 02:59:09 +0000361 RecentPositive.clear();
Quentin Colombetb926bda2016-05-19 22:40:37 +0000362 TodoList.clear();
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000363 // Reuse RegBundles as our ActiveNodes vector.
364 ActiveNodes = &RegBundles;
365 ActiveNodes->clear();
366 ActiveNodes->resize(bundles->getNumBundles());
Jakob Stoklund Olesen36b5d8a2011-04-06 19:13:57 +0000367}
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000368
Jakob Stoklund Olesen36b5d8a2011-04-06 19:13:57 +0000369bool
370SpillPlacement::finish() {
371 assert(ActiveNodes && "Call prepare() first");
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000372
Jakob Stoklund Olesen36b5d8a2011-04-06 19:13:57 +0000373 // Write preferences back to ActiveNodes.
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000374 bool Perfect = true;
Francis Visoiu Mistrihb52e0362017-05-17 01:07:53 +0000375 for (unsigned n : ActiveNodes->set_bits())
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000376 if (!nodes[n].preferReg()) {
Jakob Stoklund Olesen36b5d8a2011-04-06 19:13:57 +0000377 ActiveNodes->reset(n);
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000378 Perfect = false;
379 }
Craig Topperc0196b12014-04-14 00:51:57 +0000380 ActiveNodes = nullptr;
Jakob Stoklund Olesen8e236ea2011-01-06 01:21:53 +0000381 return Perfect;
382}