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 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame^] | 59 | static constexpr uint32_t kPackedSwitchJumpTableThreshold = 6; |
| 60 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 61 | #define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 62 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 63 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 64 | class NullCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 65 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 66 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 67 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 68 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 69 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 70 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 71 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 72 | // Live registers will be restored in the catch block if caught. |
| 73 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 74 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 75 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 76 | QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 77 | } |
| 78 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 79 | bool IsFatal() const OVERRIDE { return true; } |
| 80 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 81 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; } |
| 82 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 83 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 84 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 85 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 86 | }; |
| 87 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 88 | class DivZeroCheckSlowPathARM : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 89 | public: |
| 90 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 91 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 92 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 93 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 94 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 95 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 96 | // Live registers will be restored in the catch block if caught. |
| 97 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 98 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 99 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 100 | QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 103 | bool IsFatal() const OVERRIDE { return true; } |
| 104 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 105 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; } |
| 106 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 107 | private: |
| 108 | HDivZeroCheck* const instruction_; |
| 109 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 110 | }; |
| 111 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 112 | class SuspendCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 113 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 114 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 115 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 116 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 117 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 118 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 119 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 120 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 121 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 122 | QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 123 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 124 | if (successor_ == nullptr) { |
| 125 | __ b(GetReturnLabel()); |
| 126 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 127 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 128 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 131 | Label* GetReturnLabel() { |
| 132 | DCHECK(successor_ == nullptr); |
| 133 | return &return_label_; |
| 134 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 135 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 136 | HBasicBlock* GetSuccessor() const { |
| 137 | return successor_; |
| 138 | } |
| 139 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 140 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; } |
| 141 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 142 | private: |
| 143 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 144 | // If not null, the block to branch to after the suspend check. |
| 145 | HBasicBlock* const successor_; |
| 146 | |
| 147 | // 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] | 148 | Label return_label_; |
| 149 | |
| 150 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 151 | }; |
| 152 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 153 | class BoundsCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 154 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 155 | explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction) |
| 156 | : instruction_(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 157 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 158 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 159 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 160 | LocationSummary* locations = instruction_->GetLocations(); |
| 161 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 162 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 163 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 164 | // Live registers will be restored in the catch block if caught. |
| 165 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 166 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 167 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 168 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 169 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 170 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 171 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 172 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 173 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 174 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 175 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 176 | Primitive::kPrimInt); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 177 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 178 | QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 179 | } |
| 180 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 181 | bool IsFatal() const OVERRIDE { return true; } |
| 182 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 183 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; } |
| 184 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 185 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 186 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 187 | |
| 188 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 189 | }; |
| 190 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 191 | class LoadClassSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 192 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 193 | LoadClassSlowPathARM(HLoadClass* cls, |
| 194 | HInstruction* at, |
| 195 | uint32_t dex_pc, |
| 196 | bool do_clinit) |
| 197 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 198 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 199 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 200 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 201 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 202 | LocationSummary* locations = at_->GetLocations(); |
| 203 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 204 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 205 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 206 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 207 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 208 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 209 | __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 210 | int32_t entry_point_offset = do_clinit_ |
| 211 | ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 212 | : QUICK_ENTRY_POINT(pInitializeType); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 213 | arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 214 | |
| 215 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 216 | Location out = locations->Out(); |
| 217 | if (out.IsValid()) { |
| 218 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 219 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 220 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 221 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 222 | __ b(GetExitLabel()); |
| 223 | } |
| 224 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 225 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; } |
| 226 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 227 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 228 | // The class this slow path will load. |
| 229 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 230 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 231 | // The instruction where this slow path is happening. |
| 232 | // (Might be the load class or an initialization check). |
| 233 | HInstruction* const at_; |
| 234 | |
| 235 | // The dex PC of `at_`. |
| 236 | const uint32_t dex_pc_; |
| 237 | |
| 238 | // Whether to initialize the class. |
| 239 | const bool do_clinit_; |
| 240 | |
| 241 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 242 | }; |
| 243 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 244 | class LoadStringSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 245 | public: |
| 246 | explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {} |
| 247 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 248 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 249 | LocationSummary* locations = instruction_->GetLocations(); |
| 250 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 251 | |
| 252 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 253 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 254 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 255 | |
| 256 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 257 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 258 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 259 | QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 260 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 261 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 262 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 263 | __ b(GetExitLabel()); |
| 264 | } |
| 265 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 266 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; } |
| 267 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 268 | private: |
| 269 | HLoadString* const instruction_; |
| 270 | |
| 271 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 272 | }; |
| 273 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 274 | class TypeCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 275 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 276 | TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal) |
| 277 | : instruction_(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 278 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 279 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 280 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 281 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 282 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 283 | DCHECK(instruction_->IsCheckCast() |
| 284 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 285 | |
| 286 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 287 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 288 | |
| 289 | if (instruction_->IsCheckCast()) { |
| 290 | // The codegen for the instruction overwrites `temp`, so put it back in place. |
| 291 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 292 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 293 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 294 | __ LoadFromOffset(kLoadWord, temp, obj, class_offset); |
| 295 | __ MaybeUnpoisonHeapReference(temp); |
| 296 | } |
| 297 | |
| 298 | if (!is_fatal_) { |
| 299 | SaveLiveRegisters(codegen, locations); |
| 300 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 301 | |
| 302 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 303 | // move resolver. |
| 304 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 305 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 306 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 307 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 308 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 309 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 310 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 311 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 312 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 313 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 314 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 315 | instruction_, |
| 316 | instruction_->GetDexPc(), |
| 317 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 318 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 319 | } else { |
| 320 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 321 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 322 | instruction_, |
| 323 | instruction_->GetDexPc(), |
| 324 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 325 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 326 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 327 | if (!is_fatal_) { |
| 328 | RestoreLiveRegisters(codegen, locations); |
| 329 | __ b(GetExitLabel()); |
| 330 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 331 | } |
| 332 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 333 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; } |
| 334 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 335 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 336 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 337 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 338 | HInstruction* const instruction_; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 339 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 340 | |
| 341 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 342 | }; |
| 343 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 344 | class DeoptimizationSlowPathARM : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 345 | public: |
| 346 | explicit DeoptimizationSlowPathARM(HInstruction* instruction) |
| 347 | : instruction_(instruction) {} |
| 348 | |
| 349 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 350 | __ Bind(GetEntryLabel()); |
| 351 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 352 | DCHECK(instruction_->IsDeoptimize()); |
| 353 | HDeoptimize* deoptimize = instruction_->AsDeoptimize(); |
| 354 | uint32_t dex_pc = deoptimize->GetDexPc(); |
| 355 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 356 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this); |
| 357 | } |
| 358 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 359 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; } |
| 360 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 361 | private: |
| 362 | HInstruction* const instruction_; |
| 363 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM); |
| 364 | }; |
| 365 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 366 | class ArraySetSlowPathARM : public SlowPathCode { |
| 367 | public: |
| 368 | explicit ArraySetSlowPathARM(HInstruction* instruction) : instruction_(instruction) {} |
| 369 | |
| 370 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 371 | LocationSummary* locations = instruction_->GetLocations(); |
| 372 | __ Bind(GetEntryLabel()); |
| 373 | SaveLiveRegisters(codegen, locations); |
| 374 | |
| 375 | InvokeRuntimeCallingConvention calling_convention; |
| 376 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 377 | parallel_move.AddMove( |
| 378 | locations->InAt(0), |
| 379 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 380 | Primitive::kPrimNot, |
| 381 | nullptr); |
| 382 | parallel_move.AddMove( |
| 383 | locations->InAt(1), |
| 384 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 385 | Primitive::kPrimInt, |
| 386 | nullptr); |
| 387 | parallel_move.AddMove( |
| 388 | locations->InAt(2), |
| 389 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 390 | Primitive::kPrimNot, |
| 391 | nullptr); |
| 392 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 393 | |
| 394 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 395 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 396 | instruction_, |
| 397 | instruction_->GetDexPc(), |
| 398 | this); |
| 399 | RestoreLiveRegisters(codegen, locations); |
| 400 | __ b(GetExitLabel()); |
| 401 | } |
| 402 | |
| 403 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; } |
| 404 | |
| 405 | private: |
| 406 | HInstruction* const instruction_; |
| 407 | |
| 408 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM); |
| 409 | }; |
| 410 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 411 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 412 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 413 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 414 | inline Condition ARMCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 415 | switch (cond) { |
| 416 | case kCondEQ: return EQ; |
| 417 | case kCondNE: return NE; |
| 418 | case kCondLT: return LT; |
| 419 | case kCondLE: return LE; |
| 420 | case kCondGT: return GT; |
| 421 | case kCondGE: return GE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 422 | case kCondB: return LO; |
| 423 | case kCondBE: return LS; |
| 424 | case kCondA: return HI; |
| 425 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 426 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 427 | LOG(FATAL) << "Unreachable"; |
| 428 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 431 | // Maps signed condition to unsigned condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 432 | inline Condition ARMUnsignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 433 | switch (cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 434 | case kCondEQ: return EQ; |
| 435 | case kCondNE: return NE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 436 | // Signed to unsigned. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 437 | case kCondLT: return LO; |
| 438 | case kCondLE: return LS; |
| 439 | case kCondGT: return HI; |
| 440 | case kCondGE: return HS; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 441 | // Unsigned remain unchanged. |
| 442 | case kCondB: return LO; |
| 443 | case kCondBE: return LS; |
| 444 | case kCondA: return HI; |
| 445 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 446 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 447 | LOG(FATAL) << "Unreachable"; |
| 448 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 449 | } |
| 450 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 451 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 452 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 456 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 457 | } |
| 458 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 459 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 460 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 461 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 462 | } |
| 463 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 464 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 465 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 466 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 467 | } |
| 468 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 469 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 470 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 471 | return kArmWordSize; |
| 472 | } |
| 473 | |
| 474 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 475 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 476 | return kArmWordSize; |
| 477 | } |
| 478 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 479 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 480 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 481 | const CompilerOptions& compiler_options, |
| 482 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 483 | : CodeGenerator(graph, |
| 484 | kNumberOfCoreRegisters, |
| 485 | kNumberOfSRegisters, |
| 486 | kNumberOfRegisterPairs, |
| 487 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 488 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 489 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 490 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 491 | compiler_options, |
| 492 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 493 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 494 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 495 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 496 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 497 | assembler_(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 498 | isa_features_(isa_features), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 499 | method_patches_(MethodReferenceComparator(), |
| 500 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 501 | call_patches_(MethodReferenceComparator(), |
| 502 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 503 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 504 | // Always save the LR register to mimic Quick. |
| 505 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 506 | } |
| 507 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 508 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 509 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 510 | __ FinalizeCode(); |
| 511 | |
| 512 | // Adjust native pc offsets in stack maps. |
| 513 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
| 514 | uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset; |
| 515 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 516 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 517 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 518 | // Adjust pc offsets for the disassembly information. |
| 519 | if (disasm_info_ != nullptr) { |
| 520 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 521 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 522 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 523 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 524 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 525 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 526 | } |
| 527 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 528 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 529 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 530 | } |
| 531 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 532 | |
| 533 | CodeGenerator::Finalize(allocator); |
| 534 | } |
| 535 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 536 | Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 537 | switch (type) { |
| 538 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 539 | size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 540 | ArmManagedRegister pair = |
| 541 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 542 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); |
| 543 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); |
| 544 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 545 | blocked_core_registers_[pair.AsRegisterPairLow()] = true; |
| 546 | blocked_core_registers_[pair.AsRegisterPairHigh()] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 547 | UpdateBlockedPairRegisters(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 548 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | case Primitive::kPrimByte: |
| 552 | case Primitive::kPrimBoolean: |
| 553 | case Primitive::kPrimChar: |
| 554 | case Primitive::kPrimShort: |
| 555 | case Primitive::kPrimInt: |
| 556 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 557 | int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 558 | // Block all register pairs that contain `reg`. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 559 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 560 | ArmManagedRegister current = |
| 561 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 562 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 563 | blocked_register_pairs_[i] = true; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 564 | } |
| 565 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 566 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 567 | } |
| 568 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 569 | case Primitive::kPrimFloat: { |
| 570 | int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 571 | return Location::FpuRegisterLocation(reg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 572 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 573 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 574 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 3c03503 | 2014-10-28 10:46:40 +0000 | [diff] [blame] | 575 | int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters); |
| 576 | DCHECK_EQ(reg % 2, 0); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 577 | return Location::FpuRegisterPairLocation(reg, reg + 1); |
| 578 | } |
| 579 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 580 | case Primitive::kPrimVoid: |
| 581 | LOG(FATAL) << "Unreachable type " << type; |
| 582 | } |
| 583 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 584 | return Location(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 585 | } |
| 586 | |
Nicolas Geoffray | a0bb2bd | 2015-01-26 12:49:35 +0000 | [diff] [blame] | 587 | void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 588 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 589 | blocked_register_pairs_[R1_R2] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 590 | |
| 591 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 592 | blocked_core_registers_[SP] = true; |
| 593 | blocked_core_registers_[LR] = true; |
| 594 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 595 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 596 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 597 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 598 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 599 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 600 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 601 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 602 | if (is_baseline) { |
| 603 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 604 | blocked_core_registers_[kCoreCalleeSaves[i]] = true; |
| 605 | } |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 606 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 607 | blocked_core_registers_[kCoreSavedRegisterForBaseline] = false; |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 608 | } |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 609 | |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 610 | if (is_baseline || GetGraph()->IsDebuggable()) { |
| 611 | // Stubs do not save callee-save floating point registers. If the graph |
| 612 | // is debuggable, we need to deal with these registers differently. For |
| 613 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 614 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 615 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 616 | } |
| 617 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 618 | |
| 619 | UpdateBlockedPairRegisters(); |
| 620 | } |
| 621 | |
| 622 | void CodeGeneratorARM::UpdateBlockedPairRegisters() const { |
| 623 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 624 | ArmManagedRegister current = |
| 625 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 626 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 627 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 628 | blocked_register_pairs_[i] = true; |
| 629 | } |
| 630 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 631 | } |
| 632 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 633 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
| 634 | : HGraphVisitor(graph), |
| 635 | assembler_(codegen->GetAssembler()), |
| 636 | codegen_(codegen) {} |
| 637 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 638 | void CodeGeneratorARM::ComputeSpillMask() { |
| 639 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 640 | // Save one extra register for baseline. Note that on thumb2, there is no easy |
| 641 | // instruction to restore just the PC, so this actually helps both baseline |
| 642 | // and non-baseline to save and restore at least two registers at entry and exit. |
| 643 | core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 644 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 645 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 646 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 647 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 648 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 649 | // but in the range. |
| 650 | if (fpu_spill_mask_ != 0) { |
| 651 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 652 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 653 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 654 | fpu_spill_mask_ |= (1 << i); |
| 655 | } |
| 656 | } |
| 657 | } |
| 658 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 659 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 660 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 664 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 665 | } |
| 666 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 667 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 668 | bool skip_overflow_check = |
| 669 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 670 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 671 | __ Bind(&frame_entry_label_); |
| 672 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 673 | if (HasEmptyFrame()) { |
| 674 | return; |
| 675 | } |
| 676 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 677 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 678 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 679 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 680 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 681 | } |
| 682 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 683 | __ PushList(core_spill_mask_); |
| 684 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 685 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 686 | if (fpu_spill_mask_ != 0) { |
| 687 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 688 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 689 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 690 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 691 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 692 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 693 | __ AddConstant(SP, -adjust); |
| 694 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 695 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 699 | if (HasEmptyFrame()) { |
| 700 | __ bx(LR); |
| 701 | return; |
| 702 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 703 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 704 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 705 | __ AddConstant(SP, adjust); |
| 706 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 707 | if (fpu_spill_mask_ != 0) { |
| 708 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 709 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 710 | __ cfi().AdjustCFAOffset(-kArmPointerSize * POPCOUNT(fpu_spill_mask_)); |
| 711 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 712 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 713 | // Pop LR into PC to return. |
| 714 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 715 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 716 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 717 | __ cfi().RestoreState(); |
| 718 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 719 | } |
| 720 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 721 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame^] | 722 | Label* label = GetLabelOf(block); |
| 723 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 724 | } |
| 725 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 726 | Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const { |
| 727 | switch (load->GetType()) { |
| 728 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 729 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 730 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 731 | |
| 732 | case Primitive::kPrimInt: |
| 733 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 734 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 735 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 736 | |
| 737 | case Primitive::kPrimBoolean: |
| 738 | case Primitive::kPrimByte: |
| 739 | case Primitive::kPrimChar: |
| 740 | case Primitive::kPrimShort: |
| 741 | case Primitive::kPrimVoid: |
| 742 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 743 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 747 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 748 | } |
| 749 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 750 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 751 | switch (type) { |
| 752 | case Primitive::kPrimBoolean: |
| 753 | case Primitive::kPrimByte: |
| 754 | case Primitive::kPrimChar: |
| 755 | case Primitive::kPrimShort: |
| 756 | case Primitive::kPrimInt: |
| 757 | case Primitive::kPrimNot: { |
| 758 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 759 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 760 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 761 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 762 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 763 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 764 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 765 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 766 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 767 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 768 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 769 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 770 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 771 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 772 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 773 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 774 | // Skip R1, and use R2_R3 instead. |
| 775 | gp_index_++; |
| 776 | index++; |
| 777 | } |
| 778 | } |
| 779 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 780 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 781 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 782 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 783 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 784 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 785 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 786 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | case Primitive::kPrimFloat: { |
| 791 | uint32_t stack_index = stack_index_++; |
| 792 | if (float_index_ % 2 == 0) { |
| 793 | float_index_ = std::max(double_index_, float_index_); |
| 794 | } |
| 795 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 796 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 797 | } else { |
| 798 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | case Primitive::kPrimDouble: { |
| 803 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 804 | uint32_t stack_index = stack_index_; |
| 805 | stack_index_ += 2; |
| 806 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 807 | uint32_t index = double_index_; |
| 808 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 809 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 810 | calling_convention.GetFpuRegisterAt(index), |
| 811 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 812 | DCHECK(ExpectedPairLayout(result)); |
| 813 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 814 | } else { |
| 815 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 816 | } |
| 817 | } |
| 818 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 819 | case Primitive::kPrimVoid: |
| 820 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 821 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 822 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 823 | return Location(); |
| 824 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 825 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 826 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 827 | switch (type) { |
| 828 | case Primitive::kPrimBoolean: |
| 829 | case Primitive::kPrimByte: |
| 830 | case Primitive::kPrimChar: |
| 831 | case Primitive::kPrimShort: |
| 832 | case Primitive::kPrimInt: |
| 833 | case Primitive::kPrimNot: { |
| 834 | return Location::RegisterLocation(R0); |
| 835 | } |
| 836 | |
| 837 | case Primitive::kPrimFloat: { |
| 838 | return Location::FpuRegisterLocation(S0); |
| 839 | } |
| 840 | |
| 841 | case Primitive::kPrimLong: { |
| 842 | return Location::RegisterPairLocation(R0, R1); |
| 843 | } |
| 844 | |
| 845 | case Primitive::kPrimDouble: { |
| 846 | return Location::FpuRegisterPairLocation(S0, S1); |
| 847 | } |
| 848 | |
| 849 | case Primitive::kPrimVoid: |
| 850 | return Location(); |
| 851 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 852 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 853 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 854 | } |
| 855 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 856 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 857 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 858 | } |
| 859 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 860 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 861 | if (source.Equals(destination)) { |
| 862 | return; |
| 863 | } |
| 864 | if (destination.IsRegister()) { |
| 865 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 866 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 867 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 868 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 869 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 870 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 871 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 872 | } else if (destination.IsFpuRegister()) { |
| 873 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 874 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 875 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 876 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 877 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 878 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 879 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 880 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 881 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 882 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 883 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 884 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 885 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 886 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 887 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 888 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 889 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 890 | } |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 895 | if (source.Equals(destination)) { |
| 896 | return; |
| 897 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 898 | if (destination.IsRegisterPair()) { |
| 899 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 900 | EmitParallelMoves( |
| 901 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 902 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 903 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 904 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 905 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 906 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 907 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 908 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 909 | } else if (source.IsFpuRegisterPair()) { |
| 910 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 911 | destination.AsRegisterPairHigh<Register>(), |
| 912 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 913 | } else { |
| 914 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 915 | DCHECK(ExpectedPairLayout(destination)); |
| 916 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 917 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 918 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 919 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 920 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 921 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 922 | SP, |
| 923 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 924 | } else if (source.IsRegisterPair()) { |
| 925 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 926 | source.AsRegisterPairLow<Register>(), |
| 927 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 928 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 929 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 930 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 931 | } else { |
| 932 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 933 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 934 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 935 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 936 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 937 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 938 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 939 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 940 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 941 | SP, destination.GetStackIndex()); |
| 942 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 943 | } else if (source.IsFpuRegisterPair()) { |
| 944 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 945 | SP, |
| 946 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 947 | } else { |
| 948 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 949 | EmitParallelMoves( |
| 950 | Location::StackSlot(source.GetStackIndex()), |
| 951 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 952 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 953 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 954 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 955 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 956 | } |
| 957 | } |
| 958 | } |
| 959 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 960 | void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 961 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 962 | if (instruction->IsCurrentMethod()) { |
| 963 | Move32(location, Location::StackSlot(kCurrentMethodStackOffset)); |
| 964 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 965 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 966 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 967 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 968 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 969 | int32_t value = GetInt32ValueOf(const_to_move); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 970 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 971 | __ LoadImmediate(location.AsRegister<Register>(), value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 972 | } else { |
| 973 | DCHECK(location.IsStackSlot()); |
| 974 | __ LoadImmediate(IP, value); |
| 975 | __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); |
| 976 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 977 | } else { |
Nicolas Geoffray | 3747b48 | 2015-01-19 17:17:16 +0000 | [diff] [blame] | 978 | DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName(); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 979 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 980 | if (location.IsRegisterPair()) { |
| 981 | __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 982 | __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value)); |
| 983 | } else { |
| 984 | DCHECK(location.IsDoubleStackSlot()); |
| 985 | __ LoadImmediate(IP, Low32Bits(value)); |
| 986 | __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); |
| 987 | __ LoadImmediate(IP, High32Bits(value)); |
| 988 | __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize)); |
| 989 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 990 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 991 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 992 | uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
| 993 | switch (instruction->GetType()) { |
| 994 | case Primitive::kPrimBoolean: |
| 995 | case Primitive::kPrimByte: |
| 996 | case Primitive::kPrimChar: |
| 997 | case Primitive::kPrimShort: |
| 998 | case Primitive::kPrimInt: |
| 999 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1000 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1001 | Move32(location, Location::StackSlot(stack_slot)); |
| 1002 | break; |
| 1003 | |
| 1004 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1005 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1006 | Move64(location, Location::DoubleStackSlot(stack_slot)); |
| 1007 | break; |
| 1008 | |
| 1009 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1010 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1011 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 1012 | } else if (instruction->IsTemporary()) { |
| 1013 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1014 | if (temp_location.IsStackSlot()) { |
| 1015 | Move32(location, temp_location); |
| 1016 | } else { |
| 1017 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 1018 | Move64(location, temp_location); |
| 1019 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1020 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1021 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1022 | switch (instruction->GetType()) { |
| 1023 | case Primitive::kPrimBoolean: |
| 1024 | case Primitive::kPrimByte: |
| 1025 | case Primitive::kPrimChar: |
| 1026 | case Primitive::kPrimShort: |
| 1027 | case Primitive::kPrimNot: |
| 1028 | case Primitive::kPrimInt: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1029 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1030 | Move32(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1031 | break; |
| 1032 | |
| 1033 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1034 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1035 | Move64(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1036 | break; |
| 1037 | |
| 1038 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1039 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1040 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1041 | } |
| 1042 | } |
| 1043 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1044 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 1045 | DCHECK(location.IsRegister()); |
| 1046 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 1047 | } |
| 1048 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1049 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
| 1050 | if (Primitive::Is64BitType(dst_type)) { |
| 1051 | Move64(dst, src); |
| 1052 | } else { |
| 1053 | Move32(dst, src); |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1058 | if (location.IsRegister()) { |
| 1059 | locations->AddTemp(location); |
| 1060 | } else if (location.IsRegisterPair()) { |
| 1061 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1062 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1063 | } else { |
| 1064 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1065 | } |
| 1066 | } |
| 1067 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1068 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1069 | HInstruction* instruction, |
| 1070 | uint32_t dex_pc, |
| 1071 | SlowPathCode* slow_path) { |
| 1072 | InvokeRuntime(GetThreadOffset<kArmWordSize>(entrypoint).Int32Value(), |
| 1073 | instruction, |
| 1074 | dex_pc, |
| 1075 | slow_path); |
| 1076 | } |
| 1077 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1078 | void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset, |
| 1079 | HInstruction* instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1080 | uint32_t dex_pc, |
| 1081 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1082 | ValidateInvokeRuntime(instruction, slow_path); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1083 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 1084 | __ blx(LR); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1085 | RecordPcInfo(instruction, dex_pc, slow_path); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1086 | } |
| 1087 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1088 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1089 | DCHECK(!successor->IsExitBlock()); |
| 1090 | |
| 1091 | HBasicBlock* block = got->GetBlock(); |
| 1092 | HInstruction* previous = got->GetPrevious(); |
| 1093 | |
| 1094 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1095 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1096 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 1097 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1098 | return; |
| 1099 | } |
| 1100 | |
| 1101 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1102 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1103 | } |
| 1104 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1105 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1106 | } |
| 1107 | } |
| 1108 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1109 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 1110 | got->SetLocations(nullptr); |
| 1111 | } |
| 1112 | |
| 1113 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 1114 | HandleGoto(got, got->GetSuccessor()); |
| 1115 | } |
| 1116 | |
| 1117 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1118 | try_boundary->SetLocations(nullptr); |
| 1119 | } |
| 1120 | |
| 1121 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1122 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1123 | if (!successor->IsExitBlock()) { |
| 1124 | HandleGoto(try_boundary, successor); |
| 1125 | } |
| 1126 | } |
| 1127 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1128 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1129 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1132 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1135 | void InstructionCodeGeneratorARM::GenerateCompareWithImmediate(Register left, int32_t right) { |
| 1136 | ShifterOperand operand; |
| 1137 | if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, right, &operand)) { |
| 1138 | __ cmp(left, operand); |
| 1139 | } else { |
| 1140 | Register temp = IP; |
| 1141 | __ LoadImmediate(temp, right); |
| 1142 | __ cmp(left, ShifterOperand(temp)); |
| 1143 | } |
| 1144 | } |
| 1145 | |
| 1146 | void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond, |
| 1147 | Label* true_label, |
| 1148 | Label* false_label) { |
| 1149 | __ vmstat(); // transfer FP status register to ARM APSR. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1150 | // TODO: merge into a single branch (except "equal or unordered" and "not equal") |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1151 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1152 | __ b(true_label, VS); // VS for unordered. |
| 1153 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1154 | __ b(false_label, VS); // VS for unordered. |
| 1155 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1156 | __ b(true_label, ARMCondition(cond->GetCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 1160 | Label* true_label, |
| 1161 | Label* false_label) { |
| 1162 | LocationSummary* locations = cond->GetLocations(); |
| 1163 | Location left = locations->InAt(0); |
| 1164 | Location right = locations->InAt(1); |
| 1165 | IfCondition if_cond = cond->GetCondition(); |
| 1166 | |
| 1167 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1168 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 1169 | IfCondition true_high_cond = if_cond; |
| 1170 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1171 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1172 | |
| 1173 | // Set the conditions for the test, remembering that == needs to be |
| 1174 | // decided using the low words. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1175 | // TODO: consider avoiding jumps with temporary and CMP low+SBC high |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1176 | switch (if_cond) { |
| 1177 | case kCondEQ: |
| 1178 | case kCondNE: |
| 1179 | // Nothing to do. |
| 1180 | break; |
| 1181 | case kCondLT: |
| 1182 | false_high_cond = kCondGT; |
| 1183 | break; |
| 1184 | case kCondLE: |
| 1185 | true_high_cond = kCondLT; |
| 1186 | break; |
| 1187 | case kCondGT: |
| 1188 | false_high_cond = kCondLT; |
| 1189 | break; |
| 1190 | case kCondGE: |
| 1191 | true_high_cond = kCondGT; |
| 1192 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1193 | case kCondB: |
| 1194 | false_high_cond = kCondA; |
| 1195 | break; |
| 1196 | case kCondBE: |
| 1197 | true_high_cond = kCondB; |
| 1198 | break; |
| 1199 | case kCondA: |
| 1200 | false_high_cond = kCondB; |
| 1201 | break; |
| 1202 | case kCondAE: |
| 1203 | true_high_cond = kCondA; |
| 1204 | break; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1205 | } |
| 1206 | if (right.IsConstant()) { |
| 1207 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1208 | int32_t val_low = Low32Bits(value); |
| 1209 | int32_t val_high = High32Bits(value); |
| 1210 | |
| 1211 | GenerateCompareWithImmediate(left_high, val_high); |
| 1212 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1213 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1214 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1215 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1216 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1217 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1218 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1219 | } |
| 1220 | // Must be equal high, so compare the lows. |
| 1221 | GenerateCompareWithImmediate(left_low, val_low); |
| 1222 | } else { |
| 1223 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 1224 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 1225 | |
| 1226 | __ cmp(left_high, ShifterOperand(right_high)); |
| 1227 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1228 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1229 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1230 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1231 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1232 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1233 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1234 | } |
| 1235 | // Must be equal high, so compare the lows. |
| 1236 | __ cmp(left_low, ShifterOperand(right_low)); |
| 1237 | } |
| 1238 | // The last comparison might be unsigned. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1239 | // TODO: optimize cases where this is always true/false |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1240 | __ b(true_label, final_condition); |
| 1241 | } |
| 1242 | |
| 1243 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HIf* if_instr, |
| 1244 | HCondition* condition, |
| 1245 | Label* true_target, |
| 1246 | Label* false_target, |
| 1247 | Label* always_true_target) { |
| 1248 | LocationSummary* locations = condition->GetLocations(); |
| 1249 | Location left = locations->InAt(0); |
| 1250 | Location right = locations->InAt(1); |
| 1251 | |
| 1252 | // We don't want true_target as a nullptr. |
| 1253 | if (true_target == nullptr) { |
| 1254 | true_target = always_true_target; |
| 1255 | } |
| 1256 | bool falls_through = (false_target == nullptr); |
| 1257 | |
| 1258 | // FP compares don't like null false_targets. |
| 1259 | if (false_target == nullptr) { |
| 1260 | false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1261 | } |
| 1262 | |
| 1263 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1264 | switch (type) { |
| 1265 | case Primitive::kPrimLong: |
| 1266 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1267 | break; |
| 1268 | case Primitive::kPrimFloat: |
| 1269 | __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>()); |
| 1270 | GenerateFPJumps(condition, true_target, false_target); |
| 1271 | break; |
| 1272 | case Primitive::kPrimDouble: |
| 1273 | __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), |
| 1274 | FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); |
| 1275 | GenerateFPJumps(condition, true_target, false_target); |
| 1276 | break; |
| 1277 | default: |
| 1278 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1279 | } |
| 1280 | |
| 1281 | if (!falls_through) { |
| 1282 | __ b(false_target); |
| 1283 | } |
| 1284 | } |
| 1285 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1286 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
| 1287 | Label* true_target, |
| 1288 | Label* false_target, |
| 1289 | Label* always_true_target) { |
| 1290 | HInstruction* cond = instruction->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1291 | if (cond->IsIntConstant()) { |
| 1292 | // Constant condition, statically compared against 1. |
| 1293 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 1294 | if (cond_value == 1) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1295 | if (always_true_target != nullptr) { |
| 1296 | __ b(always_true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1297 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1298 | return; |
| 1299 | } else { |
| 1300 | DCHECK_EQ(cond_value, 0); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1301 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1302 | } else { |
| 1303 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1304 | // Condition has been materialized, compare the output to 0 |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1305 | DCHECK(instruction->GetLocations()->InAt(0).IsRegister()); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 1306 | __ CompareAndBranchIfNonZero(instruction->GetLocations()->InAt(0).AsRegister<Register>(), |
| 1307 | true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1308 | } else { |
| 1309 | // Condition has not been materialized, use its inputs as the |
| 1310 | // comparison and its condition as the branch condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1311 | Primitive::Type type = |
| 1312 | cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt; |
| 1313 | // Is this a long or FP comparison that has been folded into the HCondition? |
| 1314 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1315 | // Generate the comparison directly. |
| 1316 | GenerateCompareTestAndBranch(instruction->AsIf(), cond->AsCondition(), |
| 1317 | true_target, false_target, always_true_target); |
| 1318 | return; |
| 1319 | } |
| 1320 | |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1321 | LocationSummary* locations = cond->GetLocations(); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1322 | DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0); |
Nicolas Geoffray | 3bcc8ea | 2014-11-28 15:00:02 +0000 | [diff] [blame] | 1323 | Register left = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1324 | Location right = locations->InAt(1); |
| 1325 | if (right.IsRegister()) { |
| 1326 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1327 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1328 | DCHECK(right.IsConstant()); |
| 1329 | GenerateCompareWithImmediate(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1330 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1331 | __ b(true_target, ARMCondition(cond->AsCondition()->GetCondition())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1332 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1333 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1334 | if (false_target != nullptr) { |
| 1335 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1336 | } |
| 1337 | } |
| 1338 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1339 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
| 1340 | LocationSummary* locations = |
| 1341 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
| 1342 | HInstruction* cond = if_instr->InputAt(0); |
| 1343 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1344 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
| 1349 | Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 1350 | Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1351 | Label* always_true_target = true_target; |
| 1352 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1353 | if_instr->IfTrueSuccessor())) { |
| 1354 | always_true_target = nullptr; |
| 1355 | } |
| 1356 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1357 | if_instr->IfFalseSuccessor())) { |
| 1358 | false_target = nullptr; |
| 1359 | } |
| 1360 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 1361 | } |
| 1362 | |
| 1363 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1364 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1365 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 1366 | HInstruction* cond = deoptimize->InputAt(0); |
Aart Bik | bb245d1 | 2015-10-19 11:05:03 -0700 | [diff] [blame] | 1367 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1368 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1369 | } |
| 1370 | } |
| 1371 | |
| 1372 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 1373 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1374 | DeoptimizationSlowPathARM(deoptimize); |
| 1375 | codegen_->AddSlowPath(slow_path); |
| 1376 | Label* slow_path_entry = slow_path->GetEntryLabel(); |
| 1377 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 1378 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1379 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1380 | void LocationsBuilderARM::VisitCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1381 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1382 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1383 | // Handle the long/FP comparisons made in instruction simplification. |
| 1384 | switch (cond->InputAt(0)->GetType()) { |
| 1385 | case Primitive::kPrimLong: |
| 1386 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1387 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1388 | if (cond->NeedsMaterialization()) { |
| 1389 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 1390 | } |
| 1391 | break; |
| 1392 | |
| 1393 | case Primitive::kPrimFloat: |
| 1394 | case Primitive::kPrimDouble: |
| 1395 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1396 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1397 | if (cond->NeedsMaterialization()) { |
| 1398 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1399 | } |
| 1400 | break; |
| 1401 | |
| 1402 | default: |
| 1403 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1404 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1405 | if (cond->NeedsMaterialization()) { |
| 1406 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1407 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1408 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1409 | } |
| 1410 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1411 | void InstructionCodeGeneratorARM::VisitCondition(HCondition* cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1412 | if (!cond->NeedsMaterialization()) { |
| 1413 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1414 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1415 | |
| 1416 | LocationSummary* locations = cond->GetLocations(); |
| 1417 | Location left = locations->InAt(0); |
| 1418 | Location right = locations->InAt(1); |
| 1419 | Register out = locations->Out().AsRegister<Register>(); |
| 1420 | Label true_label, false_label; |
| 1421 | |
| 1422 | switch (cond->InputAt(0)->GetType()) { |
| 1423 | default: { |
| 1424 | // Integer case. |
| 1425 | if (right.IsRegister()) { |
| 1426 | __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>())); |
| 1427 | } else { |
| 1428 | DCHECK(right.IsConstant()); |
| 1429 | GenerateCompareWithImmediate(left.AsRegister<Register>(), |
| 1430 | CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
| 1431 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1432 | __ it(ARMCondition(cond->GetCondition()), kItElse); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1433 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1434 | ARMCondition(cond->GetCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1435 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1436 | ARMCondition(cond->GetOppositeCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1437 | return; |
| 1438 | } |
| 1439 | case Primitive::kPrimLong: |
| 1440 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1441 | break; |
| 1442 | case Primitive::kPrimFloat: |
| 1443 | __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>()); |
| 1444 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1445 | break; |
| 1446 | case Primitive::kPrimDouble: |
| 1447 | __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), |
| 1448 | FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); |
| 1449 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1450 | break; |
| 1451 | } |
| 1452 | |
| 1453 | // Convert the jumps into the result. |
| 1454 | Label done_label; |
| 1455 | |
| 1456 | // False case: result = 0. |
| 1457 | __ Bind(&false_label); |
| 1458 | __ LoadImmediate(out, 0); |
| 1459 | __ b(&done_label); |
| 1460 | |
| 1461 | // True case: result = 1. |
| 1462 | __ Bind(&true_label); |
| 1463 | __ LoadImmediate(out, 1); |
| 1464 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
| 1468 | VisitCondition(comp); |
| 1469 | } |
| 1470 | |
| 1471 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
| 1472 | VisitCondition(comp); |
| 1473 | } |
| 1474 | |
| 1475 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
| 1476 | VisitCondition(comp); |
| 1477 | } |
| 1478 | |
| 1479 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
| 1480 | VisitCondition(comp); |
| 1481 | } |
| 1482 | |
| 1483 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
| 1484 | VisitCondition(comp); |
| 1485 | } |
| 1486 | |
| 1487 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
| 1488 | VisitCondition(comp); |
| 1489 | } |
| 1490 | |
| 1491 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1492 | VisitCondition(comp); |
| 1493 | } |
| 1494 | |
| 1495 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1496 | VisitCondition(comp); |
| 1497 | } |
| 1498 | |
| 1499 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
| 1500 | VisitCondition(comp); |
| 1501 | } |
| 1502 | |
| 1503 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
| 1504 | VisitCondition(comp); |
| 1505 | } |
| 1506 | |
| 1507 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1508 | VisitCondition(comp); |
| 1509 | } |
| 1510 | |
| 1511 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1512 | VisitCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1513 | } |
| 1514 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1515 | void LocationsBuilderARM::VisitBelow(HBelow* comp) { |
| 1516 | VisitCondition(comp); |
| 1517 | } |
| 1518 | |
| 1519 | void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) { |
| 1520 | VisitCondition(comp); |
| 1521 | } |
| 1522 | |
| 1523 | void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 1524 | VisitCondition(comp); |
| 1525 | } |
| 1526 | |
| 1527 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 1528 | VisitCondition(comp); |
| 1529 | } |
| 1530 | |
| 1531 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
| 1532 | VisitCondition(comp); |
| 1533 | } |
| 1534 | |
| 1535 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
| 1536 | VisitCondition(comp); |
| 1537 | } |
| 1538 | |
| 1539 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 1540 | VisitCondition(comp); |
| 1541 | } |
| 1542 | |
| 1543 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 1544 | VisitCondition(comp); |
| 1545 | } |
| 1546 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1547 | void LocationsBuilderARM::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1548 | local->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1549 | } |
| 1550 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1551 | void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) { |
| 1552 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1553 | } |
| 1554 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1555 | void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1556 | load->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1557 | } |
| 1558 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1559 | void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1560 | // Nothing to do, this is driven by the code generator. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1561 | } |
| 1562 | |
| 1563 | void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1564 | LocationSummary* locations = |
| 1565 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1566 | switch (store->InputAt(1)->GetType()) { |
| 1567 | case Primitive::kPrimBoolean: |
| 1568 | case Primitive::kPrimByte: |
| 1569 | case Primitive::kPrimChar: |
| 1570 | case Primitive::kPrimShort: |
| 1571 | case Primitive::kPrimInt: |
| 1572 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1573 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1574 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1575 | break; |
| 1576 | |
| 1577 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1578 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1579 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1580 | break; |
| 1581 | |
| 1582 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1583 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1584 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1587 | void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1591 | LocationSummary* locations = |
| 1592 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1593 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1594 | } |
| 1595 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1596 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1597 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1598 | } |
| 1599 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1600 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 1601 | LocationSummary* locations = |
| 1602 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1603 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1604 | } |
| 1605 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1606 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1607 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1608 | } |
| 1609 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1610 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1611 | LocationSummary* locations = |
| 1612 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1613 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1614 | } |
| 1615 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1616 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1617 | // Will be generated at use site. |
| 1618 | } |
| 1619 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1620 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 1621 | LocationSummary* locations = |
| 1622 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1623 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1624 | } |
| 1625 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1626 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1627 | // Will be generated at use site. |
| 1628 | } |
| 1629 | |
| 1630 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1631 | LocationSummary* locations = |
| 1632 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1633 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1634 | } |
| 1635 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1636 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1637 | // Will be generated at use site. |
| 1638 | } |
| 1639 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1640 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1641 | memory_barrier->SetLocations(nullptr); |
| 1642 | } |
| 1643 | |
| 1644 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1645 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1646 | } |
| 1647 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1648 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1649 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1650 | } |
| 1651 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1652 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1653 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1654 | } |
| 1655 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1656 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1657 | LocationSummary* locations = |
| 1658 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1659 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1660 | } |
| 1661 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1662 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1663 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1664 | } |
| 1665 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1666 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1667 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1668 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1669 | // the method_idx. |
| 1670 | HandleInvoke(invoke); |
| 1671 | } |
| 1672 | |
| 1673 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1674 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1675 | } |
| 1676 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1677 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1678 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1679 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1680 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1681 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1682 | IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(), |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1683 | codegen_->GetAssembler(), |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1684 | codegen_->GetInstructionSetFeatures()); |
| 1685 | if (intrinsic.TryDispatch(invoke)) { |
| 1686 | return; |
| 1687 | } |
| 1688 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1689 | HandleInvoke(invoke); |
| 1690 | } |
| 1691 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1692 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 1693 | if (invoke->GetLocations()->Intrinsified()) { |
| 1694 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 1695 | intrinsic.Dispatch(invoke); |
| 1696 | return true; |
| 1697 | } |
| 1698 | return false; |
| 1699 | } |
| 1700 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1701 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1702 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1703 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1704 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1705 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1706 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1707 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1708 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1709 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1710 | LocationSummary* locations = invoke->GetLocations(); |
| 1711 | codegen_->GenerateStaticOrDirectCall( |
| 1712 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 1713 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1714 | } |
| 1715 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1716 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1717 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1718 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1719 | } |
| 1720 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1721 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1722 | IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(), |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1723 | codegen_->GetAssembler(), |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1724 | codegen_->GetInstructionSetFeatures()); |
| 1725 | if (intrinsic.TryDispatch(invoke)) { |
| 1726 | return; |
| 1727 | } |
| 1728 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1729 | HandleInvoke(invoke); |
| 1730 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1731 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1732 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1733 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1734 | return; |
| 1735 | } |
| 1736 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1737 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1738 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1739 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1740 | } |
| 1741 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1742 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1743 | HandleInvoke(invoke); |
| 1744 | // Add the hidden argument. |
| 1745 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 1746 | } |
| 1747 | |
| 1748 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1749 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1750 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1751 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 1752 | invoke->GetImtIndex() % mirror::Class::kImtSize, kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1753 | LocationSummary* locations = invoke->GetLocations(); |
| 1754 | Location receiver = locations->InAt(0); |
| 1755 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1756 | |
| 1757 | // Set the hidden argument. |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1758 | __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(), |
| 1759 | invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1760 | |
| 1761 | // temp = object->GetClass(); |
| 1762 | if (receiver.IsStackSlot()) { |
| 1763 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 1764 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 1765 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1766 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1767 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1768 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1769 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1770 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1771 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1772 | kArmWordSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1773 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 1774 | // LR = temp->GetEntryPoint(); |
| 1775 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 1776 | // LR(); |
| 1777 | __ blx(LR); |
| 1778 | DCHECK(!codegen_->IsLeafMethod()); |
| 1779 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1780 | } |
| 1781 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1782 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 1783 | LocationSummary* locations = |
| 1784 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1785 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 1786 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1787 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 1788 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1789 | break; |
| 1790 | } |
| 1791 | case Primitive::kPrimLong: { |
| 1792 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1793 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1794 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1795 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1796 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1797 | case Primitive::kPrimFloat: |
| 1798 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1799 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1800 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1801 | break; |
| 1802 | |
| 1803 | default: |
| 1804 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1805 | } |
| 1806 | } |
| 1807 | |
| 1808 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 1809 | LocationSummary* locations = neg->GetLocations(); |
| 1810 | Location out = locations->Out(); |
| 1811 | Location in = locations->InAt(0); |
| 1812 | switch (neg->GetResultType()) { |
| 1813 | case Primitive::kPrimInt: |
| 1814 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1815 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1816 | break; |
| 1817 | |
| 1818 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1819 | DCHECK(in.IsRegisterPair()); |
| 1820 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 1821 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 1822 | in.AsRegisterPairLow<Register>(), |
| 1823 | ShifterOperand(0)); |
| 1824 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 1825 | // instruction here, as it does not exist in the Thumb-2 |
| 1826 | // instruction set. We use the following approach |
| 1827 | // using SBC and SUB instead. |
| 1828 | // |
| 1829 | // out.hi = -C |
| 1830 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 1831 | out.AsRegisterPairHigh<Register>(), |
| 1832 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 1833 | // out.hi = out.hi - in.hi |
| 1834 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 1835 | out.AsRegisterPairHigh<Register>(), |
| 1836 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 1837 | break; |
| 1838 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1839 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1840 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1841 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1842 | break; |
| 1843 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1844 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1845 | DCHECK(in.IsFpuRegisterPair()); |
| 1846 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1847 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1848 | break; |
| 1849 | |
| 1850 | default: |
| 1851 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1852 | } |
| 1853 | } |
| 1854 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1855 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1856 | Primitive::Type result_type = conversion->GetResultType(); |
| 1857 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1858 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1859 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 1860 | // The float-to-long, double-to-long and long-to-float type conversions |
| 1861 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1862 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 1863 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 1864 | && result_type == Primitive::kPrimLong) |
| 1865 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1866 | ? LocationSummary::kCall |
| 1867 | : LocationSummary::kNoCall; |
| 1868 | LocationSummary* locations = |
| 1869 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 1870 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1871 | // The Java language does not allow treating boolean as an integral type but |
| 1872 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1873 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1874 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1875 | case Primitive::kPrimByte: |
| 1876 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1877 | case Primitive::kPrimBoolean: |
| 1878 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1879 | case Primitive::kPrimShort: |
| 1880 | case Primitive::kPrimInt: |
| 1881 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1882 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1883 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1884 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1885 | break; |
| 1886 | |
| 1887 | default: |
| 1888 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1889 | << " to " << result_type; |
| 1890 | } |
| 1891 | break; |
| 1892 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1893 | case Primitive::kPrimShort: |
| 1894 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1895 | case Primitive::kPrimBoolean: |
| 1896 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1897 | case Primitive::kPrimByte: |
| 1898 | case Primitive::kPrimInt: |
| 1899 | case Primitive::kPrimChar: |
| 1900 | // Processing a Dex `int-to-short' instruction. |
| 1901 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1902 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1903 | break; |
| 1904 | |
| 1905 | default: |
| 1906 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1907 | << " to " << result_type; |
| 1908 | } |
| 1909 | break; |
| 1910 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1911 | case Primitive::kPrimInt: |
| 1912 | switch (input_type) { |
| 1913 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1914 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1915 | locations->SetInAt(0, Location::Any()); |
| 1916 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1917 | break; |
| 1918 | |
| 1919 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1920 | // Processing a Dex `float-to-int' instruction. |
| 1921 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1922 | locations->SetOut(Location::RequiresRegister()); |
| 1923 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1924 | break; |
| 1925 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1926 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1927 | // Processing a Dex `double-to-int' instruction. |
| 1928 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1929 | locations->SetOut(Location::RequiresRegister()); |
| 1930 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1931 | break; |
| 1932 | |
| 1933 | default: |
| 1934 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1935 | << " to " << result_type; |
| 1936 | } |
| 1937 | break; |
| 1938 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1939 | case Primitive::kPrimLong: |
| 1940 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1941 | case Primitive::kPrimBoolean: |
| 1942 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1943 | case Primitive::kPrimByte: |
| 1944 | case Primitive::kPrimShort: |
| 1945 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1946 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1947 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1948 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1949 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1950 | break; |
| 1951 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1952 | case Primitive::kPrimFloat: { |
| 1953 | // Processing a Dex `float-to-long' instruction. |
| 1954 | InvokeRuntimeCallingConvention calling_convention; |
| 1955 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 1956 | calling_convention.GetFpuRegisterAt(0))); |
| 1957 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 1958 | break; |
| 1959 | } |
| 1960 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1961 | case Primitive::kPrimDouble: { |
| 1962 | // Processing a Dex `double-to-long' instruction. |
| 1963 | InvokeRuntimeCallingConvention calling_convention; |
| 1964 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 1965 | calling_convention.GetFpuRegisterAt(0), |
| 1966 | calling_convention.GetFpuRegisterAt(1))); |
| 1967 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1968 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1969 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1970 | |
| 1971 | default: |
| 1972 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1973 | << " to " << result_type; |
| 1974 | } |
| 1975 | break; |
| 1976 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1977 | case Primitive::kPrimChar: |
| 1978 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1979 | case Primitive::kPrimBoolean: |
| 1980 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1981 | case Primitive::kPrimByte: |
| 1982 | case Primitive::kPrimShort: |
| 1983 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1984 | // Processing a Dex `int-to-char' instruction. |
| 1985 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1986 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1987 | break; |
| 1988 | |
| 1989 | default: |
| 1990 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1991 | << " to " << result_type; |
| 1992 | } |
| 1993 | break; |
| 1994 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1995 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1996 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1997 | case Primitive::kPrimBoolean: |
| 1998 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1999 | case Primitive::kPrimByte: |
| 2000 | case Primitive::kPrimShort: |
| 2001 | case Primitive::kPrimInt: |
| 2002 | case Primitive::kPrimChar: |
| 2003 | // Processing a Dex `int-to-float' instruction. |
| 2004 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2005 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2006 | break; |
| 2007 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2008 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2009 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2010 | InvokeRuntimeCallingConvention calling_convention; |
| 2011 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2012 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2013 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2014 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2015 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2016 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2017 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2018 | // Processing a Dex `double-to-float' instruction. |
| 2019 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2020 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2021 | break; |
| 2022 | |
| 2023 | default: |
| 2024 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2025 | << " to " << result_type; |
| 2026 | }; |
| 2027 | break; |
| 2028 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2029 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2030 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2031 | case Primitive::kPrimBoolean: |
| 2032 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2033 | case Primitive::kPrimByte: |
| 2034 | case Primitive::kPrimShort: |
| 2035 | case Primitive::kPrimInt: |
| 2036 | case Primitive::kPrimChar: |
| 2037 | // Processing a Dex `int-to-double' instruction. |
| 2038 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2039 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2040 | break; |
| 2041 | |
| 2042 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2043 | // Processing a Dex `long-to-double' instruction. |
| 2044 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2045 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2046 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2047 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2048 | break; |
| 2049 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2050 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2051 | // Processing a Dex `float-to-double' instruction. |
| 2052 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2053 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2054 | break; |
| 2055 | |
| 2056 | default: |
| 2057 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2058 | << " to " << result_type; |
| 2059 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2060 | break; |
| 2061 | |
| 2062 | default: |
| 2063 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2064 | << " to " << result_type; |
| 2065 | } |
| 2066 | } |
| 2067 | |
| 2068 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 2069 | LocationSummary* locations = conversion->GetLocations(); |
| 2070 | Location out = locations->Out(); |
| 2071 | Location in = locations->InAt(0); |
| 2072 | Primitive::Type result_type = conversion->GetResultType(); |
| 2073 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2074 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2075 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2076 | case Primitive::kPrimByte: |
| 2077 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2078 | case Primitive::kPrimBoolean: |
| 2079 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2080 | case Primitive::kPrimShort: |
| 2081 | case Primitive::kPrimInt: |
| 2082 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2083 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2084 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2085 | break; |
| 2086 | |
| 2087 | default: |
| 2088 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2089 | << " to " << result_type; |
| 2090 | } |
| 2091 | break; |
| 2092 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2093 | case Primitive::kPrimShort: |
| 2094 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2095 | case Primitive::kPrimBoolean: |
| 2096 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2097 | case Primitive::kPrimByte: |
| 2098 | case Primitive::kPrimInt: |
| 2099 | case Primitive::kPrimChar: |
| 2100 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2101 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2102 | break; |
| 2103 | |
| 2104 | default: |
| 2105 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2106 | << " to " << result_type; |
| 2107 | } |
| 2108 | break; |
| 2109 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2110 | case Primitive::kPrimInt: |
| 2111 | switch (input_type) { |
| 2112 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2113 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2114 | DCHECK(out.IsRegister()); |
| 2115 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2116 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2117 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2118 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2119 | } else { |
| 2120 | DCHECK(in.IsConstant()); |
| 2121 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2122 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2123 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2124 | } |
| 2125 | break; |
| 2126 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2127 | case Primitive::kPrimFloat: { |
| 2128 | // Processing a Dex `float-to-int' instruction. |
| 2129 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
| 2130 | __ vmovs(temp, in.AsFpuRegister<SRegister>()); |
| 2131 | __ vcvtis(temp, temp); |
| 2132 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 2133 | break; |
| 2134 | } |
| 2135 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2136 | case Primitive::kPrimDouble: { |
| 2137 | // Processing a Dex `double-to-int' instruction. |
| 2138 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
| 2139 | DRegister temp_d = FromLowSToD(temp_s); |
| 2140 | __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
| 2141 | __ vcvtid(temp_s, temp_d); |
| 2142 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2143 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2144 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2145 | |
| 2146 | default: |
| 2147 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2148 | << " to " << result_type; |
| 2149 | } |
| 2150 | break; |
| 2151 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2152 | case Primitive::kPrimLong: |
| 2153 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2154 | case Primitive::kPrimBoolean: |
| 2155 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2156 | case Primitive::kPrimByte: |
| 2157 | case Primitive::kPrimShort: |
| 2158 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2159 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2160 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2161 | DCHECK(out.IsRegisterPair()); |
| 2162 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2163 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2164 | // Sign extension. |
| 2165 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 2166 | out.AsRegisterPairLow<Register>(), |
| 2167 | 31); |
| 2168 | break; |
| 2169 | |
| 2170 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2171 | // Processing a Dex `float-to-long' instruction. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2172 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2173 | conversion, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2174 | conversion->GetDexPc(), |
| 2175 | nullptr); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2176 | break; |
| 2177 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2178 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2179 | // Processing a Dex `double-to-long' instruction. |
| 2180 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2181 | conversion, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2182 | conversion->GetDexPc(), |
| 2183 | nullptr); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2184 | break; |
| 2185 | |
| 2186 | default: |
| 2187 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2188 | << " to " << result_type; |
| 2189 | } |
| 2190 | break; |
| 2191 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2192 | case Primitive::kPrimChar: |
| 2193 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2194 | case Primitive::kPrimBoolean: |
| 2195 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2196 | case Primitive::kPrimByte: |
| 2197 | case Primitive::kPrimShort: |
| 2198 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2199 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2200 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2201 | break; |
| 2202 | |
| 2203 | default: |
| 2204 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2205 | << " to " << result_type; |
| 2206 | } |
| 2207 | break; |
| 2208 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2209 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2210 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2211 | case Primitive::kPrimBoolean: |
| 2212 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2213 | case Primitive::kPrimByte: |
| 2214 | case Primitive::kPrimShort: |
| 2215 | case Primitive::kPrimInt: |
| 2216 | case Primitive::kPrimChar: { |
| 2217 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2218 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 2219 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2220 | break; |
| 2221 | } |
| 2222 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2223 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2224 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2225 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f), |
| 2226 | conversion, |
| 2227 | conversion->GetDexPc(), |
| 2228 | nullptr); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2229 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2230 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2231 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2232 | // Processing a Dex `double-to-float' instruction. |
| 2233 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 2234 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2235 | break; |
| 2236 | |
| 2237 | default: |
| 2238 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2239 | << " to " << result_type; |
| 2240 | }; |
| 2241 | break; |
| 2242 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2243 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2244 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2245 | case Primitive::kPrimBoolean: |
| 2246 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2247 | case Primitive::kPrimByte: |
| 2248 | case Primitive::kPrimShort: |
| 2249 | case Primitive::kPrimInt: |
| 2250 | case Primitive::kPrimChar: { |
| 2251 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2252 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2253 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2254 | out.AsFpuRegisterPairLow<SRegister>()); |
| 2255 | break; |
| 2256 | } |
| 2257 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2258 | case Primitive::kPrimLong: { |
| 2259 | // Processing a Dex `long-to-double' instruction. |
| 2260 | Register low = in.AsRegisterPairLow<Register>(); |
| 2261 | Register high = in.AsRegisterPairHigh<Register>(); |
| 2262 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 2263 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2264 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2265 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2266 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 2267 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2268 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2269 | // temp_d = int-to-double(high) |
| 2270 | __ vmovsr(temp_s, high); |
| 2271 | __ vcvtdi(temp_d, temp_s); |
| 2272 | // constant_d = k2Pow32EncodingForDouble |
| 2273 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 2274 | // out_d = unsigned-to-double(low) |
| 2275 | __ vmovsr(out_s, low); |
| 2276 | __ vcvtdu(out_d, out_s); |
| 2277 | // out_d += temp_d * constant_d |
| 2278 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2279 | break; |
| 2280 | } |
| 2281 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2282 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2283 | // Processing a Dex `float-to-double' instruction. |
| 2284 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2285 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2286 | break; |
| 2287 | |
| 2288 | default: |
| 2289 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2290 | << " to " << result_type; |
| 2291 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2292 | break; |
| 2293 | |
| 2294 | default: |
| 2295 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2296 | << " to " << result_type; |
| 2297 | } |
| 2298 | } |
| 2299 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2300 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2301 | LocationSummary* locations = |
| 2302 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2303 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2304 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2305 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2306 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2307 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2308 | break; |
| 2309 | } |
| 2310 | |
| 2311 | case Primitive::kPrimLong: { |
| 2312 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2313 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2314 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2315 | break; |
| 2316 | } |
| 2317 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2318 | case Primitive::kPrimFloat: |
| 2319 | case Primitive::kPrimDouble: { |
| 2320 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2321 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2322 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2323 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2324 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2325 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2326 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2327 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2328 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 2332 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2333 | Location out = locations->Out(); |
| 2334 | Location first = locations->InAt(0); |
| 2335 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2336 | switch (add->GetResultType()) { |
| 2337 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2338 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2339 | __ add(out.AsRegister<Register>(), |
| 2340 | first.AsRegister<Register>(), |
| 2341 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2342 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2343 | __ AddConstant(out.AsRegister<Register>(), |
| 2344 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2345 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2346 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2347 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2348 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2349 | case Primitive::kPrimLong: { |
| 2350 | DCHECK(second.IsRegisterPair()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2351 | __ adds(out.AsRegisterPairLow<Register>(), |
| 2352 | first.AsRegisterPairLow<Register>(), |
| 2353 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2354 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 2355 | first.AsRegisterPairHigh<Register>(), |
| 2356 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2357 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2358 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2359 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2360 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2361 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 2362 | first.AsFpuRegister<SRegister>(), |
| 2363 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2364 | break; |
| 2365 | |
| 2366 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2367 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2368 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2369 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2370 | break; |
| 2371 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2372 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2373 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2374 | } |
| 2375 | } |
| 2376 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2377 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2378 | LocationSummary* locations = |
| 2379 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2380 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2381 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2382 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2383 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2384 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2385 | break; |
| 2386 | } |
| 2387 | |
| 2388 | case Primitive::kPrimLong: { |
| 2389 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2390 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2391 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2392 | break; |
| 2393 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2394 | case Primitive::kPrimFloat: |
| 2395 | case Primitive::kPrimDouble: { |
| 2396 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2397 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2398 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2399 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2400 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2401 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2402 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2403 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2404 | } |
| 2405 | |
| 2406 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 2407 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2408 | Location out = locations->Out(); |
| 2409 | Location first = locations->InAt(0); |
| 2410 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2411 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2412 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2413 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2414 | __ sub(out.AsRegister<Register>(), |
| 2415 | first.AsRegister<Register>(), |
| 2416 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2417 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2418 | __ AddConstant(out.AsRegister<Register>(), |
| 2419 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2420 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2421 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2422 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2423 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2424 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2425 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2426 | DCHECK(second.IsRegisterPair()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2427 | __ subs(out.AsRegisterPairLow<Register>(), |
| 2428 | first.AsRegisterPairLow<Register>(), |
| 2429 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2430 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2431 | first.AsRegisterPairHigh<Register>(), |
| 2432 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2433 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2434 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2435 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2436 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2437 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 2438 | first.AsFpuRegister<SRegister>(), |
| 2439 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2440 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2441 | } |
| 2442 | |
| 2443 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2444 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2445 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2446 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2447 | break; |
| 2448 | } |
| 2449 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2450 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2451 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2452 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2453 | } |
| 2454 | } |
| 2455 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2456 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 2457 | LocationSummary* locations = |
| 2458 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2459 | switch (mul->GetResultType()) { |
| 2460 | case Primitive::kPrimInt: |
| 2461 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2462 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2463 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2464 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2465 | break; |
| 2466 | } |
| 2467 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2468 | case Primitive::kPrimFloat: |
| 2469 | case Primitive::kPrimDouble: { |
| 2470 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2471 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2472 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2473 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2474 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2475 | |
| 2476 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2477 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2478 | } |
| 2479 | } |
| 2480 | |
| 2481 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 2482 | LocationSummary* locations = mul->GetLocations(); |
| 2483 | Location out = locations->Out(); |
| 2484 | Location first = locations->InAt(0); |
| 2485 | Location second = locations->InAt(1); |
| 2486 | switch (mul->GetResultType()) { |
| 2487 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2488 | __ mul(out.AsRegister<Register>(), |
| 2489 | first.AsRegister<Register>(), |
| 2490 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2491 | break; |
| 2492 | } |
| 2493 | case Primitive::kPrimLong: { |
| 2494 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 2495 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 2496 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2497 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 2498 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2499 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2500 | |
| 2501 | // Extra checks to protect caused by the existence of R1_R2. |
| 2502 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 2503 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 2504 | DCHECK_NE(out_hi, in1_lo); |
| 2505 | DCHECK_NE(out_hi, in2_lo); |
| 2506 | |
| 2507 | // input: in1 - 64 bits, in2 - 64 bits |
| 2508 | // output: out |
| 2509 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2510 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2511 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 2512 | |
| 2513 | // IP <- in1.lo * in2.hi |
| 2514 | __ mul(IP, in1_lo, in2_hi); |
| 2515 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2516 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 2517 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 2518 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 2519 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2520 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 2521 | break; |
| 2522 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2523 | |
| 2524 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2525 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 2526 | first.AsFpuRegister<SRegister>(), |
| 2527 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2528 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2529 | } |
| 2530 | |
| 2531 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2532 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2533 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2534 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2535 | break; |
| 2536 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2537 | |
| 2538 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2539 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2540 | } |
| 2541 | } |
| 2542 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2543 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2544 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2545 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2546 | |
| 2547 | LocationSummary* locations = instruction->GetLocations(); |
| 2548 | Location second = locations->InAt(1); |
| 2549 | DCHECK(second.IsConstant()); |
| 2550 | |
| 2551 | Register out = locations->Out().AsRegister<Register>(); |
| 2552 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2553 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2554 | DCHECK(imm == 1 || imm == -1); |
| 2555 | |
| 2556 | if (instruction->IsRem()) { |
| 2557 | __ LoadImmediate(out, 0); |
| 2558 | } else { |
| 2559 | if (imm == 1) { |
| 2560 | __ Mov(out, dividend); |
| 2561 | } else { |
| 2562 | __ rsb(out, dividend, ShifterOperand(0)); |
| 2563 | } |
| 2564 | } |
| 2565 | } |
| 2566 | |
| 2567 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2568 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2569 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2570 | |
| 2571 | LocationSummary* locations = instruction->GetLocations(); |
| 2572 | Location second = locations->InAt(1); |
| 2573 | DCHECK(second.IsConstant()); |
| 2574 | |
| 2575 | Register out = locations->Out().AsRegister<Register>(); |
| 2576 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2577 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2578 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 2579 | uint32_t abs_imm = static_cast<uint32_t>(std::abs(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2580 | DCHECK(IsPowerOfTwo(abs_imm)); |
| 2581 | int ctz_imm = CTZ(abs_imm); |
| 2582 | |
| 2583 | if (ctz_imm == 1) { |
| 2584 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 2585 | } else { |
| 2586 | __ Asr(temp, dividend, 31); |
| 2587 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 2588 | } |
| 2589 | __ add(out, temp, ShifterOperand(dividend)); |
| 2590 | |
| 2591 | if (instruction->IsDiv()) { |
| 2592 | __ Asr(out, out, ctz_imm); |
| 2593 | if (imm < 0) { |
| 2594 | __ rsb(out, out, ShifterOperand(0)); |
| 2595 | } |
| 2596 | } else { |
| 2597 | __ ubfx(out, out, 0, ctz_imm); |
| 2598 | __ sub(out, out, ShifterOperand(temp)); |
| 2599 | } |
| 2600 | } |
| 2601 | |
| 2602 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2603 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2604 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2605 | |
| 2606 | LocationSummary* locations = instruction->GetLocations(); |
| 2607 | Location second = locations->InAt(1); |
| 2608 | DCHECK(second.IsConstant()); |
| 2609 | |
| 2610 | Register out = locations->Out().AsRegister<Register>(); |
| 2611 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2612 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 2613 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 2614 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2615 | |
| 2616 | int64_t magic; |
| 2617 | int shift; |
| 2618 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2619 | |
| 2620 | __ LoadImmediate(temp1, magic); |
| 2621 | __ smull(temp2, temp1, dividend, temp1); |
| 2622 | |
| 2623 | if (imm > 0 && magic < 0) { |
| 2624 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 2625 | } else if (imm < 0 && magic > 0) { |
| 2626 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 2627 | } |
| 2628 | |
| 2629 | if (shift != 0) { |
| 2630 | __ Asr(temp1, temp1, shift); |
| 2631 | } |
| 2632 | |
| 2633 | if (instruction->IsDiv()) { |
| 2634 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 2635 | } else { |
| 2636 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 2637 | // TODO: Strength reduction for mls. |
| 2638 | __ LoadImmediate(temp2, imm); |
| 2639 | __ mls(out, temp1, temp2, dividend); |
| 2640 | } |
| 2641 | } |
| 2642 | |
| 2643 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 2644 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2645 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2646 | |
| 2647 | LocationSummary* locations = instruction->GetLocations(); |
| 2648 | Location second = locations->InAt(1); |
| 2649 | DCHECK(second.IsConstant()); |
| 2650 | |
| 2651 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2652 | if (imm == 0) { |
| 2653 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2654 | } else if (imm == 1 || imm == -1) { |
| 2655 | DivRemOneOrMinusOne(instruction); |
| 2656 | } else if (IsPowerOfTwo(std::abs(imm))) { |
| 2657 | DivRemByPowerOfTwo(instruction); |
| 2658 | } else { |
| 2659 | DCHECK(imm <= -2 || imm >= 2); |
| 2660 | GenerateDivRemWithAnyConstant(instruction); |
| 2661 | } |
| 2662 | } |
| 2663 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2664 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2665 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 2666 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 2667 | // pLdiv runtime call. |
| 2668 | call_kind = LocationSummary::kCall; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2669 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 2670 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2671 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 2672 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 2673 | // pIdivmod runtime call. |
| 2674 | call_kind = LocationSummary::kCall; |
| 2675 | } |
| 2676 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2677 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2678 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2679 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2680 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2681 | if (div->InputAt(1)->IsConstant()) { |
| 2682 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2683 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
| 2684 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2685 | int32_t abs_imm = std::abs(div->InputAt(1)->AsIntConstant()->GetValue()); |
| 2686 | if (abs_imm <= 1) { |
| 2687 | // No temp register required. |
| 2688 | } else { |
| 2689 | locations->AddTemp(Location::RequiresRegister()); |
| 2690 | if (!IsPowerOfTwo(abs_imm)) { |
| 2691 | locations->AddTemp(Location::RequiresRegister()); |
| 2692 | } |
| 2693 | } |
| 2694 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2695 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2696 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2697 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2698 | } else { |
| 2699 | InvokeRuntimeCallingConvention calling_convention; |
| 2700 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2701 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2702 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 2703 | // we only need the former. |
| 2704 | locations->SetOut(Location::RegisterLocation(R0)); |
| 2705 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2706 | break; |
| 2707 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2708 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2709 | InvokeRuntimeCallingConvention calling_convention; |
| 2710 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2711 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2712 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2713 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2714 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2715 | break; |
| 2716 | } |
| 2717 | case Primitive::kPrimFloat: |
| 2718 | case Primitive::kPrimDouble: { |
| 2719 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2720 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2721 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2722 | break; |
| 2723 | } |
| 2724 | |
| 2725 | default: |
| 2726 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2727 | } |
| 2728 | } |
| 2729 | |
| 2730 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 2731 | LocationSummary* locations = div->GetLocations(); |
| 2732 | Location out = locations->Out(); |
| 2733 | Location first = locations->InAt(0); |
| 2734 | Location second = locations->InAt(1); |
| 2735 | |
| 2736 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2737 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2738 | if (second.IsConstant()) { |
| 2739 | GenerateDivRemConstantIntegral(div); |
| 2740 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2741 | __ sdiv(out.AsRegister<Register>(), |
| 2742 | first.AsRegister<Register>(), |
| 2743 | second.AsRegister<Register>()); |
| 2744 | } else { |
| 2745 | InvokeRuntimeCallingConvention calling_convention; |
| 2746 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 2747 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 2748 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 2749 | |
| 2750 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr); |
| 2751 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2752 | break; |
| 2753 | } |
| 2754 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2755 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2756 | InvokeRuntimeCallingConvention calling_convention; |
| 2757 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2758 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 2759 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 2760 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 2761 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2762 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2763 | |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2764 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2765 | break; |
| 2766 | } |
| 2767 | |
| 2768 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2769 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 2770 | first.AsFpuRegister<SRegister>(), |
| 2771 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2772 | break; |
| 2773 | } |
| 2774 | |
| 2775 | case Primitive::kPrimDouble: { |
| 2776 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2777 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2778 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 2779 | break; |
| 2780 | } |
| 2781 | |
| 2782 | default: |
| 2783 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2784 | } |
| 2785 | } |
| 2786 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2787 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2788 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2789 | |
| 2790 | // Most remainders are implemented in the runtime. |
| 2791 | LocationSummary::CallKind call_kind = LocationSummary::kCall; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2792 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 2793 | // sdiv will be replaced by other instruction sequence. |
| 2794 | call_kind = LocationSummary::kNoCall; |
| 2795 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 2796 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2797 | // Have hardware divide instruction for int, do it with three instructions. |
| 2798 | call_kind = LocationSummary::kNoCall; |
| 2799 | } |
| 2800 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2801 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 2802 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2803 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2804 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2805 | if (rem->InputAt(1)->IsConstant()) { |
| 2806 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2807 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
| 2808 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2809 | int32_t abs_imm = std::abs(rem->InputAt(1)->AsIntConstant()->GetValue()); |
| 2810 | if (abs_imm <= 1) { |
| 2811 | // No temp register required. |
| 2812 | } else { |
| 2813 | locations->AddTemp(Location::RequiresRegister()); |
| 2814 | if (!IsPowerOfTwo(abs_imm)) { |
| 2815 | locations->AddTemp(Location::RequiresRegister()); |
| 2816 | } |
| 2817 | } |
| 2818 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2819 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2820 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2821 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2822 | locations->AddTemp(Location::RequiresRegister()); |
| 2823 | } else { |
| 2824 | InvokeRuntimeCallingConvention calling_convention; |
| 2825 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2826 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2827 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 2828 | // we only need the latter. |
| 2829 | locations->SetOut(Location::RegisterLocation(R1)); |
| 2830 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2831 | break; |
| 2832 | } |
| 2833 | case Primitive::kPrimLong: { |
| 2834 | InvokeRuntimeCallingConvention calling_convention; |
| 2835 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2836 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2837 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2838 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2839 | // The runtime helper puts the output in R2,R3. |
| 2840 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 2841 | break; |
| 2842 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2843 | case Primitive::kPrimFloat: { |
| 2844 | InvokeRuntimeCallingConvention calling_convention; |
| 2845 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 2846 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 2847 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 2848 | break; |
| 2849 | } |
| 2850 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2851 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2852 | InvokeRuntimeCallingConvention calling_convention; |
| 2853 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 2854 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 2855 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 2856 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 2857 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2858 | break; |
| 2859 | } |
| 2860 | |
| 2861 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2862 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2863 | } |
| 2864 | } |
| 2865 | |
| 2866 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 2867 | LocationSummary* locations = rem->GetLocations(); |
| 2868 | Location out = locations->Out(); |
| 2869 | Location first = locations->InAt(0); |
| 2870 | Location second = locations->InAt(1); |
| 2871 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2872 | Primitive::Type type = rem->GetResultType(); |
| 2873 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2874 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2875 | if (second.IsConstant()) { |
| 2876 | GenerateDivRemConstantIntegral(rem); |
| 2877 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2878 | Register reg1 = first.AsRegister<Register>(); |
| 2879 | Register reg2 = second.AsRegister<Register>(); |
| 2880 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2881 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2882 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 2883 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2884 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 2885 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2886 | } else { |
| 2887 | InvokeRuntimeCallingConvention calling_convention; |
| 2888 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 2889 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 2890 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 2891 | |
| 2892 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr); |
| 2893 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2894 | break; |
| 2895 | } |
| 2896 | |
| 2897 | case Primitive::kPrimLong: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2898 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2899 | break; |
| 2900 | } |
| 2901 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2902 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2903 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2904 | break; |
| 2905 | } |
| 2906 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2907 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2908 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2909 | break; |
| 2910 | } |
| 2911 | |
| 2912 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2913 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2914 | } |
| 2915 | } |
| 2916 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2917 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2918 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 2919 | ? LocationSummary::kCallOnSlowPath |
| 2920 | : LocationSummary::kNoCall; |
| 2921 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2922 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2923 | if (instruction->HasUses()) { |
| 2924 | locations->SetOut(Location::SameAsFirstInput()); |
| 2925 | } |
| 2926 | } |
| 2927 | |
| 2928 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 2929 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2930 | codegen_->AddSlowPath(slow_path); |
| 2931 | |
| 2932 | LocationSummary* locations = instruction->GetLocations(); |
| 2933 | Location value = locations->InAt(0); |
| 2934 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2935 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 2936 | case Primitive::kPrimByte: |
| 2937 | case Primitive::kPrimChar: |
| 2938 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2939 | case Primitive::kPrimInt: { |
| 2940 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 2941 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2942 | } else { |
| 2943 | DCHECK(value.IsConstant()) << value; |
| 2944 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 2945 | __ b(slow_path->GetEntryLabel()); |
| 2946 | } |
| 2947 | } |
| 2948 | break; |
| 2949 | } |
| 2950 | case Primitive::kPrimLong: { |
| 2951 | if (value.IsRegisterPair()) { |
| 2952 | __ orrs(IP, |
| 2953 | value.AsRegisterPairLow<Register>(), |
| 2954 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 2955 | __ b(slow_path->GetEntryLabel(), EQ); |
| 2956 | } else { |
| 2957 | DCHECK(value.IsConstant()) << value; |
| 2958 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 2959 | __ b(slow_path->GetEntryLabel()); |
| 2960 | } |
| 2961 | } |
| 2962 | break; |
| 2963 | default: |
| 2964 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 2965 | } |
| 2966 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2967 | } |
| 2968 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2969 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 2970 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 2971 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2972 | LocationSummary* locations = |
| 2973 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2974 | |
| 2975 | switch (op->GetResultType()) { |
| 2976 | case Primitive::kPrimInt: { |
| 2977 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2978 | locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1))); |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2979 | // Make the output overlap, as it will be used to hold the masked |
| 2980 | // second input. |
| 2981 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2982 | break; |
| 2983 | } |
| 2984 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2985 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2986 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2987 | locations->AddTemp(Location::RequiresRegister()); |
| 2988 | locations->SetOut(Location::RequiresRegister()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2989 | break; |
| 2990 | } |
| 2991 | default: |
| 2992 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 2993 | } |
| 2994 | } |
| 2995 | |
| 2996 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 2997 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 2998 | |
| 2999 | LocationSummary* locations = op->GetLocations(); |
| 3000 | Location out = locations->Out(); |
| 3001 | Location first = locations->InAt(0); |
| 3002 | Location second = locations->InAt(1); |
| 3003 | |
| 3004 | Primitive::Type type = op->GetResultType(); |
| 3005 | switch (type) { |
| 3006 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3007 | Register out_reg = out.AsRegister<Register>(); |
| 3008 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3009 | // Arm doesn't mask the shift count so we need to do it ourselves. |
| 3010 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3011 | Register second_reg = second.AsRegister<Register>(); |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3012 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftValue)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3013 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3014 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3015 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3016 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3017 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3018 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3019 | } |
| 3020 | } else { |
| 3021 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3022 | uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue); |
| 3023 | if (shift_value == 0) { // arm does not support shifting with 0 immediate. |
| 3024 | __ Mov(out_reg, first_reg); |
| 3025 | } else if (op->IsShl()) { |
| 3026 | __ Lsl(out_reg, first_reg, shift_value); |
| 3027 | } else if (op->IsShr()) { |
| 3028 | __ Asr(out_reg, first_reg, shift_value); |
| 3029 | } else { |
| 3030 | __ Lsr(out_reg, first_reg, shift_value); |
| 3031 | } |
| 3032 | } |
| 3033 | break; |
| 3034 | } |
| 3035 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3036 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 3037 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3038 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3039 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3040 | |
| 3041 | Register high = first.AsRegisterPairHigh<Register>(); |
| 3042 | Register low = first.AsRegisterPairLow<Register>(); |
| 3043 | |
| 3044 | Register second_reg = second.AsRegister<Register>(); |
| 3045 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3046 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3047 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftValue)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3048 | // Shift the high part |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3049 | __ Lsl(o_h, high, o_l); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3050 | // Shift the low part and `or` what overflew on the high part |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3051 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3052 | __ Lsr(temp, low, temp); |
| 3053 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 3054 | // If the shift is > 32 bits, override the high part |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3055 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3056 | __ it(PL); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3057 | __ Lsl(o_h, low, temp, PL); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3058 | // Shift the low part |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3059 | __ Lsl(o_l, low, o_l); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3060 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3061 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3062 | // Shift the low part |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3063 | __ Lsr(o_l, low, o_h); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3064 | // Shift the high part and `or` what underflew on the low part |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3065 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3066 | __ Lsl(temp, high, temp); |
| 3067 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3068 | // If the shift is > 32 bits, override the low part |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3069 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3070 | __ it(PL); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3071 | __ Asr(o_l, high, temp, PL); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3072 | // Shift the high part |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3073 | __ Asr(o_h, high, o_h); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3074 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3075 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3076 | // same as Shr except we use `Lsr`s and not `Asr`s |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3077 | __ Lsr(o_l, low, o_h); |
| 3078 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3079 | __ Lsl(temp, high, temp); |
| 3080 | __ orr(o_l, o_l, ShifterOperand(temp)); |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3081 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3082 | __ it(PL); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3083 | __ Lsr(o_l, high, temp, PL); |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3084 | __ Lsr(o_h, high, o_h); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3085 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3086 | break; |
| 3087 | } |
| 3088 | default: |
| 3089 | LOG(FATAL) << "Unexpected operation type " << type; |
| 3090 | } |
| 3091 | } |
| 3092 | |
| 3093 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 3094 | HandleShift(shl); |
| 3095 | } |
| 3096 | |
| 3097 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 3098 | HandleShift(shl); |
| 3099 | } |
| 3100 | |
| 3101 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 3102 | HandleShift(shr); |
| 3103 | } |
| 3104 | |
| 3105 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 3106 | HandleShift(shr); |
| 3107 | } |
| 3108 | |
| 3109 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 3110 | HandleShift(ushr); |
| 3111 | } |
| 3112 | |
| 3113 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 3114 | HandleShift(ushr); |
| 3115 | } |
| 3116 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3117 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3118 | LocationSummary* locations = |
| 3119 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3120 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3121 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3122 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3123 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3124 | } |
| 3125 | |
| 3126 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
| 3127 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3128 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3129 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3130 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3131 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3132 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3133 | instruction->GetDexPc(), |
| 3134 | nullptr); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3135 | } |
| 3136 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3137 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 3138 | LocationSummary* locations = |
| 3139 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3140 | InvokeRuntimeCallingConvention calling_convention; |
| 3141 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3142 | locations->SetOut(Location::RegisterLocation(R0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3143 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3144 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3145 | } |
| 3146 | |
| 3147 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
| 3148 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3149 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3150 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3151 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3152 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3153 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3154 | instruction->GetDexPc(), |
| 3155 | nullptr); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3156 | } |
| 3157 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3158 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3159 | LocationSummary* locations = |
| 3160 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3161 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3162 | if (location.IsStackSlot()) { |
| 3163 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3164 | } else if (location.IsDoubleStackSlot()) { |
| 3165 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3166 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3167 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3168 | } |
| 3169 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3170 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 3171 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3172 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3173 | } |
| 3174 | |
| 3175 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3176 | LocationSummary* locations = |
| 3177 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3178 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3179 | } |
| 3180 | |
| 3181 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3182 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3183 | } |
| 3184 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3185 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3186 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3187 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3188 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3189 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3190 | } |
| 3191 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3192 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 3193 | LocationSummary* locations = not_->GetLocations(); |
| 3194 | Location out = locations->Out(); |
| 3195 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3196 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3197 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3198 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3199 | break; |
| 3200 | |
| 3201 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3202 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 3203 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 3204 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 3205 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3206 | break; |
| 3207 | |
| 3208 | default: |
| 3209 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3210 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3211 | } |
| 3212 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3213 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3214 | LocationSummary* locations = |
| 3215 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3216 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3217 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3218 | } |
| 3219 | |
| 3220 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3221 | LocationSummary* locations = bool_not->GetLocations(); |
| 3222 | Location out = locations->Out(); |
| 3223 | Location in = locations->InAt(0); |
| 3224 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 3225 | } |
| 3226 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3227 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3228 | LocationSummary* locations = |
| 3229 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3230 | switch (compare->InputAt(0)->GetType()) { |
| 3231 | case Primitive::kPrimLong: { |
| 3232 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3233 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3234 | // Output overlaps because it is written before doing the low comparison. |
| 3235 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3236 | break; |
| 3237 | } |
| 3238 | case Primitive::kPrimFloat: |
| 3239 | case Primitive::kPrimDouble: { |
| 3240 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3241 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3242 | locations->SetOut(Location::RequiresRegister()); |
| 3243 | break; |
| 3244 | } |
| 3245 | default: |
| 3246 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 3247 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3248 | } |
| 3249 | |
| 3250 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3251 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3252 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3253 | Location left = locations->InAt(0); |
| 3254 | Location right = locations->InAt(1); |
| 3255 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3256 | Label less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3257 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 3258 | switch (type) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3259 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3260 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 3261 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3262 | __ b(&less, LT); |
| 3263 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3264 | // 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] | 3265 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3266 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 3267 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3268 | break; |
| 3269 | } |
| 3270 | case Primitive::kPrimFloat: |
| 3271 | case Primitive::kPrimDouble: { |
| 3272 | __ LoadImmediate(out, 0); |
| 3273 | if (type == Primitive::kPrimFloat) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3274 | __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3275 | } else { |
| 3276 | __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), |
| 3277 | FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); |
| 3278 | } |
| 3279 | __ vmstat(); // transfer FP status register to ARM APSR. |
| 3280 | __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3281 | break; |
| 3282 | } |
| 3283 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3284 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3285 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3286 | __ b(&done, EQ); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3287 | __ 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] | 3288 | |
| 3289 | __ Bind(&greater); |
| 3290 | __ LoadImmediate(out, 1); |
| 3291 | __ b(&done); |
| 3292 | |
| 3293 | __ Bind(&less); |
| 3294 | __ LoadImmediate(out, -1); |
| 3295 | |
| 3296 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3297 | } |
| 3298 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3299 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3300 | LocationSummary* locations = |
| 3301 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 3302 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3303 | locations->SetInAt(i, Location::Any()); |
| 3304 | } |
| 3305 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3306 | } |
| 3307 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3308 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3309 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3310 | } |
| 3311 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3312 | void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3313 | // TODO (ported from quick): revisit Arm barrier kinds |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3314 | DmbOptions flavor = DmbOptions::ISH; // quiet c++ warnings |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3315 | switch (kind) { |
| 3316 | case MemBarrierKind::kAnyStore: |
| 3317 | case MemBarrierKind::kLoadAny: |
| 3318 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3319 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3320 | break; |
| 3321 | } |
| 3322 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3323 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3324 | break; |
| 3325 | } |
| 3326 | default: |
| 3327 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 3328 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3329 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3330 | } |
| 3331 | |
| 3332 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 3333 | uint32_t offset, |
| 3334 | Register out_lo, |
| 3335 | Register out_hi) { |
| 3336 | if (offset != 0) { |
| 3337 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3338 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 3339 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3340 | } |
| 3341 | __ ldrexd(out_lo, out_hi, addr); |
| 3342 | } |
| 3343 | |
| 3344 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 3345 | uint32_t offset, |
| 3346 | Register value_lo, |
| 3347 | Register value_hi, |
| 3348 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3349 | Register temp2, |
| 3350 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3351 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3352 | if (offset != 0) { |
| 3353 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3354 | __ add(IP, addr, ShifterOperand(temp1)); |
| 3355 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3356 | } |
| 3357 | __ Bind(&fail); |
| 3358 | // We need a load followed by store. (The address used in a STREX instruction must |
| 3359 | // be the same as the address in the most recently executed LDREX instruction.) |
| 3360 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3361 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3362 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3363 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3364 | } |
| 3365 | |
| 3366 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3367 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3368 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3369 | LocationSummary* locations = |
| 3370 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3371 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3372 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3373 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3374 | if (Primitive::IsFloatingPointType(field_type)) { |
| 3375 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3376 | } else { |
| 3377 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3378 | } |
| 3379 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3380 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3381 | bool generate_volatile = field_info.IsVolatile() |
| 3382 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3383 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3384 | bool needs_write_barrier = |
| 3385 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3386 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3387 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3388 | if (needs_write_barrier) { |
| 3389 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3390 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3391 | } else if (generate_volatile) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3392 | // Arm encoding have some additional constraints for ldrexd/strexd: |
| 3393 | // - registers need to be consecutive |
| 3394 | // - the first register should be even but not R14. |
| 3395 | // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever |
| 3396 | // enable Arm encoding. |
| 3397 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 3398 | |
| 3399 | locations->AddTemp(Location::RequiresRegister()); |
| 3400 | locations->AddTemp(Location::RequiresRegister()); |
| 3401 | if (field_type == Primitive::kPrimDouble) { |
| 3402 | // For doubles we need two more registers to copy the value. |
| 3403 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 3404 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 3405 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3406 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3407 | } |
| 3408 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3409 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3410 | const FieldInfo& field_info, |
| 3411 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3412 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3413 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3414 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3415 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3416 | Location value = locations->InAt(1); |
| 3417 | |
| 3418 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3419 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3420 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3421 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3422 | bool needs_write_barrier = |
| 3423 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3424 | |
| 3425 | if (is_volatile) { |
| 3426 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 3427 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3428 | |
| 3429 | switch (field_type) { |
| 3430 | case Primitive::kPrimBoolean: |
| 3431 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3432 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3433 | break; |
| 3434 | } |
| 3435 | |
| 3436 | case Primitive::kPrimShort: |
| 3437 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3438 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3439 | break; |
| 3440 | } |
| 3441 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3442 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3443 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3444 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 3445 | // Note that in the case where `value` is a null reference, |
| 3446 | // we do not enter this block, as a null reference does not |
| 3447 | // need poisoning. |
| 3448 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 3449 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3450 | __ Mov(temp, value.AsRegister<Register>()); |
| 3451 | __ PoisonHeapReference(temp); |
| 3452 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 3453 | } else { |
| 3454 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 3455 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3456 | break; |
| 3457 | } |
| 3458 | |
| 3459 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3460 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3461 | GenerateWideAtomicStore(base, offset, |
| 3462 | value.AsRegisterPairLow<Register>(), |
| 3463 | value.AsRegisterPairHigh<Register>(), |
| 3464 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3465 | locations->GetTemp(1).AsRegister<Register>(), |
| 3466 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3467 | } else { |
| 3468 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3469 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3470 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3471 | break; |
| 3472 | } |
| 3473 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3474 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3475 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3476 | break; |
| 3477 | } |
| 3478 | |
| 3479 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3480 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3481 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3482 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 3483 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 3484 | |
| 3485 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 3486 | |
| 3487 | GenerateWideAtomicStore(base, offset, |
| 3488 | value_reg_lo, |
| 3489 | value_reg_hi, |
| 3490 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3491 | locations->GetTemp(3).AsRegister<Register>(), |
| 3492 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3493 | } else { |
| 3494 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3495 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3496 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3497 | break; |
| 3498 | } |
| 3499 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3500 | case Primitive::kPrimVoid: |
| 3501 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3502 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3503 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3504 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3505 | // Longs and doubles are handled in the switch. |
| 3506 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 3507 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3508 | } |
| 3509 | |
| 3510 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 3511 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3512 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3513 | codegen_->MarkGCCard( |
| 3514 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3515 | } |
| 3516 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3517 | if (is_volatile) { |
| 3518 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 3519 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3520 | } |
| 3521 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3522 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3523 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3524 | LocationSummary* locations = |
| 3525 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3526 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3527 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3528 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3529 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3530 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3531 | bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong); |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 3532 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3533 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3534 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3535 | } else { |
| 3536 | locations->SetOut(Location::RequiresRegister(), |
| 3537 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 3538 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3539 | if (volatile_for_double) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3540 | // Arm encoding have some additional constraints for ldrexd/strexd: |
| 3541 | // - registers need to be consecutive |
| 3542 | // - the first register should be even but not R14. |
| 3543 | // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever |
| 3544 | // enable Arm encoding. |
| 3545 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 3546 | locations->AddTemp(Location::RequiresRegister()); |
| 3547 | locations->AddTemp(Location::RequiresRegister()); |
| 3548 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3549 | } |
| 3550 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 3551 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 3552 | Opcode opcode) { |
| 3553 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 3554 | if (constant->IsConstant() && |
| 3555 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 3556 | return Location::ConstantLocation(constant->AsConstant()); |
| 3557 | } |
| 3558 | return Location::RequiresRegister(); |
| 3559 | } |
| 3560 | |
| 3561 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 3562 | Opcode opcode) { |
| 3563 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 3564 | if (Primitive::Is64BitType(input_cst->GetType())) { |
| 3565 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode) && |
| 3566 | CanEncodeConstantAsImmediate(High32Bits(value), opcode); |
| 3567 | } else { |
| 3568 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 3569 | } |
| 3570 | } |
| 3571 | |
| 3572 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, Opcode opcode) { |
| 3573 | ShifterOperand so; |
| 3574 | ArmAssembler* assembler = codegen_->GetAssembler(); |
| 3575 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, &so)) { |
| 3576 | return true; |
| 3577 | } |
| 3578 | Opcode neg_opcode = kNoOperand; |
| 3579 | switch (opcode) { |
| 3580 | case AND: |
| 3581 | neg_opcode = BIC; |
| 3582 | break; |
| 3583 | case ORR: |
| 3584 | neg_opcode = ORN; |
| 3585 | break; |
| 3586 | default: |
| 3587 | return false; |
| 3588 | } |
| 3589 | return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, ~value, &so); |
| 3590 | } |
| 3591 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3592 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 3593 | const FieldInfo& field_info) { |
| 3594 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3595 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3596 | LocationSummary* locations = instruction->GetLocations(); |
| 3597 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3598 | Location out = locations->Out(); |
| 3599 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3600 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3601 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3602 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3603 | |
| 3604 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3605 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3606 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3607 | break; |
| 3608 | } |
| 3609 | |
| 3610 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3611 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3612 | break; |
| 3613 | } |
| 3614 | |
| 3615 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3616 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3617 | break; |
| 3618 | } |
| 3619 | |
| 3620 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3621 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3622 | break; |
| 3623 | } |
| 3624 | |
| 3625 | case Primitive::kPrimInt: |
| 3626 | case Primitive::kPrimNot: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3627 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3628 | break; |
| 3629 | } |
| 3630 | |
| 3631 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3632 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3633 | GenerateWideAtomicLoad(base, offset, |
| 3634 | out.AsRegisterPairLow<Register>(), |
| 3635 | out.AsRegisterPairHigh<Register>()); |
| 3636 | } else { |
| 3637 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 3638 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3639 | break; |
| 3640 | } |
| 3641 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3642 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3643 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3644 | break; |
| 3645 | } |
| 3646 | |
| 3647 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3648 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3649 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3650 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 3651 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 3652 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3653 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3654 | __ vmovdrr(out_reg, lo, hi); |
| 3655 | } else { |
| 3656 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3657 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3658 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3659 | break; |
| 3660 | } |
| 3661 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3662 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3663 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3664 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3665 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3666 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3667 | // Doubles are handled in the switch. |
| 3668 | if (field_type != Primitive::kPrimDouble) { |
| 3669 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3670 | } |
| 3671 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3672 | if (is_volatile) { |
| 3673 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 3674 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3675 | |
| 3676 | if (field_type == Primitive::kPrimNot) { |
| 3677 | __ MaybeUnpoisonHeapReference(out.AsRegister<Register>()); |
| 3678 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3679 | } |
| 3680 | |
| 3681 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 3682 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3683 | } |
| 3684 | |
| 3685 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3686 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3687 | } |
| 3688 | |
| 3689 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 3690 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3691 | } |
| 3692 | |
| 3693 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 3694 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3695 | } |
| 3696 | |
| 3697 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3698 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3699 | } |
| 3700 | |
| 3701 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3702 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3703 | } |
| 3704 | |
| 3705 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3706 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3707 | } |
| 3708 | |
| 3709 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3710 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3711 | } |
| 3712 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 3713 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 3714 | HUnresolvedInstanceFieldGet* instruction) { |
| 3715 | FieldAccessCallingConventionARM calling_convention; |
| 3716 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3717 | instruction, instruction->GetFieldType(), calling_convention); |
| 3718 | } |
| 3719 | |
| 3720 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 3721 | HUnresolvedInstanceFieldGet* instruction) { |
| 3722 | FieldAccessCallingConventionARM calling_convention; |
| 3723 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3724 | instruction->GetFieldType(), |
| 3725 | instruction->GetFieldIndex(), |
| 3726 | instruction->GetDexPc(), |
| 3727 | calling_convention); |
| 3728 | } |
| 3729 | |
| 3730 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 3731 | HUnresolvedInstanceFieldSet* instruction) { |
| 3732 | FieldAccessCallingConventionARM calling_convention; |
| 3733 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3734 | instruction, instruction->GetFieldType(), calling_convention); |
| 3735 | } |
| 3736 | |
| 3737 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 3738 | HUnresolvedInstanceFieldSet* instruction) { |
| 3739 | FieldAccessCallingConventionARM calling_convention; |
| 3740 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3741 | instruction->GetFieldType(), |
| 3742 | instruction->GetFieldIndex(), |
| 3743 | instruction->GetDexPc(), |
| 3744 | calling_convention); |
| 3745 | } |
| 3746 | |
| 3747 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 3748 | HUnresolvedStaticFieldGet* instruction) { |
| 3749 | FieldAccessCallingConventionARM calling_convention; |
| 3750 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3751 | instruction, instruction->GetFieldType(), calling_convention); |
| 3752 | } |
| 3753 | |
| 3754 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 3755 | HUnresolvedStaticFieldGet* instruction) { |
| 3756 | FieldAccessCallingConventionARM calling_convention; |
| 3757 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3758 | instruction->GetFieldType(), |
| 3759 | instruction->GetFieldIndex(), |
| 3760 | instruction->GetDexPc(), |
| 3761 | calling_convention); |
| 3762 | } |
| 3763 | |
| 3764 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 3765 | HUnresolvedStaticFieldSet* instruction) { |
| 3766 | FieldAccessCallingConventionARM calling_convention; |
| 3767 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3768 | instruction, instruction->GetFieldType(), calling_convention); |
| 3769 | } |
| 3770 | |
| 3771 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 3772 | HUnresolvedStaticFieldSet* instruction) { |
| 3773 | FieldAccessCallingConventionARM calling_convention; |
| 3774 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3775 | instruction->GetFieldType(), |
| 3776 | instruction->GetFieldIndex(), |
| 3777 | instruction->GetDexPc(), |
| 3778 | calling_convention); |
| 3779 | } |
| 3780 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3781 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3782 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3783 | ? LocationSummary::kCallOnSlowPath |
| 3784 | : LocationSummary::kNoCall; |
| 3785 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3786 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3787 | if (instruction->HasUses()) { |
| 3788 | locations->SetOut(Location::SameAsFirstInput()); |
| 3789 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3790 | } |
| 3791 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3792 | void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3793 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 3794 | return; |
| 3795 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3796 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3797 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3798 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
| 3799 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3800 | } |
| 3801 | |
| 3802 | void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3803 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3804 | codegen_->AddSlowPath(slow_path); |
| 3805 | |
| 3806 | LocationSummary* locations = instruction->GetLocations(); |
| 3807 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3808 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3809 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3810 | } |
| 3811 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3812 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3813 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3814 | GenerateImplicitNullCheck(instruction); |
| 3815 | } else { |
| 3816 | GenerateExplicitNullCheck(instruction); |
| 3817 | } |
| 3818 | } |
| 3819 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3820 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3821 | LocationSummary* locations = |
| 3822 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3823 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3824 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3825 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3826 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3827 | } else { |
| 3828 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3829 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3830 | } |
| 3831 | |
| 3832 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 3833 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3834 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3835 | Location index = locations->InAt(1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3836 | Primitive::Type type = instruction->GetType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3837 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3838 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3839 | case Primitive::kPrimBoolean: { |
| 3840 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3841 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3842 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3843 | size_t offset = |
| 3844 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3845 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset); |
| 3846 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3847 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3848 | __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset); |
| 3849 | } |
| 3850 | break; |
| 3851 | } |
| 3852 | |
| 3853 | case Primitive::kPrimByte: { |
| 3854 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3855 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3856 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3857 | size_t offset = |
| 3858 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3859 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset); |
| 3860 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3861 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3862 | __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset); |
| 3863 | } |
| 3864 | break; |
| 3865 | } |
| 3866 | |
| 3867 | case Primitive::kPrimShort: { |
| 3868 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3869 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3870 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3871 | size_t offset = |
| 3872 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3873 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset); |
| 3874 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3875 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3876 | __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset); |
| 3877 | } |
| 3878 | break; |
| 3879 | } |
| 3880 | |
| 3881 | case Primitive::kPrimChar: { |
| 3882 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3883 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3884 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3885 | size_t offset = |
| 3886 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3887 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset); |
| 3888 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3889 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3890 | __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset); |
| 3891 | } |
| 3892 | break; |
| 3893 | } |
| 3894 | |
| 3895 | case Primitive::kPrimInt: |
| 3896 | case Primitive::kPrimNot: { |
Roland Levillain | 33d6903 | 2015-06-18 18:20:59 +0100 | [diff] [blame] | 3897 | static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 3898 | "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3899 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3900 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3901 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3902 | size_t offset = |
| 3903 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3904 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 3905 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3906 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3907 | __ LoadFromOffset(kLoadWord, out, IP, data_offset); |
| 3908 | } |
| 3909 | break; |
| 3910 | } |
| 3911 | |
| 3912 | case Primitive::kPrimLong: { |
| 3913 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3914 | Location out = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3915 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3916 | size_t offset = |
| 3917 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3918 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3919 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3920 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3921 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3922 | } |
| 3923 | break; |
| 3924 | } |
| 3925 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3926 | case Primitive::kPrimFloat: { |
| 3927 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 3928 | Location out = locations->Out(); |
| 3929 | DCHECK(out.IsFpuRegister()); |
| 3930 | if (index.IsConstant()) { |
| 3931 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 3932 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset); |
| 3933 | } else { |
| 3934 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 3935 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset); |
| 3936 | } |
| 3937 | break; |
| 3938 | } |
| 3939 | |
| 3940 | case Primitive::kPrimDouble: { |
| 3941 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 3942 | Location out = locations->Out(); |
| 3943 | DCHECK(out.IsFpuRegisterPair()); |
| 3944 | if (index.IsConstant()) { |
| 3945 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 3946 | __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset); |
| 3947 | } else { |
| 3948 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
| 3949 | __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 3950 | } |
| 3951 | break; |
| 3952 | } |
| 3953 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3954 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3955 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3956 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3957 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3958 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3959 | |
| 3960 | if (type == Primitive::kPrimNot) { |
| 3961 | Register out = locations->Out().AsRegister<Register>(); |
| 3962 | __ MaybeUnpoisonHeapReference(out); |
| 3963 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3964 | } |
| 3965 | |
| 3966 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3967 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3968 | |
| 3969 | bool needs_write_barrier = |
| 3970 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3971 | bool may_need_runtime_call = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3972 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3973 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3974 | instruction, |
| 3975 | may_need_runtime_call ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
| 3976 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3977 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3978 | if (Primitive::IsFloatingPointType(value_type)) { |
| 3979 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3980 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3981 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3982 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3983 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3984 | if (needs_write_barrier) { |
| 3985 | // Temporary registers for the write barrier. |
| 3986 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 3987 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3988 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3989 | } |
| 3990 | |
| 3991 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 3992 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3993 | Register array = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3994 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3995 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3996 | bool may_need_runtime_call = locations->CanCall(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3997 | bool needs_write_barrier = |
| 3998 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3999 | |
| 4000 | switch (value_type) { |
| 4001 | case Primitive::kPrimBoolean: |
| 4002 | case Primitive::kPrimByte: { |
| 4003 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4004 | Register value = locations->InAt(2).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4005 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4006 | size_t offset = |
| 4007 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4008 | __ StoreToOffset(kStoreByte, value, array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4009 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4010 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4011 | __ StoreToOffset(kStoreByte, value, IP, data_offset); |
| 4012 | } |
| 4013 | break; |
| 4014 | } |
| 4015 | |
| 4016 | case Primitive::kPrimShort: |
| 4017 | case Primitive::kPrimChar: { |
| 4018 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4019 | Register value = locations->InAt(2).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4020 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4021 | size_t offset = |
| 4022 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4023 | __ StoreToOffset(kStoreHalfword, value, array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4024 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4025 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4026 | __ StoreToOffset(kStoreHalfword, value, IP, data_offset); |
| 4027 | } |
| 4028 | break; |
| 4029 | } |
| 4030 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4031 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4032 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4033 | Register value = locations->InAt(2).AsRegister<Register>(); |
| 4034 | Register source = value; |
| 4035 | |
| 4036 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 4037 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4038 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4039 | size_t offset = |
| 4040 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4041 | __ StoreToOffset(kStoreWord, source, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4042 | } else { |
| 4043 | DCHECK(index.IsRegister()) << index; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4044 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4045 | __ StoreToOffset(kStoreWord, source, IP, data_offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4046 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4047 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4048 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4049 | |
| 4050 | DCHECK(needs_write_barrier); |
| 4051 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 4052 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 4053 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4054 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4055 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4056 | Label done; |
| 4057 | SlowPathCode* slow_path = nullptr; |
| 4058 | |
| 4059 | if (may_need_runtime_call) { |
| 4060 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 4061 | codegen_->AddSlowPath(slow_path); |
| 4062 | if (instruction->GetValueCanBeNull()) { |
| 4063 | Label non_zero; |
| 4064 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 4065 | if (index.IsConstant()) { |
| 4066 | size_t offset = |
| 4067 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4068 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 4069 | } else { |
| 4070 | DCHECK(index.IsRegister()) << index; |
| 4071 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4072 | __ StoreToOffset(kStoreWord, value, IP, data_offset); |
| 4073 | } |
| 4074 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4075 | __ b(&done); |
| 4076 | __ Bind(&non_zero); |
| 4077 | } |
| 4078 | |
| 4079 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 4080 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4081 | __ MaybeUnpoisonHeapReference(temp1); |
| 4082 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 4083 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 4084 | // No need to poison/unpoison, we're comparing two poisoined references. |
| 4085 | __ cmp(temp1, ShifterOperand(temp2)); |
| 4086 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4087 | Label do_put; |
| 4088 | __ b(&do_put, EQ); |
| 4089 | __ MaybeUnpoisonHeapReference(temp1); |
| 4090 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 4091 | // No need to poison/unpoison, we're comparing against null. |
| 4092 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 4093 | __ Bind(&do_put); |
| 4094 | } else { |
| 4095 | __ b(slow_path->GetEntryLabel(), NE); |
| 4096 | } |
| 4097 | } |
| 4098 | |
| 4099 | if (kPoisonHeapReferences) { |
| 4100 | // Note that in the case where `value` is a null reference, |
| 4101 | // we do not enter this block, as a null reference does not |
| 4102 | // need poisoning. |
| 4103 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 4104 | __ Mov(temp1, value); |
| 4105 | __ PoisonHeapReference(temp1); |
| 4106 | source = temp1; |
| 4107 | } |
| 4108 | |
| 4109 | if (index.IsConstant()) { |
| 4110 | size_t offset = |
| 4111 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4112 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 4113 | } else { |
| 4114 | DCHECK(index.IsRegister()) << index; |
| 4115 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4116 | __ StoreToOffset(kStoreWord, source, IP, data_offset); |
| 4117 | } |
| 4118 | |
| 4119 | if (!may_need_runtime_call) { |
| 4120 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4121 | } |
| 4122 | |
| 4123 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 4124 | |
| 4125 | if (done.IsLinked()) { |
| 4126 | __ Bind(&done); |
| 4127 | } |
| 4128 | |
| 4129 | if (slow_path != nullptr) { |
| 4130 | __ Bind(slow_path->GetExitLabel()); |
| 4131 | } |
| 4132 | |
| 4133 | break; |
| 4134 | } |
| 4135 | |
| 4136 | case Primitive::kPrimInt: { |
| 4137 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4138 | Register value = locations->InAt(2).AsRegister<Register>(); |
| 4139 | if (index.IsConstant()) { |
| 4140 | size_t offset = |
| 4141 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4142 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 4143 | } else { |
| 4144 | DCHECK(index.IsRegister()) << index; |
| 4145 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4146 | __ StoreToOffset(kStoreWord, value, IP, data_offset); |
| 4147 | } |
| 4148 | |
| 4149 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4150 | break; |
| 4151 | } |
| 4152 | |
| 4153 | case Primitive::kPrimLong: { |
| 4154 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4155 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4156 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4157 | size_t offset = |
| 4158 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4159 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4160 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4161 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4162 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4163 | } |
| 4164 | break; |
| 4165 | } |
| 4166 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4167 | case Primitive::kPrimFloat: { |
| 4168 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4169 | Location value = locations->InAt(2); |
| 4170 | DCHECK(value.IsFpuRegister()); |
| 4171 | if (index.IsConstant()) { |
| 4172 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4173 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4174 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4175 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4176 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 4177 | } |
| 4178 | break; |
| 4179 | } |
| 4180 | |
| 4181 | case Primitive::kPrimDouble: { |
| 4182 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4183 | Location value = locations->InAt(2); |
| 4184 | DCHECK(value.IsFpuRegisterPair()); |
| 4185 | if (index.IsConstant()) { |
| 4186 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4187 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4188 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4189 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4190 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 4191 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4192 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4193 | break; |
| 4194 | } |
| 4195 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4196 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4197 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4198 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4199 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4200 | |
| 4201 | // Ints and objects are handled in the switch. |
| 4202 | if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) { |
| 4203 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4204 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4205 | } |
| 4206 | |
| 4207 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4208 | LocationSummary* locations = |
| 4209 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4210 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4211 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4212 | } |
| 4213 | |
| 4214 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 4215 | LocationSummary* locations = instruction->GetLocations(); |
| 4216 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4217 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4218 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4219 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4220 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4221 | } |
| 4222 | |
| 4223 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4224 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4225 | ? LocationSummary::kCallOnSlowPath |
| 4226 | : LocationSummary::kNoCall; |
| 4227 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4228 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4229 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4230 | if (instruction->HasUses()) { |
| 4231 | locations->SetOut(Location::SameAsFirstInput()); |
| 4232 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4233 | } |
| 4234 | |
| 4235 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4236 | LocationSummary* locations = instruction->GetLocations(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4237 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4238 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4239 | codegen_->AddSlowPath(slow_path); |
| 4240 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4241 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 4242 | Register length = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4243 | |
| 4244 | __ cmp(index, ShifterOperand(length)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 4245 | __ b(slow_path->GetEntryLabel(), HS); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4246 | } |
| 4247 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4248 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 4249 | Register card, |
| 4250 | Register object, |
| 4251 | Register value, |
| 4252 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4253 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4254 | if (can_be_null) { |
| 4255 | __ CompareAndBranchIfZero(value, &is_null); |
| 4256 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4257 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value()); |
| 4258 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 4259 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4260 | if (can_be_null) { |
| 4261 | __ Bind(&is_null); |
| 4262 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4263 | } |
| 4264 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4265 | void LocationsBuilderARM::VisitTemporary(HTemporary* temp) { |
| 4266 | temp->SetLocations(nullptr); |
| 4267 | } |
| 4268 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4269 | void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4270 | // Nothing to do, this is driven by the code generator. |
| 4271 | } |
| 4272 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4273 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4274 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4275 | } |
| 4276 | |
| 4277 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4278 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4279 | } |
| 4280 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4281 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4282 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4283 | } |
| 4284 | |
| 4285 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4286 | HBasicBlock* block = instruction->GetBlock(); |
| 4287 | if (block->GetLoopInformation() != nullptr) { |
| 4288 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4289 | // The back edge will generate the suspend check. |
| 4290 | return; |
| 4291 | } |
| 4292 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4293 | // The goto will generate the suspend check. |
| 4294 | return; |
| 4295 | } |
| 4296 | GenerateSuspendCheck(instruction, nullptr); |
| 4297 | } |
| 4298 | |
| 4299 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4300 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4301 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4302 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 4303 | if (slow_path == nullptr) { |
| 4304 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 4305 | instruction->SetSlowPath(slow_path); |
| 4306 | codegen_->AddSlowPath(slow_path); |
| 4307 | if (successor != nullptr) { |
| 4308 | DCHECK(successor->IsLoopHeader()); |
| 4309 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4310 | } |
| 4311 | } else { |
| 4312 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4313 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4314 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 4315 | __ LoadFromOffset( |
| 4316 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4317 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4318 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4319 | __ Bind(slow_path->GetReturnLabel()); |
| 4320 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4321 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4322 | __ b(slow_path->GetEntryLabel()); |
| 4323 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4324 | } |
| 4325 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4326 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 4327 | return codegen_->GetAssembler(); |
| 4328 | } |
| 4329 | |
| 4330 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 4331 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4332 | Location source = move->GetSource(); |
| 4333 | Location destination = move->GetDestination(); |
| 4334 | |
| 4335 | if (source.IsRegister()) { |
| 4336 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4337 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4338 | } else { |
| 4339 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4340 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4341 | SP, destination.GetStackIndex()); |
| 4342 | } |
| 4343 | } else if (source.IsStackSlot()) { |
| 4344 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4345 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4346 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4347 | } else if (destination.IsFpuRegister()) { |
| 4348 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4349 | } else { |
| 4350 | DCHECK(destination.IsStackSlot()); |
| 4351 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 4352 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4353 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4354 | } else if (source.IsFpuRegister()) { |
| 4355 | if (destination.IsFpuRegister()) { |
| 4356 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4357 | } else { |
| 4358 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4359 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 4360 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4361 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4362 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4363 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 4364 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4365 | } else if (destination.IsRegisterPair()) { |
| 4366 | DCHECK(ExpectedPairLayout(destination)); |
| 4367 | __ LoadFromOffset( |
| 4368 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 4369 | } else { |
| 4370 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 4371 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 4372 | SP, |
| 4373 | source.GetStackIndex()); |
| 4374 | } |
| 4375 | } else if (source.IsRegisterPair()) { |
| 4376 | if (destination.IsRegisterPair()) { |
| 4377 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 4378 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 4379 | } else { |
| 4380 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4381 | DCHECK(ExpectedPairLayout(source)); |
| 4382 | __ StoreToOffset( |
| 4383 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 4384 | } |
| 4385 | } else if (source.IsFpuRegisterPair()) { |
| 4386 | if (destination.IsFpuRegisterPair()) { |
| 4387 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 4388 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 4389 | } else { |
| 4390 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4391 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 4392 | SP, |
| 4393 | destination.GetStackIndex()); |
| 4394 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4395 | } else { |
| 4396 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4397 | HConstant* constant = source.GetConstant(); |
| 4398 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 4399 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4400 | if (destination.IsRegister()) { |
| 4401 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 4402 | } else { |
| 4403 | DCHECK(destination.IsStackSlot()); |
| 4404 | __ LoadImmediate(IP, value); |
| 4405 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4406 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4407 | } else if (constant->IsLongConstant()) { |
| 4408 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4409 | if (destination.IsRegisterPair()) { |
| 4410 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 4411 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4412 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4413 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4414 | __ LoadImmediate(IP, Low32Bits(value)); |
| 4415 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4416 | __ LoadImmediate(IP, High32Bits(value)); |
| 4417 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 4418 | } |
| 4419 | } else if (constant->IsDoubleConstant()) { |
| 4420 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4421 | if (destination.IsFpuRegisterPair()) { |
| 4422 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4423 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4424 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4425 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4426 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 4427 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4428 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 4429 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 4430 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4431 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4432 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4433 | float value = constant->AsFloatConstant()->GetValue(); |
| 4434 | if (destination.IsFpuRegister()) { |
| 4435 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 4436 | } else { |
| 4437 | DCHECK(destination.IsStackSlot()); |
| 4438 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 4439 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4440 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4441 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4442 | } |
| 4443 | } |
| 4444 | |
| 4445 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 4446 | __ Mov(IP, reg); |
| 4447 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 4448 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 4449 | } |
| 4450 | |
| 4451 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 4452 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 4453 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 4454 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 4455 | SP, mem1 + stack_offset); |
| 4456 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 4457 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 4458 | SP, mem2 + stack_offset); |
| 4459 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 4460 | } |
| 4461 | |
| 4462 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 4463 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4464 | Location source = move->GetSource(); |
| 4465 | Location destination = move->GetDestination(); |
| 4466 | |
| 4467 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4468 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 4469 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 4470 | __ Mov(IP, source.AsRegister<Register>()); |
| 4471 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 4472 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4473 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4474 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4475 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4476 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4477 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 4478 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4479 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 4480 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4481 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 4482 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4483 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4484 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4485 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4486 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4487 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 4488 | destination.AsRegisterPairHigh<Register>(), |
| 4489 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4490 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4491 | Register low_reg = source.IsRegisterPair() |
| 4492 | ? source.AsRegisterPairLow<Register>() |
| 4493 | : destination.AsRegisterPairLow<Register>(); |
| 4494 | int mem = source.IsRegisterPair() |
| 4495 | ? destination.GetStackIndex() |
| 4496 | : source.GetStackIndex(); |
| 4497 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4498 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4499 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4500 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4501 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4502 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 4503 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4504 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4505 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4506 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4507 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 4508 | DRegister reg = source.IsFpuRegisterPair() |
| 4509 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 4510 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 4511 | int mem = source.IsFpuRegisterPair() |
| 4512 | ? destination.GetStackIndex() |
| 4513 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4514 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4515 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4516 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4517 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 4518 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 4519 | : destination.AsFpuRegister<SRegister>(); |
| 4520 | int mem = source.IsFpuRegister() |
| 4521 | ? destination.GetStackIndex() |
| 4522 | : source.GetStackIndex(); |
| 4523 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 4524 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4525 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 4526 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 4527 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 4528 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 4529 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4530 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 4531 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4532 | } |
| 4533 | } |
| 4534 | |
| 4535 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 4536 | __ Push(static_cast<Register>(reg)); |
| 4537 | } |
| 4538 | |
| 4539 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 4540 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4541 | } |
| 4542 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4543 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4544 | InvokeRuntimeCallingConvention calling_convention; |
| 4545 | CodeGenerator::CreateLoadClassLocationSummary( |
| 4546 | cls, |
| 4547 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 4548 | Location::RegisterLocation(R0)); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4549 | } |
| 4550 | |
| 4551 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4552 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4553 | if (cls->NeedsAccessCheck()) { |
| 4554 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 4555 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 4556 | cls, |
| 4557 | cls->GetDexPc(), |
| 4558 | nullptr); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4559 | return; |
| 4560 | } |
| 4561 | |
| 4562 | Register out = locations->Out().AsRegister<Register>(); |
| 4563 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 4564 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4565 | DCHECK(!cls->CanCallRuntime()); |
| 4566 | DCHECK(!cls->MustGenerateClinitCheck()); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4567 | __ LoadFromOffset( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4568 | kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4569 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4570 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4571 | __ LoadFromOffset(kLoadWord, |
| 4572 | out, |
| 4573 | current_method, |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4574 | ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4575 | __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4576 | // TODO: We will need a read barrier here. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4577 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4578 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4579 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4580 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4581 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4582 | if (cls->MustGenerateClinitCheck()) { |
| 4583 | GenerateClassInitializationCheck(slow_path, out); |
| 4584 | } else { |
| 4585 | __ Bind(slow_path->GetExitLabel()); |
| 4586 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4587 | } |
| 4588 | } |
| 4589 | |
| 4590 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 4591 | LocationSummary* locations = |
| 4592 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 4593 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4594 | if (check->HasUses()) { |
| 4595 | locations->SetOut(Location::SameAsFirstInput()); |
| 4596 | } |
| 4597 | } |
| 4598 | |
| 4599 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4600 | // We assume the class is not null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4601 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4602 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4603 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4604 | GenerateClassInitializationCheck(slow_path, |
| 4605 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4606 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4607 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4608 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4609 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4610 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 4611 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 4612 | __ b(slow_path->GetEntryLabel(), LT); |
| 4613 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 4614 | // properly. Therefore, we do a memory fence. |
| 4615 | __ dmb(ISH); |
| 4616 | __ Bind(slow_path->GetExitLabel()); |
| 4617 | } |
| 4618 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4619 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
| 4620 | LocationSummary* locations = |
| 4621 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4622 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4623 | locations->SetOut(Location::RequiresRegister()); |
| 4624 | } |
| 4625 | |
| 4626 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4627 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4628 | codegen_->AddSlowPath(slow_path); |
| 4629 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4630 | LocationSummary* locations = load->GetLocations(); |
| 4631 | Register out = locations->Out().AsRegister<Register>(); |
| 4632 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 4633 | __ LoadFromOffset( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4634 | kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 4635 | __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4636 | __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4637 | // TODO: We will need a read barrier here. |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4638 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4639 | __ Bind(slow_path->GetExitLabel()); |
| 4640 | } |
| 4641 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4642 | static int32_t GetExceptionTlsOffset() { |
| 4643 | return Thread::ExceptionOffset<kArmWordSize>().Int32Value(); |
| 4644 | } |
| 4645 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4646 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 4647 | LocationSummary* locations = |
| 4648 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4649 | locations->SetOut(Location::RequiresRegister()); |
| 4650 | } |
| 4651 | |
| 4652 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4653 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4654 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 4655 | } |
| 4656 | |
| 4657 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 4658 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4659 | } |
| 4660 | |
| 4661 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4662 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4663 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4664 | } |
| 4665 | |
| 4666 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 4667 | LocationSummary* locations = |
| 4668 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4669 | InvokeRuntimeCallingConvention calling_convention; |
| 4670 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4671 | } |
| 4672 | |
| 4673 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
| 4674 | codegen_->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 4675 | QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4676 | } |
| 4677 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4678 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4679 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4680 | switch (instruction->GetTypeCheckKind()) { |
| 4681 | case TypeCheckKind::kExactCheck: |
| 4682 | case TypeCheckKind::kAbstractClassCheck: |
| 4683 | case TypeCheckKind::kClassHierarchyCheck: |
| 4684 | case TypeCheckKind::kArrayObjectCheck: |
| 4685 | call_kind = LocationSummary::kNoCall; |
| 4686 | break; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4687 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4688 | case TypeCheckKind::kInterfaceCheck: |
| 4689 | call_kind = LocationSummary::kCall; |
| 4690 | break; |
| 4691 | case TypeCheckKind::kArrayCheck: |
| 4692 | call_kind = LocationSummary::kCallOnSlowPath; |
| 4693 | break; |
| 4694 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4695 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4696 | if (call_kind != LocationSummary::kCall) { |
| 4697 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4698 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4699 | // The out register is used as a temporary, so it overlaps with the inputs. |
| 4700 | // Note that TypeCheckSlowPathARM uses this register too. |
| 4701 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4702 | } else { |
| 4703 | InvokeRuntimeCallingConvention calling_convention; |
| 4704 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4705 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4706 | locations->SetOut(Location::RegisterLocation(R0)); |
| 4707 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4708 | } |
| 4709 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4710 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4711 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4712 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4713 | Register cls = locations->InAt(1).AsRegister<Register>(); |
| 4714 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4715 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4716 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4717 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4718 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4719 | Label done, zero; |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4720 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4721 | |
| 4722 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4723 | // avoid null check if we know obj is not null. |
| 4724 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | d56376c | 2015-05-21 12:32:34 +0000 | [diff] [blame] | 4725 | __ CompareAndBranchIfZero(obj, &zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4726 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4727 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4728 | // In case of an interface/unresolved check, we put the object class into the object register. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4729 | // This is safe, as the register is caller-save, and the object must be in another |
| 4730 | // register if it survives the runtime call. |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4731 | Register target = (instruction->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) || |
| 4732 | (instruction->GetTypeCheckKind() == TypeCheckKind::kUnresolvedCheck) |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4733 | ? obj |
| 4734 | : out; |
| 4735 | __ LoadFromOffset(kLoadWord, target, obj, class_offset); |
| 4736 | __ MaybeUnpoisonHeapReference(target); |
| 4737 | |
| 4738 | switch (instruction->GetTypeCheckKind()) { |
| 4739 | case TypeCheckKind::kExactCheck: { |
| 4740 | __ cmp(out, ShifterOperand(cls)); |
| 4741 | // Classes must be equal for the instanceof to succeed. |
| 4742 | __ b(&zero, NE); |
| 4743 | __ LoadImmediate(out, 1); |
| 4744 | __ b(&done); |
| 4745 | break; |
| 4746 | } |
| 4747 | case TypeCheckKind::kAbstractClassCheck: { |
| 4748 | // If the class is abstract, we eagerly fetch the super class of the |
| 4749 | // object to avoid doing a comparison we know will fail. |
| 4750 | Label loop; |
| 4751 | __ Bind(&loop); |
| 4752 | __ LoadFromOffset(kLoadWord, out, out, super_offset); |
| 4753 | __ MaybeUnpoisonHeapReference(out); |
| 4754 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4755 | __ CompareAndBranchIfZero(out, &done); |
| 4756 | __ cmp(out, ShifterOperand(cls)); |
| 4757 | __ b(&loop, NE); |
| 4758 | __ LoadImmediate(out, 1); |
| 4759 | if (zero.IsLinked()) { |
| 4760 | __ b(&done); |
| 4761 | } |
| 4762 | break; |
| 4763 | } |
| 4764 | case TypeCheckKind::kClassHierarchyCheck: { |
| 4765 | // Walk over the class hierarchy to find a match. |
| 4766 | Label loop, success; |
| 4767 | __ Bind(&loop); |
| 4768 | __ cmp(out, ShifterOperand(cls)); |
| 4769 | __ b(&success, EQ); |
| 4770 | __ LoadFromOffset(kLoadWord, out, out, super_offset); |
| 4771 | __ MaybeUnpoisonHeapReference(out); |
| 4772 | __ CompareAndBranchIfNonZero(out, &loop); |
| 4773 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4774 | __ b(&done); |
| 4775 | __ Bind(&success); |
| 4776 | __ LoadImmediate(out, 1); |
| 4777 | if (zero.IsLinked()) { |
| 4778 | __ b(&done); |
| 4779 | } |
| 4780 | break; |
| 4781 | } |
| 4782 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4783 | // Do an exact check. |
| 4784 | Label exact_check; |
| 4785 | __ cmp(out, ShifterOperand(cls)); |
| 4786 | __ b(&exact_check, EQ); |
| 4787 | // Otherwise, we need to check that the object's class is a non primitive array. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4788 | __ LoadFromOffset(kLoadWord, out, out, component_offset); |
| 4789 | __ MaybeUnpoisonHeapReference(out); |
| 4790 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4791 | __ CompareAndBranchIfZero(out, &done); |
| 4792 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 4793 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 4794 | __ CompareAndBranchIfNonZero(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4795 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4796 | __ LoadImmediate(out, 1); |
| 4797 | __ b(&done); |
| 4798 | break; |
| 4799 | } |
| 4800 | case TypeCheckKind::kArrayCheck: { |
| 4801 | __ cmp(out, ShifterOperand(cls)); |
| 4802 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4803 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM( |
| 4804 | instruction, /* is_fatal */ false); |
| 4805 | codegen_->AddSlowPath(slow_path); |
| 4806 | __ b(slow_path->GetEntryLabel(), NE); |
| 4807 | __ LoadImmediate(out, 1); |
| 4808 | if (zero.IsLinked()) { |
| 4809 | __ b(&done); |
| 4810 | } |
| 4811 | break; |
| 4812 | } |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4813 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4814 | case TypeCheckKind::kInterfaceCheck: |
| 4815 | default: { |
| 4816 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 4817 | instruction, |
| 4818 | instruction->GetDexPc(), |
| 4819 | nullptr); |
| 4820 | if (zero.IsLinked()) { |
| 4821 | __ b(&done); |
| 4822 | } |
| 4823 | break; |
| 4824 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4825 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4826 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4827 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4828 | __ Bind(&zero); |
| 4829 | __ LoadImmediate(out, 0); |
| 4830 | } |
| 4831 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4832 | if (done.IsLinked()) { |
| 4833 | __ Bind(&done); |
| 4834 | } |
| 4835 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4836 | if (slow_path != nullptr) { |
| 4837 | __ Bind(slow_path->GetExitLabel()); |
| 4838 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4839 | } |
| 4840 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4841 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4842 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4843 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 4844 | |
| 4845 | switch (instruction->GetTypeCheckKind()) { |
| 4846 | case TypeCheckKind::kExactCheck: |
| 4847 | case TypeCheckKind::kAbstractClassCheck: |
| 4848 | case TypeCheckKind::kClassHierarchyCheck: |
| 4849 | case TypeCheckKind::kArrayObjectCheck: |
| 4850 | call_kind = throws_into_catch |
| 4851 | ? LocationSummary::kCallOnSlowPath |
| 4852 | : LocationSummary::kNoCall; |
| 4853 | break; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4854 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4855 | case TypeCheckKind::kInterfaceCheck: |
| 4856 | call_kind = LocationSummary::kCall; |
| 4857 | break; |
| 4858 | case TypeCheckKind::kArrayCheck: |
| 4859 | call_kind = LocationSummary::kCallOnSlowPath; |
| 4860 | break; |
| 4861 | } |
| 4862 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4863 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4864 | instruction, call_kind); |
| 4865 | if (call_kind != LocationSummary::kCall) { |
| 4866 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4867 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4868 | // Note that TypeCheckSlowPathARM uses this register too. |
| 4869 | locations->AddTemp(Location::RequiresRegister()); |
| 4870 | } else { |
| 4871 | InvokeRuntimeCallingConvention calling_convention; |
| 4872 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4873 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4874 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4875 | } |
| 4876 | |
| 4877 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
| 4878 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4879 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4880 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4881 | Register temp = locations->WillCall() |
| 4882 | ? Register(kNoRegister) |
| 4883 | : locations->GetTemp(0).AsRegister<Register>(); |
| 4884 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4885 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4886 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4887 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4888 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 4889 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4890 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4891 | if (!locations->WillCall()) { |
| 4892 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM( |
| 4893 | instruction, !locations->CanCall()); |
| 4894 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 4895 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4896 | |
| 4897 | Label done; |
| 4898 | // Avoid null check if we know obj is not null. |
| 4899 | if (instruction->MustDoNullCheck()) { |
| 4900 | __ CompareAndBranchIfZero(obj, &done); |
| 4901 | } |
| 4902 | |
| 4903 | if (locations->WillCall()) { |
| 4904 | __ LoadFromOffset(kLoadWord, obj, obj, class_offset); |
| 4905 | __ MaybeUnpoisonHeapReference(obj); |
| 4906 | } else { |
| 4907 | __ LoadFromOffset(kLoadWord, temp, obj, class_offset); |
| 4908 | __ MaybeUnpoisonHeapReference(temp); |
| 4909 | } |
| 4910 | |
| 4911 | switch (instruction->GetTypeCheckKind()) { |
| 4912 | case TypeCheckKind::kExactCheck: |
| 4913 | case TypeCheckKind::kArrayCheck: { |
| 4914 | __ cmp(temp, ShifterOperand(cls)); |
| 4915 | // Jump to slow path for throwing the exception or doing a |
| 4916 | // more involved array check. |
| 4917 | __ b(slow_path->GetEntryLabel(), NE); |
| 4918 | break; |
| 4919 | } |
| 4920 | case TypeCheckKind::kAbstractClassCheck: { |
| 4921 | // If the class is abstract, we eagerly fetch the super class of the |
| 4922 | // object to avoid doing a comparison we know will fail. |
| 4923 | Label loop; |
| 4924 | __ Bind(&loop); |
| 4925 | __ LoadFromOffset(kLoadWord, temp, temp, super_offset); |
| 4926 | __ MaybeUnpoisonHeapReference(temp); |
| 4927 | // Jump to the slow path to throw the exception. |
| 4928 | __ CompareAndBranchIfZero(temp, slow_path->GetEntryLabel()); |
| 4929 | __ cmp(temp, ShifterOperand(cls)); |
| 4930 | __ b(&loop, NE); |
| 4931 | break; |
| 4932 | } |
| 4933 | case TypeCheckKind::kClassHierarchyCheck: { |
| 4934 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4935 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4936 | __ Bind(&loop); |
| 4937 | __ cmp(temp, ShifterOperand(cls)); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4938 | __ b(&done, EQ); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4939 | __ LoadFromOffset(kLoadWord, temp, temp, super_offset); |
| 4940 | __ MaybeUnpoisonHeapReference(temp); |
| 4941 | __ CompareAndBranchIfNonZero(temp, &loop); |
| 4942 | // Jump to the slow path to throw the exception. |
| 4943 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4944 | break; |
| 4945 | } |
| 4946 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4947 | // Do an exact check. |
| 4948 | __ cmp(temp, ShifterOperand(cls)); |
| 4949 | __ b(&done, EQ); |
| 4950 | // Otherwise, we need to check that the object's class is a non primitive array. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4951 | __ LoadFromOffset(kLoadWord, temp, temp, component_offset); |
| 4952 | __ MaybeUnpoisonHeapReference(temp); |
| 4953 | __ CompareAndBranchIfZero(temp, slow_path->GetEntryLabel()); |
| 4954 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 4955 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 4956 | __ CompareAndBranchIfNonZero(temp, slow_path->GetEntryLabel()); |
| 4957 | break; |
| 4958 | } |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4959 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4960 | case TypeCheckKind::kInterfaceCheck: |
| 4961 | default: |
| 4962 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 4963 | instruction, |
| 4964 | instruction->GetDexPc(), |
| 4965 | nullptr); |
| 4966 | break; |
| 4967 | } |
| 4968 | __ Bind(&done); |
| 4969 | |
| 4970 | if (slow_path != nullptr) { |
| 4971 | __ Bind(slow_path->GetExitLabel()); |
| 4972 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4973 | } |
| 4974 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4975 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4976 | LocationSummary* locations = |
| 4977 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4978 | InvokeRuntimeCallingConvention calling_convention; |
| 4979 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4980 | } |
| 4981 | |
| 4982 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4983 | codegen_->InvokeRuntime(instruction->IsEnter() |
| 4984 | ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject), |
| 4985 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 4986 | instruction->GetDexPc(), |
| 4987 | nullptr); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4988 | } |
| 4989 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4990 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 4991 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 4992 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4993 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4994 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4995 | LocationSummary* locations = |
| 4996 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4997 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 4998 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4999 | // Note: GVN reorders commutative operations to have the constant on the right hand side. |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5000 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5001 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 5002 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5003 | } |
| 5004 | |
| 5005 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 5006 | HandleBitwiseOperation(instruction); |
| 5007 | } |
| 5008 | |
| 5009 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 5010 | HandleBitwiseOperation(instruction); |
| 5011 | } |
| 5012 | |
| 5013 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 5014 | HandleBitwiseOperation(instruction); |
| 5015 | } |
| 5016 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5017 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 5018 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 5019 | if (value == 0xffffffffu) { |
| 5020 | if (out != first) { |
| 5021 | __ mov(out, ShifterOperand(first)); |
| 5022 | } |
| 5023 | return; |
| 5024 | } |
| 5025 | if (value == 0u) { |
| 5026 | __ mov(out, ShifterOperand(0)); |
| 5027 | return; |
| 5028 | } |
| 5029 | ShifterOperand so; |
| 5030 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 5031 | __ and_(out, first, so); |
| 5032 | } else { |
| 5033 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)); |
| 5034 | __ bic(out, first, ShifterOperand(~value)); |
| 5035 | } |
| 5036 | } |
| 5037 | |
| 5038 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 5039 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 5040 | if (value == 0u) { |
| 5041 | if (out != first) { |
| 5042 | __ mov(out, ShifterOperand(first)); |
| 5043 | } |
| 5044 | return; |
| 5045 | } |
| 5046 | if (value == 0xffffffffu) { |
| 5047 | __ mvn(out, ShifterOperand(0)); |
| 5048 | return; |
| 5049 | } |
| 5050 | ShifterOperand so; |
| 5051 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 5052 | __ orr(out, first, so); |
| 5053 | } else { |
| 5054 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 5055 | __ orn(out, first, ShifterOperand(~value)); |
| 5056 | } |
| 5057 | } |
| 5058 | |
| 5059 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 5060 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 5061 | if (value == 0u) { |
| 5062 | if (out != first) { |
| 5063 | __ mov(out, ShifterOperand(first)); |
| 5064 | } |
| 5065 | return; |
| 5066 | } |
| 5067 | __ eor(out, first, ShifterOperand(value)); |
| 5068 | } |
| 5069 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5070 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5071 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5072 | Location first = locations->InAt(0); |
| 5073 | Location second = locations->InAt(1); |
| 5074 | Location out = locations->Out(); |
| 5075 | |
| 5076 | if (second.IsConstant()) { |
| 5077 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 5078 | uint32_t value_low = Low32Bits(value); |
| 5079 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 5080 | Register first_reg = first.AsRegister<Register>(); |
| 5081 | Register out_reg = out.AsRegister<Register>(); |
| 5082 | if (instruction->IsAnd()) { |
| 5083 | GenerateAndConst(out_reg, first_reg, value_low); |
| 5084 | } else if (instruction->IsOr()) { |
| 5085 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 5086 | } else { |
| 5087 | DCHECK(instruction->IsXor()); |
| 5088 | GenerateEorConst(out_reg, first_reg, value_low); |
| 5089 | } |
| 5090 | } else { |
| 5091 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 5092 | uint32_t value_high = High32Bits(value); |
| 5093 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 5094 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 5095 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 5096 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 5097 | if (instruction->IsAnd()) { |
| 5098 | GenerateAndConst(out_low, first_low, value_low); |
| 5099 | GenerateAndConst(out_high, first_high, value_high); |
| 5100 | } else if (instruction->IsOr()) { |
| 5101 | GenerateOrrConst(out_low, first_low, value_low); |
| 5102 | GenerateOrrConst(out_high, first_high, value_high); |
| 5103 | } else { |
| 5104 | DCHECK(instruction->IsXor()); |
| 5105 | GenerateEorConst(out_low, first_low, value_low); |
| 5106 | GenerateEorConst(out_high, first_high, value_high); |
| 5107 | } |
| 5108 | } |
| 5109 | return; |
| 5110 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5111 | |
| 5112 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5113 | Register first_reg = first.AsRegister<Register>(); |
| 5114 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 5115 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5116 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5117 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5118 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5119 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5120 | } else { |
| 5121 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5122 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5123 | } |
| 5124 | } else { |
| 5125 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5126 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 5127 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 5128 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 5129 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 5130 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 5131 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5132 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5133 | __ and_(out_low, first_low, second_low); |
| 5134 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5135 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5136 | __ orr(out_low, first_low, second_low); |
| 5137 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5138 | } else { |
| 5139 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5140 | __ eor(out_low, first_low, second_low); |
| 5141 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5142 | } |
| 5143 | } |
| 5144 | } |
| 5145 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5146 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 5147 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 5148 | MethodReference target_method) { |
| 5149 | if (desired_dispatch_info.method_load_kind == |
| 5150 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative) { |
| 5151 | // TODO: Implement this type. For the moment, we fall back to kDexCacheViaMethod. |
| 5152 | return HInvokeStaticOrDirect::DispatchInfo { |
| 5153 | HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod, |
| 5154 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 5155 | 0u, |
| 5156 | 0u |
| 5157 | }; |
| 5158 | } |
| 5159 | if (desired_dispatch_info.code_ptr_location == |
| 5160 | HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative) { |
| 5161 | const DexFile& outer_dex_file = GetGraph()->GetDexFile(); |
| 5162 | if (&outer_dex_file != target_method.dex_file) { |
| 5163 | // Calls across dex files are more likely to exceed the available BL range, |
| 5164 | // so use absolute patch with fixup if available and kCallArtMethod otherwise. |
| 5165 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = |
| 5166 | (desired_dispatch_info.method_load_kind == |
| 5167 | HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) |
| 5168 | ? HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup |
| 5169 | : HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod; |
| 5170 | return HInvokeStaticOrDirect::DispatchInfo { |
| 5171 | desired_dispatch_info.method_load_kind, |
| 5172 | code_ptr_location, |
| 5173 | desired_dispatch_info.method_load_data, |
| 5174 | 0u |
| 5175 | }; |
| 5176 | } |
| 5177 | } |
| 5178 | return desired_dispatch_info; |
| 5179 | } |
| 5180 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5181 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5182 | // For better instruction scheduling we load the direct code pointer before the method pointer. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5183 | switch (invoke->GetCodePtrLocation()) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5184 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 5185 | // LR = code address from literal pool with link-time patch. |
| 5186 | __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5187 | break; |
| 5188 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 5189 | // LR = invoke->GetDirectCodePtr(); |
| 5190 | __ LoadImmediate(LR, invoke->GetDirectCodePtr()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5191 | break; |
| 5192 | default: |
| 5193 | break; |
| 5194 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 5195 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5196 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 5197 | switch (invoke->GetMethodLoadKind()) { |
| 5198 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 5199 | // temp = thread->string_init_entrypoint |
| 5200 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, invoke->GetStringInitOffset()); |
| 5201 | break; |
| 5202 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 5203 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 5204 | break; |
| 5205 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 5206 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 5207 | break; |
| 5208 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 5209 | __ LoadLiteral(temp.AsRegister<Register>(), |
| 5210 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 5211 | break; |
| 5212 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5213 | // TODO: Implement this type. |
| 5214 | // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 5215 | LOG(FATAL) << "Unsupported"; |
| 5216 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5217 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 5218 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 5219 | Register method_reg; |
| 5220 | Register reg = temp.AsRegister<Register>(); |
| 5221 | if (current_method.IsRegister()) { |
| 5222 | method_reg = current_method.AsRegister<Register>(); |
| 5223 | } else { |
| 5224 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 5225 | DCHECK(!current_method.IsValid()); |
| 5226 | method_reg = reg; |
| 5227 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 5228 | } |
| 5229 | // temp = current_method->dex_cache_resolved_methods_; |
| 5230 | __ LoadFromOffset( |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 5231 | kLoadWord, reg, method_reg, ArtMethod::DexCacheResolvedMethodsOffset( |
| 5232 | kArmPointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5233 | // temp = temp[index_in_cache] |
| 5234 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 5235 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 5236 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 5237 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5238 | } |
| 5239 | |
| 5240 | switch (invoke->GetCodePtrLocation()) { |
| 5241 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 5242 | __ bl(GetFrameEntryLabel()); |
| 5243 | break; |
| 5244 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5245 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame^] | 5246 | __ BindTrackedLabel(&relative_call_patches_.back().label); |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5247 | // Arbitrarily branch to the BL itself, override at link time. |
| 5248 | __ bl(&relative_call_patches_.back().label); |
| 5249 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5250 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 5251 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 5252 | // LR prepared above for better instruction scheduling. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5253 | // LR() |
| 5254 | __ blx(LR); |
| 5255 | break; |
| 5256 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 5257 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 5258 | __ LoadFromOffset( |
| 5259 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
| 5260 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmWordSize).Int32Value()); |
| 5261 | // LR() |
| 5262 | __ blx(LR); |
| 5263 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 5264 | } |
| 5265 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 5266 | DCHECK(!IsLeafMethod()); |
| 5267 | } |
| 5268 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5269 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 5270 | Register temp = temp_location.AsRegister<Register>(); |
| 5271 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 5272 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
| 5273 | LocationSummary* locations = invoke->GetLocations(); |
| 5274 | Location receiver = locations->InAt(0); |
| 5275 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5276 | // temp = object->GetClass(); |
| 5277 | DCHECK(receiver.IsRegister()); |
| 5278 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
| 5279 | MaybeRecordImplicitNullCheck(invoke); |
| 5280 | __ MaybeUnpoisonHeapReference(temp); |
| 5281 | // temp = temp->GetMethodAt(method_offset); |
| 5282 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 5283 | kArmWordSize).Int32Value(); |
| 5284 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 5285 | // LR = temp->GetEntryPoint(); |
| 5286 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 5287 | // LR(); |
| 5288 | __ blx(LR); |
| 5289 | } |
| 5290 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5291 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 5292 | DCHECK(linker_patches->empty()); |
| 5293 | size_t size = method_patches_.size() + call_patches_.size() + relative_call_patches_.size(); |
| 5294 | linker_patches->reserve(size); |
| 5295 | for (const auto& entry : method_patches_) { |
| 5296 | const MethodReference& target_method = entry.first; |
| 5297 | Literal* literal = entry.second; |
| 5298 | DCHECK(literal->GetLabel()->IsBound()); |
| 5299 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 5300 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 5301 | target_method.dex_file, |
| 5302 | target_method.dex_method_index)); |
| 5303 | } |
| 5304 | for (const auto& entry : call_patches_) { |
| 5305 | const MethodReference& target_method = entry.first; |
| 5306 | Literal* literal = entry.second; |
| 5307 | DCHECK(literal->GetLabel()->IsBound()); |
| 5308 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 5309 | linker_patches->push_back(LinkerPatch::CodePatch(literal_offset, |
| 5310 | target_method.dex_file, |
| 5311 | target_method.dex_method_index)); |
| 5312 | } |
| 5313 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 5314 | uint32_t literal_offset = info.label.Position(); |
| 5315 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 5316 | info.target_method.dex_file, |
| 5317 | info.target_method.dex_method_index)); |
| 5318 | } |
| 5319 | } |
| 5320 | |
| 5321 | Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method, |
| 5322 | MethodToLiteralMap* map) { |
| 5323 | // Look up the literal for target_method. |
| 5324 | auto lb = map->lower_bound(target_method); |
| 5325 | if (lb != map->end() && !map->key_comp()(target_method, lb->first)) { |
| 5326 | return lb->second; |
| 5327 | } |
| 5328 | // We don't have a literal for this method yet, insert a new one. |
| 5329 | Literal* literal = __ NewLiteral<uint32_t>(0u); |
| 5330 | map->PutBefore(lb, target_method, literal); |
| 5331 | return literal; |
| 5332 | } |
| 5333 | |
| 5334 | Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) { |
| 5335 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 5336 | } |
| 5337 | |
| 5338 | Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) { |
| 5339 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 5340 | } |
| 5341 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5342 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5343 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5344 | LOG(FATAL) << "Unreachable"; |
| 5345 | } |
| 5346 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5347 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5348 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5349 | LOG(FATAL) << "Unreachable"; |
| 5350 | } |
| 5351 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5352 | void LocationsBuilderARM::VisitFakeString(HFakeString* instruction) { |
| 5353 | DCHECK(codegen_->IsBaseline()); |
| 5354 | LocationSummary* locations = |
| 5355 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5356 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 5357 | } |
| 5358 | |
| 5359 | void InstructionCodeGeneratorARM::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 5360 | DCHECK(codegen_->IsBaseline()); |
| 5361 | // Will be generated at use site. |
| 5362 | } |
| 5363 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5364 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5365 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5366 | LocationSummary* locations = |
| 5367 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 5368 | locations->SetInAt(0, Location::RequiresRegister()); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame^] | 5369 | if (switch_instr->GetNumEntries() >= kPackedSwitchJumpTableThreshold && |
| 5370 | codegen_->GetAssembler()->IsThumb()) { |
| 5371 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 5372 | if (switch_instr->GetStartValue() != 0) { |
| 5373 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 5374 | } |
| 5375 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5376 | } |
| 5377 | |
| 5378 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5379 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame^] | 5380 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5381 | LocationSummary* locations = switch_instr->GetLocations(); |
| 5382 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 5383 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 5384 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame^] | 5385 | if (num_entries < kPackedSwitchJumpTableThreshold || !codegen_->GetAssembler()->IsThumb()) { |
| 5386 | // Create a series of compare/jumps. |
| 5387 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 5388 | for (uint32_t i = 0; i < num_entries; i++) { |
| 5389 | GenerateCompareWithImmediate(value_reg, lower_bound + i); |
| 5390 | __ b(codegen_->GetLabelOf(successors[i]), EQ); |
| 5391 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5392 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame^] | 5393 | // And the default for any other value. |
| 5394 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 5395 | __ b(codegen_->GetLabelOf(default_block)); |
| 5396 | } |
| 5397 | } else { |
| 5398 | // Create a table lookup. |
| 5399 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 5400 | |
| 5401 | // Materialize a pointer to the switch table |
| 5402 | std::vector<Label*> labels(num_entries); |
| 5403 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 5404 | for (uint32_t i = 0; i < num_entries; i++) { |
| 5405 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 5406 | } |
| 5407 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 5408 | |
| 5409 | // Remove the bias. |
| 5410 | Register key_reg; |
| 5411 | if (lower_bound != 0) { |
| 5412 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 5413 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 5414 | } else { |
| 5415 | key_reg = value_reg; |
| 5416 | } |
| 5417 | |
| 5418 | // Check whether the value is in the table, jump to default block if not. |
| 5419 | __ CmpConstant(key_reg, num_entries - 1); |
| 5420 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 5421 | |
| 5422 | // Load the displacement from the table. |
| 5423 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 5424 | |
| 5425 | // Dispatch is a direct add to the PC (for Thumb2). |
| 5426 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5427 | } |
| 5428 | } |
| 5429 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5430 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 5431 | if (!trg.IsValid()) { |
| 5432 | DCHECK(type == Primitive::kPrimVoid); |
| 5433 | return; |
| 5434 | } |
| 5435 | |
| 5436 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 5437 | |
| 5438 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 5439 | if (return_loc.Equals(trg)) { |
| 5440 | return; |
| 5441 | } |
| 5442 | |
| 5443 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 5444 | // with the last branch. |
| 5445 | if (type == Primitive::kPrimLong) { |
| 5446 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 5447 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 5448 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 5449 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 5450 | } else if (type == Primitive::kPrimDouble) { |
| 5451 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 5452 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 5453 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 5454 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 5455 | } else { |
| 5456 | // Let the parallel move resolver take care of all of this. |
| 5457 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 5458 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 5459 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 5460 | } |
| 5461 | } |
| 5462 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5463 | #undef __ |
| 5464 | #undef QUICK_ENTRY_POINT |
| 5465 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5466 | } // namespace arm |
| 5467 | } // namespace art |