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