v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
maglev-graph-printer.h
Go to the documentation of this file.
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
17
18namespace v8 {
19namespace internal {
20namespace maglev {
21
22class BasicBlock;
23class ControlNode;
24class Graph;
25class MaglevCompilationInfo;
26class MaglevGraphLabeller;
27class Node;
28class NodeBase;
29class Phi;
30class ProcessingState;
31
32#ifdef V8_ENABLE_MAGLEV_GRAPH_PRINTER
33
34class MaglevPrintingVisitor {
35 public:
36 explicit MaglevPrintingVisitor(MaglevGraphLabeller* graph_labeller,
37 std::ostream& os);
38
39 void PreProcessGraph(Graph* graph);
40 void PostProcessGraph(Graph* graph) {}
41 void PostProcessBasicBlock(BasicBlock* block) {}
43 void PostPhiProcessing() {}
44 ProcessResult Process(Phi* phi, const ProcessingState& state);
45 ProcessResult Process(Node* node, const ProcessingState& state);
46 ProcessResult Process(ControlNode* node, const ProcessingState& state);
47
48 std::ostream& os() { return *os_for_additional_info_; }
49
50 private:
51 MaglevGraphLabeller* graph_labeller_;
52 std::ostream& os_;
53 std::unique_ptr<std::ostream> os_for_additional_info_;
54 std::set<BasicBlock*> loop_headers_;
55 std::vector<BasicBlock*> targets_;
56 NodeIdT max_node_id_ = kInvalidNodeId;
57 MaglevGraphLabeller::Provenance existing_provenance_;
58};
59
60void PrintGraph(std::ostream& os, MaglevCompilationInfo* compilation_info,
61 Graph* const graph);
62
63class PrintNode {
64 public:
65 PrintNode(MaglevGraphLabeller* graph_labeller, const NodeBase* node,
66 bool skip_targets = false)
67 : graph_labeller_(graph_labeller),
68 node_(node),
69 skip_targets_(skip_targets) {}
70
71 void Print(std::ostream& os) const;
72
73 private:
74 MaglevGraphLabeller* graph_labeller_;
75 const NodeBase* node_;
76 // This is used when tracing graph building, since targets might not exist
77 // yet.
78 const bool skip_targets_;
79};
80
81class PrintNodeLabel {
82 public:
83 PrintNodeLabel(MaglevGraphLabeller* graph_labeller, const NodeBase* node)
84 : graph_labeller_(graph_labeller), node_(node) {}
85
86 void Print(std::ostream& os) const;
87
88 private:
89 MaglevGraphLabeller* graph_labeller_;
90 const NodeBase* node_;
91};
92
93#else
94
95// Dummy inlined definitions of the printer classes/functions.
96
98 public:
100 std::ostream& os)
101 : os_(os) {}
102
103 void PreProcessGraph(Graph* graph) {}
104 void PostProcessGraph(Graph* graph) {}
111 }
114 }
118
119 std::ostream& os() { return os_; }
120
121 private:
122 std::ostream& os_;
123};
124
125inline void PrintGraph(std::ostream& os,
126 MaglevCompilationInfo* compilation_info,
127 Graph* const graph) {}
128
130 public:
131 PrintNode(MaglevGraphLabeller* graph_labeller, const NodeBase* node,
132 bool skip_targets = false) {}
133 void Print(std::ostream& os) const {}
134};
135
137 public:
138 PrintNodeLabel(MaglevGraphLabeller* graph_labeller, const NodeBase* node) {}
139 void Print(std::ostream& os) const {}
140};
141
142#endif // V8_ENABLE_MAGLEV_GRAPH_PRINTER
143
144inline std::ostream& operator<<(std::ostream& os, const PrintNode& printer) {
145 printer.Print(os);
146 return os;
147}
148
149inline std::ostream& operator<<(std::ostream& os,
150 const PrintNodeLabel& printer) {
151 printer.Print(os);
152 return os;
153}
154
155} // namespace maglev
156} // namespace internal
157} // namespace v8
158
159#endif // V8_MAGLEV_MAGLEV_GRAPH_PRINTER_H_
ProcessResult Process(Phi *phi, const ProcessingState &state)
ProcessResult Process(ControlNode *node, const ProcessingState &state)
MaglevPrintingVisitor(MaglevGraphLabeller *graph_labeller, std::ostream &os)
ProcessResult Process(Node *node, const ProcessingState &state)
BlockProcessResult PreProcessBasicBlock(BasicBlock *block)
PrintNodeLabel(MaglevGraphLabeller *graph_labeller, const NodeBase *node)
void Print(std::ostream &os) const
PrintNode(MaglevGraphLabeller *graph_labeller, const NodeBase *node, bool skip_targets=false)
static constexpr NodeIdT kInvalidNodeId
Definition maglev-ir.h:899
void PrintGraph(std::ostream &os, MaglevCompilationInfo *compilation_info, Graph *const graph)
std::ostream & operator<<(std::ostream &os, const PrintNode &printer)
Node * node_