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