Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_arm.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 18 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 19 | #include "arch/arm/instruction_set_features_arm.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 20 | #include "art_method.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 21 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 25 | #include "intrinsics.h" |
| 26 | #include "intrinsics_arm.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 27 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 28 | #include "mirror/class-inl.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 29 | #include "thread.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 30 | #include "utils/arm/assembler_arm.h" |
| 31 | #include "utils/arm/managed_register_arm.h" |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 32 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 33 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 34 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 36 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 37 | namespace arm { |
| 38 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 39 | static bool ExpectedPairLayout(Location location) { |
| 40 | // We expected this for both core and fpu register pairs. |
| 41 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 42 | } |
| 43 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 44 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 45 | static constexpr Register kMethodRegisterArgument = R0; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 46 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 47 | // We unconditionally allocate R5 to ensure we can do long operations |
| 48 | // with baseline. |
| 49 | static constexpr Register kCoreSavedRegisterForBaseline = R5; |
| 50 | static constexpr Register kCoreCalleeSaves[] = |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 51 | { R5, R6, R7, R8, R10, R11, LR }; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 52 | static constexpr SRegister kFpuCalleeSaves[] = |
| 53 | { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 54 | |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 55 | // D31 cannot be split into two S registers, and the register allocator only works on |
| 56 | // S registers. Therefore there is no need to block it. |
| 57 | static constexpr DRegister DTMP = D31; |
| 58 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 59 | #define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 60 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 61 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 62 | class NullCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 63 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 64 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 65 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 66 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 67 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 68 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 69 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 70 | // Live registers will be restored in the catch block if caught. |
| 71 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 72 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 73 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 74 | QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 75 | } |
| 76 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 77 | bool IsFatal() const OVERRIDE { return true; } |
| 78 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 79 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; } |
| 80 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 81 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 82 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 83 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 84 | }; |
| 85 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 86 | class DivZeroCheckSlowPathARM : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 87 | public: |
| 88 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 89 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 90 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 91 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 92 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 93 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 94 | // Live registers will be restored in the catch block if caught. |
| 95 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 96 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 97 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 98 | QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 101 | bool IsFatal() const OVERRIDE { return true; } |
| 102 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 103 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; } |
| 104 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 105 | private: |
| 106 | HDivZeroCheck* const instruction_; |
| 107 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 108 | }; |
| 109 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 110 | class SuspendCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 111 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 112 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 113 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 114 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 115 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 116 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 117 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 118 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 119 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 120 | QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 121 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 122 | if (successor_ == nullptr) { |
| 123 | __ b(GetReturnLabel()); |
| 124 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 125 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 126 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 129 | Label* GetReturnLabel() { |
| 130 | DCHECK(successor_ == nullptr); |
| 131 | return &return_label_; |
| 132 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 133 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 134 | HBasicBlock* GetSuccessor() const { |
| 135 | return successor_; |
| 136 | } |
| 137 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 138 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; } |
| 139 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 140 | private: |
| 141 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 142 | // If not null, the block to branch to after the suspend check. |
| 143 | HBasicBlock* const successor_; |
| 144 | |
| 145 | // If `successor_` is null, the label to branch to after the suspend check. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 146 | Label return_label_; |
| 147 | |
| 148 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 149 | }; |
| 150 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 151 | class BoundsCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 152 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 153 | explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction) |
| 154 | : instruction_(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 155 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 156 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 157 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 158 | LocationSummary* locations = instruction_->GetLocations(); |
| 159 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 160 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 161 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 162 | // Live registers will be restored in the catch block if caught. |
| 163 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 164 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 165 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 166 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 167 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 168 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 169 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 170 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 171 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 172 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 173 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 174 | Primitive::kPrimInt); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 175 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 176 | QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 177 | } |
| 178 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 179 | bool IsFatal() const OVERRIDE { return true; } |
| 180 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 181 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; } |
| 182 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 183 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 184 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 185 | |
| 186 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 187 | }; |
| 188 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 189 | class LoadClassSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 190 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 191 | LoadClassSlowPathARM(HLoadClass* cls, |
| 192 | HInstruction* at, |
| 193 | uint32_t dex_pc, |
| 194 | bool do_clinit) |
| 195 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 196 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 197 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 198 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 199 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 200 | LocationSummary* locations = at_->GetLocations(); |
| 201 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 202 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 203 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 204 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 205 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 206 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 207 | __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 208 | int32_t entry_point_offset = do_clinit_ |
| 209 | ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 210 | : QUICK_ENTRY_POINT(pInitializeType); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 211 | arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 212 | |
| 213 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 214 | Location out = locations->Out(); |
| 215 | if (out.IsValid()) { |
| 216 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 217 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 218 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 219 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 220 | __ b(GetExitLabel()); |
| 221 | } |
| 222 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 223 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; } |
| 224 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 225 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 226 | // The class this slow path will load. |
| 227 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 228 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 229 | // The instruction where this slow path is happening. |
| 230 | // (Might be the load class or an initialization check). |
| 231 | HInstruction* const at_; |
| 232 | |
| 233 | // The dex PC of `at_`. |
| 234 | const uint32_t dex_pc_; |
| 235 | |
| 236 | // Whether to initialize the class. |
| 237 | const bool do_clinit_; |
| 238 | |
| 239 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 240 | }; |
| 241 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 242 | class LoadStringSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 243 | public: |
| 244 | explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {} |
| 245 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 246 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 247 | LocationSummary* locations = instruction_->GetLocations(); |
| 248 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 249 | |
| 250 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 251 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 252 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 253 | |
| 254 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 255 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 256 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 257 | QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 258 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 259 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 260 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 261 | __ b(GetExitLabel()); |
| 262 | } |
| 263 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 264 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; } |
| 265 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 266 | private: |
| 267 | HLoadString* const instruction_; |
| 268 | |
| 269 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 270 | }; |
| 271 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 272 | class TypeCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 273 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 274 | TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal) |
| 275 | : instruction_(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 276 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 277 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 278 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 279 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 280 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 281 | DCHECK(instruction_->IsCheckCast() |
| 282 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 283 | |
| 284 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 285 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 286 | |
| 287 | if (instruction_->IsCheckCast()) { |
| 288 | // The codegen for the instruction overwrites `temp`, so put it back in place. |
| 289 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 290 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 291 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 292 | __ LoadFromOffset(kLoadWord, temp, obj, class_offset); |
| 293 | __ MaybeUnpoisonHeapReference(temp); |
| 294 | } |
| 295 | |
| 296 | if (!is_fatal_) { |
| 297 | SaveLiveRegisters(codegen, locations); |
| 298 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 299 | |
| 300 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 301 | // move resolver. |
| 302 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 303 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 304 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 305 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 306 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 307 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 308 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 309 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 310 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 311 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 312 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 313 | instruction_, |
| 314 | instruction_->GetDexPc(), |
| 315 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 316 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 317 | } else { |
| 318 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 319 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 320 | instruction_, |
| 321 | instruction_->GetDexPc(), |
| 322 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 323 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 324 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 325 | if (!is_fatal_) { |
| 326 | RestoreLiveRegisters(codegen, locations); |
| 327 | __ b(GetExitLabel()); |
| 328 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 329 | } |
| 330 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 331 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; } |
| 332 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 333 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 334 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 335 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 336 | HInstruction* const instruction_; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 337 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 338 | |
| 339 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 340 | }; |
| 341 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 342 | class DeoptimizationSlowPathARM : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 343 | public: |
| 344 | explicit DeoptimizationSlowPathARM(HInstruction* instruction) |
| 345 | : instruction_(instruction) {} |
| 346 | |
| 347 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 348 | __ Bind(GetEntryLabel()); |
| 349 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 350 | DCHECK(instruction_->IsDeoptimize()); |
| 351 | HDeoptimize* deoptimize = instruction_->AsDeoptimize(); |
| 352 | uint32_t dex_pc = deoptimize->GetDexPc(); |
| 353 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 354 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this); |
| 355 | } |
| 356 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 357 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; } |
| 358 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 359 | private: |
| 360 | HInstruction* const instruction_; |
| 361 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM); |
| 362 | }; |
| 363 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 364 | class ArraySetSlowPathARM : public SlowPathCode { |
| 365 | public: |
| 366 | explicit ArraySetSlowPathARM(HInstruction* instruction) : instruction_(instruction) {} |
| 367 | |
| 368 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 369 | LocationSummary* locations = instruction_->GetLocations(); |
| 370 | __ Bind(GetEntryLabel()); |
| 371 | SaveLiveRegisters(codegen, locations); |
| 372 | |
| 373 | InvokeRuntimeCallingConvention calling_convention; |
| 374 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 375 | parallel_move.AddMove( |
| 376 | locations->InAt(0), |
| 377 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 378 | Primitive::kPrimNot, |
| 379 | nullptr); |
| 380 | parallel_move.AddMove( |
| 381 | locations->InAt(1), |
| 382 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 383 | Primitive::kPrimInt, |
| 384 | nullptr); |
| 385 | parallel_move.AddMove( |
| 386 | locations->InAt(2), |
| 387 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 388 | Primitive::kPrimNot, |
| 389 | nullptr); |
| 390 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 391 | |
| 392 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 393 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 394 | instruction_, |
| 395 | instruction_->GetDexPc(), |
| 396 | this); |
| 397 | RestoreLiveRegisters(codegen, locations); |
| 398 | __ b(GetExitLabel()); |
| 399 | } |
| 400 | |
| 401 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; } |
| 402 | |
| 403 | private: |
| 404 | HInstruction* const instruction_; |
| 405 | |
| 406 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM); |
| 407 | }; |
| 408 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 409 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 410 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 411 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 412 | inline Condition ARMSignedOrFPCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 413 | switch (cond) { |
| 414 | case kCondEQ: return EQ; |
| 415 | case kCondNE: return NE; |
| 416 | case kCondLT: return LT; |
| 417 | case kCondLE: return LE; |
| 418 | case kCondGT: return GT; |
| 419 | case kCondGE: return GE; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 420 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 421 | LOG(FATAL) << "Unreachable"; |
| 422 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 425 | inline Condition ARMUnsignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 426 | switch (cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 427 | case kCondEQ: return EQ; |
| 428 | case kCondNE: return NE; |
| 429 | case kCondLT: return LO; |
| 430 | case kCondLE: return LS; |
| 431 | case kCondGT: return HI; |
| 432 | case kCondGE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 433 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 434 | LOG(FATAL) << "Unreachable"; |
| 435 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 436 | } |
| 437 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 438 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 439 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 443 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 444 | } |
| 445 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 446 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 447 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 448 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 449 | } |
| 450 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 451 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 452 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 453 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 454 | } |
| 455 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 456 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 457 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 458 | return kArmWordSize; |
| 459 | } |
| 460 | |
| 461 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 462 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 463 | return kArmWordSize; |
| 464 | } |
| 465 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 466 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 467 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 468 | const CompilerOptions& compiler_options, |
| 469 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 470 | : CodeGenerator(graph, |
| 471 | kNumberOfCoreRegisters, |
| 472 | kNumberOfSRegisters, |
| 473 | kNumberOfRegisterPairs, |
| 474 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 475 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 88a95ba | 2015-09-30 17:18:14 +0100 | [diff] [blame] | 476 | graph->IsDebuggable() |
| 477 | // If the graph is debuggable, we need to save the fpu registers ourselves, |
| 478 | // as the stubs do not do it. |
| 479 | ? 0 |
| 480 | : ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 481 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 482 | compiler_options, |
| 483 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 484 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 485 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 486 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 487 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 488 | assembler_(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 489 | isa_features_(isa_features), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 490 | method_patches_(MethodReferenceComparator(), |
| 491 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 492 | call_patches_(MethodReferenceComparator(), |
| 493 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 494 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 495 | // Always save the LR register to mimic Quick. |
| 496 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 497 | } |
| 498 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 499 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 500 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 501 | __ FinalizeCode(); |
| 502 | |
| 503 | // Adjust native pc offsets in stack maps. |
| 504 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
| 505 | uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset; |
| 506 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 507 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 508 | } |
| 509 | // Adjust native pc offsets of block labels. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 510 | for (HBasicBlock* block : *block_order_) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 511 | // Get the label directly from block_labels_ rather than through GetLabelOf() to avoid |
| 512 | // FirstNonEmptyBlock() which could lead to adjusting a label more than once. |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 513 | DCHECK_LT(block->GetBlockId(), GetGraph()->GetBlocks().size()); |
| 514 | Label* block_label = &block_labels_[block->GetBlockId()]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 515 | DCHECK_EQ(block_label->IsBound(), !block->IsSingleJump()); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 516 | if (block_label->IsBound()) { |
| 517 | __ AdjustLabelPosition(block_label); |
| 518 | } |
| 519 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 520 | // Adjust pc offsets for the disassembly information. |
| 521 | if (disasm_info_ != nullptr) { |
| 522 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 523 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 524 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 525 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 526 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 527 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 528 | } |
| 529 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 530 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 531 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 532 | } |
| 533 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 534 | // Adjust pc offsets for relative call patches. |
| 535 | for (MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 536 | __ AdjustLabelPosition(&info.label); |
| 537 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 538 | |
| 539 | CodeGenerator::Finalize(allocator); |
| 540 | } |
| 541 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 542 | Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 543 | switch (type) { |
| 544 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 545 | size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 546 | ArmManagedRegister pair = |
| 547 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 548 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); |
| 549 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); |
| 550 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 551 | blocked_core_registers_[pair.AsRegisterPairLow()] = true; |
| 552 | blocked_core_registers_[pair.AsRegisterPairHigh()] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 553 | UpdateBlockedPairRegisters(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 554 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | case Primitive::kPrimByte: |
| 558 | case Primitive::kPrimBoolean: |
| 559 | case Primitive::kPrimChar: |
| 560 | case Primitive::kPrimShort: |
| 561 | case Primitive::kPrimInt: |
| 562 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 563 | int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 564 | // Block all register pairs that contain `reg`. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 565 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 566 | ArmManagedRegister current = |
| 567 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 568 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 569 | blocked_register_pairs_[i] = true; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 570 | } |
| 571 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 572 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 573 | } |
| 574 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 575 | case Primitive::kPrimFloat: { |
| 576 | int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 577 | return Location::FpuRegisterLocation(reg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 578 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 579 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 580 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 3c03503 | 2014-10-28 10:46:40 +0000 | [diff] [blame] | 581 | int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters); |
| 582 | DCHECK_EQ(reg % 2, 0); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 583 | return Location::FpuRegisterPairLocation(reg, reg + 1); |
| 584 | } |
| 585 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 586 | case Primitive::kPrimVoid: |
| 587 | LOG(FATAL) << "Unreachable type " << type; |
| 588 | } |
| 589 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 590 | return Location(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 591 | } |
| 592 | |
Nicolas Geoffray | a0bb2bd | 2015-01-26 12:49:35 +0000 | [diff] [blame] | 593 | void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 594 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 595 | blocked_register_pairs_[R1_R2] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 596 | |
| 597 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 598 | blocked_core_registers_[SP] = true; |
| 599 | blocked_core_registers_[LR] = true; |
| 600 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 601 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 602 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 603 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 604 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 605 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 606 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 607 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 608 | if (is_baseline) { |
| 609 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 610 | blocked_core_registers_[kCoreCalleeSaves[i]] = true; |
| 611 | } |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 612 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 613 | blocked_core_registers_[kCoreSavedRegisterForBaseline] = false; |
| 614 | |
| 615 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 616 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 617 | } |
| 618 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 619 | |
| 620 | UpdateBlockedPairRegisters(); |
| 621 | } |
| 622 | |
| 623 | void CodeGeneratorARM::UpdateBlockedPairRegisters() const { |
| 624 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 625 | ArmManagedRegister current = |
| 626 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 627 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 628 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 629 | blocked_register_pairs_[i] = true; |
| 630 | } |
| 631 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 632 | } |
| 633 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 634 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
| 635 | : HGraphVisitor(graph), |
| 636 | assembler_(codegen->GetAssembler()), |
| 637 | codegen_(codegen) {} |
| 638 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 639 | void CodeGeneratorARM::ComputeSpillMask() { |
| 640 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 641 | // Save one extra register for baseline. Note that on thumb2, there is no easy |
| 642 | // instruction to restore just the PC, so this actually helps both baseline |
| 643 | // and non-baseline to save and restore at least two registers at entry and exit. |
| 644 | core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 645 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 646 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 647 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 648 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 649 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 650 | // but in the range. |
| 651 | if (fpu_spill_mask_ != 0) { |
| 652 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 653 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 654 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 655 | fpu_spill_mask_ |= (1 << i); |
| 656 | } |
| 657 | } |
| 658 | } |
| 659 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 660 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 661 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 665 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 666 | } |
| 667 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 668 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 669 | bool skip_overflow_check = |
| 670 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 671 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 672 | __ Bind(&frame_entry_label_); |
| 673 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 674 | if (HasEmptyFrame()) { |
| 675 | return; |
| 676 | } |
| 677 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 678 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 679 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 680 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 681 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 682 | } |
| 683 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 684 | __ PushList(core_spill_mask_); |
| 685 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 686 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 687 | if (fpu_spill_mask_ != 0) { |
| 688 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 689 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 690 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 691 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 692 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 693 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 694 | __ AddConstant(SP, -adjust); |
| 695 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 696 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 700 | if (HasEmptyFrame()) { |
| 701 | __ bx(LR); |
| 702 | return; |
| 703 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 704 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 705 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 706 | __ AddConstant(SP, adjust); |
| 707 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 708 | if (fpu_spill_mask_ != 0) { |
| 709 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 710 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 711 | __ cfi().AdjustCFAOffset(-kArmPointerSize * POPCOUNT(fpu_spill_mask_)); |
| 712 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 713 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 714 | // Pop LR into PC to return. |
| 715 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 716 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 717 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 718 | __ cfi().RestoreState(); |
| 719 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 720 | } |
| 721 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 722 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
| 723 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 724 | } |
| 725 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 726 | Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const { |
| 727 | switch (load->GetType()) { |
| 728 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 729 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 730 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 731 | |
| 732 | case Primitive::kPrimInt: |
| 733 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 734 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 735 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 736 | |
| 737 | case Primitive::kPrimBoolean: |
| 738 | case Primitive::kPrimByte: |
| 739 | case Primitive::kPrimChar: |
| 740 | case Primitive::kPrimShort: |
| 741 | case Primitive::kPrimVoid: |
| 742 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 743 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 747 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 748 | } |
| 749 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 750 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 751 | switch (type) { |
| 752 | case Primitive::kPrimBoolean: |
| 753 | case Primitive::kPrimByte: |
| 754 | case Primitive::kPrimChar: |
| 755 | case Primitive::kPrimShort: |
| 756 | case Primitive::kPrimInt: |
| 757 | case Primitive::kPrimNot: { |
| 758 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 759 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 760 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 761 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 762 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 763 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 764 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 765 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 766 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 767 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 768 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 769 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 770 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 771 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 772 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 773 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 774 | // Skip R1, and use R2_R3 instead. |
| 775 | gp_index_++; |
| 776 | index++; |
| 777 | } |
| 778 | } |
| 779 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 780 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 781 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 782 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 783 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 784 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 785 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 786 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | case Primitive::kPrimFloat: { |
| 791 | uint32_t stack_index = stack_index_++; |
| 792 | if (float_index_ % 2 == 0) { |
| 793 | float_index_ = std::max(double_index_, float_index_); |
| 794 | } |
| 795 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 796 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 797 | } else { |
| 798 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | case Primitive::kPrimDouble: { |
| 803 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 804 | uint32_t stack_index = stack_index_; |
| 805 | stack_index_ += 2; |
| 806 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 807 | uint32_t index = double_index_; |
| 808 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 809 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 810 | calling_convention.GetFpuRegisterAt(index), |
| 811 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 812 | DCHECK(ExpectedPairLayout(result)); |
| 813 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 814 | } else { |
| 815 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 816 | } |
| 817 | } |
| 818 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 819 | case Primitive::kPrimVoid: |
| 820 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 821 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 822 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 823 | return Location(); |
| 824 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 825 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 826 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 827 | switch (type) { |
| 828 | case Primitive::kPrimBoolean: |
| 829 | case Primitive::kPrimByte: |
| 830 | case Primitive::kPrimChar: |
| 831 | case Primitive::kPrimShort: |
| 832 | case Primitive::kPrimInt: |
| 833 | case Primitive::kPrimNot: { |
| 834 | return Location::RegisterLocation(R0); |
| 835 | } |
| 836 | |
| 837 | case Primitive::kPrimFloat: { |
| 838 | return Location::FpuRegisterLocation(S0); |
| 839 | } |
| 840 | |
| 841 | case Primitive::kPrimLong: { |
| 842 | return Location::RegisterPairLocation(R0, R1); |
| 843 | } |
| 844 | |
| 845 | case Primitive::kPrimDouble: { |
| 846 | return Location::FpuRegisterPairLocation(S0, S1); |
| 847 | } |
| 848 | |
| 849 | case Primitive::kPrimVoid: |
| 850 | return Location(); |
| 851 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 852 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 853 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 854 | } |
| 855 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 856 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 857 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 858 | } |
| 859 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 860 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 861 | if (source.Equals(destination)) { |
| 862 | return; |
| 863 | } |
| 864 | if (destination.IsRegister()) { |
| 865 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 866 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 867 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 868 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 869 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 870 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 871 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 872 | } else if (destination.IsFpuRegister()) { |
| 873 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 874 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 875 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 876 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 877 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 878 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 879 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 880 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 881 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 882 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 883 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 884 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 885 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 886 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 887 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 888 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 889 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 890 | } |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 895 | if (source.Equals(destination)) { |
| 896 | return; |
| 897 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 898 | if (destination.IsRegisterPair()) { |
| 899 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 900 | EmitParallelMoves( |
| 901 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 902 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 903 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 904 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 905 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 906 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 907 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 908 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 909 | } else if (source.IsFpuRegisterPair()) { |
| 910 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 911 | destination.AsRegisterPairHigh<Register>(), |
| 912 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 913 | } else { |
| 914 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 915 | DCHECK(ExpectedPairLayout(destination)); |
| 916 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 917 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 918 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 919 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 920 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 921 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 922 | SP, |
| 923 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 924 | } else if (source.IsRegisterPair()) { |
| 925 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 926 | source.AsRegisterPairLow<Register>(), |
| 927 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 928 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 929 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 930 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 931 | } else { |
| 932 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 933 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 934 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 935 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 936 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 937 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 938 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 939 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 940 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 941 | SP, destination.GetStackIndex()); |
| 942 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 943 | } else if (source.IsFpuRegisterPair()) { |
| 944 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 945 | SP, |
| 946 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 947 | } else { |
| 948 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 949 | EmitParallelMoves( |
| 950 | Location::StackSlot(source.GetStackIndex()), |
| 951 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 952 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 953 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 954 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 955 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 956 | } |
| 957 | } |
| 958 | } |
| 959 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 960 | void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 961 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 962 | if (instruction->IsCurrentMethod()) { |
| 963 | Move32(location, Location::StackSlot(kCurrentMethodStackOffset)); |
| 964 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 965 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 966 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 967 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 968 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 969 | int32_t value = GetInt32ValueOf(const_to_move); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 970 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 971 | __ LoadImmediate(location.AsRegister<Register>(), value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 972 | } else { |
| 973 | DCHECK(location.IsStackSlot()); |
| 974 | __ LoadImmediate(IP, value); |
| 975 | __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); |
| 976 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 977 | } else { |
Nicolas Geoffray | 3747b48 | 2015-01-19 17:17:16 +0000 | [diff] [blame] | 978 | DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName(); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 979 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 980 | if (location.IsRegisterPair()) { |
| 981 | __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 982 | __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value)); |
| 983 | } else { |
| 984 | DCHECK(location.IsDoubleStackSlot()); |
| 985 | __ LoadImmediate(IP, Low32Bits(value)); |
| 986 | __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); |
| 987 | __ LoadImmediate(IP, High32Bits(value)); |
| 988 | __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize)); |
| 989 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 990 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 991 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 992 | uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
| 993 | switch (instruction->GetType()) { |
| 994 | case Primitive::kPrimBoolean: |
| 995 | case Primitive::kPrimByte: |
| 996 | case Primitive::kPrimChar: |
| 997 | case Primitive::kPrimShort: |
| 998 | case Primitive::kPrimInt: |
| 999 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1000 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1001 | Move32(location, Location::StackSlot(stack_slot)); |
| 1002 | break; |
| 1003 | |
| 1004 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1005 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1006 | Move64(location, Location::DoubleStackSlot(stack_slot)); |
| 1007 | break; |
| 1008 | |
| 1009 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1010 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1011 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 1012 | } else if (instruction->IsTemporary()) { |
| 1013 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1014 | if (temp_location.IsStackSlot()) { |
| 1015 | Move32(location, temp_location); |
| 1016 | } else { |
| 1017 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 1018 | Move64(location, temp_location); |
| 1019 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1020 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1021 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1022 | switch (instruction->GetType()) { |
| 1023 | case Primitive::kPrimBoolean: |
| 1024 | case Primitive::kPrimByte: |
| 1025 | case Primitive::kPrimChar: |
| 1026 | case Primitive::kPrimShort: |
| 1027 | case Primitive::kPrimNot: |
| 1028 | case Primitive::kPrimInt: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1029 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1030 | Move32(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1031 | break; |
| 1032 | |
| 1033 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1034 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1035 | Move64(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1036 | break; |
| 1037 | |
| 1038 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1039 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1040 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1041 | } |
| 1042 | } |
| 1043 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1044 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 1045 | DCHECK(location.IsRegister()); |
| 1046 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 1047 | } |
| 1048 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 1049 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
| 1050 | if (Primitive::Is64BitType(dst_type)) { |
| 1051 | Move64(dst, src); |
| 1052 | } else { |
| 1053 | Move32(dst, src); |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1058 | if (location.IsRegister()) { |
| 1059 | locations->AddTemp(location); |
| 1060 | } else if (location.IsRegisterPair()) { |
| 1061 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1062 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1063 | } else { |
| 1064 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1065 | } |
| 1066 | } |
| 1067 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1068 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1069 | HInstruction* instruction, |
| 1070 | uint32_t dex_pc, |
| 1071 | SlowPathCode* slow_path) { |
| 1072 | InvokeRuntime(GetThreadOffset<kArmWordSize>(entrypoint).Int32Value(), |
| 1073 | instruction, |
| 1074 | dex_pc, |
| 1075 | slow_path); |
| 1076 | } |
| 1077 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1078 | void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset, |
| 1079 | HInstruction* instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1080 | uint32_t dex_pc, |
| 1081 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1082 | ValidateInvokeRuntime(instruction, slow_path); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1083 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 1084 | __ blx(LR); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1085 | RecordPcInfo(instruction, dex_pc, slow_path); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1086 | } |
| 1087 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1088 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1089 | DCHECK(!successor->IsExitBlock()); |
| 1090 | |
| 1091 | HBasicBlock* block = got->GetBlock(); |
| 1092 | HInstruction* previous = got->GetPrevious(); |
| 1093 | |
| 1094 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1095 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1096 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 1097 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1098 | return; |
| 1099 | } |
| 1100 | |
| 1101 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1102 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1103 | } |
| 1104 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1105 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1106 | } |
| 1107 | } |
| 1108 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1109 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 1110 | got->SetLocations(nullptr); |
| 1111 | } |
| 1112 | |
| 1113 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 1114 | HandleGoto(got, got->GetSuccessor()); |
| 1115 | } |
| 1116 | |
| 1117 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1118 | try_boundary->SetLocations(nullptr); |
| 1119 | } |
| 1120 | |
| 1121 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1122 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1123 | if (!successor->IsExitBlock()) { |
| 1124 | HandleGoto(try_boundary, successor); |
| 1125 | } |
| 1126 | } |
| 1127 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1128 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1129 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1132 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1133 | UNUSED(exit); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1136 | void InstructionCodeGeneratorARM::GenerateCompareWithImmediate(Register left, int32_t right) { |
| 1137 | ShifterOperand operand; |
| 1138 | if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, right, &operand)) { |
| 1139 | __ cmp(left, operand); |
| 1140 | } else { |
| 1141 | Register temp = IP; |
| 1142 | __ LoadImmediate(temp, right); |
| 1143 | __ cmp(left, ShifterOperand(temp)); |
| 1144 | } |
| 1145 | } |
| 1146 | |
| 1147 | void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond, |
| 1148 | Label* true_label, |
| 1149 | Label* false_label) { |
| 1150 | __ vmstat(); // transfer FP status register to ARM APSR. |
| 1151 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1152 | __ b(true_label, VS); // VS for unordered. |
| 1153 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1154 | __ b(false_label, VS); // VS for unordered. |
| 1155 | } |
| 1156 | __ b(true_label, ARMSignedOrFPCondition(cond->GetCondition())); |
| 1157 | } |
| 1158 | |
| 1159 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 1160 | Label* true_label, |
| 1161 | Label* false_label) { |
| 1162 | LocationSummary* locations = cond->GetLocations(); |
| 1163 | Location left = locations->InAt(0); |
| 1164 | Location right = locations->InAt(1); |
| 1165 | IfCondition if_cond = cond->GetCondition(); |
| 1166 | |
| 1167 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1168 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 1169 | IfCondition true_high_cond = if_cond; |
| 1170 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
| 1171 | Condition final_condition = ARMUnsignedCondition(if_cond); |
| 1172 | |
| 1173 | // Set the conditions for the test, remembering that == needs to be |
| 1174 | // decided using the low words. |
| 1175 | switch (if_cond) { |
| 1176 | case kCondEQ: |
| 1177 | case kCondNE: |
| 1178 | // Nothing to do. |
| 1179 | break; |
| 1180 | case kCondLT: |
| 1181 | false_high_cond = kCondGT; |
| 1182 | break; |
| 1183 | case kCondLE: |
| 1184 | true_high_cond = kCondLT; |
| 1185 | break; |
| 1186 | case kCondGT: |
| 1187 | false_high_cond = kCondLT; |
| 1188 | break; |
| 1189 | case kCondGE: |
| 1190 | true_high_cond = kCondGT; |
| 1191 | break; |
| 1192 | } |
| 1193 | if (right.IsConstant()) { |
| 1194 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1195 | int32_t val_low = Low32Bits(value); |
| 1196 | int32_t val_high = High32Bits(value); |
| 1197 | |
| 1198 | GenerateCompareWithImmediate(left_high, val_high); |
| 1199 | if (if_cond == kCondNE) { |
| 1200 | __ b(true_label, ARMSignedOrFPCondition(true_high_cond)); |
| 1201 | } else if (if_cond == kCondEQ) { |
| 1202 | __ b(false_label, ARMSignedOrFPCondition(false_high_cond)); |
| 1203 | } else { |
| 1204 | __ b(true_label, ARMSignedOrFPCondition(true_high_cond)); |
| 1205 | __ b(false_label, ARMSignedOrFPCondition(false_high_cond)); |
| 1206 | } |
| 1207 | // Must be equal high, so compare the lows. |
| 1208 | GenerateCompareWithImmediate(left_low, val_low); |
| 1209 | } else { |
| 1210 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 1211 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 1212 | |
| 1213 | __ cmp(left_high, ShifterOperand(right_high)); |
| 1214 | if (if_cond == kCondNE) { |
| 1215 | __ b(true_label, ARMSignedOrFPCondition(true_high_cond)); |
| 1216 | } else if (if_cond == kCondEQ) { |
| 1217 | __ b(false_label, ARMSignedOrFPCondition(false_high_cond)); |
| 1218 | } else { |
| 1219 | __ b(true_label, ARMSignedOrFPCondition(true_high_cond)); |
| 1220 | __ b(false_label, ARMSignedOrFPCondition(false_high_cond)); |
| 1221 | } |
| 1222 | // Must be equal high, so compare the lows. |
| 1223 | __ cmp(left_low, ShifterOperand(right_low)); |
| 1224 | } |
| 1225 | // The last comparison might be unsigned. |
| 1226 | __ b(true_label, final_condition); |
| 1227 | } |
| 1228 | |
| 1229 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HIf* if_instr, |
| 1230 | HCondition* condition, |
| 1231 | Label* true_target, |
| 1232 | Label* false_target, |
| 1233 | Label* always_true_target) { |
| 1234 | LocationSummary* locations = condition->GetLocations(); |
| 1235 | Location left = locations->InAt(0); |
| 1236 | Location right = locations->InAt(1); |
| 1237 | |
| 1238 | // We don't want true_target as a nullptr. |
| 1239 | if (true_target == nullptr) { |
| 1240 | true_target = always_true_target; |
| 1241 | } |
| 1242 | bool falls_through = (false_target == nullptr); |
| 1243 | |
| 1244 | // FP compares don't like null false_targets. |
| 1245 | if (false_target == nullptr) { |
| 1246 | false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1247 | } |
| 1248 | |
| 1249 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1250 | switch (type) { |
| 1251 | case Primitive::kPrimLong: |
| 1252 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1253 | break; |
| 1254 | case Primitive::kPrimFloat: |
| 1255 | __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>()); |
| 1256 | GenerateFPJumps(condition, true_target, false_target); |
| 1257 | break; |
| 1258 | case Primitive::kPrimDouble: |
| 1259 | __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), |
| 1260 | FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); |
| 1261 | GenerateFPJumps(condition, true_target, false_target); |
| 1262 | break; |
| 1263 | default: |
| 1264 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1265 | } |
| 1266 | |
| 1267 | if (!falls_through) { |
| 1268 | __ b(false_target); |
| 1269 | } |
| 1270 | } |
| 1271 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1272 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
| 1273 | Label* true_target, |
| 1274 | Label* false_target, |
| 1275 | Label* always_true_target) { |
| 1276 | HInstruction* cond = instruction->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1277 | if (cond->IsIntConstant()) { |
| 1278 | // Constant condition, statically compared against 1. |
| 1279 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 1280 | if (cond_value == 1) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1281 | if (always_true_target != nullptr) { |
| 1282 | __ b(always_true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1283 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1284 | return; |
| 1285 | } else { |
| 1286 | DCHECK_EQ(cond_value, 0); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1287 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1288 | } else { |
| 1289 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1290 | // Condition has been materialized, compare the output to 0 |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1291 | DCHECK(instruction->GetLocations()->InAt(0).IsRegister()); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 1292 | __ CompareAndBranchIfNonZero(instruction->GetLocations()->InAt(0).AsRegister<Register>(), |
| 1293 | true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1294 | } else { |
| 1295 | // Condition has not been materialized, use its inputs as the |
| 1296 | // comparison and its condition as the branch condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1297 | Primitive::Type type = |
| 1298 | cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt; |
| 1299 | // Is this a long or FP comparison that has been folded into the HCondition? |
| 1300 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1301 | // Generate the comparison directly. |
| 1302 | GenerateCompareTestAndBranch(instruction->AsIf(), cond->AsCondition(), |
| 1303 | true_target, false_target, always_true_target); |
| 1304 | return; |
| 1305 | } |
| 1306 | |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1307 | LocationSummary* locations = cond->GetLocations(); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1308 | DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0); |
Nicolas Geoffray | 3bcc8ea | 2014-11-28 15:00:02 +0000 | [diff] [blame] | 1309 | Register left = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1310 | Location right = locations->InAt(1); |
| 1311 | if (right.IsRegister()) { |
| 1312 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1313 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1314 | DCHECK(right.IsConstant()); |
| 1315 | GenerateCompareWithImmediate(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1316 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1317 | __ b(true_target, ARMSignedOrFPCondition(cond->AsCondition()->GetCondition())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1318 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1319 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1320 | if (false_target != nullptr) { |
| 1321 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1322 | } |
| 1323 | } |
| 1324 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1325 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
| 1326 | LocationSummary* locations = |
| 1327 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
| 1328 | HInstruction* cond = if_instr->InputAt(0); |
| 1329 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1330 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
| 1335 | Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 1336 | Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1337 | Label* always_true_target = true_target; |
| 1338 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1339 | if_instr->IfTrueSuccessor())) { |
| 1340 | always_true_target = nullptr; |
| 1341 | } |
| 1342 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1343 | if_instr->IfFalseSuccessor())) { |
| 1344 | false_target = nullptr; |
| 1345 | } |
| 1346 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 1347 | } |
| 1348 | |
| 1349 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1350 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1351 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 1352 | HInstruction* cond = deoptimize->InputAt(0); |
| 1353 | DCHECK(cond->IsCondition()); |
| 1354 | if (cond->AsCondition()->NeedsMaterialization()) { |
| 1355 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1356 | } |
| 1357 | } |
| 1358 | |
| 1359 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 1360 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1361 | DeoptimizationSlowPathARM(deoptimize); |
| 1362 | codegen_->AddSlowPath(slow_path); |
| 1363 | Label* slow_path_entry = slow_path->GetEntryLabel(); |
| 1364 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 1365 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1366 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1367 | void LocationsBuilderARM::VisitCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1368 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1369 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1370 | // Handle the long/FP comparisons made in instruction simplification. |
| 1371 | switch (cond->InputAt(0)->GetType()) { |
| 1372 | case Primitive::kPrimLong: |
| 1373 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1374 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1375 | if (cond->NeedsMaterialization()) { |
| 1376 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 1377 | } |
| 1378 | break; |
| 1379 | |
| 1380 | case Primitive::kPrimFloat: |
| 1381 | case Primitive::kPrimDouble: |
| 1382 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1383 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1384 | if (cond->NeedsMaterialization()) { |
| 1385 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1386 | } |
| 1387 | break; |
| 1388 | |
| 1389 | default: |
| 1390 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1391 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1392 | if (cond->NeedsMaterialization()) { |
| 1393 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1394 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1395 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1396 | } |
| 1397 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1398 | void InstructionCodeGeneratorARM::VisitCondition(HCondition* cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1399 | if (!cond->NeedsMaterialization()) { |
| 1400 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1401 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1402 | |
| 1403 | LocationSummary* locations = cond->GetLocations(); |
| 1404 | Location left = locations->InAt(0); |
| 1405 | Location right = locations->InAt(1); |
| 1406 | Register out = locations->Out().AsRegister<Register>(); |
| 1407 | Label true_label, false_label; |
| 1408 | |
| 1409 | switch (cond->InputAt(0)->GetType()) { |
| 1410 | default: { |
| 1411 | // Integer case. |
| 1412 | if (right.IsRegister()) { |
| 1413 | __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>())); |
| 1414 | } else { |
| 1415 | DCHECK(right.IsConstant()); |
| 1416 | GenerateCompareWithImmediate(left.AsRegister<Register>(), |
| 1417 | CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
| 1418 | } |
| 1419 | __ it(ARMSignedOrFPCondition(cond->GetCondition()), kItElse); |
| 1420 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1), |
| 1421 | ARMSignedOrFPCondition(cond->GetCondition())); |
| 1422 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0), |
| 1423 | ARMSignedOrFPCondition(cond->GetOppositeCondition())); |
| 1424 | return; |
| 1425 | } |
| 1426 | case Primitive::kPrimLong: |
| 1427 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1428 | break; |
| 1429 | case Primitive::kPrimFloat: |
| 1430 | __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>()); |
| 1431 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1432 | break; |
| 1433 | case Primitive::kPrimDouble: |
| 1434 | __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), |
| 1435 | FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); |
| 1436 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1437 | break; |
| 1438 | } |
| 1439 | |
| 1440 | // Convert the jumps into the result. |
| 1441 | Label done_label; |
| 1442 | |
| 1443 | // False case: result = 0. |
| 1444 | __ Bind(&false_label); |
| 1445 | __ LoadImmediate(out, 0); |
| 1446 | __ b(&done_label); |
| 1447 | |
| 1448 | // True case: result = 1. |
| 1449 | __ Bind(&true_label); |
| 1450 | __ LoadImmediate(out, 1); |
| 1451 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
| 1455 | VisitCondition(comp); |
| 1456 | } |
| 1457 | |
| 1458 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
| 1459 | VisitCondition(comp); |
| 1460 | } |
| 1461 | |
| 1462 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
| 1463 | VisitCondition(comp); |
| 1464 | } |
| 1465 | |
| 1466 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
| 1467 | VisitCondition(comp); |
| 1468 | } |
| 1469 | |
| 1470 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
| 1471 | VisitCondition(comp); |
| 1472 | } |
| 1473 | |
| 1474 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
| 1475 | VisitCondition(comp); |
| 1476 | } |
| 1477 | |
| 1478 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1479 | VisitCondition(comp); |
| 1480 | } |
| 1481 | |
| 1482 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1483 | VisitCondition(comp); |
| 1484 | } |
| 1485 | |
| 1486 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
| 1487 | VisitCondition(comp); |
| 1488 | } |
| 1489 | |
| 1490 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
| 1491 | VisitCondition(comp); |
| 1492 | } |
| 1493 | |
| 1494 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1495 | VisitCondition(comp); |
| 1496 | } |
| 1497 | |
| 1498 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1499 | VisitCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | void LocationsBuilderARM::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1503 | local->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1504 | } |
| 1505 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1506 | void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) { |
| 1507 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1508 | } |
| 1509 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1510 | void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1511 | load->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1512 | } |
| 1513 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1514 | void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1515 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1516 | UNUSED(load); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1520 | LocationSummary* locations = |
| 1521 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1522 | switch (store->InputAt(1)->GetType()) { |
| 1523 | case Primitive::kPrimBoolean: |
| 1524 | case Primitive::kPrimByte: |
| 1525 | case Primitive::kPrimChar: |
| 1526 | case Primitive::kPrimShort: |
| 1527 | case Primitive::kPrimInt: |
| 1528 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1529 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1530 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1531 | break; |
| 1532 | |
| 1533 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1534 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1535 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1536 | break; |
| 1537 | |
| 1538 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1539 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1540 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1541 | } |
| 1542 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1543 | void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1544 | UNUSED(store); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1548 | LocationSummary* locations = |
| 1549 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1550 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1551 | } |
| 1552 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1553 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1554 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1555 | UNUSED(constant); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1556 | } |
| 1557 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1558 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 1559 | LocationSummary* locations = |
| 1560 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1561 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1562 | } |
| 1563 | |
| 1564 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant) { |
| 1565 | // Will be generated at use site. |
| 1566 | UNUSED(constant); |
| 1567 | } |
| 1568 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1569 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1570 | LocationSummary* locations = |
| 1571 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1572 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1573 | } |
| 1574 | |
| 1575 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) { |
| 1576 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1577 | UNUSED(constant); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1578 | } |
| 1579 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1580 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 1581 | LocationSummary* locations = |
| 1582 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1583 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1584 | } |
| 1585 | |
| 1586 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) { |
| 1587 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1588 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1589 | } |
| 1590 | |
| 1591 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1592 | LocationSummary* locations = |
| 1593 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1594 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1595 | } |
| 1596 | |
| 1597 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1598 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1599 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1600 | } |
| 1601 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1602 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1603 | memory_barrier->SetLocations(nullptr); |
| 1604 | } |
| 1605 | |
| 1606 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1607 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1608 | } |
| 1609 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1610 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1611 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1612 | } |
| 1613 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1614 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1615 | UNUSED(ret); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1616 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1617 | } |
| 1618 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1619 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1620 | LocationSummary* locations = |
| 1621 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1622 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1623 | } |
| 1624 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1625 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1626 | UNUSED(ret); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1627 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1630 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1631 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1632 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1633 | // the method_idx. |
| 1634 | HandleInvoke(invoke); |
| 1635 | } |
| 1636 | |
| 1637 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1638 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1639 | } |
| 1640 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1641 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1642 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1643 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1644 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1645 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1646 | IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(), |
| 1647 | codegen_->GetInstructionSetFeatures()); |
| 1648 | if (intrinsic.TryDispatch(invoke)) { |
| 1649 | return; |
| 1650 | } |
| 1651 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1652 | HandleInvoke(invoke); |
| 1653 | } |
| 1654 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1655 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 1656 | if (invoke->GetLocations()->Intrinsified()) { |
| 1657 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 1658 | intrinsic.Dispatch(invoke); |
| 1659 | return true; |
| 1660 | } |
| 1661 | return false; |
| 1662 | } |
| 1663 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1664 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1665 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1666 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1667 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1668 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1669 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1670 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1671 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1672 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1673 | LocationSummary* locations = invoke->GetLocations(); |
| 1674 | codegen_->GenerateStaticOrDirectCall( |
| 1675 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 1676 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1677 | } |
| 1678 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1679 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1680 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1681 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1682 | } |
| 1683 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1684 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1685 | IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(), |
| 1686 | codegen_->GetInstructionSetFeatures()); |
| 1687 | if (intrinsic.TryDispatch(invoke)) { |
| 1688 | return; |
| 1689 | } |
| 1690 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1691 | HandleInvoke(invoke); |
| 1692 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1693 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1694 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1695 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1696 | return; |
| 1697 | } |
| 1698 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1699 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1700 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1701 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1702 | } |
| 1703 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1704 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1705 | HandleInvoke(invoke); |
| 1706 | // Add the hidden argument. |
| 1707 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 1708 | } |
| 1709 | |
| 1710 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1711 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1712 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1713 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 1714 | invoke->GetImtIndex() % mirror::Class::kImtSize, kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1715 | LocationSummary* locations = invoke->GetLocations(); |
| 1716 | Location receiver = locations->InAt(0); |
| 1717 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1718 | |
| 1719 | // Set the hidden argument. |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1720 | __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(), |
| 1721 | invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1722 | |
| 1723 | // temp = object->GetClass(); |
| 1724 | if (receiver.IsStackSlot()) { |
| 1725 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 1726 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 1727 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1728 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1729 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1730 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1731 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1732 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1733 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1734 | kArmWordSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1735 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 1736 | // LR = temp->GetEntryPoint(); |
| 1737 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 1738 | // LR(); |
| 1739 | __ blx(LR); |
| 1740 | DCHECK(!codegen_->IsLeafMethod()); |
| 1741 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1742 | } |
| 1743 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1744 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 1745 | LocationSummary* locations = |
| 1746 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1747 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 1748 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1749 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 1750 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1751 | break; |
| 1752 | } |
| 1753 | case Primitive::kPrimLong: { |
| 1754 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1755 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1756 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1757 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1758 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1759 | case Primitive::kPrimFloat: |
| 1760 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1761 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1762 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1763 | break; |
| 1764 | |
| 1765 | default: |
| 1766 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1767 | } |
| 1768 | } |
| 1769 | |
| 1770 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 1771 | LocationSummary* locations = neg->GetLocations(); |
| 1772 | Location out = locations->Out(); |
| 1773 | Location in = locations->InAt(0); |
| 1774 | switch (neg->GetResultType()) { |
| 1775 | case Primitive::kPrimInt: |
| 1776 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1777 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1778 | break; |
| 1779 | |
| 1780 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1781 | DCHECK(in.IsRegisterPair()); |
| 1782 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 1783 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 1784 | in.AsRegisterPairLow<Register>(), |
| 1785 | ShifterOperand(0)); |
| 1786 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 1787 | // instruction here, as it does not exist in the Thumb-2 |
| 1788 | // instruction set. We use the following approach |
| 1789 | // using SBC and SUB instead. |
| 1790 | // |
| 1791 | // out.hi = -C |
| 1792 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 1793 | out.AsRegisterPairHigh<Register>(), |
| 1794 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 1795 | // out.hi = out.hi - in.hi |
| 1796 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 1797 | out.AsRegisterPairHigh<Register>(), |
| 1798 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 1799 | break; |
| 1800 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1801 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1802 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1803 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1804 | break; |
| 1805 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1806 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1807 | DCHECK(in.IsFpuRegisterPair()); |
| 1808 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1809 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1810 | break; |
| 1811 | |
| 1812 | default: |
| 1813 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1814 | } |
| 1815 | } |
| 1816 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1817 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1818 | Primitive::Type result_type = conversion->GetResultType(); |
| 1819 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1820 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1821 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 1822 | // The float-to-long, double-to-long and long-to-float type conversions |
| 1823 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1824 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 1825 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 1826 | && result_type == Primitive::kPrimLong) |
| 1827 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1828 | ? LocationSummary::kCall |
| 1829 | : LocationSummary::kNoCall; |
| 1830 | LocationSummary* locations = |
| 1831 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 1832 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1833 | // The Java language does not allow treating boolean as an integral type but |
| 1834 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1835 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1836 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1837 | case Primitive::kPrimByte: |
| 1838 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1839 | case Primitive::kPrimBoolean: |
| 1840 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1841 | case Primitive::kPrimShort: |
| 1842 | case Primitive::kPrimInt: |
| 1843 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1844 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1845 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1846 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1847 | break; |
| 1848 | |
| 1849 | default: |
| 1850 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1851 | << " to " << result_type; |
| 1852 | } |
| 1853 | break; |
| 1854 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1855 | case Primitive::kPrimShort: |
| 1856 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1857 | case Primitive::kPrimBoolean: |
| 1858 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1859 | case Primitive::kPrimByte: |
| 1860 | case Primitive::kPrimInt: |
| 1861 | case Primitive::kPrimChar: |
| 1862 | // Processing a Dex `int-to-short' instruction. |
| 1863 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1864 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1865 | break; |
| 1866 | |
| 1867 | default: |
| 1868 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1869 | << " to " << result_type; |
| 1870 | } |
| 1871 | break; |
| 1872 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1873 | case Primitive::kPrimInt: |
| 1874 | switch (input_type) { |
| 1875 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1876 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1877 | locations->SetInAt(0, Location::Any()); |
| 1878 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1879 | break; |
| 1880 | |
| 1881 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1882 | // Processing a Dex `float-to-int' instruction. |
| 1883 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1884 | locations->SetOut(Location::RequiresRegister()); |
| 1885 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1886 | break; |
| 1887 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1888 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1889 | // Processing a Dex `double-to-int' instruction. |
| 1890 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1891 | locations->SetOut(Location::RequiresRegister()); |
| 1892 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1893 | break; |
| 1894 | |
| 1895 | default: |
| 1896 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1897 | << " to " << result_type; |
| 1898 | } |
| 1899 | break; |
| 1900 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1901 | case Primitive::kPrimLong: |
| 1902 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1903 | case Primitive::kPrimBoolean: |
| 1904 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1905 | case Primitive::kPrimByte: |
| 1906 | case Primitive::kPrimShort: |
| 1907 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1908 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1909 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1910 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1911 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1912 | break; |
| 1913 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1914 | case Primitive::kPrimFloat: { |
| 1915 | // Processing a Dex `float-to-long' instruction. |
| 1916 | InvokeRuntimeCallingConvention calling_convention; |
| 1917 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 1918 | calling_convention.GetFpuRegisterAt(0))); |
| 1919 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 1920 | break; |
| 1921 | } |
| 1922 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1923 | case Primitive::kPrimDouble: { |
| 1924 | // Processing a Dex `double-to-long' instruction. |
| 1925 | InvokeRuntimeCallingConvention calling_convention; |
| 1926 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 1927 | calling_convention.GetFpuRegisterAt(0), |
| 1928 | calling_convention.GetFpuRegisterAt(1))); |
| 1929 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1930 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1931 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1932 | |
| 1933 | default: |
| 1934 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1935 | << " to " << result_type; |
| 1936 | } |
| 1937 | break; |
| 1938 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1939 | case Primitive::kPrimChar: |
| 1940 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1941 | case Primitive::kPrimBoolean: |
| 1942 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1943 | case Primitive::kPrimByte: |
| 1944 | case Primitive::kPrimShort: |
| 1945 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1946 | // Processing a Dex `int-to-char' instruction. |
| 1947 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1948 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1949 | break; |
| 1950 | |
| 1951 | default: |
| 1952 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1953 | << " to " << result_type; |
| 1954 | } |
| 1955 | break; |
| 1956 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1957 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1958 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1959 | case Primitive::kPrimBoolean: |
| 1960 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1961 | case Primitive::kPrimByte: |
| 1962 | case Primitive::kPrimShort: |
| 1963 | case Primitive::kPrimInt: |
| 1964 | case Primitive::kPrimChar: |
| 1965 | // Processing a Dex `int-to-float' instruction. |
| 1966 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1967 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1968 | break; |
| 1969 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 1970 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1971 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 1972 | InvokeRuntimeCallingConvention calling_convention; |
| 1973 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 1974 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 1975 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1976 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 1977 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1978 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1979 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1980 | // Processing a Dex `double-to-float' instruction. |
| 1981 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1982 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1983 | break; |
| 1984 | |
| 1985 | default: |
| 1986 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1987 | << " to " << result_type; |
| 1988 | }; |
| 1989 | break; |
| 1990 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1991 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1992 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1993 | case Primitive::kPrimBoolean: |
| 1994 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1995 | case Primitive::kPrimByte: |
| 1996 | case Primitive::kPrimShort: |
| 1997 | case Primitive::kPrimInt: |
| 1998 | case Primitive::kPrimChar: |
| 1999 | // Processing a Dex `int-to-double' instruction. |
| 2000 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2001 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2002 | break; |
| 2003 | |
| 2004 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2005 | // Processing a Dex `long-to-double' instruction. |
| 2006 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2007 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2008 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2009 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2010 | break; |
| 2011 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2012 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2013 | // Processing a Dex `float-to-double' instruction. |
| 2014 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2015 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2016 | break; |
| 2017 | |
| 2018 | default: |
| 2019 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2020 | << " to " << result_type; |
| 2021 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2022 | break; |
| 2023 | |
| 2024 | default: |
| 2025 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2026 | << " to " << result_type; |
| 2027 | } |
| 2028 | } |
| 2029 | |
| 2030 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 2031 | LocationSummary* locations = conversion->GetLocations(); |
| 2032 | Location out = locations->Out(); |
| 2033 | Location in = locations->InAt(0); |
| 2034 | Primitive::Type result_type = conversion->GetResultType(); |
| 2035 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2036 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2037 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2038 | case Primitive::kPrimByte: |
| 2039 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2040 | case Primitive::kPrimBoolean: |
| 2041 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2042 | case Primitive::kPrimShort: |
| 2043 | case Primitive::kPrimInt: |
| 2044 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2045 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2046 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2047 | break; |
| 2048 | |
| 2049 | default: |
| 2050 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2051 | << " to " << result_type; |
| 2052 | } |
| 2053 | break; |
| 2054 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2055 | case Primitive::kPrimShort: |
| 2056 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2057 | case Primitive::kPrimBoolean: |
| 2058 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2059 | case Primitive::kPrimByte: |
| 2060 | case Primitive::kPrimInt: |
| 2061 | case Primitive::kPrimChar: |
| 2062 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2063 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2064 | break; |
| 2065 | |
| 2066 | default: |
| 2067 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2068 | << " to " << result_type; |
| 2069 | } |
| 2070 | break; |
| 2071 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2072 | case Primitive::kPrimInt: |
| 2073 | switch (input_type) { |
| 2074 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2075 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2076 | DCHECK(out.IsRegister()); |
| 2077 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2078 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2079 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2080 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2081 | } else { |
| 2082 | DCHECK(in.IsConstant()); |
| 2083 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2084 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2085 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2086 | } |
| 2087 | break; |
| 2088 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2089 | case Primitive::kPrimFloat: { |
| 2090 | // Processing a Dex `float-to-int' instruction. |
| 2091 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
| 2092 | __ vmovs(temp, in.AsFpuRegister<SRegister>()); |
| 2093 | __ vcvtis(temp, temp); |
| 2094 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 2095 | break; |
| 2096 | } |
| 2097 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2098 | case Primitive::kPrimDouble: { |
| 2099 | // Processing a Dex `double-to-int' instruction. |
| 2100 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
| 2101 | DRegister temp_d = FromLowSToD(temp_s); |
| 2102 | __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
| 2103 | __ vcvtid(temp_s, temp_d); |
| 2104 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2105 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2106 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2107 | |
| 2108 | default: |
| 2109 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2110 | << " to " << result_type; |
| 2111 | } |
| 2112 | break; |
| 2113 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2114 | case Primitive::kPrimLong: |
| 2115 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2116 | case Primitive::kPrimBoolean: |
| 2117 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2118 | case Primitive::kPrimByte: |
| 2119 | case Primitive::kPrimShort: |
| 2120 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2121 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2122 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2123 | DCHECK(out.IsRegisterPair()); |
| 2124 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2125 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2126 | // Sign extension. |
| 2127 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 2128 | out.AsRegisterPairLow<Register>(), |
| 2129 | 31); |
| 2130 | break; |
| 2131 | |
| 2132 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2133 | // Processing a Dex `float-to-long' instruction. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2134 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2135 | conversion, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2136 | conversion->GetDexPc(), |
| 2137 | nullptr); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2138 | break; |
| 2139 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2140 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2141 | // Processing a Dex `double-to-long' instruction. |
| 2142 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2143 | conversion, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2144 | conversion->GetDexPc(), |
| 2145 | nullptr); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2146 | break; |
| 2147 | |
| 2148 | default: |
| 2149 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2150 | << " to " << result_type; |
| 2151 | } |
| 2152 | break; |
| 2153 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2154 | case Primitive::kPrimChar: |
| 2155 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2156 | case Primitive::kPrimBoolean: |
| 2157 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2158 | case Primitive::kPrimByte: |
| 2159 | case Primitive::kPrimShort: |
| 2160 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2161 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2162 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2163 | break; |
| 2164 | |
| 2165 | default: |
| 2166 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2167 | << " to " << result_type; |
| 2168 | } |
| 2169 | break; |
| 2170 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2171 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2172 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2173 | case Primitive::kPrimBoolean: |
| 2174 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2175 | case Primitive::kPrimByte: |
| 2176 | case Primitive::kPrimShort: |
| 2177 | case Primitive::kPrimInt: |
| 2178 | case Primitive::kPrimChar: { |
| 2179 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2180 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 2181 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2182 | break; |
| 2183 | } |
| 2184 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2185 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2186 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2187 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f), |
| 2188 | conversion, |
| 2189 | conversion->GetDexPc(), |
| 2190 | nullptr); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2191 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2192 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2193 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2194 | // Processing a Dex `double-to-float' instruction. |
| 2195 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 2196 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2197 | break; |
| 2198 | |
| 2199 | default: |
| 2200 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2201 | << " to " << result_type; |
| 2202 | }; |
| 2203 | break; |
| 2204 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2205 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2206 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2207 | case Primitive::kPrimBoolean: |
| 2208 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2209 | case Primitive::kPrimByte: |
| 2210 | case Primitive::kPrimShort: |
| 2211 | case Primitive::kPrimInt: |
| 2212 | case Primitive::kPrimChar: { |
| 2213 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2214 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2215 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2216 | out.AsFpuRegisterPairLow<SRegister>()); |
| 2217 | break; |
| 2218 | } |
| 2219 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2220 | case Primitive::kPrimLong: { |
| 2221 | // Processing a Dex `long-to-double' instruction. |
| 2222 | Register low = in.AsRegisterPairLow<Register>(); |
| 2223 | Register high = in.AsRegisterPairHigh<Register>(); |
| 2224 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 2225 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2226 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2227 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2228 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 2229 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2230 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2231 | // temp_d = int-to-double(high) |
| 2232 | __ vmovsr(temp_s, high); |
| 2233 | __ vcvtdi(temp_d, temp_s); |
| 2234 | // constant_d = k2Pow32EncodingForDouble |
| 2235 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 2236 | // out_d = unsigned-to-double(low) |
| 2237 | __ vmovsr(out_s, low); |
| 2238 | __ vcvtdu(out_d, out_s); |
| 2239 | // out_d += temp_d * constant_d |
| 2240 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2241 | break; |
| 2242 | } |
| 2243 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2244 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2245 | // Processing a Dex `float-to-double' instruction. |
| 2246 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2247 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2248 | break; |
| 2249 | |
| 2250 | default: |
| 2251 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2252 | << " to " << result_type; |
| 2253 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2254 | break; |
| 2255 | |
| 2256 | default: |
| 2257 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2258 | << " to " << result_type; |
| 2259 | } |
| 2260 | } |
| 2261 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2262 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2263 | LocationSummary* locations = |
| 2264 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2265 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2266 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2267 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2268 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2269 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2270 | break; |
| 2271 | } |
| 2272 | |
| 2273 | case Primitive::kPrimLong: { |
| 2274 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2275 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2276 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2277 | break; |
| 2278 | } |
| 2279 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2280 | case Primitive::kPrimFloat: |
| 2281 | case Primitive::kPrimDouble: { |
| 2282 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2283 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2284 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2285 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2286 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2287 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2288 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2289 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2290 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2291 | } |
| 2292 | |
| 2293 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 2294 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2295 | Location out = locations->Out(); |
| 2296 | Location first = locations->InAt(0); |
| 2297 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2298 | switch (add->GetResultType()) { |
| 2299 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2300 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2301 | __ add(out.AsRegister<Register>(), |
| 2302 | first.AsRegister<Register>(), |
| 2303 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2304 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2305 | __ AddConstant(out.AsRegister<Register>(), |
| 2306 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2307 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2308 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2309 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2310 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2311 | case Primitive::kPrimLong: { |
| 2312 | DCHECK(second.IsRegisterPair()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2313 | __ adds(out.AsRegisterPairLow<Register>(), |
| 2314 | first.AsRegisterPairLow<Register>(), |
| 2315 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2316 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 2317 | first.AsRegisterPairHigh<Register>(), |
| 2318 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2319 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2320 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2321 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2322 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2323 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 2324 | first.AsFpuRegister<SRegister>(), |
| 2325 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2326 | break; |
| 2327 | |
| 2328 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2329 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2330 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2331 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2332 | break; |
| 2333 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2334 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2335 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2336 | } |
| 2337 | } |
| 2338 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2339 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2340 | LocationSummary* locations = |
| 2341 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2342 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2343 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2344 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2345 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2346 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2347 | break; |
| 2348 | } |
| 2349 | |
| 2350 | case Primitive::kPrimLong: { |
| 2351 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2352 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2353 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2354 | break; |
| 2355 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2356 | case Primitive::kPrimFloat: |
| 2357 | case Primitive::kPrimDouble: { |
| 2358 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2359 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2360 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2361 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2362 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2363 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2364 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2365 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2366 | } |
| 2367 | |
| 2368 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 2369 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2370 | Location out = locations->Out(); |
| 2371 | Location first = locations->InAt(0); |
| 2372 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2373 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2374 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2375 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2376 | __ sub(out.AsRegister<Register>(), |
| 2377 | first.AsRegister<Register>(), |
| 2378 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2379 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2380 | __ AddConstant(out.AsRegister<Register>(), |
| 2381 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2382 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2383 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2384 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2385 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2386 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2387 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2388 | DCHECK(second.IsRegisterPair()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2389 | __ subs(out.AsRegisterPairLow<Register>(), |
| 2390 | first.AsRegisterPairLow<Register>(), |
| 2391 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2392 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2393 | first.AsRegisterPairHigh<Register>(), |
| 2394 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2395 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2396 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2397 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2398 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2399 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 2400 | first.AsFpuRegister<SRegister>(), |
| 2401 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2402 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2403 | } |
| 2404 | |
| 2405 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2406 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2407 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2408 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2409 | break; |
| 2410 | } |
| 2411 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2412 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2413 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2414 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2415 | } |
| 2416 | } |
| 2417 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2418 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 2419 | LocationSummary* locations = |
| 2420 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2421 | switch (mul->GetResultType()) { |
| 2422 | case Primitive::kPrimInt: |
| 2423 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2424 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2425 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2426 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2427 | break; |
| 2428 | } |
| 2429 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2430 | case Primitive::kPrimFloat: |
| 2431 | case Primitive::kPrimDouble: { |
| 2432 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2433 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2434 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2435 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2436 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2437 | |
| 2438 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2439 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2440 | } |
| 2441 | } |
| 2442 | |
| 2443 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 2444 | LocationSummary* locations = mul->GetLocations(); |
| 2445 | Location out = locations->Out(); |
| 2446 | Location first = locations->InAt(0); |
| 2447 | Location second = locations->InAt(1); |
| 2448 | switch (mul->GetResultType()) { |
| 2449 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2450 | __ mul(out.AsRegister<Register>(), |
| 2451 | first.AsRegister<Register>(), |
| 2452 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2453 | break; |
| 2454 | } |
| 2455 | case Primitive::kPrimLong: { |
| 2456 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 2457 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 2458 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2459 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 2460 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2461 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2462 | |
| 2463 | // Extra checks to protect caused by the existence of R1_R2. |
| 2464 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 2465 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 2466 | DCHECK_NE(out_hi, in1_lo); |
| 2467 | DCHECK_NE(out_hi, in2_lo); |
| 2468 | |
| 2469 | // input: in1 - 64 bits, in2 - 64 bits |
| 2470 | // output: out |
| 2471 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2472 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2473 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 2474 | |
| 2475 | // IP <- in1.lo * in2.hi |
| 2476 | __ mul(IP, in1_lo, in2_hi); |
| 2477 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2478 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 2479 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 2480 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 2481 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2482 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 2483 | break; |
| 2484 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2485 | |
| 2486 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2487 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 2488 | first.AsFpuRegister<SRegister>(), |
| 2489 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2490 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2491 | } |
| 2492 | |
| 2493 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2494 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2495 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2496 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2497 | break; |
| 2498 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2499 | |
| 2500 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2501 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2502 | } |
| 2503 | } |
| 2504 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2505 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2506 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2507 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2508 | |
| 2509 | LocationSummary* locations = instruction->GetLocations(); |
| 2510 | Location second = locations->InAt(1); |
| 2511 | DCHECK(second.IsConstant()); |
| 2512 | |
| 2513 | Register out = locations->Out().AsRegister<Register>(); |
| 2514 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2515 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2516 | DCHECK(imm == 1 || imm == -1); |
| 2517 | |
| 2518 | if (instruction->IsRem()) { |
| 2519 | __ LoadImmediate(out, 0); |
| 2520 | } else { |
| 2521 | if (imm == 1) { |
| 2522 | __ Mov(out, dividend); |
| 2523 | } else { |
| 2524 | __ rsb(out, dividend, ShifterOperand(0)); |
| 2525 | } |
| 2526 | } |
| 2527 | } |
| 2528 | |
| 2529 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2530 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2531 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2532 | |
| 2533 | LocationSummary* locations = instruction->GetLocations(); |
| 2534 | Location second = locations->InAt(1); |
| 2535 | DCHECK(second.IsConstant()); |
| 2536 | |
| 2537 | Register out = locations->Out().AsRegister<Register>(); |
| 2538 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2539 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2540 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 2541 | uint32_t abs_imm = static_cast<uint32_t>(std::abs(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2542 | DCHECK(IsPowerOfTwo(abs_imm)); |
| 2543 | int ctz_imm = CTZ(abs_imm); |
| 2544 | |
| 2545 | if (ctz_imm == 1) { |
| 2546 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 2547 | } else { |
| 2548 | __ Asr(temp, dividend, 31); |
| 2549 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 2550 | } |
| 2551 | __ add(out, temp, ShifterOperand(dividend)); |
| 2552 | |
| 2553 | if (instruction->IsDiv()) { |
| 2554 | __ Asr(out, out, ctz_imm); |
| 2555 | if (imm < 0) { |
| 2556 | __ rsb(out, out, ShifterOperand(0)); |
| 2557 | } |
| 2558 | } else { |
| 2559 | __ ubfx(out, out, 0, ctz_imm); |
| 2560 | __ sub(out, out, ShifterOperand(temp)); |
| 2561 | } |
| 2562 | } |
| 2563 | |
| 2564 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2565 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2566 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2567 | |
| 2568 | LocationSummary* locations = instruction->GetLocations(); |
| 2569 | Location second = locations->InAt(1); |
| 2570 | DCHECK(second.IsConstant()); |
| 2571 | |
| 2572 | Register out = locations->Out().AsRegister<Register>(); |
| 2573 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2574 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 2575 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 2576 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2577 | |
| 2578 | int64_t magic; |
| 2579 | int shift; |
| 2580 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2581 | |
| 2582 | __ LoadImmediate(temp1, magic); |
| 2583 | __ smull(temp2, temp1, dividend, temp1); |
| 2584 | |
| 2585 | if (imm > 0 && magic < 0) { |
| 2586 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 2587 | } else if (imm < 0 && magic > 0) { |
| 2588 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 2589 | } |
| 2590 | |
| 2591 | if (shift != 0) { |
| 2592 | __ Asr(temp1, temp1, shift); |
| 2593 | } |
| 2594 | |
| 2595 | if (instruction->IsDiv()) { |
| 2596 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 2597 | } else { |
| 2598 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 2599 | // TODO: Strength reduction for mls. |
| 2600 | __ LoadImmediate(temp2, imm); |
| 2601 | __ mls(out, temp1, temp2, dividend); |
| 2602 | } |
| 2603 | } |
| 2604 | |
| 2605 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 2606 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2607 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2608 | |
| 2609 | LocationSummary* locations = instruction->GetLocations(); |
| 2610 | Location second = locations->InAt(1); |
| 2611 | DCHECK(second.IsConstant()); |
| 2612 | |
| 2613 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2614 | if (imm == 0) { |
| 2615 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2616 | } else if (imm == 1 || imm == -1) { |
| 2617 | DivRemOneOrMinusOne(instruction); |
| 2618 | } else if (IsPowerOfTwo(std::abs(imm))) { |
| 2619 | DivRemByPowerOfTwo(instruction); |
| 2620 | } else { |
| 2621 | DCHECK(imm <= -2 || imm >= 2); |
| 2622 | GenerateDivRemWithAnyConstant(instruction); |
| 2623 | } |
| 2624 | } |
| 2625 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2626 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2627 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 2628 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 2629 | // pLdiv runtime call. |
| 2630 | call_kind = LocationSummary::kCall; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2631 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 2632 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2633 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 2634 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 2635 | // pIdivmod runtime call. |
| 2636 | call_kind = LocationSummary::kCall; |
| 2637 | } |
| 2638 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2639 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2640 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2641 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2642 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2643 | if (div->InputAt(1)->IsConstant()) { |
| 2644 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2645 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
| 2646 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2647 | int32_t abs_imm = std::abs(div->InputAt(1)->AsIntConstant()->GetValue()); |
| 2648 | if (abs_imm <= 1) { |
| 2649 | // No temp register required. |
| 2650 | } else { |
| 2651 | locations->AddTemp(Location::RequiresRegister()); |
| 2652 | if (!IsPowerOfTwo(abs_imm)) { |
| 2653 | locations->AddTemp(Location::RequiresRegister()); |
| 2654 | } |
| 2655 | } |
| 2656 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2657 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2658 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2659 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2660 | } else { |
| 2661 | InvokeRuntimeCallingConvention calling_convention; |
| 2662 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2663 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2664 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 2665 | // we only need the former. |
| 2666 | locations->SetOut(Location::RegisterLocation(R0)); |
| 2667 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2668 | break; |
| 2669 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2670 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2671 | InvokeRuntimeCallingConvention calling_convention; |
| 2672 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2673 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2674 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2675 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2676 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2677 | break; |
| 2678 | } |
| 2679 | case Primitive::kPrimFloat: |
| 2680 | case Primitive::kPrimDouble: { |
| 2681 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2682 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2683 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2684 | break; |
| 2685 | } |
| 2686 | |
| 2687 | default: |
| 2688 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2689 | } |
| 2690 | } |
| 2691 | |
| 2692 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 2693 | LocationSummary* locations = div->GetLocations(); |
| 2694 | Location out = locations->Out(); |
| 2695 | Location first = locations->InAt(0); |
| 2696 | Location second = locations->InAt(1); |
| 2697 | |
| 2698 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2699 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2700 | if (second.IsConstant()) { |
| 2701 | GenerateDivRemConstantIntegral(div); |
| 2702 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2703 | __ sdiv(out.AsRegister<Register>(), |
| 2704 | first.AsRegister<Register>(), |
| 2705 | second.AsRegister<Register>()); |
| 2706 | } else { |
| 2707 | InvokeRuntimeCallingConvention calling_convention; |
| 2708 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 2709 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 2710 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 2711 | |
| 2712 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr); |
| 2713 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2714 | break; |
| 2715 | } |
| 2716 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2717 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2718 | InvokeRuntimeCallingConvention calling_convention; |
| 2719 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2720 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 2721 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 2722 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 2723 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2724 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2725 | |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2726 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2727 | break; |
| 2728 | } |
| 2729 | |
| 2730 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2731 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 2732 | first.AsFpuRegister<SRegister>(), |
| 2733 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2734 | break; |
| 2735 | } |
| 2736 | |
| 2737 | case Primitive::kPrimDouble: { |
| 2738 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2739 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2740 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 2741 | break; |
| 2742 | } |
| 2743 | |
| 2744 | default: |
| 2745 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2746 | } |
| 2747 | } |
| 2748 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2749 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2750 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2751 | |
| 2752 | // Most remainders are implemented in the runtime. |
| 2753 | LocationSummary::CallKind call_kind = LocationSummary::kCall; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2754 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 2755 | // sdiv will be replaced by other instruction sequence. |
| 2756 | call_kind = LocationSummary::kNoCall; |
| 2757 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 2758 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2759 | // Have hardware divide instruction for int, do it with three instructions. |
| 2760 | call_kind = LocationSummary::kNoCall; |
| 2761 | } |
| 2762 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2763 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 2764 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2765 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2766 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2767 | if (rem->InputAt(1)->IsConstant()) { |
| 2768 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2769 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
| 2770 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2771 | int32_t abs_imm = std::abs(rem->InputAt(1)->AsIntConstant()->GetValue()); |
| 2772 | if (abs_imm <= 1) { |
| 2773 | // No temp register required. |
| 2774 | } else { |
| 2775 | locations->AddTemp(Location::RequiresRegister()); |
| 2776 | if (!IsPowerOfTwo(abs_imm)) { |
| 2777 | locations->AddTemp(Location::RequiresRegister()); |
| 2778 | } |
| 2779 | } |
| 2780 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2781 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2782 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2783 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2784 | locations->AddTemp(Location::RequiresRegister()); |
| 2785 | } else { |
| 2786 | InvokeRuntimeCallingConvention calling_convention; |
| 2787 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2788 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2789 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 2790 | // we only need the latter. |
| 2791 | locations->SetOut(Location::RegisterLocation(R1)); |
| 2792 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2793 | break; |
| 2794 | } |
| 2795 | case Primitive::kPrimLong: { |
| 2796 | InvokeRuntimeCallingConvention calling_convention; |
| 2797 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2798 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2799 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2800 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2801 | // The runtime helper puts the output in R2,R3. |
| 2802 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 2803 | break; |
| 2804 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2805 | case Primitive::kPrimFloat: { |
| 2806 | InvokeRuntimeCallingConvention calling_convention; |
| 2807 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 2808 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 2809 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 2810 | break; |
| 2811 | } |
| 2812 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2813 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2814 | InvokeRuntimeCallingConvention calling_convention; |
| 2815 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 2816 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 2817 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 2818 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 2819 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2820 | break; |
| 2821 | } |
| 2822 | |
| 2823 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2824 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2825 | } |
| 2826 | } |
| 2827 | |
| 2828 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 2829 | LocationSummary* locations = rem->GetLocations(); |
| 2830 | Location out = locations->Out(); |
| 2831 | Location first = locations->InAt(0); |
| 2832 | Location second = locations->InAt(1); |
| 2833 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2834 | Primitive::Type type = rem->GetResultType(); |
| 2835 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2836 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2837 | if (second.IsConstant()) { |
| 2838 | GenerateDivRemConstantIntegral(rem); |
| 2839 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2840 | Register reg1 = first.AsRegister<Register>(); |
| 2841 | Register reg2 = second.AsRegister<Register>(); |
| 2842 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2843 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2844 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 2845 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2846 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 2847 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2848 | } else { |
| 2849 | InvokeRuntimeCallingConvention calling_convention; |
| 2850 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 2851 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 2852 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 2853 | |
| 2854 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr); |
| 2855 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2856 | break; |
| 2857 | } |
| 2858 | |
| 2859 | case Primitive::kPrimLong: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2860 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2861 | break; |
| 2862 | } |
| 2863 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2864 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2865 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2866 | break; |
| 2867 | } |
| 2868 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2869 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2870 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2871 | break; |
| 2872 | } |
| 2873 | |
| 2874 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2875 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2876 | } |
| 2877 | } |
| 2878 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2879 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2880 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 2881 | ? LocationSummary::kCallOnSlowPath |
| 2882 | : LocationSummary::kNoCall; |
| 2883 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2884 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2885 | if (instruction->HasUses()) { |
| 2886 | locations->SetOut(Location::SameAsFirstInput()); |
| 2887 | } |
| 2888 | } |
| 2889 | |
| 2890 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 2891 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2892 | codegen_->AddSlowPath(slow_path); |
| 2893 | |
| 2894 | LocationSummary* locations = instruction->GetLocations(); |
| 2895 | Location value = locations->InAt(0); |
| 2896 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2897 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 2898 | case Primitive::kPrimByte: |
| 2899 | case Primitive::kPrimChar: |
| 2900 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2901 | case Primitive::kPrimInt: { |
| 2902 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 2903 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2904 | } else { |
| 2905 | DCHECK(value.IsConstant()) << value; |
| 2906 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 2907 | __ b(slow_path->GetEntryLabel()); |
| 2908 | } |
| 2909 | } |
| 2910 | break; |
| 2911 | } |
| 2912 | case Primitive::kPrimLong: { |
| 2913 | if (value.IsRegisterPair()) { |
| 2914 | __ orrs(IP, |
| 2915 | value.AsRegisterPairLow<Register>(), |
| 2916 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 2917 | __ b(slow_path->GetEntryLabel(), EQ); |
| 2918 | } else { |
| 2919 | DCHECK(value.IsConstant()) << value; |
| 2920 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 2921 | __ b(slow_path->GetEntryLabel()); |
| 2922 | } |
| 2923 | } |
| 2924 | break; |
| 2925 | default: |
| 2926 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 2927 | } |
| 2928 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2929 | } |
| 2930 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2931 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 2932 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 2933 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2934 | LocationSummary* locations = |
| 2935 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2936 | |
| 2937 | switch (op->GetResultType()) { |
| 2938 | case Primitive::kPrimInt: { |
| 2939 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2940 | locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1))); |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2941 | // Make the output overlap, as it will be used to hold the masked |
| 2942 | // second input. |
| 2943 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2944 | break; |
| 2945 | } |
| 2946 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2947 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2948 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2949 | locations->AddTemp(Location::RequiresRegister()); |
| 2950 | locations->SetOut(Location::RequiresRegister()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2951 | break; |
| 2952 | } |
| 2953 | default: |
| 2954 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 2955 | } |
| 2956 | } |
| 2957 | |
| 2958 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 2959 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 2960 | |
| 2961 | LocationSummary* locations = op->GetLocations(); |
| 2962 | Location out = locations->Out(); |
| 2963 | Location first = locations->InAt(0); |
| 2964 | Location second = locations->InAt(1); |
| 2965 | |
| 2966 | Primitive::Type type = op->GetResultType(); |
| 2967 | switch (type) { |
| 2968 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2969 | Register out_reg = out.AsRegister<Register>(); |
| 2970 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2971 | // Arm doesn't mask the shift count so we need to do it ourselves. |
| 2972 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2973 | Register second_reg = second.AsRegister<Register>(); |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2974 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftValue)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2975 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2976 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2977 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2978 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2979 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2980 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2981 | } |
| 2982 | } else { |
| 2983 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2984 | uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue); |
| 2985 | if (shift_value == 0) { // arm does not support shifting with 0 immediate. |
| 2986 | __ Mov(out_reg, first_reg); |
| 2987 | } else if (op->IsShl()) { |
| 2988 | __ Lsl(out_reg, first_reg, shift_value); |
| 2989 | } else if (op->IsShr()) { |
| 2990 | __ Asr(out_reg, first_reg, shift_value); |
| 2991 | } else { |
| 2992 | __ Lsr(out_reg, first_reg, shift_value); |
| 2993 | } |
| 2994 | } |
| 2995 | break; |
| 2996 | } |
| 2997 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2998 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 2999 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3000 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3001 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3002 | |
| 3003 | Register high = first.AsRegisterPairHigh<Register>(); |
| 3004 | Register low = first.AsRegisterPairLow<Register>(); |
| 3005 | |
| 3006 | Register second_reg = second.AsRegister<Register>(); |
| 3007 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3008 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3009 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftValue)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3010 | // Shift the high part |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3011 | __ Lsl(o_h, high, o_l); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3012 | // Shift the low part and `or` what overflew on the high part |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3013 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3014 | __ Lsr(temp, low, temp); |
| 3015 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 3016 | // If the shift is > 32 bits, override the high part |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3017 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3018 | __ it(PL); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3019 | __ Lsl(o_h, low, temp, PL); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3020 | // Shift the low part |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3021 | __ Lsl(o_l, low, o_l); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3022 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3023 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3024 | // Shift the low part |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3025 | __ Lsr(o_l, low, o_h); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3026 | // Shift the high part and `or` what underflew on the low part |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3027 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3028 | __ Lsl(temp, high, temp); |
| 3029 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3030 | // If the shift is > 32 bits, override the low part |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3031 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3032 | __ it(PL); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3033 | __ Asr(o_l, high, temp, PL); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3034 | // Shift the high part |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3035 | __ Asr(o_h, high, o_h); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3036 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3037 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3038 | // same as Shr except we use `Lsr`s and not `Asr`s |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3039 | __ Lsr(o_l, low, o_h); |
| 3040 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3041 | __ Lsl(temp, high, temp); |
| 3042 | __ orr(o_l, o_l, ShifterOperand(temp)); |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3043 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3044 | __ it(PL); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3045 | __ Lsr(o_l, high, temp, PL); |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3046 | __ Lsr(o_h, high, o_h); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3047 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3048 | break; |
| 3049 | } |
| 3050 | default: |
| 3051 | LOG(FATAL) << "Unexpected operation type " << type; |
| 3052 | } |
| 3053 | } |
| 3054 | |
| 3055 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 3056 | HandleShift(shl); |
| 3057 | } |
| 3058 | |
| 3059 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 3060 | HandleShift(shl); |
| 3061 | } |
| 3062 | |
| 3063 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 3064 | HandleShift(shr); |
| 3065 | } |
| 3066 | |
| 3067 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 3068 | HandleShift(shr); |
| 3069 | } |
| 3070 | |
| 3071 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 3072 | HandleShift(ushr); |
| 3073 | } |
| 3074 | |
| 3075 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 3076 | HandleShift(ushr); |
| 3077 | } |
| 3078 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3079 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3080 | LocationSummary* locations = |
| 3081 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3082 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3083 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3084 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3085 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3086 | } |
| 3087 | |
| 3088 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
| 3089 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3090 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3091 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3092 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3093 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3094 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3095 | instruction->GetDexPc(), |
| 3096 | nullptr); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3097 | } |
| 3098 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3099 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 3100 | LocationSummary* locations = |
| 3101 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3102 | InvokeRuntimeCallingConvention calling_convention; |
| 3103 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3104 | locations->SetOut(Location::RegisterLocation(R0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3105 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3106 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3107 | } |
| 3108 | |
| 3109 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
| 3110 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3111 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3112 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3113 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3114 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3115 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3116 | instruction->GetDexPc(), |
| 3117 | nullptr); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3118 | } |
| 3119 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3120 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3121 | LocationSummary* locations = |
| 3122 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3123 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3124 | if (location.IsStackSlot()) { |
| 3125 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3126 | } else if (location.IsDoubleStackSlot()) { |
| 3127 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3128 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3129 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3130 | } |
| 3131 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3132 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 3133 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3134 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3135 | } |
| 3136 | |
| 3137 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3138 | LocationSummary* locations = |
| 3139 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3140 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3141 | } |
| 3142 | |
| 3143 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3144 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3145 | } |
| 3146 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3147 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3148 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3149 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3150 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3151 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3152 | } |
| 3153 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3154 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 3155 | LocationSummary* locations = not_->GetLocations(); |
| 3156 | Location out = locations->Out(); |
| 3157 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3158 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3159 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3160 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3161 | break; |
| 3162 | |
| 3163 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3164 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 3165 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 3166 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 3167 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3168 | break; |
| 3169 | |
| 3170 | default: |
| 3171 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3172 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3173 | } |
| 3174 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3175 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3176 | LocationSummary* locations = |
| 3177 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3178 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3179 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3180 | } |
| 3181 | |
| 3182 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3183 | LocationSummary* locations = bool_not->GetLocations(); |
| 3184 | Location out = locations->Out(); |
| 3185 | Location in = locations->InAt(0); |
| 3186 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 3187 | } |
| 3188 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3189 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3190 | LocationSummary* locations = |
| 3191 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3192 | switch (compare->InputAt(0)->GetType()) { |
| 3193 | case Primitive::kPrimLong: { |
| 3194 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3195 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3196 | // Output overlaps because it is written before doing the low comparison. |
| 3197 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3198 | break; |
| 3199 | } |
| 3200 | case Primitive::kPrimFloat: |
| 3201 | case Primitive::kPrimDouble: { |
| 3202 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3203 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3204 | locations->SetOut(Location::RequiresRegister()); |
| 3205 | break; |
| 3206 | } |
| 3207 | default: |
| 3208 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 3209 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3210 | } |
| 3211 | |
| 3212 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3213 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3214 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3215 | Location left = locations->InAt(0); |
| 3216 | Location right = locations->InAt(1); |
| 3217 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3218 | Label less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3219 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 3220 | switch (type) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3221 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3222 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 3223 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3224 | __ b(&less, LT); |
| 3225 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3226 | // 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] | 3227 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3228 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 3229 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3230 | break; |
| 3231 | } |
| 3232 | case Primitive::kPrimFloat: |
| 3233 | case Primitive::kPrimDouble: { |
| 3234 | __ LoadImmediate(out, 0); |
| 3235 | if (type == Primitive::kPrimFloat) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3236 | __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3237 | } else { |
| 3238 | __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), |
| 3239 | FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); |
| 3240 | } |
| 3241 | __ vmstat(); // transfer FP status register to ARM APSR. |
| 3242 | __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3243 | break; |
| 3244 | } |
| 3245 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3246 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3247 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3248 | __ b(&done, EQ); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3249 | __ 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] | 3250 | |
| 3251 | __ Bind(&greater); |
| 3252 | __ LoadImmediate(out, 1); |
| 3253 | __ b(&done); |
| 3254 | |
| 3255 | __ Bind(&less); |
| 3256 | __ LoadImmediate(out, -1); |
| 3257 | |
| 3258 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3259 | } |
| 3260 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3261 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3262 | LocationSummary* locations = |
| 3263 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 3264 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3265 | locations->SetInAt(i, Location::Any()); |
| 3266 | } |
| 3267 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3268 | } |
| 3269 | |
| 3270 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3271 | UNUSED(instruction); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3272 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3273 | } |
| 3274 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3275 | void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3276 | // TODO (ported from quick): revisit Arm barrier kinds |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3277 | DmbOptions flavor = DmbOptions::ISH; // quiet c++ warnings |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3278 | switch (kind) { |
| 3279 | case MemBarrierKind::kAnyStore: |
| 3280 | case MemBarrierKind::kLoadAny: |
| 3281 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3282 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3283 | break; |
| 3284 | } |
| 3285 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3286 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3287 | break; |
| 3288 | } |
| 3289 | default: |
| 3290 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 3291 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3292 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3293 | } |
| 3294 | |
| 3295 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 3296 | uint32_t offset, |
| 3297 | Register out_lo, |
| 3298 | Register out_hi) { |
| 3299 | if (offset != 0) { |
| 3300 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3301 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 3302 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3303 | } |
| 3304 | __ ldrexd(out_lo, out_hi, addr); |
| 3305 | } |
| 3306 | |
| 3307 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 3308 | uint32_t offset, |
| 3309 | Register value_lo, |
| 3310 | Register value_hi, |
| 3311 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3312 | Register temp2, |
| 3313 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3314 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3315 | if (offset != 0) { |
| 3316 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3317 | __ add(IP, addr, ShifterOperand(temp1)); |
| 3318 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3319 | } |
| 3320 | __ Bind(&fail); |
| 3321 | // We need a load followed by store. (The address used in a STREX instruction must |
| 3322 | // be the same as the address in the most recently executed LDREX instruction.) |
| 3323 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3324 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3325 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3326 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3327 | } |
| 3328 | |
| 3329 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3330 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3331 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3332 | LocationSummary* locations = |
| 3333 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3334 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3335 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3336 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3337 | if (Primitive::IsFloatingPointType(field_type)) { |
| 3338 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3339 | } else { |
| 3340 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3341 | } |
| 3342 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3343 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3344 | bool generate_volatile = field_info.IsVolatile() |
| 3345 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3346 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3347 | bool needs_write_barrier = |
| 3348 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3349 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3350 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3351 | if (needs_write_barrier) { |
| 3352 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3353 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3354 | } else if (generate_volatile) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3355 | // Arm encoding have some additional constraints for ldrexd/strexd: |
| 3356 | // - registers need to be consecutive |
| 3357 | // - the first register should be even but not R14. |
| 3358 | // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever |
| 3359 | // enable Arm encoding. |
| 3360 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 3361 | |
| 3362 | locations->AddTemp(Location::RequiresRegister()); |
| 3363 | locations->AddTemp(Location::RequiresRegister()); |
| 3364 | if (field_type == Primitive::kPrimDouble) { |
| 3365 | // For doubles we need two more registers to copy the value. |
| 3366 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 3367 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 3368 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3369 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3370 | } |
| 3371 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3372 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3373 | const FieldInfo& field_info, |
| 3374 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3375 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3376 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3377 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3378 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3379 | Location value = locations->InAt(1); |
| 3380 | |
| 3381 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3382 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3383 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3384 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3385 | bool needs_write_barrier = |
| 3386 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3387 | |
| 3388 | if (is_volatile) { |
| 3389 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 3390 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3391 | |
| 3392 | switch (field_type) { |
| 3393 | case Primitive::kPrimBoolean: |
| 3394 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3395 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3396 | break; |
| 3397 | } |
| 3398 | |
| 3399 | case Primitive::kPrimShort: |
| 3400 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3401 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3402 | break; |
| 3403 | } |
| 3404 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3405 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3406 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3407 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 3408 | // Note that in the case where `value` is a null reference, |
| 3409 | // we do not enter this block, as a null reference does not |
| 3410 | // need poisoning. |
| 3411 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 3412 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3413 | __ Mov(temp, value.AsRegister<Register>()); |
| 3414 | __ PoisonHeapReference(temp); |
| 3415 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 3416 | } else { |
| 3417 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 3418 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3419 | break; |
| 3420 | } |
| 3421 | |
| 3422 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3423 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3424 | GenerateWideAtomicStore(base, offset, |
| 3425 | value.AsRegisterPairLow<Register>(), |
| 3426 | value.AsRegisterPairHigh<Register>(), |
| 3427 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3428 | locations->GetTemp(1).AsRegister<Register>(), |
| 3429 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3430 | } else { |
| 3431 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3432 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3433 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3434 | break; |
| 3435 | } |
| 3436 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3437 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3438 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3439 | break; |
| 3440 | } |
| 3441 | |
| 3442 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3443 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3444 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3445 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 3446 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 3447 | |
| 3448 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 3449 | |
| 3450 | GenerateWideAtomicStore(base, offset, |
| 3451 | value_reg_lo, |
| 3452 | value_reg_hi, |
| 3453 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3454 | locations->GetTemp(3).AsRegister<Register>(), |
| 3455 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3456 | } else { |
| 3457 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3458 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3459 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3460 | break; |
| 3461 | } |
| 3462 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3463 | case Primitive::kPrimVoid: |
| 3464 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3465 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3466 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3467 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3468 | // Longs and doubles are handled in the switch. |
| 3469 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 3470 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3471 | } |
| 3472 | |
| 3473 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 3474 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3475 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3476 | codegen_->MarkGCCard( |
| 3477 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3478 | } |
| 3479 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3480 | if (is_volatile) { |
| 3481 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 3482 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3483 | } |
| 3484 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3485 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3486 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3487 | LocationSummary* locations = |
| 3488 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3489 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3490 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3491 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3492 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3493 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3494 | bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong); |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 3495 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3496 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3497 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3498 | } else { |
| 3499 | locations->SetOut(Location::RequiresRegister(), |
| 3500 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 3501 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3502 | if (volatile_for_double) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3503 | // Arm encoding have some additional constraints for ldrexd/strexd: |
| 3504 | // - registers need to be consecutive |
| 3505 | // - the first register should be even but not R14. |
| 3506 | // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever |
| 3507 | // enable Arm encoding. |
| 3508 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 3509 | locations->AddTemp(Location::RequiresRegister()); |
| 3510 | locations->AddTemp(Location::RequiresRegister()); |
| 3511 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3512 | } |
| 3513 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3514 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 3515 | const FieldInfo& field_info) { |
| 3516 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3517 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3518 | LocationSummary* locations = instruction->GetLocations(); |
| 3519 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3520 | Location out = locations->Out(); |
| 3521 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3522 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3523 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3524 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3525 | |
| 3526 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3527 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3528 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3529 | break; |
| 3530 | } |
| 3531 | |
| 3532 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3533 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3534 | break; |
| 3535 | } |
| 3536 | |
| 3537 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3538 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3539 | break; |
| 3540 | } |
| 3541 | |
| 3542 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3543 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3544 | break; |
| 3545 | } |
| 3546 | |
| 3547 | case Primitive::kPrimInt: |
| 3548 | case Primitive::kPrimNot: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3549 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3550 | break; |
| 3551 | } |
| 3552 | |
| 3553 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3554 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3555 | GenerateWideAtomicLoad(base, offset, |
| 3556 | out.AsRegisterPairLow<Register>(), |
| 3557 | out.AsRegisterPairHigh<Register>()); |
| 3558 | } else { |
| 3559 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 3560 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3561 | break; |
| 3562 | } |
| 3563 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3564 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3565 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3566 | break; |
| 3567 | } |
| 3568 | |
| 3569 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3570 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3571 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3572 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 3573 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 3574 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3575 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3576 | __ vmovdrr(out_reg, lo, hi); |
| 3577 | } else { |
| 3578 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3579 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3580 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3581 | break; |
| 3582 | } |
| 3583 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3584 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3585 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3586 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3587 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3588 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3589 | // Doubles are handled in the switch. |
| 3590 | if (field_type != Primitive::kPrimDouble) { |
| 3591 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3592 | } |
| 3593 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3594 | if (is_volatile) { |
| 3595 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 3596 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3597 | |
| 3598 | if (field_type == Primitive::kPrimNot) { |
| 3599 | __ MaybeUnpoisonHeapReference(out.AsRegister<Register>()); |
| 3600 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3601 | } |
| 3602 | |
| 3603 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 3604 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3605 | } |
| 3606 | |
| 3607 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3608 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3609 | } |
| 3610 | |
| 3611 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 3612 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3613 | } |
| 3614 | |
| 3615 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 3616 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3617 | } |
| 3618 | |
| 3619 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3620 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3621 | } |
| 3622 | |
| 3623 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3624 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3625 | } |
| 3626 | |
| 3627 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3628 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3629 | } |
| 3630 | |
| 3631 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3632 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3633 | } |
| 3634 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 3635 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 3636 | HUnresolvedInstanceFieldGet* instruction) { |
| 3637 | FieldAccessCallingConventionARM calling_convention; |
| 3638 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3639 | instruction, instruction->GetFieldType(), calling_convention); |
| 3640 | } |
| 3641 | |
| 3642 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 3643 | HUnresolvedInstanceFieldGet* instruction) { |
| 3644 | FieldAccessCallingConventionARM calling_convention; |
| 3645 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3646 | instruction->GetFieldType(), |
| 3647 | instruction->GetFieldIndex(), |
| 3648 | instruction->GetDexPc(), |
| 3649 | calling_convention); |
| 3650 | } |
| 3651 | |
| 3652 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 3653 | HUnresolvedInstanceFieldSet* instruction) { |
| 3654 | FieldAccessCallingConventionARM calling_convention; |
| 3655 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3656 | instruction, instruction->GetFieldType(), calling_convention); |
| 3657 | } |
| 3658 | |
| 3659 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 3660 | HUnresolvedInstanceFieldSet* instruction) { |
| 3661 | FieldAccessCallingConventionARM calling_convention; |
| 3662 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3663 | instruction->GetFieldType(), |
| 3664 | instruction->GetFieldIndex(), |
| 3665 | instruction->GetDexPc(), |
| 3666 | calling_convention); |
| 3667 | } |
| 3668 | |
| 3669 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 3670 | HUnresolvedStaticFieldGet* instruction) { |
| 3671 | FieldAccessCallingConventionARM calling_convention; |
| 3672 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3673 | instruction, instruction->GetFieldType(), calling_convention); |
| 3674 | } |
| 3675 | |
| 3676 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 3677 | HUnresolvedStaticFieldGet* instruction) { |
| 3678 | FieldAccessCallingConventionARM calling_convention; |
| 3679 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3680 | instruction->GetFieldType(), |
| 3681 | instruction->GetFieldIndex(), |
| 3682 | instruction->GetDexPc(), |
| 3683 | calling_convention); |
| 3684 | } |
| 3685 | |
| 3686 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 3687 | HUnresolvedStaticFieldSet* instruction) { |
| 3688 | FieldAccessCallingConventionARM calling_convention; |
| 3689 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3690 | instruction, instruction->GetFieldType(), calling_convention); |
| 3691 | } |
| 3692 | |
| 3693 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 3694 | HUnresolvedStaticFieldSet* instruction) { |
| 3695 | FieldAccessCallingConventionARM calling_convention; |
| 3696 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3697 | instruction->GetFieldType(), |
| 3698 | instruction->GetFieldIndex(), |
| 3699 | instruction->GetDexPc(), |
| 3700 | calling_convention); |
| 3701 | } |
| 3702 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3703 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3704 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3705 | ? LocationSummary::kCallOnSlowPath |
| 3706 | : LocationSummary::kNoCall; |
| 3707 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3708 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3709 | if (instruction->HasUses()) { |
| 3710 | locations->SetOut(Location::SameAsFirstInput()); |
| 3711 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3712 | } |
| 3713 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3714 | void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3715 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 3716 | return; |
| 3717 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3718 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3719 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3720 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
| 3721 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3722 | } |
| 3723 | |
| 3724 | void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3725 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3726 | codegen_->AddSlowPath(slow_path); |
| 3727 | |
| 3728 | LocationSummary* locations = instruction->GetLocations(); |
| 3729 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3730 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3731 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3732 | } |
| 3733 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3734 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3735 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3736 | GenerateImplicitNullCheck(instruction); |
| 3737 | } else { |
| 3738 | GenerateExplicitNullCheck(instruction); |
| 3739 | } |
| 3740 | } |
| 3741 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3742 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3743 | LocationSummary* locations = |
| 3744 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3745 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3746 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3747 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3748 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3749 | } else { |
| 3750 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3751 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3752 | } |
| 3753 | |
| 3754 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 3755 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3756 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3757 | Location index = locations->InAt(1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3758 | Primitive::Type type = instruction->GetType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3759 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3760 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3761 | case Primitive::kPrimBoolean: { |
| 3762 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3763 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3764 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3765 | size_t offset = |
| 3766 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3767 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset); |
| 3768 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3769 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3770 | __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset); |
| 3771 | } |
| 3772 | break; |
| 3773 | } |
| 3774 | |
| 3775 | case Primitive::kPrimByte: { |
| 3776 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3777 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3778 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3779 | size_t offset = |
| 3780 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3781 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset); |
| 3782 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3783 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3784 | __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset); |
| 3785 | } |
| 3786 | break; |
| 3787 | } |
| 3788 | |
| 3789 | case Primitive::kPrimShort: { |
| 3790 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3791 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3792 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3793 | size_t offset = |
| 3794 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3795 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset); |
| 3796 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3797 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3798 | __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset); |
| 3799 | } |
| 3800 | break; |
| 3801 | } |
| 3802 | |
| 3803 | case Primitive::kPrimChar: { |
| 3804 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3805 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3806 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3807 | size_t offset = |
| 3808 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3809 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset); |
| 3810 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3811 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3812 | __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset); |
| 3813 | } |
| 3814 | break; |
| 3815 | } |
| 3816 | |
| 3817 | case Primitive::kPrimInt: |
| 3818 | case Primitive::kPrimNot: { |
Roland Levillain | 33d6903 | 2015-06-18 18:20:59 +0100 | [diff] [blame] | 3819 | static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 3820 | "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3821 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3822 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3823 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3824 | size_t offset = |
| 3825 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3826 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 3827 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3828 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3829 | __ LoadFromOffset(kLoadWord, out, IP, data_offset); |
| 3830 | } |
| 3831 | break; |
| 3832 | } |
| 3833 | |
| 3834 | case Primitive::kPrimLong: { |
| 3835 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3836 | Location out = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3837 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3838 | size_t offset = |
| 3839 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3840 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3841 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3842 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3843 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3844 | } |
| 3845 | break; |
| 3846 | } |
| 3847 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3848 | case Primitive::kPrimFloat: { |
| 3849 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 3850 | Location out = locations->Out(); |
| 3851 | DCHECK(out.IsFpuRegister()); |
| 3852 | if (index.IsConstant()) { |
| 3853 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 3854 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset); |
| 3855 | } else { |
| 3856 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 3857 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset); |
| 3858 | } |
| 3859 | break; |
| 3860 | } |
| 3861 | |
| 3862 | case Primitive::kPrimDouble: { |
| 3863 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 3864 | Location out = locations->Out(); |
| 3865 | DCHECK(out.IsFpuRegisterPair()); |
| 3866 | if (index.IsConstant()) { |
| 3867 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 3868 | __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset); |
| 3869 | } else { |
| 3870 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
| 3871 | __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 3872 | } |
| 3873 | break; |
| 3874 | } |
| 3875 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3876 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3877 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3878 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3879 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3880 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3881 | |
| 3882 | if (type == Primitive::kPrimNot) { |
| 3883 | Register out = locations->Out().AsRegister<Register>(); |
| 3884 | __ MaybeUnpoisonHeapReference(out); |
| 3885 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3886 | } |
| 3887 | |
| 3888 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3889 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3890 | |
| 3891 | bool needs_write_barrier = |
| 3892 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3893 | bool may_need_runtime_call = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3894 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3895 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3896 | instruction, |
| 3897 | may_need_runtime_call ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
| 3898 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3899 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3900 | if (Primitive::IsFloatingPointType(value_type)) { |
| 3901 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3902 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3903 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3904 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3905 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3906 | if (needs_write_barrier) { |
| 3907 | // Temporary registers for the write barrier. |
| 3908 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 3909 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3910 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3911 | } |
| 3912 | |
| 3913 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 3914 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3915 | Register array = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3916 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3917 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3918 | bool may_need_runtime_call = locations->CanCall(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3919 | bool needs_write_barrier = |
| 3920 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3921 | |
| 3922 | switch (value_type) { |
| 3923 | case Primitive::kPrimBoolean: |
| 3924 | case Primitive::kPrimByte: { |
| 3925 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3926 | Register value = locations->InAt(2).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3927 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3928 | size_t offset = |
| 3929 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3930 | __ StoreToOffset(kStoreByte, value, array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3931 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3932 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3933 | __ StoreToOffset(kStoreByte, value, IP, data_offset); |
| 3934 | } |
| 3935 | break; |
| 3936 | } |
| 3937 | |
| 3938 | case Primitive::kPrimShort: |
| 3939 | case Primitive::kPrimChar: { |
| 3940 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3941 | Register value = locations->InAt(2).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [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_2) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3945 | __ StoreToOffset(kStoreHalfword, value, array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3946 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3947 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3948 | __ StoreToOffset(kStoreHalfword, value, IP, data_offset); |
| 3949 | } |
| 3950 | break; |
| 3951 | } |
| 3952 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3953 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3954 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 3955 | Register value = locations->InAt(2).AsRegister<Register>(); |
| 3956 | Register source = value; |
| 3957 | |
| 3958 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 3959 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3960 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3961 | size_t offset = |
| 3962 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3963 | __ StoreToOffset(kStoreWord, source, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3964 | } else { |
| 3965 | DCHECK(index.IsRegister()) << index; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3966 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3967 | __ StoreToOffset(kStoreWord, source, IP, data_offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3968 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3969 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3970 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3971 | |
| 3972 | DCHECK(needs_write_barrier); |
| 3973 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 3974 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 3975 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3976 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3977 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3978 | Label done; |
| 3979 | SlowPathCode* slow_path = nullptr; |
| 3980 | |
| 3981 | if (may_need_runtime_call) { |
| 3982 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 3983 | codegen_->AddSlowPath(slow_path); |
| 3984 | if (instruction->GetValueCanBeNull()) { |
| 3985 | Label non_zero; |
| 3986 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 3987 | if (index.IsConstant()) { |
| 3988 | size_t offset = |
| 3989 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 3990 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 3991 | } else { |
| 3992 | DCHECK(index.IsRegister()) << index; |
| 3993 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 3994 | __ StoreToOffset(kStoreWord, value, IP, data_offset); |
| 3995 | } |
| 3996 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3997 | __ b(&done); |
| 3998 | __ Bind(&non_zero); |
| 3999 | } |
| 4000 | |
| 4001 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 4002 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4003 | __ MaybeUnpoisonHeapReference(temp1); |
| 4004 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 4005 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 4006 | // No need to poison/unpoison, we're comparing two poisoined references. |
| 4007 | __ cmp(temp1, ShifterOperand(temp2)); |
| 4008 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4009 | Label do_put; |
| 4010 | __ b(&do_put, EQ); |
| 4011 | __ MaybeUnpoisonHeapReference(temp1); |
| 4012 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 4013 | // No need to poison/unpoison, we're comparing against null. |
| 4014 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 4015 | __ Bind(&do_put); |
| 4016 | } else { |
| 4017 | __ b(slow_path->GetEntryLabel(), NE); |
| 4018 | } |
| 4019 | } |
| 4020 | |
| 4021 | if (kPoisonHeapReferences) { |
| 4022 | // Note that in the case where `value` is a null reference, |
| 4023 | // we do not enter this block, as a null reference does not |
| 4024 | // need poisoning. |
| 4025 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 4026 | __ Mov(temp1, value); |
| 4027 | __ PoisonHeapReference(temp1); |
| 4028 | source = temp1; |
| 4029 | } |
| 4030 | |
| 4031 | if (index.IsConstant()) { |
| 4032 | size_t offset = |
| 4033 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4034 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 4035 | } else { |
| 4036 | DCHECK(index.IsRegister()) << index; |
| 4037 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4038 | __ StoreToOffset(kStoreWord, source, IP, data_offset); |
| 4039 | } |
| 4040 | |
| 4041 | if (!may_need_runtime_call) { |
| 4042 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4043 | } |
| 4044 | |
| 4045 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 4046 | |
| 4047 | if (done.IsLinked()) { |
| 4048 | __ Bind(&done); |
| 4049 | } |
| 4050 | |
| 4051 | if (slow_path != nullptr) { |
| 4052 | __ Bind(slow_path->GetExitLabel()); |
| 4053 | } |
| 4054 | |
| 4055 | break; |
| 4056 | } |
| 4057 | |
| 4058 | case Primitive::kPrimInt: { |
| 4059 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4060 | Register value = locations->InAt(2).AsRegister<Register>(); |
| 4061 | if (index.IsConstant()) { |
| 4062 | size_t offset = |
| 4063 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4064 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 4065 | } else { |
| 4066 | DCHECK(index.IsRegister()) << index; |
| 4067 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4068 | __ StoreToOffset(kStoreWord, value, IP, data_offset); |
| 4069 | } |
| 4070 | |
| 4071 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4072 | break; |
| 4073 | } |
| 4074 | |
| 4075 | case Primitive::kPrimLong: { |
| 4076 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4077 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4078 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4079 | size_t offset = |
| 4080 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4081 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4082 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4083 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4084 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4085 | } |
| 4086 | break; |
| 4087 | } |
| 4088 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4089 | case Primitive::kPrimFloat: { |
| 4090 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4091 | Location value = locations->InAt(2); |
| 4092 | DCHECK(value.IsFpuRegister()); |
| 4093 | if (index.IsConstant()) { |
| 4094 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4095 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4096 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4097 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4098 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 4099 | } |
| 4100 | break; |
| 4101 | } |
| 4102 | |
| 4103 | case Primitive::kPrimDouble: { |
| 4104 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4105 | Location value = locations->InAt(2); |
| 4106 | DCHECK(value.IsFpuRegisterPair()); |
| 4107 | if (index.IsConstant()) { |
| 4108 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4109 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4110 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4111 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4112 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 4113 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4114 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4115 | break; |
| 4116 | } |
| 4117 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4118 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4119 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4120 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4121 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4122 | |
| 4123 | // Ints and objects are handled in the switch. |
| 4124 | if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) { |
| 4125 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4126 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4127 | } |
| 4128 | |
| 4129 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4130 | LocationSummary* locations = |
| 4131 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4132 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4133 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4134 | } |
| 4135 | |
| 4136 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 4137 | LocationSummary* locations = instruction->GetLocations(); |
| 4138 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4139 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4140 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4141 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4142 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4143 | } |
| 4144 | |
| 4145 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4146 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4147 | ? LocationSummary::kCallOnSlowPath |
| 4148 | : LocationSummary::kNoCall; |
| 4149 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4150 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4151 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4152 | if (instruction->HasUses()) { |
| 4153 | locations->SetOut(Location::SameAsFirstInput()); |
| 4154 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4155 | } |
| 4156 | |
| 4157 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4158 | LocationSummary* locations = instruction->GetLocations(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4159 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4160 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4161 | codegen_->AddSlowPath(slow_path); |
| 4162 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4163 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 4164 | Register length = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4165 | |
| 4166 | __ cmp(index, ShifterOperand(length)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 4167 | __ b(slow_path->GetEntryLabel(), HS); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4168 | } |
| 4169 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4170 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 4171 | Register card, |
| 4172 | Register object, |
| 4173 | Register value, |
| 4174 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4175 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4176 | if (can_be_null) { |
| 4177 | __ CompareAndBranchIfZero(value, &is_null); |
| 4178 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4179 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value()); |
| 4180 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 4181 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4182 | if (can_be_null) { |
| 4183 | __ Bind(&is_null); |
| 4184 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4185 | } |
| 4186 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4187 | void LocationsBuilderARM::VisitTemporary(HTemporary* temp) { |
| 4188 | temp->SetLocations(nullptr); |
| 4189 | } |
| 4190 | |
| 4191 | void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) { |
| 4192 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4193 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4194 | } |
| 4195 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4196 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4197 | UNUSED(instruction); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4198 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4199 | } |
| 4200 | |
| 4201 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4202 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4203 | } |
| 4204 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4205 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4206 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4207 | } |
| 4208 | |
| 4209 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4210 | HBasicBlock* block = instruction->GetBlock(); |
| 4211 | if (block->GetLoopInformation() != nullptr) { |
| 4212 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4213 | // The back edge will generate the suspend check. |
| 4214 | return; |
| 4215 | } |
| 4216 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4217 | // The goto will generate the suspend check. |
| 4218 | return; |
| 4219 | } |
| 4220 | GenerateSuspendCheck(instruction, nullptr); |
| 4221 | } |
| 4222 | |
| 4223 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4224 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4225 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4226 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 4227 | if (slow_path == nullptr) { |
| 4228 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 4229 | instruction->SetSlowPath(slow_path); |
| 4230 | codegen_->AddSlowPath(slow_path); |
| 4231 | if (successor != nullptr) { |
| 4232 | DCHECK(successor->IsLoopHeader()); |
| 4233 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4234 | } |
| 4235 | } else { |
| 4236 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4237 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4238 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 4239 | __ LoadFromOffset( |
| 4240 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4241 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4242 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4243 | __ Bind(slow_path->GetReturnLabel()); |
| 4244 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4245 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4246 | __ b(slow_path->GetEntryLabel()); |
| 4247 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4248 | } |
| 4249 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4250 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 4251 | return codegen_->GetAssembler(); |
| 4252 | } |
| 4253 | |
| 4254 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 4255 | DCHECK_LT(index, moves_.size()); |
| 4256 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4257 | Location source = move->GetSource(); |
| 4258 | Location destination = move->GetDestination(); |
| 4259 | |
| 4260 | if (source.IsRegister()) { |
| 4261 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4262 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4263 | } else { |
| 4264 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4265 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4266 | SP, destination.GetStackIndex()); |
| 4267 | } |
| 4268 | } else if (source.IsStackSlot()) { |
| 4269 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4270 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4271 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4272 | } else if (destination.IsFpuRegister()) { |
| 4273 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4274 | } else { |
| 4275 | DCHECK(destination.IsStackSlot()); |
| 4276 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 4277 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4278 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4279 | } else if (source.IsFpuRegister()) { |
| 4280 | if (destination.IsFpuRegister()) { |
| 4281 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4282 | } else { |
| 4283 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4284 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 4285 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4286 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4287 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4288 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 4289 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4290 | } else if (destination.IsRegisterPair()) { |
| 4291 | DCHECK(ExpectedPairLayout(destination)); |
| 4292 | __ LoadFromOffset( |
| 4293 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 4294 | } else { |
| 4295 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 4296 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 4297 | SP, |
| 4298 | source.GetStackIndex()); |
| 4299 | } |
| 4300 | } else if (source.IsRegisterPair()) { |
| 4301 | if (destination.IsRegisterPair()) { |
| 4302 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 4303 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 4304 | } else { |
| 4305 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4306 | DCHECK(ExpectedPairLayout(source)); |
| 4307 | __ StoreToOffset( |
| 4308 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 4309 | } |
| 4310 | } else if (source.IsFpuRegisterPair()) { |
| 4311 | if (destination.IsFpuRegisterPair()) { |
| 4312 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 4313 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 4314 | } else { |
| 4315 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4316 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 4317 | SP, |
| 4318 | destination.GetStackIndex()); |
| 4319 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4320 | } else { |
| 4321 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4322 | HConstant* constant = source.GetConstant(); |
| 4323 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 4324 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4325 | if (destination.IsRegister()) { |
| 4326 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 4327 | } else { |
| 4328 | DCHECK(destination.IsStackSlot()); |
| 4329 | __ LoadImmediate(IP, value); |
| 4330 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4331 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4332 | } else if (constant->IsLongConstant()) { |
| 4333 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4334 | if (destination.IsRegisterPair()) { |
| 4335 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 4336 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4337 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4338 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4339 | __ LoadImmediate(IP, Low32Bits(value)); |
| 4340 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4341 | __ LoadImmediate(IP, High32Bits(value)); |
| 4342 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 4343 | } |
| 4344 | } else if (constant->IsDoubleConstant()) { |
| 4345 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4346 | if (destination.IsFpuRegisterPair()) { |
| 4347 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4348 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4349 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4350 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4351 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 4352 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4353 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 4354 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 4355 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4356 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4357 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4358 | float value = constant->AsFloatConstant()->GetValue(); |
| 4359 | if (destination.IsFpuRegister()) { |
| 4360 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 4361 | } else { |
| 4362 | DCHECK(destination.IsStackSlot()); |
| 4363 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 4364 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4365 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4366 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4367 | } |
| 4368 | } |
| 4369 | |
| 4370 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 4371 | __ Mov(IP, reg); |
| 4372 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 4373 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 4374 | } |
| 4375 | |
| 4376 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 4377 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 4378 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 4379 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 4380 | SP, mem1 + stack_offset); |
| 4381 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 4382 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 4383 | SP, mem2 + stack_offset); |
| 4384 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 4385 | } |
| 4386 | |
| 4387 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 4388 | DCHECK_LT(index, moves_.size()); |
| 4389 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4390 | Location source = move->GetSource(); |
| 4391 | Location destination = move->GetDestination(); |
| 4392 | |
| 4393 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4394 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 4395 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 4396 | __ Mov(IP, source.AsRegister<Register>()); |
| 4397 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 4398 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4399 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4400 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4401 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4402 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4403 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 4404 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4405 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 4406 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4407 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 4408 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4409 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4410 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4411 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4412 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4413 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 4414 | destination.AsRegisterPairHigh<Register>(), |
| 4415 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4416 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4417 | Register low_reg = source.IsRegisterPair() |
| 4418 | ? source.AsRegisterPairLow<Register>() |
| 4419 | : destination.AsRegisterPairLow<Register>(); |
| 4420 | int mem = source.IsRegisterPair() |
| 4421 | ? destination.GetStackIndex() |
| 4422 | : source.GetStackIndex(); |
| 4423 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4424 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4425 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4426 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4427 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4428 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 4429 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4430 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4431 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4432 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4433 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 4434 | DRegister reg = source.IsFpuRegisterPair() |
| 4435 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 4436 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 4437 | int mem = source.IsFpuRegisterPair() |
| 4438 | ? destination.GetStackIndex() |
| 4439 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4440 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4441 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4442 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4443 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 4444 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 4445 | : destination.AsFpuRegister<SRegister>(); |
| 4446 | int mem = source.IsFpuRegister() |
| 4447 | ? destination.GetStackIndex() |
| 4448 | : source.GetStackIndex(); |
| 4449 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 4450 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4451 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 4452 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 4453 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 4454 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 4455 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4456 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 4457 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4458 | } |
| 4459 | } |
| 4460 | |
| 4461 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 4462 | __ Push(static_cast<Register>(reg)); |
| 4463 | } |
| 4464 | |
| 4465 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 4466 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4467 | } |
| 4468 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4469 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4470 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 4471 | ? LocationSummary::kCallOnSlowPath |
| 4472 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4473 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4474 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4475 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4476 | locations->SetOut(Location::RequiresRegister()); |
| 4477 | } |
| 4478 | |
| 4479 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4480 | LocationSummary* locations = cls->GetLocations(); |
| 4481 | Register out = locations->Out().AsRegister<Register>(); |
| 4482 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4483 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4484 | DCHECK(!cls->CanCallRuntime()); |
| 4485 | DCHECK(!cls->MustGenerateClinitCheck()); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4486 | __ LoadFromOffset( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4487 | kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4488 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4489 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4490 | __ LoadFromOffset(kLoadWord, |
| 4491 | out, |
| 4492 | current_method, |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4493 | ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4494 | __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4495 | // TODO: We will need a read barrier here. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4496 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4497 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4498 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4499 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4500 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4501 | if (cls->MustGenerateClinitCheck()) { |
| 4502 | GenerateClassInitializationCheck(slow_path, out); |
| 4503 | } else { |
| 4504 | __ Bind(slow_path->GetExitLabel()); |
| 4505 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4506 | } |
| 4507 | } |
| 4508 | |
| 4509 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 4510 | LocationSummary* locations = |
| 4511 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 4512 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4513 | if (check->HasUses()) { |
| 4514 | locations->SetOut(Location::SameAsFirstInput()); |
| 4515 | } |
| 4516 | } |
| 4517 | |
| 4518 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4519 | // We assume the class is not null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4520 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4521 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4522 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4523 | GenerateClassInitializationCheck(slow_path, |
| 4524 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4525 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4526 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4527 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4528 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4529 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 4530 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 4531 | __ b(slow_path->GetEntryLabel(), LT); |
| 4532 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 4533 | // properly. Therefore, we do a memory fence. |
| 4534 | __ dmb(ISH); |
| 4535 | __ Bind(slow_path->GetExitLabel()); |
| 4536 | } |
| 4537 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4538 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
| 4539 | LocationSummary* locations = |
| 4540 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4541 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4542 | locations->SetOut(Location::RequiresRegister()); |
| 4543 | } |
| 4544 | |
| 4545 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4546 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4547 | codegen_->AddSlowPath(slow_path); |
| 4548 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4549 | LocationSummary* locations = load->GetLocations(); |
| 4550 | Register out = locations->Out().AsRegister<Register>(); |
| 4551 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 4552 | __ LoadFromOffset( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4553 | kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 4554 | __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4555 | __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4556 | // TODO: We will need a read barrier here. |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4557 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4558 | __ Bind(slow_path->GetExitLabel()); |
| 4559 | } |
| 4560 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4561 | static int32_t GetExceptionTlsOffset() { |
| 4562 | return Thread::ExceptionOffset<kArmWordSize>().Int32Value(); |
| 4563 | } |
| 4564 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4565 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 4566 | LocationSummary* locations = |
| 4567 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4568 | locations->SetOut(Location::RequiresRegister()); |
| 4569 | } |
| 4570 | |
| 4571 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4572 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4573 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 4574 | } |
| 4575 | |
| 4576 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 4577 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4578 | } |
| 4579 | |
| 4580 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4581 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4582 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4583 | } |
| 4584 | |
| 4585 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 4586 | LocationSummary* locations = |
| 4587 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4588 | InvokeRuntimeCallingConvention calling_convention; |
| 4589 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4590 | } |
| 4591 | |
| 4592 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
| 4593 | codegen_->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 4594 | QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4595 | } |
| 4596 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4597 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4598 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4599 | switch (instruction->GetTypeCheckKind()) { |
| 4600 | case TypeCheckKind::kExactCheck: |
| 4601 | case TypeCheckKind::kAbstractClassCheck: |
| 4602 | case TypeCheckKind::kClassHierarchyCheck: |
| 4603 | case TypeCheckKind::kArrayObjectCheck: |
| 4604 | call_kind = LocationSummary::kNoCall; |
| 4605 | break; |
| 4606 | case TypeCheckKind::kInterfaceCheck: |
| 4607 | call_kind = LocationSummary::kCall; |
| 4608 | break; |
| 4609 | case TypeCheckKind::kArrayCheck: |
| 4610 | call_kind = LocationSummary::kCallOnSlowPath; |
| 4611 | break; |
| 4612 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4613 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4614 | if (call_kind != LocationSummary::kCall) { |
| 4615 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4616 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4617 | // The out register is used as a temporary, so it overlaps with the inputs. |
| 4618 | // Note that TypeCheckSlowPathARM uses this register too. |
| 4619 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4620 | } else { |
| 4621 | InvokeRuntimeCallingConvention calling_convention; |
| 4622 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4623 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4624 | locations->SetOut(Location::RegisterLocation(R0)); |
| 4625 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4626 | } |
| 4627 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4628 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4629 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4630 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4631 | Register cls = locations->InAt(1).AsRegister<Register>(); |
| 4632 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4633 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4634 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4635 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4636 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4637 | Label done, zero; |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4638 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4639 | |
| 4640 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4641 | // avoid null check if we know obj is not null. |
| 4642 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | d56376c | 2015-05-21 12:32:34 +0000 | [diff] [blame] | 4643 | __ CompareAndBranchIfZero(obj, &zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4644 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4645 | |
| 4646 | // In case of an interface check, we put the object class into the object register. |
| 4647 | // This is safe, as the register is caller-save, and the object must be in another |
| 4648 | // register if it survives the runtime call. |
| 4649 | Register target = (instruction->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) |
| 4650 | ? obj |
| 4651 | : out; |
| 4652 | __ LoadFromOffset(kLoadWord, target, obj, class_offset); |
| 4653 | __ MaybeUnpoisonHeapReference(target); |
| 4654 | |
| 4655 | switch (instruction->GetTypeCheckKind()) { |
| 4656 | case TypeCheckKind::kExactCheck: { |
| 4657 | __ cmp(out, ShifterOperand(cls)); |
| 4658 | // Classes must be equal for the instanceof to succeed. |
| 4659 | __ b(&zero, NE); |
| 4660 | __ LoadImmediate(out, 1); |
| 4661 | __ b(&done); |
| 4662 | break; |
| 4663 | } |
| 4664 | case TypeCheckKind::kAbstractClassCheck: { |
| 4665 | // If the class is abstract, we eagerly fetch the super class of the |
| 4666 | // object to avoid doing a comparison we know will fail. |
| 4667 | Label loop; |
| 4668 | __ Bind(&loop); |
| 4669 | __ LoadFromOffset(kLoadWord, out, out, super_offset); |
| 4670 | __ MaybeUnpoisonHeapReference(out); |
| 4671 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4672 | __ CompareAndBranchIfZero(out, &done); |
| 4673 | __ cmp(out, ShifterOperand(cls)); |
| 4674 | __ b(&loop, NE); |
| 4675 | __ LoadImmediate(out, 1); |
| 4676 | if (zero.IsLinked()) { |
| 4677 | __ b(&done); |
| 4678 | } |
| 4679 | break; |
| 4680 | } |
| 4681 | case TypeCheckKind::kClassHierarchyCheck: { |
| 4682 | // Walk over the class hierarchy to find a match. |
| 4683 | Label loop, success; |
| 4684 | __ Bind(&loop); |
| 4685 | __ cmp(out, ShifterOperand(cls)); |
| 4686 | __ b(&success, EQ); |
| 4687 | __ LoadFromOffset(kLoadWord, out, out, super_offset); |
| 4688 | __ MaybeUnpoisonHeapReference(out); |
| 4689 | __ CompareAndBranchIfNonZero(out, &loop); |
| 4690 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4691 | __ b(&done); |
| 4692 | __ Bind(&success); |
| 4693 | __ LoadImmediate(out, 1); |
| 4694 | if (zero.IsLinked()) { |
| 4695 | __ b(&done); |
| 4696 | } |
| 4697 | break; |
| 4698 | } |
| 4699 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4700 | // Do an exact check. |
| 4701 | Label exact_check; |
| 4702 | __ cmp(out, ShifterOperand(cls)); |
| 4703 | __ b(&exact_check, EQ); |
| 4704 | // Otherwise, we need to check that the object's class is a non primitive array. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4705 | __ LoadFromOffset(kLoadWord, out, out, component_offset); |
| 4706 | __ MaybeUnpoisonHeapReference(out); |
| 4707 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4708 | __ CompareAndBranchIfZero(out, &done); |
| 4709 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 4710 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 4711 | __ CompareAndBranchIfNonZero(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4712 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4713 | __ LoadImmediate(out, 1); |
| 4714 | __ b(&done); |
| 4715 | break; |
| 4716 | } |
| 4717 | case TypeCheckKind::kArrayCheck: { |
| 4718 | __ cmp(out, ShifterOperand(cls)); |
| 4719 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4720 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM( |
| 4721 | instruction, /* is_fatal */ false); |
| 4722 | codegen_->AddSlowPath(slow_path); |
| 4723 | __ b(slow_path->GetEntryLabel(), NE); |
| 4724 | __ LoadImmediate(out, 1); |
| 4725 | if (zero.IsLinked()) { |
| 4726 | __ b(&done); |
| 4727 | } |
| 4728 | break; |
| 4729 | } |
| 4730 | |
| 4731 | case TypeCheckKind::kInterfaceCheck: |
| 4732 | default: { |
| 4733 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 4734 | instruction, |
| 4735 | instruction->GetDexPc(), |
| 4736 | nullptr); |
| 4737 | if (zero.IsLinked()) { |
| 4738 | __ b(&done); |
| 4739 | } |
| 4740 | break; |
| 4741 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4742 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4743 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4744 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4745 | __ Bind(&zero); |
| 4746 | __ LoadImmediate(out, 0); |
| 4747 | } |
| 4748 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4749 | if (done.IsLinked()) { |
| 4750 | __ Bind(&done); |
| 4751 | } |
| 4752 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4753 | if (slow_path != nullptr) { |
| 4754 | __ Bind(slow_path->GetExitLabel()); |
| 4755 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4756 | } |
| 4757 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4758 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4759 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4760 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 4761 | |
| 4762 | switch (instruction->GetTypeCheckKind()) { |
| 4763 | case TypeCheckKind::kExactCheck: |
| 4764 | case TypeCheckKind::kAbstractClassCheck: |
| 4765 | case TypeCheckKind::kClassHierarchyCheck: |
| 4766 | case TypeCheckKind::kArrayObjectCheck: |
| 4767 | call_kind = throws_into_catch |
| 4768 | ? LocationSummary::kCallOnSlowPath |
| 4769 | : LocationSummary::kNoCall; |
| 4770 | break; |
| 4771 | case TypeCheckKind::kInterfaceCheck: |
| 4772 | call_kind = LocationSummary::kCall; |
| 4773 | break; |
| 4774 | case TypeCheckKind::kArrayCheck: |
| 4775 | call_kind = LocationSummary::kCallOnSlowPath; |
| 4776 | break; |
| 4777 | } |
| 4778 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4779 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4780 | instruction, call_kind); |
| 4781 | if (call_kind != LocationSummary::kCall) { |
| 4782 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4783 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4784 | // Note that TypeCheckSlowPathARM uses this register too. |
| 4785 | locations->AddTemp(Location::RequiresRegister()); |
| 4786 | } else { |
| 4787 | InvokeRuntimeCallingConvention calling_convention; |
| 4788 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4789 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4790 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4791 | } |
| 4792 | |
| 4793 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
| 4794 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4795 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4796 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4797 | Register temp = locations->WillCall() |
| 4798 | ? Register(kNoRegister) |
| 4799 | : locations->GetTemp(0).AsRegister<Register>(); |
| 4800 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4801 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4802 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4803 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4804 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 4805 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4806 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4807 | if (!locations->WillCall()) { |
| 4808 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM( |
| 4809 | instruction, !locations->CanCall()); |
| 4810 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 4811 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4812 | |
| 4813 | Label done; |
| 4814 | // Avoid null check if we know obj is not null. |
| 4815 | if (instruction->MustDoNullCheck()) { |
| 4816 | __ CompareAndBranchIfZero(obj, &done); |
| 4817 | } |
| 4818 | |
| 4819 | if (locations->WillCall()) { |
| 4820 | __ LoadFromOffset(kLoadWord, obj, obj, class_offset); |
| 4821 | __ MaybeUnpoisonHeapReference(obj); |
| 4822 | } else { |
| 4823 | __ LoadFromOffset(kLoadWord, temp, obj, class_offset); |
| 4824 | __ MaybeUnpoisonHeapReference(temp); |
| 4825 | } |
| 4826 | |
| 4827 | switch (instruction->GetTypeCheckKind()) { |
| 4828 | case TypeCheckKind::kExactCheck: |
| 4829 | case TypeCheckKind::kArrayCheck: { |
| 4830 | __ cmp(temp, ShifterOperand(cls)); |
| 4831 | // Jump to slow path for throwing the exception or doing a |
| 4832 | // more involved array check. |
| 4833 | __ b(slow_path->GetEntryLabel(), NE); |
| 4834 | break; |
| 4835 | } |
| 4836 | case TypeCheckKind::kAbstractClassCheck: { |
| 4837 | // If the class is abstract, we eagerly fetch the super class of the |
| 4838 | // object to avoid doing a comparison we know will fail. |
| 4839 | Label loop; |
| 4840 | __ Bind(&loop); |
| 4841 | __ LoadFromOffset(kLoadWord, temp, temp, super_offset); |
| 4842 | __ MaybeUnpoisonHeapReference(temp); |
| 4843 | // Jump to the slow path to throw the exception. |
| 4844 | __ CompareAndBranchIfZero(temp, slow_path->GetEntryLabel()); |
| 4845 | __ cmp(temp, ShifterOperand(cls)); |
| 4846 | __ b(&loop, NE); |
| 4847 | break; |
| 4848 | } |
| 4849 | case TypeCheckKind::kClassHierarchyCheck: { |
| 4850 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4851 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4852 | __ Bind(&loop); |
| 4853 | __ cmp(temp, ShifterOperand(cls)); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4854 | __ b(&done, EQ); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4855 | __ LoadFromOffset(kLoadWord, temp, temp, super_offset); |
| 4856 | __ MaybeUnpoisonHeapReference(temp); |
| 4857 | __ CompareAndBranchIfNonZero(temp, &loop); |
| 4858 | // Jump to the slow path to throw the exception. |
| 4859 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4860 | break; |
| 4861 | } |
| 4862 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4863 | // Do an exact check. |
| 4864 | __ cmp(temp, ShifterOperand(cls)); |
| 4865 | __ b(&done, EQ); |
| 4866 | // Otherwise, we need to check that the object's class is a non primitive array. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4867 | __ LoadFromOffset(kLoadWord, temp, temp, component_offset); |
| 4868 | __ MaybeUnpoisonHeapReference(temp); |
| 4869 | __ CompareAndBranchIfZero(temp, slow_path->GetEntryLabel()); |
| 4870 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 4871 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 4872 | __ CompareAndBranchIfNonZero(temp, slow_path->GetEntryLabel()); |
| 4873 | break; |
| 4874 | } |
| 4875 | case TypeCheckKind::kInterfaceCheck: |
| 4876 | default: |
| 4877 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 4878 | instruction, |
| 4879 | instruction->GetDexPc(), |
| 4880 | nullptr); |
| 4881 | break; |
| 4882 | } |
| 4883 | __ Bind(&done); |
| 4884 | |
| 4885 | if (slow_path != nullptr) { |
| 4886 | __ Bind(slow_path->GetExitLabel()); |
| 4887 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4888 | } |
| 4889 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4890 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4891 | LocationSummary* locations = |
| 4892 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4893 | InvokeRuntimeCallingConvention calling_convention; |
| 4894 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4895 | } |
| 4896 | |
| 4897 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4898 | codegen_->InvokeRuntime(instruction->IsEnter() |
| 4899 | ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject), |
| 4900 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 4901 | instruction->GetDexPc(), |
| 4902 | nullptr); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4903 | } |
| 4904 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4905 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 4906 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 4907 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 4908 | |
| 4909 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 4910 | LocationSummary* locations = |
| 4911 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4912 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 4913 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 4914 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4915 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4916 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4917 | } |
| 4918 | |
| 4919 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 4920 | HandleBitwiseOperation(instruction); |
| 4921 | } |
| 4922 | |
| 4923 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 4924 | HandleBitwiseOperation(instruction); |
| 4925 | } |
| 4926 | |
| 4927 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 4928 | HandleBitwiseOperation(instruction); |
| 4929 | } |
| 4930 | |
| 4931 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 4932 | LocationSummary* locations = instruction->GetLocations(); |
| 4933 | |
| 4934 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4935 | Register first = locations->InAt(0).AsRegister<Register>(); |
| 4936 | Register second = locations->InAt(1).AsRegister<Register>(); |
| 4937 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4938 | if (instruction->IsAnd()) { |
| 4939 | __ and_(out, first, ShifterOperand(second)); |
| 4940 | } else if (instruction->IsOr()) { |
| 4941 | __ orr(out, first, ShifterOperand(second)); |
| 4942 | } else { |
| 4943 | DCHECK(instruction->IsXor()); |
| 4944 | __ eor(out, first, ShifterOperand(second)); |
| 4945 | } |
| 4946 | } else { |
| 4947 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 4948 | Location first = locations->InAt(0); |
| 4949 | Location second = locations->InAt(1); |
| 4950 | Location out = locations->Out(); |
| 4951 | if (instruction->IsAnd()) { |
| 4952 | __ and_(out.AsRegisterPairLow<Register>(), |
| 4953 | first.AsRegisterPairLow<Register>(), |
| 4954 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 4955 | __ and_(out.AsRegisterPairHigh<Register>(), |
| 4956 | first.AsRegisterPairHigh<Register>(), |
| 4957 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 4958 | } else if (instruction->IsOr()) { |
| 4959 | __ orr(out.AsRegisterPairLow<Register>(), |
| 4960 | first.AsRegisterPairLow<Register>(), |
| 4961 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 4962 | __ orr(out.AsRegisterPairHigh<Register>(), |
| 4963 | first.AsRegisterPairHigh<Register>(), |
| 4964 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 4965 | } else { |
| 4966 | DCHECK(instruction->IsXor()); |
| 4967 | __ eor(out.AsRegisterPairLow<Register>(), |
| 4968 | first.AsRegisterPairLow<Register>(), |
| 4969 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 4970 | __ eor(out.AsRegisterPairHigh<Register>(), |
| 4971 | first.AsRegisterPairHigh<Register>(), |
| 4972 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 4973 | } |
| 4974 | } |
| 4975 | } |
| 4976 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4977 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4978 | // For better instruction scheduling we load the direct code pointer before the method pointer. |
| 4979 | bool direct_code_loaded = false; |
| 4980 | switch (invoke->GetCodePtrLocation()) { |
| 4981 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
| 4982 | if (IsSameDexFile(*invoke->GetTargetMethod().dex_file, GetGraph()->GetDexFile())) { |
| 4983 | break; |
| 4984 | } |
| 4985 | // Calls across dex files are more likely to exceed the available BL range, |
| 4986 | // so use absolute patch by falling through to kDirectCodeFixup. |
| 4987 | FALLTHROUGH_INTENDED; |
| 4988 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4989 | // LR = code address from literal pool with link-time patch. |
| 4990 | __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
| 4991 | direct_code_loaded = true; |
| 4992 | break; |
| 4993 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 4994 | // LR = invoke->GetDirectCodePtr(); |
| 4995 | __ LoadImmediate(LR, invoke->GetDirectCodePtr()); |
| 4996 | direct_code_loaded = true; |
| 4997 | break; |
| 4998 | default: |
| 4999 | break; |
| 5000 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 5001 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5002 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 5003 | switch (invoke->GetMethodLoadKind()) { |
| 5004 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 5005 | // temp = thread->string_init_entrypoint |
| 5006 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, invoke->GetStringInitOffset()); |
| 5007 | break; |
| 5008 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 5009 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 5010 | break; |
| 5011 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 5012 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 5013 | break; |
| 5014 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 5015 | __ LoadLiteral(temp.AsRegister<Register>(), |
| 5016 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 5017 | break; |
| 5018 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
| 5019 | // TODO: Implement this type. For the moment, we fall back to kDexCacheViaMethod. |
| 5020 | FALLTHROUGH_INTENDED; |
| 5021 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 5022 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 5023 | Register method_reg; |
| 5024 | Register reg = temp.AsRegister<Register>(); |
| 5025 | if (current_method.IsRegister()) { |
| 5026 | method_reg = current_method.AsRegister<Register>(); |
| 5027 | } else { |
| 5028 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 5029 | DCHECK(!current_method.IsValid()); |
| 5030 | method_reg = reg; |
| 5031 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 5032 | } |
| 5033 | // temp = current_method->dex_cache_resolved_methods_; |
| 5034 | __ LoadFromOffset( |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 5035 | kLoadWord, reg, method_reg, ArtMethod::DexCacheResolvedMethodsOffset( |
| 5036 | kArmPointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5037 | // temp = temp[index_in_cache] |
| 5038 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 5039 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 5040 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 5041 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5042 | } |
| 5043 | |
| 5044 | switch (invoke->GetCodePtrLocation()) { |
| 5045 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 5046 | __ bl(GetFrameEntryLabel()); |
| 5047 | break; |
| 5048 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
| 5049 | if (!direct_code_loaded) { |
| 5050 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 5051 | __ Bind(&relative_call_patches_.back().label); |
| 5052 | Label label; |
| 5053 | __ bl(&label); // Arbitrarily branch to the instruction after BL, override at link time. |
| 5054 | __ Bind(&label); |
| 5055 | break; |
| 5056 | } |
| 5057 | // If we loaded the direct code above, fall through. |
| 5058 | FALLTHROUGH_INTENDED; |
| 5059 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 5060 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 5061 | // LR prepared above for better instruction scheduling. |
| 5062 | DCHECK(direct_code_loaded); |
| 5063 | // LR() |
| 5064 | __ blx(LR); |
| 5065 | break; |
| 5066 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 5067 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 5068 | __ LoadFromOffset( |
| 5069 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
| 5070 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmWordSize).Int32Value()); |
| 5071 | // LR() |
| 5072 | __ blx(LR); |
| 5073 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 5074 | } |
| 5075 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 5076 | DCHECK(!IsLeafMethod()); |
| 5077 | } |
| 5078 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5079 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 5080 | Register temp = temp_location.AsRegister<Register>(); |
| 5081 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 5082 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
| 5083 | LocationSummary* locations = invoke->GetLocations(); |
| 5084 | Location receiver = locations->InAt(0); |
| 5085 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5086 | // temp = object->GetClass(); |
| 5087 | DCHECK(receiver.IsRegister()); |
| 5088 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
| 5089 | MaybeRecordImplicitNullCheck(invoke); |
| 5090 | __ MaybeUnpoisonHeapReference(temp); |
| 5091 | // temp = temp->GetMethodAt(method_offset); |
| 5092 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 5093 | kArmWordSize).Int32Value(); |
| 5094 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 5095 | // LR = temp->GetEntryPoint(); |
| 5096 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 5097 | // LR(); |
| 5098 | __ blx(LR); |
| 5099 | } |
| 5100 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5101 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 5102 | DCHECK(linker_patches->empty()); |
| 5103 | size_t size = method_patches_.size() + call_patches_.size() + relative_call_patches_.size(); |
| 5104 | linker_patches->reserve(size); |
| 5105 | for (const auto& entry : method_patches_) { |
| 5106 | const MethodReference& target_method = entry.first; |
| 5107 | Literal* literal = entry.second; |
| 5108 | DCHECK(literal->GetLabel()->IsBound()); |
| 5109 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 5110 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 5111 | target_method.dex_file, |
| 5112 | target_method.dex_method_index)); |
| 5113 | } |
| 5114 | for (const auto& entry : call_patches_) { |
| 5115 | const MethodReference& target_method = entry.first; |
| 5116 | Literal* literal = entry.second; |
| 5117 | DCHECK(literal->GetLabel()->IsBound()); |
| 5118 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 5119 | linker_patches->push_back(LinkerPatch::CodePatch(literal_offset, |
| 5120 | target_method.dex_file, |
| 5121 | target_method.dex_method_index)); |
| 5122 | } |
| 5123 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 5124 | uint32_t literal_offset = info.label.Position(); |
| 5125 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 5126 | info.target_method.dex_file, |
| 5127 | info.target_method.dex_method_index)); |
| 5128 | } |
| 5129 | } |
| 5130 | |
| 5131 | Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method, |
| 5132 | MethodToLiteralMap* map) { |
| 5133 | // Look up the literal for target_method. |
| 5134 | auto lb = map->lower_bound(target_method); |
| 5135 | if (lb != map->end() && !map->key_comp()(target_method, lb->first)) { |
| 5136 | return lb->second; |
| 5137 | } |
| 5138 | // We don't have a literal for this method yet, insert a new one. |
| 5139 | Literal* literal = __ NewLiteral<uint32_t>(0u); |
| 5140 | map->PutBefore(lb, target_method, literal); |
| 5141 | return literal; |
| 5142 | } |
| 5143 | |
| 5144 | Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) { |
| 5145 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 5146 | } |
| 5147 | |
| 5148 | Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) { |
| 5149 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 5150 | } |
| 5151 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5152 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) { |
| 5153 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5154 | UNUSED(instruction); |
| 5155 | LOG(FATAL) << "Unreachable"; |
| 5156 | } |
| 5157 | |
| 5158 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) { |
| 5159 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5160 | UNUSED(instruction); |
| 5161 | LOG(FATAL) << "Unreachable"; |
| 5162 | } |
| 5163 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5164 | void LocationsBuilderARM::VisitFakeString(HFakeString* instruction) { |
| 5165 | DCHECK(codegen_->IsBaseline()); |
| 5166 | LocationSummary* locations = |
| 5167 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5168 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 5169 | } |
| 5170 | |
| 5171 | void InstructionCodeGeneratorARM::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 5172 | DCHECK(codegen_->IsBaseline()); |
| 5173 | // Will be generated at use site. |
| 5174 | } |
| 5175 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5176 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5177 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5178 | LocationSummary* locations = |
| 5179 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 5180 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5181 | } |
| 5182 | |
| 5183 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5184 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 5185 | int32_t num_entries = switch_instr->GetNumEntries(); |
| 5186 | LocationSummary* locations = switch_instr->GetLocations(); |
| 5187 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 5188 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 5189 | |
| 5190 | // Create a series of compare/jumps. |
| 5191 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 5192 | for (int32_t i = 0; i < num_entries; i++) { |
| 5193 | GenerateCompareWithImmediate(value_reg, lower_bound + i); |
| 5194 | __ b(codegen_->GetLabelOf(successors.at(i)), EQ); |
| 5195 | } |
| 5196 | |
| 5197 | // And the default for any other value. |
| 5198 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 5199 | __ b(codegen_->GetLabelOf(default_block)); |
| 5200 | } |
| 5201 | } |
| 5202 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5203 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 5204 | if (!trg.IsValid()) { |
| 5205 | DCHECK(type == Primitive::kPrimVoid); |
| 5206 | return; |
| 5207 | } |
| 5208 | |
| 5209 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 5210 | |
| 5211 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 5212 | if (return_loc.Equals(trg)) { |
| 5213 | return; |
| 5214 | } |
| 5215 | |
| 5216 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 5217 | // with the last branch. |
| 5218 | if (type == Primitive::kPrimLong) { |
| 5219 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 5220 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 5221 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 5222 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 5223 | } else if (type == Primitive::kPrimDouble) { |
| 5224 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 5225 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 5226 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 5227 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 5228 | } else { |
| 5229 | // Let the parallel move resolver take care of all of this. |
| 5230 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 5231 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 5232 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 5233 | } |
| 5234 | } |
| 5235 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5236 | #undef __ |
| 5237 | #undef QUICK_ENTRY_POINT |
| 5238 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5239 | } // namespace arm |
| 5240 | } // namespace art |