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 | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 22 | #include "utils/arm/assembler_arm.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 23 | |
| 24 | namespace art { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 25 | namespace arm { |
| 26 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 27 | class CodeGeneratorARM; |
| 28 | |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 29 | static constexpr size_t kArmWordSize = 4; |
| 30 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 31 | static constexpr Register kParameterCoreRegisters[] = { R1, R2, R3 }; |
| 32 | static constexpr RegisterPair kParameterCorePairRegisters[] = { R1_R2, R2_R3 }; |
| 33 | static constexpr size_t kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters); |
| 34 | |
| 35 | class InvokeDexCallingConvention : public CallingConvention<Register> { |
| 36 | public: |
| 37 | InvokeDexCallingConvention() |
| 38 | : CallingConvention(kParameterCoreRegisters, kParameterCoreRegistersLength) {} |
| 39 | |
| 40 | RegisterPair GetRegisterPairAt(size_t argument_index) { |
| 41 | DCHECK_LT(argument_index + 1, GetNumberOfRegisters()); |
| 42 | return kParameterCorePairRegisters[argument_index]; |
| 43 | } |
| 44 | |
| 45 | private: |
| 46 | DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConvention); |
| 47 | }; |
| 48 | |
| 49 | class InvokeDexCallingConventionVisitor { |
| 50 | public: |
| 51 | InvokeDexCallingConventionVisitor() : gp_index_(0) {} |
| 52 | |
| 53 | Location GetNextLocation(Primitive::Type type); |
| 54 | |
| 55 | private: |
| 56 | InvokeDexCallingConvention calling_convention; |
| 57 | uint32_t gp_index_; |
| 58 | |
| 59 | DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConventionVisitor); |
| 60 | }; |
| 61 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 62 | class LocationsBuilderARM : public HGraphVisitor { |
| 63 | public: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 64 | explicit LocationsBuilderARM(HGraph* graph, CodeGeneratorARM* codegen) |
| 65 | : HGraphVisitor(graph), codegen_(codegen) {} |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 66 | |
| 67 | #define DECLARE_VISIT_INSTRUCTION(name) \ |
| 68 | virtual void Visit##name(H##name* instr); |
| 69 | |
| 70 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 71 | |
| 72 | #undef DECLARE_VISIT_INSTRUCTION |
| 73 | |
| 74 | private: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 75 | CodeGeneratorARM* const codegen_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 76 | InvokeDexCallingConventionVisitor parameter_visitor_; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 77 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 78 | DISALLOW_COPY_AND_ASSIGN(LocationsBuilderARM); |
| 79 | }; |
| 80 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 81 | class InstructionCodeGeneratorARM : public HGraphVisitor { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 82 | public: |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 83 | InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 84 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 85 | #define DECLARE_VISIT_INSTRUCTION(name) \ |
| 86 | virtual void Visit##name(H##name* instr); |
| 87 | |
| 88 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 89 | |
| 90 | #undef DECLARE_VISIT_INSTRUCTION |
| 91 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 92 | ArmAssembler* GetAssembler() const { return assembler_; } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 93 | void LoadCurrentMethod(Register reg); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 94 | |
| 95 | private: |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 96 | ArmAssembler* const assembler_; |
| 97 | CodeGeneratorARM* const codegen_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 98 | |
| 99 | DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorARM); |
| 100 | }; |
| 101 | |
| 102 | class CodeGeneratorARM : public CodeGenerator { |
| 103 | public: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 104 | explicit CodeGeneratorARM(HGraph* graph); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 105 | virtual ~CodeGeneratorARM() { } |
| 106 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 107 | virtual void GenerateFrameEntry() OVERRIDE; |
| 108 | virtual void GenerateFrameExit() OVERRIDE; |
| 109 | virtual void Bind(Label* label) OVERRIDE; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 110 | virtual void Move(HInstruction* instruction, Location location, HInstruction* move_for) OVERRIDE; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 111 | |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 112 | virtual size_t GetWordSize() const OVERRIDE { |
| 113 | return kArmWordSize; |
| 114 | } |
| 115 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 116 | virtual HGraphVisitor* GetLocationBuilder() OVERRIDE { |
| 117 | return &location_builder_; |
| 118 | } |
| 119 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 120 | virtual HGraphVisitor* GetInstructionVisitor() OVERRIDE { |
| 121 | return &instruction_visitor_; |
| 122 | } |
| 123 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 124 | virtual ArmAssembler* GetAssembler() OVERRIDE { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 125 | return &assembler_; |
| 126 | } |
| 127 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 128 | virtual void SetupBlockedRegisters(bool* blocked_registers) const OVERRIDE; |
| 129 | virtual ManagedRegister AllocateFreeRegister( |
| 130 | Primitive::Type type, bool* blocked_registers) const OVERRIDE; |
| 131 | virtual size_t GetNumberOfRegisters() const OVERRIDE; |
| 132 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 133 | int32_t GetStackSlot(HLocal* local) const; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 134 | virtual Location GetStackLocation(HLoadLocal* load) const OVERRIDE; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 135 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 136 | virtual size_t GetNumberOfCoreRegisters() const OVERRIDE { |
| 137 | return kNumberOfCoreRegisters; |
| 138 | } |
| 139 | |
| 140 | virtual size_t GetNumberOfFloatingPointRegisters() const OVERRIDE { |
| 141 | return kNumberOfDRegisters; |
| 142 | } |
| 143 | |
| 144 | virtual void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE; |
| 145 | virtual void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE; |
| 146 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 147 | private: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 148 | // Helper method to move a 32bits value between two locations. |
| 149 | void Move32(Location destination, Location source); |
| 150 | // Helper method to move a 64bits value between two locations. |
| 151 | void Move64(Location destination, Location source); |
| 152 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 153 | LocationsBuilderARM location_builder_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 154 | InstructionCodeGeneratorARM instruction_visitor_; |
| 155 | ArmAssembler assembler_; |
| 156 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 157 | DISALLOW_COPY_AND_ASSIGN(CodeGeneratorARM); |
| 158 | }; |
| 159 | |
| 160 | } // namespace arm |
| 161 | } // namespace art |
| 162 | |
| 163 | #endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_ARM_H_ |