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