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