blob: 853541754d73bfb35f5715c9cd3895156667e2e4 [file] [log] [blame]
Scott Wakelingfe885462016-09-22 10:24:38 +01001/*
2 * Copyright (C) 2016 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#ifndef ART_COMPILER_OPTIMIZING_COMMON_ARM_H_
18#define ART_COMPILER_OPTIMIZING_COMMON_ARM_H_
19
20// TODO(VIXL): Make VIXL compile with -Wshadow.
21#pragma GCC diagnostic push
22#pragma GCC diagnostic ignored "-Wshadow"
23#include "aarch32/macro-assembler-aarch32.h"
24#pragma GCC diagnostic pop
25
26namespace art {
27namespace arm {
28namespace helpers {
29
30static_assert(vixl::aarch32::kSpCode == SP, "vixl::aarch32::kSpCode must equal ART's SP");
31
32inline dwarf::Reg DWARFReg(vixl::aarch32::Register reg) {
33 return dwarf::Reg::ArmCore(static_cast<int>(reg.GetCode()));
34}
35
36inline dwarf::Reg DWARFReg(vixl::aarch32::SRegister reg) {
37 return dwarf::Reg::ArmFp(static_cast<int>(reg.GetCode()));
38}
39
40inline vixl::aarch32::DRegister FromLowSToD(vixl::aarch32::SRegister reg) {
41 DCHECK_EQ(reg.GetCode() % 2, 0u) << reg;
42 return vixl::aarch32::DRegister(reg.GetCode() / 2);
43}
44
45inline vixl::aarch32::Register RegisterFrom(Location location) {
46 DCHECK(location.IsRegister()) << location;
47 return vixl::aarch32::Register(location.reg());
48}
49
50inline vixl::aarch32::Register RegisterFrom(Location location, Primitive::Type type) {
51 DCHECK(type != Primitive::kPrimVoid && !Primitive::IsFloatingPointType(type)) << type;
52 return RegisterFrom(location);
53}
54
55inline vixl::aarch32::DRegister DRegisterFrom(Location location) {
56 DCHECK(location.IsFpuRegister()) << location;
57 return vixl::aarch32::DRegister(location.reg());
58}
59
60inline vixl::aarch32::SRegister SRegisterFrom(Location location) {
61 DCHECK(location.IsFpuRegister()) << location;
62 return vixl::aarch32::SRegister(location.reg());
63}
64
65inline vixl::aarch32::SRegister OutputSRegister(HInstruction* instr) {
66 Primitive::Type type = instr->GetType();
67 DCHECK_EQ(type, Primitive::kPrimFloat) << type;
68 return SRegisterFrom(instr->GetLocations()->Out());
69}
70
71inline vixl::aarch32::DRegister OutputDRegister(HInstruction* instr) {
72 Primitive::Type type = instr->GetType();
73 DCHECK_EQ(type, Primitive::kPrimDouble) << type;
74 return DRegisterFrom(instr->GetLocations()->Out());
75}
76
77inline vixl::aarch32::SRegister InputSRegisterAt(HInstruction* instr, int input_index) {
78 Primitive::Type type = instr->InputAt(input_index)->GetType();
79 DCHECK_EQ(type, Primitive::kPrimFloat) << type;
80 return SRegisterFrom(instr->GetLocations()->InAt(input_index));
81}
82
83inline vixl::aarch32::DRegister InputDRegisterAt(HInstruction* instr, int input_index) {
84 Primitive::Type type = instr->InputAt(input_index)->GetType();
85 DCHECK_EQ(type, Primitive::kPrimDouble) << type;
86 return DRegisterFrom(instr->GetLocations()->InAt(input_index));
87}
88
89inline vixl::aarch32::Register OutputRegister(HInstruction* instr) {
90 return RegisterFrom(instr->GetLocations()->Out(), instr->GetType());
91}
92
93inline vixl::aarch32::Register InputRegisterAt(HInstruction* instr, int input_index) {
94 return RegisterFrom(instr->GetLocations()->InAt(input_index),
95 instr->InputAt(input_index)->GetType());
96}
97
98inline int64_t Int64ConstantFrom(Location location) {
99 HConstant* instr = location.GetConstant();
100 if (instr->IsIntConstant()) {
101 return instr->AsIntConstant()->GetValue();
102 } else if (instr->IsNullConstant()) {
103 return 0;
104 } else {
105 DCHECK(instr->IsLongConstant()) << instr->DebugName();
106 return instr->AsLongConstant()->GetValue();
107 }
108}
109
110inline vixl::aarch32::Operand OperandFrom(Location location, Primitive::Type type) {
111 if (location.IsRegister()) {
112 return vixl::aarch32::Operand(RegisterFrom(location, type));
113 } else {
114 return vixl::aarch32::Operand(Int64ConstantFrom(location));
115 }
116}
117
118inline vixl::aarch32::Operand InputOperandAt(HInstruction* instr, int input_index) {
119 return OperandFrom(instr->GetLocations()->InAt(input_index),
120 instr->InputAt(input_index)->GetType());
121}
122
123} // namespace helpers
124} // namespace arm
125} // namespace art
126
127#endif // ART_COMPILER_OPTIMIZING_COMMON_ARM_H_