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" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 22 | #include "mirror/array-inl.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 23 | #include "mirror/art_method.h" |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 24 | #include "mirror/class.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 25 | #include "thread.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 26 | #include "utils/arm/assembler_arm.h" |
| 27 | #include "utils/arm/managed_register_arm.h" |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 28 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 29 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 30 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 31 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 32 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 33 | namespace arm { |
| 34 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 35 | static DRegister FromLowSToD(SRegister reg) { |
| 36 | DCHECK_EQ(reg % 2, 0); |
| 37 | return static_cast<DRegister>(reg / 2); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 38 | } |
| 39 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 40 | static bool ExpectedPairLayout(Location location) { |
| 41 | // We expected this for both core and fpu register pairs. |
| 42 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 43 | } |
| 44 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 45 | static constexpr int kCurrentMethodStackOffset = 0; |
| 46 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 47 | static constexpr Register kRuntimeParameterCoreRegisters[] = { R0, R1, R2, R3 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 48 | static constexpr size_t kRuntimeParameterCoreRegistersLength = |
| 49 | arraysize(kRuntimeParameterCoreRegisters); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 50 | static constexpr SRegister kRuntimeParameterFpuRegisters[] = { S0, S1, S2, S3 }; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 51 | static constexpr size_t kRuntimeParameterFpuRegistersLength = |
| 52 | arraysize(kRuntimeParameterFpuRegisters); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 53 | // We unconditionally allocate R5 to ensure we can do long operations |
| 54 | // with baseline. |
| 55 | static constexpr Register kCoreSavedRegisterForBaseline = R5; |
| 56 | static constexpr Register kCoreCalleeSaves[] = |
| 57 | { R5, R6, R7, R8, R10, R11, PC }; |
| 58 | static constexpr SRegister kFpuCalleeSaves[] = |
| 59 | { 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] | 60 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 61 | class InvokeRuntimeCallingConvention : public CallingConvention<Register, SRegister> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 62 | public: |
| 63 | InvokeRuntimeCallingConvention() |
| 64 | : CallingConvention(kRuntimeParameterCoreRegisters, |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 65 | kRuntimeParameterCoreRegistersLength, |
| 66 | kRuntimeParameterFpuRegisters, |
| 67 | kRuntimeParameterFpuRegistersLength) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 68 | |
| 69 | private: |
| 70 | DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention); |
| 71 | }; |
| 72 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 73 | #define __ reinterpret_cast<ArmAssembler*>(codegen->GetAssembler())-> |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 74 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 75 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 76 | class SlowPathCodeARM : public SlowPathCode { |
| 77 | public: |
| 78 | SlowPathCodeARM() : entry_label_(), exit_label_() {} |
| 79 | |
| 80 | Label* GetEntryLabel() { return &entry_label_; } |
| 81 | Label* GetExitLabel() { return &exit_label_; } |
| 82 | |
| 83 | private: |
| 84 | Label entry_label_; |
| 85 | Label exit_label_; |
| 86 | |
| 87 | DISALLOW_COPY_AND_ASSIGN(SlowPathCodeARM); |
| 88 | }; |
| 89 | |
| 90 | class NullCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 91 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 92 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 93 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 94 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 95 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 96 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 97 | arm_codegen->InvokeRuntime( |
| 98 | QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 102 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 103 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 104 | }; |
| 105 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 106 | class DivZeroCheckSlowPathARM : public SlowPathCodeARM { |
| 107 | public: |
| 108 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 109 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 110 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 111 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 112 | __ Bind(GetEntryLabel()); |
| 113 | arm_codegen->InvokeRuntime( |
| 114 | QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc()); |
| 115 | } |
| 116 | |
| 117 | private: |
| 118 | HDivZeroCheck* const instruction_; |
| 119 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 120 | }; |
| 121 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 122 | class SuspendCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 123 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 124 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 125 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 126 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 127 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 128 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 129 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 130 | codegen->SaveLiveRegisters(instruction_->GetLocations()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 131 | arm_codegen->InvokeRuntime( |
| 132 | QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 133 | codegen->RestoreLiveRegisters(instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 134 | if (successor_ == nullptr) { |
| 135 | __ b(GetReturnLabel()); |
| 136 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 137 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 138 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 141 | Label* GetReturnLabel() { |
| 142 | DCHECK(successor_ == nullptr); |
| 143 | return &return_label_; |
| 144 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 145 | |
| 146 | private: |
| 147 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 148 | // If not null, the block to branch to after the suspend check. |
| 149 | HBasicBlock* const successor_; |
| 150 | |
| 151 | // 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] | 152 | Label return_label_; |
| 153 | |
| 154 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 155 | }; |
| 156 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 157 | class BoundsCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 158 | public: |
Roland Levillain | 5799fc0 | 2014-09-25 12:15:20 +0100 | [diff] [blame] | 159 | BoundsCheckSlowPathARM(HBoundsCheck* instruction, |
| 160 | Location index_location, |
| 161 | Location length_location) |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 162 | : instruction_(instruction), |
| 163 | index_location_(index_location), |
| 164 | length_location_(length_location) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 165 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 166 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 167 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 168 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 169 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 170 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 171 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 172 | codegen->EmitParallelMoves( |
| 173 | index_location_, |
| 174 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 175 | length_location_, |
| 176 | Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 177 | arm_codegen->InvokeRuntime( |
| 178 | QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 182 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 183 | const Location index_location_; |
| 184 | const Location length_location_; |
| 185 | |
| 186 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 187 | }; |
| 188 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 189 | class LoadClassSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 190 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 191 | LoadClassSlowPathARM(HLoadClass* cls, |
| 192 | HInstruction* at, |
| 193 | uint32_t dex_pc, |
| 194 | bool do_clinit) |
| 195 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 196 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 197 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 198 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 199 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 200 | LocationSummary* locations = at_->GetLocations(); |
| 201 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 202 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 203 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 204 | codegen->SaveLiveRegisters(locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 205 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 206 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 207 | __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 208 | arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 209 | int32_t entry_point_offset = do_clinit_ |
| 210 | ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 211 | : QUICK_ENTRY_POINT(pInitializeType); |
| 212 | arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_); |
| 213 | |
| 214 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 215 | Location out = locations->Out(); |
| 216 | if (out.IsValid()) { |
| 217 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 218 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 219 | } |
| 220 | codegen->RestoreLiveRegisters(locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 221 | __ b(GetExitLabel()); |
| 222 | } |
| 223 | |
| 224 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 225 | // The class this slow path will load. |
| 226 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 227 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 228 | // The instruction where this slow path is happening. |
| 229 | // (Might be the load class or an initialization check). |
| 230 | HInstruction* const at_; |
| 231 | |
| 232 | // The dex PC of `at_`. |
| 233 | const uint32_t dex_pc_; |
| 234 | |
| 235 | // Whether to initialize the class. |
| 236 | const bool do_clinit_; |
| 237 | |
| 238 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 239 | }; |
| 240 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 241 | class LoadStringSlowPathARM : public SlowPathCodeARM { |
| 242 | public: |
| 243 | explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {} |
| 244 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 245 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 246 | LocationSummary* locations = instruction_->GetLocations(); |
| 247 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 248 | |
| 249 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 250 | __ Bind(GetEntryLabel()); |
| 251 | codegen->SaveLiveRegisters(locations); |
| 252 | |
| 253 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 254 | arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
| 255 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 256 | arm_codegen->InvokeRuntime( |
| 257 | QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc()); |
| 258 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 259 | |
| 260 | codegen->RestoreLiveRegisters(locations); |
| 261 | __ b(GetExitLabel()); |
| 262 | } |
| 263 | |
| 264 | private: |
| 265 | HLoadString* const instruction_; |
| 266 | |
| 267 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 268 | }; |
| 269 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 270 | class TypeCheckSlowPathARM : public SlowPathCodeARM { |
| 271 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 272 | TypeCheckSlowPathARM(HInstruction* instruction, |
| 273 | Location class_to_check, |
| 274 | Location object_class, |
| 275 | uint32_t dex_pc) |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 276 | : instruction_(instruction), |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 277 | class_to_check_(class_to_check), |
| 278 | object_class_(object_class), |
| 279 | dex_pc_(dex_pc) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 280 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 281 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 282 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 283 | DCHECK(instruction_->IsCheckCast() |
| 284 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 285 | |
| 286 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 287 | __ Bind(GetEntryLabel()); |
| 288 | codegen->SaveLiveRegisters(locations); |
| 289 | |
| 290 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 291 | // move resolver. |
| 292 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 293 | codegen->EmitParallelMoves( |
| 294 | class_to_check_, |
| 295 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 296 | object_class_, |
| 297 | Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 298 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 299 | if (instruction_->IsInstanceOf()) { |
| 300 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_); |
| 301 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 302 | } else { |
| 303 | DCHECK(instruction_->IsCheckCast()); |
| 304 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_); |
| 305 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 306 | |
| 307 | codegen->RestoreLiveRegisters(locations); |
| 308 | __ b(GetExitLabel()); |
| 309 | } |
| 310 | |
| 311 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 312 | HInstruction* const instruction_; |
| 313 | const Location class_to_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 314 | const Location object_class_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 315 | uint32_t dex_pc_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 316 | |
| 317 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 318 | }; |
| 319 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 320 | #undef __ |
| 321 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 322 | #undef __ |
| 323 | #define __ reinterpret_cast<ArmAssembler*>(GetAssembler())-> |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 324 | |
| 325 | inline Condition ARMCondition(IfCondition cond) { |
| 326 | switch (cond) { |
| 327 | case kCondEQ: return EQ; |
| 328 | case kCondNE: return NE; |
| 329 | case kCondLT: return LT; |
| 330 | case kCondLE: return LE; |
| 331 | case kCondGT: return GT; |
| 332 | case kCondGE: return GE; |
| 333 | default: |
| 334 | LOG(FATAL) << "Unknown if condition"; |
| 335 | } |
| 336 | return EQ; // Unreachable. |
| 337 | } |
| 338 | |
| 339 | inline Condition ARMOppositeCondition(IfCondition cond) { |
| 340 | switch (cond) { |
| 341 | case kCondEQ: return NE; |
| 342 | case kCondNE: return EQ; |
| 343 | case kCondLT: return GE; |
| 344 | case kCondLE: return GT; |
| 345 | case kCondGT: return LE; |
| 346 | case kCondGE: return LT; |
| 347 | default: |
| 348 | LOG(FATAL) << "Unknown if condition"; |
| 349 | } |
| 350 | return EQ; // Unreachable. |
| 351 | } |
| 352 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 353 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 354 | stream << ArmManagedRegister::FromCoreRegister(Register(reg)); |
| 355 | } |
| 356 | |
| 357 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 358 | stream << ArmManagedRegister::FromSRegister(SRegister(reg)); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 359 | } |
| 360 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 361 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 362 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 363 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 364 | } |
| 365 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 366 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 367 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 368 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 369 | } |
| 370 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 371 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 372 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 373 | return kArmWordSize; |
| 374 | } |
| 375 | |
| 376 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 377 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 378 | return kArmWordSize; |
| 379 | } |
| 380 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 381 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 382 | const ArmInstructionSetFeatures& isa_features, |
| 383 | const CompilerOptions& compiler_options) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 384 | : CodeGenerator(graph, |
| 385 | kNumberOfCoreRegisters, |
| 386 | kNumberOfSRegisters, |
| 387 | kNumberOfRegisterPairs, |
| 388 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 389 | arraysize(kCoreCalleeSaves)), |
| 390 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 391 | arraysize(kFpuCalleeSaves)), |
| 392 | compiler_options), |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 393 | block_labels_(graph->GetArena(), 0), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 394 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 395 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 396 | move_resolver_(graph->GetArena(), this), |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 397 | assembler_(true), |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 398 | isa_features_(isa_features) { |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 399 | // Save one extra register for baseline. Note that on thumb2, there is no easy |
| 400 | // instruction to restore just the PC, so this actually helps both baseline |
| 401 | // and non-baseline to save and restore at least two registers at entry and exit. |
| 402 | AddAllocatedRegister(Location::RegisterLocation(kCoreSavedRegisterForBaseline)); |
| 403 | // Save the PC register to mimic Quick. |
| 404 | AddAllocatedRegister(Location::RegisterLocation(PC)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 405 | } |
| 406 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 407 | Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 408 | switch (type) { |
| 409 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 410 | size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 411 | ArmManagedRegister pair = |
| 412 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 413 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); |
| 414 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); |
| 415 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 416 | blocked_core_registers_[pair.AsRegisterPairLow()] = true; |
| 417 | blocked_core_registers_[pair.AsRegisterPairHigh()] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 418 | UpdateBlockedPairRegisters(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 419 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | case Primitive::kPrimByte: |
| 423 | case Primitive::kPrimBoolean: |
| 424 | case Primitive::kPrimChar: |
| 425 | case Primitive::kPrimShort: |
| 426 | case Primitive::kPrimInt: |
| 427 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 428 | int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 429 | // Block all register pairs that contain `reg`. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 430 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 431 | ArmManagedRegister current = |
| 432 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 433 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 434 | blocked_register_pairs_[i] = true; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 435 | } |
| 436 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 437 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 438 | } |
| 439 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 440 | case Primitive::kPrimFloat: { |
| 441 | int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 442 | return Location::FpuRegisterLocation(reg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 443 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 444 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 445 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 3c03503 | 2014-10-28 10:46:40 +0000 | [diff] [blame] | 446 | int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters); |
| 447 | DCHECK_EQ(reg % 2, 0); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 448 | return Location::FpuRegisterPairLocation(reg, reg + 1); |
| 449 | } |
| 450 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 451 | case Primitive::kPrimVoid: |
| 452 | LOG(FATAL) << "Unreachable type " << type; |
| 453 | } |
| 454 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 455 | return Location(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 456 | } |
| 457 | |
Nicolas Geoffray | a0bb2bd | 2015-01-26 12:49:35 +0000 | [diff] [blame] | 458 | void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 459 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 460 | blocked_register_pairs_[R1_R2] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 461 | |
| 462 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 463 | blocked_core_registers_[SP] = true; |
| 464 | blocked_core_registers_[LR] = true; |
| 465 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 466 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 467 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 468 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 469 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 470 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 471 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 472 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 473 | if (is_baseline) { |
| 474 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 475 | blocked_core_registers_[kCoreCalleeSaves[i]] = true; |
| 476 | } |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 477 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 478 | blocked_core_registers_[kCoreSavedRegisterForBaseline] = false; |
| 479 | |
| 480 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 481 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 482 | } |
| 483 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 484 | |
| 485 | UpdateBlockedPairRegisters(); |
| 486 | } |
| 487 | |
| 488 | void CodeGeneratorARM::UpdateBlockedPairRegisters() const { |
| 489 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 490 | ArmManagedRegister current = |
| 491 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 492 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 493 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 494 | blocked_register_pairs_[i] = true; |
| 495 | } |
| 496 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 497 | } |
| 498 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 499 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
| 500 | : HGraphVisitor(graph), |
| 501 | assembler_(codegen->GetAssembler()), |
| 502 | codegen_(codegen) {} |
| 503 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 504 | static uint32_t LeastSignificantBit(uint32_t mask) { |
| 505 | // ffs starts at 1. |
| 506 | return ffs(mask) - 1; |
| 507 | } |
| 508 | |
| 509 | void CodeGeneratorARM::ComputeSpillMask() { |
| 510 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 511 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 512 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 513 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 514 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 515 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 516 | // but in the range. |
| 517 | if (fpu_spill_mask_ != 0) { |
| 518 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 519 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 520 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 521 | fpu_spill_mask_ |= (1 << i); |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 526 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 527 | bool skip_overflow_check = |
| 528 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 529 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame^] | 530 | __ Bind(&frame_entry_label_); |
| 531 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 532 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 533 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 534 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 535 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 536 | } |
| 537 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 538 | // PC is in the list of callee-save to mimic Quick, but we need to push |
| 539 | // LR at entry instead. |
| 540 | __ PushList((core_spill_mask_ & (~(1 << PC))) | 1 << LR); |
| 541 | if (fpu_spill_mask_ != 0) { |
| 542 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 543 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
| 544 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 545 | __ AddConstant(SP, -(GetFrameSize() - FrameEntrySpillSize())); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 546 | __ StoreToOffset(kStoreWord, R0, SP, 0); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 550 | __ AddConstant(SP, GetFrameSize() - FrameEntrySpillSize()); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 551 | if (fpu_spill_mask_ != 0) { |
| 552 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 553 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
| 554 | } |
| 555 | __ PopList(core_spill_mask_); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 556 | } |
| 557 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 558 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
| 559 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 560 | } |
| 561 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 562 | Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const { |
| 563 | switch (load->GetType()) { |
| 564 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 565 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 566 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
| 567 | break; |
| 568 | |
| 569 | case Primitive::kPrimInt: |
| 570 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 571 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 572 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 573 | |
| 574 | case Primitive::kPrimBoolean: |
| 575 | case Primitive::kPrimByte: |
| 576 | case Primitive::kPrimChar: |
| 577 | case Primitive::kPrimShort: |
| 578 | case Primitive::kPrimVoid: |
| 579 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
| 580 | } |
| 581 | |
| 582 | LOG(FATAL) << "Unreachable"; |
| 583 | return Location(); |
| 584 | } |
| 585 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 586 | Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) { |
| 587 | switch (type) { |
| 588 | case Primitive::kPrimBoolean: |
| 589 | case Primitive::kPrimByte: |
| 590 | case Primitive::kPrimChar: |
| 591 | case Primitive::kPrimShort: |
| 592 | case Primitive::kPrimInt: |
| 593 | case Primitive::kPrimNot: { |
| 594 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 595 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 596 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 597 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 598 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 599 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 600 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 601 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 602 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 603 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 604 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 605 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 606 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 607 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 608 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 609 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 610 | // Skip R1, and use R2_R3 instead. |
| 611 | gp_index_++; |
| 612 | index++; |
| 613 | } |
| 614 | } |
| 615 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 616 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 617 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 618 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 619 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 620 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 621 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | case Primitive::kPrimFloat: { |
| 626 | uint32_t stack_index = stack_index_++; |
| 627 | if (float_index_ % 2 == 0) { |
| 628 | float_index_ = std::max(double_index_, float_index_); |
| 629 | } |
| 630 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 631 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 632 | } else { |
| 633 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | case Primitive::kPrimDouble: { |
| 638 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 639 | uint32_t stack_index = stack_index_; |
| 640 | stack_index_ += 2; |
| 641 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 642 | uint32_t index = double_index_; |
| 643 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 644 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 645 | calling_convention.GetFpuRegisterAt(index), |
| 646 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 647 | DCHECK(ExpectedPairLayout(result)); |
| 648 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 649 | } else { |
| 650 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 654 | case Primitive::kPrimVoid: |
| 655 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 656 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 657 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 658 | return Location(); |
| 659 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 660 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 661 | Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) { |
| 662 | switch (type) { |
| 663 | case Primitive::kPrimBoolean: |
| 664 | case Primitive::kPrimByte: |
| 665 | case Primitive::kPrimChar: |
| 666 | case Primitive::kPrimShort: |
| 667 | case Primitive::kPrimInt: |
| 668 | case Primitive::kPrimNot: { |
| 669 | return Location::RegisterLocation(R0); |
| 670 | } |
| 671 | |
| 672 | case Primitive::kPrimFloat: { |
| 673 | return Location::FpuRegisterLocation(S0); |
| 674 | } |
| 675 | |
| 676 | case Primitive::kPrimLong: { |
| 677 | return Location::RegisterPairLocation(R0, R1); |
| 678 | } |
| 679 | |
| 680 | case Primitive::kPrimDouble: { |
| 681 | return Location::FpuRegisterPairLocation(S0, S1); |
| 682 | } |
| 683 | |
| 684 | case Primitive::kPrimVoid: |
| 685 | return Location(); |
| 686 | } |
| 687 | UNREACHABLE(); |
| 688 | return Location(); |
| 689 | } |
| 690 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 691 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 692 | if (source.Equals(destination)) { |
| 693 | return; |
| 694 | } |
| 695 | if (destination.IsRegister()) { |
| 696 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 697 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 698 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 699 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 700 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 701 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 702 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 703 | } else if (destination.IsFpuRegister()) { |
| 704 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 705 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
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 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 708 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 709 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 710 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 711 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 712 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 713 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 714 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 715 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 716 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 717 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 718 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 719 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 720 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 721 | } |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 726 | if (source.Equals(destination)) { |
| 727 | return; |
| 728 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 729 | if (destination.IsRegisterPair()) { |
| 730 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 731 | EmitParallelMoves( |
| 732 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 733 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
| 734 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
| 735 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 736 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 737 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 738 | } else { |
| 739 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 740 | DCHECK(ExpectedPairLayout(destination)); |
| 741 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 742 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 743 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 744 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 745 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 746 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 747 | SP, |
| 748 | source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 749 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 750 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 751 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 752 | } else { |
| 753 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 754 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 755 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 756 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 757 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 758 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 759 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 760 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 761 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 762 | SP, destination.GetStackIndex()); |
| 763 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 764 | } else if (source.IsFpuRegisterPair()) { |
| 765 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 766 | SP, |
| 767 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 768 | } else { |
| 769 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 770 | EmitParallelMoves( |
| 771 | Location::StackSlot(source.GetStackIndex()), |
| 772 | Location::StackSlot(destination.GetStackIndex()), |
| 773 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
| 774 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 775 | } |
| 776 | } |
| 777 | } |
| 778 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 779 | void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 780 | LocationSummary* locations = instruction->GetLocations(); |
| 781 | if (locations != nullptr && locations->Out().Equals(location)) { |
| 782 | return; |
| 783 | } |
| 784 | |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 785 | if (locations != nullptr && locations->Out().IsConstant()) { |
| 786 | HConstant* const_to_move = locations->Out().GetConstant(); |
| 787 | if (const_to_move->IsIntConstant()) { |
| 788 | int32_t value = const_to_move->AsIntConstant()->GetValue(); |
| 789 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 790 | __ LoadImmediate(location.AsRegister<Register>(), value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 791 | } else { |
| 792 | DCHECK(location.IsStackSlot()); |
| 793 | __ LoadImmediate(IP, value); |
| 794 | __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); |
| 795 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 796 | } else { |
Nicolas Geoffray | 3747b48 | 2015-01-19 17:17:16 +0000 | [diff] [blame] | 797 | DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName(); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 798 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 799 | if (location.IsRegisterPair()) { |
| 800 | __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 801 | __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value)); |
| 802 | } else { |
| 803 | DCHECK(location.IsDoubleStackSlot()); |
| 804 | __ LoadImmediate(IP, Low32Bits(value)); |
| 805 | __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); |
| 806 | __ LoadImmediate(IP, High32Bits(value)); |
| 807 | __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize)); |
| 808 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 809 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 810 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 811 | uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
| 812 | switch (instruction->GetType()) { |
| 813 | case Primitive::kPrimBoolean: |
| 814 | case Primitive::kPrimByte: |
| 815 | case Primitive::kPrimChar: |
| 816 | case Primitive::kPrimShort: |
| 817 | case Primitive::kPrimInt: |
| 818 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 819 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 820 | Move32(location, Location::StackSlot(stack_slot)); |
| 821 | break; |
| 822 | |
| 823 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 824 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 825 | Move64(location, Location::DoubleStackSlot(stack_slot)); |
| 826 | break; |
| 827 | |
| 828 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 829 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 830 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 831 | } else if (instruction->IsTemporary()) { |
| 832 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 833 | if (temp_location.IsStackSlot()) { |
| 834 | Move32(location, temp_location); |
| 835 | } else { |
| 836 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 837 | Move64(location, temp_location); |
| 838 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 839 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 840 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 841 | switch (instruction->GetType()) { |
| 842 | case Primitive::kPrimBoolean: |
| 843 | case Primitive::kPrimByte: |
| 844 | case Primitive::kPrimChar: |
| 845 | case Primitive::kPrimShort: |
| 846 | case Primitive::kPrimNot: |
| 847 | case Primitive::kPrimInt: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 848 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 849 | Move32(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 850 | break; |
| 851 | |
| 852 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 853 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 854 | Move64(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 855 | break; |
| 856 | |
| 857 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 858 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 859 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 860 | } |
| 861 | } |
| 862 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 863 | void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset, |
| 864 | HInstruction* instruction, |
| 865 | uint32_t dex_pc) { |
| 866 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 867 | __ blx(LR); |
| 868 | RecordPcInfo(instruction, dex_pc); |
| 869 | DCHECK(instruction->IsSuspendCheck() |
| 870 | || instruction->IsBoundsCheck() |
| 871 | || instruction->IsNullCheck() |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 872 | || instruction->IsDivZeroCheck() |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 873 | || instruction->GetLocations()->CanCall() |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 874 | || !IsLeafMethod()); |
| 875 | } |
| 876 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 877 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 878 | got->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 879 | } |
| 880 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 881 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 882 | HBasicBlock* successor = got->GetSuccessor(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 883 | DCHECK(!successor->IsExitBlock()); |
| 884 | |
| 885 | HBasicBlock* block = got->GetBlock(); |
| 886 | HInstruction* previous = got->GetPrevious(); |
| 887 | |
| 888 | HLoopInformation* info = block->GetLoopInformation(); |
| 889 | if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) { |
| 890 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 891 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 892 | return; |
| 893 | } |
| 894 | |
| 895 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 896 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 897 | } |
| 898 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 899 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 900 | } |
| 901 | } |
| 902 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 903 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 904 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 905 | } |
| 906 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 907 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 908 | UNUSED(exit); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 909 | if (kIsDebugBuild) { |
| 910 | __ Comment("Unreachable"); |
| 911 | __ bkpt(0); |
| 912 | } |
| 913 | } |
| 914 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 915 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 916 | LocationSummary* locations = |
| 917 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 918 | HInstruction* cond = if_instr->InputAt(0); |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 919 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 920 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 921 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 922 | } |
| 923 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 924 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 925 | HInstruction* cond = if_instr->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 926 | if (cond->IsIntConstant()) { |
| 927 | // Constant condition, statically compared against 1. |
| 928 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 929 | if (cond_value == 1) { |
| 930 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 931 | if_instr->IfTrueSuccessor())) { |
| 932 | __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 933 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 934 | return; |
| 935 | } else { |
| 936 | DCHECK_EQ(cond_value, 0); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 937 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 938 | } else { |
| 939 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 940 | // Condition has been materialized, compare the output to 0 |
| 941 | DCHECK(if_instr->GetLocations()->InAt(0).IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 942 | __ cmp(if_instr->GetLocations()->InAt(0).AsRegister<Register>(), |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 943 | ShifterOperand(0)); |
| 944 | __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE); |
| 945 | } else { |
| 946 | // Condition has not been materialized, use its inputs as the |
| 947 | // comparison and its condition as the branch condition. |
| 948 | LocationSummary* locations = cond->GetLocations(); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 949 | DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0); |
Nicolas Geoffray | 3bcc8ea | 2014-11-28 15:00:02 +0000 | [diff] [blame] | 950 | Register left = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 951 | if (locations->InAt(1).IsRegister()) { |
Nicolas Geoffray | 3bcc8ea | 2014-11-28 15:00:02 +0000 | [diff] [blame] | 952 | __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 953 | } else { |
| 954 | DCHECK(locations->InAt(1).IsConstant()); |
| 955 | int32_t value = |
| 956 | locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 957 | ShifterOperand operand; |
Nicolas Geoffray | 3bcc8ea | 2014-11-28 15:00:02 +0000 | [diff] [blame] | 958 | if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) { |
| 959 | __ cmp(left, operand); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 960 | } else { |
| 961 | Register temp = IP; |
| 962 | __ LoadImmediate(temp, value); |
Nicolas Geoffray | 3bcc8ea | 2014-11-28 15:00:02 +0000 | [diff] [blame] | 963 | __ cmp(left, ShifterOperand(temp)); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 964 | } |
| 965 | } |
| 966 | __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), |
| 967 | ARMCondition(cond->AsCondition()->GetCondition())); |
| 968 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 969 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 970 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 971 | if_instr->IfFalseSuccessor())) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 972 | __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 973 | } |
| 974 | } |
| 975 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 976 | |
| 977 | void LocationsBuilderARM::VisitCondition(HCondition* comp) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 978 | LocationSummary* locations = |
| 979 | new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 980 | locations->SetInAt(0, Location::RequiresRegister()); |
| 981 | locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1))); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 982 | if (comp->NeedsMaterialization()) { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 983 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 984 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 985 | } |
| 986 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 987 | void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 988 | if (!comp->NeedsMaterialization()) return; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 989 | LocationSummary* locations = comp->GetLocations(); |
Nicolas Geoffray | 3bcc8ea | 2014-11-28 15:00:02 +0000 | [diff] [blame] | 990 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 991 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 992 | if (locations->InAt(1).IsRegister()) { |
Nicolas Geoffray | 3bcc8ea | 2014-11-28 15:00:02 +0000 | [diff] [blame] | 993 | __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 994 | } else { |
| 995 | DCHECK(locations->InAt(1).IsConstant()); |
| 996 | int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 997 | ShifterOperand operand; |
Nicolas Geoffray | 3bcc8ea | 2014-11-28 15:00:02 +0000 | [diff] [blame] | 998 | if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) { |
| 999 | __ cmp(left, operand); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1000 | } else { |
| 1001 | Register temp = IP; |
| 1002 | __ LoadImmediate(temp, value); |
Nicolas Geoffray | 3bcc8ea | 2014-11-28 15:00:02 +0000 | [diff] [blame] | 1003 | __ cmp(left, ShifterOperand(temp)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1004 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1005 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1006 | __ it(ARMCondition(comp->GetCondition()), kItElse); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1007 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1), |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1008 | ARMCondition(comp->GetCondition())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1009 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0), |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1010 | ARMOppositeCondition(comp->GetCondition())); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
| 1014 | VisitCondition(comp); |
| 1015 | } |
| 1016 | |
| 1017 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
| 1018 | VisitCondition(comp); |
| 1019 | } |
| 1020 | |
| 1021 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
| 1022 | VisitCondition(comp); |
| 1023 | } |
| 1024 | |
| 1025 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
| 1026 | VisitCondition(comp); |
| 1027 | } |
| 1028 | |
| 1029 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
| 1030 | VisitCondition(comp); |
| 1031 | } |
| 1032 | |
| 1033 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
| 1034 | VisitCondition(comp); |
| 1035 | } |
| 1036 | |
| 1037 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1038 | VisitCondition(comp); |
| 1039 | } |
| 1040 | |
| 1041 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1042 | VisitCondition(comp); |
| 1043 | } |
| 1044 | |
| 1045 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
| 1046 | VisitCondition(comp); |
| 1047 | } |
| 1048 | |
| 1049 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
| 1050 | VisitCondition(comp); |
| 1051 | } |
| 1052 | |
| 1053 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1054 | VisitCondition(comp); |
| 1055 | } |
| 1056 | |
| 1057 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1058 | VisitCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | void LocationsBuilderARM::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1062 | local->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1065 | void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) { |
| 1066 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1069 | void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1070 | load->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1073 | void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1074 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1075 | UNUSED(load); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1079 | LocationSummary* locations = |
| 1080 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1081 | switch (store->InputAt(1)->GetType()) { |
| 1082 | case Primitive::kPrimBoolean: |
| 1083 | case Primitive::kPrimByte: |
| 1084 | case Primitive::kPrimChar: |
| 1085 | case Primitive::kPrimShort: |
| 1086 | case Primitive::kPrimInt: |
| 1087 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1088 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1089 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1090 | break; |
| 1091 | |
| 1092 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1093 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1094 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1095 | break; |
| 1096 | |
| 1097 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1098 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1099 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1100 | } |
| 1101 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1102 | void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1103 | UNUSED(store); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1107 | LocationSummary* locations = |
| 1108 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1109 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1112 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1113 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1114 | UNUSED(constant); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1115 | } |
| 1116 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1117 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1118 | LocationSummary* locations = |
| 1119 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1120 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) { |
| 1124 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1125 | UNUSED(constant); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1126 | } |
| 1127 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1128 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 1129 | LocationSummary* locations = |
| 1130 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1131 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1132 | } |
| 1133 | |
| 1134 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) { |
| 1135 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1136 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1140 | LocationSummary* locations = |
| 1141 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1142 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1143 | } |
| 1144 | |
| 1145 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1146 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1147 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1148 | } |
| 1149 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1150 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1151 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1154 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1155 | UNUSED(ret); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1156 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1159 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1160 | LocationSummary* locations = |
| 1161 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1162 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1165 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1166 | UNUSED(ret); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1167 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1168 | } |
| 1169 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1170 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1171 | HandleInvoke(invoke); |
| 1172 | } |
| 1173 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1174 | void CodeGeneratorARM::LoadCurrentMethod(Register reg) { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1175 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1176 | } |
| 1177 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1178 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1179 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1180 | |
| 1181 | // TODO: Implement all kinds of calls: |
| 1182 | // 1) boot -> boot |
| 1183 | // 2) app -> boot |
| 1184 | // 3) app -> app |
| 1185 | // |
| 1186 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
| 1187 | |
| 1188 | // temp = method; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1189 | codegen_->LoadCurrentMethod(temp); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame^] | 1190 | if (!invoke->IsRecursive()) { |
| 1191 | // temp = temp->dex_cache_resolved_methods_; |
| 1192 | __ LoadFromOffset( |
| 1193 | kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value()); |
| 1194 | // temp = temp[index_in_cache] |
| 1195 | __ LoadFromOffset( |
| 1196 | kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex())); |
| 1197 | // LR = temp[offset_of_quick_compiled_code] |
| 1198 | __ LoadFromOffset(kLoadWord, LR, temp, |
| 1199 | mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 1200 | kArmWordSize).Int32Value()); |
| 1201 | // LR() |
| 1202 | __ blx(LR); |
| 1203 | } else { |
| 1204 | __ bl(codegen_->GetFrameEntryLabel()); |
| 1205 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1206 | |
| 1207 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1208 | DCHECK(!codegen_->IsLeafMethod()); |
| 1209 | } |
| 1210 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1211 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1212 | LocationSummary* locations = |
| 1213 | new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1214 | locations->AddTemp(Location::RegisterLocation(R0)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1215 | |
| 1216 | InvokeDexCallingConventionVisitor calling_convention_visitor; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1217 | for (size_t i = 0; i < invoke->InputCount(); i++) { |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1218 | HInstruction* input = invoke->InputAt(i); |
| 1219 | locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType())); |
| 1220 | } |
| 1221 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1222 | locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType())); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1223 | } |
| 1224 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1225 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 1226 | HandleInvoke(invoke); |
| 1227 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1228 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1229 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1230 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1231 | uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() + |
| 1232 | invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry); |
| 1233 | LocationSummary* locations = invoke->GetLocations(); |
| 1234 | Location receiver = locations->InAt(0); |
| 1235 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1236 | // temp = object->GetClass(); |
| 1237 | if (receiver.IsStackSlot()) { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1238 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 1239 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1240 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1241 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1242 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1243 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1244 | // temp = temp->GetMethodAt(method_offset); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 1245 | uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1246 | kArmWordSize).Int32Value(); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1247 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1248 | // LR = temp->GetEntryPoint(); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1249 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1250 | // LR(); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1251 | __ blx(LR); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1252 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1253 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1254 | } |
| 1255 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1256 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1257 | HandleInvoke(invoke); |
| 1258 | // Add the hidden argument. |
| 1259 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 1260 | } |
| 1261 | |
| 1262 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1263 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1264 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1265 | uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() + |
| 1266 | (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry); |
| 1267 | LocationSummary* locations = invoke->GetLocations(); |
| 1268 | Location receiver = locations->InAt(0); |
| 1269 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1270 | |
| 1271 | // Set the hidden argument. |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1272 | __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(), |
| 1273 | invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1274 | |
| 1275 | // temp = object->GetClass(); |
| 1276 | if (receiver.IsStackSlot()) { |
| 1277 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 1278 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 1279 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1280 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1281 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1282 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1283 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 1284 | uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1285 | kArmWordSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1286 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 1287 | // LR = temp->GetEntryPoint(); |
| 1288 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 1289 | // LR(); |
| 1290 | __ blx(LR); |
| 1291 | DCHECK(!codegen_->IsLeafMethod()); |
| 1292 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1293 | } |
| 1294 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1295 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 1296 | LocationSummary* locations = |
| 1297 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1298 | switch (neg->GetResultType()) { |
| 1299 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1300 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1301 | Location::OutputOverlap output_overlaps = (neg->GetResultType() == Primitive::kPrimLong) |
| 1302 | ? Location::kOutputOverlap |
| 1303 | : Location::kNoOutputOverlap; |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1304 | locations->SetInAt(0, Location::RequiresRegister()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1305 | locations->SetOut(Location::RequiresRegister(), output_overlaps); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1306 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1307 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1308 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1309 | case Primitive::kPrimFloat: |
| 1310 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1311 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1312 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1313 | break; |
| 1314 | |
| 1315 | default: |
| 1316 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1317 | } |
| 1318 | } |
| 1319 | |
| 1320 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 1321 | LocationSummary* locations = neg->GetLocations(); |
| 1322 | Location out = locations->Out(); |
| 1323 | Location in = locations->InAt(0); |
| 1324 | switch (neg->GetResultType()) { |
| 1325 | case Primitive::kPrimInt: |
| 1326 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1327 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1328 | break; |
| 1329 | |
| 1330 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1331 | DCHECK(in.IsRegisterPair()); |
| 1332 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 1333 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 1334 | in.AsRegisterPairLow<Register>(), |
| 1335 | ShifterOperand(0)); |
| 1336 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 1337 | // instruction here, as it does not exist in the Thumb-2 |
| 1338 | // instruction set. We use the following approach |
| 1339 | // using SBC and SUB instead. |
| 1340 | // |
| 1341 | // out.hi = -C |
| 1342 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 1343 | out.AsRegisterPairHigh<Register>(), |
| 1344 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 1345 | // out.hi = out.hi - in.hi |
| 1346 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 1347 | out.AsRegisterPairHigh<Register>(), |
| 1348 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 1349 | break; |
| 1350 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1351 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1352 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1353 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1354 | break; |
| 1355 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1356 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1357 | DCHECK(in.IsFpuRegisterPair()); |
| 1358 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1359 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1360 | break; |
| 1361 | |
| 1362 | default: |
| 1363 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1364 | } |
| 1365 | } |
| 1366 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1367 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1368 | Primitive::Type result_type = conversion->GetResultType(); |
| 1369 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1370 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1371 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1372 | // The float-to-long and double-to-long type conversions rely on a |
| 1373 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1374 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1375 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 1376 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1377 | ? LocationSummary::kCall |
| 1378 | : LocationSummary::kNoCall; |
| 1379 | LocationSummary* locations = |
| 1380 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 1381 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1382 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1383 | case Primitive::kPrimByte: |
| 1384 | switch (input_type) { |
| 1385 | case Primitive::kPrimShort: |
| 1386 | case Primitive::kPrimInt: |
| 1387 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1388 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1389 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1390 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1391 | break; |
| 1392 | |
| 1393 | default: |
| 1394 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1395 | << " to " << result_type; |
| 1396 | } |
| 1397 | break; |
| 1398 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1399 | case Primitive::kPrimShort: |
| 1400 | switch (input_type) { |
| 1401 | case Primitive::kPrimByte: |
| 1402 | case Primitive::kPrimInt: |
| 1403 | case Primitive::kPrimChar: |
| 1404 | // Processing a Dex `int-to-short' instruction. |
| 1405 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1406 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1407 | break; |
| 1408 | |
| 1409 | default: |
| 1410 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1411 | << " to " << result_type; |
| 1412 | } |
| 1413 | break; |
| 1414 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1415 | case Primitive::kPrimInt: |
| 1416 | switch (input_type) { |
| 1417 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1418 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1419 | locations->SetInAt(0, Location::Any()); |
| 1420 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1421 | break; |
| 1422 | |
| 1423 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1424 | // Processing a Dex `float-to-int' instruction. |
| 1425 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1426 | locations->SetOut(Location::RequiresRegister()); |
| 1427 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1428 | break; |
| 1429 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1430 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1431 | // Processing a Dex `double-to-int' instruction. |
| 1432 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1433 | locations->SetOut(Location::RequiresRegister()); |
| 1434 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1435 | break; |
| 1436 | |
| 1437 | default: |
| 1438 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1439 | << " to " << result_type; |
| 1440 | } |
| 1441 | break; |
| 1442 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1443 | case Primitive::kPrimLong: |
| 1444 | switch (input_type) { |
| 1445 | case Primitive::kPrimByte: |
| 1446 | case Primitive::kPrimShort: |
| 1447 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1448 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1449 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1450 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1451 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1452 | break; |
| 1453 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1454 | case Primitive::kPrimFloat: { |
| 1455 | // Processing a Dex `float-to-long' instruction. |
| 1456 | InvokeRuntimeCallingConvention calling_convention; |
| 1457 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 1458 | calling_convention.GetFpuRegisterAt(0))); |
| 1459 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 1460 | break; |
| 1461 | } |
| 1462 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1463 | case Primitive::kPrimDouble: { |
| 1464 | // Processing a Dex `double-to-long' instruction. |
| 1465 | InvokeRuntimeCallingConvention calling_convention; |
| 1466 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 1467 | calling_convention.GetFpuRegisterAt(0), |
| 1468 | calling_convention.GetFpuRegisterAt(1))); |
| 1469 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1470 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1471 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1472 | |
| 1473 | default: |
| 1474 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1475 | << " to " << result_type; |
| 1476 | } |
| 1477 | break; |
| 1478 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1479 | case Primitive::kPrimChar: |
| 1480 | switch (input_type) { |
| 1481 | case Primitive::kPrimByte: |
| 1482 | case Primitive::kPrimShort: |
| 1483 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1484 | // Processing a Dex `int-to-char' instruction. |
| 1485 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1486 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1487 | break; |
| 1488 | |
| 1489 | default: |
| 1490 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1491 | << " to " << result_type; |
| 1492 | } |
| 1493 | break; |
| 1494 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1495 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1496 | switch (input_type) { |
| 1497 | case Primitive::kPrimByte: |
| 1498 | case Primitive::kPrimShort: |
| 1499 | case Primitive::kPrimInt: |
| 1500 | case Primitive::kPrimChar: |
| 1501 | // Processing a Dex `int-to-float' instruction. |
| 1502 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1503 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1504 | break; |
| 1505 | |
| 1506 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1507 | // Processing a Dex `long-to-float' instruction. |
| 1508 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1509 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1510 | locations->AddTemp(Location::RequiresRegister()); |
| 1511 | locations->AddTemp(Location::RequiresRegister()); |
| 1512 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1513 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1514 | break; |
| 1515 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1516 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1517 | // Processing a Dex `double-to-float' instruction. |
| 1518 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1519 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1520 | break; |
| 1521 | |
| 1522 | default: |
| 1523 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1524 | << " to " << result_type; |
| 1525 | }; |
| 1526 | break; |
| 1527 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1528 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1529 | switch (input_type) { |
| 1530 | case Primitive::kPrimByte: |
| 1531 | case Primitive::kPrimShort: |
| 1532 | case Primitive::kPrimInt: |
| 1533 | case Primitive::kPrimChar: |
| 1534 | // Processing a Dex `int-to-double' instruction. |
| 1535 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1536 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1537 | break; |
| 1538 | |
| 1539 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1540 | // Processing a Dex `long-to-double' instruction. |
| 1541 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1542 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1543 | locations->AddTemp(Location::RequiresRegister()); |
| 1544 | locations->AddTemp(Location::RequiresRegister()); |
| 1545 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1546 | break; |
| 1547 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1548 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1549 | // Processing a Dex `float-to-double' instruction. |
| 1550 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1551 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1552 | break; |
| 1553 | |
| 1554 | default: |
| 1555 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1556 | << " to " << result_type; |
| 1557 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1558 | break; |
| 1559 | |
| 1560 | default: |
| 1561 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1562 | << " to " << result_type; |
| 1563 | } |
| 1564 | } |
| 1565 | |
| 1566 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 1567 | LocationSummary* locations = conversion->GetLocations(); |
| 1568 | Location out = locations->Out(); |
| 1569 | Location in = locations->InAt(0); |
| 1570 | Primitive::Type result_type = conversion->GetResultType(); |
| 1571 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1572 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1573 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1574 | case Primitive::kPrimByte: |
| 1575 | switch (input_type) { |
| 1576 | case Primitive::kPrimShort: |
| 1577 | case Primitive::kPrimInt: |
| 1578 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1579 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1580 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1581 | break; |
| 1582 | |
| 1583 | default: |
| 1584 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1585 | << " to " << result_type; |
| 1586 | } |
| 1587 | break; |
| 1588 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1589 | case Primitive::kPrimShort: |
| 1590 | switch (input_type) { |
| 1591 | case Primitive::kPrimByte: |
| 1592 | case Primitive::kPrimInt: |
| 1593 | case Primitive::kPrimChar: |
| 1594 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1595 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1596 | break; |
| 1597 | |
| 1598 | default: |
| 1599 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1600 | << " to " << result_type; |
| 1601 | } |
| 1602 | break; |
| 1603 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1604 | case Primitive::kPrimInt: |
| 1605 | switch (input_type) { |
| 1606 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1607 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1608 | DCHECK(out.IsRegister()); |
| 1609 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1610 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1611 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1612 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1613 | } else { |
| 1614 | DCHECK(in.IsConstant()); |
| 1615 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 1616 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1617 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1618 | } |
| 1619 | break; |
| 1620 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1621 | case Primitive::kPrimFloat: { |
| 1622 | // Processing a Dex `float-to-int' instruction. |
| 1623 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
| 1624 | __ vmovs(temp, in.AsFpuRegister<SRegister>()); |
| 1625 | __ vcvtis(temp, temp); |
| 1626 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 1627 | break; |
| 1628 | } |
| 1629 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1630 | case Primitive::kPrimDouble: { |
| 1631 | // Processing a Dex `double-to-int' instruction. |
| 1632 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
| 1633 | DRegister temp_d = FromLowSToD(temp_s); |
| 1634 | __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
| 1635 | __ vcvtid(temp_s, temp_d); |
| 1636 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1637 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1638 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1639 | |
| 1640 | default: |
| 1641 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1642 | << " to " << result_type; |
| 1643 | } |
| 1644 | break; |
| 1645 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1646 | case Primitive::kPrimLong: |
| 1647 | switch (input_type) { |
| 1648 | case Primitive::kPrimByte: |
| 1649 | case Primitive::kPrimShort: |
| 1650 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1651 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1652 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1653 | DCHECK(out.IsRegisterPair()); |
| 1654 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1655 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1656 | // Sign extension. |
| 1657 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 1658 | out.AsRegisterPairLow<Register>(), |
| 1659 | 31); |
| 1660 | break; |
| 1661 | |
| 1662 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1663 | // Processing a Dex `float-to-long' instruction. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1664 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 1665 | conversion, |
| 1666 | conversion->GetDexPc()); |
| 1667 | break; |
| 1668 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1669 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1670 | // Processing a Dex `double-to-long' instruction. |
| 1671 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 1672 | conversion, |
| 1673 | conversion->GetDexPc()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1674 | break; |
| 1675 | |
| 1676 | default: |
| 1677 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1678 | << " to " << result_type; |
| 1679 | } |
| 1680 | break; |
| 1681 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1682 | case Primitive::kPrimChar: |
| 1683 | switch (input_type) { |
| 1684 | case Primitive::kPrimByte: |
| 1685 | case Primitive::kPrimShort: |
| 1686 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1687 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1688 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1689 | break; |
| 1690 | |
| 1691 | default: |
| 1692 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1693 | << " to " << result_type; |
| 1694 | } |
| 1695 | break; |
| 1696 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1697 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1698 | switch (input_type) { |
| 1699 | case Primitive::kPrimByte: |
| 1700 | case Primitive::kPrimShort: |
| 1701 | case Primitive::kPrimInt: |
| 1702 | case Primitive::kPrimChar: { |
| 1703 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1704 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 1705 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1706 | break; |
| 1707 | } |
| 1708 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1709 | case Primitive::kPrimLong: { |
| 1710 | // Processing a Dex `long-to-float' instruction. |
| 1711 | Register low = in.AsRegisterPairLow<Register>(); |
| 1712 | Register high = in.AsRegisterPairHigh<Register>(); |
| 1713 | SRegister output = out.AsFpuRegister<SRegister>(); |
| 1714 | Register constant_low = locations->GetTemp(0).AsRegister<Register>(); |
| 1715 | Register constant_high = locations->GetTemp(1).AsRegister<Register>(); |
| 1716 | SRegister temp1_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>(); |
| 1717 | DRegister temp1_d = FromLowSToD(temp1_s); |
| 1718 | SRegister temp2_s = locations->GetTemp(3).AsFpuRegisterPairLow<SRegister>(); |
| 1719 | DRegister temp2_d = FromLowSToD(temp2_s); |
| 1720 | |
| 1721 | // Operations use doubles for precision reasons (each 32-bit |
| 1722 | // half of a long fits in the 53-bit mantissa of a double, |
| 1723 | // but not in the 24-bit mantissa of a float). This is |
| 1724 | // especially important for the low bits. The result is |
| 1725 | // eventually converted to float. |
| 1726 | |
| 1727 | // temp1_d = int-to-double(high) |
| 1728 | __ vmovsr(temp1_s, high); |
| 1729 | __ vcvtdi(temp1_d, temp1_s); |
| 1730 | // Using vmovd to load the `k2Pow32EncodingForDouble` constant |
| 1731 | // as an immediate value into `temp2_d` does not work, as |
| 1732 | // this instruction only transfers 8 significant bits of its |
| 1733 | // immediate operand. Instead, use two 32-bit core |
| 1734 | // registers to load `k2Pow32EncodingForDouble` into |
| 1735 | // `temp2_d`. |
| 1736 | __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble)); |
| 1737 | __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble)); |
| 1738 | __ vmovdrr(temp2_d, constant_low, constant_high); |
| 1739 | // temp1_d = temp1_d * 2^32 |
| 1740 | __ vmuld(temp1_d, temp1_d, temp2_d); |
| 1741 | // temp2_d = unsigned-to-double(low) |
| 1742 | __ vmovsr(temp2_s, low); |
| 1743 | __ vcvtdu(temp2_d, temp2_s); |
| 1744 | // temp1_d = temp1_d + temp2_d |
| 1745 | __ vaddd(temp1_d, temp1_d, temp2_d); |
| 1746 | // output = double-to-float(temp1_d); |
| 1747 | __ vcvtsd(output, temp1_d); |
| 1748 | break; |
| 1749 | } |
| 1750 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1751 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1752 | // Processing a Dex `double-to-float' instruction. |
| 1753 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 1754 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1755 | break; |
| 1756 | |
| 1757 | default: |
| 1758 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1759 | << " to " << result_type; |
| 1760 | }; |
| 1761 | break; |
| 1762 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1763 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1764 | switch (input_type) { |
| 1765 | case Primitive::kPrimByte: |
| 1766 | case Primitive::kPrimShort: |
| 1767 | case Primitive::kPrimInt: |
| 1768 | case Primitive::kPrimChar: { |
| 1769 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1770 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1771 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1772 | out.AsFpuRegisterPairLow<SRegister>()); |
| 1773 | break; |
| 1774 | } |
| 1775 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1776 | case Primitive::kPrimLong: { |
| 1777 | // Processing a Dex `long-to-double' instruction. |
| 1778 | Register low = in.AsRegisterPairLow<Register>(); |
| 1779 | Register high = in.AsRegisterPairHigh<Register>(); |
| 1780 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 1781 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1782 | Register constant_low = locations->GetTemp(0).AsRegister<Register>(); |
| 1783 | Register constant_high = locations->GetTemp(1).AsRegister<Register>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1784 | SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>(); |
| 1785 | DRegister temp_d = FromLowSToD(temp_s); |
| 1786 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1787 | // out_d = int-to-double(high) |
| 1788 | __ vmovsr(out_s, high); |
| 1789 | __ vcvtdi(out_d, out_s); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1790 | // Using vmovd to load the `k2Pow32EncodingForDouble` constant |
| 1791 | // as an immediate value into `temp_d` does not work, as |
| 1792 | // this instruction only transfers 8 significant bits of its |
| 1793 | // immediate operand. Instead, use two 32-bit core |
| 1794 | // registers to load `k2Pow32EncodingForDouble` into `temp_d`. |
| 1795 | __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble)); |
| 1796 | __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble)); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1797 | __ vmovdrr(temp_d, constant_low, constant_high); |
| 1798 | // out_d = out_d * 2^32 |
| 1799 | __ vmuld(out_d, out_d, temp_d); |
| 1800 | // temp_d = unsigned-to-double(low) |
| 1801 | __ vmovsr(temp_s, low); |
| 1802 | __ vcvtdu(temp_d, temp_s); |
| 1803 | // out_d = out_d + temp_d |
| 1804 | __ vaddd(out_d, out_d, temp_d); |
| 1805 | break; |
| 1806 | } |
| 1807 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1808 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1809 | // Processing a Dex `float-to-double' instruction. |
| 1810 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1811 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1812 | break; |
| 1813 | |
| 1814 | default: |
| 1815 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1816 | << " to " << result_type; |
| 1817 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1818 | break; |
| 1819 | |
| 1820 | default: |
| 1821 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1822 | << " to " << result_type; |
| 1823 | } |
| 1824 | } |
| 1825 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1826 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1827 | LocationSummary* locations = |
| 1828 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1829 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1830 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1831 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1832 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1833 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1834 | break; |
| 1835 | } |
| 1836 | |
| 1837 | case Primitive::kPrimLong: { |
| 1838 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1839 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1840 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1841 | break; |
| 1842 | } |
| 1843 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1844 | case Primitive::kPrimFloat: |
| 1845 | case Primitive::kPrimDouble: { |
| 1846 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1847 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1848 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1849 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1850 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1851 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1852 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1853 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1854 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 1858 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1859 | Location out = locations->Out(); |
| 1860 | Location first = locations->InAt(0); |
| 1861 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1862 | switch (add->GetResultType()) { |
| 1863 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1864 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1865 | __ add(out.AsRegister<Register>(), |
| 1866 | first.AsRegister<Register>(), |
| 1867 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1868 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1869 | __ AddConstant(out.AsRegister<Register>(), |
| 1870 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1871 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1872 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1873 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1874 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1875 | case Primitive::kPrimLong: { |
| 1876 | DCHECK(second.IsRegisterPair()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1877 | __ adds(out.AsRegisterPairLow<Register>(), |
| 1878 | first.AsRegisterPairLow<Register>(), |
| 1879 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 1880 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 1881 | first.AsRegisterPairHigh<Register>(), |
| 1882 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1883 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1884 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1885 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1886 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1887 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 1888 | first.AsFpuRegister<SRegister>(), |
| 1889 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1890 | break; |
| 1891 | |
| 1892 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1893 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1894 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 1895 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1896 | break; |
| 1897 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1898 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1899 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1900 | } |
| 1901 | } |
| 1902 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1903 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1904 | LocationSummary* locations = |
| 1905 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1906 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1907 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1908 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1909 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1910 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1911 | break; |
| 1912 | } |
| 1913 | |
| 1914 | case Primitive::kPrimLong: { |
| 1915 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1916 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1917 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1918 | break; |
| 1919 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1920 | case Primitive::kPrimFloat: |
| 1921 | case Primitive::kPrimDouble: { |
| 1922 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1923 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1924 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1925 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1926 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1927 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1928 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1929 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 1933 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1934 | Location out = locations->Out(); |
| 1935 | Location first = locations->InAt(0); |
| 1936 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1937 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1938 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1939 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1940 | __ sub(out.AsRegister<Register>(), |
| 1941 | first.AsRegister<Register>(), |
| 1942 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1943 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1944 | __ AddConstant(out.AsRegister<Register>(), |
| 1945 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1946 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1947 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1948 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1949 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1950 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1951 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1952 | DCHECK(second.IsRegisterPair()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1953 | __ subs(out.AsRegisterPairLow<Register>(), |
| 1954 | first.AsRegisterPairLow<Register>(), |
| 1955 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 1956 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 1957 | first.AsRegisterPairHigh<Register>(), |
| 1958 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1959 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1960 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1961 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1962 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1963 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 1964 | first.AsFpuRegister<SRegister>(), |
| 1965 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1966 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1970 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1971 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 1972 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1973 | break; |
| 1974 | } |
| 1975 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1976 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1977 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1978 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1979 | } |
| 1980 | } |
| 1981 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1982 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 1983 | LocationSummary* locations = |
| 1984 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 1985 | switch (mul->GetResultType()) { |
| 1986 | case Primitive::kPrimInt: |
| 1987 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1988 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1989 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1990 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1991 | break; |
| 1992 | } |
| 1993 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1994 | case Primitive::kPrimFloat: |
| 1995 | case Primitive::kPrimDouble: { |
| 1996 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1997 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1998 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1999 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2000 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2001 | |
| 2002 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2003 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2004 | } |
| 2005 | } |
| 2006 | |
| 2007 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 2008 | LocationSummary* locations = mul->GetLocations(); |
| 2009 | Location out = locations->Out(); |
| 2010 | Location first = locations->InAt(0); |
| 2011 | Location second = locations->InAt(1); |
| 2012 | switch (mul->GetResultType()) { |
| 2013 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2014 | __ mul(out.AsRegister<Register>(), |
| 2015 | first.AsRegister<Register>(), |
| 2016 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2017 | break; |
| 2018 | } |
| 2019 | case Primitive::kPrimLong: { |
| 2020 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 2021 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 2022 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2023 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 2024 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2025 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2026 | |
| 2027 | // Extra checks to protect caused by the existence of R1_R2. |
| 2028 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 2029 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 2030 | DCHECK_NE(out_hi, in1_lo); |
| 2031 | DCHECK_NE(out_hi, in2_lo); |
| 2032 | |
| 2033 | // input: in1 - 64 bits, in2 - 64 bits |
| 2034 | // output: out |
| 2035 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2036 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2037 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 2038 | |
| 2039 | // IP <- in1.lo * in2.hi |
| 2040 | __ mul(IP, in1_lo, in2_hi); |
| 2041 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2042 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 2043 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 2044 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 2045 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2046 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 2047 | break; |
| 2048 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2049 | |
| 2050 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2051 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 2052 | first.AsFpuRegister<SRegister>(), |
| 2053 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2054 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2055 | } |
| 2056 | |
| 2057 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2058 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2059 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2060 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2061 | break; |
| 2062 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2063 | |
| 2064 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2065 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2066 | } |
| 2067 | } |
| 2068 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2069 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2070 | LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong |
| 2071 | ? LocationSummary::kCall |
| 2072 | : LocationSummary::kNoCall; |
| 2073 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2074 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2075 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2076 | case Primitive::kPrimInt: { |
| 2077 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2078 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2079 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2080 | break; |
| 2081 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2082 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2083 | InvokeRuntimeCallingConvention calling_convention; |
| 2084 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2085 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2086 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2087 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2088 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2089 | break; |
| 2090 | } |
| 2091 | case Primitive::kPrimFloat: |
| 2092 | case Primitive::kPrimDouble: { |
| 2093 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2094 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2095 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2096 | break; |
| 2097 | } |
| 2098 | |
| 2099 | default: |
| 2100 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2101 | } |
| 2102 | } |
| 2103 | |
| 2104 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 2105 | LocationSummary* locations = div->GetLocations(); |
| 2106 | Location out = locations->Out(); |
| 2107 | Location first = locations->InAt(0); |
| 2108 | Location second = locations->InAt(1); |
| 2109 | |
| 2110 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2111 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2112 | __ sdiv(out.AsRegister<Register>(), |
| 2113 | first.AsRegister<Register>(), |
| 2114 | second.AsRegister<Register>()); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2115 | break; |
| 2116 | } |
| 2117 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2118 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2119 | InvokeRuntimeCallingConvention calling_convention; |
| 2120 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2121 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 2122 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 2123 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 2124 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2125 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2126 | |
| 2127 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2128 | break; |
| 2129 | } |
| 2130 | |
| 2131 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2132 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 2133 | first.AsFpuRegister<SRegister>(), |
| 2134 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2135 | break; |
| 2136 | } |
| 2137 | |
| 2138 | case Primitive::kPrimDouble: { |
| 2139 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2140 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2141 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 2142 | break; |
| 2143 | } |
| 2144 | |
| 2145 | default: |
| 2146 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2147 | } |
| 2148 | } |
| 2149 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2150 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2151 | Primitive::Type type = rem->GetResultType(); |
| 2152 | LocationSummary::CallKind call_kind = type == Primitive::kPrimInt |
| 2153 | ? LocationSummary::kNoCall |
| 2154 | : LocationSummary::kCall; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2155 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 2156 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2157 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2158 | case Primitive::kPrimInt: { |
| 2159 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2160 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2161 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2162 | locations->AddTemp(Location::RequiresRegister()); |
| 2163 | break; |
| 2164 | } |
| 2165 | case Primitive::kPrimLong: { |
| 2166 | InvokeRuntimeCallingConvention calling_convention; |
| 2167 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2168 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2169 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2170 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2171 | // The runtime helper puts the output in R2,R3. |
| 2172 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 2173 | break; |
| 2174 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2175 | case Primitive::kPrimFloat: { |
| 2176 | InvokeRuntimeCallingConvention calling_convention; |
| 2177 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 2178 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 2179 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 2180 | break; |
| 2181 | } |
| 2182 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2183 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2184 | InvokeRuntimeCallingConvention calling_convention; |
| 2185 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 2186 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 2187 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 2188 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 2189 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2190 | break; |
| 2191 | } |
| 2192 | |
| 2193 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2194 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2195 | } |
| 2196 | } |
| 2197 | |
| 2198 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 2199 | LocationSummary* locations = rem->GetLocations(); |
| 2200 | Location out = locations->Out(); |
| 2201 | Location first = locations->InAt(0); |
| 2202 | Location second = locations->InAt(1); |
| 2203 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2204 | Primitive::Type type = rem->GetResultType(); |
| 2205 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2206 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2207 | Register reg1 = first.AsRegister<Register>(); |
| 2208 | Register reg2 = second.AsRegister<Register>(); |
| 2209 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2210 | |
| 2211 | // temp = reg1 / reg2 (integer division) |
| 2212 | // temp = temp * reg2 |
| 2213 | // dest = reg1 - temp |
| 2214 | __ sdiv(temp, reg1, reg2); |
| 2215 | __ mul(temp, temp, reg2); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2216 | __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2217 | break; |
| 2218 | } |
| 2219 | |
| 2220 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2221 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc()); |
| 2222 | break; |
| 2223 | } |
| 2224 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2225 | case Primitive::kPrimFloat: { |
| 2226 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc()); |
| 2227 | break; |
| 2228 | } |
| 2229 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2230 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2231 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2232 | break; |
| 2233 | } |
| 2234 | |
| 2235 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2236 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2237 | } |
| 2238 | } |
| 2239 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2240 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2241 | LocationSummary* locations = |
| 2242 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2243 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2244 | if (instruction->HasUses()) { |
| 2245 | locations->SetOut(Location::SameAsFirstInput()); |
| 2246 | } |
| 2247 | } |
| 2248 | |
| 2249 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2250 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
| 2251 | codegen_->AddSlowPath(slow_path); |
| 2252 | |
| 2253 | LocationSummary* locations = instruction->GetLocations(); |
| 2254 | Location value = locations->InAt(0); |
| 2255 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2256 | switch (instruction->GetType()) { |
| 2257 | case Primitive::kPrimInt: { |
| 2258 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2259 | __ cmp(value.AsRegister<Register>(), ShifterOperand(0)); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2260 | __ b(slow_path->GetEntryLabel(), EQ); |
| 2261 | } else { |
| 2262 | DCHECK(value.IsConstant()) << value; |
| 2263 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 2264 | __ b(slow_path->GetEntryLabel()); |
| 2265 | } |
| 2266 | } |
| 2267 | break; |
| 2268 | } |
| 2269 | case Primitive::kPrimLong: { |
| 2270 | if (value.IsRegisterPair()) { |
| 2271 | __ orrs(IP, |
| 2272 | value.AsRegisterPairLow<Register>(), |
| 2273 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 2274 | __ b(slow_path->GetEntryLabel(), EQ); |
| 2275 | } else { |
| 2276 | DCHECK(value.IsConstant()) << value; |
| 2277 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 2278 | __ b(slow_path->GetEntryLabel()); |
| 2279 | } |
| 2280 | } |
| 2281 | break; |
| 2282 | default: |
| 2283 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 2284 | } |
| 2285 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2286 | } |
| 2287 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2288 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 2289 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 2290 | |
| 2291 | LocationSummary::CallKind call_kind = op->GetResultType() == Primitive::kPrimLong |
| 2292 | ? LocationSummary::kCall |
| 2293 | : LocationSummary::kNoCall; |
| 2294 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(op, call_kind); |
| 2295 | |
| 2296 | switch (op->GetResultType()) { |
| 2297 | case Primitive::kPrimInt: { |
| 2298 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2299 | locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1))); |
| 2300 | locations->SetOut(Location::RequiresRegister()); |
| 2301 | break; |
| 2302 | } |
| 2303 | case Primitive::kPrimLong: { |
| 2304 | InvokeRuntimeCallingConvention calling_convention; |
| 2305 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2306 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2307 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2308 | // The runtime helper puts the output in R0,R1. |
| 2309 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2310 | break; |
| 2311 | } |
| 2312 | default: |
| 2313 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 2314 | } |
| 2315 | } |
| 2316 | |
| 2317 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 2318 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 2319 | |
| 2320 | LocationSummary* locations = op->GetLocations(); |
| 2321 | Location out = locations->Out(); |
| 2322 | Location first = locations->InAt(0); |
| 2323 | Location second = locations->InAt(1); |
| 2324 | |
| 2325 | Primitive::Type type = op->GetResultType(); |
| 2326 | switch (type) { |
| 2327 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2328 | Register out_reg = out.AsRegister<Register>(); |
| 2329 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2330 | // Arm doesn't mask the shift count so we need to do it ourselves. |
| 2331 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2332 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2333 | __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue)); |
| 2334 | if (op->IsShl()) { |
| 2335 | __ Lsl(out_reg, first_reg, second_reg); |
| 2336 | } else if (op->IsShr()) { |
| 2337 | __ Asr(out_reg, first_reg, second_reg); |
| 2338 | } else { |
| 2339 | __ Lsr(out_reg, first_reg, second_reg); |
| 2340 | } |
| 2341 | } else { |
| 2342 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2343 | uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue); |
| 2344 | if (shift_value == 0) { // arm does not support shifting with 0 immediate. |
| 2345 | __ Mov(out_reg, first_reg); |
| 2346 | } else if (op->IsShl()) { |
| 2347 | __ Lsl(out_reg, first_reg, shift_value); |
| 2348 | } else if (op->IsShr()) { |
| 2349 | __ Asr(out_reg, first_reg, shift_value); |
| 2350 | } else { |
| 2351 | __ Lsr(out_reg, first_reg, shift_value); |
| 2352 | } |
| 2353 | } |
| 2354 | break; |
| 2355 | } |
| 2356 | case Primitive::kPrimLong: { |
| 2357 | // TODO: Inline the assembly instead of calling the runtime. |
| 2358 | InvokeRuntimeCallingConvention calling_convention; |
| 2359 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2360 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2361 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegister<Register>()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2362 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2363 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2364 | |
| 2365 | int32_t entry_point_offset; |
| 2366 | if (op->IsShl()) { |
| 2367 | entry_point_offset = QUICK_ENTRY_POINT(pShlLong); |
| 2368 | } else if (op->IsShr()) { |
| 2369 | entry_point_offset = QUICK_ENTRY_POINT(pShrLong); |
| 2370 | } else { |
| 2371 | entry_point_offset = QUICK_ENTRY_POINT(pUshrLong); |
| 2372 | } |
| 2373 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 2374 | __ blx(LR); |
| 2375 | break; |
| 2376 | } |
| 2377 | default: |
| 2378 | LOG(FATAL) << "Unexpected operation type " << type; |
| 2379 | } |
| 2380 | } |
| 2381 | |
| 2382 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 2383 | HandleShift(shl); |
| 2384 | } |
| 2385 | |
| 2386 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 2387 | HandleShift(shl); |
| 2388 | } |
| 2389 | |
| 2390 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 2391 | HandleShift(shr); |
| 2392 | } |
| 2393 | |
| 2394 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 2395 | HandleShift(shr); |
| 2396 | } |
| 2397 | |
| 2398 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 2399 | HandleShift(ushr); |
| 2400 | } |
| 2401 | |
| 2402 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 2403 | HandleShift(ushr); |
| 2404 | } |
| 2405 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2406 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2407 | LocationSummary* locations = |
| 2408 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2409 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2410 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2411 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2412 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2413 | } |
| 2414 | |
| 2415 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
| 2416 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2417 | codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2418 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2419 | codegen_->InvokeRuntime( |
| 2420 | QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2421 | } |
| 2422 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2423 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 2424 | LocationSummary* locations = |
| 2425 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 2426 | InvokeRuntimeCallingConvention calling_convention; |
| 2427 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 2428 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2429 | locations->SetOut(Location::RegisterLocation(R0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 2430 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2431 | } |
| 2432 | |
| 2433 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
| 2434 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 2435 | codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2436 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2437 | codegen_->InvokeRuntime( |
| 2438 | QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2439 | } |
| 2440 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2441 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2442 | LocationSummary* locations = |
| 2443 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2444 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 2445 | if (location.IsStackSlot()) { |
| 2446 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 2447 | } else if (location.IsDoubleStackSlot()) { |
| 2448 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2449 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2450 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2451 | } |
| 2452 | |
| 2453 | void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2454 | // Nothing to do, the parameter is already at its location. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2455 | UNUSED(instruction); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2456 | } |
| 2457 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2458 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2459 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2460 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2461 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2462 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 2463 | } |
| 2464 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2465 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 2466 | LocationSummary* locations = not_->GetLocations(); |
| 2467 | Location out = locations->Out(); |
| 2468 | Location in = locations->InAt(0); |
| 2469 | switch (not_->InputAt(0)->GetType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2470 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2471 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2472 | break; |
| 2473 | |
| 2474 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 2475 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 2476 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 2477 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 2478 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2479 | break; |
| 2480 | |
| 2481 | default: |
| 2482 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 2483 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 2484 | } |
| 2485 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2486 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2487 | LocationSummary* locations = |
| 2488 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2489 | switch (compare->InputAt(0)->GetType()) { |
| 2490 | case Primitive::kPrimLong: { |
| 2491 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2492 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2493 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2494 | break; |
| 2495 | } |
| 2496 | case Primitive::kPrimFloat: |
| 2497 | case Primitive::kPrimDouble: { |
| 2498 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2499 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2500 | locations->SetOut(Location::RequiresRegister()); |
| 2501 | break; |
| 2502 | } |
| 2503 | default: |
| 2504 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 2505 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2506 | } |
| 2507 | |
| 2508 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2509 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2510 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2511 | Location left = locations->InAt(0); |
| 2512 | Location right = locations->InAt(1); |
| 2513 | |
| 2514 | Label less, greater, done; |
| 2515 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 2516 | switch (type) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2517 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2518 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 2519 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2520 | __ b(&less, LT); |
| 2521 | __ b(&greater, GT); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2522 | // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags. |
| 2523 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2524 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 2525 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2526 | break; |
| 2527 | } |
| 2528 | case Primitive::kPrimFloat: |
| 2529 | case Primitive::kPrimDouble: { |
| 2530 | __ LoadImmediate(out, 0); |
| 2531 | if (type == Primitive::kPrimFloat) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2532 | __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2533 | } else { |
| 2534 | __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), |
| 2535 | FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); |
| 2536 | } |
| 2537 | __ vmstat(); // transfer FP status register to ARM APSR. |
| 2538 | __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2539 | break; |
| 2540 | } |
| 2541 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2542 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2543 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2544 | __ b(&done, EQ); |
| 2545 | __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats. |
| 2546 | |
| 2547 | __ Bind(&greater); |
| 2548 | __ LoadImmediate(out, 1); |
| 2549 | __ b(&done); |
| 2550 | |
| 2551 | __ Bind(&less); |
| 2552 | __ LoadImmediate(out, -1); |
| 2553 | |
| 2554 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2555 | } |
| 2556 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2557 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2558 | LocationSummary* locations = |
| 2559 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 2560 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 2561 | locations->SetInAt(i, Location::Any()); |
| 2562 | } |
| 2563 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2564 | } |
| 2565 | |
| 2566 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2567 | UNUSED(instruction); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2568 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2569 | } |
| 2570 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2571 | void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 2572 | // TODO (ported from quick): revisit Arm barrier kinds |
| 2573 | DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings |
| 2574 | switch (kind) { |
| 2575 | case MemBarrierKind::kAnyStore: |
| 2576 | case MemBarrierKind::kLoadAny: |
| 2577 | case MemBarrierKind::kAnyAny: { |
| 2578 | flavour = DmbOptions::ISH; |
| 2579 | break; |
| 2580 | } |
| 2581 | case MemBarrierKind::kStoreStore: { |
| 2582 | flavour = DmbOptions::ISHST; |
| 2583 | break; |
| 2584 | } |
| 2585 | default: |
| 2586 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 2587 | } |
| 2588 | __ dmb(flavour); |
| 2589 | } |
| 2590 | |
| 2591 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 2592 | uint32_t offset, |
| 2593 | Register out_lo, |
| 2594 | Register out_hi) { |
| 2595 | if (offset != 0) { |
| 2596 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 2597 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 2598 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2599 | } |
| 2600 | __ ldrexd(out_lo, out_hi, addr); |
| 2601 | } |
| 2602 | |
| 2603 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 2604 | uint32_t offset, |
| 2605 | Register value_lo, |
| 2606 | Register value_hi, |
| 2607 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2608 | Register temp2, |
| 2609 | HInstruction* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2610 | Label fail; |
| 2611 | if (offset != 0) { |
| 2612 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 2613 | __ add(IP, addr, ShifterOperand(temp1)); |
| 2614 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2615 | } |
| 2616 | __ Bind(&fail); |
| 2617 | // We need a load followed by store. (The address used in a STREX instruction must |
| 2618 | // be the same as the address in the most recently executed LDREX instruction.) |
| 2619 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2620 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2621 | __ strexd(temp1, value_lo, value_hi, addr); |
| 2622 | __ cmp(temp1, ShifterOperand(0)); |
| 2623 | __ b(&fail, NE); |
| 2624 | } |
| 2625 | |
| 2626 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 2627 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2628 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2629 | LocationSummary* locations = |
| 2630 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2631 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2632 | locations->SetInAt(1, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2633 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2634 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2635 | Primitive::Type field_type = field_info.GetFieldType(); |
| 2636 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2637 | bool generate_volatile = field_info.IsVolatile() |
| 2638 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2639 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 2640 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2641 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
| 2642 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 2643 | locations->AddTemp(Location::RequiresRegister()); |
| 2644 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2645 | } else if (generate_volatile) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2646 | // Arm encoding have some additional constraints for ldrexd/strexd: |
| 2647 | // - registers need to be consecutive |
| 2648 | // - the first register should be even but not R14. |
| 2649 | // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever |
| 2650 | // enable Arm encoding. |
| 2651 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 2652 | |
| 2653 | locations->AddTemp(Location::RequiresRegister()); |
| 2654 | locations->AddTemp(Location::RequiresRegister()); |
| 2655 | if (field_type == Primitive::kPrimDouble) { |
| 2656 | // For doubles we need two more registers to copy the value. |
| 2657 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 2658 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 2659 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 2660 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2661 | } |
| 2662 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2663 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
| 2664 | const FieldInfo& field_info) { |
| 2665 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2666 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2667 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2668 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 2669 | Location value = locations->InAt(1); |
| 2670 | |
| 2671 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2672 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2673 | Primitive::Type field_type = field_info.GetFieldType(); |
| 2674 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 2675 | |
| 2676 | if (is_volatile) { |
| 2677 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 2678 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2679 | |
| 2680 | switch (field_type) { |
| 2681 | case Primitive::kPrimBoolean: |
| 2682 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2683 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2684 | break; |
| 2685 | } |
| 2686 | |
| 2687 | case Primitive::kPrimShort: |
| 2688 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2689 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2690 | break; |
| 2691 | } |
| 2692 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2693 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2694 | case Primitive::kPrimNot: { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2695 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2696 | break; |
| 2697 | } |
| 2698 | |
| 2699 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2700 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2701 | GenerateWideAtomicStore(base, offset, |
| 2702 | value.AsRegisterPairLow<Register>(), |
| 2703 | value.AsRegisterPairHigh<Register>(), |
| 2704 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2705 | locations->GetTemp(1).AsRegister<Register>(), |
| 2706 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2707 | } else { |
| 2708 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2709 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2710 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2711 | break; |
| 2712 | } |
| 2713 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2714 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2715 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2716 | break; |
| 2717 | } |
| 2718 | |
| 2719 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2720 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2721 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2722 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 2723 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 2724 | |
| 2725 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 2726 | |
| 2727 | GenerateWideAtomicStore(base, offset, |
| 2728 | value_reg_lo, |
| 2729 | value_reg_hi, |
| 2730 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2731 | locations->GetTemp(3).AsRegister<Register>(), |
| 2732 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2733 | } else { |
| 2734 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2735 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2736 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2737 | break; |
| 2738 | } |
| 2739 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2740 | case Primitive::kPrimVoid: |
| 2741 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2742 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2743 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2744 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2745 | // Longs and doubles are handled in the switch. |
| 2746 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 2747 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2748 | } |
| 2749 | |
| 2750 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 2751 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2752 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 2753 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>()); |
| 2754 | } |
| 2755 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2756 | if (is_volatile) { |
| 2757 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 2758 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2759 | } |
| 2760 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2761 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 2762 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2763 | LocationSummary* locations = |
| 2764 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2765 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2766 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2767 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2768 | bool generate_volatile = field_info.IsVolatile() |
| 2769 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2770 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2771 | if (generate_volatile) { |
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()); |
| 3615 | locations->SetOut(Location::RequiresRegister()); |
| 3616 | } |
| 3617 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3618 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3619 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3620 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 3621 | Register cls = locations->InAt(1).AsRegister<Register>(); |
| 3622 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3623 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3624 | Label done, zero; |
| 3625 | SlowPathCodeARM* slow_path = nullptr; |
| 3626 | |
| 3627 | // Return 0 if `obj` is null. |
| 3628 | // TODO: avoid this check if we know obj is not null. |
| 3629 | __ cmp(obj, ShifterOperand(0)); |
| 3630 | __ b(&zero, EQ); |
| 3631 | // Compare the class of `obj` with `cls`. |
| 3632 | __ LoadFromOffset(kLoadWord, out, obj, class_offset); |
| 3633 | __ cmp(out, ShifterOperand(cls)); |
| 3634 | if (instruction->IsClassFinal()) { |
| 3635 | // Classes must be equal for the instanceof to succeed. |
| 3636 | __ b(&zero, NE); |
| 3637 | __ LoadImmediate(out, 1); |
| 3638 | __ b(&done); |
| 3639 | } else { |
| 3640 | // If the classes are not equal, we go into a slow path. |
| 3641 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 3642 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM( |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3643 | instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3644 | codegen_->AddSlowPath(slow_path); |
| 3645 | __ b(slow_path->GetEntryLabel(), NE); |
| 3646 | __ LoadImmediate(out, 1); |
| 3647 | __ b(&done); |
| 3648 | } |
| 3649 | __ Bind(&zero); |
| 3650 | __ LoadImmediate(out, 0); |
| 3651 | if (slow_path != nullptr) { |
| 3652 | __ Bind(slow_path->GetExitLabel()); |
| 3653 | } |
| 3654 | __ Bind(&done); |
| 3655 | } |
| 3656 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3657 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
| 3658 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 3659 | instruction, LocationSummary::kCallOnSlowPath); |
| 3660 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3661 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3662 | locations->AddTemp(Location::RequiresRegister()); |
| 3663 | } |
| 3664 | |
| 3665 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
| 3666 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3667 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 3668 | Register cls = locations->InAt(1).AsRegister<Register>(); |
| 3669 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3670 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3671 | |
| 3672 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM( |
| 3673 | instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc()); |
| 3674 | codegen_->AddSlowPath(slow_path); |
| 3675 | |
| 3676 | // TODO: avoid this check if we know obj is not null. |
| 3677 | __ cmp(obj, ShifterOperand(0)); |
| 3678 | __ b(slow_path->GetExitLabel(), EQ); |
| 3679 | // Compare the class of `obj` with `cls`. |
| 3680 | __ LoadFromOffset(kLoadWord, temp, obj, class_offset); |
| 3681 | __ cmp(temp, ShifterOperand(cls)); |
| 3682 | __ b(slow_path->GetEntryLabel(), NE); |
| 3683 | __ Bind(slow_path->GetExitLabel()); |
| 3684 | } |
| 3685 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 3686 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 3687 | LocationSummary* locations = |
| 3688 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3689 | InvokeRuntimeCallingConvention calling_convention; |
| 3690 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3691 | } |
| 3692 | |
| 3693 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 3694 | codegen_->InvokeRuntime(instruction->IsEnter() |
| 3695 | ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject), |
| 3696 | instruction, |
| 3697 | instruction->GetDexPc()); |
| 3698 | } |
| 3699 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3700 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 3701 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 3702 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 3703 | |
| 3704 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 3705 | LocationSummary* locations = |
| 3706 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3707 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 3708 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 3709 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3710 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3711 | Location::OutputOverlap output_overlaps = (instruction->GetResultType() == Primitive::kPrimLong) |
| 3712 | ? Location::kOutputOverlap |
| 3713 | : Location::kNoOutputOverlap; |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3714 | locations->SetOut(Location::RequiresRegister(), output_overlaps); |
| 3715 | } |
| 3716 | |
| 3717 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 3718 | HandleBitwiseOperation(instruction); |
| 3719 | } |
| 3720 | |
| 3721 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 3722 | HandleBitwiseOperation(instruction); |
| 3723 | } |
| 3724 | |
| 3725 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 3726 | HandleBitwiseOperation(instruction); |
| 3727 | } |
| 3728 | |
| 3729 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 3730 | LocationSummary* locations = instruction->GetLocations(); |
| 3731 | |
| 3732 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3733 | Register first = locations->InAt(0).AsRegister<Register>(); |
| 3734 | Register second = locations->InAt(1).AsRegister<Register>(); |
| 3735 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3736 | if (instruction->IsAnd()) { |
| 3737 | __ and_(out, first, ShifterOperand(second)); |
| 3738 | } else if (instruction->IsOr()) { |
| 3739 | __ orr(out, first, ShifterOperand(second)); |
| 3740 | } else { |
| 3741 | DCHECK(instruction->IsXor()); |
| 3742 | __ eor(out, first, ShifterOperand(second)); |
| 3743 | } |
| 3744 | } else { |
| 3745 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3746 | Location first = locations->InAt(0); |
| 3747 | Location second = locations->InAt(1); |
| 3748 | Location out = locations->Out(); |
| 3749 | if (instruction->IsAnd()) { |
| 3750 | __ and_(out.AsRegisterPairLow<Register>(), |
| 3751 | first.AsRegisterPairLow<Register>(), |
| 3752 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3753 | __ and_(out.AsRegisterPairHigh<Register>(), |
| 3754 | first.AsRegisterPairHigh<Register>(), |
| 3755 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3756 | } else if (instruction->IsOr()) { |
| 3757 | __ orr(out.AsRegisterPairLow<Register>(), |
| 3758 | first.AsRegisterPairLow<Register>(), |
| 3759 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3760 | __ orr(out.AsRegisterPairHigh<Register>(), |
| 3761 | first.AsRegisterPairHigh<Register>(), |
| 3762 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3763 | } else { |
| 3764 | DCHECK(instruction->IsXor()); |
| 3765 | __ eor(out.AsRegisterPairLow<Register>(), |
| 3766 | first.AsRegisterPairLow<Register>(), |
| 3767 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3768 | __ eor(out.AsRegisterPairHigh<Register>(), |
| 3769 | first.AsRegisterPairHigh<Register>(), |
| 3770 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3771 | } |
| 3772 | } |
| 3773 | } |
| 3774 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 3775 | } // namespace arm |
| 3776 | } // namespace art |