blob: 8bb053ed8a2503df10628d219400af199dfc4ab2 [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
Logan Chiendf576142012-03-20 17:36:32 +080020#include "compiler.h"
Shih-wei Liaod1fec812012-02-13 09:51:10 -080021#include "dex_file.h"
Logan Chien0f0899a2012-03-23 10:48:18 +080022#include "elf_image.h"
Elliott Hughes0f3c5532012-03-30 14:51:51 -070023#include "instruction_set.h"
Shih-wei Liaod1fec812012-02-13 09:51:10 -080024#include "macros.h"
Logan Chienf7015fd2012-03-18 01:19:37 +080025#include "object.h"
Shih-wei Liaod1fec812012-02-13 09:51:10 -080026
27#include <UniquePtr.h>
28
29#include <string>
Logan Chiendf576142012-03-20 17:36:32 +080030#include <utility>
31#include <vector>
Shih-wei Liaod1fec812012-02-13 09:51:10 -080032
33namespace art {
34 class ClassLoader;
Logan Chienf04364f2012-02-10 12:01:39 +080035 class CompiledInvokeStub;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080036 class CompiledMethod;
37 class Compiler;
Logan Chien4dd96f52012-02-29 01:26:58 +080038 class OatCompilationUnit;
Logan Chienf7015fd2012-03-18 01:19:37 +080039 class Method;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080040}
41
42
43namespace llvm {
44 class Function;
45 class LLVMContext;
46 class Module;
47 class PointerType;
48 class StructType;
49 class Type;
50}
51
52
53namespace art {
54namespace compiler_llvm {
55
Logan Chien8b977d32012-02-21 19:14:55 +080056class CompilationUnit;
Logan Chienf7015fd2012-03-18 01:19:37 +080057class ElfLoader;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080058class IRBuilder;
59
60class CompilerLLVM {
61 public:
62 CompilerLLVM(Compiler* compiler, InstructionSet insn_set);
63
64 ~CompilerLLVM();
65
Logan Chien7f767612012-03-01 18:54:49 +080066 void MaterializeIfThresholdReached();
67
68 void MaterializeRemainder();
Shih-wei Liaod1fec812012-02-13 09:51:10 -080069
70 Compiler* GetCompiler() const {
71 return compiler_;
72 }
73
74 InstructionSet GetInstructionSet() const {
75 return insn_set_;
76 }
77
Logan Chienaeb53032012-03-18 02:29:38 +080078 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 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
Logan Chien937105a2012-04-02 02:37:37 +080096 const void* GetMethodCodeAddr(const CompiledMethod* cm) const;
Logan Chienf7015fd2012-03-18 01:19:37 +080097
98 const Method::InvokeStub* GetMethodInvokeStubAddr(
Logan Chien937105a2012-04-02 02:37:37 +080099 const CompiledInvokeStub* cm) const;
Logan Chienf7015fd2012-03-18 01:19:37 +0800100
Logan Chiendf576142012-03-20 17:36:32 +0800101 std::vector<ElfImage> GetElfImages() 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 bitcode_filename_;
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800133
Logan Chienf7015fd2012-03-18 01:19:37 +0800134 UniquePtr<ElfLoader> elf_loader_;
135
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800136 DISALLOW_COPY_AND_ASSIGN(CompilerLLVM);
137};
138
139
140} // namespace compiler_llvm
141} // namespace art
142
Logan Chiend6e614b2012-03-01 20:57:44 +0800143#endif // ART_SRC_COMPILER_LLVM_COMPILER_LLVM_H_