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