blob: 4d6e66413d16ef242f1e19bb5a7ddf30d128cb5f [file] [log] [blame]
Nicolas Geoffraya7062e02014-05-22 12:50:17 +01001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "register_allocator.h"
18
Ian Rogersc7dd2952014-10-21 23:31:19 -070019#include <sstream>
20
Ian Rogerse77493c2014-08-20 15:08:45 -070021#include "base/bit_vector-inl.h"
Nicolas Geoffraya7062e02014-05-22 12:50:17 +010022#include "code_generator.h"
23#include "ssa_liveness_analysis.h"
24
25namespace art {
26
27static constexpr size_t kMaxLifetimePosition = -1;
Nicolas Geoffray31d76b42014-06-09 15:02:22 +010028static constexpr size_t kDefaultNumberOfSpillSlots = 4;
Nicolas Geoffraya7062e02014-05-22 12:50:17 +010029
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +010030RegisterAllocator::RegisterAllocator(ArenaAllocator* allocator,
31 CodeGenerator* codegen,
32 const SsaLivenessAnalysis& liveness)
Nicolas Geoffraya7062e02014-05-22 12:50:17 +010033 : allocator_(allocator),
34 codegen_(codegen),
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +010035 liveness_(liveness),
Nicolas Geoffray39468442014-09-02 15:17:15 +010036 unhandled_core_intervals_(allocator, 0),
37 unhandled_fp_intervals_(allocator, 0),
38 unhandled_(nullptr),
Nicolas Geoffraya7062e02014-05-22 12:50:17 +010039 handled_(allocator, 0),
40 active_(allocator, 0),
41 inactive_(allocator, 0),
Nicolas Geoffray102cbed2014-10-15 18:31:05 +010042 physical_core_register_intervals_(allocator, codegen->GetNumberOfCoreRegisters()),
43 physical_fp_register_intervals_(allocator, codegen->GetNumberOfFloatingPointRegisters()),
Nicolas Geoffray39468442014-09-02 15:17:15 +010044 temp_intervals_(allocator, 4),
Nicolas Geoffray31d76b42014-06-09 15:02:22 +010045 spill_slots_(allocator, kDefaultNumberOfSpillSlots),
Nicolas Geoffray39468442014-09-02 15:17:15 +010046 safepoints_(allocator, 0),
Nicolas Geoffraya7062e02014-05-22 12:50:17 +010047 processing_core_registers_(false),
48 number_of_registers_(-1),
49 registers_array_(nullptr),
Nicolas Geoffray102cbed2014-10-15 18:31:05 +010050 blocked_core_registers_(codegen->GetBlockedCoreRegisters()),
51 blocked_fp_registers_(codegen->GetBlockedFloatingPointRegisters()),
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +010052 reserved_out_slots_(0),
53 maximum_number_of_live_registers_(0) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +010054 codegen->SetupBlockedRegisters();
Nicolas Geoffray102cbed2014-10-15 18:31:05 +010055 physical_core_register_intervals_.SetSize(codegen->GetNumberOfCoreRegisters());
56 physical_fp_register_intervals_.SetSize(codegen->GetNumberOfFloatingPointRegisters());
Nicolas Geoffray39468442014-09-02 15:17:15 +010057 // Always reserve for the current method and the graph's max out registers.
58 // TODO: compute it instead.
59 reserved_out_slots_ = 1 + codegen->GetGraph()->GetMaximumNumberOfOutVRegs();
Nicolas Geoffraya7062e02014-05-22 12:50:17 +010060}
61
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +010062bool RegisterAllocator::CanAllocateRegistersFor(const HGraph& graph,
63 InstructionSet instruction_set) {
64 if (!Supports(instruction_set)) {
65 return false;
66 }
67 for (size_t i = 0, e = graph.GetBlocks().Size(); i < e; ++i) {
68 for (HInstructionIterator it(graph.GetBlocks().Get(i)->GetInstructions());
69 !it.Done();
70 it.Advance()) {
71 HInstruction* current = it.Current();
Nicolas Geoffray412f10c2014-06-19 10:00:34 +010072 if (current->GetType() == Primitive::kPrimLong && instruction_set != kX86_64) return false;
Nicolas Geoffray102cbed2014-10-15 18:31:05 +010073 if ((current->GetType() == Primitive::kPrimFloat || current->GetType() == Primitive::kPrimDouble)
74 && instruction_set != kX86_64) {
75 return false;
76 }
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +010077 }
78 }
79 return true;
80}
81
82static bool ShouldProcess(bool processing_core_registers, LiveInterval* interval) {
Nicolas Geoffray39468442014-09-02 15:17:15 +010083 if (interval == nullptr) return false;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +010084 bool is_core_register = (interval->GetType() != Primitive::kPrimDouble)
85 && (interval->GetType() != Primitive::kPrimFloat);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +010086 return processing_core_registers == is_core_register;
87}
88
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +010089void RegisterAllocator::AllocateRegisters() {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +010090 AllocateRegistersInternal();
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +010091 Resolve();
92
93 if (kIsDebugBuild) {
94 processing_core_registers_ = true;
95 ValidateInternal(true);
96 processing_core_registers_ = false;
97 ValidateInternal(true);
98 }
99}
100
101void RegisterAllocator::BlockRegister(Location location,
102 size_t start,
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100103 size_t end) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100104 int reg = location.reg();
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100105 DCHECK(location.IsRegister() || location.IsFpuRegister());
106 LiveInterval* interval = location.IsRegister()
107 ? physical_core_register_intervals_.Get(reg)
108 : physical_fp_register_intervals_.Get(reg);
109 Primitive::Type type = location.IsRegister()
110 ? Primitive::kPrimInt
111 : Primitive::kPrimDouble;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100112 if (interval == nullptr) {
113 interval = LiveInterval::MakeFixedInterval(allocator_, reg, type);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100114 if (location.IsRegister()) {
115 physical_core_register_intervals_.Put(reg, interval);
116 } else {
117 physical_fp_register_intervals_.Put(reg, interval);
118 }
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100119 }
120 DCHECK(interval->GetRegister() == reg);
121 interval->AddRange(start, end);
122}
123
124void RegisterAllocator::AllocateRegistersInternal() {
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100125 // Iterate post-order, to ensure the list is sorted, and the last added interval
126 // is the one with the lowest start position.
Nicolas Geoffray39468442014-09-02 15:17:15 +0100127 for (HLinearPostOrderIterator it(liveness_); !it.Done(); it.Advance()) {
128 HBasicBlock* block = it.Current();
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800129 for (HBackwardInstructionIterator back_it(block->GetInstructions()); !back_it.Done();
130 back_it.Advance()) {
131 ProcessInstruction(back_it.Current());
Nicolas Geoffray39468442014-09-02 15:17:15 +0100132 }
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800133 for (HInstructionIterator inst_it(block->GetPhis()); !inst_it.Done(); inst_it.Advance()) {
134 ProcessInstruction(inst_it.Current());
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100135 }
136 }
137
Nicolas Geoffray39468442014-09-02 15:17:15 +0100138 number_of_registers_ = codegen_->GetNumberOfCoreRegisters();
139 registers_array_ = allocator_->AllocArray<size_t>(number_of_registers_);
140 processing_core_registers_ = true;
141 unhandled_ = &unhandled_core_intervals_;
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100142 for (size_t i = 0, e = physical_core_register_intervals_.Size(); i < e; ++i) {
143 LiveInterval* fixed = physical_core_register_intervals_.Get(i);
144 if (fixed != nullptr) {
Mingyao Yang296bd602014-10-06 16:47:28 -0700145 // Fixed interval is added to inactive_ instead of unhandled_.
146 // It's also the only type of inactive interval whose start position
147 // can be after the current interval during linear scan.
148 // Fixed interval is never split and never moves to unhandled_.
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100149 inactive_.Add(fixed);
150 }
151 }
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100152 LinearScan();
Nicolas Geoffray39468442014-09-02 15:17:15 +0100153
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100154 size_t saved_maximum_number_of_live_registers = maximum_number_of_live_registers_;
155 maximum_number_of_live_registers_ = 0;
156
Nicolas Geoffray39468442014-09-02 15:17:15 +0100157 inactive_.Reset();
158 active_.Reset();
159 handled_.Reset();
160
161 number_of_registers_ = codegen_->GetNumberOfFloatingPointRegisters();
162 registers_array_ = allocator_->AllocArray<size_t>(number_of_registers_);
163 processing_core_registers_ = false;
164 unhandled_ = &unhandled_fp_intervals_;
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100165 for (size_t i = 0, e = physical_fp_register_intervals_.Size(); i < e; ++i) {
166 LiveInterval* fixed = physical_fp_register_intervals_.Get(i);
167 if (fixed != nullptr) {
Mingyao Yang296bd602014-10-06 16:47:28 -0700168 // Fixed interval is added to inactive_ instead of unhandled_.
169 // It's also the only type of inactive interval whose start position
170 // can be after the current interval during linear scan.
171 // Fixed interval is never split and never moves to unhandled_.
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100172 inactive_.Add(fixed);
173 }
174 }
Nicolas Geoffray39468442014-09-02 15:17:15 +0100175 LinearScan();
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100176 maximum_number_of_live_registers_ += saved_maximum_number_of_live_registers;
Nicolas Geoffray39468442014-09-02 15:17:15 +0100177}
178
179void RegisterAllocator::ProcessInstruction(HInstruction* instruction) {
180 LocationSummary* locations = instruction->GetLocations();
181 size_t position = instruction->GetLifetimePosition();
182
183 if (locations == nullptr) return;
184
185 // Create synthesized intervals for temporaries.
186 for (size_t i = 0; i < locations->GetTempCount(); ++i) {
187 Location temp = locations->GetTemp(i);
Nicolas Geoffray52839d12014-11-07 17:47:25 +0000188 if (temp.IsRegister() || temp.IsFpuRegister()) {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100189 BlockRegister(temp, position, position + 1);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100190 } else {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100191 DCHECK(temp.IsUnallocated());
Nicolas Geoffray52839d12014-11-07 17:47:25 +0000192 DCHECK(temp.GetPolicy() == Location::kRequiresRegister);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100193 LiveInterval* interval = LiveInterval::MakeTempInterval(allocator_, Primitive::kPrimInt);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100194 temp_intervals_.Add(interval);
195 interval->AddRange(position, position + 1);
196 unhandled_core_intervals_.Add(interval);
197 }
198 }
199
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100200 bool core_register = (instruction->GetType() != Primitive::kPrimDouble)
201 && (instruction->GetType() != Primitive::kPrimFloat);
202
Nicolas Geoffray39468442014-09-02 15:17:15 +0100203 if (locations->CanCall()) {
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100204 if (!instruction->IsSuspendCheck()) {
205 codegen_->MarkNotLeaf();
206 }
Nicolas Geoffray39468442014-09-02 15:17:15 +0100207 safepoints_.Add(instruction);
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100208 if (locations->OnlyCallsOnSlowPath()) {
209 // We add a synthesized range at this position to record the live registers
210 // at this position. Ideally, we could just update the safepoints when locations
211 // are updated, but we currently need to know the full stack size before updating
212 // locations (because of parameters and the fact that we don't have a frame pointer).
213 // And knowing the full stack size requires to know the maximum number of live
214 // registers at calls in slow paths.
215 // By adding the following interval in the algorithm, we can compute this
216 // maximum before updating locations.
217 LiveInterval* interval = LiveInterval::MakeSlowPathInterval(allocator_, instruction);
218 interval->AddRange(position, position + 1);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100219 unhandled_core_intervals_.Add(interval);
220 unhandled_fp_intervals_.Add(interval);
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100221 }
222 }
223
224 if (locations->WillCall()) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100225 // Block all registers.
226 for (size_t i = 0; i < codegen_->GetNumberOfCoreRegisters(); ++i) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100227 BlockRegister(Location::RegisterLocation(i),
Nicolas Geoffray39468442014-09-02 15:17:15 +0100228 position,
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100229 position + 1);
230 }
231 for (size_t i = 0; i < codegen_->GetNumberOfFloatingPointRegisters(); ++i) {
232 BlockRegister(Location::FpuRegisterLocation(i),
233 position,
234 position + 1);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100235 }
236 }
237
238 for (size_t i = 0; i < instruction->InputCount(); ++i) {
239 Location input = locations->InAt(i);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100240 if (input.IsRegister() || input.IsFpuRegister()) {
241 BlockRegister(input, position, position + 1);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100242 }
243 }
244
Nicolas Geoffray39468442014-09-02 15:17:15 +0100245 LiveInterval* current = instruction->GetLiveInterval();
246 if (current == nullptr) return;
247
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100248 GrowableArray<LiveInterval*>& unhandled = core_register
249 ? unhandled_core_intervals_
250 : unhandled_fp_intervals_;
251
Nicolas Geoffray76905622014-09-25 14:39:26 +0100252 DCHECK(unhandled.IsEmpty() || current->StartsBeforeOrAt(unhandled.Peek()));
Nicolas Geoffray39468442014-09-02 15:17:15 +0100253 // Some instructions define their output in fixed register/stack slot. We need
254 // to ensure we know these locations before doing register allocation. For a
255 // given register, we create an interval that covers these locations. The register
256 // will be unavailable at these locations when trying to allocate one for an
257 // interval.
258 //
259 // The backwards walking ensures the ranges are ordered on increasing start positions.
260 Location output = locations->Out();
Calin Juravled0d48522014-11-04 16:40:20 +0000261 if (output.IsUnallocated() && output.GetPolicy() == Location::kSameAsFirstInput) {
262 Location first = locations->InAt(0);
263 if (first.IsRegister() || first.IsFpuRegister()) {
264 current->SetFrom(position + 1);
265 current->SetRegister(first.reg());
266 }
267 } else if (output.IsRegister() || output.IsFpuRegister()) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100268 // Shift the interval's start by one to account for the blocked register.
269 current->SetFrom(position + 1);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100270 current->SetRegister(output.reg());
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100271 BlockRegister(output, position, position + 1);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100272 } else if (output.IsStackSlot() || output.IsDoubleStackSlot()) {
273 current->SetSpillSlot(output.GetStackIndex());
274 }
275
276 // If needed, add interval to the list of unhandled intervals.
277 if (current->HasSpillSlot() || instruction->IsConstant()) {
Nicolas Geoffrayc8147a72014-10-21 16:06:20 +0100278 // Split just before first register use.
Nicolas Geoffray39468442014-09-02 15:17:15 +0100279 size_t first_register_use = current->FirstRegisterUse();
280 if (first_register_use != kNoLifetime) {
Nicolas Geoffrayc8147a72014-10-21 16:06:20 +0100281 LiveInterval* split = Split(current, first_register_use - 1);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000282 // Don't add directly to `unhandled`, it needs to be sorted and the start
Nicolas Geoffray39468442014-09-02 15:17:15 +0100283 // of this new interval might be after intervals already in the list.
284 AddSorted(&unhandled, split);
285 } else {
286 // Nothing to do, we won't allocate a register for this value.
287 }
288 } else {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000289 // Don't add directly to `unhandled`, temp or safepoint intervals
290 // for this instruction may have been added, and those can be
291 // processed first.
292 AddSorted(&unhandled, current);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100293 }
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100294}
295
Nicolas Geoffray31d76b42014-06-09 15:02:22 +0100296class AllRangesIterator : public ValueObject {
297 public:
298 explicit AllRangesIterator(LiveInterval* interval)
299 : current_interval_(interval),
300 current_range_(interval->GetFirstRange()) {}
301
302 bool Done() const { return current_interval_ == nullptr; }
303 LiveRange* CurrentRange() const { return current_range_; }
304 LiveInterval* CurrentInterval() const { return current_interval_; }
305
306 void Advance() {
307 current_range_ = current_range_->GetNext();
308 if (current_range_ == nullptr) {
309 current_interval_ = current_interval_->GetNextSibling();
310 if (current_interval_ != nullptr) {
311 current_range_ = current_interval_->GetFirstRange();
312 }
313 }
314 }
315
316 private:
317 LiveInterval* current_interval_;
318 LiveRange* current_range_;
319
320 DISALLOW_COPY_AND_ASSIGN(AllRangesIterator);
321};
322
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100323bool RegisterAllocator::ValidateInternal(bool log_fatal_on_failure) const {
324 // To simplify unit testing, we eagerly create the array of intervals, and
325 // call the helper method.
326 GrowableArray<LiveInterval*> intervals(allocator_, 0);
327 for (size_t i = 0; i < liveness_.GetNumberOfSsaValues(); ++i) {
328 HInstruction* instruction = liveness_.GetInstructionFromSsaIndex(i);
329 if (ShouldProcess(processing_core_registers_, instruction->GetLiveInterval())) {
330 intervals.Add(instruction->GetLiveInterval());
331 }
332 }
333
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100334 if (processing_core_registers_) {
335 for (size_t i = 0, e = physical_core_register_intervals_.Size(); i < e; ++i) {
336 LiveInterval* fixed = physical_core_register_intervals_.Get(i);
337 if (fixed != nullptr) {
338 intervals.Add(fixed);
339 }
340 }
341 } else {
342 for (size_t i = 0, e = physical_fp_register_intervals_.Size(); i < e; ++i) {
343 LiveInterval* fixed = physical_fp_register_intervals_.Get(i);
344 if (fixed != nullptr) {
345 intervals.Add(fixed);
346 }
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100347 }
348 }
349
Nicolas Geoffray39468442014-09-02 15:17:15 +0100350 for (size_t i = 0, e = temp_intervals_.Size(); i < e; ++i) {
351 LiveInterval* temp = temp_intervals_.Get(i);
352 if (ShouldProcess(processing_core_registers_, temp)) {
353 intervals.Add(temp);
354 }
355 }
356
357 return ValidateIntervals(intervals, spill_slots_.Size(), reserved_out_slots_, *codegen_,
358 allocator_, processing_core_registers_, log_fatal_on_failure);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100359}
360
Nicolas Geoffray31d76b42014-06-09 15:02:22 +0100361bool RegisterAllocator::ValidateIntervals(const GrowableArray<LiveInterval*>& intervals,
362 size_t number_of_spill_slots,
Nicolas Geoffray39468442014-09-02 15:17:15 +0100363 size_t number_of_out_slots,
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100364 const CodeGenerator& codegen,
365 ArenaAllocator* allocator,
366 bool processing_core_registers,
367 bool log_fatal_on_failure) {
368 size_t number_of_registers = processing_core_registers
369 ? codegen.GetNumberOfCoreRegisters()
370 : codegen.GetNumberOfFloatingPointRegisters();
Nicolas Geoffray31d76b42014-06-09 15:02:22 +0100371 GrowableArray<ArenaBitVector*> liveness_of_values(
372 allocator, number_of_registers + number_of_spill_slots);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100373
374 // Allocate a bit vector per register. A live interval that has a register
375 // allocated will populate the associated bit vector based on its live ranges.
Nicolas Geoffray31d76b42014-06-09 15:02:22 +0100376 for (size_t i = 0; i < number_of_registers + number_of_spill_slots; ++i) {
377 liveness_of_values.Add(new (allocator) ArenaBitVector(allocator, 0, true));
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100378 }
379
Nicolas Geoffray31d76b42014-06-09 15:02:22 +0100380 for (size_t i = 0, e = intervals.Size(); i < e; ++i) {
381 for (AllRangesIterator it(intervals.Get(i)); !it.Done(); it.Advance()) {
382 LiveInterval* current = it.CurrentInterval();
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100383 HInstruction* defined_by = current->GetParent()->GetDefinedBy();
384 if (current->GetParent()->HasSpillSlot()
385 // Parameters have their own stack slot.
386 && !(defined_by != nullptr && defined_by->IsParameterValue())) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100387 BitVector* liveness_of_spill_slot = liveness_of_values.Get(number_of_registers
388 + current->GetParent()->GetSpillSlot() / kVRegSize
389 - number_of_out_slots);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +0100390 for (size_t j = it.CurrentRange()->GetStart(); j < it.CurrentRange()->GetEnd(); ++j) {
391 if (liveness_of_spill_slot->IsBitSet(j)) {
392 if (log_fatal_on_failure) {
393 std::ostringstream message;
394 message << "Spill slot conflict at " << j;
395 LOG(FATAL) << message.str();
396 } else {
397 return false;
398 }
399 } else {
400 liveness_of_spill_slot->SetBit(j);
401 }
402 }
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100403 }
Nicolas Geoffray31d76b42014-06-09 15:02:22 +0100404
405 if (current->HasRegister()) {
406 BitVector* liveness_of_register = liveness_of_values.Get(current->GetRegister());
407 for (size_t j = it.CurrentRange()->GetStart(); j < it.CurrentRange()->GetEnd(); ++j) {
408 if (liveness_of_register->IsBitSet(j)) {
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100409 if (log_fatal_on_failure) {
410 std::ostringstream message;
Nicolas Geoffray39468442014-09-02 15:17:15 +0100411 message << "Register conflict at " << j << " ";
412 if (defined_by != nullptr) {
413 message << "(" << defined_by->DebugName() << ")";
414 }
415 message << "for ";
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100416 if (processing_core_registers) {
417 codegen.DumpCoreRegister(message, current->GetRegister());
418 } else {
419 codegen.DumpFloatingPointRegister(message, current->GetRegister());
420 }
421 LOG(FATAL) << message.str();
422 } else {
423 return false;
424 }
425 } else {
Nicolas Geoffray31d76b42014-06-09 15:02:22 +0100426 liveness_of_register->SetBit(j);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100427 }
428 }
Nicolas Geoffray31d76b42014-06-09 15:02:22 +0100429 }
430 }
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100431 }
432 return true;
433}
434
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100435void RegisterAllocator::DumpInterval(std::ostream& stream, LiveInterval* interval) const {
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100436 interval->Dump(stream);
437 stream << ": ";
438 if (interval->HasRegister()) {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100439 if (interval->IsFloatingPoint()) {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100440 codegen_->DumpFloatingPointRegister(stream, interval->GetRegister());
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100441 } else {
442 codegen_->DumpCoreRegister(stream, interval->GetRegister());
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100443 }
444 } else {
445 stream << "spilled";
446 }
447 stream << std::endl;
448}
449
Mingyao Yang296bd602014-10-06 16:47:28 -0700450void RegisterAllocator::DumpAllIntervals(std::ostream& stream) const {
451 stream << "inactive: " << std::endl;
452 for (size_t i = 0; i < inactive_.Size(); i ++) {
453 DumpInterval(stream, inactive_.Get(i));
454 }
455 stream << "active: " << std::endl;
456 for (size_t i = 0; i < active_.Size(); i ++) {
457 DumpInterval(stream, active_.Get(i));
458 }
459 stream << "unhandled: " << std::endl;
460 auto unhandled = (unhandled_ != nullptr) ?
461 unhandled_ : &unhandled_core_intervals_;
462 for (size_t i = 0; i < unhandled->Size(); i ++) {
463 DumpInterval(stream, unhandled->Get(i));
464 }
465 stream << "handled: " << std::endl;
466 for (size_t i = 0; i < handled_.Size(); i ++) {
467 DumpInterval(stream, handled_.Get(i));
468 }
469}
470
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100471// By the book implementation of a linear scan register allocator.
472void RegisterAllocator::LinearScan() {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100473 while (!unhandled_->IsEmpty()) {
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100474 // (1) Remove interval with the lowest start position from unhandled.
Nicolas Geoffray39468442014-09-02 15:17:15 +0100475 LiveInterval* current = unhandled_->Pop();
476 DCHECK(!current->IsFixed() && !current->HasSpillSlot());
Nicolas Geoffrayc8147a72014-10-21 16:06:20 +0100477 DCHECK(unhandled_->IsEmpty() || unhandled_->Peek()->GetStart() >= current->GetStart());
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100478 size_t position = current->GetStart();
479
Mingyao Yang296bd602014-10-06 16:47:28 -0700480 // Remember the inactive_ size here since the ones moved to inactive_ from
481 // active_ below shouldn't need to be re-checked.
482 size_t inactive_intervals_to_handle = inactive_.Size();
483
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100484 // (2) Remove currently active intervals that are dead at this position.
485 // Move active intervals that have a lifetime hole at this position
486 // to inactive.
487 for (size_t i = 0; i < active_.Size(); ++i) {
488 LiveInterval* interval = active_.Get(i);
489 if (interval->IsDeadAt(position)) {
490 active_.Delete(interval);
491 --i;
492 handled_.Add(interval);
493 } else if (!interval->Covers(position)) {
494 active_.Delete(interval);
495 --i;
496 inactive_.Add(interval);
497 }
498 }
499
500 // (3) Remove currently inactive intervals that are dead at this position.
501 // Move inactive intervals that cover this position to active.
Mingyao Yang296bd602014-10-06 16:47:28 -0700502 for (size_t i = 0; i < inactive_intervals_to_handle; ++i) {
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100503 LiveInterval* interval = inactive_.Get(i);
Mingyao Yang296bd602014-10-06 16:47:28 -0700504 DCHECK(interval->GetStart() < position || interval->IsFixed());
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100505 if (interval->IsDeadAt(position)) {
506 inactive_.Delete(interval);
507 --i;
Mingyao Yang296bd602014-10-06 16:47:28 -0700508 --inactive_intervals_to_handle;
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100509 handled_.Add(interval);
510 } else if (interval->Covers(position)) {
511 inactive_.Delete(interval);
512 --i;
Mingyao Yang296bd602014-10-06 16:47:28 -0700513 --inactive_intervals_to_handle;
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100514 active_.Add(interval);
515 }
516 }
517
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100518 if (current->IsSlowPathSafepoint()) {
519 // Synthesized interval to record the maximum number of live registers
520 // at safepoints. No need to allocate a register for it.
521 maximum_number_of_live_registers_ =
522 std::max(maximum_number_of_live_registers_, active_.Size());
523 continue;
524 }
525
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100526 // (4) Try to find an available register.
527 bool success = TryAllocateFreeReg(current);
528
529 // (5) If no register could be found, we need to spill.
530 if (!success) {
531 success = AllocateBlockedReg(current);
532 }
533
534 // (6) If the interval had a register allocated, add it to the list of active
535 // intervals.
536 if (success) {
537 active_.Add(current);
538 }
539 }
540}
541
542// Find a free register. If multiple are found, pick the register that
543// is free the longest.
544bool RegisterAllocator::TryAllocateFreeReg(LiveInterval* current) {
545 size_t* free_until = registers_array_;
546
547 // First set all registers to be free.
548 for (size_t i = 0; i < number_of_registers_; ++i) {
549 free_until[i] = kMaxLifetimePosition;
550 }
551
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100552 // For each active interval, set its register to not free.
553 for (size_t i = 0, e = active_.Size(); i < e; ++i) {
554 LiveInterval* interval = active_.Get(i);
555 DCHECK(interval->HasRegister());
556 free_until[interval->GetRegister()] = 0;
557 }
558
Mingyao Yang296bd602014-10-06 16:47:28 -0700559 // For each inactive interval, set its register to be free until
560 // the next intersection with `current`.
561 for (size_t i = 0, e = inactive_.Size(); i < e; ++i) {
562 LiveInterval* inactive = inactive_.Get(i);
563 // Temp/Slow-path-safepoint interval has no holes.
564 DCHECK(!inactive->IsTemp() && !inactive->IsSlowPathSafepoint());
565 if (!current->IsSplit() && !inactive->IsFixed()) {
566 // Neither current nor inactive are fixed.
567 // Thanks to SSA, a non-split interval starting in a hole of an
568 // inactive interval should never intersect with that inactive interval.
569 // Only if it's not fixed though, because fixed intervals don't come from SSA.
570 DCHECK_EQ(inactive->FirstIntersectionWith(current), kNoLifetime);
571 continue;
572 }
573
574 DCHECK(inactive->HasRegister());
575 if (free_until[inactive->GetRegister()] == 0) {
576 // Already used by some active interval. No need to intersect.
577 continue;
578 }
579 size_t next_intersection = inactive->FirstIntersectionWith(current);
580 if (next_intersection != kNoLifetime) {
581 free_until[inactive->GetRegister()] =
582 std::min(free_until[inactive->GetRegister()], next_intersection);
583 }
584 }
585
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100586 int reg = -1;
Nicolas Geoffray39468442014-09-02 15:17:15 +0100587 if (current->HasRegister()) {
588 // Some instructions have a fixed register output.
589 reg = current->GetRegister();
590 DCHECK_NE(free_until[reg], 0u);
591 } else {
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100592 int hint = current->FindFirstRegisterHint(free_until);
593 if (hint != kNoRegister) {
594 DCHECK(!IsBlocked(hint));
595 reg = hint;
596 } else {
597 // Pick the register that is free the longest.
598 for (size_t i = 0; i < number_of_registers_; ++i) {
599 if (IsBlocked(i)) continue;
600 if (reg == -1 || free_until[i] > free_until[reg]) {
601 reg = i;
602 if (free_until[i] == kMaxLifetimePosition) break;
603 }
Nicolas Geoffray39468442014-09-02 15:17:15 +0100604 }
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100605 }
606 }
607
608 // If we could not find a register, we need to spill.
609 if (reg == -1 || free_until[reg] == 0) {
610 return false;
611 }
612
613 current->SetRegister(reg);
614 if (!current->IsDeadAt(free_until[reg])) {
615 // If the register is only available for a subset of live ranges
616 // covered by `current`, split `current` at the position where
617 // the register is not available anymore.
618 LiveInterval* split = Split(current, free_until[reg]);
619 DCHECK(split != nullptr);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100620 AddSorted(unhandled_, split);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100621 }
622 return true;
623}
624
625bool RegisterAllocator::IsBlocked(int reg) const {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100626 return processing_core_registers_
627 ? blocked_core_registers_[reg]
628 : blocked_fp_registers_[reg];
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100629}
630
631// Find the register that is used the last, and spill the interval
632// that holds it. If the first use of `current` is after that register
633// we spill `current` instead.
634bool RegisterAllocator::AllocateBlockedReg(LiveInterval* current) {
635 size_t first_register_use = current->FirstRegisterUse();
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100636 if (first_register_use == kNoLifetime) {
Nicolas Geoffray31d76b42014-06-09 15:02:22 +0100637 AllocateSpillSlotFor(current);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100638 return false;
639 }
640
641 // First set all registers as not being used.
642 size_t* next_use = registers_array_;
643 for (size_t i = 0; i < number_of_registers_; ++i) {
644 next_use[i] = kMaxLifetimePosition;
645 }
646
647 // For each active interval, find the next use of its register after the
648 // start of current.
649 for (size_t i = 0, e = active_.Size(); i < e; ++i) {
650 LiveInterval* active = active_.Get(i);
651 DCHECK(active->HasRegister());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100652 if (active->IsFixed()) {
653 next_use[active->GetRegister()] = current->GetStart();
654 } else {
655 size_t use = active->FirstRegisterUseAfter(current->GetStart());
656 if (use != kNoLifetime) {
657 next_use[active->GetRegister()] = use;
658 }
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100659 }
660 }
661
662 // For each inactive interval, find the next use of its register after the
663 // start of current.
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100664 for (size_t i = 0, e = inactive_.Size(); i < e; ++i) {
665 LiveInterval* inactive = inactive_.Get(i);
Mingyao Yang296bd602014-10-06 16:47:28 -0700666 // Temp/Slow-path-safepoint interval has no holes.
667 DCHECK(!inactive->IsTemp() && !inactive->IsSlowPathSafepoint());
668 if (!current->IsSplit() && !inactive->IsFixed()) {
669 // Neither current nor inactive are fixed.
670 // Thanks to SSA, a non-split interval starting in a hole of an
671 // inactive interval should never intersect with that inactive interval.
672 // Only if it's not fixed though, because fixed intervals don't come from SSA.
673 DCHECK_EQ(inactive->FirstIntersectionWith(current), kNoLifetime);
674 continue;
675 }
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100676 DCHECK(inactive->HasRegister());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100677 size_t next_intersection = inactive->FirstIntersectionWith(current);
678 if (next_intersection != kNoLifetime) {
679 if (inactive->IsFixed()) {
680 next_use[inactive->GetRegister()] =
681 std::min(next_intersection, next_use[inactive->GetRegister()]);
682 } else {
683 size_t use = inactive->FirstRegisterUseAfter(current->GetStart());
684 if (use != kNoLifetime) {
685 next_use[inactive->GetRegister()] = std::min(use, next_use[inactive->GetRegister()]);
686 }
687 }
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100688 }
689 }
690
691 // Pick the register that is used the last.
692 int reg = -1;
693 for (size_t i = 0; i < number_of_registers_; ++i) {
694 if (IsBlocked(i)) continue;
695 if (reg == -1 || next_use[i] > next_use[reg]) {
696 reg = i;
697 if (next_use[i] == kMaxLifetimePosition) break;
698 }
699 }
700
701 if (first_register_use >= next_use[reg]) {
702 // If the first use of that instruction is after the last use of the found
703 // register, we split this interval just before its first register use.
Nicolas Geoffray31d76b42014-06-09 15:02:22 +0100704 AllocateSpillSlotFor(current);
Nicolas Geoffrayc8147a72014-10-21 16:06:20 +0100705 LiveInterval* split = Split(current, first_register_use - 1);
706 DCHECK_NE(current, split) << "There is not enough registers available for "
707 << split->GetParent()->GetDefinedBy()->DebugName();
Nicolas Geoffray39468442014-09-02 15:17:15 +0100708 AddSorted(unhandled_, split);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100709 return false;
710 } else {
711 // Use this register and spill the active and inactives interval that
712 // have that register.
713 current->SetRegister(reg);
714
715 for (size_t i = 0, e = active_.Size(); i < e; ++i) {
716 LiveInterval* active = active_.Get(i);
717 if (active->GetRegister() == reg) {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100718 DCHECK(!active->IsFixed());
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100719 LiveInterval* split = Split(active, current->GetStart());
720 active_.DeleteAt(i);
721 handled_.Add(active);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100722 AddSorted(unhandled_, split);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100723 break;
724 }
725 }
726
Mingyao Yang296bd602014-10-06 16:47:28 -0700727 for (size_t i = 0, e = inactive_.Size(); i < e; ++i) {
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100728 LiveInterval* inactive = inactive_.Get(i);
729 if (inactive->GetRegister() == reg) {
Mingyao Yang296bd602014-10-06 16:47:28 -0700730 if (!current->IsSplit() && !inactive->IsFixed()) {
731 // Neither current nor inactive are fixed.
732 // Thanks to SSA, a non-split interval starting in a hole of an
733 // inactive interval should never intersect with that inactive interval.
734 // Only if it's not fixed though, because fixed intervals don't come from SSA.
735 DCHECK_EQ(inactive->FirstIntersectionWith(current), kNoLifetime);
736 continue;
737 }
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100738 size_t next_intersection = inactive->FirstIntersectionWith(current);
739 if (next_intersection != kNoLifetime) {
740 if (inactive->IsFixed()) {
741 LiveInterval* split = Split(current, next_intersection);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100742 AddSorted(unhandled_, split);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100743 } else {
Mingyao Yang296bd602014-10-06 16:47:28 -0700744 LiveInterval* split = Split(inactive, next_intersection);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100745 inactive_.DeleteAt(i);
Mingyao Yang296bd602014-10-06 16:47:28 -0700746 --i;
747 --e;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100748 handled_.Add(inactive);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100749 AddSorted(unhandled_, split);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100750 }
751 }
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100752 }
753 }
754
755 return true;
756 }
757}
758
Nicolas Geoffray39468442014-09-02 15:17:15 +0100759void RegisterAllocator::AddSorted(GrowableArray<LiveInterval*>* array, LiveInterval* interval) {
Nicolas Geoffrayc8147a72014-10-21 16:06:20 +0100760 DCHECK(!interval->IsFixed() && !interval->HasSpillSlot());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100761 size_t insert_at = 0;
Nicolas Geoffray39468442014-09-02 15:17:15 +0100762 for (size_t i = array->Size(); i > 0; --i) {
763 LiveInterval* current = array->Get(i - 1);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100764 if (current->StartsAfter(interval)) {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100765 insert_at = i;
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100766 break;
767 }
768 }
Nicolas Geoffray39468442014-09-02 15:17:15 +0100769 array->InsertAt(insert_at, interval);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100770}
771
772LiveInterval* RegisterAllocator::Split(LiveInterval* interval, size_t position) {
773 DCHECK(position >= interval->GetStart());
774 DCHECK(!interval->IsDeadAt(position));
775 if (position == interval->GetStart()) {
776 // Spill slot will be allocated when handling `interval` again.
777 interval->ClearRegister();
778 return interval;
779 } else {
780 LiveInterval* new_interval = interval->SplitAt(position);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100781 return new_interval;
782 }
783}
784
Nicolas Geoffray31d76b42014-06-09 15:02:22 +0100785void RegisterAllocator::AllocateSpillSlotFor(LiveInterval* interval) {
786 LiveInterval* parent = interval->GetParent();
787
788 // An instruction gets a spill slot for its entire lifetime. If the parent
789 // of this interval already has a spill slot, there is nothing to do.
790 if (parent->HasSpillSlot()) {
791 return;
792 }
793
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100794 HInstruction* defined_by = parent->GetDefinedBy();
795 if (defined_by->IsParameterValue()) {
796 // Parameters have their own stack slot.
797 parent->SetSpillSlot(codegen_->GetStackSlotOfParameter(defined_by->AsParameterValue()));
798 return;
799 }
800
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100801 if (defined_by->IsConstant()) {
802 // Constants don't need a spill slot.
803 return;
804 }
805
Nicolas Geoffray31d76b42014-06-09 15:02:22 +0100806 LiveInterval* last_sibling = interval;
807 while (last_sibling->GetNextSibling() != nullptr) {
808 last_sibling = last_sibling->GetNextSibling();
809 }
810 size_t end = last_sibling->GetEnd();
811
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100812 // Find an available spill slot.
813 size_t slot = 0;
814 for (size_t e = spill_slots_.Size(); slot < e; ++slot) {
815 // We check if it is less rather than less or equal because the parallel move
816 // resolver does not work when a single spill slot needs to be exchanged with
817 // a double spill slot. The strict comparison avoids needing to exchange these
818 // locations at the same lifetime position.
819 if (spill_slots_.Get(slot) < parent->GetStart()
820 && (slot == (e - 1) || spill_slots_.Get(slot + 1) < parent->GetStart())) {
821 break;
822 }
823 }
824
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100825 if (parent->NeedsTwoSpillSlots()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100826 if (slot == spill_slots_.Size()) {
827 // We need a new spill slot.
828 spill_slots_.Add(end);
829 spill_slots_.Add(end);
830 } else if (slot == spill_slots_.Size() - 1) {
831 spill_slots_.Put(slot, end);
832 spill_slots_.Add(end);
833 } else {
834 spill_slots_.Put(slot, end);
835 spill_slots_.Put(slot + 1, end);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +0100836 }
Nicolas Geoffray31d76b42014-06-09 15:02:22 +0100837 } else {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100838 if (slot == spill_slots_.Size()) {
839 // We need a new spill slot.
840 spill_slots_.Add(end);
841 } else {
842 spill_slots_.Put(slot, end);
843 }
Nicolas Geoffray31d76b42014-06-09 15:02:22 +0100844 }
845
Nicolas Geoffray39468442014-09-02 15:17:15 +0100846 parent->SetSpillSlot((slot + reserved_out_slots_) * kVRegSize);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100847}
848
Nicolas Geoffray2a877f32014-09-10 10:49:34 +0100849static bool IsValidDestination(Location destination) {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100850 return destination.IsRegister()
851 || destination.IsFpuRegister()
852 || destination.IsStackSlot()
853 || destination.IsDoubleStackSlot();
Nicolas Geoffray2a877f32014-09-10 10:49:34 +0100854}
855
Nicolas Geoffray740475d2014-09-29 10:33:25 +0100856void RegisterAllocator::AddInputMoveFor(HInstruction* user,
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100857 Location source,
858 Location destination) const {
Nicolas Geoffray2a877f32014-09-10 10:49:34 +0100859 DCHECK(IsValidDestination(destination));
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100860 if (source.Equals(destination)) return;
861
Roland Levillain476df552014-10-09 17:51:36 +0100862 DCHECK(!user->IsPhi());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100863
Nicolas Geoffray740475d2014-09-29 10:33:25 +0100864 HInstruction* previous = user->GetPrevious();
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100865 HParallelMove* move = nullptr;
866 if (previous == nullptr
Roland Levillain476df552014-10-09 17:51:36 +0100867 || !previous->IsParallelMove()
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100868 || previous->GetLifetimePosition() < user->GetLifetimePosition()) {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100869 move = new (allocator_) HParallelMove(allocator_);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100870 move->SetLifetimePosition(user->GetLifetimePosition());
Nicolas Geoffray740475d2014-09-29 10:33:25 +0100871 user->GetBlock()->InsertInstructionBefore(move, user);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100872 } else {
873 move = previous->AsParallelMove();
874 }
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100875 DCHECK_EQ(move->GetLifetimePosition(), user->GetLifetimePosition());
Nicolas Geoffray740475d2014-09-29 10:33:25 +0100876 move->AddMove(new (allocator_) MoveOperands(source, destination, nullptr));
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100877}
878
879void RegisterAllocator::InsertParallelMoveAt(size_t position,
Nicolas Geoffray740475d2014-09-29 10:33:25 +0100880 HInstruction* instruction,
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100881 Location source,
882 Location destination) const {
Nicolas Geoffray2a877f32014-09-10 10:49:34 +0100883 DCHECK(IsValidDestination(destination));
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100884 if (source.Equals(destination)) return;
885
886 HInstruction* at = liveness_.GetInstructionFromPosition(position / 2);
887 if (at == nullptr) {
Mingyao Yang296bd602014-10-06 16:47:28 -0700888 // Block boundary, don't do anything the connection of split siblings will handle it.
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100889 return;
890 }
891 HParallelMove* move;
892 if ((position & 1) == 1) {
893 // Move must happen after the instruction.
894 DCHECK(!at->IsControlFlow());
895 move = at->GetNext()->AsParallelMove();
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100896 // This is a parallel move for connecting siblings in a same block. We need to
897 // differentiate it with moves for connecting blocks, and input moves.
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100898 if (move == nullptr || move->GetLifetimePosition() > position) {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100899 move = new (allocator_) HParallelMove(allocator_);
900 move->SetLifetimePosition(position);
901 at->GetBlock()->InsertInstructionBefore(move, at->GetNext());
902 }
903 } else {
904 // Move must happen before the instruction.
905 HInstruction* previous = at->GetPrevious();
Nicolas Geoffray740475d2014-09-29 10:33:25 +0100906 if (previous == nullptr
907 || !previous->IsParallelMove()
908 || previous->GetLifetimePosition() != position) {
909 // If the previous is a parallel move, then its position must be lower
910 // than the given `position`: it was added just after the non-parallel
911 // move instruction that precedes `instruction`.
912 DCHECK(previous == nullptr
913 || !previous->IsParallelMove()
914 || previous->GetLifetimePosition() < position);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100915 move = new (allocator_) HParallelMove(allocator_);
916 move->SetLifetimePosition(position);
917 at->GetBlock()->InsertInstructionBefore(move, at);
918 } else {
919 move = previous->AsParallelMove();
920 }
921 }
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100922 DCHECK_EQ(move->GetLifetimePosition(), position);
Nicolas Geoffray740475d2014-09-29 10:33:25 +0100923 move->AddMove(new (allocator_) MoveOperands(source, destination, instruction));
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100924}
925
926void RegisterAllocator::InsertParallelMoveAtExitOf(HBasicBlock* block,
Nicolas Geoffray740475d2014-09-29 10:33:25 +0100927 HInstruction* instruction,
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100928 Location source,
929 Location destination) const {
Nicolas Geoffray2a877f32014-09-10 10:49:34 +0100930 DCHECK(IsValidDestination(destination));
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100931 if (source.Equals(destination)) return;
932
933 DCHECK_EQ(block->GetSuccessors().Size(), 1u);
934 HInstruction* last = block->GetLastInstruction();
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100935 // We insert moves at exit for phi predecessors and connecting blocks.
936 // A block ending with an if cannot branch to a block with phis because
937 // we do not allow critical edges. It can also not connect
938 // a split interval between two blocks: the move has to happen in the successor.
939 DCHECK(!last->IsIf());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100940 HInstruction* previous = last->GetPrevious();
941 HParallelMove* move;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100942 // This is a parallel move for connecting blocks. We need to differentiate
943 // it with moves for connecting siblings in a same block, and output moves.
Nicolas Geoffray740475d2014-09-29 10:33:25 +0100944 if (previous == nullptr || !previous->IsParallelMove()
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100945 || previous->AsParallelMove()->GetLifetimePosition() != block->GetLifetimeEnd()) {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100946 move = new (allocator_) HParallelMove(allocator_);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100947 move->SetLifetimePosition(block->GetLifetimeEnd());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100948 block->InsertInstructionBefore(move, last);
949 } else {
950 move = previous->AsParallelMove();
951 }
Nicolas Geoffray740475d2014-09-29 10:33:25 +0100952 move->AddMove(new (allocator_) MoveOperands(source, destination, instruction));
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100953}
954
955void RegisterAllocator::InsertParallelMoveAtEntryOf(HBasicBlock* block,
Nicolas Geoffray740475d2014-09-29 10:33:25 +0100956 HInstruction* instruction,
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100957 Location source,
958 Location destination) const {
Nicolas Geoffray2a877f32014-09-10 10:49:34 +0100959 DCHECK(IsValidDestination(destination));
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100960 if (source.Equals(destination)) return;
961
962 HInstruction* first = block->GetFirstInstruction();
963 HParallelMove* move = first->AsParallelMove();
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100964 // This is a parallel move for connecting blocks. We need to differentiate
965 // it with moves for connecting siblings in a same block, and input moves.
966 if (move == nullptr || move->GetLifetimePosition() != block->GetLifetimeStart()) {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100967 move = new (allocator_) HParallelMove(allocator_);
968 move->SetLifetimePosition(block->GetLifetimeStart());
969 block->InsertInstructionBefore(move, first);
970 }
Nicolas Geoffray740475d2014-09-29 10:33:25 +0100971 move->AddMove(new (allocator_) MoveOperands(source, destination, instruction));
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100972}
973
974void RegisterAllocator::InsertMoveAfter(HInstruction* instruction,
975 Location source,
976 Location destination) const {
Nicolas Geoffray2a877f32014-09-10 10:49:34 +0100977 DCHECK(IsValidDestination(destination));
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100978 if (source.Equals(destination)) return;
979
Roland Levillain476df552014-10-09 17:51:36 +0100980 if (instruction->IsPhi()) {
Nicolas Geoffray740475d2014-09-29 10:33:25 +0100981 InsertParallelMoveAtEntryOf(instruction->GetBlock(), instruction, source, destination);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100982 return;
983 }
984
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100985 size_t position = instruction->GetLifetimePosition() + 1;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100986 HParallelMove* move = instruction->GetNext()->AsParallelMove();
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100987 // This is a parallel move for moving the output of an instruction. We need
988 // to differentiate with input moves, moves for connecting siblings in a
989 // and moves for connecting blocks.
990 if (move == nullptr || move->GetLifetimePosition() != position) {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100991 move = new (allocator_) HParallelMove(allocator_);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100992 move->SetLifetimePosition(position);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100993 instruction->GetBlock()->InsertInstructionBefore(move, instruction->GetNext());
994 }
Nicolas Geoffray740475d2014-09-29 10:33:25 +0100995 move->AddMove(new (allocator_) MoveOperands(source, destination, instruction));
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100996}
997
998void RegisterAllocator::ConnectSiblings(LiveInterval* interval) {
999 LiveInterval* current = interval;
1000 if (current->HasSpillSlot() && current->HasRegister()) {
1001 // We spill eagerly, so move must be at definition.
1002 InsertMoveAfter(interval->GetDefinedBy(),
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001003 interval->IsFloatingPoint()
1004 ? Location::FpuRegisterLocation(interval->GetRegister())
1005 : Location::RegisterLocation(interval->GetRegister()),
Nicolas Geoffray01ef3452014-10-01 11:32:17 +01001006 interval->NeedsTwoSpillSlots()
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001007 ? Location::DoubleStackSlot(interval->GetParent()->GetSpillSlot())
1008 : Location::StackSlot(interval->GetParent()->GetSpillSlot()));
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01001009 }
1010 UsePosition* use = current->GetFirstUse();
1011
1012 // Walk over all siblings, updating locations of use positions, and
1013 // connecting them when they are adjacent.
1014 do {
Nicolas Geoffray01ef3452014-10-01 11:32:17 +01001015 Location source = current->ToLocation();
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01001016
1017 // Walk over all uses covered by this interval, and update the location
1018 // information.
1019 while (use != nullptr && use->GetPosition() <= current->GetEnd()) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001020 LocationSummary* locations = use->GetUser()->GetLocations();
1021 if (use->GetIsEnvironment()) {
1022 locations->SetEnvironmentAt(use->GetInputIndex(), source);
1023 } else {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01001024 Location expected_location = locations->InAt(use->GetInputIndex());
1025 if (expected_location.IsUnallocated()) {
1026 locations->SetInAt(use->GetInputIndex(), source);
Nicolas Geoffray2a877f32014-09-10 10:49:34 +01001027 } else if (!expected_location.IsConstant()) {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01001028 AddInputMoveFor(use->GetUser(), source, expected_location);
1029 }
1030 }
1031 use = use->GetNext();
1032 }
1033
1034 // If the next interval starts just after this one, and has a register,
1035 // insert a move.
1036 LiveInterval* next_sibling = current->GetNextSibling();
1037 if (next_sibling != nullptr
1038 && next_sibling->HasRegister()
1039 && current->GetEnd() == next_sibling->GetStart()) {
Nicolas Geoffray01ef3452014-10-01 11:32:17 +01001040 Location destination = next_sibling->ToLocation();
Nicolas Geoffray740475d2014-09-29 10:33:25 +01001041 InsertParallelMoveAt(current->GetEnd(), interval->GetDefinedBy(), source, destination);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01001042 }
Nicolas Geoffray39468442014-09-02 15:17:15 +01001043
1044 // At each safepoint, we record stack and register information.
1045 for (size_t i = 0, e = safepoints_.Size(); i < e; ++i) {
1046 HInstruction* safepoint = safepoints_.Get(i);
1047 size_t position = safepoint->GetLifetimePosition();
1048 LocationSummary* locations = safepoint->GetLocations();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00001049 if (!current->Covers(position)) {
1050 continue;
1051 }
1052 if (interval->GetStart() == position) {
1053 // The safepoint is for this instruction, so the location of the instruction
1054 // does not need to be saved.
1055 continue;
1056 }
Nicolas Geoffray39468442014-09-02 15:17:15 +01001057
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +01001058 if ((current->GetType() == Primitive::kPrimNot) && current->GetParent()->HasSpillSlot()) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001059 locations->SetStackBit(current->GetParent()->GetSpillSlot() / kVRegSize);
1060 }
1061
1062 switch (source.GetKind()) {
1063 case Location::kRegister: {
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +01001064 locations->AddLiveRegister(source);
Nicolas Geoffray39468442014-09-02 15:17:15 +01001065 if (current->GetType() == Primitive::kPrimNot) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001066 locations->SetRegisterBit(source.reg());
Nicolas Geoffray39468442014-09-02 15:17:15 +01001067 }
1068 break;
1069 }
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001070 case Location::kFpuRegister: {
1071 locations->AddLiveRegister(source);
1072 break;
1073 }
Nicolas Geoffray39468442014-09-02 15:17:15 +01001074 case Location::kStackSlot: // Fall-through
1075 case Location::kDoubleStackSlot: // Fall-through
1076 case Location::kConstant: {
1077 // Nothing to do.
1078 break;
1079 }
1080 default: {
1081 LOG(FATAL) << "Unexpected location for object";
1082 }
1083 }
1084 }
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01001085 current = next_sibling;
1086 } while (current != nullptr);
1087 DCHECK(use == nullptr);
1088}
1089
1090void RegisterAllocator::ConnectSplitSiblings(LiveInterval* interval,
1091 HBasicBlock* from,
1092 HBasicBlock* to) const {
1093 if (interval->GetNextSibling() == nullptr) {
1094 // Nothing to connect. The whole range was allocated to the same location.
1095 return;
1096 }
1097
1098 size_t from_position = from->GetLifetimeEnd() - 1;
Mingyao Yang296bd602014-10-06 16:47:28 -07001099 // When an instruction dies at entry of another, and the latter is the beginning
Nicolas Geoffray76905622014-09-25 14:39:26 +01001100 // of a block, the register allocator ensures the former has a register
1101 // at block->GetLifetimeStart() + 1. Since this is at a block boundary, it must
1102 // must be handled in this method.
1103 size_t to_position = to->GetLifetimeStart() + 1;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01001104
1105 LiveInterval* destination = nullptr;
1106 LiveInterval* source = nullptr;
1107
1108 LiveInterval* current = interval;
1109
1110 // Check the intervals that cover `from` and `to`.
1111 while ((current != nullptr) && (source == nullptr || destination == nullptr)) {
1112 if (current->Covers(from_position)) {
1113 DCHECK(source == nullptr);
1114 source = current;
1115 }
1116 if (current->Covers(to_position)) {
1117 DCHECK(destination == nullptr);
1118 destination = current;
1119 }
1120
1121 current = current->GetNextSibling();
1122 }
1123
1124 if (destination == source) {
1125 // Interval was not split.
1126 return;
1127 }
1128
Nicolas Geoffray8ddb00c2014-09-29 12:00:40 +01001129 DCHECK(destination != nullptr && source != nullptr);
1130
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01001131 if (!destination->HasRegister()) {
1132 // Values are eagerly spilled. Spill slot already contains appropriate value.
1133 return;
1134 }
1135
1136 // If `from` has only one successor, we can put the moves at the exit of it. Otherwise
1137 // we need to put the moves at the entry of `to`.
1138 if (from->GetSuccessors().Size() == 1) {
Nicolas Geoffray740475d2014-09-29 10:33:25 +01001139 InsertParallelMoveAtExitOf(from,
1140 interval->GetParent()->GetDefinedBy(),
Nicolas Geoffray01ef3452014-10-01 11:32:17 +01001141 source->ToLocation(),
1142 destination->ToLocation());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01001143 } else {
1144 DCHECK_EQ(to->GetPredecessors().Size(), 1u);
Nicolas Geoffray740475d2014-09-29 10:33:25 +01001145 InsertParallelMoveAtEntryOf(to,
1146 interval->GetParent()->GetDefinedBy(),
Nicolas Geoffray01ef3452014-10-01 11:32:17 +01001147 source->ToLocation(),
1148 destination->ToLocation());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01001149 }
1150}
1151
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01001152void RegisterAllocator::Resolve() {
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +01001153 codegen_->ComputeFrameSize(
1154 spill_slots_.Size(), maximum_number_of_live_registers_, reserved_out_slots_);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01001155
1156 // Adjust the Out Location of instructions.
1157 // TODO: Use pointers of Location inside LiveInterval to avoid doing another iteration.
1158 for (size_t i = 0, e = liveness_.GetNumberOfSsaValues(); i < e; ++i) {
1159 HInstruction* instruction = liveness_.GetInstructionFromSsaIndex(i);
1160 LiveInterval* current = instruction->GetLiveInterval();
1161 LocationSummary* locations = instruction->GetLocations();
1162 Location location = locations->Out();
Roland Levillain476df552014-10-09 17:51:36 +01001163 if (instruction->IsParameterValue()) {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01001164 // Now that we know the frame size, adjust the parameter's location.
1165 if (location.IsStackSlot()) {
1166 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1167 current->SetSpillSlot(location.GetStackIndex());
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +00001168 locations->UpdateOut(location);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01001169 } else if (location.IsDoubleStackSlot()) {
1170 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1171 current->SetSpillSlot(location.GetStackIndex());
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +00001172 locations->UpdateOut(location);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01001173 } else if (current->HasSpillSlot()) {
1174 current->SetSpillSlot(current->GetSpillSlot() + codegen_->GetFrameSize());
1175 }
1176 }
1177
Nicolas Geoffray01ef3452014-10-01 11:32:17 +01001178 Location source = current->ToLocation();
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01001179
1180 if (location.IsUnallocated()) {
1181 if (location.GetPolicy() == Location::kSameAsFirstInput) {
Calin Juravled0d48522014-11-04 16:40:20 +00001182 if (locations->InAt(0).IsUnallocated()) {
1183 locations->SetInAt(0, source);
1184 } else {
1185 DCHECK(locations->InAt(0).Equals(source));
1186 }
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01001187 }
1188 locations->SetOut(source);
1189 } else {
1190 DCHECK(source.Equals(location));
1191 }
1192 }
1193
1194 // Connect siblings.
1195 for (size_t i = 0, e = liveness_.GetNumberOfSsaValues(); i < e; ++i) {
1196 HInstruction* instruction = liveness_.GetInstructionFromSsaIndex(i);
1197 ConnectSiblings(instruction->GetLiveInterval());
1198 }
1199
1200 // Resolve non-linear control flow across branches. Order does not matter.
1201 for (HLinearOrderIterator it(liveness_); !it.Done(); it.Advance()) {
1202 HBasicBlock* block = it.Current();
1203 BitVector* live = liveness_.GetLiveInSet(*block);
1204 for (uint32_t idx : live->Indexes()) {
1205 HInstruction* current = liveness_.GetInstructionFromSsaIndex(idx);
1206 LiveInterval* interval = current->GetLiveInterval();
1207 for (size_t i = 0, e = block->GetPredecessors().Size(); i < e; ++i) {
1208 ConnectSplitSiblings(interval, block->GetPredecessors().Get(i), block);
1209 }
1210 }
1211 }
1212
1213 // Resolve phi inputs. Order does not matter.
1214 for (HLinearOrderIterator it(liveness_); !it.Done(); it.Advance()) {
1215 HBasicBlock* current = it.Current();
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001216 for (HInstructionIterator inst_it(current->GetPhis()); !inst_it.Done(); inst_it.Advance()) {
1217 HInstruction* phi = inst_it.Current();
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01001218 for (size_t i = 0, e = current->GetPredecessors().Size(); i < e; ++i) {
1219 HBasicBlock* predecessor = current->GetPredecessors().Get(i);
1220 DCHECK_EQ(predecessor->GetSuccessors().Size(), 1u);
1221 HInstruction* input = phi->InputAt(i);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +01001222 Location source = input->GetLiveInterval()->GetLocationAt(
1223 predecessor->GetLifetimeEnd() - 1);
1224 Location destination = phi->GetLiveInterval()->ToLocation();
Nicolas Geoffray740475d2014-09-29 10:33:25 +01001225 InsertParallelMoveAtExitOf(predecessor, nullptr, source, destination);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01001226 }
1227 }
1228 }
Nicolas Geoffray39468442014-09-02 15:17:15 +01001229
1230 // Assign temp locations.
1231 HInstruction* current = nullptr;
1232 size_t temp_index = 0;
1233 for (size_t i = 0; i < temp_intervals_.Size(); ++i) {
1234 LiveInterval* temp = temp_intervals_.Get(i);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +01001235 HInstruction* at = liveness_.GetTempUser(temp);
1236 if (at != current) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001237 temp_index = 0;
Nicolas Geoffray01ef3452014-10-01 11:32:17 +01001238 current = at;
Nicolas Geoffray39468442014-09-02 15:17:15 +01001239 }
Nicolas Geoffray01ef3452014-10-01 11:32:17 +01001240 LocationSummary* locations = at->GetLocations();
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001241 DCHECK(temp->GetType() == Primitive::kPrimInt);
Nicolas Geoffray39468442014-09-02 15:17:15 +01001242 locations->SetTempAt(
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001243 temp_index++, Location::RegisterLocation(temp->GetRegister()));
Nicolas Geoffray39468442014-09-02 15:17:15 +01001244 }
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01001245}
1246
Nicolas Geoffraya7062e02014-05-22 12:50:17 +01001247} // namespace art