blob: f39f686bf69b3fd5169503fe97da1d4e22f91934 [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
17#ifndef ART_SRC_COMPILER_LLVM_LLVM_COMPILER_H_
18#define ART_SRC_COMPILER_LLVM_LLVM_COMPILER_H_
19
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;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080033}
34
35
36namespace llvm {
37 class Function;
38 class LLVMContext;
39 class Module;
40 class PointerType;
41 class StructType;
42 class Type;
43}
44
45
46namespace art {
47namespace compiler_llvm {
48
49class IRBuilder;
50
51class CompilerLLVM {
52 public:
53 CompilerLLVM(Compiler* compiler, InstructionSet insn_set);
54
55 ~CompilerLLVM();
56
57 void MaterializeLLVMModule();
58
59 void WriteBitcodeToFile(std::string const &filename);
60
61 Compiler* GetCompiler() const {
62 return compiler_;
63 }
64
65 InstructionSet GetInstructionSet() const {
66 return insn_set_;
67 }
68
69 llvm::Module* GetModule() const {
70 return module_;
71 }
72
73 llvm::LLVMContext* GetLLVMContext() const {
74 return context_.get();
75 }
76
77 IRBuilder* GetIRBuilder() const {
78 return irb_.get();
79 }
80
81 CompiledMethod* CompileDexMethod(DexFile::CodeItem const* code_item,
82 uint32_t access_flags,
83 uint32_t method_idx,
84 ClassLoader const* class_loader,
85 DexFile const& dex_file);
86
Logan Chienf04364f2012-02-10 12:01:39 +080087 CompiledInvokeStub* CreateInvokeStub(bool is_static, char const *shorty);
88
Shih-wei Liaod1fec812012-02-13 09:51:10 -080089 private:
90 Compiler* compiler_;
91
92 Mutex compiler_lock_;
93
94 InstructionSet insn_set_;
95
96 UniquePtr<llvm::LLVMContext> context_;
97
98 UniquePtr<IRBuilder> irb_;
99
100 llvm::Module* module_;
101
102 DISALLOW_COPY_AND_ASSIGN(CompilerLLVM);
103};
104
105
106} // namespace compiler_llvm
107} // namespace art
108
109#endif // ART_SRC_COMPILER_LLVM_LLVM_COMPILER_H_