blob: d4bf3da182807923115ef1e5047097d4c5d0eeb1 [file] [log] [blame]
buzbee67bf8852011-08-17 17:51:35 -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
buzbee395116c2013-02-27 14:30:25 -080017#ifndef ART_SRC_COMPILER_DEX_COMPILER_IR_H_
18#define ART_SRC_COMPILER_DEX_COMPILER_IR_H_
buzbee67bf8852011-08-17 17:51:35 -070019
Elliott Hughesa0e18062012-04-13 15:59:59 -070020#include <vector>
Brian Carlstrom37d48792013-03-22 14:14:45 -070021#include <llvm/IR/Module.h>
buzbee1fd33462013-03-25 13:40:45 -070022#include "compiler/dex/quick/mir_to_lir.h"
23#include "backend.h"
Ian Rogers1212a022013-03-04 10:48:41 -080024#include "compiler/driver/compiler_driver.h"
Ian Rogers89756f22013-03-04 16:40:02 -080025#include "compiler/driver/dex_compilation_unit.h"
Ian Rogers4c1c2832013-03-04 18:30:13 -080026#include "compiler/llvm/intrinsic_helper.h"
Brian Carlstrom265091e2013-01-30 14:08:26 -080027#include "compiler/llvm/ir_builder.h"
buzbeecbd6d442012-11-17 14:11:25 -080028#include "compiler_enums.h"
Brian Carlstrom265091e2013-01-30 14:08:26 -080029#include "compiler_utility.h"
30#include "dex_instruction.h"
31#include "safe_map.h"
buzbee67bf8852011-08-17 17:51:35 -070032
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080033namespace art {
34
buzbeeeaf09bc2012-11-15 14:51:41 -080035struct ArenaBitVector;
buzbeeeaf09bc2012-11-15 14:51:41 -080036class LLVMInfo;
Brian Carlstrom265091e2013-01-30 14:08:26 -080037namespace llvm {
38class LlvmCompilationUnit;
39} // namespace llvm
buzbeeeaf09bc2012-11-15 14:51:41 -080040
buzbeeba938cb2012-02-03 14:47:55 -080041struct ArenaMemBlock;
42struct Memstats;
buzbee311ca162013-02-28 15:56:43 -080043class MIRGraph;
buzbee1fd33462013-03-25 13:40:45 -070044class Mir2Lir;
buzbee5b537102012-01-17 17:33:47 -080045
Elliott Hughes719ace42012-03-09 18:06:03 -080046struct CompilationUnit {
Elliott Hughese52e49b2012-04-02 16:05:44 -070047 CompilationUnit()
buzbee311ca162013-02-28 15:56:43 -080048 : compiler_driver(NULL),
Bill Buzbeea114add2012-05-03 15:00:40 -070049 class_linker(NULL),
50 dex_file(NULL),
Bill Buzbeea114add2012-05-03 15:00:40 -070051 class_loader(NULL),
Ian Rogersfffdb022013-01-04 15:14:08 -080052 class_def_idx(0),
Bill Buzbeea114add2012-05-03 15:00:40 -070053 method_idx(0),
54 code_item(NULL),
55 access_flags(0),
Ian Rogers08f753d2012-08-24 14:35:25 -070056 invoke_type(kDirect),
Bill Buzbeea114add2012-05-03 15:00:40 -070057 shorty(NULL),
buzbeefa57c472012-11-21 12:06:18 -080058 disable_opt(0),
59 enable_debug(0),
buzbeefa57c472012-11-21 12:06:18 -080060 verbose(false),
buzbee1fd33462013-03-25 13:40:45 -070061 compiler_backend(kNoBackend),
buzbeefa57c472012-11-21 12:06:18 -080062 instruction_set(kNone),
buzbeefa57c472012-11-21 12:06:18 -080063 num_dalvik_registers(0),
buzbee311ca162013-02-28 15:56:43 -080064 insns(NULL),
buzbeefa57c472012-11-21 12:06:18 -080065 num_ins(0),
66 num_outs(0),
67 num_regs(0),
buzbeefa57c472012-11-21 12:06:18 -080068 num_compiler_temps(0),
buzbeefa57c472012-11-21 12:06:18 -080069 compiler_flip_match(false),
70 arena_head(NULL),
71 current_arena(NULL),
72 num_arena_blocks(0),
Bill Buzbeea114add2012-05-03 15:00:40 -070073 mstats(NULL),
buzbee311ca162013-02-28 15:56:43 -080074 mir_graph(NULL),
buzbee1fd33462013-03-25 13:40:45 -070075 cg(NULL) {}
buzbee311ca162013-02-28 15:56:43 -080076 /*
77 * Fields needed/generated by common frontend and generally used throughout
78 * the compiler.
79 */
Ian Rogers1212a022013-03-04 10:48:41 -080080 CompilerDriver* compiler_driver;
buzbee02031b12012-11-23 09:41:35 -080081 ClassLinker* class_linker; // Linker to resolve fields and methods.
82 const DexFile* dex_file; // DexFile containing the method being compiled.
83 jobject class_loader; // compiling method's class loader.
Ian Rogersfffdb022013-01-04 15:14:08 -080084 uint32_t class_def_idx; // compiling method's defining class definition index.
buzbee02031b12012-11-23 09:41:35 -080085 uint32_t method_idx; // compiling method's index into method_ids of DexFile.
86 const DexFile::CodeItem* code_item; // compiling method's DexFile code_item.
87 uint32_t access_flags; // compiling method's access flags.
88 InvokeType invoke_type; // compiling method's invocation type.
89 const char* shorty; // compiling method's shorty.
buzbee02031b12012-11-23 09:41:35 -080090 uint32_t disable_opt; // opt_control_vector flags.
91 uint32_t enable_debug; // debugControlVector flags.
buzbee311ca162013-02-28 15:56:43 -080092 bool verbose;
buzbee1fd33462013-03-25 13:40:45 -070093 CompilerBackend compiler_backend;
buzbeefa57c472012-11-21 12:06:18 -080094 InstructionSet instruction_set;
buzbee67bf8852011-08-17 17:51:35 -070095
buzbee1fd33462013-03-25 13:40:45 -070096 // TODO: much of this info available elsewhere. Go to the original source?
buzbee02031b12012-11-23 09:41:35 -080097 int num_dalvik_registers; // method->registers_size.
buzbee311ca162013-02-28 15:56:43 -080098 const uint16_t* insns;
buzbeefa57c472012-11-21 12:06:18 -080099 int num_ins;
100 int num_outs;
buzbee02031b12012-11-23 09:41:35 -0800101 int num_regs; // Unlike num_dalvik_registers, does not include ins.
buzbee1fd33462013-03-25 13:40:45 -0700102
103 // TODO: may want to move this to MIRGraph.
buzbeefa57c472012-11-21 12:06:18 -0800104 int num_compiler_temps;
buzbee1fd33462013-03-25 13:40:45 -0700105
Bill Buzbeea114add2012-05-03 15:00:40 -0700106 // If non-empty, apply optimizer/debug flags only to matching methods.
buzbeefa57c472012-11-21 12:06:18 -0800107 std::string compiler_method_match;
108 // Flips sense of compiler_method_match - apply flags if doesn't match.
109 bool compiler_flip_match;
buzbee1fd33462013-03-25 13:40:45 -0700110
111 // TODO: move memory management to mir_graph, or just switch to using standard containers.
buzbeefa57c472012-11-21 12:06:18 -0800112 ArenaMemBlock* arena_head;
113 ArenaMemBlock* current_arena;
114 int num_arena_blocks;
Bill Buzbeea114add2012-05-03 15:00:40 -0700115 Memstats* mstats;
buzbee1fd33462013-03-25 13:40:45 -0700116
buzbee311ca162013-02-28 15:56:43 -0800117 UniquePtr<MIRGraph> mir_graph; // MIR container.
buzbee1fd33462013-03-25 13:40:45 -0700118 UniquePtr<Backend> cg; // Target-specific codegen.
Elliott Hughes719ace42012-03-09 18:06:03 -0800119};
buzbee67bf8852011-08-17 17:51:35 -0700120
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800121} // namespace art
122
buzbee395116c2013-02-27 14:30:25 -0800123#endif // ART_SRC_COMPILER_DEX_COMPILER_IR_H_