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 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 77 | arm_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 78 | instruction_, |
| 79 | instruction_->GetDexPc(), |
| 80 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 81 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 82 | } |
| 83 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 84 | bool IsFatal() const OVERRIDE { return true; } |
| 85 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 86 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; } |
| 87 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 88 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 89 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 90 | }; |
| 91 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 92 | class DivZeroCheckSlowPathARM : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 93 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 94 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 95 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 96 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 97 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 98 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 99 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 100 | // Live registers will be restored in the catch block if caught. |
| 101 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 102 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 103 | arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 104 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 107 | bool IsFatal() const OVERRIDE { return true; } |
| 108 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 109 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; } |
| 110 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 111 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 112 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 113 | }; |
| 114 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 115 | class SuspendCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 116 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 117 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 118 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 119 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 120 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 121 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 122 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 123 | arm_codegen->InvokeRuntime(kQuickTestSuspend, 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); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 177 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 178 | ? kQuickThrowStringBounds |
| 179 | : kQuickThrowArrayBounds; |
| 180 | arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 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()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 212 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 213 | : kQuickInitializeType; |
| 214 | arm_codegen->InvokeRuntime(entrypoint, at_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 215 | if (do_clinit_) { |
| 216 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 217 | } else { |
| 218 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 219 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 220 | |
| 221 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 222 | Location out = locations->Out(); |
| 223 | if (out.IsValid()) { |
| 224 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 225 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 226 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 227 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 228 | __ b(GetExitLabel()); |
| 229 | } |
| 230 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 231 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; } |
| 232 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 233 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 234 | // The class this slow path will load. |
| 235 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 236 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 237 | // The instruction where this slow path is happening. |
| 238 | // (Might be the load class or an initialization check). |
| 239 | HInstruction* const at_; |
| 240 | |
| 241 | // The dex PC of `at_`. |
| 242 | const uint32_t dex_pc_; |
| 243 | |
| 244 | // Whether to initialize the class. |
| 245 | const bool do_clinit_; |
| 246 | |
| 247 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 248 | }; |
| 249 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 250 | class LoadStringSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 251 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 252 | explicit LoadStringSlowPathARM(HLoadString* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 253 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 254 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 255 | LocationSummary* locations = instruction_->GetLocations(); |
| 256 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 257 | |
| 258 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 259 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 260 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 261 | |
| 262 | InvokeRuntimeCallingConvention calling_convention; |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 263 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 264 | __ LoadImmediate(calling_convention.GetRegisterAt(0), string_index); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 265 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 266 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 267 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 268 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 269 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 270 | __ b(GetExitLabel()); |
| 271 | } |
| 272 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 273 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; } |
| 274 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 275 | private: |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 276 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 277 | }; |
| 278 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 279 | class TypeCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 280 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 281 | TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 282 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 283 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 284 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 285 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 286 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 287 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 288 | DCHECK(instruction_->IsCheckCast() |
| 289 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 290 | |
| 291 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 292 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 293 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 294 | if (!is_fatal_) { |
| 295 | SaveLiveRegisters(codegen, locations); |
| 296 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 297 | |
| 298 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 299 | // move resolver. |
| 300 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 301 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 302 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 303 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 304 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 305 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 306 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 307 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 308 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 309 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 310 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 311 | instruction_, |
| 312 | instruction_->GetDexPc(), |
| 313 | this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 314 | CheckEntrypointTypes< |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 315 | kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 316 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 317 | } else { |
| 318 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 319 | arm_codegen->InvokeRuntime(kQuickCheckCast, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 320 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 321 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 322 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 323 | if (!is_fatal_) { |
| 324 | RestoreLiveRegisters(codegen, locations); |
| 325 | __ b(GetExitLabel()); |
| 326 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 327 | } |
| 328 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 329 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; } |
| 330 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 331 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 332 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 333 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 334 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 335 | |
| 336 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 337 | }; |
| 338 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 339 | class DeoptimizationSlowPathARM : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 340 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 341 | explicit DeoptimizationSlowPathARM(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 342 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 343 | |
| 344 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 345 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 346 | __ Bind(GetEntryLabel()); |
| 347 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 348 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 349 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 350 | } |
| 351 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 352 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; } |
| 353 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 354 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 355 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM); |
| 356 | }; |
| 357 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 358 | class ArraySetSlowPathARM : public SlowPathCode { |
| 359 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 360 | explicit ArraySetSlowPathARM(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 361 | |
| 362 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 363 | LocationSummary* locations = instruction_->GetLocations(); |
| 364 | __ Bind(GetEntryLabel()); |
| 365 | SaveLiveRegisters(codegen, locations); |
| 366 | |
| 367 | InvokeRuntimeCallingConvention calling_convention; |
| 368 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 369 | parallel_move.AddMove( |
| 370 | locations->InAt(0), |
| 371 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 372 | Primitive::kPrimNot, |
| 373 | nullptr); |
| 374 | parallel_move.AddMove( |
| 375 | locations->InAt(1), |
| 376 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 377 | Primitive::kPrimInt, |
| 378 | nullptr); |
| 379 | parallel_move.AddMove( |
| 380 | locations->InAt(2), |
| 381 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 382 | Primitive::kPrimNot, |
| 383 | nullptr); |
| 384 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 385 | |
| 386 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 387 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 388 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 389 | RestoreLiveRegisters(codegen, locations); |
| 390 | __ b(GetExitLabel()); |
| 391 | } |
| 392 | |
| 393 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; } |
| 394 | |
| 395 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 396 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM); |
| 397 | }; |
| 398 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 399 | // Slow path marking an object during a read barrier. |
| 400 | class ReadBarrierMarkSlowPathARM : public SlowPathCode { |
| 401 | public: |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 402 | ReadBarrierMarkSlowPathARM(HInstruction* instruction, Location obj) |
| 403 | : SlowPathCode(instruction), obj_(obj) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 404 | DCHECK(kEmitCompilerReadBarrier); |
| 405 | } |
| 406 | |
| 407 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; } |
| 408 | |
| 409 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 410 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 411 | Register reg = obj_.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 412 | DCHECK(locations->CanCall()); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 413 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 414 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 415 | instruction_->IsStaticFieldGet() || |
| 416 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 417 | instruction_->IsArraySet() || |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 418 | instruction_->IsLoadClass() || |
| 419 | instruction_->IsLoadString() || |
| 420 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 421 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 422 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 423 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 424 | << "Unexpected instruction in read barrier marking slow path: " |
| 425 | << instruction_->DebugName(); |
| 426 | |
| 427 | __ Bind(GetEntryLabel()); |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 428 | // No need to save live registers; it's taken care of by the |
| 429 | // entrypoint. Also, there is no need to update the stack mask, |
| 430 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 431 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 432 | DCHECK_NE(reg, SP); |
| 433 | DCHECK_NE(reg, LR); |
| 434 | DCHECK_NE(reg, PC); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 435 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 436 | // as a temporary, it cannot be the entry point's input/output. |
| 437 | DCHECK_NE(reg, IP); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 438 | DCHECK(0 <= reg && reg < kNumberOfCoreRegisters) << reg; |
| 439 | // "Compact" slow path, saving two moves. |
| 440 | // |
| 441 | // Instead of using the standard runtime calling convention (input |
| 442 | // and output in R0): |
| 443 | // |
| 444 | // R0 <- obj |
| 445 | // R0 <- ReadBarrierMark(R0) |
| 446 | // obj <- R0 |
| 447 | // |
| 448 | // we just use rX (the register holding `obj`) as input and output |
| 449 | // of a dedicated entrypoint: |
| 450 | // |
| 451 | // rX <- ReadBarrierMarkRegX(rX) |
| 452 | // |
| 453 | int32_t entry_point_offset = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 454 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 455 | // This runtime call does not require a stack map. |
| 456 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 457 | __ b(GetExitLabel()); |
| 458 | } |
| 459 | |
| 460 | private: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 461 | const Location obj_; |
| 462 | |
| 463 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM); |
| 464 | }; |
| 465 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 466 | // Slow path generating a read barrier for a heap reference. |
| 467 | class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCode { |
| 468 | public: |
| 469 | ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction, |
| 470 | Location out, |
| 471 | Location ref, |
| 472 | Location obj, |
| 473 | uint32_t offset, |
| 474 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 475 | : SlowPathCode(instruction), |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 476 | out_(out), |
| 477 | ref_(ref), |
| 478 | obj_(obj), |
| 479 | offset_(offset), |
| 480 | index_(index) { |
| 481 | DCHECK(kEmitCompilerReadBarrier); |
| 482 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 483 | // has been overwritten by (or after) the heap object reference load |
| 484 | // to be instrumented, e.g.: |
| 485 | // |
| 486 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 487 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 488 | // |
| 489 | // In that case, we have lost the information about the original |
| 490 | // object, and the emitted read barrier cannot work properly. |
| 491 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 492 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 493 | } |
| 494 | |
| 495 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 496 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 497 | LocationSummary* locations = instruction_->GetLocations(); |
| 498 | Register reg_out = out_.AsRegister<Register>(); |
| 499 | DCHECK(locations->CanCall()); |
| 500 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 501 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 502 | instruction_->IsStaticFieldGet() || |
| 503 | instruction_->IsArrayGet() || |
| 504 | instruction_->IsInstanceOf() || |
| 505 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 506 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 507 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 508 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 509 | |
| 510 | __ Bind(GetEntryLabel()); |
| 511 | SaveLiveRegisters(codegen, locations); |
| 512 | |
| 513 | // We may have to change the index's value, but as `index_` is a |
| 514 | // constant member (like other "inputs" of this slow path), |
| 515 | // introduce a copy of it, `index`. |
| 516 | Location index = index_; |
| 517 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 518 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 519 | if (instruction_->IsArrayGet()) { |
| 520 | // Compute the actual memory offset and store it in `index`. |
| 521 | Register index_reg = index_.AsRegister<Register>(); |
| 522 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 523 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 524 | // We are about to change the value of `index_reg` (see the |
| 525 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 526 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 527 | // not been saved by the previous call to |
| 528 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 529 | // callee-save register -- |
| 530 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 531 | // callee-save registers, as it has been designed with the |
| 532 | // assumption that callee-save registers are supposed to be |
| 533 | // handled by the called function. So, as a callee-save |
| 534 | // register, `index_reg` _would_ eventually be saved onto |
| 535 | // the stack, but it would be too late: we would have |
| 536 | // changed its value earlier. Therefore, we manually save |
| 537 | // it here into another freely available register, |
| 538 | // `free_reg`, chosen of course among the caller-save |
| 539 | // registers (as a callee-save `free_reg` register would |
| 540 | // exhibit the same problem). |
| 541 | // |
| 542 | // Note we could have requested a temporary register from |
| 543 | // the register allocator instead; but we prefer not to, as |
| 544 | // this is a slow path, and we know we can find a |
| 545 | // caller-save register that is available. |
| 546 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 547 | __ Mov(free_reg, index_reg); |
| 548 | index_reg = free_reg; |
| 549 | index = Location::RegisterLocation(index_reg); |
| 550 | } else { |
| 551 | // The initial register stored in `index_` has already been |
| 552 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 553 | // (as it is not a callee-save register), so we can freely |
| 554 | // use it. |
| 555 | } |
| 556 | // Shifting the index value contained in `index_reg` by the scale |
| 557 | // factor (2) cannot overflow in practice, as the runtime is |
| 558 | // unable to allocate object arrays with a size larger than |
| 559 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 560 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 561 | static_assert( |
| 562 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 563 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 564 | __ AddConstant(index_reg, index_reg, offset_); |
| 565 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 566 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 567 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 568 | // (as in the case of ArrayGet), as it is actually an offset |
| 569 | // to an object field within an object. |
| 570 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 571 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 572 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 573 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 574 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 575 | DCHECK_EQ(offset_, 0U); |
| 576 | DCHECK(index_.IsRegisterPair()); |
| 577 | // UnsafeGet's offset location is a register pair, the low |
| 578 | // part contains the correct offset. |
| 579 | index = index_.ToLow(); |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | // We're moving two or three locations to locations that could |
| 584 | // overlap, so we need a parallel move resolver. |
| 585 | InvokeRuntimeCallingConvention calling_convention; |
| 586 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 587 | parallel_move.AddMove(ref_, |
| 588 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 589 | Primitive::kPrimNot, |
| 590 | nullptr); |
| 591 | parallel_move.AddMove(obj_, |
| 592 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 593 | Primitive::kPrimNot, |
| 594 | nullptr); |
| 595 | if (index.IsValid()) { |
| 596 | parallel_move.AddMove(index, |
| 597 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 598 | Primitive::kPrimInt, |
| 599 | nullptr); |
| 600 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 601 | } else { |
| 602 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 603 | __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_); |
| 604 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 605 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 606 | CheckEntrypointTypes< |
| 607 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 608 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 609 | |
| 610 | RestoreLiveRegisters(codegen, locations); |
| 611 | __ b(GetExitLabel()); |
| 612 | } |
| 613 | |
| 614 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; } |
| 615 | |
| 616 | private: |
| 617 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 618 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 619 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 620 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 621 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 622 | return static_cast<Register>(i); |
| 623 | } |
| 624 | } |
| 625 | // We shall never fail to find a free caller-save register, as |
| 626 | // there are more than two core caller-save registers on ARM |
| 627 | // (meaning it is possible to find one which is different from |
| 628 | // `ref` and `obj`). |
| 629 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 630 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 631 | UNREACHABLE(); |
| 632 | } |
| 633 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 634 | const Location out_; |
| 635 | const Location ref_; |
| 636 | const Location obj_; |
| 637 | const uint32_t offset_; |
| 638 | // An additional location containing an index to an array. |
| 639 | // Only used for HArrayGet and the UnsafeGetObject & |
| 640 | // UnsafeGetObjectVolatile intrinsics. |
| 641 | const Location index_; |
| 642 | |
| 643 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM); |
| 644 | }; |
| 645 | |
| 646 | // Slow path generating a read barrier for a GC root. |
| 647 | class ReadBarrierForRootSlowPathARM : public SlowPathCode { |
| 648 | public: |
| 649 | ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 650 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 651 | DCHECK(kEmitCompilerReadBarrier); |
| 652 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 653 | |
| 654 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 655 | LocationSummary* locations = instruction_->GetLocations(); |
| 656 | Register reg_out = out_.AsRegister<Register>(); |
| 657 | DCHECK(locations->CanCall()); |
| 658 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 659 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 660 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 661 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 662 | |
| 663 | __ Bind(GetEntryLabel()); |
| 664 | SaveLiveRegisters(codegen, locations); |
| 665 | |
| 666 | InvokeRuntimeCallingConvention calling_convention; |
| 667 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 668 | arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 669 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 670 | instruction_, |
| 671 | instruction_->GetDexPc(), |
| 672 | this); |
| 673 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 674 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 675 | |
| 676 | RestoreLiveRegisters(codegen, locations); |
| 677 | __ b(GetExitLabel()); |
| 678 | } |
| 679 | |
| 680 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; } |
| 681 | |
| 682 | private: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 683 | const Location out_; |
| 684 | const Location root_; |
| 685 | |
| 686 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM); |
| 687 | }; |
| 688 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 689 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 690 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 691 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 692 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 693 | inline Condition ARMCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 694 | switch (cond) { |
| 695 | case kCondEQ: return EQ; |
| 696 | case kCondNE: return NE; |
| 697 | case kCondLT: return LT; |
| 698 | case kCondLE: return LE; |
| 699 | case kCondGT: return GT; |
| 700 | case kCondGE: return GE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 701 | case kCondB: return LO; |
| 702 | case kCondBE: return LS; |
| 703 | case kCondA: return HI; |
| 704 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 705 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 706 | LOG(FATAL) << "Unreachable"; |
| 707 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 708 | } |
| 709 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 710 | // Maps signed condition to unsigned condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 711 | inline Condition ARMUnsignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 712 | switch (cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 713 | case kCondEQ: return EQ; |
| 714 | case kCondNE: return NE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 715 | // Signed to unsigned. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 716 | case kCondLT: return LO; |
| 717 | case kCondLE: return LS; |
| 718 | case kCondGT: return HI; |
| 719 | case kCondGE: return HS; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 720 | // Unsigned remain unchanged. |
| 721 | case kCondB: return LO; |
| 722 | case kCondBE: return LS; |
| 723 | case kCondA: return HI; |
| 724 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 725 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 726 | LOG(FATAL) << "Unreachable"; |
| 727 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 728 | } |
| 729 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 730 | inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 731 | // The ARM condition codes can express all the necessary branches, see the |
| 732 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 733 | // There is no dex instruction or HIR that would need the missing conditions |
| 734 | // "equal or unordered" or "not equal". |
| 735 | switch (cond) { |
| 736 | case kCondEQ: return EQ; |
| 737 | case kCondNE: return NE /* unordered */; |
| 738 | case kCondLT: return gt_bias ? CC : LT /* unordered */; |
| 739 | case kCondLE: return gt_bias ? LS : LE /* unordered */; |
| 740 | case kCondGT: return gt_bias ? HI /* unordered */ : GT; |
| 741 | case kCondGE: return gt_bias ? CS /* unordered */ : GE; |
| 742 | default: |
| 743 | LOG(FATAL) << "UNREACHABLE"; |
| 744 | UNREACHABLE(); |
| 745 | } |
| 746 | } |
| 747 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 748 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 749 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 753 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 754 | } |
| 755 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 756 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 757 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 758 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 759 | } |
| 760 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 761 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 762 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 763 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 764 | } |
| 765 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 766 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 767 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 768 | return kArmWordSize; |
| 769 | } |
| 770 | |
| 771 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 772 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 773 | return kArmWordSize; |
| 774 | } |
| 775 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 776 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 777 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 778 | const CompilerOptions& compiler_options, |
| 779 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 780 | : CodeGenerator(graph, |
| 781 | kNumberOfCoreRegisters, |
| 782 | kNumberOfSRegisters, |
| 783 | kNumberOfRegisterPairs, |
| 784 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 785 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 786 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 787 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 788 | compiler_options, |
| 789 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 790 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 791 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 792 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 793 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 794 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 795 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 796 | uint32_literals_(std::less<uint32_t>(), |
| 797 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 798 | method_patches_(MethodReferenceComparator(), |
| 799 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 800 | call_patches_(MethodReferenceComparator(), |
| 801 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 802 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 803 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 804 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 805 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 806 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 807 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 808 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 809 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 810 | boot_image_address_patches_(std::less<uint32_t>(), |
| 811 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 812 | // Always save the LR register to mimic Quick. |
| 813 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 814 | } |
| 815 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 816 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 817 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 818 | __ FinalizeCode(); |
| 819 | |
| 820 | // Adjust native pc offsets in stack maps. |
| 821 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
| 822 | uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset; |
| 823 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 824 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 825 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 826 | // Adjust pc offsets for the disassembly information. |
| 827 | if (disasm_info_ != nullptr) { |
| 828 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 829 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 830 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 831 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 832 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 833 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 834 | } |
| 835 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 836 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 837 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 838 | } |
| 839 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 840 | |
| 841 | CodeGenerator::Finalize(allocator); |
| 842 | } |
| 843 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 844 | void CodeGeneratorARM::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 845 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 846 | blocked_register_pairs_[R1_R2] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 847 | |
| 848 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 849 | blocked_core_registers_[SP] = true; |
| 850 | blocked_core_registers_[LR] = true; |
| 851 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 852 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 853 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 854 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 855 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 856 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 857 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 858 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 859 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 860 | // Stubs do not save callee-save floating point registers. If the graph |
| 861 | // is debuggable, we need to deal with these registers differently. For |
| 862 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 863 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 864 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 865 | } |
| 866 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 867 | |
| 868 | UpdateBlockedPairRegisters(); |
| 869 | } |
| 870 | |
| 871 | void CodeGeneratorARM::UpdateBlockedPairRegisters() const { |
| 872 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 873 | ArmManagedRegister current = |
| 874 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 875 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 876 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 877 | blocked_register_pairs_[i] = true; |
| 878 | } |
| 879 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 880 | } |
| 881 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 882 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 883 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 884 | assembler_(codegen->GetAssembler()), |
| 885 | codegen_(codegen) {} |
| 886 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 887 | void CodeGeneratorARM::ComputeSpillMask() { |
| 888 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 889 | 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] | 890 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 891 | // restore another arbitrary register. |
| 892 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 893 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 894 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 895 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 896 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 897 | // but in the range. |
| 898 | if (fpu_spill_mask_ != 0) { |
| 899 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 900 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 901 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 902 | fpu_spill_mask_ |= (1 << i); |
| 903 | } |
| 904 | } |
| 905 | } |
| 906 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 907 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 908 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 912 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 913 | } |
| 914 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 915 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 916 | bool skip_overflow_check = |
| 917 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 918 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 919 | __ Bind(&frame_entry_label_); |
| 920 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 921 | if (HasEmptyFrame()) { |
| 922 | return; |
| 923 | } |
| 924 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 925 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 926 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 927 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 928 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 929 | } |
| 930 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 931 | __ PushList(core_spill_mask_); |
| 932 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 933 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 934 | if (fpu_spill_mask_ != 0) { |
| 935 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 936 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 937 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 938 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 939 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 940 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 941 | __ AddConstant(SP, -adjust); |
| 942 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 943 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 947 | if (HasEmptyFrame()) { |
| 948 | __ bx(LR); |
| 949 | return; |
| 950 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 951 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 952 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 953 | __ AddConstant(SP, adjust); |
| 954 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 955 | if (fpu_spill_mask_ != 0) { |
| 956 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 957 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 958 | __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 959 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 960 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 961 | // Pop LR into PC to return. |
| 962 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 963 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 964 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 965 | __ cfi().RestoreState(); |
| 966 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 967 | } |
| 968 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 969 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 970 | Label* label = GetLabelOf(block); |
| 971 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 972 | } |
| 973 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 974 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 975 | switch (type) { |
| 976 | case Primitive::kPrimBoolean: |
| 977 | case Primitive::kPrimByte: |
| 978 | case Primitive::kPrimChar: |
| 979 | case Primitive::kPrimShort: |
| 980 | case Primitive::kPrimInt: |
| 981 | case Primitive::kPrimNot: { |
| 982 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 983 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 984 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 985 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 986 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 987 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 988 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 989 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 990 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 991 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 992 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 993 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 994 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 995 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 996 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 997 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 998 | // Skip R1, and use R2_R3 instead. |
| 999 | gp_index_++; |
| 1000 | index++; |
| 1001 | } |
| 1002 | } |
| 1003 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 1004 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1005 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1006 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1007 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1008 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1009 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1010 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | case Primitive::kPrimFloat: { |
| 1015 | uint32_t stack_index = stack_index_++; |
| 1016 | if (float_index_ % 2 == 0) { |
| 1017 | float_index_ = std::max(double_index_, float_index_); |
| 1018 | } |
| 1019 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 1020 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1021 | } else { |
| 1022 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | case Primitive::kPrimDouble: { |
| 1027 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 1028 | uint32_t stack_index = stack_index_; |
| 1029 | stack_index_ += 2; |
| 1030 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 1031 | uint32_t index = double_index_; |
| 1032 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1033 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1034 | calling_convention.GetFpuRegisterAt(index), |
| 1035 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1036 | DCHECK(ExpectedPairLayout(result)); |
| 1037 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1038 | } else { |
| 1039 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1040 | } |
| 1041 | } |
| 1042 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1043 | case Primitive::kPrimVoid: |
| 1044 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1045 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1046 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1047 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1048 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1049 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1050 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1051 | switch (type) { |
| 1052 | case Primitive::kPrimBoolean: |
| 1053 | case Primitive::kPrimByte: |
| 1054 | case Primitive::kPrimChar: |
| 1055 | case Primitive::kPrimShort: |
| 1056 | case Primitive::kPrimInt: |
| 1057 | case Primitive::kPrimNot: { |
| 1058 | return Location::RegisterLocation(R0); |
| 1059 | } |
| 1060 | |
| 1061 | case Primitive::kPrimFloat: { |
| 1062 | return Location::FpuRegisterLocation(S0); |
| 1063 | } |
| 1064 | |
| 1065 | case Primitive::kPrimLong: { |
| 1066 | return Location::RegisterPairLocation(R0, R1); |
| 1067 | } |
| 1068 | |
| 1069 | case Primitive::kPrimDouble: { |
| 1070 | return Location::FpuRegisterPairLocation(S0, S1); |
| 1071 | } |
| 1072 | |
| 1073 | case Primitive::kPrimVoid: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1074 | return Location::NoLocation(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1075 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1076 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1077 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1078 | } |
| 1079 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1080 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 1081 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1082 | } |
| 1083 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1084 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 1085 | if (source.Equals(destination)) { |
| 1086 | return; |
| 1087 | } |
| 1088 | if (destination.IsRegister()) { |
| 1089 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1090 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1091 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1092 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1093 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1094 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1095 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1096 | } else if (destination.IsFpuRegister()) { |
| 1097 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1098 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1099 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1100 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1101 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1102 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1103 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1104 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1105 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1106 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1107 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1108 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1109 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1110 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1111 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1112 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 1113 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1114 | } |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 1119 | if (source.Equals(destination)) { |
| 1120 | return; |
| 1121 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1122 | if (destination.IsRegisterPair()) { |
| 1123 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1124 | EmitParallelMoves( |
| 1125 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1126 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1127 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1128 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1129 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1130 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1131 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1132 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1133 | } else if (source.IsFpuRegisterPair()) { |
| 1134 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 1135 | destination.AsRegisterPairHigh<Register>(), |
| 1136 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1137 | } else { |
| 1138 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1139 | DCHECK(ExpectedPairLayout(destination)); |
| 1140 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 1141 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1142 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1143 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1144 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1145 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1146 | SP, |
| 1147 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1148 | } else if (source.IsRegisterPair()) { |
| 1149 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1150 | source.AsRegisterPairLow<Register>(), |
| 1151 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1152 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1153 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1154 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1155 | } else { |
| 1156 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1157 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1158 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1159 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 1160 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1161 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 1162 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1163 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1164 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1165 | SP, destination.GetStackIndex()); |
| 1166 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1167 | } else if (source.IsFpuRegisterPair()) { |
| 1168 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 1169 | SP, |
| 1170 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1171 | } else { |
| 1172 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1173 | EmitParallelMoves( |
| 1174 | Location::StackSlot(source.GetStackIndex()), |
| 1175 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1176 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1177 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1178 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 1179 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1180 | } |
| 1181 | } |
| 1182 | } |
| 1183 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1184 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 1185 | DCHECK(location.IsRegister()); |
| 1186 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 1187 | } |
| 1188 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1189 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1190 | HParallelMove move(GetGraph()->GetArena()); |
| 1191 | move.AddMove(src, dst, dst_type, nullptr); |
| 1192 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1196 | if (location.IsRegister()) { |
| 1197 | locations->AddTemp(location); |
| 1198 | } else if (location.IsRegisterPair()) { |
| 1199 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1200 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1201 | } else { |
| 1202 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1203 | } |
| 1204 | } |
| 1205 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1206 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1207 | HInstruction* instruction, |
| 1208 | uint32_t dex_pc, |
| 1209 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1210 | ValidateInvokeRuntime(instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1211 | GenerateInvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value()); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1212 | RecordPcInfo(instruction, dex_pc, slow_path); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1213 | } |
| 1214 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1215 | void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1216 | HInstruction* instruction, |
| 1217 | SlowPathCode* slow_path) { |
| 1218 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1219 | GenerateInvokeRuntime(entry_point_offset); |
| 1220 | } |
| 1221 | |
| 1222 | void CodeGeneratorARM::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1223 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 1224 | __ blx(LR); |
| 1225 | } |
| 1226 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1227 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1228 | DCHECK(!successor->IsExitBlock()); |
| 1229 | |
| 1230 | HBasicBlock* block = got->GetBlock(); |
| 1231 | HInstruction* previous = got->GetPrevious(); |
| 1232 | |
| 1233 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1234 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1235 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 1236 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1237 | return; |
| 1238 | } |
| 1239 | |
| 1240 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1241 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1242 | } |
| 1243 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1244 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1245 | } |
| 1246 | } |
| 1247 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1248 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 1249 | got->SetLocations(nullptr); |
| 1250 | } |
| 1251 | |
| 1252 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 1253 | HandleGoto(got, got->GetSuccessor()); |
| 1254 | } |
| 1255 | |
| 1256 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1257 | try_boundary->SetLocations(nullptr); |
| 1258 | } |
| 1259 | |
| 1260 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1261 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1262 | if (!successor->IsExitBlock()) { |
| 1263 | HandleGoto(try_boundary, successor); |
| 1264 | } |
| 1265 | } |
| 1266 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1267 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1268 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1269 | } |
| 1270 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1271 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1272 | } |
| 1273 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1274 | void InstructionCodeGeneratorARM::GenerateVcmp(HInstruction* instruction) { |
| 1275 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 1276 | Location lhs_loc = instruction->GetLocations()->InAt(0); |
| 1277 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1278 | if (rhs_loc.IsConstant()) { |
| 1279 | // 0.0 is the only immediate that can be encoded directly in |
| 1280 | // a VCMP instruction. |
| 1281 | // |
| 1282 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1283 | // specify that in a floating-point comparison, positive zero |
| 1284 | // and negative zero are considered equal, so we can use the |
| 1285 | // literal 0.0 for both cases here. |
| 1286 | // |
| 1287 | // Note however that some methods (Float.equal, Float.compare, |
| 1288 | // Float.compareTo, Double.equal, Double.compare, |
| 1289 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1290 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1291 | // -0.0. So if we ever translate calls to these methods into a |
| 1292 | // HCompare instruction, we must handle the -0.0 case with |
| 1293 | // care here. |
| 1294 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1295 | if (type == Primitive::kPrimFloat) { |
| 1296 | __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>()); |
| 1297 | } else { |
| 1298 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1299 | __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1300 | } |
| 1301 | } else { |
| 1302 | if (type == Primitive::kPrimFloat) { |
| 1303 | __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>()); |
| 1304 | } else { |
| 1305 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1306 | __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()), |
| 1307 | FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1308 | } |
| 1309 | } |
| 1310 | } |
| 1311 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1312 | void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond, |
| 1313 | Label* true_label, |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1314 | Label* false_label ATTRIBUTE_UNUSED) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1315 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1316 | __ b(true_label, ARMFPCondition(cond->GetCondition(), cond->IsGtBias())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 1320 | Label* true_label, |
| 1321 | Label* false_label) { |
| 1322 | LocationSummary* locations = cond->GetLocations(); |
| 1323 | Location left = locations->InAt(0); |
| 1324 | Location right = locations->InAt(1); |
| 1325 | IfCondition if_cond = cond->GetCondition(); |
| 1326 | |
| 1327 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1328 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 1329 | IfCondition true_high_cond = if_cond; |
| 1330 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1331 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1332 | |
| 1333 | // Set the conditions for the test, remembering that == needs to be |
| 1334 | // decided using the low words. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1335 | // TODO: consider avoiding jumps with temporary and CMP low+SBC high |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1336 | switch (if_cond) { |
| 1337 | case kCondEQ: |
| 1338 | case kCondNE: |
| 1339 | // Nothing to do. |
| 1340 | break; |
| 1341 | case kCondLT: |
| 1342 | false_high_cond = kCondGT; |
| 1343 | break; |
| 1344 | case kCondLE: |
| 1345 | true_high_cond = kCondLT; |
| 1346 | break; |
| 1347 | case kCondGT: |
| 1348 | false_high_cond = kCondLT; |
| 1349 | break; |
| 1350 | case kCondGE: |
| 1351 | true_high_cond = kCondGT; |
| 1352 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1353 | case kCondB: |
| 1354 | false_high_cond = kCondA; |
| 1355 | break; |
| 1356 | case kCondBE: |
| 1357 | true_high_cond = kCondB; |
| 1358 | break; |
| 1359 | case kCondA: |
| 1360 | false_high_cond = kCondB; |
| 1361 | break; |
| 1362 | case kCondAE: |
| 1363 | true_high_cond = kCondA; |
| 1364 | break; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1365 | } |
| 1366 | if (right.IsConstant()) { |
| 1367 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1368 | int32_t val_low = Low32Bits(value); |
| 1369 | int32_t val_high = High32Bits(value); |
| 1370 | |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1371 | __ CmpConstant(left_high, val_high); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1372 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1373 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1374 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1375 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1376 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1377 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1378 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1379 | } |
| 1380 | // Must be equal high, so compare the lows. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1381 | __ CmpConstant(left_low, val_low); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1382 | } else { |
| 1383 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 1384 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 1385 | |
| 1386 | __ cmp(left_high, ShifterOperand(right_high)); |
| 1387 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1388 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1389 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1390 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1391 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1392 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1393 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1394 | } |
| 1395 | // Must be equal high, so compare the lows. |
| 1396 | __ cmp(left_low, ShifterOperand(right_low)); |
| 1397 | } |
| 1398 | // The last comparison might be unsigned. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1399 | // TODO: optimize cases where this is always true/false |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1400 | __ b(true_label, final_condition); |
| 1401 | } |
| 1402 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1403 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition, |
| 1404 | Label* true_target_in, |
| 1405 | Label* false_target_in) { |
| 1406 | // Generated branching requires both targets to be explicit. If either of the |
| 1407 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1408 | Label fallthrough_target; |
| 1409 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1410 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1411 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1412 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1413 | switch (type) { |
| 1414 | case Primitive::kPrimLong: |
| 1415 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1416 | break; |
| 1417 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1418 | case Primitive::kPrimDouble: |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1419 | GenerateVcmp(condition); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1420 | GenerateFPJumps(condition, true_target, false_target); |
| 1421 | break; |
| 1422 | default: |
| 1423 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1424 | } |
| 1425 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1426 | if (false_target != &fallthrough_target) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1427 | __ b(false_target); |
| 1428 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1429 | |
| 1430 | if (fallthrough_target.IsLinked()) { |
| 1431 | __ Bind(&fallthrough_target); |
| 1432 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1433 | } |
| 1434 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1435 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1436 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1437 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1438 | Label* false_target) { |
| 1439 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1440 | |
| 1441 | if (true_target == nullptr && false_target == nullptr) { |
| 1442 | // Nothing to do. The code always falls through. |
| 1443 | return; |
| 1444 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1445 | // Constant condition, statically compared against "true" (integer value 1). |
| 1446 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1447 | if (true_target != nullptr) { |
| 1448 | __ b(true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1449 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1450 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1451 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1452 | if (false_target != nullptr) { |
| 1453 | __ b(false_target); |
| 1454 | } |
| 1455 | } |
| 1456 | return; |
| 1457 | } |
| 1458 | |
| 1459 | // The following code generates these patterns: |
| 1460 | // (1) true_target == nullptr && false_target != nullptr |
| 1461 | // - opposite condition true => branch to false_target |
| 1462 | // (2) true_target != nullptr && false_target == nullptr |
| 1463 | // - condition true => branch to true_target |
| 1464 | // (3) true_target != nullptr && false_target != nullptr |
| 1465 | // - condition true => branch to true_target |
| 1466 | // - branch to false_target |
| 1467 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1468 | // Condition has been materialized, compare the output to 0. |
| 1469 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 1470 | DCHECK(cond_val.IsRegister()); |
| 1471 | if (true_target == nullptr) { |
| 1472 | __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target); |
| 1473 | } else { |
| 1474 | __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1475 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1476 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1477 | // Condition has not been materialized. Use its inputs as the comparison and |
| 1478 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1479 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1480 | |
| 1481 | // If this is a long or FP comparison that has been folded into |
| 1482 | // the HCondition, generate the comparison directly. |
| 1483 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1484 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1485 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1486 | return; |
| 1487 | } |
| 1488 | |
| 1489 | LocationSummary* locations = cond->GetLocations(); |
| 1490 | DCHECK(locations->InAt(0).IsRegister()); |
| 1491 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 1492 | Location right = locations->InAt(1); |
| 1493 | if (right.IsRegister()) { |
| 1494 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1495 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1496 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1497 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1498 | } |
| 1499 | if (true_target == nullptr) { |
| 1500 | __ b(false_target, ARMCondition(condition->GetOppositeCondition())); |
| 1501 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1502 | __ b(true_target, ARMCondition(condition->GetCondition())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1503 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1504 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1505 | |
| 1506 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1507 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1508 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1509 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1510 | } |
| 1511 | } |
| 1512 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1513 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1514 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1515 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1516 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1517 | } |
| 1518 | } |
| 1519 | |
| 1520 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1521 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1522 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1523 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1524 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1525 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1526 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1527 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1531 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1532 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1533 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1534 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1535 | } |
| 1536 | } |
| 1537 | |
| 1538 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1539 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1540 | GenerateTestAndBranch(deoptimize, |
| 1541 | /* condition_input_index */ 0, |
| 1542 | slow_path->GetEntryLabel(), |
| 1543 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1544 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1545 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1546 | void LocationsBuilderARM::VisitSelect(HSelect* select) { |
| 1547 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1548 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1549 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1550 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1551 | } else { |
| 1552 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1553 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1554 | } |
| 1555 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1556 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1557 | } |
| 1558 | locations->SetOut(Location::SameAsFirstInput()); |
| 1559 | } |
| 1560 | |
| 1561 | void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) { |
| 1562 | LocationSummary* locations = select->GetLocations(); |
| 1563 | Label false_target; |
| 1564 | GenerateTestAndBranch(select, |
| 1565 | /* condition_input_index */ 2, |
| 1566 | /* true_target */ nullptr, |
| 1567 | &false_target); |
| 1568 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1569 | __ Bind(&false_target); |
| 1570 | } |
| 1571 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1572 | void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1573 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1574 | } |
| 1575 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1576 | void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1577 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1578 | } |
| 1579 | |
| 1580 | void CodeGeneratorARM::GenerateNop() { |
| 1581 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1582 | } |
| 1583 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1584 | void LocationsBuilderARM::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1585 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1586 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1587 | // Handle the long/FP comparisons made in instruction simplification. |
| 1588 | switch (cond->InputAt(0)->GetType()) { |
| 1589 | case Primitive::kPrimLong: |
| 1590 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1591 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1592 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1593 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 1594 | } |
| 1595 | break; |
| 1596 | |
| 1597 | case Primitive::kPrimFloat: |
| 1598 | case Primitive::kPrimDouble: |
| 1599 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1600 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1601 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1602 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1603 | } |
| 1604 | break; |
| 1605 | |
| 1606 | default: |
| 1607 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1608 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1609 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1610 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1611 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1612 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1613 | } |
| 1614 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1615 | void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1616 | if (cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1617 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1618 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1619 | |
| 1620 | LocationSummary* locations = cond->GetLocations(); |
| 1621 | Location left = locations->InAt(0); |
| 1622 | Location right = locations->InAt(1); |
| 1623 | Register out = locations->Out().AsRegister<Register>(); |
| 1624 | Label true_label, false_label; |
| 1625 | |
| 1626 | switch (cond->InputAt(0)->GetType()) { |
| 1627 | default: { |
| 1628 | // Integer case. |
| 1629 | if (right.IsRegister()) { |
| 1630 | __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>())); |
| 1631 | } else { |
| 1632 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1633 | __ CmpConstant(left.AsRegister<Register>(), |
| 1634 | CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1635 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1636 | __ it(ARMCondition(cond->GetCondition()), kItElse); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1637 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1638 | ARMCondition(cond->GetCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1639 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1640 | ARMCondition(cond->GetOppositeCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1641 | return; |
| 1642 | } |
| 1643 | case Primitive::kPrimLong: |
| 1644 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1645 | break; |
| 1646 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1647 | case Primitive::kPrimDouble: |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1648 | GenerateVcmp(cond); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1649 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1650 | break; |
| 1651 | } |
| 1652 | |
| 1653 | // Convert the jumps into the result. |
| 1654 | Label done_label; |
| 1655 | |
| 1656 | // False case: result = 0. |
| 1657 | __ Bind(&false_label); |
| 1658 | __ LoadImmediate(out, 0); |
| 1659 | __ b(&done_label); |
| 1660 | |
| 1661 | // True case: result = 1. |
| 1662 | __ Bind(&true_label); |
| 1663 | __ LoadImmediate(out, 1); |
| 1664 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1668 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1669 | } |
| 1670 | |
| 1671 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1672 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1673 | } |
| 1674 | |
| 1675 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1676 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1677 | } |
| 1678 | |
| 1679 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1680 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1681 | } |
| 1682 | |
| 1683 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1684 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1685 | } |
| 1686 | |
| 1687 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1688 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1689 | } |
| 1690 | |
| 1691 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1692 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1696 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1697 | } |
| 1698 | |
| 1699 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1700 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1704 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1708 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1712 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1713 | } |
| 1714 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1715 | void LocationsBuilderARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1716 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1717 | } |
| 1718 | |
| 1719 | void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1720 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1724 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1728 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1732 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1736 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1740 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1744 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1745 | } |
| 1746 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1747 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1748 | LocationSummary* locations = |
| 1749 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1750 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1751 | } |
| 1752 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1753 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1754 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1755 | } |
| 1756 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1757 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 1758 | LocationSummary* locations = |
| 1759 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1760 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1761 | } |
| 1762 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1763 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1764 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1765 | } |
| 1766 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1767 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1768 | LocationSummary* locations = |
| 1769 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1770 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1771 | } |
| 1772 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1773 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1774 | // Will be generated at use site. |
| 1775 | } |
| 1776 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1777 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 1778 | LocationSummary* locations = |
| 1779 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1780 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1781 | } |
| 1782 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1783 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1784 | // Will be generated at use site. |
| 1785 | } |
| 1786 | |
| 1787 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1788 | LocationSummary* locations = |
| 1789 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1790 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1791 | } |
| 1792 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1793 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1794 | // Will be generated at use site. |
| 1795 | } |
| 1796 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1797 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1798 | memory_barrier->SetLocations(nullptr); |
| 1799 | } |
| 1800 | |
| 1801 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1802 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1803 | } |
| 1804 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1805 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1806 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1807 | } |
| 1808 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1809 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1810 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1811 | } |
| 1812 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1813 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1814 | LocationSummary* locations = |
| 1815 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1816 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1817 | } |
| 1818 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1819 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1820 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1821 | } |
| 1822 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1823 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1824 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1825 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1826 | // the method_idx. |
| 1827 | HandleInvoke(invoke); |
| 1828 | } |
| 1829 | |
| 1830 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1831 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1832 | } |
| 1833 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1834 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1835 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1836 | // art::PrepareForRegisterAllocation. |
| 1837 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1838 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1839 | IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(), |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1840 | codegen_->GetAssembler(), |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1841 | codegen_->GetInstructionSetFeatures()); |
| 1842 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1843 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 1844 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 1845 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1846 | return; |
| 1847 | } |
| 1848 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1849 | HandleInvoke(invoke); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1850 | |
| 1851 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 1852 | if (invoke->HasPcRelativeDexCache()) { |
| 1853 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 1854 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1855 | } |
| 1856 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1857 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 1858 | if (invoke->GetLocations()->Intrinsified()) { |
| 1859 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 1860 | intrinsic.Dispatch(invoke); |
| 1861 | return true; |
| 1862 | } |
| 1863 | return false; |
| 1864 | } |
| 1865 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1866 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1867 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1868 | // art::PrepareForRegisterAllocation. |
| 1869 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1870 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1871 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1872 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1873 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1874 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1875 | LocationSummary* locations = invoke->GetLocations(); |
| 1876 | codegen_->GenerateStaticOrDirectCall( |
| 1877 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 1878 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1879 | } |
| 1880 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1881 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1882 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1883 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1884 | } |
| 1885 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1886 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1887 | IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(), |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1888 | codegen_->GetAssembler(), |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1889 | codegen_->GetInstructionSetFeatures()); |
| 1890 | if (intrinsic.TryDispatch(invoke)) { |
| 1891 | return; |
| 1892 | } |
| 1893 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1894 | HandleInvoke(invoke); |
| 1895 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1896 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1897 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1898 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1899 | return; |
| 1900 | } |
| 1901 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1902 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1903 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1904 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
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::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1908 | HandleInvoke(invoke); |
| 1909 | // Add the hidden argument. |
| 1910 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 1911 | } |
| 1912 | |
| 1913 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1914 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1915 | LocationSummary* locations = invoke->GetLocations(); |
| 1916 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 1917 | Register hidden_reg = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1918 | Location receiver = locations->InAt(0); |
| 1919 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1920 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1921 | // Set the hidden argument. This is safe to do this here, as R12 |
| 1922 | // won't be modified thereafter, before the `blx` (call) instruction. |
| 1923 | DCHECK_EQ(R12, hidden_reg); |
| 1924 | __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1925 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1926 | if (receiver.IsStackSlot()) { |
| 1927 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1928 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1929 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 1930 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1931 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1932 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1933 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1934 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1935 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 1936 | // emit a read barrier for the previous class reference load. |
| 1937 | // However this is not required in practice, as this is an |
| 1938 | // intermediate/temporary reference and because the current |
| 1939 | // concurrent copying collector keeps the from-space memory |
| 1940 | // intact/accessible until the end of the marking phase (the |
| 1941 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1942 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 1943 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 1944 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 1945 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 1946 | invoke->GetImtIndex(), kArmPointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1947 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 1948 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1949 | uint32_t entry_point = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1950 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1951 | // LR = temp->GetEntryPoint(); |
| 1952 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 1953 | // LR(); |
| 1954 | __ blx(LR); |
| 1955 | DCHECK(!codegen_->IsLeafMethod()); |
| 1956 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1957 | } |
| 1958 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1959 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 1960 | LocationSummary* locations = |
| 1961 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1962 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 1963 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1964 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 1965 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1966 | break; |
| 1967 | } |
| 1968 | case Primitive::kPrimLong: { |
| 1969 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1970 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1971 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1972 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1973 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1974 | case Primitive::kPrimFloat: |
| 1975 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1976 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1977 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1978 | break; |
| 1979 | |
| 1980 | default: |
| 1981 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1982 | } |
| 1983 | } |
| 1984 | |
| 1985 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 1986 | LocationSummary* locations = neg->GetLocations(); |
| 1987 | Location out = locations->Out(); |
| 1988 | Location in = locations->InAt(0); |
| 1989 | switch (neg->GetResultType()) { |
| 1990 | case Primitive::kPrimInt: |
| 1991 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1992 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1993 | break; |
| 1994 | |
| 1995 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1996 | DCHECK(in.IsRegisterPair()); |
| 1997 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 1998 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 1999 | in.AsRegisterPairLow<Register>(), |
| 2000 | ShifterOperand(0)); |
| 2001 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 2002 | // instruction here, as it does not exist in the Thumb-2 |
| 2003 | // instruction set. We use the following approach |
| 2004 | // using SBC and SUB instead. |
| 2005 | // |
| 2006 | // out.hi = -C |
| 2007 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2008 | out.AsRegisterPairHigh<Register>(), |
| 2009 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 2010 | // out.hi = out.hi - in.hi |
| 2011 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 2012 | out.AsRegisterPairHigh<Register>(), |
| 2013 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 2014 | break; |
| 2015 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2016 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2017 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2018 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2019 | break; |
| 2020 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2021 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2022 | DCHECK(in.IsFpuRegisterPair()); |
| 2023 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2024 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2025 | break; |
| 2026 | |
| 2027 | default: |
| 2028 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2029 | } |
| 2030 | } |
| 2031 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2032 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2033 | Primitive::Type result_type = conversion->GetResultType(); |
| 2034 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2035 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2036 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2037 | // The float-to-long, double-to-long and long-to-float type conversions |
| 2038 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2039 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2040 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2041 | && result_type == Primitive::kPrimLong) |
| 2042 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2043 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2044 | : LocationSummary::kNoCall; |
| 2045 | LocationSummary* locations = |
| 2046 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2047 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2048 | // The Java language does not allow treating boolean as an integral type but |
| 2049 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2050 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2051 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2052 | case Primitive::kPrimByte: |
| 2053 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2054 | case Primitive::kPrimLong: |
| 2055 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2056 | case Primitive::kPrimBoolean: |
| 2057 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2058 | case Primitive::kPrimShort: |
| 2059 | case Primitive::kPrimInt: |
| 2060 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2061 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2062 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2063 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2064 | break; |
| 2065 | |
| 2066 | default: |
| 2067 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2068 | << " to " << result_type; |
| 2069 | } |
| 2070 | break; |
| 2071 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2072 | case Primitive::kPrimShort: |
| 2073 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2074 | case Primitive::kPrimLong: |
| 2075 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2076 | case Primitive::kPrimBoolean: |
| 2077 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2078 | case Primitive::kPrimByte: |
| 2079 | case Primitive::kPrimInt: |
| 2080 | case Primitive::kPrimChar: |
| 2081 | // Processing a Dex `int-to-short' instruction. |
| 2082 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2083 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2084 | break; |
| 2085 | |
| 2086 | default: |
| 2087 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2088 | << " to " << result_type; |
| 2089 | } |
| 2090 | break; |
| 2091 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2092 | case Primitive::kPrimInt: |
| 2093 | switch (input_type) { |
| 2094 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2095 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2096 | locations->SetInAt(0, Location::Any()); |
| 2097 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2098 | break; |
| 2099 | |
| 2100 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2101 | // Processing a Dex `float-to-int' instruction. |
| 2102 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2103 | locations->SetOut(Location::RequiresRegister()); |
| 2104 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2105 | break; |
| 2106 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2107 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2108 | // Processing a Dex `double-to-int' instruction. |
| 2109 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2110 | locations->SetOut(Location::RequiresRegister()); |
| 2111 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2112 | break; |
| 2113 | |
| 2114 | default: |
| 2115 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2116 | << " to " << result_type; |
| 2117 | } |
| 2118 | break; |
| 2119 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2120 | case Primitive::kPrimLong: |
| 2121 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2122 | case Primitive::kPrimBoolean: |
| 2123 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2124 | case Primitive::kPrimByte: |
| 2125 | case Primitive::kPrimShort: |
| 2126 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2127 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2128 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2129 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2130 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2131 | break; |
| 2132 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2133 | case Primitive::kPrimFloat: { |
| 2134 | // Processing a Dex `float-to-long' instruction. |
| 2135 | InvokeRuntimeCallingConvention calling_convention; |
| 2136 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 2137 | calling_convention.GetFpuRegisterAt(0))); |
| 2138 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 2139 | break; |
| 2140 | } |
| 2141 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2142 | case Primitive::kPrimDouble: { |
| 2143 | // Processing a Dex `double-to-long' instruction. |
| 2144 | InvokeRuntimeCallingConvention calling_convention; |
| 2145 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 2146 | calling_convention.GetFpuRegisterAt(0), |
| 2147 | calling_convention.GetFpuRegisterAt(1))); |
| 2148 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2149 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2150 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2151 | |
| 2152 | default: |
| 2153 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2154 | << " to " << result_type; |
| 2155 | } |
| 2156 | break; |
| 2157 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2158 | case Primitive::kPrimChar: |
| 2159 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2160 | case Primitive::kPrimLong: |
| 2161 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2162 | case Primitive::kPrimBoolean: |
| 2163 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2164 | case Primitive::kPrimByte: |
| 2165 | case Primitive::kPrimShort: |
| 2166 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2167 | // Processing a Dex `int-to-char' instruction. |
| 2168 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2169 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2170 | break; |
| 2171 | |
| 2172 | default: |
| 2173 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2174 | << " to " << result_type; |
| 2175 | } |
| 2176 | break; |
| 2177 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2178 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2179 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2180 | case Primitive::kPrimBoolean: |
| 2181 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2182 | case Primitive::kPrimByte: |
| 2183 | case Primitive::kPrimShort: |
| 2184 | case Primitive::kPrimInt: |
| 2185 | case Primitive::kPrimChar: |
| 2186 | // Processing a Dex `int-to-float' instruction. |
| 2187 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2188 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2189 | break; |
| 2190 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2191 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2192 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2193 | InvokeRuntimeCallingConvention calling_convention; |
| 2194 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2195 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2196 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2197 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2198 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2199 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2200 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2201 | // Processing a Dex `double-to-float' instruction. |
| 2202 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2203 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2204 | break; |
| 2205 | |
| 2206 | default: |
| 2207 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2208 | << " to " << result_type; |
| 2209 | }; |
| 2210 | break; |
| 2211 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2212 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2213 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2214 | case Primitive::kPrimBoolean: |
| 2215 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2216 | case Primitive::kPrimByte: |
| 2217 | case Primitive::kPrimShort: |
| 2218 | case Primitive::kPrimInt: |
| 2219 | case Primitive::kPrimChar: |
| 2220 | // Processing a Dex `int-to-double' instruction. |
| 2221 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2222 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2223 | break; |
| 2224 | |
| 2225 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2226 | // Processing a Dex `long-to-double' instruction. |
| 2227 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2228 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2229 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2230 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2231 | break; |
| 2232 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2233 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2234 | // Processing a Dex `float-to-double' instruction. |
| 2235 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2236 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2237 | break; |
| 2238 | |
| 2239 | default: |
| 2240 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2241 | << " to " << result_type; |
| 2242 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2243 | break; |
| 2244 | |
| 2245 | default: |
| 2246 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2247 | << " to " << result_type; |
| 2248 | } |
| 2249 | } |
| 2250 | |
| 2251 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 2252 | LocationSummary* locations = conversion->GetLocations(); |
| 2253 | Location out = locations->Out(); |
| 2254 | Location in = locations->InAt(0); |
| 2255 | Primitive::Type result_type = conversion->GetResultType(); |
| 2256 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2257 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2258 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2259 | case Primitive::kPrimByte: |
| 2260 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2261 | case Primitive::kPrimLong: |
| 2262 | // Type conversion from long to byte is a result of code transformations. |
| 2263 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8); |
| 2264 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2265 | case Primitive::kPrimBoolean: |
| 2266 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2267 | case Primitive::kPrimShort: |
| 2268 | case Primitive::kPrimInt: |
| 2269 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2270 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2271 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2272 | break; |
| 2273 | |
| 2274 | default: |
| 2275 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2276 | << " to " << result_type; |
| 2277 | } |
| 2278 | break; |
| 2279 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2280 | case Primitive::kPrimShort: |
| 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 short is a result of code transformations. |
| 2284 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 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 | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2288 | case Primitive::kPrimByte: |
| 2289 | case Primitive::kPrimInt: |
| 2290 | case Primitive::kPrimChar: |
| 2291 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2292 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +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 | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2301 | case Primitive::kPrimInt: |
| 2302 | switch (input_type) { |
| 2303 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2304 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2305 | DCHECK(out.IsRegister()); |
| 2306 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2307 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2308 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2309 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2310 | } else { |
| 2311 | DCHECK(in.IsConstant()); |
| 2312 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2313 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2314 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2315 | } |
| 2316 | break; |
| 2317 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2318 | case Primitive::kPrimFloat: { |
| 2319 | // Processing a Dex `float-to-int' instruction. |
| 2320 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2321 | __ vcvtis(temp, in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2322 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 2323 | break; |
| 2324 | } |
| 2325 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2326 | case Primitive::kPrimDouble: { |
| 2327 | // Processing a Dex `double-to-int' instruction. |
| 2328 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2329 | __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2330 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2331 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2332 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2333 | |
| 2334 | default: |
| 2335 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2336 | << " to " << result_type; |
| 2337 | } |
| 2338 | break; |
| 2339 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2340 | case Primitive::kPrimLong: |
| 2341 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2342 | case Primitive::kPrimBoolean: |
| 2343 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2344 | case Primitive::kPrimByte: |
| 2345 | case Primitive::kPrimShort: |
| 2346 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2347 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2348 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2349 | DCHECK(out.IsRegisterPair()); |
| 2350 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2351 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2352 | // Sign extension. |
| 2353 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 2354 | out.AsRegisterPairLow<Register>(), |
| 2355 | 31); |
| 2356 | break; |
| 2357 | |
| 2358 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2359 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2360 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2361 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2362 | break; |
| 2363 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2364 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2365 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2366 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2367 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2368 | break; |
| 2369 | |
| 2370 | default: |
| 2371 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2372 | << " to " << result_type; |
| 2373 | } |
| 2374 | break; |
| 2375 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2376 | case Primitive::kPrimChar: |
| 2377 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2378 | case Primitive::kPrimLong: |
| 2379 | // Type conversion from long to char is a result of code transformations. |
| 2380 | __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 2381 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2382 | case Primitive::kPrimBoolean: |
| 2383 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2384 | case Primitive::kPrimByte: |
| 2385 | case Primitive::kPrimShort: |
| 2386 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2387 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2388 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2389 | break; |
| 2390 | |
| 2391 | default: |
| 2392 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2393 | << " to " << result_type; |
| 2394 | } |
| 2395 | break; |
| 2396 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2397 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2398 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2399 | case Primitive::kPrimBoolean: |
| 2400 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2401 | case Primitive::kPrimByte: |
| 2402 | case Primitive::kPrimShort: |
| 2403 | case Primitive::kPrimInt: |
| 2404 | case Primitive::kPrimChar: { |
| 2405 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2406 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 2407 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2408 | break; |
| 2409 | } |
| 2410 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2411 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2412 | // Processing a Dex `long-to-float' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2413 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2414 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2415 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2416 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2417 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2418 | // Processing a Dex `double-to-float' instruction. |
| 2419 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 2420 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2421 | break; |
| 2422 | |
| 2423 | default: |
| 2424 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2425 | << " to " << result_type; |
| 2426 | }; |
| 2427 | break; |
| 2428 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2429 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2430 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2431 | case Primitive::kPrimBoolean: |
| 2432 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2433 | case Primitive::kPrimByte: |
| 2434 | case Primitive::kPrimShort: |
| 2435 | case Primitive::kPrimInt: |
| 2436 | case Primitive::kPrimChar: { |
| 2437 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2438 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2439 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2440 | out.AsFpuRegisterPairLow<SRegister>()); |
| 2441 | break; |
| 2442 | } |
| 2443 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2444 | case Primitive::kPrimLong: { |
| 2445 | // Processing a Dex `long-to-double' instruction. |
| 2446 | Register low = in.AsRegisterPairLow<Register>(); |
| 2447 | Register high = in.AsRegisterPairHigh<Register>(); |
| 2448 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 2449 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2450 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2451 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2452 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 2453 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2454 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2455 | // temp_d = int-to-double(high) |
| 2456 | __ vmovsr(temp_s, high); |
| 2457 | __ vcvtdi(temp_d, temp_s); |
| 2458 | // constant_d = k2Pow32EncodingForDouble |
| 2459 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 2460 | // out_d = unsigned-to-double(low) |
| 2461 | __ vmovsr(out_s, low); |
| 2462 | __ vcvtdu(out_d, out_s); |
| 2463 | // out_d += temp_d * constant_d |
| 2464 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2465 | break; |
| 2466 | } |
| 2467 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2468 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2469 | // Processing a Dex `float-to-double' instruction. |
| 2470 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2471 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2472 | break; |
| 2473 | |
| 2474 | default: |
| 2475 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2476 | << " to " << result_type; |
| 2477 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2478 | break; |
| 2479 | |
| 2480 | default: |
| 2481 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2482 | << " to " << result_type; |
| 2483 | } |
| 2484 | } |
| 2485 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2486 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2487 | LocationSummary* locations = |
| 2488 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2489 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2490 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2491 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2492 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2493 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2494 | break; |
| 2495 | } |
| 2496 | |
| 2497 | case Primitive::kPrimLong: { |
| 2498 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2499 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2500 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2501 | break; |
| 2502 | } |
| 2503 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2504 | case Primitive::kPrimFloat: |
| 2505 | case Primitive::kPrimDouble: { |
| 2506 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2507 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2508 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2509 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2510 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2511 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2512 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2513 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2514 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 2518 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2519 | Location out = locations->Out(); |
| 2520 | Location first = locations->InAt(0); |
| 2521 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2522 | switch (add->GetResultType()) { |
| 2523 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2524 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2525 | __ add(out.AsRegister<Register>(), |
| 2526 | first.AsRegister<Register>(), |
| 2527 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2528 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2529 | __ AddConstant(out.AsRegister<Register>(), |
| 2530 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2531 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2532 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2533 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2534 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2535 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2536 | if (second.IsConstant()) { |
| 2537 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 2538 | GenerateAddLongConst(out, first, value); |
| 2539 | } else { |
| 2540 | DCHECK(second.IsRegisterPair()); |
| 2541 | __ adds(out.AsRegisterPairLow<Register>(), |
| 2542 | first.AsRegisterPairLow<Register>(), |
| 2543 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2544 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 2545 | first.AsRegisterPairHigh<Register>(), |
| 2546 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 2547 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2548 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2549 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2550 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2551 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2552 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 2553 | first.AsFpuRegister<SRegister>(), |
| 2554 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2555 | break; |
| 2556 | |
| 2557 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2558 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2559 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2560 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2561 | break; |
| 2562 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2563 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2564 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2565 | } |
| 2566 | } |
| 2567 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2568 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2569 | LocationSummary* locations = |
| 2570 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2571 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2572 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2573 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2574 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2575 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2576 | break; |
| 2577 | } |
| 2578 | |
| 2579 | case Primitive::kPrimLong: { |
| 2580 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2581 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2582 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2583 | break; |
| 2584 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2585 | case Primitive::kPrimFloat: |
| 2586 | case Primitive::kPrimDouble: { |
| 2587 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2588 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2589 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2590 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2591 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2592 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2593 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2594 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2595 | } |
| 2596 | |
| 2597 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 2598 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2599 | Location out = locations->Out(); |
| 2600 | Location first = locations->InAt(0); |
| 2601 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2602 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2603 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2604 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2605 | __ sub(out.AsRegister<Register>(), |
| 2606 | first.AsRegister<Register>(), |
| 2607 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2608 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2609 | __ AddConstant(out.AsRegister<Register>(), |
| 2610 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2611 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2612 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2613 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2614 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2615 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2616 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2617 | if (second.IsConstant()) { |
| 2618 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 2619 | GenerateAddLongConst(out, first, -value); |
| 2620 | } else { |
| 2621 | DCHECK(second.IsRegisterPair()); |
| 2622 | __ subs(out.AsRegisterPairLow<Register>(), |
| 2623 | first.AsRegisterPairLow<Register>(), |
| 2624 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2625 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2626 | first.AsRegisterPairHigh<Register>(), |
| 2627 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 2628 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2629 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2630 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2631 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2632 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2633 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 2634 | first.AsFpuRegister<SRegister>(), |
| 2635 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2636 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2637 | } |
| 2638 | |
| 2639 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2640 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2641 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2642 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2643 | break; |
| 2644 | } |
| 2645 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2646 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2647 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2648 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2649 | } |
| 2650 | } |
| 2651 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2652 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 2653 | LocationSummary* locations = |
| 2654 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2655 | switch (mul->GetResultType()) { |
| 2656 | case Primitive::kPrimInt: |
| 2657 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2658 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2659 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2660 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2661 | break; |
| 2662 | } |
| 2663 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2664 | case Primitive::kPrimFloat: |
| 2665 | case Primitive::kPrimDouble: { |
| 2666 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2667 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2668 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2669 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2670 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2671 | |
| 2672 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2673 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2674 | } |
| 2675 | } |
| 2676 | |
| 2677 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 2678 | LocationSummary* locations = mul->GetLocations(); |
| 2679 | Location out = locations->Out(); |
| 2680 | Location first = locations->InAt(0); |
| 2681 | Location second = locations->InAt(1); |
| 2682 | switch (mul->GetResultType()) { |
| 2683 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2684 | __ mul(out.AsRegister<Register>(), |
| 2685 | first.AsRegister<Register>(), |
| 2686 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2687 | break; |
| 2688 | } |
| 2689 | case Primitive::kPrimLong: { |
| 2690 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 2691 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 2692 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2693 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 2694 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2695 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2696 | |
| 2697 | // Extra checks to protect caused by the existence of R1_R2. |
| 2698 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 2699 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 2700 | DCHECK_NE(out_hi, in1_lo); |
| 2701 | DCHECK_NE(out_hi, in2_lo); |
| 2702 | |
| 2703 | // input: in1 - 64 bits, in2 - 64 bits |
| 2704 | // output: out |
| 2705 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2706 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2707 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 2708 | |
| 2709 | // IP <- in1.lo * in2.hi |
| 2710 | __ mul(IP, in1_lo, in2_hi); |
| 2711 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2712 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 2713 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 2714 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 2715 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2716 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 2717 | break; |
| 2718 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2719 | |
| 2720 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2721 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 2722 | first.AsFpuRegister<SRegister>(), |
| 2723 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2724 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2725 | } |
| 2726 | |
| 2727 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2728 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2729 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2730 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2731 | break; |
| 2732 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2733 | |
| 2734 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2735 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2736 | } |
| 2737 | } |
| 2738 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2739 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2740 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2741 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2742 | |
| 2743 | LocationSummary* locations = instruction->GetLocations(); |
| 2744 | Location second = locations->InAt(1); |
| 2745 | DCHECK(second.IsConstant()); |
| 2746 | |
| 2747 | Register out = locations->Out().AsRegister<Register>(); |
| 2748 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2749 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2750 | DCHECK(imm == 1 || imm == -1); |
| 2751 | |
| 2752 | if (instruction->IsRem()) { |
| 2753 | __ LoadImmediate(out, 0); |
| 2754 | } else { |
| 2755 | if (imm == 1) { |
| 2756 | __ Mov(out, dividend); |
| 2757 | } else { |
| 2758 | __ rsb(out, dividend, ShifterOperand(0)); |
| 2759 | } |
| 2760 | } |
| 2761 | } |
| 2762 | |
| 2763 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2764 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2765 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2766 | |
| 2767 | LocationSummary* locations = instruction->GetLocations(); |
| 2768 | Location second = locations->InAt(1); |
| 2769 | DCHECK(second.IsConstant()); |
| 2770 | |
| 2771 | Register out = locations->Out().AsRegister<Register>(); |
| 2772 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2773 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2774 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2775 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2776 | int ctz_imm = CTZ(abs_imm); |
| 2777 | |
| 2778 | if (ctz_imm == 1) { |
| 2779 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 2780 | } else { |
| 2781 | __ Asr(temp, dividend, 31); |
| 2782 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 2783 | } |
| 2784 | __ add(out, temp, ShifterOperand(dividend)); |
| 2785 | |
| 2786 | if (instruction->IsDiv()) { |
| 2787 | __ Asr(out, out, ctz_imm); |
| 2788 | if (imm < 0) { |
| 2789 | __ rsb(out, out, ShifterOperand(0)); |
| 2790 | } |
| 2791 | } else { |
| 2792 | __ ubfx(out, out, 0, ctz_imm); |
| 2793 | __ sub(out, out, ShifterOperand(temp)); |
| 2794 | } |
| 2795 | } |
| 2796 | |
| 2797 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2798 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2799 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2800 | |
| 2801 | LocationSummary* locations = instruction->GetLocations(); |
| 2802 | Location second = locations->InAt(1); |
| 2803 | DCHECK(second.IsConstant()); |
| 2804 | |
| 2805 | Register out = locations->Out().AsRegister<Register>(); |
| 2806 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2807 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 2808 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 2809 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2810 | |
| 2811 | int64_t magic; |
| 2812 | int shift; |
| 2813 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2814 | |
| 2815 | __ LoadImmediate(temp1, magic); |
| 2816 | __ smull(temp2, temp1, dividend, temp1); |
| 2817 | |
| 2818 | if (imm > 0 && magic < 0) { |
| 2819 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 2820 | } else if (imm < 0 && magic > 0) { |
| 2821 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 2822 | } |
| 2823 | |
| 2824 | if (shift != 0) { |
| 2825 | __ Asr(temp1, temp1, shift); |
| 2826 | } |
| 2827 | |
| 2828 | if (instruction->IsDiv()) { |
| 2829 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 2830 | } else { |
| 2831 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 2832 | // TODO: Strength reduction for mls. |
| 2833 | __ LoadImmediate(temp2, imm); |
| 2834 | __ mls(out, temp1, temp2, dividend); |
| 2835 | } |
| 2836 | } |
| 2837 | |
| 2838 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 2839 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2840 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2841 | |
| 2842 | LocationSummary* locations = instruction->GetLocations(); |
| 2843 | Location second = locations->InAt(1); |
| 2844 | DCHECK(second.IsConstant()); |
| 2845 | |
| 2846 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2847 | if (imm == 0) { |
| 2848 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2849 | } else if (imm == 1 || imm == -1) { |
| 2850 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2851 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2852 | DivRemByPowerOfTwo(instruction); |
| 2853 | } else { |
| 2854 | DCHECK(imm <= -2 || imm >= 2); |
| 2855 | GenerateDivRemWithAnyConstant(instruction); |
| 2856 | } |
| 2857 | } |
| 2858 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2859 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2860 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 2861 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 2862 | // pLdiv runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2863 | call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2864 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 2865 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2866 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 2867 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 2868 | // pIdivmod runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2869 | call_kind = LocationSummary::kCallOnMainOnly; |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2870 | } |
| 2871 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2872 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2873 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2874 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2875 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2876 | if (div->InputAt(1)->IsConstant()) { |
| 2877 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 2878 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2879 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2880 | int32_t value = div->InputAt(1)->AsIntConstant()->GetValue(); |
| 2881 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2882 | // No temp register required. |
| 2883 | } else { |
| 2884 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2885 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2886 | locations->AddTemp(Location::RequiresRegister()); |
| 2887 | } |
| 2888 | } |
| 2889 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2890 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2891 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2892 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2893 | } else { |
| 2894 | InvokeRuntimeCallingConvention calling_convention; |
| 2895 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2896 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2897 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 2898 | // we only need the former. |
| 2899 | locations->SetOut(Location::RegisterLocation(R0)); |
| 2900 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2901 | break; |
| 2902 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2903 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2904 | InvokeRuntimeCallingConvention calling_convention; |
| 2905 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2906 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2907 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2908 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2909 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2910 | break; |
| 2911 | } |
| 2912 | case Primitive::kPrimFloat: |
| 2913 | case Primitive::kPrimDouble: { |
| 2914 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2915 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2916 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2917 | break; |
| 2918 | } |
| 2919 | |
| 2920 | default: |
| 2921 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2922 | } |
| 2923 | } |
| 2924 | |
| 2925 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 2926 | LocationSummary* locations = div->GetLocations(); |
| 2927 | Location out = locations->Out(); |
| 2928 | Location first = locations->InAt(0); |
| 2929 | Location second = locations->InAt(1); |
| 2930 | |
| 2931 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2932 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2933 | if (second.IsConstant()) { |
| 2934 | GenerateDivRemConstantIntegral(div); |
| 2935 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2936 | __ sdiv(out.AsRegister<Register>(), |
| 2937 | first.AsRegister<Register>(), |
| 2938 | second.AsRegister<Register>()); |
| 2939 | } else { |
| 2940 | InvokeRuntimeCallingConvention calling_convention; |
| 2941 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 2942 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 2943 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 2944 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2945 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2946 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2947 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2948 | break; |
| 2949 | } |
| 2950 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2951 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2952 | InvokeRuntimeCallingConvention calling_convention; |
| 2953 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2954 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 2955 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 2956 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 2957 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2958 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2959 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2960 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2961 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2962 | break; |
| 2963 | } |
| 2964 | |
| 2965 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2966 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 2967 | first.AsFpuRegister<SRegister>(), |
| 2968 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2969 | break; |
| 2970 | } |
| 2971 | |
| 2972 | case Primitive::kPrimDouble: { |
| 2973 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2974 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2975 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 2976 | break; |
| 2977 | } |
| 2978 | |
| 2979 | default: |
| 2980 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2981 | } |
| 2982 | } |
| 2983 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2984 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2985 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2986 | |
| 2987 | // Most remainders are implemented in the runtime. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2988 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2989 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 2990 | // sdiv will be replaced by other instruction sequence. |
| 2991 | call_kind = LocationSummary::kNoCall; |
| 2992 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 2993 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2994 | // Have hardware divide instruction for int, do it with three instructions. |
| 2995 | call_kind = LocationSummary::kNoCall; |
| 2996 | } |
| 2997 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2998 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 2999 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3000 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3001 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3002 | if (rem->InputAt(1)->IsConstant()) { |
| 3003 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3004 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3005 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3006 | int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue(); |
| 3007 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3008 | // No temp register required. |
| 3009 | } else { |
| 3010 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3011 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3012 | locations->AddTemp(Location::RequiresRegister()); |
| 3013 | } |
| 3014 | } |
| 3015 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3016 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3017 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3018 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3019 | locations->AddTemp(Location::RequiresRegister()); |
| 3020 | } else { |
| 3021 | InvokeRuntimeCallingConvention calling_convention; |
| 3022 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3023 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3024 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 3025 | // we only need the latter. |
| 3026 | locations->SetOut(Location::RegisterLocation(R1)); |
| 3027 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3028 | break; |
| 3029 | } |
| 3030 | case Primitive::kPrimLong: { |
| 3031 | InvokeRuntimeCallingConvention calling_convention; |
| 3032 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3033 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3034 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3035 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3036 | // The runtime helper puts the output in R2,R3. |
| 3037 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 3038 | break; |
| 3039 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3040 | case Primitive::kPrimFloat: { |
| 3041 | InvokeRuntimeCallingConvention calling_convention; |
| 3042 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 3043 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 3044 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 3045 | break; |
| 3046 | } |
| 3047 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3048 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3049 | InvokeRuntimeCallingConvention calling_convention; |
| 3050 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 3051 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 3052 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 3053 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 3054 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3055 | break; |
| 3056 | } |
| 3057 | |
| 3058 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3059 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3060 | } |
| 3061 | } |
| 3062 | |
| 3063 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 3064 | LocationSummary* locations = rem->GetLocations(); |
| 3065 | Location out = locations->Out(); |
| 3066 | Location first = locations->InAt(0); |
| 3067 | Location second = locations->InAt(1); |
| 3068 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3069 | Primitive::Type type = rem->GetResultType(); |
| 3070 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3071 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3072 | if (second.IsConstant()) { |
| 3073 | GenerateDivRemConstantIntegral(rem); |
| 3074 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3075 | Register reg1 = first.AsRegister<Register>(); |
| 3076 | Register reg2 = second.AsRegister<Register>(); |
| 3077 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3078 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3079 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3080 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3081 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3082 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3083 | } else { |
| 3084 | InvokeRuntimeCallingConvention calling_convention; |
| 3085 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3086 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3087 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 3088 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3089 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3090 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3091 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3092 | break; |
| 3093 | } |
| 3094 | |
| 3095 | case Primitive::kPrimLong: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3096 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3097 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3098 | break; |
| 3099 | } |
| 3100 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3101 | case Primitive::kPrimFloat: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3102 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3103 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3104 | break; |
| 3105 | } |
| 3106 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3107 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3108 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3109 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3110 | break; |
| 3111 | } |
| 3112 | |
| 3113 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3114 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3115 | } |
| 3116 | } |
| 3117 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3118 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3119 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3120 | ? LocationSummary::kCallOnSlowPath |
| 3121 | : LocationSummary::kNoCall; |
| 3122 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3123 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3124 | if (instruction->HasUses()) { |
| 3125 | locations->SetOut(Location::SameAsFirstInput()); |
| 3126 | } |
| 3127 | } |
| 3128 | |
| 3129 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3130 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3131 | codegen_->AddSlowPath(slow_path); |
| 3132 | |
| 3133 | LocationSummary* locations = instruction->GetLocations(); |
| 3134 | Location value = locations->InAt(0); |
| 3135 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3136 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3137 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3138 | case Primitive::kPrimByte: |
| 3139 | case Primitive::kPrimChar: |
| 3140 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3141 | case Primitive::kPrimInt: { |
| 3142 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3143 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3144 | } else { |
| 3145 | DCHECK(value.IsConstant()) << value; |
| 3146 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3147 | __ b(slow_path->GetEntryLabel()); |
| 3148 | } |
| 3149 | } |
| 3150 | break; |
| 3151 | } |
| 3152 | case Primitive::kPrimLong: { |
| 3153 | if (value.IsRegisterPair()) { |
| 3154 | __ orrs(IP, |
| 3155 | value.AsRegisterPairLow<Register>(), |
| 3156 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 3157 | __ b(slow_path->GetEntryLabel(), EQ); |
| 3158 | } else { |
| 3159 | DCHECK(value.IsConstant()) << value; |
| 3160 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3161 | __ b(slow_path->GetEntryLabel()); |
| 3162 | } |
| 3163 | } |
| 3164 | break; |
| 3165 | default: |
| 3166 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3167 | } |
| 3168 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3169 | } |
| 3170 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3171 | void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) { |
| 3172 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 3173 | Location rhs = locations->InAt(1); |
| 3174 | Register out = locations->Out().AsRegister<Register>(); |
| 3175 | |
| 3176 | if (rhs.IsConstant()) { |
| 3177 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 3178 | // so map all rotations to a +ve. equivalent in that range. |
| 3179 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 3180 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 3181 | if (rot) { |
| 3182 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 3183 | // (e.g. left by 2 bits == right by 30.) |
| 3184 | __ Ror(out, in, rot); |
| 3185 | } else if (out != in) { |
| 3186 | __ Mov(out, in); |
| 3187 | } |
| 3188 | } else { |
| 3189 | __ Ror(out, in, rhs.AsRegister<Register>()); |
| 3190 | } |
| 3191 | } |
| 3192 | |
| 3193 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 3194 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 3195 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 3196 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 3197 | void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) { |
| 3198 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3199 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3200 | Location rhs = locations->InAt(1); |
| 3201 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 3202 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 3203 | |
| 3204 | if (rhs.IsConstant()) { |
| 3205 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 3206 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3207 | rot &= kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3208 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 3209 | // logic below to a simple pair of binary orr. |
| 3210 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 3211 | if (rot >= kArmBitsPerWord) { |
| 3212 | rot -= kArmBitsPerWord; |
| 3213 | std::swap(in_reg_hi, in_reg_lo); |
| 3214 | } |
| 3215 | // Rotate, or mov to out for zero or word size rotations. |
| 3216 | if (rot != 0u) { |
| 3217 | __ Lsr(out_reg_hi, in_reg_hi, rot); |
| 3218 | __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot)); |
| 3219 | __ Lsr(out_reg_lo, in_reg_lo, rot); |
| 3220 | __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot)); |
| 3221 | } else { |
| 3222 | __ Mov(out_reg_lo, in_reg_lo); |
| 3223 | __ Mov(out_reg_hi, in_reg_hi); |
| 3224 | } |
| 3225 | } else { |
| 3226 | Register shift_right = locations->GetTemp(0).AsRegister<Register>(); |
| 3227 | Register shift_left = locations->GetTemp(1).AsRegister<Register>(); |
| 3228 | Label end; |
| 3229 | Label shift_by_32_plus_shift_right; |
| 3230 | |
| 3231 | __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F)); |
| 3232 | __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6); |
| 3233 | __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep); |
| 3234 | __ b(&shift_by_32_plus_shift_right, CC); |
| 3235 | |
| 3236 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 3237 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 3238 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 3239 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3240 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3241 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3242 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 3243 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left)); |
| 3244 | __ b(&end); |
| 3245 | |
| 3246 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 3247 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 3248 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 3249 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 3250 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3251 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3252 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3253 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 3254 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right)); |
| 3255 | |
| 3256 | __ Bind(&end); |
| 3257 | } |
| 3258 | } |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3259 | |
| 3260 | void LocationsBuilderARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3261 | LocationSummary* locations = |
| 3262 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3263 | switch (ror->GetResultType()) { |
| 3264 | case Primitive::kPrimInt: { |
| 3265 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3266 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 3267 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3268 | break; |
| 3269 | } |
| 3270 | case Primitive::kPrimLong: { |
| 3271 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3272 | if (ror->InputAt(1)->IsConstant()) { |
| 3273 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 3274 | } else { |
| 3275 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3276 | locations->AddTemp(Location::RequiresRegister()); |
| 3277 | locations->AddTemp(Location::RequiresRegister()); |
| 3278 | } |
| 3279 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3280 | break; |
| 3281 | } |
| 3282 | default: |
| 3283 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3284 | } |
| 3285 | } |
| 3286 | |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3287 | void InstructionCodeGeneratorARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3288 | LocationSummary* locations = ror->GetLocations(); |
| 3289 | Primitive::Type type = ror->GetResultType(); |
| 3290 | switch (type) { |
| 3291 | case Primitive::kPrimInt: { |
| 3292 | HandleIntegerRotate(locations); |
| 3293 | break; |
| 3294 | } |
| 3295 | case Primitive::kPrimLong: { |
| 3296 | HandleLongRotate(locations); |
| 3297 | break; |
| 3298 | } |
| 3299 | default: |
| 3300 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3301 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3302 | } |
| 3303 | } |
| 3304 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3305 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 3306 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3307 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3308 | LocationSummary* locations = |
| 3309 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3310 | |
| 3311 | switch (op->GetResultType()) { |
| 3312 | case Primitive::kPrimInt: { |
| 3313 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3314 | if (op->InputAt(1)->IsConstant()) { |
| 3315 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3316 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3317 | } else { |
| 3318 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3319 | // Make the output overlap, as it will be used to hold the masked |
| 3320 | // second input. |
| 3321 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3322 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3323 | break; |
| 3324 | } |
| 3325 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3326 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3327 | if (op->InputAt(1)->IsConstant()) { |
| 3328 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3329 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 3330 | // don't clash with high registers which the register allocator currently guarantees. |
| 3331 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3332 | } else { |
| 3333 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3334 | locations->AddTemp(Location::RequiresRegister()); |
| 3335 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3336 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3337 | break; |
| 3338 | } |
| 3339 | default: |
| 3340 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3341 | } |
| 3342 | } |
| 3343 | |
| 3344 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 3345 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3346 | |
| 3347 | LocationSummary* locations = op->GetLocations(); |
| 3348 | Location out = locations->Out(); |
| 3349 | Location first = locations->InAt(0); |
| 3350 | Location second = locations->InAt(1); |
| 3351 | |
| 3352 | Primitive::Type type = op->GetResultType(); |
| 3353 | switch (type) { |
| 3354 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3355 | Register out_reg = out.AsRegister<Register>(); |
| 3356 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3357 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3358 | Register second_reg = second.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3359 | // 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] | 3360 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3361 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3362 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3363 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3364 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3365 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3366 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3367 | } |
| 3368 | } else { |
| 3369 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3370 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3371 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3372 | __ Mov(out_reg, first_reg); |
| 3373 | } else if (op->IsShl()) { |
| 3374 | __ Lsl(out_reg, first_reg, shift_value); |
| 3375 | } else if (op->IsShr()) { |
| 3376 | __ Asr(out_reg, first_reg, shift_value); |
| 3377 | } else { |
| 3378 | __ Lsr(out_reg, first_reg, shift_value); |
| 3379 | } |
| 3380 | } |
| 3381 | break; |
| 3382 | } |
| 3383 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3384 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 3385 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3386 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3387 | Register high = first.AsRegisterPairHigh<Register>(); |
| 3388 | Register low = first.AsRegisterPairLow<Register>(); |
| 3389 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3390 | if (second.IsRegister()) { |
| 3391 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3392 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3393 | Register second_reg = second.AsRegister<Register>(); |
| 3394 | |
| 3395 | if (op->IsShl()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3396 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3397 | // Shift the high part |
| 3398 | __ Lsl(o_h, high, o_l); |
| 3399 | // Shift the low part and `or` what overflew on the high part |
| 3400 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3401 | __ Lsr(temp, low, temp); |
| 3402 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 3403 | // If the shift is > 32 bits, override the high part |
| 3404 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3405 | __ it(PL); |
| 3406 | __ Lsl(o_h, low, temp, PL); |
| 3407 | // Shift the low part |
| 3408 | __ Lsl(o_l, low, o_l); |
| 3409 | } else if (op->IsShr()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3410 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3411 | // Shift the low part |
| 3412 | __ Lsr(o_l, low, o_h); |
| 3413 | // Shift the high part and `or` what underflew on the low part |
| 3414 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3415 | __ Lsl(temp, high, temp); |
| 3416 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3417 | // If the shift is > 32 bits, override the low part |
| 3418 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3419 | __ it(PL); |
| 3420 | __ Asr(o_l, high, temp, PL); |
| 3421 | // Shift the high part |
| 3422 | __ Asr(o_h, high, o_h); |
| 3423 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3424 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3425 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 3426 | __ Lsr(o_l, low, o_h); |
| 3427 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3428 | __ Lsl(temp, high, temp); |
| 3429 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3430 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3431 | __ it(PL); |
| 3432 | __ Lsr(o_l, high, temp, PL); |
| 3433 | __ Lsr(o_h, high, o_h); |
| 3434 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3435 | } else { |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3436 | // Register allocator doesn't create partial overlap. |
| 3437 | DCHECK_NE(o_l, high); |
| 3438 | DCHECK_NE(o_h, low); |
| 3439 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3440 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3441 | if (shift_value > 32) { |
| 3442 | if (op->IsShl()) { |
| 3443 | __ Lsl(o_h, low, shift_value - 32); |
| 3444 | __ LoadImmediate(o_l, 0); |
| 3445 | } else if (op->IsShr()) { |
| 3446 | __ Asr(o_l, high, shift_value - 32); |
| 3447 | __ Asr(o_h, high, 31); |
| 3448 | } else { |
| 3449 | __ Lsr(o_l, high, shift_value - 32); |
| 3450 | __ LoadImmediate(o_h, 0); |
| 3451 | } |
| 3452 | } else if (shift_value == 32) { |
| 3453 | if (op->IsShl()) { |
| 3454 | __ mov(o_h, ShifterOperand(low)); |
| 3455 | __ LoadImmediate(o_l, 0); |
| 3456 | } else if (op->IsShr()) { |
| 3457 | __ mov(o_l, ShifterOperand(high)); |
| 3458 | __ Asr(o_h, high, 31); |
| 3459 | } else { |
| 3460 | __ mov(o_l, ShifterOperand(high)); |
| 3461 | __ LoadImmediate(o_h, 0); |
| 3462 | } |
Vladimir Marko | f9d741e | 2015-11-20 15:08:11 +0000 | [diff] [blame] | 3463 | } else if (shift_value == 1) { |
| 3464 | if (op->IsShl()) { |
| 3465 | __ Lsls(o_l, low, 1); |
| 3466 | __ adc(o_h, high, ShifterOperand(high)); |
| 3467 | } else if (op->IsShr()) { |
| 3468 | __ Asrs(o_h, high, 1); |
| 3469 | __ Rrx(o_l, low); |
| 3470 | } else { |
| 3471 | __ Lsrs(o_h, high, 1); |
| 3472 | __ Rrx(o_l, low); |
| 3473 | } |
| 3474 | } else { |
| 3475 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3476 | if (op->IsShl()) { |
| 3477 | __ Lsl(o_h, high, shift_value); |
| 3478 | __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value)); |
| 3479 | __ Lsl(o_l, low, shift_value); |
| 3480 | } else if (op->IsShr()) { |
| 3481 | __ Lsr(o_l, low, shift_value); |
| 3482 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3483 | __ Asr(o_h, high, shift_value); |
| 3484 | } else { |
| 3485 | __ Lsr(o_l, low, shift_value); |
| 3486 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3487 | __ Lsr(o_h, high, shift_value); |
| 3488 | } |
| 3489 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3490 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3491 | break; |
| 3492 | } |
| 3493 | default: |
| 3494 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3495 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3496 | } |
| 3497 | } |
| 3498 | |
| 3499 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 3500 | HandleShift(shl); |
| 3501 | } |
| 3502 | |
| 3503 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 3504 | HandleShift(shl); |
| 3505 | } |
| 3506 | |
| 3507 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 3508 | HandleShift(shr); |
| 3509 | } |
| 3510 | |
| 3511 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 3512 | HandleShift(shr); |
| 3513 | } |
| 3514 | |
| 3515 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 3516 | HandleShift(ushr); |
| 3517 | } |
| 3518 | |
| 3519 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 3520 | HandleShift(ushr); |
| 3521 | } |
| 3522 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3523 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3524 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3525 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3526 | if (instruction->IsStringAlloc()) { |
| 3527 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3528 | } else { |
| 3529 | InvokeRuntimeCallingConvention calling_convention; |
| 3530 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3531 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3532 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3533 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3534 | } |
| 3535 | |
| 3536 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3537 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3538 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3539 | if (instruction->IsStringAlloc()) { |
| 3540 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3541 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3542 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3543 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 3544 | __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value()); |
| 3545 | __ blx(LR); |
| 3546 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3547 | } else { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3548 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3549 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3550 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3551 | } |
| 3552 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3553 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 3554 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3555 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3556 | InvokeRuntimeCallingConvention calling_convention; |
| 3557 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3558 | locations->SetOut(Location::RegisterLocation(R0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3559 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3560 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3561 | } |
| 3562 | |
| 3563 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
| 3564 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3565 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3566 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3567 | // of poisoning the reference. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3568 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3569 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3570 | } |
| 3571 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3572 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3573 | LocationSummary* locations = |
| 3574 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3575 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3576 | if (location.IsStackSlot()) { |
| 3577 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3578 | } else if (location.IsDoubleStackSlot()) { |
| 3579 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3580 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3581 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3582 | } |
| 3583 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3584 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 3585 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3586 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3587 | } |
| 3588 | |
| 3589 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3590 | LocationSummary* locations = |
| 3591 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3592 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3593 | } |
| 3594 | |
| 3595 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3596 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3597 | } |
| 3598 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3599 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3600 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3601 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3602 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3603 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3604 | } |
| 3605 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3606 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 3607 | LocationSummary* locations = not_->GetLocations(); |
| 3608 | Location out = locations->Out(); |
| 3609 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3610 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3611 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3612 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3613 | break; |
| 3614 | |
| 3615 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3616 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 3617 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 3618 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 3619 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3620 | break; |
| 3621 | |
| 3622 | default: |
| 3623 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3624 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3625 | } |
| 3626 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3627 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3628 | LocationSummary* locations = |
| 3629 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3630 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3631 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3632 | } |
| 3633 | |
| 3634 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3635 | LocationSummary* locations = bool_not->GetLocations(); |
| 3636 | Location out = locations->Out(); |
| 3637 | Location in = locations->InAt(0); |
| 3638 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 3639 | } |
| 3640 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3641 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3642 | LocationSummary* locations = |
| 3643 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3644 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3645 | case Primitive::kPrimBoolean: |
| 3646 | case Primitive::kPrimByte: |
| 3647 | case Primitive::kPrimShort: |
| 3648 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3649 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3650 | case Primitive::kPrimLong: { |
| 3651 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3652 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3653 | // Output overlaps because it is written before doing the low comparison. |
| 3654 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3655 | break; |
| 3656 | } |
| 3657 | case Primitive::kPrimFloat: |
| 3658 | case Primitive::kPrimDouble: { |
| 3659 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 3660 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3661 | locations->SetOut(Location::RequiresRegister()); |
| 3662 | break; |
| 3663 | } |
| 3664 | default: |
| 3665 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 3666 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3667 | } |
| 3668 | |
| 3669 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3670 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3671 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3672 | Location left = locations->InAt(0); |
| 3673 | Location right = locations->InAt(1); |
| 3674 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3675 | Label less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3676 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3677 | Condition less_cond; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3678 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3679 | case Primitive::kPrimBoolean: |
| 3680 | case Primitive::kPrimByte: |
| 3681 | case Primitive::kPrimShort: |
| 3682 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3683 | case Primitive::kPrimInt: { |
| 3684 | __ LoadImmediate(out, 0); |
| 3685 | __ cmp(left.AsRegister<Register>(), |
| 3686 | ShifterOperand(right.AsRegister<Register>())); // Signed compare. |
| 3687 | less_cond = LT; |
| 3688 | break; |
| 3689 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3690 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3691 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 3692 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3693 | __ b(&less, LT); |
| 3694 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3695 | // 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] | 3696 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3697 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 3698 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3699 | less_cond = LO; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3700 | break; |
| 3701 | } |
| 3702 | case Primitive::kPrimFloat: |
| 3703 | case Primitive::kPrimDouble: { |
| 3704 | __ LoadImmediate(out, 0); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 3705 | GenerateVcmp(compare); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3706 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3707 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3708 | break; |
| 3709 | } |
| 3710 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3711 | LOG(FATAL) << "Unexpected compare type " << type; |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3712 | UNREACHABLE(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3713 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3714 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3715 | __ b(&done, EQ); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3716 | __ b(&less, less_cond); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3717 | |
| 3718 | __ Bind(&greater); |
| 3719 | __ LoadImmediate(out, 1); |
| 3720 | __ b(&done); |
| 3721 | |
| 3722 | __ Bind(&less); |
| 3723 | __ LoadImmediate(out, -1); |
| 3724 | |
| 3725 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3726 | } |
| 3727 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3728 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3729 | LocationSummary* locations = |
| 3730 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3731 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 3732 | locations->SetInAt(i, Location::Any()); |
| 3733 | } |
| 3734 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3735 | } |
| 3736 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3737 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3738 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3739 | } |
| 3740 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3741 | void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3742 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 3743 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3744 | switch (kind) { |
| 3745 | case MemBarrierKind::kAnyStore: |
| 3746 | case MemBarrierKind::kLoadAny: |
| 3747 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3748 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3749 | break; |
| 3750 | } |
| 3751 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3752 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3753 | break; |
| 3754 | } |
| 3755 | default: |
| 3756 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 3757 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3758 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3759 | } |
| 3760 | |
| 3761 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 3762 | uint32_t offset, |
| 3763 | Register out_lo, |
| 3764 | Register out_hi) { |
| 3765 | if (offset != 0) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3766 | // Ensure `out_lo` is different from `addr`, so that loading |
| 3767 | // `offset` into `out_lo` does not clutter `addr`. |
| 3768 | DCHECK_NE(out_lo, addr); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3769 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3770 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 3771 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3772 | } |
| 3773 | __ ldrexd(out_lo, out_hi, addr); |
| 3774 | } |
| 3775 | |
| 3776 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 3777 | uint32_t offset, |
| 3778 | Register value_lo, |
| 3779 | Register value_hi, |
| 3780 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3781 | Register temp2, |
| 3782 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3783 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3784 | if (offset != 0) { |
| 3785 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3786 | __ add(IP, addr, ShifterOperand(temp1)); |
| 3787 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3788 | } |
| 3789 | __ Bind(&fail); |
| 3790 | // We need a load followed by store. (The address used in a STREX instruction must |
| 3791 | // be the same as the address in the most recently executed LDREX instruction.) |
| 3792 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3793 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3794 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3795 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3796 | } |
| 3797 | |
| 3798 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3799 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3800 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3801 | LocationSummary* locations = |
| 3802 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3803 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3804 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3805 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3806 | if (Primitive::IsFloatingPointType(field_type)) { |
| 3807 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3808 | } else { |
| 3809 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3810 | } |
| 3811 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3812 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3813 | bool generate_volatile = field_info.IsVolatile() |
| 3814 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3815 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3816 | bool needs_write_barrier = |
| 3817 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3818 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3819 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3820 | if (needs_write_barrier) { |
| 3821 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3822 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3823 | } else if (generate_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3824 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3825 | // - registers need to be consecutive |
| 3826 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3827 | // We don't test for ARM yet, and the assertion makes sure that we |
| 3828 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3829 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 3830 | |
| 3831 | locations->AddTemp(Location::RequiresRegister()); |
| 3832 | locations->AddTemp(Location::RequiresRegister()); |
| 3833 | if (field_type == Primitive::kPrimDouble) { |
| 3834 | // For doubles we need two more registers to copy the value. |
| 3835 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 3836 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 3837 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3838 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3839 | } |
| 3840 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3841 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3842 | const FieldInfo& field_info, |
| 3843 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3844 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3845 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3846 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3847 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3848 | Location value = locations->InAt(1); |
| 3849 | |
| 3850 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3851 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3852 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3853 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3854 | bool needs_write_barrier = |
| 3855 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3856 | |
| 3857 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3858 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3859 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3860 | |
| 3861 | switch (field_type) { |
| 3862 | case Primitive::kPrimBoolean: |
| 3863 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3864 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3865 | break; |
| 3866 | } |
| 3867 | |
| 3868 | case Primitive::kPrimShort: |
| 3869 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3870 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3871 | break; |
| 3872 | } |
| 3873 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3874 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3875 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3876 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 3877 | // Note that in the case where `value` is a null reference, |
| 3878 | // we do not enter this block, as a null reference does not |
| 3879 | // need poisoning. |
| 3880 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 3881 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3882 | __ Mov(temp, value.AsRegister<Register>()); |
| 3883 | __ PoisonHeapReference(temp); |
| 3884 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 3885 | } else { |
| 3886 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 3887 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3888 | break; |
| 3889 | } |
| 3890 | |
| 3891 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3892 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3893 | GenerateWideAtomicStore(base, offset, |
| 3894 | value.AsRegisterPairLow<Register>(), |
| 3895 | value.AsRegisterPairHigh<Register>(), |
| 3896 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3897 | locations->GetTemp(1).AsRegister<Register>(), |
| 3898 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3899 | } else { |
| 3900 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3901 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3902 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3903 | break; |
| 3904 | } |
| 3905 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3906 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3907 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3908 | break; |
| 3909 | } |
| 3910 | |
| 3911 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3912 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3913 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3914 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 3915 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 3916 | |
| 3917 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 3918 | |
| 3919 | GenerateWideAtomicStore(base, offset, |
| 3920 | value_reg_lo, |
| 3921 | value_reg_hi, |
| 3922 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3923 | locations->GetTemp(3).AsRegister<Register>(), |
| 3924 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3925 | } else { |
| 3926 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3927 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3928 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3929 | break; |
| 3930 | } |
| 3931 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3932 | case Primitive::kPrimVoid: |
| 3933 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3934 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3935 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3936 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3937 | // Longs and doubles are handled in the switch. |
| 3938 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 3939 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3940 | } |
| 3941 | |
| 3942 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 3943 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3944 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3945 | codegen_->MarkGCCard( |
| 3946 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3947 | } |
| 3948 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3949 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3950 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3951 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3952 | } |
| 3953 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3954 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3955 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3956 | |
| 3957 | bool object_field_get_with_read_barrier = |
| 3958 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3959 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3960 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 3961 | object_field_get_with_read_barrier ? |
| 3962 | LocationSummary::kCallOnSlowPath : |
| 3963 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3964 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3965 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3966 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3967 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3968 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3969 | // The output overlaps in case of volatile long: we don't want the |
| 3970 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 3971 | // object's location. Likewise, in the case of an object field get |
| 3972 | // with read barriers enabled, we do not want the load to overwrite |
| 3973 | // the object's location, as we need it to emit the read barrier. |
| 3974 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 3975 | object_field_get_with_read_barrier; |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 3976 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3977 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3978 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3979 | } else { |
| 3980 | locations->SetOut(Location::RequiresRegister(), |
| 3981 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 3982 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3983 | if (volatile_for_double) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3984 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3985 | // - registers need to be consecutive |
| 3986 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3987 | // We don't test for ARM yet, and the assertion makes sure that we |
| 3988 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3989 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 3990 | locations->AddTemp(Location::RequiresRegister()); |
| 3991 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3992 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 3993 | // We need a temporary register for the read barrier marking slow |
| 3994 | // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
| 3995 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3996 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3997 | } |
| 3998 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 3999 | Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 4000 | DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat) |
| 4001 | << input->GetType(); |
| 4002 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 4003 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 4004 | return Location::ConstantLocation(input->AsConstant()); |
| 4005 | } else { |
| 4006 | return Location::RequiresFpuRegister(); |
| 4007 | } |
| 4008 | } |
| 4009 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4010 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 4011 | Opcode opcode) { |
| 4012 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 4013 | if (constant->IsConstant() && |
| 4014 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 4015 | return Location::ConstantLocation(constant->AsConstant()); |
| 4016 | } |
| 4017 | return Location::RequiresRegister(); |
| 4018 | } |
| 4019 | |
| 4020 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 4021 | Opcode opcode) { |
| 4022 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 4023 | if (Primitive::Is64BitType(input_cst->GetType())) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4024 | Opcode high_opcode = opcode; |
| 4025 | SetCc low_set_cc = kCcDontCare; |
| 4026 | switch (opcode) { |
| 4027 | case SUB: |
| 4028 | // Flip the operation to an ADD. |
| 4029 | value = -value; |
| 4030 | opcode = ADD; |
| 4031 | FALLTHROUGH_INTENDED; |
| 4032 | case ADD: |
| 4033 | if (Low32Bits(value) == 0u) { |
| 4034 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 4035 | } |
| 4036 | high_opcode = ADC; |
| 4037 | low_set_cc = kCcSet; |
| 4038 | break; |
| 4039 | default: |
| 4040 | break; |
| 4041 | } |
| 4042 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 4043 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4044 | } else { |
| 4045 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 4046 | } |
| 4047 | } |
| 4048 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4049 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, |
| 4050 | Opcode opcode, |
| 4051 | SetCc set_cc) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4052 | ShifterOperand so; |
| 4053 | ArmAssembler* assembler = codegen_->GetAssembler(); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4054 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4055 | return true; |
| 4056 | } |
| 4057 | Opcode neg_opcode = kNoOperand; |
| 4058 | switch (opcode) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4059 | case AND: neg_opcode = BIC; value = ~value; break; |
| 4060 | case ORR: neg_opcode = ORN; value = ~value; break; |
| 4061 | case ADD: neg_opcode = SUB; value = -value; break; |
| 4062 | case ADC: neg_opcode = SBC; value = ~value; break; |
| 4063 | case SUB: neg_opcode = ADD; value = -value; break; |
| 4064 | case SBC: neg_opcode = ADC; value = ~value; break; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4065 | default: |
| 4066 | return false; |
| 4067 | } |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4068 | return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, value, set_cc, &so); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4069 | } |
| 4070 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4071 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 4072 | const FieldInfo& field_info) { |
| 4073 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4074 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4075 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4076 | Location base_loc = locations->InAt(0); |
| 4077 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4078 | Location out = locations->Out(); |
| 4079 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4080 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4081 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4082 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4083 | |
| 4084 | switch (field_type) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4085 | case Primitive::kPrimBoolean: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4086 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4087 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4088 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4089 | case Primitive::kPrimByte: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4090 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4091 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4092 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4093 | case Primitive::kPrimShort: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4094 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4095 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4096 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4097 | case Primitive::kPrimChar: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4098 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4099 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4100 | |
| 4101 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4102 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4103 | break; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4104 | |
| 4105 | case Primitive::kPrimNot: { |
| 4106 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4107 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4108 | Location temp_loc = locations->GetTemp(0); |
| 4109 | // Note that a potential implicit null check is handled in this |
| 4110 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call. |
| 4111 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4112 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4113 | if (is_volatile) { |
| 4114 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4115 | } |
| 4116 | } else { |
| 4117 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
| 4118 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4119 | if (is_volatile) { |
| 4120 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4121 | } |
| 4122 | // If read barriers are enabled, emit read barriers other than |
| 4123 | // Baker's using a slow path (and also unpoison the loaded |
| 4124 | // reference, if heap poisoning is enabled). |
| 4125 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4126 | } |
| 4127 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4128 | } |
| 4129 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4130 | case Primitive::kPrimLong: |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4131 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4132 | GenerateWideAtomicLoad(base, offset, |
| 4133 | out.AsRegisterPairLow<Register>(), |
| 4134 | out.AsRegisterPairHigh<Register>()); |
| 4135 | } else { |
| 4136 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 4137 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4138 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4139 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4140 | case Primitive::kPrimFloat: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4141 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4142 | break; |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4143 | |
| 4144 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4145 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4146 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4147 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4148 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4149 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4150 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4151 | __ vmovdrr(out_reg, lo, hi); |
| 4152 | } else { |
| 4153 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4154 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4155 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4156 | break; |
| 4157 | } |
| 4158 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4159 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4160 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4161 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4162 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4163 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4164 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 4165 | // Potential implicit null checks, in the case of reference or |
| 4166 | // double fields, are handled in the previous switch statement. |
| 4167 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4168 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4169 | } |
| 4170 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4171 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4172 | if (field_type == Primitive::kPrimNot) { |
| 4173 | // Memory barriers, in the case of references, are also handled |
| 4174 | // in the previous switch statement. |
| 4175 | } else { |
| 4176 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4177 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4178 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4179 | } |
| 4180 | |
| 4181 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4182 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4183 | } |
| 4184 | |
| 4185 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4186 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4187 | } |
| 4188 | |
| 4189 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4190 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4191 | } |
| 4192 | |
| 4193 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4194 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4195 | } |
| 4196 | |
| 4197 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4198 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4199 | } |
| 4200 | |
| 4201 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4202 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4203 | } |
| 4204 | |
| 4205 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4206 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4207 | } |
| 4208 | |
| 4209 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4210 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4211 | } |
| 4212 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4213 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 4214 | HUnresolvedInstanceFieldGet* instruction) { |
| 4215 | FieldAccessCallingConventionARM calling_convention; |
| 4216 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4217 | instruction, instruction->GetFieldType(), calling_convention); |
| 4218 | } |
| 4219 | |
| 4220 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 4221 | HUnresolvedInstanceFieldGet* instruction) { |
| 4222 | FieldAccessCallingConventionARM calling_convention; |
| 4223 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4224 | instruction->GetFieldType(), |
| 4225 | instruction->GetFieldIndex(), |
| 4226 | instruction->GetDexPc(), |
| 4227 | calling_convention); |
| 4228 | } |
| 4229 | |
| 4230 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 4231 | HUnresolvedInstanceFieldSet* instruction) { |
| 4232 | FieldAccessCallingConventionARM calling_convention; |
| 4233 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4234 | instruction, instruction->GetFieldType(), calling_convention); |
| 4235 | } |
| 4236 | |
| 4237 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 4238 | HUnresolvedInstanceFieldSet* instruction) { |
| 4239 | FieldAccessCallingConventionARM calling_convention; |
| 4240 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4241 | instruction->GetFieldType(), |
| 4242 | instruction->GetFieldIndex(), |
| 4243 | instruction->GetDexPc(), |
| 4244 | calling_convention); |
| 4245 | } |
| 4246 | |
| 4247 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 4248 | HUnresolvedStaticFieldGet* instruction) { |
| 4249 | FieldAccessCallingConventionARM calling_convention; |
| 4250 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4251 | instruction, instruction->GetFieldType(), calling_convention); |
| 4252 | } |
| 4253 | |
| 4254 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 4255 | HUnresolvedStaticFieldGet* instruction) { |
| 4256 | FieldAccessCallingConventionARM calling_convention; |
| 4257 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4258 | instruction->GetFieldType(), |
| 4259 | instruction->GetFieldIndex(), |
| 4260 | instruction->GetDexPc(), |
| 4261 | calling_convention); |
| 4262 | } |
| 4263 | |
| 4264 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 4265 | HUnresolvedStaticFieldSet* instruction) { |
| 4266 | FieldAccessCallingConventionARM calling_convention; |
| 4267 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4268 | instruction, instruction->GetFieldType(), calling_convention); |
| 4269 | } |
| 4270 | |
| 4271 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 4272 | HUnresolvedStaticFieldSet* instruction) { |
| 4273 | FieldAccessCallingConventionARM calling_convention; |
| 4274 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4275 | instruction->GetFieldType(), |
| 4276 | instruction->GetFieldIndex(), |
| 4277 | instruction->GetDexPc(), |
| 4278 | calling_convention); |
| 4279 | } |
| 4280 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4281 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4282 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4283 | ? LocationSummary::kCallOnSlowPath |
| 4284 | : LocationSummary::kNoCall; |
| 4285 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4286 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4287 | if (instruction->HasUses()) { |
| 4288 | locations->SetOut(Location::SameAsFirstInput()); |
| 4289 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4290 | } |
| 4291 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4292 | void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4293 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4294 | return; |
| 4295 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4296 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4297 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4298 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4299 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4300 | } |
| 4301 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4302 | void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4303 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4304 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4305 | |
| 4306 | LocationSummary* locations = instruction->GetLocations(); |
| 4307 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4308 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4309 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4310 | } |
| 4311 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4312 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4313 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4314 | } |
| 4315 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4316 | static LoadOperandType GetLoadOperandType(Primitive::Type type) { |
| 4317 | switch (type) { |
| 4318 | case Primitive::kPrimNot: |
| 4319 | return kLoadWord; |
| 4320 | case Primitive::kPrimBoolean: |
| 4321 | return kLoadUnsignedByte; |
| 4322 | case Primitive::kPrimByte: |
| 4323 | return kLoadSignedByte; |
| 4324 | case Primitive::kPrimChar: |
| 4325 | return kLoadUnsignedHalfword; |
| 4326 | case Primitive::kPrimShort: |
| 4327 | return kLoadSignedHalfword; |
| 4328 | case Primitive::kPrimInt: |
| 4329 | return kLoadWord; |
| 4330 | case Primitive::kPrimLong: |
| 4331 | return kLoadWordPair; |
| 4332 | case Primitive::kPrimFloat: |
| 4333 | return kLoadSWord; |
| 4334 | case Primitive::kPrimDouble: |
| 4335 | return kLoadDWord; |
| 4336 | default: |
| 4337 | LOG(FATAL) << "Unreachable type " << type; |
| 4338 | UNREACHABLE(); |
| 4339 | } |
| 4340 | } |
| 4341 | |
| 4342 | static StoreOperandType GetStoreOperandType(Primitive::Type type) { |
| 4343 | switch (type) { |
| 4344 | case Primitive::kPrimNot: |
| 4345 | return kStoreWord; |
| 4346 | case Primitive::kPrimBoolean: |
| 4347 | case Primitive::kPrimByte: |
| 4348 | return kStoreByte; |
| 4349 | case Primitive::kPrimChar: |
| 4350 | case Primitive::kPrimShort: |
| 4351 | return kStoreHalfword; |
| 4352 | case Primitive::kPrimInt: |
| 4353 | return kStoreWord; |
| 4354 | case Primitive::kPrimLong: |
| 4355 | return kStoreWordPair; |
| 4356 | case Primitive::kPrimFloat: |
| 4357 | return kStoreSWord; |
| 4358 | case Primitive::kPrimDouble: |
| 4359 | return kStoreDWord; |
| 4360 | default: |
| 4361 | LOG(FATAL) << "Unreachable type " << type; |
| 4362 | UNREACHABLE(); |
| 4363 | } |
| 4364 | } |
| 4365 | |
| 4366 | void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type, |
| 4367 | Location out_loc, |
| 4368 | Register base, |
| 4369 | Register reg_offset, |
| 4370 | Condition cond) { |
| 4371 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 4372 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 4373 | |
| 4374 | switch (type) { |
| 4375 | case Primitive::kPrimByte: |
| 4376 | __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4377 | break; |
| 4378 | case Primitive::kPrimBoolean: |
| 4379 | __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4380 | break; |
| 4381 | case Primitive::kPrimShort: |
| 4382 | __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4383 | break; |
| 4384 | case Primitive::kPrimChar: |
| 4385 | __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4386 | break; |
| 4387 | case Primitive::kPrimNot: |
| 4388 | case Primitive::kPrimInt: |
| 4389 | __ ldr(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4390 | break; |
| 4391 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| 4392 | case Primitive::kPrimLong: |
| 4393 | case Primitive::kPrimFloat: |
| 4394 | case Primitive::kPrimDouble: |
| 4395 | default: |
| 4396 | LOG(FATAL) << "Unreachable type " << type; |
| 4397 | UNREACHABLE(); |
| 4398 | } |
| 4399 | } |
| 4400 | |
| 4401 | void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type, |
| 4402 | Location loc, |
| 4403 | Register base, |
| 4404 | Register reg_offset, |
| 4405 | Condition cond) { |
| 4406 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 4407 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 4408 | |
| 4409 | switch (type) { |
| 4410 | case Primitive::kPrimByte: |
| 4411 | case Primitive::kPrimBoolean: |
| 4412 | __ strb(loc.AsRegister<Register>(), mem_address, cond); |
| 4413 | break; |
| 4414 | case Primitive::kPrimShort: |
| 4415 | case Primitive::kPrimChar: |
| 4416 | __ strh(loc.AsRegister<Register>(), mem_address, cond); |
| 4417 | break; |
| 4418 | case Primitive::kPrimNot: |
| 4419 | case Primitive::kPrimInt: |
| 4420 | __ str(loc.AsRegister<Register>(), mem_address, cond); |
| 4421 | break; |
| 4422 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| 4423 | case Primitive::kPrimLong: |
| 4424 | case Primitive::kPrimFloat: |
| 4425 | case Primitive::kPrimDouble: |
| 4426 | default: |
| 4427 | LOG(FATAL) << "Unreachable type " << type; |
| 4428 | UNREACHABLE(); |
| 4429 | } |
| 4430 | } |
| 4431 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4432 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4433 | bool object_array_get_with_read_barrier = |
| 4434 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4435 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4436 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4437 | object_array_get_with_read_barrier ? |
| 4438 | LocationSummary::kCallOnSlowPath : |
| 4439 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4440 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4441 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4442 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4443 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4444 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4445 | // The output overlaps in the case of an object array get with |
| 4446 | // read barriers enabled: we do not want the move to overwrite the |
| 4447 | // array's location, as we need it to emit the read barrier. |
| 4448 | locations->SetOut( |
| 4449 | Location::RequiresRegister(), |
| 4450 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4451 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4452 | // We need a temporary register for the read barrier marking slow |
| 4453 | // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier. |
| 4454 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4455 | locations->AddTemp(Location::RequiresRegister()); |
| 4456 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4457 | } |
| 4458 | |
| 4459 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 4460 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4461 | Location obj_loc = locations->InAt(0); |
| 4462 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4463 | Location index = locations->InAt(1); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4464 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4465 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4466 | Primitive::Type type = instruction->GetType(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4467 | HInstruction* array_instr = instruction->GetArray(); |
| 4468 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 4469 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 4470 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4471 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4472 | switch (type) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4473 | case Primitive::kPrimBoolean: |
| 4474 | case Primitive::kPrimByte: |
| 4475 | case Primitive::kPrimShort: |
| 4476 | case Primitive::kPrimChar: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4477 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4478 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4479 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 4480 | uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type)); |
| 4481 | |
| 4482 | LoadOperandType load_type = GetLoadOperandType(type); |
| 4483 | __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4484 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4485 | Register temp = IP; |
| 4486 | |
| 4487 | if (has_intermediate_address) { |
| 4488 | // We do not need to compute the intermediate address from the array: the |
| 4489 | // input instruction has done it already. See the comment in |
| 4490 | // `TryExtractArrayAccessAddress()`. |
| 4491 | if (kIsDebugBuild) { |
| 4492 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 4493 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 4494 | } |
| 4495 | temp = obj; |
| 4496 | } else { |
| 4497 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 4498 | } |
| 4499 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4500 | } |
| 4501 | break; |
| 4502 | } |
| 4503 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4504 | case Primitive::kPrimNot: { |
| 4505 | static_assert( |
| 4506 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4507 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4508 | // /* HeapReference<Object> */ out = |
| 4509 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4510 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4511 | Location temp = locations->GetTemp(0); |
| 4512 | // Note that a potential implicit null check is handled in this |
| 4513 | // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call. |
| 4514 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4515 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 4516 | } else { |
| 4517 | Register out = out_loc.AsRegister<Register>(); |
| 4518 | if (index.IsConstant()) { |
| 4519 | size_t offset = |
| 4520 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4521 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 4522 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4523 | // If read barriers are enabled, emit read barriers other than |
| 4524 | // Baker's using a slow path (and also unpoison the loaded |
| 4525 | // reference, if heap poisoning is enabled). |
| 4526 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4527 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4528 | Register temp = IP; |
| 4529 | |
| 4530 | if (has_intermediate_address) { |
| 4531 | // We do not need to compute the intermediate address from the array: the |
| 4532 | // input instruction has done it already. See the comment in |
| 4533 | // `TryExtractArrayAccessAddress()`. |
| 4534 | if (kIsDebugBuild) { |
| 4535 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 4536 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 4537 | } |
| 4538 | temp = obj; |
| 4539 | } else { |
| 4540 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 4541 | } |
| 4542 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4543 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4544 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4545 | // If read barriers are enabled, emit read barriers other than |
| 4546 | // Baker's using a slow path (and also unpoison the loaded |
| 4547 | // reference, if heap poisoning is enabled). |
| 4548 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4549 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4550 | } |
| 4551 | } |
| 4552 | break; |
| 4553 | } |
| 4554 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4555 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4556 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4557 | size_t offset = |
| 4558 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4559 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4560 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4561 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4562 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4563 | } |
| 4564 | break; |
| 4565 | } |
| 4566 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4567 | case Primitive::kPrimFloat: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4568 | SRegister out = out_loc.AsFpuRegister<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4569 | if (index.IsConstant()) { |
| 4570 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4571 | __ LoadSFromOffset(out, obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4572 | } else { |
| 4573 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4574 | __ LoadSFromOffset(out, IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4575 | } |
| 4576 | break; |
| 4577 | } |
| 4578 | |
| 4579 | case Primitive::kPrimDouble: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4580 | SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4581 | if (index.IsConstant()) { |
| 4582 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4583 | __ LoadDFromOffset(FromLowSToD(out), obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4584 | } else { |
| 4585 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4586 | __ LoadDFromOffset(FromLowSToD(out), IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4587 | } |
| 4588 | break; |
| 4589 | } |
| 4590 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4591 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4592 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4593 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4594 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4595 | |
| 4596 | if (type == Primitive::kPrimNot) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4597 | // Potential implicit null checks, in the case of reference |
| 4598 | // arrays, are handled in the previous switch statement. |
| 4599 | } else { |
| 4600 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4601 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4602 | } |
| 4603 | |
| 4604 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4605 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4606 | |
| 4607 | bool needs_write_barrier = |
| 4608 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4609 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4610 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4611 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4612 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 4613 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4614 | LocationSummary::kCallOnSlowPath : |
| 4615 | LocationSummary::kNoCall); |
| 4616 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4617 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4618 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4619 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4620 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4621 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4622 | locations->SetInAt(2, Location::RequiresRegister()); |
| 4623 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4624 | if (needs_write_barrier) { |
| 4625 | // Temporary registers for the write barrier. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4626 | // These registers may be used for Baker read barriers too. |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4627 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 4628 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4629 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4630 | } |
| 4631 | |
| 4632 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 4633 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4634 | Location array_loc = locations->InAt(0); |
| 4635 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4636 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4637 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4638 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4639 | bool needs_write_barrier = |
| 4640 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4641 | uint32_t data_offset = |
| 4642 | mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 4643 | Location value_loc = locations->InAt(2); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4644 | HInstruction* array_instr = instruction->GetArray(); |
| 4645 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 4646 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 4647 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4648 | |
| 4649 | switch (value_type) { |
| 4650 | case Primitive::kPrimBoolean: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4651 | case Primitive::kPrimByte: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4652 | case Primitive::kPrimShort: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4653 | case Primitive::kPrimChar: |
| 4654 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4655 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4656 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 4657 | uint32_t full_offset = |
| 4658 | data_offset + (const_index << Primitive::ComponentSizeShift(value_type)); |
| 4659 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 4660 | __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4661 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4662 | Register temp = IP; |
| 4663 | |
| 4664 | if (has_intermediate_address) { |
| 4665 | // We do not need to compute the intermediate address from the array: the |
| 4666 | // input instruction has done it already. See the comment in |
| 4667 | // `TryExtractArrayAccessAddress()`. |
| 4668 | if (kIsDebugBuild) { |
| 4669 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 4670 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset); |
| 4671 | } |
| 4672 | temp = array; |
| 4673 | } else { |
| 4674 | __ add(temp, array, ShifterOperand(data_offset)); |
| 4675 | } |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4676 | codegen_->StoreToShiftedRegOffset(value_type, |
| 4677 | value_loc, |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4678 | temp, |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4679 | index.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4680 | } |
| 4681 | break; |
| 4682 | } |
| 4683 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4684 | case Primitive::kPrimNot: { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4685 | Register value = value_loc.AsRegister<Register>(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4686 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 4687 | // See the comment in instruction_simplifier_shared.cc. |
| 4688 | DCHECK(!has_intermediate_address); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4689 | |
| 4690 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 4691 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4692 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4693 | size_t offset = |
| 4694 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4695 | __ StoreToOffset(kStoreWord, value, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4696 | } else { |
| 4697 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4698 | __ add(IP, array, ShifterOperand(data_offset)); |
| 4699 | codegen_->StoreToShiftedRegOffset(value_type, |
| 4700 | value_loc, |
| 4701 | IP, |
| 4702 | index.AsRegister<Register>()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4703 | } |
Roland Levillain | 1407ee7 | 2016-01-08 15:56:19 +0000 | [diff] [blame] | 4704 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4705 | DCHECK(!needs_write_barrier); |
| 4706 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4707 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4708 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4709 | |
| 4710 | DCHECK(needs_write_barrier); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4711 | Location temp1_loc = locations->GetTemp(0); |
| 4712 | Register temp1 = temp1_loc.AsRegister<Register>(); |
| 4713 | Location temp2_loc = locations->GetTemp(1); |
| 4714 | Register temp2 = temp2_loc.AsRegister<Register>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4715 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4716 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4717 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4718 | Label done; |
| 4719 | SlowPathCode* slow_path = nullptr; |
| 4720 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4721 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4722 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 4723 | codegen_->AddSlowPath(slow_path); |
| 4724 | if (instruction->GetValueCanBeNull()) { |
| 4725 | Label non_zero; |
| 4726 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 4727 | if (index.IsConstant()) { |
| 4728 | size_t offset = |
| 4729 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4730 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 4731 | } else { |
| 4732 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4733 | __ add(IP, array, ShifterOperand(data_offset)); |
| 4734 | codegen_->StoreToShiftedRegOffset(value_type, |
| 4735 | value_loc, |
| 4736 | IP, |
| 4737 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4738 | } |
| 4739 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4740 | __ b(&done); |
| 4741 | __ Bind(&non_zero); |
| 4742 | } |
| 4743 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4744 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4745 | if (!kUseBakerReadBarrier) { |
| 4746 | // When (non-Baker) read barriers are enabled, the type |
| 4747 | // checking instrumentation requires two read barriers |
| 4748 | // generated by CodeGeneratorARM::GenerateReadBarrierSlow: |
| 4749 | // |
| 4750 | // __ Mov(temp2, temp1); |
| 4751 | // // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 4752 | // __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 4753 | // codegen_->GenerateReadBarrierSlow( |
| 4754 | // instruction, temp1_loc, temp1_loc, temp2_loc, component_offset); |
| 4755 | // |
| 4756 | // // /* HeapReference<Class> */ temp2 = value->klass_ |
| 4757 | // __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 4758 | // codegen_->GenerateReadBarrierSlow( |
| 4759 | // instruction, temp2_loc, temp2_loc, value_loc, class_offset, temp1_loc); |
| 4760 | // |
| 4761 | // __ cmp(temp1, ShifterOperand(temp2)); |
| 4762 | // |
| 4763 | // However, the second read barrier may trash `temp`, as it |
| 4764 | // is a temporary register, and as such would not be saved |
| 4765 | // along with live registers before calling the runtime (nor |
| 4766 | // restored afterwards). So in this case, we bail out and |
| 4767 | // delegate the work to the array set slow path. |
| 4768 | // |
| 4769 | // TODO: Extend the register allocator to support a new |
| 4770 | // "(locally) live temp" location so as to avoid always |
| 4771 | // going into the slow path when read barriers are enabled? |
| 4772 | // |
| 4773 | // There is no such problem with Baker read barriers (see below). |
| 4774 | __ b(slow_path->GetEntryLabel()); |
| 4775 | } else { |
| 4776 | Register temp3 = IP; |
| 4777 | Location temp3_loc = Location::RegisterLocation(temp3); |
| 4778 | |
| 4779 | // Note: `temp3` (scratch register IP) cannot be used as |
| 4780 | // `ref` argument of GenerateFieldLoadWithBakerReadBarrier |
| 4781 | // calls below (see ReadBarrierMarkSlowPathARM for more |
| 4782 | // details). |
| 4783 | |
| 4784 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 4785 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4786 | temp1_loc, |
| 4787 | array, |
| 4788 | class_offset, |
| 4789 | temp3_loc, |
| 4790 | /* needs_null_check */ true); |
| 4791 | |
| 4792 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 4793 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4794 | temp1_loc, |
| 4795 | temp1, |
| 4796 | component_offset, |
| 4797 | temp3_loc, |
| 4798 | /* needs_null_check */ false); |
| 4799 | // Register `temp1` is not trashed by the read barrier |
| 4800 | // emitted by GenerateFieldLoadWithBakerReadBarrier below, |
| 4801 | // as that method produces a call to a ReadBarrierMarkRegX |
| 4802 | // entry point, which saves all potentially live registers, |
| 4803 | // including temporaries such a `temp1`. |
| 4804 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 4805 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4806 | temp2_loc, |
| 4807 | value, |
| 4808 | class_offset, |
| 4809 | temp3_loc, |
| 4810 | /* needs_null_check */ false); |
| 4811 | // If heap poisoning is enabled, `temp1` and `temp2` have |
| 4812 | // been unpoisoned by the the previous calls to |
| 4813 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
| 4814 | __ cmp(temp1, ShifterOperand(temp2)); |
| 4815 | |
| 4816 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4817 | Label do_put; |
| 4818 | __ b(&do_put, EQ); |
| 4819 | // We do not need to emit a read barrier for the |
| 4820 | // following heap reference load, as `temp1` is only used |
| 4821 | // in a comparison with null below, and this reference |
| 4822 | // is not kept afterwards. |
| 4823 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 4824 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 4825 | // If heap poisoning is enabled, no need to unpoison |
| 4826 | // `temp`, as we are comparing against null below. |
| 4827 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 4828 | __ Bind(&do_put); |
| 4829 | } else { |
| 4830 | __ b(slow_path->GetEntryLabel(), NE); |
| 4831 | } |
| 4832 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4833 | } else { |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4834 | // Non read barrier code. |
| 4835 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4836 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 4837 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 4838 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4839 | __ MaybeUnpoisonHeapReference(temp1); |
| 4840 | |
| 4841 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 4842 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 4843 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 4844 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 4845 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 4846 | // nor `temp2`, as we are comparing two poisoned references. |
| 4847 | __ cmp(temp1, ShifterOperand(temp2)); |
| 4848 | |
| 4849 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4850 | Label do_put; |
| 4851 | __ b(&do_put, EQ); |
| 4852 | // If heap poisoning is enabled, the `temp1` reference has |
| 4853 | // not been unpoisoned yet; unpoison it now. |
| 4854 | __ MaybeUnpoisonHeapReference(temp1); |
| 4855 | |
| 4856 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 4857 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 4858 | // If heap poisoning is enabled, no need to unpoison |
| 4859 | // `temp1`, as we are comparing against null below. |
| 4860 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 4861 | __ Bind(&do_put); |
| 4862 | } else { |
| 4863 | __ b(slow_path->GetEntryLabel(), NE); |
| 4864 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4865 | } |
| 4866 | } |
| 4867 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4868 | Register source = value; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4869 | if (kPoisonHeapReferences) { |
| 4870 | // Note that in the case where `value` is a null reference, |
| 4871 | // we do not enter this block, as a null reference does not |
| 4872 | // need poisoning. |
| 4873 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 4874 | __ Mov(temp1, value); |
| 4875 | __ PoisonHeapReference(temp1); |
| 4876 | source = temp1; |
| 4877 | } |
| 4878 | |
| 4879 | if (index.IsConstant()) { |
| 4880 | size_t offset = |
| 4881 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4882 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 4883 | } else { |
| 4884 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4885 | |
| 4886 | __ add(IP, array, ShifterOperand(data_offset)); |
| 4887 | codegen_->StoreToShiftedRegOffset(value_type, |
| 4888 | Location::RegisterLocation(source), |
| 4889 | IP, |
| 4890 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4891 | } |
| 4892 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4893 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4894 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4895 | } |
| 4896 | |
| 4897 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 4898 | |
| 4899 | if (done.IsLinked()) { |
| 4900 | __ Bind(&done); |
| 4901 | } |
| 4902 | |
| 4903 | if (slow_path != nullptr) { |
| 4904 | __ Bind(slow_path->GetExitLabel()); |
| 4905 | } |
| 4906 | |
| 4907 | break; |
| 4908 | } |
| 4909 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4910 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4911 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4912 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4913 | size_t offset = |
| 4914 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4915 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4916 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4917 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4918 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4919 | } |
| 4920 | break; |
| 4921 | } |
| 4922 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4923 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4924 | Location value = locations->InAt(2); |
| 4925 | DCHECK(value.IsFpuRegister()); |
| 4926 | if (index.IsConstant()) { |
| 4927 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4928 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4929 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4930 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4931 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 4932 | } |
| 4933 | break; |
| 4934 | } |
| 4935 | |
| 4936 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4937 | Location value = locations->InAt(2); |
| 4938 | DCHECK(value.IsFpuRegisterPair()); |
| 4939 | if (index.IsConstant()) { |
| 4940 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4941 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4942 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4943 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4944 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 4945 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4946 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4947 | break; |
| 4948 | } |
| 4949 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4950 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4951 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4952 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4953 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4954 | |
Roland Levillain | 80e6709 | 2016-01-08 16:04:55 +0000 | [diff] [blame] | 4955 | // Objects are handled in the switch. |
| 4956 | if (value_type != Primitive::kPrimNot) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4957 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4958 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4959 | } |
| 4960 | |
| 4961 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4962 | LocationSummary* locations = |
| 4963 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4964 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4965 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4966 | } |
| 4967 | |
| 4968 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 4969 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 4970 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4971 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4972 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4973 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4974 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4975 | } |
| 4976 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4977 | void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 4978 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 4979 | DCHECK(!kEmitCompilerReadBarrier); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4980 | LocationSummary* locations = |
| 4981 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4982 | |
| 4983 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4984 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 4985 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4986 | } |
| 4987 | |
| 4988 | void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 4989 | LocationSummary* locations = instruction->GetLocations(); |
| 4990 | Location out = locations->Out(); |
| 4991 | Location first = locations->InAt(0); |
| 4992 | Location second = locations->InAt(1); |
| 4993 | |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 4994 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 4995 | DCHECK(!kEmitCompilerReadBarrier); |
| 4996 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4997 | if (second.IsRegister()) { |
| 4998 | __ add(out.AsRegister<Register>(), |
| 4999 | first.AsRegister<Register>(), |
| 5000 | ShifterOperand(second.AsRegister<Register>())); |
| 5001 | } else { |
| 5002 | __ AddConstant(out.AsRegister<Register>(), |
| 5003 | first.AsRegister<Register>(), |
| 5004 | second.GetConstant()->AsIntConstant()->GetValue()); |
| 5005 | } |
| 5006 | } |
| 5007 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5008 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5009 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5010 | ? LocationSummary::kCallOnSlowPath |
| 5011 | : LocationSummary::kNoCall; |
| 5012 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5013 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5014 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5015 | if (instruction->HasUses()) { |
| 5016 | locations->SetOut(Location::SameAsFirstInput()); |
| 5017 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5018 | } |
| 5019 | |
| 5020 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5021 | LocationSummary* locations = instruction->GetLocations(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5022 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5023 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5024 | codegen_->AddSlowPath(slow_path); |
| 5025 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5026 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 5027 | Register length = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5028 | |
| 5029 | __ cmp(index, ShifterOperand(length)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 5030 | __ b(slow_path->GetEntryLabel(), HS); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5031 | } |
| 5032 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5033 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 5034 | Register card, |
| 5035 | Register object, |
| 5036 | Register value, |
| 5037 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5038 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5039 | if (can_be_null) { |
| 5040 | __ CompareAndBranchIfZero(value, &is_null); |
| 5041 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5042 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5043 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 5044 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5045 | if (can_be_null) { |
| 5046 | __ Bind(&is_null); |
| 5047 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5048 | } |
| 5049 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5050 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5051 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5052 | } |
| 5053 | |
| 5054 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5055 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5056 | } |
| 5057 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5058 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5059 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5060 | } |
| 5061 | |
| 5062 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5063 | HBasicBlock* block = instruction->GetBlock(); |
| 5064 | if (block->GetLoopInformation() != nullptr) { |
| 5065 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5066 | // The back edge will generate the suspend check. |
| 5067 | return; |
| 5068 | } |
| 5069 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5070 | // The goto will generate the suspend check. |
| 5071 | return; |
| 5072 | } |
| 5073 | GenerateSuspendCheck(instruction, nullptr); |
| 5074 | } |
| 5075 | |
| 5076 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5077 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5078 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5079 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 5080 | if (slow_path == nullptr) { |
| 5081 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 5082 | instruction->SetSlowPath(slow_path); |
| 5083 | codegen_->AddSlowPath(slow_path); |
| 5084 | if (successor != nullptr) { |
| 5085 | DCHECK(successor->IsLoopHeader()); |
| 5086 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5087 | } |
| 5088 | } else { |
| 5089 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5090 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5091 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 5092 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5093 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5094 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5095 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5096 | __ Bind(slow_path->GetReturnLabel()); |
| 5097 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5098 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5099 | __ b(slow_path->GetEntryLabel()); |
| 5100 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5101 | } |
| 5102 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5103 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 5104 | return codegen_->GetAssembler(); |
| 5105 | } |
| 5106 | |
| 5107 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5108 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5109 | Location source = move->GetSource(); |
| 5110 | Location destination = move->GetDestination(); |
| 5111 | |
| 5112 | if (source.IsRegister()) { |
| 5113 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5114 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5115 | } else if (destination.IsFpuRegister()) { |
| 5116 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5117 | } else { |
| 5118 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5119 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5120 | SP, destination.GetStackIndex()); |
| 5121 | } |
| 5122 | } else if (source.IsStackSlot()) { |
| 5123 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5124 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5125 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5126 | } else if (destination.IsFpuRegister()) { |
| 5127 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5128 | } else { |
| 5129 | DCHECK(destination.IsStackSlot()); |
| 5130 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 5131 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5132 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5133 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5134 | if (destination.IsRegister()) { |
| 5135 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
| 5136 | } else if (destination.IsFpuRegister()) { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5137 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5138 | } else { |
| 5139 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5140 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 5141 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5142 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5143 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5144 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 5145 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5146 | } else if (destination.IsRegisterPair()) { |
| 5147 | DCHECK(ExpectedPairLayout(destination)); |
| 5148 | __ LoadFromOffset( |
| 5149 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 5150 | } else { |
| 5151 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 5152 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5153 | SP, |
| 5154 | source.GetStackIndex()); |
| 5155 | } |
| 5156 | } else if (source.IsRegisterPair()) { |
| 5157 | if (destination.IsRegisterPair()) { |
| 5158 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 5159 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5160 | } else if (destination.IsFpuRegisterPair()) { |
| 5161 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5162 | source.AsRegisterPairLow<Register>(), |
| 5163 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5164 | } else { |
| 5165 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5166 | DCHECK(ExpectedPairLayout(source)); |
| 5167 | __ StoreToOffset( |
| 5168 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 5169 | } |
| 5170 | } else if (source.IsFpuRegisterPair()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5171 | if (destination.IsRegisterPair()) { |
| 5172 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5173 | destination.AsRegisterPairHigh<Register>(), |
| 5174 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5175 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5176 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5177 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5178 | } else { |
| 5179 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5180 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 5181 | SP, |
| 5182 | destination.GetStackIndex()); |
| 5183 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5184 | } else { |
| 5185 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5186 | HConstant* constant = source.GetConstant(); |
| 5187 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5188 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5189 | if (destination.IsRegister()) { |
| 5190 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 5191 | } else { |
| 5192 | DCHECK(destination.IsStackSlot()); |
| 5193 | __ LoadImmediate(IP, value); |
| 5194 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5195 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5196 | } else if (constant->IsLongConstant()) { |
| 5197 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5198 | if (destination.IsRegisterPair()) { |
| 5199 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 5200 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5201 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5202 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5203 | __ LoadImmediate(IP, Low32Bits(value)); |
| 5204 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5205 | __ LoadImmediate(IP, High32Bits(value)); |
| 5206 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5207 | } |
| 5208 | } else if (constant->IsDoubleConstant()) { |
| 5209 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5210 | if (destination.IsFpuRegisterPair()) { |
| 5211 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5212 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5213 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5214 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5215 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 5216 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5217 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 5218 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5219 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5220 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5221 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5222 | float value = constant->AsFloatConstant()->GetValue(); |
| 5223 | if (destination.IsFpuRegister()) { |
| 5224 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 5225 | } else { |
| 5226 | DCHECK(destination.IsStackSlot()); |
| 5227 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 5228 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5229 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5230 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5231 | } |
| 5232 | } |
| 5233 | |
| 5234 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 5235 | __ Mov(IP, reg); |
| 5236 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 5237 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 5238 | } |
| 5239 | |
| 5240 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 5241 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 5242 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 5243 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5244 | SP, mem1 + stack_offset); |
| 5245 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 5246 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5247 | SP, mem2 + stack_offset); |
| 5248 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 5249 | } |
| 5250 | |
| 5251 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5252 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5253 | Location source = move->GetSource(); |
| 5254 | Location destination = move->GetDestination(); |
| 5255 | |
| 5256 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5257 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 5258 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 5259 | __ Mov(IP, source.AsRegister<Register>()); |
| 5260 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5261 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5262 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5263 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5264 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5265 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5266 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5267 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5268 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5269 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5270 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5271 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5272 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5273 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5274 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5275 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5276 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5277 | destination.AsRegisterPairHigh<Register>(), |
| 5278 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5279 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5280 | Register low_reg = source.IsRegisterPair() |
| 5281 | ? source.AsRegisterPairLow<Register>() |
| 5282 | : destination.AsRegisterPairLow<Register>(); |
| 5283 | int mem = source.IsRegisterPair() |
| 5284 | ? destination.GetStackIndex() |
| 5285 | : source.GetStackIndex(); |
| 5286 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5287 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5288 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5289 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5290 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5291 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 5292 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5293 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5294 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5295 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5296 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 5297 | DRegister reg = source.IsFpuRegisterPair() |
| 5298 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 5299 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 5300 | int mem = source.IsFpuRegisterPair() |
| 5301 | ? destination.GetStackIndex() |
| 5302 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5303 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5304 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5305 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5306 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 5307 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 5308 | : destination.AsFpuRegister<SRegister>(); |
| 5309 | int mem = source.IsFpuRegister() |
| 5310 | ? destination.GetStackIndex() |
| 5311 | : source.GetStackIndex(); |
| 5312 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5313 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5314 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5315 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5316 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5317 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 5318 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5319 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5320 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5321 | } |
| 5322 | } |
| 5323 | |
| 5324 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 5325 | __ Push(static_cast<Register>(reg)); |
| 5326 | } |
| 5327 | |
| 5328 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 5329 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5330 | } |
| 5331 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5332 | HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind( |
| 5333 | HLoadClass::LoadKind desired_class_load_kind) { |
| 5334 | if (kEmitCompilerReadBarrier) { |
| 5335 | switch (desired_class_load_kind) { |
| 5336 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5337 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5338 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5339 | // TODO: Implement for read barrier. |
| 5340 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5341 | default: |
| 5342 | break; |
| 5343 | } |
| 5344 | } |
| 5345 | switch (desired_class_load_kind) { |
| 5346 | case HLoadClass::LoadKind::kReferrersClass: |
| 5347 | break; |
| 5348 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5349 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5350 | break; |
| 5351 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5352 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5353 | break; |
| 5354 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5355 | break; |
| 5356 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 5357 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5358 | break; |
| 5359 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5360 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5361 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5362 | // is incompatible with it. |
| 5363 | // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods |
| 5364 | // with irreducible loops. |
| 5365 | if (GetGraph()->HasIrreducibleLoops()) { |
| 5366 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5367 | } |
| 5368 | break; |
| 5369 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5370 | break; |
| 5371 | } |
| 5372 | return desired_class_load_kind; |
| 5373 | } |
| 5374 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5375 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5376 | if (cls->NeedsAccessCheck()) { |
| 5377 | InvokeRuntimeCallingConvention calling_convention; |
| 5378 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5379 | cls, |
| 5380 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 5381 | Location::RegisterLocation(R0), |
| 5382 | /* code_generator_supports_read_barrier */ true); |
| 5383 | return; |
| 5384 | } |
| 5385 | |
| 5386 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier) |
| 5387 | ? LocationSummary::kCallOnSlowPath |
| 5388 | : LocationSummary::kNoCall; |
| 5389 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
| 5390 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5391 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 5392 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod || |
| 5393 | load_kind == HLoadClass::LoadKind::kDexCachePcRelative) { |
| 5394 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5395 | } |
| 5396 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5397 | } |
| 5398 | |
| 5399 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5400 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5401 | if (cls->NeedsAccessCheck()) { |
| 5402 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 5403 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5404 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5405 | return; |
| 5406 | } |
| 5407 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5408 | Location out_loc = locations->Out(); |
| 5409 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5410 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5411 | bool generate_null_check = false; |
| 5412 | switch (cls->GetLoadKind()) { |
| 5413 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5414 | DCHECK(!cls->CanCallRuntime()); |
| 5415 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5416 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5417 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 5418 | GenerateGcRootFieldLoad( |
| 5419 | cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
| 5420 | break; |
| 5421 | } |
| 5422 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
| 5423 | DCHECK(!kEmitCompilerReadBarrier); |
| 5424 | __ LoadLiteral(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 5425 | cls->GetTypeIndex())); |
| 5426 | break; |
| 5427 | } |
| 5428 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
| 5429 | DCHECK(!kEmitCompilerReadBarrier); |
| 5430 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 5431 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 5432 | __ BindTrackedLabel(&labels->movw_label); |
| 5433 | __ movw(out, /* placeholder */ 0u); |
| 5434 | __ BindTrackedLabel(&labels->movt_label); |
| 5435 | __ movt(out, /* placeholder */ 0u); |
| 5436 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5437 | __ add(out, out, ShifterOperand(PC)); |
| 5438 | break; |
| 5439 | } |
| 5440 | case HLoadClass::LoadKind::kBootImageAddress: { |
| 5441 | DCHECK(!kEmitCompilerReadBarrier); |
| 5442 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5443 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5444 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5445 | break; |
| 5446 | } |
| 5447 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 5448 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5449 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5450 | // 16-bit LDR immediate has a 5-bit offset multiplied by the size and that gives |
| 5451 | // a 128B range. To try and reduce the number of literals if we load multiple types, |
| 5452 | // simply split the dex cache address to a 128B aligned base loaded from a literal |
| 5453 | // and the remaining offset embedded in the load. |
| 5454 | static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes."); |
| 5455 | DCHECK_ALIGNED(cls->GetAddress(), 4u); |
| 5456 | constexpr size_t offset_bits = /* encoded bits */ 5 + /* scale */ 2; |
| 5457 | uint32_t base_address = address & ~MaxInt<uint32_t>(offset_bits); |
| 5458 | uint32_t offset = address & MaxInt<uint32_t>(offset_bits); |
| 5459 | __ LoadLiteral(out, codegen_->DeduplicateDexCacheAddressLiteral(base_address)); |
| 5460 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) |
| 5461 | GenerateGcRootFieldLoad(cls, out_loc, out, offset); |
| 5462 | generate_null_check = !cls->IsInDexCache(); |
| 5463 | break; |
| 5464 | } |
| 5465 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 5466 | Register base_reg = locations->InAt(0).AsRegister<Register>(); |
| 5467 | HArmDexCacheArraysBase* base = cls->InputAt(0)->AsArmDexCacheArraysBase(); |
| 5468 | int32_t offset = cls->GetDexCacheElementOffset() - base->GetElementOffset(); |
| 5469 | // /* GcRoot<mirror::Class> */ out = *(dex_cache_arrays_base + offset) |
| 5470 | GenerateGcRootFieldLoad(cls, out_loc, base_reg, offset); |
| 5471 | generate_null_check = !cls->IsInDexCache(); |
| 5472 | break; |
| 5473 | } |
| 5474 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 5475 | // /* GcRoot<mirror::Class>[] */ out = |
| 5476 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5477 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 5478 | __ LoadFromOffset(kLoadWord, |
| 5479 | out, |
| 5480 | current_method, |
| 5481 | ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value()); |
| 5482 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5483 | size_t offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex()); |
| 5484 | GenerateGcRootFieldLoad(cls, out_loc, out, offset); |
| 5485 | generate_null_check = !cls->IsInDexCache(); |
| 5486 | } |
| 5487 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5488 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5489 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5490 | DCHECK(cls->CanCallRuntime()); |
| 5491 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
| 5492 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5493 | codegen_->AddSlowPath(slow_path); |
| 5494 | if (generate_null_check) { |
| 5495 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 5496 | } |
| 5497 | if (cls->MustGenerateClinitCheck()) { |
| 5498 | GenerateClassInitializationCheck(slow_path, out); |
| 5499 | } else { |
| 5500 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5501 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5502 | } |
| 5503 | } |
| 5504 | |
| 5505 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 5506 | LocationSummary* locations = |
| 5507 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5508 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5509 | if (check->HasUses()) { |
| 5510 | locations->SetOut(Location::SameAsFirstInput()); |
| 5511 | } |
| 5512 | } |
| 5513 | |
| 5514 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5515 | // We assume the class is not null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5516 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5517 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5518 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5519 | GenerateClassInitializationCheck(slow_path, |
| 5520 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5521 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5522 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5523 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5524 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5525 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 5526 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 5527 | __ b(slow_path->GetEntryLabel(), LT); |
| 5528 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 5529 | // properly. Therefore, we do a memory fence. |
| 5530 | __ dmb(ISH); |
| 5531 | __ Bind(slow_path->GetExitLabel()); |
| 5532 | } |
| 5533 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5534 | HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind( |
| 5535 | HLoadString::LoadKind desired_string_load_kind) { |
| 5536 | if (kEmitCompilerReadBarrier) { |
| 5537 | switch (desired_string_load_kind) { |
| 5538 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5539 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5540 | case HLoadString::LoadKind::kBootImageAddress: |
| 5541 | // TODO: Implement for read barrier. |
| 5542 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 5543 | default: |
| 5544 | break; |
| 5545 | } |
| 5546 | } |
| 5547 | switch (desired_string_load_kind) { |
| 5548 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5549 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5550 | break; |
| 5551 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5552 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5553 | break; |
| 5554 | case HLoadString::LoadKind::kBootImageAddress: |
| 5555 | break; |
| 5556 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5557 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5558 | break; |
| 5559 | case HLoadString::LoadKind::kDexCachePcRelative: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5560 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5561 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5562 | // is incompatible with it. |
| 5563 | // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods |
| 5564 | // with irreducible loops. |
| 5565 | if (GetGraph()->HasIrreducibleLoops()) { |
| 5566 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 5567 | } |
| 5568 | break; |
| 5569 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5570 | break; |
| 5571 | } |
| 5572 | return desired_string_load_kind; |
| 5573 | } |
| 5574 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5575 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5576 | LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5577 | ? LocationSummary::kCallOnSlowPath |
| 5578 | : LocationSummary::kNoCall; |
| 5579 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5580 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 5581 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod || |
| 5582 | load_kind == HLoadString::LoadKind::kDexCachePcRelative) { |
| 5583 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5584 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5585 | locations->SetOut(Location::RequiresRegister()); |
| 5586 | } |
| 5587 | |
| 5588 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5589 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5590 | Location out_loc = locations->Out(); |
| 5591 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5592 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5593 | switch (load->GetLoadKind()) { |
| 5594 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
| 5595 | DCHECK(!kEmitCompilerReadBarrier); |
| 5596 | __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 5597 | load->GetStringIndex())); |
| 5598 | return; // No dex cache slow path. |
| 5599 | } |
| 5600 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 5601 | DCHECK(!kEmitCompilerReadBarrier); |
| 5602 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 5603 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
| 5604 | __ BindTrackedLabel(&labels->movw_label); |
| 5605 | __ movw(out, /* placeholder */ 0u); |
| 5606 | __ BindTrackedLabel(&labels->movt_label); |
| 5607 | __ movt(out, /* placeholder */ 0u); |
| 5608 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5609 | __ add(out, out, ShifterOperand(PC)); |
| 5610 | return; // No dex cache slow path. |
| 5611 | } |
| 5612 | case HLoadString::LoadKind::kBootImageAddress: { |
| 5613 | DCHECK(!kEmitCompilerReadBarrier); |
| 5614 | DCHECK_NE(load->GetAddress(), 0u); |
| 5615 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 5616 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5617 | return; // No dex cache slow path. |
| 5618 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5619 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5620 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5621 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5622 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5623 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
| 5624 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 5625 | codegen_->AddSlowPath(slow_path); |
| 5626 | __ b(slow_path->GetEntryLabel()); |
| 5627 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5628 | } |
| 5629 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5630 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5631 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5632 | } |
| 5633 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5634 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 5635 | LocationSummary* locations = |
| 5636 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5637 | locations->SetOut(Location::RequiresRegister()); |
| 5638 | } |
| 5639 | |
| 5640 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5641 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5642 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 5643 | } |
| 5644 | |
| 5645 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 5646 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5647 | } |
| 5648 | |
| 5649 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5650 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5651 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5652 | } |
| 5653 | |
| 5654 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 5655 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5656 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5657 | InvokeRuntimeCallingConvention calling_convention; |
| 5658 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5659 | } |
| 5660 | |
| 5661 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 5662 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5663 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5664 | } |
| 5665 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5666 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5667 | return kEmitCompilerReadBarrier && |
| 5668 | (kUseBakerReadBarrier || |
| 5669 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5670 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5671 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5672 | } |
| 5673 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5674 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5675 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5676 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5677 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5678 | case TypeCheckKind::kExactCheck: |
| 5679 | case TypeCheckKind::kAbstractClassCheck: |
| 5680 | case TypeCheckKind::kClassHierarchyCheck: |
| 5681 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5682 | call_kind = |
| 5683 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5684 | break; |
| 5685 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5686 | case TypeCheckKind::kUnresolvedCheck: |
| 5687 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5688 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5689 | break; |
| 5690 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5691 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5692 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5693 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5694 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5695 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 5696 | // Note that TypeCheckSlowPathARM uses this register too. |
| 5697 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5698 | // When read barriers are enabled, we need a temporary register for |
| 5699 | // some cases. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5700 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5701 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5702 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5703 | } |
| 5704 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5705 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5706 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5707 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5708 | Location obj_loc = locations->InAt(0); |
| 5709 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5710 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5711 | Location out_loc = locations->Out(); |
| 5712 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5713 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5714 | locations->GetTemp(0) : |
| 5715 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5716 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5717 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5718 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5719 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5720 | Label done, zero; |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5721 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5722 | |
| 5723 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5724 | // avoid null check if we know obj is not null. |
| 5725 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | d56376c | 2015-05-21 12:32:34 +0000 | [diff] [blame] | 5726 | __ CompareAndBranchIfZero(obj, &zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5727 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5728 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5729 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5730 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5731 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5732 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5733 | case TypeCheckKind::kExactCheck: { |
| 5734 | __ cmp(out, ShifterOperand(cls)); |
| 5735 | // Classes must be equal for the instanceof to succeed. |
| 5736 | __ b(&zero, NE); |
| 5737 | __ LoadImmediate(out, 1); |
| 5738 | __ b(&done); |
| 5739 | break; |
| 5740 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5741 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5742 | case TypeCheckKind::kAbstractClassCheck: { |
| 5743 | // If the class is abstract, we eagerly fetch the super class of the |
| 5744 | // object to avoid doing a comparison we know will fail. |
| 5745 | Label loop; |
| 5746 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5747 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5748 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5749 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5750 | __ CompareAndBranchIfZero(out, &done); |
| 5751 | __ cmp(out, ShifterOperand(cls)); |
| 5752 | __ b(&loop, NE); |
| 5753 | __ LoadImmediate(out, 1); |
| 5754 | if (zero.IsLinked()) { |
| 5755 | __ b(&done); |
| 5756 | } |
| 5757 | break; |
| 5758 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5759 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5760 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5761 | // Walk over the class hierarchy to find a match. |
| 5762 | Label loop, success; |
| 5763 | __ Bind(&loop); |
| 5764 | __ cmp(out, ShifterOperand(cls)); |
| 5765 | __ b(&success, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5766 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5767 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5768 | __ CompareAndBranchIfNonZero(out, &loop); |
| 5769 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5770 | __ b(&done); |
| 5771 | __ Bind(&success); |
| 5772 | __ LoadImmediate(out, 1); |
| 5773 | if (zero.IsLinked()) { |
| 5774 | __ b(&done); |
| 5775 | } |
| 5776 | break; |
| 5777 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5778 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5779 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5780 | // Do an exact check. |
| 5781 | Label exact_check; |
| 5782 | __ cmp(out, ShifterOperand(cls)); |
| 5783 | __ b(&exact_check, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5784 | // 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] | 5785 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5786 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5787 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5788 | __ CompareAndBranchIfZero(out, &done); |
| 5789 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 5790 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 5791 | __ CompareAndBranchIfNonZero(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5792 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5793 | __ LoadImmediate(out, 1); |
| 5794 | __ b(&done); |
| 5795 | break; |
| 5796 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5797 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5798 | case TypeCheckKind::kArrayCheck: { |
| 5799 | __ cmp(out, ShifterOperand(cls)); |
| 5800 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5801 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5802 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5803 | codegen_->AddSlowPath(slow_path); |
| 5804 | __ b(slow_path->GetEntryLabel(), NE); |
| 5805 | __ LoadImmediate(out, 1); |
| 5806 | if (zero.IsLinked()) { |
| 5807 | __ b(&done); |
| 5808 | } |
| 5809 | break; |
| 5810 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5811 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5812 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5813 | case TypeCheckKind::kInterfaceCheck: { |
| 5814 | // 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] | 5815 | // into the slow path for the unresolved and interface check |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5816 | // cases. |
| 5817 | // |
| 5818 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5819 | // entry point without resorting to a type checking slow path |
| 5820 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5821 | // require to assign fixed registers for the inputs of this |
| 5822 | // HInstanceOf instruction (following the runtime calling |
| 5823 | // convention), which might be cluttered by the potential first |
| 5824 | // read barrier emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5825 | // |
| 5826 | // TODO: Introduce a new runtime entry point taking the object |
| 5827 | // to test (instead of its class) as argument, and let it deal |
| 5828 | // with the read barrier issues. This will let us refactor this |
| 5829 | // case of the `switch` code as it was previously (with a direct |
| 5830 | // call to the runtime not using a type checking slow path). |
| 5831 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5832 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5833 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5834 | /* is_fatal */ false); |
| 5835 | codegen_->AddSlowPath(slow_path); |
| 5836 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5837 | if (zero.IsLinked()) { |
| 5838 | __ b(&done); |
| 5839 | } |
| 5840 | break; |
| 5841 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5842 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5843 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5844 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5845 | __ Bind(&zero); |
| 5846 | __ LoadImmediate(out, 0); |
| 5847 | } |
| 5848 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5849 | if (done.IsLinked()) { |
| 5850 | __ Bind(&done); |
| 5851 | } |
| 5852 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5853 | if (slow_path != nullptr) { |
| 5854 | __ Bind(slow_path->GetExitLabel()); |
| 5855 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5856 | } |
| 5857 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5858 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5859 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5860 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 5861 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5862 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5863 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5864 | case TypeCheckKind::kExactCheck: |
| 5865 | case TypeCheckKind::kAbstractClassCheck: |
| 5866 | case TypeCheckKind::kClassHierarchyCheck: |
| 5867 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5868 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 5869 | LocationSummary::kCallOnSlowPath : |
| 5870 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5871 | break; |
| 5872 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5873 | case TypeCheckKind::kUnresolvedCheck: |
| 5874 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5875 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5876 | break; |
| 5877 | } |
| 5878 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5879 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5880 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5881 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5882 | // Note that TypeCheckSlowPathARM uses this "temp" register too. |
| 5883 | locations->AddTemp(Location::RequiresRegister()); |
| 5884 | // When read barriers are enabled, we need an additional temporary |
| 5885 | // register for some cases. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5886 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5887 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5888 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5889 | } |
| 5890 | |
| 5891 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5892 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5893 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5894 | Location obj_loc = locations->InAt(0); |
| 5895 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5896 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5897 | Location temp_loc = locations->GetTemp(0); |
| 5898 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5899 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5900 | locations->GetTemp(1) : |
| 5901 | Location::NoLocation(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5902 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5903 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5904 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5905 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5906 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5907 | bool is_type_check_slow_path_fatal = |
| 5908 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 5909 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5910 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5911 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 5912 | !instruction->CanThrowIntoCatchBlock(); |
| 5913 | SlowPathCode* type_check_slow_path = |
| 5914 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5915 | is_type_check_slow_path_fatal); |
| 5916 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5917 | |
| 5918 | Label done; |
| 5919 | // Avoid null check if we know obj is not null. |
| 5920 | if (instruction->MustDoNullCheck()) { |
| 5921 | __ CompareAndBranchIfZero(obj, &done); |
| 5922 | } |
| 5923 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5924 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5925 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5926 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5927 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5928 | case TypeCheckKind::kExactCheck: |
| 5929 | case TypeCheckKind::kArrayCheck: { |
| 5930 | __ cmp(temp, ShifterOperand(cls)); |
| 5931 | // Jump to slow path for throwing the exception or doing a |
| 5932 | // more involved array check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5933 | __ b(type_check_slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5934 | break; |
| 5935 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5936 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5937 | case TypeCheckKind::kAbstractClassCheck: { |
| 5938 | // If the class is abstract, we eagerly fetch the super class of the |
| 5939 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5940 | Label loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5941 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5942 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5943 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5944 | |
| 5945 | // If the class reference currently in `temp` is not null, jump |
| 5946 | // to the `compare_classes` label to compare it with the checked |
| 5947 | // class. |
| 5948 | __ CompareAndBranchIfNonZero(temp, &compare_classes); |
| 5949 | // Otherwise, jump to the slow path to throw the exception. |
| 5950 | // |
| 5951 | // But before, move back the object's class into `temp` before |
| 5952 | // going into the slow path, as it has been overwritten in the |
| 5953 | // meantime. |
| 5954 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5955 | GenerateReferenceLoadTwoRegisters( |
| 5956 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5957 | __ b(type_check_slow_path->GetEntryLabel()); |
| 5958 | |
| 5959 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5960 | __ cmp(temp, ShifterOperand(cls)); |
| 5961 | __ b(&loop, NE); |
| 5962 | break; |
| 5963 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5964 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5965 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5966 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5967 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5968 | __ Bind(&loop); |
| 5969 | __ cmp(temp, ShifterOperand(cls)); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5970 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5971 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5972 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5973 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5974 | |
| 5975 | // If the class reference currently in `temp` is not null, jump |
| 5976 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5977 | __ CompareAndBranchIfNonZero(temp, &loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5978 | // Otherwise, jump to the slow path to throw the exception. |
| 5979 | // |
| 5980 | // But before, move back the object's class into `temp` before |
| 5981 | // going into the slow path, as it has been overwritten in the |
| 5982 | // meantime. |
| 5983 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5984 | GenerateReferenceLoadTwoRegisters( |
| 5985 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5986 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5987 | break; |
| 5988 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5989 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5990 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5991 | // Do an exact check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5992 | Label check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5993 | __ cmp(temp, ShifterOperand(cls)); |
| 5994 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5995 | |
| 5996 | // 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] | 5997 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5998 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5999 | |
| 6000 | // If the component type is not null (i.e. the object is indeed |
| 6001 | // an array), jump to label `check_non_primitive_component_type` |
| 6002 | // to further check that this component type is not a primitive |
| 6003 | // type. |
| 6004 | __ CompareAndBranchIfNonZero(temp, &check_non_primitive_component_type); |
| 6005 | // Otherwise, jump to the slow path to throw the exception. |
| 6006 | // |
| 6007 | // But before, move back the object's class into `temp` before |
| 6008 | // going into the slow path, as it has been overwritten in the |
| 6009 | // meantime. |
| 6010 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6011 | GenerateReferenceLoadTwoRegisters( |
| 6012 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6013 | __ b(type_check_slow_path->GetEntryLabel()); |
| 6014 | |
| 6015 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6016 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6017 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
| 6018 | __ CompareAndBranchIfZero(temp, &done); |
| 6019 | // Same comment as above regarding `temp` and the slow path. |
| 6020 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6021 | GenerateReferenceLoadTwoRegisters( |
| 6022 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6023 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6024 | break; |
| 6025 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6026 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6027 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6028 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6029 | // We always go into the type check slow path for the unresolved |
| 6030 | // and interface check cases. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6031 | // |
| 6032 | // We cannot directly call the CheckCast runtime entry point |
| 6033 | // without resorting to a type checking slow path here (i.e. by |
| 6034 | // calling InvokeRuntime directly), as it would require to |
| 6035 | // assign fixed registers for the inputs of this HInstanceOf |
| 6036 | // instruction (following the runtime calling convention), which |
| 6037 | // might be cluttered by the potential first read barrier |
| 6038 | // emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6039 | // |
| 6040 | // TODO: Introduce a new runtime entry point taking the object |
| 6041 | // to test (instead of its class) as argument, and let it deal |
| 6042 | // with the read barrier issues. This will let us refactor this |
| 6043 | // case of the `switch` code as it was previously (with a direct |
| 6044 | // call to the runtime not using a type checking slow path). |
| 6045 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6046 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6047 | break; |
| 6048 | } |
| 6049 | __ Bind(&done); |
| 6050 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6051 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6052 | } |
| 6053 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6054 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6055 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6056 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6057 | InvokeRuntimeCallingConvention calling_convention; |
| 6058 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6059 | } |
| 6060 | |
| 6061 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 6062 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 6063 | instruction, |
| 6064 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6065 | if (instruction->IsEnter()) { |
| 6066 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6067 | } else { |
| 6068 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6069 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6070 | } |
| 6071 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6072 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 6073 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 6074 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6075 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6076 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6077 | LocationSummary* locations = |
| 6078 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6079 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6080 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6081 | // 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] | 6082 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6083 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 6084 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6085 | } |
| 6086 | |
| 6087 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 6088 | HandleBitwiseOperation(instruction); |
| 6089 | } |
| 6090 | |
| 6091 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 6092 | HandleBitwiseOperation(instruction); |
| 6093 | } |
| 6094 | |
| 6095 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 6096 | HandleBitwiseOperation(instruction); |
| 6097 | } |
| 6098 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 6099 | |
| 6100 | void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6101 | LocationSummary* locations = |
| 6102 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6103 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6104 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6105 | |
| 6106 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6107 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6108 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6109 | } |
| 6110 | |
| 6111 | void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6112 | LocationSummary* locations = instruction->GetLocations(); |
| 6113 | Location first = locations->InAt(0); |
| 6114 | Location second = locations->InAt(1); |
| 6115 | Location out = locations->Out(); |
| 6116 | |
| 6117 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6118 | Register first_reg = first.AsRegister<Register>(); |
| 6119 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 6120 | Register out_reg = out.AsRegister<Register>(); |
| 6121 | |
| 6122 | switch (instruction->GetOpKind()) { |
| 6123 | case HInstruction::kAnd: |
| 6124 | __ bic(out_reg, first_reg, second_reg); |
| 6125 | break; |
| 6126 | case HInstruction::kOr: |
| 6127 | __ orn(out_reg, first_reg, second_reg); |
| 6128 | break; |
| 6129 | // There is no EON on arm. |
| 6130 | case HInstruction::kXor: |
| 6131 | default: |
| 6132 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6133 | UNREACHABLE(); |
| 6134 | } |
| 6135 | return; |
| 6136 | |
| 6137 | } else { |
| 6138 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6139 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6140 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6141 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 6142 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 6143 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6144 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6145 | |
| 6146 | switch (instruction->GetOpKind()) { |
| 6147 | case HInstruction::kAnd: |
| 6148 | __ bic(out_low, first_low, second_low); |
| 6149 | __ bic(out_high, first_high, second_high); |
| 6150 | break; |
| 6151 | case HInstruction::kOr: |
| 6152 | __ orn(out_low, first_low, second_low); |
| 6153 | __ orn(out_high, first_high, second_high); |
| 6154 | break; |
| 6155 | // There is no EON on arm. |
| 6156 | case HInstruction::kXor: |
| 6157 | default: |
| 6158 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6159 | UNREACHABLE(); |
| 6160 | } |
| 6161 | } |
| 6162 | } |
| 6163 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6164 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 6165 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 6166 | if (value == 0xffffffffu) { |
| 6167 | if (out != first) { |
| 6168 | __ mov(out, ShifterOperand(first)); |
| 6169 | } |
| 6170 | return; |
| 6171 | } |
| 6172 | if (value == 0u) { |
| 6173 | __ mov(out, ShifterOperand(0)); |
| 6174 | return; |
| 6175 | } |
| 6176 | ShifterOperand so; |
| 6177 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 6178 | __ and_(out, first, so); |
| 6179 | } else { |
| 6180 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)); |
| 6181 | __ bic(out, first, ShifterOperand(~value)); |
| 6182 | } |
| 6183 | } |
| 6184 | |
| 6185 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 6186 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 6187 | if (value == 0u) { |
| 6188 | if (out != first) { |
| 6189 | __ mov(out, ShifterOperand(first)); |
| 6190 | } |
| 6191 | return; |
| 6192 | } |
| 6193 | if (value == 0xffffffffu) { |
| 6194 | __ mvn(out, ShifterOperand(0)); |
| 6195 | return; |
| 6196 | } |
| 6197 | ShifterOperand so; |
| 6198 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 6199 | __ orr(out, first, so); |
| 6200 | } else { |
| 6201 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 6202 | __ orn(out, first, ShifterOperand(~value)); |
| 6203 | } |
| 6204 | } |
| 6205 | |
| 6206 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 6207 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 6208 | if (value == 0u) { |
| 6209 | if (out != first) { |
| 6210 | __ mov(out, ShifterOperand(first)); |
| 6211 | } |
| 6212 | return; |
| 6213 | } |
| 6214 | __ eor(out, first, ShifterOperand(value)); |
| 6215 | } |
| 6216 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 6217 | void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out, |
| 6218 | Location first, |
| 6219 | uint64_t value) { |
| 6220 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6221 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6222 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6223 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6224 | uint32_t value_low = Low32Bits(value); |
| 6225 | uint32_t value_high = High32Bits(value); |
| 6226 | if (value_low == 0u) { |
| 6227 | if (out_low != first_low) { |
| 6228 | __ mov(out_low, ShifterOperand(first_low)); |
| 6229 | } |
| 6230 | __ AddConstant(out_high, first_high, value_high); |
| 6231 | return; |
| 6232 | } |
| 6233 | __ AddConstantSetFlags(out_low, first_low, value_low); |
| 6234 | ShifterOperand so; |
| 6235 | if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) { |
| 6236 | __ adc(out_high, first_high, so); |
| 6237 | } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) { |
| 6238 | __ sbc(out_high, first_high, so); |
| 6239 | } else { |
| 6240 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 6241 | UNREACHABLE(); |
| 6242 | } |
| 6243 | } |
| 6244 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6245 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6246 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6247 | Location first = locations->InAt(0); |
| 6248 | Location second = locations->InAt(1); |
| 6249 | Location out = locations->Out(); |
| 6250 | |
| 6251 | if (second.IsConstant()) { |
| 6252 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 6253 | uint32_t value_low = Low32Bits(value); |
| 6254 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6255 | Register first_reg = first.AsRegister<Register>(); |
| 6256 | Register out_reg = out.AsRegister<Register>(); |
| 6257 | if (instruction->IsAnd()) { |
| 6258 | GenerateAndConst(out_reg, first_reg, value_low); |
| 6259 | } else if (instruction->IsOr()) { |
| 6260 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 6261 | } else { |
| 6262 | DCHECK(instruction->IsXor()); |
| 6263 | GenerateEorConst(out_reg, first_reg, value_low); |
| 6264 | } |
| 6265 | } else { |
| 6266 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6267 | uint32_t value_high = High32Bits(value); |
| 6268 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6269 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6270 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6271 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6272 | if (instruction->IsAnd()) { |
| 6273 | GenerateAndConst(out_low, first_low, value_low); |
| 6274 | GenerateAndConst(out_high, first_high, value_high); |
| 6275 | } else if (instruction->IsOr()) { |
| 6276 | GenerateOrrConst(out_low, first_low, value_low); |
| 6277 | GenerateOrrConst(out_high, first_high, value_high); |
| 6278 | } else { |
| 6279 | DCHECK(instruction->IsXor()); |
| 6280 | GenerateEorConst(out_low, first_low, value_low); |
| 6281 | GenerateEorConst(out_high, first_high, value_high); |
| 6282 | } |
| 6283 | } |
| 6284 | return; |
| 6285 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6286 | |
| 6287 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6288 | Register first_reg = first.AsRegister<Register>(); |
| 6289 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 6290 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6291 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6292 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6293 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6294 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6295 | } else { |
| 6296 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6297 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6298 | } |
| 6299 | } else { |
| 6300 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6301 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6302 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6303 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 6304 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 6305 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6306 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6307 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6308 | __ and_(out_low, first_low, second_low); |
| 6309 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6310 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6311 | __ orr(out_low, first_low, second_low); |
| 6312 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6313 | } else { |
| 6314 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6315 | __ eor(out_low, first_low, second_low); |
| 6316 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6317 | } |
| 6318 | } |
| 6319 | } |
| 6320 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6321 | void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6322 | Location out, |
| 6323 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6324 | Location maybe_temp) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6325 | Register out_reg = out.AsRegister<Register>(); |
| 6326 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6327 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6328 | if (kUseBakerReadBarrier) { |
| 6329 | // Load with fast path based Baker's read barrier. |
| 6330 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6331 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6332 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6333 | } else { |
| 6334 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6335 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6336 | // in the following move operation, as we will need it for the |
| 6337 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6338 | __ Mov(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6339 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6340 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6341 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6342 | } |
| 6343 | } else { |
| 6344 | // Plain load with no read barrier. |
| 6345 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6346 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6347 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6348 | } |
| 6349 | } |
| 6350 | |
| 6351 | void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6352 | Location out, |
| 6353 | Location obj, |
| 6354 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6355 | Location maybe_temp) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6356 | Register out_reg = out.AsRegister<Register>(); |
| 6357 | Register obj_reg = obj.AsRegister<Register>(); |
| 6358 | if (kEmitCompilerReadBarrier) { |
| 6359 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6360 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6361 | // Load with fast path based Baker's read barrier. |
| 6362 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6363 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6364 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6365 | } else { |
| 6366 | // Load with slow path based read barrier. |
| 6367 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6368 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6369 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6370 | } |
| 6371 | } else { |
| 6372 | // Plain load with no read barrier. |
| 6373 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6374 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6375 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6376 | } |
| 6377 | } |
| 6378 | |
| 6379 | void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6380 | Location root, |
| 6381 | Register obj, |
| 6382 | uint32_t offset) { |
| 6383 | Register root_reg = root.AsRegister<Register>(); |
| 6384 | if (kEmitCompilerReadBarrier) { |
| 6385 | if (kUseBakerReadBarrier) { |
| 6386 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6387 | // Baker's read barrier are used: |
| 6388 | // |
| 6389 | // root = obj.field; |
| 6390 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6391 | // root = ReadBarrier::Mark(root) |
| 6392 | // } |
| 6393 | |
| 6394 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6395 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6396 | static_assert( |
| 6397 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6398 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6399 | "have different sizes."); |
| 6400 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6401 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6402 | "have different sizes."); |
| 6403 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6404 | // Slow path marking the GC root `root`. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6405 | SlowPathCode* slow_path = |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 6406 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, root); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6407 | codegen_->AddSlowPath(slow_path); |
| 6408 | |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6409 | // IP = Thread::Current()->GetIsGcMarking() |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6410 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6411 | kLoadWord, IP, TR, Thread::IsGcMarkingOffset<kArmPointerSize>().Int32Value()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6412 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
| 6413 | __ Bind(slow_path->GetExitLabel()); |
| 6414 | } else { |
| 6415 | // GC root loaded through a slow path for read barriers other |
| 6416 | // than Baker's. |
| 6417 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6418 | __ AddConstant(root_reg, obj, offset); |
| 6419 | // /* mirror::Object* */ root = root->Read() |
| 6420 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6421 | } |
| 6422 | } else { |
| 6423 | // Plain GC root load with no read barrier. |
| 6424 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6425 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6426 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6427 | // do not have to unpoison `root_reg` here. |
| 6428 | } |
| 6429 | } |
| 6430 | |
| 6431 | void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6432 | Location ref, |
| 6433 | Register obj, |
| 6434 | uint32_t offset, |
| 6435 | Location temp, |
| 6436 | bool needs_null_check) { |
| 6437 | DCHECK(kEmitCompilerReadBarrier); |
| 6438 | DCHECK(kUseBakerReadBarrier); |
| 6439 | |
| 6440 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6441 | Location no_index = Location::NoLocation(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6442 | ScaleFactor no_scale_factor = TIMES_1; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6443 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6444 | 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] | 6445 | } |
| 6446 | |
| 6447 | void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6448 | Location ref, |
| 6449 | Register obj, |
| 6450 | uint32_t data_offset, |
| 6451 | Location index, |
| 6452 | Location temp, |
| 6453 | bool needs_null_check) { |
| 6454 | DCHECK(kEmitCompilerReadBarrier); |
| 6455 | DCHECK(kUseBakerReadBarrier); |
| 6456 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6457 | static_assert( |
| 6458 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6459 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6460 | // /* HeapReference<Object> */ ref = |
| 6461 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6462 | ScaleFactor scale_factor = TIMES_4; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6463 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6464 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6465 | } |
| 6466 | |
| 6467 | void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6468 | Location ref, |
| 6469 | Register obj, |
| 6470 | uint32_t offset, |
| 6471 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6472 | ScaleFactor scale_factor, |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6473 | Location temp, |
| 6474 | bool needs_null_check) { |
| 6475 | DCHECK(kEmitCompilerReadBarrier); |
| 6476 | DCHECK(kUseBakerReadBarrier); |
| 6477 | |
| 6478 | // In slow path based read barriers, the read barrier call is |
| 6479 | // inserted after the original load. However, in fast path based |
| 6480 | // Baker's read barriers, we need to perform the load of |
| 6481 | // mirror::Object::monitor_ *before* the original reference load. |
| 6482 | // This load-load ordering is required by the read barrier. |
| 6483 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6484 | // |
| 6485 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6486 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6487 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6488 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6489 | // if (is_gray) { |
| 6490 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6491 | // } |
| 6492 | // |
| 6493 | // Note: the original implementation in ReadBarrier::Barrier is |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6494 | // slightly more complex as it performs additional checks that we do |
| 6495 | // not do here for performance reasons. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6496 | |
| 6497 | Register ref_reg = ref.AsRegister<Register>(); |
| 6498 | Register temp_reg = temp.AsRegister<Register>(); |
| 6499 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6500 | |
| 6501 | // /* int32_t */ monitor = obj->monitor_ |
| 6502 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 6503 | if (needs_null_check) { |
| 6504 | MaybeRecordImplicitNullCheck(instruction); |
| 6505 | } |
| 6506 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6507 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6508 | "art::LockWord and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6509 | |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 6510 | // Introduce a dependency on the lock_word including the rb_state, |
| 6511 | // which shall prevent load-load reordering without using |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6512 | // a memory barrier (which would be more expensive). |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 6513 | // `obj` is unchanged by this operation, but its value now depends |
| 6514 | // on `temp_reg`. |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 6515 | __ add(obj, obj, ShifterOperand(temp_reg, LSR, 32)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6516 | |
| 6517 | // The actual reference load. |
| 6518 | if (index.IsValid()) { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6519 | // Load types involving an "index": ArrayGet and |
| 6520 | // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 6521 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6522 | if (index.IsConstant()) { |
| 6523 | size_t computed_offset = |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6524 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6525 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 6526 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6527 | // Handle the special case of the |
| 6528 | // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics, which use |
| 6529 | // a register pair as index ("long offset"), of which only the low |
| 6530 | // part contains data. |
| 6531 | Register index_reg = index.IsRegisterPair() |
| 6532 | ? index.AsRegisterPairLow<Register>() |
| 6533 | : index.AsRegister<Register>(); |
| 6534 | __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6535 | __ LoadFromOffset(kLoadWord, ref_reg, IP, offset); |
| 6536 | } |
| 6537 | } else { |
| 6538 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6539 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 6540 | } |
| 6541 | |
| 6542 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6543 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6544 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6545 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6546 | SlowPathCode* slow_path = |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 6547 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, ref); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6548 | AddSlowPath(slow_path); |
| 6549 | |
| 6550 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6551 | // ref = ReadBarrier::Mark(ref); |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 6552 | // Given the numeric representation, it's enough to check the low bit of the |
| 6553 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 6554 | // which can be a 16-bit instruction unlike the TST immediate. |
| 6555 | static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0"); |
| 6556 | static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1"); |
| 6557 | static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2"); |
| 6558 | __ Lsrs(temp_reg, temp_reg, LockWord::kReadBarrierStateShift + 1); |
| 6559 | __ 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] | 6560 | __ Bind(slow_path->GetExitLabel()); |
| 6561 | } |
| 6562 | |
| 6563 | void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6564 | Location out, |
| 6565 | Location ref, |
| 6566 | Location obj, |
| 6567 | uint32_t offset, |
| 6568 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6569 | DCHECK(kEmitCompilerReadBarrier); |
| 6570 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6571 | // Insert a slow path based read barrier *after* the reference load. |
| 6572 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6573 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6574 | // reference will be carried out by the runtime within the slow |
| 6575 | // path. |
| 6576 | // |
| 6577 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6578 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6579 | // not used by the artReadBarrierSlow entry point. |
| 6580 | // |
| 6581 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6582 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6583 | ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index); |
| 6584 | AddSlowPath(slow_path); |
| 6585 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6586 | __ b(slow_path->GetEntryLabel()); |
| 6587 | __ Bind(slow_path->GetExitLabel()); |
| 6588 | } |
| 6589 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6590 | void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6591 | Location out, |
| 6592 | Location ref, |
| 6593 | Location obj, |
| 6594 | uint32_t offset, |
| 6595 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6596 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6597 | // Baker's read barriers shall be handled by the fast path |
| 6598 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
| 6599 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6600 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6601 | // by the runtime within the slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6602 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6603 | } else if (kPoisonHeapReferences) { |
| 6604 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6605 | } |
| 6606 | } |
| 6607 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6608 | void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6609 | Location out, |
| 6610 | Location root) { |
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 GC root load. |
| 6614 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6615 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6616 | // not need to do anything special for this here. |
| 6617 | SlowPathCode* slow_path = |
| 6618 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root); |
| 6619 | AddSlowPath(slow_path); |
| 6620 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6621 | __ b(slow_path->GetEntryLabel()); |
| 6622 | __ Bind(slow_path->GetExitLabel()); |
| 6623 | } |
| 6624 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6625 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 6626 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 6627 | MethodReference target_method) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6628 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 6629 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 6630 | // is incompatible with it. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6631 | // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods |
| 6632 | // with irreducible loops. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6633 | if (GetGraph()->HasIrreducibleLoops() && |
| 6634 | (dispatch_info.method_load_kind == |
| 6635 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 6636 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 6637 | } |
| 6638 | |
| 6639 | if (dispatch_info.code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6640 | const DexFile& outer_dex_file = GetGraph()->GetDexFile(); |
| 6641 | if (&outer_dex_file != target_method.dex_file) { |
| 6642 | // Calls across dex files are more likely to exceed the available BL range, |
| 6643 | // so use absolute patch with fixup if available and kCallArtMethod otherwise. |
| 6644 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = |
| 6645 | (desired_dispatch_info.method_load_kind == |
| 6646 | HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) |
| 6647 | ? HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup |
| 6648 | : HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod; |
| 6649 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6650 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6651 | code_ptr_location, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6652 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6653 | 0u |
| 6654 | }; |
| 6655 | } |
| 6656 | } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6657 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6658 | } |
| 6659 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6660 | Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 6661 | Register temp) { |
| 6662 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 6663 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 6664 | if (!invoke->GetLocations()->Intrinsified()) { |
| 6665 | return location.AsRegister<Register>(); |
| 6666 | } |
| 6667 | // For intrinsics we allow any location, so it may be on the stack. |
| 6668 | if (!location.IsRegister()) { |
| 6669 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 6670 | return temp; |
| 6671 | } |
| 6672 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 6673 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 6674 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 6675 | // simple and more robust approach rather that trying to determine if that's the case. |
| 6676 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 6677 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 6678 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 6679 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 6680 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 6681 | return temp; |
| 6682 | } |
| 6683 | return location.AsRegister<Register>(); |
| 6684 | } |
| 6685 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 6686 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6687 | // 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] | 6688 | switch (invoke->GetCodePtrLocation()) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6689 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 6690 | // LR = code address from literal pool with link-time patch. |
| 6691 | __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6692 | break; |
| 6693 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 6694 | // LR = invoke->GetDirectCodePtr(); |
| 6695 | __ LoadImmediate(LR, invoke->GetDirectCodePtr()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6696 | break; |
| 6697 | default: |
| 6698 | break; |
| 6699 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6700 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6701 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 6702 | switch (invoke->GetMethodLoadKind()) { |
| 6703 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 6704 | // temp = thread->string_init_entrypoint |
| 6705 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, invoke->GetStringInitOffset()); |
| 6706 | break; |
| 6707 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 6708 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6709 | break; |
| 6710 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 6711 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 6712 | break; |
| 6713 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 6714 | __ LoadLiteral(temp.AsRegister<Register>(), |
| 6715 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 6716 | break; |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6717 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 6718 | HArmDexCacheArraysBase* base = |
| 6719 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 6720 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 6721 | temp.AsRegister<Register>()); |
| 6722 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 6723 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 6724 | break; |
| 6725 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6726 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 6727 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6728 | Register method_reg; |
| 6729 | Register reg = temp.AsRegister<Register>(); |
| 6730 | if (current_method.IsRegister()) { |
| 6731 | method_reg = current_method.AsRegister<Register>(); |
| 6732 | } else { |
| 6733 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 6734 | DCHECK(!current_method.IsValid()); |
| 6735 | method_reg = reg; |
| 6736 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 6737 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6738 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 6739 | __ LoadFromOffset(kLoadWord, |
| 6740 | reg, |
| 6741 | method_reg, |
| 6742 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 6743 | // temp = temp[index_in_cache]; |
| 6744 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 6745 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6746 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 6747 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 6748 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6749 | } |
| 6750 | |
| 6751 | switch (invoke->GetCodePtrLocation()) { |
| 6752 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 6753 | __ bl(GetFrameEntryLabel()); |
| 6754 | break; |
| 6755 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6756 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6757 | __ BindTrackedLabel(&relative_call_patches_.back().label); |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6758 | // Arbitrarily branch to the BL itself, override at link time. |
| 6759 | __ bl(&relative_call_patches_.back().label); |
| 6760 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6761 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 6762 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 6763 | // LR prepared above for better instruction scheduling. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6764 | // LR() |
| 6765 | __ blx(LR); |
| 6766 | break; |
| 6767 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 6768 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 6769 | __ LoadFromOffset( |
| 6770 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6771 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6772 | // LR() |
| 6773 | __ blx(LR); |
| 6774 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6775 | } |
| 6776 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6777 | DCHECK(!IsLeafMethod()); |
| 6778 | } |
| 6779 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6780 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 6781 | Register temp = temp_location.AsRegister<Register>(); |
| 6782 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 6783 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6784 | |
| 6785 | // Use the calling convention instead of the location of the receiver, as |
| 6786 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 6787 | // slow path, the arguments have been moved to the right place, so here we are |
| 6788 | // guaranteed that the receiver is the first register of the calling convention. |
| 6789 | InvokeDexCallingConvention calling_convention; |
| 6790 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6791 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6792 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6793 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6794 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6795 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 6796 | // emit a read barrier for the previous class reference load. |
| 6797 | // However this is not required in practice, as this is an |
| 6798 | // intermediate/temporary reference and because the current |
| 6799 | // concurrent copying collector keeps the from-space memory |
| 6800 | // intact/accessible until the end of the marking phase (the |
| 6801 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6802 | __ MaybeUnpoisonHeapReference(temp); |
| 6803 | // temp = temp->GetMethodAt(method_offset); |
| 6804 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6805 | kArmPointerSize).Int32Value(); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6806 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 6807 | // LR = temp->GetEntryPoint(); |
| 6808 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 6809 | // LR(); |
| 6810 | __ blx(LR); |
| 6811 | } |
| 6812 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6813 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch( |
| 6814 | const DexFile& dex_file, uint32_t string_index) { |
| 6815 | return NewPcRelativePatch(dex_file, string_index, &pc_relative_string_patches_); |
| 6816 | } |
| 6817 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6818 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch( |
| 6819 | const DexFile& dex_file, uint32_t type_index) { |
| 6820 | return NewPcRelativePatch(dex_file, type_index, &pc_relative_type_patches_); |
| 6821 | } |
| 6822 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6823 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch( |
| 6824 | const DexFile& dex_file, uint32_t element_offset) { |
| 6825 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 6826 | } |
| 6827 | |
| 6828 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch( |
| 6829 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 6830 | patches->emplace_back(dex_file, offset_or_index); |
| 6831 | return &patches->back(); |
| 6832 | } |
| 6833 | |
| 6834 | Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
| 6835 | uint32_t string_index) { |
| 6836 | return boot_image_string_patches_.GetOrCreate( |
| 6837 | StringReference(&dex_file, string_index), |
| 6838 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 6839 | } |
| 6840 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6841 | Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file, |
| 6842 | uint32_t type_index) { |
| 6843 | return boot_image_type_patches_.GetOrCreate( |
| 6844 | TypeReference(&dex_file, type_index), |
| 6845 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 6846 | } |
| 6847 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6848 | Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) { |
| 6849 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 6850 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 6851 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 6852 | } |
| 6853 | |
| 6854 | Literal* CodeGeneratorARM::DeduplicateDexCacheAddressLiteral(uint32_t address) { |
| 6855 | return DeduplicateUint32Literal(address, &uint32_literals_); |
| 6856 | } |
| 6857 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6858 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 6859 | DCHECK(linker_patches->empty()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6860 | size_t size = |
| 6861 | method_patches_.size() + |
| 6862 | call_patches_.size() + |
| 6863 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6864 | /* MOVW+MOVT for each base */ 2u * pc_relative_dex_cache_patches_.size() + |
| 6865 | boot_image_string_patches_.size() + |
| 6866 | /* MOVW+MOVT for each base */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6867 | boot_image_type_patches_.size() + |
| 6868 | /* MOVW+MOVT for each base */ 2u * pc_relative_type_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6869 | boot_image_address_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6870 | linker_patches->reserve(size); |
| 6871 | for (const auto& entry : method_patches_) { |
| 6872 | const MethodReference& target_method = entry.first; |
| 6873 | Literal* literal = entry.second; |
| 6874 | DCHECK(literal->GetLabel()->IsBound()); |
| 6875 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6876 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 6877 | target_method.dex_file, |
| 6878 | target_method.dex_method_index)); |
| 6879 | } |
| 6880 | for (const auto& entry : call_patches_) { |
| 6881 | const MethodReference& target_method = entry.first; |
| 6882 | Literal* literal = entry.second; |
| 6883 | DCHECK(literal->GetLabel()->IsBound()); |
| 6884 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6885 | linker_patches->push_back(LinkerPatch::CodePatch(literal_offset, |
| 6886 | target_method.dex_file, |
| 6887 | target_method.dex_method_index)); |
| 6888 | } |
| 6889 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 6890 | uint32_t literal_offset = info.label.Position(); |
| 6891 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 6892 | info.target_method.dex_file, |
| 6893 | info.target_method.dex_method_index)); |
| 6894 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6895 | for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) { |
| 6896 | const DexFile& dex_file = info.target_dex_file; |
| 6897 | size_t base_element_offset = info.offset_or_index; |
| 6898 | DCHECK(info.add_pc_label.IsBound()); |
| 6899 | 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] | 6900 | // Add MOVW patch. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6901 | DCHECK(info.movw_label.IsBound()); |
| 6902 | 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] | 6903 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movw_offset, |
| 6904 | &dex_file, |
| 6905 | add_pc_offset, |
| 6906 | base_element_offset)); |
| 6907 | // Add MOVT patch. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6908 | DCHECK(info.movt_label.IsBound()); |
| 6909 | 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] | 6910 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movt_offset, |
| 6911 | &dex_file, |
| 6912 | add_pc_offset, |
| 6913 | base_element_offset)); |
| 6914 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6915 | for (const auto& entry : boot_image_string_patches_) { |
| 6916 | const StringReference& target_string = entry.first; |
| 6917 | Literal* literal = entry.second; |
| 6918 | DCHECK(literal->GetLabel()->IsBound()); |
| 6919 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6920 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 6921 | target_string.dex_file, |
| 6922 | target_string.string_index)); |
| 6923 | } |
| 6924 | for (const PcRelativePatchInfo& info : pc_relative_string_patches_) { |
| 6925 | const DexFile& dex_file = info.target_dex_file; |
| 6926 | uint32_t string_index = info.offset_or_index; |
| 6927 | DCHECK(info.add_pc_label.IsBound()); |
| 6928 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 6929 | // Add MOVW patch. |
| 6930 | DCHECK(info.movw_label.IsBound()); |
| 6931 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 6932 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(movw_offset, |
| 6933 | &dex_file, |
| 6934 | add_pc_offset, |
| 6935 | string_index)); |
| 6936 | // Add MOVT patch. |
| 6937 | DCHECK(info.movt_label.IsBound()); |
| 6938 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 6939 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(movt_offset, |
| 6940 | &dex_file, |
| 6941 | add_pc_offset, |
| 6942 | string_index)); |
| 6943 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6944 | for (const auto& entry : boot_image_type_patches_) { |
| 6945 | const TypeReference& target_type = entry.first; |
| 6946 | Literal* literal = entry.second; |
| 6947 | DCHECK(literal->GetLabel()->IsBound()); |
| 6948 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6949 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 6950 | target_type.dex_file, |
| 6951 | target_type.type_index)); |
| 6952 | } |
| 6953 | for (const PcRelativePatchInfo& info : pc_relative_type_patches_) { |
| 6954 | const DexFile& dex_file = info.target_dex_file; |
| 6955 | uint32_t type_index = info.offset_or_index; |
| 6956 | DCHECK(info.add_pc_label.IsBound()); |
| 6957 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 6958 | // Add MOVW patch. |
| 6959 | DCHECK(info.movw_label.IsBound()); |
| 6960 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 6961 | linker_patches->push_back(LinkerPatch::RelativeTypePatch(movw_offset, |
| 6962 | &dex_file, |
| 6963 | add_pc_offset, |
| 6964 | type_index)); |
| 6965 | // Add MOVT patch. |
| 6966 | DCHECK(info.movt_label.IsBound()); |
| 6967 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 6968 | linker_patches->push_back(LinkerPatch::RelativeTypePatch(movt_offset, |
| 6969 | &dex_file, |
| 6970 | add_pc_offset, |
| 6971 | type_index)); |
| 6972 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6973 | for (const auto& entry : boot_image_address_patches_) { |
| 6974 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
| 6975 | Literal* literal = entry.second; |
| 6976 | DCHECK(literal->GetLabel()->IsBound()); |
| 6977 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6978 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 6979 | } |
| 6980 | } |
| 6981 | |
| 6982 | Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 6983 | return map->GetOrCreate( |
| 6984 | value, |
| 6985 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6986 | } |
| 6987 | |
| 6988 | Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method, |
| 6989 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6990 | return map->GetOrCreate( |
| 6991 | target_method, |
| 6992 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6993 | } |
| 6994 | |
| 6995 | Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) { |
| 6996 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 6997 | } |
| 6998 | |
| 6999 | Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) { |
| 7000 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 7001 | } |
| 7002 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 7003 | void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7004 | LocationSummary* locations = |
| 7005 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 7006 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 7007 | Location::RequiresRegister()); |
| 7008 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 7009 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 7010 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7011 | } |
| 7012 | |
| 7013 | void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7014 | LocationSummary* locations = instr->GetLocations(); |
| 7015 | Register res = locations->Out().AsRegister<Register>(); |
| 7016 | Register accumulator = |
| 7017 | locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>(); |
| 7018 | Register mul_left = |
| 7019 | locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>(); |
| 7020 | Register mul_right = |
| 7021 | locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>(); |
| 7022 | |
| 7023 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 7024 | __ mla(res, mul_left, mul_right, accumulator); |
| 7025 | } else { |
| 7026 | __ mls(res, mul_left, mul_right, accumulator); |
| 7027 | } |
| 7028 | } |
| 7029 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7030 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7031 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7032 | LOG(FATAL) << "Unreachable"; |
| 7033 | } |
| 7034 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7035 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7036 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7037 | LOG(FATAL) << "Unreachable"; |
| 7038 | } |
| 7039 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7040 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7041 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7042 | LocationSummary* locations = |
| 7043 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7044 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7045 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7046 | codegen_->GetAssembler()->IsThumb()) { |
| 7047 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 7048 | if (switch_instr->GetStartValue() != 0) { |
| 7049 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 7050 | } |
| 7051 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7052 | } |
| 7053 | |
| 7054 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7055 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7056 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7057 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7058 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7059 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7060 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7061 | if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7062 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7063 | Register temp_reg = IP; |
| 7064 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 7065 | // the immediate, because IP is used as the destination register. For the other |
| 7066 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 7067 | // and they can be encoded in the instruction without making use of IP register. |
| 7068 | __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound); |
| 7069 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7070 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7071 | // Jump to successors[0] if value == lower_bound. |
| 7072 | __ b(codegen_->GetLabelOf(successors[0]), EQ); |
| 7073 | int32_t last_index = 0; |
| 7074 | for (; num_entries - last_index > 2; last_index += 2) { |
| 7075 | __ AddConstantSetFlags(temp_reg, temp_reg, -2); |
| 7076 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 7077 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO); |
| 7078 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 7079 | __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ); |
| 7080 | } |
| 7081 | if (num_entries - last_index == 2) { |
| 7082 | // The last missing case_value. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 7083 | __ CmpConstant(temp_reg, 1); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7084 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7085 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7086 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7087 | // And the default for any other value. |
| 7088 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 7089 | __ b(codegen_->GetLabelOf(default_block)); |
| 7090 | } |
| 7091 | } else { |
| 7092 | // Create a table lookup. |
| 7093 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7094 | |
| 7095 | // Materialize a pointer to the switch table |
| 7096 | std::vector<Label*> labels(num_entries); |
| 7097 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 7098 | for (uint32_t i = 0; i < num_entries; i++) { |
| 7099 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 7100 | } |
| 7101 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 7102 | |
| 7103 | // Remove the bias. |
| 7104 | Register key_reg; |
| 7105 | if (lower_bound != 0) { |
| 7106 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 7107 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 7108 | } else { |
| 7109 | key_reg = value_reg; |
| 7110 | } |
| 7111 | |
| 7112 | // Check whether the value is in the table, jump to default block if not. |
| 7113 | __ CmpConstant(key_reg, num_entries - 1); |
| 7114 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 7115 | |
| 7116 | // Load the displacement from the table. |
| 7117 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 7118 | |
| 7119 | // Dispatch is a direct add to the PC (for Thumb2). |
| 7120 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7121 | } |
| 7122 | } |
| 7123 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7124 | void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7125 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 7126 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7127 | } |
| 7128 | |
| 7129 | void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7130 | Register base_reg = base->GetLocations()->Out().AsRegister<Register>(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7131 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 7132 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7133 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7134 | __ movw(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7135 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7136 | __ movt(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7137 | __ BindTrackedLabel(&labels->add_pc_label); |
| 7138 | __ add(base_reg, base_reg, ShifterOperand(PC)); |
| 7139 | } |
| 7140 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7141 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 7142 | if (!trg.IsValid()) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7143 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7144 | return; |
| 7145 | } |
| 7146 | |
| 7147 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7148 | |
| 7149 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 7150 | if (return_loc.Equals(trg)) { |
| 7151 | return; |
| 7152 | } |
| 7153 | |
| 7154 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7155 | // with the last branch. |
| 7156 | if (type == Primitive::kPrimLong) { |
| 7157 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7158 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 7159 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7160 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7161 | } else if (type == Primitive::kPrimDouble) { |
| 7162 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7163 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 7164 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 7165 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7166 | } else { |
| 7167 | // Let the parallel move resolver take care of all of this. |
| 7168 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7169 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7170 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7171 | } |
| 7172 | } |
| 7173 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7174 | void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 7175 | LocationSummary* locations = |
| 7176 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7177 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7178 | locations->SetOut(Location::RequiresRegister()); |
| 7179 | } |
| 7180 | |
| 7181 | void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 7182 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7183 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7184 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7185 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7186 | __ LoadFromOffset(kLoadWord, |
| 7187 | locations->Out().AsRegister<Register>(), |
| 7188 | locations->InAt(0).AsRegister<Register>(), |
| 7189 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7190 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7191 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 7192 | instruction->GetIndex(), kArmPointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7193 | __ LoadFromOffset(kLoadWord, |
| 7194 | locations->Out().AsRegister<Register>(), |
| 7195 | locations->InAt(0).AsRegister<Register>(), |
| 7196 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 7197 | __ LoadFromOffset(kLoadWord, |
| 7198 | locations->Out().AsRegister<Register>(), |
| 7199 | locations->Out().AsRegister<Register>(), |
| 7200 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7201 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7202 | } |
| 7203 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7204 | #undef __ |
| 7205 | #undef QUICK_ENTRY_POINT |
| 7206 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7207 | } // namespace arm |
| 7208 | } // namespace art |