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