blob: 532ad1ac268fc93daa1825d1d87db4e7ae540df8 [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
Logan Chiend6c239a2011-12-23 15:11:45 +080083 llvm::BasicBlock* prologue_;
84
85 std::vector<llvm::BasicBlock*> basic_blocks_;
86
87
Shih-wei Liaod1fec812012-02-13 09:51:10 -080088 public:
Logan Chien83426162011-12-09 09:29:50 +080089 MethodCompiler(InstructionSet insn_set,
90 Compiler* compiler,
91 ClassLinker* class_linker,
92 ClassLoader const* class_loader,
93 DexFile const* dex_file,
94 DexCache* dex_cache,
95 DexFile::CodeItem const* code_item,
Shih-wei Liaod1fec812012-02-13 09:51:10 -080096 uint32_t method_idx,
97 uint32_t access_flags);
98
99 ~MethodCompiler();
100
Logan Chien83426162011-12-09 09:29:50 +0800101 CompiledMethod* Compile();
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800102
103 private:
104 void CreateFunction();
105
106 void EmitPrologue();
107 void EmitInstructions();
Logan Chien83426162011-12-09 09:29:50 +0800108 void EmitInstruction(uint32_t dex_pc, Instruction const* insn);
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800109
Logan Chien0b827102011-12-20 19:46:14 +0800110
111 // Code generation helper function
112
113 llvm::Value* EmitLoadMethodObjectAddr();
114
115 llvm::FunctionType* GetFunctionType(uint32_t method_idx, bool is_static);
116
Logan Chiend6c239a2011-12-23 15:11:45 +0800117
118 // Basic block helper functions
119 llvm::BasicBlock* GetBasicBlock(uint32_t dex_pc);
120
121 llvm::BasicBlock* GetNextBasicBlock(uint32_t dex_pc);
122
123 llvm::BasicBlock* CreateBasicBlockWithDexPC(uint32_t dex_pc,
124 char const* postfix = NULL);
125
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800126};
127
128
129} // namespace compiler_llvm
130} // namespace art
131
132#endif // ART_SRC_COMPILER_LLVM_METHOD_COMPILER_H_