blob: 0edf322d2a2f9be3a7383a1159f6a4676a316687 [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_METHOD_COMPILER_H_
18#define ART_SRC_COMPILER_LLVM_METHOD_COMPILER_H_
19
Logan Chienfca7e872011-12-20 20:08:22 +080020#include "backend_types.h"
Shih-wei Liaod1fec812012-02-13 09:51:10 -080021#include "constants.h"
22#include "dex_file.h"
23#include "dex_instruction.h"
24#include "object_utils.h"
25
26#include <llvm/Support/IRBuilder.h>
27
28#include <vector>
29
30#include <stdint.h>
31
32
33namespace art {
34 class ClassLinker;
35 class ClassLoader;
36 class CompiledMethod;
37 class Compiler;
38 class DexCache;
39}
40
41
42namespace llvm {
43 class AllocaInst;
44 class BasicBlock;
45 class Function;
46 class FunctionType;
47 class LLVMContext;
48 class Module;
49 class Type;
50}
51
52
53namespace art {
54namespace compiler_llvm {
55
56class CompilerLLVM;
57class IRBuilder;
58
59class MethodCompiler {
60 private:
Logan Chien83426162011-12-09 09:29:50 +080061 InstructionSet insn_set_;
62 Compiler* compiler_;
63 compiler_llvm::CompilerLLVM* compiler_llvm_;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080064
Logan Chien83426162011-12-09 09:29:50 +080065 ClassLinker* class_linker_;
66 ClassLoader const* class_loader_;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080067
Logan Chien83426162011-12-09 09:29:50 +080068 DexFile const* dex_file_;
69 DexCache* dex_cache_;
70 DexFile::CodeItem const* code_item_;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080071
Logan Chien83426162011-12-09 09:29:50 +080072 Method* method_;
73 MethodHelper method_helper_;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080074
75 uint32_t method_idx_;
76 uint32_t access_flags_;
77
78 llvm::Module* module_;
79 llvm::LLVMContext* context_;
80 IRBuilder& irb_;
81 llvm::Function* func_;
82
83 public:
Logan Chien83426162011-12-09 09:29:50 +080084 MethodCompiler(InstructionSet insn_set,
85 Compiler* compiler,
86 ClassLinker* class_linker,
87 ClassLoader const* class_loader,
88 DexFile const* dex_file,
89 DexCache* dex_cache,
90 DexFile::CodeItem const* code_item,
Shih-wei Liaod1fec812012-02-13 09:51:10 -080091 uint32_t method_idx,
92 uint32_t access_flags);
93
94 ~MethodCompiler();
95
Logan Chien83426162011-12-09 09:29:50 +080096 CompiledMethod* Compile();
Shih-wei Liaod1fec812012-02-13 09:51:10 -080097
98 private:
99 void CreateFunction();
100
101 void EmitPrologue();
102 void EmitInstructions();
Logan Chien83426162011-12-09 09:29:50 +0800103 void EmitInstruction(uint32_t dex_pc, Instruction const* insn);
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800104
Logan Chien0b827102011-12-20 19:46:14 +0800105
106 // Code generation helper function
107
108 llvm::Value* EmitLoadMethodObjectAddr();
109
110 llvm::FunctionType* GetFunctionType(uint32_t method_idx, bool is_static);
111
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800112};
113
114
115} // namespace compiler_llvm
116} // namespace art
117
118#endif // ART_SRC_COMPILER_LLVM_METHOD_COMPILER_H_