blob: 1b1b3a79ab5d6bdd27882ea7a5f18026036603b3 [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
19#include "nodes.h"
Mark Mendellea5af682015-10-22 17:35:49 -040020#include "code_generator.h"
Nicolas Geoffray76716a62014-05-23 10:14:19 +010021
22namespace art {
23
Andreas Gampe71fb52f2014-12-29 17:43:08 -080024LocationSummary::LocationSummary(HInstruction* instruction,
25 CallKind call_kind,
26 bool intrinsified)
Vladimir Marko2aaa4b52015-09-17 17:03:26 +010027 : inputs_(instruction->InputCount(),
28 instruction->GetBlock()->GetGraph()->GetArena()->Adapter(kArenaAllocLocationSummary)),
29 temps_(instruction->GetBlock()->GetGraph()->GetArena()->Adapter(kArenaAllocLocationSummary)),
Nicolas Geoffray39468442014-09-02 15:17:15 +010030 call_kind_(call_kind),
Vladimir Marko70e97462016-08-09 11:04:26 +010031 intrinsified_(intrinsified),
32 has_custom_slow_path_calling_convention_(false),
33 output_overlaps_(Location::kOutputOverlap),
Nicolas Geoffray39468442014-09-02 15:17:15 +010034 stack_mask_(nullptr),
35 register_mask_(0),
Andreas Gampe71fb52f2014-12-29 17:43:08 -080036 live_registers_(),
Vladimir Marko70e97462016-08-09 11:04:26 +010037 custom_slow_path_caller_saves_() {
Nicolas Geoffray39468442014-09-02 15:17:15 +010038 instruction->SetLocations(this);
39
40 if (NeedsSafepoint()) {
41 ArenaAllocator* arena = instruction->GetBlock()->GetGraph()->GetArena();
Vladimir Markof6a35de2016-03-21 12:01:50 +000042 stack_mask_ = ArenaBitVector::Create(arena, 0, true, kArenaAllocLocationSummary);
Nicolas Geoffray39468442014-09-02 15:17:15 +010043 }
Nicolas Geoffray76716a62014-05-23 10:14:19 +010044}
45
Nicolas Geoffray96f89a22014-07-11 10:57:49 +010046
47Location Location::RegisterOrConstant(HInstruction* instruction) {
48 return instruction->IsConstant()
49 ? Location::ConstantLocation(instruction->AsConstant())
50 : Location::RequiresRegister();
51}
52
Mark Mendellea5af682015-10-22 17:35:49 -040053Location Location::RegisterOrInt32Constant(HInstruction* instruction) {
54 HConstant* constant = instruction->AsConstant();
55 if (constant != nullptr) {
56 int64_t value = CodeGenerator::GetInt64ValueOf(constant);
57 if (IsInt<32>(value)) {
58 return Location::ConstantLocation(constant);
59 }
Mark Mendell3f6c7f62015-03-13 13:47:53 -040060 }
Mark Mendellea5af682015-10-22 17:35:49 -040061 return Location::RequiresRegister();
62}
63
64Location Location::FpuRegisterOrInt32Constant(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 }
71 }
72 return Location::RequiresFpuRegister();
Mark Mendell3f6c7f62015-03-13 13:47:53 -040073}
74
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +010075Location Location::ByteRegisterOrConstant(int reg, HInstruction* instruction) {
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +010076 return instruction->IsConstant()
77 ? Location::ConstantLocation(instruction->AsConstant())
78 : Location::RegisterLocation(reg);
79}
80
Mark Mendellea5af682015-10-22 17:35:49 -040081Location Location::FpuRegisterOrConstant(HInstruction* instruction) {
82 return instruction->IsConstant()
83 ? Location::ConstantLocation(instruction->AsConstant())
84 : Location::RequiresFpuRegister();
85}
86
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +010087std::ostream& operator<<(std::ostream& os, const Location& location) {
88 os << location.DebugString();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +000089 if (location.IsRegister() || location.IsFpuRegister()) {
90 os << location.reg();
91 } else if (location.IsPair()) {
92 os << location.low() << ":" << location.high();
93 } else if (location.IsStackSlot() || location.IsDoubleStackSlot()) {
94 os << location.GetStackIndex();
95 }
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +010096 return os;
97}
98
Nicolas Geoffray76716a62014-05-23 10:14:19 +010099} // namespace art