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