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