blob: 9407da6ae3c4480e18f2e7b7ed588bd8909752d7 [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
Ben Murdochc5610432016-08-08 18:44:38 +010038Node* RawMachineAssembler::RelocatableIntPtrConstant(intptr_t value,
39 RelocInfo::Mode rmode) {
40 return kPointerSize == 8
41 ? RelocatableInt64Constant(value, rmode)
42 : RelocatableInt32Constant(static_cast<int>(value), rmode);
43}
Ben Murdochb8a8cc12014-11-26 15:28:44 +000044
45Schedule* RawMachineAssembler::Export() {
46 // Compute the correct codegen order.
47 DCHECK(schedule_->rpo_order()->empty());
Ben Murdochda12d292016-06-02 14:46:10 +010048 OFStream os(stdout);
49 if (FLAG_trace_turbo_scheduler) {
50 PrintF("--- RAW SCHEDULE -------------------------------------------\n");
51 os << *schedule_;
52 }
Ben Murdochc5610432016-08-08 18:44:38 +010053 schedule_->EnsureCFGWellFormedness();
Ben Murdochda12d292016-06-02 14:46:10 +010054 schedule_->PropagateDeferredMark();
55 if (FLAG_trace_turbo_scheduler) {
56 PrintF("--- EDGE SPLIT AND PROPAGATED DEFERRED SCHEDULE ------------\n");
57 os << *schedule_;
58 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -040059 Scheduler::ComputeSpecialRPO(zone(), schedule_);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000060 // Invalidate RawMachineAssembler.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000061 Schedule* schedule = schedule_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000062 schedule_ = nullptr;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000063 return schedule;
64}
65
66
67Node* RawMachineAssembler::Parameter(size_t index) {
68 DCHECK(index < parameter_count());
69 return parameters_[index];
70}
71
72
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000073void RawMachineAssembler::Goto(RawMachineLabel* label) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000074 DCHECK(current_block_ != schedule()->end());
75 schedule()->AddGoto(CurrentBlock(), Use(label));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000076 current_block_ = nullptr;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000077}
78
79
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000080void RawMachineAssembler::Branch(Node* condition, RawMachineLabel* true_val,
81 RawMachineLabel* false_val) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000082 DCHECK(current_block_ != schedule()->end());
Ben Murdoch097c5b22016-05-18 11:27:45 +010083 Node* branch = MakeNode(common()->Branch(), 1, &condition);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000084 schedule()->AddBranch(CurrentBlock(), branch, Use(true_val), Use(false_val));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000085 current_block_ = nullptr;
86}
87
88
89void RawMachineAssembler::Switch(Node* index, RawMachineLabel* default_label,
90 int32_t* case_values,
91 RawMachineLabel** case_labels,
92 size_t case_count) {
93 DCHECK_NE(schedule()->end(), current_block_);
94 size_t succ_count = case_count + 1;
95 Node* switch_node = AddNode(common()->Switch(succ_count), index);
96 BasicBlock** succ_blocks = zone()->NewArray<BasicBlock*>(succ_count);
97 for (size_t index = 0; index < case_count; ++index) {
98 int32_t case_value = case_values[index];
Ben Murdochda12d292016-06-02 14:46:10 +010099 BasicBlock* case_block = schedule()->NewBasicBlock();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000100 Node* case_node =
101 graph()->NewNode(common()->IfValue(case_value), switch_node);
102 schedule()->AddNode(case_block, case_node);
Ben Murdochda12d292016-06-02 14:46:10 +0100103 schedule()->AddGoto(case_block, Use(case_labels[index]));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000104 succ_blocks[index] = case_block;
105 }
Ben Murdochda12d292016-06-02 14:46:10 +0100106 BasicBlock* default_block = schedule()->NewBasicBlock();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000107 Node* default_node = graph()->NewNode(common()->IfDefault(), switch_node);
108 schedule()->AddNode(default_block, default_node);
Ben Murdochda12d292016-06-02 14:46:10 +0100109 schedule()->AddGoto(default_block, Use(default_label));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000110 succ_blocks[case_count] = default_block;
111 schedule()->AddSwitch(CurrentBlock(), switch_node, succ_blocks, succ_count);
112 current_block_ = nullptr;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000113}
114
115
116void RawMachineAssembler::Return(Node* value) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000117 Node* ret = MakeNode(common()->Return(), 1, &value);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000118 schedule()->AddReturn(CurrentBlock(), ret);
119 current_block_ = nullptr;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000120}
121
122
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000123void RawMachineAssembler::Return(Node* v1, Node* v2) {
124 Node* values[] = {v1, v2};
125 Node* ret = MakeNode(common()->Return(2), 2, values);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000126 schedule()->AddReturn(CurrentBlock(), ret);
127 current_block_ = nullptr;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000128}
129
130
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000131void RawMachineAssembler::Return(Node* v1, Node* v2, Node* v3) {
132 Node* values[] = {v1, v2, v3};
133 Node* ret = MakeNode(common()->Return(3), 3, values);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000134 schedule()->AddReturn(CurrentBlock(), ret);
135 current_block_ = nullptr;
136}
137
138
139Node* RawMachineAssembler::CallN(CallDescriptor* desc, Node* function,
140 Node** args) {
141 int param_count =
142 static_cast<int>(desc->GetMachineSignature()->parameter_count());
143 int input_count = param_count + 1;
144 Node** buffer = zone()->NewArray<Node*>(input_count);
145 int index = 0;
146 buffer[index++] = function;
147 for (int i = 0; i < param_count; i++) {
148 buffer[index++] = args[i];
149 }
150 return AddNode(common()->Call(desc), input_count, buffer);
151}
152
153
154Node* RawMachineAssembler::CallNWithFrameState(CallDescriptor* desc,
155 Node* function, Node** args,
156 Node* frame_state) {
157 DCHECK(desc->NeedsFrameState());
158 int param_count =
159 static_cast<int>(desc->GetMachineSignature()->parameter_count());
160 int input_count = param_count + 2;
161 Node** buffer = zone()->NewArray<Node*>(input_count);
162 int index = 0;
163 buffer[index++] = function;
164 for (int i = 0; i < param_count; i++) {
165 buffer[index++] = args[i];
166 }
167 buffer[index++] = frame_state;
168 return AddNode(common()->Call(desc), input_count, buffer);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000169}
170
Ben Murdoch097c5b22016-05-18 11:27:45 +0100171Node* RawMachineAssembler::CallRuntime0(Runtime::FunctionId function,
172 Node* context) {
173 CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor(
174 zone(), function, 0, Operator::kNoProperties, CallDescriptor::kNoFlags);
175 int return_count = static_cast<int>(descriptor->ReturnCount());
176
177 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
178 Node* ref = AddNode(
179 common()->ExternalConstant(ExternalReference(function, isolate())));
180 Node* arity = Int32Constant(0);
181
182 return AddNode(common()->Call(descriptor), centry, ref, arity, context);
183}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000184
185Node* RawMachineAssembler::CallRuntime1(Runtime::FunctionId function,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000186 Node* arg1, Node* context) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000187 CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000188 zone(), function, 1, Operator::kNoProperties, CallDescriptor::kNoFlags);
189 int return_count = static_cast<int>(descriptor->ReturnCount());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000190
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000191 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
192 Node* ref = AddNode(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000193 common()->ExternalConstant(ExternalReference(function, isolate())));
194 Node* arity = Int32Constant(1);
195
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000196 return AddNode(common()->Call(descriptor), centry, arg1, ref, arity, context);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000197}
198
199
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000200Node* RawMachineAssembler::CallRuntime2(Runtime::FunctionId function,
201 Node* arg1, Node* arg2, Node* context) {
202 CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor(
203 zone(), function, 2, Operator::kNoProperties, CallDescriptor::kNoFlags);
204 int return_count = static_cast<int>(descriptor->ReturnCount());
205
206 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
207 Node* ref = AddNode(
208 common()->ExternalConstant(ExternalReference(function, isolate())));
209 Node* arity = Int32Constant(2);
210
211 return AddNode(common()->Call(descriptor), centry, arg1, arg2, ref, arity,
212 context);
213}
214
Ben Murdoch097c5b22016-05-18 11:27:45 +0100215Node* RawMachineAssembler::CallRuntime3(Runtime::FunctionId function,
216 Node* arg1, Node* arg2, Node* arg3,
217 Node* context) {
218 CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor(
219 zone(), function, 3, Operator::kNoProperties, CallDescriptor::kNoFlags);
220 int return_count = static_cast<int>(descriptor->ReturnCount());
221
222 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
223 Node* ref = AddNode(
224 common()->ExternalConstant(ExternalReference(function, isolate())));
225 Node* arity = Int32Constant(3);
226
227 return AddNode(common()->Call(descriptor), centry, arg1, arg2, arg3, ref,
228 arity, context);
229}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000230
231Node* RawMachineAssembler::CallRuntime4(Runtime::FunctionId function,
232 Node* arg1, Node* arg2, Node* arg3,
233 Node* arg4, Node* context) {
234 CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor(
235 zone(), function, 4, Operator::kNoProperties, CallDescriptor::kNoFlags);
236 int return_count = static_cast<int>(descriptor->ReturnCount());
237
238 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
239 Node* ref = AddNode(
240 common()->ExternalConstant(ExternalReference(function, isolate())));
241 Node* arity = Int32Constant(4);
242
243 return AddNode(common()->Call(descriptor), centry, arg1, arg2, arg3, arg4,
244 ref, arity, context);
245}
246
247
248Node* RawMachineAssembler::TailCallN(CallDescriptor* desc, Node* function,
249 Node** args) {
250 int param_count =
251 static_cast<int>(desc->GetMachineSignature()->parameter_count());
252 int input_count = param_count + 1;
253 Node** buffer = zone()->NewArray<Node*>(input_count);
254 int index = 0;
255 buffer[index++] = function;
256 for (int i = 0; i < param_count; i++) {
257 buffer[index++] = args[i];
258 }
259 Node* tail_call = MakeNode(common()->TailCall(desc), input_count, buffer);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000260 schedule()->AddTailCall(CurrentBlock(), tail_call);
261 current_block_ = nullptr;
262 return tail_call;
263}
264
Ben Murdochda12d292016-06-02 14:46:10 +0100265Node* RawMachineAssembler::TailCallRuntime0(Runtime::FunctionId function,
266 Node* context) {
267 const int kArity = 0;
268 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
269 zone(), function, kArity, Operator::kNoProperties,
270 CallDescriptor::kSupportsTailCalls);
271 int return_count = static_cast<int>(desc->ReturnCount());
272
273 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
274 Node* ref = AddNode(
275 common()->ExternalConstant(ExternalReference(function, isolate())));
276 Node* arity = Int32Constant(kArity);
277
278 Node* nodes[] = {centry, ref, arity, context};
279 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes);
280
Ben Murdochda12d292016-06-02 14:46:10 +0100281 schedule()->AddTailCall(CurrentBlock(), tail_call);
282 current_block_ = nullptr;
283 return tail_call;
284}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000285
286Node* RawMachineAssembler::TailCallRuntime1(Runtime::FunctionId function,
287 Node* arg1, Node* context) {
288 const int kArity = 1;
289 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
290 zone(), function, kArity, Operator::kNoProperties,
291 CallDescriptor::kSupportsTailCalls);
292 int return_count = static_cast<int>(desc->ReturnCount());
293
294 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
295 Node* ref = AddNode(
296 common()->ExternalConstant(ExternalReference(function, isolate())));
297 Node* arity = Int32Constant(kArity);
298
299 Node* nodes[] = {centry, arg1, ref, arity, context};
300 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes);
301
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000302 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
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000325 schedule()->AddTailCall(CurrentBlock(), tail_call);
326 current_block_ = nullptr;
327 return tail_call;
328}
329
Ben Murdoch097c5b22016-05-18 11:27:45 +0100330Node* RawMachineAssembler::TailCallRuntime3(Runtime::FunctionId function,
331 Node* arg1, Node* arg2, Node* arg3,
332 Node* context) {
333 const int kArity = 3;
334 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
335 zone(), function, kArity, Operator::kNoProperties,
336 CallDescriptor::kSupportsTailCalls);
337 int return_count = static_cast<int>(desc->ReturnCount());
338
339 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
340 Node* ref = AddNode(
341 common()->ExternalConstant(ExternalReference(function, isolate())));
342 Node* arity = Int32Constant(kArity);
343
344 Node* nodes[] = {centry, arg1, arg2, arg3, ref, arity, context};
345 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes);
346
Ben Murdoch097c5b22016-05-18 11:27:45 +0100347 schedule()->AddTailCall(CurrentBlock(), tail_call);
348 current_block_ = nullptr;
349 return tail_call;
350}
351
352Node* RawMachineAssembler::TailCallRuntime4(Runtime::FunctionId function,
353 Node* arg1, Node* arg2, Node* arg3,
354 Node* arg4, Node* context) {
355 const int kArity = 4;
356 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
357 zone(), function, kArity, Operator::kNoProperties,
358 CallDescriptor::kSupportsTailCalls);
359 int return_count = static_cast<int>(desc->ReturnCount());
360
361 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
362 Node* ref = AddNode(
363 common()->ExternalConstant(ExternalReference(function, isolate())));
364 Node* arity = Int32Constant(kArity);
365
366 Node* nodes[] = {centry, arg1, arg2, arg3, arg4, ref, arity, context};
367 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes);
368
Ben Murdoch097c5b22016-05-18 11:27:45 +0100369 schedule()->AddTailCall(CurrentBlock(), tail_call);
370 current_block_ = nullptr;
371 return tail_call;
372}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000373
374Node* RawMachineAssembler::CallCFunction0(MachineType return_type,
375 Node* function) {
376 MachineSignature::Builder builder(zone(), 1, 0);
377 builder.AddReturn(return_type);
378 const CallDescriptor* descriptor =
379 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build());
380
381 return AddNode(common()->Call(descriptor), function);
382}
383
384
385Node* RawMachineAssembler::CallCFunction1(MachineType return_type,
386 MachineType arg0_type, Node* function,
387 Node* arg0) {
388 MachineSignature::Builder builder(zone(), 1, 1);
389 builder.AddReturn(return_type);
390 builder.AddParam(arg0_type);
391 const CallDescriptor* descriptor =
392 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build());
393
394 return AddNode(common()->Call(descriptor), function, arg0);
395}
396
397
398Node* RawMachineAssembler::CallCFunction2(MachineType return_type,
399 MachineType arg0_type,
400 MachineType arg1_type, Node* function,
401 Node* arg0, Node* arg1) {
402 MachineSignature::Builder builder(zone(), 1, 2);
403 builder.AddReturn(return_type);
404 builder.AddParam(arg0_type);
405 builder.AddParam(arg1_type);
406 const CallDescriptor* descriptor =
407 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build());
408
409 return AddNode(common()->Call(descriptor), function, arg0, arg1);
410}
411
412
413Node* RawMachineAssembler::CallCFunction8(
414 MachineType return_type, MachineType arg0_type, MachineType arg1_type,
415 MachineType arg2_type, MachineType arg3_type, MachineType arg4_type,
416 MachineType arg5_type, MachineType arg6_type, MachineType arg7_type,
417 Node* function, Node* arg0, Node* arg1, Node* arg2, Node* arg3, Node* arg4,
418 Node* arg5, Node* arg6, Node* arg7) {
419 MachineSignature::Builder builder(zone(), 1, 8);
420 builder.AddReturn(return_type);
421 builder.AddParam(arg0_type);
422 builder.AddParam(arg1_type);
423 builder.AddParam(arg2_type);
424 builder.AddParam(arg3_type);
425 builder.AddParam(arg4_type);
426 builder.AddParam(arg5_type);
427 builder.AddParam(arg6_type);
428 builder.AddParam(arg7_type);
429 Node* args[] = {function, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7};
430 const CallDescriptor* descriptor =
431 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build());
432 return AddNode(common()->Call(descriptor), arraysize(args), args);
433}
434
435
436void RawMachineAssembler::Bind(RawMachineLabel* label) {
437 DCHECK(current_block_ == nullptr);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000438 DCHECK(!label->bound_);
439 label->bound_ = true;
440 current_block_ = EnsureBlock(label);
Ben Murdochda12d292016-06-02 14:46:10 +0100441 current_block_->set_deferred(label->deferred_);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000442}
443
444
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000445BasicBlock* RawMachineAssembler::Use(RawMachineLabel* label) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000446 label->used_ = true;
447 return EnsureBlock(label);
448}
449
450
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000451BasicBlock* RawMachineAssembler::EnsureBlock(RawMachineLabel* label) {
452 if (label->block_ == nullptr) label->block_ = schedule()->NewBasicBlock();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000453 return label->block_;
454}
455
456
457BasicBlock* RawMachineAssembler::CurrentBlock() {
458 DCHECK(current_block_);
459 return current_block_;
460}
461
Ben Murdoch097c5b22016-05-18 11:27:45 +0100462Node* RawMachineAssembler::Phi(MachineRepresentation rep, int input_count,
463 Node* const* inputs) {
464 Node** buffer = new (zone()->New(sizeof(Node*) * (input_count + 1)))
465 Node*[input_count + 1];
466 std::copy(inputs, inputs + input_count, buffer);
467 buffer[input_count] = graph()->start();
468 return AddNode(common()->Phi(rep, input_count), input_count + 1, buffer);
469}
470
471void RawMachineAssembler::AppendPhiInput(Node* phi, Node* new_input) {
472 const Operator* op = phi->op();
473 const Operator* new_op = common()->ResizeMergeOrPhi(op, phi->InputCount());
474 phi->InsertInput(zone(), phi->InputCount() - 1, new_input);
475 NodeProperties::ChangeOp(phi, new_op);
476}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000477
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000478Node* RawMachineAssembler::AddNode(const Operator* op, int input_count,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100479 Node* const* inputs) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000480 DCHECK_NOT_NULL(schedule_);
481 DCHECK_NOT_NULL(current_block_);
482 Node* node = MakeNode(op, input_count, inputs);
483 schedule()->AddNode(CurrentBlock(), node);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000484 return node;
485}
486
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000487Node* RawMachineAssembler::MakeNode(const Operator* op, int input_count,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100488 Node* const* inputs) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000489 // The raw machine assembler nodes do not have effect and control inputs,
490 // so we disable checking input counts here.
491 return graph()->NewNodeUnchecked(op, input_count, inputs);
492}
493
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000494RawMachineLabel::~RawMachineLabel() { DCHECK(bound_ || !used_); }
495
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000496} // namespace compiler
497} // namespace internal
498} // namespace v8