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