blob: fd46975b9a8e317c07dc374422f35c4ad9ed44d5 [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"
buzbeea61f4952013-08-23 14:27:06 -070032#include "base/timing_logger.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070033
34namespace art {
35
36class LLVMInfo;
37namespace llvm {
38class LlvmCompilationUnit;
39} // namespace llvm
40
41struct ArenaMemBlock;
42struct Memstats;
43class MIRGraph;
44class Mir2Lir;
45
46struct CompilationUnit {
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -070047 explicit CompilationUnit(ArenaPool* pool)
Brian Carlstrom7940e442013-07-12 13:46:57 -070048 : compiler_driver(NULL),
49 class_linker(NULL),
50 dex_file(NULL),
51 class_loader(NULL),
52 class_def_idx(0),
53 method_idx(0),
54 code_item(NULL),
55 access_flags(0),
56 invoke_type(kDirect),
57 shorty(NULL),
58 disable_opt(0),
59 enable_debug(0),
60 verbose(false),
61 compiler_backend(kNoBackend),
62 instruction_set(kNone),
63 num_dalvik_registers(0),
64 insns(NULL),
65 num_ins(0),
66 num_outs(0),
67 num_regs(0),
68 num_compiler_temps(0),
69 compiler_flip_match(false),
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -070070 arena(pool),
Brian Carlstrom7940e442013-07-12 13:46:57 -070071 mir_graph(NULL),
buzbeea61f4952013-08-23 14:27:06 -070072 cg(NULL),
73 timings("QuickCompiler", true, false) {
74 }
75
76 void StartTimingSplit(const char* label);
77 void NewTimingSplit(const char* label);
78 void EndTiming();
79
Brian Carlstrom7940e442013-07-12 13:46:57 -070080 /*
81 * Fields needed/generated by common frontend and generally used throughout
82 * the compiler.
83 */
84 CompilerDriver* compiler_driver;
85 ClassLinker* class_linker; // Linker to resolve fields and methods.
86 const DexFile* dex_file; // DexFile containing the method being compiled.
87 jobject class_loader; // compiling method's class loader.
Ian Rogers8b2c0b92013-09-19 02:56:49 -070088 uint16_t class_def_idx; // compiling method's defining class definition index.
Brian Carlstrom7940e442013-07-12 13:46:57 -070089 uint32_t method_idx; // compiling method's index into method_ids of DexFile.
90 const DexFile::CodeItem* code_item; // compiling method's DexFile code_item.
91 uint32_t access_flags; // compiling method's access flags.
92 InvokeType invoke_type; // compiling method's invocation type.
93 const char* shorty; // compiling method's shorty.
94 uint32_t disable_opt; // opt_control_vector flags.
95 uint32_t enable_debug; // debugControlVector flags.
96 bool verbose;
97 CompilerBackend compiler_backend;
98 InstructionSet instruction_set;
99
Dave Allison70202782013-10-22 17:52:19 -0700100 const InstructionSetFeatures& GetInstructionSetFeatures() {
101 return compiler_driver->GetInstructionSetFeatures();
102 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700103 // TODO: much of this info available elsewhere. Go to the original source?
buzbee0d829482013-10-11 15:24:55 -0700104 uint16_t num_dalvik_registers; // method->registers_size.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700105 const uint16_t* insns;
buzbee0d829482013-10-11 15:24:55 -0700106 uint16_t num_ins;
107 uint16_t num_outs;
108 uint16_t num_regs; // Unlike num_dalvik_registers, does not include ins.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700109
110 // TODO: may want to move this to MIRGraph.
buzbee0d829482013-10-11 15:24:55 -0700111 uint16_t num_compiler_temps;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700112
113 // If non-empty, apply optimizer/debug flags only to matching methods.
114 std::string compiler_method_match;
115 // Flips sense of compiler_method_match - apply flags if doesn't match.
116 bool compiler_flip_match;
117
118 // TODO: move memory management to mir_graph, or just switch to using standard containers.
119 ArenaAllocator arena;
120
121 UniquePtr<MIRGraph> mir_graph; // MIR container.
122 UniquePtr<Backend> cg; // Target-specific codegen.
buzbeea61f4952013-08-23 14:27:06 -0700123 base::TimingLogger timings;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700124};
125
126} // namespace art
127
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700128#endif // ART_COMPILER_DEX_COMPILER_IR_H_