Home | History | Annotate | Download | only in compiler
      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   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.
     50 class 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 
     64 OStream& operator<<(OStream& os, const Node& n);
     65 
     66 typedef GenericGraphVisit::NullNodeVisitor<NodeData, Node> NullNodeVisitor;
     67 
     68 typedef std::set<Node*, std::less<Node*>, zone_allocator<Node*> > NodeSet;
     69 typedef NodeSet::iterator NodeSetIter;
     70 typedef NodeSet::reverse_iterator NodeSetRIter;
     71 
     72 typedef ZoneVector<Node*> NodeVector;
     73 typedef NodeVector::iterator NodeVectorIter;
     74 typedef NodeVector::const_iterator NodeVectorConstIter;
     75 typedef NodeVector::reverse_iterator NodeVectorRIter;
     76 
     77 typedef ZoneVector<NodeVector> NodeVectorVector;
     78 typedef NodeVectorVector::iterator NodeVectorVectorIter;
     79 typedef NodeVectorVector::reverse_iterator NodeVectorVectorRIter;
     80 
     81 typedef Node::Uses::iterator UseIter;
     82 typedef Node::Inputs::iterator InputIter;
     83 
     84 // Helper to extract parameters from Operator1<*> nodes.
     85 template <typename T>
     86 static 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_
     95