Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [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 "code_generator_arm.h" |
| 18 | #include "utils/assembler.h" |
| 19 | #include "utils/arm/assembler_arm.h" |
| 20 | |
| 21 | #define __ reinterpret_cast<ArmAssembler*>(assembler())-> |
| 22 | |
| 23 | namespace art { |
| 24 | namespace arm { |
| 25 | |
| 26 | void CodeGeneratorARM::GenerateFrameEntry() { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 27 | __ PushList((1 << FP) | (1 << LR)); |
| 28 | __ mov(FP, ShifterOperand(SP)); |
| 29 | if (frame_size_ != 0) { |
| 30 | __ AddConstant(SP, -frame_size_); |
| 31 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 35 | __ mov(SP, ShifterOperand(FP)); |
| 36 | __ PopList((1 << FP) | (1 << PC)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | void CodeGeneratorARM::Bind(Label* label) { |
| 40 | __ Bind(label); |
| 41 | } |
| 42 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 43 | void CodeGeneratorARM::Push(HInstruction* instruction, Location location) { |
| 44 | __ Push(location.reg<Register>()); |
| 45 | } |
| 46 | |
| 47 | void 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 | |
| 56 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 57 | got->set_locations(nullptr); |
| 58 | } |
| 59 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 60 | void CodeGeneratorARM::VisitGoto(HGoto* got) { |
| 61 | HBasicBlock* successor = got->GetSuccessor(); |
| 62 | if (graph()->exit_block() == successor) { |
| 63 | GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 64 | } else if (!GoesToNextBlock(got->block(), successor)) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 65 | __ b(GetLabelOf(successor)); |
| 66 | } |
| 67 | } |
| 68 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 69 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
| 70 | exit->set_locations(nullptr); |
| 71 | } |
| 72 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 73 | void CodeGeneratorARM::VisitExit(HExit* exit) { |
| 74 | if (kIsDebugBuild) { |
| 75 | __ Comment("Unreachable"); |
| 76 | __ bkpt(0); |
| 77 | } |
| 78 | } |
| 79 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 80 | void 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 Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 86 | void CodeGeneratorARM::VisitIf(HIf* if_instr) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 87 | // 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 | |
| 95 | void 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 Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 103 | void CodeGeneratorARM::VisitEqual(HEqual* equal) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 104 | 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 | |
| 111 | void LocationsBuilderARM::VisitLocal(HLocal* local) { |
| 112 | local->set_locations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | void CodeGeneratorARM::VisitLocal(HLocal* local) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 116 | DCHECK_EQ(local->block(), graph()->entry_block()); |
| 117 | frame_size_ += kWordSize; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 120 | void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) { |
| 121 | LocationSummary* locations = new (graph()->arena()) LocationSummary(load); |
| 122 | locations->SetOut(Location(R0)); |
| 123 | load->set_locations(locations); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 124 | } |
| 125 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 126 | static 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 | |
| 131 | void CodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) { |
| 132 | LocationSummary* locations = load->locations(); |
| 133 | __ LoadFromOffset(kLoadWord, locations->Out().reg<Register>(), |
| 134 | FP, GetStackSlot(load->GetLocal())); |
| 135 | } |
| 136 | |
| 137 | void 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 | |
| 143 | void CodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) { |
| 144 | LocationSummary* locations = store->locations(); |
| 145 | __ StoreToOffset(kStoreWord, locations->InAt(1).reg<Register>(), |
| 146 | FP, GetStackSlot(store->GetLocal())); |
| 147 | } |
| 148 | |
| 149 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
| 150 | constant->set_locations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | void CodeGeneratorARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 154 | // Will be generated at use site. |
| 155 | } |
| 156 | |
| 157 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
| 158 | ret->set_locations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 159 | } |
| 160 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 161 | void CodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) { |
| 162 | GenerateFrameExit(); |
| 163 | } |
| 164 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 165 | void 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 | |
| 171 | void CodeGeneratorARM::VisitReturn(HReturn* ret) { |
| 172 | DCHECK_EQ(ret->locations()->InAt(0).reg<Register>(), R0); |
| 173 | GenerateFrameExit(); |
| 174 | } |
| 175 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 176 | } // namespace arm |
| 177 | } // namespace art |