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