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