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