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