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> | |
| 9 #include "src/compiler/common-operator.h" | |
| 8 #include "src/compiler/js-graph.h" | 10 #include "src/compiler/js-graph.h" |
| 9 #include "src/globals.h" | 11 #include "src/globals.h" |
| 10 | 12 |
| 11 namespace v8 { | 13 namespace v8 { |
| 12 namespace internal { | 14 namespace internal { |
| 13 | 15 |
| 16 class BitVector; | |
| 17 | |
| 14 namespace compiler { | 18 namespace compiler { |
| 15 | 19 |
| 16 class Graph; | 20 class Graph; |
| 17 | 21 |
| 18 class V8_EXPORT_PRIVATE StateValuesCache { | 22 class V8_EXPORT_PRIVATE StateValuesCache { |
| 19 public: | 23 public: |
| 20 explicit StateValuesCache(JSGraph* js_graph); | 24 explicit StateValuesCache(JSGraph* js_graph); |
| 21 | 25 |
| 22 Node* GetNodeForValues(Node** values, size_t count); | 26 Node* GetNodeForValues(Node** values, size_t count, |
| 27 const BitVector* liveness = nullptr); | |
| 23 | 28 |
| 24 private: | 29 private: |
| 25 static const size_t kMaxInputCount = 8; | 30 static const size_t kMaxInputCount = 8; |
| 31 typedef std::array<Node*, kMaxInputCount> WorkingBuffer; | |
| 26 | 32 |
| 27 struct NodeKey { | 33 struct NodeKey { |
| 28 Node* node; | 34 Node* node; |
| 29 | 35 |
| 30 explicit NodeKey(Node* node) : node(node) {} | 36 explicit NodeKey(Node* node) : node(node) {} |
| 31 }; | 37 }; |
| 32 | 38 |
| 33 struct StateValuesKey : public NodeKey { | 39 struct StateValuesKey : public NodeKey { |
| 34 // ValueArray - array of nodes ({node} has to be nullptr). | 40 // ValueArray - array of nodes ({node} has to be nullptr). |
| 35 size_t count; | 41 size_t count; |
| 42 SparseInputMask mask; | |
| 36 Node** values; | 43 Node** values; |
| 37 | 44 |
| 38 StateValuesKey(size_t count, Node** values) | 45 StateValuesKey(size_t count, SparseInputMask mask, Node** values) |
| 39 : NodeKey(nullptr), count(count), values(values) {} | 46 : NodeKey(nullptr), count(count), mask(mask), values(values) {} |
| 40 }; | 47 }; |
| 41 | 48 |
| 42 class ValueArrayIterator; | |
| 43 | |
| 44 static bool AreKeysEqual(void* key1, void* key2); | 49 static bool AreKeysEqual(void* key1, void* key2); |
| 45 static bool IsKeysEqualToNode(StateValuesKey* key, Node* node); | 50 static bool IsKeysEqualToNode(StateValuesKey* key, Node* node); |
| 46 static bool AreValueKeysEqual(StateValuesKey* key1, StateValuesKey* key2); | 51 static bool AreValueKeysEqual(StateValuesKey* key1, StateValuesKey* key2); |
| 47 | 52 |
| 48 Node* BuildTree(ValueArrayIterator* it, size_t max_height); | 53 // Fills {input_buffer}, starting from {input_count}, with {values}, starting |
| 49 NodeVector* GetWorkingSpace(size_t level); | 54 // at {idx}, sparsely encoding according to {liveness}. {input_count} is |
| 55 // updated with the new number of inputs in {input_buffer}, and a bitmask of | |
| 56 // the sparse encoding is returned. | |
| 57 SparseInputMask::BitMaskType FillBufferWithValues(WorkingBuffer& input_buffer, | |
| 58 size_t& input_count, | |
| 59 size_t& idx, Node** values, | |
| 60 size_t count, | |
| 61 const BitVector* liveness); | |
|
Jarin
2016/12/10 10:15:06
I think the style guide only allows passing const
Leszek Swirski
2016/12/13 14:35:16
Updated, thanks.
| |
| 62 | |
| 63 Node* BuildTree(size_t& idx, Node** values, size_t count, | |
| 64 const BitVector* liveness, size_t level); | |
| 65 | |
| 66 WorkingBuffer& GetWorkingSpace(size_t level); | |
| 50 Node* GetEmptyStateValues(); | 67 Node* GetEmptyStateValues(); |
| 51 Node* GetValuesNodeFromCache(Node** nodes, size_t count); | 68 Node* GetValuesNodeFromCache(Node** nodes, size_t count, |
| 69 SparseInputMask mask); | |
| 52 | 70 |
| 53 Graph* graph() { return js_graph_->graph(); } | 71 Graph* graph() { return js_graph_->graph(); } |
| 54 CommonOperatorBuilder* common() { return js_graph_->common(); } | 72 CommonOperatorBuilder* common() { return js_graph_->common(); } |
| 55 | 73 |
| 56 Zone* zone() { return graph()->zone(); } | 74 Zone* zone() { return graph()->zone(); } |
| 57 | 75 |
| 58 JSGraph* js_graph_; | 76 JSGraph* js_graph_; |
| 59 CustomMatcherZoneHashMap hash_map_; | 77 CustomMatcherZoneHashMap hash_map_; |
| 60 ZoneVector<NodeVector*> working_space_; // One working space per level. | 78 ZoneVector<WorkingBuffer> working_space_; // One working space per level. |
| 61 Node* empty_state_values_; | 79 Node* empty_state_values_; |
| 62 }; | 80 }; |
| 63 | 81 |
| 64 class V8_EXPORT_PRIVATE StateValuesAccess { | 82 class V8_EXPORT_PRIVATE StateValuesAccess { |
| 65 public: | 83 public: |
| 66 struct TypedNode { | 84 struct TypedNode { |
| 67 Node* node; | 85 Node* node; |
| 68 MachineType type; | 86 MachineType type; |
| 69 TypedNode(Node* node, MachineType type) : node(node), type(type) {} | 87 TypedNode(Node* node, MachineType type) : node(node), type(type) {} |
| 70 }; | 88 }; |
| 71 | 89 |
| 72 class V8_EXPORT_PRIVATE iterator { | 90 class V8_EXPORT_PRIVATE iterator { |
| 73 public: | 91 public: |
| 74 // Bare minimum of operators needed for range iteration. | 92 // Bare minimum of operators needed for range iteration. |
| 75 bool operator!=(iterator& other); | 93 bool operator!=(iterator& other); |
| 76 iterator& operator++(); | 94 iterator& operator++(); |
| 77 TypedNode operator*(); | 95 TypedNode operator*(); |
| 78 | 96 |
| 79 private: | 97 private: |
| 80 friend class StateValuesAccess; | 98 friend class StateValuesAccess; |
| 81 | 99 |
| 82 iterator() : current_depth_(-1) {} | 100 iterator() : current_depth_(-1) {} |
| 83 explicit iterator(Node* node); | 101 explicit iterator(Node* node); |
| 84 | 102 |
| 85 Node* node(); | 103 Node* node(); |
| 86 MachineType type(); | 104 MachineType type(); |
| 87 bool done(); | 105 bool done(); |
| 88 void Advance(); | 106 void Advance(); |
| 107 void EnsureValid(); | |
| 89 | 108 |
| 90 struct StatePos { | 109 SparseInputMask::InputIterator* Top(); |
| 91 Node* node; | |
| 92 int index; | |
| 93 | |
| 94 explicit StatePos(Node* node) : node(node), index(0) {} | |
| 95 StatePos() {} | |
| 96 }; | |
| 97 | |
| 98 StatePos* Top(); | |
| 99 void Push(Node* node); | 110 void Push(Node* node); |
| 100 void Pop(); | 111 void Pop(); |
| 101 | 112 |
| 102 static const int kMaxInlineDepth = 8; | 113 static const int kMaxInlineDepth = 8; |
| 103 StatePos stack_[kMaxInlineDepth]; | 114 SparseInputMask::InputIterator stack_[kMaxInlineDepth]; |
| 104 int current_depth_; | 115 int current_depth_; |
| 105 }; | 116 }; |
| 106 | 117 |
| 107 explicit StateValuesAccess(Node* node) : node_(node) {} | 118 explicit StateValuesAccess(Node* node) : node_(node) {} |
| 108 | 119 |
| 109 size_t size(); | 120 size_t size(); |
| 110 iterator begin() { return iterator(node_); } | 121 iterator begin() { return iterator(node_); } |
| 111 iterator end() { return iterator(); } | 122 iterator end() { return iterator(); } |
| 112 | 123 |
| 113 private: | 124 private: |
| 114 Node* node_; | 125 Node* node_; |
| 115 }; | 126 }; |
| 116 | 127 |
| 117 } // namespace compiler | 128 } // namespace compiler |
| 118 } // namespace internal | 129 } // namespace internal |
| 119 } // namespace v8 | 130 } // namespace v8 |
| 120 | 131 |
| 121 #endif // V8_COMPILER_STATE_VALUES_UTILS_H_ | 132 #endif // V8_COMPILER_STATE_VALUES_UTILS_H_ |
| OLD | NEW |