OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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_GRAPH_REDUCER_H_ |
| 6 #define V8_COMPILER_GRAPH_REDUCER_H_ |
| 7 |
| 8 #include <list> |
| 9 |
| 10 #include "src/zone-allocator.h" |
| 11 |
| 12 namespace v8 { |
| 13 namespace internal { |
| 14 namespace compiler { |
| 15 |
| 16 // Forward declarations. |
| 17 class Graph; |
| 18 class Node; |
| 19 |
| 20 |
| 21 // Represents the result of trying to reduce a node in the graph. |
| 22 class Reduction V8_FINAL { |
| 23 public: |
| 24 explicit Reduction(Node* replacement = NULL) : replacement_(replacement) {} |
| 25 |
| 26 Node* replacement() const { return replacement_; } |
| 27 bool Changed() const { return replacement() != NULL; } |
| 28 |
| 29 private: |
| 30 Node* replacement_; |
| 31 }; |
| 32 |
| 33 |
| 34 // A reducer can reduce or simplify a given node based on its operator and |
| 35 // inputs. This class functions as an extension point for the graph reducer for |
| 36 // language-specific reductions (e.g. reduction based on types or constant |
| 37 // folding of low-level operators) can be integrated into the graph reduction |
| 38 // phase. |
| 39 class Reducer { |
| 40 public: |
| 41 virtual ~Reducer() {} |
| 42 |
| 43 // Try to reduce a node if possible. |
| 44 virtual Reduction Reduce(Node* node) = 0; |
| 45 |
| 46 // Helper functions for subclasses to produce reductions for a node. |
| 47 static Reduction NoChange() { return Reduction(); } |
| 48 static Reduction Replace(Node* node) { return Reduction(node); } |
| 49 static Reduction Changed(Node* node) { return Reduction(node); } |
| 50 }; |
| 51 |
| 52 |
| 53 // Performs an iterative reduction of a node graph. |
| 54 class GraphReducer V8_FINAL { |
| 55 public: |
| 56 explicit GraphReducer(Graph* graph); |
| 57 |
| 58 Graph* graph() const { return graph_; } |
| 59 |
| 60 void AddReducer(Reducer* reducer) { reducers_.push_back(reducer); } |
| 61 |
| 62 // Reduce a single node. |
| 63 void ReduceNode(Node* node); |
| 64 // Reduce the whole graph. |
| 65 void ReduceGraph(); |
| 66 |
| 67 private: |
| 68 typedef std::list<Reducer*, zone_allocator<Reducer*> > Reducers; |
| 69 |
| 70 Graph* graph_; |
| 71 Reducers reducers_; |
| 72 }; |
| 73 } |
| 74 } |
| 75 } // namespace v8::internal::compiler |
| 76 |
| 77 #endif // V8_COMPILER_GRAPH_REDUCER_H_ |
OLD | NEW |