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

Side by Side Diff: src/compiler/raw-machine-assembler.cc

Issue 1347353003: [turbofan] Checking of input counts on node creation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: NewNode -> AddNode Created 5 years, 3 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
« no previous file with comments | « src/compiler/raw-machine-assembler.h ('k') | src/compiler/simplified-lowering.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 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 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 #include "src/compiler/raw-machine-assembler.h" 5 #include "src/compiler/raw-machine-assembler.h"
6 6
7 #include "src/code-factory.h" 7 #include "src/code-factory.h"
8 #include "src/compiler/pipeline.h" 8 #include "src/compiler/pipeline.h"
9 #include "src/compiler/scheduler.h" 9 #include "src/compiler/scheduler.h"
10 10
(...skipping 14 matching lines...) Expand all
25 parameters_(nullptr), 25 parameters_(nullptr),
26 current_block_(schedule()->start()) { 26 current_block_(schedule()->start()) {
27 int param_count = static_cast<int>(parameter_count()); 27 int param_count = static_cast<int>(parameter_count());
28 // Add an extra input node for the JSFunction parameter to the start node. 28 // Add an extra input node for the JSFunction parameter to the start node.
29 Node* s = graph->NewNode(common_.Start(param_count + 1)); 29 Node* s = graph->NewNode(common_.Start(param_count + 1));
30 graph->SetStart(s); 30 graph->SetStart(s);
31 if (parameter_count() == 0) return; 31 if (parameter_count() == 0) return;
32 parameters_ = zone()->NewArray<Node*>(param_count); 32 parameters_ = zone()->NewArray<Node*>(param_count);
33 for (size_t i = 0; i < parameter_count(); ++i) { 33 for (size_t i = 0; i < parameter_count(); ++i) {
34 parameters_[i] = 34 parameters_[i] =
35 NewNode(common()->Parameter(static_cast<int>(i)), graph->start()); 35 AddNode(common()->Parameter(static_cast<int>(i)), graph->start());
36 } 36 }
37 } 37 }
38 38
39 39
40 Schedule* RawMachineAssembler::Export() { 40 Schedule* RawMachineAssembler::Export() {
41 // Compute the correct codegen order. 41 // Compute the correct codegen order.
42 DCHECK(schedule_->rpo_order()->empty()); 42 DCHECK(schedule_->rpo_order()->empty());
43 Scheduler::ComputeSpecialRPO(zone(), schedule_); 43 Scheduler::ComputeSpecialRPO(zone(), schedule_);
44 // Invalidate RawMachineAssembler. 44 // Invalidate RawMachineAssembler.
45 Schedule* schedule = schedule_; 45 Schedule* schedule = schedule_;
(...skipping 11 matching lines...) Expand all
57 void RawMachineAssembler::Goto(Label* label) { 57 void RawMachineAssembler::Goto(Label* label) {
58 DCHECK(current_block_ != schedule()->end()); 58 DCHECK(current_block_ != schedule()->end());
59 schedule()->AddGoto(CurrentBlock(), Use(label)); 59 schedule()->AddGoto(CurrentBlock(), Use(label));
60 current_block_ = nullptr; 60 current_block_ = nullptr;
61 } 61 }
62 62
63 63
64 void RawMachineAssembler::Branch(Node* condition, Label* true_val, 64 void RawMachineAssembler::Branch(Node* condition, Label* true_val,
65 Label* false_val) { 65 Label* false_val) {
66 DCHECK(current_block_ != schedule()->end()); 66 DCHECK(current_block_ != schedule()->end());
67 Node* branch = NewNode(common()->Branch(), condition); 67 Node* branch = AddNode(common()->Branch(), condition);
68 schedule()->AddBranch(CurrentBlock(), branch, Use(true_val), Use(false_val)); 68 schedule()->AddBranch(CurrentBlock(), branch, Use(true_val), Use(false_val));
69 current_block_ = nullptr; 69 current_block_ = nullptr;
70 } 70 }
71 71
72 72
73 void RawMachineAssembler::Switch(Node* index, Label* default_label, 73 void RawMachineAssembler::Switch(Node* index, Label* default_label,
74 int32_t* case_values, Label** case_labels, 74 int32_t* case_values, Label** case_labels,
75 size_t case_count) { 75 size_t case_count) {
76 DCHECK_NE(schedule()->end(), current_block_); 76 DCHECK_NE(schedule()->end(), current_block_);
77 size_t succ_count = case_count + 1; 77 size_t succ_count = case_count + 1;
78 Node* switch_node = NewNode(common()->Switch(succ_count), index); 78 Node* switch_node = AddNode(common()->Switch(succ_count), index);
79 BasicBlock** succ_blocks = zone()->NewArray<BasicBlock*>(succ_count); 79 BasicBlock** succ_blocks = zone()->NewArray<BasicBlock*>(succ_count);
80 for (size_t index = 0; index < case_count; ++index) { 80 for (size_t index = 0; index < case_count; ++index) {
81 int32_t case_value = case_values[index]; 81 int32_t case_value = case_values[index];
82 BasicBlock* case_block = Use(case_labels[index]); 82 BasicBlock* case_block = Use(case_labels[index]);
83 Node* case_node = 83 Node* case_node =
84 graph()->NewNode(common()->IfValue(case_value), switch_node); 84 graph()->NewNode(common()->IfValue(case_value), switch_node);
85 schedule()->AddNode(case_block, case_node); 85 schedule()->AddNode(case_block, case_node);
86 succ_blocks[index] = case_block; 86 succ_blocks[index] = case_block;
87 } 87 }
88 BasicBlock* default_block = Use(default_label); 88 BasicBlock* default_block = Use(default_label);
89 Node* default_node = graph()->NewNode(common()->IfDefault(), switch_node); 89 Node* default_node = graph()->NewNode(common()->IfDefault(), switch_node);
90 schedule()->AddNode(default_block, default_node); 90 schedule()->AddNode(default_block, default_node);
91 succ_blocks[case_count] = default_block; 91 succ_blocks[case_count] = default_block;
92 schedule()->AddSwitch(CurrentBlock(), switch_node, succ_blocks, succ_count); 92 schedule()->AddSwitch(CurrentBlock(), switch_node, succ_blocks, succ_count);
93 current_block_ = nullptr; 93 current_block_ = nullptr;
94 } 94 }
95 95
96 96
97 void RawMachineAssembler::Return(Node* value) { 97 void RawMachineAssembler::Return(Node* value) {
98 Node* ret = graph()->NewNode(common()->Return(), value); 98 Node* ret = MakeNode(common()->Return(), 1, &value);
99 schedule()->AddReturn(CurrentBlock(), ret); 99 schedule()->AddReturn(CurrentBlock(), ret);
100 current_block_ = nullptr; 100 current_block_ = nullptr;
101 } 101 }
102 102
103 103
104 Node* RawMachineAssembler::CallN(CallDescriptor* desc, Node* function, 104 Node* RawMachineAssembler::CallN(CallDescriptor* desc, Node* function,
105 Node** args) { 105 Node** args) {
106 int param_count = 106 int param_count =
107 static_cast<int>(desc->GetMachineSignature()->parameter_count()); 107 static_cast<int>(desc->GetMachineSignature()->parameter_count());
108 int input_count = param_count + 3; 108 int input_count = param_count + 3;
109 Node** buffer = zone()->NewArray<Node*>(input_count); 109 Node** buffer = zone()->NewArray<Node*>(input_count);
110 int index = 0; 110 int index = 0;
111 buffer[index++] = function; 111 buffer[index++] = function;
112 for (int i = 0; i < param_count; i++) { 112 for (int i = 0; i < param_count; i++) {
113 buffer[index++] = args[i]; 113 buffer[index++] = args[i];
114 } 114 }
115 buffer[index++] = graph()->start(); 115 buffer[index++] = graph()->start();
116 buffer[index++] = graph()->start(); 116 buffer[index++] = graph()->start();
117 Node* call = graph()->NewNode(common()->Call(desc), input_count, buffer); 117 return AddNode(common()->Call(desc), input_count, buffer);
118 schedule()->AddNode(CurrentBlock(), call);
119 return call;
120 } 118 }
121 119
122 120
123 Node* RawMachineAssembler::CallNWithFrameState(CallDescriptor* desc, 121 Node* RawMachineAssembler::CallNWithFrameState(CallDescriptor* desc,
124 Node* function, Node** args, 122 Node* function, Node** args,
125 Node* frame_state) { 123 Node* frame_state) {
126 DCHECK(desc->NeedsFrameState()); 124 DCHECK(desc->NeedsFrameState());
127 int param_count = 125 int param_count =
128 static_cast<int>(desc->GetMachineSignature()->parameter_count()); 126 static_cast<int>(desc->GetMachineSignature()->parameter_count());
129 int input_count = param_count + 4; 127 int input_count = param_count + 4;
130 Node** buffer = zone()->NewArray<Node*>(input_count); 128 Node** buffer = zone()->NewArray<Node*>(input_count);
131 int index = 0; 129 int index = 0;
132 buffer[index++] = function; 130 buffer[index++] = function;
133 for (int i = 0; i < param_count; i++) { 131 for (int i = 0; i < param_count; i++) {
134 buffer[index++] = args[i]; 132 buffer[index++] = args[i];
135 } 133 }
136 buffer[index++] = frame_state; 134 buffer[index++] = frame_state;
137 buffer[index++] = graph()->start(); 135 buffer[index++] = graph()->start();
138 buffer[index++] = graph()->start(); 136 buffer[index++] = graph()->start();
139 Node* call = graph()->NewNode(common()->Call(desc), input_count, buffer); 137 return AddNode(common()->Call(desc), input_count, buffer);
140 schedule()->AddNode(CurrentBlock(), call);
141 return call;
142 } 138 }
143 139
144 140
145 Node* RawMachineAssembler::TailCallN(CallDescriptor* desc, Node* function, 141 Node* RawMachineAssembler::TailCallN(CallDescriptor* desc, Node* function,
146 Node** args) { 142 Node** args) {
147 int param_count = 143 int param_count =
148 static_cast<int>(desc->GetMachineSignature()->parameter_count()); 144 static_cast<int>(desc->GetMachineSignature()->parameter_count());
149 int input_count = param_count + 3; 145 int input_count = param_count + 3;
150 Node** buffer = zone()->NewArray<Node*>(input_count); 146 Node** buffer = zone()->NewArray<Node*>(input_count);
151 int index = 0; 147 int index = 0;
152 buffer[index++] = function; 148 buffer[index++] = function;
153 for (int i = 0; i < param_count; i++) { 149 for (int i = 0; i < param_count; i++) {
154 buffer[index++] = args[i]; 150 buffer[index++] = args[i];
155 } 151 }
156 buffer[index++] = graph()->start(); 152 buffer[index++] = graph()->start();
157 buffer[index++] = graph()->start(); 153 buffer[index++] = graph()->start();
158 Node* tail_call = 154 Node* tail_call = MakeNode(common()->TailCall(desc), input_count, buffer);
159 graph()->NewNode(common()->TailCall(desc), input_count, buffer);
160 schedule()->AddTailCall(CurrentBlock(), tail_call); 155 schedule()->AddTailCall(CurrentBlock(), tail_call);
161 return tail_call; 156 return tail_call;
162 } 157 }
163 158
164 159
165 Node* RawMachineAssembler::CallFunctionStub0(Node* function, Node* receiver, 160 Node* RawMachineAssembler::CallFunctionStub0(Node* function, Node* receiver,
166 Node* context, Node* frame_state, 161 Node* context, Node* frame_state,
167 CallFunctionFlags flags) { 162 CallFunctionFlags flags) {
168 Callable callable = CodeFactory::CallFunction(isolate(), 0, flags); 163 Callable callable = CodeFactory::CallFunction(isolate(), 0, flags);
169 CallDescriptor* desc = Linkage::GetStubCallDescriptor( 164 CallDescriptor* desc = Linkage::GetStubCallDescriptor(
170 isolate(), zone(), callable.descriptor(), 1, 165 isolate(), zone(), callable.descriptor(), 1,
171 CallDescriptor::kNeedsFrameState, Operator::kNoProperties); 166 CallDescriptor::kNeedsFrameState, Operator::kNoProperties);
172 Node* stub_code = HeapConstant(callable.code()); 167 Node* stub_code = HeapConstant(callable.code());
173 Node* call = graph()->NewNode(common()->Call(desc), stub_code, function, 168 return AddNode(common()->Call(desc), stub_code, function, receiver, context,
174 receiver, context, frame_state, 169 frame_state, graph()->start(), graph()->start());
175 graph()->start(), graph()->start());
176 schedule()->AddNode(CurrentBlock(), call);
177 return call;
178 } 170 }
179 171
180 172
181 Node* RawMachineAssembler::CallRuntime1(Runtime::FunctionId function, 173 Node* RawMachineAssembler::CallRuntime1(Runtime::FunctionId function,
182 Node* arg1, Node* context) { 174 Node* arg1, Node* context) {
183 CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor( 175 CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor(
184 zone(), function, 1, Operator::kNoProperties, false); 176 zone(), function, 1, Operator::kNoProperties, false);
185 177
186 Node* centry = HeapConstant(CEntryStub(isolate(), 1).GetCode()); 178 Node* centry = HeapConstant(CEntryStub(isolate(), 1).GetCode());
187 Node* ref = NewNode( 179 Node* ref = AddNode(
188 common()->ExternalConstant(ExternalReference(function, isolate()))); 180 common()->ExternalConstant(ExternalReference(function, isolate())));
189 Node* arity = Int32Constant(1); 181 Node* arity = Int32Constant(1);
190 182
191 Node* call = 183 return AddNode(common()->Call(descriptor), centry, arg1, ref, arity, context,
192 graph()->NewNode(common()->Call(descriptor), centry, arg1, ref, arity, 184 graph()->start(), graph()->start());
193 context, graph()->start(), graph()->start());
194 schedule()->AddNode(CurrentBlock(), call);
195 return call;
196 } 185 }
197 186
198 187
199 Node* RawMachineAssembler::CallRuntime2(Runtime::FunctionId function, 188 Node* RawMachineAssembler::CallRuntime2(Runtime::FunctionId function,
200 Node* arg1, Node* arg2, Node* context) { 189 Node* arg1, Node* arg2, Node* context) {
201 CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor( 190 CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor(
202 zone(), function, 2, Operator::kNoProperties, false); 191 zone(), function, 2, Operator::kNoProperties, false);
203 192
204 Node* centry = HeapConstant(CEntryStub(isolate(), 1).GetCode()); 193 Node* centry = HeapConstant(CEntryStub(isolate(), 1).GetCode());
205 Node* ref = NewNode( 194 Node* ref = AddNode(
206 common()->ExternalConstant(ExternalReference(function, isolate()))); 195 common()->ExternalConstant(ExternalReference(function, isolate())));
207 Node* arity = Int32Constant(2); 196 Node* arity = Int32Constant(2);
208 197
209 Node* call = 198 return AddNode(common()->Call(descriptor), centry, arg1, arg2, ref, arity,
210 graph()->NewNode(common()->Call(descriptor), centry, arg1, arg2, ref, 199 context, graph()->start(), graph()->start());
211 arity, context, graph()->start(), graph()->start());
212 schedule()->AddNode(CurrentBlock(), call);
213 return call;
214 } 200 }
215 201
216 202
217 Node* RawMachineAssembler::CallCFunction0(MachineType return_type, 203 Node* RawMachineAssembler::CallCFunction0(MachineType return_type,
218 Node* function) { 204 Node* function) {
219 MachineSignature::Builder builder(zone(), 1, 0); 205 MachineSignature::Builder builder(zone(), 1, 0);
220 builder.AddReturn(return_type); 206 builder.AddReturn(return_type);
221 const CallDescriptor* descriptor = 207 const CallDescriptor* descriptor =
222 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); 208 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build());
223 209
224 Node* call = graph()->NewNode(common()->Call(descriptor), function, 210 return AddNode(common()->Call(descriptor), function, graph()->start(),
225 graph()->start(), graph()->start()); 211 graph()->start());
226 schedule()->AddNode(CurrentBlock(), call);
227 return call;
228 } 212 }
229 213
230 214
231 Node* RawMachineAssembler::CallCFunction1(MachineType return_type, 215 Node* RawMachineAssembler::CallCFunction1(MachineType return_type,
232 MachineType arg0_type, Node* function, 216 MachineType arg0_type, Node* function,
233 Node* arg0) { 217 Node* arg0) {
234 MachineSignature::Builder builder(zone(), 1, 1); 218 MachineSignature::Builder builder(zone(), 1, 1);
235 builder.AddReturn(return_type); 219 builder.AddReturn(return_type);
236 builder.AddParam(arg0_type); 220 builder.AddParam(arg0_type);
237 const CallDescriptor* descriptor = 221 const CallDescriptor* descriptor =
238 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); 222 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build());
239 223
240 Node* call = graph()->NewNode(common()->Call(descriptor), function, arg0, 224 return AddNode(common()->Call(descriptor), function, arg0, graph()->start(),
241 graph()->start(), graph()->start()); 225 graph()->start());
242 schedule()->AddNode(CurrentBlock(), call);
243 return call;
244 } 226 }
245 227
246 228
247 Node* RawMachineAssembler::CallCFunction2(MachineType return_type, 229 Node* RawMachineAssembler::CallCFunction2(MachineType return_type,
248 MachineType arg0_type, 230 MachineType arg0_type,
249 MachineType arg1_type, Node* function, 231 MachineType arg1_type, Node* function,
250 Node* arg0, Node* arg1) { 232 Node* arg0, Node* arg1) {
251 MachineSignature::Builder builder(zone(), 1, 2); 233 MachineSignature::Builder builder(zone(), 1, 2);
252 builder.AddReturn(return_type); 234 builder.AddReturn(return_type);
253 builder.AddParam(arg0_type); 235 builder.AddParam(arg0_type);
254 builder.AddParam(arg1_type); 236 builder.AddParam(arg1_type);
255 const CallDescriptor* descriptor = 237 const CallDescriptor* descriptor =
256 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); 238 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build());
257 239
258 Node* call = graph()->NewNode(common()->Call(descriptor), function, arg0, 240 return AddNode(common()->Call(descriptor), function, arg0, arg1,
259 arg1, graph()->start(), graph()->start()); 241 graph()->start(), graph()->start());
260 schedule()->AddNode(CurrentBlock(), call);
261 return call;
262 } 242 }
263 243
264 244
265 Node* RawMachineAssembler::CallCFunction8( 245 Node* RawMachineAssembler::CallCFunction8(
266 MachineType return_type, MachineType arg0_type, MachineType arg1_type, 246 MachineType return_type, MachineType arg0_type, MachineType arg1_type,
267 MachineType arg2_type, MachineType arg3_type, MachineType arg4_type, 247 MachineType arg2_type, MachineType arg3_type, MachineType arg4_type,
268 MachineType arg5_type, MachineType arg6_type, MachineType arg7_type, 248 MachineType arg5_type, MachineType arg6_type, MachineType arg7_type,
269 Node* function, Node* arg0, Node* arg1, Node* arg2, Node* arg3, Node* arg4, 249 Node* function, Node* arg0, Node* arg1, Node* arg2, Node* arg3, Node* arg4,
270 Node* arg5, Node* arg6, Node* arg7) { 250 Node* arg5, Node* arg6, Node* arg7) {
271 MachineSignature::Builder builder(zone(), 1, 8); 251 MachineSignature::Builder builder(zone(), 1, 8);
(...skipping 12 matching lines...) Expand all
284 arg2, 264 arg2,
285 arg3, 265 arg3,
286 arg4, 266 arg4,
287 arg5, 267 arg5,
288 arg6, 268 arg6,
289 arg7, 269 arg7,
290 graph()->start(), 270 graph()->start(),
291 graph()->start()}; 271 graph()->start()};
292 const CallDescriptor* descriptor = 272 const CallDescriptor* descriptor =
293 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); 273 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build());
294 Node* call = 274 return AddNode(common()->Call(descriptor), arraysize(args), args);
295 graph()->NewNode(common()->Call(descriptor), arraysize(args), args);
296 schedule()->AddNode(CurrentBlock(), call);
297 return call;
298 } 275 }
299 276
300 277
301 void RawMachineAssembler::Bind(Label* label) { 278 void RawMachineAssembler::Bind(Label* label) {
302 DCHECK(current_block_ == nullptr); 279 DCHECK(current_block_ == nullptr);
303 DCHECK(!label->bound_); 280 DCHECK(!label->bound_);
304 label->bound_ = true; 281 label->bound_ = true;
305 current_block_ = EnsureBlock(label); 282 current_block_ = EnsureBlock(label);
306 } 283 }
307 284
308 285
309 BasicBlock* RawMachineAssembler::Use(Label* label) { 286 BasicBlock* RawMachineAssembler::Use(Label* label) {
310 label->used_ = true; 287 label->used_ = true;
311 return EnsureBlock(label); 288 return EnsureBlock(label);
312 } 289 }
313 290
314 291
315 BasicBlock* RawMachineAssembler::EnsureBlock(Label* label) { 292 BasicBlock* RawMachineAssembler::EnsureBlock(Label* label) {
316 if (label->block_ == nullptr) label->block_ = schedule()->NewBasicBlock(); 293 if (label->block_ == nullptr) label->block_ = schedule()->NewBasicBlock();
317 return label->block_; 294 return label->block_;
318 } 295 }
319 296
320 297
321 BasicBlock* RawMachineAssembler::CurrentBlock() { 298 BasicBlock* RawMachineAssembler::CurrentBlock() {
322 DCHECK(current_block_); 299 DCHECK(current_block_);
323 return current_block_; 300 return current_block_;
324 } 301 }
325 302
326 303
304 Node* RawMachineAssembler::AddNode(const Operator* op, int input_count,
305 Node** inputs) {
306 DCHECK_NOT_NULL(schedule_);
307 DCHECK(current_block_ != nullptr);
308 Node* node = MakeNode(op, input_count, inputs);
309 schedule()->AddNode(CurrentBlock(), node);
310 return node;
311 }
312
313
327 Node* RawMachineAssembler::MakeNode(const Operator* op, int input_count, 314 Node* RawMachineAssembler::MakeNode(const Operator* op, int input_count,
328 Node** inputs) { 315 Node** inputs) {
329 DCHECK_NOT_NULL(schedule_); 316 // The raw machine assembler nodes do not have effect and control inputs,
330 DCHECK(current_block_ != nullptr); 317 // so we disable checking input counts here.
331 Node* node = graph()->NewNode(op, input_count, inputs); 318 return graph()->NewNodeUnchecked(op, input_count, inputs);
332 schedule()->AddNode(CurrentBlock(), node);
333 return node;
334 } 319 }
335 320
336 } // namespace compiler 321 } // namespace compiler
337 } // namespace internal 322 } // namespace internal
338 } // namespace v8 323 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/raw-machine-assembler.h ('k') | src/compiler/simplified-lowering.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698