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