compiler.h revision 3d504075f7c1204d581923460754bf6d3714b13f
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
17f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray#ifndef ART_COMPILER_COMPILER_BACKEND_H_
18f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray#define ART_COMPILER_COMPILER_BACKEND_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
36f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffrayclass CompilerBackend {
37f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray public:
38f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  enum Kind {
39f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray    kQuick,
40f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray    kPortable
41f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  };
42f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
433d504075f7c1204d581923460754bf6d3714b13fIan Rogers  explicit CompilerBackend(uint64_t warning)
443d504075f7c1204d581923460754bf6d3714b13fIan Rogers      : maximum_compilation_time_before_warning_(warning) {
453d504075f7c1204d581923460754bf6d3714b13fIan Rogers  }
46f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
47f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  static CompilerBackend* Create(Kind kind);
48f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
49f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  virtual void Init(CompilerDriver& driver) const = 0;
50f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
51f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  virtual void UnInit(CompilerDriver& driver) const = 0;
52f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
533d504075f7c1204d581923460754bf6d3714b13fIan Rogers  virtual CompiledMethod* Compile(CompilerDriver& driver,
54f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                                  const DexFile::CodeItem* code_item,
55f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                                  uint32_t access_flags,
56f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                                  InvokeType invoke_type,
57f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                                  uint16_t class_def_idx,
58f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                                  uint32_t method_idx,
59f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                                  jobject class_loader,
60f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                                  const DexFile& dex_file) const = 0;
61f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
62f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  virtual CompiledMethod* JniCompile(CompilerDriver& driver,
63f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                                     uint32_t access_flags,
64f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                                     uint32_t method_idx,
65f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                                     const DexFile& dex_file) const = 0;
66f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
67f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  virtual uintptr_t GetEntryPointOf(mirror::ArtMethod* method) const = 0;
68f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
69f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  virtual bool WriteElf(art::File* file,
703d504075f7c1204d581923460754bf6d3714b13fIan Rogers                        OatWriter* oat_writer,
71f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                        const std::vector<const art::DexFile*>& dex_files,
72f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                        const std::string& android_root,
73f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                        bool is_host, const CompilerDriver& driver) const
74f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0;
75f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
76f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  virtual Backend* GetCodeGenerator(CompilationUnit* cu,
77f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray                                    void* compilation_unit) const = 0;
78f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
79f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  uint64_t GetMaximumCompilationTimeBeforeWarning() const {
80f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray    return maximum_compilation_time_before_warning_;
81f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  }
82f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
833d504075f7c1204d581923460754bf6d3714b13fIan Rogers  virtual bool IsPortable() const {
843d504075f7c1204d581923460754bf6d3714b13fIan Rogers    return false;
853d504075f7c1204d581923460754bf6d3714b13fIan Rogers  }
863d504075f7c1204d581923460754bf6d3714b13fIan Rogers
873d504075f7c1204d581923460754bf6d3714b13fIan Rogers  void SetBitcodeFileName(const CompilerDriver& driver, const std::string& filename) {
883d504075f7c1204d581923460754bf6d3714b13fIan Rogers    UNUSED(driver);
89f3e2cc4a38389aa75eb8ee3973a535254bf1c8d2Nicolas Geoffray    UNUSED(filename);
90f3e2cc4a38389aa75eb8ee3973a535254bf1c8d2Nicolas Geoffray  }
91f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
92f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  virtual void InitCompilationUnit(CompilationUnit& cu) const = 0;
93f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
94f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  virtual ~CompilerBackend() {}
95f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
96f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray private:
973d504075f7c1204d581923460754bf6d3714b13fIan Rogers  const uint64_t maximum_compilation_time_before_warning_;
98f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
99f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(CompilerBackend);
100f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray};
101f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
102f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray}  // namespace art
103f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray
104b84f522ff2f2b40d57d658f774da7b2a313a981eNicolas Geoffray#endif  // ART_COMPILER_COMPILER_BACKEND_H_
105