v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
turbofan-graph.h
Go to the documentation of this file.
1// Copyright 2013 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_COMPILER_TURBOFAN_GRAPH_H_
6#define V8_COMPILER_TURBOFAN_GRAPH_H_
7
8#include <array>
9
12#include "src/zone/zone.h"
13
14namespace v8 {
15namespace internal {
16namespace compiler {
17
18// Forward declarations.
19class GraphDecorator;
20class Node;
21class Operator;
22
23// Marks are used during traversal of the graph to distinguish states of nodes.
24// Each node has a mark which is a monotonically increasing integer, and a
25// {NodeMarker} has a range of values that indicate states of a node.
26using Mark = uint32_t;
27
28// NodeIds are identifying numbers for nodes that can be used to index auxiliary
29// out-of-line data associated with each node.
30using NodeId = uint32_t;
31
32class V8_EXPORT_PRIVATE TFGraph final : public NON_EXPORTED_BASE(ZoneObject) {
33 public:
34 explicit TFGraph(Zone* zone);
35 TFGraph(const TFGraph&) = delete;
36 TFGraph& operator=(const TFGraph&) = delete;
37
38 // Scope used when creating a subgraph for inlining. Automatically preserves
39 // the original start and end nodes of the graph, and resets them when you
40 // leave the scope.
42 public:
43 explicit SubgraphScope(TFGraph* graph)
44 : graph_(graph), start_(graph->start()), end_(graph->end()) {}
46 graph_->SetStart(start_);
47 graph_->SetEnd(end_);
48 }
49 SubgraphScope(const SubgraphScope&) = delete;
51
52 private:
54 Node* const start_;
55 Node* const end_;
56 };
57
58 // Base implementation used by all factory methods.
59 Node* NewNodeUnchecked(const Operator* op, int input_count,
60 Node* const* inputs, bool incomplete = false);
61
62 // Factory that checks the input count.
63 Node* NewNode(const Operator* op, int input_count, Node* const* inputs,
64 bool incomplete = false);
65
66 // Factory template for nodes with static input counts.
67 // Note: Template magic below is used to ensure this method is only considered
68 // for argument types convertible to Node* during overload resolution.
69 template <typename... Nodes>
70 Node* NewNode(const Operator* op, Nodes... nodes)
71 requires(std::conjunction_v<std::is_convertible<Nodes, Node*>...>)
72 {
73 std::array<Node*, sizeof...(nodes)> nodes_arr{
74 {static_cast<Node*>(nodes)...}};
75 return NewNode(op, nodes_arr.size(), nodes_arr.data());
76 }
77
78 // Clone the {node}, and assign a new node id to the copy.
79 Node* CloneNode(const Node* node);
80
81 Zone* zone() const { return zone_; }
82 Node* start() const { return start_; }
83 Node* end() const { return end_; }
84
86 void SetEnd(Node* end) { end_ = end; }
87
88 size_t NodeCount() const { return next_node_id_; }
89
90 void Decorate(Node* node);
91 void AddDecorator(GraphDecorator* decorator);
92 void RemoveDecorator(GraphDecorator* decorator);
93
94 // Very simple print API usable in a debugger.
95 void Print() const;
96
97 bool HasSimd() const { return has_simd_; }
98 void SetSimd(bool has_simd) { has_simd_ = has_simd; }
99
100 void RecordSimdStore(Node* store);
101 ZoneVector<Node*> const& GetSimdStoreNodes();
102
103 private:
104 friend class NodeMarkerBase;
105
106 inline NodeId NextNodeId();
107
108 Zone* const zone_;
116};
117
118// A graph decorator can be used to add behavior to the creation of nodes
119// in a graph.
121 public:
122 virtual ~GraphDecorator() = default;
123 virtual void Decorate(Node* node) = 0;
124};
125
126} // namespace compiler
127} // namespace internal
128} // namespace v8
129
130#endif // V8_COMPILER_TURBOFAN_GRAPH_H_
virtual void Decorate(Node *node)=0
SubgraphScope & operator=(const SubgraphScope &)=delete
SubgraphScope(const SubgraphScope &)=delete
TFGraph & operator=(const TFGraph &)=delete
Node * NewNode(const Operator *op, Nodes... nodes)
ZoneVector< Node * > simd_stores_
TFGraph(const TFGraph &)=delete
ZoneVector< GraphDecorator * > decorators_
Zone * zone_
uint8_t *const start_
Definition assembler.cc:131
const v8::base::TimeTicks end_
Definition sweeper.cc:54
int start
int end
#define NON_EXPORTED_BASE(code)
#define V8_EXPORT_PRIVATE
Definition macros.h:460
#define V8_NODISCARD
Definition v8config.h:693
TFGraph * graph_