Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* |
| 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 Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 22 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 23 | |
| 24 | namespace art { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 25 | namespace x86 { |
| 26 | |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 27 | static constexpr size_t kX86WordSize = 4; |
| 28 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 29 | class CodeGeneratorX86; |
| 30 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 31 | class LocationsBuilderX86 : public HGraphVisitor { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 32 | public: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 33 | LocationsBuilderX86(HGraph* graph, CodeGeneratorX86* codegen) |
| 34 | : HGraphVisitor(graph), codegen_(codegen) {} |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 36 | #define DECLARE_VISIT_INSTRUCTION(name) \ |
| 37 | virtual void Visit##name(H##name* instr); |
| 38 | |
| 39 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 40 | |
| 41 | #undef DECLARE_VISIT_INSTRUCTION |
| 42 | |
| 43 | private: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 44 | CodeGeneratorX86* const codegen_; |
| 45 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 46 | DISALLOW_COPY_AND_ASSIGN(LocationsBuilderX86); |
| 47 | }; |
| 48 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 49 | class InstructionCodeGeneratorX86 : public HGraphVisitor { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 50 | public: |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 51 | InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 52 | |
| 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 Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 60 | void LoadCurrentMethod(Register reg); |
| 61 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 62 | X86Assembler* GetAssembler() const { return assembler_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 63 | |
| 64 | private: |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 65 | X86Assembler* const assembler_; |
| 66 | CodeGeneratorX86* const codegen_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 67 | |
| 68 | DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorX86); |
| 69 | }; |
| 70 | |
| 71 | class CodeGeneratorX86 : public CodeGenerator { |
| 72 | public: |
| 73 | explicit CodeGeneratorX86(HGraph* graph) |
| 74 | : CodeGenerator(graph), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 75 | location_builder_(graph, this), |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 76 | instruction_visitor_(graph, this) { } |
| 77 | virtual ~CodeGeneratorX86() { } |
| 78 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 79 | virtual void GenerateFrameEntry() OVERRIDE; |
| 80 | virtual void GenerateFrameExit() OVERRIDE; |
| 81 | virtual void Bind(Label* label) OVERRIDE; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 82 | virtual void Move(HInstruction* instruction, Location location, HInstruction* move_for) OVERRIDE; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 83 | |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 84 | virtual size_t GetWordSize() const OVERRIDE { |
| 85 | return kX86WordSize; |
| 86 | } |
| 87 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 88 | virtual HGraphVisitor* GetLocationBuilder() OVERRIDE { |
| 89 | return &location_builder_; |
| 90 | } |
| 91 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 92 | virtual HGraphVisitor* GetInstructionVisitor() OVERRIDE { |
| 93 | return &instruction_visitor_; |
| 94 | } |
| 95 | |
| 96 | virtual X86Assembler* GetAssembler() OVERRIDE { |
| 97 | return &assembler_; |
| 98 | } |
| 99 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 100 | int32_t GetStackSlot(HLocal* local) const; |
| 101 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 102 | private: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 103 | // Helper method to move a 32bits value between two locations. |
| 104 | void Move32(Location destination, Location source); |
| 105 | // Helper method to move a 64bits value between two locations. |
| 106 | void Move64(Location destination, Location source); |
| 107 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 108 | LocationsBuilderX86 location_builder_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 109 | InstructionCodeGeneratorX86 instruction_visitor_; |
| 110 | X86Assembler assembler_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 111 | |
| 112 | DISALLOW_COPY_AND_ASSIGN(CodeGeneratorX86); |
| 113 | }; |
| 114 | |
| 115 | } // namespace x86 |
| 116 | } // namespace art |
| 117 | |
| 118 | #endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_H_ |