blob: d14dfc190f11d3a9f2a97851df0e2854522ea69e [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)
Nicolas Geoffray76716a62014-05-23 10:14:19 +010026 : inputs_(instruction->GetBlock()->GetGraph()->GetArena(), instruction->InputCount()),
Nicolas Geoffray39468442014-09-02 15:17:15 +010027 temps_(instruction->GetBlock()->GetGraph()->GetArena(), 0),
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +000028 output_overlaps_(Location::kOutputOverlap),
Nicolas Geoffray39468442014-09-02 15:17:15 +010029 call_kind_(call_kind),
30 stack_mask_(nullptr),
31 register_mask_(0),
Andreas Gampe71fb52f2014-12-29 17:43:08 -080032 live_registers_(),
33 intrinsified_(intrinsified) {
Nicolas Geoffray76716a62014-05-23 10:14:19 +010034 inputs_.SetSize(instruction->InputCount());
Nicolas Geoffray39468442014-09-02 15:17:15 +010035 for (size_t i = 0; i < instruction->InputCount(); ++i) {
Nicolas Geoffray76716a62014-05-23 10:14:19 +010036 inputs_.Put(i, Location());
37 }
Nicolas Geoffray39468442014-09-02 15:17:15 +010038 instruction->SetLocations(this);
39
40 if (NeedsSafepoint()) {
41 ArenaAllocator* arena = instruction->GetBlock()->GetGraph()->GetArena();
42 stack_mask_ = new (arena) ArenaBitVector(arena, 0, true);
43 }
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 Mendell3f6c7f62015-03-13 13:47:53 -040053Location Location::RegisterOrInt32LongConstant(HInstruction* instruction) {
Roland Levillain06b66d02015-07-01 12:47:25 +010054 if (instruction->IsIntConstant() || instruction->IsNullConstant()) {
55 return Location::ConstantLocation(instruction->AsConstant());
56 } else if (instruction->IsLongConstant()) {
57 // Does the long constant fit in a 32 bit int?
58 int64_t value = instruction->AsLongConstant()->GetValue();
59 return IsInt<32>(value)
60 ? Location::ConstantLocation(instruction->AsConstant())
61 : Location::RequiresRegister();
62 } else {
Mark Mendell3f6c7f62015-03-13 13:47:53 -040063 return Location::RequiresRegister();
64 }
Mark Mendell3f6c7f62015-03-13 13:47:53 -040065}
66
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +010067Location Location::ByteRegisterOrConstant(int reg, HInstruction* instruction) {
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +010068 return instruction->IsConstant()
69 ? Location::ConstantLocation(instruction->AsConstant())
70 : Location::RegisterLocation(reg);
71}
72
73std::ostream& operator<<(std::ostream& os, const Location& location) {
74 os << location.DebugString();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +000075 if (location.IsRegister() || location.IsFpuRegister()) {
76 os << location.reg();
77 } else if (location.IsPair()) {
78 os << location.low() << ":" << location.high();
79 } else if (location.IsStackSlot() || location.IsDoubleStackSlot()) {
80 os << location.GetStackIndex();
81 }
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +010082 return os;
83}
84
Nicolas Geoffray76716a62014-05-23 10:14:19 +010085} // namespace art