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