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