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 | |
Andreas Gampe | 2e6f38a | 2016-11-03 14:06:20 -0700 | [diff] [blame] | 19 | #include <type_traits> |
| 20 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 21 | #include "code_generator.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 22 | #include "nodes.h" |
Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 23 | |
Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 24 | namespace art { |
Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 25 | |
Andreas Gampe | 2e6f38a | 2016-11-03 14:06:20 -0700 | [diff] [blame] | 26 | // Verify that Location is trivially copyable. |
| 27 | static_assert(std::is_trivially_copyable<Location>::value, "Location should be trivially copyable"); |
| 28 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 29 | LocationSummary::LocationSummary(HInstruction* instruction, |
| 30 | CallKind call_kind, |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 31 | bool intrinsified, |
| 32 | ArenaAllocator* allocator) |
| 33 | : inputs_(instruction->InputCount(), allocator->Adapter(kArenaAllocLocationSummary)), |
| 34 | temps_(allocator->Adapter(kArenaAllocLocationSummary)), |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 35 | call_kind_(call_kind), |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 36 | intrinsified_(intrinsified), |
| 37 | has_custom_slow_path_calling_convention_(false), |
| 38 | output_overlaps_(Location::kOutputOverlap), |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 39 | stack_mask_(nullptr), |
| 40 | register_mask_(0), |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 41 | live_registers_(RegisterSet::Empty()), |
| 42 | custom_slow_path_caller_saves_(RegisterSet::Empty()) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 43 | instruction->SetLocations(this); |
| 44 | |
| 45 | if (NeedsSafepoint()) { |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 46 | stack_mask_ = ArenaBitVector::Create(allocator, 0, true, kArenaAllocLocationSummary); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 47 | } |
Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 48 | } |
| 49 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 50 | LocationSummary::LocationSummary(HInstruction* instruction, |
| 51 | CallKind call_kind, |
| 52 | bool intrinsified) |
| 53 | : LocationSummary(instruction, |
| 54 | call_kind, |
| 55 | intrinsified, |
| 56 | instruction->GetBlock()->GetGraph()->GetAllocator()) {} |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 57 | |
| 58 | Location Location::RegisterOrConstant(HInstruction* instruction) { |
| 59 | return instruction->IsConstant() |
| 60 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 61 | : Location::RequiresRegister(); |
| 62 | } |
| 63 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 64 | Location Location::RegisterOrInt32Constant(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 | } |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 71 | } |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 72 | return Location::RequiresRegister(); |
| 73 | } |
| 74 | |
| 75 | Location Location::FpuRegisterOrInt32Constant(HInstruction* instruction) { |
| 76 | HConstant* constant = instruction->AsConstant(); |
| 77 | if (constant != nullptr) { |
| 78 | int64_t value = CodeGenerator::GetInt64ValueOf(constant); |
| 79 | if (IsInt<32>(value)) { |
| 80 | return Location::ConstantLocation(constant); |
| 81 | } |
| 82 | } |
| 83 | return Location::RequiresFpuRegister(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 84 | } |
| 85 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 86 | Location Location::ByteRegisterOrConstant(int reg, HInstruction* instruction) { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 87 | return instruction->IsConstant() |
| 88 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 89 | : Location::RegisterLocation(reg); |
| 90 | } |
| 91 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 92 | Location Location::FpuRegisterOrConstant(HInstruction* instruction) { |
| 93 | return instruction->IsConstant() |
| 94 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 95 | : Location::RequiresFpuRegister(); |
| 96 | } |
| 97 | |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 98 | std::ostream& operator<<(std::ostream& os, const Location& location) { |
| 99 | os << location.DebugString(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 100 | if (location.IsRegister() || location.IsFpuRegister()) { |
| 101 | os << location.reg(); |
| 102 | } else if (location.IsPair()) { |
| 103 | os << location.low() << ":" << location.high(); |
| 104 | } else if (location.IsStackSlot() || location.IsDoubleStackSlot()) { |
| 105 | os << location.GetStackIndex(); |
| 106 | } |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 107 | return os; |
| 108 | } |
| 109 | |
Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 110 | } // namespace art |