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