Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 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 "nodes.h" |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 20 | #include "code_generator.h" |
Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 21 | |
| 22 | namespace art { |
| 23 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 24 | LocationSummary::LocationSummary(HInstruction* instruction, |
| 25 | CallKind call_kind, |
| 26 | bool intrinsified) |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 27 | : inputs_(instruction->InputCount(), |
| 28 | instruction->GetBlock()->GetGraph()->GetArena()->Adapter(kArenaAllocLocationSummary)), |
| 29 | temps_(instruction->GetBlock()->GetGraph()->GetArena()->Adapter(kArenaAllocLocationSummary)), |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 30 | output_overlaps_(Location::kOutputOverlap), |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 31 | call_kind_(call_kind), |
| 32 | stack_mask_(nullptr), |
| 33 | register_mask_(0), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 34 | live_registers_(), |
| 35 | intrinsified_(intrinsified) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 36 | 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 Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 42 | } |
| 43 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 44 | |
| 45 | Location Location::RegisterOrConstant(HInstruction* instruction) { |
| 46 | return instruction->IsConstant() |
| 47 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 48 | : Location::RequiresRegister(); |
| 49 | } |
| 50 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 51 | Location 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 Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 58 | } |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 59 | return Location::RequiresRegister(); |
| 60 | } |
| 61 | |
| 62 | Location 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 Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 71 | } |
| 72 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 73 | Location Location::ByteRegisterOrConstant(int reg, HInstruction* instruction) { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 74 | return instruction->IsConstant() |
| 75 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 76 | : Location::RegisterLocation(reg); |
| 77 | } |
| 78 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 79 | Location Location::FpuRegisterOrConstant(HInstruction* instruction) { |
| 80 | return instruction->IsConstant() |
| 81 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 82 | : Location::RequiresFpuRegister(); |
| 83 | } |
| 84 | |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 85 | std::ostream& operator<<(std::ostream& os, const Location& location) { |
| 86 | os << location.DebugString(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 87 | 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 Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 94 | return os; |
| 95 | } |
| 96 | |
Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 97 | } // namespace art |