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 COMPILER_OPTIMIZER_PASS_MANAGER_STATISTICS_H 17 #define COMPILER_OPTIMIZER_PASS_MANAGER_STATISTICS_H 18 19 #include <chrono> 20 #include "utils/arena_containers.h" 21 22 namespace panda::compiler { 23 class Graph; 24 class Pass; 25 26 class PassManagerStatistics { 27 public: 28 explicit PassManagerStatistics(Graph *graph); 29 30 NO_MOVE_SEMANTIC(PassManagerStatistics); 31 NO_COPY_SEMANTIC(PassManagerStatistics); 32 ~PassManagerStatistics() = default; 33 34 void ProcessBeforeRun(const Pass &pass); 35 36 void ProcessAfterRun(size_t local_mem_used); 37 38 void PrintStatistics() const; 39 AddInlinedMethods(size_t num)40 auto AddInlinedMethods(size_t num) 41 { 42 inlined_methods_ += num; 43 } GetInlinedMethods()44 auto GetInlinedMethods() const 45 { 46 return inlined_methods_; 47 } 48 AddPbcInstNum(uint64_t num)49 auto AddPbcInstNum(uint64_t num) 50 { 51 pbc_inst_num_ += num; 52 } SetPbcInstNum(uint64_t num)53 auto SetPbcInstNum(uint64_t num) 54 { 55 pbc_inst_num_ = num; 56 } GetPbcInstNum()57 auto GetPbcInstNum() const 58 { 59 return pbc_inst_num_; 60 } 61 GetCurrentPassIndex()62 auto GetCurrentPassIndex() const 63 { 64 return pass_run_index_; 65 } 66 67 void DumpStatisticsCsv(char sep = ',') const; 68 69 private: 70 struct GraphStatistic { 71 size_t num_of_instructions {0}; 72 size_t num_of_basicblocks {0}; 73 }; 74 struct PassStatistic { 75 int run_depth {0}; 76 const char *pass_name {nullptr}; 77 GraphStatistic before_pass; 78 GraphStatistic after_pass; 79 size_t mem_used_ir {0}; 80 size_t mem_used_local {0}; 81 size_t time_us {0}; 82 }; 83 84 private: 85 Graph *graph_; 86 // We use list because the elements inside this container are referred by pointers in other places. 87 ArenaList<PassStatistic> pass_stat_list_; 88 ArenaStack<PassStatistic *> pass_stat_stack_; 89 size_t last_allocated_local_ {0}; 90 size_t last_allocated_ir_ {0}; 91 std::chrono::time_point<std::chrono::steady_clock> last_timestamp_; 92 93 unsigned pass_run_index_ {0}; 94 int pass_call_depth_ {0}; 95 96 // Count of inlined methods 97 size_t inlined_methods_ {0}; 98 // Number of pbc instructions in main and all successfully inlined methods. 99 uint64_t pbc_inst_num_ {0}; 100 101 bool enable_ir_stat_ {false}; 102 }; 103 } // namespace panda::compiler 104 105 #endif // COMPILER_OPTIMIZER_PASS_MANAGER_STATISTICS_H 106