blob: ebdf7a2f6510729e39d8e0eea79bf8edb410296e [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"
20
21namespace art {
22
Andreas Gampe71fb52f2014-12-29 17:43:08 -080023LocationSummary::LocationSummary(HInstruction* instruction,
24 CallKind call_kind,
25 bool intrinsified)
Vladimir Marko2aaa4b52015-09-17 17:03:26 +010026 : inputs_(instruction->InputCount(),
27 instruction->GetBlock()->GetGraph()->GetArena()->Adapter(kArenaAllocLocationSummary)),
28 temps_(instruction->GetBlock()->GetGraph()->GetArena()->Adapter(kArenaAllocLocationSummary)),
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +000029 output_overlaps_(Location::kOutputOverlap),
Nicolas Geoffray39468442014-09-02 15:17:15 +010030 call_kind_(call_kind),
31 stack_mask_(nullptr),
32 register_mask_(0),
Andreas Gampe71fb52f2014-12-29 17:43:08 -080033 live_registers_(),
34 intrinsified_(intrinsified) {
Nicolas Geoffray39468442014-09-02 15:17:15 +010035 instruction->SetLocations(this);
36
37 if (NeedsSafepoint()) {
38 ArenaAllocator* arena = instruction->GetBlock()->GetGraph()->GetArena();
39 stack_mask_ = new (arena) ArenaBitVector(arena, 0, true);
40 }
Nicolas Geoffray76716a62014-05-23 10:14:19 +010041}
42
Nicolas Geoffray96f89a22014-07-11 10:57:49 +010043
44Location Location::RegisterOrConstant(HInstruction* instruction) {
45 return instruction->IsConstant()
46 ? Location::ConstantLocation(instruction->AsConstant())
47 : Location::RequiresRegister();
48}
49
Mark Mendell3f6c7f62015-03-13 13:47:53 -040050Location Location::RegisterOrInt32LongConstant(HInstruction* instruction) {
Roland Levillain06b66d02015-07-01 12:47:25 +010051 if (instruction->IsIntConstant() || instruction->IsNullConstant()) {
52 return Location::ConstantLocation(instruction->AsConstant());
53 } else if (instruction->IsLongConstant()) {
54 // Does the long constant fit in a 32 bit int?
55 int64_t value = instruction->AsLongConstant()->GetValue();
56 return IsInt<32>(value)
57 ? Location::ConstantLocation(instruction->AsConstant())
58 : Location::RequiresRegister();
59 } else {
Mark Mendell3f6c7f62015-03-13 13:47:53 -040060 return Location::RequiresRegister();
61 }
Mark Mendell3f6c7f62015-03-13 13:47:53 -040062}
63
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +010064Location Location::ByteRegisterOrConstant(int reg, HInstruction* instruction) {
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +010065 return instruction->IsConstant()
66 ? Location::ConstantLocation(instruction->AsConstant())
67 : Location::RegisterLocation(reg);
68}
69
70std::ostream& operator<<(std::ostream& os, const Location& location) {
71 os << location.DebugString();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +000072 if (location.IsRegister() || location.IsFpuRegister()) {
73 os << location.reg();
74 } else if (location.IsPair()) {
75 os << location.low() << ":" << location.high();
76 } else if (location.IsStackSlot() || location.IsDoubleStackSlot()) {
77 os << location.GetStackIndex();
78 }
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +010079 return os;
80}
81
Nicolas Geoffray76716a62014-05-23 10:14:19 +010082} // namespace art