blob: ed35f94e2b2e5fc2b8ab6e2dd6e3ed8f286c8a22 [file] [log] [blame]
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001/*
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 Geoffray787c3072014-03-17 10:20:19 +000022#include "utils/arm/assembler_arm.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000023
24namespace art {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000025namespace arm {
26
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010027class CodeGeneratorARM;
28
Nicolas Geoffray707c8092014-04-04 10:50:14 +010029static constexpr size_t kArmWordSize = 4;
30
Nicolas Geoffraya747a392014-04-17 14:56:23 +010031static constexpr Register kParameterCoreRegisters[] = { R1, R2, R3 };
32static constexpr RegisterPair kParameterCorePairRegisters[] = { R1_R2, R2_R3 };
33static constexpr size_t kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters);
34
35class 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
49class 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 Geoffraybab4ed72014-03-11 17:53:17 +000062class LocationsBuilderARM : public HGraphVisitor {
63 public:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010064 explicit LocationsBuilderARM(HGraph* graph, CodeGeneratorARM* codegen)
65 : HGraphVisitor(graph), codegen_(codegen) {}
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000066
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 Geoffray01bc96d2014-04-11 17:43:50 +010075 CodeGeneratorARM* const codegen_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +010076 InvokeDexCallingConventionVisitor parameter_visitor_;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010077
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000078 DISALLOW_COPY_AND_ASSIGN(LocationsBuilderARM);
79};
80
Nicolas Geoffray787c3072014-03-17 10:20:19 +000081class InstructionCodeGeneratorARM : public HGraphVisitor {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000082 public:
Nicolas Geoffray4a34a422014-04-03 10:38:37 +010083 InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000084
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000085#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 Geoffray4a34a422014-04-03 10:38:37 +010092 ArmAssembler* GetAssembler() const { return assembler_; }
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000093 void LoadCurrentMethod(Register reg);
Nicolas Geoffray787c3072014-03-17 10:20:19 +000094
95 private:
Nicolas Geoffray4a34a422014-04-03 10:38:37 +010096 ArmAssembler* const assembler_;
97 CodeGeneratorARM* const codegen_;
Nicolas Geoffray787c3072014-03-17 10:20:19 +000098
99 DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorARM);
100};
101
102class CodeGeneratorARM : public CodeGenerator {
103 public:
104 explicit CodeGeneratorARM(HGraph* graph)
105 : CodeGenerator(graph),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100106 location_builder_(graph, this),
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000107 instruction_visitor_(graph, this) { }
108 virtual ~CodeGeneratorARM() { }
109
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000110 virtual void GenerateFrameEntry() OVERRIDE;
111 virtual void GenerateFrameExit() OVERRIDE;
112 virtual void Bind(Label* label) OVERRIDE;
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100113 virtual void Move(HInstruction* instruction, Location location, HInstruction* move_for) OVERRIDE;
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000114
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100115 virtual size_t GetWordSize() const OVERRIDE {
116 return kArmWordSize;
117 }
118
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000119 virtual HGraphVisitor* GetLocationBuilder() OVERRIDE {
120 return &location_builder_;
121 }
122
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000123 virtual HGraphVisitor* GetInstructionVisitor() OVERRIDE {
124 return &instruction_visitor_;
125 }
126
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100127 virtual ArmAssembler* GetAssembler() OVERRIDE {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000128 return &assembler_;
129 }
130
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100131 int32_t GetStackSlot(HLocal* local) const;
132
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000133 private:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100134 // Helper method to move a 32bits value between two locations.
135 void Move32(Location destination, Location source);
136 // Helper method to move a 64bits value between two locations.
137 void Move64(Location destination, Location source);
138
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000139 LocationsBuilderARM location_builder_;
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000140 InstructionCodeGeneratorARM instruction_visitor_;
141 ArmAssembler assembler_;
142
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000143 DISALLOW_COPY_AND_ASSIGN(CodeGeneratorARM);
144};
145
146} // namespace arm
147} // namespace art
148
149#endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_ARM_H_