blob: b9f8d0057ba01bb2a0eddda6f2ae0b4941f46dd9 [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
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 Chiendf576142012-03-20 17:36:32 +0800103 std::vector<ElfImage> GetElfImages() const;
104
Logan Chien4dd96f52012-02-29 01:26:58 +0800105 CompiledMethod* CompileDexMethod(OatCompilationUnit* oat_compilation_unit);
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800106
Logan Chien88894ee2012-02-13 16:42:22 +0800107 CompiledMethod* CompileNativeMethod(OatCompilationUnit* oat_compilation_unit);
108
Logan Chienf04364f2012-02-10 12:01:39 +0800109 CompiledInvokeStub* CreateInvokeStub(bool is_static, char const *shorty);
110
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800111 private:
Logan Chience119062012-03-02 11:57:34 +0800112 void EnsureCompilationUnit();
Logan Chien8b977d32012-02-21 19:14:55 +0800113
Logan Chience119062012-03-02 11:57:34 +0800114 void Materialize();
Logan Chien8b977d32012-02-21 19:14:55 +0800115
Logan Chienf7015fd2012-03-18 01:19:37 +0800116 void LoadElfFromCompilationUnit(const CompilationUnit* cunit);
117
Logan Chien7f767612012-03-01 18:54:49 +0800118 bool IsBitcodeFileNameAvailable() const {
119 return !bitcode_filename_.empty();
120 }
Logan Chien8b977d32012-02-21 19:14:55 +0800121
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800122 Compiler* compiler_;
123
Logan Chien7f767612012-03-01 18:54:49 +0800124 public:
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800125 Mutex compiler_lock_;
126
Logan Chien7f767612012-03-01 18:54:49 +0800127 private:
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800128 InstructionSet insn_set_;
129
Logan Chien7f767612012-03-01 18:54:49 +0800130 CompilationUnit* curr_cunit_;
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800131
Logan Chien7f767612012-03-01 18:54:49 +0800132 std::vector<CompilationUnit*> cunits_;
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800133
Logan Chien8b977d32012-02-21 19:14:55 +0800134 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_