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) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame^] | 2090 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 2091 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 2092 | // pLdiv runtime call. |
| 2093 | call_kind = LocationSummary::kCall; |
| 2094 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 2095 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 2096 | // pIdivmod runtime call. |
| 2097 | call_kind = LocationSummary::kCall; |
| 2098 | } |
| 2099 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2100 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2101 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2102 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2103 | case Primitive::kPrimInt: { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame^] | 2104 | if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 2105 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2106 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2107 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2108 | } else { |
| 2109 | InvokeRuntimeCallingConvention calling_convention; |
| 2110 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2111 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2112 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 2113 | // we only need the former. |
| 2114 | locations->SetOut(Location::RegisterLocation(R0)); |
| 2115 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2116 | break; |
| 2117 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2118 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2119 | InvokeRuntimeCallingConvention calling_convention; |
| 2120 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2121 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2122 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2123 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2124 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2125 | break; |
| 2126 | } |
| 2127 | case Primitive::kPrimFloat: |
| 2128 | case Primitive::kPrimDouble: { |
| 2129 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2130 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2131 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2132 | break; |
| 2133 | } |
| 2134 | |
| 2135 | default: |
| 2136 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2137 | } |
| 2138 | } |
| 2139 | |
| 2140 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 2141 | LocationSummary* locations = div->GetLocations(); |
| 2142 | Location out = locations->Out(); |
| 2143 | Location first = locations->InAt(0); |
| 2144 | Location second = locations->InAt(1); |
| 2145 | |
| 2146 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2147 | case Primitive::kPrimInt: { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame^] | 2148 | if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 2149 | __ sdiv(out.AsRegister<Register>(), |
| 2150 | first.AsRegister<Register>(), |
| 2151 | second.AsRegister<Register>()); |
| 2152 | } else { |
| 2153 | InvokeRuntimeCallingConvention calling_convention; |
| 2154 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 2155 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 2156 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 2157 | |
| 2158 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr); |
| 2159 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2160 | break; |
| 2161 | } |
| 2162 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2163 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2164 | InvokeRuntimeCallingConvention calling_convention; |
| 2165 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2166 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 2167 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 2168 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 2169 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2170 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2171 | |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2172 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2173 | break; |
| 2174 | } |
| 2175 | |
| 2176 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2177 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 2178 | first.AsFpuRegister<SRegister>(), |
| 2179 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2180 | break; |
| 2181 | } |
| 2182 | |
| 2183 | case Primitive::kPrimDouble: { |
| 2184 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2185 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2186 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 2187 | break; |
| 2188 | } |
| 2189 | |
| 2190 | default: |
| 2191 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2192 | } |
| 2193 | } |
| 2194 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2195 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2196 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame^] | 2197 | |
| 2198 | // Most remainders are implemented in the runtime. |
| 2199 | LocationSummary::CallKind call_kind = LocationSummary::kCall; |
| 2200 | if (rem->GetResultType() == Primitive::kPrimInt && |
| 2201 | codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 2202 | // Have hardware divide instruction for int, do it with three instructions. |
| 2203 | call_kind = LocationSummary::kNoCall; |
| 2204 | } |
| 2205 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2206 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 2207 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2208 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2209 | case Primitive::kPrimInt: { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame^] | 2210 | if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 2211 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2212 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2213 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2214 | locations->AddTemp(Location::RequiresRegister()); |
| 2215 | } else { |
| 2216 | InvokeRuntimeCallingConvention calling_convention; |
| 2217 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2218 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2219 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 2220 | // we only need the latter. |
| 2221 | locations->SetOut(Location::RegisterLocation(R1)); |
| 2222 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2223 | break; |
| 2224 | } |
| 2225 | case Primitive::kPrimLong: { |
| 2226 | InvokeRuntimeCallingConvention calling_convention; |
| 2227 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2228 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2229 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2230 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2231 | // The runtime helper puts the output in R2,R3. |
| 2232 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 2233 | break; |
| 2234 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2235 | case Primitive::kPrimFloat: { |
| 2236 | InvokeRuntimeCallingConvention calling_convention; |
| 2237 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 2238 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 2239 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 2240 | break; |
| 2241 | } |
| 2242 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2243 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2244 | InvokeRuntimeCallingConvention calling_convention; |
| 2245 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 2246 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 2247 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 2248 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 2249 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2250 | break; |
| 2251 | } |
| 2252 | |
| 2253 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2254 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2255 | } |
| 2256 | } |
| 2257 | |
| 2258 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 2259 | LocationSummary* locations = rem->GetLocations(); |
| 2260 | Location out = locations->Out(); |
| 2261 | Location first = locations->InAt(0); |
| 2262 | Location second = locations->InAt(1); |
| 2263 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2264 | Primitive::Type type = rem->GetResultType(); |
| 2265 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2266 | case Primitive::kPrimInt: { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame^] | 2267 | if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 2268 | Register reg1 = first.AsRegister<Register>(); |
| 2269 | Register reg2 = second.AsRegister<Register>(); |
| 2270 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2271 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame^] | 2272 | // temp = reg1 / reg2 (integer division) |
| 2273 | // temp = temp * reg2 |
| 2274 | // dest = reg1 - temp |
| 2275 | __ sdiv(temp, reg1, reg2); |
| 2276 | __ mul(temp, temp, reg2); |
| 2277 | __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp)); |
| 2278 | } else { |
| 2279 | InvokeRuntimeCallingConvention calling_convention; |
| 2280 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 2281 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 2282 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 2283 | |
| 2284 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr); |
| 2285 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2286 | break; |
| 2287 | } |
| 2288 | |
| 2289 | case Primitive::kPrimLong: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2290 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2291 | break; |
| 2292 | } |
| 2293 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2294 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2295 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2296 | break; |
| 2297 | } |
| 2298 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2299 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2300 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2301 | break; |
| 2302 | } |
| 2303 | |
| 2304 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2305 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2306 | } |
| 2307 | } |
| 2308 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2309 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2310 | LocationSummary* locations = |
| 2311 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2312 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2313 | if (instruction->HasUses()) { |
| 2314 | locations->SetOut(Location::SameAsFirstInput()); |
| 2315 | } |
| 2316 | } |
| 2317 | |
| 2318 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2319 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
| 2320 | codegen_->AddSlowPath(slow_path); |
| 2321 | |
| 2322 | LocationSummary* locations = instruction->GetLocations(); |
| 2323 | Location value = locations->InAt(0); |
| 2324 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2325 | switch (instruction->GetType()) { |
| 2326 | case Primitive::kPrimInt: { |
| 2327 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2328 | __ cmp(value.AsRegister<Register>(), ShifterOperand(0)); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2329 | __ b(slow_path->GetEntryLabel(), EQ); |
| 2330 | } else { |
| 2331 | DCHECK(value.IsConstant()) << value; |
| 2332 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 2333 | __ b(slow_path->GetEntryLabel()); |
| 2334 | } |
| 2335 | } |
| 2336 | break; |
| 2337 | } |
| 2338 | case Primitive::kPrimLong: { |
| 2339 | if (value.IsRegisterPair()) { |
| 2340 | __ orrs(IP, |
| 2341 | value.AsRegisterPairLow<Register>(), |
| 2342 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 2343 | __ b(slow_path->GetEntryLabel(), EQ); |
| 2344 | } else { |
| 2345 | DCHECK(value.IsConstant()) << value; |
| 2346 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 2347 | __ b(slow_path->GetEntryLabel()); |
| 2348 | } |
| 2349 | } |
| 2350 | break; |
| 2351 | default: |
| 2352 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 2353 | } |
| 2354 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2355 | } |
| 2356 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2357 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 2358 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 2359 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2360 | LocationSummary* locations = |
| 2361 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2362 | |
| 2363 | switch (op->GetResultType()) { |
| 2364 | case Primitive::kPrimInt: { |
| 2365 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2366 | locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1))); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2367 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2368 | break; |
| 2369 | } |
| 2370 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2371 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2372 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2373 | locations->AddTemp(Location::RequiresRegister()); |
| 2374 | locations->SetOut(Location::RequiresRegister()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2375 | break; |
| 2376 | } |
| 2377 | default: |
| 2378 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 2379 | } |
| 2380 | } |
| 2381 | |
| 2382 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 2383 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 2384 | |
| 2385 | LocationSummary* locations = op->GetLocations(); |
| 2386 | Location out = locations->Out(); |
| 2387 | Location first = locations->InAt(0); |
| 2388 | Location second = locations->InAt(1); |
| 2389 | |
| 2390 | Primitive::Type type = op->GetResultType(); |
| 2391 | switch (type) { |
| 2392 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2393 | Register out_reg = out.AsRegister<Register>(); |
| 2394 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2395 | // Arm doesn't mask the shift count so we need to do it ourselves. |
| 2396 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2397 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2398 | __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue)); |
| 2399 | if (op->IsShl()) { |
| 2400 | __ Lsl(out_reg, first_reg, second_reg); |
| 2401 | } else if (op->IsShr()) { |
| 2402 | __ Asr(out_reg, first_reg, second_reg); |
| 2403 | } else { |
| 2404 | __ Lsr(out_reg, first_reg, second_reg); |
| 2405 | } |
| 2406 | } else { |
| 2407 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2408 | uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue); |
| 2409 | if (shift_value == 0) { // arm does not support shifting with 0 immediate. |
| 2410 | __ Mov(out_reg, first_reg); |
| 2411 | } else if (op->IsShl()) { |
| 2412 | __ Lsl(out_reg, first_reg, shift_value); |
| 2413 | } else if (op->IsShr()) { |
| 2414 | __ Asr(out_reg, first_reg, shift_value); |
| 2415 | } else { |
| 2416 | __ Lsr(out_reg, first_reg, shift_value); |
| 2417 | } |
| 2418 | } |
| 2419 | break; |
| 2420 | } |
| 2421 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2422 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 2423 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2424 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2425 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2426 | |
| 2427 | Register high = first.AsRegisterPairHigh<Register>(); |
| 2428 | Register low = first.AsRegisterPairLow<Register>(); |
| 2429 | |
| 2430 | Register second_reg = second.AsRegister<Register>(); |
| 2431 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2432 | if (op->IsShl()) { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2433 | // Shift the high part |
| 2434 | __ and_(second_reg, second_reg, ShifterOperand(63)); |
| 2435 | __ Lsl(o_h, high, second_reg); |
| 2436 | // Shift the low part and `or` what overflew on the high part |
| 2437 | __ rsb(temp, second_reg, ShifterOperand(32)); |
| 2438 | __ Lsr(temp, low, temp); |
| 2439 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 2440 | // If the shift is > 32 bits, override the high part |
| 2441 | __ subs(temp, second_reg, ShifterOperand(32)); |
| 2442 | __ it(PL); |
| 2443 | __ Lsl(o_h, low, temp, false, PL); |
| 2444 | // Shift the low part |
| 2445 | __ Lsl(o_l, low, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2446 | } else if (op->IsShr()) { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2447 | // Shift the low part |
| 2448 | __ and_(second_reg, second_reg, ShifterOperand(63)); |
| 2449 | __ Lsr(o_l, low, second_reg); |
| 2450 | // Shift the high part and `or` what underflew on the low part |
| 2451 | __ rsb(temp, second_reg, ShifterOperand(32)); |
| 2452 | __ Lsl(temp, high, temp); |
| 2453 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 2454 | // If the shift is > 32 bits, override the low part |
| 2455 | __ subs(temp, second_reg, ShifterOperand(32)); |
| 2456 | __ it(PL); |
| 2457 | __ Asr(o_l, high, temp, false, PL); |
| 2458 | // Shift the high part |
| 2459 | __ Asr(o_h, high, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2460 | } else { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2461 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 2462 | __ and_(second_reg, second_reg, ShifterOperand(63)); |
| 2463 | __ Lsr(o_l, low, second_reg); |
| 2464 | __ rsb(temp, second_reg, ShifterOperand(32)); |
| 2465 | __ Lsl(temp, high, temp); |
| 2466 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 2467 | __ subs(temp, second_reg, ShifterOperand(32)); |
| 2468 | __ it(PL); |
| 2469 | __ Lsr(o_l, high, temp, false, PL); |
| 2470 | __ Lsr(o_h, high, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2471 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2472 | break; |
| 2473 | } |
| 2474 | default: |
| 2475 | LOG(FATAL) << "Unexpected operation type " << type; |
| 2476 | } |
| 2477 | } |
| 2478 | |
| 2479 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 2480 | HandleShift(shl); |
| 2481 | } |
| 2482 | |
| 2483 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 2484 | HandleShift(shl); |
| 2485 | } |
| 2486 | |
| 2487 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 2488 | HandleShift(shr); |
| 2489 | } |
| 2490 | |
| 2491 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 2492 | HandleShift(shr); |
| 2493 | } |
| 2494 | |
| 2495 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 2496 | HandleShift(ushr); |
| 2497 | } |
| 2498 | |
| 2499 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 2500 | HandleShift(ushr); |
| 2501 | } |
| 2502 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2503 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2504 | LocationSummary* locations = |
| 2505 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2506 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2507 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2508 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2509 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2510 | } |
| 2511 | |
| 2512 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
| 2513 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2514 | codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2515 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2516 | codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(), |
| 2517 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2518 | instruction->GetDexPc(), |
| 2519 | nullptr); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2520 | } |
| 2521 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2522 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 2523 | LocationSummary* locations = |
| 2524 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 2525 | InvokeRuntimeCallingConvention calling_convention; |
| 2526 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 2527 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2528 | locations->SetOut(Location::RegisterLocation(R0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 2529 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
| 2533 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 2534 | codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2535 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2536 | codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(), |
| 2537 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2538 | instruction->GetDexPc(), |
| 2539 | nullptr); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2540 | } |
| 2541 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2542 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2543 | LocationSummary* locations = |
| 2544 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2545 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 2546 | if (location.IsStackSlot()) { |
| 2547 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 2548 | } else if (location.IsDoubleStackSlot()) { |
| 2549 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2550 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2551 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2552 | } |
| 2553 | |
| 2554 | void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2555 | // Nothing to do, the parameter is already at its location. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2556 | UNUSED(instruction); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2557 | } |
| 2558 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2559 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2560 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2561 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2562 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2563 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 2564 | } |
| 2565 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2566 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 2567 | LocationSummary* locations = not_->GetLocations(); |
| 2568 | Location out = locations->Out(); |
| 2569 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 2570 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2571 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2572 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2573 | break; |
| 2574 | |
| 2575 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 2576 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 2577 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 2578 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 2579 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2580 | break; |
| 2581 | |
| 2582 | default: |
| 2583 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 2584 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 2585 | } |
| 2586 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2587 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2588 | LocationSummary* locations = |
| 2589 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2590 | switch (compare->InputAt(0)->GetType()) { |
| 2591 | case Primitive::kPrimLong: { |
| 2592 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2593 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2594 | // Output overlaps because it is written before doing the low comparison. |
| 2595 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2596 | break; |
| 2597 | } |
| 2598 | case Primitive::kPrimFloat: |
| 2599 | case Primitive::kPrimDouble: { |
| 2600 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2601 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2602 | locations->SetOut(Location::RequiresRegister()); |
| 2603 | break; |
| 2604 | } |
| 2605 | default: |
| 2606 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 2607 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2608 | } |
| 2609 | |
| 2610 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2611 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2612 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2613 | Location left = locations->InAt(0); |
| 2614 | Location right = locations->InAt(1); |
| 2615 | |
| 2616 | Label less, greater, done; |
| 2617 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 2618 | switch (type) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2619 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2620 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 2621 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2622 | __ b(&less, LT); |
| 2623 | __ b(&greater, GT); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2624 | // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags. |
| 2625 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2626 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 2627 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2628 | break; |
| 2629 | } |
| 2630 | case Primitive::kPrimFloat: |
| 2631 | case Primitive::kPrimDouble: { |
| 2632 | __ LoadImmediate(out, 0); |
| 2633 | if (type == Primitive::kPrimFloat) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2634 | __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2635 | } else { |
| 2636 | __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), |
| 2637 | FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); |
| 2638 | } |
| 2639 | __ vmstat(); // transfer FP status register to ARM APSR. |
| 2640 | __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2641 | break; |
| 2642 | } |
| 2643 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2644 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2645 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2646 | __ b(&done, EQ); |
| 2647 | __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats. |
| 2648 | |
| 2649 | __ Bind(&greater); |
| 2650 | __ LoadImmediate(out, 1); |
| 2651 | __ b(&done); |
| 2652 | |
| 2653 | __ Bind(&less); |
| 2654 | __ LoadImmediate(out, -1); |
| 2655 | |
| 2656 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2657 | } |
| 2658 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2659 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2660 | LocationSummary* locations = |
| 2661 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 2662 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 2663 | locations->SetInAt(i, Location::Any()); |
| 2664 | } |
| 2665 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2666 | } |
| 2667 | |
| 2668 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2669 | UNUSED(instruction); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2670 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2671 | } |
| 2672 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2673 | void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 2674 | // TODO (ported from quick): revisit Arm barrier kinds |
| 2675 | DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings |
| 2676 | switch (kind) { |
| 2677 | case MemBarrierKind::kAnyStore: |
| 2678 | case MemBarrierKind::kLoadAny: |
| 2679 | case MemBarrierKind::kAnyAny: { |
| 2680 | flavour = DmbOptions::ISH; |
| 2681 | break; |
| 2682 | } |
| 2683 | case MemBarrierKind::kStoreStore: { |
| 2684 | flavour = DmbOptions::ISHST; |
| 2685 | break; |
| 2686 | } |
| 2687 | default: |
| 2688 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 2689 | } |
| 2690 | __ dmb(flavour); |
| 2691 | } |
| 2692 | |
| 2693 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 2694 | uint32_t offset, |
| 2695 | Register out_lo, |
| 2696 | Register out_hi) { |
| 2697 | if (offset != 0) { |
| 2698 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 2699 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 2700 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2701 | } |
| 2702 | __ ldrexd(out_lo, out_hi, addr); |
| 2703 | } |
| 2704 | |
| 2705 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 2706 | uint32_t offset, |
| 2707 | Register value_lo, |
| 2708 | Register value_hi, |
| 2709 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2710 | Register temp2, |
| 2711 | HInstruction* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2712 | Label fail; |
| 2713 | if (offset != 0) { |
| 2714 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 2715 | __ add(IP, addr, ShifterOperand(temp1)); |
| 2716 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2717 | } |
| 2718 | __ Bind(&fail); |
| 2719 | // We need a load followed by store. (The address used in a STREX instruction must |
| 2720 | // be the same as the address in the most recently executed LDREX instruction.) |
| 2721 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2722 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2723 | __ strexd(temp1, value_lo, value_hi, addr); |
| 2724 | __ cmp(temp1, ShifterOperand(0)); |
| 2725 | __ b(&fail, NE); |
| 2726 | } |
| 2727 | |
| 2728 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 2729 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2730 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2731 | LocationSummary* locations = |
| 2732 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2733 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2734 | locations->SetInAt(1, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2735 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2736 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2737 | Primitive::Type field_type = field_info.GetFieldType(); |
| 2738 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2739 | bool generate_volatile = field_info.IsVolatile() |
| 2740 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2741 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 2742 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2743 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
| 2744 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 2745 | locations->AddTemp(Location::RequiresRegister()); |
| 2746 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2747 | } else if (generate_volatile) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2748 | // Arm encoding have some additional constraints for ldrexd/strexd: |
| 2749 | // - registers need to be consecutive |
| 2750 | // - the first register should be even but not R14. |
| 2751 | // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever |
| 2752 | // enable Arm encoding. |
| 2753 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 2754 | |
| 2755 | locations->AddTemp(Location::RequiresRegister()); |
| 2756 | locations->AddTemp(Location::RequiresRegister()); |
| 2757 | if (field_type == Primitive::kPrimDouble) { |
| 2758 | // For doubles we need two more registers to copy the value. |
| 2759 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 2760 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 2761 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 2762 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2763 | } |
| 2764 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2765 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
| 2766 | const FieldInfo& field_info) { |
| 2767 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2768 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2769 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2770 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 2771 | Location value = locations->InAt(1); |
| 2772 | |
| 2773 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2774 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2775 | Primitive::Type field_type = field_info.GetFieldType(); |
| 2776 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 2777 | |
| 2778 | if (is_volatile) { |
| 2779 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 2780 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2781 | |
| 2782 | switch (field_type) { |
| 2783 | case Primitive::kPrimBoolean: |
| 2784 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2785 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2786 | break; |
| 2787 | } |
| 2788 | |
| 2789 | case Primitive::kPrimShort: |
| 2790 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2791 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2792 | break; |
| 2793 | } |
| 2794 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2795 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2796 | case Primitive::kPrimNot: { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2797 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2798 | break; |
| 2799 | } |
| 2800 | |
| 2801 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2802 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2803 | GenerateWideAtomicStore(base, offset, |
| 2804 | value.AsRegisterPairLow<Register>(), |
| 2805 | value.AsRegisterPairHigh<Register>(), |
| 2806 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2807 | locations->GetTemp(1).AsRegister<Register>(), |
| 2808 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2809 | } else { |
| 2810 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2811 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2812 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2813 | break; |
| 2814 | } |
| 2815 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2816 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2817 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2818 | break; |
| 2819 | } |
| 2820 | |
| 2821 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2822 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2823 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2824 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 2825 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 2826 | |
| 2827 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 2828 | |
| 2829 | GenerateWideAtomicStore(base, offset, |
| 2830 | value_reg_lo, |
| 2831 | value_reg_hi, |
| 2832 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2833 | locations->GetTemp(3).AsRegister<Register>(), |
| 2834 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2835 | } else { |
| 2836 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2837 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2838 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2839 | break; |
| 2840 | } |
| 2841 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2842 | case Primitive::kPrimVoid: |
| 2843 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2844 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2845 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2846 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2847 | // Longs and doubles are handled in the switch. |
| 2848 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 2849 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2850 | } |
| 2851 | |
| 2852 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 2853 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2854 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 2855 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>()); |
| 2856 | } |
| 2857 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2858 | if (is_volatile) { |
| 2859 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 2860 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2861 | } |
| 2862 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2863 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 2864 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2865 | LocationSummary* locations = |
| 2866 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2867 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2868 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2869 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2870 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2871 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2872 | bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong); |
| 2873 | locations->SetOut(Location::RequiresRegister(), |
| 2874 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 2875 | if (volatile_for_double) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2876 | // Arm encoding have some additional constraints for ldrexd/strexd: |
| 2877 | // - registers need to be consecutive |
| 2878 | // - the first register should be even but not R14. |
| 2879 | // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever |
| 2880 | // enable Arm encoding. |
| 2881 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 2882 | locations->AddTemp(Location::RequiresRegister()); |
| 2883 | locations->AddTemp(Location::RequiresRegister()); |
| 2884 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2885 | } |
| 2886 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2887 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 2888 | const FieldInfo& field_info) { |
| 2889 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2890 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2891 | LocationSummary* locations = instruction->GetLocations(); |
| 2892 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 2893 | Location out = locations->Out(); |
| 2894 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2895 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2896 | Primitive::Type field_type = field_info.GetFieldType(); |
| 2897 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 2898 | |
| 2899 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2900 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2901 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2902 | break; |
| 2903 | } |
| 2904 | |
| 2905 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2906 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2907 | break; |
| 2908 | } |
| 2909 | |
| 2910 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2911 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2912 | break; |
| 2913 | } |
| 2914 | |
| 2915 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2916 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2917 | break; |
| 2918 | } |
| 2919 | |
| 2920 | case Primitive::kPrimInt: |
| 2921 | case Primitive::kPrimNot: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2922 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2923 | break; |
| 2924 | } |
| 2925 | |
| 2926 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2927 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2928 | GenerateWideAtomicLoad(base, offset, |
| 2929 | out.AsRegisterPairLow<Register>(), |
| 2930 | out.AsRegisterPairHigh<Register>()); |
| 2931 | } else { |
| 2932 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 2933 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2934 | break; |
| 2935 | } |
| 2936 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2937 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2938 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2939 | break; |
| 2940 | } |
| 2941 | |
| 2942 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2943 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2944 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2945 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 2946 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 2947 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2948 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2949 | __ vmovdrr(out_reg, lo, hi); |
| 2950 | } else { |
| 2951 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2952 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2953 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2954 | break; |
| 2955 | } |
| 2956 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2957 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2958 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2959 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2960 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2961 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2962 | // Doubles are handled in the switch. |
| 2963 | if (field_type != Primitive::kPrimDouble) { |
| 2964 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2965 | } |
| 2966 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2967 | if (is_volatile) { |
| 2968 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 2969 | } |
| 2970 | } |
| 2971 | |
| 2972 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 2973 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 2974 | } |
| 2975 | |
| 2976 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 2977 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 2978 | } |
| 2979 | |
| 2980 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 2981 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 2982 | } |
| 2983 | |
| 2984 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 2985 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 2986 | } |
| 2987 | |
| 2988 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 2989 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 2990 | } |
| 2991 | |
| 2992 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 2993 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 2994 | } |
| 2995 | |
| 2996 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 2997 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 2998 | } |
| 2999 | |
| 3000 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3001 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3002 | } |
| 3003 | |
| 3004 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3005 | LocationSummary* locations = |
| 3006 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3007 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3008 | if (instruction->HasUses()) { |
| 3009 | locations->SetOut(Location::SameAsFirstInput()); |
| 3010 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3011 | } |
| 3012 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3013 | void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3014 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 3015 | return; |
| 3016 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3017 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3018 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3019 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
| 3020 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3021 | } |
| 3022 | |
| 3023 | void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 3024 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3025 | codegen_->AddSlowPath(slow_path); |
| 3026 | |
| 3027 | LocationSummary* locations = instruction->GetLocations(); |
| 3028 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3029 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3030 | __ cmp(obj.AsRegister<Register>(), ShifterOperand(0)); |
| 3031 | __ b(slow_path->GetEntryLabel(), EQ); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3032 | } |
| 3033 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3034 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
| 3035 | if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) { |
| 3036 | GenerateImplicitNullCheck(instruction); |
| 3037 | } else { |
| 3038 | GenerateExplicitNullCheck(instruction); |
| 3039 | } |
| 3040 | } |
| 3041 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3042 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3043 | LocationSummary* locations = |
| 3044 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3045 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3046 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3047 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3048 | } |
| 3049 | |
| 3050 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 3051 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3052 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3053 | Location index = locations->InAt(1); |
| 3054 | |
| 3055 | switch (instruction->GetType()) { |
| 3056 | case Primitive::kPrimBoolean: { |
| 3057 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3058 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3059 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3060 | size_t offset = |
| 3061 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3062 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset); |
| 3063 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3064 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3065 | __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset); |
| 3066 | } |
| 3067 | break; |
| 3068 | } |
| 3069 | |
| 3070 | case Primitive::kPrimByte: { |
| 3071 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3072 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3073 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3074 | size_t offset = |
| 3075 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3076 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset); |
| 3077 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3078 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3079 | __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset); |
| 3080 | } |
| 3081 | break; |
| 3082 | } |
| 3083 | |
| 3084 | case Primitive::kPrimShort: { |
| 3085 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3086 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3087 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3088 | size_t offset = |
| 3089 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3090 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset); |
| 3091 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3092 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3093 | __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset); |
| 3094 | } |
| 3095 | break; |
| 3096 | } |
| 3097 | |
| 3098 | case Primitive::kPrimChar: { |
| 3099 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3100 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3101 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3102 | size_t offset = |
| 3103 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3104 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset); |
| 3105 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3106 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3107 | __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset); |
| 3108 | } |
| 3109 | break; |
| 3110 | } |
| 3111 | |
| 3112 | case Primitive::kPrimInt: |
| 3113 | case Primitive::kPrimNot: { |
| 3114 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
| 3115 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3116 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3117 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3118 | size_t offset = |
| 3119 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3120 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 3121 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3122 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3123 | __ LoadFromOffset(kLoadWord, out, IP, data_offset); |
| 3124 | } |
| 3125 | break; |
| 3126 | } |
| 3127 | |
| 3128 | case Primitive::kPrimLong: { |
| 3129 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3130 | Location out = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3131 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3132 | size_t offset = |
| 3133 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3134 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3135 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3136 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3137 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3138 | } |
| 3139 | break; |
| 3140 | } |
| 3141 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3142 | case Primitive::kPrimFloat: { |
| 3143 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 3144 | Location out = locations->Out(); |
| 3145 | DCHECK(out.IsFpuRegister()); |
| 3146 | if (index.IsConstant()) { |
| 3147 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 3148 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset); |
| 3149 | } else { |
| 3150 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 3151 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset); |
| 3152 | } |
| 3153 | break; |
| 3154 | } |
| 3155 | |
| 3156 | case Primitive::kPrimDouble: { |
| 3157 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 3158 | Location out = locations->Out(); |
| 3159 | DCHECK(out.IsFpuRegisterPair()); |
| 3160 | if (index.IsConstant()) { |
| 3161 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 3162 | __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset); |
| 3163 | } else { |
| 3164 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
| 3165 | __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 3166 | } |
| 3167 | break; |
| 3168 | } |
| 3169 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3170 | case Primitive::kPrimVoid: |
| 3171 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3172 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3173 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3174 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3175 | } |
| 3176 | |
| 3177 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3178 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3179 | |
| 3180 | bool needs_write_barrier = |
| 3181 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 3182 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
| 3183 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3184 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3185 | instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 3186 | if (needs_runtime_call) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3187 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3188 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3189 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3190 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3191 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3192 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3193 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3194 | locations->SetInAt(2, Location::RequiresRegister()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3195 | |
| 3196 | if (needs_write_barrier) { |
| 3197 | // Temporary registers for the write barrier. |
| 3198 | locations->AddTemp(Location::RequiresRegister()); |
| 3199 | locations->AddTemp(Location::RequiresRegister()); |
| 3200 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3201 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3202 | } |
| 3203 | |
| 3204 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 3205 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3206 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3207 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3208 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3209 | bool needs_runtime_call = locations->WillCall(); |
| 3210 | bool needs_write_barrier = |
| 3211 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3212 | |
| 3213 | switch (value_type) { |
| 3214 | case Primitive::kPrimBoolean: |
| 3215 | case Primitive::kPrimByte: { |
| 3216 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3217 | Register value = locations->InAt(2).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3218 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3219 | size_t offset = |
| 3220 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3221 | __ StoreToOffset(kStoreByte, value, obj, offset); |
| 3222 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3223 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3224 | __ StoreToOffset(kStoreByte, value, IP, data_offset); |
| 3225 | } |
| 3226 | break; |
| 3227 | } |
| 3228 | |
| 3229 | case Primitive::kPrimShort: |
| 3230 | case Primitive::kPrimChar: { |
| 3231 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3232 | Register value = locations->InAt(2).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3233 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3234 | size_t offset = |
| 3235 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3236 | __ StoreToOffset(kStoreHalfword, value, obj, offset); |
| 3237 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3238 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3239 | __ StoreToOffset(kStoreHalfword, value, IP, data_offset); |
| 3240 | } |
| 3241 | break; |
| 3242 | } |
| 3243 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3244 | case Primitive::kPrimInt: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3245 | case Primitive::kPrimNot: { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3246 | if (!needs_runtime_call) { |
| 3247 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3248 | Register value = locations->InAt(2).AsRegister<Register>(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3249 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3250 | size_t offset = |
| 3251 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3252 | __ StoreToOffset(kStoreWord, value, obj, offset); |
| 3253 | } else { |
| 3254 | DCHECK(index.IsRegister()) << index; |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3255 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3256 | __ StoreToOffset(kStoreWord, value, IP, data_offset); |
| 3257 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3258 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3259 | if (needs_write_barrier) { |
| 3260 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3261 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3262 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3263 | codegen_->MarkGCCard(temp, card, obj, value); |
| 3264 | } |
| 3265 | } else { |
| 3266 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3267 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 3268 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3269 | instruction->GetDexPc(), |
| 3270 | nullptr); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3271 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3272 | break; |
| 3273 | } |
| 3274 | |
| 3275 | case Primitive::kPrimLong: { |
| 3276 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3277 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3278 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3279 | size_t offset = |
| 3280 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3281 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3282 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3283 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3284 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3285 | } |
| 3286 | break; |
| 3287 | } |
| 3288 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3289 | case Primitive::kPrimFloat: { |
| 3290 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 3291 | Location value = locations->InAt(2); |
| 3292 | DCHECK(value.IsFpuRegister()); |
| 3293 | if (index.IsConstant()) { |
| 3294 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 3295 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset); |
| 3296 | } else { |
| 3297 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 3298 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 3299 | } |
| 3300 | break; |
| 3301 | } |
| 3302 | |
| 3303 | case Primitive::kPrimDouble: { |
| 3304 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 3305 | Location value = locations->InAt(2); |
| 3306 | DCHECK(value.IsFpuRegisterPair()); |
| 3307 | if (index.IsConstant()) { |
| 3308 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 3309 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset); |
| 3310 | } else { |
| 3311 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
| 3312 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 3313 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3314 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3315 | break; |
| 3316 | } |
| 3317 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3318 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3319 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3320 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3321 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3322 | |
| 3323 | // Ints and objects are handled in the switch. |
| 3324 | if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) { |
| 3325 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3326 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3327 | } |
| 3328 | |
| 3329 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3330 | LocationSummary* locations = |
| 3331 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3332 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3333 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3334 | } |
| 3335 | |
| 3336 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 3337 | LocationSummary* locations = instruction->GetLocations(); |
| 3338 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3339 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 3340 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3341 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3342 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3343 | } |
| 3344 | |
| 3345 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3346 | LocationSummary* locations = |
| 3347 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3348 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3349 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3350 | if (instruction->HasUses()) { |
| 3351 | locations->SetOut(Location::SameAsFirstInput()); |
| 3352 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3353 | } |
| 3354 | |
| 3355 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 3356 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 3357 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3358 | instruction, locations->InAt(0), locations->InAt(1)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3359 | codegen_->AddSlowPath(slow_path); |
| 3360 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3361 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 3362 | Register length = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3363 | |
| 3364 | __ cmp(index, ShifterOperand(length)); |
| 3365 | __ b(slow_path->GetEntryLabel(), CS); |
| 3366 | } |
| 3367 | |
| 3368 | void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) { |
| 3369 | Label is_null; |
| 3370 | __ CompareAndBranchIfZero(value, &is_null); |
| 3371 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value()); |
| 3372 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 3373 | __ strb(card, Address(card, temp)); |
| 3374 | __ Bind(&is_null); |
| 3375 | } |
| 3376 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3377 | void LocationsBuilderARM::VisitTemporary(HTemporary* temp) { |
| 3378 | temp->SetLocations(nullptr); |
| 3379 | } |
| 3380 | |
| 3381 | void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) { |
| 3382 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3383 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3384 | } |
| 3385 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 3386 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3387 | UNUSED(instruction); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3388 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 3389 | } |
| 3390 | |
| 3391 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3392 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 3393 | } |
| 3394 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 3395 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 3396 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 3397 | } |
| 3398 | |
| 3399 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 3400 | HBasicBlock* block = instruction->GetBlock(); |
| 3401 | if (block->GetLoopInformation() != nullptr) { |
| 3402 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 3403 | // The back edge will generate the suspend check. |
| 3404 | return; |
| 3405 | } |
| 3406 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 3407 | // The goto will generate the suspend check. |
| 3408 | return; |
| 3409 | } |
| 3410 | GenerateSuspendCheck(instruction, nullptr); |
| 3411 | } |
| 3412 | |
| 3413 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 3414 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 3415 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 3416 | new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 3417 | codegen_->AddSlowPath(slow_path); |
| 3418 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 3419 | __ LoadFromOffset( |
| 3420 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value()); |
| 3421 | __ cmp(IP, ShifterOperand(0)); |
| 3422 | // TODO: Figure out the branch offsets and use cbz/cbnz. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 3423 | if (successor == nullptr) { |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 3424 | __ b(slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 3425 | __ Bind(slow_path->GetReturnLabel()); |
| 3426 | } else { |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 3427 | __ b(codegen_->GetLabelOf(successor), EQ); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 3428 | __ b(slow_path->GetEntryLabel()); |
| 3429 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 3430 | } |
| 3431 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3432 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 3433 | return codegen_->GetAssembler(); |
| 3434 | } |
| 3435 | |
| 3436 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
| 3437 | MoveOperands* move = moves_.Get(index); |
| 3438 | Location source = move->GetSource(); |
| 3439 | Location destination = move->GetDestination(); |
| 3440 | |
| 3441 | if (source.IsRegister()) { |
| 3442 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3443 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3444 | } else { |
| 3445 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3446 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3447 | SP, destination.GetStackIndex()); |
| 3448 | } |
| 3449 | } else if (source.IsStackSlot()) { |
| 3450 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3451 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3452 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3453 | } else if (destination.IsFpuRegister()) { |
| 3454 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3455 | } else { |
| 3456 | DCHECK(destination.IsStackSlot()); |
| 3457 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 3458 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 3459 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3460 | } else if (source.IsFpuRegister()) { |
| 3461 | if (destination.IsFpuRegister()) { |
| 3462 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3463 | } else { |
| 3464 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3465 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 3466 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3467 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 3468 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 3469 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 3470 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 3471 | } else if (destination.IsRegisterPair()) { |
| 3472 | DCHECK(ExpectedPairLayout(destination)); |
| 3473 | __ LoadFromOffset( |
| 3474 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 3475 | } else { |
| 3476 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 3477 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 3478 | SP, |
| 3479 | source.GetStackIndex()); |
| 3480 | } |
| 3481 | } else if (source.IsRegisterPair()) { |
| 3482 | if (destination.IsRegisterPair()) { |
| 3483 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 3484 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 3485 | } else { |
| 3486 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 3487 | DCHECK(ExpectedPairLayout(source)); |
| 3488 | __ StoreToOffset( |
| 3489 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 3490 | } |
| 3491 | } else if (source.IsFpuRegisterPair()) { |
| 3492 | if (destination.IsFpuRegisterPair()) { |
| 3493 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 3494 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 3495 | } else { |
| 3496 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 3497 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 3498 | SP, |
| 3499 | destination.GetStackIndex()); |
| 3500 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3501 | } else { |
| 3502 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3503 | HConstant* constant = source.GetConstant(); |
| 3504 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 3505 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3506 | if (destination.IsRegister()) { |
| 3507 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 3508 | } else { |
| 3509 | DCHECK(destination.IsStackSlot()); |
| 3510 | __ LoadImmediate(IP, value); |
| 3511 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 3512 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3513 | } else if (constant->IsLongConstant()) { |
| 3514 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 3515 | if (destination.IsRegisterPair()) { |
| 3516 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 3517 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3518 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 3519 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3520 | __ LoadImmediate(IP, Low32Bits(value)); |
| 3521 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 3522 | __ LoadImmediate(IP, High32Bits(value)); |
| 3523 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 3524 | } |
| 3525 | } else if (constant->IsDoubleConstant()) { |
| 3526 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 3527 | if (destination.IsFpuRegisterPair()) { |
| 3528 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3529 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 3530 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 3531 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3532 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 3533 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 3534 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 3535 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 3536 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3537 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3538 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3539 | float value = constant->AsFloatConstant()->GetValue(); |
| 3540 | if (destination.IsFpuRegister()) { |
| 3541 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 3542 | } else { |
| 3543 | DCHECK(destination.IsStackSlot()); |
| 3544 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 3545 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 3546 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3547 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3548 | } |
| 3549 | } |
| 3550 | |
| 3551 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 3552 | __ Mov(IP, reg); |
| 3553 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 3554 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 3555 | } |
| 3556 | |
| 3557 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 3558 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 3559 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 3560 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 3561 | SP, mem1 + stack_offset); |
| 3562 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 3563 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 3564 | SP, mem2 + stack_offset); |
| 3565 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 3566 | } |
| 3567 | |
| 3568 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
| 3569 | MoveOperands* move = moves_.Get(index); |
| 3570 | Location source = move->GetSource(); |
| 3571 | Location destination = move->GetDestination(); |
| 3572 | |
| 3573 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3574 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 3575 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 3576 | __ Mov(IP, source.AsRegister<Register>()); |
| 3577 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 3578 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3579 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3580 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3581 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3582 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3583 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 3584 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3585 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 3586 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3587 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 3588 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 3589 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 3590 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 3591 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 3592 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 3593 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 3594 | destination.AsRegisterPairHigh<Register>(), |
| 3595 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 3596 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 3597 | Register low_reg = source.IsRegisterPair() |
| 3598 | ? source.AsRegisterPairLow<Register>() |
| 3599 | : destination.AsRegisterPairLow<Register>(); |
| 3600 | int mem = source.IsRegisterPair() |
| 3601 | ? destination.GetStackIndex() |
| 3602 | : source.GetStackIndex(); |
| 3603 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 3604 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 3605 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 3606 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 3607 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 3608 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 3609 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 3610 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 3611 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 3612 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 3613 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 3614 | DRegister reg = source.IsFpuRegisterPair() |
| 3615 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 3616 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 3617 | int mem = source.IsFpuRegisterPair() |
| 3618 | ? destination.GetStackIndex() |
| 3619 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 3620 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 3621 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 3622 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3623 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 3624 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 3625 | : destination.AsFpuRegister<SRegister>(); |
| 3626 | int mem = source.IsFpuRegister() |
| 3627 | ? destination.GetStackIndex() |
| 3628 | : source.GetStackIndex(); |
| 3629 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 3630 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 3631 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 3632 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 3633 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 3634 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 3635 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3636 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 3637 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3638 | } |
| 3639 | } |
| 3640 | |
| 3641 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 3642 | __ Push(static_cast<Register>(reg)); |
| 3643 | } |
| 3644 | |
| 3645 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 3646 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 3647 | } |
| 3648 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3649 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3650 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 3651 | ? LocationSummary::kCallOnSlowPath |
| 3652 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3653 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3654 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3655 | locations->SetOut(Location::RequiresRegister()); |
| 3656 | } |
| 3657 | |
| 3658 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3659 | Register out = cls->GetLocations()->Out().AsRegister<Register>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3660 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3661 | DCHECK(!cls->CanCallRuntime()); |
| 3662 | DCHECK(!cls->MustGenerateClinitCheck()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3663 | codegen_->LoadCurrentMethod(out); |
| 3664 | __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value()); |
| 3665 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3666 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3667 | codegen_->LoadCurrentMethod(out); |
| 3668 | __ LoadFromOffset( |
| 3669 | kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value()); |
| 3670 | __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3671 | |
| 3672 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
| 3673 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 3674 | codegen_->AddSlowPath(slow_path); |
| 3675 | __ cmp(out, ShifterOperand(0)); |
| 3676 | __ b(slow_path->GetEntryLabel(), EQ); |
| 3677 | if (cls->MustGenerateClinitCheck()) { |
| 3678 | GenerateClassInitializationCheck(slow_path, out); |
| 3679 | } else { |
| 3680 | __ Bind(slow_path->GetExitLabel()); |
| 3681 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3682 | } |
| 3683 | } |
| 3684 | |
| 3685 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 3686 | LocationSummary* locations = |
| 3687 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 3688 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3689 | if (check->HasUses()) { |
| 3690 | locations->SetOut(Location::SameAsFirstInput()); |
| 3691 | } |
| 3692 | } |
| 3693 | |
| 3694 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3695 | // We assume the class is not null. |
| 3696 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
| 3697 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3698 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3699 | GenerateClassInitializationCheck(slow_path, |
| 3700 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3701 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3702 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3703 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
| 3704 | SlowPathCodeARM* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3705 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 3706 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 3707 | __ b(slow_path->GetEntryLabel(), LT); |
| 3708 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 3709 | // properly. Therefore, we do a memory fence. |
| 3710 | __ dmb(ISH); |
| 3711 | __ Bind(slow_path->GetExitLabel()); |
| 3712 | } |
| 3713 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 3714 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
| 3715 | LocationSummary* locations = |
| 3716 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
| 3717 | locations->SetOut(Location::RequiresRegister()); |
| 3718 | } |
| 3719 | |
| 3720 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) { |
| 3721 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 3722 | codegen_->AddSlowPath(slow_path); |
| 3723 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3724 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 3725 | codegen_->LoadCurrentMethod(out); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 3726 | __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value()); |
| 3727 | __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 3728 | __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
| 3729 | __ cmp(out, ShifterOperand(0)); |
| 3730 | __ b(slow_path->GetEntryLabel(), EQ); |
| 3731 | __ Bind(slow_path->GetExitLabel()); |
| 3732 | } |
| 3733 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 3734 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 3735 | LocationSummary* locations = |
| 3736 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 3737 | locations->SetOut(Location::RequiresRegister()); |
| 3738 | } |
| 3739 | |
| 3740 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3741 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 3742 | int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value(); |
| 3743 | __ LoadFromOffset(kLoadWord, out, TR, offset); |
| 3744 | __ LoadImmediate(IP, 0); |
| 3745 | __ StoreToOffset(kStoreWord, IP, TR, offset); |
| 3746 | } |
| 3747 | |
| 3748 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 3749 | LocationSummary* locations = |
| 3750 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3751 | InvokeRuntimeCallingConvention calling_convention; |
| 3752 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3753 | } |
| 3754 | |
| 3755 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
| 3756 | codegen_->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3757 | QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 3758 | } |
| 3759 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3760 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3761 | LocationSummary::CallKind call_kind = instruction->IsClassFinal() |
| 3762 | ? LocationSummary::kNoCall |
| 3763 | : LocationSummary::kCallOnSlowPath; |
| 3764 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 3765 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3766 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3767 | // The out register is used as a temporary, so it overlaps with the inputs. |
| 3768 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3769 | } |
| 3770 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3771 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3772 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3773 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 3774 | Register cls = locations->InAt(1).AsRegister<Register>(); |
| 3775 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3776 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3777 | Label done, zero; |
| 3778 | SlowPathCodeARM* slow_path = nullptr; |
| 3779 | |
| 3780 | // Return 0 if `obj` is null. |
| 3781 | // TODO: avoid this check if we know obj is not null. |
| 3782 | __ cmp(obj, ShifterOperand(0)); |
| 3783 | __ b(&zero, EQ); |
| 3784 | // Compare the class of `obj` with `cls`. |
| 3785 | __ LoadFromOffset(kLoadWord, out, obj, class_offset); |
| 3786 | __ cmp(out, ShifterOperand(cls)); |
| 3787 | if (instruction->IsClassFinal()) { |
| 3788 | // Classes must be equal for the instanceof to succeed. |
| 3789 | __ b(&zero, NE); |
| 3790 | __ LoadImmediate(out, 1); |
| 3791 | __ b(&done); |
| 3792 | } else { |
| 3793 | // If the classes are not equal, we go into a slow path. |
| 3794 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 3795 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM( |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3796 | instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3797 | codegen_->AddSlowPath(slow_path); |
| 3798 | __ b(slow_path->GetEntryLabel(), NE); |
| 3799 | __ LoadImmediate(out, 1); |
| 3800 | __ b(&done); |
| 3801 | } |
| 3802 | __ Bind(&zero); |
| 3803 | __ LoadImmediate(out, 0); |
| 3804 | if (slow_path != nullptr) { |
| 3805 | __ Bind(slow_path->GetExitLabel()); |
| 3806 | } |
| 3807 | __ Bind(&done); |
| 3808 | } |
| 3809 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3810 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
| 3811 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 3812 | instruction, LocationSummary::kCallOnSlowPath); |
| 3813 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3814 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3815 | locations->AddTemp(Location::RequiresRegister()); |
| 3816 | } |
| 3817 | |
| 3818 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
| 3819 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3820 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 3821 | Register cls = locations->InAt(1).AsRegister<Register>(); |
| 3822 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3823 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3824 | |
| 3825 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM( |
| 3826 | instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc()); |
| 3827 | codegen_->AddSlowPath(slow_path); |
| 3828 | |
| 3829 | // TODO: avoid this check if we know obj is not null. |
| 3830 | __ cmp(obj, ShifterOperand(0)); |
| 3831 | __ b(slow_path->GetExitLabel(), EQ); |
| 3832 | // Compare the class of `obj` with `cls`. |
| 3833 | __ LoadFromOffset(kLoadWord, temp, obj, class_offset); |
| 3834 | __ cmp(temp, ShifterOperand(cls)); |
| 3835 | __ b(slow_path->GetEntryLabel(), NE); |
| 3836 | __ Bind(slow_path->GetExitLabel()); |
| 3837 | } |
| 3838 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 3839 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 3840 | LocationSummary* locations = |
| 3841 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3842 | InvokeRuntimeCallingConvention calling_convention; |
| 3843 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3844 | } |
| 3845 | |
| 3846 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 3847 | codegen_->InvokeRuntime(instruction->IsEnter() |
| 3848 | ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject), |
| 3849 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3850 | instruction->GetDexPc(), |
| 3851 | nullptr); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 3852 | } |
| 3853 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3854 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 3855 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 3856 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 3857 | |
| 3858 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 3859 | LocationSummary* locations = |
| 3860 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3861 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 3862 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 3863 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3864 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3865 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3866 | } |
| 3867 | |
| 3868 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 3869 | HandleBitwiseOperation(instruction); |
| 3870 | } |
| 3871 | |
| 3872 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 3873 | HandleBitwiseOperation(instruction); |
| 3874 | } |
| 3875 | |
| 3876 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 3877 | HandleBitwiseOperation(instruction); |
| 3878 | } |
| 3879 | |
| 3880 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 3881 | LocationSummary* locations = instruction->GetLocations(); |
| 3882 | |
| 3883 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3884 | Register first = locations->InAt(0).AsRegister<Register>(); |
| 3885 | Register second = locations->InAt(1).AsRegister<Register>(); |
| 3886 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3887 | if (instruction->IsAnd()) { |
| 3888 | __ and_(out, first, ShifterOperand(second)); |
| 3889 | } else if (instruction->IsOr()) { |
| 3890 | __ orr(out, first, ShifterOperand(second)); |
| 3891 | } else { |
| 3892 | DCHECK(instruction->IsXor()); |
| 3893 | __ eor(out, first, ShifterOperand(second)); |
| 3894 | } |
| 3895 | } else { |
| 3896 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3897 | Location first = locations->InAt(0); |
| 3898 | Location second = locations->InAt(1); |
| 3899 | Location out = locations->Out(); |
| 3900 | if (instruction->IsAnd()) { |
| 3901 | __ and_(out.AsRegisterPairLow<Register>(), |
| 3902 | first.AsRegisterPairLow<Register>(), |
| 3903 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3904 | __ and_(out.AsRegisterPairHigh<Register>(), |
| 3905 | first.AsRegisterPairHigh<Register>(), |
| 3906 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3907 | } else if (instruction->IsOr()) { |
| 3908 | __ orr(out.AsRegisterPairLow<Register>(), |
| 3909 | first.AsRegisterPairLow<Register>(), |
| 3910 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3911 | __ orr(out.AsRegisterPairHigh<Register>(), |
| 3912 | first.AsRegisterPairHigh<Register>(), |
| 3913 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3914 | } else { |
| 3915 | DCHECK(instruction->IsXor()); |
| 3916 | __ eor(out.AsRegisterPairLow<Register>(), |
| 3917 | first.AsRegisterPairLow<Register>(), |
| 3918 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3919 | __ eor(out.AsRegisterPairHigh<Register>(), |
| 3920 | first.AsRegisterPairHigh<Register>(), |
| 3921 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3922 | } |
| 3923 | } |
| 3924 | } |
| 3925 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3926 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp) { |
| 3927 | DCHECK_EQ(temp, kArtMethodRegister); |
| 3928 | |
| 3929 | // TODO: Implement all kinds of calls: |
| 3930 | // 1) boot -> boot |
| 3931 | // 2) app -> boot |
| 3932 | // 3) app -> app |
| 3933 | // |
| 3934 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
| 3935 | |
| 3936 | // temp = method; |
| 3937 | LoadCurrentMethod(temp); |
| 3938 | if (!invoke->IsRecursive()) { |
| 3939 | // temp = temp->dex_cache_resolved_methods_; |
| 3940 | __ LoadFromOffset( |
| 3941 | kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value()); |
| 3942 | // temp = temp[index_in_cache] |
| 3943 | __ LoadFromOffset( |
| 3944 | kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex())); |
| 3945 | // LR = temp[offset_of_quick_compiled_code] |
| 3946 | __ LoadFromOffset(kLoadWord, LR, temp, |
| 3947 | mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 3948 | kArmWordSize).Int32Value()); |
| 3949 | // LR() |
| 3950 | __ blx(LR); |
| 3951 | } else { |
| 3952 | __ bl(GetFrameEntryLabel()); |
| 3953 | } |
| 3954 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3955 | DCHECK(!IsLeafMethod()); |
| 3956 | } |
| 3957 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 3958 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) { |
| 3959 | // Nothing to do, this should be removed during prepare for register allocator. |
| 3960 | UNUSED(instruction); |
| 3961 | LOG(FATAL) << "Unreachable"; |
| 3962 | } |
| 3963 | |
| 3964 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) { |
| 3965 | // Nothing to do, this should be removed during prepare for register allocator. |
| 3966 | UNUSED(instruction); |
| 3967 | LOG(FATAL) << "Unreachable"; |
| 3968 | } |
| 3969 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 3970 | } // namespace arm |
| 3971 | } // namespace art |