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 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 37 | template<class MirrorType> |
| 38 | class GcRoot; |
| 39 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 40 | namespace arm { |
| 41 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 42 | static bool ExpectedPairLayout(Location location) { |
| 43 | // We expected this for both core and fpu register pairs. |
| 44 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 45 | } |
| 46 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 47 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 48 | static constexpr Register kMethodRegisterArgument = R0; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 49 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 50 | static constexpr Register kCoreAlwaysSpillRegister = R5; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 51 | static constexpr Register kCoreCalleeSaves[] = |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 52 | { R5, R6, R7, R8, R10, R11, LR }; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 53 | static constexpr SRegister kFpuCalleeSaves[] = |
| 54 | { 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] | 55 | |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 56 | // D31 cannot be split into two S registers, and the register allocator only works on |
| 57 | // S registers. Therefore there is no need to block it. |
| 58 | static constexpr DRegister DTMP = D31; |
| 59 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 60 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 61 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 62 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 63 | #define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 64 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 65 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 66 | class NullCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 67 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 68 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 69 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 70 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 71 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 72 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 73 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 74 | // Live registers will be restored in the catch block if caught. |
| 75 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 76 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 77 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 78 | QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 79 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 80 | } |
| 81 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 82 | bool IsFatal() const OVERRIDE { return true; } |
| 83 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 84 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; } |
| 85 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 86 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 87 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 88 | }; |
| 89 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 90 | class DivZeroCheckSlowPathARM : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 91 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 92 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 93 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 94 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 95 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 96 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 97 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 98 | // Live registers will be restored in the catch block if caught. |
| 99 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 100 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 101 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 102 | QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 103 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 106 | bool IsFatal() const OVERRIDE { return true; } |
| 107 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 108 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; } |
| 109 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 110 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 111 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 112 | }; |
| 113 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 114 | class SuspendCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 115 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 116 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 117 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 118 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 119 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 120 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 121 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 122 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 123 | QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 124 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 125 | if (successor_ == nullptr) { |
| 126 | __ b(GetReturnLabel()); |
| 127 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 128 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 129 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 132 | Label* GetReturnLabel() { |
| 133 | DCHECK(successor_ == nullptr); |
| 134 | return &return_label_; |
| 135 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 136 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 137 | HBasicBlock* GetSuccessor() const { |
| 138 | return successor_; |
| 139 | } |
| 140 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 141 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; } |
| 142 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 143 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 144 | // If not null, the block to branch to after the suspend check. |
| 145 | HBasicBlock* const successor_; |
| 146 | |
| 147 | // 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] | 148 | Label return_label_; |
| 149 | |
| 150 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 151 | }; |
| 152 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 153 | class BoundsCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 154 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 155 | explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 156 | : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 157 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 158 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 159 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 160 | LocationSummary* locations = instruction_->GetLocations(); |
| 161 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 162 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 163 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 164 | // Live registers will be restored in the catch block if caught. |
| 165 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 166 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 167 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 168 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 169 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 170 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 171 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 172 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 173 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 174 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 175 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 176 | Primitive::kPrimInt); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 177 | uint32_t entry_point_offset = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 178 | ? QUICK_ENTRY_POINT(pThrowStringBounds) |
| 179 | : QUICK_ENTRY_POINT(pThrowArrayBounds); |
| 180 | arm_codegen->InvokeRuntime(entry_point_offset, instruction_, instruction_->GetDexPc(), this); |
| 181 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 182 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 183 | } |
| 184 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 185 | bool IsFatal() const OVERRIDE { return true; } |
| 186 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 187 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; } |
| 188 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 189 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 190 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 191 | }; |
| 192 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 193 | class LoadClassSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 194 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 195 | LoadClassSlowPathARM(HLoadClass* cls, |
| 196 | HInstruction* at, |
| 197 | uint32_t dex_pc, |
| 198 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 199 | : SlowPathCode(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 200 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 201 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 202 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 203 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 204 | LocationSummary* locations = at_->GetLocations(); |
| 205 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 206 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 207 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 208 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 209 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 210 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 211 | __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 212 | int32_t entry_point_offset = do_clinit_ |
| 213 | ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 214 | : QUICK_ENTRY_POINT(pInitializeType); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 215 | arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 216 | if (do_clinit_) { |
| 217 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 218 | } else { |
| 219 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 220 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 221 | |
| 222 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 223 | Location out = locations->Out(); |
| 224 | if (out.IsValid()) { |
| 225 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 226 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 227 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 228 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 229 | __ b(GetExitLabel()); |
| 230 | } |
| 231 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 232 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; } |
| 233 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 234 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 235 | // The class this slow path will load. |
| 236 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 237 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 238 | // The instruction where this slow path is happening. |
| 239 | // (Might be the load class or an initialization check). |
| 240 | HInstruction* const at_; |
| 241 | |
| 242 | // The dex PC of `at_`. |
| 243 | const uint32_t dex_pc_; |
| 244 | |
| 245 | // Whether to initialize the class. |
| 246 | const bool do_clinit_; |
| 247 | |
| 248 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 249 | }; |
| 250 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 251 | class LoadStringSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 252 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 253 | explicit LoadStringSlowPathARM(HLoadString* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 254 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 255 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 256 | LocationSummary* locations = instruction_->GetLocations(); |
| 257 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 258 | |
| 259 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 260 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 261 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 262 | |
| 263 | InvokeRuntimeCallingConvention calling_convention; |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 264 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 265 | __ LoadImmediate(calling_convention.GetRegisterAt(0), string_index); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 266 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 267 | QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 268 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 269 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 270 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 271 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 272 | __ b(GetExitLabel()); |
| 273 | } |
| 274 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 275 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; } |
| 276 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 277 | private: |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 278 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 279 | }; |
| 280 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 281 | class TypeCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 282 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 283 | TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 284 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 285 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 286 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 287 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 288 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 289 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 290 | DCHECK(instruction_->IsCheckCast() |
| 291 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 292 | |
| 293 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 294 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 295 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 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); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 316 | CheckEntrypointTypes< |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 317 | kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 318 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 319 | } else { |
| 320 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 321 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 322 | instruction_, |
| 323 | instruction_->GetDexPc(), |
| 324 | this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 325 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 326 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 327 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 328 | if (!is_fatal_) { |
| 329 | RestoreLiveRegisters(codegen, locations); |
| 330 | __ b(GetExitLabel()); |
| 331 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 332 | } |
| 333 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 334 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; } |
| 335 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 336 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 337 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 338 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 339 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 340 | |
| 341 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 342 | }; |
| 343 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 344 | class DeoptimizationSlowPathARM : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 345 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 346 | explicit DeoptimizationSlowPathARM(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 347 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 348 | |
| 349 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 350 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 351 | __ Bind(GetEntryLabel()); |
| 352 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 353 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 354 | instruction_, |
| 355 | instruction_->GetDexPc(), |
| 356 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 357 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 360 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; } |
| 361 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 362 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 363 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM); |
| 364 | }; |
| 365 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 366 | class ArraySetSlowPathARM : public SlowPathCode { |
| 367 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 368 | explicit ArraySetSlowPathARM(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 369 | |
| 370 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 371 | LocationSummary* locations = instruction_->GetLocations(); |
| 372 | __ Bind(GetEntryLabel()); |
| 373 | SaveLiveRegisters(codegen, locations); |
| 374 | |
| 375 | InvokeRuntimeCallingConvention calling_convention; |
| 376 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 377 | parallel_move.AddMove( |
| 378 | locations->InAt(0), |
| 379 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 380 | Primitive::kPrimNot, |
| 381 | nullptr); |
| 382 | parallel_move.AddMove( |
| 383 | locations->InAt(1), |
| 384 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 385 | Primitive::kPrimInt, |
| 386 | nullptr); |
| 387 | parallel_move.AddMove( |
| 388 | locations->InAt(2), |
| 389 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 390 | Primitive::kPrimNot, |
| 391 | nullptr); |
| 392 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 393 | |
| 394 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 395 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 396 | instruction_, |
| 397 | instruction_->GetDexPc(), |
| 398 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 399 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 400 | RestoreLiveRegisters(codegen, locations); |
| 401 | __ b(GetExitLabel()); |
| 402 | } |
| 403 | |
| 404 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; } |
| 405 | |
| 406 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 407 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM); |
| 408 | }; |
| 409 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 410 | // Slow path marking an object during a read barrier. |
| 411 | class ReadBarrierMarkSlowPathARM : public SlowPathCode { |
| 412 | public: |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 413 | ReadBarrierMarkSlowPathARM(HInstruction* instruction, Location obj) |
| 414 | : SlowPathCode(instruction), obj_(obj) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 415 | DCHECK(kEmitCompilerReadBarrier); |
| 416 | } |
| 417 | |
| 418 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; } |
| 419 | |
| 420 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 421 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 422 | Register reg = obj_.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 423 | DCHECK(locations->CanCall()); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 424 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 425 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 426 | instruction_->IsStaticFieldGet() || |
| 427 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 428 | instruction_->IsArraySet() || |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 429 | instruction_->IsLoadClass() || |
| 430 | instruction_->IsLoadString() || |
| 431 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 432 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 433 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 434 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 435 | << "Unexpected instruction in read barrier marking slow path: " |
| 436 | << instruction_->DebugName(); |
| 437 | |
| 438 | __ Bind(GetEntryLabel()); |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 439 | // No need to save live registers; it's taken care of by the |
| 440 | // entrypoint. Also, there is no need to update the stack mask, |
| 441 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 442 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 443 | DCHECK_NE(reg, SP); |
| 444 | DCHECK_NE(reg, LR); |
| 445 | DCHECK_NE(reg, PC); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 446 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 447 | // as a temporary, it cannot be the entry point's input/output. |
| 448 | DCHECK_NE(reg, IP); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 449 | DCHECK(0 <= reg && reg < kNumberOfCoreRegisters) << reg; |
| 450 | // "Compact" slow path, saving two moves. |
| 451 | // |
| 452 | // Instead of using the standard runtime calling convention (input |
| 453 | // and output in R0): |
| 454 | // |
| 455 | // R0 <- obj |
| 456 | // R0 <- ReadBarrierMark(R0) |
| 457 | // obj <- R0 |
| 458 | // |
| 459 | // we just use rX (the register holding `obj`) as input and output |
| 460 | // of a dedicated entrypoint: |
| 461 | // |
| 462 | // rX <- ReadBarrierMarkRegX(rX) |
| 463 | // |
| 464 | int32_t entry_point_offset = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 465 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 466 | // This runtime call does not require a stack map. |
| 467 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 468 | __ b(GetExitLabel()); |
| 469 | } |
| 470 | |
| 471 | private: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 472 | const Location obj_; |
| 473 | |
| 474 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM); |
| 475 | }; |
| 476 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 477 | // Slow path generating a read barrier for a heap reference. |
| 478 | class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCode { |
| 479 | public: |
| 480 | ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction, |
| 481 | Location out, |
| 482 | Location ref, |
| 483 | Location obj, |
| 484 | uint32_t offset, |
| 485 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 486 | : SlowPathCode(instruction), |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 487 | out_(out), |
| 488 | ref_(ref), |
| 489 | obj_(obj), |
| 490 | offset_(offset), |
| 491 | index_(index) { |
| 492 | DCHECK(kEmitCompilerReadBarrier); |
| 493 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 494 | // has been overwritten by (or after) the heap object reference load |
| 495 | // to be instrumented, e.g.: |
| 496 | // |
| 497 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 498 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 499 | // |
| 500 | // In that case, we have lost the information about the original |
| 501 | // object, and the emitted read barrier cannot work properly. |
| 502 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 503 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 504 | } |
| 505 | |
| 506 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 507 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 508 | LocationSummary* locations = instruction_->GetLocations(); |
| 509 | Register reg_out = out_.AsRegister<Register>(); |
| 510 | DCHECK(locations->CanCall()); |
| 511 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 512 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 513 | instruction_->IsStaticFieldGet() || |
| 514 | instruction_->IsArrayGet() || |
| 515 | instruction_->IsInstanceOf() || |
| 516 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 517 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 518 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 519 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 520 | |
| 521 | __ Bind(GetEntryLabel()); |
| 522 | SaveLiveRegisters(codegen, locations); |
| 523 | |
| 524 | // We may have to change the index's value, but as `index_` is a |
| 525 | // constant member (like other "inputs" of this slow path), |
| 526 | // introduce a copy of it, `index`. |
| 527 | Location index = index_; |
| 528 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 529 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 530 | if (instruction_->IsArrayGet()) { |
| 531 | // Compute the actual memory offset and store it in `index`. |
| 532 | Register index_reg = index_.AsRegister<Register>(); |
| 533 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 534 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 535 | // We are about to change the value of `index_reg` (see the |
| 536 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 537 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 538 | // not been saved by the previous call to |
| 539 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 540 | // callee-save register -- |
| 541 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 542 | // callee-save registers, as it has been designed with the |
| 543 | // assumption that callee-save registers are supposed to be |
| 544 | // handled by the called function. So, as a callee-save |
| 545 | // register, `index_reg` _would_ eventually be saved onto |
| 546 | // the stack, but it would be too late: we would have |
| 547 | // changed its value earlier. Therefore, we manually save |
| 548 | // it here into another freely available register, |
| 549 | // `free_reg`, chosen of course among the caller-save |
| 550 | // registers (as a callee-save `free_reg` register would |
| 551 | // exhibit the same problem). |
| 552 | // |
| 553 | // Note we could have requested a temporary register from |
| 554 | // the register allocator instead; but we prefer not to, as |
| 555 | // this is a slow path, and we know we can find a |
| 556 | // caller-save register that is available. |
| 557 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 558 | __ Mov(free_reg, index_reg); |
| 559 | index_reg = free_reg; |
| 560 | index = Location::RegisterLocation(index_reg); |
| 561 | } else { |
| 562 | // The initial register stored in `index_` has already been |
| 563 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 564 | // (as it is not a callee-save register), so we can freely |
| 565 | // use it. |
| 566 | } |
| 567 | // Shifting the index value contained in `index_reg` by the scale |
| 568 | // factor (2) cannot overflow in practice, as the runtime is |
| 569 | // unable to allocate object arrays with a size larger than |
| 570 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 571 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 572 | static_assert( |
| 573 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 574 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 575 | __ AddConstant(index_reg, index_reg, offset_); |
| 576 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 577 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 578 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 579 | // (as in the case of ArrayGet), as it is actually an offset |
| 580 | // to an object field within an object. |
| 581 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 582 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 583 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 584 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 585 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 586 | DCHECK_EQ(offset_, 0U); |
| 587 | DCHECK(index_.IsRegisterPair()); |
| 588 | // UnsafeGet's offset location is a register pair, the low |
| 589 | // part contains the correct offset. |
| 590 | index = index_.ToLow(); |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | // We're moving two or three locations to locations that could |
| 595 | // overlap, so we need a parallel move resolver. |
| 596 | InvokeRuntimeCallingConvention calling_convention; |
| 597 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 598 | parallel_move.AddMove(ref_, |
| 599 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 600 | Primitive::kPrimNot, |
| 601 | nullptr); |
| 602 | parallel_move.AddMove(obj_, |
| 603 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 604 | Primitive::kPrimNot, |
| 605 | nullptr); |
| 606 | if (index.IsValid()) { |
| 607 | parallel_move.AddMove(index, |
| 608 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 609 | Primitive::kPrimInt, |
| 610 | nullptr); |
| 611 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 612 | } else { |
| 613 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 614 | __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_); |
| 615 | } |
| 616 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 617 | instruction_, |
| 618 | instruction_->GetDexPc(), |
| 619 | this); |
| 620 | CheckEntrypointTypes< |
| 621 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 622 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 623 | |
| 624 | RestoreLiveRegisters(codegen, locations); |
| 625 | __ b(GetExitLabel()); |
| 626 | } |
| 627 | |
| 628 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; } |
| 629 | |
| 630 | private: |
| 631 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 632 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 633 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 634 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 635 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 636 | return static_cast<Register>(i); |
| 637 | } |
| 638 | } |
| 639 | // We shall never fail to find a free caller-save register, as |
| 640 | // there are more than two core caller-save registers on ARM |
| 641 | // (meaning it is possible to find one which is different from |
| 642 | // `ref` and `obj`). |
| 643 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 644 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 645 | UNREACHABLE(); |
| 646 | } |
| 647 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 648 | const Location out_; |
| 649 | const Location ref_; |
| 650 | const Location obj_; |
| 651 | const uint32_t offset_; |
| 652 | // An additional location containing an index to an array. |
| 653 | // Only used for HArrayGet and the UnsafeGetObject & |
| 654 | // UnsafeGetObjectVolatile intrinsics. |
| 655 | const Location index_; |
| 656 | |
| 657 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM); |
| 658 | }; |
| 659 | |
| 660 | // Slow path generating a read barrier for a GC root. |
| 661 | class ReadBarrierForRootSlowPathARM : public SlowPathCode { |
| 662 | public: |
| 663 | ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 664 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 665 | DCHECK(kEmitCompilerReadBarrier); |
| 666 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 667 | |
| 668 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 669 | LocationSummary* locations = instruction_->GetLocations(); |
| 670 | Register reg_out = out_.AsRegister<Register>(); |
| 671 | DCHECK(locations->CanCall()); |
| 672 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 673 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 674 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 675 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 676 | |
| 677 | __ Bind(GetEntryLabel()); |
| 678 | SaveLiveRegisters(codegen, locations); |
| 679 | |
| 680 | InvokeRuntimeCallingConvention calling_convention; |
| 681 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 682 | arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| 683 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 684 | instruction_, |
| 685 | instruction_->GetDexPc(), |
| 686 | this); |
| 687 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 688 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 689 | |
| 690 | RestoreLiveRegisters(codegen, locations); |
| 691 | __ b(GetExitLabel()); |
| 692 | } |
| 693 | |
| 694 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; } |
| 695 | |
| 696 | private: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 697 | const Location out_; |
| 698 | const Location root_; |
| 699 | |
| 700 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM); |
| 701 | }; |
| 702 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 703 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 704 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 705 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 706 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 707 | inline Condition ARMCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 708 | switch (cond) { |
| 709 | case kCondEQ: return EQ; |
| 710 | case kCondNE: return NE; |
| 711 | case kCondLT: return LT; |
| 712 | case kCondLE: return LE; |
| 713 | case kCondGT: return GT; |
| 714 | case kCondGE: return GE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 715 | case kCondB: return LO; |
| 716 | case kCondBE: return LS; |
| 717 | case kCondA: return HI; |
| 718 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 719 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 720 | LOG(FATAL) << "Unreachable"; |
| 721 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 722 | } |
| 723 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 724 | // Maps signed condition to unsigned condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 725 | inline Condition ARMUnsignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 726 | switch (cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 727 | case kCondEQ: return EQ; |
| 728 | case kCondNE: return NE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 729 | // Signed to unsigned. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 730 | case kCondLT: return LO; |
| 731 | case kCondLE: return LS; |
| 732 | case kCondGT: return HI; |
| 733 | case kCondGE: return HS; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 734 | // Unsigned remain unchanged. |
| 735 | case kCondB: return LO; |
| 736 | case kCondBE: return LS; |
| 737 | case kCondA: return HI; |
| 738 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 739 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 740 | LOG(FATAL) << "Unreachable"; |
| 741 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 742 | } |
| 743 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 744 | inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 745 | // The ARM condition codes can express all the necessary branches, see the |
| 746 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 747 | // There is no dex instruction or HIR that would need the missing conditions |
| 748 | // "equal or unordered" or "not equal". |
| 749 | switch (cond) { |
| 750 | case kCondEQ: return EQ; |
| 751 | case kCondNE: return NE /* unordered */; |
| 752 | case kCondLT: return gt_bias ? CC : LT /* unordered */; |
| 753 | case kCondLE: return gt_bias ? LS : LE /* unordered */; |
| 754 | case kCondGT: return gt_bias ? HI /* unordered */ : GT; |
| 755 | case kCondGE: return gt_bias ? CS /* unordered */ : GE; |
| 756 | default: |
| 757 | LOG(FATAL) << "UNREACHABLE"; |
| 758 | UNREACHABLE(); |
| 759 | } |
| 760 | } |
| 761 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 762 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 763 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 767 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 768 | } |
| 769 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 770 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 771 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 772 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 773 | } |
| 774 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 775 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 776 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 777 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 778 | } |
| 779 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 780 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 781 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 782 | return kArmWordSize; |
| 783 | } |
| 784 | |
| 785 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 786 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 787 | return kArmWordSize; |
| 788 | } |
| 789 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 790 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 791 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 792 | const CompilerOptions& compiler_options, |
| 793 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 794 | : CodeGenerator(graph, |
| 795 | kNumberOfCoreRegisters, |
| 796 | kNumberOfSRegisters, |
| 797 | kNumberOfRegisterPairs, |
| 798 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 799 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 800 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 801 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 802 | compiler_options, |
| 803 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 804 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 805 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 806 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 807 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 808 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 809 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 810 | uint32_literals_(std::less<uint32_t>(), |
| 811 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 812 | method_patches_(MethodReferenceComparator(), |
| 813 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 814 | call_patches_(MethodReferenceComparator(), |
| 815 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 816 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 817 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 818 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 819 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 820 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 821 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 822 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 823 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 824 | boot_image_address_patches_(std::less<uint32_t>(), |
| 825 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 826 | // Always save the LR register to mimic Quick. |
| 827 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 828 | } |
| 829 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 830 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 831 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 832 | __ FinalizeCode(); |
| 833 | |
| 834 | // Adjust native pc offsets in stack maps. |
| 835 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
| 836 | uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset; |
| 837 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 838 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 839 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 840 | // Adjust pc offsets for the disassembly information. |
| 841 | if (disasm_info_ != nullptr) { |
| 842 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 843 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 844 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 845 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 846 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 847 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 848 | } |
| 849 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 850 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 851 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 852 | } |
| 853 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 854 | |
| 855 | CodeGenerator::Finalize(allocator); |
| 856 | } |
| 857 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 858 | void CodeGeneratorARM::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 859 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 860 | blocked_register_pairs_[R1_R2] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 861 | |
| 862 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 863 | blocked_core_registers_[SP] = true; |
| 864 | blocked_core_registers_[LR] = true; |
| 865 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 866 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 867 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 868 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 869 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 870 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 871 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 872 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 873 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 874 | // Stubs do not save callee-save floating point registers. If the graph |
| 875 | // is debuggable, we need to deal with these registers differently. For |
| 876 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 877 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 878 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 879 | } |
| 880 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 881 | |
| 882 | UpdateBlockedPairRegisters(); |
| 883 | } |
| 884 | |
| 885 | void CodeGeneratorARM::UpdateBlockedPairRegisters() const { |
| 886 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 887 | ArmManagedRegister current = |
| 888 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 889 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 890 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 891 | blocked_register_pairs_[i] = true; |
| 892 | } |
| 893 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 894 | } |
| 895 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 896 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 897 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 898 | assembler_(codegen->GetAssembler()), |
| 899 | codegen_(codegen) {} |
| 900 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 901 | void CodeGeneratorARM::ComputeSpillMask() { |
| 902 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 903 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 904 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 905 | // restore another arbitrary register. |
| 906 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 907 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 908 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 909 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 910 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 911 | // but in the range. |
| 912 | if (fpu_spill_mask_ != 0) { |
| 913 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 914 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 915 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 916 | fpu_spill_mask_ |= (1 << i); |
| 917 | } |
| 918 | } |
| 919 | } |
| 920 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 921 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 922 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 926 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 927 | } |
| 928 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 929 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 930 | bool skip_overflow_check = |
| 931 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 932 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 933 | __ Bind(&frame_entry_label_); |
| 934 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 935 | if (HasEmptyFrame()) { |
| 936 | return; |
| 937 | } |
| 938 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 939 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 940 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 941 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 942 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 943 | } |
| 944 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 945 | __ PushList(core_spill_mask_); |
| 946 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 947 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 948 | if (fpu_spill_mask_ != 0) { |
| 949 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 950 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 951 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 952 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 953 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 954 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 955 | __ AddConstant(SP, -adjust); |
| 956 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 957 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 961 | if (HasEmptyFrame()) { |
| 962 | __ bx(LR); |
| 963 | return; |
| 964 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 965 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 966 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 967 | __ AddConstant(SP, adjust); |
| 968 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 969 | if (fpu_spill_mask_ != 0) { |
| 970 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 971 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 972 | __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 973 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 974 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 975 | // Pop LR into PC to return. |
| 976 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 977 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 978 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 979 | __ cfi().RestoreState(); |
| 980 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 981 | } |
| 982 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 983 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 984 | Label* label = GetLabelOf(block); |
| 985 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 986 | } |
| 987 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 988 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 989 | switch (type) { |
| 990 | case Primitive::kPrimBoolean: |
| 991 | case Primitive::kPrimByte: |
| 992 | case Primitive::kPrimChar: |
| 993 | case Primitive::kPrimShort: |
| 994 | case Primitive::kPrimInt: |
| 995 | case Primitive::kPrimNot: { |
| 996 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 997 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 998 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 999 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1000 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1001 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1002 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1003 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1004 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1005 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1006 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1007 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1008 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1009 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1010 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1011 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 1012 | // Skip R1, and use R2_R3 instead. |
| 1013 | gp_index_++; |
| 1014 | index++; |
| 1015 | } |
| 1016 | } |
| 1017 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 1018 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1019 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1020 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1021 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1022 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1023 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1024 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | case Primitive::kPrimFloat: { |
| 1029 | uint32_t stack_index = stack_index_++; |
| 1030 | if (float_index_ % 2 == 0) { |
| 1031 | float_index_ = std::max(double_index_, float_index_); |
| 1032 | } |
| 1033 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 1034 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1035 | } else { |
| 1036 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | case Primitive::kPrimDouble: { |
| 1041 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 1042 | uint32_t stack_index = stack_index_; |
| 1043 | stack_index_ += 2; |
| 1044 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 1045 | uint32_t index = double_index_; |
| 1046 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1047 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1048 | calling_convention.GetFpuRegisterAt(index), |
| 1049 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1050 | DCHECK(ExpectedPairLayout(result)); |
| 1051 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1052 | } else { |
| 1053 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1054 | } |
| 1055 | } |
| 1056 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1057 | case Primitive::kPrimVoid: |
| 1058 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1059 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1060 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1061 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1062 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1063 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1064 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1065 | switch (type) { |
| 1066 | case Primitive::kPrimBoolean: |
| 1067 | case Primitive::kPrimByte: |
| 1068 | case Primitive::kPrimChar: |
| 1069 | case Primitive::kPrimShort: |
| 1070 | case Primitive::kPrimInt: |
| 1071 | case Primitive::kPrimNot: { |
| 1072 | return Location::RegisterLocation(R0); |
| 1073 | } |
| 1074 | |
| 1075 | case Primitive::kPrimFloat: { |
| 1076 | return Location::FpuRegisterLocation(S0); |
| 1077 | } |
| 1078 | |
| 1079 | case Primitive::kPrimLong: { |
| 1080 | return Location::RegisterPairLocation(R0, R1); |
| 1081 | } |
| 1082 | |
| 1083 | case Primitive::kPrimDouble: { |
| 1084 | return Location::FpuRegisterPairLocation(S0, S1); |
| 1085 | } |
| 1086 | |
| 1087 | case Primitive::kPrimVoid: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1088 | return Location::NoLocation(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1089 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1090 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1091 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1094 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 1095 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1096 | } |
| 1097 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1098 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 1099 | if (source.Equals(destination)) { |
| 1100 | return; |
| 1101 | } |
| 1102 | if (destination.IsRegister()) { |
| 1103 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1104 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1105 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1106 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1107 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1108 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1109 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1110 | } else if (destination.IsFpuRegister()) { |
| 1111 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1112 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1113 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1114 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1115 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1116 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1117 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1118 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1119 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1120 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1121 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1122 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1123 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1124 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1125 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1126 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 1127 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1128 | } |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 1133 | if (source.Equals(destination)) { |
| 1134 | return; |
| 1135 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1136 | if (destination.IsRegisterPair()) { |
| 1137 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1138 | EmitParallelMoves( |
| 1139 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1140 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1141 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1142 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1143 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1144 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1145 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1146 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1147 | } else if (source.IsFpuRegisterPair()) { |
| 1148 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 1149 | destination.AsRegisterPairHigh<Register>(), |
| 1150 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1151 | } else { |
| 1152 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1153 | DCHECK(ExpectedPairLayout(destination)); |
| 1154 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 1155 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1156 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1157 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1158 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1159 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1160 | SP, |
| 1161 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1162 | } else if (source.IsRegisterPair()) { |
| 1163 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1164 | source.AsRegisterPairLow<Register>(), |
| 1165 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1166 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1167 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1168 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1169 | } else { |
| 1170 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1171 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1172 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1173 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 1174 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1175 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 1176 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1177 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1178 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1179 | SP, destination.GetStackIndex()); |
| 1180 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1181 | } else if (source.IsFpuRegisterPair()) { |
| 1182 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 1183 | SP, |
| 1184 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1185 | } else { |
| 1186 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1187 | EmitParallelMoves( |
| 1188 | Location::StackSlot(source.GetStackIndex()), |
| 1189 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1190 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1191 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1192 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 1193 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1194 | } |
| 1195 | } |
| 1196 | } |
| 1197 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1198 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 1199 | DCHECK(location.IsRegister()); |
| 1200 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 1201 | } |
| 1202 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1203 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1204 | HParallelMove move(GetGraph()->GetArena()); |
| 1205 | move.AddMove(src, dst, dst_type, nullptr); |
| 1206 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1210 | if (location.IsRegister()) { |
| 1211 | locations->AddTemp(location); |
| 1212 | } else if (location.IsRegisterPair()) { |
| 1213 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1214 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1215 | } else { |
| 1216 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1217 | } |
| 1218 | } |
| 1219 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1220 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1221 | HInstruction* instruction, |
| 1222 | uint32_t dex_pc, |
| 1223 | SlowPathCode* slow_path) { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1224 | InvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value(), |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1225 | instruction, |
| 1226 | dex_pc, |
| 1227 | slow_path); |
| 1228 | } |
| 1229 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1230 | void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset, |
| 1231 | HInstruction* instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1232 | uint32_t dex_pc, |
| 1233 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1234 | ValidateInvokeRuntime(instruction, slow_path); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1235 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 1236 | __ blx(LR); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1237 | RecordPcInfo(instruction, dex_pc, slow_path); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1238 | } |
| 1239 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1240 | void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1241 | HInstruction* instruction, |
| 1242 | SlowPathCode* slow_path) { |
| 1243 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| 1244 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 1245 | __ blx(LR); |
| 1246 | } |
| 1247 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1248 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1249 | DCHECK(!successor->IsExitBlock()); |
| 1250 | |
| 1251 | HBasicBlock* block = got->GetBlock(); |
| 1252 | HInstruction* previous = got->GetPrevious(); |
| 1253 | |
| 1254 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1255 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1256 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 1257 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1258 | return; |
| 1259 | } |
| 1260 | |
| 1261 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1262 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1263 | } |
| 1264 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1265 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1266 | } |
| 1267 | } |
| 1268 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1269 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 1270 | got->SetLocations(nullptr); |
| 1271 | } |
| 1272 | |
| 1273 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 1274 | HandleGoto(got, got->GetSuccessor()); |
| 1275 | } |
| 1276 | |
| 1277 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1278 | try_boundary->SetLocations(nullptr); |
| 1279 | } |
| 1280 | |
| 1281 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1282 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1283 | if (!successor->IsExitBlock()) { |
| 1284 | HandleGoto(try_boundary, successor); |
| 1285 | } |
| 1286 | } |
| 1287 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1288 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1289 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1290 | } |
| 1291 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1292 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1293 | } |
| 1294 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1295 | void InstructionCodeGeneratorARM::GenerateVcmp(HInstruction* instruction) { |
| 1296 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 1297 | Location lhs_loc = instruction->GetLocations()->InAt(0); |
| 1298 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1299 | if (rhs_loc.IsConstant()) { |
| 1300 | // 0.0 is the only immediate that can be encoded directly in |
| 1301 | // a VCMP instruction. |
| 1302 | // |
| 1303 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1304 | // specify that in a floating-point comparison, positive zero |
| 1305 | // and negative zero are considered equal, so we can use the |
| 1306 | // literal 0.0 for both cases here. |
| 1307 | // |
| 1308 | // Note however that some methods (Float.equal, Float.compare, |
| 1309 | // Float.compareTo, Double.equal, Double.compare, |
| 1310 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1311 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1312 | // -0.0. So if we ever translate calls to these methods into a |
| 1313 | // HCompare instruction, we must handle the -0.0 case with |
| 1314 | // care here. |
| 1315 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1316 | if (type == Primitive::kPrimFloat) { |
| 1317 | __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>()); |
| 1318 | } else { |
| 1319 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1320 | __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1321 | } |
| 1322 | } else { |
| 1323 | if (type == Primitive::kPrimFloat) { |
| 1324 | __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>()); |
| 1325 | } else { |
| 1326 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1327 | __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()), |
| 1328 | FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1329 | } |
| 1330 | } |
| 1331 | } |
| 1332 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1333 | void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond, |
| 1334 | Label* true_label, |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1335 | Label* false_label ATTRIBUTE_UNUSED) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1336 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1337 | __ b(true_label, ARMFPCondition(cond->GetCondition(), cond->IsGtBias())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 1341 | Label* true_label, |
| 1342 | Label* false_label) { |
| 1343 | LocationSummary* locations = cond->GetLocations(); |
| 1344 | Location left = locations->InAt(0); |
| 1345 | Location right = locations->InAt(1); |
| 1346 | IfCondition if_cond = cond->GetCondition(); |
| 1347 | |
| 1348 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1349 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 1350 | IfCondition true_high_cond = if_cond; |
| 1351 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1352 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1353 | |
| 1354 | // Set the conditions for the test, remembering that == needs to be |
| 1355 | // decided using the low words. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1356 | // TODO: consider avoiding jumps with temporary and CMP low+SBC high |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1357 | switch (if_cond) { |
| 1358 | case kCondEQ: |
| 1359 | case kCondNE: |
| 1360 | // Nothing to do. |
| 1361 | break; |
| 1362 | case kCondLT: |
| 1363 | false_high_cond = kCondGT; |
| 1364 | break; |
| 1365 | case kCondLE: |
| 1366 | true_high_cond = kCondLT; |
| 1367 | break; |
| 1368 | case kCondGT: |
| 1369 | false_high_cond = kCondLT; |
| 1370 | break; |
| 1371 | case kCondGE: |
| 1372 | true_high_cond = kCondGT; |
| 1373 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1374 | case kCondB: |
| 1375 | false_high_cond = kCondA; |
| 1376 | break; |
| 1377 | case kCondBE: |
| 1378 | true_high_cond = kCondB; |
| 1379 | break; |
| 1380 | case kCondA: |
| 1381 | false_high_cond = kCondB; |
| 1382 | break; |
| 1383 | case kCondAE: |
| 1384 | true_high_cond = kCondA; |
| 1385 | break; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1386 | } |
| 1387 | if (right.IsConstant()) { |
| 1388 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1389 | int32_t val_low = Low32Bits(value); |
| 1390 | int32_t val_high = High32Bits(value); |
| 1391 | |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1392 | __ CmpConstant(left_high, val_high); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1393 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1394 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1395 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1396 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1397 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1398 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1399 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1400 | } |
| 1401 | // Must be equal high, so compare the lows. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1402 | __ CmpConstant(left_low, val_low); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1403 | } else { |
| 1404 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 1405 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 1406 | |
| 1407 | __ cmp(left_high, ShifterOperand(right_high)); |
| 1408 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1409 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1410 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1411 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1412 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1413 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1414 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1415 | } |
| 1416 | // Must be equal high, so compare the lows. |
| 1417 | __ cmp(left_low, ShifterOperand(right_low)); |
| 1418 | } |
| 1419 | // The last comparison might be unsigned. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1420 | // TODO: optimize cases where this is always true/false |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1421 | __ b(true_label, final_condition); |
| 1422 | } |
| 1423 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1424 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition, |
| 1425 | Label* true_target_in, |
| 1426 | Label* false_target_in) { |
| 1427 | // Generated branching requires both targets to be explicit. If either of the |
| 1428 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1429 | Label fallthrough_target; |
| 1430 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1431 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1432 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1433 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1434 | switch (type) { |
| 1435 | case Primitive::kPrimLong: |
| 1436 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1437 | break; |
| 1438 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1439 | case Primitive::kPrimDouble: |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1440 | GenerateVcmp(condition); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1441 | GenerateFPJumps(condition, true_target, false_target); |
| 1442 | break; |
| 1443 | default: |
| 1444 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1445 | } |
| 1446 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1447 | if (false_target != &fallthrough_target) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1448 | __ b(false_target); |
| 1449 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1450 | |
| 1451 | if (fallthrough_target.IsLinked()) { |
| 1452 | __ Bind(&fallthrough_target); |
| 1453 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1454 | } |
| 1455 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1456 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1457 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1458 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1459 | Label* false_target) { |
| 1460 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1461 | |
| 1462 | if (true_target == nullptr && false_target == nullptr) { |
| 1463 | // Nothing to do. The code always falls through. |
| 1464 | return; |
| 1465 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1466 | // Constant condition, statically compared against "true" (integer value 1). |
| 1467 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1468 | if (true_target != nullptr) { |
| 1469 | __ b(true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1470 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1471 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1472 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1473 | if (false_target != nullptr) { |
| 1474 | __ b(false_target); |
| 1475 | } |
| 1476 | } |
| 1477 | return; |
| 1478 | } |
| 1479 | |
| 1480 | // The following code generates these patterns: |
| 1481 | // (1) true_target == nullptr && false_target != nullptr |
| 1482 | // - opposite condition true => branch to false_target |
| 1483 | // (2) true_target != nullptr && false_target == nullptr |
| 1484 | // - condition true => branch to true_target |
| 1485 | // (3) true_target != nullptr && false_target != nullptr |
| 1486 | // - condition true => branch to true_target |
| 1487 | // - branch to false_target |
| 1488 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1489 | // Condition has been materialized, compare the output to 0. |
| 1490 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 1491 | DCHECK(cond_val.IsRegister()); |
| 1492 | if (true_target == nullptr) { |
| 1493 | __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target); |
| 1494 | } else { |
| 1495 | __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1496 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1497 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1498 | // Condition has not been materialized. Use its inputs as the comparison and |
| 1499 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1500 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1501 | |
| 1502 | // If this is a long or FP comparison that has been folded into |
| 1503 | // the HCondition, generate the comparison directly. |
| 1504 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1505 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1506 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1507 | return; |
| 1508 | } |
| 1509 | |
| 1510 | LocationSummary* locations = cond->GetLocations(); |
| 1511 | DCHECK(locations->InAt(0).IsRegister()); |
| 1512 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 1513 | Location right = locations->InAt(1); |
| 1514 | if (right.IsRegister()) { |
| 1515 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1516 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1517 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1518 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1519 | } |
| 1520 | if (true_target == nullptr) { |
| 1521 | __ b(false_target, ARMCondition(condition->GetOppositeCondition())); |
| 1522 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1523 | __ b(true_target, ARMCondition(condition->GetCondition())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1524 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1525 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1526 | |
| 1527 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1528 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1529 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1530 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1531 | } |
| 1532 | } |
| 1533 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1534 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1535 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1536 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1537 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1538 | } |
| 1539 | } |
| 1540 | |
| 1541 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1542 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1543 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1544 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1545 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1546 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1547 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1548 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1549 | } |
| 1550 | |
| 1551 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1552 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1553 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1554 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1555 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1556 | } |
| 1557 | } |
| 1558 | |
| 1559 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1560 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1561 | GenerateTestAndBranch(deoptimize, |
| 1562 | /* condition_input_index */ 0, |
| 1563 | slow_path->GetEntryLabel(), |
| 1564 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1565 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1566 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1567 | void LocationsBuilderARM::VisitSelect(HSelect* select) { |
| 1568 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1569 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1570 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1571 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1572 | } else { |
| 1573 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1574 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1575 | } |
| 1576 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1577 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1578 | } |
| 1579 | locations->SetOut(Location::SameAsFirstInput()); |
| 1580 | } |
| 1581 | |
| 1582 | void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) { |
| 1583 | LocationSummary* locations = select->GetLocations(); |
| 1584 | Label false_target; |
| 1585 | GenerateTestAndBranch(select, |
| 1586 | /* condition_input_index */ 2, |
| 1587 | /* true_target */ nullptr, |
| 1588 | &false_target); |
| 1589 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1590 | __ Bind(&false_target); |
| 1591 | } |
| 1592 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1593 | void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1594 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1595 | } |
| 1596 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1597 | void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1598 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | void CodeGeneratorARM::GenerateNop() { |
| 1602 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1603 | } |
| 1604 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1605 | void LocationsBuilderARM::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1606 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1607 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1608 | // Handle the long/FP comparisons made in instruction simplification. |
| 1609 | switch (cond->InputAt(0)->GetType()) { |
| 1610 | case Primitive::kPrimLong: |
| 1611 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1612 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1613 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1614 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 1615 | } |
| 1616 | break; |
| 1617 | |
| 1618 | case Primitive::kPrimFloat: |
| 1619 | case Primitive::kPrimDouble: |
| 1620 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1621 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1622 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1623 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1624 | } |
| 1625 | break; |
| 1626 | |
| 1627 | default: |
| 1628 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1629 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1630 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1631 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1632 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1633 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1634 | } |
| 1635 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1636 | void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1637 | if (cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1638 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1639 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1640 | |
| 1641 | LocationSummary* locations = cond->GetLocations(); |
| 1642 | Location left = locations->InAt(0); |
| 1643 | Location right = locations->InAt(1); |
| 1644 | Register out = locations->Out().AsRegister<Register>(); |
| 1645 | Label true_label, false_label; |
| 1646 | |
| 1647 | switch (cond->InputAt(0)->GetType()) { |
| 1648 | default: { |
| 1649 | // Integer case. |
| 1650 | if (right.IsRegister()) { |
| 1651 | __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>())); |
| 1652 | } else { |
| 1653 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1654 | __ CmpConstant(left.AsRegister<Register>(), |
| 1655 | CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1656 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1657 | __ it(ARMCondition(cond->GetCondition()), kItElse); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1658 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1659 | ARMCondition(cond->GetCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1660 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1661 | ARMCondition(cond->GetOppositeCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1662 | return; |
| 1663 | } |
| 1664 | case Primitive::kPrimLong: |
| 1665 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1666 | break; |
| 1667 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1668 | case Primitive::kPrimDouble: |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1669 | GenerateVcmp(cond); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1670 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1671 | break; |
| 1672 | } |
| 1673 | |
| 1674 | // Convert the jumps into the result. |
| 1675 | Label done_label; |
| 1676 | |
| 1677 | // False case: result = 0. |
| 1678 | __ Bind(&false_label); |
| 1679 | __ LoadImmediate(out, 0); |
| 1680 | __ b(&done_label); |
| 1681 | |
| 1682 | // True case: result = 1. |
| 1683 | __ Bind(&true_label); |
| 1684 | __ LoadImmediate(out, 1); |
| 1685 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1686 | } |
| 1687 | |
| 1688 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1689 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1690 | } |
| 1691 | |
| 1692 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1693 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1694 | } |
| 1695 | |
| 1696 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1697 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1701 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1702 | } |
| 1703 | |
| 1704 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1705 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1706 | } |
| 1707 | |
| 1708 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1709 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1710 | } |
| 1711 | |
| 1712 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1713 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1717 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1718 | } |
| 1719 | |
| 1720 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1721 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1722 | } |
| 1723 | |
| 1724 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1725 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1729 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1730 | } |
| 1731 | |
| 1732 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1733 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1734 | } |
| 1735 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1736 | void LocationsBuilderARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1737 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1741 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1742 | } |
| 1743 | |
| 1744 | void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1745 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1746 | } |
| 1747 | |
| 1748 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1749 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1753 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1757 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1761 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1762 | } |
| 1763 | |
| 1764 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1765 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1766 | } |
| 1767 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1768 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1769 | LocationSummary* locations = |
| 1770 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1771 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1772 | } |
| 1773 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1774 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1775 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1776 | } |
| 1777 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1778 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 1779 | LocationSummary* locations = |
| 1780 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1781 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1782 | } |
| 1783 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1784 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1785 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1786 | } |
| 1787 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1788 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1789 | LocationSummary* locations = |
| 1790 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1791 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1792 | } |
| 1793 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1794 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1795 | // Will be generated at use site. |
| 1796 | } |
| 1797 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1798 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 1799 | LocationSummary* locations = |
| 1800 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1801 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1802 | } |
| 1803 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1804 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1805 | // Will be generated at use site. |
| 1806 | } |
| 1807 | |
| 1808 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1809 | LocationSummary* locations = |
| 1810 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1811 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1812 | } |
| 1813 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1814 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1815 | // Will be generated at use site. |
| 1816 | } |
| 1817 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1818 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1819 | memory_barrier->SetLocations(nullptr); |
| 1820 | } |
| 1821 | |
| 1822 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1823 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1824 | } |
| 1825 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1826 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1827 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1828 | } |
| 1829 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1830 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1831 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1832 | } |
| 1833 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1834 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1835 | LocationSummary* locations = |
| 1836 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1837 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1838 | } |
| 1839 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1840 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1841 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1842 | } |
| 1843 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1844 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1845 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1846 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1847 | // the method_idx. |
| 1848 | HandleInvoke(invoke); |
| 1849 | } |
| 1850 | |
| 1851 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1852 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1853 | } |
| 1854 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1855 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1856 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1857 | // art::PrepareForRegisterAllocation. |
| 1858 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1859 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1860 | IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(), |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1861 | codegen_->GetAssembler(), |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1862 | codegen_->GetInstructionSetFeatures()); |
| 1863 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1864 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 1865 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 1866 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1867 | return; |
| 1868 | } |
| 1869 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1870 | HandleInvoke(invoke); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1871 | |
| 1872 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 1873 | if (invoke->HasPcRelativeDexCache()) { |
| 1874 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 1875 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1876 | } |
| 1877 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1878 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 1879 | if (invoke->GetLocations()->Intrinsified()) { |
| 1880 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 1881 | intrinsic.Dispatch(invoke); |
| 1882 | return true; |
| 1883 | } |
| 1884 | return false; |
| 1885 | } |
| 1886 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1887 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1888 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1889 | // art::PrepareForRegisterAllocation. |
| 1890 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1891 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1892 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1893 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1894 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1895 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1896 | LocationSummary* locations = invoke->GetLocations(); |
| 1897 | codegen_->GenerateStaticOrDirectCall( |
| 1898 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 1899 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1900 | } |
| 1901 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1902 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1903 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1904 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1905 | } |
| 1906 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1907 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1908 | IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(), |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1909 | codegen_->GetAssembler(), |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1910 | codegen_->GetInstructionSetFeatures()); |
| 1911 | if (intrinsic.TryDispatch(invoke)) { |
| 1912 | return; |
| 1913 | } |
| 1914 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1915 | HandleInvoke(invoke); |
| 1916 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1917 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1918 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1919 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1920 | return; |
| 1921 | } |
| 1922 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1923 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1924 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1925 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1926 | } |
| 1927 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1928 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1929 | HandleInvoke(invoke); |
| 1930 | // Add the hidden argument. |
| 1931 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 1932 | } |
| 1933 | |
| 1934 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1935 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1936 | LocationSummary* locations = invoke->GetLocations(); |
| 1937 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 1938 | Register hidden_reg = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1939 | Location receiver = locations->InAt(0); |
| 1940 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1941 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1942 | // Set the hidden argument. This is safe to do this here, as R12 |
| 1943 | // won't be modified thereafter, before the `blx` (call) instruction. |
| 1944 | DCHECK_EQ(R12, hidden_reg); |
| 1945 | __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1946 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1947 | if (receiver.IsStackSlot()) { |
| 1948 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1949 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1950 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 1951 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1952 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1953 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1954 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1955 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1956 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 1957 | // emit a read barrier for the previous class reference load. |
| 1958 | // However this is not required in practice, as this is an |
| 1959 | // intermediate/temporary reference and because the current |
| 1960 | // concurrent copying collector keeps the from-space memory |
| 1961 | // intact/accessible until the end of the marking phase (the |
| 1962 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1963 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 1964 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 1965 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 1966 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 1967 | invoke->GetImtIndex(), kArmPointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1968 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 1969 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1970 | uint32_t entry_point = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1971 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1972 | // LR = temp->GetEntryPoint(); |
| 1973 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 1974 | // LR(); |
| 1975 | __ blx(LR); |
| 1976 | DCHECK(!codegen_->IsLeafMethod()); |
| 1977 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1978 | } |
| 1979 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1980 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 1981 | LocationSummary* locations = |
| 1982 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1983 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 1984 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1985 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 1986 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1987 | break; |
| 1988 | } |
| 1989 | case Primitive::kPrimLong: { |
| 1990 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1991 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1992 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1993 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1994 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1995 | case Primitive::kPrimFloat: |
| 1996 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1997 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1998 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1999 | break; |
| 2000 | |
| 2001 | default: |
| 2002 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2003 | } |
| 2004 | } |
| 2005 | |
| 2006 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 2007 | LocationSummary* locations = neg->GetLocations(); |
| 2008 | Location out = locations->Out(); |
| 2009 | Location in = locations->InAt(0); |
| 2010 | switch (neg->GetResultType()) { |
| 2011 | case Primitive::kPrimInt: |
| 2012 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2013 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2014 | break; |
| 2015 | |
| 2016 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2017 | DCHECK(in.IsRegisterPair()); |
| 2018 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 2019 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 2020 | in.AsRegisterPairLow<Register>(), |
| 2021 | ShifterOperand(0)); |
| 2022 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 2023 | // instruction here, as it does not exist in the Thumb-2 |
| 2024 | // instruction set. We use the following approach |
| 2025 | // using SBC and SUB instead. |
| 2026 | // |
| 2027 | // out.hi = -C |
| 2028 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2029 | out.AsRegisterPairHigh<Register>(), |
| 2030 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 2031 | // out.hi = out.hi - in.hi |
| 2032 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 2033 | out.AsRegisterPairHigh<Register>(), |
| 2034 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 2035 | break; |
| 2036 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2037 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2038 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2039 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2040 | break; |
| 2041 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2042 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2043 | DCHECK(in.IsFpuRegisterPair()); |
| 2044 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2045 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2046 | break; |
| 2047 | |
| 2048 | default: |
| 2049 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2050 | } |
| 2051 | } |
| 2052 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2053 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2054 | Primitive::Type result_type = conversion->GetResultType(); |
| 2055 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2056 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2057 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2058 | // The float-to-long, double-to-long and long-to-float type conversions |
| 2059 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2060 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2061 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2062 | && result_type == Primitive::kPrimLong) |
| 2063 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2064 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2065 | : LocationSummary::kNoCall; |
| 2066 | LocationSummary* locations = |
| 2067 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2068 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2069 | // The Java language does not allow treating boolean as an integral type but |
| 2070 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2071 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2072 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2073 | case Primitive::kPrimByte: |
| 2074 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2075 | case Primitive::kPrimLong: |
| 2076 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2077 | case Primitive::kPrimBoolean: |
| 2078 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2079 | case Primitive::kPrimShort: |
| 2080 | case Primitive::kPrimInt: |
| 2081 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2082 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2083 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2084 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2085 | break; |
| 2086 | |
| 2087 | default: |
| 2088 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2089 | << " to " << result_type; |
| 2090 | } |
| 2091 | break; |
| 2092 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2093 | case Primitive::kPrimShort: |
| 2094 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2095 | case Primitive::kPrimLong: |
| 2096 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2097 | case Primitive::kPrimBoolean: |
| 2098 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2099 | case Primitive::kPrimByte: |
| 2100 | case Primitive::kPrimInt: |
| 2101 | case Primitive::kPrimChar: |
| 2102 | // Processing a Dex `int-to-short' instruction. |
| 2103 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2104 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2105 | break; |
| 2106 | |
| 2107 | default: |
| 2108 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2109 | << " to " << result_type; |
| 2110 | } |
| 2111 | break; |
| 2112 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2113 | case Primitive::kPrimInt: |
| 2114 | switch (input_type) { |
| 2115 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2116 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2117 | locations->SetInAt(0, Location::Any()); |
| 2118 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2119 | break; |
| 2120 | |
| 2121 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2122 | // Processing a Dex `float-to-int' instruction. |
| 2123 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2124 | locations->SetOut(Location::RequiresRegister()); |
| 2125 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2126 | break; |
| 2127 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2128 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2129 | // Processing a Dex `double-to-int' instruction. |
| 2130 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2131 | locations->SetOut(Location::RequiresRegister()); |
| 2132 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2133 | break; |
| 2134 | |
| 2135 | default: |
| 2136 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2137 | << " to " << result_type; |
| 2138 | } |
| 2139 | break; |
| 2140 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2141 | case Primitive::kPrimLong: |
| 2142 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2143 | case Primitive::kPrimBoolean: |
| 2144 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2145 | case Primitive::kPrimByte: |
| 2146 | case Primitive::kPrimShort: |
| 2147 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2148 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2149 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2150 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2151 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2152 | break; |
| 2153 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2154 | case Primitive::kPrimFloat: { |
| 2155 | // Processing a Dex `float-to-long' instruction. |
| 2156 | InvokeRuntimeCallingConvention calling_convention; |
| 2157 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 2158 | calling_convention.GetFpuRegisterAt(0))); |
| 2159 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 2160 | break; |
| 2161 | } |
| 2162 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2163 | case Primitive::kPrimDouble: { |
| 2164 | // Processing a Dex `double-to-long' instruction. |
| 2165 | InvokeRuntimeCallingConvention calling_convention; |
| 2166 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 2167 | calling_convention.GetFpuRegisterAt(0), |
| 2168 | calling_convention.GetFpuRegisterAt(1))); |
| 2169 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2170 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2171 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2172 | |
| 2173 | default: |
| 2174 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2175 | << " to " << result_type; |
| 2176 | } |
| 2177 | break; |
| 2178 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2179 | case Primitive::kPrimChar: |
| 2180 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2181 | case Primitive::kPrimLong: |
| 2182 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2183 | case Primitive::kPrimBoolean: |
| 2184 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2185 | case Primitive::kPrimByte: |
| 2186 | case Primitive::kPrimShort: |
| 2187 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2188 | // Processing a Dex `int-to-char' instruction. |
| 2189 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2190 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2191 | break; |
| 2192 | |
| 2193 | default: |
| 2194 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2195 | << " to " << result_type; |
| 2196 | } |
| 2197 | break; |
| 2198 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2199 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2200 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2201 | case Primitive::kPrimBoolean: |
| 2202 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2203 | case Primitive::kPrimByte: |
| 2204 | case Primitive::kPrimShort: |
| 2205 | case Primitive::kPrimInt: |
| 2206 | case Primitive::kPrimChar: |
| 2207 | // Processing a Dex `int-to-float' instruction. |
| 2208 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2209 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2210 | break; |
| 2211 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2212 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2213 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2214 | InvokeRuntimeCallingConvention calling_convention; |
| 2215 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2216 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2217 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2218 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2219 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2220 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2221 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2222 | // Processing a Dex `double-to-float' instruction. |
| 2223 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2224 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2225 | break; |
| 2226 | |
| 2227 | default: |
| 2228 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2229 | << " to " << result_type; |
| 2230 | }; |
| 2231 | break; |
| 2232 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2233 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2234 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2235 | case Primitive::kPrimBoolean: |
| 2236 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2237 | case Primitive::kPrimByte: |
| 2238 | case Primitive::kPrimShort: |
| 2239 | case Primitive::kPrimInt: |
| 2240 | case Primitive::kPrimChar: |
| 2241 | // Processing a Dex `int-to-double' instruction. |
| 2242 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2243 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2244 | break; |
| 2245 | |
| 2246 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2247 | // Processing a Dex `long-to-double' instruction. |
| 2248 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2249 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2250 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2251 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2252 | break; |
| 2253 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2254 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2255 | // Processing a Dex `float-to-double' instruction. |
| 2256 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2257 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2258 | break; |
| 2259 | |
| 2260 | default: |
| 2261 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2262 | << " to " << result_type; |
| 2263 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2264 | break; |
| 2265 | |
| 2266 | default: |
| 2267 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2268 | << " to " << result_type; |
| 2269 | } |
| 2270 | } |
| 2271 | |
| 2272 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 2273 | LocationSummary* locations = conversion->GetLocations(); |
| 2274 | Location out = locations->Out(); |
| 2275 | Location in = locations->InAt(0); |
| 2276 | Primitive::Type result_type = conversion->GetResultType(); |
| 2277 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2278 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2279 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2280 | case Primitive::kPrimByte: |
| 2281 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2282 | case Primitive::kPrimLong: |
| 2283 | // Type conversion from long to byte is a result of code transformations. |
| 2284 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8); |
| 2285 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2286 | case Primitive::kPrimBoolean: |
| 2287 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2288 | case Primitive::kPrimShort: |
| 2289 | case Primitive::kPrimInt: |
| 2290 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2291 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2292 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2293 | break; |
| 2294 | |
| 2295 | default: |
| 2296 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2297 | << " to " << result_type; |
| 2298 | } |
| 2299 | break; |
| 2300 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2301 | case Primitive::kPrimShort: |
| 2302 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2303 | case Primitive::kPrimLong: |
| 2304 | // Type conversion from long to short is a result of code transformations. |
| 2305 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 2306 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2307 | case Primitive::kPrimBoolean: |
| 2308 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2309 | case Primitive::kPrimByte: |
| 2310 | case Primitive::kPrimInt: |
| 2311 | case Primitive::kPrimChar: |
| 2312 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2313 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2314 | break; |
| 2315 | |
| 2316 | default: |
| 2317 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2318 | << " to " << result_type; |
| 2319 | } |
| 2320 | break; |
| 2321 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2322 | case Primitive::kPrimInt: |
| 2323 | switch (input_type) { |
| 2324 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2325 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2326 | DCHECK(out.IsRegister()); |
| 2327 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2328 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2329 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2330 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2331 | } else { |
| 2332 | DCHECK(in.IsConstant()); |
| 2333 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2334 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2335 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2336 | } |
| 2337 | break; |
| 2338 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2339 | case Primitive::kPrimFloat: { |
| 2340 | // Processing a Dex `float-to-int' instruction. |
| 2341 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2342 | __ vcvtis(temp, in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2343 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 2344 | break; |
| 2345 | } |
| 2346 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2347 | case Primitive::kPrimDouble: { |
| 2348 | // Processing a Dex `double-to-int' instruction. |
| 2349 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2350 | __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2351 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2352 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2353 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2354 | |
| 2355 | default: |
| 2356 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2357 | << " to " << result_type; |
| 2358 | } |
| 2359 | break; |
| 2360 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2361 | case Primitive::kPrimLong: |
| 2362 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2363 | case Primitive::kPrimBoolean: |
| 2364 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2365 | case Primitive::kPrimByte: |
| 2366 | case Primitive::kPrimShort: |
| 2367 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2368 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2369 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2370 | DCHECK(out.IsRegisterPair()); |
| 2371 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2372 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2373 | // Sign extension. |
| 2374 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 2375 | out.AsRegisterPairLow<Register>(), |
| 2376 | 31); |
| 2377 | break; |
| 2378 | |
| 2379 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2380 | // Processing a Dex `float-to-long' instruction. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2381 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2382 | conversion, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2383 | conversion->GetDexPc(), |
| 2384 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2385 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2386 | break; |
| 2387 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2388 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2389 | // Processing a Dex `double-to-long' instruction. |
| 2390 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2391 | conversion, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2392 | conversion->GetDexPc(), |
| 2393 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2394 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2395 | break; |
| 2396 | |
| 2397 | default: |
| 2398 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2399 | << " to " << result_type; |
| 2400 | } |
| 2401 | break; |
| 2402 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2403 | case Primitive::kPrimChar: |
| 2404 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2405 | case Primitive::kPrimLong: |
| 2406 | // Type conversion from long to char is a result of code transformations. |
| 2407 | __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 2408 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2409 | case Primitive::kPrimBoolean: |
| 2410 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2411 | case Primitive::kPrimByte: |
| 2412 | case Primitive::kPrimShort: |
| 2413 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2414 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2415 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2416 | break; |
| 2417 | |
| 2418 | default: |
| 2419 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2420 | << " to " << result_type; |
| 2421 | } |
| 2422 | break; |
| 2423 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2424 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2425 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2426 | case Primitive::kPrimBoolean: |
| 2427 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2428 | case Primitive::kPrimByte: |
| 2429 | case Primitive::kPrimShort: |
| 2430 | case Primitive::kPrimInt: |
| 2431 | case Primitive::kPrimChar: { |
| 2432 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2433 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 2434 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2435 | break; |
| 2436 | } |
| 2437 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2438 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2439 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2440 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f), |
| 2441 | conversion, |
| 2442 | conversion->GetDexPc(), |
| 2443 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2444 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2445 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2446 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2447 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2448 | // Processing a Dex `double-to-float' instruction. |
| 2449 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 2450 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2451 | break; |
| 2452 | |
| 2453 | default: |
| 2454 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2455 | << " to " << result_type; |
| 2456 | }; |
| 2457 | break; |
| 2458 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2459 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2460 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2461 | case Primitive::kPrimBoolean: |
| 2462 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2463 | case Primitive::kPrimByte: |
| 2464 | case Primitive::kPrimShort: |
| 2465 | case Primitive::kPrimInt: |
| 2466 | case Primitive::kPrimChar: { |
| 2467 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2468 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2469 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2470 | out.AsFpuRegisterPairLow<SRegister>()); |
| 2471 | break; |
| 2472 | } |
| 2473 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2474 | case Primitive::kPrimLong: { |
| 2475 | // Processing a Dex `long-to-double' instruction. |
| 2476 | Register low = in.AsRegisterPairLow<Register>(); |
| 2477 | Register high = in.AsRegisterPairHigh<Register>(); |
| 2478 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 2479 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2480 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2481 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2482 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 2483 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2484 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2485 | // temp_d = int-to-double(high) |
| 2486 | __ vmovsr(temp_s, high); |
| 2487 | __ vcvtdi(temp_d, temp_s); |
| 2488 | // constant_d = k2Pow32EncodingForDouble |
| 2489 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 2490 | // out_d = unsigned-to-double(low) |
| 2491 | __ vmovsr(out_s, low); |
| 2492 | __ vcvtdu(out_d, out_s); |
| 2493 | // out_d += temp_d * constant_d |
| 2494 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2495 | break; |
| 2496 | } |
| 2497 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2498 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2499 | // Processing a Dex `float-to-double' instruction. |
| 2500 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2501 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2502 | break; |
| 2503 | |
| 2504 | default: |
| 2505 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2506 | << " to " << result_type; |
| 2507 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2508 | break; |
| 2509 | |
| 2510 | default: |
| 2511 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2512 | << " to " << result_type; |
| 2513 | } |
| 2514 | } |
| 2515 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2516 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2517 | LocationSummary* locations = |
| 2518 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2519 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2520 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2521 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2522 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2523 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2524 | break; |
| 2525 | } |
| 2526 | |
| 2527 | case Primitive::kPrimLong: { |
| 2528 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2529 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2530 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2531 | break; |
| 2532 | } |
| 2533 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2534 | case Primitive::kPrimFloat: |
| 2535 | case Primitive::kPrimDouble: { |
| 2536 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2537 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2538 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2539 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2540 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2541 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2542 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2543 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2544 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2545 | } |
| 2546 | |
| 2547 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 2548 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2549 | Location out = locations->Out(); |
| 2550 | Location first = locations->InAt(0); |
| 2551 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2552 | switch (add->GetResultType()) { |
| 2553 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2554 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2555 | __ add(out.AsRegister<Register>(), |
| 2556 | first.AsRegister<Register>(), |
| 2557 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2558 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2559 | __ AddConstant(out.AsRegister<Register>(), |
| 2560 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2561 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2562 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2563 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2564 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2565 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2566 | if (second.IsConstant()) { |
| 2567 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 2568 | GenerateAddLongConst(out, first, value); |
| 2569 | } else { |
| 2570 | DCHECK(second.IsRegisterPair()); |
| 2571 | __ adds(out.AsRegisterPairLow<Register>(), |
| 2572 | first.AsRegisterPairLow<Register>(), |
| 2573 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2574 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 2575 | first.AsRegisterPairHigh<Register>(), |
| 2576 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 2577 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2578 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2579 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2580 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2581 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2582 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 2583 | first.AsFpuRegister<SRegister>(), |
| 2584 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2585 | break; |
| 2586 | |
| 2587 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2588 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2589 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2590 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2591 | break; |
| 2592 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2593 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2594 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2595 | } |
| 2596 | } |
| 2597 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2598 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2599 | LocationSummary* locations = |
| 2600 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2601 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2602 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2603 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2604 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2605 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2606 | break; |
| 2607 | } |
| 2608 | |
| 2609 | case Primitive::kPrimLong: { |
| 2610 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2611 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2612 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2613 | break; |
| 2614 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2615 | case Primitive::kPrimFloat: |
| 2616 | case Primitive::kPrimDouble: { |
| 2617 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2618 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2619 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2620 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2621 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2622 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2623 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2624 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2625 | } |
| 2626 | |
| 2627 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 2628 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2629 | Location out = locations->Out(); |
| 2630 | Location first = locations->InAt(0); |
| 2631 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2632 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2633 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2634 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2635 | __ sub(out.AsRegister<Register>(), |
| 2636 | first.AsRegister<Register>(), |
| 2637 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2638 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2639 | __ AddConstant(out.AsRegister<Register>(), |
| 2640 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2641 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2642 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2643 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2644 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2645 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2646 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2647 | if (second.IsConstant()) { |
| 2648 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 2649 | GenerateAddLongConst(out, first, -value); |
| 2650 | } else { |
| 2651 | DCHECK(second.IsRegisterPair()); |
| 2652 | __ subs(out.AsRegisterPairLow<Register>(), |
| 2653 | first.AsRegisterPairLow<Register>(), |
| 2654 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2655 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2656 | first.AsRegisterPairHigh<Register>(), |
| 2657 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 2658 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2659 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2660 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2661 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2662 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2663 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 2664 | first.AsFpuRegister<SRegister>(), |
| 2665 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2666 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2667 | } |
| 2668 | |
| 2669 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2670 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2671 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2672 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2673 | break; |
| 2674 | } |
| 2675 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2676 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2677 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2678 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2679 | } |
| 2680 | } |
| 2681 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2682 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 2683 | LocationSummary* locations = |
| 2684 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2685 | switch (mul->GetResultType()) { |
| 2686 | case Primitive::kPrimInt: |
| 2687 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2688 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2689 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2690 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2691 | break; |
| 2692 | } |
| 2693 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2694 | case Primitive::kPrimFloat: |
| 2695 | case Primitive::kPrimDouble: { |
| 2696 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2697 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2698 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2699 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2700 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2701 | |
| 2702 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2703 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2704 | } |
| 2705 | } |
| 2706 | |
| 2707 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 2708 | LocationSummary* locations = mul->GetLocations(); |
| 2709 | Location out = locations->Out(); |
| 2710 | Location first = locations->InAt(0); |
| 2711 | Location second = locations->InAt(1); |
| 2712 | switch (mul->GetResultType()) { |
| 2713 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2714 | __ mul(out.AsRegister<Register>(), |
| 2715 | first.AsRegister<Register>(), |
| 2716 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2717 | break; |
| 2718 | } |
| 2719 | case Primitive::kPrimLong: { |
| 2720 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 2721 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 2722 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2723 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 2724 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2725 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2726 | |
| 2727 | // Extra checks to protect caused by the existence of R1_R2. |
| 2728 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 2729 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 2730 | DCHECK_NE(out_hi, in1_lo); |
| 2731 | DCHECK_NE(out_hi, in2_lo); |
| 2732 | |
| 2733 | // input: in1 - 64 bits, in2 - 64 bits |
| 2734 | // output: out |
| 2735 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2736 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2737 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 2738 | |
| 2739 | // IP <- in1.lo * in2.hi |
| 2740 | __ mul(IP, in1_lo, in2_hi); |
| 2741 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2742 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 2743 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 2744 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 2745 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2746 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 2747 | break; |
| 2748 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2749 | |
| 2750 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2751 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 2752 | first.AsFpuRegister<SRegister>(), |
| 2753 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2754 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2755 | } |
| 2756 | |
| 2757 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2758 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2759 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2760 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2761 | break; |
| 2762 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2763 | |
| 2764 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2765 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2766 | } |
| 2767 | } |
| 2768 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2769 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2770 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2771 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2772 | |
| 2773 | LocationSummary* locations = instruction->GetLocations(); |
| 2774 | Location second = locations->InAt(1); |
| 2775 | DCHECK(second.IsConstant()); |
| 2776 | |
| 2777 | Register out = locations->Out().AsRegister<Register>(); |
| 2778 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2779 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2780 | DCHECK(imm == 1 || imm == -1); |
| 2781 | |
| 2782 | if (instruction->IsRem()) { |
| 2783 | __ LoadImmediate(out, 0); |
| 2784 | } else { |
| 2785 | if (imm == 1) { |
| 2786 | __ Mov(out, dividend); |
| 2787 | } else { |
| 2788 | __ rsb(out, dividend, ShifterOperand(0)); |
| 2789 | } |
| 2790 | } |
| 2791 | } |
| 2792 | |
| 2793 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2794 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2795 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2796 | |
| 2797 | LocationSummary* locations = instruction->GetLocations(); |
| 2798 | Location second = locations->InAt(1); |
| 2799 | DCHECK(second.IsConstant()); |
| 2800 | |
| 2801 | Register out = locations->Out().AsRegister<Register>(); |
| 2802 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2803 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2804 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2805 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2806 | int ctz_imm = CTZ(abs_imm); |
| 2807 | |
| 2808 | if (ctz_imm == 1) { |
| 2809 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 2810 | } else { |
| 2811 | __ Asr(temp, dividend, 31); |
| 2812 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 2813 | } |
| 2814 | __ add(out, temp, ShifterOperand(dividend)); |
| 2815 | |
| 2816 | if (instruction->IsDiv()) { |
| 2817 | __ Asr(out, out, ctz_imm); |
| 2818 | if (imm < 0) { |
| 2819 | __ rsb(out, out, ShifterOperand(0)); |
| 2820 | } |
| 2821 | } else { |
| 2822 | __ ubfx(out, out, 0, ctz_imm); |
| 2823 | __ sub(out, out, ShifterOperand(temp)); |
| 2824 | } |
| 2825 | } |
| 2826 | |
| 2827 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2828 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2829 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2830 | |
| 2831 | LocationSummary* locations = instruction->GetLocations(); |
| 2832 | Location second = locations->InAt(1); |
| 2833 | DCHECK(second.IsConstant()); |
| 2834 | |
| 2835 | Register out = locations->Out().AsRegister<Register>(); |
| 2836 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2837 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 2838 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 2839 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2840 | |
| 2841 | int64_t magic; |
| 2842 | int shift; |
| 2843 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2844 | |
| 2845 | __ LoadImmediate(temp1, magic); |
| 2846 | __ smull(temp2, temp1, dividend, temp1); |
| 2847 | |
| 2848 | if (imm > 0 && magic < 0) { |
| 2849 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 2850 | } else if (imm < 0 && magic > 0) { |
| 2851 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 2852 | } |
| 2853 | |
| 2854 | if (shift != 0) { |
| 2855 | __ Asr(temp1, temp1, shift); |
| 2856 | } |
| 2857 | |
| 2858 | if (instruction->IsDiv()) { |
| 2859 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 2860 | } else { |
| 2861 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 2862 | // TODO: Strength reduction for mls. |
| 2863 | __ LoadImmediate(temp2, imm); |
| 2864 | __ mls(out, temp1, temp2, dividend); |
| 2865 | } |
| 2866 | } |
| 2867 | |
| 2868 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 2869 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2870 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2871 | |
| 2872 | LocationSummary* locations = instruction->GetLocations(); |
| 2873 | Location second = locations->InAt(1); |
| 2874 | DCHECK(second.IsConstant()); |
| 2875 | |
| 2876 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2877 | if (imm == 0) { |
| 2878 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2879 | } else if (imm == 1 || imm == -1) { |
| 2880 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2881 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2882 | DivRemByPowerOfTwo(instruction); |
| 2883 | } else { |
| 2884 | DCHECK(imm <= -2 || imm >= 2); |
| 2885 | GenerateDivRemWithAnyConstant(instruction); |
| 2886 | } |
| 2887 | } |
| 2888 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2889 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2890 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 2891 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 2892 | // pLdiv runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2893 | call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2894 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 2895 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2896 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 2897 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 2898 | // pIdivmod runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2899 | call_kind = LocationSummary::kCallOnMainOnly; |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2900 | } |
| 2901 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2902 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2903 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2904 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2905 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2906 | if (div->InputAt(1)->IsConstant()) { |
| 2907 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 2908 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2909 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2910 | int32_t value = div->InputAt(1)->AsIntConstant()->GetValue(); |
| 2911 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2912 | // No temp register required. |
| 2913 | } else { |
| 2914 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2915 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2916 | locations->AddTemp(Location::RequiresRegister()); |
| 2917 | } |
| 2918 | } |
| 2919 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2920 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2921 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2922 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2923 | } else { |
| 2924 | InvokeRuntimeCallingConvention calling_convention; |
| 2925 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2926 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2927 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 2928 | // we only need the former. |
| 2929 | locations->SetOut(Location::RegisterLocation(R0)); |
| 2930 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2931 | break; |
| 2932 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2933 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2934 | InvokeRuntimeCallingConvention calling_convention; |
| 2935 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2936 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2937 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2938 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2939 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2940 | break; |
| 2941 | } |
| 2942 | case Primitive::kPrimFloat: |
| 2943 | case Primitive::kPrimDouble: { |
| 2944 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2945 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2946 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2947 | break; |
| 2948 | } |
| 2949 | |
| 2950 | default: |
| 2951 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2952 | } |
| 2953 | } |
| 2954 | |
| 2955 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 2956 | LocationSummary* locations = div->GetLocations(); |
| 2957 | Location out = locations->Out(); |
| 2958 | Location first = locations->InAt(0); |
| 2959 | Location second = locations->InAt(1); |
| 2960 | |
| 2961 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2962 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2963 | if (second.IsConstant()) { |
| 2964 | GenerateDivRemConstantIntegral(div); |
| 2965 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2966 | __ sdiv(out.AsRegister<Register>(), |
| 2967 | first.AsRegister<Register>(), |
| 2968 | second.AsRegister<Register>()); |
| 2969 | } else { |
| 2970 | InvokeRuntimeCallingConvention calling_convention; |
| 2971 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 2972 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 2973 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 2974 | |
| 2975 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2976 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2977 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2978 | break; |
| 2979 | } |
| 2980 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2981 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2982 | InvokeRuntimeCallingConvention calling_convention; |
| 2983 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2984 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 2985 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 2986 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 2987 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2988 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2989 | |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2990 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2991 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2992 | break; |
| 2993 | } |
| 2994 | |
| 2995 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2996 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 2997 | first.AsFpuRegister<SRegister>(), |
| 2998 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2999 | break; |
| 3000 | } |
| 3001 | |
| 3002 | case Primitive::kPrimDouble: { |
| 3003 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3004 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3005 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 3006 | break; |
| 3007 | } |
| 3008 | |
| 3009 | default: |
| 3010 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3011 | } |
| 3012 | } |
| 3013 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3014 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3015 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3016 | |
| 3017 | // Most remainders are implemented in the runtime. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3018 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3019 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 3020 | // sdiv will be replaced by other instruction sequence. |
| 3021 | call_kind = LocationSummary::kNoCall; |
| 3022 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 3023 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3024 | // Have hardware divide instruction for int, do it with three instructions. |
| 3025 | call_kind = LocationSummary::kNoCall; |
| 3026 | } |
| 3027 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3028 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 3029 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3030 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3031 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3032 | if (rem->InputAt(1)->IsConstant()) { |
| 3033 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3034 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3035 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3036 | int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue(); |
| 3037 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3038 | // No temp register required. |
| 3039 | } else { |
| 3040 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3041 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3042 | locations->AddTemp(Location::RequiresRegister()); |
| 3043 | } |
| 3044 | } |
| 3045 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3046 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3047 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3048 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3049 | locations->AddTemp(Location::RequiresRegister()); |
| 3050 | } else { |
| 3051 | InvokeRuntimeCallingConvention calling_convention; |
| 3052 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3053 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3054 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 3055 | // we only need the latter. |
| 3056 | locations->SetOut(Location::RegisterLocation(R1)); |
| 3057 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3058 | break; |
| 3059 | } |
| 3060 | case Primitive::kPrimLong: { |
| 3061 | InvokeRuntimeCallingConvention calling_convention; |
| 3062 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3063 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3064 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3065 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3066 | // The runtime helper puts the output in R2,R3. |
| 3067 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 3068 | break; |
| 3069 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3070 | case Primitive::kPrimFloat: { |
| 3071 | InvokeRuntimeCallingConvention calling_convention; |
| 3072 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 3073 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 3074 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 3075 | break; |
| 3076 | } |
| 3077 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3078 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3079 | InvokeRuntimeCallingConvention calling_convention; |
| 3080 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 3081 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 3082 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 3083 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 3084 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3085 | break; |
| 3086 | } |
| 3087 | |
| 3088 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3089 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3090 | } |
| 3091 | } |
| 3092 | |
| 3093 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 3094 | LocationSummary* locations = rem->GetLocations(); |
| 3095 | Location out = locations->Out(); |
| 3096 | Location first = locations->InAt(0); |
| 3097 | Location second = locations->InAt(1); |
| 3098 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3099 | Primitive::Type type = rem->GetResultType(); |
| 3100 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3101 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3102 | if (second.IsConstant()) { |
| 3103 | GenerateDivRemConstantIntegral(rem); |
| 3104 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3105 | Register reg1 = first.AsRegister<Register>(); |
| 3106 | Register reg2 = second.AsRegister<Register>(); |
| 3107 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3108 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3109 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3110 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3111 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3112 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3113 | } else { |
| 3114 | InvokeRuntimeCallingConvention calling_convention; |
| 3115 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3116 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3117 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 3118 | |
| 3119 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3120 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3121 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3122 | break; |
| 3123 | } |
| 3124 | |
| 3125 | case Primitive::kPrimLong: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3126 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3127 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3128 | break; |
| 3129 | } |
| 3130 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3131 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3132 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3133 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3134 | break; |
| 3135 | } |
| 3136 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3137 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3138 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3139 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3140 | break; |
| 3141 | } |
| 3142 | |
| 3143 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3144 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3145 | } |
| 3146 | } |
| 3147 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3148 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3149 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3150 | ? LocationSummary::kCallOnSlowPath |
| 3151 | : LocationSummary::kNoCall; |
| 3152 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3153 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3154 | if (instruction->HasUses()) { |
| 3155 | locations->SetOut(Location::SameAsFirstInput()); |
| 3156 | } |
| 3157 | } |
| 3158 | |
| 3159 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3160 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3161 | codegen_->AddSlowPath(slow_path); |
| 3162 | |
| 3163 | LocationSummary* locations = instruction->GetLocations(); |
| 3164 | Location value = locations->InAt(0); |
| 3165 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3166 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3167 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3168 | case Primitive::kPrimByte: |
| 3169 | case Primitive::kPrimChar: |
| 3170 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3171 | case Primitive::kPrimInt: { |
| 3172 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3173 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3174 | } else { |
| 3175 | DCHECK(value.IsConstant()) << value; |
| 3176 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3177 | __ b(slow_path->GetEntryLabel()); |
| 3178 | } |
| 3179 | } |
| 3180 | break; |
| 3181 | } |
| 3182 | case Primitive::kPrimLong: { |
| 3183 | if (value.IsRegisterPair()) { |
| 3184 | __ orrs(IP, |
| 3185 | value.AsRegisterPairLow<Register>(), |
| 3186 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 3187 | __ b(slow_path->GetEntryLabel(), EQ); |
| 3188 | } else { |
| 3189 | DCHECK(value.IsConstant()) << value; |
| 3190 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3191 | __ b(slow_path->GetEntryLabel()); |
| 3192 | } |
| 3193 | } |
| 3194 | break; |
| 3195 | default: |
| 3196 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3197 | } |
| 3198 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3199 | } |
| 3200 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3201 | void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) { |
| 3202 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 3203 | Location rhs = locations->InAt(1); |
| 3204 | Register out = locations->Out().AsRegister<Register>(); |
| 3205 | |
| 3206 | if (rhs.IsConstant()) { |
| 3207 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 3208 | // so map all rotations to a +ve. equivalent in that range. |
| 3209 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 3210 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 3211 | if (rot) { |
| 3212 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 3213 | // (e.g. left by 2 bits == right by 30.) |
| 3214 | __ Ror(out, in, rot); |
| 3215 | } else if (out != in) { |
| 3216 | __ Mov(out, in); |
| 3217 | } |
| 3218 | } else { |
| 3219 | __ Ror(out, in, rhs.AsRegister<Register>()); |
| 3220 | } |
| 3221 | } |
| 3222 | |
| 3223 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 3224 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 3225 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 3226 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 3227 | void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) { |
| 3228 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3229 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3230 | Location rhs = locations->InAt(1); |
| 3231 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 3232 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 3233 | |
| 3234 | if (rhs.IsConstant()) { |
| 3235 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 3236 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3237 | rot &= kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3238 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 3239 | // logic below to a simple pair of binary orr. |
| 3240 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 3241 | if (rot >= kArmBitsPerWord) { |
| 3242 | rot -= kArmBitsPerWord; |
| 3243 | std::swap(in_reg_hi, in_reg_lo); |
| 3244 | } |
| 3245 | // Rotate, or mov to out for zero or word size rotations. |
| 3246 | if (rot != 0u) { |
| 3247 | __ Lsr(out_reg_hi, in_reg_hi, rot); |
| 3248 | __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot)); |
| 3249 | __ Lsr(out_reg_lo, in_reg_lo, rot); |
| 3250 | __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot)); |
| 3251 | } else { |
| 3252 | __ Mov(out_reg_lo, in_reg_lo); |
| 3253 | __ Mov(out_reg_hi, in_reg_hi); |
| 3254 | } |
| 3255 | } else { |
| 3256 | Register shift_right = locations->GetTemp(0).AsRegister<Register>(); |
| 3257 | Register shift_left = locations->GetTemp(1).AsRegister<Register>(); |
| 3258 | Label end; |
| 3259 | Label shift_by_32_plus_shift_right; |
| 3260 | |
| 3261 | __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F)); |
| 3262 | __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6); |
| 3263 | __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep); |
| 3264 | __ b(&shift_by_32_plus_shift_right, CC); |
| 3265 | |
| 3266 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 3267 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 3268 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 3269 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3270 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3271 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3272 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 3273 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left)); |
| 3274 | __ b(&end); |
| 3275 | |
| 3276 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 3277 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 3278 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 3279 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 3280 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3281 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3282 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3283 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 3284 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right)); |
| 3285 | |
| 3286 | __ Bind(&end); |
| 3287 | } |
| 3288 | } |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3289 | |
| 3290 | void LocationsBuilderARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3291 | LocationSummary* locations = |
| 3292 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3293 | switch (ror->GetResultType()) { |
| 3294 | case Primitive::kPrimInt: { |
| 3295 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3296 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 3297 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3298 | break; |
| 3299 | } |
| 3300 | case Primitive::kPrimLong: { |
| 3301 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3302 | if (ror->InputAt(1)->IsConstant()) { |
| 3303 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 3304 | } else { |
| 3305 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3306 | locations->AddTemp(Location::RequiresRegister()); |
| 3307 | locations->AddTemp(Location::RequiresRegister()); |
| 3308 | } |
| 3309 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3310 | break; |
| 3311 | } |
| 3312 | default: |
| 3313 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3314 | } |
| 3315 | } |
| 3316 | |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3317 | void InstructionCodeGeneratorARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3318 | LocationSummary* locations = ror->GetLocations(); |
| 3319 | Primitive::Type type = ror->GetResultType(); |
| 3320 | switch (type) { |
| 3321 | case Primitive::kPrimInt: { |
| 3322 | HandleIntegerRotate(locations); |
| 3323 | break; |
| 3324 | } |
| 3325 | case Primitive::kPrimLong: { |
| 3326 | HandleLongRotate(locations); |
| 3327 | break; |
| 3328 | } |
| 3329 | default: |
| 3330 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3331 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3332 | } |
| 3333 | } |
| 3334 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3335 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 3336 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3337 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3338 | LocationSummary* locations = |
| 3339 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3340 | |
| 3341 | switch (op->GetResultType()) { |
| 3342 | case Primitive::kPrimInt: { |
| 3343 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3344 | if (op->InputAt(1)->IsConstant()) { |
| 3345 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3346 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3347 | } else { |
| 3348 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3349 | // Make the output overlap, as it will be used to hold the masked |
| 3350 | // second input. |
| 3351 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3352 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3353 | break; |
| 3354 | } |
| 3355 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3356 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3357 | if (op->InputAt(1)->IsConstant()) { |
| 3358 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3359 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 3360 | // don't clash with high registers which the register allocator currently guarantees. |
| 3361 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3362 | } else { |
| 3363 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3364 | locations->AddTemp(Location::RequiresRegister()); |
| 3365 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3366 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3367 | break; |
| 3368 | } |
| 3369 | default: |
| 3370 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3371 | } |
| 3372 | } |
| 3373 | |
| 3374 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 3375 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3376 | |
| 3377 | LocationSummary* locations = op->GetLocations(); |
| 3378 | Location out = locations->Out(); |
| 3379 | Location first = locations->InAt(0); |
| 3380 | Location second = locations->InAt(1); |
| 3381 | |
| 3382 | Primitive::Type type = op->GetResultType(); |
| 3383 | switch (type) { |
| 3384 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3385 | Register out_reg = out.AsRegister<Register>(); |
| 3386 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3387 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3388 | Register second_reg = second.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3389 | // ARM doesn't mask the shift count so we need to do it ourselves. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3390 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3391 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3392 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3393 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3394 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3395 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3396 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3397 | } |
| 3398 | } else { |
| 3399 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3400 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3401 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3402 | __ Mov(out_reg, first_reg); |
| 3403 | } else if (op->IsShl()) { |
| 3404 | __ Lsl(out_reg, first_reg, shift_value); |
| 3405 | } else if (op->IsShr()) { |
| 3406 | __ Asr(out_reg, first_reg, shift_value); |
| 3407 | } else { |
| 3408 | __ Lsr(out_reg, first_reg, shift_value); |
| 3409 | } |
| 3410 | } |
| 3411 | break; |
| 3412 | } |
| 3413 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3414 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 3415 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3416 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3417 | Register high = first.AsRegisterPairHigh<Register>(); |
| 3418 | Register low = first.AsRegisterPairLow<Register>(); |
| 3419 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3420 | if (second.IsRegister()) { |
| 3421 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3422 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3423 | Register second_reg = second.AsRegister<Register>(); |
| 3424 | |
| 3425 | if (op->IsShl()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3426 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3427 | // Shift the high part |
| 3428 | __ Lsl(o_h, high, o_l); |
| 3429 | // Shift the low part and `or` what overflew on the high part |
| 3430 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3431 | __ Lsr(temp, low, temp); |
| 3432 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 3433 | // If the shift is > 32 bits, override the high part |
| 3434 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3435 | __ it(PL); |
| 3436 | __ Lsl(o_h, low, temp, PL); |
| 3437 | // Shift the low part |
| 3438 | __ Lsl(o_l, low, o_l); |
| 3439 | } else if (op->IsShr()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3440 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3441 | // Shift the low part |
| 3442 | __ Lsr(o_l, low, o_h); |
| 3443 | // Shift the high part and `or` what underflew on the low part |
| 3444 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3445 | __ Lsl(temp, high, temp); |
| 3446 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3447 | // If the shift is > 32 bits, override the low part |
| 3448 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3449 | __ it(PL); |
| 3450 | __ Asr(o_l, high, temp, PL); |
| 3451 | // Shift the high part |
| 3452 | __ Asr(o_h, high, o_h); |
| 3453 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3454 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3455 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 3456 | __ Lsr(o_l, low, o_h); |
| 3457 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3458 | __ Lsl(temp, high, temp); |
| 3459 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3460 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3461 | __ it(PL); |
| 3462 | __ Lsr(o_l, high, temp, PL); |
| 3463 | __ Lsr(o_h, high, o_h); |
| 3464 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3465 | } else { |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3466 | // Register allocator doesn't create partial overlap. |
| 3467 | DCHECK_NE(o_l, high); |
| 3468 | DCHECK_NE(o_h, low); |
| 3469 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3470 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3471 | if (shift_value > 32) { |
| 3472 | if (op->IsShl()) { |
| 3473 | __ Lsl(o_h, low, shift_value - 32); |
| 3474 | __ LoadImmediate(o_l, 0); |
| 3475 | } else if (op->IsShr()) { |
| 3476 | __ Asr(o_l, high, shift_value - 32); |
| 3477 | __ Asr(o_h, high, 31); |
| 3478 | } else { |
| 3479 | __ Lsr(o_l, high, shift_value - 32); |
| 3480 | __ LoadImmediate(o_h, 0); |
| 3481 | } |
| 3482 | } else if (shift_value == 32) { |
| 3483 | if (op->IsShl()) { |
| 3484 | __ mov(o_h, ShifterOperand(low)); |
| 3485 | __ LoadImmediate(o_l, 0); |
| 3486 | } else if (op->IsShr()) { |
| 3487 | __ mov(o_l, ShifterOperand(high)); |
| 3488 | __ Asr(o_h, high, 31); |
| 3489 | } else { |
| 3490 | __ mov(o_l, ShifterOperand(high)); |
| 3491 | __ LoadImmediate(o_h, 0); |
| 3492 | } |
Vladimir Marko | f9d741e | 2015-11-20 15:08:11 +0000 | [diff] [blame] | 3493 | } else if (shift_value == 1) { |
| 3494 | if (op->IsShl()) { |
| 3495 | __ Lsls(o_l, low, 1); |
| 3496 | __ adc(o_h, high, ShifterOperand(high)); |
| 3497 | } else if (op->IsShr()) { |
| 3498 | __ Asrs(o_h, high, 1); |
| 3499 | __ Rrx(o_l, low); |
| 3500 | } else { |
| 3501 | __ Lsrs(o_h, high, 1); |
| 3502 | __ Rrx(o_l, low); |
| 3503 | } |
| 3504 | } else { |
| 3505 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3506 | if (op->IsShl()) { |
| 3507 | __ Lsl(o_h, high, shift_value); |
| 3508 | __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value)); |
| 3509 | __ Lsl(o_l, low, shift_value); |
| 3510 | } else if (op->IsShr()) { |
| 3511 | __ Lsr(o_l, low, shift_value); |
| 3512 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3513 | __ Asr(o_h, high, shift_value); |
| 3514 | } else { |
| 3515 | __ Lsr(o_l, low, shift_value); |
| 3516 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3517 | __ Lsr(o_h, high, shift_value); |
| 3518 | } |
| 3519 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3520 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3521 | break; |
| 3522 | } |
| 3523 | default: |
| 3524 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3525 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3526 | } |
| 3527 | } |
| 3528 | |
| 3529 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 3530 | HandleShift(shl); |
| 3531 | } |
| 3532 | |
| 3533 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 3534 | HandleShift(shl); |
| 3535 | } |
| 3536 | |
| 3537 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 3538 | HandleShift(shr); |
| 3539 | } |
| 3540 | |
| 3541 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 3542 | HandleShift(shr); |
| 3543 | } |
| 3544 | |
| 3545 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 3546 | HandleShift(ushr); |
| 3547 | } |
| 3548 | |
| 3549 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 3550 | HandleShift(ushr); |
| 3551 | } |
| 3552 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3553 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3554 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3555 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3556 | if (instruction->IsStringAlloc()) { |
| 3557 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3558 | } else { |
| 3559 | InvokeRuntimeCallingConvention calling_convention; |
| 3560 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3561 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3562 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3563 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3564 | } |
| 3565 | |
| 3566 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3567 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3568 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3569 | if (instruction->IsStringAlloc()) { |
| 3570 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3571 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3572 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3573 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 3574 | __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value()); |
| 3575 | __ blx(LR); |
| 3576 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3577 | } else { |
| 3578 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3579 | instruction, |
| 3580 | instruction->GetDexPc(), |
| 3581 | nullptr); |
| 3582 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3583 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3584 | } |
| 3585 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3586 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 3587 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3588 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3589 | InvokeRuntimeCallingConvention calling_convention; |
| 3590 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3591 | locations->SetOut(Location::RegisterLocation(R0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3592 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3593 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3594 | } |
| 3595 | |
| 3596 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
| 3597 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3598 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3599 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3600 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3601 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3602 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3603 | instruction->GetDexPc(), |
| 3604 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3605 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3606 | } |
| 3607 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3608 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3609 | LocationSummary* locations = |
| 3610 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3611 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3612 | if (location.IsStackSlot()) { |
| 3613 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3614 | } else if (location.IsDoubleStackSlot()) { |
| 3615 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3616 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3617 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3618 | } |
| 3619 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3620 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 3621 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3622 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3623 | } |
| 3624 | |
| 3625 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3626 | LocationSummary* locations = |
| 3627 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3628 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3629 | } |
| 3630 | |
| 3631 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3632 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3633 | } |
| 3634 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3635 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3636 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3637 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3638 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3639 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3640 | } |
| 3641 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3642 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 3643 | LocationSummary* locations = not_->GetLocations(); |
| 3644 | Location out = locations->Out(); |
| 3645 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3646 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3647 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3648 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3649 | break; |
| 3650 | |
| 3651 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3652 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 3653 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 3654 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 3655 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3656 | break; |
| 3657 | |
| 3658 | default: |
| 3659 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3660 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3661 | } |
| 3662 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3663 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3664 | LocationSummary* locations = |
| 3665 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3666 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3667 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3668 | } |
| 3669 | |
| 3670 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3671 | LocationSummary* locations = bool_not->GetLocations(); |
| 3672 | Location out = locations->Out(); |
| 3673 | Location in = locations->InAt(0); |
| 3674 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 3675 | } |
| 3676 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3677 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3678 | LocationSummary* locations = |
| 3679 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3680 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3681 | case Primitive::kPrimBoolean: |
| 3682 | case Primitive::kPrimByte: |
| 3683 | case Primitive::kPrimShort: |
| 3684 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3685 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3686 | case Primitive::kPrimLong: { |
| 3687 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3688 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3689 | // Output overlaps because it is written before doing the low comparison. |
| 3690 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3691 | break; |
| 3692 | } |
| 3693 | case Primitive::kPrimFloat: |
| 3694 | case Primitive::kPrimDouble: { |
| 3695 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 3696 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3697 | locations->SetOut(Location::RequiresRegister()); |
| 3698 | break; |
| 3699 | } |
| 3700 | default: |
| 3701 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 3702 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3703 | } |
| 3704 | |
| 3705 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3706 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3707 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3708 | Location left = locations->InAt(0); |
| 3709 | Location right = locations->InAt(1); |
| 3710 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3711 | Label less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3712 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3713 | Condition less_cond; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3714 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3715 | case Primitive::kPrimBoolean: |
| 3716 | case Primitive::kPrimByte: |
| 3717 | case Primitive::kPrimShort: |
| 3718 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3719 | case Primitive::kPrimInt: { |
| 3720 | __ LoadImmediate(out, 0); |
| 3721 | __ cmp(left.AsRegister<Register>(), |
| 3722 | ShifterOperand(right.AsRegister<Register>())); // Signed compare. |
| 3723 | less_cond = LT; |
| 3724 | break; |
| 3725 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3726 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3727 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 3728 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3729 | __ b(&less, LT); |
| 3730 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3731 | // 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] | 3732 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3733 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 3734 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3735 | less_cond = LO; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3736 | break; |
| 3737 | } |
| 3738 | case Primitive::kPrimFloat: |
| 3739 | case Primitive::kPrimDouble: { |
| 3740 | __ LoadImmediate(out, 0); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 3741 | GenerateVcmp(compare); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3742 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3743 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3744 | break; |
| 3745 | } |
| 3746 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3747 | LOG(FATAL) << "Unexpected compare type " << type; |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3748 | UNREACHABLE(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3749 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3750 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3751 | __ b(&done, EQ); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3752 | __ b(&less, less_cond); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3753 | |
| 3754 | __ Bind(&greater); |
| 3755 | __ LoadImmediate(out, 1); |
| 3756 | __ b(&done); |
| 3757 | |
| 3758 | __ Bind(&less); |
| 3759 | __ LoadImmediate(out, -1); |
| 3760 | |
| 3761 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3762 | } |
| 3763 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3764 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3765 | LocationSummary* locations = |
| 3766 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3767 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 3768 | locations->SetInAt(i, Location::Any()); |
| 3769 | } |
| 3770 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3771 | } |
| 3772 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3773 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3774 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3775 | } |
| 3776 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3777 | void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3778 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 3779 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3780 | switch (kind) { |
| 3781 | case MemBarrierKind::kAnyStore: |
| 3782 | case MemBarrierKind::kLoadAny: |
| 3783 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3784 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3785 | break; |
| 3786 | } |
| 3787 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3788 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3789 | break; |
| 3790 | } |
| 3791 | default: |
| 3792 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 3793 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3794 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3795 | } |
| 3796 | |
| 3797 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 3798 | uint32_t offset, |
| 3799 | Register out_lo, |
| 3800 | Register out_hi) { |
| 3801 | if (offset != 0) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3802 | // Ensure `out_lo` is different from `addr`, so that loading |
| 3803 | // `offset` into `out_lo` does not clutter `addr`. |
| 3804 | DCHECK_NE(out_lo, addr); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3805 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3806 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 3807 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3808 | } |
| 3809 | __ ldrexd(out_lo, out_hi, addr); |
| 3810 | } |
| 3811 | |
| 3812 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 3813 | uint32_t offset, |
| 3814 | Register value_lo, |
| 3815 | Register value_hi, |
| 3816 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3817 | Register temp2, |
| 3818 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3819 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3820 | if (offset != 0) { |
| 3821 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3822 | __ add(IP, addr, ShifterOperand(temp1)); |
| 3823 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3824 | } |
| 3825 | __ Bind(&fail); |
| 3826 | // We need a load followed by store. (The address used in a STREX instruction must |
| 3827 | // be the same as the address in the most recently executed LDREX instruction.) |
| 3828 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3829 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3830 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3831 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3832 | } |
| 3833 | |
| 3834 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3835 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3836 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3837 | LocationSummary* locations = |
| 3838 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3839 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3840 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3841 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3842 | if (Primitive::IsFloatingPointType(field_type)) { |
| 3843 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3844 | } else { |
| 3845 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3846 | } |
| 3847 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3848 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3849 | bool generate_volatile = field_info.IsVolatile() |
| 3850 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3851 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3852 | bool needs_write_barrier = |
| 3853 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3854 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3855 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3856 | if (needs_write_barrier) { |
| 3857 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3858 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3859 | } else if (generate_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3860 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3861 | // - registers need to be consecutive |
| 3862 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3863 | // We don't test for ARM yet, and the assertion makes sure that we |
| 3864 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3865 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 3866 | |
| 3867 | locations->AddTemp(Location::RequiresRegister()); |
| 3868 | locations->AddTemp(Location::RequiresRegister()); |
| 3869 | if (field_type == Primitive::kPrimDouble) { |
| 3870 | // For doubles we need two more registers to copy the value. |
| 3871 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 3872 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 3873 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3874 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3875 | } |
| 3876 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3877 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3878 | const FieldInfo& field_info, |
| 3879 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3880 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3881 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3882 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3883 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3884 | Location value = locations->InAt(1); |
| 3885 | |
| 3886 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3887 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3888 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3889 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3890 | bool needs_write_barrier = |
| 3891 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3892 | |
| 3893 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3894 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3895 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3896 | |
| 3897 | switch (field_type) { |
| 3898 | case Primitive::kPrimBoolean: |
| 3899 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3900 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3901 | break; |
| 3902 | } |
| 3903 | |
| 3904 | case Primitive::kPrimShort: |
| 3905 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3906 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3907 | break; |
| 3908 | } |
| 3909 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3910 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3911 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3912 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 3913 | // Note that in the case where `value` is a null reference, |
| 3914 | // we do not enter this block, as a null reference does not |
| 3915 | // need poisoning. |
| 3916 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 3917 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3918 | __ Mov(temp, value.AsRegister<Register>()); |
| 3919 | __ PoisonHeapReference(temp); |
| 3920 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 3921 | } else { |
| 3922 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 3923 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3924 | break; |
| 3925 | } |
| 3926 | |
| 3927 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3928 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3929 | GenerateWideAtomicStore(base, offset, |
| 3930 | value.AsRegisterPairLow<Register>(), |
| 3931 | value.AsRegisterPairHigh<Register>(), |
| 3932 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3933 | locations->GetTemp(1).AsRegister<Register>(), |
| 3934 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3935 | } else { |
| 3936 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3937 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3938 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3939 | break; |
| 3940 | } |
| 3941 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3942 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3943 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3944 | break; |
| 3945 | } |
| 3946 | |
| 3947 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3948 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3949 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3950 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 3951 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 3952 | |
| 3953 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 3954 | |
| 3955 | GenerateWideAtomicStore(base, offset, |
| 3956 | value_reg_lo, |
| 3957 | value_reg_hi, |
| 3958 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3959 | locations->GetTemp(3).AsRegister<Register>(), |
| 3960 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3961 | } else { |
| 3962 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3963 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3964 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3965 | break; |
| 3966 | } |
| 3967 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3968 | case Primitive::kPrimVoid: |
| 3969 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3970 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3971 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3972 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3973 | // Longs and doubles are handled in the switch. |
| 3974 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 3975 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3976 | } |
| 3977 | |
| 3978 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 3979 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3980 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3981 | codegen_->MarkGCCard( |
| 3982 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3983 | } |
| 3984 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3985 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3986 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3987 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3988 | } |
| 3989 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3990 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3991 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3992 | |
| 3993 | bool object_field_get_with_read_barrier = |
| 3994 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3995 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3996 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 3997 | object_field_get_with_read_barrier ? |
| 3998 | LocationSummary::kCallOnSlowPath : |
| 3999 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4000 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4001 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4002 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4003 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4004 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4005 | // The output overlaps in case of volatile long: we don't want the |
| 4006 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 4007 | // object's location. Likewise, in the case of an object field get |
| 4008 | // with read barriers enabled, we do not want the load to overwrite |
| 4009 | // the object's location, as we need it to emit the read barrier. |
| 4010 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 4011 | object_field_get_with_read_barrier; |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 4012 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4013 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4014 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4015 | } else { |
| 4016 | locations->SetOut(Location::RequiresRegister(), |
| 4017 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 4018 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4019 | if (volatile_for_double) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4020 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4021 | // - registers need to be consecutive |
| 4022 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4023 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4024 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4025 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4026 | locations->AddTemp(Location::RequiresRegister()); |
| 4027 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4028 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4029 | // We need a temporary register for the read barrier marking slow |
| 4030 | // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
| 4031 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4032 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4033 | } |
| 4034 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4035 | Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 4036 | DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat) |
| 4037 | << input->GetType(); |
| 4038 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 4039 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 4040 | return Location::ConstantLocation(input->AsConstant()); |
| 4041 | } else { |
| 4042 | return Location::RequiresFpuRegister(); |
| 4043 | } |
| 4044 | } |
| 4045 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4046 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 4047 | Opcode opcode) { |
| 4048 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 4049 | if (constant->IsConstant() && |
| 4050 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 4051 | return Location::ConstantLocation(constant->AsConstant()); |
| 4052 | } |
| 4053 | return Location::RequiresRegister(); |
| 4054 | } |
| 4055 | |
| 4056 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 4057 | Opcode opcode) { |
| 4058 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 4059 | if (Primitive::Is64BitType(input_cst->GetType())) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4060 | Opcode high_opcode = opcode; |
| 4061 | SetCc low_set_cc = kCcDontCare; |
| 4062 | switch (opcode) { |
| 4063 | case SUB: |
| 4064 | // Flip the operation to an ADD. |
| 4065 | value = -value; |
| 4066 | opcode = ADD; |
| 4067 | FALLTHROUGH_INTENDED; |
| 4068 | case ADD: |
| 4069 | if (Low32Bits(value) == 0u) { |
| 4070 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 4071 | } |
| 4072 | high_opcode = ADC; |
| 4073 | low_set_cc = kCcSet; |
| 4074 | break; |
| 4075 | default: |
| 4076 | break; |
| 4077 | } |
| 4078 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 4079 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4080 | } else { |
| 4081 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 4082 | } |
| 4083 | } |
| 4084 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4085 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, |
| 4086 | Opcode opcode, |
| 4087 | SetCc set_cc) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4088 | ShifterOperand so; |
| 4089 | ArmAssembler* assembler = codegen_->GetAssembler(); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4090 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4091 | return true; |
| 4092 | } |
| 4093 | Opcode neg_opcode = kNoOperand; |
| 4094 | switch (opcode) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4095 | case AND: neg_opcode = BIC; value = ~value; break; |
| 4096 | case ORR: neg_opcode = ORN; value = ~value; break; |
| 4097 | case ADD: neg_opcode = SUB; value = -value; break; |
| 4098 | case ADC: neg_opcode = SBC; value = ~value; break; |
| 4099 | case SUB: neg_opcode = ADD; value = -value; break; |
| 4100 | case SBC: neg_opcode = ADC; value = ~value; break; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4101 | default: |
| 4102 | return false; |
| 4103 | } |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4104 | return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, value, set_cc, &so); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4105 | } |
| 4106 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4107 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 4108 | const FieldInfo& field_info) { |
| 4109 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4110 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4111 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4112 | Location base_loc = locations->InAt(0); |
| 4113 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4114 | Location out = locations->Out(); |
| 4115 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4116 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4117 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4118 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4119 | |
| 4120 | switch (field_type) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4121 | case Primitive::kPrimBoolean: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4122 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4123 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4124 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4125 | case Primitive::kPrimByte: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4126 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4127 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4128 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4129 | case Primitive::kPrimShort: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4130 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4131 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4132 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4133 | case Primitive::kPrimChar: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4134 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4135 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4136 | |
| 4137 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4138 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4139 | break; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4140 | |
| 4141 | case Primitive::kPrimNot: { |
| 4142 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4143 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4144 | Location temp_loc = locations->GetTemp(0); |
| 4145 | // Note that a potential implicit null check is handled in this |
| 4146 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call. |
| 4147 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4148 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4149 | if (is_volatile) { |
| 4150 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4151 | } |
| 4152 | } else { |
| 4153 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
| 4154 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4155 | if (is_volatile) { |
| 4156 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4157 | } |
| 4158 | // If read barriers are enabled, emit read barriers other than |
| 4159 | // Baker's using a slow path (and also unpoison the loaded |
| 4160 | // reference, if heap poisoning is enabled). |
| 4161 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4162 | } |
| 4163 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4164 | } |
| 4165 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4166 | case Primitive::kPrimLong: |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4167 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4168 | GenerateWideAtomicLoad(base, offset, |
| 4169 | out.AsRegisterPairLow<Register>(), |
| 4170 | out.AsRegisterPairHigh<Register>()); |
| 4171 | } else { |
| 4172 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 4173 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4174 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4175 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4176 | case Primitive::kPrimFloat: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4177 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4178 | break; |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4179 | |
| 4180 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4181 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4182 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4183 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4184 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4185 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4186 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4187 | __ vmovdrr(out_reg, lo, hi); |
| 4188 | } else { |
| 4189 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4190 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4191 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4192 | break; |
| 4193 | } |
| 4194 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4195 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4196 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4197 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4198 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4199 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4200 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 4201 | // Potential implicit null checks, in the case of reference or |
| 4202 | // double fields, are handled in the previous switch statement. |
| 4203 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4204 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4205 | } |
| 4206 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4207 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4208 | if (field_type == Primitive::kPrimNot) { |
| 4209 | // Memory barriers, in the case of references, are also handled |
| 4210 | // in the previous switch statement. |
| 4211 | } else { |
| 4212 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4213 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4214 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4215 | } |
| 4216 | |
| 4217 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4218 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4219 | } |
| 4220 | |
| 4221 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4222 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4223 | } |
| 4224 | |
| 4225 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4226 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4227 | } |
| 4228 | |
| 4229 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4230 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4231 | } |
| 4232 | |
| 4233 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4234 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4235 | } |
| 4236 | |
| 4237 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4238 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4239 | } |
| 4240 | |
| 4241 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4242 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4243 | } |
| 4244 | |
| 4245 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4246 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4247 | } |
| 4248 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4249 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 4250 | HUnresolvedInstanceFieldGet* instruction) { |
| 4251 | FieldAccessCallingConventionARM calling_convention; |
| 4252 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4253 | instruction, instruction->GetFieldType(), calling_convention); |
| 4254 | } |
| 4255 | |
| 4256 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 4257 | HUnresolvedInstanceFieldGet* instruction) { |
| 4258 | FieldAccessCallingConventionARM calling_convention; |
| 4259 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4260 | instruction->GetFieldType(), |
| 4261 | instruction->GetFieldIndex(), |
| 4262 | instruction->GetDexPc(), |
| 4263 | calling_convention); |
| 4264 | } |
| 4265 | |
| 4266 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 4267 | HUnresolvedInstanceFieldSet* instruction) { |
| 4268 | FieldAccessCallingConventionARM calling_convention; |
| 4269 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4270 | instruction, instruction->GetFieldType(), calling_convention); |
| 4271 | } |
| 4272 | |
| 4273 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 4274 | HUnresolvedInstanceFieldSet* instruction) { |
| 4275 | FieldAccessCallingConventionARM calling_convention; |
| 4276 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4277 | instruction->GetFieldType(), |
| 4278 | instruction->GetFieldIndex(), |
| 4279 | instruction->GetDexPc(), |
| 4280 | calling_convention); |
| 4281 | } |
| 4282 | |
| 4283 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 4284 | HUnresolvedStaticFieldGet* instruction) { |
| 4285 | FieldAccessCallingConventionARM calling_convention; |
| 4286 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4287 | instruction, instruction->GetFieldType(), calling_convention); |
| 4288 | } |
| 4289 | |
| 4290 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 4291 | HUnresolvedStaticFieldGet* instruction) { |
| 4292 | FieldAccessCallingConventionARM calling_convention; |
| 4293 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4294 | instruction->GetFieldType(), |
| 4295 | instruction->GetFieldIndex(), |
| 4296 | instruction->GetDexPc(), |
| 4297 | calling_convention); |
| 4298 | } |
| 4299 | |
| 4300 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 4301 | HUnresolvedStaticFieldSet* instruction) { |
| 4302 | FieldAccessCallingConventionARM calling_convention; |
| 4303 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4304 | instruction, instruction->GetFieldType(), calling_convention); |
| 4305 | } |
| 4306 | |
| 4307 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 4308 | HUnresolvedStaticFieldSet* instruction) { |
| 4309 | FieldAccessCallingConventionARM calling_convention; |
| 4310 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4311 | instruction->GetFieldType(), |
| 4312 | instruction->GetFieldIndex(), |
| 4313 | instruction->GetDexPc(), |
| 4314 | calling_convention); |
| 4315 | } |
| 4316 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4317 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4318 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4319 | ? LocationSummary::kCallOnSlowPath |
| 4320 | : LocationSummary::kNoCall; |
| 4321 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4322 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4323 | if (instruction->HasUses()) { |
| 4324 | locations->SetOut(Location::SameAsFirstInput()); |
| 4325 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4326 | } |
| 4327 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4328 | void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4329 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4330 | return; |
| 4331 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4332 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4333 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4334 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4335 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4336 | } |
| 4337 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4338 | void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4339 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4340 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4341 | |
| 4342 | LocationSummary* locations = instruction->GetLocations(); |
| 4343 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4344 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4345 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4346 | } |
| 4347 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4348 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4349 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4350 | } |
| 4351 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4352 | static LoadOperandType GetLoadOperandType(Primitive::Type type) { |
| 4353 | switch (type) { |
| 4354 | case Primitive::kPrimNot: |
| 4355 | return kLoadWord; |
| 4356 | case Primitive::kPrimBoolean: |
| 4357 | return kLoadUnsignedByte; |
| 4358 | case Primitive::kPrimByte: |
| 4359 | return kLoadSignedByte; |
| 4360 | case Primitive::kPrimChar: |
| 4361 | return kLoadUnsignedHalfword; |
| 4362 | case Primitive::kPrimShort: |
| 4363 | return kLoadSignedHalfword; |
| 4364 | case Primitive::kPrimInt: |
| 4365 | return kLoadWord; |
| 4366 | case Primitive::kPrimLong: |
| 4367 | return kLoadWordPair; |
| 4368 | case Primitive::kPrimFloat: |
| 4369 | return kLoadSWord; |
| 4370 | case Primitive::kPrimDouble: |
| 4371 | return kLoadDWord; |
| 4372 | default: |
| 4373 | LOG(FATAL) << "Unreachable type " << type; |
| 4374 | UNREACHABLE(); |
| 4375 | } |
| 4376 | } |
| 4377 | |
| 4378 | static StoreOperandType GetStoreOperandType(Primitive::Type type) { |
| 4379 | switch (type) { |
| 4380 | case Primitive::kPrimNot: |
| 4381 | return kStoreWord; |
| 4382 | case Primitive::kPrimBoolean: |
| 4383 | case Primitive::kPrimByte: |
| 4384 | return kStoreByte; |
| 4385 | case Primitive::kPrimChar: |
| 4386 | case Primitive::kPrimShort: |
| 4387 | return kStoreHalfword; |
| 4388 | case Primitive::kPrimInt: |
| 4389 | return kStoreWord; |
| 4390 | case Primitive::kPrimLong: |
| 4391 | return kStoreWordPair; |
| 4392 | case Primitive::kPrimFloat: |
| 4393 | return kStoreSWord; |
| 4394 | case Primitive::kPrimDouble: |
| 4395 | return kStoreDWord; |
| 4396 | default: |
| 4397 | LOG(FATAL) << "Unreachable type " << type; |
| 4398 | UNREACHABLE(); |
| 4399 | } |
| 4400 | } |
| 4401 | |
| 4402 | void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type, |
| 4403 | Location out_loc, |
| 4404 | Register base, |
| 4405 | Register reg_offset, |
| 4406 | Condition cond) { |
| 4407 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 4408 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 4409 | |
| 4410 | switch (type) { |
| 4411 | case Primitive::kPrimByte: |
| 4412 | __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4413 | break; |
| 4414 | case Primitive::kPrimBoolean: |
| 4415 | __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4416 | break; |
| 4417 | case Primitive::kPrimShort: |
| 4418 | __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4419 | break; |
| 4420 | case Primitive::kPrimChar: |
| 4421 | __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4422 | break; |
| 4423 | case Primitive::kPrimNot: |
| 4424 | case Primitive::kPrimInt: |
| 4425 | __ ldr(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4426 | break; |
| 4427 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| 4428 | case Primitive::kPrimLong: |
| 4429 | case Primitive::kPrimFloat: |
| 4430 | case Primitive::kPrimDouble: |
| 4431 | default: |
| 4432 | LOG(FATAL) << "Unreachable type " << type; |
| 4433 | UNREACHABLE(); |
| 4434 | } |
| 4435 | } |
| 4436 | |
| 4437 | void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type, |
| 4438 | Location loc, |
| 4439 | Register base, |
| 4440 | Register reg_offset, |
| 4441 | Condition cond) { |
| 4442 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 4443 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 4444 | |
| 4445 | switch (type) { |
| 4446 | case Primitive::kPrimByte: |
| 4447 | case Primitive::kPrimBoolean: |
| 4448 | __ strb(loc.AsRegister<Register>(), mem_address, cond); |
| 4449 | break; |
| 4450 | case Primitive::kPrimShort: |
| 4451 | case Primitive::kPrimChar: |
| 4452 | __ strh(loc.AsRegister<Register>(), mem_address, cond); |
| 4453 | break; |
| 4454 | case Primitive::kPrimNot: |
| 4455 | case Primitive::kPrimInt: |
| 4456 | __ str(loc.AsRegister<Register>(), mem_address, cond); |
| 4457 | break; |
| 4458 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| 4459 | case Primitive::kPrimLong: |
| 4460 | case Primitive::kPrimFloat: |
| 4461 | case Primitive::kPrimDouble: |
| 4462 | default: |
| 4463 | LOG(FATAL) << "Unreachable type " << type; |
| 4464 | UNREACHABLE(); |
| 4465 | } |
| 4466 | } |
| 4467 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4468 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4469 | bool object_array_get_with_read_barrier = |
| 4470 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4471 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4472 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4473 | object_array_get_with_read_barrier ? |
| 4474 | LocationSummary::kCallOnSlowPath : |
| 4475 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4476 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4477 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4478 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4479 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4480 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4481 | // The output overlaps in the case of an object array get with |
| 4482 | // read barriers enabled: we do not want the move to overwrite the |
| 4483 | // array's location, as we need it to emit the read barrier. |
| 4484 | locations->SetOut( |
| 4485 | Location::RequiresRegister(), |
| 4486 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4487 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4488 | // We need a temporary register for the read barrier marking slow |
| 4489 | // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier. |
| 4490 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4491 | locations->AddTemp(Location::RequiresRegister()); |
| 4492 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4493 | } |
| 4494 | |
| 4495 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 4496 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4497 | Location obj_loc = locations->InAt(0); |
| 4498 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4499 | Location index = locations->InAt(1); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4500 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4501 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4502 | Primitive::Type type = instruction->GetType(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4503 | HInstruction* array_instr = instruction->GetArray(); |
| 4504 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 4505 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 4506 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4507 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4508 | switch (type) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4509 | case Primitive::kPrimBoolean: |
| 4510 | case Primitive::kPrimByte: |
| 4511 | case Primitive::kPrimShort: |
| 4512 | case Primitive::kPrimChar: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4513 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4514 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4515 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 4516 | uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type)); |
| 4517 | |
| 4518 | LoadOperandType load_type = GetLoadOperandType(type); |
| 4519 | __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4520 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4521 | Register temp = IP; |
| 4522 | |
| 4523 | if (has_intermediate_address) { |
| 4524 | // We do not need to compute the intermediate address from the array: the |
| 4525 | // input instruction has done it already. See the comment in |
| 4526 | // `TryExtractArrayAccessAddress()`. |
| 4527 | if (kIsDebugBuild) { |
| 4528 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 4529 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 4530 | } |
| 4531 | temp = obj; |
| 4532 | } else { |
| 4533 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 4534 | } |
| 4535 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4536 | } |
| 4537 | break; |
| 4538 | } |
| 4539 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4540 | case Primitive::kPrimNot: { |
| 4541 | static_assert( |
| 4542 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4543 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4544 | // /* HeapReference<Object> */ out = |
| 4545 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4546 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4547 | Location temp = locations->GetTemp(0); |
| 4548 | // Note that a potential implicit null check is handled in this |
| 4549 | // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call. |
| 4550 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4551 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 4552 | } else { |
| 4553 | Register out = out_loc.AsRegister<Register>(); |
| 4554 | if (index.IsConstant()) { |
| 4555 | size_t offset = |
| 4556 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4557 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 4558 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4559 | // If read barriers are enabled, emit read barriers other than |
| 4560 | // Baker's using a slow path (and also unpoison the loaded |
| 4561 | // reference, if heap poisoning is enabled). |
| 4562 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4563 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4564 | Register temp = IP; |
| 4565 | |
| 4566 | if (has_intermediate_address) { |
| 4567 | // We do not need to compute the intermediate address from the array: the |
| 4568 | // input instruction has done it already. See the comment in |
| 4569 | // `TryExtractArrayAccessAddress()`. |
| 4570 | if (kIsDebugBuild) { |
| 4571 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 4572 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 4573 | } |
| 4574 | temp = obj; |
| 4575 | } else { |
| 4576 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 4577 | } |
| 4578 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4579 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4580 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4581 | // If read barriers are enabled, emit read barriers other than |
| 4582 | // Baker's using a slow path (and also unpoison the loaded |
| 4583 | // reference, if heap poisoning is enabled). |
| 4584 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4585 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4586 | } |
| 4587 | } |
| 4588 | break; |
| 4589 | } |
| 4590 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4591 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4592 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4593 | size_t offset = |
| 4594 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4595 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4596 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4597 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4598 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4599 | } |
| 4600 | break; |
| 4601 | } |
| 4602 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4603 | case Primitive::kPrimFloat: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4604 | SRegister out = out_loc.AsFpuRegister<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4605 | if (index.IsConstant()) { |
| 4606 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4607 | __ LoadSFromOffset(out, obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4608 | } else { |
| 4609 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4610 | __ LoadSFromOffset(out, IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4611 | } |
| 4612 | break; |
| 4613 | } |
| 4614 | |
| 4615 | case Primitive::kPrimDouble: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4616 | SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4617 | if (index.IsConstant()) { |
| 4618 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4619 | __ LoadDFromOffset(FromLowSToD(out), obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4620 | } else { |
| 4621 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4622 | __ LoadDFromOffset(FromLowSToD(out), IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4623 | } |
| 4624 | break; |
| 4625 | } |
| 4626 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4627 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4628 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4629 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4630 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4631 | |
| 4632 | if (type == Primitive::kPrimNot) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4633 | // Potential implicit null checks, in the case of reference |
| 4634 | // arrays, are handled in the previous switch statement. |
| 4635 | } else { |
| 4636 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4637 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4638 | } |
| 4639 | |
| 4640 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4641 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4642 | |
| 4643 | bool needs_write_barrier = |
| 4644 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4645 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4646 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4647 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4648 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 4649 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4650 | LocationSummary::kCallOnSlowPath : |
| 4651 | LocationSummary::kNoCall); |
| 4652 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4653 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4654 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4655 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4656 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4657 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4658 | locations->SetInAt(2, Location::RequiresRegister()); |
| 4659 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4660 | if (needs_write_barrier) { |
| 4661 | // Temporary registers for the write barrier. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4662 | // These registers may be used for Baker read barriers too. |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4663 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 4664 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4665 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4666 | } |
| 4667 | |
| 4668 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 4669 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4670 | Location array_loc = locations->InAt(0); |
| 4671 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4672 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4673 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4674 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4675 | bool needs_write_barrier = |
| 4676 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4677 | uint32_t data_offset = |
| 4678 | mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 4679 | Location value_loc = locations->InAt(2); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4680 | HInstruction* array_instr = instruction->GetArray(); |
| 4681 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 4682 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 4683 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4684 | |
| 4685 | switch (value_type) { |
| 4686 | case Primitive::kPrimBoolean: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4687 | case Primitive::kPrimByte: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4688 | case Primitive::kPrimShort: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4689 | case Primitive::kPrimChar: |
| 4690 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4691 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4692 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 4693 | uint32_t full_offset = |
| 4694 | data_offset + (const_index << Primitive::ComponentSizeShift(value_type)); |
| 4695 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 4696 | __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4697 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4698 | Register temp = IP; |
| 4699 | |
| 4700 | if (has_intermediate_address) { |
| 4701 | // We do not need to compute the intermediate address from the array: the |
| 4702 | // input instruction has done it already. See the comment in |
| 4703 | // `TryExtractArrayAccessAddress()`. |
| 4704 | if (kIsDebugBuild) { |
| 4705 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 4706 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset); |
| 4707 | } |
| 4708 | temp = array; |
| 4709 | } else { |
| 4710 | __ add(temp, array, ShifterOperand(data_offset)); |
| 4711 | } |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4712 | codegen_->StoreToShiftedRegOffset(value_type, |
| 4713 | value_loc, |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4714 | temp, |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4715 | index.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4716 | } |
| 4717 | break; |
| 4718 | } |
| 4719 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4720 | case Primitive::kPrimNot: { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4721 | Register value = value_loc.AsRegister<Register>(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4722 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 4723 | // See the comment in instruction_simplifier_shared.cc. |
| 4724 | DCHECK(!has_intermediate_address); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4725 | |
| 4726 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 4727 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4728 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4729 | size_t offset = |
| 4730 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4731 | __ StoreToOffset(kStoreWord, value, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4732 | } else { |
| 4733 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4734 | __ add(IP, array, ShifterOperand(data_offset)); |
| 4735 | codegen_->StoreToShiftedRegOffset(value_type, |
| 4736 | value_loc, |
| 4737 | IP, |
| 4738 | index.AsRegister<Register>()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4739 | } |
Roland Levillain | 1407ee7 | 2016-01-08 15:56:19 +0000 | [diff] [blame] | 4740 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4741 | DCHECK(!needs_write_barrier); |
| 4742 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4743 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4744 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4745 | |
| 4746 | DCHECK(needs_write_barrier); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4747 | Location temp1_loc = locations->GetTemp(0); |
| 4748 | Register temp1 = temp1_loc.AsRegister<Register>(); |
| 4749 | Location temp2_loc = locations->GetTemp(1); |
| 4750 | Register temp2 = temp2_loc.AsRegister<Register>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4751 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4752 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4753 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4754 | Label done; |
| 4755 | SlowPathCode* slow_path = nullptr; |
| 4756 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4757 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4758 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 4759 | codegen_->AddSlowPath(slow_path); |
| 4760 | if (instruction->GetValueCanBeNull()) { |
| 4761 | Label non_zero; |
| 4762 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 4763 | if (index.IsConstant()) { |
| 4764 | size_t offset = |
| 4765 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4766 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 4767 | } else { |
| 4768 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4769 | __ add(IP, array, ShifterOperand(data_offset)); |
| 4770 | codegen_->StoreToShiftedRegOffset(value_type, |
| 4771 | value_loc, |
| 4772 | IP, |
| 4773 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4774 | } |
| 4775 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4776 | __ b(&done); |
| 4777 | __ Bind(&non_zero); |
| 4778 | } |
| 4779 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4780 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4781 | if (!kUseBakerReadBarrier) { |
| 4782 | // When (non-Baker) read barriers are enabled, the type |
| 4783 | // checking instrumentation requires two read barriers |
| 4784 | // generated by CodeGeneratorARM::GenerateReadBarrierSlow: |
| 4785 | // |
| 4786 | // __ Mov(temp2, temp1); |
| 4787 | // // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 4788 | // __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 4789 | // codegen_->GenerateReadBarrierSlow( |
| 4790 | // instruction, temp1_loc, temp1_loc, temp2_loc, component_offset); |
| 4791 | // |
| 4792 | // // /* HeapReference<Class> */ temp2 = value->klass_ |
| 4793 | // __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 4794 | // codegen_->GenerateReadBarrierSlow( |
| 4795 | // instruction, temp2_loc, temp2_loc, value_loc, class_offset, temp1_loc); |
| 4796 | // |
| 4797 | // __ cmp(temp1, ShifterOperand(temp2)); |
| 4798 | // |
| 4799 | // However, the second read barrier may trash `temp`, as it |
| 4800 | // is a temporary register, and as such would not be saved |
| 4801 | // along with live registers before calling the runtime (nor |
| 4802 | // restored afterwards). So in this case, we bail out and |
| 4803 | // delegate the work to the array set slow path. |
| 4804 | // |
| 4805 | // TODO: Extend the register allocator to support a new |
| 4806 | // "(locally) live temp" location so as to avoid always |
| 4807 | // going into the slow path when read barriers are enabled? |
| 4808 | // |
| 4809 | // There is no such problem with Baker read barriers (see below). |
| 4810 | __ b(slow_path->GetEntryLabel()); |
| 4811 | } else { |
| 4812 | Register temp3 = IP; |
| 4813 | Location temp3_loc = Location::RegisterLocation(temp3); |
| 4814 | |
| 4815 | // Note: `temp3` (scratch register IP) cannot be used as |
| 4816 | // `ref` argument of GenerateFieldLoadWithBakerReadBarrier |
| 4817 | // calls below (see ReadBarrierMarkSlowPathARM for more |
| 4818 | // details). |
| 4819 | |
| 4820 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 4821 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4822 | temp1_loc, |
| 4823 | array, |
| 4824 | class_offset, |
| 4825 | temp3_loc, |
| 4826 | /* needs_null_check */ true); |
| 4827 | |
| 4828 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 4829 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4830 | temp1_loc, |
| 4831 | temp1, |
| 4832 | component_offset, |
| 4833 | temp3_loc, |
| 4834 | /* needs_null_check */ false); |
| 4835 | // Register `temp1` is not trashed by the read barrier |
| 4836 | // emitted by GenerateFieldLoadWithBakerReadBarrier below, |
| 4837 | // as that method produces a call to a ReadBarrierMarkRegX |
| 4838 | // entry point, which saves all potentially live registers, |
| 4839 | // including temporaries such a `temp1`. |
| 4840 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 4841 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4842 | temp2_loc, |
| 4843 | value, |
| 4844 | class_offset, |
| 4845 | temp3_loc, |
| 4846 | /* needs_null_check */ false); |
| 4847 | // If heap poisoning is enabled, `temp1` and `temp2` have |
| 4848 | // been unpoisoned by the the previous calls to |
| 4849 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
| 4850 | __ cmp(temp1, ShifterOperand(temp2)); |
| 4851 | |
| 4852 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4853 | Label do_put; |
| 4854 | __ b(&do_put, EQ); |
| 4855 | // We do not need to emit a read barrier for the |
| 4856 | // following heap reference load, as `temp1` is only used |
| 4857 | // in a comparison with null below, and this reference |
| 4858 | // is not kept afterwards. |
| 4859 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 4860 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 4861 | // If heap poisoning is enabled, no need to unpoison |
| 4862 | // `temp`, as we are comparing against null below. |
| 4863 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 4864 | __ Bind(&do_put); |
| 4865 | } else { |
| 4866 | __ b(slow_path->GetEntryLabel(), NE); |
| 4867 | } |
| 4868 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4869 | } else { |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4870 | // Non read barrier code. |
| 4871 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4872 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 4873 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 4874 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4875 | __ MaybeUnpoisonHeapReference(temp1); |
| 4876 | |
| 4877 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 4878 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 4879 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 4880 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 4881 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 4882 | // nor `temp2`, as we are comparing two poisoned references. |
| 4883 | __ cmp(temp1, ShifterOperand(temp2)); |
| 4884 | |
| 4885 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4886 | Label do_put; |
| 4887 | __ b(&do_put, EQ); |
| 4888 | // If heap poisoning is enabled, the `temp1` reference has |
| 4889 | // not been unpoisoned yet; unpoison it now. |
| 4890 | __ MaybeUnpoisonHeapReference(temp1); |
| 4891 | |
| 4892 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 4893 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 4894 | // If heap poisoning is enabled, no need to unpoison |
| 4895 | // `temp1`, as we are comparing against null below. |
| 4896 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 4897 | __ Bind(&do_put); |
| 4898 | } else { |
| 4899 | __ b(slow_path->GetEntryLabel(), NE); |
| 4900 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4901 | } |
| 4902 | } |
| 4903 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4904 | Register source = value; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4905 | if (kPoisonHeapReferences) { |
| 4906 | // Note that in the case where `value` is a null reference, |
| 4907 | // we do not enter this block, as a null reference does not |
| 4908 | // need poisoning. |
| 4909 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 4910 | __ Mov(temp1, value); |
| 4911 | __ PoisonHeapReference(temp1); |
| 4912 | source = temp1; |
| 4913 | } |
| 4914 | |
| 4915 | if (index.IsConstant()) { |
| 4916 | size_t offset = |
| 4917 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4918 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 4919 | } else { |
| 4920 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4921 | |
| 4922 | __ add(IP, array, ShifterOperand(data_offset)); |
| 4923 | codegen_->StoreToShiftedRegOffset(value_type, |
| 4924 | Location::RegisterLocation(source), |
| 4925 | IP, |
| 4926 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4927 | } |
| 4928 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4929 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4930 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4931 | } |
| 4932 | |
| 4933 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 4934 | |
| 4935 | if (done.IsLinked()) { |
| 4936 | __ Bind(&done); |
| 4937 | } |
| 4938 | |
| 4939 | if (slow_path != nullptr) { |
| 4940 | __ Bind(slow_path->GetExitLabel()); |
| 4941 | } |
| 4942 | |
| 4943 | break; |
| 4944 | } |
| 4945 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4946 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4947 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4948 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4949 | size_t offset = |
| 4950 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4951 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4952 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4953 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4954 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4955 | } |
| 4956 | break; |
| 4957 | } |
| 4958 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4959 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4960 | Location value = locations->InAt(2); |
| 4961 | DCHECK(value.IsFpuRegister()); |
| 4962 | if (index.IsConstant()) { |
| 4963 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4964 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4965 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4966 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4967 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 4968 | } |
| 4969 | break; |
| 4970 | } |
| 4971 | |
| 4972 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4973 | Location value = locations->InAt(2); |
| 4974 | DCHECK(value.IsFpuRegisterPair()); |
| 4975 | if (index.IsConstant()) { |
| 4976 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4977 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4978 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4979 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4980 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 4981 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4982 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4983 | break; |
| 4984 | } |
| 4985 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4986 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4987 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4988 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4989 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4990 | |
Roland Levillain | 80e6709 | 2016-01-08 16:04:55 +0000 | [diff] [blame] | 4991 | // Objects are handled in the switch. |
| 4992 | if (value_type != Primitive::kPrimNot) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4993 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4994 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4995 | } |
| 4996 | |
| 4997 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4998 | LocationSummary* locations = |
| 4999 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5000 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5001 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5002 | } |
| 5003 | |
| 5004 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 5005 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5006 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5007 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5008 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5009 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5010 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5011 | } |
| 5012 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5013 | void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 5014 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 5015 | DCHECK(!kEmitCompilerReadBarrier); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5016 | LocationSummary* locations = |
| 5017 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5018 | |
| 5019 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5020 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 5021 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5022 | } |
| 5023 | |
| 5024 | void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 5025 | LocationSummary* locations = instruction->GetLocations(); |
| 5026 | Location out = locations->Out(); |
| 5027 | Location first = locations->InAt(0); |
| 5028 | Location second = locations->InAt(1); |
| 5029 | |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 5030 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 5031 | DCHECK(!kEmitCompilerReadBarrier); |
| 5032 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5033 | if (second.IsRegister()) { |
| 5034 | __ add(out.AsRegister<Register>(), |
| 5035 | first.AsRegister<Register>(), |
| 5036 | ShifterOperand(second.AsRegister<Register>())); |
| 5037 | } else { |
| 5038 | __ AddConstant(out.AsRegister<Register>(), |
| 5039 | first.AsRegister<Register>(), |
| 5040 | second.GetConstant()->AsIntConstant()->GetValue()); |
| 5041 | } |
| 5042 | } |
| 5043 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5044 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5045 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5046 | ? LocationSummary::kCallOnSlowPath |
| 5047 | : LocationSummary::kNoCall; |
| 5048 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5049 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5050 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5051 | if (instruction->HasUses()) { |
| 5052 | locations->SetOut(Location::SameAsFirstInput()); |
| 5053 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5054 | } |
| 5055 | |
| 5056 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5057 | LocationSummary* locations = instruction->GetLocations(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5058 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5059 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5060 | codegen_->AddSlowPath(slow_path); |
| 5061 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5062 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 5063 | Register length = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5064 | |
| 5065 | __ cmp(index, ShifterOperand(length)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 5066 | __ b(slow_path->GetEntryLabel(), HS); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5067 | } |
| 5068 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5069 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 5070 | Register card, |
| 5071 | Register object, |
| 5072 | Register value, |
| 5073 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5074 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5075 | if (can_be_null) { |
| 5076 | __ CompareAndBranchIfZero(value, &is_null); |
| 5077 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5078 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5079 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 5080 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5081 | if (can_be_null) { |
| 5082 | __ Bind(&is_null); |
| 5083 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5084 | } |
| 5085 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5086 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5087 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5088 | } |
| 5089 | |
| 5090 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5091 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5092 | } |
| 5093 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5094 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5095 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5096 | } |
| 5097 | |
| 5098 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5099 | HBasicBlock* block = instruction->GetBlock(); |
| 5100 | if (block->GetLoopInformation() != nullptr) { |
| 5101 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5102 | // The back edge will generate the suspend check. |
| 5103 | return; |
| 5104 | } |
| 5105 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5106 | // The goto will generate the suspend check. |
| 5107 | return; |
| 5108 | } |
| 5109 | GenerateSuspendCheck(instruction, nullptr); |
| 5110 | } |
| 5111 | |
| 5112 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5113 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5114 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5115 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 5116 | if (slow_path == nullptr) { |
| 5117 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 5118 | instruction->SetSlowPath(slow_path); |
| 5119 | codegen_->AddSlowPath(slow_path); |
| 5120 | if (successor != nullptr) { |
| 5121 | DCHECK(successor->IsLoopHeader()); |
| 5122 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5123 | } |
| 5124 | } else { |
| 5125 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5126 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5127 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 5128 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5129 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5130 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5131 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5132 | __ Bind(slow_path->GetReturnLabel()); |
| 5133 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5134 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5135 | __ b(slow_path->GetEntryLabel()); |
| 5136 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5137 | } |
| 5138 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5139 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 5140 | return codegen_->GetAssembler(); |
| 5141 | } |
| 5142 | |
| 5143 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5144 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5145 | Location source = move->GetSource(); |
| 5146 | Location destination = move->GetDestination(); |
| 5147 | |
| 5148 | if (source.IsRegister()) { |
| 5149 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5150 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5151 | } else if (destination.IsFpuRegister()) { |
| 5152 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5153 | } else { |
| 5154 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5155 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5156 | SP, destination.GetStackIndex()); |
| 5157 | } |
| 5158 | } else if (source.IsStackSlot()) { |
| 5159 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5160 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5161 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5162 | } else if (destination.IsFpuRegister()) { |
| 5163 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5164 | } else { |
| 5165 | DCHECK(destination.IsStackSlot()); |
| 5166 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 5167 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5168 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5169 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5170 | if (destination.IsRegister()) { |
| 5171 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
| 5172 | } else if (destination.IsFpuRegister()) { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5173 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5174 | } else { |
| 5175 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5176 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 5177 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5178 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5179 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5180 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 5181 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5182 | } else if (destination.IsRegisterPair()) { |
| 5183 | DCHECK(ExpectedPairLayout(destination)); |
| 5184 | __ LoadFromOffset( |
| 5185 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 5186 | } else { |
| 5187 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 5188 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5189 | SP, |
| 5190 | source.GetStackIndex()); |
| 5191 | } |
| 5192 | } else if (source.IsRegisterPair()) { |
| 5193 | if (destination.IsRegisterPair()) { |
| 5194 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 5195 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5196 | } else if (destination.IsFpuRegisterPair()) { |
| 5197 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5198 | source.AsRegisterPairLow<Register>(), |
| 5199 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5200 | } else { |
| 5201 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5202 | DCHECK(ExpectedPairLayout(source)); |
| 5203 | __ StoreToOffset( |
| 5204 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 5205 | } |
| 5206 | } else if (source.IsFpuRegisterPair()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5207 | if (destination.IsRegisterPair()) { |
| 5208 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5209 | destination.AsRegisterPairHigh<Register>(), |
| 5210 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5211 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5212 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5213 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5214 | } else { |
| 5215 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5216 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 5217 | SP, |
| 5218 | destination.GetStackIndex()); |
| 5219 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5220 | } else { |
| 5221 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5222 | HConstant* constant = source.GetConstant(); |
| 5223 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5224 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5225 | if (destination.IsRegister()) { |
| 5226 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 5227 | } else { |
| 5228 | DCHECK(destination.IsStackSlot()); |
| 5229 | __ LoadImmediate(IP, value); |
| 5230 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5231 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5232 | } else if (constant->IsLongConstant()) { |
| 5233 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5234 | if (destination.IsRegisterPair()) { |
| 5235 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 5236 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5237 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5238 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5239 | __ LoadImmediate(IP, Low32Bits(value)); |
| 5240 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5241 | __ LoadImmediate(IP, High32Bits(value)); |
| 5242 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5243 | } |
| 5244 | } else if (constant->IsDoubleConstant()) { |
| 5245 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5246 | if (destination.IsFpuRegisterPair()) { |
| 5247 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5248 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5249 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5250 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5251 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 5252 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5253 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 5254 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5255 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5256 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5257 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5258 | float value = constant->AsFloatConstant()->GetValue(); |
| 5259 | if (destination.IsFpuRegister()) { |
| 5260 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 5261 | } else { |
| 5262 | DCHECK(destination.IsStackSlot()); |
| 5263 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 5264 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5265 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5266 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5267 | } |
| 5268 | } |
| 5269 | |
| 5270 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 5271 | __ Mov(IP, reg); |
| 5272 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 5273 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 5274 | } |
| 5275 | |
| 5276 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 5277 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 5278 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 5279 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5280 | SP, mem1 + stack_offset); |
| 5281 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 5282 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5283 | SP, mem2 + stack_offset); |
| 5284 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 5285 | } |
| 5286 | |
| 5287 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5288 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5289 | Location source = move->GetSource(); |
| 5290 | Location destination = move->GetDestination(); |
| 5291 | |
| 5292 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5293 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 5294 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 5295 | __ Mov(IP, source.AsRegister<Register>()); |
| 5296 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5297 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5298 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5299 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5300 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5301 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5302 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5303 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5304 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5305 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5306 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5307 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5308 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5309 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5310 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5311 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5312 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5313 | destination.AsRegisterPairHigh<Register>(), |
| 5314 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5315 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5316 | Register low_reg = source.IsRegisterPair() |
| 5317 | ? source.AsRegisterPairLow<Register>() |
| 5318 | : destination.AsRegisterPairLow<Register>(); |
| 5319 | int mem = source.IsRegisterPair() |
| 5320 | ? destination.GetStackIndex() |
| 5321 | : source.GetStackIndex(); |
| 5322 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5323 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5324 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5325 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5326 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5327 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 5328 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5329 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5330 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5331 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5332 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 5333 | DRegister reg = source.IsFpuRegisterPair() |
| 5334 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 5335 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 5336 | int mem = source.IsFpuRegisterPair() |
| 5337 | ? destination.GetStackIndex() |
| 5338 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5339 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5340 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5341 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5342 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 5343 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 5344 | : destination.AsFpuRegister<SRegister>(); |
| 5345 | int mem = source.IsFpuRegister() |
| 5346 | ? destination.GetStackIndex() |
| 5347 | : source.GetStackIndex(); |
| 5348 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5349 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5350 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5351 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5352 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5353 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 5354 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5355 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5356 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5357 | } |
| 5358 | } |
| 5359 | |
| 5360 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 5361 | __ Push(static_cast<Register>(reg)); |
| 5362 | } |
| 5363 | |
| 5364 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 5365 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5366 | } |
| 5367 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5368 | HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind( |
| 5369 | HLoadClass::LoadKind desired_class_load_kind) { |
| 5370 | if (kEmitCompilerReadBarrier) { |
| 5371 | switch (desired_class_load_kind) { |
| 5372 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5373 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5374 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5375 | // TODO: Implement for read barrier. |
| 5376 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5377 | default: |
| 5378 | break; |
| 5379 | } |
| 5380 | } |
| 5381 | switch (desired_class_load_kind) { |
| 5382 | case HLoadClass::LoadKind::kReferrersClass: |
| 5383 | break; |
| 5384 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5385 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5386 | break; |
| 5387 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5388 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5389 | break; |
| 5390 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5391 | break; |
| 5392 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 5393 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5394 | break; |
| 5395 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5396 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5397 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5398 | // is incompatible with it. |
| 5399 | // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods |
| 5400 | // with irreducible loops. |
| 5401 | if (GetGraph()->HasIrreducibleLoops()) { |
| 5402 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5403 | } |
| 5404 | break; |
| 5405 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5406 | break; |
| 5407 | } |
| 5408 | return desired_class_load_kind; |
| 5409 | } |
| 5410 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5411 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5412 | if (cls->NeedsAccessCheck()) { |
| 5413 | InvokeRuntimeCallingConvention calling_convention; |
| 5414 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5415 | cls, |
| 5416 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 5417 | Location::RegisterLocation(R0), |
| 5418 | /* code_generator_supports_read_barrier */ true); |
| 5419 | return; |
| 5420 | } |
| 5421 | |
| 5422 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier) |
| 5423 | ? LocationSummary::kCallOnSlowPath |
| 5424 | : LocationSummary::kNoCall; |
| 5425 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
| 5426 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5427 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 5428 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod || |
| 5429 | load_kind == HLoadClass::LoadKind::kDexCachePcRelative) { |
| 5430 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5431 | } |
| 5432 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5433 | } |
| 5434 | |
| 5435 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5436 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5437 | if (cls->NeedsAccessCheck()) { |
| 5438 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5439 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5440 | cls, |
| 5441 | cls->GetDexPc(), |
| 5442 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5443 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5444 | return; |
| 5445 | } |
| 5446 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5447 | Location out_loc = locations->Out(); |
| 5448 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5449 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5450 | bool generate_null_check = false; |
| 5451 | switch (cls->GetLoadKind()) { |
| 5452 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5453 | DCHECK(!cls->CanCallRuntime()); |
| 5454 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5455 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5456 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 5457 | GenerateGcRootFieldLoad( |
| 5458 | cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
| 5459 | break; |
| 5460 | } |
| 5461 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
| 5462 | DCHECK(!kEmitCompilerReadBarrier); |
| 5463 | __ LoadLiteral(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 5464 | cls->GetTypeIndex())); |
| 5465 | break; |
| 5466 | } |
| 5467 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
| 5468 | DCHECK(!kEmitCompilerReadBarrier); |
| 5469 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 5470 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 5471 | __ BindTrackedLabel(&labels->movw_label); |
| 5472 | __ movw(out, /* placeholder */ 0u); |
| 5473 | __ BindTrackedLabel(&labels->movt_label); |
| 5474 | __ movt(out, /* placeholder */ 0u); |
| 5475 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5476 | __ add(out, out, ShifterOperand(PC)); |
| 5477 | break; |
| 5478 | } |
| 5479 | case HLoadClass::LoadKind::kBootImageAddress: { |
| 5480 | DCHECK(!kEmitCompilerReadBarrier); |
| 5481 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5482 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5483 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5484 | break; |
| 5485 | } |
| 5486 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 5487 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5488 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5489 | // 16-bit LDR immediate has a 5-bit offset multiplied by the size and that gives |
| 5490 | // a 128B range. To try and reduce the number of literals if we load multiple types, |
| 5491 | // simply split the dex cache address to a 128B aligned base loaded from a literal |
| 5492 | // and the remaining offset embedded in the load. |
| 5493 | static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes."); |
| 5494 | DCHECK_ALIGNED(cls->GetAddress(), 4u); |
| 5495 | constexpr size_t offset_bits = /* encoded bits */ 5 + /* scale */ 2; |
| 5496 | uint32_t base_address = address & ~MaxInt<uint32_t>(offset_bits); |
| 5497 | uint32_t offset = address & MaxInt<uint32_t>(offset_bits); |
| 5498 | __ LoadLiteral(out, codegen_->DeduplicateDexCacheAddressLiteral(base_address)); |
| 5499 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) |
| 5500 | GenerateGcRootFieldLoad(cls, out_loc, out, offset); |
| 5501 | generate_null_check = !cls->IsInDexCache(); |
| 5502 | break; |
| 5503 | } |
| 5504 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 5505 | Register base_reg = locations->InAt(0).AsRegister<Register>(); |
| 5506 | HArmDexCacheArraysBase* base = cls->InputAt(0)->AsArmDexCacheArraysBase(); |
| 5507 | int32_t offset = cls->GetDexCacheElementOffset() - base->GetElementOffset(); |
| 5508 | // /* GcRoot<mirror::Class> */ out = *(dex_cache_arrays_base + offset) |
| 5509 | GenerateGcRootFieldLoad(cls, out_loc, base_reg, offset); |
| 5510 | generate_null_check = !cls->IsInDexCache(); |
| 5511 | break; |
| 5512 | } |
| 5513 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 5514 | // /* GcRoot<mirror::Class>[] */ out = |
| 5515 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5516 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 5517 | __ LoadFromOffset(kLoadWord, |
| 5518 | out, |
| 5519 | current_method, |
| 5520 | ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value()); |
| 5521 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5522 | size_t offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex()); |
| 5523 | GenerateGcRootFieldLoad(cls, out_loc, out, offset); |
| 5524 | generate_null_check = !cls->IsInDexCache(); |
| 5525 | } |
| 5526 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5527 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5528 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5529 | DCHECK(cls->CanCallRuntime()); |
| 5530 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
| 5531 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5532 | codegen_->AddSlowPath(slow_path); |
| 5533 | if (generate_null_check) { |
| 5534 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 5535 | } |
| 5536 | if (cls->MustGenerateClinitCheck()) { |
| 5537 | GenerateClassInitializationCheck(slow_path, out); |
| 5538 | } else { |
| 5539 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5540 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5541 | } |
| 5542 | } |
| 5543 | |
| 5544 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 5545 | LocationSummary* locations = |
| 5546 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5547 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5548 | if (check->HasUses()) { |
| 5549 | locations->SetOut(Location::SameAsFirstInput()); |
| 5550 | } |
| 5551 | } |
| 5552 | |
| 5553 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5554 | // We assume the class is not null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5555 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5556 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5557 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5558 | GenerateClassInitializationCheck(slow_path, |
| 5559 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5560 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5561 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5562 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5563 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5564 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 5565 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 5566 | __ b(slow_path->GetEntryLabel(), LT); |
| 5567 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 5568 | // properly. Therefore, we do a memory fence. |
| 5569 | __ dmb(ISH); |
| 5570 | __ Bind(slow_path->GetExitLabel()); |
| 5571 | } |
| 5572 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5573 | HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind( |
| 5574 | HLoadString::LoadKind desired_string_load_kind) { |
| 5575 | if (kEmitCompilerReadBarrier) { |
| 5576 | switch (desired_string_load_kind) { |
| 5577 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5578 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5579 | case HLoadString::LoadKind::kBootImageAddress: |
| 5580 | // TODO: Implement for read barrier. |
| 5581 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 5582 | default: |
| 5583 | break; |
| 5584 | } |
| 5585 | } |
| 5586 | switch (desired_string_load_kind) { |
| 5587 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5588 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5589 | break; |
| 5590 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5591 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5592 | break; |
| 5593 | case HLoadString::LoadKind::kBootImageAddress: |
| 5594 | break; |
| 5595 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5596 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5597 | break; |
| 5598 | case HLoadString::LoadKind::kDexCachePcRelative: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5599 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5600 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5601 | // is incompatible with it. |
| 5602 | // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods |
| 5603 | // with irreducible loops. |
| 5604 | if (GetGraph()->HasIrreducibleLoops()) { |
| 5605 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 5606 | } |
| 5607 | break; |
| 5608 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5609 | break; |
| 5610 | } |
| 5611 | return desired_string_load_kind; |
| 5612 | } |
| 5613 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5614 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5615 | LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5616 | ? LocationSummary::kCallOnSlowPath |
| 5617 | : LocationSummary::kNoCall; |
| 5618 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5619 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 5620 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod || |
| 5621 | load_kind == HLoadString::LoadKind::kDexCachePcRelative) { |
| 5622 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5623 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5624 | locations->SetOut(Location::RequiresRegister()); |
| 5625 | } |
| 5626 | |
| 5627 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5628 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5629 | Location out_loc = locations->Out(); |
| 5630 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5631 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5632 | switch (load->GetLoadKind()) { |
| 5633 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
| 5634 | DCHECK(!kEmitCompilerReadBarrier); |
| 5635 | __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 5636 | load->GetStringIndex())); |
| 5637 | return; // No dex cache slow path. |
| 5638 | } |
| 5639 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 5640 | DCHECK(!kEmitCompilerReadBarrier); |
| 5641 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 5642 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
| 5643 | __ BindTrackedLabel(&labels->movw_label); |
| 5644 | __ movw(out, /* placeholder */ 0u); |
| 5645 | __ BindTrackedLabel(&labels->movt_label); |
| 5646 | __ movt(out, /* placeholder */ 0u); |
| 5647 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5648 | __ add(out, out, ShifterOperand(PC)); |
| 5649 | return; // No dex cache slow path. |
| 5650 | } |
| 5651 | case HLoadString::LoadKind::kBootImageAddress: { |
| 5652 | DCHECK(!kEmitCompilerReadBarrier); |
| 5653 | DCHECK_NE(load->GetAddress(), 0u); |
| 5654 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 5655 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5656 | return; // No dex cache slow path. |
| 5657 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5658 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5659 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5660 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5661 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5662 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
| 5663 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 5664 | codegen_->AddSlowPath(slow_path); |
| 5665 | __ b(slow_path->GetEntryLabel()); |
| 5666 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5667 | } |
| 5668 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5669 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5670 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5671 | } |
| 5672 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5673 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 5674 | LocationSummary* locations = |
| 5675 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5676 | locations->SetOut(Location::RequiresRegister()); |
| 5677 | } |
| 5678 | |
| 5679 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5680 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5681 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 5682 | } |
| 5683 | |
| 5684 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 5685 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5686 | } |
| 5687 | |
| 5688 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5689 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5690 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5691 | } |
| 5692 | |
| 5693 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 5694 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5695 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5696 | InvokeRuntimeCallingConvention calling_convention; |
| 5697 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5698 | } |
| 5699 | |
| 5700 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
| 5701 | codegen_->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 5702 | QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5703 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5704 | } |
| 5705 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5706 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5707 | return kEmitCompilerReadBarrier && |
| 5708 | (kUseBakerReadBarrier || |
| 5709 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5710 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5711 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5712 | } |
| 5713 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5714 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5715 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5716 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5717 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5718 | case TypeCheckKind::kExactCheck: |
| 5719 | case TypeCheckKind::kAbstractClassCheck: |
| 5720 | case TypeCheckKind::kClassHierarchyCheck: |
| 5721 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5722 | call_kind = |
| 5723 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5724 | break; |
| 5725 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5726 | case TypeCheckKind::kUnresolvedCheck: |
| 5727 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5728 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5729 | break; |
| 5730 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5731 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5732 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5733 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5734 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5735 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 5736 | // Note that TypeCheckSlowPathARM uses this register too. |
| 5737 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5738 | // When read barriers are enabled, we need a temporary register for |
| 5739 | // some cases. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5740 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5741 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5742 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5743 | } |
| 5744 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5745 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5746 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5747 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5748 | Location obj_loc = locations->InAt(0); |
| 5749 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5750 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5751 | Location out_loc = locations->Out(); |
| 5752 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5753 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5754 | locations->GetTemp(0) : |
| 5755 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5756 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5757 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5758 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5759 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5760 | Label done, zero; |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5761 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5762 | |
| 5763 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5764 | // avoid null check if we know obj is not null. |
| 5765 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | d56376c | 2015-05-21 12:32:34 +0000 | [diff] [blame] | 5766 | __ CompareAndBranchIfZero(obj, &zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5767 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5768 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5769 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5770 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5771 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5772 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5773 | case TypeCheckKind::kExactCheck: { |
| 5774 | __ cmp(out, ShifterOperand(cls)); |
| 5775 | // Classes must be equal for the instanceof to succeed. |
| 5776 | __ b(&zero, NE); |
| 5777 | __ LoadImmediate(out, 1); |
| 5778 | __ b(&done); |
| 5779 | break; |
| 5780 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5781 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5782 | case TypeCheckKind::kAbstractClassCheck: { |
| 5783 | // If the class is abstract, we eagerly fetch the super class of the |
| 5784 | // object to avoid doing a comparison we know will fail. |
| 5785 | Label loop; |
| 5786 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5787 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5788 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5789 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5790 | __ CompareAndBranchIfZero(out, &done); |
| 5791 | __ cmp(out, ShifterOperand(cls)); |
| 5792 | __ b(&loop, NE); |
| 5793 | __ LoadImmediate(out, 1); |
| 5794 | if (zero.IsLinked()) { |
| 5795 | __ b(&done); |
| 5796 | } |
| 5797 | break; |
| 5798 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5799 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5800 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5801 | // Walk over the class hierarchy to find a match. |
| 5802 | Label loop, success; |
| 5803 | __ Bind(&loop); |
| 5804 | __ cmp(out, ShifterOperand(cls)); |
| 5805 | __ b(&success, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5806 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5807 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5808 | __ CompareAndBranchIfNonZero(out, &loop); |
| 5809 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5810 | __ b(&done); |
| 5811 | __ Bind(&success); |
| 5812 | __ LoadImmediate(out, 1); |
| 5813 | if (zero.IsLinked()) { |
| 5814 | __ b(&done); |
| 5815 | } |
| 5816 | break; |
| 5817 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5818 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5819 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5820 | // Do an exact check. |
| 5821 | Label exact_check; |
| 5822 | __ cmp(out, ShifterOperand(cls)); |
| 5823 | __ b(&exact_check, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5824 | // Otherwise, we need to check that the object's class is a non-primitive array. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5825 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5826 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5827 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5828 | __ CompareAndBranchIfZero(out, &done); |
| 5829 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 5830 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 5831 | __ CompareAndBranchIfNonZero(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5832 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5833 | __ LoadImmediate(out, 1); |
| 5834 | __ b(&done); |
| 5835 | break; |
| 5836 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5837 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5838 | case TypeCheckKind::kArrayCheck: { |
| 5839 | __ cmp(out, ShifterOperand(cls)); |
| 5840 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5841 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5842 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5843 | codegen_->AddSlowPath(slow_path); |
| 5844 | __ b(slow_path->GetEntryLabel(), NE); |
| 5845 | __ LoadImmediate(out, 1); |
| 5846 | if (zero.IsLinked()) { |
| 5847 | __ b(&done); |
| 5848 | } |
| 5849 | break; |
| 5850 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5851 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5852 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5853 | case TypeCheckKind::kInterfaceCheck: { |
| 5854 | // Note that we indeed only call on slow path, but we always go |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 5855 | // into the slow path for the unresolved and interface check |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5856 | // cases. |
| 5857 | // |
| 5858 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5859 | // entry point without resorting to a type checking slow path |
| 5860 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5861 | // require to assign fixed registers for the inputs of this |
| 5862 | // HInstanceOf instruction (following the runtime calling |
| 5863 | // convention), which might be cluttered by the potential first |
| 5864 | // read barrier emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5865 | // |
| 5866 | // TODO: Introduce a new runtime entry point taking the object |
| 5867 | // to test (instead of its class) as argument, and let it deal |
| 5868 | // with the read barrier issues. This will let us refactor this |
| 5869 | // case of the `switch` code as it was previously (with a direct |
| 5870 | // call to the runtime not using a type checking slow path). |
| 5871 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5872 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5873 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5874 | /* is_fatal */ false); |
| 5875 | codegen_->AddSlowPath(slow_path); |
| 5876 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5877 | if (zero.IsLinked()) { |
| 5878 | __ b(&done); |
| 5879 | } |
| 5880 | break; |
| 5881 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5882 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5883 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5884 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5885 | __ Bind(&zero); |
| 5886 | __ LoadImmediate(out, 0); |
| 5887 | } |
| 5888 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5889 | if (done.IsLinked()) { |
| 5890 | __ Bind(&done); |
| 5891 | } |
| 5892 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5893 | if (slow_path != nullptr) { |
| 5894 | __ Bind(slow_path->GetExitLabel()); |
| 5895 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5896 | } |
| 5897 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5898 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5899 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5900 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 5901 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5902 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5903 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5904 | case TypeCheckKind::kExactCheck: |
| 5905 | case TypeCheckKind::kAbstractClassCheck: |
| 5906 | case TypeCheckKind::kClassHierarchyCheck: |
| 5907 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5908 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 5909 | LocationSummary::kCallOnSlowPath : |
| 5910 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5911 | break; |
| 5912 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5913 | case TypeCheckKind::kUnresolvedCheck: |
| 5914 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5915 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5916 | break; |
| 5917 | } |
| 5918 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5919 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5920 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5921 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5922 | // Note that TypeCheckSlowPathARM uses this "temp" register too. |
| 5923 | locations->AddTemp(Location::RequiresRegister()); |
| 5924 | // When read barriers are enabled, we need an additional temporary |
| 5925 | // register for some cases. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5926 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5927 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5928 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5929 | } |
| 5930 | |
| 5931 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5932 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5933 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5934 | Location obj_loc = locations->InAt(0); |
| 5935 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5936 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5937 | Location temp_loc = locations->GetTemp(0); |
| 5938 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5939 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5940 | locations->GetTemp(1) : |
| 5941 | Location::NoLocation(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5942 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5943 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5944 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5945 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5946 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5947 | bool is_type_check_slow_path_fatal = |
| 5948 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 5949 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5950 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5951 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 5952 | !instruction->CanThrowIntoCatchBlock(); |
| 5953 | SlowPathCode* type_check_slow_path = |
| 5954 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5955 | is_type_check_slow_path_fatal); |
| 5956 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5957 | |
| 5958 | Label done; |
| 5959 | // Avoid null check if we know obj is not null. |
| 5960 | if (instruction->MustDoNullCheck()) { |
| 5961 | __ CompareAndBranchIfZero(obj, &done); |
| 5962 | } |
| 5963 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5964 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5965 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5966 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5967 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5968 | case TypeCheckKind::kExactCheck: |
| 5969 | case TypeCheckKind::kArrayCheck: { |
| 5970 | __ cmp(temp, ShifterOperand(cls)); |
| 5971 | // Jump to slow path for throwing the exception or doing a |
| 5972 | // more involved array check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5973 | __ b(type_check_slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5974 | break; |
| 5975 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5976 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5977 | case TypeCheckKind::kAbstractClassCheck: { |
| 5978 | // If the class is abstract, we eagerly fetch the super class of the |
| 5979 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5980 | Label loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5981 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5982 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5983 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5984 | |
| 5985 | // If the class reference currently in `temp` is not null, jump |
| 5986 | // to the `compare_classes` label to compare it with the checked |
| 5987 | // class. |
| 5988 | __ CompareAndBranchIfNonZero(temp, &compare_classes); |
| 5989 | // Otherwise, jump to the slow path to throw the exception. |
| 5990 | // |
| 5991 | // But before, move back the object's class into `temp` before |
| 5992 | // going into the slow path, as it has been overwritten in the |
| 5993 | // meantime. |
| 5994 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5995 | GenerateReferenceLoadTwoRegisters( |
| 5996 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5997 | __ b(type_check_slow_path->GetEntryLabel()); |
| 5998 | |
| 5999 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6000 | __ cmp(temp, ShifterOperand(cls)); |
| 6001 | __ b(&loop, NE); |
| 6002 | break; |
| 6003 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6004 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6005 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6006 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6007 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6008 | __ Bind(&loop); |
| 6009 | __ cmp(temp, ShifterOperand(cls)); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6010 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6011 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6012 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6013 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6014 | |
| 6015 | // If the class reference currently in `temp` is not null, jump |
| 6016 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6017 | __ CompareAndBranchIfNonZero(temp, &loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6018 | // Otherwise, jump to the slow path to throw the exception. |
| 6019 | // |
| 6020 | // But before, move back the object's class into `temp` before |
| 6021 | // going into the slow path, as it has been overwritten in the |
| 6022 | // meantime. |
| 6023 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6024 | GenerateReferenceLoadTwoRegisters( |
| 6025 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6026 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6027 | break; |
| 6028 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6029 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6030 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6031 | // Do an exact check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6032 | Label check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6033 | __ cmp(temp, ShifterOperand(cls)); |
| 6034 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6035 | |
| 6036 | // Otherwise, we need to check that the object's class is a non-primitive array. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6037 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6038 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6039 | |
| 6040 | // If the component type is not null (i.e. the object is indeed |
| 6041 | // an array), jump to label `check_non_primitive_component_type` |
| 6042 | // to further check that this component type is not a primitive |
| 6043 | // type. |
| 6044 | __ CompareAndBranchIfNonZero(temp, &check_non_primitive_component_type); |
| 6045 | // Otherwise, jump to the slow path to throw the exception. |
| 6046 | // |
| 6047 | // But before, move back the object's class into `temp` before |
| 6048 | // going into the slow path, as it has been overwritten in the |
| 6049 | // meantime. |
| 6050 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6051 | GenerateReferenceLoadTwoRegisters( |
| 6052 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6053 | __ b(type_check_slow_path->GetEntryLabel()); |
| 6054 | |
| 6055 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6056 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6057 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
| 6058 | __ CompareAndBranchIfZero(temp, &done); |
| 6059 | // Same comment as above regarding `temp` and the slow path. |
| 6060 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6061 | GenerateReferenceLoadTwoRegisters( |
| 6062 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6063 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6064 | break; |
| 6065 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6066 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6067 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6068 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6069 | // We always go into the type check slow path for the unresolved |
| 6070 | // and interface check cases. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6071 | // |
| 6072 | // We cannot directly call the CheckCast runtime entry point |
| 6073 | // without resorting to a type checking slow path here (i.e. by |
| 6074 | // calling InvokeRuntime directly), as it would require to |
| 6075 | // assign fixed registers for the inputs of this HInstanceOf |
| 6076 | // instruction (following the runtime calling convention), which |
| 6077 | // might be cluttered by the potential first read barrier |
| 6078 | // emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6079 | // |
| 6080 | // TODO: Introduce a new runtime entry point taking the object |
| 6081 | // to test (instead of its class) as argument, and let it deal |
| 6082 | // with the read barrier issues. This will let us refactor this |
| 6083 | // case of the `switch` code as it was previously (with a direct |
| 6084 | // call to the runtime not using a type checking slow path). |
| 6085 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6086 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6087 | break; |
| 6088 | } |
| 6089 | __ Bind(&done); |
| 6090 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6091 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6092 | } |
| 6093 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6094 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6095 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6096 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6097 | InvokeRuntimeCallingConvention calling_convention; |
| 6098 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6099 | } |
| 6100 | |
| 6101 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6102 | codegen_->InvokeRuntime(instruction->IsEnter() |
| 6103 | ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject), |
| 6104 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 6105 | instruction->GetDexPc(), |
| 6106 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6107 | if (instruction->IsEnter()) { |
| 6108 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6109 | } else { |
| 6110 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6111 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6112 | } |
| 6113 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6114 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 6115 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 6116 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6117 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6118 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6119 | LocationSummary* locations = |
| 6120 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6121 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6122 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6123 | // Note: GVN reorders commutative operations to have the constant on the right hand side. |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6124 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6125 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 6126 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6127 | } |
| 6128 | |
| 6129 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 6130 | HandleBitwiseOperation(instruction); |
| 6131 | } |
| 6132 | |
| 6133 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 6134 | HandleBitwiseOperation(instruction); |
| 6135 | } |
| 6136 | |
| 6137 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 6138 | HandleBitwiseOperation(instruction); |
| 6139 | } |
| 6140 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 6141 | |
| 6142 | void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6143 | LocationSummary* locations = |
| 6144 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6145 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6146 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6147 | |
| 6148 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6149 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6150 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6151 | } |
| 6152 | |
| 6153 | void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6154 | LocationSummary* locations = instruction->GetLocations(); |
| 6155 | Location first = locations->InAt(0); |
| 6156 | Location second = locations->InAt(1); |
| 6157 | Location out = locations->Out(); |
| 6158 | |
| 6159 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6160 | Register first_reg = first.AsRegister<Register>(); |
| 6161 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 6162 | Register out_reg = out.AsRegister<Register>(); |
| 6163 | |
| 6164 | switch (instruction->GetOpKind()) { |
| 6165 | case HInstruction::kAnd: |
| 6166 | __ bic(out_reg, first_reg, second_reg); |
| 6167 | break; |
| 6168 | case HInstruction::kOr: |
| 6169 | __ orn(out_reg, first_reg, second_reg); |
| 6170 | break; |
| 6171 | // There is no EON on arm. |
| 6172 | case HInstruction::kXor: |
| 6173 | default: |
| 6174 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6175 | UNREACHABLE(); |
| 6176 | } |
| 6177 | return; |
| 6178 | |
| 6179 | } else { |
| 6180 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6181 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6182 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6183 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 6184 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 6185 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6186 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6187 | |
| 6188 | switch (instruction->GetOpKind()) { |
| 6189 | case HInstruction::kAnd: |
| 6190 | __ bic(out_low, first_low, second_low); |
| 6191 | __ bic(out_high, first_high, second_high); |
| 6192 | break; |
| 6193 | case HInstruction::kOr: |
| 6194 | __ orn(out_low, first_low, second_low); |
| 6195 | __ orn(out_high, first_high, second_high); |
| 6196 | break; |
| 6197 | // There is no EON on arm. |
| 6198 | case HInstruction::kXor: |
| 6199 | default: |
| 6200 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6201 | UNREACHABLE(); |
| 6202 | } |
| 6203 | } |
| 6204 | } |
| 6205 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6206 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 6207 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 6208 | if (value == 0xffffffffu) { |
| 6209 | if (out != first) { |
| 6210 | __ mov(out, ShifterOperand(first)); |
| 6211 | } |
| 6212 | return; |
| 6213 | } |
| 6214 | if (value == 0u) { |
| 6215 | __ mov(out, ShifterOperand(0)); |
| 6216 | return; |
| 6217 | } |
| 6218 | ShifterOperand so; |
| 6219 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 6220 | __ and_(out, first, so); |
| 6221 | } else { |
| 6222 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)); |
| 6223 | __ bic(out, first, ShifterOperand(~value)); |
| 6224 | } |
| 6225 | } |
| 6226 | |
| 6227 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 6228 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 6229 | if (value == 0u) { |
| 6230 | if (out != first) { |
| 6231 | __ mov(out, ShifterOperand(first)); |
| 6232 | } |
| 6233 | return; |
| 6234 | } |
| 6235 | if (value == 0xffffffffu) { |
| 6236 | __ mvn(out, ShifterOperand(0)); |
| 6237 | return; |
| 6238 | } |
| 6239 | ShifterOperand so; |
| 6240 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 6241 | __ orr(out, first, so); |
| 6242 | } else { |
| 6243 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 6244 | __ orn(out, first, ShifterOperand(~value)); |
| 6245 | } |
| 6246 | } |
| 6247 | |
| 6248 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 6249 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 6250 | if (value == 0u) { |
| 6251 | if (out != first) { |
| 6252 | __ mov(out, ShifterOperand(first)); |
| 6253 | } |
| 6254 | return; |
| 6255 | } |
| 6256 | __ eor(out, first, ShifterOperand(value)); |
| 6257 | } |
| 6258 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 6259 | void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out, |
| 6260 | Location first, |
| 6261 | uint64_t value) { |
| 6262 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6263 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6264 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6265 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6266 | uint32_t value_low = Low32Bits(value); |
| 6267 | uint32_t value_high = High32Bits(value); |
| 6268 | if (value_low == 0u) { |
| 6269 | if (out_low != first_low) { |
| 6270 | __ mov(out_low, ShifterOperand(first_low)); |
| 6271 | } |
| 6272 | __ AddConstant(out_high, first_high, value_high); |
| 6273 | return; |
| 6274 | } |
| 6275 | __ AddConstantSetFlags(out_low, first_low, value_low); |
| 6276 | ShifterOperand so; |
| 6277 | if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) { |
| 6278 | __ adc(out_high, first_high, so); |
| 6279 | } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) { |
| 6280 | __ sbc(out_high, first_high, so); |
| 6281 | } else { |
| 6282 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 6283 | UNREACHABLE(); |
| 6284 | } |
| 6285 | } |
| 6286 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6287 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6288 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6289 | Location first = locations->InAt(0); |
| 6290 | Location second = locations->InAt(1); |
| 6291 | Location out = locations->Out(); |
| 6292 | |
| 6293 | if (second.IsConstant()) { |
| 6294 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 6295 | uint32_t value_low = Low32Bits(value); |
| 6296 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6297 | Register first_reg = first.AsRegister<Register>(); |
| 6298 | Register out_reg = out.AsRegister<Register>(); |
| 6299 | if (instruction->IsAnd()) { |
| 6300 | GenerateAndConst(out_reg, first_reg, value_low); |
| 6301 | } else if (instruction->IsOr()) { |
| 6302 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 6303 | } else { |
| 6304 | DCHECK(instruction->IsXor()); |
| 6305 | GenerateEorConst(out_reg, first_reg, value_low); |
| 6306 | } |
| 6307 | } else { |
| 6308 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6309 | uint32_t value_high = High32Bits(value); |
| 6310 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6311 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6312 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6313 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6314 | if (instruction->IsAnd()) { |
| 6315 | GenerateAndConst(out_low, first_low, value_low); |
| 6316 | GenerateAndConst(out_high, first_high, value_high); |
| 6317 | } else if (instruction->IsOr()) { |
| 6318 | GenerateOrrConst(out_low, first_low, value_low); |
| 6319 | GenerateOrrConst(out_high, first_high, value_high); |
| 6320 | } else { |
| 6321 | DCHECK(instruction->IsXor()); |
| 6322 | GenerateEorConst(out_low, first_low, value_low); |
| 6323 | GenerateEorConst(out_high, first_high, value_high); |
| 6324 | } |
| 6325 | } |
| 6326 | return; |
| 6327 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6328 | |
| 6329 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6330 | Register first_reg = first.AsRegister<Register>(); |
| 6331 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 6332 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6333 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6334 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6335 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6336 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6337 | } else { |
| 6338 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6339 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6340 | } |
| 6341 | } else { |
| 6342 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6343 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6344 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6345 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 6346 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 6347 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6348 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6349 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6350 | __ and_(out_low, first_low, second_low); |
| 6351 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6352 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6353 | __ orr(out_low, first_low, second_low); |
| 6354 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6355 | } else { |
| 6356 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6357 | __ eor(out_low, first_low, second_low); |
| 6358 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6359 | } |
| 6360 | } |
| 6361 | } |
| 6362 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6363 | void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6364 | Location out, |
| 6365 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6366 | Location maybe_temp) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6367 | Register out_reg = out.AsRegister<Register>(); |
| 6368 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6369 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6370 | if (kUseBakerReadBarrier) { |
| 6371 | // Load with fast path based Baker's read barrier. |
| 6372 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6373 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6374 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6375 | } else { |
| 6376 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6377 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6378 | // in the following move operation, as we will need it for the |
| 6379 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6380 | __ Mov(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6381 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6382 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6383 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6384 | } |
| 6385 | } else { |
| 6386 | // Plain load with no read barrier. |
| 6387 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6388 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6389 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6390 | } |
| 6391 | } |
| 6392 | |
| 6393 | void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6394 | Location out, |
| 6395 | Location obj, |
| 6396 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6397 | Location maybe_temp) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6398 | Register out_reg = out.AsRegister<Register>(); |
| 6399 | Register obj_reg = obj.AsRegister<Register>(); |
| 6400 | if (kEmitCompilerReadBarrier) { |
| 6401 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6402 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6403 | // Load with fast path based Baker's read barrier. |
| 6404 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6405 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6406 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6407 | } else { |
| 6408 | // Load with slow path based read barrier. |
| 6409 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6410 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6411 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6412 | } |
| 6413 | } else { |
| 6414 | // Plain load with no read barrier. |
| 6415 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6416 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6417 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6418 | } |
| 6419 | } |
| 6420 | |
| 6421 | void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6422 | Location root, |
| 6423 | Register obj, |
| 6424 | uint32_t offset) { |
| 6425 | Register root_reg = root.AsRegister<Register>(); |
| 6426 | if (kEmitCompilerReadBarrier) { |
| 6427 | if (kUseBakerReadBarrier) { |
| 6428 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6429 | // Baker's read barrier are used: |
| 6430 | // |
| 6431 | // root = obj.field; |
| 6432 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6433 | // root = ReadBarrier::Mark(root) |
| 6434 | // } |
| 6435 | |
| 6436 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6437 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6438 | static_assert( |
| 6439 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6440 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6441 | "have different sizes."); |
| 6442 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6443 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6444 | "have different sizes."); |
| 6445 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6446 | // Slow path marking the GC root `root`. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6447 | SlowPathCode* slow_path = |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 6448 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, root); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6449 | codegen_->AddSlowPath(slow_path); |
| 6450 | |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6451 | // IP = Thread::Current()->GetIsGcMarking() |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6452 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6453 | kLoadWord, IP, TR, Thread::IsGcMarkingOffset<kArmPointerSize>().Int32Value()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6454 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
| 6455 | __ Bind(slow_path->GetExitLabel()); |
| 6456 | } else { |
| 6457 | // GC root loaded through a slow path for read barriers other |
| 6458 | // than Baker's. |
| 6459 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6460 | __ AddConstant(root_reg, obj, offset); |
| 6461 | // /* mirror::Object* */ root = root->Read() |
| 6462 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6463 | } |
| 6464 | } else { |
| 6465 | // Plain GC root load with no read barrier. |
| 6466 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6467 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6468 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6469 | // do not have to unpoison `root_reg` here. |
| 6470 | } |
| 6471 | } |
| 6472 | |
| 6473 | void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6474 | Location ref, |
| 6475 | Register obj, |
| 6476 | uint32_t offset, |
| 6477 | Location temp, |
| 6478 | bool needs_null_check) { |
| 6479 | DCHECK(kEmitCompilerReadBarrier); |
| 6480 | DCHECK(kUseBakerReadBarrier); |
| 6481 | |
| 6482 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6483 | Location no_index = Location::NoLocation(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6484 | ScaleFactor no_scale_factor = TIMES_1; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6485 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6486 | instruction, ref, obj, offset, no_index, no_scale_factor, temp, needs_null_check); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6487 | } |
| 6488 | |
| 6489 | void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6490 | Location ref, |
| 6491 | Register obj, |
| 6492 | uint32_t data_offset, |
| 6493 | Location index, |
| 6494 | Location temp, |
| 6495 | bool needs_null_check) { |
| 6496 | DCHECK(kEmitCompilerReadBarrier); |
| 6497 | DCHECK(kUseBakerReadBarrier); |
| 6498 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6499 | static_assert( |
| 6500 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6501 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6502 | // /* HeapReference<Object> */ ref = |
| 6503 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6504 | ScaleFactor scale_factor = TIMES_4; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6505 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6506 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6507 | } |
| 6508 | |
| 6509 | void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6510 | Location ref, |
| 6511 | Register obj, |
| 6512 | uint32_t offset, |
| 6513 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6514 | ScaleFactor scale_factor, |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6515 | Location temp, |
| 6516 | bool needs_null_check) { |
| 6517 | DCHECK(kEmitCompilerReadBarrier); |
| 6518 | DCHECK(kUseBakerReadBarrier); |
| 6519 | |
| 6520 | // In slow path based read barriers, the read barrier call is |
| 6521 | // inserted after the original load. However, in fast path based |
| 6522 | // Baker's read barriers, we need to perform the load of |
| 6523 | // mirror::Object::monitor_ *before* the original reference load. |
| 6524 | // This load-load ordering is required by the read barrier. |
| 6525 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6526 | // |
| 6527 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6528 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6529 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6530 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6531 | // if (is_gray) { |
| 6532 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6533 | // } |
| 6534 | // |
| 6535 | // Note: the original implementation in ReadBarrier::Barrier is |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6536 | // slightly more complex as it performs additional checks that we do |
| 6537 | // not do here for performance reasons. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6538 | |
| 6539 | Register ref_reg = ref.AsRegister<Register>(); |
| 6540 | Register temp_reg = temp.AsRegister<Register>(); |
| 6541 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6542 | |
| 6543 | // /* int32_t */ monitor = obj->monitor_ |
| 6544 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 6545 | if (needs_null_check) { |
| 6546 | MaybeRecordImplicitNullCheck(instruction); |
| 6547 | } |
| 6548 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6549 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6550 | "art::LockWord and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6551 | |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 6552 | // Introduce a dependency on the lock_word including the rb_state, |
| 6553 | // which shall prevent load-load reordering without using |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6554 | // a memory barrier (which would be more expensive). |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 6555 | // `obj` is unchanged by this operation, but its value now depends |
| 6556 | // on `temp_reg`. |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 6557 | __ add(obj, obj, ShifterOperand(temp_reg, LSR, 32)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6558 | |
| 6559 | // The actual reference load. |
| 6560 | if (index.IsValid()) { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6561 | // Load types involving an "index": ArrayGet and |
| 6562 | // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 6563 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6564 | if (index.IsConstant()) { |
| 6565 | size_t computed_offset = |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6566 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6567 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 6568 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6569 | // Handle the special case of the |
| 6570 | // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics, which use |
| 6571 | // a register pair as index ("long offset"), of which only the low |
| 6572 | // part contains data. |
| 6573 | Register index_reg = index.IsRegisterPair() |
| 6574 | ? index.AsRegisterPairLow<Register>() |
| 6575 | : index.AsRegister<Register>(); |
| 6576 | __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6577 | __ LoadFromOffset(kLoadWord, ref_reg, IP, offset); |
| 6578 | } |
| 6579 | } else { |
| 6580 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6581 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 6582 | } |
| 6583 | |
| 6584 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6585 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6586 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6587 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6588 | SlowPathCode* slow_path = |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 6589 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, ref); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6590 | AddSlowPath(slow_path); |
| 6591 | |
| 6592 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6593 | // ref = ReadBarrier::Mark(ref); |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 6594 | // Given the numeric representation, it's enough to check the low bit of the |
| 6595 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 6596 | // which can be a 16-bit instruction unlike the TST immediate. |
| 6597 | static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0"); |
| 6598 | static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1"); |
| 6599 | static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2"); |
| 6600 | __ Lsrs(temp_reg, temp_reg, LockWord::kReadBarrierStateShift + 1); |
| 6601 | __ b(slow_path->GetEntryLabel(), CS); // Carry flag is the last bit shifted out by LSRS. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6602 | __ Bind(slow_path->GetExitLabel()); |
| 6603 | } |
| 6604 | |
| 6605 | void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6606 | Location out, |
| 6607 | Location ref, |
| 6608 | Location obj, |
| 6609 | uint32_t offset, |
| 6610 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6611 | DCHECK(kEmitCompilerReadBarrier); |
| 6612 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6613 | // Insert a slow path based read barrier *after* the reference load. |
| 6614 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6615 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6616 | // reference will be carried out by the runtime within the slow |
| 6617 | // path. |
| 6618 | // |
| 6619 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6620 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6621 | // not used by the artReadBarrierSlow entry point. |
| 6622 | // |
| 6623 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6624 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6625 | ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index); |
| 6626 | AddSlowPath(slow_path); |
| 6627 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6628 | __ b(slow_path->GetEntryLabel()); |
| 6629 | __ Bind(slow_path->GetExitLabel()); |
| 6630 | } |
| 6631 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6632 | void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6633 | Location out, |
| 6634 | Location ref, |
| 6635 | Location obj, |
| 6636 | uint32_t offset, |
| 6637 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6638 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6639 | // Baker's read barriers shall be handled by the fast path |
| 6640 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
| 6641 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6642 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6643 | // by the runtime within the slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6644 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6645 | } else if (kPoisonHeapReferences) { |
| 6646 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6647 | } |
| 6648 | } |
| 6649 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6650 | void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6651 | Location out, |
| 6652 | Location root) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6653 | DCHECK(kEmitCompilerReadBarrier); |
| 6654 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6655 | // Insert a slow path based read barrier *after* the GC root load. |
| 6656 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6657 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6658 | // not need to do anything special for this here. |
| 6659 | SlowPathCode* slow_path = |
| 6660 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root); |
| 6661 | AddSlowPath(slow_path); |
| 6662 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6663 | __ b(slow_path->GetEntryLabel()); |
| 6664 | __ Bind(slow_path->GetExitLabel()); |
| 6665 | } |
| 6666 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6667 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 6668 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 6669 | MethodReference target_method) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6670 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 6671 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 6672 | // is incompatible with it. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6673 | // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods |
| 6674 | // with irreducible loops. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6675 | if (GetGraph()->HasIrreducibleLoops() && |
| 6676 | (dispatch_info.method_load_kind == |
| 6677 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 6678 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 6679 | } |
| 6680 | |
| 6681 | if (dispatch_info.code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6682 | const DexFile& outer_dex_file = GetGraph()->GetDexFile(); |
| 6683 | if (&outer_dex_file != target_method.dex_file) { |
| 6684 | // Calls across dex files are more likely to exceed the available BL range, |
| 6685 | // so use absolute patch with fixup if available and kCallArtMethod otherwise. |
| 6686 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = |
| 6687 | (desired_dispatch_info.method_load_kind == |
| 6688 | HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) |
| 6689 | ? HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup |
| 6690 | : HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod; |
| 6691 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6692 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6693 | code_ptr_location, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6694 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6695 | 0u |
| 6696 | }; |
| 6697 | } |
| 6698 | } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6699 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6700 | } |
| 6701 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6702 | Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 6703 | Register temp) { |
| 6704 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 6705 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 6706 | if (!invoke->GetLocations()->Intrinsified()) { |
| 6707 | return location.AsRegister<Register>(); |
| 6708 | } |
| 6709 | // For intrinsics we allow any location, so it may be on the stack. |
| 6710 | if (!location.IsRegister()) { |
| 6711 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 6712 | return temp; |
| 6713 | } |
| 6714 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 6715 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 6716 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 6717 | // simple and more robust approach rather that trying to determine if that's the case. |
| 6718 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 6719 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 6720 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 6721 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 6722 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 6723 | return temp; |
| 6724 | } |
| 6725 | return location.AsRegister<Register>(); |
| 6726 | } |
| 6727 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 6728 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6729 | // For better instruction scheduling we load the direct code pointer before the method pointer. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6730 | switch (invoke->GetCodePtrLocation()) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6731 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 6732 | // LR = code address from literal pool with link-time patch. |
| 6733 | __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6734 | break; |
| 6735 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 6736 | // LR = invoke->GetDirectCodePtr(); |
| 6737 | __ LoadImmediate(LR, invoke->GetDirectCodePtr()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6738 | break; |
| 6739 | default: |
| 6740 | break; |
| 6741 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6742 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6743 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 6744 | switch (invoke->GetMethodLoadKind()) { |
| 6745 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 6746 | // temp = thread->string_init_entrypoint |
| 6747 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, invoke->GetStringInitOffset()); |
| 6748 | break; |
| 6749 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 6750 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6751 | break; |
| 6752 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 6753 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 6754 | break; |
| 6755 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 6756 | __ LoadLiteral(temp.AsRegister<Register>(), |
| 6757 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 6758 | break; |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6759 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 6760 | HArmDexCacheArraysBase* base = |
| 6761 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 6762 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 6763 | temp.AsRegister<Register>()); |
| 6764 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 6765 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 6766 | break; |
| 6767 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6768 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 6769 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6770 | Register method_reg; |
| 6771 | Register reg = temp.AsRegister<Register>(); |
| 6772 | if (current_method.IsRegister()) { |
| 6773 | method_reg = current_method.AsRegister<Register>(); |
| 6774 | } else { |
| 6775 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 6776 | DCHECK(!current_method.IsValid()); |
| 6777 | method_reg = reg; |
| 6778 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 6779 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6780 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 6781 | __ LoadFromOffset(kLoadWord, |
| 6782 | reg, |
| 6783 | method_reg, |
| 6784 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 6785 | // temp = temp[index_in_cache]; |
| 6786 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 6787 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6788 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 6789 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 6790 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6791 | } |
| 6792 | |
| 6793 | switch (invoke->GetCodePtrLocation()) { |
| 6794 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 6795 | __ bl(GetFrameEntryLabel()); |
| 6796 | break; |
| 6797 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6798 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6799 | __ BindTrackedLabel(&relative_call_patches_.back().label); |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6800 | // Arbitrarily branch to the BL itself, override at link time. |
| 6801 | __ bl(&relative_call_patches_.back().label); |
| 6802 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6803 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 6804 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 6805 | // LR prepared above for better instruction scheduling. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6806 | // LR() |
| 6807 | __ blx(LR); |
| 6808 | break; |
| 6809 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 6810 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 6811 | __ LoadFromOffset( |
| 6812 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6813 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6814 | // LR() |
| 6815 | __ blx(LR); |
| 6816 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6817 | } |
| 6818 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6819 | DCHECK(!IsLeafMethod()); |
| 6820 | } |
| 6821 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6822 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 6823 | Register temp = temp_location.AsRegister<Register>(); |
| 6824 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 6825 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6826 | |
| 6827 | // Use the calling convention instead of the location of the receiver, as |
| 6828 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 6829 | // slow path, the arguments have been moved to the right place, so here we are |
| 6830 | // guaranteed that the receiver is the first register of the calling convention. |
| 6831 | InvokeDexCallingConvention calling_convention; |
| 6832 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6833 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6834 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6835 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6836 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6837 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 6838 | // emit a read barrier for the previous class reference load. |
| 6839 | // However this is not required in practice, as this is an |
| 6840 | // intermediate/temporary reference and because the current |
| 6841 | // concurrent copying collector keeps the from-space memory |
| 6842 | // intact/accessible until the end of the marking phase (the |
| 6843 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6844 | __ MaybeUnpoisonHeapReference(temp); |
| 6845 | // temp = temp->GetMethodAt(method_offset); |
| 6846 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6847 | kArmPointerSize).Int32Value(); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6848 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 6849 | // LR = temp->GetEntryPoint(); |
| 6850 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 6851 | // LR(); |
| 6852 | __ blx(LR); |
| 6853 | } |
| 6854 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6855 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch( |
| 6856 | const DexFile& dex_file, uint32_t string_index) { |
| 6857 | return NewPcRelativePatch(dex_file, string_index, &pc_relative_string_patches_); |
| 6858 | } |
| 6859 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6860 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch( |
| 6861 | const DexFile& dex_file, uint32_t type_index) { |
| 6862 | return NewPcRelativePatch(dex_file, type_index, &pc_relative_type_patches_); |
| 6863 | } |
| 6864 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6865 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch( |
| 6866 | const DexFile& dex_file, uint32_t element_offset) { |
| 6867 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 6868 | } |
| 6869 | |
| 6870 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch( |
| 6871 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 6872 | patches->emplace_back(dex_file, offset_or_index); |
| 6873 | return &patches->back(); |
| 6874 | } |
| 6875 | |
| 6876 | Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
| 6877 | uint32_t string_index) { |
| 6878 | return boot_image_string_patches_.GetOrCreate( |
| 6879 | StringReference(&dex_file, string_index), |
| 6880 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 6881 | } |
| 6882 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6883 | Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file, |
| 6884 | uint32_t type_index) { |
| 6885 | return boot_image_type_patches_.GetOrCreate( |
| 6886 | TypeReference(&dex_file, type_index), |
| 6887 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 6888 | } |
| 6889 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6890 | Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) { |
| 6891 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 6892 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 6893 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 6894 | } |
| 6895 | |
| 6896 | Literal* CodeGeneratorARM::DeduplicateDexCacheAddressLiteral(uint32_t address) { |
| 6897 | return DeduplicateUint32Literal(address, &uint32_literals_); |
| 6898 | } |
| 6899 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6900 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 6901 | DCHECK(linker_patches->empty()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6902 | size_t size = |
| 6903 | method_patches_.size() + |
| 6904 | call_patches_.size() + |
| 6905 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6906 | /* MOVW+MOVT for each base */ 2u * pc_relative_dex_cache_patches_.size() + |
| 6907 | boot_image_string_patches_.size() + |
| 6908 | /* MOVW+MOVT for each base */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6909 | boot_image_type_patches_.size() + |
| 6910 | /* MOVW+MOVT for each base */ 2u * pc_relative_type_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6911 | boot_image_address_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6912 | linker_patches->reserve(size); |
| 6913 | for (const auto& entry : method_patches_) { |
| 6914 | const MethodReference& target_method = entry.first; |
| 6915 | Literal* literal = entry.second; |
| 6916 | DCHECK(literal->GetLabel()->IsBound()); |
| 6917 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6918 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 6919 | target_method.dex_file, |
| 6920 | target_method.dex_method_index)); |
| 6921 | } |
| 6922 | for (const auto& entry : call_patches_) { |
| 6923 | const MethodReference& target_method = entry.first; |
| 6924 | Literal* literal = entry.second; |
| 6925 | DCHECK(literal->GetLabel()->IsBound()); |
| 6926 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6927 | linker_patches->push_back(LinkerPatch::CodePatch(literal_offset, |
| 6928 | target_method.dex_file, |
| 6929 | target_method.dex_method_index)); |
| 6930 | } |
| 6931 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 6932 | uint32_t literal_offset = info.label.Position(); |
| 6933 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 6934 | info.target_method.dex_file, |
| 6935 | info.target_method.dex_method_index)); |
| 6936 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6937 | for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) { |
| 6938 | const DexFile& dex_file = info.target_dex_file; |
| 6939 | size_t base_element_offset = info.offset_or_index; |
| 6940 | DCHECK(info.add_pc_label.IsBound()); |
| 6941 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6942 | // Add MOVW patch. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6943 | DCHECK(info.movw_label.IsBound()); |
| 6944 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6945 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movw_offset, |
| 6946 | &dex_file, |
| 6947 | add_pc_offset, |
| 6948 | base_element_offset)); |
| 6949 | // Add MOVT patch. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6950 | DCHECK(info.movt_label.IsBound()); |
| 6951 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6952 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movt_offset, |
| 6953 | &dex_file, |
| 6954 | add_pc_offset, |
| 6955 | base_element_offset)); |
| 6956 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6957 | for (const auto& entry : boot_image_string_patches_) { |
| 6958 | const StringReference& target_string = entry.first; |
| 6959 | Literal* literal = entry.second; |
| 6960 | DCHECK(literal->GetLabel()->IsBound()); |
| 6961 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6962 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 6963 | target_string.dex_file, |
| 6964 | target_string.string_index)); |
| 6965 | } |
| 6966 | for (const PcRelativePatchInfo& info : pc_relative_string_patches_) { |
| 6967 | const DexFile& dex_file = info.target_dex_file; |
| 6968 | uint32_t string_index = info.offset_or_index; |
| 6969 | DCHECK(info.add_pc_label.IsBound()); |
| 6970 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 6971 | // Add MOVW patch. |
| 6972 | DCHECK(info.movw_label.IsBound()); |
| 6973 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 6974 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(movw_offset, |
| 6975 | &dex_file, |
| 6976 | add_pc_offset, |
| 6977 | string_index)); |
| 6978 | // Add MOVT patch. |
| 6979 | DCHECK(info.movt_label.IsBound()); |
| 6980 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 6981 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(movt_offset, |
| 6982 | &dex_file, |
| 6983 | add_pc_offset, |
| 6984 | string_index)); |
| 6985 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6986 | for (const auto& entry : boot_image_type_patches_) { |
| 6987 | const TypeReference& target_type = entry.first; |
| 6988 | Literal* literal = entry.second; |
| 6989 | DCHECK(literal->GetLabel()->IsBound()); |
| 6990 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6991 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 6992 | target_type.dex_file, |
| 6993 | target_type.type_index)); |
| 6994 | } |
| 6995 | for (const PcRelativePatchInfo& info : pc_relative_type_patches_) { |
| 6996 | const DexFile& dex_file = info.target_dex_file; |
| 6997 | uint32_t type_index = info.offset_or_index; |
| 6998 | DCHECK(info.add_pc_label.IsBound()); |
| 6999 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 7000 | // Add MOVW patch. |
| 7001 | DCHECK(info.movw_label.IsBound()); |
| 7002 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 7003 | linker_patches->push_back(LinkerPatch::RelativeTypePatch(movw_offset, |
| 7004 | &dex_file, |
| 7005 | add_pc_offset, |
| 7006 | type_index)); |
| 7007 | // Add MOVT patch. |
| 7008 | DCHECK(info.movt_label.IsBound()); |
| 7009 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 7010 | linker_patches->push_back(LinkerPatch::RelativeTypePatch(movt_offset, |
| 7011 | &dex_file, |
| 7012 | add_pc_offset, |
| 7013 | type_index)); |
| 7014 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7015 | for (const auto& entry : boot_image_address_patches_) { |
| 7016 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
| 7017 | Literal* literal = entry.second; |
| 7018 | DCHECK(literal->GetLabel()->IsBound()); |
| 7019 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7020 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 7021 | } |
| 7022 | } |
| 7023 | |
| 7024 | Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 7025 | return map->GetOrCreate( |
| 7026 | value, |
| 7027 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7028 | } |
| 7029 | |
| 7030 | Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method, |
| 7031 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7032 | return map->GetOrCreate( |
| 7033 | target_method, |
| 7034 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7035 | } |
| 7036 | |
| 7037 | Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) { |
| 7038 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 7039 | } |
| 7040 | |
| 7041 | Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) { |
| 7042 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 7043 | } |
| 7044 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 7045 | void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7046 | LocationSummary* locations = |
| 7047 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 7048 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 7049 | Location::RequiresRegister()); |
| 7050 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 7051 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 7052 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7053 | } |
| 7054 | |
| 7055 | void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7056 | LocationSummary* locations = instr->GetLocations(); |
| 7057 | Register res = locations->Out().AsRegister<Register>(); |
| 7058 | Register accumulator = |
| 7059 | locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>(); |
| 7060 | Register mul_left = |
| 7061 | locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>(); |
| 7062 | Register mul_right = |
| 7063 | locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>(); |
| 7064 | |
| 7065 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 7066 | __ mla(res, mul_left, mul_right, accumulator); |
| 7067 | } else { |
| 7068 | __ mls(res, mul_left, mul_right, accumulator); |
| 7069 | } |
| 7070 | } |
| 7071 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7072 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7073 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7074 | LOG(FATAL) << "Unreachable"; |
| 7075 | } |
| 7076 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7077 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7078 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7079 | LOG(FATAL) << "Unreachable"; |
| 7080 | } |
| 7081 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7082 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7083 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7084 | LocationSummary* locations = |
| 7085 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7086 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7087 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7088 | codegen_->GetAssembler()->IsThumb()) { |
| 7089 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 7090 | if (switch_instr->GetStartValue() != 0) { |
| 7091 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 7092 | } |
| 7093 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7094 | } |
| 7095 | |
| 7096 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7097 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7098 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7099 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7100 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7101 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7102 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7103 | if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7104 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7105 | Register temp_reg = IP; |
| 7106 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 7107 | // the immediate, because IP is used as the destination register. For the other |
| 7108 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 7109 | // and they can be encoded in the instruction without making use of IP register. |
| 7110 | __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound); |
| 7111 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7112 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7113 | // Jump to successors[0] if value == lower_bound. |
| 7114 | __ b(codegen_->GetLabelOf(successors[0]), EQ); |
| 7115 | int32_t last_index = 0; |
| 7116 | for (; num_entries - last_index > 2; last_index += 2) { |
| 7117 | __ AddConstantSetFlags(temp_reg, temp_reg, -2); |
| 7118 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 7119 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO); |
| 7120 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 7121 | __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ); |
| 7122 | } |
| 7123 | if (num_entries - last_index == 2) { |
| 7124 | // The last missing case_value. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 7125 | __ CmpConstant(temp_reg, 1); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7126 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7127 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7128 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7129 | // And the default for any other value. |
| 7130 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 7131 | __ b(codegen_->GetLabelOf(default_block)); |
| 7132 | } |
| 7133 | } else { |
| 7134 | // Create a table lookup. |
| 7135 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7136 | |
| 7137 | // Materialize a pointer to the switch table |
| 7138 | std::vector<Label*> labels(num_entries); |
| 7139 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 7140 | for (uint32_t i = 0; i < num_entries; i++) { |
| 7141 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 7142 | } |
| 7143 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 7144 | |
| 7145 | // Remove the bias. |
| 7146 | Register key_reg; |
| 7147 | if (lower_bound != 0) { |
| 7148 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 7149 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 7150 | } else { |
| 7151 | key_reg = value_reg; |
| 7152 | } |
| 7153 | |
| 7154 | // Check whether the value is in the table, jump to default block if not. |
| 7155 | __ CmpConstant(key_reg, num_entries - 1); |
| 7156 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 7157 | |
| 7158 | // Load the displacement from the table. |
| 7159 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 7160 | |
| 7161 | // Dispatch is a direct add to the PC (for Thumb2). |
| 7162 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7163 | } |
| 7164 | } |
| 7165 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7166 | void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7167 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 7168 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7169 | } |
| 7170 | |
| 7171 | void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7172 | Register base_reg = base->GetLocations()->Out().AsRegister<Register>(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7173 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 7174 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7175 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7176 | __ movw(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7177 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7178 | __ movt(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7179 | __ BindTrackedLabel(&labels->add_pc_label); |
| 7180 | __ add(base_reg, base_reg, ShifterOperand(PC)); |
| 7181 | } |
| 7182 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7183 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 7184 | if (!trg.IsValid()) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7185 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7186 | return; |
| 7187 | } |
| 7188 | |
| 7189 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7190 | |
| 7191 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 7192 | if (return_loc.Equals(trg)) { |
| 7193 | return; |
| 7194 | } |
| 7195 | |
| 7196 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7197 | // with the last branch. |
| 7198 | if (type == Primitive::kPrimLong) { |
| 7199 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7200 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 7201 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7202 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7203 | } else if (type == Primitive::kPrimDouble) { |
| 7204 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7205 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 7206 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 7207 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7208 | } else { |
| 7209 | // Let the parallel move resolver take care of all of this. |
| 7210 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7211 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7212 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7213 | } |
| 7214 | } |
| 7215 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7216 | void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 7217 | LocationSummary* locations = |
| 7218 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7219 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7220 | locations->SetOut(Location::RequiresRegister()); |
| 7221 | } |
| 7222 | |
| 7223 | void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 7224 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7225 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7226 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7227 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7228 | __ LoadFromOffset(kLoadWord, |
| 7229 | locations->Out().AsRegister<Register>(), |
| 7230 | locations->InAt(0).AsRegister<Register>(), |
| 7231 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7232 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7233 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 7234 | instruction->GetIndex(), kArmPointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7235 | __ LoadFromOffset(kLoadWord, |
| 7236 | locations->Out().AsRegister<Register>(), |
| 7237 | locations->InAt(0).AsRegister<Register>(), |
| 7238 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 7239 | __ LoadFromOffset(kLoadWord, |
| 7240 | locations->Out().AsRegister<Register>(), |
| 7241 | locations->Out().AsRegister<Register>(), |
| 7242 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7243 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7244 | } |
| 7245 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7246 | #undef __ |
| 7247 | #undef QUICK_ENTRY_POINT |
| 7248 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7249 | } // namespace arm |
| 7250 | } // namespace art |