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