Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_COMPILER_STATE_VALUES_UTILS_H_ | 5 #ifndef V8_COMPILER_STATE_VALUES_UTILS_H_ |
| 6 #define V8_COMPILER_STATE_VALUES_UTILS_H_ | 6 #define V8_COMPILER_STATE_VALUES_UTILS_H_ |
| 7 | 7 |
| 8 #include <array> | |
| 8 #include "src/compiler/js-graph.h" | 9 #include "src/compiler/js-graph.h" |
| 9 #include "src/globals.h" | 10 #include "src/globals.h" |
| 10 | 11 |
| 11 namespace v8 { | 12 namespace v8 { |
| 12 namespace internal { | 13 namespace internal { |
| 13 | 14 |
| 15 class BitVector; | |
| 16 | |
| 14 namespace compiler { | 17 namespace compiler { |
| 15 | 18 |
| 16 class Graph; | 19 class Graph; |
| 17 | 20 |
| 18 class V8_EXPORT_PRIVATE StateValuesCache { | 21 class V8_EXPORT_PRIVATE StateValuesCache { |
| 19 public: | 22 public: |
| 20 explicit StateValuesCache(JSGraph* js_graph); | 23 explicit StateValuesCache(JSGraph* js_graph); |
| 21 | 24 |
| 22 Node* GetNodeForValues(Node** values, size_t count); | 25 Node* GetNodeForValues(Node** values, size_t count, |
| 26 const BitVector* liveness); | |
| 23 | 27 |
| 24 private: | 28 private: |
| 25 static const size_t kMaxInputCount = 8; | 29 static const size_t kMaxInputCount = 8; |
| 30 typedef std::array<Node*, kMaxInputCount> WorkingBuffer; | |
| 26 | 31 |
| 27 struct NodeKey { | 32 struct NodeKey { |
| 28 Node* node; | 33 Node* node; |
| 29 | 34 |
| 30 explicit NodeKey(Node* node) : node(node) {} | 35 explicit NodeKey(Node* node) : node(node) {} |
| 31 }; | 36 }; |
| 32 | 37 |
| 33 struct StateValuesKey : public NodeKey { | 38 struct StateValuesKey : public NodeKey { |
| 34 // ValueArray - array of nodes ({node} has to be nullptr). | 39 // ValueArray - array of nodes ({node} has to be nullptr). |
| 35 size_t count; | 40 size_t count; |
| 41 uint32_t mask; | |
| 36 Node** values; | 42 Node** values; |
| 37 | 43 |
| 38 StateValuesKey(size_t count, Node** values) | 44 StateValuesKey(size_t count, uint32_t mask, Node** values) |
| 39 : NodeKey(nullptr), count(count), values(values) {} | 45 : NodeKey(nullptr), count(count), mask(mask), values(values) {} |
| 40 }; | 46 }; |
| 41 | 47 |
| 42 class ValueArrayIterator; | |
| 43 | |
| 44 static bool AreKeysEqual(void* key1, void* key2); | 48 static bool AreKeysEqual(void* key1, void* key2); |
| 45 static bool IsKeysEqualToNode(StateValuesKey* key, Node* node); | 49 static bool IsKeysEqualToNode(StateValuesKey* key, Node* node); |
| 46 static bool AreValueKeysEqual(StateValuesKey* key1, StateValuesKey* key2); | 50 static bool AreValueKeysEqual(StateValuesKey* key1, StateValuesKey* key2); |
| 47 | 51 |
| 48 Node* BuildTree(ValueArrayIterator* it, size_t max_height); | 52 Node* BuildTree(size_t& idx, Node** values, size_t count, |
| 49 NodeVector* GetWorkingSpace(size_t level); | 53 const BitVector* liveness, size_t level); |
| 54 | |
| 55 WorkingBuffer& GetWorkingSpace(size_t level); | |
| 50 Node* GetEmptyStateValues(); | 56 Node* GetEmptyStateValues(); |
| 51 Node* GetValuesNodeFromCache(Node** nodes, size_t count); | 57 Node* GetValuesNodeFromCache(Node** nodes, size_t count, uint32_t mask); |
| 52 | 58 |
| 53 Graph* graph() { return js_graph_->graph(); } | 59 Graph* graph() { return js_graph_->graph(); } |
| 54 CommonOperatorBuilder* common() { return js_graph_->common(); } | 60 CommonOperatorBuilder* common() { return js_graph_->common(); } |
| 55 | 61 |
| 56 Zone* zone() { return graph()->zone(); } | 62 Zone* zone() { return graph()->zone(); } |
| 57 | 63 |
| 58 JSGraph* js_graph_; | 64 JSGraph* js_graph_; |
| 59 CustomMatcherZoneHashMap hash_map_; | 65 CustomMatcherZoneHashMap hash_map_; |
| 60 ZoneVector<NodeVector*> working_space_; // One working space per level. | 66 ZoneVector<WorkingBuffer> working_space_; // One working space per level. |
| 61 Node* empty_state_values_; | 67 Node* empty_state_values_; |
| 62 }; | 68 }; |
| 63 | 69 |
| 64 class V8_EXPORT_PRIVATE StateValuesAccess { | 70 class V8_EXPORT_PRIVATE StateValuesAccess { |
| 65 public: | 71 public: |
| 66 struct TypedNode { | 72 struct TypedNode { |
| 67 Node* node; | 73 Node* node; |
| 68 MachineType type; | 74 MachineType type; |
| 69 TypedNode(Node* node, MachineType type) : node(node), type(type) {} | 75 TypedNode(Node* node, MachineType type) : node(node), type(type) {} |
| 70 }; | 76 }; |
| 71 | 77 |
| 72 class V8_EXPORT_PRIVATE iterator { | 78 class V8_EXPORT_PRIVATE iterator { |
| 73 public: | 79 public: |
| 74 // Bare minimum of operators needed for range iteration. | 80 // Bare minimum of operators needed for range iteration. |
| 75 bool operator!=(iterator& other); | 81 bool operator!=(iterator& other); |
| 76 iterator& operator++(); | 82 iterator& operator++(); |
| 77 TypedNode operator*(); | 83 TypedNode operator*(); |
| 78 | 84 |
| 79 private: | 85 private: |
| 80 friend class StateValuesAccess; | 86 friend class StateValuesAccess; |
| 81 | 87 |
| 82 iterator() : current_depth_(-1) {} | 88 iterator() : current_depth_(-1) {} |
| 83 explicit iterator(Node* node); | 89 explicit iterator(Node* node); |
| 84 | 90 |
| 85 Node* node(); | 91 Node* node(); |
| 86 MachineType type(); | 92 MachineType type(); |
| 87 bool done(); | 93 bool done(); |
| 88 void Advance(); | 94 void Advance(); |
| 95 void MoveToNextSibling(); | |
| 96 void EnsureValid(); | |
| 89 | 97 |
| 90 struct StatePos { | 98 struct StatePos { |
| 91 Node* node; | 99 Node* node; |
| 100 uint32_t mask; | |
|
Jarin
2016/12/08 07:59:43
This needs some explanation of what it means.
Leszek Swirski
2016/12/08 15:44:31
Removed after iterator refactor.
| |
| 92 int index; | 101 int index; |
| 93 | |
| 94 explicit StatePos(Node* node) : node(node), index(0) {} | |
| 95 StatePos() {} | |
| 96 }; | 102 }; |
| 97 | 103 |
| 98 StatePos* Top(); | 104 StatePos* Top(); |
| 99 void Push(Node* node); | 105 void Push(Node* node, uint32_t mask); |
| 100 void Pop(); | 106 void Pop(); |
| 101 | 107 |
| 102 static const int kMaxInlineDepth = 8; | 108 static const int kMaxInlineDepth = 8; |
| 103 StatePos stack_[kMaxInlineDepth]; | 109 StatePos stack_[kMaxInlineDepth]; |
| 104 int current_depth_; | 110 int current_depth_; |
| 105 }; | 111 }; |
| 106 | 112 |
| 107 explicit StateValuesAccess(Node* node) : node_(node) {} | 113 explicit StateValuesAccess(Node* node) : node_(node) {} |
| 108 | 114 |
| 109 size_t size(); | 115 size_t size(); |
| 110 iterator begin() { return iterator(node_); } | 116 iterator begin() { return iterator(node_); } |
| 111 iterator end() { return iterator(); } | 117 iterator end() { return iterator(); } |
| 112 | 118 |
| 113 private: | 119 private: |
| 114 Node* node_; | 120 Node* node_; |
| 115 }; | 121 }; |
| 116 | 122 |
| 117 } // namespace compiler | 123 } // namespace compiler |
| 118 } // namespace internal | 124 } // namespace internal |
| 119 } // namespace v8 | 125 } // namespace v8 |
| 120 | 126 |
| 121 #endif // V8_COMPILER_STATE_VALUES_UTILS_H_ | 127 #endif // V8_COMPILER_STATE_VALUES_UTILS_H_ |
| OLD | NEW |