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 | #ifndef ART_COMPILER_OPTIMIZING_CODE_GENERATOR_ARM_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_CODE_GENERATOR_ARM_H_ |
| 19 | |
| 20 | #include "code_generator.h" |
| 21 | #include "nodes.h" |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 22 | #include "parallel_move_resolver.h" |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 23 | #include "utils/arm/assembler_thumb2.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 24 | |
| 25 | namespace art { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 26 | namespace arm { |
| 27 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 28 | class CodeGeneratorARM; |
| 29 | |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 30 | static constexpr size_t kArmWordSize = 4; |
| 31 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 32 | static constexpr Register kParameterCoreRegisters[] = { R1, R2, R3 }; |
| 33 | static constexpr RegisterPair kParameterCorePairRegisters[] = { R1_R2, R2_R3 }; |
| 34 | static constexpr size_t kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 35 | static constexpr DRegister kParameterFpuRegisters[] = { }; |
| 36 | static constexpr size_t kParameterFpuRegistersLength = 0; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 37 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 38 | class InvokeDexCallingConvention : public CallingConvention<Register, DRegister> { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 39 | public: |
| 40 | InvokeDexCallingConvention() |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 41 | : CallingConvention(kParameterCoreRegisters, |
| 42 | kParameterCoreRegistersLength, |
| 43 | kParameterFpuRegisters, |
| 44 | kParameterFpuRegistersLength) {} |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 45 | |
| 46 | RegisterPair GetRegisterPairAt(size_t argument_index) { |
| 47 | DCHECK_LT(argument_index + 1, GetNumberOfRegisters()); |
| 48 | return kParameterCorePairRegisters[argument_index]; |
| 49 | } |
| 50 | |
| 51 | private: |
| 52 | DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConvention); |
| 53 | }; |
| 54 | |
| 55 | class InvokeDexCallingConventionVisitor { |
| 56 | public: |
| 57 | InvokeDexCallingConventionVisitor() : gp_index_(0) {} |
| 58 | |
| 59 | Location GetNextLocation(Primitive::Type type); |
| 60 | |
| 61 | private: |
| 62 | InvokeDexCallingConvention calling_convention; |
| 63 | uint32_t gp_index_; |
| 64 | |
| 65 | DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConventionVisitor); |
| 66 | }; |
| 67 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 68 | class ParallelMoveResolverARM : public ParallelMoveResolver { |
| 69 | public: |
| 70 | ParallelMoveResolverARM(ArenaAllocator* allocator, CodeGeneratorARM* codegen) |
| 71 | : ParallelMoveResolver(allocator), codegen_(codegen) {} |
| 72 | |
| 73 | virtual void EmitMove(size_t index) OVERRIDE; |
| 74 | virtual void EmitSwap(size_t index) OVERRIDE; |
| 75 | virtual void SpillScratch(int reg) OVERRIDE; |
| 76 | virtual void RestoreScratch(int reg) OVERRIDE; |
| 77 | |
| 78 | ArmAssembler* GetAssembler() const; |
| 79 | |
| 80 | private: |
| 81 | void Exchange(Register reg, int mem); |
| 82 | void Exchange(int mem1, int mem2); |
| 83 | |
| 84 | CodeGeneratorARM* const codegen_; |
| 85 | |
| 86 | DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverARM); |
| 87 | }; |
| 88 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 89 | class LocationsBuilderARM : public HGraphVisitor { |
| 90 | public: |
Roland Levillain | 5799fc0 | 2014-09-25 12:15:20 +0100 | [diff] [blame] | 91 | LocationsBuilderARM(HGraph* graph, CodeGeneratorARM* codegen) |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 92 | : HGraphVisitor(graph), codegen_(codegen) {} |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 93 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 94 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 95 | virtual void Visit##name(H##name* instr); |
| 96 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 97 | FOR_EACH_CONCRETE_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 98 | |
| 99 | #undef DECLARE_VISIT_INSTRUCTION |
| 100 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 101 | void HandleInvoke(HInvoke* invoke); |
| 102 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 103 | private: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 104 | CodeGeneratorARM* const codegen_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 105 | InvokeDexCallingConventionVisitor parameter_visitor_; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 106 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 107 | DISALLOW_COPY_AND_ASSIGN(LocationsBuilderARM); |
| 108 | }; |
| 109 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 110 | class InstructionCodeGeneratorARM : public HGraphVisitor { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 111 | public: |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 112 | InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 113 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 114 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 115 | virtual void Visit##name(H##name* instr); |
| 116 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 117 | FOR_EACH_CONCRETE_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 118 | |
| 119 | #undef DECLARE_VISIT_INSTRUCTION |
| 120 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 121 | ArmAssembler* GetAssembler() const { return assembler_; } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 122 | void LoadCurrentMethod(Register reg); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 123 | |
| 124 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 125 | // Generate code for the given suspend check. If not null, `successor` |
| 126 | // is the block to branch to if the suspend check is not needed, and after |
| 127 | // the suspend call. |
| 128 | void GenerateSuspendCheck(HSuspendCheck* check, HBasicBlock* successor); |
| 129 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 130 | ArmAssembler* const assembler_; |
| 131 | CodeGeneratorARM* const codegen_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 132 | |
| 133 | DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorARM); |
| 134 | }; |
| 135 | |
| 136 | class CodeGeneratorARM : public CodeGenerator { |
| 137 | public: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 138 | explicit CodeGeneratorARM(HGraph* graph); |
Nicolas Geoffray | 8a16d97 | 2014-09-11 10:30:02 +0100 | [diff] [blame] | 139 | virtual ~CodeGeneratorARM() {} |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 140 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 141 | virtual void GenerateFrameEntry() OVERRIDE; |
| 142 | virtual void GenerateFrameExit() OVERRIDE; |
| 143 | virtual void Bind(Label* label) OVERRIDE; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 144 | virtual void Move(HInstruction* instruction, Location location, HInstruction* move_for) OVERRIDE; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 145 | virtual void SaveCoreRegister(Location stack_location, uint32_t reg_id) OVERRIDE; |
| 146 | virtual void RestoreCoreRegister(Location stack_location, uint32_t reg_id) OVERRIDE; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 147 | |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 148 | virtual size_t GetWordSize() const OVERRIDE { |
| 149 | return kArmWordSize; |
| 150 | } |
| 151 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 152 | virtual size_t FrameEntrySpillSize() const OVERRIDE; |
| 153 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 154 | virtual HGraphVisitor* GetLocationBuilder() OVERRIDE { |
| 155 | return &location_builder_; |
| 156 | } |
| 157 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 158 | virtual HGraphVisitor* GetInstructionVisitor() OVERRIDE { |
| 159 | return &instruction_visitor_; |
| 160 | } |
| 161 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 162 | virtual ArmAssembler* GetAssembler() OVERRIDE { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 163 | return &assembler_; |
| 164 | } |
| 165 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame^] | 166 | virtual void SetupBlockedRegisters() const OVERRIDE; |
| 167 | virtual Location AllocateFreeRegister(Primitive::Type type) const OVERRIDE; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 168 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 169 | virtual Location GetStackLocation(HLoadLocal* load) const OVERRIDE; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 170 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 171 | virtual void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE; |
| 172 | virtual void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE; |
| 173 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 174 | ParallelMoveResolverARM* GetMoveResolver() { |
| 175 | return &move_resolver_; |
| 176 | } |
| 177 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 178 | virtual InstructionSet GetInstructionSet() const OVERRIDE { |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 179 | return InstructionSet::kThumb2; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 180 | } |
| 181 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 182 | // Helper method to move a 32bits value between two locations. |
| 183 | void Move32(Location destination, Location source); |
| 184 | // Helper method to move a 64bits value between two locations. |
| 185 | void Move64(Location destination, Location source); |
| 186 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 187 | // Emit a write barrier. |
| 188 | void MarkGCCard(Register temp, Register card, Register object, Register value); |
| 189 | |
| 190 | private: |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 191 | LocationsBuilderARM location_builder_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 192 | InstructionCodeGeneratorARM instruction_visitor_; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 193 | ParallelMoveResolverARM move_resolver_; |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 194 | Thumb2Assembler assembler_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 195 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 196 | DISALLOW_COPY_AND_ASSIGN(CodeGeneratorARM); |
| 197 | }; |
| 198 | |
| 199 | } // namespace arm |
| 200 | } // namespace art |
| 201 | |
| 202 | #endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_ARM_H_ |