Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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_SRC_COMPILER_LLVM_METHOD_COMPILER_H_ |
| 18 | #define ART_SRC_COMPILER_LLVM_METHOD_COMPILER_H_ |
| 19 | |
Logan Chien | fca7e87 | 2011-12-20 20:08:22 +0800 | [diff] [blame] | 20 | #include "backend_types.h" |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 21 | #include "constants.h" |
| 22 | #include "dex_file.h" |
| 23 | #include "dex_instruction.h" |
| 24 | #include "object_utils.h" |
| 25 | |
| 26 | #include <llvm/Support/IRBuilder.h> |
| 27 | |
| 28 | #include <vector> |
| 29 | |
| 30 | #include <stdint.h> |
| 31 | |
| 32 | |
| 33 | namespace art { |
| 34 | class ClassLinker; |
| 35 | class ClassLoader; |
| 36 | class CompiledMethod; |
| 37 | class Compiler; |
| 38 | class DexCache; |
| 39 | } |
| 40 | |
| 41 | |
| 42 | namespace llvm { |
| 43 | class AllocaInst; |
| 44 | class BasicBlock; |
| 45 | class Function; |
| 46 | class FunctionType; |
| 47 | class LLVMContext; |
| 48 | class Module; |
| 49 | class Type; |
| 50 | } |
| 51 | |
| 52 | |
| 53 | namespace art { |
| 54 | namespace compiler_llvm { |
| 55 | |
| 56 | class CompilerLLVM; |
| 57 | class IRBuilder; |
| 58 | |
| 59 | class MethodCompiler { |
| 60 | private: |
Logan Chien | 8342616 | 2011-12-09 09:29:50 +0800 | [diff] [blame] | 61 | InstructionSet insn_set_; |
| 62 | Compiler* compiler_; |
| 63 | compiler_llvm::CompilerLLVM* compiler_llvm_; |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 64 | |
Logan Chien | 8342616 | 2011-12-09 09:29:50 +0800 | [diff] [blame] | 65 | ClassLinker* class_linker_; |
| 66 | ClassLoader const* class_loader_; |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 67 | |
Logan Chien | 8342616 | 2011-12-09 09:29:50 +0800 | [diff] [blame] | 68 | DexFile const* dex_file_; |
| 69 | DexCache* dex_cache_; |
| 70 | DexFile::CodeItem const* code_item_; |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 71 | |
Logan Chien | 8342616 | 2011-12-09 09:29:50 +0800 | [diff] [blame] | 72 | Method* method_; |
| 73 | MethodHelper method_helper_; |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 74 | |
| 75 | uint32_t method_idx_; |
| 76 | uint32_t access_flags_; |
| 77 | |
| 78 | llvm::Module* module_; |
| 79 | llvm::LLVMContext* context_; |
| 80 | IRBuilder& irb_; |
| 81 | llvm::Function* func_; |
| 82 | |
| 83 | public: |
Logan Chien | 8342616 | 2011-12-09 09:29:50 +0800 | [diff] [blame] | 84 | MethodCompiler(InstructionSet insn_set, |
| 85 | Compiler* compiler, |
| 86 | ClassLinker* class_linker, |
| 87 | ClassLoader const* class_loader, |
| 88 | DexFile const* dex_file, |
| 89 | DexCache* dex_cache, |
| 90 | DexFile::CodeItem const* code_item, |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 91 | uint32_t method_idx, |
| 92 | uint32_t access_flags); |
| 93 | |
| 94 | ~MethodCompiler(); |
| 95 | |
Logan Chien | 8342616 | 2011-12-09 09:29:50 +0800 | [diff] [blame] | 96 | CompiledMethod* Compile(); |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 97 | |
| 98 | private: |
| 99 | void CreateFunction(); |
| 100 | |
| 101 | void EmitPrologue(); |
| 102 | void EmitInstructions(); |
Logan Chien | 8342616 | 2011-12-09 09:29:50 +0800 | [diff] [blame] | 103 | void EmitInstruction(uint32_t dex_pc, Instruction const* insn); |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 104 | |
Logan Chien | 0b82710 | 2011-12-20 19:46:14 +0800 | [diff] [blame^] | 105 | |
| 106 | // Code generation helper function |
| 107 | |
| 108 | llvm::Value* EmitLoadMethodObjectAddr(); |
| 109 | |
| 110 | llvm::FunctionType* GetFunctionType(uint32_t method_idx, bool is_static); |
| 111 | |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | |
| 115 | } // namespace compiler_llvm |
| 116 | } // namespace art |
| 117 | |
| 118 | #endif // ART_SRC_COMPILER_LLVM_METHOD_COMPILER_H_ |