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 | |
Logan Chien | d6c239a | 2011-12-23 15:11:45 +0800 | [diff] [blame^] | 83 | llvm::BasicBlock* prologue_; |
| 84 | |
| 85 | std::vector<llvm::BasicBlock*> basic_blocks_; |
| 86 | |
| 87 | |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 88 | public: |
Logan Chien | 8342616 | 2011-12-09 09:29:50 +0800 | [diff] [blame] | 89 | MethodCompiler(InstructionSet insn_set, |
| 90 | Compiler* compiler, |
| 91 | ClassLinker* class_linker, |
| 92 | ClassLoader const* class_loader, |
| 93 | DexFile const* dex_file, |
| 94 | DexCache* dex_cache, |
| 95 | DexFile::CodeItem const* code_item, |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 96 | uint32_t method_idx, |
| 97 | uint32_t access_flags); |
| 98 | |
| 99 | ~MethodCompiler(); |
| 100 | |
Logan Chien | 8342616 | 2011-12-09 09:29:50 +0800 | [diff] [blame] | 101 | CompiledMethod* Compile(); |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 102 | |
| 103 | private: |
| 104 | void CreateFunction(); |
| 105 | |
| 106 | void EmitPrologue(); |
| 107 | void EmitInstructions(); |
Logan Chien | 8342616 | 2011-12-09 09:29:50 +0800 | [diff] [blame] | 108 | void EmitInstruction(uint32_t dex_pc, Instruction const* insn); |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 109 | |
Logan Chien | 0b82710 | 2011-12-20 19:46:14 +0800 | [diff] [blame] | 110 | |
| 111 | // Code generation helper function |
| 112 | |
| 113 | llvm::Value* EmitLoadMethodObjectAddr(); |
| 114 | |
| 115 | llvm::FunctionType* GetFunctionType(uint32_t method_idx, bool is_static); |
| 116 | |
Logan Chien | d6c239a | 2011-12-23 15:11:45 +0800 | [diff] [blame^] | 117 | |
| 118 | // Basic block helper functions |
| 119 | llvm::BasicBlock* GetBasicBlock(uint32_t dex_pc); |
| 120 | |
| 121 | llvm::BasicBlock* GetNextBasicBlock(uint32_t dex_pc); |
| 122 | |
| 123 | llvm::BasicBlock* CreateBasicBlockWithDexPC(uint32_t dex_pc, |
| 124 | char const* postfix = NULL); |
| 125 | |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | |
| 129 | } // namespace compiler_llvm |
| 130 | } // namespace art |
| 131 | |
| 132 | #endif // ART_SRC_COMPILER_LLVM_METHOD_COMPILER_H_ |