blob: a9fe209063489aa54f35a7d341605310a440ee8c [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
Nicolas Geoffray76716a62014-05-23 10:14:19 +010021#include "nodes.h"
Mark Mendellea5af682015-10-22 17:35:49 -040022#include "code_generator.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,
31 bool intrinsified)
Vladimir Marko2aaa4b52015-09-17 17:03:26 +010032 : inputs_(instruction->InputCount(),
33 instruction->GetBlock()->GetGraph()->GetArena()->Adapter(kArenaAllocLocationSummary)),
34 temps_(instruction->GetBlock()->GetGraph()->GetArena()->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()) {
46 ArenaAllocator* arena = instruction->GetBlock()->GetGraph()->GetArena();
Vladimir Markof6a35de2016-03-21 12:01:50 +000047 stack_mask_ = ArenaBitVector::Create(arena, 0, true, kArenaAllocLocationSummary);
Nicolas Geoffray39468442014-09-02 15:17:15 +010048 }
Nicolas Geoffray76716a62014-05-23 10:14:19 +010049}
50
Nicolas Geoffray96f89a22014-07-11 10:57:49 +010051
52Location Location::RegisterOrConstant(HInstruction* instruction) {
53 return instruction->IsConstant()
54 ? Location::ConstantLocation(instruction->AsConstant())
55 : Location::RequiresRegister();
56}
57
Mark Mendellea5af682015-10-22 17:35:49 -040058Location Location::RegisterOrInt32Constant(HInstruction* instruction) {
59 HConstant* constant = instruction->AsConstant();
60 if (constant != nullptr) {
61 int64_t value = CodeGenerator::GetInt64ValueOf(constant);
62 if (IsInt<32>(value)) {
63 return Location::ConstantLocation(constant);
64 }
Mark Mendell3f6c7f62015-03-13 13:47:53 -040065 }
Mark Mendellea5af682015-10-22 17:35:49 -040066 return Location::RequiresRegister();
67}
68
69Location Location::FpuRegisterOrInt32Constant(HInstruction* instruction) {
70 HConstant* constant = instruction->AsConstant();
71 if (constant != nullptr) {
72 int64_t value = CodeGenerator::GetInt64ValueOf(constant);
73 if (IsInt<32>(value)) {
74 return Location::ConstantLocation(constant);
75 }
76 }
77 return Location::RequiresFpuRegister();
Mark Mendell3f6c7f62015-03-13 13:47:53 -040078}
79
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +010080Location Location::ByteRegisterOrConstant(int reg, HInstruction* instruction) {
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +010081 return instruction->IsConstant()
82 ? Location::ConstantLocation(instruction->AsConstant())
83 : Location::RegisterLocation(reg);
84}
85
Mark Mendellea5af682015-10-22 17:35:49 -040086Location Location::FpuRegisterOrConstant(HInstruction* instruction) {
87 return instruction->IsConstant()
88 ? Location::ConstantLocation(instruction->AsConstant())
89 : Location::RequiresFpuRegister();
90}
91
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +010092std::ostream& operator<<(std::ostream& os, const Location& location) {
93 os << location.DebugString();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +000094 if (location.IsRegister() || location.IsFpuRegister()) {
95 os << location.reg();
96 } else if (location.IsPair()) {
97 os << location.low() << ":" << location.high();
98 } else if (location.IsStackSlot() || location.IsDoubleStackSlot()) {
99 os << location.GetStackIndex();
100 }
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +0100101 return os;
102}
103
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100104} // namespace art