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 | |
Logan Chien | d6e614b | 2012-03-01 20:57:44 +0800 | [diff] [blame] | 17 | #ifndef ART_SRC_COMPILER_LLVM_COMPILER_LLVM_H_ |
| 18 | #define ART_SRC_COMPILER_LLVM_COMPILER_LLVM_H_ |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 19 | |
Logan Chien | df57614 | 2012-03-20 17:36:32 +0800 | [diff] [blame] | 20 | #include "compiler.h" |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 21 | #include "dex_file.h" |
Logan Chien | 0f0899a | 2012-03-23 10:48:18 +0800 | [diff] [blame] | 22 | #include "elf_image.h" |
Elliott Hughes | 0f3c553 | 2012-03-30 14:51:51 -0700 | [diff] [blame] | 23 | #include "instruction_set.h" |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 24 | #include "macros.h" |
Logan Chien | f7015fd | 2012-03-18 01:19:37 +0800 | [diff] [blame] | 25 | #include "object.h" |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 26 | |
| 27 | #include <UniquePtr.h> |
| 28 | |
| 29 | #include <string> |
Logan Chien | df57614 | 2012-03-20 17:36:32 +0800 | [diff] [blame] | 30 | #include <utility> |
| 31 | #include <vector> |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 32 | |
| 33 | namespace art { |
| 34 | class ClassLoader; |
Logan Chien | f04364f | 2012-02-10 12:01:39 +0800 | [diff] [blame] | 35 | class CompiledInvokeStub; |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 36 | class CompiledMethod; |
| 37 | class Compiler; |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 38 | class OatCompilationUnit; |
Logan Chien | f7015fd | 2012-03-18 01:19:37 +0800 | [diff] [blame] | 39 | class Method; |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | |
| 43 | namespace llvm { |
| 44 | class Function; |
| 45 | class LLVMContext; |
| 46 | class Module; |
| 47 | class PointerType; |
| 48 | class StructType; |
| 49 | class Type; |
| 50 | } |
| 51 | |
| 52 | |
| 53 | namespace art { |
| 54 | namespace compiler_llvm { |
| 55 | |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 56 | class CompilationUnit; |
Logan Chien | f7015fd | 2012-03-18 01:19:37 +0800 | [diff] [blame] | 57 | class ElfLoader; |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 58 | class IRBuilder; |
| 59 | |
| 60 | class CompilerLLVM { |
| 61 | public: |
| 62 | CompilerLLVM(Compiler* compiler, InstructionSet insn_set); |
| 63 | |
| 64 | ~CompilerLLVM(); |
| 65 | |
Logan Chien | 7f76761 | 2012-03-01 18:54:49 +0800 | [diff] [blame] | 66 | void MaterializeIfThresholdReached(); |
| 67 | |
| 68 | void MaterializeRemainder(); |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 69 | |
| 70 | Compiler* GetCompiler() const { |
| 71 | return compiler_; |
| 72 | } |
| 73 | |
| 74 | InstructionSet GetInstructionSet() const { |
| 75 | return insn_set_; |
| 76 | } |
| 77 | |
Logan Chien | aeb5303 | 2012-03-18 02:29:38 +0800 | [diff] [blame] | 78 | size_t GetNumCompilationUnits() const { |
| 79 | return cunits_.size(); |
| 80 | } |
| 81 | |
| 82 | const CompilationUnit* GetCompilationUnit(size_t i) const { |
| 83 | return cunits_[i]; |
| 84 | } |
| 85 | |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 86 | void SetBitcodeFileName(std::string const& filename) { |
| 87 | bitcode_filename_ = filename; |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 88 | } |
| 89 | |
Logan Chien | f7015fd | 2012-03-18 01:19:37 +0800 | [diff] [blame] | 90 | void EnableAutoElfLoading(); |
| 91 | |
| 92 | bool IsAutoElfLoadingEnabled() const { |
| 93 | return (elf_loader_.get() != NULL); |
| 94 | } |
| 95 | |
Logan Chien | 937105a | 2012-04-02 02:37:37 +0800 | [diff] [blame] | 96 | const void* GetMethodCodeAddr(const CompiledMethod* cm) const; |
Logan Chien | f7015fd | 2012-03-18 01:19:37 +0800 | [diff] [blame] | 97 | |
| 98 | const Method::InvokeStub* GetMethodInvokeStubAddr( |
Logan Chien | 937105a | 2012-04-02 02:37:37 +0800 | [diff] [blame] | 99 | const CompiledInvokeStub* cm) const; |
Logan Chien | f7015fd | 2012-03-18 01:19:37 +0800 | [diff] [blame] | 100 | |
Logan Chien | df57614 | 2012-03-20 17:36:32 +0800 | [diff] [blame] | 101 | std::vector<ElfImage> GetElfImages() const; |
| 102 | |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 103 | CompiledMethod* CompileDexMethod(OatCompilationUnit* oat_compilation_unit); |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 104 | |
Logan Chien | 88894ee | 2012-02-13 16:42:22 +0800 | [diff] [blame] | 105 | CompiledMethod* CompileNativeMethod(OatCompilationUnit* oat_compilation_unit); |
| 106 | |
Logan Chien | f04364f | 2012-02-10 12:01:39 +0800 | [diff] [blame] | 107 | CompiledInvokeStub* CreateInvokeStub(bool is_static, char const *shorty); |
| 108 | |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 109 | private: |
Logan Chien | ce11906 | 2012-03-02 11:57:34 +0800 | [diff] [blame] | 110 | void EnsureCompilationUnit(); |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 111 | |
Logan Chien | ce11906 | 2012-03-02 11:57:34 +0800 | [diff] [blame] | 112 | void Materialize(); |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 113 | |
Logan Chien | f7015fd | 2012-03-18 01:19:37 +0800 | [diff] [blame] | 114 | void LoadElfFromCompilationUnit(const CompilationUnit* cunit); |
| 115 | |
Logan Chien | 7f76761 | 2012-03-01 18:54:49 +0800 | [diff] [blame] | 116 | bool IsBitcodeFileNameAvailable() const { |
| 117 | return !bitcode_filename_.empty(); |
| 118 | } |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 119 | |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 120 | Compiler* compiler_; |
| 121 | |
Logan Chien | 7f76761 | 2012-03-01 18:54:49 +0800 | [diff] [blame] | 122 | public: |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 123 | Mutex compiler_lock_; |
| 124 | |
Logan Chien | 7f76761 | 2012-03-01 18:54:49 +0800 | [diff] [blame] | 125 | private: |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 126 | InstructionSet insn_set_; |
| 127 | |
Logan Chien | 7f76761 | 2012-03-01 18:54:49 +0800 | [diff] [blame] | 128 | CompilationUnit* curr_cunit_; |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 129 | |
Logan Chien | 7f76761 | 2012-03-01 18:54:49 +0800 | [diff] [blame] | 130 | std::vector<CompilationUnit*> cunits_; |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 131 | |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 132 | std::string bitcode_filename_; |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 133 | |
Logan Chien | f7015fd | 2012-03-18 01:19:37 +0800 | [diff] [blame] | 134 | UniquePtr<ElfLoader> elf_loader_; |
| 135 | |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 136 | DISALLOW_COPY_AND_ASSIGN(CompilerLLVM); |
| 137 | }; |
| 138 | |
| 139 | |
| 140 | } // namespace compiler_llvm |
| 141 | } // namespace art |
| 142 | |
Logan Chien | d6e614b | 2012-03-01 20:57:44 +0800 | [diff] [blame] | 143 | #endif // ART_SRC_COMPILER_LLVM_COMPILER_LLVM_H_ |