code_generator_x86.h revision 01bc96d007b67fdb7fe349232a83e4b354ce3d08
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 Geoffraynamespace x86 {
26d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
27707c809f661554713edfacf338365adca8dfd3a3Nicolas Geoffraystatic constexpr size_t kX86WordSize = 4;
28707c809f661554713edfacf338365adca8dfd3a3Nicolas Geoffray
2901bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffrayclass CodeGeneratorX86;
3001bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray
31bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffrayclass LocationsBuilderX86 : public HGraphVisitor {
32bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray public:
3301bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray  LocationsBuilderX86(HGraph* graph, CodeGeneratorX86* codegen)
3401bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray      : HGraphVisitor(graph), codegen_(codegen) {}
35bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
36bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray#define DECLARE_VISIT_INSTRUCTION(name)     \
37bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  virtual void Visit##name(H##name* instr);
38bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
39bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION)
40bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
41bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray#undef DECLARE_VISIT_INSTRUCTION
42bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
43bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray private:
4401bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray  CodeGeneratorX86* const codegen_;
4501bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray
46bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(LocationsBuilderX86);
47bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray};
48bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
49787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffrayclass InstructionCodeGeneratorX86 : public HGraphVisitor {
50d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray public:
514a34a428c6a2588e0857ef6baf88f1b73ce65958Nicolas Geoffray  InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* 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
608ccc3f5d06fd217cdaabd37e743adab2031d3720Nicolas Geoffray  void LoadCurrentMethod(Register reg);
618ccc3f5d06fd217cdaabd37e743adab2031d3720Nicolas Geoffray
624a34a428c6a2588e0857ef6baf88f1b73ce65958Nicolas Geoffray  X86Assembler* GetAssembler() const { return assembler_; }
63787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray
64787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray private:
654a34a428c6a2588e0857ef6baf88f1b73ce65958Nicolas Geoffray  X86Assembler* const assembler_;
664a34a428c6a2588e0857ef6baf88f1b73ce65958Nicolas Geoffray  CodeGeneratorX86* const codegen_;
67787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray
68787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorX86);
69787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray};
70787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray
71787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffrayclass CodeGeneratorX86 : public CodeGenerator {
72787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray public:
73787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  explicit CodeGeneratorX86(HGraph* graph)
74787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray      : CodeGenerator(graph),
7501bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray        location_builder_(graph, this),
76787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray        instruction_visitor_(graph, this) { }
77787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  virtual ~CodeGeneratorX86() { }
78787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray
79bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  virtual void GenerateFrameEntry() OVERRIDE;
80bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  virtual void GenerateFrameExit() OVERRIDE;
81bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  virtual void Bind(Label* label) OVERRIDE;
824a34a428c6a2588e0857ef6baf88f1b73ce65958Nicolas Geoffray  virtual void Move(HInstruction* instruction, Location location, HInstruction* move_for) OVERRIDE;
83bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
84707c809f661554713edfacf338365adca8dfd3a3Nicolas Geoffray  virtual size_t GetWordSize() const OVERRIDE {
85707c809f661554713edfacf338365adca8dfd3a3Nicolas Geoffray    return kX86WordSize;
86707c809f661554713edfacf338365adca8dfd3a3Nicolas Geoffray  }
87707c809f661554713edfacf338365adca8dfd3a3Nicolas Geoffray
88bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  virtual HGraphVisitor* GetLocationBuilder() OVERRIDE {
89bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    return &location_builder_;
90bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  }
91bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
92787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  virtual HGraphVisitor* GetInstructionVisitor() OVERRIDE {
93787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray    return &instruction_visitor_;
94787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  }
95787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray
96787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  virtual X86Assembler* GetAssembler() OVERRIDE {
97787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray    return &assembler_;
98787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  }
99787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray
1004a34a428c6a2588e0857ef6baf88f1b73ce65958Nicolas Geoffray  int32_t GetStackSlot(HLocal* local) const;
1014a34a428c6a2588e0857ef6baf88f1b73ce65958Nicolas Geoffray
102d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray private:
10301bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray  // Helper method to move a 32bits value between two locations.
10401bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray  void Move32(Location destination, Location source);
10501bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray  // Helper method to move a 64bits value between two locations.
10601bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray  void Move64(Location destination, Location source);
10701bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray
108bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  LocationsBuilderX86 location_builder_;
109787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  InstructionCodeGeneratorX86 instruction_visitor_;
110787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  X86Assembler assembler_;
111d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
112d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(CodeGeneratorX86);
113d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray};
114d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
115d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray}  // namespace x86
116d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray}  // namespace art
117d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
118d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#endif  // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_H_
119