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" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 18 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 19 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 20 | #include "gc/accounting/card_table.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 21 | #include "mirror/array-inl.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 22 | #include "mirror/art_method.h" |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 23 | #include "mirror/class.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 24 | #include "thread.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 25 | #include "utils/arm/assembler_arm.h" |
| 26 | #include "utils/arm/managed_register_arm.h" |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 27 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 28 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 29 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 30 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 31 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 32 | namespace arm { |
| 33 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 34 | static DRegister FromLowSToD(SRegister reg) { |
| 35 | DCHECK_EQ(reg % 2, 0); |
| 36 | return static_cast<DRegister>(reg / 2); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 37 | } |
| 38 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 39 | static constexpr bool kExplicitStackOverflowCheck = false; |
| 40 | |
| 41 | static constexpr int kNumberOfPushedRegistersAtEntry = 1 + 2; // LR, R6, R7 |
| 42 | static constexpr int kCurrentMethodStackOffset = 0; |
| 43 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 44 | static constexpr Register kRuntimeParameterCoreRegisters[] = { R0, R1, R2, R3 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 45 | static constexpr size_t kRuntimeParameterCoreRegistersLength = |
| 46 | arraysize(kRuntimeParameterCoreRegisters); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 47 | static constexpr SRegister kRuntimeParameterFpuRegisters[] = { }; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 48 | static constexpr size_t kRuntimeParameterFpuRegistersLength = 0; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 49 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 50 | class InvokeRuntimeCallingConvention : public CallingConvention<Register, SRegister> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 51 | public: |
| 52 | InvokeRuntimeCallingConvention() |
| 53 | : CallingConvention(kRuntimeParameterCoreRegisters, |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 54 | kRuntimeParameterCoreRegistersLength, |
| 55 | kRuntimeParameterFpuRegisters, |
| 56 | kRuntimeParameterFpuRegistersLength) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 57 | |
| 58 | private: |
| 59 | DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention); |
| 60 | }; |
| 61 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 62 | #define __ reinterpret_cast<ArmAssembler*>(codegen->GetAssembler())-> |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 63 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 64 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 65 | class SlowPathCodeARM : public SlowPathCode { |
| 66 | public: |
| 67 | SlowPathCodeARM() : entry_label_(), exit_label_() {} |
| 68 | |
| 69 | Label* GetEntryLabel() { return &entry_label_; } |
| 70 | Label* GetExitLabel() { return &exit_label_; } |
| 71 | |
| 72 | private: |
| 73 | Label entry_label_; |
| 74 | Label exit_label_; |
| 75 | |
| 76 | DISALLOW_COPY_AND_ASSIGN(SlowPathCodeARM); |
| 77 | }; |
| 78 | |
| 79 | class NullCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 80 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 81 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 82 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 83 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 84 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 85 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 86 | arm_codegen->InvokeRuntime( |
| 87 | QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 91 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 92 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 93 | }; |
| 94 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 95 | class DivZeroCheckSlowPathARM : public SlowPathCodeARM { |
| 96 | public: |
| 97 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 98 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 99 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 100 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 101 | __ Bind(GetEntryLabel()); |
| 102 | arm_codegen->InvokeRuntime( |
| 103 | QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc()); |
| 104 | } |
| 105 | |
| 106 | private: |
| 107 | HDivZeroCheck* const instruction_; |
| 108 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 109 | }; |
| 110 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 111 | class StackOverflowCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 112 | public: |
| 113 | StackOverflowCheckSlowPathARM() {} |
| 114 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 115 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 116 | __ Bind(GetEntryLabel()); |
| 117 | __ LoadFromOffset(kLoadWord, PC, TR, |
| 118 | QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pThrowStackOverflow).Int32Value()); |
| 119 | } |
| 120 | |
| 121 | private: |
| 122 | DISALLOW_COPY_AND_ASSIGN(StackOverflowCheckSlowPathARM); |
| 123 | }; |
| 124 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 125 | class SuspendCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 126 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 127 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 128 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 129 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 130 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 131 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 132 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 133 | codegen->SaveLiveRegisters(instruction_->GetLocations()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 134 | arm_codegen->InvokeRuntime( |
| 135 | QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 136 | codegen->RestoreLiveRegisters(instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 137 | if (successor_ == nullptr) { |
| 138 | __ b(GetReturnLabel()); |
| 139 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 140 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 141 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 144 | Label* GetReturnLabel() { |
| 145 | DCHECK(successor_ == nullptr); |
| 146 | return &return_label_; |
| 147 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 148 | |
| 149 | private: |
| 150 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 151 | // If not null, the block to branch to after the suspend check. |
| 152 | HBasicBlock* const successor_; |
| 153 | |
| 154 | // If `successor_` is null, the label to branch to after the suspend check. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 155 | Label return_label_; |
| 156 | |
| 157 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 158 | }; |
| 159 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 160 | class BoundsCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 161 | public: |
Roland Levillain | 5799fc0 | 2014-09-25 12:15:20 +0100 | [diff] [blame] | 162 | BoundsCheckSlowPathARM(HBoundsCheck* instruction, |
| 163 | Location index_location, |
| 164 | Location length_location) |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 165 | : instruction_(instruction), |
| 166 | index_location_(index_location), |
| 167 | length_location_(length_location) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 168 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 169 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 170 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 171 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 172 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 173 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 174 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 175 | codegen->EmitParallelMoves( |
| 176 | index_location_, |
| 177 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 178 | length_location_, |
| 179 | Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 180 | arm_codegen->InvokeRuntime( |
| 181 | QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 185 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 186 | const Location index_location_; |
| 187 | const Location length_location_; |
| 188 | |
| 189 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 190 | }; |
| 191 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 192 | class LoadClassSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 193 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 194 | LoadClassSlowPathARM(HLoadClass* cls, |
| 195 | HInstruction* at, |
| 196 | uint32_t dex_pc, |
| 197 | bool do_clinit) |
| 198 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 199 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 200 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 201 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 202 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 203 | LocationSummary* locations = at_->GetLocations(); |
| 204 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 205 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 206 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 207 | codegen->SaveLiveRegisters(locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 208 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 209 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 210 | __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 211 | arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 212 | int32_t entry_point_offset = do_clinit_ |
| 213 | ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 214 | : QUICK_ENTRY_POINT(pInitializeType); |
| 215 | arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_); |
| 216 | |
| 217 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 218 | Location out = locations->Out(); |
| 219 | if (out.IsValid()) { |
| 220 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 221 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 222 | } |
| 223 | codegen->RestoreLiveRegisters(locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 224 | __ b(GetExitLabel()); |
| 225 | } |
| 226 | |
| 227 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 228 | // The class this slow path will load. |
| 229 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 230 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 231 | // The instruction where this slow path is happening. |
| 232 | // (Might be the load class or an initialization check). |
| 233 | HInstruction* const at_; |
| 234 | |
| 235 | // The dex PC of `at_`. |
| 236 | const uint32_t dex_pc_; |
| 237 | |
| 238 | // Whether to initialize the class. |
| 239 | const bool do_clinit_; |
| 240 | |
| 241 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 242 | }; |
| 243 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 244 | class LoadStringSlowPathARM : public SlowPathCodeARM { |
| 245 | public: |
| 246 | explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {} |
| 247 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 248 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 249 | LocationSummary* locations = instruction_->GetLocations(); |
| 250 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 251 | |
| 252 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 253 | __ Bind(GetEntryLabel()); |
| 254 | codegen->SaveLiveRegisters(locations); |
| 255 | |
| 256 | InvokeRuntimeCallingConvention calling_convention; |
| 257 | arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(0)); |
| 258 | __ LoadImmediate(calling_convention.GetRegisterAt(1), instruction_->GetStringIndex()); |
| 259 | arm_codegen->InvokeRuntime( |
| 260 | QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc()); |
| 261 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 262 | |
| 263 | codegen->RestoreLiveRegisters(locations); |
| 264 | __ b(GetExitLabel()); |
| 265 | } |
| 266 | |
| 267 | private: |
| 268 | HLoadString* const instruction_; |
| 269 | |
| 270 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 271 | }; |
| 272 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 273 | class TypeCheckSlowPathARM : public SlowPathCodeARM { |
| 274 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 275 | TypeCheckSlowPathARM(HInstruction* instruction, |
| 276 | Location class_to_check, |
| 277 | Location object_class, |
| 278 | uint32_t dex_pc) |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 279 | : instruction_(instruction), |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 280 | class_to_check_(class_to_check), |
| 281 | object_class_(object_class), |
| 282 | dex_pc_(dex_pc) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 283 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 284 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 285 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 286 | DCHECK(instruction_->IsCheckCast() |
| 287 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 288 | |
| 289 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 290 | __ Bind(GetEntryLabel()); |
| 291 | codegen->SaveLiveRegisters(locations); |
| 292 | |
| 293 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 294 | // move resolver. |
| 295 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 296 | codegen->EmitParallelMoves( |
| 297 | class_to_check_, |
| 298 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 299 | object_class_, |
| 300 | Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 301 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 302 | if (instruction_->IsInstanceOf()) { |
| 303 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_); |
| 304 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 305 | } else { |
| 306 | DCHECK(instruction_->IsCheckCast()); |
| 307 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_); |
| 308 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 309 | |
| 310 | codegen->RestoreLiveRegisters(locations); |
| 311 | __ b(GetExitLabel()); |
| 312 | } |
| 313 | |
| 314 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 315 | HInstruction* const instruction_; |
| 316 | const Location class_to_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 317 | const Location object_class_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 318 | uint32_t dex_pc_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 319 | |
| 320 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 321 | }; |
| 322 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 323 | #undef __ |
| 324 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 325 | #undef __ |
| 326 | #define __ reinterpret_cast<ArmAssembler*>(GetAssembler())-> |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 327 | |
| 328 | inline Condition ARMCondition(IfCondition cond) { |
| 329 | switch (cond) { |
| 330 | case kCondEQ: return EQ; |
| 331 | case kCondNE: return NE; |
| 332 | case kCondLT: return LT; |
| 333 | case kCondLE: return LE; |
| 334 | case kCondGT: return GT; |
| 335 | case kCondGE: return GE; |
| 336 | default: |
| 337 | LOG(FATAL) << "Unknown if condition"; |
| 338 | } |
| 339 | return EQ; // Unreachable. |
| 340 | } |
| 341 | |
| 342 | inline Condition ARMOppositeCondition(IfCondition cond) { |
| 343 | switch (cond) { |
| 344 | case kCondEQ: return NE; |
| 345 | case kCondNE: return EQ; |
| 346 | case kCondLT: return GE; |
| 347 | case kCondLE: return GT; |
| 348 | case kCondGT: return LE; |
| 349 | case kCondGE: return LT; |
| 350 | default: |
| 351 | LOG(FATAL) << "Unknown if condition"; |
| 352 | } |
| 353 | return EQ; // Unreachable. |
| 354 | } |
| 355 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 356 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 357 | stream << ArmManagedRegister::FromCoreRegister(Register(reg)); |
| 358 | } |
| 359 | |
| 360 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 361 | stream << ArmManagedRegister::FromSRegister(SRegister(reg)); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 362 | } |
| 363 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 364 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 365 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 366 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 367 | } |
| 368 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 369 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 370 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 371 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 372 | } |
| 373 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 374 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph) |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 375 | : CodeGenerator(graph, kNumberOfCoreRegisters, kNumberOfSRegisters, kNumberOfRegisterPairs), |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 376 | block_labels_(graph->GetArena(), 0), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 377 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 378 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 379 | move_resolver_(graph->GetArena(), this), |
| 380 | assembler_(true) {} |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 381 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 382 | size_t CodeGeneratorARM::FrameEntrySpillSize() const { |
| 383 | return kNumberOfPushedRegistersAtEntry * kArmWordSize; |
| 384 | } |
| 385 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 386 | Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 387 | switch (type) { |
| 388 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 389 | size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 390 | ArmManagedRegister pair = |
| 391 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 392 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); |
| 393 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); |
| 394 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 395 | blocked_core_registers_[pair.AsRegisterPairLow()] = true; |
| 396 | blocked_core_registers_[pair.AsRegisterPairHigh()] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 397 | UpdateBlockedPairRegisters(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 398 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | case Primitive::kPrimByte: |
| 402 | case Primitive::kPrimBoolean: |
| 403 | case Primitive::kPrimChar: |
| 404 | case Primitive::kPrimShort: |
| 405 | case Primitive::kPrimInt: |
| 406 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 407 | int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 408 | // Block all register pairs that contain `reg`. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 409 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 410 | ArmManagedRegister current = |
| 411 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 412 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 413 | blocked_register_pairs_[i] = true; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 414 | } |
| 415 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 416 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 417 | } |
| 418 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 419 | case Primitive::kPrimFloat: { |
| 420 | int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 421 | return Location::FpuRegisterLocation(reg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 422 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 423 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 424 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 3c03503 | 2014-10-28 10:46:40 +0000 | [diff] [blame] | 425 | int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters); |
| 426 | DCHECK_EQ(reg % 2, 0); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 427 | return Location::FpuRegisterPairLocation(reg, reg + 1); |
| 428 | } |
| 429 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 430 | case Primitive::kPrimVoid: |
| 431 | LOG(FATAL) << "Unreachable type " << type; |
| 432 | } |
| 433 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 434 | return Location(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 435 | } |
| 436 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 437 | void CodeGeneratorARM::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 438 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 439 | blocked_register_pairs_[R1_R2] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 440 | |
| 441 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 442 | blocked_core_registers_[SP] = true; |
| 443 | blocked_core_registers_[LR] = true; |
| 444 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 445 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 446 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 447 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 448 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 449 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 450 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 451 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 452 | // TODO: We currently don't use Quick's callee saved registers. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 453 | // We always save and restore R6 and R7 to make sure we can use three |
| 454 | // register pairs for long operations. |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 455 | blocked_core_registers_[R4] = true; |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 456 | blocked_core_registers_[R5] = true; |
| 457 | blocked_core_registers_[R8] = true; |
| 458 | blocked_core_registers_[R10] = true; |
| 459 | blocked_core_registers_[R11] = true; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 460 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 461 | blocked_fpu_registers_[S16] = true; |
| 462 | blocked_fpu_registers_[S17] = true; |
| 463 | blocked_fpu_registers_[S18] = true; |
| 464 | blocked_fpu_registers_[S19] = true; |
| 465 | blocked_fpu_registers_[S20] = true; |
| 466 | blocked_fpu_registers_[S21] = true; |
| 467 | blocked_fpu_registers_[S22] = true; |
| 468 | blocked_fpu_registers_[S23] = true; |
Nicolas Geoffray | 3c03503 | 2014-10-28 10:46:40 +0000 | [diff] [blame] | 469 | blocked_fpu_registers_[S24] = true; |
| 470 | blocked_fpu_registers_[S25] = true; |
| 471 | blocked_fpu_registers_[S26] = true; |
| 472 | blocked_fpu_registers_[S27] = true; |
| 473 | blocked_fpu_registers_[S28] = true; |
| 474 | blocked_fpu_registers_[S29] = true; |
| 475 | blocked_fpu_registers_[S30] = true; |
| 476 | blocked_fpu_registers_[S31] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 477 | |
| 478 | UpdateBlockedPairRegisters(); |
| 479 | } |
| 480 | |
| 481 | void CodeGeneratorARM::UpdateBlockedPairRegisters() const { |
| 482 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 483 | ArmManagedRegister current = |
| 484 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 485 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 486 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 487 | blocked_register_pairs_[i] = true; |
| 488 | } |
| 489 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 490 | } |
| 491 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 492 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
| 493 | : HGraphVisitor(graph), |
| 494 | assembler_(codegen->GetAssembler()), |
| 495 | codegen_(codegen) {} |
| 496 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 497 | void CodeGeneratorARM::GenerateFrameEntry() { |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 498 | bool skip_overflow_check = IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 499 | if (!skip_overflow_check) { |
| 500 | if (kExplicitStackOverflowCheck) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 501 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 502 | AddSlowPath(slow_path); |
| 503 | |
| 504 | __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value()); |
| 505 | __ cmp(SP, ShifterOperand(IP)); |
| 506 | __ b(slow_path->GetEntryLabel(), CC); |
| 507 | } else { |
| 508 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 509 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 510 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 511 | } |
| 512 | } |
| 513 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 514 | core_spill_mask_ |= (1 << LR | 1 << R6 | 1 << R7); |
| 515 | __ PushList(1 << LR | 1 << R6 | 1 << R7); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 516 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 517 | // The return PC has already been pushed on the stack. |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 518 | __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize)); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 519 | __ StoreToOffset(kStoreWord, R0, SP, 0); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 523 | __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 524 | __ PopList(1 << PC | 1 << R6 | 1 << R7); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 525 | } |
| 526 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 527 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
| 528 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 529 | } |
| 530 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 531 | Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const { |
| 532 | switch (load->GetType()) { |
| 533 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 534 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 535 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
| 536 | break; |
| 537 | |
| 538 | case Primitive::kPrimInt: |
| 539 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 540 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 541 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 542 | |
| 543 | case Primitive::kPrimBoolean: |
| 544 | case Primitive::kPrimByte: |
| 545 | case Primitive::kPrimChar: |
| 546 | case Primitive::kPrimShort: |
| 547 | case Primitive::kPrimVoid: |
| 548 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
| 549 | } |
| 550 | |
| 551 | LOG(FATAL) << "Unreachable"; |
| 552 | return Location(); |
| 553 | } |
| 554 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 555 | Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) { |
| 556 | switch (type) { |
| 557 | case Primitive::kPrimBoolean: |
| 558 | case Primitive::kPrimByte: |
| 559 | case Primitive::kPrimChar: |
| 560 | case Primitive::kPrimShort: |
| 561 | case Primitive::kPrimInt: |
| 562 | case Primitive::kPrimNot: { |
| 563 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 564 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 565 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 566 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 567 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 568 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 569 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 570 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 571 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 572 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 573 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 574 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 575 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 576 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 577 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 578 | ArmManagedRegister pair = ArmManagedRegister::FromRegisterPair( |
| 579 | calling_convention.GetRegisterPairAt(index)); |
| 580 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 581 | } else if (index + 1 == calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 582 | return Location::QuickParameter(index, stack_index); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 583 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 584 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | case Primitive::kPrimFloat: { |
| 589 | uint32_t stack_index = stack_index_++; |
| 590 | if (float_index_ % 2 == 0) { |
| 591 | float_index_ = std::max(double_index_, float_index_); |
| 592 | } |
| 593 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 594 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 595 | } else { |
| 596 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | case Primitive::kPrimDouble: { |
| 601 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 602 | uint32_t stack_index = stack_index_; |
| 603 | stack_index_ += 2; |
| 604 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 605 | uint32_t index = double_index_; |
| 606 | double_index_ += 2; |
| 607 | return Location::FpuRegisterPairLocation( |
| 608 | calling_convention.GetFpuRegisterAt(index), |
| 609 | calling_convention.GetFpuRegisterAt(index + 1)); |
| 610 | } else { |
| 611 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 612 | } |
| 613 | } |
| 614 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 615 | case Primitive::kPrimVoid: |
| 616 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 617 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 618 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 619 | return Location(); |
| 620 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 621 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 622 | Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) { |
| 623 | switch (type) { |
| 624 | case Primitive::kPrimBoolean: |
| 625 | case Primitive::kPrimByte: |
| 626 | case Primitive::kPrimChar: |
| 627 | case Primitive::kPrimShort: |
| 628 | case Primitive::kPrimInt: |
| 629 | case Primitive::kPrimNot: { |
| 630 | return Location::RegisterLocation(R0); |
| 631 | } |
| 632 | |
| 633 | case Primitive::kPrimFloat: { |
| 634 | return Location::FpuRegisterLocation(S0); |
| 635 | } |
| 636 | |
| 637 | case Primitive::kPrimLong: { |
| 638 | return Location::RegisterPairLocation(R0, R1); |
| 639 | } |
| 640 | |
| 641 | case Primitive::kPrimDouble: { |
| 642 | return Location::FpuRegisterPairLocation(S0, S1); |
| 643 | } |
| 644 | |
| 645 | case Primitive::kPrimVoid: |
| 646 | return Location(); |
| 647 | } |
| 648 | UNREACHABLE(); |
| 649 | return Location(); |
| 650 | } |
| 651 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 652 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 653 | if (source.Equals(destination)) { |
| 654 | return; |
| 655 | } |
| 656 | if (destination.IsRegister()) { |
| 657 | if (source.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 658 | __ Mov(destination.As<Register>(), source.As<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 659 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 660 | __ vmovrs(destination.As<Register>(), source.As<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 661 | } else { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 662 | __ LoadFromOffset(kLoadWord, destination.As<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 663 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 664 | } else if (destination.IsFpuRegister()) { |
| 665 | if (source.IsRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 666 | __ vmovsr(destination.As<SRegister>(), source.As<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 667 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 668 | __ vmovs(destination.As<SRegister>(), source.As<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 669 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 670 | __ LoadSFromOffset(destination.As<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 671 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 672 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 673 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 674 | if (source.IsRegister()) { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 675 | __ StoreToOffset(kStoreWord, source.As<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 676 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 677 | __ StoreSToOffset(source.As<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 678 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 679 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 680 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 681 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 682 | } |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 687 | if (source.Equals(destination)) { |
| 688 | return; |
| 689 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 690 | if (destination.IsRegisterPair()) { |
| 691 | if (source.IsRegisterPair()) { |
| 692 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 693 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 694 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 695 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 696 | } else if (source.IsQuickParameter()) { |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 697 | uint16_t register_index = source.GetQuickParameterRegisterIndex(); |
| 698 | uint16_t stack_index = source.GetQuickParameterStackIndex(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 699 | InvokeDexCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 700 | __ Mov(destination.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 701 | calling_convention.GetRegisterAt(register_index)); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 702 | __ LoadFromOffset(kLoadWord, destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 703 | SP, calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 704 | } else { |
| 705 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 706 | if (destination.AsRegisterPairLow<Register>() == R1) { |
| 707 | DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 708 | __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex()); |
| 709 | __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 710 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 711 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 712 | SP, source.GetStackIndex()); |
| 713 | } |
| 714 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 715 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 716 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 717 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 718 | SP, |
| 719 | source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 720 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 721 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 722 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 723 | } else if (destination.IsQuickParameter()) { |
| 724 | InvokeDexCallingConvention calling_convention; |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 725 | uint16_t register_index = destination.GetQuickParameterRegisterIndex(); |
| 726 | uint16_t stack_index = destination.GetQuickParameterStackIndex(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 727 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 728 | __ Mov(calling_convention.GetRegisterAt(register_index), |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 729 | source.AsRegisterPairLow<Register>()); |
| 730 | __ StoreToOffset(kStoreWord, source.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 731 | SP, calling_convention.GetStackOffsetOf(stack_index + 1)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 732 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 733 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 734 | } else { |
| 735 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 736 | __ LoadFromOffset( |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 737 | kLoadWord, calling_convention.GetRegisterAt(register_index), SP, source.GetStackIndex()); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 738 | __ LoadFromOffset(kLoadWord, R0, SP, source.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 739 | __ StoreToOffset(kStoreWord, R0, SP, calling_convention.GetStackOffsetOf(stack_index + 1)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 740 | } |
| 741 | } else { |
| 742 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 743 | if (source.IsRegisterPair()) { |
| 744 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 745 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 746 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 747 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 748 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 749 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 750 | SP, destination.GetStackIndex()); |
| 751 | } |
| 752 | } else if (source.IsQuickParameter()) { |
| 753 | InvokeDexCallingConvention calling_convention; |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 754 | uint16_t register_index = source.GetQuickParameterRegisterIndex(); |
| 755 | uint16_t stack_index = source.GetQuickParameterStackIndex(); |
| 756 | __ StoreToOffset(kStoreWord, calling_convention.GetRegisterAt(register_index), |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 757 | SP, destination.GetStackIndex()); |
| 758 | __ LoadFromOffset(kLoadWord, R0, |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 759 | SP, calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize()); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 760 | __ StoreToOffset(kStoreWord, R0, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 761 | } else if (source.IsFpuRegisterPair()) { |
| 762 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 763 | SP, |
| 764 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 765 | } else { |
| 766 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 767 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 768 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 769 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize)); |
| 770 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 771 | } |
| 772 | } |
| 773 | } |
| 774 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 775 | void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 776 | LocationSummary* locations = instruction->GetLocations(); |
| 777 | if (locations != nullptr && locations->Out().Equals(location)) { |
| 778 | return; |
| 779 | } |
| 780 | |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 781 | if (locations != nullptr && locations->Out().IsConstant()) { |
| 782 | HConstant* const_to_move = locations->Out().GetConstant(); |
| 783 | if (const_to_move->IsIntConstant()) { |
| 784 | int32_t value = const_to_move->AsIntConstant()->GetValue(); |
| 785 | if (location.IsRegister()) { |
| 786 | __ LoadImmediate(location.As<Register>(), value); |
| 787 | } else { |
| 788 | DCHECK(location.IsStackSlot()); |
| 789 | __ LoadImmediate(IP, value); |
| 790 | __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); |
| 791 | } |
| 792 | } else if (const_to_move->IsLongConstant()) { |
| 793 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 794 | if (location.IsRegisterPair()) { |
| 795 | __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 796 | __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value)); |
| 797 | } else { |
| 798 | DCHECK(location.IsDoubleStackSlot()); |
| 799 | __ LoadImmediate(IP, Low32Bits(value)); |
| 800 | __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); |
| 801 | __ LoadImmediate(IP, High32Bits(value)); |
| 802 | __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize)); |
| 803 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 804 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 805 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 806 | uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
| 807 | switch (instruction->GetType()) { |
| 808 | case Primitive::kPrimBoolean: |
| 809 | case Primitive::kPrimByte: |
| 810 | case Primitive::kPrimChar: |
| 811 | case Primitive::kPrimShort: |
| 812 | case Primitive::kPrimInt: |
| 813 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 814 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 815 | Move32(location, Location::StackSlot(stack_slot)); |
| 816 | break; |
| 817 | |
| 818 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 819 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 820 | Move64(location, Location::DoubleStackSlot(stack_slot)); |
| 821 | break; |
| 822 | |
| 823 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 824 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 825 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 826 | } else if (instruction->IsTemporary()) { |
| 827 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 828 | if (temp_location.IsStackSlot()) { |
| 829 | Move32(location, temp_location); |
| 830 | } else { |
| 831 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 832 | Move64(location, temp_location); |
| 833 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 834 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 835 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 836 | switch (instruction->GetType()) { |
| 837 | case Primitive::kPrimBoolean: |
| 838 | case Primitive::kPrimByte: |
| 839 | case Primitive::kPrimChar: |
| 840 | case Primitive::kPrimShort: |
| 841 | case Primitive::kPrimNot: |
| 842 | case Primitive::kPrimInt: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 843 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 844 | Move32(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 845 | break; |
| 846 | |
| 847 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 848 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 849 | Move64(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 850 | break; |
| 851 | |
| 852 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 853 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 854 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 855 | } |
| 856 | } |
| 857 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 858 | void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset, |
| 859 | HInstruction* instruction, |
| 860 | uint32_t dex_pc) { |
| 861 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 862 | __ blx(LR); |
| 863 | RecordPcInfo(instruction, dex_pc); |
| 864 | DCHECK(instruction->IsSuspendCheck() |
| 865 | || instruction->IsBoundsCheck() |
| 866 | || instruction->IsNullCheck() |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 867 | || instruction->IsDivZeroCheck() |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 868 | || !IsLeafMethod()); |
| 869 | } |
| 870 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 871 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 872 | got->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 873 | } |
| 874 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 875 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 876 | HBasicBlock* successor = got->GetSuccessor(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 877 | DCHECK(!successor->IsExitBlock()); |
| 878 | |
| 879 | HBasicBlock* block = got->GetBlock(); |
| 880 | HInstruction* previous = got->GetPrevious(); |
| 881 | |
| 882 | HLoopInformation* info = block->GetLoopInformation(); |
| 883 | if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) { |
| 884 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 885 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 886 | return; |
| 887 | } |
| 888 | |
| 889 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 890 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 891 | } |
| 892 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 893 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 894 | } |
| 895 | } |
| 896 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 897 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 898 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 899 | } |
| 900 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 901 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 902 | UNUSED(exit); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 903 | if (kIsDebugBuild) { |
| 904 | __ Comment("Unreachable"); |
| 905 | __ bkpt(0); |
| 906 | } |
| 907 | } |
| 908 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 909 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 910 | LocationSummary* locations = |
| 911 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 912 | HInstruction* cond = if_instr->InputAt(0); |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 913 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 914 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 915 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 916 | } |
| 917 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 918 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 919 | HInstruction* cond = if_instr->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 920 | if (cond->IsIntConstant()) { |
| 921 | // Constant condition, statically compared against 1. |
| 922 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 923 | if (cond_value == 1) { |
| 924 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 925 | if_instr->IfTrueSuccessor())) { |
| 926 | __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 927 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 928 | return; |
| 929 | } else { |
| 930 | DCHECK_EQ(cond_value, 0); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 931 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 932 | } else { |
| 933 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 934 | // Condition has been materialized, compare the output to 0 |
| 935 | DCHECK(if_instr->GetLocations()->InAt(0).IsRegister()); |
| 936 | __ cmp(if_instr->GetLocations()->InAt(0).As<Register>(), |
| 937 | ShifterOperand(0)); |
| 938 | __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE); |
| 939 | } else { |
| 940 | // Condition has not been materialized, use its inputs as the |
| 941 | // comparison and its condition as the branch condition. |
| 942 | LocationSummary* locations = cond->GetLocations(); |
| 943 | if (locations->InAt(1).IsRegister()) { |
| 944 | __ cmp(locations->InAt(0).As<Register>(), |
| 945 | ShifterOperand(locations->InAt(1).As<Register>())); |
| 946 | } else { |
| 947 | DCHECK(locations->InAt(1).IsConstant()); |
| 948 | int32_t value = |
| 949 | locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 950 | ShifterOperand operand; |
| 951 | if (ShifterOperand::CanHoldArm(value, &operand)) { |
| 952 | __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value)); |
| 953 | } else { |
| 954 | Register temp = IP; |
| 955 | __ LoadImmediate(temp, value); |
| 956 | __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp)); |
| 957 | } |
| 958 | } |
| 959 | __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), |
| 960 | ARMCondition(cond->AsCondition()->GetCondition())); |
| 961 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 962 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 963 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 964 | if_instr->IfFalseSuccessor())) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 965 | __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 966 | } |
| 967 | } |
| 968 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 969 | |
| 970 | void LocationsBuilderARM::VisitCondition(HCondition* comp) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 971 | LocationSummary* locations = |
| 972 | new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 973 | locations->SetInAt(0, Location::RequiresRegister()); |
| 974 | locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1))); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 975 | if (comp->NeedsMaterialization()) { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 976 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 977 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 978 | } |
| 979 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 980 | void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 981 | if (!comp->NeedsMaterialization()) return; |
| 982 | |
| 983 | LocationSummary* locations = comp->GetLocations(); |
| 984 | if (locations->InAt(1).IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 985 | __ cmp(locations->InAt(0).As<Register>(), |
| 986 | ShifterOperand(locations->InAt(1).As<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 987 | } else { |
| 988 | DCHECK(locations->InAt(1).IsConstant()); |
| 989 | int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 990 | ShifterOperand operand; |
| 991 | if (ShifterOperand::CanHoldArm(value, &operand)) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 992 | __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 993 | } else { |
| 994 | Register temp = IP; |
| 995 | __ LoadImmediate(temp, value); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 996 | __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 997 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 998 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 999 | __ it(ARMCondition(comp->GetCondition()), kItElse); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1000 | __ mov(locations->Out().As<Register>(), ShifterOperand(1), |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1001 | ARMCondition(comp->GetCondition())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1002 | __ mov(locations->Out().As<Register>(), ShifterOperand(0), |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1003 | ARMOppositeCondition(comp->GetCondition())); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
| 1007 | VisitCondition(comp); |
| 1008 | } |
| 1009 | |
| 1010 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
| 1011 | VisitCondition(comp); |
| 1012 | } |
| 1013 | |
| 1014 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
| 1015 | VisitCondition(comp); |
| 1016 | } |
| 1017 | |
| 1018 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
| 1019 | VisitCondition(comp); |
| 1020 | } |
| 1021 | |
| 1022 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
| 1023 | VisitCondition(comp); |
| 1024 | } |
| 1025 | |
| 1026 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
| 1027 | VisitCondition(comp); |
| 1028 | } |
| 1029 | |
| 1030 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1031 | VisitCondition(comp); |
| 1032 | } |
| 1033 | |
| 1034 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1035 | VisitCondition(comp); |
| 1036 | } |
| 1037 | |
| 1038 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
| 1039 | VisitCondition(comp); |
| 1040 | } |
| 1041 | |
| 1042 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
| 1043 | VisitCondition(comp); |
| 1044 | } |
| 1045 | |
| 1046 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1047 | VisitCondition(comp); |
| 1048 | } |
| 1049 | |
| 1050 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1051 | VisitCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | void LocationsBuilderARM::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1055 | local->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1056 | } |
| 1057 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1058 | void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) { |
| 1059 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1060 | } |
| 1061 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1062 | void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1063 | load->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1064 | } |
| 1065 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1066 | void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1067 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1068 | UNUSED(load); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1072 | LocationSummary* locations = |
| 1073 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1074 | switch (store->InputAt(1)->GetType()) { |
| 1075 | case Primitive::kPrimBoolean: |
| 1076 | case Primitive::kPrimByte: |
| 1077 | case Primitive::kPrimChar: |
| 1078 | case Primitive::kPrimShort: |
| 1079 | case Primitive::kPrimInt: |
| 1080 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1081 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1082 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1083 | break; |
| 1084 | |
| 1085 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1086 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1087 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1088 | break; |
| 1089 | |
| 1090 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1091 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1092 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1095 | void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1096 | UNUSED(store); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1100 | LocationSummary* locations = |
| 1101 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1102 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1103 | } |
| 1104 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1105 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1106 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1107 | UNUSED(constant); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1108 | } |
| 1109 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1110 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1111 | LocationSummary* locations = |
| 1112 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1113 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) { |
| 1117 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1118 | UNUSED(constant); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1119 | } |
| 1120 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1121 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 1122 | LocationSummary* locations = |
| 1123 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1124 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1125 | } |
| 1126 | |
| 1127 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) { |
| 1128 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1129 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1133 | LocationSummary* locations = |
| 1134 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1135 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1136 | } |
| 1137 | |
| 1138 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1139 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1140 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1141 | } |
| 1142 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1143 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1144 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1145 | } |
| 1146 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1147 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1148 | UNUSED(ret); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1149 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1150 | } |
| 1151 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1152 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1153 | LocationSummary* locations = |
| 1154 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1155 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1158 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1159 | UNUSED(ret); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1160 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1161 | } |
| 1162 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1163 | void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1164 | HandleInvoke(invoke); |
| 1165 | } |
| 1166 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1167 | void CodeGeneratorARM::LoadCurrentMethod(Register reg) { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1168 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1172 | Register temp = invoke->GetLocations()->GetTemp(0).As<Register>(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1173 | |
| 1174 | // TODO: Implement all kinds of calls: |
| 1175 | // 1) boot -> boot |
| 1176 | // 2) app -> boot |
| 1177 | // 3) app -> app |
| 1178 | // |
| 1179 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
| 1180 | |
| 1181 | // temp = method; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1182 | codegen_->LoadCurrentMethod(temp); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1183 | // temp = temp->dex_cache_resolved_methods_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1184 | __ LoadFromOffset( |
| 1185 | kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1186 | // temp = temp[index_in_cache] |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1187 | __ LoadFromOffset( |
| 1188 | kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache())); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1189 | // LR = temp[offset_of_quick_compiled_code] |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1190 | __ LoadFromOffset(kLoadWord, LR, temp, |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 1191 | mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1192 | kArmWordSize).Int32Value()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1193 | // LR() |
| 1194 | __ blx(LR); |
| 1195 | |
| 1196 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1197 | DCHECK(!codegen_->IsLeafMethod()); |
| 1198 | } |
| 1199 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1200 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1201 | LocationSummary* locations = |
| 1202 | new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1203 | locations->AddTemp(Location::RegisterLocation(R0)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1204 | |
| 1205 | InvokeDexCallingConventionVisitor calling_convention_visitor; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1206 | for (size_t i = 0; i < invoke->InputCount(); i++) { |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1207 | HInstruction* input = invoke->InputAt(i); |
| 1208 | locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType())); |
| 1209 | } |
| 1210 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1211 | locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType())); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1212 | } |
| 1213 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1214 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 1215 | HandleInvoke(invoke); |
| 1216 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1217 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1218 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1219 | Register temp = invoke->GetLocations()->GetTemp(0).As<Register>(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1220 | uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() + |
| 1221 | invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry); |
| 1222 | LocationSummary* locations = invoke->GetLocations(); |
| 1223 | Location receiver = locations->InAt(0); |
| 1224 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1225 | // temp = object->GetClass(); |
| 1226 | if (receiver.IsStackSlot()) { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1227 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 1228 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1229 | } else { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1230 | __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1231 | } |
| 1232 | // temp = temp->GetMethodAt(method_offset); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 1233 | uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1234 | kArmWordSize).Int32Value(); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1235 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1236 | // LR = temp->GetEntryPoint(); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1237 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1238 | // LR(); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1239 | __ blx(LR); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1240 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1241 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1244 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1245 | HandleInvoke(invoke); |
| 1246 | // Add the hidden argument. |
| 1247 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 1248 | } |
| 1249 | |
| 1250 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1251 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 1252 | Register temp = invoke->GetLocations()->GetTemp(0).As<Register>(); |
| 1253 | uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() + |
| 1254 | (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry); |
| 1255 | LocationSummary* locations = invoke->GetLocations(); |
| 1256 | Location receiver = locations->InAt(0); |
| 1257 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1258 | |
| 1259 | // Set the hidden argument. |
| 1260 | __ LoadImmediate(invoke->GetLocations()->GetTemp(1).As<Register>(), invoke->GetDexMethodIndex()); |
| 1261 | |
| 1262 | // temp = object->GetClass(); |
| 1263 | if (receiver.IsStackSlot()) { |
| 1264 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 1265 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 1266 | } else { |
| 1267 | __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset); |
| 1268 | } |
| 1269 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 1270 | uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1271 | kArmWordSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1272 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 1273 | // LR = temp->GetEntryPoint(); |
| 1274 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 1275 | // LR(); |
| 1276 | __ blx(LR); |
| 1277 | DCHECK(!codegen_->IsLeafMethod()); |
| 1278 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1279 | } |
| 1280 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1281 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 1282 | LocationSummary* locations = |
| 1283 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1284 | switch (neg->GetResultType()) { |
| 1285 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1286 | case Primitive::kPrimLong: { |
| 1287 | bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1288 | locations->SetInAt(0, Location::RequiresRegister()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1289 | locations->SetOut(Location::RequiresRegister(), output_overlaps); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1290 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1291 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1292 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1293 | case Primitive::kPrimFloat: |
| 1294 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1295 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1296 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1297 | break; |
| 1298 | |
| 1299 | default: |
| 1300 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 1305 | LocationSummary* locations = neg->GetLocations(); |
| 1306 | Location out = locations->Out(); |
| 1307 | Location in = locations->InAt(0); |
| 1308 | switch (neg->GetResultType()) { |
| 1309 | case Primitive::kPrimInt: |
| 1310 | DCHECK(in.IsRegister()); |
Roland Levillain | b762d2e | 2014-10-22 10:11:06 +0100 | [diff] [blame] | 1311 | __ rsb(out.As<Register>(), in.As<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1312 | break; |
| 1313 | |
| 1314 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1315 | DCHECK(in.IsRegisterPair()); |
| 1316 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 1317 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 1318 | in.AsRegisterPairLow<Register>(), |
| 1319 | ShifterOperand(0)); |
| 1320 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 1321 | // instruction here, as it does not exist in the Thumb-2 |
| 1322 | // instruction set. We use the following approach |
| 1323 | // using SBC and SUB instead. |
| 1324 | // |
| 1325 | // out.hi = -C |
| 1326 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 1327 | out.AsRegisterPairHigh<Register>(), |
| 1328 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 1329 | // out.hi = out.hi - in.hi |
| 1330 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 1331 | out.AsRegisterPairHigh<Register>(), |
| 1332 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 1333 | break; |
| 1334 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1335 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1336 | DCHECK(in.IsFpuRegister()); |
| 1337 | __ vnegs(out.As<SRegister>(), in.As<SRegister>()); |
| 1338 | break; |
| 1339 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1340 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1341 | DCHECK(in.IsFpuRegisterPair()); |
| 1342 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1343 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1344 | break; |
| 1345 | |
| 1346 | default: |
| 1347 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1348 | } |
| 1349 | } |
| 1350 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1351 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 1352 | LocationSummary* locations = |
| 1353 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 1354 | Primitive::Type result_type = conversion->GetResultType(); |
| 1355 | Primitive::Type input_type = conversion->GetInputType(); |
| 1356 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1357 | case Primitive::kPrimByte: |
| 1358 | switch (input_type) { |
| 1359 | case Primitive::kPrimShort: |
| 1360 | case Primitive::kPrimInt: |
| 1361 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1362 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1363 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1364 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1365 | break; |
| 1366 | |
| 1367 | default: |
| 1368 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1369 | << " to " << result_type; |
| 1370 | } |
| 1371 | break; |
| 1372 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1373 | case Primitive::kPrimShort: |
| 1374 | switch (input_type) { |
| 1375 | case Primitive::kPrimByte: |
| 1376 | case Primitive::kPrimInt: |
| 1377 | case Primitive::kPrimChar: |
| 1378 | // Processing a Dex `int-to-short' instruction. |
| 1379 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1380 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1381 | break; |
| 1382 | |
| 1383 | default: |
| 1384 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1385 | << " to " << result_type; |
| 1386 | } |
| 1387 | break; |
| 1388 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1389 | case Primitive::kPrimInt: |
| 1390 | switch (input_type) { |
| 1391 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1392 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1393 | locations->SetInAt(0, Location::Any()); |
| 1394 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1395 | break; |
| 1396 | |
| 1397 | case Primitive::kPrimFloat: |
| 1398 | case Primitive::kPrimDouble: |
| 1399 | LOG(FATAL) << "Type conversion from " << input_type |
| 1400 | << " to " << result_type << " not yet implemented"; |
| 1401 | break; |
| 1402 | |
| 1403 | default: |
| 1404 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1405 | << " to " << result_type; |
| 1406 | } |
| 1407 | break; |
| 1408 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1409 | case Primitive::kPrimLong: |
| 1410 | switch (input_type) { |
| 1411 | case Primitive::kPrimByte: |
| 1412 | case Primitive::kPrimShort: |
| 1413 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1414 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1415 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1416 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1417 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1418 | break; |
| 1419 | |
| 1420 | case Primitive::kPrimFloat: |
| 1421 | case Primitive::kPrimDouble: |
| 1422 | LOG(FATAL) << "Type conversion from " << input_type << " to " |
| 1423 | << result_type << " not yet implemented"; |
| 1424 | break; |
| 1425 | |
| 1426 | default: |
| 1427 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1428 | << " to " << result_type; |
| 1429 | } |
| 1430 | break; |
| 1431 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1432 | case Primitive::kPrimChar: |
| 1433 | switch (input_type) { |
| 1434 | case Primitive::kPrimByte: |
| 1435 | case Primitive::kPrimShort: |
| 1436 | case Primitive::kPrimInt: |
| 1437 | case Primitive::kPrimChar: |
| 1438 | // Processing a Dex `int-to-char' instruction. |
| 1439 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1440 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1441 | break; |
| 1442 | |
| 1443 | default: |
| 1444 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1445 | << " to " << result_type; |
| 1446 | } |
| 1447 | break; |
| 1448 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1449 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1450 | switch (input_type) { |
| 1451 | case Primitive::kPrimByte: |
| 1452 | case Primitive::kPrimShort: |
| 1453 | case Primitive::kPrimInt: |
| 1454 | case Primitive::kPrimChar: |
| 1455 | // Processing a Dex `int-to-float' instruction. |
| 1456 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1457 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1458 | break; |
| 1459 | |
| 1460 | case Primitive::kPrimLong: |
| 1461 | case Primitive::kPrimDouble: |
| 1462 | LOG(FATAL) << "Type conversion from " << input_type |
| 1463 | << " to " << result_type << " not yet implemented"; |
| 1464 | break; |
| 1465 | |
| 1466 | default: |
| 1467 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1468 | << " to " << result_type; |
| 1469 | }; |
| 1470 | break; |
| 1471 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1472 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1473 | switch (input_type) { |
| 1474 | case Primitive::kPrimByte: |
| 1475 | case Primitive::kPrimShort: |
| 1476 | case Primitive::kPrimInt: |
| 1477 | case Primitive::kPrimChar: |
| 1478 | // Processing a Dex `int-to-double' instruction. |
| 1479 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1480 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1481 | break; |
| 1482 | |
| 1483 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame^] | 1484 | // Processing a Dex `long-to-double' instruction. |
| 1485 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1486 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1487 | locations->AddTemp(Location::RequiresRegister()); |
| 1488 | locations->AddTemp(Location::RequiresRegister()); |
| 1489 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1490 | break; |
| 1491 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1492 | case Primitive::kPrimFloat: |
| 1493 | LOG(FATAL) << "Type conversion from " << input_type |
| 1494 | << " to " << result_type << " not yet implemented"; |
| 1495 | break; |
| 1496 | |
| 1497 | default: |
| 1498 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1499 | << " to " << result_type; |
| 1500 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1501 | break; |
| 1502 | |
| 1503 | default: |
| 1504 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1505 | << " to " << result_type; |
| 1506 | } |
| 1507 | } |
| 1508 | |
| 1509 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 1510 | LocationSummary* locations = conversion->GetLocations(); |
| 1511 | Location out = locations->Out(); |
| 1512 | Location in = locations->InAt(0); |
| 1513 | Primitive::Type result_type = conversion->GetResultType(); |
| 1514 | Primitive::Type input_type = conversion->GetInputType(); |
| 1515 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1516 | case Primitive::kPrimByte: |
| 1517 | switch (input_type) { |
| 1518 | case Primitive::kPrimShort: |
| 1519 | case Primitive::kPrimInt: |
| 1520 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1521 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1522 | __ sbfx(out.As<Register>(), in.As<Register>(), 0, 8); |
| 1523 | break; |
| 1524 | |
| 1525 | default: |
| 1526 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1527 | << " to " << result_type; |
| 1528 | } |
| 1529 | break; |
| 1530 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1531 | case Primitive::kPrimShort: |
| 1532 | switch (input_type) { |
| 1533 | case Primitive::kPrimByte: |
| 1534 | case Primitive::kPrimInt: |
| 1535 | case Primitive::kPrimChar: |
| 1536 | // Processing a Dex `int-to-short' instruction. |
| 1537 | __ sbfx(out.As<Register>(), in.As<Register>(), 0, 16); |
| 1538 | break; |
| 1539 | |
| 1540 | default: |
| 1541 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1542 | << " to " << result_type; |
| 1543 | } |
| 1544 | break; |
| 1545 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1546 | case Primitive::kPrimInt: |
| 1547 | switch (input_type) { |
| 1548 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1549 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1550 | DCHECK(out.IsRegister()); |
| 1551 | if (in.IsRegisterPair()) { |
| 1552 | __ Mov(out.As<Register>(), in.AsRegisterPairLow<Register>()); |
| 1553 | } else if (in.IsDoubleStackSlot()) { |
| 1554 | __ LoadFromOffset(kLoadWord, out.As<Register>(), SP, in.GetStackIndex()); |
| 1555 | } else { |
| 1556 | DCHECK(in.IsConstant()); |
| 1557 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 1558 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 1559 | __ LoadImmediate(out.As<Register>(), static_cast<int32_t>(value)); |
| 1560 | } |
| 1561 | break; |
| 1562 | |
| 1563 | case Primitive::kPrimFloat: |
| 1564 | case Primitive::kPrimDouble: |
| 1565 | LOG(FATAL) << "Type conversion from " << input_type |
| 1566 | << " to " << result_type << " not yet implemented"; |
| 1567 | break; |
| 1568 | |
| 1569 | default: |
| 1570 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1571 | << " to " << result_type; |
| 1572 | } |
| 1573 | break; |
| 1574 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1575 | case Primitive::kPrimLong: |
| 1576 | switch (input_type) { |
| 1577 | case Primitive::kPrimByte: |
| 1578 | case Primitive::kPrimShort: |
| 1579 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1580 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1581 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1582 | DCHECK(out.IsRegisterPair()); |
| 1583 | DCHECK(in.IsRegister()); |
| 1584 | __ Mov(out.AsRegisterPairLow<Register>(), in.As<Register>()); |
| 1585 | // Sign extension. |
| 1586 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 1587 | out.AsRegisterPairLow<Register>(), |
| 1588 | 31); |
| 1589 | break; |
| 1590 | |
| 1591 | case Primitive::kPrimFloat: |
| 1592 | case Primitive::kPrimDouble: |
| 1593 | LOG(FATAL) << "Type conversion from " << input_type << " to " |
| 1594 | << result_type << " not yet implemented"; |
| 1595 | break; |
| 1596 | |
| 1597 | default: |
| 1598 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1599 | << " to " << result_type; |
| 1600 | } |
| 1601 | break; |
| 1602 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1603 | case Primitive::kPrimChar: |
| 1604 | switch (input_type) { |
| 1605 | case Primitive::kPrimByte: |
| 1606 | case Primitive::kPrimShort: |
| 1607 | case Primitive::kPrimInt: |
| 1608 | case Primitive::kPrimChar: |
| 1609 | // Processing a Dex `int-to-char' instruction. |
| 1610 | __ ubfx(out.As<Register>(), in.As<Register>(), 0, 16); |
| 1611 | break; |
| 1612 | |
| 1613 | default: |
| 1614 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1615 | << " to " << result_type; |
| 1616 | } |
| 1617 | break; |
| 1618 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1619 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1620 | switch (input_type) { |
| 1621 | case Primitive::kPrimByte: |
| 1622 | case Primitive::kPrimShort: |
| 1623 | case Primitive::kPrimInt: |
| 1624 | case Primitive::kPrimChar: { |
| 1625 | // Processing a Dex `int-to-float' instruction. |
| 1626 | __ vmovsr(out.As<SRegister>(), in.As<Register>()); |
| 1627 | __ vcvtsi(out.As<SRegister>(), out.As<SRegister>()); |
| 1628 | break; |
| 1629 | } |
| 1630 | |
| 1631 | case Primitive::kPrimLong: |
| 1632 | case Primitive::kPrimDouble: |
| 1633 | LOG(FATAL) << "Type conversion from " << input_type |
| 1634 | << " to " << result_type << " not yet implemented"; |
| 1635 | break; |
| 1636 | |
| 1637 | default: |
| 1638 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1639 | << " to " << result_type; |
| 1640 | }; |
| 1641 | break; |
| 1642 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1643 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1644 | switch (input_type) { |
| 1645 | case Primitive::kPrimByte: |
| 1646 | case Primitive::kPrimShort: |
| 1647 | case Primitive::kPrimInt: |
| 1648 | case Primitive::kPrimChar: { |
| 1649 | // Processing a Dex `int-to-double' instruction. |
| 1650 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.As<Register>()); |
| 1651 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1652 | out.AsFpuRegisterPairLow<SRegister>()); |
| 1653 | break; |
| 1654 | } |
| 1655 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame^] | 1656 | case Primitive::kPrimLong: { |
| 1657 | // Processing a Dex `long-to-double' instruction. |
| 1658 | Register low = in.AsRegisterPairLow<Register>(); |
| 1659 | Register high = in.AsRegisterPairHigh<Register>(); |
| 1660 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 1661 | DRegister out_d = FromLowSToD(out_s); |
| 1662 | Register constant_low = locations->GetTemp(0).As<Register>(); |
| 1663 | Register constant_high = locations->GetTemp(1).As<Register>(); |
| 1664 | SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>(); |
| 1665 | DRegister temp_d = FromLowSToD(temp_s); |
| 1666 | |
| 1667 | // Binary encoding of 2^32 for type double. |
| 1668 | const uint64_t c = UINT64_C(0x41F0000000000000); |
| 1669 | |
| 1670 | // out_d = int-to-double(high) |
| 1671 | __ vmovsr(out_s, high); |
| 1672 | __ vcvtdi(out_d, out_s); |
| 1673 | // Using vmovd to load the `c` constant as an immediate |
| 1674 | // value into `temp_d` does not work, as this instruction |
| 1675 | // only transfers 8 significant bits of its immediate |
| 1676 | // operand. Instead, use two 32-bit core registers to |
| 1677 | // load `c` into `temp_d`. |
| 1678 | __ LoadImmediate(constant_low, Low32Bits(c)); |
| 1679 | __ LoadImmediate(constant_high, High32Bits(c)); |
| 1680 | __ vmovdrr(temp_d, constant_low, constant_high); |
| 1681 | // out_d = out_d * 2^32 |
| 1682 | __ vmuld(out_d, out_d, temp_d); |
| 1683 | // temp_d = unsigned-to-double(low) |
| 1684 | __ vmovsr(temp_s, low); |
| 1685 | __ vcvtdu(temp_d, temp_s); |
| 1686 | // out_d = out_d + temp_d |
| 1687 | __ vaddd(out_d, out_d, temp_d); |
| 1688 | break; |
| 1689 | } |
| 1690 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1691 | case Primitive::kPrimFloat: |
| 1692 | LOG(FATAL) << "Type conversion from " << input_type |
| 1693 | << " to " << result_type << " not yet implemented"; |
| 1694 | break; |
| 1695 | |
| 1696 | default: |
| 1697 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1698 | << " to " << result_type; |
| 1699 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1700 | break; |
| 1701 | |
| 1702 | default: |
| 1703 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1704 | << " to " << result_type; |
| 1705 | } |
| 1706 | } |
| 1707 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1708 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1709 | LocationSummary* locations = |
| 1710 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1711 | switch (add->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1712 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1713 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1714 | bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong); |
| 1715 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1716 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 1717 | locations->SetOut(Location::RequiresRegister(), output_overlaps); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1718 | break; |
| 1719 | } |
| 1720 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1721 | case Primitive::kPrimFloat: |
| 1722 | case Primitive::kPrimDouble: { |
| 1723 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1724 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1725 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1726 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1727 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1728 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1729 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1730 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1731 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1732 | } |
| 1733 | |
| 1734 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 1735 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1736 | Location out = locations->Out(); |
| 1737 | Location first = locations->InAt(0); |
| 1738 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1739 | switch (add->GetResultType()) { |
| 1740 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1741 | if (second.IsRegister()) { |
| 1742 | __ add(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1743 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1744 | __ AddConstant(out.As<Register>(), |
| 1745 | first.As<Register>(), |
| 1746 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1747 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1748 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1749 | |
| 1750 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1751 | __ adds(out.AsRegisterPairLow<Register>(), |
| 1752 | first.AsRegisterPairLow<Register>(), |
| 1753 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 1754 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 1755 | first.AsRegisterPairHigh<Register>(), |
| 1756 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1757 | break; |
| 1758 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1759 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1760 | __ vadds(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1761 | break; |
| 1762 | |
| 1763 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1764 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1765 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 1766 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1767 | break; |
| 1768 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1769 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1770 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1771 | } |
| 1772 | } |
| 1773 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1774 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1775 | LocationSummary* locations = |
| 1776 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1777 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1778 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1779 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1780 | bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong); |
| 1781 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1782 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
| 1783 | locations->SetOut(Location::RequiresRegister(), output_overlaps); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1784 | break; |
| 1785 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1786 | case Primitive::kPrimFloat: |
| 1787 | case Primitive::kPrimDouble: { |
| 1788 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1789 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1790 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1791 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1792 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1793 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1794 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1795 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 1799 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1800 | Location out = locations->Out(); |
| 1801 | Location first = locations->InAt(0); |
| 1802 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1803 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1804 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1805 | if (second.IsRegister()) { |
| 1806 | __ sub(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1807 | } else { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1808 | __ AddConstant(out.As<Register>(), |
| 1809 | first.As<Register>(), |
| 1810 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1811 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1812 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1813 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1814 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1815 | case Primitive::kPrimLong: { |
| 1816 | __ subs(out.AsRegisterPairLow<Register>(), |
| 1817 | first.AsRegisterPairLow<Register>(), |
| 1818 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 1819 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 1820 | first.AsRegisterPairHigh<Register>(), |
| 1821 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1822 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1823 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1824 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1825 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1826 | __ vsubs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1827 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1828 | } |
| 1829 | |
| 1830 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1831 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1832 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 1833 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1834 | break; |
| 1835 | } |
| 1836 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1837 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1838 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1839 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1840 | } |
| 1841 | } |
| 1842 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1843 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 1844 | LocationSummary* locations = |
| 1845 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 1846 | switch (mul->GetResultType()) { |
| 1847 | case Primitive::kPrimInt: |
| 1848 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1849 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1850 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1851 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1852 | break; |
| 1853 | } |
| 1854 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1855 | case Primitive::kPrimFloat: |
| 1856 | case Primitive::kPrimDouble: { |
| 1857 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1858 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1859 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1860 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1861 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1862 | |
| 1863 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1864 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1865 | } |
| 1866 | } |
| 1867 | |
| 1868 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 1869 | LocationSummary* locations = mul->GetLocations(); |
| 1870 | Location out = locations->Out(); |
| 1871 | Location first = locations->InAt(0); |
| 1872 | Location second = locations->InAt(1); |
| 1873 | switch (mul->GetResultType()) { |
| 1874 | case Primitive::kPrimInt: { |
| 1875 | __ mul(out.As<Register>(), first.As<Register>(), second.As<Register>()); |
| 1876 | break; |
| 1877 | } |
| 1878 | case Primitive::kPrimLong: { |
| 1879 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 1880 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 1881 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 1882 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 1883 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 1884 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 1885 | |
| 1886 | // Extra checks to protect caused by the existence of R1_R2. |
| 1887 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 1888 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 1889 | DCHECK_NE(out_hi, in1_lo); |
| 1890 | DCHECK_NE(out_hi, in2_lo); |
| 1891 | |
| 1892 | // input: in1 - 64 bits, in2 - 64 bits |
| 1893 | // output: out |
| 1894 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 1895 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 1896 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 1897 | |
| 1898 | // IP <- in1.lo * in2.hi |
| 1899 | __ mul(IP, in1_lo, in2_hi); |
| 1900 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 1901 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 1902 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 1903 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 1904 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 1905 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 1906 | break; |
| 1907 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1908 | |
| 1909 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1910 | __ vmuls(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1911 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1912 | } |
| 1913 | |
| 1914 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1915 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1916 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 1917 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1918 | break; |
| 1919 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1920 | |
| 1921 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1922 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1923 | } |
| 1924 | } |
| 1925 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1926 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1927 | LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong |
| 1928 | ? LocationSummary::kCall |
| 1929 | : LocationSummary::kNoCall; |
| 1930 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 1931 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1932 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1933 | case Primitive::kPrimInt: { |
| 1934 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1935 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1936 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1937 | break; |
| 1938 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1939 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1940 | InvokeRuntimeCallingConvention calling_convention; |
| 1941 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 1942 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 1943 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 1944 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 1945 | // The runtime helper puts the output in R0,R2. |
| 1946 | locations->SetOut(Location::RegisterPairLocation(R0, R2)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1947 | break; |
| 1948 | } |
| 1949 | case Primitive::kPrimFloat: |
| 1950 | case Primitive::kPrimDouble: { |
| 1951 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1952 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1953 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1954 | break; |
| 1955 | } |
| 1956 | |
| 1957 | default: |
| 1958 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 1959 | } |
| 1960 | } |
| 1961 | |
| 1962 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 1963 | LocationSummary* locations = div->GetLocations(); |
| 1964 | Location out = locations->Out(); |
| 1965 | Location first = locations->InAt(0); |
| 1966 | Location second = locations->InAt(1); |
| 1967 | |
| 1968 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1969 | case Primitive::kPrimInt: { |
| 1970 | __ sdiv(out.As<Register>(), first.As<Register>(), second.As<Register>()); |
| 1971 | break; |
| 1972 | } |
| 1973 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1974 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1975 | InvokeRuntimeCallingConvention calling_convention; |
| 1976 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 1977 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 1978 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 1979 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 1980 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
| 1981 | DCHECK_EQ(R2, out.AsRegisterPairHigh<Register>()); |
| 1982 | |
| 1983 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1984 | break; |
| 1985 | } |
| 1986 | |
| 1987 | case Primitive::kPrimFloat: { |
| 1988 | __ vdivs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>()); |
| 1989 | break; |
| 1990 | } |
| 1991 | |
| 1992 | case Primitive::kPrimDouble: { |
| 1993 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1994 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 1995 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 1996 | break; |
| 1997 | } |
| 1998 | |
| 1999 | default: |
| 2000 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2001 | } |
| 2002 | } |
| 2003 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2004 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
| 2005 | LocationSummary::CallKind call_kind = rem->GetResultType() == Primitive::kPrimLong |
| 2006 | ? LocationSummary::kCall |
| 2007 | : LocationSummary::kNoCall; |
| 2008 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 2009 | |
| 2010 | switch (rem->GetResultType()) { |
| 2011 | case Primitive::kPrimInt: { |
| 2012 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2013 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2014 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2015 | locations->AddTemp(Location::RequiresRegister()); |
| 2016 | break; |
| 2017 | } |
| 2018 | case Primitive::kPrimLong: { |
| 2019 | InvokeRuntimeCallingConvention calling_convention; |
| 2020 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2021 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2022 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2023 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2024 | // The runtime helper puts the output in R2,R3. |
| 2025 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 2026 | break; |
| 2027 | } |
| 2028 | case Primitive::kPrimFloat: |
| 2029 | case Primitive::kPrimDouble: { |
| 2030 | LOG(FATAL) << "Unimplemented rem type " << rem->GetResultType(); |
| 2031 | break; |
| 2032 | } |
| 2033 | |
| 2034 | default: |
| 2035 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 2036 | } |
| 2037 | } |
| 2038 | |
| 2039 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 2040 | LocationSummary* locations = rem->GetLocations(); |
| 2041 | Location out = locations->Out(); |
| 2042 | Location first = locations->InAt(0); |
| 2043 | Location second = locations->InAt(1); |
| 2044 | |
| 2045 | switch (rem->GetResultType()) { |
| 2046 | case Primitive::kPrimInt: { |
| 2047 | Register reg1 = first.As<Register>(); |
| 2048 | Register reg2 = second.As<Register>(); |
| 2049 | Register temp = locations->GetTemp(0).As<Register>(); |
| 2050 | |
| 2051 | // temp = reg1 / reg2 (integer division) |
| 2052 | // temp = temp * reg2 |
| 2053 | // dest = reg1 - temp |
| 2054 | __ sdiv(temp, reg1, reg2); |
| 2055 | __ mul(temp, temp, reg2); |
| 2056 | __ sub(out.As<Register>(), reg1, ShifterOperand(temp)); |
| 2057 | break; |
| 2058 | } |
| 2059 | |
| 2060 | case Primitive::kPrimLong: { |
| 2061 | InvokeRuntimeCallingConvention calling_convention; |
| 2062 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2063 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 2064 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 2065 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 2066 | DCHECK_EQ(R2, out.AsRegisterPairLow<Register>()); |
| 2067 | DCHECK_EQ(R3, out.AsRegisterPairHigh<Register>()); |
| 2068 | |
| 2069 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc()); |
| 2070 | break; |
| 2071 | } |
| 2072 | |
| 2073 | case Primitive::kPrimFloat: |
| 2074 | case Primitive::kPrimDouble: { |
| 2075 | LOG(FATAL) << "Unimplemented rem type " << rem->GetResultType(); |
| 2076 | break; |
| 2077 | } |
| 2078 | |
| 2079 | default: |
| 2080 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 2081 | } |
| 2082 | } |
| 2083 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2084 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2085 | LocationSummary* locations = |
| 2086 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2087 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2088 | if (instruction->HasUses()) { |
| 2089 | locations->SetOut(Location::SameAsFirstInput()); |
| 2090 | } |
| 2091 | } |
| 2092 | |
| 2093 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2094 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
| 2095 | codegen_->AddSlowPath(slow_path); |
| 2096 | |
| 2097 | LocationSummary* locations = instruction->GetLocations(); |
| 2098 | Location value = locations->InAt(0); |
| 2099 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2100 | switch (instruction->GetType()) { |
| 2101 | case Primitive::kPrimInt: { |
| 2102 | if (value.IsRegister()) { |
| 2103 | __ cmp(value.As<Register>(), ShifterOperand(0)); |
| 2104 | __ b(slow_path->GetEntryLabel(), EQ); |
| 2105 | } else { |
| 2106 | DCHECK(value.IsConstant()) << value; |
| 2107 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 2108 | __ b(slow_path->GetEntryLabel()); |
| 2109 | } |
| 2110 | } |
| 2111 | break; |
| 2112 | } |
| 2113 | case Primitive::kPrimLong: { |
| 2114 | if (value.IsRegisterPair()) { |
| 2115 | __ orrs(IP, |
| 2116 | value.AsRegisterPairLow<Register>(), |
| 2117 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 2118 | __ b(slow_path->GetEntryLabel(), EQ); |
| 2119 | } else { |
| 2120 | DCHECK(value.IsConstant()) << value; |
| 2121 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 2122 | __ b(slow_path->GetEntryLabel()); |
| 2123 | } |
| 2124 | } |
| 2125 | break; |
| 2126 | default: |
| 2127 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 2128 | } |
| 2129 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2130 | } |
| 2131 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2132 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 2133 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 2134 | |
| 2135 | LocationSummary::CallKind call_kind = op->GetResultType() == Primitive::kPrimLong |
| 2136 | ? LocationSummary::kCall |
| 2137 | : LocationSummary::kNoCall; |
| 2138 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(op, call_kind); |
| 2139 | |
| 2140 | switch (op->GetResultType()) { |
| 2141 | case Primitive::kPrimInt: { |
| 2142 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2143 | locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1))); |
| 2144 | locations->SetOut(Location::RequiresRegister()); |
| 2145 | break; |
| 2146 | } |
| 2147 | case Primitive::kPrimLong: { |
| 2148 | InvokeRuntimeCallingConvention calling_convention; |
| 2149 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2150 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2151 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 2152 | // The runtime helper puts the output in R0,R2. |
| 2153 | locations->SetOut(Location::RegisterPairLocation(R0, R2)); |
| 2154 | break; |
| 2155 | } |
| 2156 | default: |
| 2157 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 2158 | } |
| 2159 | } |
| 2160 | |
| 2161 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 2162 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 2163 | |
| 2164 | LocationSummary* locations = op->GetLocations(); |
| 2165 | Location out = locations->Out(); |
| 2166 | Location first = locations->InAt(0); |
| 2167 | Location second = locations->InAt(1); |
| 2168 | |
| 2169 | Primitive::Type type = op->GetResultType(); |
| 2170 | switch (type) { |
| 2171 | case Primitive::kPrimInt: { |
| 2172 | Register out_reg = out.As<Register>(); |
| 2173 | Register first_reg = first.As<Register>(); |
| 2174 | // Arm doesn't mask the shift count so we need to do it ourselves. |
| 2175 | if (second.IsRegister()) { |
| 2176 | Register second_reg = second.As<Register>(); |
| 2177 | __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue)); |
| 2178 | if (op->IsShl()) { |
| 2179 | __ Lsl(out_reg, first_reg, second_reg); |
| 2180 | } else if (op->IsShr()) { |
| 2181 | __ Asr(out_reg, first_reg, second_reg); |
| 2182 | } else { |
| 2183 | __ Lsr(out_reg, first_reg, second_reg); |
| 2184 | } |
| 2185 | } else { |
| 2186 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2187 | uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue); |
| 2188 | if (shift_value == 0) { // arm does not support shifting with 0 immediate. |
| 2189 | __ Mov(out_reg, first_reg); |
| 2190 | } else if (op->IsShl()) { |
| 2191 | __ Lsl(out_reg, first_reg, shift_value); |
| 2192 | } else if (op->IsShr()) { |
| 2193 | __ Asr(out_reg, first_reg, shift_value); |
| 2194 | } else { |
| 2195 | __ Lsr(out_reg, first_reg, shift_value); |
| 2196 | } |
| 2197 | } |
| 2198 | break; |
| 2199 | } |
| 2200 | case Primitive::kPrimLong: { |
| 2201 | // TODO: Inline the assembly instead of calling the runtime. |
| 2202 | InvokeRuntimeCallingConvention calling_convention; |
| 2203 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2204 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 2205 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.As<Register>()); |
| 2206 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
| 2207 | DCHECK_EQ(R2, out.AsRegisterPairHigh<Register>()); |
| 2208 | |
| 2209 | int32_t entry_point_offset; |
| 2210 | if (op->IsShl()) { |
| 2211 | entry_point_offset = QUICK_ENTRY_POINT(pShlLong); |
| 2212 | } else if (op->IsShr()) { |
| 2213 | entry_point_offset = QUICK_ENTRY_POINT(pShrLong); |
| 2214 | } else { |
| 2215 | entry_point_offset = QUICK_ENTRY_POINT(pUshrLong); |
| 2216 | } |
| 2217 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 2218 | __ blx(LR); |
| 2219 | break; |
| 2220 | } |
| 2221 | default: |
| 2222 | LOG(FATAL) << "Unexpected operation type " << type; |
| 2223 | } |
| 2224 | } |
| 2225 | |
| 2226 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 2227 | HandleShift(shl); |
| 2228 | } |
| 2229 | |
| 2230 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 2231 | HandleShift(shl); |
| 2232 | } |
| 2233 | |
| 2234 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 2235 | HandleShift(shr); |
| 2236 | } |
| 2237 | |
| 2238 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 2239 | HandleShift(shr); |
| 2240 | } |
| 2241 | |
| 2242 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 2243 | HandleShift(ushr); |
| 2244 | } |
| 2245 | |
| 2246 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 2247 | HandleShift(ushr); |
| 2248 | } |
| 2249 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2250 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2251 | LocationSummary* locations = |
| 2252 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2253 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2254 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2255 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2256 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2257 | } |
| 2258 | |
| 2259 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
| 2260 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2261 | codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2262 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2263 | codegen_->InvokeRuntime( |
| 2264 | QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2265 | } |
| 2266 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2267 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 2268 | LocationSummary* locations = |
| 2269 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 2270 | InvokeRuntimeCallingConvention calling_convention; |
| 2271 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2272 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2273 | locations->SetOut(Location::RegisterLocation(R0)); |
| 2274 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 2275 | } |
| 2276 | |
| 2277 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
| 2278 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2279 | codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2280 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2281 | codegen_->InvokeRuntime( |
| 2282 | QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2283 | } |
| 2284 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2285 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2286 | LocationSummary* locations = |
| 2287 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2288 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 2289 | if (location.IsStackSlot()) { |
| 2290 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 2291 | } else if (location.IsDoubleStackSlot()) { |
| 2292 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2293 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2294 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2295 | } |
| 2296 | |
| 2297 | void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2298 | // Nothing to do, the parameter is already at its location. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2299 | UNUSED(instruction); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2300 | } |
| 2301 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2302 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2303 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2304 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2305 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2306 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 2307 | } |
| 2308 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2309 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 2310 | LocationSummary* locations = not_->GetLocations(); |
| 2311 | Location out = locations->Out(); |
| 2312 | Location in = locations->InAt(0); |
| 2313 | switch (not_->InputAt(0)->GetType()) { |
| 2314 | case Primitive::kPrimBoolean: |
| 2315 | __ eor(out.As<Register>(), in.As<Register>(), ShifterOperand(1)); |
| 2316 | break; |
| 2317 | |
| 2318 | case Primitive::kPrimInt: |
| 2319 | __ mvn(out.As<Register>(), ShifterOperand(in.As<Register>())); |
| 2320 | break; |
| 2321 | |
| 2322 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 2323 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 2324 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 2325 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 2326 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2327 | break; |
| 2328 | |
| 2329 | default: |
| 2330 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 2331 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 2332 | } |
| 2333 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2334 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2335 | LocationSummary* locations = |
| 2336 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2337 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2338 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2339 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2340 | } |
| 2341 | |
| 2342 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2343 | LocationSummary* locations = compare->GetLocations(); |
| 2344 | switch (compare->InputAt(0)->GetType()) { |
| 2345 | case Primitive::kPrimLong: { |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2346 | Register output = locations->Out().As<Register>(); |
| 2347 | Location left = locations->InAt(0); |
| 2348 | Location right = locations->InAt(1); |
| 2349 | Label less, greater, done; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2350 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 2351 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2352 | __ b(&less, LT); |
| 2353 | __ b(&greater, GT); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2354 | // Do LoadImmediate before any `cmp`, as LoadImmediate might affect |
| 2355 | // the status flags. |
| 2356 | __ LoadImmediate(output, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2357 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 2358 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2359 | __ b(&done, EQ); |
| 2360 | __ b(&less, CC); |
| 2361 | |
| 2362 | __ Bind(&greater); |
| 2363 | __ LoadImmediate(output, 1); |
| 2364 | __ b(&done); |
| 2365 | |
| 2366 | __ Bind(&less); |
| 2367 | __ LoadImmediate(output, -1); |
| 2368 | |
| 2369 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2370 | break; |
| 2371 | } |
| 2372 | default: |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2373 | LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2374 | } |
| 2375 | } |
| 2376 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2377 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2378 | LocationSummary* locations = |
| 2379 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 2380 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 2381 | locations->SetInAt(i, Location::Any()); |
| 2382 | } |
| 2383 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2384 | } |
| 2385 | |
| 2386 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2387 | UNUSED(instruction); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2388 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2389 | } |
| 2390 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2391 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2392 | LocationSummary* locations = |
| 2393 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2394 | bool needs_write_barrier = |
| 2395 | CodeGenerator::StoreNeedsWriteBarrier(instruction->GetFieldType(), instruction->GetValue()); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2396 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2397 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 2398 | // Temporary registers for the write barrier. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2399 | if (needs_write_barrier) { |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 2400 | locations->AddTemp(Location::RequiresRegister()); |
| 2401 | locations->AddTemp(Location::RequiresRegister()); |
| 2402 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2403 | } |
| 2404 | |
| 2405 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 2406 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2407 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2408 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2409 | Primitive::Type field_type = instruction->GetFieldType(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2410 | |
| 2411 | switch (field_type) { |
| 2412 | case Primitive::kPrimBoolean: |
| 2413 | case Primitive::kPrimByte: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2414 | Register value = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2415 | __ StoreToOffset(kStoreByte, value, obj, offset); |
| 2416 | break; |
| 2417 | } |
| 2418 | |
| 2419 | case Primitive::kPrimShort: |
| 2420 | case Primitive::kPrimChar: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2421 | Register value = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2422 | __ StoreToOffset(kStoreHalfword, value, obj, offset); |
| 2423 | break; |
| 2424 | } |
| 2425 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2426 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2427 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2428 | Register value = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2429 | __ StoreToOffset(kStoreWord, value, obj, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2430 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->GetValue())) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2431 | Register temp = locations->GetTemp(0).As<Register>(); |
| 2432 | Register card = locations->GetTemp(1).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2433 | codegen_->MarkGCCard(temp, card, obj, value); |
| 2434 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2435 | break; |
| 2436 | } |
| 2437 | |
| 2438 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2439 | Location value = locations->InAt(1); |
| 2440 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2441 | break; |
| 2442 | } |
| 2443 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2444 | case Primitive::kPrimFloat: { |
| 2445 | SRegister value = locations->InAt(1).As<SRegister>(); |
| 2446 | __ StoreSToOffset(value, obj, offset); |
| 2447 | break; |
| 2448 | } |
| 2449 | |
| 2450 | case Primitive::kPrimDouble: { |
| 2451 | DRegister value = FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>()); |
| 2452 | __ StoreDToOffset(value, obj, offset); |
| 2453 | break; |
| 2454 | } |
| 2455 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2456 | case Primitive::kPrimVoid: |
| 2457 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2458 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2459 | } |
| 2460 | } |
| 2461 | |
| 2462 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2463 | LocationSummary* locations = |
| 2464 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2465 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2466 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2467 | } |
| 2468 | |
| 2469 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 2470 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2471 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2472 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 2473 | |
| 2474 | switch (instruction->GetType()) { |
| 2475 | case Primitive::kPrimBoolean: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2476 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2477 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset); |
| 2478 | break; |
| 2479 | } |
| 2480 | |
| 2481 | case Primitive::kPrimByte: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2482 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2483 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset); |
| 2484 | break; |
| 2485 | } |
| 2486 | |
| 2487 | case Primitive::kPrimShort: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2488 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2489 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset); |
| 2490 | break; |
| 2491 | } |
| 2492 | |
| 2493 | case Primitive::kPrimChar: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2494 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2495 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset); |
| 2496 | break; |
| 2497 | } |
| 2498 | |
| 2499 | case Primitive::kPrimInt: |
| 2500 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2501 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2502 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2503 | break; |
| 2504 | } |
| 2505 | |
| 2506 | case Primitive::kPrimLong: { |
| 2507 | // TODO: support volatile. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2508 | Location out = locations->Out(); |
| 2509 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2510 | break; |
| 2511 | } |
| 2512 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2513 | case Primitive::kPrimFloat: { |
| 2514 | SRegister out = locations->Out().As<SRegister>(); |
| 2515 | __ LoadSFromOffset(out, obj, offset); |
| 2516 | break; |
| 2517 | } |
| 2518 | |
| 2519 | case Primitive::kPrimDouble: { |
| 2520 | DRegister out = FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>()); |
| 2521 | __ LoadDFromOffset(out, obj, offset); |
| 2522 | break; |
| 2523 | } |
| 2524 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2525 | case Primitive::kPrimVoid: |
| 2526 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2527 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2528 | } |
| 2529 | } |
| 2530 | |
| 2531 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2532 | LocationSummary* locations = |
| 2533 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2534 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2535 | if (instruction->HasUses()) { |
| 2536 | locations->SetOut(Location::SameAsFirstInput()); |
| 2537 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 2541 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2542 | codegen_->AddSlowPath(slow_path); |
| 2543 | |
| 2544 | LocationSummary* locations = instruction->GetLocations(); |
| 2545 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2546 | |
| 2547 | if (obj.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2548 | __ cmp(obj.As<Register>(), ShifterOperand(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2549 | __ b(slow_path->GetEntryLabel(), EQ); |
| 2550 | } else { |
| 2551 | DCHECK(obj.IsConstant()) << obj; |
| 2552 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 2553 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2554 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2555 | } |
| 2556 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2557 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2558 | LocationSummary* locations = |
| 2559 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2560 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2561 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2562 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2563 | } |
| 2564 | |
| 2565 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 2566 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2567 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2568 | Location index = locations->InAt(1); |
| 2569 | |
| 2570 | switch (instruction->GetType()) { |
| 2571 | case Primitive::kPrimBoolean: { |
| 2572 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2573 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2574 | if (index.IsConstant()) { |
| 2575 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
| 2576 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset); |
| 2577 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2578 | __ add(IP, obj, ShifterOperand(index.As<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2579 | __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset); |
| 2580 | } |
| 2581 | break; |
| 2582 | } |
| 2583 | |
| 2584 | case Primitive::kPrimByte: { |
| 2585 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2586 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2587 | if (index.IsConstant()) { |
| 2588 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
| 2589 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset); |
| 2590 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2591 | __ add(IP, obj, ShifterOperand(index.As<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2592 | __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset); |
| 2593 | } |
| 2594 | break; |
| 2595 | } |
| 2596 | |
| 2597 | case Primitive::kPrimShort: { |
| 2598 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2599 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2600 | if (index.IsConstant()) { |
| 2601 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 2602 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset); |
| 2603 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2604 | __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2605 | __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset); |
| 2606 | } |
| 2607 | break; |
| 2608 | } |
| 2609 | |
| 2610 | case Primitive::kPrimChar: { |
| 2611 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2612 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2613 | if (index.IsConstant()) { |
| 2614 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 2615 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset); |
| 2616 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2617 | __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2618 | __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset); |
| 2619 | } |
| 2620 | break; |
| 2621 | } |
| 2622 | |
| 2623 | case Primitive::kPrimInt: |
| 2624 | case Primitive::kPrimNot: { |
| 2625 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
| 2626 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2627 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2628 | if (index.IsConstant()) { |
| 2629 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2630 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2631 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2632 | __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2633 | __ LoadFromOffset(kLoadWord, out, IP, data_offset); |
| 2634 | } |
| 2635 | break; |
| 2636 | } |
| 2637 | |
| 2638 | case Primitive::kPrimLong: { |
| 2639 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2640 | Location out = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2641 | if (index.IsConstant()) { |
| 2642 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2643 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2644 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2645 | __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8)); |
| 2646 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2647 | } |
| 2648 | break; |
| 2649 | } |
| 2650 | |
| 2651 | case Primitive::kPrimFloat: |
| 2652 | case Primitive::kPrimDouble: |
| 2653 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2654 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2655 | case Primitive::kPrimVoid: |
| 2656 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2657 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2658 | } |
| 2659 | } |
| 2660 | |
| 2661 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2662 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2663 | |
| 2664 | bool needs_write_barrier = |
| 2665 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 2666 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
| 2667 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2668 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2669 | instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 2670 | if (needs_runtime_call) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2671 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2672 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2673 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2674 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2675 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2676 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2677 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2678 | locations->SetInAt(2, Location::RequiresRegister()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2679 | |
| 2680 | if (needs_write_barrier) { |
| 2681 | // Temporary registers for the write barrier. |
| 2682 | locations->AddTemp(Location::RequiresRegister()); |
| 2683 | locations->AddTemp(Location::RequiresRegister()); |
| 2684 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2685 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2686 | } |
| 2687 | |
| 2688 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 2689 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2690 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2691 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2692 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2693 | bool needs_runtime_call = locations->WillCall(); |
| 2694 | bool needs_write_barrier = |
| 2695 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2696 | |
| 2697 | switch (value_type) { |
| 2698 | case Primitive::kPrimBoolean: |
| 2699 | case Primitive::kPrimByte: { |
| 2700 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2701 | Register value = locations->InAt(2).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2702 | if (index.IsConstant()) { |
| 2703 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
| 2704 | __ StoreToOffset(kStoreByte, value, obj, offset); |
| 2705 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2706 | __ add(IP, obj, ShifterOperand(index.As<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2707 | __ StoreToOffset(kStoreByte, value, IP, data_offset); |
| 2708 | } |
| 2709 | break; |
| 2710 | } |
| 2711 | |
| 2712 | case Primitive::kPrimShort: |
| 2713 | case Primitive::kPrimChar: { |
| 2714 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2715 | Register value = locations->InAt(2).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2716 | if (index.IsConstant()) { |
| 2717 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 2718 | __ StoreToOffset(kStoreHalfword, value, obj, offset); |
| 2719 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2720 | __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2721 | __ StoreToOffset(kStoreHalfword, value, IP, data_offset); |
| 2722 | } |
| 2723 | break; |
| 2724 | } |
| 2725 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2726 | case Primitive::kPrimInt: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2727 | case Primitive::kPrimNot: { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2728 | if (!needs_runtime_call) { |
| 2729 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2730 | Register value = locations->InAt(2).As<Register>(); |
| 2731 | if (index.IsConstant()) { |
| 2732 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2733 | __ StoreToOffset(kStoreWord, value, obj, offset); |
| 2734 | } else { |
| 2735 | DCHECK(index.IsRegister()) << index; |
| 2736 | __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4)); |
| 2737 | __ StoreToOffset(kStoreWord, value, IP, data_offset); |
| 2738 | } |
| 2739 | if (needs_write_barrier) { |
| 2740 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 2741 | Register temp = locations->GetTemp(0).As<Register>(); |
| 2742 | Register card = locations->GetTemp(1).As<Register>(); |
| 2743 | codegen_->MarkGCCard(temp, card, obj, value); |
| 2744 | } |
| 2745 | } else { |
| 2746 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 2747 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc()); |
| 2748 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2749 | break; |
| 2750 | } |
| 2751 | |
| 2752 | case Primitive::kPrimLong: { |
| 2753 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2754 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2755 | if (index.IsConstant()) { |
| 2756 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2757 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2758 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2759 | __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8)); |
| 2760 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2761 | } |
| 2762 | break; |
| 2763 | } |
| 2764 | |
| 2765 | case Primitive::kPrimFloat: |
| 2766 | case Primitive::kPrimDouble: |
| 2767 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2768 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2769 | case Primitive::kPrimVoid: |
| 2770 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2771 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2772 | } |
| 2773 | } |
| 2774 | |
| 2775 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2776 | LocationSummary* locations = |
| 2777 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2778 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2779 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2780 | } |
| 2781 | |
| 2782 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 2783 | LocationSummary* locations = instruction->GetLocations(); |
| 2784 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2785 | Register obj = locations->InAt(0).As<Register>(); |
| 2786 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2787 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2788 | } |
| 2789 | |
| 2790 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2791 | LocationSummary* locations = |
| 2792 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2793 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2794 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2795 | if (instruction->HasUses()) { |
| 2796 | locations->SetOut(Location::SameAsFirstInput()); |
| 2797 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2798 | } |
| 2799 | |
| 2800 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2801 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 2802 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2803 | instruction, locations->InAt(0), locations->InAt(1)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2804 | codegen_->AddSlowPath(slow_path); |
| 2805 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2806 | Register index = locations->InAt(0).As<Register>(); |
| 2807 | Register length = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2808 | |
| 2809 | __ cmp(index, ShifterOperand(length)); |
| 2810 | __ b(slow_path->GetEntryLabel(), CS); |
| 2811 | } |
| 2812 | |
| 2813 | void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) { |
| 2814 | Label is_null; |
| 2815 | __ CompareAndBranchIfZero(value, &is_null); |
| 2816 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value()); |
| 2817 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 2818 | __ strb(card, Address(card, temp)); |
| 2819 | __ Bind(&is_null); |
| 2820 | } |
| 2821 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2822 | void LocationsBuilderARM::VisitTemporary(HTemporary* temp) { |
| 2823 | temp->SetLocations(nullptr); |
| 2824 | } |
| 2825 | |
| 2826 | void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) { |
| 2827 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2828 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2829 | } |
| 2830 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2831 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2832 | UNUSED(instruction); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2833 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2834 | } |
| 2835 | |
| 2836 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2837 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 2838 | } |
| 2839 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2840 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 2841 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 2842 | } |
| 2843 | |
| 2844 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2845 | HBasicBlock* block = instruction->GetBlock(); |
| 2846 | if (block->GetLoopInformation() != nullptr) { |
| 2847 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 2848 | // The back edge will generate the suspend check. |
| 2849 | return; |
| 2850 | } |
| 2851 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 2852 | // The goto will generate the suspend check. |
| 2853 | return; |
| 2854 | } |
| 2855 | GenerateSuspendCheck(instruction, nullptr); |
| 2856 | } |
| 2857 | |
| 2858 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2859 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2860 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2861 | new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2862 | codegen_->AddSlowPath(slow_path); |
| 2863 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 2864 | __ LoadFromOffset( |
| 2865 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value()); |
| 2866 | __ cmp(IP, ShifterOperand(0)); |
| 2867 | // TODO: Figure out the branch offsets and use cbz/cbnz. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2868 | if (successor == nullptr) { |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 2869 | __ b(slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2870 | __ Bind(slow_path->GetReturnLabel()); |
| 2871 | } else { |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 2872 | __ b(codegen_->GetLabelOf(successor), EQ); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2873 | __ b(slow_path->GetEntryLabel()); |
| 2874 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2875 | } |
| 2876 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2877 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 2878 | return codegen_->GetAssembler(); |
| 2879 | } |
| 2880 | |
| 2881 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
| 2882 | MoveOperands* move = moves_.Get(index); |
| 2883 | Location source = move->GetSource(); |
| 2884 | Location destination = move->GetDestination(); |
| 2885 | |
| 2886 | if (source.IsRegister()) { |
| 2887 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2888 | __ Mov(destination.As<Register>(), source.As<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2889 | } else { |
| 2890 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2891 | __ StoreToOffset(kStoreWord, source.As<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2892 | SP, destination.GetStackIndex()); |
| 2893 | } |
| 2894 | } else if (source.IsStackSlot()) { |
| 2895 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2896 | __ LoadFromOffset(kLoadWord, destination.As<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2897 | SP, source.GetStackIndex()); |
| 2898 | } else { |
| 2899 | DCHECK(destination.IsStackSlot()); |
| 2900 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 2901 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 2902 | } |
| 2903 | } else { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2904 | DCHECK(source.IsConstant()); |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 2905 | DCHECK(source.GetConstant()->IsIntConstant()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2906 | int32_t value = source.GetConstant()->AsIntConstant()->GetValue(); |
| 2907 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2908 | __ LoadImmediate(destination.As<Register>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2909 | } else { |
| 2910 | DCHECK(destination.IsStackSlot()); |
| 2911 | __ LoadImmediate(IP, value); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2912 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2913 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2914 | } |
| 2915 | } |
| 2916 | |
| 2917 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 2918 | __ Mov(IP, reg); |
| 2919 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 2920 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 2921 | } |
| 2922 | |
| 2923 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 2924 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 2925 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 2926 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 2927 | SP, mem1 + stack_offset); |
| 2928 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 2929 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 2930 | SP, mem2 + stack_offset); |
| 2931 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 2932 | } |
| 2933 | |
| 2934 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
| 2935 | MoveOperands* move = moves_.Get(index); |
| 2936 | Location source = move->GetSource(); |
| 2937 | Location destination = move->GetDestination(); |
| 2938 | |
| 2939 | if (source.IsRegister() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2940 | DCHECK_NE(source.As<Register>(), IP); |
| 2941 | DCHECK_NE(destination.As<Register>(), IP); |
| 2942 | __ Mov(IP, source.As<Register>()); |
| 2943 | __ Mov(source.As<Register>(), destination.As<Register>()); |
| 2944 | __ Mov(destination.As<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2945 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2946 | Exchange(source.As<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2947 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2948 | Exchange(destination.As<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2949 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 2950 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 2951 | } else { |
| 2952 | LOG(FATAL) << "Unimplemented"; |
| 2953 | } |
| 2954 | } |
| 2955 | |
| 2956 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 2957 | __ Push(static_cast<Register>(reg)); |
| 2958 | } |
| 2959 | |
| 2960 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 2961 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2962 | } |
| 2963 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2964 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2965 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 2966 | ? LocationSummary::kCallOnSlowPath |
| 2967 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2968 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2969 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2970 | locations->SetOut(Location::RequiresRegister()); |
| 2971 | } |
| 2972 | |
| 2973 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) { |
| 2974 | Register out = cls->GetLocations()->Out().As<Register>(); |
| 2975 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2976 | DCHECK(!cls->CanCallRuntime()); |
| 2977 | DCHECK(!cls->MustGenerateClinitCheck()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2978 | codegen_->LoadCurrentMethod(out); |
| 2979 | __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value()); |
| 2980 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2981 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2982 | codegen_->LoadCurrentMethod(out); |
| 2983 | __ LoadFromOffset( |
| 2984 | kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value()); |
| 2985 | __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2986 | |
| 2987 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
| 2988 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 2989 | codegen_->AddSlowPath(slow_path); |
| 2990 | __ cmp(out, ShifterOperand(0)); |
| 2991 | __ b(slow_path->GetEntryLabel(), EQ); |
| 2992 | if (cls->MustGenerateClinitCheck()) { |
| 2993 | GenerateClassInitializationCheck(slow_path, out); |
| 2994 | } else { |
| 2995 | __ Bind(slow_path->GetExitLabel()); |
| 2996 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2997 | } |
| 2998 | } |
| 2999 | |
| 3000 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 3001 | LocationSummary* locations = |
| 3002 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 3003 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3004 | if (check->HasUses()) { |
| 3005 | locations->SetOut(Location::SameAsFirstInput()); |
| 3006 | } |
| 3007 | } |
| 3008 | |
| 3009 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3010 | // We assume the class is not null. |
| 3011 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
| 3012 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3013 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3014 | GenerateClassInitializationCheck(slow_path, check->GetLocations()->InAt(0).As<Register>()); |
| 3015 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3016 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3017 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
| 3018 | SlowPathCodeARM* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3019 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 3020 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 3021 | __ b(slow_path->GetEntryLabel(), LT); |
| 3022 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 3023 | // properly. Therefore, we do a memory fence. |
| 3024 | __ dmb(ISH); |
| 3025 | __ Bind(slow_path->GetExitLabel()); |
| 3026 | } |
| 3027 | |
| 3028 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3029 | LocationSummary* locations = |
| 3030 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3031 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3032 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3033 | } |
| 3034 | |
| 3035 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3036 | LocationSummary* locations = instruction->GetLocations(); |
| 3037 | Register cls = locations->InAt(0).As<Register>(); |
| 3038 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 3039 | |
| 3040 | switch (instruction->GetType()) { |
| 3041 | case Primitive::kPrimBoolean: { |
| 3042 | Register out = locations->Out().As<Register>(); |
| 3043 | __ LoadFromOffset(kLoadUnsignedByte, out, cls, offset); |
| 3044 | break; |
| 3045 | } |
| 3046 | |
| 3047 | case Primitive::kPrimByte: { |
| 3048 | Register out = locations->Out().As<Register>(); |
| 3049 | __ LoadFromOffset(kLoadSignedByte, out, cls, offset); |
| 3050 | break; |
| 3051 | } |
| 3052 | |
| 3053 | case Primitive::kPrimShort: { |
| 3054 | Register out = locations->Out().As<Register>(); |
| 3055 | __ LoadFromOffset(kLoadSignedHalfword, out, cls, offset); |
| 3056 | break; |
| 3057 | } |
| 3058 | |
| 3059 | case Primitive::kPrimChar: { |
| 3060 | Register out = locations->Out().As<Register>(); |
| 3061 | __ LoadFromOffset(kLoadUnsignedHalfword, out, cls, offset); |
| 3062 | break; |
| 3063 | } |
| 3064 | |
| 3065 | case Primitive::kPrimInt: |
| 3066 | case Primitive::kPrimNot: { |
| 3067 | Register out = locations->Out().As<Register>(); |
| 3068 | __ LoadFromOffset(kLoadWord, out, cls, offset); |
| 3069 | break; |
| 3070 | } |
| 3071 | |
| 3072 | case Primitive::kPrimLong: { |
| 3073 | // TODO: support volatile. |
| 3074 | Location out = locations->Out(); |
| 3075 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), cls, offset); |
| 3076 | break; |
| 3077 | } |
| 3078 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3079 | case Primitive::kPrimFloat: { |
| 3080 | SRegister out = locations->Out().As<SRegister>(); |
| 3081 | __ LoadSFromOffset(out, cls, offset); |
| 3082 | break; |
| 3083 | } |
| 3084 | |
| 3085 | case Primitive::kPrimDouble: { |
| 3086 | DRegister out = FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>()); |
| 3087 | __ LoadDFromOffset(out, cls, offset); |
| 3088 | break; |
| 3089 | } |
| 3090 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3091 | case Primitive::kPrimVoid: |
| 3092 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 3093 | UNREACHABLE(); |
| 3094 | } |
| 3095 | } |
| 3096 | |
| 3097 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3098 | LocationSummary* locations = |
| 3099 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3100 | bool needs_write_barrier = |
| 3101 | CodeGenerator::StoreNeedsWriteBarrier(instruction->GetFieldType(), instruction->GetValue()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3102 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3103 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3104 | // Temporary registers for the write barrier. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3105 | if (needs_write_barrier) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3106 | locations->AddTemp(Location::RequiresRegister()); |
| 3107 | locations->AddTemp(Location::RequiresRegister()); |
| 3108 | } |
| 3109 | } |
| 3110 | |
| 3111 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3112 | LocationSummary* locations = instruction->GetLocations(); |
| 3113 | Register cls = locations->InAt(0).As<Register>(); |
| 3114 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 3115 | Primitive::Type field_type = instruction->GetFieldType(); |
| 3116 | |
| 3117 | switch (field_type) { |
| 3118 | case Primitive::kPrimBoolean: |
| 3119 | case Primitive::kPrimByte: { |
| 3120 | Register value = locations->InAt(1).As<Register>(); |
| 3121 | __ StoreToOffset(kStoreByte, value, cls, offset); |
| 3122 | break; |
| 3123 | } |
| 3124 | |
| 3125 | case Primitive::kPrimShort: |
| 3126 | case Primitive::kPrimChar: { |
| 3127 | Register value = locations->InAt(1).As<Register>(); |
| 3128 | __ StoreToOffset(kStoreHalfword, value, cls, offset); |
| 3129 | break; |
| 3130 | } |
| 3131 | |
| 3132 | case Primitive::kPrimInt: |
| 3133 | case Primitive::kPrimNot: { |
| 3134 | Register value = locations->InAt(1).As<Register>(); |
| 3135 | __ StoreToOffset(kStoreWord, value, cls, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3136 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->GetValue())) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3137 | Register temp = locations->GetTemp(0).As<Register>(); |
| 3138 | Register card = locations->GetTemp(1).As<Register>(); |
| 3139 | codegen_->MarkGCCard(temp, card, cls, value); |
| 3140 | } |
| 3141 | break; |
| 3142 | } |
| 3143 | |
| 3144 | case Primitive::kPrimLong: { |
| 3145 | Location value = locations->InAt(1); |
| 3146 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), cls, offset); |
| 3147 | break; |
| 3148 | } |
| 3149 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3150 | case Primitive::kPrimFloat: { |
| 3151 | SRegister value = locations->InAt(1).As<SRegister>(); |
| 3152 | __ StoreSToOffset(value, cls, offset); |
| 3153 | break; |
| 3154 | } |
| 3155 | |
| 3156 | case Primitive::kPrimDouble: { |
| 3157 | DRegister value = FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>()); |
| 3158 | __ StoreDToOffset(value, cls, offset); |
| 3159 | break; |
| 3160 | } |
| 3161 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3162 | case Primitive::kPrimVoid: |
| 3163 | LOG(FATAL) << "Unreachable type " << field_type; |
| 3164 | UNREACHABLE(); |
| 3165 | } |
| 3166 | } |
| 3167 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 3168 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
| 3169 | LocationSummary* locations = |
| 3170 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
| 3171 | locations->SetOut(Location::RequiresRegister()); |
| 3172 | } |
| 3173 | |
| 3174 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) { |
| 3175 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 3176 | codegen_->AddSlowPath(slow_path); |
| 3177 | |
| 3178 | Register out = load->GetLocations()->Out().As<Register>(); |
| 3179 | codegen_->LoadCurrentMethod(out); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 3180 | __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value()); |
| 3181 | __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 3182 | __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
| 3183 | __ cmp(out, ShifterOperand(0)); |
| 3184 | __ b(slow_path->GetEntryLabel(), EQ); |
| 3185 | __ Bind(slow_path->GetExitLabel()); |
| 3186 | } |
| 3187 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 3188 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 3189 | LocationSummary* locations = |
| 3190 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 3191 | locations->SetOut(Location::RequiresRegister()); |
| 3192 | } |
| 3193 | |
| 3194 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
| 3195 | Register out = load->GetLocations()->Out().As<Register>(); |
| 3196 | int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value(); |
| 3197 | __ LoadFromOffset(kLoadWord, out, TR, offset); |
| 3198 | __ LoadImmediate(IP, 0); |
| 3199 | __ StoreToOffset(kStoreWord, IP, TR, offset); |
| 3200 | } |
| 3201 | |
| 3202 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 3203 | LocationSummary* locations = |
| 3204 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3205 | InvokeRuntimeCallingConvention calling_convention; |
| 3206 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3207 | } |
| 3208 | |
| 3209 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
| 3210 | codegen_->InvokeRuntime( |
| 3211 | QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc()); |
| 3212 | } |
| 3213 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3214 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3215 | LocationSummary::CallKind call_kind = instruction->IsClassFinal() |
| 3216 | ? LocationSummary::kNoCall |
| 3217 | : LocationSummary::kCallOnSlowPath; |
| 3218 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 3219 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3220 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3221 | locations->SetOut(Location::RequiresRegister()); |
| 3222 | } |
| 3223 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3224 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3225 | LocationSummary* locations = instruction->GetLocations(); |
| 3226 | Register obj = locations->InAt(0).As<Register>(); |
| 3227 | Register cls = locations->InAt(1).As<Register>(); |
| 3228 | Register out = locations->Out().As<Register>(); |
| 3229 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3230 | Label done, zero; |
| 3231 | SlowPathCodeARM* slow_path = nullptr; |
| 3232 | |
| 3233 | // Return 0 if `obj` is null. |
| 3234 | // TODO: avoid this check if we know obj is not null. |
| 3235 | __ cmp(obj, ShifterOperand(0)); |
| 3236 | __ b(&zero, EQ); |
| 3237 | // Compare the class of `obj` with `cls`. |
| 3238 | __ LoadFromOffset(kLoadWord, out, obj, class_offset); |
| 3239 | __ cmp(out, ShifterOperand(cls)); |
| 3240 | if (instruction->IsClassFinal()) { |
| 3241 | // Classes must be equal for the instanceof to succeed. |
| 3242 | __ b(&zero, NE); |
| 3243 | __ LoadImmediate(out, 1); |
| 3244 | __ b(&done); |
| 3245 | } else { |
| 3246 | // If the classes are not equal, we go into a slow path. |
| 3247 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 3248 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM( |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3249 | instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3250 | codegen_->AddSlowPath(slow_path); |
| 3251 | __ b(slow_path->GetEntryLabel(), NE); |
| 3252 | __ LoadImmediate(out, 1); |
| 3253 | __ b(&done); |
| 3254 | } |
| 3255 | __ Bind(&zero); |
| 3256 | __ LoadImmediate(out, 0); |
| 3257 | if (slow_path != nullptr) { |
| 3258 | __ Bind(slow_path->GetExitLabel()); |
| 3259 | } |
| 3260 | __ Bind(&done); |
| 3261 | } |
| 3262 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3263 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
| 3264 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 3265 | instruction, LocationSummary::kCallOnSlowPath); |
| 3266 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3267 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3268 | locations->AddTemp(Location::RequiresRegister()); |
| 3269 | } |
| 3270 | |
| 3271 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
| 3272 | LocationSummary* locations = instruction->GetLocations(); |
| 3273 | Register obj = locations->InAt(0).As<Register>(); |
| 3274 | Register cls = locations->InAt(1).As<Register>(); |
| 3275 | Register temp = locations->GetTemp(0).As<Register>(); |
| 3276 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3277 | |
| 3278 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM( |
| 3279 | instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc()); |
| 3280 | codegen_->AddSlowPath(slow_path); |
| 3281 | |
| 3282 | // TODO: avoid this check if we know obj is not null. |
| 3283 | __ cmp(obj, ShifterOperand(0)); |
| 3284 | __ b(slow_path->GetExitLabel(), EQ); |
| 3285 | // Compare the class of `obj` with `cls`. |
| 3286 | __ LoadFromOffset(kLoadWord, temp, obj, class_offset); |
| 3287 | __ cmp(temp, ShifterOperand(cls)); |
| 3288 | __ b(slow_path->GetEntryLabel(), NE); |
| 3289 | __ Bind(slow_path->GetExitLabel()); |
| 3290 | } |
| 3291 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 3292 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 3293 | LocationSummary* locations = |
| 3294 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3295 | InvokeRuntimeCallingConvention calling_convention; |
| 3296 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3297 | } |
| 3298 | |
| 3299 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 3300 | codegen_->InvokeRuntime(instruction->IsEnter() |
| 3301 | ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject), |
| 3302 | instruction, |
| 3303 | instruction->GetDexPc()); |
| 3304 | } |
| 3305 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3306 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 3307 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 3308 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 3309 | |
| 3310 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 3311 | LocationSummary* locations = |
| 3312 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3313 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 3314 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 3315 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3316 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3317 | bool output_overlaps = (instruction->GetResultType() == Primitive::kPrimLong); |
| 3318 | locations->SetOut(Location::RequiresRegister(), output_overlaps); |
| 3319 | } |
| 3320 | |
| 3321 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 3322 | HandleBitwiseOperation(instruction); |
| 3323 | } |
| 3324 | |
| 3325 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 3326 | HandleBitwiseOperation(instruction); |
| 3327 | } |
| 3328 | |
| 3329 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 3330 | HandleBitwiseOperation(instruction); |
| 3331 | } |
| 3332 | |
| 3333 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 3334 | LocationSummary* locations = instruction->GetLocations(); |
| 3335 | |
| 3336 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3337 | Register first = locations->InAt(0).As<Register>(); |
| 3338 | Register second = locations->InAt(1).As<Register>(); |
| 3339 | Register out = locations->Out().As<Register>(); |
| 3340 | if (instruction->IsAnd()) { |
| 3341 | __ and_(out, first, ShifterOperand(second)); |
| 3342 | } else if (instruction->IsOr()) { |
| 3343 | __ orr(out, first, ShifterOperand(second)); |
| 3344 | } else { |
| 3345 | DCHECK(instruction->IsXor()); |
| 3346 | __ eor(out, first, ShifterOperand(second)); |
| 3347 | } |
| 3348 | } else { |
| 3349 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3350 | Location first = locations->InAt(0); |
| 3351 | Location second = locations->InAt(1); |
| 3352 | Location out = locations->Out(); |
| 3353 | if (instruction->IsAnd()) { |
| 3354 | __ and_(out.AsRegisterPairLow<Register>(), |
| 3355 | first.AsRegisterPairLow<Register>(), |
| 3356 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3357 | __ and_(out.AsRegisterPairHigh<Register>(), |
| 3358 | first.AsRegisterPairHigh<Register>(), |
| 3359 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3360 | } else if (instruction->IsOr()) { |
| 3361 | __ orr(out.AsRegisterPairLow<Register>(), |
| 3362 | first.AsRegisterPairLow<Register>(), |
| 3363 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3364 | __ orr(out.AsRegisterPairHigh<Register>(), |
| 3365 | first.AsRegisterPairHigh<Register>(), |
| 3366 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3367 | } else { |
| 3368 | DCHECK(instruction->IsXor()); |
| 3369 | __ eor(out.AsRegisterPairLow<Register>(), |
| 3370 | first.AsRegisterPairLow<Register>(), |
| 3371 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3372 | __ eor(out.AsRegisterPairHigh<Register>(), |
| 3373 | first.AsRegisterPairHigh<Register>(), |
| 3374 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3375 | } |
| 3376 | } |
| 3377 | } |
| 3378 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 3379 | } // namespace arm |
| 3380 | } // namespace art |