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