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