code_generator_x86.h revision 4a34a428c6a2588e0857ef6baf88f1b73ce65958
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 Geoffraynamespace x86 {
27d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
28bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffrayclass LocationsBuilderX86 : public HGraphVisitor {
29bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray public:
30bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  explicit LocationsBuilderX86(HGraph* graph) : HGraphVisitor(graph) { }
31bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
32bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray#define DECLARE_VISIT_INSTRUCTION(name)     \
33bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  virtual void Visit##name(H##name* instr);
34bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
35bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION)
36bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
37bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray#undef DECLARE_VISIT_INSTRUCTION
38bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
39bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray private:
40bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(LocationsBuilderX86);
41bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray};
42bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
434a34a428c6a2588e0857ef6baf88f1b73ce65958Nicolas Geoffrayclass CodeGeneratorX86;
444a34a428c6a2588e0857ef6baf88f1b73ce65958Nicolas Geoffray
45787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffrayclass InstructionCodeGeneratorX86 : public HGraphVisitor {
46d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray public:
474a34a428c6a2588e0857ef6baf88f1b73ce65958Nicolas Geoffray  InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen);
48d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
49d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#define DECLARE_VISIT_INSTRUCTION(name)     \
50d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray  virtual void Visit##name(H##name* instr);
51d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
52d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray  FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION)
53d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
54d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#undef DECLARE_VISIT_INSTRUCTION
55d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
568ccc3f5d06fd217cdaabd37e743adab2031d3720Nicolas Geoffray  void LoadCurrentMethod(Register reg);
578ccc3f5d06fd217cdaabd37e743adab2031d3720Nicolas Geoffray
584a34a428c6a2588e0857ef6baf88f1b73ce65958Nicolas Geoffray  X86Assembler* GetAssembler() const { return assembler_; }
59787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray
60787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray private:
614a34a428c6a2588e0857ef6baf88f1b73ce65958Nicolas Geoffray  X86Assembler* const assembler_;
624a34a428c6a2588e0857ef6baf88f1b73ce65958Nicolas Geoffray  CodeGeneratorX86* const codegen_;
63787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray
64787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorX86);
65787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray};
66787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray
67787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffrayclass CodeGeneratorX86 : public CodeGenerator {
68787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray public:
69787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  explicit CodeGeneratorX86(HGraph* graph)
70787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray      : CodeGenerator(graph),
71787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray        location_builder_(graph),
72787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray        instruction_visitor_(graph, this) { }
73787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  virtual ~CodeGeneratorX86() { }
74787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray
75bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  virtual void GenerateFrameEntry() OVERRIDE;
76bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  virtual void GenerateFrameExit() OVERRIDE;
77bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  virtual void Bind(Label* label) OVERRIDE;
784a34a428c6a2588e0857ef6baf88f1b73ce65958Nicolas Geoffray  virtual void Move(HInstruction* instruction, Location location, HInstruction* move_for) OVERRIDE;
79bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
80bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  virtual HGraphVisitor* GetLocationBuilder() OVERRIDE {
81bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    return &location_builder_;
82bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  }
83bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
84787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  virtual HGraphVisitor* GetInstructionVisitor() OVERRIDE {
85787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray    return &instruction_visitor_;
86787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  }
87787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray
88787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  virtual X86Assembler* GetAssembler() OVERRIDE {
89787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray    return &assembler_;
90787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  }
91787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray
924a34a428c6a2588e0857ef6baf88f1b73ce65958Nicolas Geoffray  int32_t GetStackSlot(HLocal* local) const;
934a34a428c6a2588e0857ef6baf88f1b73ce65958Nicolas Geoffray
94d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray private:
95bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  LocationsBuilderX86 location_builder_;
96787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  InstructionCodeGeneratorX86 instruction_visitor_;
97787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  X86Assembler assembler_;
98d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
99d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(CodeGeneratorX86);
100d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray};
101d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
102d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray}  // namespace x86
103d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray}  // namespace art
104d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
105d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#endif  // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_H_
106