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 
     22 #include "compiler_enums.h"
     23 #include "dex/quick/mir_to_lir.h"
     24 #include "dex_instruction.h"
     25 #include "driver/compiler_driver.h"
     26 #include "driver/dex_compilation_unit.h"
     27 #include "safe_map.h"
     28 #include "utils/scoped_arena_allocator.h"
     29 #include "base/timing_logger.h"
     30 #include "utils/arena_allocator.h"
     31 
     32 namespace art {
     33 
     34 struct ArenaMemBlock;
     35 class Backend;
     36 struct Memstats;
     37 class MIRGraph;
     38 class Mir2Lir;
     39 
     40 struct CompilationUnit {
     41   explicit CompilationUnit(ArenaPool* pool);
     42   ~CompilationUnit();
     43 
     44   void StartTimingSplit(const char* label);
     45   void NewTimingSplit(const char* label);
     46   void EndTiming();
     47 
     48   /*
     49    * Fields needed/generated by common frontend and generally used throughout
     50    * the compiler.
     51   */
     52   CompilerDriver* compiler_driver;
     53   ClassLinker* class_linker;           // Linker to resolve fields and methods.
     54   const DexFile* dex_file;             // DexFile containing the method being compiled.
     55   jobject class_loader;                // compiling method's class loader.
     56   uint16_t class_def_idx;              // compiling method's defining class definition index.
     57   uint32_t method_idx;                 // compiling method's index into method_ids of DexFile.
     58   const DexFile::CodeItem* code_item;  // compiling method's DexFile code_item.
     59   uint32_t access_flags;               // compiling method's access flags.
     60   InvokeType invoke_type;              // compiling method's invocation type.
     61   const char* shorty;                  // compiling method's shorty.
     62   uint32_t disable_opt;                // opt_control_vector flags.
     63   uint32_t enable_debug;               // debugControlVector flags.
     64   bool verbose;
     65   const Compiler* compiler;
     66   InstructionSet instruction_set;
     67   bool target64;
     68 
     69   InstructionSetFeatures GetInstructionSetFeatures() {
     70     return compiler_driver->GetInstructionSetFeatures();
     71   }
     72   // TODO: much of this info available elsewhere.  Go to the original source?
     73   uint16_t num_dalvik_registers;        // method->registers_size.
     74   const uint16_t* insns;
     75   uint16_t num_ins;
     76   uint16_t num_outs;
     77   uint16_t num_regs;            // Unlike num_dalvik_registers, does not include ins.
     78 
     79   // If non-empty, apply optimizer/debug flags only to matching methods.
     80   std::string compiler_method_match;
     81   // Flips sense of compiler_method_match - apply flags if doesn't match.
     82   bool compiler_flip_match;
     83 
     84   // TODO: move memory management to mir_graph, or just switch to using standard containers.
     85   ArenaAllocator arena;
     86   ArenaStack arena_stack;  // Arenas for ScopedArenaAllocator.
     87 
     88   std::unique_ptr<MIRGraph> mir_graph;   // MIR container.
     89   std::unique_ptr<Backend> cg;           // Target-specific codegen.
     90   TimingLogger timings;
     91   bool print_pass;                 // Do we want to print a pass or not?
     92 };
     93 
     94 }  // namespace art
     95 
     96 #endif  // ART_COMPILER_DEX_COMPILER_IR_H_
     97