blob: 07ffa61452e1c03d3f8fd09548a9f8fc0e4586db [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 Chien8b977d32012-02-21 19:14:55 +080071 void SetElfFileName(std::string const& filename) {
72 elf_filename_ = filename;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080073 }
74
Logan Chien8b977d32012-02-21 19:14:55 +080075 void SetBitcodeFileName(std::string const& filename) {
76 bitcode_filename_ = filename;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080077 }
78
Logan Chien4dd96f52012-02-29 01:26:58 +080079 CompiledMethod* CompileDexMethod(OatCompilationUnit* oat_compilation_unit);
Shih-wei Liaod1fec812012-02-13 09:51:10 -080080
Logan Chien88894ee2012-02-13 16:42:22 +080081 CompiledMethod* CompileNativeMethod(OatCompilationUnit* oat_compilation_unit);
82
Logan Chienf04364f2012-02-10 12:01:39 +080083 CompiledInvokeStub* CreateInvokeStub(bool is_static, char const *shorty);
84
Shih-wei Liaod1fec812012-02-13 09:51:10 -080085 private:
Logan Chien7f767612012-03-01 18:54:49 +080086 void EnsureCompilationUnit(MutexLock& GUARD);
Logan Chien8b977d32012-02-21 19:14:55 +080087
Logan Chien7f767612012-03-01 18:54:49 +080088 void Materialize(MutexLock& GUARD);
Logan Chien8b977d32012-02-21 19:14:55 +080089
Logan Chien7f767612012-03-01 18:54:49 +080090 bool IsBitcodeFileNameAvailable() const {
91 return !bitcode_filename_.empty();
92 }
Logan Chien8b977d32012-02-21 19:14:55 +080093
Shih-wei Liaod1fec812012-02-13 09:51:10 -080094 Compiler* compiler_;
95
Logan Chien7f767612012-03-01 18:54:49 +080096 public:
Shih-wei Liaod1fec812012-02-13 09:51:10 -080097 Mutex compiler_lock_;
98
Logan Chien7f767612012-03-01 18:54:49 +080099 private:
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800100 InstructionSet insn_set_;
101
Logan Chien7f767612012-03-01 18:54:49 +0800102 CompilationUnit* curr_cunit_;
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800103
Logan Chien7f767612012-03-01 18:54:49 +0800104 std::vector<CompilationUnit*> cunits_;
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800105
Logan Chien8b977d32012-02-21 19:14:55 +0800106 std::string elf_filename_;
107
108 std::string bitcode_filename_;
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800109
110 DISALLOW_COPY_AND_ASSIGN(CompilerLLVM);
111};
112
113
114} // namespace compiler_llvm
115} // namespace art
116
Logan Chiend6e614b2012-03-01 20:57:44 +0800117#endif // ART_SRC_COMPILER_LLVM_COMPILER_LLVM_H_