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