1 /** 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef PANDA_PAOC_H 17 #define PANDA_PAOC_H 18 19 #include "paoc_options.h" 20 #include "aot_builder/aot_builder.h" 21 #include "paoc_clusters.h" 22 #include "runtime/compiler.h" 23 #include "utils/span.h" 24 25 namespace panda::paoc { 26 27 struct SkipInfo { 28 bool is_first_compiled; 29 bool is_last_compiled; 30 }; 31 32 enum class PaocMode : uint8_t { AOT, JIT, OSR }; 33 34 class Paoc { 35 public: 36 int Run(const panda::Span<const char *> &args); 37 38 private: 39 void RunAotMode(const panda::Span<const char *> &args); 40 void Clear(panda::mem::InternalAllocatorPtr allocator); 41 void StartAotFile(const panda_file::File &pfile_ref); 42 bool CompileFiles(); 43 bool CompilePandaFile(const panda_file::File &pfile_ref); 44 panda::Class *ResolveClass(const panda_file::File &pfile_ref, panda_file::File::EntityId class_id); 45 bool PossibleToCompile(const panda_file::File &pfile_ref, const panda::Class *klass, 46 panda_file::File::EntityId class_id); 47 bool Compile(Class *klass, const panda_file::File &pfile_ref); 48 49 struct CompilingContext; 50 51 bool Compile(Method *method, size_t method_index); 52 bool CompileJit(CompilingContext *ctx); 53 bool CompileOsr(CompilingContext *ctx); 54 bool CompileAot(CompilingContext *ctx); 55 void PrintError(const std::string &error); 56 bool ShouldIgnoreFailures(); 57 void PrintUsage(const panda::PandArgParser &pa_parser); 58 bool IsMethodInList(const std::string &method_full_name); 59 bool Skip(Method *method); 60 static std::string GetFileLocation(const panda_file::File &pfile_ref, std::string location); 61 static bool CompareBootFiles(std::string filename, std::string paoc_location); 62 bool LoadPandaFiles(); 63 void BuildClassHashTable(const panda_file::File &pfile_ref); 64 65 class ErrorHandler : public ClassLinkerErrorHandler { OnError(ClassLinker::Error error,const PandaString & message)66 void OnError([[maybe_unused]] ClassLinker::Error error, [[maybe_unused]] const PandaString &message) override {} 67 }; 68 69 class PaocInitializer; 70 71 std::unique_ptr<panda::RuntimeOptions> runtime_options_ {nullptr}; 72 std::unique_ptr<panda::paoc::Options> paoc_options_ {nullptr}; 73 74 compiler::AotBuilder aot_builder_; 75 compiler::RuntimeInterface *runtime_ {nullptr}; 76 77 PaocMode mode_ {PaocMode::AOT}; 78 ClassLinker *loader_ {nullptr}; 79 ArenaAllocator *code_allocator_ {nullptr}; 80 std::set<std::string> methods_list_; 81 std::unordered_map<std::string, std::string> location_mapping_; 82 std::unordered_map<std::string, const panda_file::File *> preloaded_files_; 83 size_t compilation_index_ {0}; 84 SkipInfo skip_info_ {false, false}; 85 86 PaocClusters clusters_info_; 87 compiler::SharedSlowPathData *slow_path_data_ {nullptr}; 88 89 std::ofstream statistics_dump_; 90 }; 91 92 } // namespace panda::paoc 93 #endif // PANDA_PAOC_H 94