blob: 29dfddf4d6c453e9ac65d537a6fea1bb5afc511b [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 Markoca6fff82017-10-03 14:49:14 +010046 ArenaAllocator* arena = instruction->GetBlock()->GetGraph()->GetAllocator();
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
Vladimir Markoca6fff82017-10-03 14:49:14 +010051LocationSummary::LocationSummary(HInstruction* instruction,
52 CallKind call_kind,
53 bool intrinsified)
54 : LocationSummary(instruction,
55 call_kind,
56 intrinsified,
57 instruction->GetBlock()->GetGraph()->GetAllocator()) {}
Nicolas Geoffray96f89a22014-07-11 10:57:49 +010058
59Location Location::RegisterOrConstant(HInstruction* instruction) {
60 return instruction->IsConstant()
61 ? Location::ConstantLocation(instruction->AsConstant())
62 : Location::RequiresRegister();
63}
64
Mark Mendellea5af682015-10-22 17:35:49 -040065Location Location::RegisterOrInt32Constant(HInstruction* instruction) {
66 HConstant* constant = instruction->AsConstant();
67 if (constant != nullptr) {
68 int64_t value = CodeGenerator::GetInt64ValueOf(constant);
69 if (IsInt<32>(value)) {
70 return Location::ConstantLocation(constant);
71 }
Mark Mendell3f6c7f62015-03-13 13:47:53 -040072 }
Mark Mendellea5af682015-10-22 17:35:49 -040073 return Location::RequiresRegister();
74}
75
76Location Location::FpuRegisterOrInt32Constant(HInstruction* instruction) {
77 HConstant* constant = instruction->AsConstant();
78 if (constant != nullptr) {
79 int64_t value = CodeGenerator::GetInt64ValueOf(constant);
80 if (IsInt<32>(value)) {
81 return Location::ConstantLocation(constant);
82 }
83 }
84 return Location::RequiresFpuRegister();
Mark Mendell3f6c7f62015-03-13 13:47:53 -040085}
86
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +010087Location Location::ByteRegisterOrConstant(int reg, HInstruction* instruction) {
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +010088 return instruction->IsConstant()
89 ? Location::ConstantLocation(instruction->AsConstant())
90 : Location::RegisterLocation(reg);
91}
92
Mark Mendellea5af682015-10-22 17:35:49 -040093Location Location::FpuRegisterOrConstant(HInstruction* instruction) {
94 return instruction->IsConstant()
95 ? Location::ConstantLocation(instruction->AsConstant())
96 : Location::RequiresFpuRegister();
97}
98
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +010099std::ostream& operator<<(std::ostream& os, const Location& location) {
100 os << location.DebugString();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +0000101 if (location.IsRegister() || location.IsFpuRegister()) {
102 os << location.reg();
103 } else if (location.IsPair()) {
104 os << location.low() << ":" << location.high();
105 } else if (location.IsStackSlot() || location.IsDoubleStackSlot()) {
106 os << location.GetStackIndex();
107 }
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +0100108 return os;
109}
110
Nicolas Geoffray76716a62014-05-23 10:14:19 +0100111} // namespace art