blob: 562a1d2d016c44c95144f5924ec68095b62cf5ec [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"
23
24#include <UniquePtr.h>
25
26#include <string>
27
28namespace art {
29 class ClassLoader;
Logan Chienf04364f2012-02-10 12:01:39 +080030 class CompiledInvokeStub;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080031 class CompiledMethod;
32 class Compiler;
Logan Chien4dd96f52012-02-29 01:26:58 +080033 class OatCompilationUnit;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080034}
35
36
37namespace llvm {
38 class Function;
39 class LLVMContext;
40 class Module;
41 class PointerType;
42 class StructType;
43 class Type;
44}
45
46
47namespace art {
48namespace compiler_llvm {
49
Logan Chien8b977d32012-02-21 19:14:55 +080050class CompilationUnit;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080051class IRBuilder;
52
53class CompilerLLVM {
54 public:
55 CompilerLLVM(Compiler* compiler, InstructionSet insn_set);
56
57 ~CompilerLLVM();
58
Logan Chien7f767612012-03-01 18:54:49 +080059 void MaterializeIfThresholdReached();
60
61 void MaterializeRemainder();
Shih-wei Liaod1fec812012-02-13 09:51:10 -080062
63 Compiler* GetCompiler() const {
64 return compiler_;
65 }
66
67 InstructionSet GetInstructionSet() const {
68 return insn_set_;
69 }
70
Logan Chienaeb53032012-03-18 02:29:38 +080071 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 Chien8b977d32012-02-21 19:14:55 +080079 void SetElfFileName(std::string const& filename) {
80 elf_filename_ = filename;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080081 }
82
Logan Chien8b977d32012-02-21 19:14:55 +080083 void SetBitcodeFileName(std::string const& filename) {
84 bitcode_filename_ = filename;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080085 }
86
Logan Chien4dd96f52012-02-29 01:26:58 +080087 CompiledMethod* CompileDexMethod(OatCompilationUnit* oat_compilation_unit);
Shih-wei Liaod1fec812012-02-13 09:51:10 -080088
Logan Chien88894ee2012-02-13 16:42:22 +080089 CompiledMethod* CompileNativeMethod(OatCompilationUnit* oat_compilation_unit);
90
Logan Chienf04364f2012-02-10 12:01:39 +080091 CompiledInvokeStub* CreateInvokeStub(bool is_static, char const *shorty);
92
Shih-wei Liaod1fec812012-02-13 09:51:10 -080093 private:
Logan Chience119062012-03-02 11:57:34 +080094 void EnsureCompilationUnit();
Logan Chien8b977d32012-02-21 19:14:55 +080095
Logan Chience119062012-03-02 11:57:34 +080096 void Materialize();
Logan Chien8b977d32012-02-21 19:14:55 +080097
Logan Chien7f767612012-03-01 18:54:49 +080098 bool IsBitcodeFileNameAvailable() const {
99 return !bitcode_filename_.empty();
100 }
Logan Chien8b977d32012-02-21 19:14:55 +0800101
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800102 Compiler* compiler_;
103
Logan Chien7f767612012-03-01 18:54:49 +0800104 public:
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800105 Mutex compiler_lock_;
106
Logan Chien7f767612012-03-01 18:54:49 +0800107 private:
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800108 InstructionSet insn_set_;
109
Logan Chien7f767612012-03-01 18:54:49 +0800110 CompilationUnit* curr_cunit_;
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800111
Logan Chien7f767612012-03-01 18:54:49 +0800112 std::vector<CompilationUnit*> cunits_;
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800113
Logan Chien8b977d32012-02-21 19:14:55 +0800114 std::string elf_filename_;
115
116 std::string bitcode_filename_;
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800117
118 DISALLOW_COPY_AND_ASSIGN(CompilerLLVM);
119};
120
121
122} // namespace compiler_llvm
123} // namespace art
124
Logan Chiend6e614b2012-03-01 20:57:44 +0800125#endif // ART_SRC_COMPILER_LLVM_COMPILER_LLVM_H_