blob: eb1aec187ab9923609a0b1ab3f2364f02ffb7c88 [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 "dex_instruction.h"
30#include "safe_map.h"
buzbee862a7602013-04-05 10:58:54 -070031#include "arena_allocator.h"
buzbee67bf8852011-08-17 17:51:35 -070032
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080033namespace art {
34
buzbeeeaf09bc2012-11-15 14:51:41 -080035class LLVMInfo;
Brian Carlstrom265091e2013-01-30 14:08:26 -080036namespace llvm {
37class LlvmCompilationUnit;
38} // namespace llvm
buzbeeeaf09bc2012-11-15 14:51:41 -080039
buzbeeba938cb2012-02-03 14:47:55 -080040struct ArenaMemBlock;
41struct Memstats;
buzbee311ca162013-02-28 15:56:43 -080042class MIRGraph;
buzbee1fd33462013-03-25 13:40:45 -070043class Mir2Lir;
buzbee5b537102012-01-17 17:33:47 -080044
Elliott Hughes719ace42012-03-09 18:06:03 -080045struct CompilationUnit {
Elliott Hughese52e49b2012-04-02 16:05:44 -070046 CompilationUnit()
buzbee311ca162013-02-28 15:56:43 -080047 : compiler_driver(NULL),
Bill Buzbeea114add2012-05-03 15:00:40 -070048 class_linker(NULL),
49 dex_file(NULL),
Bill Buzbeea114add2012-05-03 15:00:40 -070050 class_loader(NULL),
Ian Rogersfffdb022013-01-04 15:14:08 -080051 class_def_idx(0),
Bill Buzbeea114add2012-05-03 15:00:40 -070052 method_idx(0),
53 code_item(NULL),
54 access_flags(0),
Ian Rogers08f753d2012-08-24 14:35:25 -070055 invoke_type(kDirect),
Bill Buzbeea114add2012-05-03 15:00:40 -070056 shorty(NULL),
buzbeefa57c472012-11-21 12:06:18 -080057 disable_opt(0),
58 enable_debug(0),
buzbeefa57c472012-11-21 12:06:18 -080059 verbose(false),
buzbee1fd33462013-03-25 13:40:45 -070060 compiler_backend(kNoBackend),
buzbeefa57c472012-11-21 12:06:18 -080061 instruction_set(kNone),
buzbeefa57c472012-11-21 12:06:18 -080062 num_dalvik_registers(0),
buzbee311ca162013-02-28 15:56:43 -080063 insns(NULL),
buzbeefa57c472012-11-21 12:06:18 -080064 num_ins(0),
65 num_outs(0),
66 num_regs(0),
buzbeefa57c472012-11-21 12:06:18 -080067 num_compiler_temps(0),
buzbeefa57c472012-11-21 12:06:18 -080068 compiler_flip_match(false),
buzbee311ca162013-02-28 15:56:43 -080069 mir_graph(NULL),
buzbee1fd33462013-03-25 13:40:45 -070070 cg(NULL) {}
buzbee311ca162013-02-28 15:56:43 -080071 /*
72 * Fields needed/generated by common frontend and generally used throughout
73 * the compiler.
74 */
Ian Rogers1212a022013-03-04 10:48:41 -080075 CompilerDriver* compiler_driver;
buzbee02031b12012-11-23 09:41:35 -080076 ClassLinker* class_linker; // Linker to resolve fields and methods.
77 const DexFile* dex_file; // DexFile containing the method being compiled.
78 jobject class_loader; // compiling method's class loader.
Ian Rogersfffdb022013-01-04 15:14:08 -080079 uint32_t class_def_idx; // compiling method's defining class definition index.
buzbee02031b12012-11-23 09:41:35 -080080 uint32_t method_idx; // compiling method's index into method_ids of DexFile.
81 const DexFile::CodeItem* code_item; // compiling method's DexFile code_item.
82 uint32_t access_flags; // compiling method's access flags.
83 InvokeType invoke_type; // compiling method's invocation type.
84 const char* shorty; // compiling method's shorty.
buzbee02031b12012-11-23 09:41:35 -080085 uint32_t disable_opt; // opt_control_vector flags.
86 uint32_t enable_debug; // debugControlVector flags.
buzbee311ca162013-02-28 15:56:43 -080087 bool verbose;
buzbee1fd33462013-03-25 13:40:45 -070088 CompilerBackend compiler_backend;
buzbeefa57c472012-11-21 12:06:18 -080089 InstructionSet instruction_set;
buzbee67bf8852011-08-17 17:51:35 -070090
buzbee1fd33462013-03-25 13:40:45 -070091 // TODO: much of this info available elsewhere. Go to the original source?
buzbee02031b12012-11-23 09:41:35 -080092 int num_dalvik_registers; // method->registers_size.
buzbee311ca162013-02-28 15:56:43 -080093 const uint16_t* insns;
buzbeefa57c472012-11-21 12:06:18 -080094 int num_ins;
95 int num_outs;
buzbee02031b12012-11-23 09:41:35 -080096 int num_regs; // Unlike num_dalvik_registers, does not include ins.
buzbee1fd33462013-03-25 13:40:45 -070097
98 // TODO: may want to move this to MIRGraph.
buzbeefa57c472012-11-21 12:06:18 -080099 int num_compiler_temps;
buzbee1fd33462013-03-25 13:40:45 -0700100
Bill Buzbeea114add2012-05-03 15:00:40 -0700101 // If non-empty, apply optimizer/debug flags only to matching methods.
buzbeefa57c472012-11-21 12:06:18 -0800102 std::string compiler_method_match;
103 // Flips sense of compiler_method_match - apply flags if doesn't match.
104 bool compiler_flip_match;
buzbee1fd33462013-03-25 13:40:45 -0700105
106 // TODO: move memory management to mir_graph, or just switch to using standard containers.
buzbee862a7602013-04-05 10:58:54 -0700107 ArenaAllocator arena;
buzbee1fd33462013-03-25 13:40:45 -0700108
buzbee311ca162013-02-28 15:56:43 -0800109 UniquePtr<MIRGraph> mir_graph; // MIR container.
buzbee1fd33462013-03-25 13:40:45 -0700110 UniquePtr<Backend> cg; // Target-specific codegen.
Elliott Hughes719ace42012-03-09 18:06:03 -0800111};
buzbee67bf8852011-08-17 17:51:35 -0700112
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800113} // namespace art
114
buzbee395116c2013-02-27 14:30:25 -0800115#endif // ART_SRC_COMPILER_DEX_COMPILER_IR_H_