Home | History | Annotate | Download | only in dex
      1 /*
      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 
     17 #ifndef ART_COMPILER_DEX_COMPILER_IR_H_
     18 #define ART_COMPILER_DEX_COMPILER_IR_H_
     19 
     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 
     33 namespace art {
     34 
     35 class LLVMInfo;
     36 namespace llvm {
     37 class LlvmCompilationUnit;
     38 }  // namespace llvm
     39 
     40 struct ArenaMemBlock;
     41 struct Memstats;
     42 class MIRGraph;
     43 class Mir2Lir;
     44 
     45 struct CompilationUnit {
     46   explicit CompilationUnit(ArenaPool* pool)
     47     : 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),
     69       arena(pool),
     70       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.
     80   uint16_t class_def_idx;              // compiling method's defining class definition index.
     81   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?
     93   int num_dalvik_registers;        // method->registers_size.
     94   const uint16_t* insns;
     95   int num_ins;
     96   int num_outs;
     97   int num_regs;            // Unlike num_dalvik_registers, does not include ins.
     98 
     99   // TODO: may want to move this to MIRGraph.
    100   int num_compiler_temps;
    101 
    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 
    116 #endif  // ART_COMPILER_DEX_COMPILER_IR_H_
    117