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