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