176716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffray  /*
276716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffray * Copyright (C) 2014 The Android Open Source Project
376716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffray *
476716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License");
576716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffray * you may not use this file except in compliance with the License.
676716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffray * You may obtain a copy of the License at
776716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffray *
876716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffray *      http://www.apache.org/licenses/LICENSE-2.0
976716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffray *
1076716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffray * Unless required by applicable law or agreed to in writing, software
1176716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS,
1276716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1376716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffray * See the License for the specific language governing permissions and
1476716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffray * limitations under the License.
1576716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffray */
1676716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffray
1776716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffray#include "locations.h"
1876716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffray
1976716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffray#include "nodes.h"
20ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell#include "code_generator.h"
2176716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffray
2276716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffraynamespace art {
2376716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffray
2471fb52fee246b7d511f520febbd73dc7a9bbca79Andreas GampeLocationSummary::LocationSummary(HInstruction* instruction,
2571fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe                                 CallKind call_kind,
2671fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe                                 bool intrinsified)
272aaa4b5532d30c4e65d8892b556400bb61f9dc8cVladimir Marko    : inputs_(instruction->InputCount(),
282aaa4b5532d30c4e65d8892b556400bb61f9dc8cVladimir Marko              instruction->GetBlock()->GetGraph()->GetArena()->Adapter(kArenaAllocLocationSummary)),
292aaa4b5532d30c4e65d8892b556400bb61f9dc8cVladimir Marko      temps_(instruction->GetBlock()->GetGraph()->GetArena()->Adapter(kArenaAllocLocationSummary)),
306c2dff8ff8e1440fa4d9e1b2ba2a44d036882801Nicolas Geoffray      output_overlaps_(Location::kOutputOverlap),
313946844c34ad965515f677084b07d663d70ad1b8Nicolas Geoffray      call_kind_(call_kind),
323946844c34ad965515f677084b07d663d70ad1b8Nicolas Geoffray      stack_mask_(nullptr),
333946844c34ad965515f677084b07d663d70ad1b8Nicolas Geoffray      register_mask_(0),
3471fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe      live_registers_(),
3571fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe      intrinsified_(intrinsified) {
363946844c34ad965515f677084b07d663d70ad1b8Nicolas Geoffray  instruction->SetLocations(this);
373946844c34ad965515f677084b07d663d70ad1b8Nicolas Geoffray
383946844c34ad965515f677084b07d663d70ad1b8Nicolas Geoffray  if (NeedsSafepoint()) {
393946844c34ad965515f677084b07d663d70ad1b8Nicolas Geoffray    ArenaAllocator* arena = instruction->GetBlock()->GetGraph()->GetArena();
40f6a35de9eeefb20f6446f1b4815b4dcb0161d09cVladimir Marko    stack_mask_ = ArenaBitVector::Create(arena, 0, true, kArenaAllocLocationSummary);
413946844c34ad965515f677084b07d663d70ad1b8Nicolas Geoffray  }
4276716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffray}
4376716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffray
4496f89a290eb67d7bf4b1636798fa28df14309cc7Nicolas Geoffray
4596f89a290eb67d7bf4b1636798fa28df14309cc7Nicolas GeoffrayLocation Location::RegisterOrConstant(HInstruction* instruction) {
4696f89a290eb67d7bf4b1636798fa28df14309cc7Nicolas Geoffray  return instruction->IsConstant()
4796f89a290eb67d7bf4b1636798fa28df14309cc7Nicolas Geoffray      ? Location::ConstantLocation(instruction->AsConstant())
4896f89a290eb67d7bf4b1636798fa28df14309cc7Nicolas Geoffray      : Location::RequiresRegister();
4996f89a290eb67d7bf4b1636798fa28df14309cc7Nicolas Geoffray}
5096f89a290eb67d7bf4b1636798fa28df14309cc7Nicolas Geoffray
51ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark MendellLocation Location::RegisterOrInt32Constant(HInstruction* instruction) {
52ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell  HConstant* constant = instruction->AsConstant();
53ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell  if (constant != nullptr) {
54ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell    int64_t value = CodeGenerator::GetInt64ValueOf(constant);
55ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell    if (IsInt<32>(value)) {
56ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell      return Location::ConstantLocation(constant);
57ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell    }
583f6c7f61855172d3d9b7a9221baba76136088e7cMark Mendell  }
59ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell  return Location::RequiresRegister();
60ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell}
61ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell
62ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark MendellLocation Location::FpuRegisterOrInt32Constant(HInstruction* instruction) {
63ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell  HConstant* constant = instruction->AsConstant();
64ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell  if (constant != nullptr) {
65ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell    int64_t value = CodeGenerator::GetInt64ValueOf(constant);
66ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell    if (IsInt<32>(value)) {
67ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell      return Location::ConstantLocation(constant);
68ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell    }
69ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell  }
70ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell  return Location::RequiresFpuRegister();
713f6c7f61855172d3d9b7a9221baba76136088e7cMark Mendell}
723f6c7f61855172d3d9b7a9221baba76136088e7cMark Mendell
7356b9ee6fe1d6880c5fca0e7feb28b25a1ded2e2fNicolas GeoffrayLocation Location::ByteRegisterOrConstant(int reg, HInstruction* instruction) {
7426a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray  return instruction->IsConstant()
7526a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray      ? Location::ConstantLocation(instruction->AsConstant())
7626a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray      : Location::RegisterLocation(reg);
7726a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray}
7826a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray
79ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark MendellLocation Location::FpuRegisterOrConstant(HInstruction* instruction) {
80ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell  return instruction->IsConstant()
81ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell      ? Location::ConstantLocation(instruction->AsConstant())
82ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell      : Location::RequiresFpuRegister();
83ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell}
84ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell
8526a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffraystd::ostream& operator<<(std::ostream& os, const Location& location) {
8626a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray  os << location.DebugString();
87f7a0c4e421b5edaad5b7a15bfff687da28d0b287Nicolas Geoffray  if (location.IsRegister() || location.IsFpuRegister()) {
88f7a0c4e421b5edaad5b7a15bfff687da28d0b287Nicolas Geoffray    os << location.reg();
89f7a0c4e421b5edaad5b7a15bfff687da28d0b287Nicolas Geoffray  } else if (location.IsPair()) {
90f7a0c4e421b5edaad5b7a15bfff687da28d0b287Nicolas Geoffray    os << location.low() << ":" << location.high();
91f7a0c4e421b5edaad5b7a15bfff687da28d0b287Nicolas Geoffray  } else if (location.IsStackSlot() || location.IsDoubleStackSlot()) {
92f7a0c4e421b5edaad5b7a15bfff687da28d0b287Nicolas Geoffray    os << location.GetStackIndex();
93f7a0c4e421b5edaad5b7a15bfff687da28d0b287Nicolas Geoffray  }
9426a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray  return os;
9526a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray}
9626a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray
9776716a69a0e51b3516227e8b7e365e4b9490618cNicolas Geoffray}  // namespace art
98