compiler.h revision b34f69ab43aaf7a6e6045c95f398baf566ef5023
1f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray/*
2f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray * Copyright (C) 2014 The Android Open Source Project
3f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray *
4f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License");
5f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray * you may not use this file except in compliance with the License.
6f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray * You may obtain a copy of the License at
7f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray *
8f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray *      http://www.apache.org/licenses/LICENSE-2.0
9f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray *
10f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray * Unless required by applicable law or agreed to in writing, software
11f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS,
12f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray * See the License for the specific language governing permissions and
14f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray * limitations under the License.
15f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray */
16f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
17b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray#ifndef ART_COMPILER_COMPILER_H_
18b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray#define ART_COMPILER_COMPILER_H_
19f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
20f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray#include "dex_file.h"
21f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray#include "os.h"
22f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
23f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffraynamespace art {
24f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
25f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffrayclass Backend;
26b48b9eb6d181a1f52e2e605cf26a21505f1d46edIan Rogersstruct CompilationUnit;
27f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffrayclass CompilerDriver;
28f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffrayclass CompiledMethod;
29f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffrayclass MIRGraph;
30f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffrayclass OatWriter;
31f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
32f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffraynamespace mirror {
33f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  class ArtMethod;
34f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray}
35f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
36b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffrayclass Compiler {
37f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray public:
38f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  enum Kind {
39f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray    kQuick,
40b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray    kOptimizing,
41f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray    kPortable
42f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  };
43f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
44b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray  explicit Compiler(uint64_t warning)
453d504075f7c1204d581923460754bf6d3714b13fIan Rogers      : maximum_compilation_time_before_warning_(warning) {
463d504075f7c1204d581923460754bf6d3714b13fIan Rogers  }
47f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
48b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray  static Compiler* Create(Kind kind);
49f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
50f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  virtual void Init(CompilerDriver& driver) const = 0;
51f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
52f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  virtual void UnInit(CompilerDriver& driver) const = 0;
53f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
543d504075f7c1204d581923460754bf6d3714b13fIan Rogers  virtual CompiledMethod* Compile(CompilerDriver& driver,
55f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                                  const DexFile::CodeItem* code_item,
56f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                                  uint32_t access_flags,
57f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                                  InvokeType invoke_type,
58f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                                  uint16_t class_def_idx,
59f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                                  uint32_t method_idx,
60f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                                  jobject class_loader,
61f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                                  const DexFile& dex_file) const = 0;
62f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
63b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray  static CompiledMethod* TryCompileWithSeaIR(art::CompilerDriver& driver,
64b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                                             const art::DexFile::CodeItem* code_item,
65b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                                             uint32_t access_flags,
66b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                                             art::InvokeType invoke_type,
67b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                                             uint16_t class_def_idx,
68b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                                             uint32_t method_idx,
69b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                                             jobject class_loader,
70b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                                             const art::DexFile& dex_file);
71b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray
72f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  virtual CompiledMethod* JniCompile(CompilerDriver& driver,
73f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                                     uint32_t access_flags,
74f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                                     uint32_t method_idx,
75f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                                     const DexFile& dex_file) const = 0;
76f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
77f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  virtual uintptr_t GetEntryPointOf(mirror::ArtMethod* method) const = 0;
78f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
79f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  virtual bool WriteElf(art::File* file,
803d504075f7c1204d581923460754bf6d3714b13fIan Rogers                        OatWriter* oat_writer,
81f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                        const std::vector<const art::DexFile*>& dex_files,
82f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                        const std::string& android_root,
83f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                        bool is_host, const CompilerDriver& driver) const
84f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0;
85f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
86f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  virtual Backend* GetCodeGenerator(CompilationUnit* cu,
87f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                                    void* compilation_unit) const = 0;
88f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
89f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  uint64_t GetMaximumCompilationTimeBeforeWarning() const {
90f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray    return maximum_compilation_time_before_warning_;
91f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  }
92f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
933d504075f7c1204d581923460754bf6d3714b13fIan Rogers  virtual bool IsPortable() const {
943d504075f7c1204d581923460754bf6d3714b13fIan Rogers    return false;
953d504075f7c1204d581923460754bf6d3714b13fIan Rogers  }
963d504075f7c1204d581923460754bf6d3714b13fIan Rogers
973d504075f7c1204d581923460754bf6d3714b13fIan Rogers  void SetBitcodeFileName(const CompilerDriver& driver, const std::string& filename) {
983d504075f7c1204d581923460754bf6d3714b13fIan Rogers    UNUSED(driver);
99f3e2cc4a38389aa75eb8ee3973a535254bf1c8d2Nicolas Geoffray    UNUSED(filename);
100f3e2cc4a38389aa75eb8ee3973a535254bf1c8d2Nicolas Geoffray  }
101f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
102f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  virtual void InitCompilationUnit(CompilationUnit& cu) const = 0;
103f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
104b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray  virtual ~Compiler() {}
105f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
106ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell  /*
107ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell   * @brief Generate and return Dwarf CFI initialization, if supported by the
108ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell   * backend.
109ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell   * @param driver CompilerDriver for this compile.
110ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell   * @returns nullptr if not supported by backend or a vector of bytes for CFI DWARF
111ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell   * information.
112ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell   * @note This is used for backtrace information in generated code.
113ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell   */
114ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell  virtual std::vector<uint8_t>* GetCallFrameInformationInitialization(const CompilerDriver& driver)
115ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell      const {
116ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell    return nullptr;
117ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell  }
118ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell
119f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray private:
1203d504075f7c1204d581923460754bf6d3714b13fIan Rogers  const uint64_t maximum_compilation_time_before_warning_;
121f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
122b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(Compiler);
123f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray};
124f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
125f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray}  // namespace art
126f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
127b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray#endif  // ART_COMPILER_COMPILER_H_
128