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_GENERIC_ALGORITHM_INL_H_ 6 #define V8_COMPILER_GENERIC_ALGORITHM_INL_H_ 7 8 #include <vector> 9 10 #include "src/compiler/generic-algorithm.h" 11 #include "src/compiler/generic-graph.h" 12 #include "src/compiler/generic-node.h" 13 #include "src/compiler/generic-node-inl.h" 14 15 namespace v8 { 16 namespace internal { 17 namespace compiler { 18 19 template <class N> 20 class NodeInputIterationTraits { 21 public: 22 typedef N Node; 23 typedef typename N::Inputs::iterator Iterator; 24 begin(Node * node)25 static Iterator begin(Node* node) { return node->inputs().begin(); } end(Node * node)26 static Iterator end(Node* node) { return node->inputs().end(); } max_id(GenericGraphBase * graph)27 static int max_id(GenericGraphBase* graph) { return graph->NodeCount(); } to(Iterator iterator)28 static Node* to(Iterator iterator) { return *iterator; } from(Iterator iterator)29 static Node* from(Iterator iterator) { return iterator.edge().from(); } 30 }; 31 32 template <class N> 33 class NodeUseIterationTraits { 34 public: 35 typedef N Node; 36 typedef typename N::Uses::iterator Iterator; 37 begin(Node * node)38 static Iterator begin(Node* node) { return node->uses().begin(); } end(Node * node)39 static Iterator end(Node* node) { return node->uses().end(); } max_id(GenericGraphBase * graph)40 static int max_id(GenericGraphBase* graph) { return graph->NodeCount(); } to(Iterator iterator)41 static Node* to(Iterator iterator) { return *iterator; } from(Iterator iterator)42 static Node* from(Iterator iterator) { return iterator.edge().to(); } 43 }; 44 } 45 } 46 } // namespace v8::internal::compiler 47 48 #endif // V8_COMPILER_GENERIC_ALGORITHM_INL_H_ 49