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