blob: 1ab206f69e676d973e18b0925304720cd3f87301 [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 Geoffray6c2dff82015-01-21 14:56:54 +000030 output_overlaps_(Location::kOutputOverlap),
Nicolas Geoffray39468442014-09-02 15:17:15 +010031 call_kind_(call_kind),
32 stack_mask_(nullptr),
33 register_mask_(0),
Andreas Gampe71fb52f2014-12-29 17:43:08 -080034 live_registers_(),
35 intrinsified_(intrinsified) {
Nicolas Geoffray39468442014-09-02 15:17:15 +010036 instruction->SetLocations(this);
37
38 if (NeedsSafepoint()) {
39 ArenaAllocator* arena = instruction->GetBlock()->GetGraph()->GetArena();
40 stack_mask_ = new (arena) ArenaBitVector(arena, 0, true);
41 }
Nicolas Geoffray76716a62014-05-23 10:14:19 +010042}
43
Nicolas Geoffray96f89a22014-07-11 10:57:49 +010044
45Location Location::RegisterOrConstant(HInstruction* instruction) {
46 return instruction->IsConstant()
47 ? Location::ConstantLocation(instruction->AsConstant())
48 : Location::RequiresRegister();
49}
50
Mark Mendellea5af682015-10-22 17:35:49 -040051Location Location::RegisterOrInt32Constant(HInstruction* instruction) {
52 HConstant* constant = instruction->AsConstant();
53 if (constant != nullptr) {
54 int64_t value = CodeGenerator::GetInt64ValueOf(constant);
55 if (IsInt<32>(value)) {
56 return Location::ConstantLocation(constant);
57 }
Mark Mendell3f6c7f62015-03-13 13:47:53 -040058 }
Mark Mendellea5af682015-10-22 17:35:49 -040059 return Location::RequiresRegister();
60}
61
62Location Location::FpuRegisterOrInt32Constant(HInstruction* instruction) {
63 HConstant* constant = instruction->AsConstant();
64 if (constant != nullptr) {
65 int64_t value = CodeGenerator::GetInt64ValueOf(constant);
66 if (IsInt<32>(value)) {
67 return Location::ConstantLocation(constant);
68 }
69 }
70 return Location::RequiresFpuRegister();
Mark Mendell3f6c7f62015-03-13 13:47:53 -040071}
72
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +010073Location Location::ByteRegisterOrConstant(int reg, HInstruction* instruction) {
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +010074 return instruction->IsConstant()
75 ? Location::ConstantLocation(instruction->AsConstant())
76 : Location::RegisterLocation(reg);
77}
78
Mark Mendellea5af682015-10-22 17:35:49 -040079Location Location::FpuRegisterOrConstant(HInstruction* instruction) {
80 return instruction->IsConstant()
81 ? Location::ConstantLocation(instruction->AsConstant())
82 : Location::RequiresFpuRegister();
83}
84
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +010085std::ostream& operator<<(std::ostream& os, const Location& location) {
86 os << location.DebugString();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +000087 if (location.IsRegister() || location.IsFpuRegister()) {
88 os << location.reg();
89 } else if (location.IsPair()) {
90 os << location.low() << ":" << location.high();
91 } else if (location.IsStackSlot() || location.IsDoubleStackSlot()) {
92 os << location.GetStackIndex();
93 }
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +010094 return os;
95}
96
Nicolas Geoffray76716a62014-05-23 10:14:19 +010097} // namespace art