OLD | NEW |
(Empty) | |
| 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_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 |
| 20 namespace v8 { |
| 21 namespace internal { |
| 22 namespace compiler { |
| 23 |
| 24 class NodeData { |
| 25 public: |
| 26 Operator* op() const { return op_; } |
| 27 void set_op(Operator* op) { op_ = op; } |
| 28 |
| 29 IrOpcode::Value opcode() const { |
| 30 ASSERT(op_->opcode() <= IrOpcode::kLast); |
| 31 return static_cast<IrOpcode::Value>(op_->opcode()); |
| 32 } |
| 33 |
| 34 Bounds bounds() { return bounds_; } |
| 35 |
| 36 protected: |
| 37 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. |
| 50 class Node : public GenericNode<NodeData, Node> { |
| 51 public: |
| 52 Node(GenericGraphBase* graph, int input_count) |
| 53 : GenericNode<NodeData, Node>(graph, input_count) {} |
| 54 |
| 55 void Initialize(Operator* op) { set_op(op); } |
| 56 }; |
| 57 |
| 58 OStream& operator<<(OStream& os, const Node& n); |
| 59 |
| 60 typedef GenericGraphVisit::NullNodeVisitor<NodeData, Node> NullNodeVisitor; |
| 61 |
| 62 typedef zone_allocator<Node*> NodePtrZoneAllocator; |
| 63 |
| 64 typedef std::set<Node*, std::less<Node*>, NodePtrZoneAllocator> NodeSet; |
| 65 typedef NodeSet::iterator NodeSetIter; |
| 66 typedef NodeSet::reverse_iterator NodeSetRIter; |
| 67 |
| 68 typedef std::deque<Node*, NodePtrZoneAllocator> NodeDeque; |
| 69 typedef NodeDeque::iterator NodeDequeIter; |
| 70 |
| 71 typedef std::vector<Node*, NodePtrZoneAllocator> NodeVector; |
| 72 typedef NodeVector::iterator NodeVectorIter; |
| 73 typedef NodeVector::reverse_iterator NodeVectorRIter; |
| 74 |
| 75 typedef zone_allocator<NodeVector> ZoneNodeVectorAllocator; |
| 76 typedef std::vector<NodeVector, ZoneNodeVectorAllocator> NodeVectorVector; |
| 77 typedef NodeVectorVector::iterator NodeVectorVectorIter; |
| 78 typedef NodeVectorVector::reverse_iterator NodeVectorVectorRIter; |
| 79 |
| 80 typedef Node::Uses::iterator UseIter; |
| 81 typedef Node::Inputs::iterator InputIter; |
| 82 |
| 83 // Helper to extract parameters from Operator1<*> nodes. |
| 84 template <typename T> |
| 85 static inline T OpParameter(Node* node) { |
| 86 return reinterpret_cast<Operator1<T>*>(node->op())->parameter(); |
| 87 } |
| 88 } |
| 89 } |
| 90 } // namespace v8::internal::compiler |
| 91 |
| 92 #endif // V8_COMPILER_NODE_H_ |
OLD | NEW |