Line data Source code
1 : // Copyright 2014 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 : #include "src/compiler/node-origin-table.h"
6 : #include "src/compiler/graph.h"
7 : #include "src/compiler/node-aux-data.h"
8 :
9 : namespace v8 {
10 : namespace internal {
11 : namespace compiler {
12 :
13 1144 : void NodeOrigin::PrintJson(std::ostream& out) const {
14 286 : out << "{ ";
15 286 : switch (origin_kind_) {
16 : case kGraphNode:
17 286 : out << "\"nodeId\" : ";
18 286 : break;
19 : case kWasmBytecode:
20 0 : out << "\"bytecodePosition\" : ";
21 0 : break;
22 : }
23 : out << created_from();
24 286 : out << ", \"reducer\" : \"" << reducer_name() << "\"";
25 286 : out << ", \"phase\" : \"" << phase_name() << "\"";
26 286 : out << "}";
27 286 : }
28 :
29 0 : class NodeOriginTable::Decorator final : public GraphDecorator {
30 : public:
31 1 : explicit Decorator(NodeOriginTable* origins) : origins_(origins) {}
32 :
33 70 : void Decorate(Node* node) final {
34 70 : origins_->SetNodeOrigin(node, origins_->current_origin_);
35 70 : }
36 :
37 : private:
38 : NodeOriginTable* origins_;
39 : };
40 :
41 2264406 : NodeOriginTable::NodeOriginTable(Graph* graph)
42 : : graph_(graph),
43 : decorator_(nullptr),
44 : current_origin_(NodeOrigin::Unknown()),
45 : current_phase_name_("unknown"),
46 3396609 : table_(graph->zone()) {}
47 :
48 1 : void NodeOriginTable::AddDecorator() {
49 : DCHECK_NULL(decorator_);
50 2 : decorator_ = new (graph_->zone()) Decorator(this);
51 1 : graph_->AddDecorator(decorator_);
52 1 : }
53 :
54 1 : void NodeOriginTable::RemoveDecorator() {
55 : DCHECK_NOT_NULL(decorator_);
56 1 : graph_->RemoveDecorator(decorator_);
57 1 : decorator_ = nullptr;
58 1 : }
59 :
60 761 : NodeOrigin NodeOriginTable::GetNodeOrigin(Node* node) const {
61 761 : return table_.Get(node);
62 : }
63 :
64 0 : void NodeOriginTable::SetNodeOrigin(Node* node, const NodeOrigin& no) {
65 70 : table_.Set(node, no);
66 0 : }
67 :
68 2 : void NodeOriginTable::PrintJson(std::ostream& os) const {
69 2 : os << "{";
70 : bool needs_comma = false;
71 72 : for (auto i : table_) {
72 70 : NodeOrigin no = i.second;
73 70 : if (no.IsKnown()) {
74 36 : if (needs_comma) {
75 35 : os << ",";
76 : }
77 72 : os << "\"" << i.first << "\""
78 36 : << ": ";
79 36 : no.PrintJson(os);
80 : needs_comma = true;
81 : }
82 : }
83 2 : os << "}";
84 2 : }
85 :
86 : } // namespace compiler
87 : } // namespace internal
88 178779 : } // namespace v8
|