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