blob: 3fbe63119f2baff5b7c060967251ebd3792ebdd3 [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 Geoffraybab4ed72014-03-11 17:53:17 +000031class LocationsBuilderARM : public HGraphVisitor {
32 public:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010033 explicit LocationsBuilderARM(HGraph* graph, CodeGeneratorARM* codegen)
34 : HGraphVisitor(graph), codegen_(codegen) {}
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000035
36#define DECLARE_VISIT_INSTRUCTION(name) \
37 virtual void Visit##name(H##name* instr);
38
39 FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION)
40
41#undef DECLARE_VISIT_INSTRUCTION
42
43 private:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010044 CodeGeneratorARM* const codegen_;
45
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000046 DISALLOW_COPY_AND_ASSIGN(LocationsBuilderARM);
47};
48
Nicolas Geoffray787c3072014-03-17 10:20:19 +000049class InstructionCodeGeneratorARM : public HGraphVisitor {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000050 public:
Nicolas Geoffray4a34a422014-04-03 10:38:37 +010051 InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000052
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000053#define DECLARE_VISIT_INSTRUCTION(name) \
54 virtual void Visit##name(H##name* instr);
55
56 FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION)
57
58#undef DECLARE_VISIT_INSTRUCTION
59
Nicolas Geoffray4a34a422014-04-03 10:38:37 +010060 ArmAssembler* GetAssembler() const { return assembler_; }
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000061 void LoadCurrentMethod(Register reg);
Nicolas Geoffray787c3072014-03-17 10:20:19 +000062
63 private:
Nicolas Geoffray4a34a422014-04-03 10:38:37 +010064 ArmAssembler* const assembler_;
65 CodeGeneratorARM* const codegen_;
Nicolas Geoffray787c3072014-03-17 10:20:19 +000066
67 DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorARM);
68};
69
70class CodeGeneratorARM : public CodeGenerator {
71 public:
72 explicit CodeGeneratorARM(HGraph* graph)
73 : CodeGenerator(graph),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010074 location_builder_(graph, this),
Nicolas Geoffray787c3072014-03-17 10:20:19 +000075 instruction_visitor_(graph, this) { }
76 virtual ~CodeGeneratorARM() { }
77
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000078 virtual void GenerateFrameEntry() OVERRIDE;
79 virtual void GenerateFrameExit() OVERRIDE;
80 virtual void Bind(Label* label) OVERRIDE;
Nicolas Geoffray4a34a422014-04-03 10:38:37 +010081 virtual void Move(HInstruction* instruction, Location location, HInstruction* move_for) OVERRIDE;
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000082
Nicolas Geoffray707c8092014-04-04 10:50:14 +010083 virtual size_t GetWordSize() const OVERRIDE {
84 return kArmWordSize;
85 }
86
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000087 virtual HGraphVisitor* GetLocationBuilder() OVERRIDE {
88 return &location_builder_;
89 }
90
Nicolas Geoffray787c3072014-03-17 10:20:19 +000091 virtual HGraphVisitor* GetInstructionVisitor() OVERRIDE {
92 return &instruction_visitor_;
93 }
94
Nicolas Geoffray4a34a422014-04-03 10:38:37 +010095 virtual ArmAssembler* GetAssembler() OVERRIDE {
Nicolas Geoffray787c3072014-03-17 10:20:19 +000096 return &assembler_;
97 }
98
Nicolas Geoffray4a34a422014-04-03 10:38:37 +010099 int32_t GetStackSlot(HLocal* local) const;
100
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000101 private:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100102 // Helper method to move a 32bits value between two locations.
103 void Move32(Location destination, Location source);
104 // Helper method to move a 64bits value between two locations.
105 void Move64(Location destination, Location source);
106
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000107 LocationsBuilderARM location_builder_;
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000108 InstructionCodeGeneratorARM instruction_visitor_;
109 ArmAssembler assembler_;
110
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000111 DISALLOW_COPY_AND_ASSIGN(CodeGeneratorARM);
112};
113
114} // namespace arm
115} // namespace art
116
117#endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_ARM_H_