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); |
| 35 | |
| 36 | class InvokeDexCallingConvention : public CallingConvention<Register> { |
| 37 | public: |
| 38 | InvokeDexCallingConvention() |
| 39 | : CallingConvention(kParameterCoreRegisters, kParameterCoreRegistersLength) {} |
| 40 | |
| 41 | RegisterPair GetRegisterPairAt(size_t argument_index) { |
| 42 | DCHECK_LT(argument_index + 1, GetNumberOfRegisters()); |
| 43 | return kParameterCorePairRegisters[argument_index]; |
| 44 | } |
| 45 | |
| 46 | private: |
| 47 | DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConvention); |
| 48 | }; |
| 49 | |
| 50 | class InvokeDexCallingConventionVisitor { |
| 51 | public: |
| 52 | InvokeDexCallingConventionVisitor() : gp_index_(0) {} |
| 53 | |
| 54 | Location GetNextLocation(Primitive::Type type); |
| 55 | |
| 56 | private: |
| 57 | InvokeDexCallingConvention calling_convention; |
| 58 | uint32_t gp_index_; |
| 59 | |
| 60 | DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConventionVisitor); |
| 61 | }; |
| 62 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 63 | class ParallelMoveResolverARM : public ParallelMoveResolver { |
| 64 | public: |
| 65 | ParallelMoveResolverARM(ArenaAllocator* allocator, CodeGeneratorARM* codegen) |
| 66 | : ParallelMoveResolver(allocator), codegen_(codegen) {} |
| 67 | |
| 68 | virtual void EmitMove(size_t index) OVERRIDE; |
| 69 | virtual void EmitSwap(size_t index) OVERRIDE; |
| 70 | virtual void SpillScratch(int reg) OVERRIDE; |
| 71 | virtual void RestoreScratch(int reg) OVERRIDE; |
| 72 | |
| 73 | ArmAssembler* GetAssembler() const; |
| 74 | |
| 75 | private: |
| 76 | void Exchange(Register reg, int mem); |
| 77 | void Exchange(int mem1, int mem2); |
| 78 | |
| 79 | CodeGeneratorARM* const codegen_; |
| 80 | |
| 81 | DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverARM); |
| 82 | }; |
| 83 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 84 | class LocationsBuilderARM : public HGraphVisitor { |
| 85 | public: |
Roland Levillain | 5799fc0 | 2014-09-25 12:15:20 +0100 | [diff] [blame^] | 86 | LocationsBuilderARM(HGraph* graph, CodeGeneratorARM* codegen) |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 87 | : HGraphVisitor(graph), codegen_(codegen) {} |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 88 | |
| 89 | #define DECLARE_VISIT_INSTRUCTION(name) \ |
| 90 | virtual void Visit##name(H##name* instr); |
| 91 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 92 | FOR_EACH_CONCRETE_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 93 | |
| 94 | #undef DECLARE_VISIT_INSTRUCTION |
| 95 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 96 | void HandleInvoke(HInvoke* invoke); |
| 97 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 98 | private: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 99 | CodeGeneratorARM* const codegen_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 100 | InvokeDexCallingConventionVisitor parameter_visitor_; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 101 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 102 | DISALLOW_COPY_AND_ASSIGN(LocationsBuilderARM); |
| 103 | }; |
| 104 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 105 | class InstructionCodeGeneratorARM : public HGraphVisitor { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 106 | public: |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 107 | InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 108 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 109 | #define DECLARE_VISIT_INSTRUCTION(name) \ |
| 110 | virtual void Visit##name(H##name* instr); |
| 111 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 112 | FOR_EACH_CONCRETE_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 113 | |
| 114 | #undef DECLARE_VISIT_INSTRUCTION |
| 115 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 116 | ArmAssembler* GetAssembler() const { return assembler_; } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 117 | void LoadCurrentMethod(Register reg); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 118 | |
| 119 | private: |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 120 | ArmAssembler* const assembler_; |
| 121 | CodeGeneratorARM* const codegen_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 122 | |
| 123 | DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorARM); |
| 124 | }; |
| 125 | |
| 126 | class CodeGeneratorARM : public CodeGenerator { |
| 127 | public: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 128 | explicit CodeGeneratorARM(HGraph* graph); |
Nicolas Geoffray | 8a16d97 | 2014-09-11 10:30:02 +0100 | [diff] [blame] | 129 | virtual ~CodeGeneratorARM() {} |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 130 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 131 | virtual void GenerateFrameEntry() OVERRIDE; |
| 132 | virtual void GenerateFrameExit() OVERRIDE; |
| 133 | virtual void Bind(Label* label) OVERRIDE; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 134 | virtual void Move(HInstruction* instruction, Location location, HInstruction* move_for) OVERRIDE; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 135 | virtual void SaveCoreRegister(Location stack_location, uint32_t reg_id) OVERRIDE; |
| 136 | virtual void RestoreCoreRegister(Location stack_location, uint32_t reg_id) OVERRIDE; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 137 | |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 138 | virtual size_t GetWordSize() const OVERRIDE { |
| 139 | return kArmWordSize; |
| 140 | } |
| 141 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 142 | virtual size_t FrameEntrySpillSize() const OVERRIDE; |
| 143 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 144 | virtual HGraphVisitor* GetLocationBuilder() OVERRIDE { |
| 145 | return &location_builder_; |
| 146 | } |
| 147 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 148 | virtual HGraphVisitor* GetInstructionVisitor() OVERRIDE { |
| 149 | return &instruction_visitor_; |
| 150 | } |
| 151 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 152 | virtual ArmAssembler* GetAssembler() OVERRIDE { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 153 | return &assembler_; |
| 154 | } |
| 155 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 156 | virtual void SetupBlockedRegisters(bool* blocked_registers) const OVERRIDE; |
| 157 | virtual ManagedRegister AllocateFreeRegister( |
| 158 | Primitive::Type type, bool* blocked_registers) const OVERRIDE; |
| 159 | virtual size_t GetNumberOfRegisters() const OVERRIDE; |
| 160 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 161 | virtual Location GetStackLocation(HLoadLocal* load) const OVERRIDE; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 162 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 163 | virtual size_t GetNumberOfCoreRegisters() const OVERRIDE { |
| 164 | return kNumberOfCoreRegisters; |
| 165 | } |
| 166 | |
| 167 | virtual size_t GetNumberOfFloatingPointRegisters() const OVERRIDE { |
| 168 | return kNumberOfDRegisters; |
| 169 | } |
| 170 | |
| 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_ |