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