blob: dd5044f4dc5f0960956548cbcdda4d7f7f1a4a59 [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
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000026namespace x86 {
27
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000028class LocationsBuilderX86 : public HGraphVisitor {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000029 public:
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000030 explicit LocationsBuilderX86(HGraph* graph) : HGraphVisitor(graph) { }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000031
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000032#define DECLARE_VISIT_INSTRUCTION(name) \
33 virtual void Visit##name(H##name* instr);
34
35 FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION)
36
37#undef DECLARE_VISIT_INSTRUCTION
38
39 private:
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000040 DISALLOW_COPY_AND_ASSIGN(LocationsBuilderX86);
41};
42
Nicolas Geoffray4a34a422014-04-03 10:38:37 +010043class CodeGeneratorX86;
44
Nicolas Geoffray787c3072014-03-17 10:20:19 +000045class InstructionCodeGeneratorX86 : public HGraphVisitor {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000046 public:
Nicolas Geoffray4a34a422014-04-03 10:38:37 +010047 InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000048
49#define DECLARE_VISIT_INSTRUCTION(name) \
50 virtual void Visit##name(H##name* instr);
51
52 FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION)
53
54#undef DECLARE_VISIT_INSTRUCTION
55
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000056 void LoadCurrentMethod(Register reg);
57
Nicolas Geoffray4a34a422014-04-03 10:38:37 +010058 X86Assembler* GetAssembler() const { return assembler_; }
Nicolas Geoffray787c3072014-03-17 10:20:19 +000059
60 private:
Nicolas Geoffray4a34a422014-04-03 10:38:37 +010061 X86Assembler* const assembler_;
62 CodeGeneratorX86* const codegen_;
Nicolas Geoffray787c3072014-03-17 10:20:19 +000063
64 DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorX86);
65};
66
67class CodeGeneratorX86 : public CodeGenerator {
68 public:
69 explicit CodeGeneratorX86(HGraph* graph)
70 : CodeGenerator(graph),
71 location_builder_(graph),
72 instruction_visitor_(graph, this) { }
73 virtual ~CodeGeneratorX86() { }
74
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000075 virtual void GenerateFrameEntry() OVERRIDE;
76 virtual void GenerateFrameExit() OVERRIDE;
77 virtual void Bind(Label* label) OVERRIDE;
Nicolas Geoffray4a34a422014-04-03 10:38:37 +010078 virtual void Move(HInstruction* instruction, Location location, HInstruction* move_for) OVERRIDE;
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000079
80 virtual HGraphVisitor* GetLocationBuilder() OVERRIDE {
81 return &location_builder_;
82 }
83
Nicolas Geoffray787c3072014-03-17 10:20:19 +000084 virtual HGraphVisitor* GetInstructionVisitor() OVERRIDE {
85 return &instruction_visitor_;
86 }
87
88 virtual X86Assembler* GetAssembler() OVERRIDE {
89 return &assembler_;
90 }
91
Nicolas Geoffray4a34a422014-04-03 10:38:37 +010092 int32_t GetStackSlot(HLocal* local) const;
93
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000094 private:
95 LocationsBuilderX86 location_builder_;
Nicolas Geoffray787c3072014-03-17 10:20:19 +000096 InstructionCodeGeneratorX86 instruction_visitor_;
97 X86Assembler assembler_;
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000098
99 DISALLOW_COPY_AND_ASSIGN(CodeGeneratorX86);
100};
101
102} // namespace x86
103} // namespace art
104
105#endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_H_