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" 20 21 namespace art { 22 23 LocationSummary::LocationSummary(HInstruction* instruction, 24 CallKind call_kind, 25 bool intrinsified) 26 : inputs_(instruction->GetBlock()->GetGraph()->GetArena(), instruction->InputCount()), 27 temps_(instruction->GetBlock()->GetGraph()->GetArena(), 0), 28 output_overlaps_(Location::kOutputOverlap), 29 call_kind_(call_kind), 30 stack_mask_(nullptr), 31 register_mask_(0), 32 live_registers_(), 33 intrinsified_(intrinsified) { 34 inputs_.SetSize(instruction->InputCount()); 35 for (size_t i = 0; i < instruction->InputCount(); ++i) { 36 inputs_.Put(i, Location()); 37 } 38 instruction->SetLocations(this); 39 40 if (NeedsSafepoint()) { 41 ArenaAllocator* arena = instruction->GetBlock()->GetGraph()->GetArena(); 42 stack_mask_ = new (arena) ArenaBitVector(arena, 0, true); 43 } 44 } 45 46 47 Location Location::RegisterOrConstant(HInstruction* instruction) { 48 return instruction->IsConstant() 49 ? Location::ConstantLocation(instruction->AsConstant()) 50 : Location::RequiresRegister(); 51 } 52 53 Location Location::RegisterOrInt32LongConstant(HInstruction* instruction) { 54 if (!instruction->IsConstant() || !instruction->AsConstant()->IsLongConstant()) { 55 return Location::RequiresRegister(); 56 } 57 58 // Does the long constant fit in a 32 bit int? 59 int64_t value = instruction->AsConstant()->AsLongConstant()->GetValue(); 60 61 return IsInt<32>(value) 62 ? Location::ConstantLocation(instruction->AsConstant()) 63 : Location::RequiresRegister(); 64 } 65 66 Location Location::ByteRegisterOrConstant(int reg, HInstruction* instruction) { 67 return instruction->IsConstant() 68 ? Location::ConstantLocation(instruction->AsConstant()) 69 : Location::RegisterLocation(reg); 70 } 71 72 std::ostream& operator<<(std::ostream& os, const Location& location) { 73 os << location.DebugString(); 74 if (location.IsRegister() || location.IsFpuRegister()) { 75 os << location.reg(); 76 } else if (location.IsPair()) { 77 os << location.low() << ":" << location.high(); 78 } else if (location.IsStackSlot() || location.IsDoubleStackSlot()) { 79 os << location.GetStackIndex(); 80 } 81 return os; 82 } 83 84 } // namespace art 85