blob: bdc31547cbc47bc898481661acf921ea75925846 [file] [log] [blame]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001/*
2 * Copyright (C) 2011 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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_COMPILER_DEX_COMPILER_IR_H_
18#define ART_COMPILER_DEX_COMPILER_IR_H_
Brian Carlstrom7940e442013-07-12 13:46:57 -070019
20#include <vector>
21#include <llvm/IR/Module.h>
22#include "arena_allocator.h"
23#include "backend.h"
24#include "compiler_enums.h"
25#include "dex/quick/mir_to_lir.h"
26#include "dex_instruction.h"
27#include "driver/compiler_driver.h"
28#include "driver/dex_compilation_unit.h"
29#include "llvm/intrinsic_helper.h"
30#include "llvm/ir_builder.h"
31#include "safe_map.h"
32
33namespace art {
34
35class LLVMInfo;
36namespace llvm {
37class LlvmCompilationUnit;
38} // namespace llvm
39
40struct ArenaMemBlock;
41struct Memstats;
42class MIRGraph;
43class Mir2Lir;
44
45struct CompilationUnit {
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -070046 explicit CompilationUnit(ArenaPool* pool)
Brian Carlstrom7940e442013-07-12 13:46:57 -070047 : compiler_driver(NULL),
48 class_linker(NULL),
49 dex_file(NULL),
50 class_loader(NULL),
51 class_def_idx(0),
52 method_idx(0),
53 code_item(NULL),
54 access_flags(0),
55 invoke_type(kDirect),
56 shorty(NULL),
57 disable_opt(0),
58 enable_debug(0),
59 verbose(false),
60 compiler_backend(kNoBackend),
61 instruction_set(kNone),
62 num_dalvik_registers(0),
63 insns(NULL),
64 num_ins(0),
65 num_outs(0),
66 num_regs(0),
67 num_compiler_temps(0),
68 compiler_flip_match(false),
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -070069 arena(pool),
Brian Carlstrom7940e442013-07-12 13:46:57 -070070 mir_graph(NULL),
71 cg(NULL) {}
72 /*
73 * Fields needed/generated by common frontend and generally used throughout
74 * the compiler.
75 */
76 CompilerDriver* compiler_driver;
77 ClassLinker* class_linker; // Linker to resolve fields and methods.
78 const DexFile* dex_file; // DexFile containing the method being compiled.
79 jobject class_loader; // compiling method's class loader.
Ian Rogers8b2c0b92013-09-19 02:56:49 -070080 uint16_t class_def_idx; // compiling method's defining class definition index.
Brian Carlstrom7940e442013-07-12 13:46:57 -070081 uint32_t method_idx; // compiling method's index into method_ids of DexFile.
82 const DexFile::CodeItem* code_item; // compiling method's DexFile code_item.
83 uint32_t access_flags; // compiling method's access flags.
84 InvokeType invoke_type; // compiling method's invocation type.
85 const char* shorty; // compiling method's shorty.
86 uint32_t disable_opt; // opt_control_vector flags.
87 uint32_t enable_debug; // debugControlVector flags.
88 bool verbose;
89 CompilerBackend compiler_backend;
90 InstructionSet instruction_set;
91
92 // TODO: much of this info available elsewhere. Go to the original source?
buzbee0d829482013-10-11 15:24:55 -070093 uint16_t num_dalvik_registers; // method->registers_size.
Brian Carlstrom7940e442013-07-12 13:46:57 -070094 const uint16_t* insns;
buzbee0d829482013-10-11 15:24:55 -070095 uint16_t num_ins;
96 uint16_t num_outs;
97 uint16_t num_regs; // Unlike num_dalvik_registers, does not include ins.
Brian Carlstrom7940e442013-07-12 13:46:57 -070098
99 // TODO: may want to move this to MIRGraph.
buzbee0d829482013-10-11 15:24:55 -0700100 uint16_t num_compiler_temps;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700101
102 // If non-empty, apply optimizer/debug flags only to matching methods.
103 std::string compiler_method_match;
104 // Flips sense of compiler_method_match - apply flags if doesn't match.
105 bool compiler_flip_match;
106
107 // TODO: move memory management to mir_graph, or just switch to using standard containers.
108 ArenaAllocator arena;
109
110 UniquePtr<MIRGraph> mir_graph; // MIR container.
111 UniquePtr<Backend> cg; // Target-specific codegen.
112};
113
114} // namespace art
115
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700116#endif // ART_COMPILER_DEX_COMPILER_IR_H_