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" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 23 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 24 | #include "intrinsics.h" |
| 25 | #include "intrinsics_arm.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 26 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 27 | #include "mirror/class-inl.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 28 | #include "thread.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 29 | #include "utils/arm/assembler_arm.h" |
| 30 | #include "utils/arm/managed_register_arm.h" |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 31 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 32 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 33 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 34 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 35 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 36 | namespace arm { |
| 37 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 38 | static bool ExpectedPairLayout(Location location) { |
| 39 | // We expected this for both core and fpu register pairs. |
| 40 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 41 | } |
| 42 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 43 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 44 | static constexpr Register kMethodRegisterArgument = R0; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 45 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 46 | // We unconditionally allocate R5 to ensure we can do long operations |
| 47 | // with baseline. |
| 48 | static constexpr Register kCoreSavedRegisterForBaseline = R5; |
| 49 | static constexpr Register kCoreCalleeSaves[] = |
| 50 | { R5, R6, R7, R8, R10, R11, PC }; |
| 51 | static constexpr SRegister kFpuCalleeSaves[] = |
| 52 | { 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] | 53 | |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 54 | // D31 cannot be split into two S registers, and the register allocator only works on |
| 55 | // S registers. Therefore there is no need to block it. |
| 56 | static constexpr DRegister DTMP = D31; |
| 57 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 58 | #define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 59 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 60 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 61 | class NullCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 62 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 63 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 64 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 65 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 66 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 67 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 68 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 69 | QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 72 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; } |
| 73 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 74 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 75 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 76 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 77 | }; |
| 78 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 79 | class DivZeroCheckSlowPathARM : public SlowPathCodeARM { |
| 80 | public: |
| 81 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 82 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 83 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 84 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 85 | __ Bind(GetEntryLabel()); |
| 86 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 87 | QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 90 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; } |
| 91 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 92 | private: |
| 93 | HDivZeroCheck* const instruction_; |
| 94 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 95 | }; |
| 96 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 97 | class SuspendCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 98 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 99 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 100 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 101 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 102 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 103 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 104 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 105 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 106 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 107 | QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 108 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 109 | if (successor_ == nullptr) { |
| 110 | __ b(GetReturnLabel()); |
| 111 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 112 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 113 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 116 | Label* GetReturnLabel() { |
| 117 | DCHECK(successor_ == nullptr); |
| 118 | return &return_label_; |
| 119 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 120 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 121 | HBasicBlock* GetSuccessor() const { |
| 122 | return successor_; |
| 123 | } |
| 124 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 125 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; } |
| 126 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 127 | private: |
| 128 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 129 | // If not null, the block to branch to after the suspend check. |
| 130 | HBasicBlock* const successor_; |
| 131 | |
| 132 | // 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] | 133 | Label return_label_; |
| 134 | |
| 135 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 136 | }; |
| 137 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 138 | class BoundsCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 139 | public: |
Roland Levillain | 5799fc0 | 2014-09-25 12:15:20 +0100 | [diff] [blame] | 140 | BoundsCheckSlowPathARM(HBoundsCheck* instruction, |
| 141 | Location index_location, |
| 142 | Location length_location) |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 143 | : instruction_(instruction), |
| 144 | index_location_(index_location), |
| 145 | length_location_(length_location) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 146 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 147 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 148 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 149 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 150 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 151 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 152 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 153 | codegen->EmitParallelMoves( |
| 154 | index_location_, |
| 155 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 156 | Primitive::kPrimInt, |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 157 | length_location_, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 158 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 159 | Primitive::kPrimInt); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 160 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 161 | QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 162 | } |
| 163 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 164 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; } |
| 165 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 166 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 167 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 168 | const Location index_location_; |
| 169 | const Location length_location_; |
| 170 | |
| 171 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 172 | }; |
| 173 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 174 | class LoadClassSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 175 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 176 | LoadClassSlowPathARM(HLoadClass* cls, |
| 177 | HInstruction* at, |
| 178 | uint32_t dex_pc, |
| 179 | bool do_clinit) |
| 180 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 181 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 182 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 183 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 184 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 185 | LocationSummary* locations = at_->GetLocations(); |
| 186 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 187 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 188 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 189 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 190 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 191 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 192 | __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 193 | int32_t entry_point_offset = do_clinit_ |
| 194 | ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 195 | : QUICK_ENTRY_POINT(pInitializeType); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 196 | arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 197 | |
| 198 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 199 | Location out = locations->Out(); |
| 200 | if (out.IsValid()) { |
| 201 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 202 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 203 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 204 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 205 | __ b(GetExitLabel()); |
| 206 | } |
| 207 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 208 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; } |
| 209 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 210 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 211 | // The class this slow path will load. |
| 212 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 213 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 214 | // The instruction where this slow path is happening. |
| 215 | // (Might be the load class or an initialization check). |
| 216 | HInstruction* const at_; |
| 217 | |
| 218 | // The dex PC of `at_`. |
| 219 | const uint32_t dex_pc_; |
| 220 | |
| 221 | // Whether to initialize the class. |
| 222 | const bool do_clinit_; |
| 223 | |
| 224 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 225 | }; |
| 226 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 227 | class LoadStringSlowPathARM : public SlowPathCodeARM { |
| 228 | public: |
| 229 | explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {} |
| 230 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 231 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 232 | LocationSummary* locations = instruction_->GetLocations(); |
| 233 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 234 | |
| 235 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 236 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 237 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 238 | |
| 239 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 240 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 241 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 242 | QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 243 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 244 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 245 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 246 | __ b(GetExitLabel()); |
| 247 | } |
| 248 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 249 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; } |
| 250 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 251 | private: |
| 252 | HLoadString* const instruction_; |
| 253 | |
| 254 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 255 | }; |
| 256 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 257 | class TypeCheckSlowPathARM : public SlowPathCodeARM { |
| 258 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 259 | TypeCheckSlowPathARM(HInstruction* instruction, |
| 260 | Location class_to_check, |
| 261 | Location object_class, |
| 262 | uint32_t dex_pc) |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 263 | : instruction_(instruction), |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 264 | class_to_check_(class_to_check), |
| 265 | object_class_(object_class), |
| 266 | dex_pc_(dex_pc) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 267 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 268 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 269 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 270 | DCHECK(instruction_->IsCheckCast() |
| 271 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 272 | |
| 273 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 274 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 275 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 276 | |
| 277 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 278 | // move resolver. |
| 279 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 280 | codegen->EmitParallelMoves( |
| 281 | class_to_check_, |
| 282 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 283 | Primitive::kPrimNot, |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 284 | object_class_, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 285 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 286 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 287 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 288 | if (instruction_->IsInstanceOf()) { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 289 | arm_codegen->InvokeRuntime( |
| 290 | QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_, this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 291 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 292 | } else { |
| 293 | DCHECK(instruction_->IsCheckCast()); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 294 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_, this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 295 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 296 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 297 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 298 | __ b(GetExitLabel()); |
| 299 | } |
| 300 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 301 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; } |
| 302 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 303 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 304 | HInstruction* const instruction_; |
| 305 | const Location class_to_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 306 | const Location object_class_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 307 | uint32_t dex_pc_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 308 | |
| 309 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 310 | }; |
| 311 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 312 | class DeoptimizationSlowPathARM : public SlowPathCodeARM { |
| 313 | public: |
| 314 | explicit DeoptimizationSlowPathARM(HInstruction* instruction) |
| 315 | : instruction_(instruction) {} |
| 316 | |
| 317 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 318 | __ Bind(GetEntryLabel()); |
| 319 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 320 | DCHECK(instruction_->IsDeoptimize()); |
| 321 | HDeoptimize* deoptimize = instruction_->AsDeoptimize(); |
| 322 | uint32_t dex_pc = deoptimize->GetDexPc(); |
| 323 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 324 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this); |
| 325 | } |
| 326 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 327 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; } |
| 328 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 329 | private: |
| 330 | HInstruction* const instruction_; |
| 331 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM); |
| 332 | }; |
| 333 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 334 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 335 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 336 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 337 | inline Condition ARMSignedOrFPCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 338 | switch (cond) { |
| 339 | case kCondEQ: return EQ; |
| 340 | case kCondNE: return NE; |
| 341 | case kCondLT: return LT; |
| 342 | case kCondLE: return LE; |
| 343 | case kCondGT: return GT; |
| 344 | case kCondGE: return GE; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 345 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 346 | LOG(FATAL) << "Unreachable"; |
| 347 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 350 | inline Condition ARMUnsignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 351 | switch (cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 352 | case kCondEQ: return EQ; |
| 353 | case kCondNE: return NE; |
| 354 | case kCondLT: return LO; |
| 355 | case kCondLE: return LS; |
| 356 | case kCondGT: return HI; |
| 357 | case kCondGE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 358 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 359 | LOG(FATAL) << "Unreachable"; |
| 360 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 363 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 364 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 368 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 369 | } |
| 370 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 371 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 372 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 373 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 374 | } |
| 375 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 376 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 377 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 378 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 379 | } |
| 380 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 381 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 382 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 383 | return kArmWordSize; |
| 384 | } |
| 385 | |
| 386 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 387 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 388 | return kArmWordSize; |
| 389 | } |
| 390 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 391 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 392 | const ArmInstructionSetFeatures& isa_features, |
| 393 | const CompilerOptions& compiler_options) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 394 | : CodeGenerator(graph, |
| 395 | kNumberOfCoreRegisters, |
| 396 | kNumberOfSRegisters, |
| 397 | kNumberOfRegisterPairs, |
| 398 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 399 | arraysize(kCoreCalleeSaves)), |
| 400 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 401 | arraysize(kFpuCalleeSaves)), |
| 402 | compiler_options), |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 403 | block_labels_(graph->GetArena(), 0), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 404 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 405 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 406 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 407 | assembler_(), |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 408 | isa_features_(isa_features) { |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 409 | // Save the PC register to mimic Quick. |
| 410 | AddAllocatedRegister(Location::RegisterLocation(PC)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 411 | } |
| 412 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 413 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 414 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 415 | __ FinalizeCode(); |
| 416 | |
| 417 | // Adjust native pc offsets in stack maps. |
| 418 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
| 419 | uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset; |
| 420 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 421 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 422 | } |
| 423 | // Adjust native pc offsets of block labels. |
| 424 | for (size_t block_idx = 0u, end = block_order_->Size(); block_idx != end; ++block_idx) { |
| 425 | HBasicBlock* block = block_order_->Get(block_idx); |
| 426 | // Get the label directly from block_labels_ rather than through GetLabelOf() to avoid |
| 427 | // FirstNonEmptyBlock() which could lead to adjusting a label more than once. |
| 428 | DCHECK_LT(static_cast<size_t>(block->GetBlockId()), block_labels_.Size()); |
| 429 | Label* block_label = &block_labels_.GetRawStorage()[block->GetBlockId()]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 430 | DCHECK_EQ(block_label->IsBound(), !block->IsSingleJump()); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 431 | if (block_label->IsBound()) { |
| 432 | __ AdjustLabelPosition(block_label); |
| 433 | } |
| 434 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 435 | // Adjust pc offsets for the disassembly information. |
| 436 | if (disasm_info_ != nullptr) { |
| 437 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 438 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 439 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 440 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 441 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 442 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 443 | } |
| 444 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 445 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 446 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 447 | } |
| 448 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 449 | |
| 450 | CodeGenerator::Finalize(allocator); |
| 451 | } |
| 452 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 453 | Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 454 | switch (type) { |
| 455 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 456 | size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 457 | ArmManagedRegister pair = |
| 458 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 459 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); |
| 460 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); |
| 461 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 462 | blocked_core_registers_[pair.AsRegisterPairLow()] = true; |
| 463 | blocked_core_registers_[pair.AsRegisterPairHigh()] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 464 | UpdateBlockedPairRegisters(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 465 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | case Primitive::kPrimByte: |
| 469 | case Primitive::kPrimBoolean: |
| 470 | case Primitive::kPrimChar: |
| 471 | case Primitive::kPrimShort: |
| 472 | case Primitive::kPrimInt: |
| 473 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 474 | int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 475 | // Block all register pairs that contain `reg`. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 476 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 477 | ArmManagedRegister current = |
| 478 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 479 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 480 | blocked_register_pairs_[i] = true; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 481 | } |
| 482 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 483 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 484 | } |
| 485 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 486 | case Primitive::kPrimFloat: { |
| 487 | int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 488 | return Location::FpuRegisterLocation(reg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 489 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 490 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 491 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 3c03503 | 2014-10-28 10:46:40 +0000 | [diff] [blame] | 492 | int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters); |
| 493 | DCHECK_EQ(reg % 2, 0); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 494 | return Location::FpuRegisterPairLocation(reg, reg + 1); |
| 495 | } |
| 496 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 497 | case Primitive::kPrimVoid: |
| 498 | LOG(FATAL) << "Unreachable type " << type; |
| 499 | } |
| 500 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 501 | return Location(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 502 | } |
| 503 | |
Nicolas Geoffray | a0bb2bd | 2015-01-26 12:49:35 +0000 | [diff] [blame] | 504 | void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 505 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 506 | blocked_register_pairs_[R1_R2] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 507 | |
| 508 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 509 | blocked_core_registers_[SP] = true; |
| 510 | blocked_core_registers_[LR] = true; |
| 511 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 512 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 513 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 514 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 515 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 516 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 517 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 518 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 519 | if (is_baseline) { |
| 520 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 521 | blocked_core_registers_[kCoreCalleeSaves[i]] = true; |
| 522 | } |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 523 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 524 | blocked_core_registers_[kCoreSavedRegisterForBaseline] = false; |
| 525 | |
| 526 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 527 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 528 | } |
| 529 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 530 | |
| 531 | UpdateBlockedPairRegisters(); |
| 532 | } |
| 533 | |
| 534 | void CodeGeneratorARM::UpdateBlockedPairRegisters() const { |
| 535 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 536 | ArmManagedRegister current = |
| 537 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 538 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 539 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 540 | blocked_register_pairs_[i] = true; |
| 541 | } |
| 542 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 543 | } |
| 544 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 545 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
| 546 | : HGraphVisitor(graph), |
| 547 | assembler_(codegen->GetAssembler()), |
| 548 | codegen_(codegen) {} |
| 549 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 550 | void CodeGeneratorARM::ComputeSpillMask() { |
| 551 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 552 | // Save one extra register for baseline. Note that on thumb2, there is no easy |
| 553 | // instruction to restore just the PC, so this actually helps both baseline |
| 554 | // and non-baseline to save and restore at least two registers at entry and exit. |
| 555 | core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 556 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 557 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 558 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 559 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 560 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 561 | // but in the range. |
| 562 | if (fpu_spill_mask_ != 0) { |
| 563 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 564 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 565 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 566 | fpu_spill_mask_ |= (1 << i); |
| 567 | } |
| 568 | } |
| 569 | } |
| 570 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 571 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 572 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 576 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 577 | } |
| 578 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 579 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 580 | bool skip_overflow_check = |
| 581 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 582 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 583 | __ Bind(&frame_entry_label_); |
| 584 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 585 | if (HasEmptyFrame()) { |
| 586 | return; |
| 587 | } |
| 588 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 589 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 590 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 591 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 592 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 593 | } |
| 594 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 595 | // PC is in the list of callee-save to mimic Quick, but we need to push |
| 596 | // LR at entry instead. |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 597 | uint32_t push_mask = (core_spill_mask_ & (~(1 << PC))) | 1 << LR; |
| 598 | __ PushList(push_mask); |
| 599 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(push_mask)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 600 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, push_mask, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 601 | if (fpu_spill_mask_ != 0) { |
| 602 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 603 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 604 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 605 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 606 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 607 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 608 | __ AddConstant(SP, -adjust); |
| 609 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 610 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 614 | if (HasEmptyFrame()) { |
| 615 | __ bx(LR); |
| 616 | return; |
| 617 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 618 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 619 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 620 | __ AddConstant(SP, adjust); |
| 621 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 622 | if (fpu_spill_mask_ != 0) { |
| 623 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 624 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 625 | __ cfi().AdjustCFAOffset(-kArmPointerSize * POPCOUNT(fpu_spill_mask_)); |
| 626 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 627 | } |
| 628 | __ PopList(core_spill_mask_); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 629 | __ cfi().RestoreState(); |
| 630 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 631 | } |
| 632 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 633 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
| 634 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 635 | } |
| 636 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 637 | Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const { |
| 638 | switch (load->GetType()) { |
| 639 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 640 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 641 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 642 | |
| 643 | case Primitive::kPrimInt: |
| 644 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 645 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 646 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 647 | |
| 648 | case Primitive::kPrimBoolean: |
| 649 | case Primitive::kPrimByte: |
| 650 | case Primitive::kPrimChar: |
| 651 | case Primitive::kPrimShort: |
| 652 | case Primitive::kPrimVoid: |
| 653 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 654 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 658 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 659 | } |
| 660 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 661 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 662 | switch (type) { |
| 663 | case Primitive::kPrimBoolean: |
| 664 | case Primitive::kPrimByte: |
| 665 | case Primitive::kPrimChar: |
| 666 | case Primitive::kPrimShort: |
| 667 | case Primitive::kPrimInt: |
| 668 | case Primitive::kPrimNot: { |
| 669 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 670 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 671 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 672 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 673 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 674 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 675 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 676 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 677 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 678 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 679 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 680 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 681 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 682 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 683 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 684 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 685 | // Skip R1, and use R2_R3 instead. |
| 686 | gp_index_++; |
| 687 | index++; |
| 688 | } |
| 689 | } |
| 690 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 691 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 692 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 693 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 694 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 695 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 696 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | case Primitive::kPrimFloat: { |
| 701 | uint32_t stack_index = stack_index_++; |
| 702 | if (float_index_ % 2 == 0) { |
| 703 | float_index_ = std::max(double_index_, float_index_); |
| 704 | } |
| 705 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 706 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 707 | } else { |
| 708 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | case Primitive::kPrimDouble: { |
| 713 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 714 | uint32_t stack_index = stack_index_; |
| 715 | stack_index_ += 2; |
| 716 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 717 | uint32_t index = double_index_; |
| 718 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 719 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 720 | calling_convention.GetFpuRegisterAt(index), |
| 721 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 722 | DCHECK(ExpectedPairLayout(result)); |
| 723 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 724 | } else { |
| 725 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 726 | } |
| 727 | } |
| 728 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 729 | case Primitive::kPrimVoid: |
| 730 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 731 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 732 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 733 | return Location(); |
| 734 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 735 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 736 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 737 | switch (type) { |
| 738 | case Primitive::kPrimBoolean: |
| 739 | case Primitive::kPrimByte: |
| 740 | case Primitive::kPrimChar: |
| 741 | case Primitive::kPrimShort: |
| 742 | case Primitive::kPrimInt: |
| 743 | case Primitive::kPrimNot: { |
| 744 | return Location::RegisterLocation(R0); |
| 745 | } |
| 746 | |
| 747 | case Primitive::kPrimFloat: { |
| 748 | return Location::FpuRegisterLocation(S0); |
| 749 | } |
| 750 | |
| 751 | case Primitive::kPrimLong: { |
| 752 | return Location::RegisterPairLocation(R0, R1); |
| 753 | } |
| 754 | |
| 755 | case Primitive::kPrimDouble: { |
| 756 | return Location::FpuRegisterPairLocation(S0, S1); |
| 757 | } |
| 758 | |
| 759 | case Primitive::kPrimVoid: |
| 760 | return Location(); |
| 761 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 762 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 763 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 764 | } |
| 765 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 766 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 767 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 768 | } |
| 769 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 770 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 771 | if (source.Equals(destination)) { |
| 772 | return; |
| 773 | } |
| 774 | if (destination.IsRegister()) { |
| 775 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 776 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 777 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 778 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 779 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 780 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 781 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 782 | } else if (destination.IsFpuRegister()) { |
| 783 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 784 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 785 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 786 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 787 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 788 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 789 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 790 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 791 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 792 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 793 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 794 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 795 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 796 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 797 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 798 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 799 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 800 | } |
| 801 | } |
| 802 | } |
| 803 | |
| 804 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 805 | if (source.Equals(destination)) { |
| 806 | return; |
| 807 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 808 | if (destination.IsRegisterPair()) { |
| 809 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 810 | EmitParallelMoves( |
| 811 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 812 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 813 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 814 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 815 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 816 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 817 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 818 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 819 | } else { |
| 820 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 821 | DCHECK(ExpectedPairLayout(destination)); |
| 822 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 823 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 824 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 825 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 826 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 827 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 828 | SP, |
| 829 | source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 830 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 831 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 832 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 833 | } else { |
| 834 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 835 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 836 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 837 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 838 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 839 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 840 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 841 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 842 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 843 | SP, destination.GetStackIndex()); |
| 844 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 845 | } else if (source.IsFpuRegisterPair()) { |
| 846 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 847 | SP, |
| 848 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 849 | } else { |
| 850 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 851 | EmitParallelMoves( |
| 852 | Location::StackSlot(source.GetStackIndex()), |
| 853 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 854 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 855 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 856 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 857 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 858 | } |
| 859 | } |
| 860 | } |
| 861 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 862 | void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 863 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 864 | if (instruction->IsCurrentMethod()) { |
| 865 | Move32(location, Location::StackSlot(kCurrentMethodStackOffset)); |
| 866 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 867 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 868 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 869 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 870 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 871 | int32_t value = GetInt32ValueOf(const_to_move); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 872 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 873 | __ LoadImmediate(location.AsRegister<Register>(), value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 874 | } else { |
| 875 | DCHECK(location.IsStackSlot()); |
| 876 | __ LoadImmediate(IP, value); |
| 877 | __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); |
| 878 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 879 | } else { |
Nicolas Geoffray | 3747b48 | 2015-01-19 17:17:16 +0000 | [diff] [blame] | 880 | DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName(); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 881 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 882 | if (location.IsRegisterPair()) { |
| 883 | __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 884 | __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value)); |
| 885 | } else { |
| 886 | DCHECK(location.IsDoubleStackSlot()); |
| 887 | __ LoadImmediate(IP, Low32Bits(value)); |
| 888 | __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); |
| 889 | __ LoadImmediate(IP, High32Bits(value)); |
| 890 | __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize)); |
| 891 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 892 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 893 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 894 | uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
| 895 | switch (instruction->GetType()) { |
| 896 | case Primitive::kPrimBoolean: |
| 897 | case Primitive::kPrimByte: |
| 898 | case Primitive::kPrimChar: |
| 899 | case Primitive::kPrimShort: |
| 900 | case Primitive::kPrimInt: |
| 901 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 902 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 903 | Move32(location, Location::StackSlot(stack_slot)); |
| 904 | break; |
| 905 | |
| 906 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 907 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 908 | Move64(location, Location::DoubleStackSlot(stack_slot)); |
| 909 | break; |
| 910 | |
| 911 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 912 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 913 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 914 | } else if (instruction->IsTemporary()) { |
| 915 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 916 | if (temp_location.IsStackSlot()) { |
| 917 | Move32(location, temp_location); |
| 918 | } else { |
| 919 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 920 | Move64(location, temp_location); |
| 921 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 922 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 923 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 924 | switch (instruction->GetType()) { |
| 925 | case Primitive::kPrimBoolean: |
| 926 | case Primitive::kPrimByte: |
| 927 | case Primitive::kPrimChar: |
| 928 | case Primitive::kPrimShort: |
| 929 | case Primitive::kPrimNot: |
| 930 | case Primitive::kPrimInt: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 931 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 932 | Move32(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 933 | break; |
| 934 | |
| 935 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 936 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 937 | Move64(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 938 | break; |
| 939 | |
| 940 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 941 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 942 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 943 | } |
| 944 | } |
| 945 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 946 | void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset, |
| 947 | HInstruction* instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 948 | uint32_t dex_pc, |
| 949 | SlowPathCode* slow_path) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 950 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 951 | __ blx(LR); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 952 | RecordPcInfo(instruction, dex_pc, slow_path); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 953 | DCHECK(instruction->IsSuspendCheck() |
| 954 | || instruction->IsBoundsCheck() |
| 955 | || instruction->IsNullCheck() |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 956 | || instruction->IsDivZeroCheck() |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 957 | || instruction->GetLocations()->CanCall() |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 958 | || !IsLeafMethod()); |
| 959 | } |
| 960 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 961 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 962 | DCHECK(!successor->IsExitBlock()); |
| 963 | |
| 964 | HBasicBlock* block = got->GetBlock(); |
| 965 | HInstruction* previous = got->GetPrevious(); |
| 966 | |
| 967 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 968 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 969 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 970 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 971 | return; |
| 972 | } |
| 973 | |
| 974 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 975 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 976 | } |
| 977 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 978 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 979 | } |
| 980 | } |
| 981 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 982 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 983 | got->SetLocations(nullptr); |
| 984 | } |
| 985 | |
| 986 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 987 | HandleGoto(got, got->GetSuccessor()); |
| 988 | } |
| 989 | |
| 990 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 991 | try_boundary->SetLocations(nullptr); |
| 992 | } |
| 993 | |
| 994 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 995 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 996 | if (!successor->IsExitBlock()) { |
| 997 | HandleGoto(try_boundary, successor); |
| 998 | } |
| 999 | } |
| 1000 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1001 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1002 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1003 | } |
| 1004 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1005 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1006 | UNUSED(exit); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1009 | void InstructionCodeGeneratorARM::GenerateCompareWithImmediate(Register left, int32_t right) { |
| 1010 | ShifterOperand operand; |
| 1011 | if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, right, &operand)) { |
| 1012 | __ cmp(left, operand); |
| 1013 | } else { |
| 1014 | Register temp = IP; |
| 1015 | __ LoadImmediate(temp, right); |
| 1016 | __ cmp(left, ShifterOperand(temp)); |
| 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond, |
| 1021 | Label* true_label, |
| 1022 | Label* false_label) { |
| 1023 | __ vmstat(); // transfer FP status register to ARM APSR. |
| 1024 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1025 | __ b(true_label, VS); // VS for unordered. |
| 1026 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1027 | __ b(false_label, VS); // VS for unordered. |
| 1028 | } |
| 1029 | __ b(true_label, ARMSignedOrFPCondition(cond->GetCondition())); |
| 1030 | } |
| 1031 | |
| 1032 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 1033 | Label* true_label, |
| 1034 | Label* false_label) { |
| 1035 | LocationSummary* locations = cond->GetLocations(); |
| 1036 | Location left = locations->InAt(0); |
| 1037 | Location right = locations->InAt(1); |
| 1038 | IfCondition if_cond = cond->GetCondition(); |
| 1039 | |
| 1040 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1041 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 1042 | IfCondition true_high_cond = if_cond; |
| 1043 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
| 1044 | Condition final_condition = ARMUnsignedCondition(if_cond); |
| 1045 | |
| 1046 | // Set the conditions for the test, remembering that == needs to be |
| 1047 | // decided using the low words. |
| 1048 | switch (if_cond) { |
| 1049 | case kCondEQ: |
| 1050 | case kCondNE: |
| 1051 | // Nothing to do. |
| 1052 | break; |
| 1053 | case kCondLT: |
| 1054 | false_high_cond = kCondGT; |
| 1055 | break; |
| 1056 | case kCondLE: |
| 1057 | true_high_cond = kCondLT; |
| 1058 | break; |
| 1059 | case kCondGT: |
| 1060 | false_high_cond = kCondLT; |
| 1061 | break; |
| 1062 | case kCondGE: |
| 1063 | true_high_cond = kCondGT; |
| 1064 | break; |
| 1065 | } |
| 1066 | if (right.IsConstant()) { |
| 1067 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1068 | int32_t val_low = Low32Bits(value); |
| 1069 | int32_t val_high = High32Bits(value); |
| 1070 | |
| 1071 | GenerateCompareWithImmediate(left_high, val_high); |
| 1072 | if (if_cond == kCondNE) { |
| 1073 | __ b(true_label, ARMSignedOrFPCondition(true_high_cond)); |
| 1074 | } else if (if_cond == kCondEQ) { |
| 1075 | __ b(false_label, ARMSignedOrFPCondition(false_high_cond)); |
| 1076 | } else { |
| 1077 | __ b(true_label, ARMSignedOrFPCondition(true_high_cond)); |
| 1078 | __ b(false_label, ARMSignedOrFPCondition(false_high_cond)); |
| 1079 | } |
| 1080 | // Must be equal high, so compare the lows. |
| 1081 | GenerateCompareWithImmediate(left_low, val_low); |
| 1082 | } else { |
| 1083 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 1084 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 1085 | |
| 1086 | __ cmp(left_high, ShifterOperand(right_high)); |
| 1087 | if (if_cond == kCondNE) { |
| 1088 | __ b(true_label, ARMSignedOrFPCondition(true_high_cond)); |
| 1089 | } else if (if_cond == kCondEQ) { |
| 1090 | __ b(false_label, ARMSignedOrFPCondition(false_high_cond)); |
| 1091 | } else { |
| 1092 | __ b(true_label, ARMSignedOrFPCondition(true_high_cond)); |
| 1093 | __ b(false_label, ARMSignedOrFPCondition(false_high_cond)); |
| 1094 | } |
| 1095 | // Must be equal high, so compare the lows. |
| 1096 | __ cmp(left_low, ShifterOperand(right_low)); |
| 1097 | } |
| 1098 | // The last comparison might be unsigned. |
| 1099 | __ b(true_label, final_condition); |
| 1100 | } |
| 1101 | |
| 1102 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HIf* if_instr, |
| 1103 | HCondition* condition, |
| 1104 | Label* true_target, |
| 1105 | Label* false_target, |
| 1106 | Label* always_true_target) { |
| 1107 | LocationSummary* locations = condition->GetLocations(); |
| 1108 | Location left = locations->InAt(0); |
| 1109 | Location right = locations->InAt(1); |
| 1110 | |
| 1111 | // We don't want true_target as a nullptr. |
| 1112 | if (true_target == nullptr) { |
| 1113 | true_target = always_true_target; |
| 1114 | } |
| 1115 | bool falls_through = (false_target == nullptr); |
| 1116 | |
| 1117 | // FP compares don't like null false_targets. |
| 1118 | if (false_target == nullptr) { |
| 1119 | false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1120 | } |
| 1121 | |
| 1122 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1123 | switch (type) { |
| 1124 | case Primitive::kPrimLong: |
| 1125 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1126 | break; |
| 1127 | case Primitive::kPrimFloat: |
| 1128 | __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>()); |
| 1129 | GenerateFPJumps(condition, true_target, false_target); |
| 1130 | break; |
| 1131 | case Primitive::kPrimDouble: |
| 1132 | __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), |
| 1133 | FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); |
| 1134 | GenerateFPJumps(condition, true_target, false_target); |
| 1135 | break; |
| 1136 | default: |
| 1137 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1138 | } |
| 1139 | |
| 1140 | if (!falls_through) { |
| 1141 | __ b(false_target); |
| 1142 | } |
| 1143 | } |
| 1144 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1145 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
| 1146 | Label* true_target, |
| 1147 | Label* false_target, |
| 1148 | Label* always_true_target) { |
| 1149 | HInstruction* cond = instruction->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1150 | if (cond->IsIntConstant()) { |
| 1151 | // Constant condition, statically compared against 1. |
| 1152 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 1153 | if (cond_value == 1) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1154 | if (always_true_target != nullptr) { |
| 1155 | __ b(always_true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1156 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1157 | return; |
| 1158 | } else { |
| 1159 | DCHECK_EQ(cond_value, 0); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1160 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1161 | } else { |
| 1162 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1163 | // Condition has been materialized, compare the output to 0 |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1164 | DCHECK(instruction->GetLocations()->InAt(0).IsRegister()); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 1165 | __ CompareAndBranchIfNonZero(instruction->GetLocations()->InAt(0).AsRegister<Register>(), |
| 1166 | true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1167 | } else { |
| 1168 | // Condition has not been materialized, use its inputs as the |
| 1169 | // comparison and its condition as the branch condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1170 | Primitive::Type type = |
| 1171 | cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt; |
| 1172 | // Is this a long or FP comparison that has been folded into the HCondition? |
| 1173 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1174 | // Generate the comparison directly. |
| 1175 | GenerateCompareTestAndBranch(instruction->AsIf(), cond->AsCondition(), |
| 1176 | true_target, false_target, always_true_target); |
| 1177 | return; |
| 1178 | } |
| 1179 | |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1180 | LocationSummary* locations = cond->GetLocations(); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1181 | DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0); |
Nicolas Geoffray | 3bcc8ea | 2014-11-28 15:00:02 +0000 | [diff] [blame] | 1182 | Register left = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1183 | Location right = locations->InAt(1); |
| 1184 | if (right.IsRegister()) { |
| 1185 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1186 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1187 | DCHECK(right.IsConstant()); |
| 1188 | GenerateCompareWithImmediate(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1189 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1190 | __ b(true_target, ARMSignedOrFPCondition(cond->AsCondition()->GetCondition())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1191 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1192 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1193 | if (false_target != nullptr) { |
| 1194 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1195 | } |
| 1196 | } |
| 1197 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1198 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
| 1199 | LocationSummary* locations = |
| 1200 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
| 1201 | HInstruction* cond = if_instr->InputAt(0); |
| 1202 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1203 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1204 | } |
| 1205 | } |
| 1206 | |
| 1207 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
| 1208 | Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 1209 | Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1210 | Label* always_true_target = true_target; |
| 1211 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1212 | if_instr->IfTrueSuccessor())) { |
| 1213 | always_true_target = nullptr; |
| 1214 | } |
| 1215 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1216 | if_instr->IfFalseSuccessor())) { |
| 1217 | false_target = nullptr; |
| 1218 | } |
| 1219 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 1220 | } |
| 1221 | |
| 1222 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1223 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1224 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 1225 | HInstruction* cond = deoptimize->InputAt(0); |
| 1226 | DCHECK(cond->IsCondition()); |
| 1227 | if (cond->AsCondition()->NeedsMaterialization()) { |
| 1228 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1229 | } |
| 1230 | } |
| 1231 | |
| 1232 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1233 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) |
| 1234 | DeoptimizationSlowPathARM(deoptimize); |
| 1235 | codegen_->AddSlowPath(slow_path); |
| 1236 | Label* slow_path_entry = slow_path->GetEntryLabel(); |
| 1237 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 1238 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1239 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1240 | void LocationsBuilderARM::VisitCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1241 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1242 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1243 | // Handle the long/FP comparisons made in instruction simplification. |
| 1244 | switch (cond->InputAt(0)->GetType()) { |
| 1245 | case Primitive::kPrimLong: |
| 1246 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1247 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1248 | if (cond->NeedsMaterialization()) { |
| 1249 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 1250 | } |
| 1251 | break; |
| 1252 | |
| 1253 | case Primitive::kPrimFloat: |
| 1254 | case Primitive::kPrimDouble: |
| 1255 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1256 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1257 | if (cond->NeedsMaterialization()) { |
| 1258 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1259 | } |
| 1260 | break; |
| 1261 | |
| 1262 | default: |
| 1263 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1264 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1265 | if (cond->NeedsMaterialization()) { |
| 1266 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1267 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1268 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1269 | } |
| 1270 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1271 | void InstructionCodeGeneratorARM::VisitCondition(HCondition* cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1272 | if (!cond->NeedsMaterialization()) { |
| 1273 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1274 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1275 | |
| 1276 | LocationSummary* locations = cond->GetLocations(); |
| 1277 | Location left = locations->InAt(0); |
| 1278 | Location right = locations->InAt(1); |
| 1279 | Register out = locations->Out().AsRegister<Register>(); |
| 1280 | Label true_label, false_label; |
| 1281 | |
| 1282 | switch (cond->InputAt(0)->GetType()) { |
| 1283 | default: { |
| 1284 | // Integer case. |
| 1285 | if (right.IsRegister()) { |
| 1286 | __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>())); |
| 1287 | } else { |
| 1288 | DCHECK(right.IsConstant()); |
| 1289 | GenerateCompareWithImmediate(left.AsRegister<Register>(), |
| 1290 | CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
| 1291 | } |
| 1292 | __ it(ARMSignedOrFPCondition(cond->GetCondition()), kItElse); |
| 1293 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1), |
| 1294 | ARMSignedOrFPCondition(cond->GetCondition())); |
| 1295 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0), |
| 1296 | ARMSignedOrFPCondition(cond->GetOppositeCondition())); |
| 1297 | return; |
| 1298 | } |
| 1299 | case Primitive::kPrimLong: |
| 1300 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1301 | break; |
| 1302 | case Primitive::kPrimFloat: |
| 1303 | __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>()); |
| 1304 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1305 | break; |
| 1306 | case Primitive::kPrimDouble: |
| 1307 | __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), |
| 1308 | FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); |
| 1309 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1310 | break; |
| 1311 | } |
| 1312 | |
| 1313 | // Convert the jumps into the result. |
| 1314 | Label done_label; |
| 1315 | |
| 1316 | // False case: result = 0. |
| 1317 | __ Bind(&false_label); |
| 1318 | __ LoadImmediate(out, 0); |
| 1319 | __ b(&done_label); |
| 1320 | |
| 1321 | // True case: result = 1. |
| 1322 | __ Bind(&true_label); |
| 1323 | __ LoadImmediate(out, 1); |
| 1324 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
| 1328 | VisitCondition(comp); |
| 1329 | } |
| 1330 | |
| 1331 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
| 1332 | VisitCondition(comp); |
| 1333 | } |
| 1334 | |
| 1335 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
| 1336 | VisitCondition(comp); |
| 1337 | } |
| 1338 | |
| 1339 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
| 1340 | VisitCondition(comp); |
| 1341 | } |
| 1342 | |
| 1343 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
| 1344 | VisitCondition(comp); |
| 1345 | } |
| 1346 | |
| 1347 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
| 1348 | VisitCondition(comp); |
| 1349 | } |
| 1350 | |
| 1351 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1352 | VisitCondition(comp); |
| 1353 | } |
| 1354 | |
| 1355 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1356 | VisitCondition(comp); |
| 1357 | } |
| 1358 | |
| 1359 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
| 1360 | VisitCondition(comp); |
| 1361 | } |
| 1362 | |
| 1363 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
| 1364 | VisitCondition(comp); |
| 1365 | } |
| 1366 | |
| 1367 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1368 | VisitCondition(comp); |
| 1369 | } |
| 1370 | |
| 1371 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1372 | VisitCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1373 | } |
| 1374 | |
| 1375 | void LocationsBuilderARM::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1376 | local->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1377 | } |
| 1378 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1379 | void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) { |
| 1380 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1381 | } |
| 1382 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1383 | void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1384 | load->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1385 | } |
| 1386 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1387 | void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1388 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1389 | UNUSED(load); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1393 | LocationSummary* locations = |
| 1394 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1395 | switch (store->InputAt(1)->GetType()) { |
| 1396 | case Primitive::kPrimBoolean: |
| 1397 | case Primitive::kPrimByte: |
| 1398 | case Primitive::kPrimChar: |
| 1399 | case Primitive::kPrimShort: |
| 1400 | case Primitive::kPrimInt: |
| 1401 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1402 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1403 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1404 | break; |
| 1405 | |
| 1406 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1407 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1408 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1409 | break; |
| 1410 | |
| 1411 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1412 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1413 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1414 | } |
| 1415 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1416 | void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1417 | UNUSED(store); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1421 | LocationSummary* locations = |
| 1422 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1423 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1424 | } |
| 1425 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1426 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1427 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1428 | UNUSED(constant); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1429 | } |
| 1430 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1431 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 1432 | LocationSummary* locations = |
| 1433 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1434 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1435 | } |
| 1436 | |
| 1437 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant) { |
| 1438 | // Will be generated at use site. |
| 1439 | UNUSED(constant); |
| 1440 | } |
| 1441 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1442 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1443 | LocationSummary* locations = |
| 1444 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1445 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) { |
| 1449 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1450 | UNUSED(constant); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1451 | } |
| 1452 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1453 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 1454 | LocationSummary* locations = |
| 1455 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1456 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1457 | } |
| 1458 | |
| 1459 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) { |
| 1460 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1461 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1465 | LocationSummary* locations = |
| 1466 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1467 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1468 | } |
| 1469 | |
| 1470 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1471 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1472 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1473 | } |
| 1474 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1475 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1476 | memory_barrier->SetLocations(nullptr); |
| 1477 | } |
| 1478 | |
| 1479 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1480 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1481 | } |
| 1482 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1483 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1484 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1487 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1488 | UNUSED(ret); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1489 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1490 | } |
| 1491 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1492 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1493 | LocationSummary* locations = |
| 1494 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1495 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1496 | } |
| 1497 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1498 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1499 | UNUSED(ret); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1500 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1501 | } |
| 1502 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1503 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1504 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1505 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1506 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1507 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1508 | IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(), |
| 1509 | codegen_->GetInstructionSetFeatures()); |
| 1510 | if (intrinsic.TryDispatch(invoke)) { |
| 1511 | return; |
| 1512 | } |
| 1513 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1514 | HandleInvoke(invoke); |
| 1515 | } |
| 1516 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1517 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 1518 | if (invoke->GetLocations()->Intrinsified()) { |
| 1519 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 1520 | intrinsic.Dispatch(invoke); |
| 1521 | return true; |
| 1522 | } |
| 1523 | return false; |
| 1524 | } |
| 1525 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1526 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1527 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1528 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1529 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1530 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1531 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1532 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1533 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1534 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1535 | LocationSummary* locations = invoke->GetLocations(); |
| 1536 | codegen_->GenerateStaticOrDirectCall( |
| 1537 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 1538 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1539 | } |
| 1540 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1541 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1542 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1543 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1544 | } |
| 1545 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1546 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1547 | IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(), |
| 1548 | codegen_->GetInstructionSetFeatures()); |
| 1549 | if (intrinsic.TryDispatch(invoke)) { |
| 1550 | return; |
| 1551 | } |
| 1552 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1553 | HandleInvoke(invoke); |
| 1554 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1555 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1556 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1557 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1558 | return; |
| 1559 | } |
| 1560 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1561 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1562 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 1563 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1564 | LocationSummary* locations = invoke->GetLocations(); |
| 1565 | Location receiver = locations->InAt(0); |
| 1566 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1567 | // temp = object->GetClass(); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1568 | DCHECK(receiver.IsRegister()); |
| 1569 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1570 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1571 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1572 | // temp = temp->GetMethodAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1573 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1574 | kArmWordSize).Int32Value(); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1575 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1576 | // LR = temp->GetEntryPoint(); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1577 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1578 | // LR(); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1579 | __ blx(LR); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1580 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1581 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1582 | } |
| 1583 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1584 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1585 | HandleInvoke(invoke); |
| 1586 | // Add the hidden argument. |
| 1587 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 1588 | } |
| 1589 | |
| 1590 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1591 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1592 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1593 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 1594 | invoke->GetImtIndex() % mirror::Class::kImtSize, kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1595 | LocationSummary* locations = invoke->GetLocations(); |
| 1596 | Location receiver = locations->InAt(0); |
| 1597 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1598 | |
| 1599 | // Set the hidden argument. |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1600 | __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(), |
| 1601 | invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1602 | |
| 1603 | // temp = object->GetClass(); |
| 1604 | if (receiver.IsStackSlot()) { |
| 1605 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 1606 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 1607 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1608 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1609 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1610 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1611 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1612 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1613 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1614 | kArmWordSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1615 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 1616 | // LR = temp->GetEntryPoint(); |
| 1617 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 1618 | // LR(); |
| 1619 | __ blx(LR); |
| 1620 | DCHECK(!codegen_->IsLeafMethod()); |
| 1621 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1622 | } |
| 1623 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1624 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 1625 | LocationSummary* locations = |
| 1626 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1627 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 1628 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1629 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 1630 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1631 | break; |
| 1632 | } |
| 1633 | case Primitive::kPrimLong: { |
| 1634 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1635 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1636 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1637 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1638 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1639 | case Primitive::kPrimFloat: |
| 1640 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1641 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1642 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1643 | break; |
| 1644 | |
| 1645 | default: |
| 1646 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1647 | } |
| 1648 | } |
| 1649 | |
| 1650 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 1651 | LocationSummary* locations = neg->GetLocations(); |
| 1652 | Location out = locations->Out(); |
| 1653 | Location in = locations->InAt(0); |
| 1654 | switch (neg->GetResultType()) { |
| 1655 | case Primitive::kPrimInt: |
| 1656 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1657 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1658 | break; |
| 1659 | |
| 1660 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1661 | DCHECK(in.IsRegisterPair()); |
| 1662 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 1663 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 1664 | in.AsRegisterPairLow<Register>(), |
| 1665 | ShifterOperand(0)); |
| 1666 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 1667 | // instruction here, as it does not exist in the Thumb-2 |
| 1668 | // instruction set. We use the following approach |
| 1669 | // using SBC and SUB instead. |
| 1670 | // |
| 1671 | // out.hi = -C |
| 1672 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 1673 | out.AsRegisterPairHigh<Register>(), |
| 1674 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 1675 | // out.hi = out.hi - in.hi |
| 1676 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 1677 | out.AsRegisterPairHigh<Register>(), |
| 1678 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 1679 | break; |
| 1680 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1681 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1682 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1683 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1684 | break; |
| 1685 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1686 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1687 | DCHECK(in.IsFpuRegisterPair()); |
| 1688 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1689 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1690 | break; |
| 1691 | |
| 1692 | default: |
| 1693 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1694 | } |
| 1695 | } |
| 1696 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1697 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1698 | Primitive::Type result_type = conversion->GetResultType(); |
| 1699 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1700 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1701 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 1702 | // The float-to-long, double-to-long and long-to-float type conversions |
| 1703 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1704 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 1705 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 1706 | && result_type == Primitive::kPrimLong) |
| 1707 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1708 | ? LocationSummary::kCall |
| 1709 | : LocationSummary::kNoCall; |
| 1710 | LocationSummary* locations = |
| 1711 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 1712 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1713 | // The Java language does not allow treating boolean as an integral type but |
| 1714 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1715 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1716 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1717 | case Primitive::kPrimByte: |
| 1718 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1719 | case Primitive::kPrimBoolean: |
| 1720 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1721 | case Primitive::kPrimShort: |
| 1722 | case Primitive::kPrimInt: |
| 1723 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1724 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1725 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1726 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1727 | break; |
| 1728 | |
| 1729 | default: |
| 1730 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1731 | << " to " << result_type; |
| 1732 | } |
| 1733 | break; |
| 1734 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1735 | case Primitive::kPrimShort: |
| 1736 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1737 | case Primitive::kPrimBoolean: |
| 1738 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1739 | case Primitive::kPrimByte: |
| 1740 | case Primitive::kPrimInt: |
| 1741 | case Primitive::kPrimChar: |
| 1742 | // Processing a Dex `int-to-short' instruction. |
| 1743 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1744 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1745 | break; |
| 1746 | |
| 1747 | default: |
| 1748 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1749 | << " to " << result_type; |
| 1750 | } |
| 1751 | break; |
| 1752 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1753 | case Primitive::kPrimInt: |
| 1754 | switch (input_type) { |
| 1755 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1756 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1757 | locations->SetInAt(0, Location::Any()); |
| 1758 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1759 | break; |
| 1760 | |
| 1761 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1762 | // Processing a Dex `float-to-int' instruction. |
| 1763 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1764 | locations->SetOut(Location::RequiresRegister()); |
| 1765 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1766 | break; |
| 1767 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1768 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1769 | // Processing a Dex `double-to-int' instruction. |
| 1770 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1771 | locations->SetOut(Location::RequiresRegister()); |
| 1772 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1773 | break; |
| 1774 | |
| 1775 | default: |
| 1776 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1777 | << " to " << result_type; |
| 1778 | } |
| 1779 | break; |
| 1780 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1781 | case Primitive::kPrimLong: |
| 1782 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1783 | case Primitive::kPrimBoolean: |
| 1784 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1785 | case Primitive::kPrimByte: |
| 1786 | case Primitive::kPrimShort: |
| 1787 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1788 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1789 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1790 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1791 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1792 | break; |
| 1793 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1794 | case Primitive::kPrimFloat: { |
| 1795 | // Processing a Dex `float-to-long' instruction. |
| 1796 | InvokeRuntimeCallingConvention calling_convention; |
| 1797 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 1798 | calling_convention.GetFpuRegisterAt(0))); |
| 1799 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 1800 | break; |
| 1801 | } |
| 1802 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1803 | case Primitive::kPrimDouble: { |
| 1804 | // Processing a Dex `double-to-long' instruction. |
| 1805 | InvokeRuntimeCallingConvention calling_convention; |
| 1806 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 1807 | calling_convention.GetFpuRegisterAt(0), |
| 1808 | calling_convention.GetFpuRegisterAt(1))); |
| 1809 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1810 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1811 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1812 | |
| 1813 | default: |
| 1814 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1815 | << " to " << result_type; |
| 1816 | } |
| 1817 | break; |
| 1818 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1819 | case Primitive::kPrimChar: |
| 1820 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1821 | case Primitive::kPrimBoolean: |
| 1822 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1823 | case Primitive::kPrimByte: |
| 1824 | case Primitive::kPrimShort: |
| 1825 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1826 | // Processing a Dex `int-to-char' instruction. |
| 1827 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1828 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1829 | break; |
| 1830 | |
| 1831 | default: |
| 1832 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1833 | << " to " << result_type; |
| 1834 | } |
| 1835 | break; |
| 1836 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1837 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1838 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1839 | case Primitive::kPrimBoolean: |
| 1840 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1841 | case Primitive::kPrimByte: |
| 1842 | case Primitive::kPrimShort: |
| 1843 | case Primitive::kPrimInt: |
| 1844 | case Primitive::kPrimChar: |
| 1845 | // Processing a Dex `int-to-float' instruction. |
| 1846 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1847 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1848 | break; |
| 1849 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 1850 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1851 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 1852 | InvokeRuntimeCallingConvention calling_convention; |
| 1853 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 1854 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 1855 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1856 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 1857 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1858 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1859 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1860 | // Processing a Dex `double-to-float' instruction. |
| 1861 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1862 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1863 | break; |
| 1864 | |
| 1865 | default: |
| 1866 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1867 | << " to " << result_type; |
| 1868 | }; |
| 1869 | break; |
| 1870 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1871 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1872 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1873 | case Primitive::kPrimBoolean: |
| 1874 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1875 | case Primitive::kPrimByte: |
| 1876 | case Primitive::kPrimShort: |
| 1877 | case Primitive::kPrimInt: |
| 1878 | case Primitive::kPrimChar: |
| 1879 | // Processing a Dex `int-to-double' instruction. |
| 1880 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1881 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1882 | break; |
| 1883 | |
| 1884 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1885 | // Processing a Dex `long-to-double' instruction. |
| 1886 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1887 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 1888 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1889 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1890 | break; |
| 1891 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1892 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1893 | // Processing a Dex `float-to-double' instruction. |
| 1894 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1895 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1896 | break; |
| 1897 | |
| 1898 | default: |
| 1899 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1900 | << " to " << result_type; |
| 1901 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1902 | break; |
| 1903 | |
| 1904 | default: |
| 1905 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1906 | << " to " << result_type; |
| 1907 | } |
| 1908 | } |
| 1909 | |
| 1910 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 1911 | LocationSummary* locations = conversion->GetLocations(); |
| 1912 | Location out = locations->Out(); |
| 1913 | Location in = locations->InAt(0); |
| 1914 | Primitive::Type result_type = conversion->GetResultType(); |
| 1915 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1916 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1917 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1918 | case Primitive::kPrimByte: |
| 1919 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1920 | case Primitive::kPrimBoolean: |
| 1921 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1922 | case Primitive::kPrimShort: |
| 1923 | case Primitive::kPrimInt: |
| 1924 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1925 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1926 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1927 | break; |
| 1928 | |
| 1929 | default: |
| 1930 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1931 | << " to " << result_type; |
| 1932 | } |
| 1933 | break; |
| 1934 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1935 | case Primitive::kPrimShort: |
| 1936 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1937 | case Primitive::kPrimBoolean: |
| 1938 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1939 | case Primitive::kPrimByte: |
| 1940 | case Primitive::kPrimInt: |
| 1941 | case Primitive::kPrimChar: |
| 1942 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1943 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1944 | break; |
| 1945 | |
| 1946 | default: |
| 1947 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1948 | << " to " << result_type; |
| 1949 | } |
| 1950 | break; |
| 1951 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1952 | case Primitive::kPrimInt: |
| 1953 | switch (input_type) { |
| 1954 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1955 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1956 | DCHECK(out.IsRegister()); |
| 1957 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1958 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1959 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1960 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1961 | } else { |
| 1962 | DCHECK(in.IsConstant()); |
| 1963 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 1964 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1965 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1966 | } |
| 1967 | break; |
| 1968 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1969 | case Primitive::kPrimFloat: { |
| 1970 | // Processing a Dex `float-to-int' instruction. |
| 1971 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
| 1972 | __ vmovs(temp, in.AsFpuRegister<SRegister>()); |
| 1973 | __ vcvtis(temp, temp); |
| 1974 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 1975 | break; |
| 1976 | } |
| 1977 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1978 | case Primitive::kPrimDouble: { |
| 1979 | // Processing a Dex `double-to-int' instruction. |
| 1980 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
| 1981 | DRegister temp_d = FromLowSToD(temp_s); |
| 1982 | __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
| 1983 | __ vcvtid(temp_s, temp_d); |
| 1984 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1985 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1986 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1987 | |
| 1988 | default: |
| 1989 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1990 | << " to " << result_type; |
| 1991 | } |
| 1992 | break; |
| 1993 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1994 | case Primitive::kPrimLong: |
| 1995 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1996 | case Primitive::kPrimBoolean: |
| 1997 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1998 | case Primitive::kPrimByte: |
| 1999 | case Primitive::kPrimShort: |
| 2000 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2001 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2002 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2003 | DCHECK(out.IsRegisterPair()); |
| 2004 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2005 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2006 | // Sign extension. |
| 2007 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 2008 | out.AsRegisterPairLow<Register>(), |
| 2009 | 31); |
| 2010 | break; |
| 2011 | |
| 2012 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2013 | // Processing a Dex `float-to-long' instruction. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2014 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2015 | conversion, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2016 | conversion->GetDexPc(), |
| 2017 | nullptr); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2018 | break; |
| 2019 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2020 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2021 | // Processing a Dex `double-to-long' instruction. |
| 2022 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2023 | conversion, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2024 | conversion->GetDexPc(), |
| 2025 | nullptr); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2026 | break; |
| 2027 | |
| 2028 | default: |
| 2029 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2030 | << " to " << result_type; |
| 2031 | } |
| 2032 | break; |
| 2033 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2034 | case Primitive::kPrimChar: |
| 2035 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2036 | case Primitive::kPrimBoolean: |
| 2037 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2038 | case Primitive::kPrimByte: |
| 2039 | case Primitive::kPrimShort: |
| 2040 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2041 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2042 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2043 | break; |
| 2044 | |
| 2045 | default: |
| 2046 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2047 | << " to " << result_type; |
| 2048 | } |
| 2049 | break; |
| 2050 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2051 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2052 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2053 | case Primitive::kPrimBoolean: |
| 2054 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2055 | case Primitive::kPrimByte: |
| 2056 | case Primitive::kPrimShort: |
| 2057 | case Primitive::kPrimInt: |
| 2058 | case Primitive::kPrimChar: { |
| 2059 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2060 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 2061 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2062 | break; |
| 2063 | } |
| 2064 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2065 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2066 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2067 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f), |
| 2068 | conversion, |
| 2069 | conversion->GetDexPc(), |
| 2070 | nullptr); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2071 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2072 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2073 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2074 | // Processing a Dex `double-to-float' instruction. |
| 2075 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 2076 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2077 | break; |
| 2078 | |
| 2079 | default: |
| 2080 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2081 | << " to " << result_type; |
| 2082 | }; |
| 2083 | break; |
| 2084 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2085 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2086 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2087 | case Primitive::kPrimBoolean: |
| 2088 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2089 | case Primitive::kPrimByte: |
| 2090 | case Primitive::kPrimShort: |
| 2091 | case Primitive::kPrimInt: |
| 2092 | case Primitive::kPrimChar: { |
| 2093 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2094 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2095 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2096 | out.AsFpuRegisterPairLow<SRegister>()); |
| 2097 | break; |
| 2098 | } |
| 2099 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2100 | case Primitive::kPrimLong: { |
| 2101 | // Processing a Dex `long-to-double' instruction. |
| 2102 | Register low = in.AsRegisterPairLow<Register>(); |
| 2103 | Register high = in.AsRegisterPairHigh<Register>(); |
| 2104 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 2105 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2106 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2107 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2108 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 2109 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2110 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2111 | // temp_d = int-to-double(high) |
| 2112 | __ vmovsr(temp_s, high); |
| 2113 | __ vcvtdi(temp_d, temp_s); |
| 2114 | // constant_d = k2Pow32EncodingForDouble |
| 2115 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 2116 | // out_d = unsigned-to-double(low) |
| 2117 | __ vmovsr(out_s, low); |
| 2118 | __ vcvtdu(out_d, out_s); |
| 2119 | // out_d += temp_d * constant_d |
| 2120 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2121 | break; |
| 2122 | } |
| 2123 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2124 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2125 | // Processing a Dex `float-to-double' instruction. |
| 2126 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2127 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2128 | break; |
| 2129 | |
| 2130 | default: |
| 2131 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2132 | << " to " << result_type; |
| 2133 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2134 | break; |
| 2135 | |
| 2136 | default: |
| 2137 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2138 | << " to " << result_type; |
| 2139 | } |
| 2140 | } |
| 2141 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2142 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2143 | LocationSummary* locations = |
| 2144 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2145 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2146 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2147 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2148 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2149 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2150 | break; |
| 2151 | } |
| 2152 | |
| 2153 | case Primitive::kPrimLong: { |
| 2154 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2155 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2156 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2157 | break; |
| 2158 | } |
| 2159 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2160 | case Primitive::kPrimFloat: |
| 2161 | case Primitive::kPrimDouble: { |
| 2162 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2163 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2164 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2165 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2166 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2167 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2168 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2169 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2170 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2171 | } |
| 2172 | |
| 2173 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 2174 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2175 | Location out = locations->Out(); |
| 2176 | Location first = locations->InAt(0); |
| 2177 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2178 | switch (add->GetResultType()) { |
| 2179 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2180 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2181 | __ add(out.AsRegister<Register>(), |
| 2182 | first.AsRegister<Register>(), |
| 2183 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2184 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2185 | __ AddConstant(out.AsRegister<Register>(), |
| 2186 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2187 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2188 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2189 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2190 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2191 | case Primitive::kPrimLong: { |
| 2192 | DCHECK(second.IsRegisterPair()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2193 | __ adds(out.AsRegisterPairLow<Register>(), |
| 2194 | first.AsRegisterPairLow<Register>(), |
| 2195 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2196 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 2197 | first.AsRegisterPairHigh<Register>(), |
| 2198 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2199 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2200 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2201 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2202 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2203 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 2204 | first.AsFpuRegister<SRegister>(), |
| 2205 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2206 | break; |
| 2207 | |
| 2208 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2209 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2210 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2211 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2212 | break; |
| 2213 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2214 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2215 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2216 | } |
| 2217 | } |
| 2218 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2219 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2220 | LocationSummary* locations = |
| 2221 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2222 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2223 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2224 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2225 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2226 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2227 | break; |
| 2228 | } |
| 2229 | |
| 2230 | case Primitive::kPrimLong: { |
| 2231 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2232 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2233 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2234 | break; |
| 2235 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2236 | case Primitive::kPrimFloat: |
| 2237 | case Primitive::kPrimDouble: { |
| 2238 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2239 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2240 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2241 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2242 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2243 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2244 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2245 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 2249 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2250 | Location out = locations->Out(); |
| 2251 | Location first = locations->InAt(0); |
| 2252 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2253 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2254 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2255 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2256 | __ sub(out.AsRegister<Register>(), |
| 2257 | first.AsRegister<Register>(), |
| 2258 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2259 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2260 | __ AddConstant(out.AsRegister<Register>(), |
| 2261 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2262 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2263 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2264 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2265 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2266 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2267 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2268 | DCHECK(second.IsRegisterPair()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2269 | __ subs(out.AsRegisterPairLow<Register>(), |
| 2270 | first.AsRegisterPairLow<Register>(), |
| 2271 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2272 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2273 | first.AsRegisterPairHigh<Register>(), |
| 2274 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2275 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2276 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2277 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2278 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2279 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 2280 | first.AsFpuRegister<SRegister>(), |
| 2281 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2282 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2283 | } |
| 2284 | |
| 2285 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2286 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2287 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2288 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2289 | break; |
| 2290 | } |
| 2291 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2292 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2293 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2294 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2295 | } |
| 2296 | } |
| 2297 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2298 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 2299 | LocationSummary* locations = |
| 2300 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2301 | switch (mul->GetResultType()) { |
| 2302 | case Primitive::kPrimInt: |
| 2303 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2304 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2305 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2306 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2307 | break; |
| 2308 | } |
| 2309 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2310 | case Primitive::kPrimFloat: |
| 2311 | case Primitive::kPrimDouble: { |
| 2312 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2313 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2314 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2315 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2316 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2317 | |
| 2318 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2319 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2320 | } |
| 2321 | } |
| 2322 | |
| 2323 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 2324 | LocationSummary* locations = mul->GetLocations(); |
| 2325 | Location out = locations->Out(); |
| 2326 | Location first = locations->InAt(0); |
| 2327 | Location second = locations->InAt(1); |
| 2328 | switch (mul->GetResultType()) { |
| 2329 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2330 | __ mul(out.AsRegister<Register>(), |
| 2331 | first.AsRegister<Register>(), |
| 2332 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2333 | break; |
| 2334 | } |
| 2335 | case Primitive::kPrimLong: { |
| 2336 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 2337 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 2338 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2339 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 2340 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2341 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2342 | |
| 2343 | // Extra checks to protect caused by the existence of R1_R2. |
| 2344 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 2345 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 2346 | DCHECK_NE(out_hi, in1_lo); |
| 2347 | DCHECK_NE(out_hi, in2_lo); |
| 2348 | |
| 2349 | // input: in1 - 64 bits, in2 - 64 bits |
| 2350 | // output: out |
| 2351 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2352 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2353 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 2354 | |
| 2355 | // IP <- in1.lo * in2.hi |
| 2356 | __ mul(IP, in1_lo, in2_hi); |
| 2357 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2358 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 2359 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 2360 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 2361 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2362 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 2363 | break; |
| 2364 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2365 | |
| 2366 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2367 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 2368 | first.AsFpuRegister<SRegister>(), |
| 2369 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2370 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2371 | } |
| 2372 | |
| 2373 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2374 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2375 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2376 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2377 | break; |
| 2378 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2379 | |
| 2380 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2381 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2382 | } |
| 2383 | } |
| 2384 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2385 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2386 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2387 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2388 | |
| 2389 | LocationSummary* locations = instruction->GetLocations(); |
| 2390 | Location second = locations->InAt(1); |
| 2391 | DCHECK(second.IsConstant()); |
| 2392 | |
| 2393 | Register out = locations->Out().AsRegister<Register>(); |
| 2394 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2395 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2396 | DCHECK(imm == 1 || imm == -1); |
| 2397 | |
| 2398 | if (instruction->IsRem()) { |
| 2399 | __ LoadImmediate(out, 0); |
| 2400 | } else { |
| 2401 | if (imm == 1) { |
| 2402 | __ Mov(out, dividend); |
| 2403 | } else { |
| 2404 | __ rsb(out, dividend, ShifterOperand(0)); |
| 2405 | } |
| 2406 | } |
| 2407 | } |
| 2408 | |
| 2409 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2410 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2411 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2412 | |
| 2413 | LocationSummary* locations = instruction->GetLocations(); |
| 2414 | Location second = locations->InAt(1); |
| 2415 | DCHECK(second.IsConstant()); |
| 2416 | |
| 2417 | Register out = locations->Out().AsRegister<Register>(); |
| 2418 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2419 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2420 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 2421 | uint32_t abs_imm = static_cast<uint32_t>(std::abs(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2422 | DCHECK(IsPowerOfTwo(abs_imm)); |
| 2423 | int ctz_imm = CTZ(abs_imm); |
| 2424 | |
| 2425 | if (ctz_imm == 1) { |
| 2426 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 2427 | } else { |
| 2428 | __ Asr(temp, dividend, 31); |
| 2429 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 2430 | } |
| 2431 | __ add(out, temp, ShifterOperand(dividend)); |
| 2432 | |
| 2433 | if (instruction->IsDiv()) { |
| 2434 | __ Asr(out, out, ctz_imm); |
| 2435 | if (imm < 0) { |
| 2436 | __ rsb(out, out, ShifterOperand(0)); |
| 2437 | } |
| 2438 | } else { |
| 2439 | __ ubfx(out, out, 0, ctz_imm); |
| 2440 | __ sub(out, out, ShifterOperand(temp)); |
| 2441 | } |
| 2442 | } |
| 2443 | |
| 2444 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2445 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2446 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2447 | |
| 2448 | LocationSummary* locations = instruction->GetLocations(); |
| 2449 | Location second = locations->InAt(1); |
| 2450 | DCHECK(second.IsConstant()); |
| 2451 | |
| 2452 | Register out = locations->Out().AsRegister<Register>(); |
| 2453 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2454 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 2455 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 2456 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2457 | |
| 2458 | int64_t magic; |
| 2459 | int shift; |
| 2460 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2461 | |
| 2462 | __ LoadImmediate(temp1, magic); |
| 2463 | __ smull(temp2, temp1, dividend, temp1); |
| 2464 | |
| 2465 | if (imm > 0 && magic < 0) { |
| 2466 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 2467 | } else if (imm < 0 && magic > 0) { |
| 2468 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 2469 | } |
| 2470 | |
| 2471 | if (shift != 0) { |
| 2472 | __ Asr(temp1, temp1, shift); |
| 2473 | } |
| 2474 | |
| 2475 | if (instruction->IsDiv()) { |
| 2476 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 2477 | } else { |
| 2478 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 2479 | // TODO: Strength reduction for mls. |
| 2480 | __ LoadImmediate(temp2, imm); |
| 2481 | __ mls(out, temp1, temp2, dividend); |
| 2482 | } |
| 2483 | } |
| 2484 | |
| 2485 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 2486 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2487 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2488 | |
| 2489 | LocationSummary* locations = instruction->GetLocations(); |
| 2490 | Location second = locations->InAt(1); |
| 2491 | DCHECK(second.IsConstant()); |
| 2492 | |
| 2493 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2494 | if (imm == 0) { |
| 2495 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2496 | } else if (imm == 1 || imm == -1) { |
| 2497 | DivRemOneOrMinusOne(instruction); |
| 2498 | } else if (IsPowerOfTwo(std::abs(imm))) { |
| 2499 | DivRemByPowerOfTwo(instruction); |
| 2500 | } else { |
| 2501 | DCHECK(imm <= -2 || imm >= 2); |
| 2502 | GenerateDivRemWithAnyConstant(instruction); |
| 2503 | } |
| 2504 | } |
| 2505 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2506 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2507 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 2508 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 2509 | // pLdiv runtime call. |
| 2510 | call_kind = LocationSummary::kCall; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2511 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 2512 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2513 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 2514 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 2515 | // pIdivmod runtime call. |
| 2516 | call_kind = LocationSummary::kCall; |
| 2517 | } |
| 2518 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2519 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2520 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2521 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2522 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2523 | if (div->InputAt(1)->IsConstant()) { |
| 2524 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2525 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
| 2526 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2527 | int32_t abs_imm = std::abs(div->InputAt(1)->AsIntConstant()->GetValue()); |
| 2528 | if (abs_imm <= 1) { |
| 2529 | // No temp register required. |
| 2530 | } else { |
| 2531 | locations->AddTemp(Location::RequiresRegister()); |
| 2532 | if (!IsPowerOfTwo(abs_imm)) { |
| 2533 | locations->AddTemp(Location::RequiresRegister()); |
| 2534 | } |
| 2535 | } |
| 2536 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2537 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2538 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2539 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2540 | } else { |
| 2541 | InvokeRuntimeCallingConvention calling_convention; |
| 2542 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2543 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2544 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 2545 | // we only need the former. |
| 2546 | locations->SetOut(Location::RegisterLocation(R0)); |
| 2547 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2548 | break; |
| 2549 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2550 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2551 | InvokeRuntimeCallingConvention calling_convention; |
| 2552 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2553 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2554 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2555 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2556 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2557 | break; |
| 2558 | } |
| 2559 | case Primitive::kPrimFloat: |
| 2560 | case Primitive::kPrimDouble: { |
| 2561 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2562 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2563 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2564 | break; |
| 2565 | } |
| 2566 | |
| 2567 | default: |
| 2568 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2569 | } |
| 2570 | } |
| 2571 | |
| 2572 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 2573 | LocationSummary* locations = div->GetLocations(); |
| 2574 | Location out = locations->Out(); |
| 2575 | Location first = locations->InAt(0); |
| 2576 | Location second = locations->InAt(1); |
| 2577 | |
| 2578 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2579 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2580 | if (second.IsConstant()) { |
| 2581 | GenerateDivRemConstantIntegral(div); |
| 2582 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2583 | __ sdiv(out.AsRegister<Register>(), |
| 2584 | first.AsRegister<Register>(), |
| 2585 | second.AsRegister<Register>()); |
| 2586 | } else { |
| 2587 | InvokeRuntimeCallingConvention calling_convention; |
| 2588 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 2589 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 2590 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 2591 | |
| 2592 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr); |
| 2593 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2594 | break; |
| 2595 | } |
| 2596 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2597 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2598 | InvokeRuntimeCallingConvention calling_convention; |
| 2599 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2600 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 2601 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 2602 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 2603 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2604 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2605 | |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2606 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2607 | break; |
| 2608 | } |
| 2609 | |
| 2610 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2611 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 2612 | first.AsFpuRegister<SRegister>(), |
| 2613 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2614 | break; |
| 2615 | } |
| 2616 | |
| 2617 | case Primitive::kPrimDouble: { |
| 2618 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2619 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2620 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 2621 | break; |
| 2622 | } |
| 2623 | |
| 2624 | default: |
| 2625 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2626 | } |
| 2627 | } |
| 2628 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2629 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2630 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2631 | |
| 2632 | // Most remainders are implemented in the runtime. |
| 2633 | LocationSummary::CallKind call_kind = LocationSummary::kCall; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2634 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 2635 | // sdiv will be replaced by other instruction sequence. |
| 2636 | call_kind = LocationSummary::kNoCall; |
| 2637 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 2638 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2639 | // Have hardware divide instruction for int, do it with three instructions. |
| 2640 | call_kind = LocationSummary::kNoCall; |
| 2641 | } |
| 2642 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2643 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 2644 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2645 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2646 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2647 | if (rem->InputAt(1)->IsConstant()) { |
| 2648 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2649 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
| 2650 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2651 | int32_t abs_imm = std::abs(rem->InputAt(1)->AsIntConstant()->GetValue()); |
| 2652 | if (abs_imm <= 1) { |
| 2653 | // No temp register required. |
| 2654 | } else { |
| 2655 | locations->AddTemp(Location::RequiresRegister()); |
| 2656 | if (!IsPowerOfTwo(abs_imm)) { |
| 2657 | locations->AddTemp(Location::RequiresRegister()); |
| 2658 | } |
| 2659 | } |
| 2660 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2661 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2662 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2663 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2664 | locations->AddTemp(Location::RequiresRegister()); |
| 2665 | } else { |
| 2666 | InvokeRuntimeCallingConvention calling_convention; |
| 2667 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2668 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2669 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 2670 | // we only need the latter. |
| 2671 | locations->SetOut(Location::RegisterLocation(R1)); |
| 2672 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2673 | break; |
| 2674 | } |
| 2675 | case Primitive::kPrimLong: { |
| 2676 | InvokeRuntimeCallingConvention calling_convention; |
| 2677 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2678 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2679 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2680 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2681 | // The runtime helper puts the output in R2,R3. |
| 2682 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 2683 | break; |
| 2684 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2685 | case Primitive::kPrimFloat: { |
| 2686 | InvokeRuntimeCallingConvention calling_convention; |
| 2687 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 2688 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 2689 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 2690 | break; |
| 2691 | } |
| 2692 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2693 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2694 | InvokeRuntimeCallingConvention calling_convention; |
| 2695 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 2696 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 2697 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 2698 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 2699 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2700 | break; |
| 2701 | } |
| 2702 | |
| 2703 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2704 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2705 | } |
| 2706 | } |
| 2707 | |
| 2708 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 2709 | LocationSummary* locations = rem->GetLocations(); |
| 2710 | Location out = locations->Out(); |
| 2711 | Location first = locations->InAt(0); |
| 2712 | Location second = locations->InAt(1); |
| 2713 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2714 | Primitive::Type type = rem->GetResultType(); |
| 2715 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2716 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2717 | if (second.IsConstant()) { |
| 2718 | GenerateDivRemConstantIntegral(rem); |
| 2719 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2720 | Register reg1 = first.AsRegister<Register>(); |
| 2721 | Register reg2 = second.AsRegister<Register>(); |
| 2722 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2723 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2724 | // temp = reg1 / reg2 (integer division) |
| 2725 | // temp = temp * reg2 |
| 2726 | // dest = reg1 - temp |
| 2727 | __ sdiv(temp, reg1, reg2); |
| 2728 | __ mul(temp, temp, reg2); |
| 2729 | __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp)); |
| 2730 | } else { |
| 2731 | InvokeRuntimeCallingConvention calling_convention; |
| 2732 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 2733 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 2734 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 2735 | |
| 2736 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr); |
| 2737 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2738 | break; |
| 2739 | } |
| 2740 | |
| 2741 | case Primitive::kPrimLong: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2742 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2743 | break; |
| 2744 | } |
| 2745 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2746 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2747 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2748 | break; |
| 2749 | } |
| 2750 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2751 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2752 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2753 | break; |
| 2754 | } |
| 2755 | |
| 2756 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2757 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2758 | } |
| 2759 | } |
| 2760 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2761 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2762 | LocationSummary* locations = |
| 2763 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2764 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2765 | if (instruction->HasUses()) { |
| 2766 | locations->SetOut(Location::SameAsFirstInput()); |
| 2767 | } |
| 2768 | } |
| 2769 | |
| 2770 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2771 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
| 2772 | codegen_->AddSlowPath(slow_path); |
| 2773 | |
| 2774 | LocationSummary* locations = instruction->GetLocations(); |
| 2775 | Location value = locations->InAt(0); |
| 2776 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2777 | switch (instruction->GetType()) { |
| 2778 | case Primitive::kPrimInt: { |
| 2779 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 2780 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2781 | } else { |
| 2782 | DCHECK(value.IsConstant()) << value; |
| 2783 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 2784 | __ b(slow_path->GetEntryLabel()); |
| 2785 | } |
| 2786 | } |
| 2787 | break; |
| 2788 | } |
| 2789 | case Primitive::kPrimLong: { |
| 2790 | if (value.IsRegisterPair()) { |
| 2791 | __ orrs(IP, |
| 2792 | value.AsRegisterPairLow<Register>(), |
| 2793 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 2794 | __ b(slow_path->GetEntryLabel(), EQ); |
| 2795 | } else { |
| 2796 | DCHECK(value.IsConstant()) << value; |
| 2797 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 2798 | __ b(slow_path->GetEntryLabel()); |
| 2799 | } |
| 2800 | } |
| 2801 | break; |
| 2802 | default: |
| 2803 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 2804 | } |
| 2805 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2806 | } |
| 2807 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2808 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 2809 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 2810 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2811 | LocationSummary* locations = |
| 2812 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2813 | |
| 2814 | switch (op->GetResultType()) { |
| 2815 | case Primitive::kPrimInt: { |
| 2816 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2817 | locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1))); |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2818 | // Make the output overlap, as it will be used to hold the masked |
| 2819 | // second input. |
| 2820 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2821 | break; |
| 2822 | } |
| 2823 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2824 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2825 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2826 | locations->AddTemp(Location::RequiresRegister()); |
| 2827 | locations->SetOut(Location::RequiresRegister()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2828 | break; |
| 2829 | } |
| 2830 | default: |
| 2831 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 2832 | } |
| 2833 | } |
| 2834 | |
| 2835 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 2836 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 2837 | |
| 2838 | LocationSummary* locations = op->GetLocations(); |
| 2839 | Location out = locations->Out(); |
| 2840 | Location first = locations->InAt(0); |
| 2841 | Location second = locations->InAt(1); |
| 2842 | |
| 2843 | Primitive::Type type = op->GetResultType(); |
| 2844 | switch (type) { |
| 2845 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2846 | Register out_reg = out.AsRegister<Register>(); |
| 2847 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2848 | // Arm doesn't mask the shift count so we need to do it ourselves. |
| 2849 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2850 | Register second_reg = second.AsRegister<Register>(); |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2851 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftValue)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2852 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2853 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2854 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2855 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2856 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2857 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2858 | } |
| 2859 | } else { |
| 2860 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2861 | uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue); |
| 2862 | if (shift_value == 0) { // arm does not support shifting with 0 immediate. |
| 2863 | __ Mov(out_reg, first_reg); |
| 2864 | } else if (op->IsShl()) { |
| 2865 | __ Lsl(out_reg, first_reg, shift_value); |
| 2866 | } else if (op->IsShr()) { |
| 2867 | __ Asr(out_reg, first_reg, shift_value); |
| 2868 | } else { |
| 2869 | __ Lsr(out_reg, first_reg, shift_value); |
| 2870 | } |
| 2871 | } |
| 2872 | break; |
| 2873 | } |
| 2874 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2875 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 2876 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2877 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2878 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2879 | |
| 2880 | Register high = first.AsRegisterPairHigh<Register>(); |
| 2881 | Register low = first.AsRegisterPairLow<Register>(); |
| 2882 | |
| 2883 | Register second_reg = second.AsRegister<Register>(); |
| 2884 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2885 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2886 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftValue)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2887 | // Shift the high part |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2888 | __ Lsl(o_h, high, o_l); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2889 | // Shift the low part and `or` what overflew on the high part |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2890 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2891 | __ Lsr(temp, low, temp); |
| 2892 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 2893 | // If the shift is > 32 bits, override the high part |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2894 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2895 | __ it(PL); |
| 2896 | __ Lsl(o_h, low, temp, false, PL); |
| 2897 | // Shift the low part |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2898 | __ Lsl(o_l, low, o_l); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2899 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2900 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2901 | // Shift the low part |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2902 | __ Lsr(o_l, low, o_h); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2903 | // Shift the high part and `or` what underflew on the low part |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2904 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2905 | __ Lsl(temp, high, temp); |
| 2906 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 2907 | // If the shift is > 32 bits, override the low part |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2908 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2909 | __ it(PL); |
| 2910 | __ Asr(o_l, high, temp, false, PL); |
| 2911 | // Shift the high part |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2912 | __ Asr(o_h, high, o_h); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2913 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2914 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2915 | // same as Shr except we use `Lsr`s and not `Asr`s |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2916 | __ Lsr(o_l, low, o_h); |
| 2917 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2918 | __ Lsl(temp, high, temp); |
| 2919 | __ orr(o_l, o_l, ShifterOperand(temp)); |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2920 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 2921 | __ it(PL); |
| 2922 | __ Lsr(o_l, high, temp, false, PL); |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 2923 | __ Lsr(o_h, high, o_h); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2924 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2925 | break; |
| 2926 | } |
| 2927 | default: |
| 2928 | LOG(FATAL) << "Unexpected operation type " << type; |
| 2929 | } |
| 2930 | } |
| 2931 | |
| 2932 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 2933 | HandleShift(shl); |
| 2934 | } |
| 2935 | |
| 2936 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 2937 | HandleShift(shl); |
| 2938 | } |
| 2939 | |
| 2940 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 2941 | HandleShift(shr); |
| 2942 | } |
| 2943 | |
| 2944 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 2945 | HandleShift(shr); |
| 2946 | } |
| 2947 | |
| 2948 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 2949 | HandleShift(ushr); |
| 2950 | } |
| 2951 | |
| 2952 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 2953 | HandleShift(ushr); |
| 2954 | } |
| 2955 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2956 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2957 | LocationSummary* locations = |
| 2958 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2959 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2960 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 2961 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2962 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2963 | } |
| 2964 | |
| 2965 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
| 2966 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2967 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2968 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 2969 | // of poisoning the reference. |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2970 | codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(), |
| 2971 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2972 | instruction->GetDexPc(), |
| 2973 | nullptr); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2974 | } |
| 2975 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2976 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 2977 | LocationSummary* locations = |
| 2978 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 2979 | InvokeRuntimeCallingConvention calling_convention; |
| 2980 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2981 | locations->SetOut(Location::RegisterLocation(R0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 2982 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 2983 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2984 | } |
| 2985 | |
| 2986 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
| 2987 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2988 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2989 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 2990 | // of poisoning the reference. |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2991 | codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(), |
| 2992 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2993 | instruction->GetDexPc(), |
| 2994 | nullptr); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2995 | } |
| 2996 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2997 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2998 | LocationSummary* locations = |
| 2999 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3000 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3001 | if (location.IsStackSlot()) { |
| 3002 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3003 | } else if (location.IsDoubleStackSlot()) { |
| 3004 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3005 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3006 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3007 | } |
| 3008 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3009 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 3010 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3011 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3012 | } |
| 3013 | |
| 3014 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3015 | LocationSummary* locations = |
| 3016 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3017 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3018 | } |
| 3019 | |
| 3020 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3021 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3022 | } |
| 3023 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3024 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3025 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3026 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3027 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3028 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3029 | } |
| 3030 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3031 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 3032 | LocationSummary* locations = not_->GetLocations(); |
| 3033 | Location out = locations->Out(); |
| 3034 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3035 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3036 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3037 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3038 | break; |
| 3039 | |
| 3040 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3041 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 3042 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 3043 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 3044 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3045 | break; |
| 3046 | |
| 3047 | default: |
| 3048 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3049 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3050 | } |
| 3051 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3052 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3053 | LocationSummary* locations = |
| 3054 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3055 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3056 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3057 | } |
| 3058 | |
| 3059 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3060 | LocationSummary* locations = bool_not->GetLocations(); |
| 3061 | Location out = locations->Out(); |
| 3062 | Location in = locations->InAt(0); |
| 3063 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 3064 | } |
| 3065 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3066 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3067 | LocationSummary* locations = |
| 3068 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3069 | switch (compare->InputAt(0)->GetType()) { |
| 3070 | case Primitive::kPrimLong: { |
| 3071 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3072 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3073 | // Output overlaps because it is written before doing the low comparison. |
| 3074 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3075 | break; |
| 3076 | } |
| 3077 | case Primitive::kPrimFloat: |
| 3078 | case Primitive::kPrimDouble: { |
| 3079 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3080 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3081 | locations->SetOut(Location::RequiresRegister()); |
| 3082 | break; |
| 3083 | } |
| 3084 | default: |
| 3085 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 3086 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3087 | } |
| 3088 | |
| 3089 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3090 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3091 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3092 | Location left = locations->InAt(0); |
| 3093 | Location right = locations->InAt(1); |
| 3094 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3095 | Label less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3096 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 3097 | switch (type) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3098 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3099 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 3100 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3101 | __ b(&less, LT); |
| 3102 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3103 | // 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] | 3104 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3105 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 3106 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3107 | break; |
| 3108 | } |
| 3109 | case Primitive::kPrimFloat: |
| 3110 | case Primitive::kPrimDouble: { |
| 3111 | __ LoadImmediate(out, 0); |
| 3112 | if (type == Primitive::kPrimFloat) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3113 | __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3114 | } else { |
| 3115 | __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), |
| 3116 | FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); |
| 3117 | } |
| 3118 | __ vmstat(); // transfer FP status register to ARM APSR. |
| 3119 | __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3120 | break; |
| 3121 | } |
| 3122 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3123 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3124 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3125 | __ b(&done, EQ); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3126 | __ b(&less, LO); // LO is for both: unsigned compare for longs and 'less than' for floats. |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3127 | |
| 3128 | __ Bind(&greater); |
| 3129 | __ LoadImmediate(out, 1); |
| 3130 | __ b(&done); |
| 3131 | |
| 3132 | __ Bind(&less); |
| 3133 | __ LoadImmediate(out, -1); |
| 3134 | |
| 3135 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3136 | } |
| 3137 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3138 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3139 | LocationSummary* locations = |
| 3140 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 3141 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3142 | locations->SetInAt(i, Location::Any()); |
| 3143 | } |
| 3144 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3145 | } |
| 3146 | |
| 3147 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3148 | UNUSED(instruction); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3149 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3150 | } |
| 3151 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3152 | void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3153 | // TODO (ported from quick): revisit Arm barrier kinds |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3154 | DmbOptions flavor = DmbOptions::ISH; // quiet c++ warnings |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3155 | switch (kind) { |
| 3156 | case MemBarrierKind::kAnyStore: |
| 3157 | case MemBarrierKind::kLoadAny: |
| 3158 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3159 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3160 | break; |
| 3161 | } |
| 3162 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3163 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3164 | break; |
| 3165 | } |
| 3166 | default: |
| 3167 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 3168 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3169 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3170 | } |
| 3171 | |
| 3172 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 3173 | uint32_t offset, |
| 3174 | Register out_lo, |
| 3175 | Register out_hi) { |
| 3176 | if (offset != 0) { |
| 3177 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3178 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 3179 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3180 | } |
| 3181 | __ ldrexd(out_lo, out_hi, addr); |
| 3182 | } |
| 3183 | |
| 3184 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 3185 | uint32_t offset, |
| 3186 | Register value_lo, |
| 3187 | Register value_hi, |
| 3188 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3189 | Register temp2, |
| 3190 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3191 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3192 | if (offset != 0) { |
| 3193 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3194 | __ add(IP, addr, ShifterOperand(temp1)); |
| 3195 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3196 | } |
| 3197 | __ Bind(&fail); |
| 3198 | // We need a load followed by store. (The address used in a STREX instruction must |
| 3199 | // be the same as the address in the most recently executed LDREX instruction.) |
| 3200 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3201 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3202 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3203 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3204 | } |
| 3205 | |
| 3206 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3207 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3208 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3209 | LocationSummary* locations = |
| 3210 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3211 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3212 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3213 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3214 | if (Primitive::IsFloatingPointType(field_type)) { |
| 3215 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3216 | } else { |
| 3217 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3218 | } |
| 3219 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3220 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3221 | bool generate_volatile = field_info.IsVolatile() |
| 3222 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3223 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3224 | bool needs_write_barrier = |
| 3225 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3226 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3227 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3228 | if (needs_write_barrier) { |
| 3229 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3230 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3231 | } else if (generate_volatile) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3232 | // Arm encoding have some additional constraints for ldrexd/strexd: |
| 3233 | // - registers need to be consecutive |
| 3234 | // - the first register should be even but not R14. |
| 3235 | // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever |
| 3236 | // enable Arm encoding. |
| 3237 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 3238 | |
| 3239 | locations->AddTemp(Location::RequiresRegister()); |
| 3240 | locations->AddTemp(Location::RequiresRegister()); |
| 3241 | if (field_type == Primitive::kPrimDouble) { |
| 3242 | // For doubles we need two more registers to copy the value. |
| 3243 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 3244 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 3245 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3246 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3247 | } |
| 3248 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3249 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3250 | const FieldInfo& field_info, |
| 3251 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3252 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3253 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3254 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3255 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3256 | Location value = locations->InAt(1); |
| 3257 | |
| 3258 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3259 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3260 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3261 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3262 | bool needs_write_barrier = |
| 3263 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3264 | |
| 3265 | if (is_volatile) { |
| 3266 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 3267 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3268 | |
| 3269 | switch (field_type) { |
| 3270 | case Primitive::kPrimBoolean: |
| 3271 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3272 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3273 | break; |
| 3274 | } |
| 3275 | |
| 3276 | case Primitive::kPrimShort: |
| 3277 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3278 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3279 | break; |
| 3280 | } |
| 3281 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3282 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3283 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3284 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 3285 | // Note that in the case where `value` is a null reference, |
| 3286 | // we do not enter this block, as a null reference does not |
| 3287 | // need poisoning. |
| 3288 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 3289 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3290 | __ Mov(temp, value.AsRegister<Register>()); |
| 3291 | __ PoisonHeapReference(temp); |
| 3292 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 3293 | } else { |
| 3294 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 3295 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3296 | break; |
| 3297 | } |
| 3298 | |
| 3299 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3300 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3301 | GenerateWideAtomicStore(base, offset, |
| 3302 | value.AsRegisterPairLow<Register>(), |
| 3303 | value.AsRegisterPairHigh<Register>(), |
| 3304 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3305 | locations->GetTemp(1).AsRegister<Register>(), |
| 3306 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3307 | } else { |
| 3308 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3309 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3310 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3311 | break; |
| 3312 | } |
| 3313 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3314 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3315 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3316 | break; |
| 3317 | } |
| 3318 | |
| 3319 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3320 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3321 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3322 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 3323 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 3324 | |
| 3325 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 3326 | |
| 3327 | GenerateWideAtomicStore(base, offset, |
| 3328 | value_reg_lo, |
| 3329 | value_reg_hi, |
| 3330 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3331 | locations->GetTemp(3).AsRegister<Register>(), |
| 3332 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3333 | } else { |
| 3334 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3335 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3336 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3337 | break; |
| 3338 | } |
| 3339 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3340 | case Primitive::kPrimVoid: |
| 3341 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3342 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3343 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3344 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3345 | // Longs and doubles are handled in the switch. |
| 3346 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 3347 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3348 | } |
| 3349 | |
| 3350 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 3351 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3352 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3353 | codegen_->MarkGCCard( |
| 3354 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3355 | } |
| 3356 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3357 | if (is_volatile) { |
| 3358 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 3359 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3360 | } |
| 3361 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3362 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3363 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3364 | LocationSummary* locations = |
| 3365 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3366 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3367 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3368 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3369 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3370 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3371 | bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong); |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 3372 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3373 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3374 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3375 | } else { |
| 3376 | locations->SetOut(Location::RequiresRegister(), |
| 3377 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 3378 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3379 | if (volatile_for_double) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3380 | // Arm encoding have some additional constraints for ldrexd/strexd: |
| 3381 | // - registers need to be consecutive |
| 3382 | // - the first register should be even but not R14. |
| 3383 | // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever |
| 3384 | // enable Arm encoding. |
| 3385 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 3386 | locations->AddTemp(Location::RequiresRegister()); |
| 3387 | locations->AddTemp(Location::RequiresRegister()); |
| 3388 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3389 | } |
| 3390 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3391 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 3392 | const FieldInfo& field_info) { |
| 3393 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3394 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3395 | LocationSummary* locations = instruction->GetLocations(); |
| 3396 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3397 | Location out = locations->Out(); |
| 3398 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3399 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3400 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3401 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3402 | |
| 3403 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3404 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3405 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3406 | break; |
| 3407 | } |
| 3408 | |
| 3409 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3410 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3411 | break; |
| 3412 | } |
| 3413 | |
| 3414 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3415 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3416 | break; |
| 3417 | } |
| 3418 | |
| 3419 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3420 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3421 | break; |
| 3422 | } |
| 3423 | |
| 3424 | case Primitive::kPrimInt: |
| 3425 | case Primitive::kPrimNot: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3426 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3427 | break; |
| 3428 | } |
| 3429 | |
| 3430 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3431 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3432 | GenerateWideAtomicLoad(base, offset, |
| 3433 | out.AsRegisterPairLow<Register>(), |
| 3434 | out.AsRegisterPairHigh<Register>()); |
| 3435 | } else { |
| 3436 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 3437 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3438 | break; |
| 3439 | } |
| 3440 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3441 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3442 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3443 | break; |
| 3444 | } |
| 3445 | |
| 3446 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3447 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3448 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3449 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 3450 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 3451 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3452 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3453 | __ vmovdrr(out_reg, lo, hi); |
| 3454 | } else { |
| 3455 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3456 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3457 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3458 | break; |
| 3459 | } |
| 3460 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3461 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3462 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3463 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3464 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3465 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3466 | // Doubles are handled in the switch. |
| 3467 | if (field_type != Primitive::kPrimDouble) { |
| 3468 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3469 | } |
| 3470 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3471 | if (is_volatile) { |
| 3472 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 3473 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3474 | |
| 3475 | if (field_type == Primitive::kPrimNot) { |
| 3476 | __ MaybeUnpoisonHeapReference(out.AsRegister<Register>()); |
| 3477 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3478 | } |
| 3479 | |
| 3480 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 3481 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3482 | } |
| 3483 | |
| 3484 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3485 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3486 | } |
| 3487 | |
| 3488 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 3489 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3490 | } |
| 3491 | |
| 3492 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 3493 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3494 | } |
| 3495 | |
| 3496 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3497 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3498 | } |
| 3499 | |
| 3500 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3501 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3502 | } |
| 3503 | |
| 3504 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3505 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3506 | } |
| 3507 | |
| 3508 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3509 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3510 | } |
| 3511 | |
| 3512 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3513 | LocationSummary* locations = |
| 3514 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3515 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3516 | if (instruction->HasUses()) { |
| 3517 | locations->SetOut(Location::SameAsFirstInput()); |
| 3518 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3519 | } |
| 3520 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3521 | void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3522 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 3523 | return; |
| 3524 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3525 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3526 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3527 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
| 3528 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3529 | } |
| 3530 | |
| 3531 | void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 3532 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3533 | codegen_->AddSlowPath(slow_path); |
| 3534 | |
| 3535 | LocationSummary* locations = instruction->GetLocations(); |
| 3536 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3537 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3538 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3539 | } |
| 3540 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3541 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
| 3542 | if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) { |
| 3543 | GenerateImplicitNullCheck(instruction); |
| 3544 | } else { |
| 3545 | GenerateExplicitNullCheck(instruction); |
| 3546 | } |
| 3547 | } |
| 3548 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3549 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3550 | LocationSummary* locations = |
| 3551 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3552 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3553 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3554 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3555 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3556 | } else { |
| 3557 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3558 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3559 | } |
| 3560 | |
| 3561 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 3562 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3563 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3564 | Location index = locations->InAt(1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3565 | Primitive::Type type = instruction->GetType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3566 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3567 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3568 | case Primitive::kPrimBoolean: { |
| 3569 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3570 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3571 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3572 | size_t offset = |
| 3573 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3574 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset); |
| 3575 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3576 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3577 | __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset); |
| 3578 | } |
| 3579 | break; |
| 3580 | } |
| 3581 | |
| 3582 | case Primitive::kPrimByte: { |
| 3583 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3584 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3585 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3586 | size_t offset = |
| 3587 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3588 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset); |
| 3589 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3590 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3591 | __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset); |
| 3592 | } |
| 3593 | break; |
| 3594 | } |
| 3595 | |
| 3596 | case Primitive::kPrimShort: { |
| 3597 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3598 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3599 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3600 | size_t offset = |
| 3601 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3602 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset); |
| 3603 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3604 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3605 | __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset); |
| 3606 | } |
| 3607 | break; |
| 3608 | } |
| 3609 | |
| 3610 | case Primitive::kPrimChar: { |
| 3611 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3612 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3613 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3614 | size_t offset = |
| 3615 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3616 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset); |
| 3617 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3618 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3619 | __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset); |
| 3620 | } |
| 3621 | break; |
| 3622 | } |
| 3623 | |
| 3624 | case Primitive::kPrimInt: |
| 3625 | case Primitive::kPrimNot: { |
Roland Levillain | 33d6903 | 2015-06-18 18:20:59 +0100 | [diff] [blame] | 3626 | static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 3627 | "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3628 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3629 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3630 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3631 | size_t offset = |
| 3632 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3633 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 3634 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3635 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3636 | __ LoadFromOffset(kLoadWord, out, IP, data_offset); |
| 3637 | } |
| 3638 | break; |
| 3639 | } |
| 3640 | |
| 3641 | case Primitive::kPrimLong: { |
| 3642 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3643 | Location out = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3644 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3645 | size_t offset = |
| 3646 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3647 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3648 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3649 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3650 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3651 | } |
| 3652 | break; |
| 3653 | } |
| 3654 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3655 | case Primitive::kPrimFloat: { |
| 3656 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 3657 | Location out = locations->Out(); |
| 3658 | DCHECK(out.IsFpuRegister()); |
| 3659 | if (index.IsConstant()) { |
| 3660 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 3661 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset); |
| 3662 | } else { |
| 3663 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 3664 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset); |
| 3665 | } |
| 3666 | break; |
| 3667 | } |
| 3668 | |
| 3669 | case Primitive::kPrimDouble: { |
| 3670 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 3671 | Location out = locations->Out(); |
| 3672 | DCHECK(out.IsFpuRegisterPair()); |
| 3673 | if (index.IsConstant()) { |
| 3674 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 3675 | __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset); |
| 3676 | } else { |
| 3677 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
| 3678 | __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 3679 | } |
| 3680 | break; |
| 3681 | } |
| 3682 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3683 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3684 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3685 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3686 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3687 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3688 | |
| 3689 | if (type == Primitive::kPrimNot) { |
| 3690 | Register out = locations->Out().AsRegister<Register>(); |
| 3691 | __ MaybeUnpoisonHeapReference(out); |
| 3692 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3693 | } |
| 3694 | |
| 3695 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3696 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3697 | |
| 3698 | bool needs_write_barrier = |
| 3699 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 3700 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
| 3701 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3702 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3703 | instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 3704 | if (needs_runtime_call) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3705 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3706 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3707 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3708 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3709 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3710 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3711 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3712 | if (Primitive::IsFloatingPointType(value_type)) { |
| 3713 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 3714 | } else { |
| 3715 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3716 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3717 | |
| 3718 | if (needs_write_barrier) { |
| 3719 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3720 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3721 | locations->AddTemp(Location::RequiresRegister()); |
| 3722 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3723 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3724 | } |
| 3725 | |
| 3726 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 3727 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3728 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3729 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3730 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3731 | bool needs_runtime_call = locations->WillCall(); |
| 3732 | bool needs_write_barrier = |
| 3733 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3734 | |
| 3735 | switch (value_type) { |
| 3736 | case Primitive::kPrimBoolean: |
| 3737 | case Primitive::kPrimByte: { |
| 3738 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3739 | Register value = locations->InAt(2).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3740 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3741 | size_t offset = |
| 3742 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3743 | __ StoreToOffset(kStoreByte, value, obj, offset); |
| 3744 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3745 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3746 | __ StoreToOffset(kStoreByte, value, IP, data_offset); |
| 3747 | } |
| 3748 | break; |
| 3749 | } |
| 3750 | |
| 3751 | case Primitive::kPrimShort: |
| 3752 | case Primitive::kPrimChar: { |
| 3753 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3754 | Register value = locations->InAt(2).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3755 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3756 | size_t offset = |
| 3757 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3758 | __ StoreToOffset(kStoreHalfword, value, obj, offset); |
| 3759 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3760 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3761 | __ StoreToOffset(kStoreHalfword, value, IP, data_offset); |
| 3762 | } |
| 3763 | break; |
| 3764 | } |
| 3765 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3766 | case Primitive::kPrimInt: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3767 | case Primitive::kPrimNot: { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3768 | if (!needs_runtime_call) { |
| 3769 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3770 | Register value = locations->InAt(2).AsRegister<Register>(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3771 | Register source = value; |
| 3772 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 3773 | // Note that in the case where `value` is a null reference, |
| 3774 | // we do not enter this block, as a null reference does not |
| 3775 | // need poisoning. |
| 3776 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 3777 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3778 | __ Mov(temp, value); |
| 3779 | __ PoisonHeapReference(temp); |
| 3780 | source = temp; |
| 3781 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3782 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3783 | size_t offset = |
| 3784 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3785 | __ StoreToOffset(kStoreWord, source, obj, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3786 | } else { |
| 3787 | DCHECK(index.IsRegister()) << index; |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3788 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3789 | __ StoreToOffset(kStoreWord, source, IP, data_offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3790 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3791 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3792 | if (needs_write_barrier) { |
| 3793 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3794 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3795 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3796 | codegen_->MarkGCCard(temp, card, obj, value, instruction->GetValueCanBeNull()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3797 | } |
| 3798 | } else { |
| 3799 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3800 | // Note: if heap poisoning is enabled, pAputObject takes cares |
| 3801 | // of poisoning the reference. |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3802 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 3803 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3804 | instruction->GetDexPc(), |
| 3805 | nullptr); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3806 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3807 | break; |
| 3808 | } |
| 3809 | |
| 3810 | case Primitive::kPrimLong: { |
| 3811 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3812 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3813 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3814 | size_t offset = |
| 3815 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3816 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3817 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3818 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3819 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3820 | } |
| 3821 | break; |
| 3822 | } |
| 3823 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3824 | case Primitive::kPrimFloat: { |
| 3825 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 3826 | Location value = locations->InAt(2); |
| 3827 | DCHECK(value.IsFpuRegister()); |
| 3828 | if (index.IsConstant()) { |
| 3829 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 3830 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset); |
| 3831 | } else { |
| 3832 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 3833 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 3834 | } |
| 3835 | break; |
| 3836 | } |
| 3837 | |
| 3838 | case Primitive::kPrimDouble: { |
| 3839 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 3840 | Location value = locations->InAt(2); |
| 3841 | DCHECK(value.IsFpuRegisterPair()); |
| 3842 | if (index.IsConstant()) { |
| 3843 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 3844 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset); |
| 3845 | } else { |
| 3846 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
| 3847 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 3848 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3849 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3850 | break; |
| 3851 | } |
| 3852 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3853 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3854 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3855 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3856 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3857 | |
| 3858 | // Ints and objects are handled in the switch. |
| 3859 | if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) { |
| 3860 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3861 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3862 | } |
| 3863 | |
| 3864 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3865 | LocationSummary* locations = |
| 3866 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3867 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3868 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3869 | } |
| 3870 | |
| 3871 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 3872 | LocationSummary* locations = instruction->GetLocations(); |
| 3873 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3874 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 3875 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3876 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3877 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3878 | } |
| 3879 | |
| 3880 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3881 | LocationSummary* locations = |
| 3882 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3883 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3884 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3885 | if (instruction->HasUses()) { |
| 3886 | locations->SetOut(Location::SameAsFirstInput()); |
| 3887 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3888 | } |
| 3889 | |
| 3890 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 3891 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 3892 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3893 | instruction, locations->InAt(0), locations->InAt(1)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3894 | codegen_->AddSlowPath(slow_path); |
| 3895 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3896 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 3897 | Register length = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3898 | |
| 3899 | __ cmp(index, ShifterOperand(length)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3900 | __ b(slow_path->GetEntryLabel(), HS); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3901 | } |
| 3902 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3903 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 3904 | Register card, |
| 3905 | Register object, |
| 3906 | Register value, |
| 3907 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3908 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3909 | if (can_be_null) { |
| 3910 | __ CompareAndBranchIfZero(value, &is_null); |
| 3911 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3912 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value()); |
| 3913 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 3914 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3915 | if (can_be_null) { |
| 3916 | __ Bind(&is_null); |
| 3917 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3918 | } |
| 3919 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3920 | void LocationsBuilderARM::VisitTemporary(HTemporary* temp) { |
| 3921 | temp->SetLocations(nullptr); |
| 3922 | } |
| 3923 | |
| 3924 | void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) { |
| 3925 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3926 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3927 | } |
| 3928 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 3929 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3930 | UNUSED(instruction); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3931 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 3932 | } |
| 3933 | |
| 3934 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3935 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 3936 | } |
| 3937 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 3938 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 3939 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 3940 | } |
| 3941 | |
| 3942 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 3943 | HBasicBlock* block = instruction->GetBlock(); |
| 3944 | if (block->GetLoopInformation() != nullptr) { |
| 3945 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 3946 | // The back edge will generate the suspend check. |
| 3947 | return; |
| 3948 | } |
| 3949 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 3950 | // The goto will generate the suspend check. |
| 3951 | return; |
| 3952 | } |
| 3953 | GenerateSuspendCheck(instruction, nullptr); |
| 3954 | } |
| 3955 | |
| 3956 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 3957 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 3958 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 3959 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 3960 | if (slow_path == nullptr) { |
| 3961 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 3962 | instruction->SetSlowPath(slow_path); |
| 3963 | codegen_->AddSlowPath(slow_path); |
| 3964 | if (successor != nullptr) { |
| 3965 | DCHECK(successor->IsLoopHeader()); |
| 3966 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 3967 | } |
| 3968 | } else { |
| 3969 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 3970 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 3971 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 3972 | __ LoadFromOffset( |
| 3973 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 3974 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3975 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 3976 | __ Bind(slow_path->GetReturnLabel()); |
| 3977 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3978 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 3979 | __ b(slow_path->GetEntryLabel()); |
| 3980 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 3981 | } |
| 3982 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3983 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 3984 | return codegen_->GetAssembler(); |
| 3985 | } |
| 3986 | |
| 3987 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
| 3988 | MoveOperands* move = moves_.Get(index); |
| 3989 | Location source = move->GetSource(); |
| 3990 | Location destination = move->GetDestination(); |
| 3991 | |
| 3992 | if (source.IsRegister()) { |
| 3993 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3994 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3995 | } else { |
| 3996 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3997 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3998 | SP, destination.GetStackIndex()); |
| 3999 | } |
| 4000 | } else if (source.IsStackSlot()) { |
| 4001 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4002 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4003 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4004 | } else if (destination.IsFpuRegister()) { |
| 4005 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4006 | } else { |
| 4007 | DCHECK(destination.IsStackSlot()); |
| 4008 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 4009 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4010 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4011 | } else if (source.IsFpuRegister()) { |
| 4012 | if (destination.IsFpuRegister()) { |
| 4013 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4014 | } else { |
| 4015 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4016 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 4017 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4018 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4019 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4020 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 4021 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4022 | } else if (destination.IsRegisterPair()) { |
| 4023 | DCHECK(ExpectedPairLayout(destination)); |
| 4024 | __ LoadFromOffset( |
| 4025 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 4026 | } else { |
| 4027 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 4028 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 4029 | SP, |
| 4030 | source.GetStackIndex()); |
| 4031 | } |
| 4032 | } else if (source.IsRegisterPair()) { |
| 4033 | if (destination.IsRegisterPair()) { |
| 4034 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 4035 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 4036 | } else { |
| 4037 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4038 | DCHECK(ExpectedPairLayout(source)); |
| 4039 | __ StoreToOffset( |
| 4040 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 4041 | } |
| 4042 | } else if (source.IsFpuRegisterPair()) { |
| 4043 | if (destination.IsFpuRegisterPair()) { |
| 4044 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 4045 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 4046 | } else { |
| 4047 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4048 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 4049 | SP, |
| 4050 | destination.GetStackIndex()); |
| 4051 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4052 | } else { |
| 4053 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4054 | HConstant* constant = source.GetConstant(); |
| 4055 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 4056 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4057 | if (destination.IsRegister()) { |
| 4058 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 4059 | } else { |
| 4060 | DCHECK(destination.IsStackSlot()); |
| 4061 | __ LoadImmediate(IP, value); |
| 4062 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4063 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4064 | } else if (constant->IsLongConstant()) { |
| 4065 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4066 | if (destination.IsRegisterPair()) { |
| 4067 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 4068 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4069 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4070 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4071 | __ LoadImmediate(IP, Low32Bits(value)); |
| 4072 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4073 | __ LoadImmediate(IP, High32Bits(value)); |
| 4074 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 4075 | } |
| 4076 | } else if (constant->IsDoubleConstant()) { |
| 4077 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4078 | if (destination.IsFpuRegisterPair()) { |
| 4079 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4080 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4081 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4082 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4083 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 4084 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4085 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 4086 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 4087 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4088 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4089 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4090 | float value = constant->AsFloatConstant()->GetValue(); |
| 4091 | if (destination.IsFpuRegister()) { |
| 4092 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 4093 | } else { |
| 4094 | DCHECK(destination.IsStackSlot()); |
| 4095 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 4096 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4097 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4098 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4099 | } |
| 4100 | } |
| 4101 | |
| 4102 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 4103 | __ Mov(IP, reg); |
| 4104 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 4105 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 4106 | } |
| 4107 | |
| 4108 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 4109 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 4110 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 4111 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 4112 | SP, mem1 + stack_offset); |
| 4113 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 4114 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 4115 | SP, mem2 + stack_offset); |
| 4116 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 4117 | } |
| 4118 | |
| 4119 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
| 4120 | MoveOperands* move = moves_.Get(index); |
| 4121 | Location source = move->GetSource(); |
| 4122 | Location destination = move->GetDestination(); |
| 4123 | |
| 4124 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4125 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 4126 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 4127 | __ Mov(IP, source.AsRegister<Register>()); |
| 4128 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 4129 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4130 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4131 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4132 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4133 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4134 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 4135 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4136 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 4137 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4138 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 4139 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4140 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4141 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4142 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4143 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4144 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 4145 | destination.AsRegisterPairHigh<Register>(), |
| 4146 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4147 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4148 | Register low_reg = source.IsRegisterPair() |
| 4149 | ? source.AsRegisterPairLow<Register>() |
| 4150 | : destination.AsRegisterPairLow<Register>(); |
| 4151 | int mem = source.IsRegisterPair() |
| 4152 | ? destination.GetStackIndex() |
| 4153 | : source.GetStackIndex(); |
| 4154 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4155 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4156 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4157 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4158 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4159 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 4160 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4161 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4162 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4163 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4164 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 4165 | DRegister reg = source.IsFpuRegisterPair() |
| 4166 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 4167 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 4168 | int mem = source.IsFpuRegisterPair() |
| 4169 | ? destination.GetStackIndex() |
| 4170 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4171 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4172 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4173 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4174 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 4175 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 4176 | : destination.AsFpuRegister<SRegister>(); |
| 4177 | int mem = source.IsFpuRegister() |
| 4178 | ? destination.GetStackIndex() |
| 4179 | : source.GetStackIndex(); |
| 4180 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 4181 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4182 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 4183 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 4184 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 4185 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 4186 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4187 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 4188 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4189 | } |
| 4190 | } |
| 4191 | |
| 4192 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 4193 | __ Push(static_cast<Register>(reg)); |
| 4194 | } |
| 4195 | |
| 4196 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 4197 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4198 | } |
| 4199 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4200 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4201 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 4202 | ? LocationSummary::kCallOnSlowPath |
| 4203 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4204 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4205 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4206 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4207 | locations->SetOut(Location::RequiresRegister()); |
| 4208 | } |
| 4209 | |
| 4210 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4211 | LocationSummary* locations = cls->GetLocations(); |
| 4212 | Register out = locations->Out().AsRegister<Register>(); |
| 4213 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4214 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4215 | DCHECK(!cls->CanCallRuntime()); |
| 4216 | DCHECK(!cls->MustGenerateClinitCheck()); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4217 | __ LoadFromOffset( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4218 | kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4219 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4220 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4221 | __ LoadFromOffset(kLoadWord, |
| 4222 | out, |
| 4223 | current_method, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4224 | ArtMethod::DexCacheResolvedTypesOffset().Int32Value()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4225 | __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4226 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4227 | |
| 4228 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
| 4229 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4230 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4231 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4232 | if (cls->MustGenerateClinitCheck()) { |
| 4233 | GenerateClassInitializationCheck(slow_path, out); |
| 4234 | } else { |
| 4235 | __ Bind(slow_path->GetExitLabel()); |
| 4236 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4237 | } |
| 4238 | } |
| 4239 | |
| 4240 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 4241 | LocationSummary* locations = |
| 4242 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 4243 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4244 | if (check->HasUses()) { |
| 4245 | locations->SetOut(Location::SameAsFirstInput()); |
| 4246 | } |
| 4247 | } |
| 4248 | |
| 4249 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4250 | // We assume the class is not null. |
| 4251 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
| 4252 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4253 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4254 | GenerateClassInitializationCheck(slow_path, |
| 4255 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4256 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4257 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4258 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
| 4259 | SlowPathCodeARM* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4260 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 4261 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 4262 | __ b(slow_path->GetEntryLabel(), LT); |
| 4263 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 4264 | // properly. Therefore, we do a memory fence. |
| 4265 | __ dmb(ISH); |
| 4266 | __ Bind(slow_path->GetExitLabel()); |
| 4267 | } |
| 4268 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4269 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
| 4270 | LocationSummary* locations = |
| 4271 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4272 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4273 | locations->SetOut(Location::RequiresRegister()); |
| 4274 | } |
| 4275 | |
| 4276 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) { |
| 4277 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 4278 | codegen_->AddSlowPath(slow_path); |
| 4279 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4280 | LocationSummary* locations = load->GetLocations(); |
| 4281 | Register out = locations->Out().AsRegister<Register>(); |
| 4282 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 4283 | __ LoadFromOffset( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4284 | kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 4285 | __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4286 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4287 | __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4288 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4289 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4290 | __ Bind(slow_path->GetExitLabel()); |
| 4291 | } |
| 4292 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4293 | static int32_t GetExceptionTlsOffset() { |
| 4294 | return Thread::ExceptionOffset<kArmWordSize>().Int32Value(); |
| 4295 | } |
| 4296 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4297 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 4298 | LocationSummary* locations = |
| 4299 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4300 | locations->SetOut(Location::RequiresRegister()); |
| 4301 | } |
| 4302 | |
| 4303 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4304 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4305 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 4306 | } |
| 4307 | |
| 4308 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 4309 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4310 | } |
| 4311 | |
| 4312 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4313 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4314 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4315 | } |
| 4316 | |
| 4317 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 4318 | LocationSummary* locations = |
| 4319 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4320 | InvokeRuntimeCallingConvention calling_convention; |
| 4321 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4322 | } |
| 4323 | |
| 4324 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
| 4325 | codegen_->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 4326 | QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4327 | } |
| 4328 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4329 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4330 | LocationSummary::CallKind call_kind = instruction->IsClassFinal() |
| 4331 | ? LocationSummary::kNoCall |
| 4332 | : LocationSummary::kCallOnSlowPath; |
| 4333 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4334 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4335 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4336 | // The out register is used as a temporary, so it overlaps with the inputs. |
| 4337 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4338 | } |
| 4339 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4340 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4341 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4342 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4343 | Register cls = locations->InAt(1).AsRegister<Register>(); |
| 4344 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4345 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4346 | Label done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4347 | SlowPathCodeARM* slow_path = nullptr; |
| 4348 | |
| 4349 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4350 | // avoid null check if we know obj is not null. |
| 4351 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | d56376c | 2015-05-21 12:32:34 +0000 | [diff] [blame] | 4352 | __ CompareAndBranchIfZero(obj, &zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4353 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4354 | // Compare the class of `obj` with `cls`. |
| 4355 | __ LoadFromOffset(kLoadWord, out, obj, class_offset); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4356 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4357 | __ cmp(out, ShifterOperand(cls)); |
| 4358 | if (instruction->IsClassFinal()) { |
| 4359 | // Classes must be equal for the instanceof to succeed. |
| 4360 | __ b(&zero, NE); |
| 4361 | __ LoadImmediate(out, 1); |
| 4362 | __ b(&done); |
| 4363 | } else { |
| 4364 | // If the classes are not equal, we go into a slow path. |
| 4365 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4366 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM( |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4367 | instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4368 | codegen_->AddSlowPath(slow_path); |
| 4369 | __ b(slow_path->GetEntryLabel(), NE); |
| 4370 | __ LoadImmediate(out, 1); |
| 4371 | __ b(&done); |
| 4372 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4373 | |
| 4374 | if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) { |
| 4375 | __ Bind(&zero); |
| 4376 | __ LoadImmediate(out, 0); |
| 4377 | } |
| 4378 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4379 | if (slow_path != nullptr) { |
| 4380 | __ Bind(slow_path->GetExitLabel()); |
| 4381 | } |
| 4382 | __ Bind(&done); |
| 4383 | } |
| 4384 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4385 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
| 4386 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 4387 | instruction, LocationSummary::kCallOnSlowPath); |
| 4388 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4389 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4390 | locations->AddTemp(Location::RequiresRegister()); |
| 4391 | } |
| 4392 | |
| 4393 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
| 4394 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4395 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4396 | Register cls = locations->InAt(1).AsRegister<Register>(); |
| 4397 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4398 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4399 | |
| 4400 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM( |
| 4401 | instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc()); |
| 4402 | codegen_->AddSlowPath(slow_path); |
| 4403 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4404 | // avoid null check if we know obj is not null. |
| 4405 | if (instruction->MustDoNullCheck()) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4406 | __ CompareAndBranchIfZero(obj, slow_path->GetExitLabel()); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4407 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4408 | // Compare the class of `obj` with `cls`. |
| 4409 | __ LoadFromOffset(kLoadWord, temp, obj, class_offset); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4410 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4411 | __ cmp(temp, ShifterOperand(cls)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4412 | // The checkcast succeeds if the classes are equal (fast path). |
| 4413 | // Otherwise, we need to go into the slow path to check the types. |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4414 | __ b(slow_path->GetEntryLabel(), NE); |
| 4415 | __ Bind(slow_path->GetExitLabel()); |
| 4416 | } |
| 4417 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4418 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4419 | LocationSummary* locations = |
| 4420 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4421 | InvokeRuntimeCallingConvention calling_convention; |
| 4422 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4423 | } |
| 4424 | |
| 4425 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4426 | codegen_->InvokeRuntime(instruction->IsEnter() |
| 4427 | ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject), |
| 4428 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 4429 | instruction->GetDexPc(), |
| 4430 | nullptr); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4431 | } |
| 4432 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4433 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 4434 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 4435 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 4436 | |
| 4437 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 4438 | LocationSummary* locations = |
| 4439 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4440 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 4441 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 4442 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4443 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4444 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4445 | } |
| 4446 | |
| 4447 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 4448 | HandleBitwiseOperation(instruction); |
| 4449 | } |
| 4450 | |
| 4451 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 4452 | HandleBitwiseOperation(instruction); |
| 4453 | } |
| 4454 | |
| 4455 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 4456 | HandleBitwiseOperation(instruction); |
| 4457 | } |
| 4458 | |
| 4459 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 4460 | LocationSummary* locations = instruction->GetLocations(); |
| 4461 | |
| 4462 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4463 | Register first = locations->InAt(0).AsRegister<Register>(); |
| 4464 | Register second = locations->InAt(1).AsRegister<Register>(); |
| 4465 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4466 | if (instruction->IsAnd()) { |
| 4467 | __ and_(out, first, ShifterOperand(second)); |
| 4468 | } else if (instruction->IsOr()) { |
| 4469 | __ orr(out, first, ShifterOperand(second)); |
| 4470 | } else { |
| 4471 | DCHECK(instruction->IsXor()); |
| 4472 | __ eor(out, first, ShifterOperand(second)); |
| 4473 | } |
| 4474 | } else { |
| 4475 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 4476 | Location first = locations->InAt(0); |
| 4477 | Location second = locations->InAt(1); |
| 4478 | Location out = locations->Out(); |
| 4479 | if (instruction->IsAnd()) { |
| 4480 | __ and_(out.AsRegisterPairLow<Register>(), |
| 4481 | first.AsRegisterPairLow<Register>(), |
| 4482 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 4483 | __ and_(out.AsRegisterPairHigh<Register>(), |
| 4484 | first.AsRegisterPairHigh<Register>(), |
| 4485 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 4486 | } else if (instruction->IsOr()) { |
| 4487 | __ orr(out.AsRegisterPairLow<Register>(), |
| 4488 | first.AsRegisterPairLow<Register>(), |
| 4489 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 4490 | __ orr(out.AsRegisterPairHigh<Register>(), |
| 4491 | first.AsRegisterPairHigh<Register>(), |
| 4492 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 4493 | } else { |
| 4494 | DCHECK(instruction->IsXor()); |
| 4495 | __ eor(out.AsRegisterPairLow<Register>(), |
| 4496 | first.AsRegisterPairLow<Register>(), |
| 4497 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 4498 | __ eor(out.AsRegisterPairHigh<Register>(), |
| 4499 | first.AsRegisterPairHigh<Register>(), |
| 4500 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 4501 | } |
| 4502 | } |
| 4503 | } |
| 4504 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4505 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 4506 | // TODO: Implement all kinds of calls: |
| 4507 | // 1) boot -> boot |
| 4508 | // 2) app -> boot |
| 4509 | // 3) app -> app |
| 4510 | // |
| 4511 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
| 4512 | |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 4513 | if (invoke->IsStringInit()) { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4514 | Register reg = temp.AsRegister<Register>(); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 4515 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4516 | __ LoadFromOffset(kLoadWord, reg, TR, invoke->GetStringInitOffset()); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 4517 | // LR = temp[offset_of_quick_compiled_code] |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4518 | __ LoadFromOffset(kLoadWord, LR, reg, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4519 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 4520 | kArmWordSize).Int32Value()); |
| 4521 | // LR() |
| 4522 | __ blx(LR); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4523 | } else if (invoke->IsRecursive()) { |
| 4524 | __ bl(GetFrameEntryLabel()); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 4525 | } else { |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 4526 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 4527 | Register method_reg; |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4528 | Register reg = temp.AsRegister<Register>(); |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 4529 | if (current_method.IsRegister()) { |
| 4530 | method_reg = current_method.AsRegister<Register>(); |
| 4531 | } else { |
| 4532 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 4533 | DCHECK(!current_method.IsValid()); |
| 4534 | method_reg = reg; |
| 4535 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 4536 | } |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4537 | // reg = current_method->dex_cache_resolved_methods_; |
| 4538 | __ LoadFromOffset( |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 4539 | kLoadWord, reg, method_reg, ArtMethod::DexCacheResolvedMethodsOffset().Int32Value()); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4540 | // reg = reg[index_in_cache] |
| 4541 | __ LoadFromOffset( |
| 4542 | kLoadWord, reg, reg, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex())); |
| 4543 | // LR = reg[offset_of_quick_compiled_code] |
| 4544 | __ LoadFromOffset(kLoadWord, LR, reg, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4545 | kArmWordSize).Int32Value()); |
| 4546 | // LR() |
| 4547 | __ blx(LR); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 4548 | } |
| 4549 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 4550 | DCHECK(!IsLeafMethod()); |
| 4551 | } |
| 4552 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4553 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) { |
| 4554 | // Nothing to do, this should be removed during prepare for register allocator. |
| 4555 | UNUSED(instruction); |
| 4556 | LOG(FATAL) << "Unreachable"; |
| 4557 | } |
| 4558 | |
| 4559 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) { |
| 4560 | // Nothing to do, this should be removed during prepare for register allocator. |
| 4561 | UNUSED(instruction); |
| 4562 | LOG(FATAL) << "Unreachable"; |
| 4563 | } |
| 4564 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 4565 | void LocationsBuilderARM::VisitFakeString(HFakeString* instruction) { |
| 4566 | DCHECK(codegen_->IsBaseline()); |
| 4567 | LocationSummary* locations = |
| 4568 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4569 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 4570 | } |
| 4571 | |
| 4572 | void InstructionCodeGeneratorARM::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 4573 | DCHECK(codegen_->IsBaseline()); |
| 4574 | // Will be generated at use site. |
| 4575 | } |
| 4576 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4577 | #undef __ |
| 4578 | #undef QUICK_ENTRY_POINT |
| 4579 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 4580 | } // namespace arm |
| 4581 | } // namespace art |