code_generator_x86.h revision 787c3076635cf117eb646c5a89a9014b2072fb44
1d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray/*
2d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * Copyright (C) 2014 The Android Open Source Project
3d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray *
4d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License");
5d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * you may not use this file except in compliance with the License.
6d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * You may obtain a copy of the License at
7d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray *
8d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray *      http://www.apache.org/licenses/LICENSE-2.0
9d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray *
10d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * Unless required by applicable law or agreed to in writing, software
11d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS,
12d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * See the License for the specific language governing permissions and
14d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * limitations under the License.
15d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray */
16d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
17d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#ifndef ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_H_
18d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#define ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_H_
19d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
20d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#include "code_generator.h"
21d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#include "nodes.h"
22787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray#include "utils/x86/assembler_x86.h"
23d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
24d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffraynamespace art {
25d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
26d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffrayclass Assembler;
27d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffrayclass Label;
28d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
29d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffraynamespace x86 {
30d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
31bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffrayclass LocationsBuilderX86 : public HGraphVisitor {
32bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray public:
33bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  explicit LocationsBuilderX86(HGraph* graph) : HGraphVisitor(graph) { }
34bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
35bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray#define DECLARE_VISIT_INSTRUCTION(name)     \
36bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  virtual void Visit##name(H##name* instr);
37bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
38bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION)
39bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
40bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray#undef DECLARE_VISIT_INSTRUCTION
41bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
42bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray private:
43bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(LocationsBuilderX86);
44bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray};
45bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
46787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffrayclass InstructionCodeGeneratorX86 : public HGraphVisitor {
47d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray public:
48787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  explicit InstructionCodeGeneratorX86(HGraph* graph, CodeGenerator* codegen)
49787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray      : HGraphVisitor(graph),
50787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray        assembler_(codegen->GetAssembler()),
51787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray        codegen_(codegen) { }
52d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
53d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#define DECLARE_VISIT_INSTRUCTION(name)     \
54d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray  virtual void Visit##name(H##name* instr);
55d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
56d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray  FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION)
57d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
58d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#undef DECLARE_VISIT_INSTRUCTION
59d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
60787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  Assembler* GetAssembler() const { return assembler_; }
61787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray
62787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray private:
63787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  Assembler* const assembler_;
64787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  CodeGenerator* const codegen_;
65787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray
66787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorX86);
67787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray};
68787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray
69787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffrayclass CodeGeneratorX86 : public CodeGenerator {
70787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray public:
71787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  explicit CodeGeneratorX86(HGraph* graph)
72787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray      : CodeGenerator(graph),
73787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray        location_builder_(graph),
74787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray        instruction_visitor_(graph, this) { }
75787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  virtual ~CodeGeneratorX86() { }
76787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray
77bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray protected:
78bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  virtual void GenerateFrameEntry() OVERRIDE;
79bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  virtual void GenerateFrameExit() OVERRIDE;
80bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  virtual void Bind(Label* label) OVERRIDE;
81bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  virtual void Move(HInstruction* instruction, Location location) OVERRIDE;
82bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  virtual void Push(HInstruction* instruction, Location location) OVERRIDE;
83bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
84bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  virtual HGraphVisitor* GetLocationBuilder() OVERRIDE {
85bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    return &location_builder_;
86bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  }
87bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
88787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  virtual HGraphVisitor* GetInstructionVisitor() OVERRIDE {
89787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray    return &instruction_visitor_;
90787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  }
91787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray
92787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  virtual X86Assembler* GetAssembler() OVERRIDE {
93787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray    return &assembler_;
94787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  }
95787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray
96d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray private:
97bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  LocationsBuilderX86 location_builder_;
98787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  InstructionCodeGeneratorX86 instruction_visitor_;
99787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  X86Assembler assembler_;
100d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
101d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(CodeGeneratorX86);
102d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray};
103d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
104d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray}  // namespace x86
105d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray}  // namespace art
106d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
107d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#endif  // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_H_
108