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