1 /* 2 * Copyright (c) 2021-2024 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 #ifndef COMPILER_OPTIMIZER_IR_VISUALIZER_PRINTER_H 16 #define COMPILER_OPTIMIZER_IR_VISUALIZER_PRINTER_H 17 18 #include <iostream> 19 #include <string> 20 21 namespace ark::compiler { 22 // This class dump graph in C1Visualizer format 23 // Option: --compiler-visualizer-dump 24 // Open dump files: 25 // 1. Download c1visualizer (http://lafo.ssw.uni-linz.ac.at/c1visualizer/c1visualizer-1.7.zip). 26 // 2. Run c1visualizer for your OS from folder "bin". 27 // 3. Open files. 28 29 class VisualizerPrinter { 30 public: VisualizerPrinter(const Graph * graph,std::ostream * output,const char * passName)31 VisualizerPrinter(const Graph *graph, std::ostream *output, const char *passName) 32 : graph_(graph), output_(output), passName_(passName) 33 { 34 } 35 36 NO_MOVE_SEMANTIC(VisualizerPrinter); 37 NO_COPY_SEMANTIC(VisualizerPrinter); 38 ~VisualizerPrinter() = default; 39 40 void Print(); 41 42 private: 43 void PrintBeginTag(const char *tag); 44 45 void PrintEndTag(const char *tag); 46 47 std::string MakeOffset(); 48 49 void PrintProperty(const char *prop, const ArenaString &value); 50 51 void PrintProperty(const char *prop, int value); 52 53 template <typename T> 54 void PrintDependences(const std::string &preffix, const T &blocks); 55 56 void PrintBasicBlock(BasicBlock *block); 57 58 void PrintInsts(BasicBlock *block); 59 60 void PrintInst(Inst *inst); 61 62 private: 63 const Graph *graph_; 64 std::ostream *output_; 65 const char *passName_; 66 uint32_t offset_ {0}; 67 }; 68 } // namespace ark::compiler 69 70 #endif // COMPILER_OPTIMIZER_IR_VISUALIZER_PRINTER_H 71