1 /*
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
19 #include <type_traits>
20
21 #include "code_generator.h"
22 #include "nodes.h"
23
24 namespace art HIDDEN {
25
26 // Verify that Location is trivially copyable.
27 static_assert(std::is_trivially_copyable<Location>::value, "Location should be trivially copyable");
28
AllocateInputLocations(HInstruction * instruction,ArenaAllocator * allocator)29 static inline ArrayRef<Location> AllocateInputLocations(HInstruction* instruction,
30 ArenaAllocator* allocator) {
31 size_t input_count = instruction->InputCount();
32 Location* array = allocator->AllocArray<Location>(input_count, kArenaAllocLocationSummary);
33 return {array, input_count};
34 }
35
LocationSummary(HInstruction * instruction,CallKind call_kind,bool intrinsified,ArenaAllocator * allocator)36 LocationSummary::LocationSummary(HInstruction* instruction,
37 CallKind call_kind,
38 bool intrinsified,
39 ArenaAllocator* allocator)
40 : inputs_(AllocateInputLocations(instruction, allocator)),
41 temps_(allocator->Adapter(kArenaAllocLocationSummary)),
42 stack_mask_(nullptr),
43 call_kind_(call_kind),
44 intrinsified_(intrinsified),
45 has_custom_slow_path_calling_convention_(false),
46 output_overlaps_(Location::kOutputOverlap),
47 register_mask_(0),
48 live_registers_(RegisterSet::Empty()),
49 custom_slow_path_caller_saves_(RegisterSet::Empty()) {
50 instruction->SetLocations(this);
51
52 if (NeedsSafepoint()) {
53 stack_mask_ = ArenaBitVector::Create(allocator, 0, true, kArenaAllocLocationSummary);
54 }
55 }
56
LocationSummary(HInstruction * instruction,CallKind call_kind,bool intrinsified)57 LocationSummary::LocationSummary(HInstruction* instruction,
58 CallKind call_kind,
59 bool intrinsified)
60 : LocationSummary(instruction,
61 call_kind,
62 intrinsified,
63 instruction->GetBlock()->GetGraph()->GetAllocator()) {}
64
RegisterOrConstant(HInstruction * instruction)65 Location Location::RegisterOrConstant(HInstruction* instruction) {
66 return instruction->IsConstant()
67 ? Location::ConstantLocation(instruction)
68 : Location::RequiresRegister();
69 }
70
RegisterOrInt32Constant(HInstruction * instruction)71 Location Location::RegisterOrInt32Constant(HInstruction* instruction) {
72 HConstant* constant = instruction->AsConstantOrNull();
73 if (constant != nullptr) {
74 int64_t value = CodeGenerator::GetInt64ValueOf(constant);
75 if (IsInt<32>(value)) {
76 return Location::ConstantLocation(constant);
77 }
78 }
79 return Location::RequiresRegister();
80 }
81
FpuRegisterOrInt32Constant(HInstruction * instruction)82 Location Location::FpuRegisterOrInt32Constant(HInstruction* instruction) {
83 HConstant* constant = instruction->AsConstantOrNull();
84 if (constant != nullptr) {
85 int64_t value = CodeGenerator::GetInt64ValueOf(constant);
86 if (IsInt<32>(value)) {
87 return Location::ConstantLocation(constant);
88 }
89 }
90 return Location::RequiresFpuRegister();
91 }
92
ByteRegisterOrConstant(int reg,HInstruction * instruction)93 Location Location::ByteRegisterOrConstant(int reg, HInstruction* instruction) {
94 return instruction->IsConstant()
95 ? Location::ConstantLocation(instruction)
96 : Location::RegisterLocation(reg);
97 }
98
FpuRegisterOrConstant(HInstruction * instruction)99 Location Location::FpuRegisterOrConstant(HInstruction* instruction) {
100 return instruction->IsConstant()
101 ? Location::ConstantLocation(instruction)
102 : Location::RequiresFpuRegister();
103 }
104
DCheckInstructionIsConstant(HInstruction * instruction)105 void Location::DCheckInstructionIsConstant(HInstruction* instruction) {
106 DCHECK(instruction != nullptr);
107 DCHECK(instruction->IsConstant());
108 DCHECK_EQ(reinterpret_cast<uintptr_t>(instruction),
109 reinterpret_cast<uintptr_t>(instruction->AsConstant()));
110 }
111
operator <<(std::ostream & os,const Location & location)112 std::ostream& operator<<(std::ostream& os, const Location& location) {
113 os << location.DebugString();
114 if (location.IsRegister() || location.IsFpuRegister()) {
115 os << location.reg();
116 } else if (location.IsPair()) {
117 os << location.low() << ":" << location.high();
118 } else if (location.IsStackSlot() || location.IsDoubleStackSlot()) {
119 os << location.GetStackIndex();
120 }
121 return os;
122 }
123
124 } // namespace art
125