| 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 |  | 
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 21 | #include "nodes.h" | 
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 22 | #include "code_generator.h" | 
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 23 |  | 
 | 24 | namespace art { | 
 | 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, | 
 | 31 |                                  bool intrinsified) | 
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 32 |     : inputs_(instruction->InputCount(), | 
 | 33 |               instruction->GetBlock()->GetGraph()->GetArena()->Adapter(kArenaAllocLocationSummary)), | 
 | 34 |       temps_(instruction->GetBlock()->GetGraph()->GetArena()->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()) { | 
 | 46 |     ArenaAllocator* arena = instruction->GetBlock()->GetGraph()->GetArena(); | 
| Vladimir Marko | f6a35de | 2016-03-21 12:01:50 +0000 | [diff] [blame] | 47 |     stack_mask_ = ArenaBitVector::Create(arena, 0, true, kArenaAllocLocationSummary); | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 48 |   } | 
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 49 | } | 
 | 50 |  | 
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 51 |  | 
 | 52 | Location Location::RegisterOrConstant(HInstruction* instruction) { | 
 | 53 |   return instruction->IsConstant() | 
 | 54 |       ? Location::ConstantLocation(instruction->AsConstant()) | 
 | 55 |       : Location::RequiresRegister(); | 
 | 56 | } | 
 | 57 |  | 
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 58 | Location Location::RegisterOrInt32Constant(HInstruction* instruction) { | 
 | 59 |   HConstant* constant = instruction->AsConstant(); | 
 | 60 |   if (constant != nullptr) { | 
 | 61 |     int64_t value = CodeGenerator::GetInt64ValueOf(constant); | 
 | 62 |     if (IsInt<32>(value)) { | 
 | 63 |       return Location::ConstantLocation(constant); | 
 | 64 |     } | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 65 |   } | 
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 66 |   return Location::RequiresRegister(); | 
 | 67 | } | 
 | 68 |  | 
 | 69 | Location Location::FpuRegisterOrInt32Constant(HInstruction* instruction) { | 
 | 70 |   HConstant* constant = instruction->AsConstant(); | 
 | 71 |   if (constant != nullptr) { | 
 | 72 |     int64_t value = CodeGenerator::GetInt64ValueOf(constant); | 
 | 73 |     if (IsInt<32>(value)) { | 
 | 74 |       return Location::ConstantLocation(constant); | 
 | 75 |     } | 
 | 76 |   } | 
 | 77 |   return Location::RequiresFpuRegister(); | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 78 | } | 
 | 79 |  | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 80 | Location Location::ByteRegisterOrConstant(int reg, HInstruction* instruction) { | 
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 81 |   return instruction->IsConstant() | 
 | 82 |       ? Location::ConstantLocation(instruction->AsConstant()) | 
 | 83 |       : Location::RegisterLocation(reg); | 
 | 84 | } | 
 | 85 |  | 
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 86 | Location Location::FpuRegisterOrConstant(HInstruction* instruction) { | 
 | 87 |   return instruction->IsConstant() | 
 | 88 |       ? Location::ConstantLocation(instruction->AsConstant()) | 
 | 89 |       : Location::RequiresFpuRegister(); | 
 | 90 | } | 
 | 91 |  | 
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 92 | std::ostream& operator<<(std::ostream& os, const Location& location) { | 
 | 93 |   os << location.DebugString(); | 
| Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 94 |   if (location.IsRegister() || location.IsFpuRegister()) { | 
 | 95 |     os << location.reg(); | 
 | 96 |   } else if (location.IsPair()) { | 
 | 97 |     os << location.low() << ":" << location.high(); | 
 | 98 |   } else if (location.IsStackSlot() || location.IsDoubleStackSlot()) { | 
 | 99 |     os << location.GetStackIndex(); | 
 | 100 |   } | 
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 101 |   return os; | 
 | 102 | } | 
 | 103 |  | 
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 104 | }  // namespace art |