v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
node-aux-data.h
Go to the documentation of this file.
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_NODE_AUX_DATA_H_
6#define V8_COMPILER_NODE_AUX_DATA_H_
7
8#include "src/compiler/node.h"
10
11namespace v8 {
12namespace internal {
13namespace compiler {
14
15// Forward declarations.
16class Node;
17
18template <class T>
20 return T();
21}
22
23template <class T>
25 return T(zone);
26}
27
28template <class T, T def(Zone*) = DefaultConstruct<T>>
30 public:
31 explicit NodeAuxData(Zone* zone) : zone_(zone), aux_data_(zone) {}
32 explicit NodeAuxData(size_t initial_size, Zone* zone)
33 : zone_(zone), aux_data_(initial_size, def(zone), zone) {}
34
35 // Update entry. Returns true iff entry was changed.
36 bool Set(Node* node, T const& data) {
37 NodeId const id = node->id();
38 return Set(id, data);
39 }
40
41 bool Set(NodeId id, T const& data) {
42 if (id >= aux_data_.size()) aux_data_.resize(id + 1, def(zone_));
43 if (aux_data_[id] != data) {
44 aux_data_[id] = data;
45 return true;
46 }
47 return false;
48 }
49
50 T Get(Node* node) const { return Get(node->id()); }
51
52 T Get(NodeId id) const {
53 return (id < aux_data_.size()) ? aux_data_[id] : def(zone_);
54 }
55
56 class const_iterator;
57 friend class const_iterator;
58
59 const_iterator begin() const;
60 const_iterator end() const;
61
62 private:
65};
66
67template <class T, T def(Zone*)>
69 public:
70 using iterator_category = std::forward_iterator_tag;
71 using difference_type = int;
72 using value_type = std::pair<size_t, T>;
75
76 const_iterator(const ZoneVector<T>* data, size_t current)
77 : data_(data), current_(current) {}
79 : data_(other.data_), current_(other.current_) {}
80
82 return std::make_pair(current_, (*data_)[current_]);
83 }
84 bool operator==(const const_iterator& other) const {
85 return current_ == other.current_ && data_ == other.data_;
86 }
87 bool operator!=(const const_iterator& other) const {
88 return !(*this == other);
89 }
91 ++current_;
92 return *this;
93 }
95
96 private:
98 size_t current_;
99};
100
101template <class T, T def(Zone*)>
103 const {
104 return typename NodeAuxData<T, def>::const_iterator(&aux_data_, 0);
105}
106
107template <class T, T def(Zone*)>
109 return typename NodeAuxData<T, def>::const_iterator(&aux_data_,
110 aux_data_.size());
111}
112
113template <class T, T kNonExistent>
115 public:
116 explicit NodeAuxDataMap(Zone* zone) : map_(zone) {}
117
118 void Put(NodeId key, T value) { map_[key] = value; }
119
120 T Get(NodeId key) const {
121 auto entry = map_.find(key);
122 if (entry == map_.end()) return kNonExistent;
123 return entry->second;
124 }
125
126 void Reserve(size_t count) {
127 size_t new_capacity = map_.size() + count;
128 map_.reserve(new_capacity);
129 }
130
131 private:
133};
134
135} // namespace compiler
136} // namespace internal
137} // namespace v8
138
139#endif // V8_COMPILER_NODE_AUX_DATA_H_
#define T
uint8_t data_[MAX_STACK_LENGTH]
union v8::internal::@341::BuiltinMetadata::KindSpecificData data
ZoneUnorderedMap< NodeId, T > map_
bool operator!=(const const_iterator &other) const
const_iterator(const ZoneVector< T > *data, size_t current)
bool operator==(const const_iterator &other) const
bool Set(Node *node, T const &data)
NodeAuxData(size_t initial_size, Zone *zone)
bool Set(NodeId id, T const &data)
uint32_t count
T ZoneConstruct(Zone *zone)
T DefaultConstruct(Zone *zone)
return value
Definition map-inl.h:893
base::uc32 current_