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