blob: bf27c5cf7a70b4e032d8a24d04048c78e8fd0582 [file] [log] [blame]
Nicolas Geoffray76716a62014-05-23 10:14:19 +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#ifndef ART_COMPILER_OPTIMIZING_LOCATIONS_H_
18#define ART_COMPILER_OPTIMIZING_LOCATIONS_H_
19
20#include "base/bit_field.h"
Nicolas Geoffray39468442014-09-02 15:17:15 +010021#include "base/bit_vector.h"
Ian Rogers0279ebb2014-10-08 17:27:48 -070022#include "base/value_object.h"
23#include "utils/arena_object.h"
Nicolas Geoffray76716a62014-05-23 10:14:19 +010024#include "utils/growable_array.h"
Nicolas Geoffray76716a62014-05-23 10:14:19 +010025
26namespace art {
27
Nicolas Geoffray96f89a22014-07-11 10:57:49 +010028class HConstant;
Nicolas Geoffray76716a62014-05-23 10:14:19 +010029class HInstruction;
Nicolas Geoffray424f6762014-11-03 14:51:25 +000030class Location;
31
32std::ostream& operator<<(std::ostream& os, const Location& location);
Nicolas Geoffray76716a62014-05-23 10:14:19 +010033
34/**
35 * A Location is an abstraction over the potential location
36 * of an instruction. It could be in register or stack.
37 */
38class Location : public ValueObject {
39 public:
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +000040 enum OutputOverlap {
41 kOutputOverlap,
42 kNoOutputOverlap
43 };
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +010044
Nicolas Geoffray76716a62014-05-23 10:14:19 +010045 enum Kind {
46 kInvalid = 0,
Nicolas Geoffray96f89a22014-07-11 10:57:49 +010047 kConstant = 1,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010048 kStackSlot = 2, // 32bit stack slot.
Nicolas Geoffray96f89a22014-07-11 10:57:49 +010049 kDoubleStackSlot = 3, // 64bit stack slot.
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010050
51 kRegister = 4, // Core register.
52
53 // We do not use the value 5 because it conflicts with kLocationConstantMask.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +010054 kDoNotUse5 = 5,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010055
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000056 kFpuRegister = 6, // Float register.
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010057
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000058 kRegisterPair = 7, // Long register.
59
60 kFpuRegisterPair = 8, // Double register.
61
62 // We do not use the value 9 because it conflicts with kLocationConstantMask.
63 kDoNotUse9 = 9,
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +010064
Nicolas Geoffray76716a62014-05-23 10:14:19 +010065 // Unallocated location represents a location that is not fixed and can be
66 // allocated by a register allocator. Each unallocated location has
67 // a policy that specifies what kind of location is suitable. Payload
68 // contains register allocation policy.
Mark Mendell3e6a3bf2015-01-19 14:09:22 -050069 kUnallocated = 10,
Nicolas Geoffray76716a62014-05-23 10:14:19 +010070 };
71
72 Location() : value_(kInvalid) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010073 // Verify that non-constant location kinds do not interfere with kConstant.
Andreas Gampe785d2f22014-11-03 22:57:30 -080074 static_assert((kInvalid & kLocationConstantMask) != kConstant, "TagError");
75 static_assert((kUnallocated & kLocationConstantMask) != kConstant, "TagError");
76 static_assert((kStackSlot & kLocationConstantMask) != kConstant, "TagError");
77 static_assert((kDoubleStackSlot & kLocationConstantMask) != kConstant, "TagError");
78 static_assert((kRegister & kLocationConstantMask) != kConstant, "TagError");
Andreas Gampe785d2f22014-11-03 22:57:30 -080079 static_assert((kFpuRegister & kLocationConstantMask) != kConstant, "TagError");
80 static_assert((kRegisterPair & kLocationConstantMask) != kConstant, "TagError");
81 static_assert((kFpuRegisterPair & kLocationConstantMask) != kConstant, "TagError");
82 static_assert((kConstant & kLocationConstantMask) == kConstant, "TagError");
Nicolas Geoffray96f89a22014-07-11 10:57:49 +010083
Nicolas Geoffray76716a62014-05-23 10:14:19 +010084 DCHECK(!IsValid());
85 }
86
87 Location(const Location& other) : ValueObject(), value_(other.value_) {}
88
89 Location& operator=(const Location& other) {
90 value_ = other.value_;
91 return *this;
92 }
93
Nicolas Geoffray96f89a22014-07-11 10:57:49 +010094 bool IsConstant() const {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010095 return (value_ & kLocationConstantMask) == kConstant;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +010096 }
97
98 static Location ConstantLocation(HConstant* constant) {
99 DCHECK(constant != nullptr);
Ian Rogers13735952014-10-08 12:43:28 -0700100 return Location(kConstant | reinterpret_cast<uintptr_t>(constant));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100101 }
102
103 HConstant* GetConstant() const {
104 DCHECK(IsConstant());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100105 return reinterpret_cast<HConstant*>(value_ & ~kLocationConstantMask);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100106 }
107
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100108 bool IsValid() const {
109 return value_ != kInvalid;
110 }
111
112 bool IsInvalid() const {
113 return !IsValid();
114 }
115
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100116 // Empty location. Used if there the location should be ignored.
117 static Location NoLocation() {
118 return Location();
119 }
120
121 // Register locations.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100122 static Location RegisterLocation(int reg) {
123 return Location(kRegister, reg);
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100124 }
125
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100126 static Location FpuRegisterLocation(int reg) {
127 return Location(kFpuRegister, reg);
128 }
129
130 static Location RegisterPairLocation(int low, int high) {
131 return Location(kRegisterPair, low << 16 | high);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100132 }
133
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000134 static Location FpuRegisterPairLocation(int low, int high) {
135 return Location(kFpuRegisterPair, low << 16 | high);
136 }
137
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100138 bool IsRegister() const {
139 return GetKind() == kRegister;
140 }
141
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100142 bool IsFpuRegister() const {
143 return GetKind() == kFpuRegister;
144 }
145
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100146 bool IsRegisterPair() const {
147 return GetKind() == kRegisterPair;
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100148 }
149
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000150 bool IsFpuRegisterPair() const {
151 return GetKind() == kFpuRegisterPair;
152 }
153
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100154 int reg() const {
155 DCHECK(IsRegister() || IsFpuRegister());
156 return GetPayload();
157 }
158
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000159 int low() const {
160 DCHECK(IsPair());
161 return GetPayload() >> 16;
162 }
163
164 int high() const {
165 DCHECK(IsPair());
166 return GetPayload() & 0xFFFF;
167 }
168
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100169 template <typename T>
Roland Levillain271ab9c2014-11-27 15:23:57 +0000170 T AsRegister() const {
171 DCHECK(IsRegister());
172 return static_cast<T>(reg());
173 }
174
175 template <typename T>
176 T AsFpuRegister() const {
177 DCHECK(IsFpuRegister());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100178 return static_cast<T>(reg());
179 }
180
181 template <typename T>
182 T AsRegisterPairLow() const {
183 DCHECK(IsRegisterPair());
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000184 return static_cast<T>(low());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100185 }
186
187 template <typename T>
188 T AsRegisterPairHigh() const {
189 DCHECK(IsRegisterPair());
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000190 return static_cast<T>(high());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100191 }
192
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000193 template <typename T>
194 T AsFpuRegisterPairLow() const {
195 DCHECK(IsFpuRegisterPair());
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000196 return static_cast<T>(low());
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000197 }
198
199 template <typename T>
200 T AsFpuRegisterPairHigh() const {
201 DCHECK(IsFpuRegisterPair());
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000202 return static_cast<T>(high());
203 }
204
205 bool IsPair() const {
206 return IsRegisterPair() || IsFpuRegisterPair();
207 }
208
209 Location ToLow() const {
210 return IsRegisterPair()
211 ? Location::RegisterLocation(low())
212 : Location::FpuRegisterLocation(low());
213 }
214
215 Location ToHigh() const {
216 return IsRegisterPair()
217 ? Location::RegisterLocation(high())
218 : Location::FpuRegisterLocation(high());
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000219 }
220
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100221 static uintptr_t EncodeStackIndex(intptr_t stack_index) {
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100222 DCHECK(-kStackIndexBias <= stack_index);
223 DCHECK(stack_index < kStackIndexBias);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100224 return static_cast<uintptr_t>(kStackIndexBias + stack_index);
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100225 }
226
227 static Location StackSlot(intptr_t stack_index) {
Ian Rogers13735952014-10-08 12:43:28 -0700228 uintptr_t payload = EncodeStackIndex(stack_index);
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100229 Location loc(kStackSlot, payload);
230 // Ensure that sign is preserved.
231 DCHECK_EQ(loc.GetStackIndex(), stack_index);
232 return loc;
233 }
234
235 bool IsStackSlot() const {
236 return GetKind() == kStackSlot;
237 }
238
239 static Location DoubleStackSlot(intptr_t stack_index) {
Ian Rogers13735952014-10-08 12:43:28 -0700240 uintptr_t payload = EncodeStackIndex(stack_index);
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100241 Location loc(kDoubleStackSlot, payload);
242 // Ensure that sign is preserved.
243 DCHECK_EQ(loc.GetStackIndex(), stack_index);
244 return loc;
245 }
246
247 bool IsDoubleStackSlot() const {
248 return GetKind() == kDoubleStackSlot;
249 }
250
251 intptr_t GetStackIndex() const {
252 DCHECK(IsStackSlot() || IsDoubleStackSlot());
253 // Decode stack index manually to preserve sign.
254 return GetPayload() - kStackIndexBias;
255 }
256
257 intptr_t GetHighStackIndex(uintptr_t word_size) const {
258 DCHECK(IsDoubleStackSlot());
259 // Decode stack index manually to preserve sign.
260 return GetPayload() - kStackIndexBias + word_size;
261 }
262
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100263 Kind GetKind() const {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100264 return IsConstant() ? kConstant : KindField::Decode(value_);
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100265 }
266
267 bool Equals(Location other) const {
268 return value_ == other.value_;
269 }
270
271 const char* DebugString() const {
272 switch (GetKind()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100273 case kInvalid: return "I";
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100274 case kRegister: return "R";
275 case kStackSlot: return "S";
276 case kDoubleStackSlot: return "DS";
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100277 case kUnallocated: return "U";
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100278 case kConstant: return "C";
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100279 case kFpuRegister: return "F";
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100280 case kRegisterPair: return "RP";
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000281 case kFpuRegisterPair: return "FP";
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100282 case kDoNotUse5: // fall-through
283 case kDoNotUse9:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100284 LOG(FATAL) << "Should not use this location kind";
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100285 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100286 UNREACHABLE();
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100287 return "?";
288 }
289
290 // Unallocated locations.
291 enum Policy {
292 kAny,
293 kRequiresRegister,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100294 kRequiresFpuRegister,
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100295 kSameAsFirstInput,
296 };
297
298 bool IsUnallocated() const {
299 return GetKind() == kUnallocated;
300 }
301
302 static Location UnallocatedLocation(Policy policy) {
303 return Location(kUnallocated, PolicyField::Encode(policy));
304 }
305
306 // Any free register is suitable to replace this unallocated location.
307 static Location Any() {
308 return UnallocatedLocation(kAny);
309 }
310
311 static Location RequiresRegister() {
312 return UnallocatedLocation(kRequiresRegister);
313 }
314
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100315 static Location RequiresFpuRegister() {
316 return UnallocatedLocation(kRequiresFpuRegister);
317 }
318
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100319 static Location RegisterOrConstant(HInstruction* instruction);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100320 static Location ByteRegisterOrConstant(int reg, HInstruction* instruction);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100321
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100322 // The location of the first input to the instruction will be
323 // used to replace this unallocated location.
324 static Location SameAsFirstInput() {
325 return UnallocatedLocation(kSameAsFirstInput);
326 }
327
328 Policy GetPolicy() const {
329 DCHECK(IsUnallocated());
330 return PolicyField::Decode(GetPayload());
331 }
332
Ian Rogers13735952014-10-08 12:43:28 -0700333 uintptr_t GetEncoding() const {
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100334 return GetPayload();
335 }
336
337 private:
338 // Number of bits required to encode Kind value.
339 static constexpr uint32_t kBitsForKind = 4;
Ian Rogers13735952014-10-08 12:43:28 -0700340 static constexpr uint32_t kBitsForPayload = kBitsPerIntPtrT - kBitsForKind;
341 static constexpr uintptr_t kLocationConstantMask = 0x3;
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100342
Ian Rogers13735952014-10-08 12:43:28 -0700343 explicit Location(uintptr_t value) : value_(value) {}
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100344
Ian Rogers13735952014-10-08 12:43:28 -0700345 Location(Kind kind, uintptr_t payload)
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100346 : value_(KindField::Encode(kind) | PayloadField::Encode(payload)) {}
347
Ian Rogers13735952014-10-08 12:43:28 -0700348 uintptr_t GetPayload() const {
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100349 return PayloadField::Decode(value_);
350 }
351
352 typedef BitField<Kind, 0, kBitsForKind> KindField;
Ian Rogers13735952014-10-08 12:43:28 -0700353 typedef BitField<uintptr_t, kBitsForKind, kBitsForPayload> PayloadField;
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100354
355 // Layout for kUnallocated locations payload.
356 typedef BitField<Policy, 0, 3> PolicyField;
357
358 // Layout for stack slots.
359 static const intptr_t kStackIndexBias =
360 static_cast<intptr_t>(1) << (kBitsForPayload - 1);
361
362 // Location either contains kind and payload fields or a tagged handle for
363 // a constant locations. Values of enumeration Kind are selected in such a
364 // way that none of them can be interpreted as a kConstant tag.
Ian Rogers13735952014-10-08 12:43:28 -0700365 uintptr_t value_;
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100366};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700367std::ostream& operator<<(std::ostream& os, const Location::Kind& rhs);
368std::ostream& operator<<(std::ostream& os, const Location::Policy& rhs);
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100369
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100370class RegisterSet : public ValueObject {
371 public:
372 RegisterSet() : core_registers_(0), floating_point_registers_(0) {}
373
374 void Add(Location loc) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100375 if (loc.IsRegister()) {
376 core_registers_ |= (1 << loc.reg());
377 } else {
378 DCHECK(loc.IsFpuRegister());
379 floating_point_registers_ |= (1 << loc.reg());
380 }
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100381 }
382
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100383 void Remove(Location loc) {
384 if (loc.IsRegister()) {
385 core_registers_ &= ~(1 << loc.reg());
386 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000387 DCHECK(loc.IsFpuRegister()) << loc;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100388 floating_point_registers_ &= ~(1 << loc.reg());
389 }
390 }
391
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100392 bool ContainsCoreRegister(uint32_t id) {
393 return Contains(core_registers_, id);
394 }
395
396 bool ContainsFloatingPointRegister(uint32_t id) {
397 return Contains(floating_point_registers_, id);
398 }
399
400 static bool Contains(uint32_t register_set, uint32_t reg) {
401 return (register_set & (1 << reg)) != 0;
402 }
403
Nicolas Geoffray87d03762014-11-19 15:17:56 +0000404 size_t GetNumberOfRegisters() const {
405 return __builtin_popcount(core_registers_) + __builtin_popcount(floating_point_registers_);
406 }
407
Nicolas Geoffray98893962015-01-21 12:32:32 +0000408 uint32_t GetCoreRegisters() const {
409 return core_registers_;
410 }
411
412 uint32_t GetFloatingPointRegisters() const {
413 return floating_point_registers_;
414 }
415
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100416 private:
417 uint32_t core_registers_;
418 uint32_t floating_point_registers_;
419
420 DISALLOW_COPY_AND_ASSIGN(RegisterSet);
421};
422
Andreas Gampe878d58c2015-01-15 23:24:00 -0800423static constexpr bool kIntrinsified = true;
424
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100425/**
426 * The code generator computes LocationSummary for each instruction so that
427 * the instruction itself knows what code to generate: where to find the inputs
428 * and where to place the result.
429 *
430 * The intent is to have the code for generating the instruction independent of
431 * register allocation. A register allocator just has to provide a LocationSummary.
432 */
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700433class LocationSummary : public ArenaObject<kArenaAllocMisc> {
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100434 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100435 enum CallKind {
436 kNoCall,
437 kCallOnSlowPath,
438 kCall
439 };
440
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800441 LocationSummary(HInstruction* instruction,
442 CallKind call_kind = kNoCall,
443 bool intrinsified = false);
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100444
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100445 void SetInAt(uint32_t at, Location location) {
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000446 DCHECK(inputs_.Get(at).IsUnallocated() || inputs_.Get(at).IsInvalid());
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100447 inputs_.Put(at, location);
448 }
449
450 Location InAt(uint32_t at) const {
451 return inputs_.Get(at);
452 }
453
454 size_t GetInputCount() const {
455 return inputs_.Size();
456 }
457
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000458 void SetOut(Location location, Location::OutputOverlap overlaps = Location::kOutputOverlap) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +0000459 DCHECK(output_.IsInvalid());
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100460 output_overlaps_ = overlaps;
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000461 output_ = location;
462 }
463
464 void UpdateOut(Location location) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +0000465 // There are two reasons for updating an output:
466 // 1) Parameters, where we only know the exact stack slot after
467 // doing full register allocation.
468 // 2) Unallocated location.
469 DCHECK(output_.IsStackSlot() || output_.IsDoubleStackSlot() || output_.IsUnallocated());
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000470 output_ = location;
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100471 }
472
473 void AddTemp(Location location) {
474 temps_.Add(location);
475 }
476
477 Location GetTemp(uint32_t at) const {
478 return temps_.Get(at);
479 }
480
481 void SetTempAt(uint32_t at, Location location) {
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000482 DCHECK(temps_.Get(at).IsUnallocated() || temps_.Get(at).IsInvalid());
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100483 temps_.Put(at, location);
484 }
485
486 size_t GetTempCount() const {
487 return temps_.Size();
488 }
489
Nicolas Geoffray39468442014-09-02 15:17:15 +0100490 void SetEnvironmentAt(uint32_t at, Location location) {
491 environment_.Put(at, location);
492 }
493
494 Location GetEnvironmentAt(uint32_t at) const {
495 return environment_.Get(at);
496 }
497
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100498 Location Out() const { return output_; }
499
Nicolas Geoffray39468442014-09-02 15:17:15 +0100500 bool CanCall() const { return call_kind_ != kNoCall; }
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100501 bool WillCall() const { return call_kind_ == kCall; }
502 bool OnlyCallsOnSlowPath() const { return call_kind_ == kCallOnSlowPath; }
Nicolas Geoffray39468442014-09-02 15:17:15 +0100503 bool NeedsSafepoint() const { return CanCall(); }
504
505 void SetStackBit(uint32_t index) {
506 stack_mask_->SetBit(index);
507 }
508
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100509 void ClearStackBit(uint32_t index) {
510 stack_mask_->ClearBit(index);
511 }
512
Nicolas Geoffray39468442014-09-02 15:17:15 +0100513 void SetRegisterBit(uint32_t reg_id) {
514 register_mask_ |= (1 << reg_id);
515 }
516
Nicolas Geoffray98893962015-01-21 12:32:32 +0000517 uint32_t GetRegisterMask() const {
518 return register_mask_;
519 }
520
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100521 bool RegisterContainsObject(uint32_t reg_id) {
522 return RegisterSet::Contains(register_mask_, reg_id);
523 }
524
525 void AddLiveRegister(Location location) {
526 live_registers_.Add(location);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100527 }
528
529 BitVector* GetStackMask() const {
530 return stack_mask_;
531 }
532
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100533 RegisterSet* GetLiveRegisters() {
534 return &live_registers_;
535 }
536
Nicolas Geoffray87d03762014-11-19 15:17:56 +0000537 size_t GetNumberOfLiveRegisters() const {
538 return live_registers_.GetNumberOfRegisters();
539 }
540
Nicolas Geoffray829280c2015-01-28 10:20:37 +0000541 bool OutputUsesSameAs(uint32_t input_index) const {
542 return (input_index == 0)
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100543 && output_.IsUnallocated()
Nicolas Geoffray829280c2015-01-28 10:20:37 +0000544 && (output_.GetPolicy() == Location::kSameAsFirstInput);
545 }
546
547 bool IsFixedInput(uint32_t input_index) const {
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000548 Location input = inputs_.Get(input_index);
Nicolas Geoffray829280c2015-01-28 10:20:37 +0000549 return input.IsRegister()
Nicolas Geoffray98893962015-01-21 12:32:32 +0000550 || input.IsFpuRegister()
551 || input.IsPair()
552 || input.IsStackSlot()
Nicolas Geoffray829280c2015-01-28 10:20:37 +0000553 || input.IsDoubleStackSlot();
Nicolas Geoffray76905622014-09-25 14:39:26 +0100554 }
555
Nicolas Geoffray829280c2015-01-28 10:20:37 +0000556 bool OutputCanOverlapWithInputs() const {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000557 return output_overlaps_ == Location::kOutputOverlap;
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100558 }
559
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800560 bool Intrinsified() const {
561 return intrinsified_;
562 }
563
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100564 private:
565 GrowableArray<Location> inputs_;
566 GrowableArray<Location> temps_;
Nicolas Geoffray39468442014-09-02 15:17:15 +0100567 GrowableArray<Location> environment_;
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100568 // Whether the output overlaps with any of the inputs. If it overlaps, then it cannot
569 // share the same register as the inputs.
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000570 Location::OutputOverlap output_overlaps_;
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100571 Location output_;
Nicolas Geoffray39468442014-09-02 15:17:15 +0100572 const CallKind call_kind_;
573
574 // Mask of objects that live in the stack.
575 BitVector* stack_mask_;
576
577 // Mask of objects that live in register.
578 uint32_t register_mask_;
579
580 // Registers that are in use at this position.
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100581 RegisterSet live_registers_;
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100582
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800583 // Whether these are locations for an intrinsified call.
584 const bool intrinsified_;
585
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000586 ART_FRIEND_TEST(RegisterAllocatorTest, ExpectedInRegisterHint);
587 ART_FRIEND_TEST(RegisterAllocatorTest, SameAsFirstInputHint);
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100588 DISALLOW_COPY_AND_ASSIGN(LocationSummary);
589};
590
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100591} // namespace art
592
593#endif // ART_COMPILER_OPTIMIZING_LOCATIONS_H_