blob: f5a282a8456a63660cb3623d42f1e2e5ac98dc04 [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"
Logan Chien0f0899a2012-03-23 10:48:18 +080022#include "elf_image.h"
Shih-wei Liaod1fec812012-02-13 09:51:10 -080023#include "macros.h"
Logan Chienf7015fd2012-03-18 01:19:37 +080024#include "object.h"
Shih-wei Liaod1fec812012-02-13 09:51:10 -080025
26#include <UniquePtr.h>
27
28#include <string>
29
30namespace art {
31 class ClassLoader;
Logan Chienf04364f2012-02-10 12:01:39 +080032 class CompiledInvokeStub;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080033 class CompiledMethod;
34 class Compiler;
Logan Chien4dd96f52012-02-29 01:26:58 +080035 class OatCompilationUnit;
Logan Chienf7015fd2012-03-18 01:19:37 +080036 class Method;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080037}
38
39
40namespace llvm {
41 class Function;
42 class LLVMContext;
43 class Module;
44 class PointerType;
45 class StructType;
46 class Type;
47}
48
49
50namespace art {
51namespace compiler_llvm {
52
Logan Chien8b977d32012-02-21 19:14:55 +080053class CompilationUnit;
Logan Chienf7015fd2012-03-18 01:19:37 +080054class ElfLoader;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080055class IRBuilder;
56
57class CompilerLLVM {
58 public:
59 CompilerLLVM(Compiler* compiler, InstructionSet insn_set);
60
61 ~CompilerLLVM();
62
Logan Chien7f767612012-03-01 18:54:49 +080063 void MaterializeIfThresholdReached();
64
65 void MaterializeRemainder();
Shih-wei Liaod1fec812012-02-13 09:51:10 -080066
67 Compiler* GetCompiler() const {
68 return compiler_;
69 }
70
71 InstructionSet GetInstructionSet() const {
72 return insn_set_;
73 }
74
Logan Chienaeb53032012-03-18 02:29:38 +080075 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 Chien8b977d32012-02-21 19:14:55 +080083 void SetElfFileName(std::string const& filename) {
84 elf_filename_ = filename;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080085 }
86
Logan Chien8b977d32012-02-21 19:14:55 +080087 void SetBitcodeFileName(std::string const& filename) {
88 bitcode_filename_ = filename;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080089 }
90
Logan Chienf7015fd2012-03-18 01:19:37 +080091 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 Chien4dd96f52012-02-29 01:26:58 +0800104 CompiledMethod* CompileDexMethod(OatCompilationUnit* oat_compilation_unit);
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800105
Logan Chien88894ee2012-02-13 16:42:22 +0800106 CompiledMethod* CompileNativeMethod(OatCompilationUnit* oat_compilation_unit);
107
Logan Chienf04364f2012-02-10 12:01:39 +0800108 CompiledInvokeStub* CreateInvokeStub(bool is_static, char const *shorty);
109
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800110 private:
Logan Chience119062012-03-02 11:57:34 +0800111 void EnsureCompilationUnit();
Logan Chien8b977d32012-02-21 19:14:55 +0800112
Logan Chience119062012-03-02 11:57:34 +0800113 void Materialize();
Logan Chien8b977d32012-02-21 19:14:55 +0800114
Logan Chienf7015fd2012-03-18 01:19:37 +0800115 void LoadElfFromCompilationUnit(const CompilationUnit* cunit);
116
Logan Chien7f767612012-03-01 18:54:49 +0800117 bool IsBitcodeFileNameAvailable() const {
118 return !bitcode_filename_.empty();
119 }
Logan Chien8b977d32012-02-21 19:14:55 +0800120
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800121 Compiler* compiler_;
122
Logan Chien7f767612012-03-01 18:54:49 +0800123 public:
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800124 Mutex compiler_lock_;
125
Logan Chien7f767612012-03-01 18:54:49 +0800126 private:
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800127 InstructionSet insn_set_;
128
Logan Chien7f767612012-03-01 18:54:49 +0800129 CompilationUnit* curr_cunit_;
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800130
Logan Chien7f767612012-03-01 18:54:49 +0800131 std::vector<CompilationUnit*> cunits_;
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800132
Logan Chien8b977d32012-02-21 19:14:55 +0800133 std::string elf_filename_;
134
135 std::string bitcode_filename_;
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800136
Logan Chienf7015fd2012-03-18 01:19:37 +0800137 UniquePtr<ElfLoader> elf_loader_;
138
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800139 DISALLOW_COPY_AND_ASSIGN(CompilerLLVM);
140};
141
142
143} // namespace compiler_llvm
144} // namespace art
145
Logan Chiend6e614b2012-03-01 20:57:44 +0800146#endif // ART_SRC_COMPILER_LLVM_COMPILER_LLVM_H_