blob: 728d79af5b36c297471ce6be6d51f058cc237c6a [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005#include "src/compiler/raw-machine-assembler.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006
7#include "src/code-factory.h"
8#include "src/compiler/node-properties.h"
9#include "src/compiler/pipeline.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010#include "src/compiler/scheduler.h"
11
12namespace v8 {
13namespace internal {
14namespace compiler {
15
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000016RawMachineAssembler::RawMachineAssembler(Isolate* isolate, Graph* graph,
17 CallDescriptor* call_descriptor,
18 MachineRepresentation word,
Emily Bernierd0a1eb72015-03-24 16:35:39 -040019 MachineOperatorBuilder::Flags flags)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000020 : isolate_(isolate),
21 graph_(graph),
Ben Murdochb8a8cc12014-11-26 15:28:44 +000022 schedule_(new (zone()) Schedule(zone())),
Emily Bernierd0a1eb72015-03-24 16:35:39 -040023 machine_(zone(), word, flags),
Ben Murdochb8a8cc12014-11-26 15:28:44 +000024 common_(zone()),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000025 call_descriptor_(call_descriptor),
26 parameters_(parameter_count(), zone()),
Ben Murdochb8a8cc12014-11-26 15:28:44 +000027 current_block_(schedule()->start()) {
28 int param_count = static_cast<int>(parameter_count());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000029 // Add an extra input for the JSFunction parameter to the start node.
30 graph->SetStart(graph->NewNode(common_.Start(param_count + 1)));
Ben Murdochb8a8cc12014-11-26 15:28:44 +000031 for (size_t i = 0; i < parameter_count(); ++i) {
32 parameters_[i] =
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000033 AddNode(common()->Parameter(static_cast<int>(i)), graph->start());
Ben Murdochb8a8cc12014-11-26 15:28:44 +000034 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000035 graph->SetEnd(graph->NewNode(common_.End(0)));
Ben Murdochb8a8cc12014-11-26 15:28:44 +000036}
37
38
39Schedule* RawMachineAssembler::Export() {
40 // Compute the correct codegen order.
41 DCHECK(schedule_->rpo_order()->empty());
Ben Murdochda12d292016-06-02 14:46:10 +010042 OFStream os(stdout);
43 if (FLAG_trace_turbo_scheduler) {
44 PrintF("--- RAW SCHEDULE -------------------------------------------\n");
45 os << *schedule_;
46 }
47 schedule_->EnsureSplitEdgeForm();
48 schedule_->PropagateDeferredMark();
49 if (FLAG_trace_turbo_scheduler) {
50 PrintF("--- EDGE SPLIT AND PROPAGATED DEFERRED SCHEDULE ------------\n");
51 os << *schedule_;
52 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -040053 Scheduler::ComputeSpecialRPO(zone(), schedule_);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000054 // Invalidate RawMachineAssembler.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000055 Schedule* schedule = schedule_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000056 schedule_ = nullptr;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000057 return schedule;
58}
59
60
61Node* RawMachineAssembler::Parameter(size_t index) {
62 DCHECK(index < parameter_count());
63 return parameters_[index];
64}
65
66
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000067void RawMachineAssembler::Goto(RawMachineLabel* label) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000068 DCHECK(current_block_ != schedule()->end());
69 schedule()->AddGoto(CurrentBlock(), Use(label));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000070 current_block_ = nullptr;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000071}
72
73
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000074void RawMachineAssembler::Branch(Node* condition, RawMachineLabel* true_val,
75 RawMachineLabel* false_val) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000076 DCHECK(current_block_ != schedule()->end());
Ben Murdoch097c5b22016-05-18 11:27:45 +010077 Node* branch = MakeNode(common()->Branch(), 1, &condition);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000078 schedule()->AddBranch(CurrentBlock(), branch, Use(true_val), Use(false_val));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000079 current_block_ = nullptr;
80}
81
82
83void RawMachineAssembler::Switch(Node* index, RawMachineLabel* default_label,
84 int32_t* case_values,
85 RawMachineLabel** case_labels,
86 size_t case_count) {
87 DCHECK_NE(schedule()->end(), current_block_);
88 size_t succ_count = case_count + 1;
89 Node* switch_node = AddNode(common()->Switch(succ_count), index);
90 BasicBlock** succ_blocks = zone()->NewArray<BasicBlock*>(succ_count);
91 for (size_t index = 0; index < case_count; ++index) {
92 int32_t case_value = case_values[index];
Ben Murdochda12d292016-06-02 14:46:10 +010093 BasicBlock* case_block = schedule()->NewBasicBlock();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000094 Node* case_node =
95 graph()->NewNode(common()->IfValue(case_value), switch_node);
96 schedule()->AddNode(case_block, case_node);
Ben Murdochda12d292016-06-02 14:46:10 +010097 schedule()->AddGoto(case_block, Use(case_labels[index]));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000098 succ_blocks[index] = case_block;
99 }
Ben Murdochda12d292016-06-02 14:46:10 +0100100 BasicBlock* default_block = schedule()->NewBasicBlock();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000101 Node* default_node = graph()->NewNode(common()->IfDefault(), switch_node);
102 schedule()->AddNode(default_block, default_node);
Ben Murdochda12d292016-06-02 14:46:10 +0100103 schedule()->AddGoto(default_block, Use(default_label));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000104 succ_blocks[case_count] = default_block;
105 schedule()->AddSwitch(CurrentBlock(), switch_node, succ_blocks, succ_count);
106 current_block_ = nullptr;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000107}
108
109
110void RawMachineAssembler::Return(Node* value) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000111 Node* ret = MakeNode(common()->Return(), 1, &value);
112 NodeProperties::MergeControlToEnd(graph(), common(), ret);
113 schedule()->AddReturn(CurrentBlock(), ret);
114 current_block_ = nullptr;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000115}
116
117
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000118void RawMachineAssembler::Return(Node* v1, Node* v2) {
119 Node* values[] = {v1, v2};
120 Node* ret = MakeNode(common()->Return(2), 2, values);
121 NodeProperties::MergeControlToEnd(graph(), common(), ret);
122 schedule()->AddReturn(CurrentBlock(), ret);
123 current_block_ = nullptr;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000124}
125
126
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000127void RawMachineAssembler::Return(Node* v1, Node* v2, Node* v3) {
128 Node* values[] = {v1, v2, v3};
129 Node* ret = MakeNode(common()->Return(3), 3, values);
130 NodeProperties::MergeControlToEnd(graph(), common(), ret);
131 schedule()->AddReturn(CurrentBlock(), ret);
132 current_block_ = nullptr;
133}
134
135
136Node* RawMachineAssembler::CallN(CallDescriptor* desc, Node* function,
137 Node** args) {
138 int param_count =
139 static_cast<int>(desc->GetMachineSignature()->parameter_count());
140 int input_count = param_count + 1;
141 Node** buffer = zone()->NewArray<Node*>(input_count);
142 int index = 0;
143 buffer[index++] = function;
144 for (int i = 0; i < param_count; i++) {
145 buffer[index++] = args[i];
146 }
147 return AddNode(common()->Call(desc), input_count, buffer);
148}
149
150
151Node* RawMachineAssembler::CallNWithFrameState(CallDescriptor* desc,
152 Node* function, Node** args,
153 Node* frame_state) {
154 DCHECK(desc->NeedsFrameState());
155 int param_count =
156 static_cast<int>(desc->GetMachineSignature()->parameter_count());
157 int input_count = param_count + 2;
158 Node** buffer = zone()->NewArray<Node*>(input_count);
159 int index = 0;
160 buffer[index++] = function;
161 for (int i = 0; i < param_count; i++) {
162 buffer[index++] = args[i];
163 }
164 buffer[index++] = frame_state;
165 return AddNode(common()->Call(desc), input_count, buffer);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000166}
167
Ben Murdoch097c5b22016-05-18 11:27:45 +0100168Node* RawMachineAssembler::CallRuntime0(Runtime::FunctionId function,
169 Node* context) {
170 CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor(
171 zone(), function, 0, Operator::kNoProperties, CallDescriptor::kNoFlags);
172 int return_count = static_cast<int>(descriptor->ReturnCount());
173
174 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
175 Node* ref = AddNode(
176 common()->ExternalConstant(ExternalReference(function, isolate())));
177 Node* arity = Int32Constant(0);
178
179 return AddNode(common()->Call(descriptor), centry, ref, arity, context);
180}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000181
182Node* RawMachineAssembler::CallRuntime1(Runtime::FunctionId function,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000183 Node* arg1, Node* context) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000184 CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000185 zone(), function, 1, Operator::kNoProperties, CallDescriptor::kNoFlags);
186 int return_count = static_cast<int>(descriptor->ReturnCount());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000187
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000188 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
189 Node* ref = AddNode(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000190 common()->ExternalConstant(ExternalReference(function, isolate())));
191 Node* arity = Int32Constant(1);
192
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000193 return AddNode(common()->Call(descriptor), centry, arg1, ref, arity, context);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000194}
195
196
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000197Node* RawMachineAssembler::CallRuntime2(Runtime::FunctionId function,
198 Node* arg1, Node* arg2, Node* context) {
199 CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor(
200 zone(), function, 2, Operator::kNoProperties, CallDescriptor::kNoFlags);
201 int return_count = static_cast<int>(descriptor->ReturnCount());
202
203 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
204 Node* ref = AddNode(
205 common()->ExternalConstant(ExternalReference(function, isolate())));
206 Node* arity = Int32Constant(2);
207
208 return AddNode(common()->Call(descriptor), centry, arg1, arg2, ref, arity,
209 context);
210}
211
Ben Murdoch097c5b22016-05-18 11:27:45 +0100212Node* RawMachineAssembler::CallRuntime3(Runtime::FunctionId function,
213 Node* arg1, Node* arg2, Node* arg3,
214 Node* context) {
215 CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor(
216 zone(), function, 3, Operator::kNoProperties, CallDescriptor::kNoFlags);
217 int return_count = static_cast<int>(descriptor->ReturnCount());
218
219 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
220 Node* ref = AddNode(
221 common()->ExternalConstant(ExternalReference(function, isolate())));
222 Node* arity = Int32Constant(3);
223
224 return AddNode(common()->Call(descriptor), centry, arg1, arg2, arg3, ref,
225 arity, context);
226}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000227
228Node* RawMachineAssembler::CallRuntime4(Runtime::FunctionId function,
229 Node* arg1, Node* arg2, Node* arg3,
230 Node* arg4, Node* context) {
231 CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor(
232 zone(), function, 4, Operator::kNoProperties, CallDescriptor::kNoFlags);
233 int return_count = static_cast<int>(descriptor->ReturnCount());
234
235 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
236 Node* ref = AddNode(
237 common()->ExternalConstant(ExternalReference(function, isolate())));
238 Node* arity = Int32Constant(4);
239
240 return AddNode(common()->Call(descriptor), centry, arg1, arg2, arg3, arg4,
241 ref, arity, context);
242}
243
244
245Node* RawMachineAssembler::TailCallN(CallDescriptor* desc, Node* function,
246 Node** args) {
247 int param_count =
248 static_cast<int>(desc->GetMachineSignature()->parameter_count());
249 int input_count = param_count + 1;
250 Node** buffer = zone()->NewArray<Node*>(input_count);
251 int index = 0;
252 buffer[index++] = function;
253 for (int i = 0; i < param_count; i++) {
254 buffer[index++] = args[i];
255 }
256 Node* tail_call = MakeNode(common()->TailCall(desc), input_count, buffer);
257 NodeProperties::MergeControlToEnd(graph(), common(), tail_call);
258 schedule()->AddTailCall(CurrentBlock(), tail_call);
259 current_block_ = nullptr;
260 return tail_call;
261}
262
Ben Murdochda12d292016-06-02 14:46:10 +0100263Node* RawMachineAssembler::TailCallRuntime0(Runtime::FunctionId function,
264 Node* context) {
265 const int kArity = 0;
266 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
267 zone(), function, kArity, Operator::kNoProperties,
268 CallDescriptor::kSupportsTailCalls);
269 int return_count = static_cast<int>(desc->ReturnCount());
270
271 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
272 Node* ref = AddNode(
273 common()->ExternalConstant(ExternalReference(function, isolate())));
274 Node* arity = Int32Constant(kArity);
275
276 Node* nodes[] = {centry, ref, arity, context};
277 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes);
278
279 NodeProperties::MergeControlToEnd(graph(), common(), tail_call);
280 schedule()->AddTailCall(CurrentBlock(), tail_call);
281 current_block_ = nullptr;
282 return tail_call;
283}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000284
285Node* RawMachineAssembler::TailCallRuntime1(Runtime::FunctionId function,
286 Node* arg1, Node* context) {
287 const int kArity = 1;
288 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
289 zone(), function, kArity, Operator::kNoProperties,
290 CallDescriptor::kSupportsTailCalls);
291 int return_count = static_cast<int>(desc->ReturnCount());
292
293 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
294 Node* ref = AddNode(
295 common()->ExternalConstant(ExternalReference(function, isolate())));
296 Node* arity = Int32Constant(kArity);
297
298 Node* nodes[] = {centry, arg1, ref, arity, context};
299 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes);
300
301 NodeProperties::MergeControlToEnd(graph(), common(), tail_call);
302 schedule()->AddTailCall(CurrentBlock(), tail_call);
303 current_block_ = nullptr;
304 return tail_call;
305}
306
307
308Node* RawMachineAssembler::TailCallRuntime2(Runtime::FunctionId function,
309 Node* arg1, Node* arg2,
310 Node* context) {
311 const int kArity = 2;
312 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
313 zone(), function, kArity, Operator::kNoProperties,
314 CallDescriptor::kSupportsTailCalls);
315 int return_count = static_cast<int>(desc->ReturnCount());
316
317 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
318 Node* ref = AddNode(
319 common()->ExternalConstant(ExternalReference(function, isolate())));
320 Node* arity = Int32Constant(kArity);
321
322 Node* nodes[] = {centry, arg1, arg2, ref, arity, context};
323 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes);
324
325 NodeProperties::MergeControlToEnd(graph(), common(), tail_call);
326 schedule()->AddTailCall(CurrentBlock(), tail_call);
327 current_block_ = nullptr;
328 return tail_call;
329}
330
Ben Murdoch097c5b22016-05-18 11:27:45 +0100331Node* RawMachineAssembler::TailCallRuntime3(Runtime::FunctionId function,
332 Node* arg1, Node* arg2, Node* arg3,
333 Node* context) {
334 const int kArity = 3;
335 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
336 zone(), function, kArity, Operator::kNoProperties,
337 CallDescriptor::kSupportsTailCalls);
338 int return_count = static_cast<int>(desc->ReturnCount());
339
340 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
341 Node* ref = AddNode(
342 common()->ExternalConstant(ExternalReference(function, isolate())));
343 Node* arity = Int32Constant(kArity);
344
345 Node* nodes[] = {centry, arg1, arg2, arg3, ref, arity, context};
346 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes);
347
348 NodeProperties::MergeControlToEnd(graph(), common(), tail_call);
349 schedule()->AddTailCall(CurrentBlock(), tail_call);
350 current_block_ = nullptr;
351 return tail_call;
352}
353
354Node* RawMachineAssembler::TailCallRuntime4(Runtime::FunctionId function,
355 Node* arg1, Node* arg2, Node* arg3,
356 Node* arg4, Node* context) {
357 const int kArity = 4;
358 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
359 zone(), function, kArity, Operator::kNoProperties,
360 CallDescriptor::kSupportsTailCalls);
361 int return_count = static_cast<int>(desc->ReturnCount());
362
363 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
364 Node* ref = AddNode(
365 common()->ExternalConstant(ExternalReference(function, isolate())));
366 Node* arity = Int32Constant(kArity);
367
368 Node* nodes[] = {centry, arg1, arg2, arg3, arg4, ref, arity, context};
369 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes);
370
371 NodeProperties::MergeControlToEnd(graph(), common(), tail_call);
372 schedule()->AddTailCall(CurrentBlock(), tail_call);
373 current_block_ = nullptr;
374 return tail_call;
375}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000376
377Node* RawMachineAssembler::CallCFunction0(MachineType return_type,
378 Node* function) {
379 MachineSignature::Builder builder(zone(), 1, 0);
380 builder.AddReturn(return_type);
381 const CallDescriptor* descriptor =
382 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build());
383
384 return AddNode(common()->Call(descriptor), function);
385}
386
387
388Node* RawMachineAssembler::CallCFunction1(MachineType return_type,
389 MachineType arg0_type, Node* function,
390 Node* arg0) {
391 MachineSignature::Builder builder(zone(), 1, 1);
392 builder.AddReturn(return_type);
393 builder.AddParam(arg0_type);
394 const CallDescriptor* descriptor =
395 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build());
396
397 return AddNode(common()->Call(descriptor), function, arg0);
398}
399
400
401Node* RawMachineAssembler::CallCFunction2(MachineType return_type,
402 MachineType arg0_type,
403 MachineType arg1_type, Node* function,
404 Node* arg0, Node* arg1) {
405 MachineSignature::Builder builder(zone(), 1, 2);
406 builder.AddReturn(return_type);
407 builder.AddParam(arg0_type);
408 builder.AddParam(arg1_type);
409 const CallDescriptor* descriptor =
410 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build());
411
412 return AddNode(common()->Call(descriptor), function, arg0, arg1);
413}
414
415
416Node* RawMachineAssembler::CallCFunction8(
417 MachineType return_type, MachineType arg0_type, MachineType arg1_type,
418 MachineType arg2_type, MachineType arg3_type, MachineType arg4_type,
419 MachineType arg5_type, MachineType arg6_type, MachineType arg7_type,
420 Node* function, Node* arg0, Node* arg1, Node* arg2, Node* arg3, Node* arg4,
421 Node* arg5, Node* arg6, Node* arg7) {
422 MachineSignature::Builder builder(zone(), 1, 8);
423 builder.AddReturn(return_type);
424 builder.AddParam(arg0_type);
425 builder.AddParam(arg1_type);
426 builder.AddParam(arg2_type);
427 builder.AddParam(arg3_type);
428 builder.AddParam(arg4_type);
429 builder.AddParam(arg5_type);
430 builder.AddParam(arg6_type);
431 builder.AddParam(arg7_type);
432 Node* args[] = {function, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7};
433 const CallDescriptor* descriptor =
434 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build());
435 return AddNode(common()->Call(descriptor), arraysize(args), args);
436}
437
438
439void RawMachineAssembler::Bind(RawMachineLabel* label) {
440 DCHECK(current_block_ == nullptr);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000441 DCHECK(!label->bound_);
442 label->bound_ = true;
443 current_block_ = EnsureBlock(label);
Ben Murdochda12d292016-06-02 14:46:10 +0100444 current_block_->set_deferred(label->deferred_);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000445}
446
447
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000448BasicBlock* RawMachineAssembler::Use(RawMachineLabel* label) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000449 label->used_ = true;
450 return EnsureBlock(label);
451}
452
453
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000454BasicBlock* RawMachineAssembler::EnsureBlock(RawMachineLabel* label) {
455 if (label->block_ == nullptr) label->block_ = schedule()->NewBasicBlock();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000456 return label->block_;
457}
458
459
460BasicBlock* RawMachineAssembler::CurrentBlock() {
461 DCHECK(current_block_);
462 return current_block_;
463}
464
Ben Murdoch097c5b22016-05-18 11:27:45 +0100465Node* RawMachineAssembler::Phi(MachineRepresentation rep, int input_count,
466 Node* const* inputs) {
467 Node** buffer = new (zone()->New(sizeof(Node*) * (input_count + 1)))
468 Node*[input_count + 1];
469 std::copy(inputs, inputs + input_count, buffer);
470 buffer[input_count] = graph()->start();
471 return AddNode(common()->Phi(rep, input_count), input_count + 1, buffer);
472}
473
474void RawMachineAssembler::AppendPhiInput(Node* phi, Node* new_input) {
475 const Operator* op = phi->op();
476 const Operator* new_op = common()->ResizeMergeOrPhi(op, phi->InputCount());
477 phi->InsertInput(zone(), phi->InputCount() - 1, new_input);
478 NodeProperties::ChangeOp(phi, new_op);
479}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000480
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000481Node* RawMachineAssembler::AddNode(const Operator* op, int input_count,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100482 Node* const* inputs) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000483 DCHECK_NOT_NULL(schedule_);
484 DCHECK_NOT_NULL(current_block_);
485 Node* node = MakeNode(op, input_count, inputs);
486 schedule()->AddNode(CurrentBlock(), node);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000487 return node;
488}
489
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000490Node* RawMachineAssembler::MakeNode(const Operator* op, int input_count,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100491 Node* const* inputs) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000492 // The raw machine assembler nodes do not have effect and control inputs,
493 // so we disable checking input counts here.
494 return graph()->NewNodeUnchecked(op, input_count, inputs);
495}
496
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000497RawMachineLabel::~RawMachineLabel() { DCHECK(bound_ || !used_); }
498
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000499} // namespace compiler
500} // namespace internal
501} // namespace v8