blob: 62bf7ba4d85114cbed2803c1ccb50b7bd6cc4202 [file] [log] [blame]
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001/*
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 "code_generator_arm.h"
18#include "utils/assembler.h"
19#include "utils/arm/assembler_arm.h"
20
21#define __ reinterpret_cast<ArmAssembler*>(assembler())->
22
23namespace art {
24namespace arm {
25
26void CodeGeneratorARM::GenerateFrameEntry() {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000027 __ PushList((1 << FP) | (1 << LR));
28 __ mov(FP, ShifterOperand(SP));
29 if (frame_size_ != 0) {
30 __ AddConstant(SP, -frame_size_);
31 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000032}
33
34void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000035 __ mov(SP, ShifterOperand(FP));
36 __ PopList((1 << FP) | (1 << PC));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000037}
38
39void CodeGeneratorARM::Bind(Label* label) {
40 __ Bind(label);
41}
42
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000043void CodeGeneratorARM::Push(HInstruction* instruction, Location location) {
44 __ Push(location.reg<Register>());
45}
46
47void CodeGeneratorARM::Move(HInstruction* instruction, Location location) {
48 HIntConstant* constant = instruction->AsIntConstant();
49 if (constant != nullptr) {
50 __ LoadImmediate(location.reg<Register>(), constant->value());
51 } else {
52 __ Pop(location.reg<Register>());
53 }
54}
55
56void LocationsBuilderARM::VisitGoto(HGoto* got) {
57 got->set_locations(nullptr);
58}
59
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000060void CodeGeneratorARM::VisitGoto(HGoto* got) {
61 HBasicBlock* successor = got->GetSuccessor();
62 if (graph()->exit_block() == successor) {
63 GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000064 } else if (!GoesToNextBlock(got->block(), successor)) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000065 __ b(GetLabelOf(successor));
66 }
67}
68
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000069void LocationsBuilderARM::VisitExit(HExit* exit) {
70 exit->set_locations(nullptr);
71}
72
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000073void CodeGeneratorARM::VisitExit(HExit* exit) {
74 if (kIsDebugBuild) {
75 __ Comment("Unreachable");
76 __ bkpt(0);
77 }
78}
79
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000080void LocationsBuilderARM::VisitIf(HIf* if_instr) {
81 LocationSummary* locations = new (graph()->arena()) LocationSummary(if_instr);
82 locations->SetInAt(0, Location(R0));
83 if_instr->set_locations(locations);
84}
85
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000086void CodeGeneratorARM::VisitIf(HIf* if_instr) {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000087 // TODO: Generate the input as a condition, instead of materializing in a register.
88 __ cmp(if_instr->locations()->InAt(0).reg<Register>(), ShifterOperand(0));
89 __ b(GetLabelOf(if_instr->IfFalseSuccessor()), EQ);
90 if (!GoesToNextBlock(if_instr->block(), if_instr->IfTrueSuccessor())) {
91 __ b(GetLabelOf(if_instr->IfTrueSuccessor()));
92 }
93}
94
95void LocationsBuilderARM::VisitEqual(HEqual* equal) {
96 LocationSummary* locations = new (graph()->arena()) LocationSummary(equal);
97 locations->SetInAt(0, Location(R0));
98 locations->SetInAt(1, Location(R1));
99 locations->SetOut(Location(R0));
100 equal->set_locations(locations);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000101}
102
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000103void CodeGeneratorARM::VisitEqual(HEqual* equal) {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000104 LocationSummary* locations = equal->locations();
105 __ teq(locations->InAt(0).reg<Register>(),
106 ShifterOperand(locations->InAt(1).reg<Register>()));
107 __ mov(locations->Out().reg<Register>(), ShifterOperand(1), EQ);
108 __ mov(locations->Out().reg<Register>(), ShifterOperand(0), NE);
109}
110
111void LocationsBuilderARM::VisitLocal(HLocal* local) {
112 local->set_locations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000113}
114
115void CodeGeneratorARM::VisitLocal(HLocal* local) {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000116 DCHECK_EQ(local->block(), graph()->entry_block());
117 frame_size_ += kWordSize;
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000118}
119
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000120void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
121 LocationSummary* locations = new (graph()->arena()) LocationSummary(load);
122 locations->SetOut(Location(R0));
123 load->set_locations(locations);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000124}
125
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000126static int32_t GetStackSlot(HLocal* local) {
127 // We are currently using FP to access locals, so the offset must be negative.
128 return (local->reg_number() + 1) * -kWordSize;
129}
130
131void CodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
132 LocationSummary* locations = load->locations();
133 __ LoadFromOffset(kLoadWord, locations->Out().reg<Register>(),
134 FP, GetStackSlot(load->GetLocal()));
135}
136
137void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
138 LocationSummary* locations = new (graph()->arena()) LocationSummary(store);
139 locations->SetInAt(1, Location(R0));
140 store->set_locations(locations);
141}
142
143void CodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
144 LocationSummary* locations = store->locations();
145 __ StoreToOffset(kStoreWord, locations->InAt(1).reg<Register>(),
146 FP, GetStackSlot(store->GetLocal()));
147}
148
149void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
150 constant->set_locations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000151}
152
153void CodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000154 // Will be generated at use site.
155}
156
157void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
158 ret->set_locations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000159}
160
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000161void CodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
162 GenerateFrameExit();
163}
164
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000165void LocationsBuilderARM::VisitReturn(HReturn* ret) {
166 LocationSummary* locations = new (graph()->arena()) LocationSummary(ret);
167 locations->SetInAt(0, Location(R0));
168 ret->set_locations(locations);
169}
170
171void CodeGeneratorARM::VisitReturn(HReturn* ret) {
172 DCHECK_EQ(ret->locations()->InAt(0).reg<Register>(), R0);
173 GenerateFrameExit();
174}
175
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000176} // namespace arm
177} // namespace art