blob: 626c13d3fba2bcac4246d2b5e43c71619077f212 [file] [log] [blame]
Shih-wei Liaod1fec812012-02-13 09:51:10 -08001/*
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 Chiend6e614b2012-03-01 20:57:44 +080017#ifndef ART_SRC_COMPILER_LLVM_COMPILER_LLVM_H_
18#define ART_SRC_COMPILER_LLVM_COMPILER_LLVM_H_
Shih-wei Liaod1fec812012-02-13 09:51:10 -080019
20#include "constants.h"
21#include "dex_file.h"
22#include "macros.h"
Logan Chienf7015fd2012-03-18 01:19:37 +080023#include "object.h"
Shih-wei Liaod1fec812012-02-13 09:51:10 -080024
25#include <UniquePtr.h>
26
27#include <string>
28
29namespace art {
30 class ClassLoader;
Logan Chienf04364f2012-02-10 12:01:39 +080031 class CompiledInvokeStub;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080032 class CompiledMethod;
33 class Compiler;
Logan Chien4dd96f52012-02-29 01:26:58 +080034 class OatCompilationUnit;
Logan Chienf7015fd2012-03-18 01:19:37 +080035 class Method;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080036}
37
38
39namespace llvm {
40 class Function;
41 class LLVMContext;
42 class Module;
43 class PointerType;
44 class StructType;
45 class Type;
46}
47
48
49namespace art {
50namespace compiler_llvm {
51
Logan Chien8b977d32012-02-21 19:14:55 +080052class CompilationUnit;
Logan Chienf7015fd2012-03-18 01:19:37 +080053class ElfLoader;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080054class IRBuilder;
55
56class CompilerLLVM {
57 public:
58 CompilerLLVM(Compiler* compiler, InstructionSet insn_set);
59
60 ~CompilerLLVM();
61
Logan Chien7f767612012-03-01 18:54:49 +080062 void MaterializeIfThresholdReached();
63
64 void MaterializeRemainder();
Shih-wei Liaod1fec812012-02-13 09:51:10 -080065
66 Compiler* GetCompiler() const {
67 return compiler_;
68 }
69
70 InstructionSet GetInstructionSet() const {
71 return insn_set_;
72 }
73
Logan Chienaeb53032012-03-18 02:29:38 +080074 size_t GetNumCompilationUnits() const {
75 return cunits_.size();
76 }
77
78 const CompilationUnit* GetCompilationUnit(size_t i) const {
79 return cunits_[i];
80 }
81
Logan Chien8b977d32012-02-21 19:14:55 +080082 void SetElfFileName(std::string const& filename) {
83 elf_filename_ = filename;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080084 }
85
Logan Chien8b977d32012-02-21 19:14:55 +080086 void SetBitcodeFileName(std::string const& filename) {
87 bitcode_filename_ = filename;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080088 }
89
Logan Chienf7015fd2012-03-18 01:19:37 +080090 void EnableAutoElfLoading();
91
92 bool IsAutoElfLoadingEnabled() const {
93 return (elf_loader_.get() != NULL);
94 }
95
96 const void* GetMethodCodeAddr(const CompiledMethod* cm,
97 const Method* method) const;
98
99 const Method::InvokeStub* GetMethodInvokeStubAddr(
100 const CompiledInvokeStub* cm,
101 const Method* method) const;
102
Logan Chien4dd96f52012-02-29 01:26:58 +0800103 CompiledMethod* CompileDexMethod(OatCompilationUnit* oat_compilation_unit);
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800104
Logan Chien88894ee2012-02-13 16:42:22 +0800105 CompiledMethod* CompileNativeMethod(OatCompilationUnit* oat_compilation_unit);
106
Logan Chienf04364f2012-02-10 12:01:39 +0800107 CompiledInvokeStub* CreateInvokeStub(bool is_static, char const *shorty);
108
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800109 private:
Logan Chience119062012-03-02 11:57:34 +0800110 void EnsureCompilationUnit();
Logan Chien8b977d32012-02-21 19:14:55 +0800111
Logan Chience119062012-03-02 11:57:34 +0800112 void Materialize();
Logan Chien8b977d32012-02-21 19:14:55 +0800113
Logan Chienf7015fd2012-03-18 01:19:37 +0800114 void LoadElfFromCompilationUnit(const CompilationUnit* cunit);
115
Logan Chien7f767612012-03-01 18:54:49 +0800116 bool IsBitcodeFileNameAvailable() const {
117 return !bitcode_filename_.empty();
118 }
Logan Chien8b977d32012-02-21 19:14:55 +0800119
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800120 Compiler* compiler_;
121
Logan Chien7f767612012-03-01 18:54:49 +0800122 public:
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800123 Mutex compiler_lock_;
124
Logan Chien7f767612012-03-01 18:54:49 +0800125 private:
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800126 InstructionSet insn_set_;
127
Logan Chien7f767612012-03-01 18:54:49 +0800128 CompilationUnit* curr_cunit_;
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800129
Logan Chien7f767612012-03-01 18:54:49 +0800130 std::vector<CompilationUnit*> cunits_;
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800131
Logan Chien8b977d32012-02-21 19:14:55 +0800132 std::string elf_filename_;
133
134 std::string bitcode_filename_;
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800135
Logan Chienf7015fd2012-03-18 01:19:37 +0800136 UniquePtr<ElfLoader> elf_loader_;
137
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800138 DISALLOW_COPY_AND_ASSIGN(CompilerLLVM);
139};
140
141
142} // namespace compiler_llvm
143} // namespace art
144
Logan Chiend6e614b2012-03-01 20:57:44 +0800145#endif // ART_SRC_COMPILER_LLVM_COMPILER_LLVM_H_