Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(667)

Side by Side Diff: src/compiler/generic-node-inl.h

Issue 426233002: Land the Fan (disabled) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Review feedback, rebase and "git cl format" Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/compiler/generic-node.h ('k') | src/compiler/graph.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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_NODE_INL_H_
6 #define V8_COMPILER_GENERIC_NODE_INL_H_
7
8 #include "src/v8.h"
9
10 #include "src/compiler/generic-graph.h"
11 #include "src/compiler/generic-node.h"
12 #include "src/zone.h"
13
14 namespace v8 {
15 namespace internal {
16 namespace compiler {
17
18 template <class B, class S>
19 GenericNode<B, S>::GenericNode(GenericGraphBase* graph, int input_count)
20 : BaseClass(graph->zone()),
21 input_count_(input_count),
22 has_appendable_inputs_(false),
23 use_count_(0),
24 first_use_(NULL),
25 last_use_(NULL) {
26 inputs_.static_ = reinterpret_cast<Input*>(this + 1), AssignUniqueID(graph);
27 }
28
29 template <class B, class S>
30 inline void GenericNode<B, S>::AssignUniqueID(GenericGraphBase* graph) {
31 id_ = graph->NextNodeID();
32 }
33
34 template <class B, class S>
35 inline typename GenericNode<B, S>::Inputs::iterator
36 GenericNode<B, S>::Inputs::begin() {
37 return GenericNode::Inputs::iterator(this->node_, 0);
38 }
39
40 template <class B, class S>
41 inline typename GenericNode<B, S>::Inputs::iterator
42 GenericNode<B, S>::Inputs::end() {
43 return GenericNode::Inputs::iterator(this->node_, this->node_->InputCount());
44 }
45
46 template <class B, class S>
47 inline typename GenericNode<B, S>::Uses::iterator
48 GenericNode<B, S>::Uses::begin() {
49 return GenericNode::Uses::iterator(this->node_);
50 }
51
52 template <class B, class S>
53 inline typename GenericNode<B, S>::Uses::iterator
54 GenericNode<B, S>::Uses::end() {
55 return GenericNode::Uses::iterator();
56 }
57
58 template <class B, class S>
59 void GenericNode<B, S>::ReplaceUses(GenericNode* replace_to) {
60 for (Use* use = first_use_; use != NULL; use = use->next) {
61 use->from->GetInputRecordPtr(use->input_index)->to = replace_to;
62 }
63 if (replace_to->last_use_ == NULL) {
64 ASSERT_EQ(NULL, replace_to->first_use_);
65 replace_to->first_use_ = first_use_;
66 } else {
67 ASSERT_NE(NULL, replace_to->first_use_);
68 replace_to->last_use_->next = first_use_;
69 first_use_->prev = replace_to->last_use_;
70 }
71 replace_to->last_use_ = last_use_;
72 replace_to->use_count_ += use_count_;
73 use_count_ = 0;
74 first_use_ = NULL;
75 last_use_ = NULL;
76 }
77
78 template <class B, class S>
79 template <class UnaryPredicate>
80 void GenericNode<B, S>::ReplaceUsesIf(UnaryPredicate pred,
81 GenericNode* replace_to) {
82 for (Use* use = first_use_; use != NULL;) {
83 Use* next = use->next;
84 if (pred(static_cast<S*>(use->from))) {
85 RemoveUse(use);
86 replace_to->AppendUse(use);
87 use->from->GetInputRecordPtr(use->input_index)->to = replace_to;
88 }
89 use = next;
90 }
91 }
92
93 template <class B, class S>
94 void GenericNode<B, S>::RemoveAllInputs() {
95 for (typename Inputs::iterator iter(inputs().begin()); iter != inputs().end();
96 ++iter) {
97 iter.GetInput()->Update(NULL);
98 }
99 }
100
101 template <class B, class S>
102 void GenericNode<B, S>::TrimInputCount(int new_input_count) {
103 if (new_input_count == input_count_) return; // Nothing to do.
104
105 ASSERT(new_input_count < input_count_);
106
107 // Update inline inputs.
108 for (int i = new_input_count; i < input_count_; i++) {
109 GenericNode<B, S>::Input* input = GetInputRecordPtr(i);
110 input->Update(NULL);
111 }
112 input_count_ = new_input_count;
113 }
114
115 template <class B, class S>
116 void GenericNode<B, S>::ReplaceInput(int index, GenericNode<B, S>* new_to) {
117 Input* input = GetInputRecordPtr(index);
118 input->Update(new_to);
119 }
120
121 template <class B, class S>
122 void GenericNode<B, S>::Input::Update(GenericNode<B, S>* new_to) {
123 GenericNode* old_to = this->to;
124 if (new_to == old_to) return; // Nothing to do.
125 // Snip out the use from where it used to be
126 if (old_to != NULL) {
127 old_to->RemoveUse(use);
128 }
129 to = new_to;
130 // And put it into the new node's use list.
131 if (new_to != NULL) {
132 new_to->AppendUse(use);
133 } else {
134 use->next = NULL;
135 use->prev = NULL;
136 }
137 }
138
139 template <class B, class S>
140 void GenericNode<B, S>::EnsureAppendableInputs(Zone* zone) {
141 if (!has_appendable_inputs_) {
142 void* deque_buffer = zone->New(sizeof(InputDeque));
143 InputDeque* deque = new (deque_buffer) InputDeque(ZoneInputAllocator(zone));
144 for (int i = 0; i < input_count_; ++i) {
145 deque->push_back(inputs_.static_[i]);
146 }
147 inputs_.appendable_ = deque;
148 has_appendable_inputs_ = true;
149 }
150 }
151
152 template <class B, class S>
153 void GenericNode<B, S>::AppendInput(Zone* zone, GenericNode<B, S>* to_append) {
154 EnsureAppendableInputs(zone);
155 Use* new_use = new (zone) Use;
156 Input new_input;
157 new_input.to = to_append;
158 new_input.use = new_use;
159 inputs_.appendable_->push_back(new_input);
160 new_use->input_index = input_count_;
161 new_use->from = this;
162 to_append->AppendUse(new_use);
163 input_count_++;
164 }
165
166 template <class B, class S>
167 void GenericNode<B, S>::InsertInput(Zone* zone, int index,
168 GenericNode<B, S>* to_insert) {
169 ASSERT(index >= 0 && index < InputCount());
170 // TODO(turbofan): Optimize this implementation!
171 AppendInput(zone, InputAt(InputCount() - 1));
172 for (int i = InputCount() - 1; i > index; --i) {
173 ReplaceInput(i, InputAt(i - 1));
174 }
175 ReplaceInput(index, to_insert);
176 }
177
178 template <class B, class S>
179 void GenericNode<B, S>::AppendUse(Use* use) {
180 use->next = NULL;
181 use->prev = last_use_;
182 if (last_use_ == NULL) {
183 first_use_ = use;
184 } else {
185 last_use_->next = use;
186 }
187 last_use_ = use;
188 ++use_count_;
189 }
190
191 template <class B, class S>
192 void GenericNode<B, S>::RemoveUse(Use* use) {
193 if (last_use_ == use) {
194 last_use_ = use->prev;
195 }
196 if (use->prev != NULL) {
197 use->prev->next = use->next;
198 } else {
199 first_use_ = use->next;
200 }
201 if (use->next != NULL) {
202 use->next->prev = use->prev;
203 }
204 --use_count_;
205 }
206
207 template <class B, class S>
208 inline bool GenericNode<B, S>::OwnedBy(GenericNode* owner) const {
209 return first_use_ != NULL && first_use_->from == owner &&
210 first_use_->next == NULL;
211 }
212
213 template <class B, class S>
214 S* GenericNode<B, S>::New(GenericGraphBase* graph, int input_count,
215 S** inputs) {
216 size_t node_size = sizeof(GenericNode);
217 size_t inputs_size = input_count * sizeof(Input);
218 size_t uses_size = input_count * sizeof(Use);
219 size_t size = node_size + inputs_size + uses_size;
220 Zone* zone = graph->zone();
221 void* buffer = zone->New(size);
222 S* result = new (buffer) S(graph, input_count);
223 Input* input =
224 reinterpret_cast<Input*>(reinterpret_cast<char*>(buffer) + node_size);
225 Use* use =
226 reinterpret_cast<Use*>(reinterpret_cast<char*>(input) + inputs_size);
227
228 for (int current = 0; current < input_count; ++current) {
229 GenericNode* to = *inputs++;
230 input->to = to;
231 input->use = use;
232 use->input_index = current;
233 use->from = result;
234 to->AppendUse(use);
235 ++use;
236 ++input;
237 }
238 return result;
239 }
240 }
241 }
242 } // namespace v8::internal::compiler
243
244 #endif // V8_COMPILER_GENERIC_NODE_INL_H_
OLDNEW
« no previous file with comments | « src/compiler/generic-node.h ('k') | src/compiler/graph.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698