blob: c3f5a532c63ae4e5f141c99455f83a2b4d67c71f [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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_NODE_H_
6#define V8_COMPILER_NODE_H_
7
8#include <deque>
9#include <set>
10#include <vector>
11
12#include "src/compiler/generic-algorithm.h"
13#include "src/compiler/generic-node.h"
14#include "src/compiler/opcodes.h"
15#include "src/compiler/operator.h"
16#include "src/types.h"
17#include "src/zone.h"
18#include "src/zone-allocator.h"
19
20namespace v8 {
21namespace internal {
22namespace compiler {
23
24class NodeData {
25 public:
26 const Operator* op() const { return op_; }
27 void set_op(const Operator* op) { op_ = op; }
28
29 IrOpcode::Value opcode() const {
30 DCHECK(op_->opcode() <= IrOpcode::kLast);
31 return static_cast<IrOpcode::Value>(op_->opcode());
32 }
33
34 Bounds bounds() { return bounds_; }
35
36 protected:
37 const Operator* op_;
38 Bounds bounds_;
39 explicit NodeData(Zone* zone) : bounds_(Bounds(Type::None(zone))) {}
40
41 friend class NodeProperties;
42 void set_bounds(Bounds b) { bounds_ = b; }
43};
44
45// A Node is the basic primitive of an IR graph. In addition to the members
46// inherited from Vector, Nodes only contain a mutable Operator that may change
47// during compilation, e.g. during lowering passes. Other information that
48// needs to be associated with Nodes during compilation must be stored
49// out-of-line indexed by the Node's id.
50class Node FINAL : public GenericNode<NodeData, Node> {
51 public:
52 Node(GenericGraphBase* graph, int input_count)
53 : GenericNode<NodeData, Node>(graph, input_count) {}
54
55 void Initialize(const Operator* op) { set_op(op); }
56
57 bool IsDead() const { return InputCount() > 0 && InputAt(0) == NULL; }
58 void Kill();
59
60 void CollectProjections(ZoneVector<Node*>* projections);
61 Node* FindProjection(size_t projection_index);
62};
63
64OStream& operator<<(OStream& os, const Node& n);
65
66typedef GenericGraphVisit::NullNodeVisitor<NodeData, Node> NullNodeVisitor;
67
68typedef std::set<Node*, std::less<Node*>, zone_allocator<Node*> > NodeSet;
69typedef NodeSet::iterator NodeSetIter;
70typedef NodeSet::reverse_iterator NodeSetRIter;
71
72typedef ZoneVector<Node*> NodeVector;
73typedef NodeVector::iterator NodeVectorIter;
74typedef NodeVector::const_iterator NodeVectorConstIter;
75typedef NodeVector::reverse_iterator NodeVectorRIter;
76
77typedef ZoneVector<NodeVector> NodeVectorVector;
78typedef NodeVectorVector::iterator NodeVectorVectorIter;
79typedef NodeVectorVector::reverse_iterator NodeVectorVectorRIter;
80
81typedef Node::Uses::iterator UseIter;
82typedef Node::Inputs::iterator InputIter;
83
84// Helper to extract parameters from Operator1<*> nodes.
85template <typename T>
86static inline const T& OpParameter(const Node* node) {
87 return OpParameter<T>(node->op());
88}
89
90} // namespace compiler
91} // namespace internal
92} // namespace v8
93
94#endif // V8_COMPILER_NODE_H_