blob: 5879c6fa07dd90c9dc8dc20cc48c98e65bd27467 [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#include "locations.h"
18
Andreas Gampe2e6f38a2016-11-03 14:06:20 -070019#include <type_traits>
20
Mark Mendellea5af682015-10-22 17:35:49 -040021#include "code_generator.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070022#include "nodes.h"
Nicolas Geoffray76716a62014-05-23 10:14:19 +010023
24namespace art {
25
Andreas Gampe2e6f38a2016-11-03 14:06:20 -070026// Verify that Location is trivially copyable.
27static_assert(std::is_trivially_copyable<Location>::value, "Location should be trivially copyable");
28
Andreas Gampe71fb52f2014-12-29 17:43:08 -080029LocationSummary::LocationSummary(HInstruction* instruction,
30 CallKind call_kind,
Vladimir Markoca6fff82017-10-03 14:49:14 +010031 bool intrinsified,
32 ArenaAllocator* allocator)
33 : inputs_(instruction->InputCount(), allocator->Adapter(kArenaAllocLocationSummary)),
34 temps_(allocator->Adapter(kArenaAllocLocationSummary)),
Nicolas Geoffray39468442014-09-02 15:17:15 +010035 call_kind_(call_kind),
Vladimir Marko70e97462016-08-09 11:04:26 +010036 intrinsified_(intrinsified),
37 has_custom_slow_path_calling_convention_(false),
38 output_overlaps_(Location::kOutputOverlap),
Nicolas Geoffray39468442014-09-02 15:17:15 +010039 stack_mask_(nullptr),
40 register_mask_(0),
Vladimir Marko804b03f2016-09-14 16:26:36 +010041 live_registers_(RegisterSet::Empty()),
42 custom_slow_path_caller_saves_(RegisterSet::Empty()) {
Nicolas Geoffray39468442014-09-02 15:17:15 +010043 instruction->SetLocations(this);
44
45 if (NeedsSafepoint()) {
Vladimir Markoe764d2e2017-10-05 14:35:55 +010046 stack_mask_ = ArenaBitVector::Create(allocator, 0, true, kArenaAllocLocationSummary);
Nicolas Geoffray39468442014-09-02 15:17:15 +010047 }
Nicolas Geoffray76716a62014-05-23 10:14:19 +010048}
49
Vladimir Markoca6fff82017-10-03 14:49:14 +010050LocationSummary::LocationSummary(HInstruction* instruction,
51 CallKind call_kind,
52 bool intrinsified)
53 : LocationSummary(instruction,
54 call_kind,
55 intrinsified,
56 instruction->GetBlock()->GetGraph()->GetAllocator()) {}
Nicolas Geoffray96f89a22014-07-11 10:57:49 +010057
58Location Location::RegisterOrConstant(HInstruction* instruction) {
59 return instruction->IsConstant()
60 ? Location::ConstantLocation(instruction->AsConstant())
61 : Location::RequiresRegister();
62}
63
Mark Mendellea5af682015-10-22 17:35:49 -040064Location Location::RegisterOrInt32Constant(HInstruction* instruction) {
65 HConstant* constant = instruction->AsConstant();
66 if (constant != nullptr) {
67 int64_t value = CodeGenerator::GetInt64ValueOf(constant);
68 if (IsInt<32>(value)) {
69 return Location::ConstantLocation(constant);
70 }
Mark Mendell3f6c7f62015-03-13 13:47:53 -040071 }
Mark Mendellea5af682015-10-22 17:35:49 -040072 return Location::RequiresRegister();
73}
74
75Location Location::FpuRegisterOrInt32Constant(HInstruction* instruction) {
76 HConstant* constant = instruction->AsConstant();
77 if (constant != nullptr) {
78 int64_t value = CodeGenerator::GetInt64ValueOf(constant);
79 if (IsInt<32>(value)) {
80 return Location::ConstantLocation(constant);
81 }
82 }
83 return Location::RequiresFpuRegister();
Mark Mendell3f6c7f62015-03-13 13:47:53 -040084}
85
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +010086Location Location::ByteRegisterOrConstant(int reg, HInstruction* instruction) {
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +010087 return instruction->IsConstant()
88 ? Location::ConstantLocation(instruction->AsConstant())
89 : Location::RegisterLocation(reg);
90}
91
Mark Mendellea5af682015-10-22 17:35:49 -040092Location Location::FpuRegisterOrConstant(HInstruction* instruction) {
93 return instruction->IsConstant()
94 ? Location::ConstantLocation(instruction->AsConstant())
95 : Location::RequiresFpuRegister();
96}
97
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +010098std::ostream& operator<<(std::ostream& os, const Location& location) {
99 os << location.DebugString();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +0000100 if (location.IsRegister() || location.IsFpuRegister()) {
101 os << location.reg();
102 } else if (location.IsPair()) {
103 os << location.low() << ":" << location.high();
104 } else if (location.IsStackSlot() || location.IsDoubleStackSlot()) {
105 os << location.GetStackIndex();
106 }
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +0100107 return os;
108}
109
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100110} // namespace art