v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
maglev-graph-labeller.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_LABELLER_H_
6#define V8_MAGLEV_MAGLEV_GRAPH_LABELLER_H_
7
8#include <map>
9
12#include "src/utils/utils.h"
13
14namespace v8 {
15namespace internal {
16namespace maglev {
17
19 public:
25 struct NodeInfo {
26 int label = -1;
28 };
29
31 BytecodeOffset bytecode_offset, SourcePosition position) {
32 if (nodes_
33 .emplace(node, NodeInfo{next_node_label_,
34 {unit, bytecode_offset, position}})
35 .second) {
37 }
38 }
39 void RegisterNode(const NodeBase* node) {
40 RegisterNode(node, nullptr, BytecodeOffset::None(),
42 }
43
44 int NodeId(const NodeBase* node) { return nodes_[node].label; }
46 return nodes_[node].provenance;
47 }
48
49 int max_node_id() const { return next_node_label_ - 1; }
50
51 void PrintNodeLabel(std::ostream& os, const NodeBase* node) {
52 if (node != nullptr && node->Is<VirtualObject>()) {
53 // VirtualObjects are unregisted nodes, since they are not attached to
54 // the graph, but its inlined allocation is.
55 const VirtualObject* vo = node->Cast<VirtualObject>();
56 os << "VO{" << vo->id() << "}:";
57 node = vo->allocation();
58 }
59 auto node_id_it = nodes_.find(node);
60
61 if (node_id_it == nodes_.end()) {
62 os << "<unregistered node " << node << ">";
63 return;
64 }
65
66 if (node->has_id()) {
67 os << "v" << node->id() << "/";
68 }
69 os << "n" << node_id_it->second.label;
70 }
71
72 void PrintInput(std::ostream& os, const Input& input) {
73 PrintNodeLabel(os, input.node());
74 os << ":" << input.operand();
75 }
76
77 private:
78 std::map<const NodeBase*, NodeInfo> nodes_;
80};
81
82} // namespace maglev
83} // namespace internal
84} // namespace v8
85
86#endif // V8_MAGLEV_MAGLEV_GRAPH_LABELLER_H_
static constexpr BytecodeOffset None()
Definition utils.h:675
static SourcePosition Unknown()
std::map< const NodeBase *, NodeInfo > nodes_
void RegisterNode(const NodeBase *node, const MaglevCompilationUnit *unit, BytecodeOffset bytecode_offset, SourcePosition position)
const Provenance & GetNodeProvenance(const NodeBase *node)
void PrintInput(std::ostream &os, const Input &input)
void PrintNodeLabel(std::ostream &os, const NodeBase *node)
InlinedAllocation * allocation() const
Definition maglev-ir.h:5664
Node * node
int position
Definition liveedit.cc:290