Home | History | Annotate | Download | only in compiler
      1 /*
      2  * Copyright (C) 2014 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_COMPILERS_H_
     18 #define ART_COMPILER_COMPILERS_H_
     19 
     20 #include "compiler.h"
     21 
     22 namespace art {
     23 
     24 class QuickCompiler : public Compiler {
     25  public:
     26   explicit QuickCompiler(CompilerDriver* driver) : Compiler(driver, 100) {}
     27 
     28   void Init() const OVERRIDE;
     29 
     30   void UnInit() const OVERRIDE;
     31 
     32   CompiledMethod* Compile(const DexFile::CodeItem* code_item,
     33                           uint32_t access_flags,
     34                           InvokeType invoke_type,
     35                           uint16_t class_def_idx,
     36                           uint32_t method_idx,
     37                           jobject class_loader,
     38                           const DexFile& dex_file) const OVERRIDE;
     39 
     40   CompiledMethod* JniCompile(uint32_t access_flags,
     41                              uint32_t method_idx,
     42                              const DexFile& dex_file) const OVERRIDE;
     43 
     44   uintptr_t GetEntryPointOf(mirror::ArtMethod* method) const OVERRIDE
     45       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
     46 
     47   bool WriteElf(art::File* file,
     48                 OatWriter* oat_writer,
     49                 const std::vector<const art::DexFile*>& dex_files,
     50                 const std::string& android_root,
     51                 bool is_host) const
     52     OVERRIDE
     53     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
     54 
     55   Backend* GetCodeGenerator(CompilationUnit* cu, void* compilation_unit) const OVERRIDE;
     56 
     57   void InitCompilationUnit(CompilationUnit& cu) const OVERRIDE {}
     58 
     59   /*
     60    * @brief Generate and return Dwarf CFI initialization, if supported by the
     61    * backend.
     62    * @param driver CompilerDriver for this compile.
     63    * @returns nullptr if not supported by backend or a vector of bytes for CFI DWARF
     64    * information.
     65    * @note This is used for backtrace information in generated code.
     66    */
     67   std::vector<uint8_t>* GetCallFrameInformationInitialization(const CompilerDriver& driver) const
     68       OVERRIDE;
     69 
     70  private:
     71   DISALLOW_COPY_AND_ASSIGN(QuickCompiler);
     72 };
     73 
     74 class OptimizingCompiler FINAL : public QuickCompiler {
     75  public:
     76   explicit OptimizingCompiler(CompilerDriver* driver);
     77 
     78   CompiledMethod* Compile(const DexFile::CodeItem* code_item,
     79                           uint32_t access_flags,
     80                           InvokeType invoke_type,
     81                           uint16_t class_def_idx,
     82                           uint32_t method_idx,
     83                           jobject class_loader,
     84                           const DexFile& dex_file) const OVERRIDE;
     85 
     86   CompiledMethod* TryCompile(const DexFile::CodeItem* code_item,
     87                              uint32_t access_flags,
     88                              InvokeType invoke_type,
     89                              uint16_t class_def_idx,
     90                              uint32_t method_idx,
     91                              jobject class_loader,
     92                              const DexFile& dex_file) const;
     93 
     94  private:
     95   std::unique_ptr<std::ostream> visualizer_output_;
     96 
     97   DISALLOW_COPY_AND_ASSIGN(OptimizingCompiler);
     98 };
     99 
    100 }  // namespace art
    101 
    102 #endif  // ART_COMPILER_COMPILERS_H_
    103