1 // Copyright 2022 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_MAGLEV_MAGLEV_GRAPH_PRINTER_H_ 6 #define V8_MAGLEV_MAGLEV_GRAPH_PRINTER_H_ 7 8 #include <memory> 9 #include <ostream> 10 #include <set> 11 #include <vector> 12 13 namespace v8 { 14 namespace internal { 15 namespace maglev { 16 17 class BasicBlock; 18 class ControlNode; 19 class Graph; 20 class MaglevCompilationUnit; 21 class MaglevGraphLabeller; 22 class Node; 23 class NodeBase; 24 class Phi; 25 class ProcessingState; 26 27 class MaglevPrintingVisitor { 28 public: 29 explicit MaglevPrintingVisitor(std::ostream& os); 30 31 void PreProcessGraph(MaglevCompilationUnit*, Graph* graph); PostProcessGraph(MaglevCompilationUnit *,Graph * graph)32 void PostProcessGraph(MaglevCompilationUnit*, Graph* graph) {} 33 void PreProcessBasicBlock(MaglevCompilationUnit*, BasicBlock* block); 34 void Process(Phi* phi, const ProcessingState& state); 35 void Process(Node* node, const ProcessingState& state); 36 void Process(ControlNode* node, const ProcessingState& state); 37 os()38 std::ostream& os() { return *os_for_additional_info_; } 39 40 private: 41 std::ostream& os_; 42 std::unique_ptr<std::ostream> os_for_additional_info_; 43 std::set<BasicBlock*> loop_headers_; 44 std::vector<BasicBlock*> targets_; 45 }; 46 47 void PrintGraph(std::ostream& os, MaglevCompilationUnit* compilation_unit, 48 Graph* const graph); 49 50 class PrintNode { 51 public: PrintNode(MaglevGraphLabeller * graph_labeller,const NodeBase * node)52 PrintNode(MaglevGraphLabeller* graph_labeller, const NodeBase* node) 53 : graph_labeller_(graph_labeller), node_(node) {} 54 55 void Print(std::ostream& os) const; 56 57 private: 58 MaglevGraphLabeller* graph_labeller_; 59 const NodeBase* node_; 60 }; 61 62 std::ostream& operator<<(std::ostream& os, const PrintNode& printer); 63 64 class PrintNodeLabel { 65 public: PrintNodeLabel(MaglevGraphLabeller * graph_labeller,const Node * node)66 PrintNodeLabel(MaglevGraphLabeller* graph_labeller, const Node* node) 67 : graph_labeller_(graph_labeller), node_(node) {} 68 69 void Print(std::ostream& os) const; 70 71 private: 72 MaglevGraphLabeller* graph_labeller_; 73 const Node* node_; 74 }; 75 76 std::ostream& operator<<(std::ostream& os, const PrintNodeLabel& printer); 77 78 } // namespace maglev 79 } // namespace internal 80 } // namespace v8 81 82 #endif // V8_MAGLEV_MAGLEV_GRAPH_PRINTER_H_ 83