blob: 505237bd550515c693d6e9e977b5eb795d8deec3 [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_X86_H_
18#define ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_H_
19
20#include "code_generator.h"
21#include "nodes.h"
Nicolas Geoffray787c3072014-03-17 10:20:19 +000022#include "utils/x86/assembler_x86.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000023
24namespace art {
25
26class Assembler;
27class Label;
28
29namespace x86 {
30
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000031class LocationsBuilderX86 : public HGraphVisitor {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000032 public:
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000033 explicit LocationsBuilderX86(HGraph* graph) : HGraphVisitor(graph) { }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000034
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000035#define DECLARE_VISIT_INSTRUCTION(name) \
36 virtual void Visit##name(H##name* instr);
37
38 FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION)
39
40#undef DECLARE_VISIT_INSTRUCTION
41
42 private:
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000043 DISALLOW_COPY_AND_ASSIGN(LocationsBuilderX86);
44};
45
Nicolas Geoffray787c3072014-03-17 10:20:19 +000046class InstructionCodeGeneratorX86 : public HGraphVisitor {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000047 public:
Nicolas Geoffray787c3072014-03-17 10:20:19 +000048 explicit InstructionCodeGeneratorX86(HGraph* graph, CodeGenerator* codegen)
49 : HGraphVisitor(graph),
50 assembler_(codegen->GetAssembler()),
51 codegen_(codegen) { }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000052
53#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 Geoffray8ccc3f52014-03-19 10:34:11 +000060 void LoadCurrentMethod(Register reg);
61
Nicolas Geoffray787c3072014-03-17 10:20:19 +000062 Assembler* GetAssembler() const { return assembler_; }
63
64 private:
65 Assembler* const assembler_;
66 CodeGenerator* const codegen_;
67
68 DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorX86);
69};
70
71class CodeGeneratorX86 : public CodeGenerator {
72 public:
73 explicit CodeGeneratorX86(HGraph* graph)
74 : CodeGenerator(graph),
75 location_builder_(graph),
76 instruction_visitor_(graph, this) { }
77 virtual ~CodeGeneratorX86() { }
78
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000079 protected:
80 virtual void GenerateFrameEntry() OVERRIDE;
81 virtual void GenerateFrameExit() OVERRIDE;
82 virtual void Bind(Label* label) OVERRIDE;
83 virtual void Move(HInstruction* instruction, Location location) OVERRIDE;
84 virtual void Push(HInstruction* instruction, Location location) OVERRIDE;
85
86 virtual HGraphVisitor* GetLocationBuilder() OVERRIDE {
87 return &location_builder_;
88 }
89
Nicolas Geoffray787c3072014-03-17 10:20:19 +000090 virtual HGraphVisitor* GetInstructionVisitor() OVERRIDE {
91 return &instruction_visitor_;
92 }
93
94 virtual X86Assembler* GetAssembler() OVERRIDE {
95 return &assembler_;
96 }
97
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000098 private:
99 LocationsBuilderX86 location_builder_;
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000100 InstructionCodeGeneratorX86 instruction_visitor_;
101 X86Assembler assembler_;
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000102
103 DISALLOW_COPY_AND_ASSIGN(CodeGeneratorX86);
104};
105
106} // namespace x86
107} // namespace art
108
109#endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_H_