Line data Source code
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 : #include "src/compiler/backend/instruction-selector.h"
6 :
7 : #include <limits>
8 :
9 : #include "src/assembler-inl.h"
10 : #include "src/base/adapters.h"
11 : #include "src/compiler/backend/instruction-selector-impl.h"
12 : #include "src/compiler/compiler-source-position-table.h"
13 : #include "src/compiler/node-matchers.h"
14 : #include "src/compiler/pipeline.h"
15 : #include "src/compiler/schedule.h"
16 : #include "src/compiler/state-values-utils.h"
17 : #include "src/deoptimizer.h"
18 :
19 : namespace v8 {
20 : namespace internal {
21 : namespace compiler {
22 :
23 2515355 : InstructionSelector::InstructionSelector(
24 : Zone* zone, size_t node_count, Linkage* linkage,
25 : InstructionSequence* sequence, Schedule* schedule,
26 : SourcePositionTable* source_positions, Frame* frame,
27 : EnableSwitchJumpTable enable_switch_jump_table,
28 : SourcePositionMode source_position_mode, Features features,
29 : EnableScheduling enable_scheduling,
30 : EnableRootsRelativeAddressing enable_roots_relative_addressing,
31 : PoisoningMitigationLevel poisoning_level, EnableTraceTurboJson trace_turbo)
32 : : zone_(zone),
33 : linkage_(linkage),
34 : sequence_(sequence),
35 : source_positions_(source_positions),
36 : source_position_mode_(source_position_mode),
37 : features_(features),
38 : schedule_(schedule),
39 : current_block_(nullptr),
40 : instructions_(zone),
41 : continuation_inputs_(sequence->zone()),
42 : continuation_outputs_(sequence->zone()),
43 : defined_(node_count, false, zone),
44 : used_(node_count, false, zone),
45 : effect_level_(node_count, 0, zone),
46 : virtual_registers_(node_count,
47 : InstructionOperand::kInvalidVirtualRegister, zone),
48 : virtual_register_rename_(zone),
49 : scheduler_(nullptr),
50 : enable_scheduling_(enable_scheduling),
51 : enable_roots_relative_addressing_(enable_roots_relative_addressing),
52 : enable_switch_jump_table_(enable_switch_jump_table),
53 : poisoning_level_(poisoning_level),
54 : frame_(frame),
55 : instruction_selection_failed_(false),
56 : instr_origins_(sequence->zone()),
57 7547779 : trace_turbo_(trace_turbo) {
58 2516212 : instructions_.reserve(node_count);
59 2515980 : continuation_inputs_.reserve(5);
60 2516859 : continuation_outputs_.reserve(2);
61 :
62 2517531 : if (trace_turbo_ == kEnableTraceTurboJson) {
63 2 : instr_origins_.assign(node_count, {-1, 0});
64 : }
65 2517531 : }
66 :
67 2516977 : bool InstructionSelector::SelectInstructions() {
68 : // Mark the inputs of all phis in loop headers as used.
69 : BasicBlockVector* blocks = schedule()->rpo_order();
70 22824041 : for (auto const block : *blocks) {
71 20307064 : if (!block->IsLoopHeader()) continue;
72 : DCHECK_LE(2u, block->PredecessorCount());
73 2168178 : for (Node* const phi : *block) {
74 1938669 : if (phi->opcode() != IrOpcode::kPhi) continue;
75 :
76 : // Mark all inputs as used.
77 1426796 : for (Node* const input : phi->inputs()) {
78 : MarkAsUsed(input);
79 : }
80 : }
81 : }
82 :
83 : // Visit each basic block in post order.
84 22826263 : for (auto i = blocks->rbegin(); i != blocks->rend(); ++i) {
85 20308554 : VisitBlock(*i);
86 20309291 : if (instruction_selection_failed()) return false;
87 : }
88 :
89 : // Schedule the selected instructions.
90 2517709 : if (UseInstructionScheduling()) {
91 2187 : scheduler_ = new (zone()) InstructionScheduler(zone(), sequence());
92 : }
93 :
94 22828538 : for (auto const block : *blocks) {
95 : InstructionBlock* instruction_block =
96 20308771 : sequence()->InstructionBlockAt(RpoNumber::FromInt(block->rpo_number()));
97 24632888 : for (size_t i = 0; i < instruction_block->phis().size(); i++) {
98 2161826 : UpdateRenamesInPhi(instruction_block->PhiAt(i));
99 : }
100 20309239 : size_t end = instruction_block->code_end();
101 20309239 : size_t start = instruction_block->code_start();
102 : DCHECK_LE(end, start);
103 20309239 : StartBlock(RpoNumber::FromInt(block->rpo_number()));
104 20309559 : if (end != start) {
105 118972268 : while (start-- > end + 1) {
106 49330840 : UpdateRenames(instructions_[start]);
107 49331348 : AddInstruction(instructions_[start]);
108 : }
109 20310146 : UpdateRenames(instructions_[end]);
110 20310591 : AddTerminator(instructions_[end]);
111 : }
112 20310307 : EndBlock(RpoNumber::FromInt(block->rpo_number()));
113 : }
114 : #if DEBUG
115 : sequence()->ValidateSSA();
116 : #endif
117 : return true;
118 : }
119 :
120 20309117 : void InstructionSelector::StartBlock(RpoNumber rpo) {
121 20309117 : if (UseInstructionScheduling()) {
122 : DCHECK_NOT_NULL(scheduler_);
123 134748 : scheduler_->StartBlock(rpo);
124 : } else {
125 20174369 : sequence()->StartBlock(rpo);
126 : }
127 20309503 : }
128 :
129 20310521 : void InstructionSelector::EndBlock(RpoNumber rpo) {
130 20310521 : if (UseInstructionScheduling()) {
131 : DCHECK_NOT_NULL(scheduler_);
132 134748 : scheduler_->EndBlock(rpo);
133 : } else {
134 20175773 : sequence()->EndBlock(rpo);
135 : }
136 20310848 : }
137 :
138 20310378 : void InstructionSelector::AddTerminator(Instruction* instr) {
139 20310378 : if (UseInstructionScheduling()) {
140 : DCHECK_NOT_NULL(scheduler_);
141 134748 : scheduler_->AddTerminator(instr);
142 : } else {
143 20175630 : sequence()->AddInstruction(instr);
144 : }
145 20310642 : }
146 :
147 49331414 : void InstructionSelector::AddInstruction(Instruction* instr) {
148 49331414 : if (UseInstructionScheduling()) {
149 : DCHECK_NOT_NULL(scheduler_);
150 208167 : scheduler_->AddInstruction(instr);
151 : } else {
152 49123247 : sequence()->AddInstruction(instr);
153 : }
154 49331214 : }
155 :
156 16 : Instruction* InstructionSelector::Emit(InstructionCode opcode,
157 : InstructionOperand output,
158 : size_t temp_count,
159 : InstructionOperand* temps) {
160 17969994 : size_t output_count = output.IsInvalid() ? 0 : 1;
161 18590332 : return Emit(opcode, output_count, &output, 0, nullptr, temp_count, temps);
162 : }
163 :
164 5938326 : Instruction* InstructionSelector::Emit(InstructionCode opcode,
165 : InstructionOperand output,
166 : InstructionOperand a, size_t temp_count,
167 : InstructionOperand* temps) {
168 6846733 : size_t output_count = output.IsInvalid() ? 0 : 1;
169 16020402 : return Emit(opcode, output_count, &output, 1, &a, temp_count, temps);
170 : }
171 :
172 1320017 : Instruction* InstructionSelector::Emit(InstructionCode opcode,
173 : InstructionOperand output,
174 : InstructionOperand a,
175 : InstructionOperand b, size_t temp_count,
176 : InstructionOperand* temps) {
177 1320017 : size_t output_count = output.IsInvalid() ? 0 : 1;
178 1320017 : InstructionOperand inputs[] = {a, b};
179 : size_t input_count = arraysize(inputs);
180 : return Emit(opcode, output_count, &output, input_count, inputs, temp_count,
181 1320017 : temps);
182 : }
183 :
184 1980 : Instruction* InstructionSelector::Emit(InstructionCode opcode,
185 : InstructionOperand output,
186 : InstructionOperand a,
187 : InstructionOperand b,
188 : InstructionOperand c, size_t temp_count,
189 : InstructionOperand* temps) {
190 1980 : size_t output_count = output.IsInvalid() ? 0 : 1;
191 1980 : InstructionOperand inputs[] = {a, b, c};
192 : size_t input_count = arraysize(inputs);
193 : return Emit(opcode, output_count, &output, input_count, inputs, temp_count,
194 1980 : temps);
195 : }
196 :
197 0 : Instruction* InstructionSelector::Emit(
198 : InstructionCode opcode, InstructionOperand output, InstructionOperand a,
199 : InstructionOperand b, InstructionOperand c, InstructionOperand d,
200 : size_t temp_count, InstructionOperand* temps) {
201 0 : size_t output_count = output.IsInvalid() ? 0 : 1;
202 0 : InstructionOperand inputs[] = {a, b, c, d};
203 : size_t input_count = arraysize(inputs);
204 : return Emit(opcode, output_count, &output, input_count, inputs, temp_count,
205 0 : temps);
206 : }
207 :
208 0 : Instruction* InstructionSelector::Emit(
209 : InstructionCode opcode, InstructionOperand output, InstructionOperand a,
210 : InstructionOperand b, InstructionOperand c, InstructionOperand d,
211 : InstructionOperand e, size_t temp_count, InstructionOperand* temps) {
212 0 : size_t output_count = output.IsInvalid() ? 0 : 1;
213 0 : InstructionOperand inputs[] = {a, b, c, d, e};
214 : size_t input_count = arraysize(inputs);
215 : return Emit(opcode, output_count, &output, input_count, inputs, temp_count,
216 0 : temps);
217 : }
218 :
219 0 : Instruction* InstructionSelector::Emit(
220 : InstructionCode opcode, InstructionOperand output, InstructionOperand a,
221 : InstructionOperand b, InstructionOperand c, InstructionOperand d,
222 : InstructionOperand e, InstructionOperand f, size_t temp_count,
223 : InstructionOperand* temps) {
224 0 : size_t output_count = output.IsInvalid() ? 0 : 1;
225 0 : InstructionOperand inputs[] = {a, b, c, d, e, f};
226 : size_t input_count = arraysize(inputs);
227 : return Emit(opcode, output_count, &output, input_count, inputs, temp_count,
228 0 : temps);
229 : }
230 :
231 67123997 : Instruction* InstructionSelector::Emit(
232 : InstructionCode opcode, size_t output_count, InstructionOperand* outputs,
233 : size_t input_count, InstructionOperand* inputs, size_t temp_count,
234 : InstructionOperand* temps) {
235 134247994 : if (output_count >= Instruction::kMaxOutputCount ||
236 134247510 : input_count >= Instruction::kMaxInputCount ||
237 : temp_count >= Instruction::kMaxTempCount) {
238 : set_instruction_selection_failed();
239 9 : return nullptr;
240 : }
241 :
242 : Instruction* instr =
243 : Instruction::New(instruction_zone(), opcode, output_count, outputs,
244 67123988 : input_count, inputs, temp_count, temps);
245 67125135 : return Emit(instr);
246 : }
247 :
248 0 : Instruction* InstructionSelector::Emit(Instruction* instr) {
249 69639703 : instructions_.push_back(instr);
250 67125135 : return instr;
251 : }
252 :
253 11847961 : bool InstructionSelector::CanCover(Node* user, Node* node) const {
254 : // 1. Both {user} and {node} must be in the same basic block.
255 11847961 : if (schedule()->block(node) != schedule()->block(user)) {
256 : return false;
257 : }
258 : // 2. Pure {node}s must be owned by the {user}.
259 11016033 : if (node->op()->HasProperty(Operator::kPure)) {
260 8663977 : return node->OwnedBy(user);
261 : }
262 : // 3. Impure {node}s must match the effect level of {user}.
263 2352056 : if (GetEffectLevel(node) != GetEffectLevel(user)) {
264 : return false;
265 : }
266 : // 4. Only {node} must have value edges pointing to {user}.
267 14868275 : for (Edge const edge : node->use_edges()) {
268 6351496 : if (edge.from() != user && NodeProperties::IsValueEdge(edge)) {
269 156146 : return false;
270 : }
271 : }
272 2165283 : return true;
273 : }
274 :
275 650 : bool InstructionSelector::CanCoverTransitively(Node* user, Node* node,
276 : Node* node_input) const {
277 650 : if (CanCover(user, node) && CanCover(node, node_input)) {
278 : // If {node} is pure, transitivity might not hold.
279 19 : if (node->op()->HasProperty(Operator::kPure)) {
280 : // If {node_input} is pure, the effect levels do not matter.
281 19 : if (node_input->op()->HasProperty(Operator::kPure)) return true;
282 : // Otherwise, {user} and {node_input} must have the same effect level.
283 17 : return GetEffectLevel(user) == GetEffectLevel(node_input);
284 : }
285 : return true;
286 : }
287 : return false;
288 : }
289 :
290 134309 : bool InstructionSelector::IsOnlyUserOfNodeInSameBlock(Node* user,
291 : Node* node) const {
292 134309 : BasicBlock* bb_user = schedule()->block(user);
293 134310 : BasicBlock* bb_node = schedule()->block(node);
294 134311 : if (bb_user != bb_node) return false;
295 277198 : for (Edge const edge : node->use_edges()) {
296 : Node* from = edge.from();
297 155225 : if ((from != user) && (schedule()->block(from) == bb_user)) {
298 : return false;
299 : }
300 : }
301 121973 : return true;
302 : }
303 :
304 69641996 : void InstructionSelector::UpdateRenames(Instruction* instruction) {
305 349802068 : for (size_t i = 0; i < instruction->InputCount(); i++) {
306 140080878 : TryRename(instruction->InputAt(i));
307 : }
308 69641154 : }
309 :
310 2161825 : void InstructionSelector::UpdateRenamesInPhi(PhiInstruction* phi) {
311 12594673 : for (size_t i = 0; i < phi->operands().size(); i++) {
312 5216426 : int vreg = phi->operands()[i];
313 : int renamed = GetRename(vreg);
314 5216426 : if (vreg != renamed) {
315 296376 : phi->RenameInput(i, renamed);
316 : }
317 : }
318 2161823 : }
319 :
320 0 : int InstructionSelector::GetRename(int virtual_register) {
321 : int rename = virtual_register;
322 : while (true) {
323 165834892 : if (static_cast<size_t>(rename) >= virtual_register_rename_.size()) break;
324 45707435 : int next = virtual_register_rename_[rename];
325 45707435 : if (next == InstructionOperand::kInvalidVirtualRegister) {
326 : break;
327 : }
328 : rename = next;
329 : }
330 0 : return rename;
331 : }
332 :
333 140081016 : void InstructionSelector::TryRename(InstructionOperand* op) {
334 140081016 : if (!op->IsUnallocated()) return;
335 : UnallocatedOperand* unalloc = UnallocatedOperand::cast(op);
336 : int vreg = unalloc->virtual_register();
337 : int rename = GetRename(vreg);
338 74827666 : if (rename != vreg) {
339 2576978 : *unalloc = UnallocatedOperand(*unalloc, rename);
340 : }
341 : }
342 :
343 2578948 : void InstructionSelector::SetRename(const Node* node, const Node* rename) {
344 2578948 : int vreg = GetVirtualRegister(node);
345 5157898 : if (static_cast<size_t>(vreg) >= virtual_register_rename_.size()) {
346 2284935 : int invalid = InstructionOperand::kInvalidVirtualRegister;
347 2284935 : virtual_register_rename_.resize(vreg + 1, invalid);
348 : }
349 2578946 : virtual_register_rename_[vreg] = GetVirtualRegister(rename);
350 2578948 : }
351 :
352 162867389 : int InstructionSelector::GetVirtualRegister(const Node* node) {
353 : DCHECK_NOT_NULL(node);
354 162867389 : size_t const id = node->id();
355 : DCHECK_LT(id, virtual_registers_.size());
356 162867389 : int virtual_register = virtual_registers_[id];
357 162867389 : if (virtual_register == InstructionOperand::kInvalidVirtualRegister) {
358 45615961 : virtual_register = sequence()->NextVirtualRegister();
359 45616004 : virtual_registers_[id] = virtual_register;
360 : }
361 162867432 : return virtual_register;
362 : }
363 :
364 249 : const std::map<NodeId, int> InstructionSelector::GetVirtualRegistersForTesting()
365 : const {
366 : std::map<NodeId, int> virtual_registers;
367 4509 : for (size_t n = 0; n < virtual_registers_.size(); ++n) {
368 2130 : if (virtual_registers_[n] != InstructionOperand::kInvalidVirtualRegister) {
369 727 : NodeId const id = static_cast<NodeId>(n);
370 1454 : virtual_registers.insert(std::make_pair(id, virtual_registers_[n]));
371 : }
372 : }
373 249 : return virtual_registers;
374 : }
375 :
376 1116502 : bool InstructionSelector::IsDefined(Node* node) const {
377 : DCHECK_NOT_NULL(node);
378 54035623 : size_t const id = node->id();
379 : DCHECK_LT(id, defined_.size());
380 1116502 : return defined_[id];
381 : }
382 :
383 14897986 : void InstructionSelector::MarkAsDefined(Node* node) {
384 : DCHECK_NOT_NULL(node);
385 40289133 : size_t const id = node->id();
386 : DCHECK_LT(id, defined_.size());
387 : defined_[id] = true;
388 14897986 : }
389 :
390 872628 : bool InstructionSelector::IsUsed(Node* node) const {
391 : DCHECK_NOT_NULL(node);
392 : // TODO(bmeurer): This is a terrible monster hack, but we have to make sure
393 : // that the Retain is actually emitted, otherwise the GC will mess up.
394 114490272 : if (node->opcode() == IrOpcode::kRetain) return true;
395 114482271 : if (!node->op()->HasProperty(Operator::kEliminatable)) return true;
396 100641358 : size_t const id = node->id();
397 : DCHECK_LT(id, used_.size());
398 865663 : return used_[id];
399 : }
400 :
401 10373082 : void InstructionSelector::MarkAsUsed(Node* node) {
402 : DCHECK_NOT_NULL(node);
403 87874377 : size_t const id = node->id();
404 : DCHECK_LT(id, used_.size());
405 : used_[id] = true;
406 10373082 : }
407 :
408 14980284 : int InstructionSelector::GetEffectLevel(Node* node) const {
409 : DCHECK_NOT_NULL(node);
410 19684430 : size_t const id = node->id();
411 : DCHECK_LT(id, effect_level_.size());
412 19684430 : return effect_level_[id];
413 : }
414 :
415 0 : void InstructionSelector::SetEffectLevel(Node* node, int effect_level) {
416 : DCHECK_NOT_NULL(node);
417 122444412 : size_t const id = node->id();
418 : DCHECK_LT(id, effect_level_.size());
419 122444412 : effect_level_[id] = effect_level;
420 0 : }
421 :
422 12899594 : bool InstructionSelector::CanAddressRelativeToRootsRegister() const {
423 20200642 : return enable_roots_relative_addressing_ == kEnableRootsRelativeAddressing &&
424 12899594 : CanUseRootsRegister();
425 : }
426 :
427 2883303 : bool InstructionSelector::CanUseRootsRegister() const {
428 : return linkage()->GetIncomingDescriptor()->flags() &
429 2883303 : CallDescriptor::kCanUseRoots;
430 : }
431 :
432 0 : void InstructionSelector::MarkAsRepresentation(MachineRepresentation rep,
433 : const InstructionOperand& op) {
434 : UnallocatedOperand unalloc = UnallocatedOperand::cast(op);
435 6156678 : sequence()->MarkAsRepresentation(rep, unalloc.virtual_register());
436 0 : }
437 :
438 28391808 : void InstructionSelector::MarkAsRepresentation(MachineRepresentation rep,
439 : Node* node) {
440 28391808 : sequence()->MarkAsRepresentation(rep, GetVirtualRegister(node));
441 28392615 : }
442 :
443 : namespace {
444 :
445 23888609 : InstructionOperand OperandForDeopt(Isolate* isolate, OperandGenerator* g,
446 : Node* input, FrameStateInputKind kind,
447 : MachineRepresentation rep) {
448 23888609 : if (rep == MachineRepresentation::kNone) {
449 0 : return g->TempImmediate(FrameStateDescriptor::kImpossibleValue);
450 : }
451 :
452 23888609 : switch (input->opcode()) {
453 : case IrOpcode::kInt32Constant:
454 : case IrOpcode::kInt64Constant:
455 : case IrOpcode::kNumberConstant:
456 : case IrOpcode::kFloat32Constant:
457 : case IrOpcode::kFloat64Constant:
458 : case IrOpcode::kDelayedStringConstant:
459 674166 : return g->UseImmediate(input);
460 : case IrOpcode::kHeapConstant: {
461 5958160 : if (!CanBeTaggedPointer(rep)) {
462 : // If we have inconsistent static and dynamic types, e.g. if we
463 : // smi-check a string, we can get here with a heap object that
464 : // says it is a smi. In that case, we return an invalid instruction
465 : // operand, which will be interpreted as an optimized-out value.
466 :
467 : // TODO(jarin) Ideally, we should turn the current instruction
468 : // into an abort (we should never execute it).
469 0 : return InstructionOperand();
470 : }
471 :
472 5958160 : Handle<HeapObject> constant = HeapConstantOf(input->op());
473 : RootIndex root_index;
474 5958156 : if (isolate->roots_table().IsRootHandle(constant, &root_index) &&
475 : root_index == RootIndex::kOptimizedOut) {
476 : // For an optimized-out object we return an invalid instruction
477 : // operand, so that we take the fast path for optimized-out values.
478 343 : return InstructionOperand();
479 : }
480 :
481 5957813 : return g->UseImmediate(input);
482 : }
483 : case IrOpcode::kArgumentsElementsState:
484 : case IrOpcode::kArgumentsLengthState:
485 : case IrOpcode::kObjectState:
486 : case IrOpcode::kTypedObjectState:
487 0 : UNREACHABLE();
488 : break;
489 : default:
490 17256283 : switch (kind) {
491 : case FrameStateInputKind::kStackSlot:
492 14922494 : return g->UseUniqueSlot(input);
493 : case FrameStateInputKind::kAny:
494 : // Currently deopts "wrap" other operations, so the deopt's inputs
495 : // are potentially needed until the end of the deoptimising code.
496 2333789 : return g->UseAnyAtEnd(input);
497 : }
498 : }
499 0 : UNREACHABLE();
500 : }
501 :
502 : } // namespace
503 :
504 3600497 : class StateObjectDeduplicator {
505 : public:
506 : explicit StateObjectDeduplicator(Zone* zone) : objects_(zone) {}
507 : static const size_t kNotDuplicated = SIZE_MAX;
508 :
509 109883 : size_t GetObjectId(Node* node) {
510 : DCHECK(node->opcode() == IrOpcode::kTypedObjectState ||
511 : node->opcode() == IrOpcode::kObjectId ||
512 : node->opcode() == IrOpcode::kArgumentsElementsState);
513 282277 : for (size_t i = 0; i < objects_.size(); ++i) {
514 105994 : if (objects_[i] == node) return i;
515 : // ObjectId nodes are the Turbofan way to express objects with the same
516 : // identity in the deopt info. So they should always be mapped to
517 : // previously appearing TypedObjectState nodes.
518 316356 : if (HasObjectId(objects_[i]) && HasObjectId(node) &&
519 105181 : ObjectIdOf(objects_[i]->op()) == ObjectIdOf(node->op())) {
520 : return i;
521 : }
522 : }
523 : DCHECK(node->opcode() == IrOpcode::kTypedObjectState ||
524 : node->opcode() == IrOpcode::kArgumentsElementsState);
525 : return kNotDuplicated;
526 : }
527 :
528 : size_t InsertObject(Node* node) {
529 : DCHECK(node->opcode() == IrOpcode::kTypedObjectState ||
530 : node->opcode() == IrOpcode::kObjectId ||
531 : node->opcode() == IrOpcode::kArgumentsElementsState);
532 : size_t id = objects_.size();
533 115837 : objects_.push_back(node);
534 : return id;
535 : }
536 :
537 : private:
538 : static bool HasObjectId(Node* node) {
539 211175 : return node->opcode() == IrOpcode::kTypedObjectState ||
540 : node->opcode() == IrOpcode::kObjectId;
541 : }
542 :
543 : ZoneVector<Node*> objects_;
544 : };
545 :
546 : // Returns the number of instruction operands added to inputs.
547 52575109 : size_t InstructionSelector::AddOperandToStateValueDescriptor(
548 : StateValueList* values, InstructionOperandVector* inputs,
549 : OperandGenerator* g, StateObjectDeduplicator* deduplicator, Node* input,
550 : MachineType type, FrameStateInputKind kind, Zone* zone) {
551 52575109 : if (input == nullptr) {
552 28565414 : values->PushOptimizedOut();
553 28565762 : return 0;
554 : }
555 :
556 24009695 : switch (input->opcode()) {
557 : case IrOpcode::kArgumentsElementsState: {
558 5954 : values->PushArgumentsElements(ArgumentsStateTypeOf(input->op()));
559 : // The elements backing store of an arguments object participates in the
560 : // duplicate object counting, but can itself never appear duplicated.
561 : DCHECK_EQ(StateObjectDeduplicator::kNotDuplicated,
562 : deduplicator->GetObjectId(input));
563 : deduplicator->InsertObject(input);
564 5954 : return 0;
565 : }
566 : case IrOpcode::kArgumentsLengthState: {
567 6262 : values->PushArgumentsLength(ArgumentsStateTypeOf(input->op()));
568 6262 : return 0;
569 : }
570 : case IrOpcode::kObjectState: {
571 0 : UNREACHABLE();
572 : }
573 : case IrOpcode::kTypedObjectState:
574 : case IrOpcode::kObjectId: {
575 109883 : size_t id = deduplicator->GetObjectId(input);
576 109883 : if (id == StateObjectDeduplicator::kNotDuplicated) {
577 : DCHECK_EQ(IrOpcode::kTypedObjectState, input->opcode());
578 : size_t entries = 0;
579 : id = deduplicator->InsertObject(input);
580 90086 : StateValueList* nested = values->PushRecursiveField(zone, id);
581 : int const input_count = input->op()->ValueInputCount();
582 90086 : ZoneVector<MachineType> const* types = MachineTypesOf(input->op());
583 1158776 : for (int i = 0; i < input_count; ++i) {
584 : entries += AddOperandToStateValueDescriptor(
585 534345 : nested, inputs, g, deduplicator, input->InputAt(i), types->at(i),
586 534345 : kind, zone);
587 : }
588 : return entries;
589 : } else {
590 : // Deoptimizer counts duplicate objects for the running id, so we have
591 : // to push the input again.
592 : deduplicator->InsertObject(input);
593 19797 : values->PushDuplicate(id);
594 19797 : return 0;
595 : }
596 : }
597 : default: {
598 : InstructionOperand op =
599 23887596 : OperandForDeopt(isolate(), g, input, kind, type.representation());
600 23887441 : if (op.kind() == InstructionOperand::INVALID) {
601 : // Invalid operand means the value is impossible or optimized-out.
602 343 : values->PushOptimizedOut();
603 345 : return 0;
604 : } else {
605 23887098 : inputs->push_back(op);
606 : values->PushPlain(type);
607 23888419 : return 1;
608 : }
609 : }
610 : }
611 : }
612 :
613 : // Returns the number of instruction operands added to inputs.
614 3955869 : size_t InstructionSelector::AddInputsToFrameStateDescriptor(
615 : FrameStateDescriptor* descriptor, Node* state, OperandGenerator* g,
616 : StateObjectDeduplicator* deduplicator, InstructionOperandVector* inputs,
617 : FrameStateInputKind kind, Zone* zone) {
618 : DCHECK_EQ(IrOpcode::kFrameState, state->op()->opcode());
619 :
620 : size_t entries = 0;
621 : size_t initial_size = inputs->size();
622 : USE(initial_size); // initial_size is only used for debug.
623 :
624 3955869 : if (descriptor->outer_state()) {
625 : entries += AddInputsToFrameStateDescriptor(
626 : descriptor->outer_state(), state->InputAt(kFrameStateOuterStateInput),
627 355401 : g, deduplicator, inputs, kind, zone);
628 : }
629 :
630 : Node* parameters = state->InputAt(kFrameStateParametersInput);
631 : Node* locals = state->InputAt(kFrameStateLocalsInput);
632 : Node* stack = state->InputAt(kFrameStateStackInput);
633 : Node* context = state->InputAt(kFrameStateContextInput);
634 : Node* function = state->InputAt(kFrameStateFunctionInput);
635 :
636 : DCHECK_EQ(descriptor->parameters_count(),
637 : StateValuesAccess(parameters).size());
638 : DCHECK_EQ(descriptor->locals_count(), StateValuesAccess(locals).size());
639 : DCHECK_EQ(descriptor->stack_count(), StateValuesAccess(stack).size());
640 :
641 : StateValueList* values_descriptor = descriptor->GetStateValueDescriptors();
642 :
643 : DCHECK_EQ(values_descriptor->size(), 0u);
644 3955849 : values_descriptor->ReserveSize(descriptor->GetSize());
645 :
646 : entries += AddOperandToStateValueDescriptor(
647 : values_descriptor, inputs, g, deduplicator, function,
648 3955858 : MachineType::AnyTagged(), FrameStateInputKind::kStackSlot, zone);
649 23911964 : for (StateValuesAccess::TypedNode input_node :
650 9978000 : StateValuesAccess(parameters)) {
651 9977935 : entries += AddOperandToStateValueDescriptor(values_descriptor, inputs, g,
652 : deduplicator, input_node.node,
653 9977935 : input_node.type, kind, zone);
654 : }
655 3955870 : if (descriptor->HasContext()) {
656 : entries += AddOperandToStateValueDescriptor(
657 : values_descriptor, inputs, g, deduplicator, context,
658 3871563 : MachineType::AnyTagged(), FrameStateInputKind::kStackSlot, zone);
659 : }
660 64768231 : for (StateValuesAccess::TypedNode input_node : StateValuesAccess(locals)) {
661 30405265 : entries += AddOperandToStateValueDescriptor(values_descriptor, inputs, g,
662 : deduplicator, input_node.node,
663 30405265 : input_node.type, kind, zone);
664 : }
665 11616988 : for (StateValuesAccess::TypedNode input_node : StateValuesAccess(stack)) {
666 3830546 : entries += AddOperandToStateValueDescriptor(values_descriptor, inputs, g,
667 : deduplicator, input_node.node,
668 3830546 : input_node.type, kind, zone);
669 : }
670 : DCHECK_EQ(initial_size + entries, inputs->size());
671 3955880 : return entries;
672 : }
673 :
674 561949 : Instruction* InstructionSelector::EmitWithContinuation(
675 : InstructionCode opcode, FlagsContinuation* cont) {
676 561949 : return EmitWithContinuation(opcode, 0, nullptr, 0, nullptr, cont);
677 : }
678 :
679 0 : Instruction* InstructionSelector::EmitWithContinuation(
680 : InstructionCode opcode, InstructionOperand a, FlagsContinuation* cont) {
681 0 : return EmitWithContinuation(opcode, 0, nullptr, 1, &a, cont);
682 : }
683 :
684 4344221 : Instruction* InstructionSelector::EmitWithContinuation(
685 : InstructionCode opcode, InstructionOperand a, InstructionOperand b,
686 : FlagsContinuation* cont) {
687 4344221 : InstructionOperand inputs[] = {a, b};
688 : return EmitWithContinuation(opcode, 0, nullptr, arraysize(inputs), inputs,
689 4344221 : cont);
690 : }
691 :
692 0 : Instruction* InstructionSelector::EmitWithContinuation(
693 : InstructionCode opcode, InstructionOperand a, InstructionOperand b,
694 : InstructionOperand c, FlagsContinuation* cont) {
695 0 : InstructionOperand inputs[] = {a, b, c};
696 : return EmitWithContinuation(opcode, 0, nullptr, arraysize(inputs), inputs,
697 0 : cont);
698 : }
699 :
700 6729678 : Instruction* InstructionSelector::EmitWithContinuation(
701 : InstructionCode opcode, size_t output_count, InstructionOperand* outputs,
702 : size_t input_count, InstructionOperand* inputs, FlagsContinuation* cont) {
703 : OperandGenerator g(this);
704 :
705 : opcode = cont->Encode(opcode);
706 :
707 6729678 : continuation_inputs_.resize(0);
708 33494252 : for (size_t i = 0; i < input_count; i++) {
709 13382125 : continuation_inputs_.push_back(inputs[i]);
710 : }
711 :
712 6729868 : continuation_outputs_.resize(0);
713 8810208 : for (size_t i = 0; i < output_count; i++) {
714 1040164 : continuation_outputs_.push_back(outputs[i]);
715 : }
716 :
717 6729866 : if (cont->IsBranch()) {
718 10818539 : continuation_inputs_.push_back(g.Label(cont->true_block()));
719 10818591 : continuation_inputs_.push_back(g.Label(cont->false_block()));
720 1320677 : } else if (cont->IsDeoptimize()) {
721 332015 : opcode |= MiscField::encode(static_cast<int>(input_count));
722 332015 : AppendDeoptimizeArguments(&continuation_inputs_, cont->kind(),
723 : cont->reason(), cont->feedback(),
724 332015 : cont->frame_state());
725 988662 : } else if (cont->IsSet()) {
726 751450 : continuation_outputs_.push_back(g.DefineAsRegister(cont->result()));
727 612937 : } else if (cont->IsTrap()) {
728 34567 : int trap_id = static_cast<int>(cont->trap_id());
729 69143 : continuation_inputs_.push_back(g.UseImmediate(trap_id));
730 : } else {
731 : DCHECK(cont->IsNone());
732 : }
733 :
734 : size_t const emit_inputs_size = continuation_inputs_.size();
735 : auto* emit_inputs =
736 6729958 : emit_inputs_size ? &continuation_inputs_.front() : nullptr;
737 : size_t const emit_outputs_size = continuation_outputs_.size();
738 : auto* emit_outputs =
739 6729958 : emit_outputs_size ? &continuation_outputs_.front() : nullptr;
740 : return Emit(opcode, emit_outputs_size, emit_outputs, emit_inputs_size,
741 6729958 : emit_inputs, 0, nullptr);
742 : }
743 :
744 375697 : void InstructionSelector::AppendDeoptimizeArguments(
745 : InstructionOperandVector* args, DeoptimizeKind kind,
746 : DeoptimizeReason reason, VectorSlotPair const& feedback,
747 : Node* frame_state) {
748 : OperandGenerator g(this);
749 375697 : FrameStateDescriptor* const descriptor = GetFrameStateDescriptor(frame_state);
750 : DCHECK_NE(DeoptimizeKind::kLazy, kind);
751 : int const state_id =
752 375698 : sequence()->AddDeoptimizationEntry(descriptor, kind, reason, feedback);
753 751395 : args->push_back(g.TempImmediate(state_id));
754 : StateObjectDeduplicator deduplicator(instruction_zone());
755 : AddInputsToFrameStateDescriptor(descriptor, frame_state, &g, &deduplicator,
756 : args, FrameStateInputKind::kAny,
757 375697 : instruction_zone());
758 375699 : }
759 :
760 43684 : Instruction* InstructionSelector::EmitDeoptimize(
761 : InstructionCode opcode, size_t output_count, InstructionOperand* outputs,
762 : size_t input_count, InstructionOperand* inputs, DeoptimizeKind kind,
763 : DeoptimizeReason reason, VectorSlotPair const& feedback,
764 : Node* frame_state) {
765 : InstructionOperandVector args(instruction_zone());
766 43684 : for (size_t i = 0; i < input_count; ++i) {
767 0 : args.push_back(inputs[i]);
768 : }
769 43684 : opcode |= MiscField::encode(static_cast<int>(input_count));
770 43684 : AppendDeoptimizeArguments(&args, kind, reason, feedback, frame_state);
771 : return Emit(opcode, output_count, outputs, args.size(), &args.front(), 0,
772 87368 : nullptr);
773 : }
774 :
775 : // An internal helper class for generating the operands to calls.
776 : // TODO(bmeurer): Get rid of the CallBuffer business and make
777 : // InstructionSelector::VisitCall platform independent instead.
778 6280757 : struct CallBuffer {
779 6280752 : CallBuffer(Zone* zone, const CallDescriptor* call_descriptor,
780 : FrameStateDescriptor* frame_state)
781 : : descriptor(call_descriptor),
782 : frame_state_descriptor(frame_state),
783 : output_nodes(zone),
784 : outputs(zone),
785 : instruction_args(zone),
786 6280752 : pushed_nodes(zone) {
787 6280752 : output_nodes.reserve(call_descriptor->ReturnCount());
788 6280800 : outputs.reserve(call_descriptor->ReturnCount());
789 6280826 : pushed_nodes.reserve(input_count());
790 6280841 : instruction_args.reserve(input_count() + frame_state_value_count());
791 6280842 : }
792 :
793 : const CallDescriptor* descriptor;
794 : FrameStateDescriptor* frame_state_descriptor;
795 : ZoneVector<PushParameter> output_nodes;
796 : InstructionOperandVector outputs;
797 : InstructionOperandVector instruction_args;
798 : ZoneVector<PushParameter> pushed_nodes;
799 :
800 : size_t input_count() const { return descriptor->InputCount(); }
801 :
802 : size_t frame_state_count() const { return descriptor->FrameStateCount(); }
803 :
804 : size_t frame_state_value_count() const {
805 : return (frame_state_descriptor == nullptr)
806 : ? 0
807 3224797 : : (frame_state_descriptor->GetTotalSize() +
808 9505638 : 1); // Include deopt id.
809 : }
810 : };
811 :
812 : // TODO(bmeurer): Get rid of the CallBuffer business and make
813 : // InstructionSelector::VisitCall platform independent instead.
814 6280777 : void InstructionSelector::InitializeCallBuffer(Node* call, CallBuffer* buffer,
815 : CallBufferFlags flags,
816 : bool is_tail_call,
817 : int stack_param_delta) {
818 : OperandGenerator g(this);
819 6280777 : size_t ret_count = buffer->descriptor->ReturnCount();
820 : DCHECK_LE(call->op()->ValueOutputCount(), ret_count);
821 : DCHECK_EQ(
822 : call->op()->ValueInputCount(),
823 : static_cast<int>(buffer->input_count() + buffer->frame_state_count()));
824 :
825 6280777 : if (ret_count > 0) {
826 : // Collect the projections that represent multiple outputs from this call.
827 6147470 : if (ret_count == 1) {
828 : PushParameter result = {call, buffer->descriptor->GetReturnLocation(0)};
829 6142186 : buffer->output_nodes.push_back(result);
830 : } else {
831 5284 : buffer->output_nodes.resize(ret_count);
832 : int stack_count = 0;
833 55832 : for (size_t i = 0; i < ret_count; ++i) {
834 25274 : LinkageLocation location = buffer->descriptor->GetReturnLocation(i);
835 25274 : buffer->output_nodes[i] = PushParameter(nullptr, location);
836 25274 : if (location.IsCallerFrameSlot()) {
837 14704 : stack_count += location.GetSizeInPointers();
838 : }
839 : }
840 79346 : for (Edge const edge : call->use_edges()) {
841 37031 : if (!NodeProperties::IsValueEdge(edge)) continue;
842 : Node* node = edge.from();
843 : DCHECK_EQ(IrOpcode::kProjection, node->opcode());
844 14480 : size_t const index = ProjectionIndexOf(node->op());
845 :
846 : DCHECK_LT(index, buffer->output_nodes.size());
847 : DCHECK(!buffer->output_nodes[index].node);
848 14480 : buffer->output_nodes[index].node = node;
849 : }
850 5284 : frame_->EnsureReturnSlots(stack_count);
851 : }
852 :
853 : // Filter out the outputs that aren't live because no projection uses them.
854 : size_t outputs_needed_by_framestate =
855 6147478 : buffer->frame_state_descriptor == nullptr
856 : ? 0
857 : : buffer->frame_state_descriptor->state_combine()
858 6147478 : .ConsumedOutputCount();
859 18482408 : for (size_t i = 0; i < buffer->output_nodes.size(); i++) {
860 6167462 : bool output_is_live = buffer->output_nodes[i].node != nullptr ||
861 : i < outputs_needed_by_framestate;
862 6167462 : if (output_is_live) {
863 6156664 : LinkageLocation location = buffer->output_nodes[i].location;
864 : MachineRepresentation rep = location.GetType().representation();
865 :
866 : Node* output = buffer->output_nodes[i].node;
867 : InstructionOperand op = output == nullptr
868 : ? g.TempLocation(location)
869 6156664 : : g.DefineAsLocation(output, location);
870 : MarkAsRepresentation(rep, op);
871 :
872 6156648 : if (!UnallocatedOperand::cast(op).HasFixedSlotPolicy()) {
873 6151577 : buffer->outputs.push_back(op);
874 6151596 : buffer->output_nodes[i].node = nullptr;
875 : }
876 : }
877 : }
878 : }
879 :
880 : // The first argument is always the callee code.
881 : Node* callee = call->InputAt(0);
882 : bool call_code_immediate = (flags & kCallCodeImmediate) != 0;
883 : bool call_address_immediate = (flags & kCallAddressImmediate) != 0;
884 : bool call_use_fixed_target_reg = (flags & kCallFixedTargetRegister) != 0;
885 : bool call_through_slot = (flags & kAllowCallThroughSlot) != 0;
886 6280788 : switch (buffer->descriptor->kind()) {
887 : case CallDescriptor::kCallCodeObject:
888 : // TODO(jgruber, v8:7449): The below is a hack to support tail-calls from
889 : // JS-linkage callers with a register code target. The problem is that the
890 : // code target register may be clobbered before the final jmp by
891 : // AssemblePopArgumentsAdaptorFrame. As a more permanent fix we could
892 : // entirely remove support for tail-calls from JS-linkage callers.
893 15143858 : buffer->instruction_args.push_back(
894 5174867 : (call_code_immediate && callee->opcode() == IrOpcode::kHeapConstant)
895 : ? g.UseImmediate(callee)
896 : : call_use_fixed_target_reg
897 : ? g.UseFixed(callee, kJavaScriptCallCodeStartRegister)
898 : : is_tail_call ? g.UseUniqueRegister(callee)
899 : : call_through_slot ? g.UseUniqueSlot(callee)
900 : : g.UseRegister(callee));
901 5174853 : break;
902 : case CallDescriptor::kCallAddress:
903 241256 : buffer->instruction_args.push_back(
904 108388 : (call_address_immediate &&
905 : callee->opcode() == IrOpcode::kExternalConstant)
906 : ? g.UseImmediate(callee)
907 : : call_use_fixed_target_reg
908 : ? g.UseFixed(callee, kJavaScriptCallCodeStartRegister)
909 : : g.UseRegister(callee));
910 108388 : break;
911 : case CallDescriptor::kCallWasmFunction:
912 : case CallDescriptor::kCallWasmImportWrapper:
913 2033405 : buffer->instruction_args.push_back(
914 970108 : (call_address_immediate &&
915 876966 : (callee->opcode() == IrOpcode::kRelocatableInt64Constant ||
916 : callee->opcode() == IrOpcode::kRelocatableInt32Constant))
917 : ? g.UseImmediate(callee)
918 : : call_use_fixed_target_reg
919 : ? g.UseFixed(callee, kJavaScriptCallCodeStartRegister)
920 : : g.UseRegister(callee));
921 970137 : break;
922 : case CallDescriptor::kCallBuiltinPointer:
923 : // The common case for builtin pointers is to have the target in a
924 : // register. If we have a constant, we use a register anyway to simplify
925 : // related code.
926 7168 : buffer->instruction_args.push_back(
927 : call_use_fixed_target_reg
928 : ? g.UseFixed(callee, kJavaScriptCallCodeStartRegister)
929 : : g.UseRegister(callee));
930 3584 : break;
931 : case CallDescriptor::kCallJSFunction:
932 23829 : buffer->instruction_args.push_back(
933 47658 : g.UseLocation(callee, buffer->descriptor->GetInputLocation(0)));
934 23829 : break;
935 : }
936 : DCHECK_EQ(1u, buffer->instruction_args.size());
937 :
938 : // Argument 1 is used for poison-alias index (encoded in a word-sized
939 : // immediate. This an index of the operand that aliases with poison register
940 : // or -1 if there is no aliasing.
941 12561606 : buffer->instruction_args.push_back(g.TempImmediate(-1));
942 : const size_t poison_alias_index = 1;
943 : DCHECK_EQ(buffer->instruction_args.size() - 1, poison_alias_index);
944 :
945 : // If the call needs a frame state, we insert the state information as
946 : // follows (n is the number of value inputs to the frame state):
947 : // arg 2 : deoptimization id.
948 : // arg 3 - arg (n + 2) : value inputs to the frame state.
949 : size_t frame_state_entries = 0;
950 : USE(frame_state_entries); // frame_state_entries is only used for debug.
951 6280807 : if (buffer->frame_state_descriptor != nullptr) {
952 : Node* frame_state =
953 6449556 : call->InputAt(static_cast<int>(buffer->descriptor->InputCount()));
954 :
955 : // If it was a syntactic tail call we need to drop the current frame and
956 : // all the frames on top of it that are either an arguments adaptor frame
957 : // or a tail caller frame.
958 3224778 : if (is_tail_call) {
959 0 : frame_state = NodeProperties::GetFrameStateInput(frame_state);
960 : buffer->frame_state_descriptor =
961 0 : buffer->frame_state_descriptor->outer_state();
962 0 : while (buffer->frame_state_descriptor != nullptr &&
963 : buffer->frame_state_descriptor->type() ==
964 : FrameStateType::kArgumentsAdaptor) {
965 0 : frame_state = NodeProperties::GetFrameStateInput(frame_state);
966 : buffer->frame_state_descriptor =
967 0 : buffer->frame_state_descriptor->outer_state();
968 : }
969 : }
970 :
971 6449564 : int const state_id = sequence()->AddDeoptimizationEntry(
972 : buffer->frame_state_descriptor, DeoptimizeKind::kLazy,
973 3224773 : DeoptimizeReason::kUnknown, VectorSlotPair());
974 6449580 : buffer->instruction_args.push_back(g.TempImmediate(state_id));
975 :
976 : StateObjectDeduplicator deduplicator(instruction_zone());
977 :
978 : frame_state_entries =
979 3224794 : 1 + AddInputsToFrameStateDescriptor(
980 : buffer->frame_state_descriptor, frame_state, &g, &deduplicator,
981 : &buffer->instruction_args, FrameStateInputKind::kStackSlot,
982 : instruction_zone());
983 :
984 : DCHECK_EQ(2 + frame_state_entries, buffer->instruction_args.size());
985 : }
986 :
987 : size_t input_count = static_cast<size_t>(buffer->input_count());
988 :
989 : // Split the arguments into pushed_nodes and instruction_args. Pushed
990 : // arguments require an explicit push instruction before the call and do
991 : // not appear as arguments to the call. Everything else ends up
992 : // as an InstructionOperand argument to the call.
993 : auto iter(call->inputs().begin());
994 : size_t pushed_count = 0;
995 6280827 : bool call_tail = (flags & kCallTail) != 0;
996 60901717 : for (size_t index = 0; index < input_count; ++iter, ++index) {
997 : DCHECK(iter != call->inputs().end());
998 : DCHECK_NE(IrOpcode::kFrameState, (*iter)->op()->opcode());
999 33591216 : if (index == 0) continue; // The first argument (callee) is already done.
1000 :
1001 42059308 : LinkageLocation location = buffer->descriptor->GetInputLocation(index);
1002 21029654 : if (call_tail) {
1003 : location = LinkageLocation::ConvertToTailCallerLocation(
1004 : location, stack_param_delta);
1005 : }
1006 21029654 : InstructionOperand op = g.UseLocation(*iter, location);
1007 : UnallocatedOperand unallocated = UnallocatedOperand::cast(op);
1008 21029733 : if (unallocated.HasFixedSlotPolicy() && !call_tail) {
1009 3683426 : int stack_index = -unallocated.fixed_slot_index() - 1;
1010 7366852 : if (static_cast<size_t>(stack_index) >= buffer->pushed_nodes.size()) {
1011 1719360 : buffer->pushed_nodes.resize(stack_index + 1);
1012 : }
1013 : PushParameter param = {*iter, location};
1014 3683428 : buffer->pushed_nodes[stack_index] = param;
1015 : pushed_count++;
1016 : } else {
1017 : // If we do load poisoning and the linkage uses the poisoning register,
1018 : // then we request the input in memory location, and during code
1019 : // generation, we move the input to the register.
1020 17346314 : if (poisoning_level_ != PoisoningMitigationLevel::kDontPoison &&
1021 : unallocated.HasFixedRegisterPolicy()) {
1022 : int reg = unallocated.fixed_register_index();
1023 7 : if (Register::from_code(reg) == kSpeculationPoisonRegister) {
1024 : buffer->instruction_args[poison_alias_index] = g.TempImmediate(
1025 0 : static_cast<int32_t>(buffer->instruction_args.size()));
1026 0 : op = g.UseRegisterOrSlotOrConstant(*iter);
1027 : }
1028 : }
1029 17346307 : buffer->instruction_args.push_back(op);
1030 : }
1031 : }
1032 : DCHECK_EQ(input_count, buffer->instruction_args.size() + pushed_count -
1033 : frame_state_entries - 1);
1034 6280837 : if (V8_TARGET_ARCH_STORES_RETURN_ADDRESS_ON_STACK && call_tail &&
1035 6280837 : stack_param_delta != 0) {
1036 : // For tail calls that change the size of their parameter list and keep
1037 : // their return address on the stack, move the return address to just above
1038 : // the parameters.
1039 : LinkageLocation saved_return_location =
1040 19272 : LinkageLocation::ForSavedCallerReturnAddress();
1041 : InstructionOperand return_address =
1042 : g.UsePointerLocation(LinkageLocation::ConvertToTailCallerLocation(
1043 : saved_return_location, stack_param_delta),
1044 19272 : saved_return_location);
1045 19272 : buffer->instruction_args.push_back(return_address);
1046 : }
1047 6280837 : }
1048 :
1049 0 : bool InstructionSelector::IsSourcePositionUsed(Node* node) {
1050 39132600 : return (source_position_mode_ == kAllSourcePositions ||
1051 15237879 : node->opcode() == IrOpcode::kCall ||
1052 15237886 : node->opcode() == IrOpcode::kCallWithCallerSavedRegisters ||
1053 15232051 : node->opcode() == IrOpcode::kTrapIf ||
1054 15203268 : node->opcode() == IrOpcode::kTrapUnless ||
1055 34911051 : node->opcode() == IrOpcode::kProtectedLoad ||
1056 0 : node->opcode() == IrOpcode::kProtectedStore);
1057 : }
1058 :
1059 20309010 : void InstructionSelector::VisitBlock(BasicBlock* block) {
1060 : DCHECK(!current_block_);
1061 20309010 : current_block_ = block;
1062 : auto current_num_instructions = [&] {
1063 : DCHECK_GE(kMaxInt, instructions_.size());
1064 474722554 : return static_cast<int>(instructions_.size());
1065 20309010 : };
1066 : int current_block_end = current_num_instructions();
1067 :
1068 : int effect_level = 0;
1069 133903344 : for (Node* const node : *block) {
1070 : SetEffectLevel(node, effect_level);
1071 222324484 : if (node->opcode() == IrOpcode::kStore ||
1072 108730129 : node->opcode() == IrOpcode::kUnalignedStore ||
1073 102787908 : node->opcode() == IrOpcode::kCall ||
1074 102786510 : node->opcode() == IrOpcode::kCallWithCallerSavedRegisters ||
1075 216287993 : node->opcode() == IrOpcode::kProtectedLoad ||
1076 : node->opcode() == IrOpcode::kProtectedStore) {
1077 11044616 : ++effect_level;
1078 : }
1079 : }
1080 :
1081 : // We visit the control first, then the nodes in the block, so the block's
1082 : // control input should be on the same effect level as the last node.
1083 20309010 : if (block->control_input() != nullptr) {
1084 : SetEffectLevel(block->control_input(), effect_level);
1085 : }
1086 :
1087 72969913 : auto FinishEmittedInstructions = [&](Node* node, int instruction_start) {
1088 151713272 : if (instruction_selection_failed()) return false;
1089 145941140 : if (current_num_instructions() == instruction_start) return true;
1090 : std::reverse(instructions_.begin() + instruction_start,
1091 : instructions_.end());
1092 63049743 : if (!node) return true;
1093 54106242 : if (!source_positions_) return true;
1094 39847816 : SourcePosition source_position = source_positions_->GetSourcePosition(node);
1095 59647506 : if (source_position.IsKnown() && IsSourcePositionUsed(node)) {
1096 4835742 : sequence()->SetSourcePosition(instructions_[instruction_start],
1097 4835742 : source_position);
1098 : }
1099 : return true;
1100 20309010 : };
1101 :
1102 : // Generate code for the block control "top down", but schedule the code
1103 : // "bottom up".
1104 20309010 : VisitControl(block);
1105 20308222 : if (!FinishEmittedInstructions(block->control_input(), current_block_end))
1106 9 : return;
1107 :
1108 : // Visit code in reverse control flow order, because architecture-specific
1109 : // matching may cover more than one node at a time.
1110 133927031 : for (auto node : base::Reversed(*block)) {
1111 : int current_node_end = current_num_instructions();
1112 : // Skip nodes that are unused or already defined.
1113 166536765 : if (IsUsed(node) && !IsDefined(node)) {
1114 : // Generate code for this node "top down", but schedule the code "bottom
1115 : // up".
1116 52664607 : VisitNode(node);
1117 52663215 : if (!FinishEmittedInstructions(node, current_node_end)) return;
1118 : }
1119 113619443 : if (trace_turbo_ == kEnableTraceTurboJson) {
1120 73 : instr_origins_[node->id()] = {current_num_instructions(),
1121 : current_node_end};
1122 : }
1123 : }
1124 :
1125 : // We're done with the block.
1126 : InstructionBlock* instruction_block =
1127 20309387 : sequence()->InstructionBlockAt(RpoNumber::FromInt(block->rpo_number()));
1128 20309193 : if (current_num_instructions() == current_block_end) {
1129 : // Avoid empty block: insert a {kArchNop} instruction.
1130 : Emit(Instruction::New(sequence()->zone(), kArchNop));
1131 : }
1132 : instruction_block->set_code_start(current_num_instructions());
1133 : instruction_block->set_code_end(current_block_end);
1134 20309292 : current_block_ = nullptr;
1135 : }
1136 :
1137 20308828 : void InstructionSelector::VisitControl(BasicBlock* block) {
1138 : #ifdef DEBUG
1139 : // SSA deconstruction requires targets of branches not to have phis.
1140 : // Edge split form guarantees this property, but is more strict.
1141 : if (block->SuccessorCount() > 1) {
1142 : for (BasicBlock* const successor : block->successors()) {
1143 : for (Node* const node : *successor) {
1144 : if (IrOpcode::IsPhiOpcode(node->opcode())) {
1145 : std::ostringstream str;
1146 : str << "You might have specified merged variables for a label with "
1147 : << "only one predecessor." << std::endl
1148 : << "# Current Block: " << *successor << std::endl
1149 : << "# Node: " << *node;
1150 : FATAL("%s", str.str().c_str());
1151 : }
1152 : }
1153 : }
1154 : }
1155 : #endif
1156 :
1157 : Node* input = block->control_input();
1158 20308828 : int instruction_end = static_cast<int>(instructions_.size());
1159 20308828 : switch (block->control()) {
1160 : case BasicBlock::kGoto:
1161 8944707 : VisitGoto(block->SuccessorAt(0));
1162 8944654 : break;
1163 : case BasicBlock::kCall: {
1164 : DCHECK_EQ(IrOpcode::kCall, input->opcode());
1165 : BasicBlock* success = block->SuccessorAt(0);
1166 : BasicBlock* exception = block->SuccessorAt(1);
1167 219623 : VisitCall(input, exception);
1168 219623 : VisitGoto(success);
1169 219623 : break;
1170 : }
1171 : case BasicBlock::kTailCall: {
1172 : DCHECK_EQ(IrOpcode::kTailCall, input->opcode());
1173 119688 : VisitTailCall(input);
1174 119688 : break;
1175 : }
1176 : case BasicBlock::kBranch: {
1177 : DCHECK_EQ(IrOpcode::kBranch, input->opcode());
1178 : BasicBlock* tbranch = block->SuccessorAt(0);
1179 : BasicBlock* fbranch = block->SuccessorAt(1);
1180 5409269 : if (tbranch == fbranch) {
1181 0 : VisitGoto(tbranch);
1182 : } else {
1183 5409269 : VisitBranch(input, tbranch, fbranch);
1184 : }
1185 : break;
1186 : }
1187 : case BasicBlock::kSwitch: {
1188 : DCHECK_EQ(IrOpcode::kSwitch, input->opcode());
1189 : // Last successor must be {IfDefault}.
1190 34181 : BasicBlock* default_branch = block->successors().back();
1191 : DCHECK_EQ(IrOpcode::kIfDefault, default_branch->front()->opcode());
1192 : // All other successors must be {IfValue}s.
1193 : int32_t min_value = std::numeric_limits<int32_t>::max();
1194 : int32_t max_value = std::numeric_limits<int32_t>::min();
1195 34181 : size_t case_count = block->SuccessorCount() - 1;
1196 : ZoneVector<CaseInfo> cases(case_count, zone());
1197 812863 : for (size_t i = 0; i < case_count; ++i) {
1198 : BasicBlock* branch = block->SuccessorAt(i);
1199 389343 : const IfValueParameters& p = IfValueParametersOf(branch->front()->op());
1200 389341 : cases[i] = CaseInfo{p.value(), p.comparison_order(), branch};
1201 389341 : if (min_value > p.value()) min_value = p.value();
1202 389341 : if (max_value < p.value()) max_value = p.value();
1203 : }
1204 : SwitchInfo sw(cases, min_value, max_value, default_branch);
1205 34179 : VisitSwitch(input, sw);
1206 : break;
1207 : }
1208 : case BasicBlock::kReturn: {
1209 : DCHECK_EQ(IrOpcode::kReturn, input->opcode());
1210 2787696 : VisitReturn(input);
1211 2788357 : break;
1212 : }
1213 : case BasicBlock::kDeoptimize: {
1214 43684 : DeoptimizeParameters p = DeoptimizeParametersOf(input->op());
1215 : Node* value = input->InputAt(0);
1216 : VisitDeoptimize(p.kind(), p.reason(), p.feedback(), value);
1217 : break;
1218 : }
1219 : case BasicBlock::kThrow:
1220 : DCHECK_EQ(IrOpcode::kThrow, input->opcode());
1221 : VisitThrow(input);
1222 : break;
1223 : case BasicBlock::kNone: {
1224 : // Exit block doesn't have control.
1225 : DCHECK_NULL(input);
1226 : break;
1227 : }
1228 : default:
1229 0 : UNREACHABLE();
1230 : break;
1231 : }
1232 20307989 : if (trace_turbo_ == kEnableTraceTurboJson && input) {
1233 5 : int instruction_start = static_cast<int>(instructions_.size());
1234 5 : instr_origins_[input->id()] = {instruction_start, instruction_end};
1235 : }
1236 20307989 : }
1237 :
1238 0 : void InstructionSelector::MarkPairProjectionsAsWord32(Node* node) {
1239 0 : Node* projection0 = NodeProperties::FindProjection(node, 0);
1240 0 : if (projection0) {
1241 : MarkAsWord32(projection0);
1242 : }
1243 0 : Node* projection1 = NodeProperties::FindProjection(node, 1);
1244 0 : if (projection1) {
1245 : MarkAsWord32(projection1);
1246 : }
1247 0 : }
1248 :
1249 52664387 : void InstructionSelector::VisitNode(Node* node) {
1250 : DCHECK_NOT_NULL(schedule()->block(node)); // should only use scheduled nodes.
1251 52664387 : switch (node->opcode()) {
1252 : case IrOpcode::kStart:
1253 : case IrOpcode::kLoop:
1254 : case IrOpcode::kEnd:
1255 : case IrOpcode::kBranch:
1256 : case IrOpcode::kIfTrue:
1257 : case IrOpcode::kIfFalse:
1258 : case IrOpcode::kIfSuccess:
1259 : case IrOpcode::kSwitch:
1260 : case IrOpcode::kIfValue:
1261 : case IrOpcode::kIfDefault:
1262 : case IrOpcode::kEffectPhi:
1263 : case IrOpcode::kMerge:
1264 : case IrOpcode::kTerminate:
1265 : case IrOpcode::kBeginRegion:
1266 : // No code needed for these graph artifacts.
1267 : return;
1268 : case IrOpcode::kIfException:
1269 198366 : return MarkAsReference(node), VisitIfException(node);
1270 : case IrOpcode::kFinishRegion:
1271 : return MarkAsReference(node), VisitFinishRegion(node);
1272 : case IrOpcode::kParameter: {
1273 : MachineType type =
1274 3584282 : linkage()->GetParameterType(ParameterIndexOf(node->op()));
1275 3583619 : MarkAsRepresentation(type.representation(), node);
1276 3584260 : return VisitParameter(node);
1277 : }
1278 : case IrOpcode::kOsrValue:
1279 21595 : return MarkAsReference(node), VisitOsrValue(node);
1280 : case IrOpcode::kPhi: {
1281 2161805 : MachineRepresentation rep = PhiRepresentationOf(node->op());
1282 2161794 : if (rep == MachineRepresentation::kNone) return;
1283 2161795 : MarkAsRepresentation(rep, node);
1284 2161792 : return VisitPhi(node);
1285 : }
1286 : case IrOpcode::kProjection:
1287 451356 : return VisitProjection(node);
1288 : case IrOpcode::kInt32Constant:
1289 : case IrOpcode::kInt64Constant:
1290 : case IrOpcode::kExternalConstant:
1291 : case IrOpcode::kRelocatableInt32Constant:
1292 : case IrOpcode::kRelocatableInt64Constant:
1293 7578352 : return VisitConstant(node);
1294 : case IrOpcode::kFloat32Constant:
1295 10381 : return MarkAsFloat32(node), VisitConstant(node);
1296 : case IrOpcode::kFloat64Constant:
1297 198843 : return MarkAsFloat64(node), VisitConstant(node);
1298 : case IrOpcode::kHeapConstant:
1299 4894748 : return MarkAsReference(node), VisitConstant(node);
1300 : case IrOpcode::kNumberConstant: {
1301 1378861 : double value = OpParameter<double>(node->op());
1302 1378861 : if (!IsSmiDouble(value)) MarkAsReference(node);
1303 1378861 : return VisitConstant(node);
1304 : }
1305 : case IrOpcode::kDelayedStringConstant:
1306 1648 : return MarkAsReference(node), VisitConstant(node);
1307 : case IrOpcode::kCall:
1308 5940804 : return VisitCall(node);
1309 : case IrOpcode::kCallWithCallerSavedRegisters:
1310 676 : return VisitCallWithCallerSavedRegisters(node);
1311 : case IrOpcode::kDeoptimizeIf:
1312 112057 : return VisitDeoptimizeIf(node);
1313 : case IrOpcode::kDeoptimizeUnless:
1314 219957 : return VisitDeoptimizeUnless(node);
1315 : case IrOpcode::kTrapIf:
1316 5839 : return VisitTrapIf(node, TrapIdOf(node->op()));
1317 : case IrOpcode::kTrapUnless:
1318 28748 : return VisitTrapUnless(node, TrapIdOf(node->op()));
1319 : case IrOpcode::kFrameState:
1320 : case IrOpcode::kStateValues:
1321 : case IrOpcode::kObjectState:
1322 : return;
1323 : case IrOpcode::kDebugAbort:
1324 0 : VisitDebugAbort(node);
1325 0 : return;
1326 : case IrOpcode::kDebugBreak:
1327 : VisitDebugBreak(node);
1328 : return;
1329 : case IrOpcode::kUnreachable:
1330 : VisitUnreachable(node);
1331 : return;
1332 : case IrOpcode::kDeadValue:
1333 0 : VisitDeadValue(node);
1334 0 : return;
1335 : case IrOpcode::kComment:
1336 4 : VisitComment(node);
1337 4 : return;
1338 : case IrOpcode::kRetain:
1339 9383 : VisitRetain(node);
1340 9383 : return;
1341 : case IrOpcode::kLoad: {
1342 7286386 : LoadRepresentation type = LoadRepresentationOf(node->op());
1343 7286374 : MarkAsRepresentation(type.representation(), node);
1344 7286444 : return VisitLoad(node);
1345 : }
1346 : case IrOpcode::kPoisonedLoad: {
1347 0 : LoadRepresentation type = LoadRepresentationOf(node->op());
1348 0 : MarkAsRepresentation(type.representation(), node);
1349 0 : return VisitPoisonedLoad(node);
1350 : }
1351 : case IrOpcode::kStore:
1352 4864726 : return VisitStore(node);
1353 : case IrOpcode::kProtectedStore:
1354 144018 : return VisitProtectedStore(node);
1355 : case IrOpcode::kWord32And:
1356 183716 : return MarkAsWord32(node), VisitWord32And(node);
1357 : case IrOpcode::kWord32Or:
1358 129121 : return MarkAsWord32(node), VisitWord32Or(node);
1359 : case IrOpcode::kWord32Xor:
1360 22736 : return MarkAsWord32(node), VisitWord32Xor(node);
1361 : case IrOpcode::kWord32Shl:
1362 68346 : return MarkAsWord32(node), VisitWord32Shl(node);
1363 : case IrOpcode::kWord32Shr:
1364 87558 : return MarkAsWord32(node), VisitWord32Shr(node);
1365 : case IrOpcode::kWord32Sar:
1366 181143 : return MarkAsWord32(node), VisitWord32Sar(node);
1367 : case IrOpcode::kWord32Ror:
1368 27674 : return MarkAsWord32(node), VisitWord32Ror(node);
1369 : case IrOpcode::kWord32Equal:
1370 108042 : return VisitWord32Equal(node);
1371 : case IrOpcode::kWord32Clz:
1372 447 : return MarkAsWord32(node), VisitWord32Clz(node);
1373 : case IrOpcode::kWord32Ctz:
1374 332 : return MarkAsWord32(node), VisitWord32Ctz(node);
1375 : case IrOpcode::kWord32ReverseBits:
1376 0 : return MarkAsWord32(node), VisitWord32ReverseBits(node);
1377 : case IrOpcode::kWord32ReverseBytes:
1378 44 : return MarkAsWord32(node), VisitWord32ReverseBytes(node);
1379 : case IrOpcode::kInt32AbsWithOverflow:
1380 0 : return MarkAsWord32(node), VisitInt32AbsWithOverflow(node);
1381 : case IrOpcode::kWord32Popcnt:
1382 64 : return MarkAsWord32(node), VisitWord32Popcnt(node);
1383 : case IrOpcode::kWord64Popcnt:
1384 44 : return MarkAsWord32(node), VisitWord64Popcnt(node);
1385 : case IrOpcode::kWord64And:
1386 184965 : return MarkAsWord64(node), VisitWord64And(node);
1387 : case IrOpcode::kWord64Or:
1388 22338 : return MarkAsWord64(node), VisitWord64Or(node);
1389 : case IrOpcode::kWord64Xor:
1390 877 : return MarkAsWord64(node), VisitWord64Xor(node);
1391 : case IrOpcode::kWord64Shl:
1392 301078 : return MarkAsWord64(node), VisitWord64Shl(node);
1393 : case IrOpcode::kWord64Shr:
1394 48741 : return MarkAsWord64(node), VisitWord64Shr(node);
1395 : case IrOpcode::kWord64Sar:
1396 643497 : return MarkAsWord64(node), VisitWord64Sar(node);
1397 : case IrOpcode::kWord64Ror:
1398 112 : return MarkAsWord64(node), VisitWord64Ror(node);
1399 : case IrOpcode::kWord64Clz:
1400 36 : return MarkAsWord64(node), VisitWord64Clz(node);
1401 : case IrOpcode::kWord64Ctz:
1402 44 : return MarkAsWord64(node), VisitWord64Ctz(node);
1403 : case IrOpcode::kWord64ReverseBits:
1404 0 : return MarkAsWord64(node), VisitWord64ReverseBits(node);
1405 : case IrOpcode::kWord64ReverseBytes:
1406 12 : return MarkAsWord64(node), VisitWord64ReverseBytes(node);
1407 : case IrOpcode::kInt64AbsWithOverflow:
1408 0 : return MarkAsWord64(node), VisitInt64AbsWithOverflow(node);
1409 : case IrOpcode::kWord64Equal:
1410 37936 : return VisitWord64Equal(node);
1411 : case IrOpcode::kInt32Add:
1412 332140 : return MarkAsWord32(node), VisitInt32Add(node);
1413 : case IrOpcode::kInt32AddWithOverflow:
1414 13924 : return MarkAsWord32(node), VisitInt32AddWithOverflow(node);
1415 : case IrOpcode::kInt32Sub:
1416 57287 : return MarkAsWord32(node), VisitInt32Sub(node);
1417 : case IrOpcode::kInt32SubWithOverflow:
1418 13924 : return VisitInt32SubWithOverflow(node);
1419 : case IrOpcode::kInt32Mul:
1420 57313 : return MarkAsWord32(node), VisitInt32Mul(node);
1421 : case IrOpcode::kInt32MulWithOverflow:
1422 13924 : return MarkAsWord32(node), VisitInt32MulWithOverflow(node);
1423 : case IrOpcode::kInt32MulHigh:
1424 4214 : return VisitInt32MulHigh(node);
1425 : case IrOpcode::kInt32Div:
1426 15662 : return MarkAsWord32(node), VisitInt32Div(node);
1427 : case IrOpcode::kInt32Mod:
1428 16280 : return MarkAsWord32(node), VisitInt32Mod(node);
1429 : case IrOpcode::kInt32LessThan:
1430 28341 : return VisitInt32LessThan(node);
1431 : case IrOpcode::kInt32LessThanOrEqual:
1432 27746 : return VisitInt32LessThanOrEqual(node);
1433 : case IrOpcode::kUint32Div:
1434 14453 : return MarkAsWord32(node), VisitUint32Div(node);
1435 : case IrOpcode::kUint32LessThan:
1436 33154 : return VisitUint32LessThan(node);
1437 : case IrOpcode::kUint32LessThanOrEqual:
1438 27910 : return VisitUint32LessThanOrEqual(node);
1439 : case IrOpcode::kUint32Mod:
1440 14602 : return MarkAsWord32(node), VisitUint32Mod(node);
1441 : case IrOpcode::kUint32MulHigh:
1442 1636 : return VisitUint32MulHigh(node);
1443 : case IrOpcode::kInt64Add:
1444 2119284 : return MarkAsWord64(node), VisitInt64Add(node);
1445 : case IrOpcode::kInt64AddWithOverflow:
1446 26896 : return MarkAsWord64(node), VisitInt64AddWithOverflow(node);
1447 : case IrOpcode::kInt64Sub:
1448 25743 : return MarkAsWord64(node), VisitInt64Sub(node);
1449 : case IrOpcode::kInt64SubWithOverflow:
1450 26896 : return MarkAsWord64(node), VisitInt64SubWithOverflow(node);
1451 : case IrOpcode::kInt64Mul:
1452 20786 : return MarkAsWord64(node), VisitInt64Mul(node);
1453 : case IrOpcode::kInt64Div:
1454 1852 : return MarkAsWord64(node), VisitInt64Div(node);
1455 : case IrOpcode::kInt64Mod:
1456 880 : return MarkAsWord64(node), VisitInt64Mod(node);
1457 : case IrOpcode::kInt64LessThan:
1458 1142 : return VisitInt64LessThan(node);
1459 : case IrOpcode::kInt64LessThanOrEqual:
1460 829 : return VisitInt64LessThanOrEqual(node);
1461 : case IrOpcode::kUint64Div:
1462 896 : return MarkAsWord64(node), VisitUint64Div(node);
1463 : case IrOpcode::kUint64LessThan:
1464 5690 : return VisitUint64LessThan(node);
1465 : case IrOpcode::kUint64LessThanOrEqual:
1466 408 : return VisitUint64LessThanOrEqual(node);
1467 : case IrOpcode::kUint64Mod:
1468 872 : return MarkAsWord64(node), VisitUint64Mod(node);
1469 : case IrOpcode::kBitcastTaggedToWord:
1470 1507050 : return MarkAsRepresentation(MachineType::PointerRepresentation(), node),
1471 : VisitBitcastTaggedToWord(node);
1472 : case IrOpcode::kBitcastWordToTagged:
1473 568010 : return MarkAsReference(node), VisitBitcastWordToTagged(node);
1474 : case IrOpcode::kBitcastWordToTaggedSigned:
1475 804628 : return MarkAsRepresentation(MachineRepresentation::kTaggedSigned, node),
1476 804628 : EmitIdentity(node);
1477 : case IrOpcode::kChangeFloat32ToFloat64:
1478 20404 : return MarkAsFloat64(node), VisitChangeFloat32ToFloat64(node);
1479 : case IrOpcode::kChangeInt32ToFloat64:
1480 432778 : return MarkAsFloat64(node), VisitChangeInt32ToFloat64(node);
1481 : case IrOpcode::kChangeInt64ToFloat64:
1482 260 : return MarkAsFloat64(node), VisitChangeInt64ToFloat64(node);
1483 : case IrOpcode::kChangeUint32ToFloat64:
1484 11203 : return MarkAsFloat64(node), VisitChangeUint32ToFloat64(node);
1485 : case IrOpcode::kChangeFloat64ToInt32:
1486 1793 : return MarkAsWord32(node), VisitChangeFloat64ToInt32(node);
1487 : case IrOpcode::kChangeFloat64ToInt64:
1488 24 : return MarkAsWord64(node), VisitChangeFloat64ToInt64(node);
1489 : case IrOpcode::kChangeFloat64ToUint32:
1490 690 : return MarkAsWord32(node), VisitChangeFloat64ToUint32(node);
1491 : case IrOpcode::kChangeFloat64ToUint64:
1492 2912 : return MarkAsWord64(node), VisitChangeFloat64ToUint64(node);
1493 : case IrOpcode::kFloat64SilenceNaN:
1494 : MarkAsFloat64(node);
1495 6244 : if (CanProduceSignalingNaN(node->InputAt(0))) {
1496 6049 : return VisitFloat64SilenceNaN(node);
1497 : } else {
1498 195 : return EmitIdentity(node);
1499 : }
1500 : case IrOpcode::kTruncateFloat64ToInt64:
1501 103 : return MarkAsWord64(node), VisitTruncateFloat64ToInt64(node);
1502 : case IrOpcode::kTruncateFloat64ToUint32:
1503 60 : return MarkAsWord32(node), VisitTruncateFloat64ToUint32(node);
1504 : case IrOpcode::kTruncateFloat32ToInt32:
1505 348 : return MarkAsWord32(node), VisitTruncateFloat32ToInt32(node);
1506 : case IrOpcode::kTruncateFloat32ToUint32:
1507 56 : return MarkAsWord32(node), VisitTruncateFloat32ToUint32(node);
1508 : case IrOpcode::kTryTruncateFloat32ToInt64:
1509 52 : return MarkAsWord64(node), VisitTryTruncateFloat32ToInt64(node);
1510 : case IrOpcode::kTryTruncateFloat64ToInt64:
1511 764 : return MarkAsWord64(node), VisitTryTruncateFloat64ToInt64(node);
1512 : case IrOpcode::kTryTruncateFloat32ToUint64:
1513 52 : return MarkAsWord64(node), VisitTryTruncateFloat32ToUint64(node);
1514 : case IrOpcode::kTryTruncateFloat64ToUint64:
1515 60 : return MarkAsWord64(node), VisitTryTruncateFloat64ToUint64(node);
1516 : case IrOpcode::kChangeInt32ToInt64:
1517 459527 : return MarkAsWord64(node), VisitChangeInt32ToInt64(node);
1518 : case IrOpcode::kChangeUint32ToUint64:
1519 303926 : return MarkAsWord64(node), VisitChangeUint32ToUint64(node);
1520 : case IrOpcode::kChangeTaggedToCompressed:
1521 8 : return MarkAsWord32(node), VisitChangeTaggedToCompressed(node);
1522 : case IrOpcode::kChangeTaggedPointerToCompressedPointer:
1523 : return MarkAsWord32(node),
1524 4 : VisitChangeTaggedPointerToCompressedPointer(node);
1525 : case IrOpcode::kChangeTaggedSignedToCompressedSigned:
1526 : return MarkAsWord32(node),
1527 4 : VisitChangeTaggedSignedToCompressedSigned(node);
1528 : case IrOpcode::kChangeCompressedToTagged:
1529 8 : return MarkAsWord64(node), VisitChangeCompressedToTagged(node);
1530 : case IrOpcode::kChangeCompressedPointerToTaggedPointer:
1531 : return MarkAsWord64(node),
1532 4 : VisitChangeCompressedPointerToTaggedPointer(node);
1533 : case IrOpcode::kChangeCompressedSignedToTaggedSigned:
1534 : return MarkAsWord64(node),
1535 4 : VisitChangeCompressedSignedToTaggedSigned(node);
1536 : case IrOpcode::kTruncateFloat64ToFloat32:
1537 17935 : return MarkAsFloat32(node), VisitTruncateFloat64ToFloat32(node);
1538 : case IrOpcode::kTruncateFloat64ToWord32:
1539 55432 : return MarkAsWord32(node), VisitTruncateFloat64ToWord32(node);
1540 : case IrOpcode::kTruncateInt64ToInt32:
1541 572190 : return MarkAsWord32(node), VisitTruncateInt64ToInt32(node);
1542 : case IrOpcode::kRoundFloat64ToInt32:
1543 126664 : return MarkAsWord32(node), VisitRoundFloat64ToInt32(node);
1544 : case IrOpcode::kRoundInt64ToFloat32:
1545 32 : return MarkAsFloat32(node), VisitRoundInt64ToFloat32(node);
1546 : case IrOpcode::kRoundInt32ToFloat32:
1547 960 : return MarkAsFloat32(node), VisitRoundInt32ToFloat32(node);
1548 : case IrOpcode::kRoundInt64ToFloat64:
1549 2996 : return MarkAsFloat64(node), VisitRoundInt64ToFloat64(node);
1550 : case IrOpcode::kBitcastFloat32ToInt32:
1551 553 : return MarkAsWord32(node), VisitBitcastFloat32ToInt32(node);
1552 : case IrOpcode::kRoundUint32ToFloat32:
1553 88 : return MarkAsFloat32(node), VisitRoundUint32ToFloat32(node);
1554 : case IrOpcode::kRoundUint64ToFloat32:
1555 32 : return MarkAsFloat64(node), VisitRoundUint64ToFloat32(node);
1556 : case IrOpcode::kRoundUint64ToFloat64:
1557 3607 : return MarkAsFloat64(node), VisitRoundUint64ToFloat64(node);
1558 : case IrOpcode::kBitcastFloat64ToInt64:
1559 528 : return MarkAsWord64(node), VisitBitcastFloat64ToInt64(node);
1560 : case IrOpcode::kBitcastInt32ToFloat32:
1561 307 : return MarkAsFloat32(node), VisitBitcastInt32ToFloat32(node);
1562 : case IrOpcode::kBitcastInt64ToFloat64:
1563 156 : return MarkAsFloat64(node), VisitBitcastInt64ToFloat64(node);
1564 : case IrOpcode::kFloat32Add:
1565 1744 : return MarkAsFloat32(node), VisitFloat32Add(node);
1566 : case IrOpcode::kFloat32Sub:
1567 2553 : return MarkAsFloat32(node), VisitFloat32Sub(node);
1568 : case IrOpcode::kFloat32Neg:
1569 166 : return MarkAsFloat32(node), VisitFloat32Neg(node);
1570 : case IrOpcode::kFloat32Mul:
1571 869 : return MarkAsFloat32(node), VisitFloat32Mul(node);
1572 : case IrOpcode::kFloat32Div:
1573 353 : return MarkAsFloat32(node), VisitFloat32Div(node);
1574 : case IrOpcode::kFloat32Abs:
1575 68 : return MarkAsFloat32(node), VisitFloat32Abs(node);
1576 : case IrOpcode::kFloat32Sqrt:
1577 174 : return MarkAsFloat32(node), VisitFloat32Sqrt(node);
1578 : case IrOpcode::kFloat32Equal:
1579 106 : return VisitFloat32Equal(node);
1580 : case IrOpcode::kFloat32LessThan:
1581 106 : return VisitFloat32LessThan(node);
1582 : case IrOpcode::kFloat32LessThanOrEqual:
1583 103 : return VisitFloat32LessThanOrEqual(node);
1584 : case IrOpcode::kFloat32Max:
1585 66 : return MarkAsFloat32(node), VisitFloat32Max(node);
1586 : case IrOpcode::kFloat32Min:
1587 66 : return MarkAsFloat32(node), VisitFloat32Min(node);
1588 : case IrOpcode::kFloat64Add:
1589 80005 : return MarkAsFloat64(node), VisitFloat64Add(node);
1590 : case IrOpcode::kFloat64Sub:
1591 15853 : return MarkAsFloat64(node), VisitFloat64Sub(node);
1592 : case IrOpcode::kFloat64Neg:
1593 10633 : return MarkAsFloat64(node), VisitFloat64Neg(node);
1594 : case IrOpcode::kFloat64Mul:
1595 11878 : return MarkAsFloat64(node), VisitFloat64Mul(node);
1596 : case IrOpcode::kFloat64Div:
1597 11967 : return MarkAsFloat64(node), VisitFloat64Div(node);
1598 : case IrOpcode::kFloat64Mod:
1599 1646 : return MarkAsFloat64(node), VisitFloat64Mod(node);
1600 : case IrOpcode::kFloat64Min:
1601 337 : return MarkAsFloat64(node), VisitFloat64Min(node);
1602 : case IrOpcode::kFloat64Max:
1603 252 : return MarkAsFloat64(node), VisitFloat64Max(node);
1604 : case IrOpcode::kFloat64Abs:
1605 628 : return MarkAsFloat64(node), VisitFloat64Abs(node);
1606 : case IrOpcode::kFloat64Acos:
1607 : return MarkAsFloat64(node), VisitFloat64Acos(node);
1608 : case IrOpcode::kFloat64Acosh:
1609 : return MarkAsFloat64(node), VisitFloat64Acosh(node);
1610 : case IrOpcode::kFloat64Asin:
1611 : return MarkAsFloat64(node), VisitFloat64Asin(node);
1612 : case IrOpcode::kFloat64Asinh:
1613 : return MarkAsFloat64(node), VisitFloat64Asinh(node);
1614 : case IrOpcode::kFloat64Atan:
1615 : return MarkAsFloat64(node), VisitFloat64Atan(node);
1616 : case IrOpcode::kFloat64Atanh:
1617 : return MarkAsFloat64(node), VisitFloat64Atanh(node);
1618 : case IrOpcode::kFloat64Atan2:
1619 : return MarkAsFloat64(node), VisitFloat64Atan2(node);
1620 : case IrOpcode::kFloat64Cbrt:
1621 : return MarkAsFloat64(node), VisitFloat64Cbrt(node);
1622 : case IrOpcode::kFloat64Cos:
1623 : return MarkAsFloat64(node), VisitFloat64Cos(node);
1624 : case IrOpcode::kFloat64Cosh:
1625 : return MarkAsFloat64(node), VisitFloat64Cosh(node);
1626 : case IrOpcode::kFloat64Exp:
1627 : return MarkAsFloat64(node), VisitFloat64Exp(node);
1628 : case IrOpcode::kFloat64Expm1:
1629 : return MarkAsFloat64(node), VisitFloat64Expm1(node);
1630 : case IrOpcode::kFloat64Log:
1631 : return MarkAsFloat64(node), VisitFloat64Log(node);
1632 : case IrOpcode::kFloat64Log1p:
1633 : return MarkAsFloat64(node), VisitFloat64Log1p(node);
1634 : case IrOpcode::kFloat64Log10:
1635 : return MarkAsFloat64(node), VisitFloat64Log10(node);
1636 : case IrOpcode::kFloat64Log2:
1637 : return MarkAsFloat64(node), VisitFloat64Log2(node);
1638 : case IrOpcode::kFloat64Pow:
1639 : return MarkAsFloat64(node), VisitFloat64Pow(node);
1640 : case IrOpcode::kFloat64Sin:
1641 : return MarkAsFloat64(node), VisitFloat64Sin(node);
1642 : case IrOpcode::kFloat64Sinh:
1643 : return MarkAsFloat64(node), VisitFloat64Sinh(node);
1644 : case IrOpcode::kFloat64Sqrt:
1645 415 : return MarkAsFloat64(node), VisitFloat64Sqrt(node);
1646 : case IrOpcode::kFloat64Tan:
1647 : return MarkAsFloat64(node), VisitFloat64Tan(node);
1648 : case IrOpcode::kFloat64Tanh:
1649 : return MarkAsFloat64(node), VisitFloat64Tanh(node);
1650 : case IrOpcode::kFloat64Equal:
1651 2616 : return VisitFloat64Equal(node);
1652 : case IrOpcode::kFloat64LessThan:
1653 4902 : return VisitFloat64LessThan(node);
1654 : case IrOpcode::kFloat64LessThanOrEqual:
1655 1147 : return VisitFloat64LessThanOrEqual(node);
1656 : case IrOpcode::kFloat32RoundDown:
1657 50 : return MarkAsFloat32(node), VisitFloat32RoundDown(node);
1658 : case IrOpcode::kFloat64RoundDown:
1659 27402 : return MarkAsFloat64(node), VisitFloat64RoundDown(node);
1660 : case IrOpcode::kFloat32RoundUp:
1661 50 : return MarkAsFloat32(node), VisitFloat32RoundUp(node);
1662 : case IrOpcode::kFloat64RoundUp:
1663 8787 : return MarkAsFloat64(node), VisitFloat64RoundUp(node);
1664 : case IrOpcode::kFloat32RoundTruncate:
1665 195 : return MarkAsFloat32(node), VisitFloat32RoundTruncate(node);
1666 : case IrOpcode::kFloat64RoundTruncate:
1667 7922 : return MarkAsFloat64(node), VisitFloat64RoundTruncate(node);
1668 : case IrOpcode::kFloat64RoundTiesAway:
1669 0 : return MarkAsFloat64(node), VisitFloat64RoundTiesAway(node);
1670 : case IrOpcode::kFloat32RoundTiesEven:
1671 24 : return MarkAsFloat32(node), VisitFloat32RoundTiesEven(node);
1672 : case IrOpcode::kFloat64RoundTiesEven:
1673 1060 : return MarkAsFloat64(node), VisitFloat64RoundTiesEven(node);
1674 : case IrOpcode::kFloat64ExtractLowWord32:
1675 116 : return MarkAsWord32(node), VisitFloat64ExtractLowWord32(node);
1676 : case IrOpcode::kFloat64ExtractHighWord32:
1677 96424 : return MarkAsWord32(node), VisitFloat64ExtractHighWord32(node);
1678 : case IrOpcode::kFloat64InsertLowWord32:
1679 116 : return MarkAsFloat64(node), VisitFloat64InsertLowWord32(node);
1680 : case IrOpcode::kFloat64InsertHighWord32:
1681 116 : return MarkAsFloat64(node), VisitFloat64InsertHighWord32(node);
1682 : case IrOpcode::kTaggedPoisonOnSpeculation:
1683 : return MarkAsReference(node), VisitTaggedPoisonOnSpeculation(node);
1684 : case IrOpcode::kWord32PoisonOnSpeculation:
1685 : return MarkAsWord32(node), VisitWord32PoisonOnSpeculation(node);
1686 : case IrOpcode::kWord64PoisonOnSpeculation:
1687 : return MarkAsWord64(node), VisitWord64PoisonOnSpeculation(node);
1688 : case IrOpcode::kStackSlot:
1689 366541 : return VisitStackSlot(node);
1690 : case IrOpcode::kLoadStackPointer:
1691 1 : return VisitLoadStackPointer(node);
1692 : case IrOpcode::kLoadFramePointer:
1693 32660 : return VisitLoadFramePointer(node);
1694 : case IrOpcode::kLoadParentFramePointer:
1695 50404 : return VisitLoadParentFramePointer(node);
1696 : case IrOpcode::kUnalignedLoad: {
1697 0 : LoadRepresentation type = LoadRepresentationOf(node->op());
1698 0 : MarkAsRepresentation(type.representation(), node);
1699 0 : return VisitUnalignedLoad(node);
1700 : }
1701 : case IrOpcode::kUnalignedStore:
1702 0 : return VisitUnalignedStore(node);
1703 : case IrOpcode::kInt32PairAdd:
1704 : MarkAsWord32(node);
1705 0 : MarkPairProjectionsAsWord32(node);
1706 0 : return VisitInt32PairAdd(node);
1707 : case IrOpcode::kInt32PairSub:
1708 : MarkAsWord32(node);
1709 0 : MarkPairProjectionsAsWord32(node);
1710 0 : return VisitInt32PairSub(node);
1711 : case IrOpcode::kInt32PairMul:
1712 : MarkAsWord32(node);
1713 0 : MarkPairProjectionsAsWord32(node);
1714 0 : return VisitInt32PairMul(node);
1715 : case IrOpcode::kWord32PairShl:
1716 : MarkAsWord32(node);
1717 0 : MarkPairProjectionsAsWord32(node);
1718 0 : return VisitWord32PairShl(node);
1719 : case IrOpcode::kWord32PairShr:
1720 : MarkAsWord32(node);
1721 0 : MarkPairProjectionsAsWord32(node);
1722 0 : return VisitWord32PairShr(node);
1723 : case IrOpcode::kWord32PairSar:
1724 : MarkAsWord32(node);
1725 0 : MarkPairProjectionsAsWord32(node);
1726 0 : return VisitWord32PairSar(node);
1727 : case IrOpcode::kWord32AtomicLoad: {
1728 1076 : LoadRepresentation type = LoadRepresentationOf(node->op());
1729 1076 : MarkAsRepresentation(type.representation(), node);
1730 1076 : return VisitWord32AtomicLoad(node);
1731 : }
1732 : case IrOpcode::kWord64AtomicLoad: {
1733 584 : LoadRepresentation type = LoadRepresentationOf(node->op());
1734 584 : MarkAsRepresentation(type.representation(), node);
1735 584 : return VisitWord64AtomicLoad(node);
1736 : }
1737 : case IrOpcode::kWord32AtomicStore:
1738 2071 : return VisitWord32AtomicStore(node);
1739 : case IrOpcode::kWord64AtomicStore:
1740 2024 : return VisitWord64AtomicStore(node);
1741 : case IrOpcode::kWord32AtomicPairStore:
1742 0 : return VisitWord32AtomicPairStore(node);
1743 : case IrOpcode::kWord32AtomicPairLoad: {
1744 : MarkAsWord32(node);
1745 0 : MarkPairProjectionsAsWord32(node);
1746 0 : return VisitWord32AtomicPairLoad(node);
1747 : }
1748 : #define ATOMIC_CASE(name, rep) \
1749 : case IrOpcode::k##rep##Atomic##name: { \
1750 : MachineType type = AtomicOpType(node->op()); \
1751 : MarkAsRepresentation(type.representation(), node); \
1752 : return Visit##rep##Atomic##name(node); \
1753 : }
1754 2924 : ATOMIC_CASE(Add, Word32)
1755 2039 : ATOMIC_CASE(Add, Word64)
1756 1978 : ATOMIC_CASE(Sub, Word32)
1757 2655 : ATOMIC_CASE(Sub, Word64)
1758 2769 : ATOMIC_CASE(And, Word32)
1759 2287 : ATOMIC_CASE(And, Word64)
1760 2505 : ATOMIC_CASE(Or, Word32)
1761 2520 : ATOMIC_CASE(Or, Word64)
1762 2554 : ATOMIC_CASE(Xor, Word32)
1763 2516 : ATOMIC_CASE(Xor, Word64)
1764 2604 : ATOMIC_CASE(Exchange, Word32)
1765 2879 : ATOMIC_CASE(Exchange, Word64)
1766 739 : ATOMIC_CASE(CompareExchange, Word32)
1767 332 : ATOMIC_CASE(CompareExchange, Word64)
1768 : #undef ATOMIC_CASE
1769 : #define ATOMIC_CASE(name) \
1770 : case IrOpcode::kWord32AtomicPair##name: { \
1771 : MarkAsWord32(node); \
1772 : MarkPairProjectionsAsWord32(node); \
1773 : return VisitWord32AtomicPair##name(node); \
1774 : }
1775 0 : ATOMIC_CASE(Add)
1776 0 : ATOMIC_CASE(Sub)
1777 0 : ATOMIC_CASE(And)
1778 0 : ATOMIC_CASE(Or)
1779 0 : ATOMIC_CASE(Xor)
1780 0 : ATOMIC_CASE(Exchange)
1781 0 : ATOMIC_CASE(CompareExchange)
1782 : #undef ATOMIC_CASE
1783 : case IrOpcode::kProtectedLoad: {
1784 93577 : LoadRepresentation type = LoadRepresentationOf(node->op());
1785 93576 : MarkAsRepresentation(type.representation(), node);
1786 93588 : return VisitProtectedLoad(node);
1787 : }
1788 : case IrOpcode::kSignExtendWord8ToInt32:
1789 4 : return MarkAsWord32(node), VisitSignExtendWord8ToInt32(node);
1790 : case IrOpcode::kSignExtendWord16ToInt32:
1791 4 : return MarkAsWord32(node), VisitSignExtendWord16ToInt32(node);
1792 : case IrOpcode::kSignExtendWord8ToInt64:
1793 4 : return MarkAsWord64(node), VisitSignExtendWord8ToInt64(node);
1794 : case IrOpcode::kSignExtendWord16ToInt64:
1795 4 : return MarkAsWord64(node), VisitSignExtendWord16ToInt64(node);
1796 : case IrOpcode::kSignExtendWord32ToInt64:
1797 4 : return MarkAsWord64(node), VisitSignExtendWord32ToInt64(node);
1798 : case IrOpcode::kUnsafePointerAdd:
1799 6823 : MarkAsRepresentation(MachineType::PointerRepresentation(), node);
1800 : return VisitUnsafePointerAdd(node);
1801 : case IrOpcode::kF32x4Splat:
1802 140 : return MarkAsSimd128(node), VisitF32x4Splat(node);
1803 : case IrOpcode::kF32x4ExtractLane:
1804 32 : return MarkAsFloat32(node), VisitF32x4ExtractLane(node);
1805 : case IrOpcode::kF32x4ReplaceLane:
1806 32 : return MarkAsSimd128(node), VisitF32x4ReplaceLane(node);
1807 : case IrOpcode::kF32x4SConvertI32x4:
1808 4 : return MarkAsSimd128(node), VisitF32x4SConvertI32x4(node);
1809 : case IrOpcode::kF32x4UConvertI32x4:
1810 4 : return MarkAsSimd128(node), VisitF32x4UConvertI32x4(node);
1811 : case IrOpcode::kF32x4Abs:
1812 4 : return MarkAsSimd128(node), VisitF32x4Abs(node);
1813 : case IrOpcode::kF32x4Neg:
1814 4 : return MarkAsSimd128(node), VisitF32x4Neg(node);
1815 : case IrOpcode::kF32x4RecipApprox:
1816 4 : return MarkAsSimd128(node), VisitF32x4RecipApprox(node);
1817 : case IrOpcode::kF32x4RecipSqrtApprox:
1818 4 : return MarkAsSimd128(node), VisitF32x4RecipSqrtApprox(node);
1819 : case IrOpcode::kF32x4Add:
1820 12 : return MarkAsSimd128(node), VisitF32x4Add(node);
1821 : case IrOpcode::kF32x4AddHoriz:
1822 4 : return MarkAsSimd128(node), VisitF32x4AddHoriz(node);
1823 : case IrOpcode::kF32x4Sub:
1824 4 : return MarkAsSimd128(node), VisitF32x4Sub(node);
1825 : case IrOpcode::kF32x4Mul:
1826 4 : return MarkAsSimd128(node), VisitF32x4Mul(node);
1827 : case IrOpcode::kF32x4Min:
1828 4 : return MarkAsSimd128(node), VisitF32x4Min(node);
1829 : case IrOpcode::kF32x4Max:
1830 4 : return MarkAsSimd128(node), VisitF32x4Max(node);
1831 : case IrOpcode::kF32x4Eq:
1832 4 : return MarkAsSimd128(node), VisitF32x4Eq(node);
1833 : case IrOpcode::kF32x4Ne:
1834 4 : return MarkAsSimd128(node), VisitF32x4Ne(node);
1835 : case IrOpcode::kF32x4Lt:
1836 8 : return MarkAsSimd128(node), VisitF32x4Lt(node);
1837 : case IrOpcode::kF32x4Le:
1838 8 : return MarkAsSimd128(node), VisitF32x4Le(node);
1839 : case IrOpcode::kI32x4Splat:
1840 1072 : return MarkAsSimd128(node), VisitI32x4Splat(node);
1841 : case IrOpcode::kI32x4ExtractLane:
1842 1884 : return MarkAsWord32(node), VisitI32x4ExtractLane(node);
1843 : case IrOpcode::kI32x4ReplaceLane:
1844 1784 : return MarkAsSimd128(node), VisitI32x4ReplaceLane(node);
1845 : case IrOpcode::kI32x4SConvertF32x4:
1846 4 : return MarkAsSimd128(node), VisitI32x4SConvertF32x4(node);
1847 : case IrOpcode::kI32x4SConvertI16x8Low:
1848 4 : return MarkAsSimd128(node), VisitI32x4SConvertI16x8Low(node);
1849 : case IrOpcode::kI32x4SConvertI16x8High:
1850 4 : return MarkAsSimd128(node), VisitI32x4SConvertI16x8High(node);
1851 : case IrOpcode::kI32x4Neg:
1852 4 : return MarkAsSimd128(node), VisitI32x4Neg(node);
1853 : case IrOpcode::kI32x4Shl:
1854 124 : return MarkAsSimd128(node), VisitI32x4Shl(node);
1855 : case IrOpcode::kI32x4ShrS:
1856 124 : return MarkAsSimd128(node), VisitI32x4ShrS(node);
1857 : case IrOpcode::kI32x4Add:
1858 12 : return MarkAsSimd128(node), VisitI32x4Add(node);
1859 : case IrOpcode::kI32x4AddHoriz:
1860 4 : return MarkAsSimd128(node), VisitI32x4AddHoriz(node);
1861 : case IrOpcode::kI32x4Sub:
1862 4 : return MarkAsSimd128(node), VisitI32x4Sub(node);
1863 : case IrOpcode::kI32x4Mul:
1864 4 : return MarkAsSimd128(node), VisitI32x4Mul(node);
1865 : case IrOpcode::kI32x4MinS:
1866 4 : return MarkAsSimd128(node), VisitI32x4MinS(node);
1867 : case IrOpcode::kI32x4MaxS:
1868 4 : return MarkAsSimd128(node), VisitI32x4MaxS(node);
1869 : case IrOpcode::kI32x4Eq:
1870 12 : return MarkAsSimd128(node), VisitI32x4Eq(node);
1871 : case IrOpcode::kI32x4Ne:
1872 16 : return MarkAsSimd128(node), VisitI32x4Ne(node);
1873 : case IrOpcode::kI32x4GtS:
1874 8 : return MarkAsSimd128(node), VisitI32x4GtS(node);
1875 : case IrOpcode::kI32x4GeS:
1876 8 : return MarkAsSimd128(node), VisitI32x4GeS(node);
1877 : case IrOpcode::kI32x4UConvertF32x4:
1878 4 : return MarkAsSimd128(node), VisitI32x4UConvertF32x4(node);
1879 : case IrOpcode::kI32x4UConvertI16x8Low:
1880 4 : return MarkAsSimd128(node), VisitI32x4UConvertI16x8Low(node);
1881 : case IrOpcode::kI32x4UConvertI16x8High:
1882 4 : return MarkAsSimd128(node), VisitI32x4UConvertI16x8High(node);
1883 : case IrOpcode::kI32x4ShrU:
1884 124 : return MarkAsSimd128(node), VisitI32x4ShrU(node);
1885 : case IrOpcode::kI32x4MinU:
1886 4 : return MarkAsSimd128(node), VisitI32x4MinU(node);
1887 : case IrOpcode::kI32x4MaxU:
1888 4 : return MarkAsSimd128(node), VisitI32x4MaxU(node);
1889 : case IrOpcode::kI32x4GtU:
1890 8 : return MarkAsSimd128(node), VisitI32x4GtU(node);
1891 : case IrOpcode::kI32x4GeU:
1892 8 : return MarkAsSimd128(node), VisitI32x4GeU(node);
1893 : case IrOpcode::kI16x8Splat:
1894 404 : return MarkAsSimd128(node), VisitI16x8Splat(node);
1895 : case IrOpcode::kI16x8ExtractLane:
1896 32 : return MarkAsWord32(node), VisitI16x8ExtractLane(node);
1897 : case IrOpcode::kI16x8ReplaceLane:
1898 52 : return MarkAsSimd128(node), VisitI16x8ReplaceLane(node);
1899 : case IrOpcode::kI16x8SConvertI8x16Low:
1900 4 : return MarkAsSimd128(node), VisitI16x8SConvertI8x16Low(node);
1901 : case IrOpcode::kI16x8SConvertI8x16High:
1902 4 : return MarkAsSimd128(node), VisitI16x8SConvertI8x16High(node);
1903 : case IrOpcode::kI16x8Neg:
1904 4 : return MarkAsSimd128(node), VisitI16x8Neg(node);
1905 : case IrOpcode::kI16x8Shl:
1906 60 : return MarkAsSimd128(node), VisitI16x8Shl(node);
1907 : case IrOpcode::kI16x8ShrS:
1908 60 : return MarkAsSimd128(node), VisitI16x8ShrS(node);
1909 : case IrOpcode::kI16x8SConvertI32x4:
1910 4 : return MarkAsSimd128(node), VisitI16x8SConvertI32x4(node);
1911 : case IrOpcode::kI16x8Add:
1912 4 : return MarkAsSimd128(node), VisitI16x8Add(node);
1913 : case IrOpcode::kI16x8AddSaturateS:
1914 4 : return MarkAsSimd128(node), VisitI16x8AddSaturateS(node);
1915 : case IrOpcode::kI16x8AddHoriz:
1916 4 : return MarkAsSimd128(node), VisitI16x8AddHoriz(node);
1917 : case IrOpcode::kI16x8Sub:
1918 4 : return MarkAsSimd128(node), VisitI16x8Sub(node);
1919 : case IrOpcode::kI16x8SubSaturateS:
1920 4 : return MarkAsSimd128(node), VisitI16x8SubSaturateS(node);
1921 : case IrOpcode::kI16x8Mul:
1922 4 : return MarkAsSimd128(node), VisitI16x8Mul(node);
1923 : case IrOpcode::kI16x8MinS:
1924 4 : return MarkAsSimd128(node), VisitI16x8MinS(node);
1925 : case IrOpcode::kI16x8MaxS:
1926 4 : return MarkAsSimd128(node), VisitI16x8MaxS(node);
1927 : case IrOpcode::kI16x8Eq:
1928 12 : return MarkAsSimd128(node), VisitI16x8Eq(node);
1929 : case IrOpcode::kI16x8Ne:
1930 16 : return MarkAsSimd128(node), VisitI16x8Ne(node);
1931 : case IrOpcode::kI16x8GtS:
1932 8 : return MarkAsSimd128(node), VisitI16x8GtS(node);
1933 : case IrOpcode::kI16x8GeS:
1934 8 : return MarkAsSimd128(node), VisitI16x8GeS(node);
1935 : case IrOpcode::kI16x8UConvertI8x16Low:
1936 4 : return MarkAsSimd128(node), VisitI16x8UConvertI8x16Low(node);
1937 : case IrOpcode::kI16x8UConvertI8x16High:
1938 4 : return MarkAsSimd128(node), VisitI16x8UConvertI8x16High(node);
1939 : case IrOpcode::kI16x8ShrU:
1940 60 : return MarkAsSimd128(node), VisitI16x8ShrU(node);
1941 : case IrOpcode::kI16x8UConvertI32x4:
1942 4 : return MarkAsSimd128(node), VisitI16x8UConvertI32x4(node);
1943 : case IrOpcode::kI16x8AddSaturateU:
1944 4 : return MarkAsSimd128(node), VisitI16x8AddSaturateU(node);
1945 : case IrOpcode::kI16x8SubSaturateU:
1946 4 : return MarkAsSimd128(node), VisitI16x8SubSaturateU(node);
1947 : case IrOpcode::kI16x8MinU:
1948 4 : return MarkAsSimd128(node), VisitI16x8MinU(node);
1949 : case IrOpcode::kI16x8MaxU:
1950 4 : return MarkAsSimd128(node), VisitI16x8MaxU(node);
1951 : case IrOpcode::kI16x8GtU:
1952 8 : return MarkAsSimd128(node), VisitI16x8GtU(node);
1953 : case IrOpcode::kI16x8GeU:
1954 8 : return MarkAsSimd128(node), VisitI16x8GeU(node);
1955 : case IrOpcode::kI8x16Splat:
1956 304 : return MarkAsSimd128(node), VisitI8x16Splat(node);
1957 : case IrOpcode::kI8x16ExtractLane:
1958 32 : return MarkAsWord32(node), VisitI8x16ExtractLane(node);
1959 : case IrOpcode::kI8x16ReplaceLane:
1960 84 : return MarkAsSimd128(node), VisitI8x16ReplaceLane(node);
1961 : case IrOpcode::kI8x16Neg:
1962 4 : return MarkAsSimd128(node), VisitI8x16Neg(node);
1963 : case IrOpcode::kI8x16Shl:
1964 28 : return MarkAsSimd128(node), VisitI8x16Shl(node);
1965 : case IrOpcode::kI8x16ShrS:
1966 28 : return MarkAsSimd128(node), VisitI8x16ShrS(node);
1967 : case IrOpcode::kI8x16SConvertI16x8:
1968 4 : return MarkAsSimd128(node), VisitI8x16SConvertI16x8(node);
1969 : case IrOpcode::kI8x16Add:
1970 4 : return MarkAsSimd128(node), VisitI8x16Add(node);
1971 : case IrOpcode::kI8x16AddSaturateS:
1972 4 : return MarkAsSimd128(node), VisitI8x16AddSaturateS(node);
1973 : case IrOpcode::kI8x16Sub:
1974 4 : return MarkAsSimd128(node), VisitI8x16Sub(node);
1975 : case IrOpcode::kI8x16SubSaturateS:
1976 4 : return MarkAsSimd128(node), VisitI8x16SubSaturateS(node);
1977 : case IrOpcode::kI8x16Mul:
1978 4 : return MarkAsSimd128(node), VisitI8x16Mul(node);
1979 : case IrOpcode::kI8x16MinS:
1980 4 : return MarkAsSimd128(node), VisitI8x16MinS(node);
1981 : case IrOpcode::kI8x16MaxS:
1982 4 : return MarkAsSimd128(node), VisitI8x16MaxS(node);
1983 : case IrOpcode::kI8x16Eq:
1984 12 : return MarkAsSimd128(node), VisitI8x16Eq(node);
1985 : case IrOpcode::kI8x16Ne:
1986 16 : return MarkAsSimd128(node), VisitI8x16Ne(node);
1987 : case IrOpcode::kI8x16GtS:
1988 8 : return MarkAsSimd128(node), VisitI8x16GtS(node);
1989 : case IrOpcode::kI8x16GeS:
1990 8 : return MarkAsSimd128(node), VisitI8x16GeS(node);
1991 : case IrOpcode::kI8x16ShrU:
1992 28 : return MarkAsSimd128(node), VisitI8x16ShrU(node);
1993 : case IrOpcode::kI8x16UConvertI16x8:
1994 4 : return MarkAsSimd128(node), VisitI8x16UConvertI16x8(node);
1995 : case IrOpcode::kI8x16AddSaturateU:
1996 4 : return MarkAsSimd128(node), VisitI8x16AddSaturateU(node);
1997 : case IrOpcode::kI8x16SubSaturateU:
1998 4 : return MarkAsSimd128(node), VisitI8x16SubSaturateU(node);
1999 : case IrOpcode::kI8x16MinU:
2000 4 : return MarkAsSimd128(node), VisitI8x16MinU(node);
2001 : case IrOpcode::kI8x16MaxU:
2002 4 : return MarkAsSimd128(node), VisitI8x16MaxU(node);
2003 : case IrOpcode::kI8x16GtU:
2004 8 : return MarkAsSimd128(node), VisitI8x16GtU(node);
2005 : case IrOpcode::kI8x16GeU:
2006 8 : return MarkAsSimd128(node), VisitI16x8GeU(node);
2007 : case IrOpcode::kS128Zero:
2008 16 : return MarkAsSimd128(node), VisitS128Zero(node);
2009 : case IrOpcode::kS128And:
2010 4 : return MarkAsSimd128(node), VisitS128And(node);
2011 : case IrOpcode::kS128Or:
2012 4 : return MarkAsSimd128(node), VisitS128Or(node);
2013 : case IrOpcode::kS128Xor:
2014 4 : return MarkAsSimd128(node), VisitS128Xor(node);
2015 : case IrOpcode::kS128Not:
2016 4 : return MarkAsSimd128(node), VisitS128Not(node);
2017 : case IrOpcode::kS128Select:
2018 28 : return MarkAsSimd128(node), VisitS128Select(node);
2019 : case IrOpcode::kS8x16Shuffle:
2020 5084 : return MarkAsSimd128(node), VisitS8x16Shuffle(node);
2021 : case IrOpcode::kS1x4AnyTrue:
2022 20 : return MarkAsWord32(node), VisitS1x4AnyTrue(node);
2023 : case IrOpcode::kS1x4AllTrue:
2024 20 : return MarkAsWord32(node), VisitS1x4AllTrue(node);
2025 : case IrOpcode::kS1x8AnyTrue:
2026 20 : return MarkAsWord32(node), VisitS1x8AnyTrue(node);
2027 : case IrOpcode::kS1x8AllTrue:
2028 20 : return MarkAsWord32(node), VisitS1x8AllTrue(node);
2029 : case IrOpcode::kS1x16AnyTrue:
2030 20 : return MarkAsWord32(node), VisitS1x16AnyTrue(node);
2031 : case IrOpcode::kS1x16AllTrue:
2032 20 : return MarkAsWord32(node), VisitS1x16AllTrue(node);
2033 : default:
2034 0 : FATAL("Unexpected operator #%d:%s @ node #%d", node->opcode(),
2035 0 : node->op()->mnemonic(), node->id());
2036 : break;
2037 : }
2038 : }
2039 :
2040 0 : void InstructionSelector::EmitWordPoisonOnSpeculation(Node* node) {
2041 0 : if (poisoning_level_ != PoisoningMitigationLevel::kDontPoison) {
2042 : OperandGenerator g(this);
2043 0 : Node* input_node = NodeProperties::GetValueInput(node, 0);
2044 0 : InstructionOperand input = g.UseRegister(input_node);
2045 0 : InstructionOperand output = g.DefineSameAsFirst(node);
2046 : Emit(kArchWordPoisonOnSpeculation, output, input);
2047 : } else {
2048 0 : EmitIdentity(node);
2049 : }
2050 0 : }
2051 :
2052 0 : void InstructionSelector::VisitWord32PoisonOnSpeculation(Node* node) {
2053 0 : EmitWordPoisonOnSpeculation(node);
2054 0 : }
2055 :
2056 0 : void InstructionSelector::VisitWord64PoisonOnSpeculation(Node* node) {
2057 0 : EmitWordPoisonOnSpeculation(node);
2058 0 : }
2059 :
2060 0 : void InstructionSelector::VisitTaggedPoisonOnSpeculation(Node* node) {
2061 0 : EmitWordPoisonOnSpeculation(node);
2062 0 : }
2063 :
2064 1 : void InstructionSelector::VisitLoadStackPointer(Node* node) {
2065 : OperandGenerator g(this);
2066 1 : Emit(kArchStackPointer, g.DefineAsRegister(node));
2067 1 : }
2068 :
2069 32660 : void InstructionSelector::VisitLoadFramePointer(Node* node) {
2070 : OperandGenerator g(this);
2071 32660 : Emit(kArchFramePointer, g.DefineAsRegister(node));
2072 32660 : }
2073 :
2074 50404 : void InstructionSelector::VisitLoadParentFramePointer(Node* node) {
2075 : OperandGenerator g(this);
2076 50404 : Emit(kArchParentFramePointer, g.DefineAsRegister(node));
2077 50404 : }
2078 :
2079 0 : void InstructionSelector::VisitFloat64Acos(Node* node) {
2080 116 : VisitFloat64Ieee754Unop(node, kIeee754Float64Acos);
2081 0 : }
2082 :
2083 0 : void InstructionSelector::VisitFloat64Acosh(Node* node) {
2084 116 : VisitFloat64Ieee754Unop(node, kIeee754Float64Acosh);
2085 0 : }
2086 :
2087 0 : void InstructionSelector::VisitFloat64Asin(Node* node) {
2088 116 : VisitFloat64Ieee754Unop(node, kIeee754Float64Asin);
2089 0 : }
2090 :
2091 0 : void InstructionSelector::VisitFloat64Asinh(Node* node) {
2092 116 : VisitFloat64Ieee754Unop(node, kIeee754Float64Asinh);
2093 0 : }
2094 :
2095 0 : void InstructionSelector::VisitFloat64Atan(Node* node) {
2096 133 : VisitFloat64Ieee754Unop(node, kIeee754Float64Atan);
2097 0 : }
2098 :
2099 0 : void InstructionSelector::VisitFloat64Atanh(Node* node) {
2100 116 : VisitFloat64Ieee754Unop(node, kIeee754Float64Atanh);
2101 0 : }
2102 :
2103 0 : void InstructionSelector::VisitFloat64Atan2(Node* node) {
2104 129 : VisitFloat64Ieee754Binop(node, kIeee754Float64Atan2);
2105 0 : }
2106 :
2107 0 : void InstructionSelector::VisitFloat64Cbrt(Node* node) {
2108 116 : VisitFloat64Ieee754Unop(node, kIeee754Float64Cbrt);
2109 0 : }
2110 :
2111 0 : void InstructionSelector::VisitFloat64Cos(Node* node) {
2112 271 : VisitFloat64Ieee754Unop(node, kIeee754Float64Cos);
2113 0 : }
2114 :
2115 0 : void InstructionSelector::VisitFloat64Cosh(Node* node) {
2116 123 : VisitFloat64Ieee754Unop(node, kIeee754Float64Cosh);
2117 0 : }
2118 :
2119 0 : void InstructionSelector::VisitFloat64Exp(Node* node) {
2120 148 : VisitFloat64Ieee754Unop(node, kIeee754Float64Exp);
2121 0 : }
2122 :
2123 0 : void InstructionSelector::VisitFloat64Expm1(Node* node) {
2124 123 : VisitFloat64Ieee754Unop(node, kIeee754Float64Expm1);
2125 0 : }
2126 :
2127 0 : void InstructionSelector::VisitFloat64Log(Node* node) {
2128 284 : VisitFloat64Ieee754Unop(node, kIeee754Float64Log);
2129 0 : }
2130 :
2131 0 : void InstructionSelector::VisitFloat64Log1p(Node* node) {
2132 116 : VisitFloat64Ieee754Unop(node, kIeee754Float64Log1p);
2133 0 : }
2134 :
2135 0 : void InstructionSelector::VisitFloat64Log2(Node* node) {
2136 116 : VisitFloat64Ieee754Unop(node, kIeee754Float64Log2);
2137 0 : }
2138 :
2139 0 : void InstructionSelector::VisitFloat64Log10(Node* node) {
2140 116 : VisitFloat64Ieee754Unop(node, kIeee754Float64Log10);
2141 0 : }
2142 :
2143 0 : void InstructionSelector::VisitFloat64Pow(Node* node) {
2144 336 : VisitFloat64Ieee754Binop(node, kIeee754Float64Pow);
2145 0 : }
2146 :
2147 0 : void InstructionSelector::VisitFloat64Sin(Node* node) {
2148 268 : VisitFloat64Ieee754Unop(node, kIeee754Float64Sin);
2149 0 : }
2150 :
2151 0 : void InstructionSelector::VisitFloat64Sinh(Node* node) {
2152 123 : VisitFloat64Ieee754Unop(node, kIeee754Float64Sinh);
2153 0 : }
2154 :
2155 0 : void InstructionSelector::VisitFloat64Tan(Node* node) {
2156 168 : VisitFloat64Ieee754Unop(node, kIeee754Float64Tan);
2157 0 : }
2158 :
2159 0 : void InstructionSelector::VisitFloat64Tanh(Node* node) {
2160 123 : VisitFloat64Ieee754Unop(node, kIeee754Float64Tanh);
2161 0 : }
2162 :
2163 307 : void InstructionSelector::EmitTableSwitch(const SwitchInfo& sw,
2164 : InstructionOperand& index_operand) {
2165 : OperandGenerator g(this);
2166 307 : size_t input_count = 2 + sw.value_range();
2167 : DCHECK_LE(sw.value_range(), std::numeric_limits<size_t>::max() - 2);
2168 : auto* inputs = zone()->NewArray<InstructionOperand>(input_count);
2169 307 : inputs[0] = index_operand;
2170 : InstructionOperand default_operand = g.Label(sw.default_branch());
2171 307 : std::fill(&inputs[1], &inputs[input_count], default_operand);
2172 201325 : for (const CaseInfo& c : sw.CasesUnsorted()) {
2173 201018 : size_t value = c.value - sw.min_value();
2174 : DCHECK_LE(0u, value);
2175 : DCHECK_LT(value + 2, input_count);
2176 402036 : inputs[value + 2] = g.Label(c.branch);
2177 : }
2178 307 : Emit(kArchTableSwitch, 0, nullptr, input_count, inputs, 0, nullptr);
2179 307 : }
2180 :
2181 0 : void InstructionSelector::EmitLookupSwitch(const SwitchInfo& sw,
2182 : InstructionOperand& value_operand) {
2183 : OperandGenerator g(this);
2184 0 : std::vector<CaseInfo> cases = sw.CasesSortedByOriginalOrder();
2185 0 : size_t input_count = 2 + sw.case_count() * 2;
2186 : DCHECK_LE(sw.case_count(), (std::numeric_limits<size_t>::max() - 2) / 2);
2187 : auto* inputs = zone()->NewArray<InstructionOperand>(input_count);
2188 0 : inputs[0] = value_operand;
2189 0 : inputs[1] = g.Label(sw.default_branch());
2190 0 : for (size_t index = 0; index < cases.size(); ++index) {
2191 : const CaseInfo& c = cases[index];
2192 0 : inputs[index * 2 + 2 + 0] = g.TempImmediate(c.value);
2193 0 : inputs[index * 2 + 2 + 1] = g.Label(c.branch);
2194 : }
2195 0 : Emit(kArchLookupSwitch, 0, nullptr, input_count, inputs, 0, nullptr);
2196 0 : }
2197 :
2198 33870 : void InstructionSelector::EmitBinarySearchSwitch(
2199 : const SwitchInfo& sw, InstructionOperand& value_operand) {
2200 : OperandGenerator g(this);
2201 33870 : size_t input_count = 2 + sw.case_count() * 2;
2202 : DCHECK_LE(sw.case_count(), (std::numeric_limits<size_t>::max() - 2) / 2);
2203 : auto* inputs = zone()->NewArray<InstructionOperand>(input_count);
2204 33871 : inputs[0] = value_operand;
2205 33873 : inputs[1] = g.Label(sw.default_branch());
2206 33873 : std::vector<CaseInfo> cases = sw.CasesSortedByValue();
2207 : std::stable_sort(cases.begin(), cases.end(),
2208 : [](CaseInfo a, CaseInfo b) { return a.value < b.value; });
2209 410526 : for (size_t index = 0; index < cases.size(); ++index) {
2210 : const CaseInfo& c = cases[index];
2211 188327 : inputs[index * 2 + 2 + 0] = g.TempImmediate(c.value);
2212 376650 : inputs[index * 2 + 2 + 1] = g.Label(c.branch);
2213 : }
2214 33873 : Emit(kArchBinarySearchSwitch, 0, nullptr, input_count, inputs, 0, nullptr);
2215 33873 : }
2216 :
2217 0 : void InstructionSelector::VisitBitcastTaggedToWord(Node* node) {
2218 1507048 : EmitIdentity(node);
2219 0 : }
2220 :
2221 568010 : void InstructionSelector::VisitBitcastWordToTagged(Node* node) {
2222 : OperandGenerator g(this);
2223 568010 : Emit(kArchNop, g.DefineSameAsFirst(node), g.Use(node->InputAt(0)));
2224 568011 : }
2225 :
2226 : // 32 bit targets do not implement the following instructions.
2227 : #if V8_TARGET_ARCH_32_BIT
2228 :
2229 : void InstructionSelector::VisitWord64And(Node* node) { UNIMPLEMENTED(); }
2230 :
2231 : void InstructionSelector::VisitWord64Or(Node* node) { UNIMPLEMENTED(); }
2232 :
2233 : void InstructionSelector::VisitWord64Xor(Node* node) { UNIMPLEMENTED(); }
2234 :
2235 : void InstructionSelector::VisitWord64Shl(Node* node) { UNIMPLEMENTED(); }
2236 :
2237 : void InstructionSelector::VisitWord64Shr(Node* node) { UNIMPLEMENTED(); }
2238 :
2239 : void InstructionSelector::VisitWord64Sar(Node* node) { UNIMPLEMENTED(); }
2240 :
2241 : void InstructionSelector::VisitWord64Ror(Node* node) { UNIMPLEMENTED(); }
2242 :
2243 : void InstructionSelector::VisitWord64Clz(Node* node) { UNIMPLEMENTED(); }
2244 :
2245 : void InstructionSelector::VisitWord64Ctz(Node* node) { UNIMPLEMENTED(); }
2246 :
2247 : void InstructionSelector::VisitWord64ReverseBits(Node* node) {
2248 : UNIMPLEMENTED();
2249 : }
2250 :
2251 : void InstructionSelector::VisitWord64Popcnt(Node* node) { UNIMPLEMENTED(); }
2252 :
2253 : void InstructionSelector::VisitWord64Equal(Node* node) { UNIMPLEMENTED(); }
2254 :
2255 : void InstructionSelector::VisitInt64Add(Node* node) { UNIMPLEMENTED(); }
2256 :
2257 : void InstructionSelector::VisitInt64AddWithOverflow(Node* node) {
2258 : UNIMPLEMENTED();
2259 : }
2260 :
2261 : void InstructionSelector::VisitInt64Sub(Node* node) { UNIMPLEMENTED(); }
2262 :
2263 : void InstructionSelector::VisitInt64SubWithOverflow(Node* node) {
2264 : UNIMPLEMENTED();
2265 : }
2266 :
2267 : void InstructionSelector::VisitInt64Mul(Node* node) { UNIMPLEMENTED(); }
2268 :
2269 : void InstructionSelector::VisitInt64Div(Node* node) { UNIMPLEMENTED(); }
2270 :
2271 : void InstructionSelector::VisitInt64LessThan(Node* node) { UNIMPLEMENTED(); }
2272 :
2273 : void InstructionSelector::VisitInt64LessThanOrEqual(Node* node) {
2274 : UNIMPLEMENTED();
2275 : }
2276 :
2277 : void InstructionSelector::VisitUint64Div(Node* node) { UNIMPLEMENTED(); }
2278 :
2279 : void InstructionSelector::VisitInt64Mod(Node* node) { UNIMPLEMENTED(); }
2280 :
2281 : void InstructionSelector::VisitUint64LessThan(Node* node) { UNIMPLEMENTED(); }
2282 :
2283 : void InstructionSelector::VisitUint64LessThanOrEqual(Node* node) {
2284 : UNIMPLEMENTED();
2285 : }
2286 :
2287 : void InstructionSelector::VisitUint64Mod(Node* node) { UNIMPLEMENTED(); }
2288 :
2289 : void InstructionSelector::VisitChangeInt32ToInt64(Node* node) {
2290 : UNIMPLEMENTED();
2291 : }
2292 :
2293 : void InstructionSelector::VisitChangeInt64ToFloat64(Node* node) {
2294 : UNIMPLEMENTED();
2295 : }
2296 :
2297 : void InstructionSelector::VisitChangeUint32ToUint64(Node* node) {
2298 : UNIMPLEMENTED();
2299 : }
2300 :
2301 : void InstructionSelector::VisitChangeTaggedToCompressed(Node* node) {
2302 : UNIMPLEMENTED();
2303 : }
2304 :
2305 : void InstructionSelector::VisitChangeTaggedPointerToCompressedPointer(
2306 : Node* node) {
2307 : UNIMPLEMENTED();
2308 : }
2309 :
2310 : void InstructionSelector::VisitChangeTaggedSignedToCompressedSigned(
2311 : Node* node) {
2312 : UNIMPLEMENTED();
2313 : }
2314 :
2315 : void InstructionSelector::VisitChangeCompressedToTagged(Node* node) {
2316 : UNIMPLEMENTED();
2317 : }
2318 :
2319 : void InstructionSelector::VisitChangeCompressedPointerToTaggedPointer(
2320 : Node* node) {
2321 : UNIMPLEMENTED();
2322 : }
2323 :
2324 : void InstructionSelector::VisitChangeCompressedSignedToTaggedSigned(
2325 : Node* node) {
2326 : UNIMPLEMENTED();
2327 : }
2328 :
2329 : void InstructionSelector::VisitChangeFloat64ToInt64(Node* node) {
2330 : UNIMPLEMENTED();
2331 : }
2332 :
2333 : void InstructionSelector::VisitChangeFloat64ToUint64(Node* node) {
2334 : UNIMPLEMENTED();
2335 : }
2336 :
2337 : void InstructionSelector::VisitTruncateFloat64ToInt64(Node* node) {
2338 : UNIMPLEMENTED();
2339 : }
2340 :
2341 : void InstructionSelector::VisitTryTruncateFloat32ToInt64(Node* node) {
2342 : UNIMPLEMENTED();
2343 : }
2344 :
2345 : void InstructionSelector::VisitTryTruncateFloat64ToInt64(Node* node) {
2346 : UNIMPLEMENTED();
2347 : }
2348 :
2349 : void InstructionSelector::VisitTryTruncateFloat32ToUint64(Node* node) {
2350 : UNIMPLEMENTED();
2351 : }
2352 :
2353 : void InstructionSelector::VisitTryTruncateFloat64ToUint64(Node* node) {
2354 : UNIMPLEMENTED();
2355 : }
2356 :
2357 : void InstructionSelector::VisitTruncateInt64ToInt32(Node* node) {
2358 : UNIMPLEMENTED();
2359 : }
2360 :
2361 : void InstructionSelector::VisitRoundInt64ToFloat32(Node* node) {
2362 : UNIMPLEMENTED();
2363 : }
2364 :
2365 : void InstructionSelector::VisitRoundInt64ToFloat64(Node* node) {
2366 : UNIMPLEMENTED();
2367 : }
2368 :
2369 : void InstructionSelector::VisitRoundUint64ToFloat32(Node* node) {
2370 : UNIMPLEMENTED();
2371 : }
2372 :
2373 : void InstructionSelector::VisitRoundUint64ToFloat64(Node* node) {
2374 : UNIMPLEMENTED();
2375 : }
2376 :
2377 : void InstructionSelector::VisitBitcastFloat64ToInt64(Node* node) {
2378 : UNIMPLEMENTED();
2379 : }
2380 :
2381 : void InstructionSelector::VisitBitcastInt64ToFloat64(Node* node) {
2382 : UNIMPLEMENTED();
2383 : }
2384 :
2385 : void InstructionSelector::VisitSignExtendWord8ToInt64(Node* node) {
2386 : UNIMPLEMENTED();
2387 : }
2388 :
2389 : void InstructionSelector::VisitSignExtendWord16ToInt64(Node* node) {
2390 : UNIMPLEMENTED();
2391 : }
2392 :
2393 : void InstructionSelector::VisitSignExtendWord32ToInt64(Node* node) {
2394 : UNIMPLEMENTED();
2395 : }
2396 : #endif // V8_TARGET_ARCH_32_BIT
2397 :
2398 : // 64 bit targets do not implement the following instructions.
2399 : #if V8_TARGET_ARCH_64_BIT
2400 0 : void InstructionSelector::VisitInt32PairAdd(Node* node) { UNIMPLEMENTED(); }
2401 :
2402 0 : void InstructionSelector::VisitInt32PairSub(Node* node) { UNIMPLEMENTED(); }
2403 :
2404 0 : void InstructionSelector::VisitInt32PairMul(Node* node) { UNIMPLEMENTED(); }
2405 :
2406 0 : void InstructionSelector::VisitWord32PairShl(Node* node) { UNIMPLEMENTED(); }
2407 :
2408 0 : void InstructionSelector::VisitWord32PairShr(Node* node) { UNIMPLEMENTED(); }
2409 :
2410 0 : void InstructionSelector::VisitWord32PairSar(Node* node) { UNIMPLEMENTED(); }
2411 : #endif // V8_TARGET_ARCH_64_BIT
2412 :
2413 : #if !V8_TARGET_ARCH_IA32 && !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_MIPS
2414 0 : void InstructionSelector::VisitWord32AtomicPairLoad(Node* node) {
2415 0 : UNIMPLEMENTED();
2416 : }
2417 :
2418 0 : void InstructionSelector::VisitWord32AtomicPairStore(Node* node) {
2419 0 : UNIMPLEMENTED();
2420 : }
2421 :
2422 0 : void InstructionSelector::VisitWord32AtomicPairAdd(Node* node) {
2423 0 : UNIMPLEMENTED();
2424 : }
2425 :
2426 0 : void InstructionSelector::VisitWord32AtomicPairSub(Node* node) {
2427 0 : UNIMPLEMENTED();
2428 : }
2429 :
2430 0 : void InstructionSelector::VisitWord32AtomicPairAnd(Node* node) {
2431 0 : UNIMPLEMENTED();
2432 : }
2433 :
2434 0 : void InstructionSelector::VisitWord32AtomicPairOr(Node* node) {
2435 0 : UNIMPLEMENTED();
2436 : }
2437 :
2438 0 : void InstructionSelector::VisitWord32AtomicPairXor(Node* node) {
2439 0 : UNIMPLEMENTED();
2440 : }
2441 :
2442 0 : void InstructionSelector::VisitWord32AtomicPairExchange(Node* node) {
2443 0 : UNIMPLEMENTED();
2444 : }
2445 :
2446 0 : void InstructionSelector::VisitWord32AtomicPairCompareExchange(Node* node) {
2447 0 : UNIMPLEMENTED();
2448 : }
2449 : #endif // !V8_TARGET_ARCH_IA32 && !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_MIPS
2450 :
2451 : #if !V8_TARGET_ARCH_X64 && !V8_TARGET_ARCH_ARM64 && !V8_TARGET_ARCH_MIPS64 && \
2452 : !V8_TARGET_ARCH_S390 && !V8_TARGET_ARCH_PPC
2453 : void InstructionSelector::VisitWord64AtomicLoad(Node* node) { UNIMPLEMENTED(); }
2454 :
2455 : void InstructionSelector::VisitWord64AtomicStore(Node* node) {
2456 : UNIMPLEMENTED();
2457 : }
2458 :
2459 : void InstructionSelector::VisitWord64AtomicAdd(Node* node) { UNIMPLEMENTED(); }
2460 :
2461 : void InstructionSelector::VisitWord64AtomicSub(Node* node) { UNIMPLEMENTED(); }
2462 :
2463 : void InstructionSelector::VisitWord64AtomicAnd(Node* node) { UNIMPLEMENTED(); }
2464 :
2465 : void InstructionSelector::VisitWord64AtomicOr(Node* node) { UNIMPLEMENTED(); }
2466 :
2467 : void InstructionSelector::VisitWord64AtomicXor(Node* node) { UNIMPLEMENTED(); }
2468 :
2469 : void InstructionSelector::VisitWord64AtomicExchange(Node* node) {
2470 : UNIMPLEMENTED();
2471 : }
2472 :
2473 : void InstructionSelector::VisitWord64AtomicCompareExchange(Node* node) {
2474 : UNIMPLEMENTED();
2475 : }
2476 : #endif // !V8_TARGET_ARCH_X64 && !V8_TARGET_ARCH_ARM64 && !V8_TARGET_ARCH_PPC
2477 : // !V8_TARGET_ARCH_MIPS64 && !V8_TARGET_ARCH_S390
2478 :
2479 1 : void InstructionSelector::VisitFinishRegion(Node* node) { EmitIdentity(node); }
2480 :
2481 3583530 : void InstructionSelector::VisitParameter(Node* node) {
2482 : OperandGenerator g(this);
2483 3583530 : int index = ParameterIndexOf(node->op());
2484 : InstructionOperand op =
2485 3583698 : linkage()->ParameterHasSecondaryLocation(index)
2486 : ? g.DefineAsDualLocation(
2487 : node, linkage()->GetParameterLocation(index),
2488 441698 : linkage()->GetParameterSecondaryLocation(index))
2489 4025639 : : g.DefineAsLocation(node, linkage()->GetParameterLocation(index));
2490 :
2491 : Emit(kArchNop, op);
2492 3584149 : }
2493 :
2494 : namespace {
2495 : LinkageLocation ExceptionLocation() {
2496 : return LinkageLocation::ForRegister(kReturnRegister0.code(),
2497 : MachineType::IntPtr());
2498 : }
2499 : } // namespace
2500 :
2501 198365 : void InstructionSelector::VisitIfException(Node* node) {
2502 : OperandGenerator g(this);
2503 : DCHECK_EQ(IrOpcode::kCall, node->InputAt(1)->opcode());
2504 198365 : Emit(kArchNop, g.DefineAsLocation(node, ExceptionLocation()));
2505 198367 : }
2506 :
2507 21595 : void InstructionSelector::VisitOsrValue(Node* node) {
2508 : OperandGenerator g(this);
2509 21595 : int index = OsrValueIndexOf(node->op());
2510 21595 : Emit(kArchNop,
2511 : g.DefineAsLocation(node, linkage()->GetOsrValueLocation(index)));
2512 21595 : }
2513 :
2514 2161783 : void InstructionSelector::VisitPhi(Node* node) {
2515 : const int input_count = node->op()->ValueInputCount();
2516 : DCHECK_EQ(input_count, current_block_->PredecessorCount());
2517 : PhiInstruction* phi = new (instruction_zone())
2518 : PhiInstruction(instruction_zone(), GetVirtualRegister(node),
2519 4323582 : static_cast<size_t>(input_count));
2520 : sequence()
2521 2161786 : ->InstructionBlockAt(RpoNumber::FromInt(current_block_->rpo_number()))
2522 2161786 : ->AddPhi(phi);
2523 12594554 : for (int i = 0; i < input_count; ++i) {
2524 : Node* const input = node->InputAt(i);
2525 : MarkAsUsed(input);
2526 5216363 : phi->SetInput(static_cast<size_t>(i), GetVirtualRegister(input));
2527 : }
2528 2161812 : }
2529 :
2530 451351 : void InstructionSelector::VisitProjection(Node* node) {
2531 : OperandGenerator g(this);
2532 : Node* value = node->InputAt(0);
2533 451351 : switch (value->opcode()) {
2534 : case IrOpcode::kInt32AddWithOverflow:
2535 : case IrOpcode::kInt32SubWithOverflow:
2536 : case IrOpcode::kInt32MulWithOverflow:
2537 : case IrOpcode::kInt64AddWithOverflow:
2538 : case IrOpcode::kInt64SubWithOverflow:
2539 : case IrOpcode::kTryTruncateFloat32ToInt64:
2540 : case IrOpcode::kTryTruncateFloat64ToInt64:
2541 : case IrOpcode::kTryTruncateFloat32ToUint64:
2542 : case IrOpcode::kTryTruncateFloat64ToUint64:
2543 : case IrOpcode::kInt32PairAdd:
2544 : case IrOpcode::kInt32PairSub:
2545 : case IrOpcode::kInt32PairMul:
2546 : case IrOpcode::kWord32PairShl:
2547 : case IrOpcode::kWord32PairShr:
2548 : case IrOpcode::kWord32PairSar:
2549 : case IrOpcode::kInt32AbsWithOverflow:
2550 : case IrOpcode::kInt64AbsWithOverflow:
2551 436879 : if (ProjectionIndexOf(node->op()) == 0u) {
2552 340386 : Emit(kArchNop, g.DefineSameAsFirst(node), g.Use(value));
2553 : } else {
2554 : DCHECK_EQ(1u, ProjectionIndexOf(node->op()));
2555 : MarkAsUsed(value);
2556 : }
2557 : break;
2558 : default:
2559 : break;
2560 : }
2561 451353 : }
2562 :
2563 14062565 : void InstructionSelector::VisitConstant(Node* node) {
2564 : // We must emit a NOP here because every live range needs a defining
2565 : // instruction in the register allocator.
2566 : OperandGenerator g(this);
2567 14062565 : Emit(kArchNop, g.DefineAsConstant(node));
2568 14063915 : }
2569 :
2570 6161088 : void InstructionSelector::VisitCall(Node* node, BasicBlock* handler) {
2571 : OperandGenerator g(this);
2572 6161088 : auto call_descriptor = CallDescriptorOf(node->op());
2573 :
2574 : FrameStateDescriptor* frame_state_descriptor = nullptr;
2575 6161073 : if (call_descriptor->NeedsFrameState()) {
2576 3224786 : frame_state_descriptor = GetFrameStateDescriptor(
2577 3224786 : node->InputAt(static_cast<int>(call_descriptor->InputCount())));
2578 : }
2579 :
2580 6161071 : CallBuffer buffer(zone(), call_descriptor, frame_state_descriptor);
2581 : CallDescriptor::Flags flags = call_descriptor->flags();
2582 :
2583 : // Compute InstructionOperands for inputs and outputs.
2584 : // TODO(turbofan): on some architectures it's probably better to use
2585 : // the code object in a register if there are multiple uses of it.
2586 : // Improve constant pool and the heuristics in the register allocator
2587 : // for where to emit constants.
2588 : CallBufferFlags call_buffer_flags(kCallCodeImmediate | kCallAddressImmediate);
2589 6161157 : if (flags & CallDescriptor::kAllowCallThroughSlot) {
2590 : // TODO(v8:6666): Remove kAllowCallThroughSlot and use a pc-relative call
2591 : // instead once builtins are embedded in every build configuration.
2592 : call_buffer_flags |= kAllowCallThroughSlot;
2593 : #ifndef V8_TARGET_ARCH_32_BIT
2594 : // kAllowCallThroughSlot is only supported on ia32.
2595 0 : UNREACHABLE();
2596 : #endif
2597 : }
2598 6161157 : InitializeCallBuffer(node, &buffer, call_buffer_flags, false);
2599 :
2600 6161147 : EmitPrepareArguments(&(buffer.pushed_nodes), call_descriptor, node);
2601 :
2602 : // Pass label of exception handler block.
2603 6161076 : if (handler) {
2604 : DCHECK_EQ(IrOpcode::kIfException, handler->front()->opcode());
2605 : flags |= CallDescriptor::kHasExceptionHandler;
2606 439246 : buffer.instruction_args.push_back(g.Label(handler));
2607 : }
2608 :
2609 : // Select the appropriate opcode based on the call type.
2610 : InstructionCode opcode = kArchNop;
2611 6161076 : switch (call_descriptor->kind()) {
2612 : case CallDescriptor::kCallAddress:
2613 25620 : opcode = kArchCallCFunction | MiscField::encode(static_cast<int>(
2614 25620 : call_descriptor->ParameterCount()));
2615 25620 : break;
2616 : case CallDescriptor::kCallCodeObject:
2617 5138195 : opcode = kArchCallCodeObject | MiscField::encode(flags);
2618 5138195 : break;
2619 : case CallDescriptor::kCallJSFunction:
2620 23829 : opcode = kArchCallJSFunction | MiscField::encode(flags);
2621 23829 : break;
2622 : case CallDescriptor::kCallWasmFunction:
2623 : case CallDescriptor::kCallWasmImportWrapper:
2624 969845 : opcode = kArchCallWasmFunction | MiscField::encode(flags);
2625 969845 : break;
2626 : case CallDescriptor::kCallBuiltinPointer:
2627 3584 : opcode = kArchCallBuiltinPointer | MiscField::encode(flags);
2628 3584 : break;
2629 : }
2630 :
2631 : // Emit the call instruction.
2632 : size_t const output_count = buffer.outputs.size();
2633 6161076 : auto* outputs = output_count ? &buffer.outputs.front() : nullptr;
2634 : Instruction* call_instr =
2635 : Emit(opcode, output_count, outputs, buffer.instruction_args.size(),
2636 6161076 : &buffer.instruction_args.front());
2637 6161147 : if (instruction_selection_failed()) return;
2638 : call_instr->MarkAsCall();
2639 :
2640 6161146 : EmitPrepareResults(&(buffer.output_nodes), call_descriptor, node);
2641 : }
2642 :
2643 676 : void InstructionSelector::VisitCallWithCallerSavedRegisters(
2644 : Node* node, BasicBlock* handler) {
2645 : OperandGenerator g(this);
2646 676 : const auto fp_mode = CallDescriptorOf(node->op())->get_save_fp_mode();
2647 676 : Emit(kArchSaveCallerRegisters | MiscField::encode(static_cast<int>(fp_mode)),
2648 : g.NoOutput());
2649 676 : VisitCall(node, handler);
2650 676 : Emit(kArchRestoreCallerRegisters |
2651 : MiscField::encode(static_cast<int>(fp_mode)),
2652 : g.NoOutput());
2653 676 : }
2654 :
2655 119688 : void InstructionSelector::VisitTailCall(Node* node) {
2656 : OperandGenerator g(this);
2657 119688 : auto call_descriptor = CallDescriptorOf(node->op());
2658 :
2659 : CallDescriptor* caller = linkage()->GetIncomingDescriptor();
2660 : DCHECK(caller->CanTailCall(node));
2661 119688 : const CallDescriptor* callee = CallDescriptorOf(node->op());
2662 119688 : int stack_param_delta = callee->GetStackParameterDelta(caller);
2663 119688 : CallBuffer buffer(zone(), call_descriptor, nullptr);
2664 :
2665 : // Compute InstructionOperands for inputs and outputs.
2666 : CallBufferFlags flags(kCallCodeImmediate | kCallTail);
2667 119688 : if (IsTailCallAddressImmediate()) {
2668 : flags |= kCallAddressImmediate;
2669 : }
2670 119688 : if (callee->flags() & CallDescriptor::kFixedTargetRegister) {
2671 : flags |= kCallFixedTargetRegister;
2672 : }
2673 : DCHECK_EQ(callee->flags() & CallDescriptor::kAllowCallThroughSlot, 0);
2674 119688 : InitializeCallBuffer(node, &buffer, flags, true, stack_param_delta);
2675 :
2676 : // Select the appropriate opcode based on the call type.
2677 : InstructionCode opcode;
2678 : InstructionOperandVector temps(zone());
2679 119688 : if (linkage()->GetIncomingDescriptor()->IsJSFunctionCall()) {
2680 1120 : switch (call_descriptor->kind()) {
2681 : case CallDescriptor::kCallCodeObject:
2682 : opcode = kArchTailCallCodeObjectFromJSFunction;
2683 : break;
2684 : default:
2685 0 : UNREACHABLE();
2686 : return;
2687 : }
2688 1120 : int temps_count = GetTempsCountForTailCallFromJSFunction();
2689 7840 : for (int i = 0; i < temps_count; i++) {
2690 6720 : temps.push_back(g.TempRegister());
2691 : }
2692 : } else {
2693 118568 : switch (call_descriptor->kind()) {
2694 : case CallDescriptor::kCallCodeObject:
2695 : opcode = kArchTailCallCodeObject;
2696 : break;
2697 : case CallDescriptor::kCallAddress:
2698 : opcode = kArchTailCallAddress;
2699 82768 : break;
2700 : case CallDescriptor::kCallWasmFunction:
2701 : opcode = kArchTailCallWasm;
2702 248 : break;
2703 : default:
2704 0 : UNREACHABLE();
2705 : return;
2706 : }
2707 : }
2708 119688 : opcode |= MiscField::encode(call_descriptor->flags());
2709 :
2710 : Emit(kArchPrepareTailCall, g.NoOutput());
2711 :
2712 : // Add an immediate operand that represents the first slot that is unused
2713 : // with respect to the stack pointer that has been updated for the tail call
2714 : // instruction. This is used by backends that need to pad arguments for stack
2715 : // alignment, in order to store an optional slot of padding above the
2716 : // arguments.
2717 119688 : int optional_padding_slot = callee->GetFirstUnusedStackSlot();
2718 239376 : buffer.instruction_args.push_back(g.TempImmediate(optional_padding_slot));
2719 :
2720 : int first_unused_stack_slot =
2721 : (V8_TARGET_ARCH_STORES_RETURN_ADDRESS_ON_STACK ? true : false) +
2722 119688 : stack_param_delta;
2723 239376 : buffer.instruction_args.push_back(g.TempImmediate(first_unused_stack_slot));
2724 :
2725 : // Emit the tailcall instruction.
2726 119688 : Emit(opcode, 0, nullptr, buffer.instruction_args.size(),
2727 : &buffer.instruction_args.front(), temps.size(),
2728 119688 : temps.empty() ? nullptr : &temps.front());
2729 119688 : }
2730 :
2731 9164287 : void InstructionSelector::VisitGoto(BasicBlock* target) {
2732 : // jump to the next block.
2733 : OperandGenerator g(this);
2734 : Emit(kArchJmp, g.NoOutput(), g.Label(target));
2735 9164278 : }
2736 :
2737 2786846 : void InstructionSelector::VisitReturn(Node* ret) {
2738 : OperandGenerator g(this);
2739 : const int input_count = linkage()->GetIncomingDescriptor()->ReturnCount() == 0
2740 : ? 1
2741 2786846 : : ret->op()->ValueInputCount();
2742 : DCHECK_GE(input_count, 1);
2743 2786846 : auto value_locations = zone()->NewArray<InstructionOperand>(input_count);
2744 : Node* pop_count = ret->InputAt(0);
2745 39784 : value_locations[0] = (pop_count->opcode() == IrOpcode::kInt32Constant ||
2746 : pop_count->opcode() == IrOpcode::kInt64Constant)
2747 : ? g.UseImmediate(pop_count)
2748 5535212 : : g.UseRegister(pop_count);
2749 8335584 : for (int i = 1; i < input_count; ++i) {
2750 : value_locations[i] =
2751 5548136 : g.UseLocation(ret->InputAt(i), linkage()->GetReturnLocation(i - 1));
2752 : }
2753 2788092 : Emit(kArchRet, 0, nullptr, input_count, value_locations);
2754 2788472 : }
2755 :
2756 5409228 : void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch,
2757 : BasicBlock* fbranch) {
2758 5409228 : if (NeedsPoisoning(IsSafetyCheckOf(branch->op()))) {
2759 : FlagsContinuation cont =
2760 : FlagsContinuation::ForBranchAndPoison(kNotEqual, tbranch, fbranch);
2761 0 : VisitWordCompareZero(branch, branch->InputAt(0), &cont);
2762 : } else {
2763 : FlagsContinuation cont =
2764 : FlagsContinuation::ForBranch(kNotEqual, tbranch, fbranch);
2765 5409172 : VisitWordCompareZero(branch, branch->InputAt(0), &cont);
2766 : }
2767 5409230 : }
2768 :
2769 112056 : void InstructionSelector::VisitDeoptimizeIf(Node* node) {
2770 112056 : DeoptimizeParameters p = DeoptimizeParametersOf(node->op());
2771 112057 : if (NeedsPoisoning(p.is_safety_check())) {
2772 : FlagsContinuation cont = FlagsContinuation::ForDeoptimizeAndPoison(
2773 : kNotEqual, p.kind(), p.reason(), p.feedback(), node->InputAt(1));
2774 0 : VisitWordCompareZero(node, node->InputAt(0), &cont);
2775 : } else {
2776 : FlagsContinuation cont = FlagsContinuation::ForDeoptimize(
2777 : kNotEqual, p.kind(), p.reason(), p.feedback(), node->InputAt(1));
2778 112057 : VisitWordCompareZero(node, node->InputAt(0), &cont);
2779 : }
2780 112056 : }
2781 :
2782 219957 : void InstructionSelector::VisitDeoptimizeUnless(Node* node) {
2783 219957 : DeoptimizeParameters p = DeoptimizeParametersOf(node->op());
2784 219957 : if (NeedsPoisoning(p.is_safety_check())) {
2785 : FlagsContinuation cont = FlagsContinuation::ForDeoptimizeAndPoison(
2786 : kEqual, p.kind(), p.reason(), p.feedback(), node->InputAt(1));
2787 0 : VisitWordCompareZero(node, node->InputAt(0), &cont);
2788 : } else {
2789 : FlagsContinuation cont = FlagsContinuation::ForDeoptimize(
2790 : kEqual, p.kind(), p.reason(), p.feedback(), node->InputAt(1));
2791 219957 : VisitWordCompareZero(node, node->InputAt(0), &cont);
2792 : }
2793 219957 : }
2794 :
2795 5829 : void InstructionSelector::VisitTrapIf(Node* node, TrapId trap_id) {
2796 : FlagsContinuation cont =
2797 : FlagsContinuation::ForTrap(kNotEqual, trap_id, node->InputAt(1));
2798 5833 : VisitWordCompareZero(node, node->InputAt(0), &cont);
2799 5839 : }
2800 :
2801 28729 : void InstructionSelector::VisitTrapUnless(Node* node, TrapId trap_id) {
2802 : FlagsContinuation cont =
2803 : FlagsContinuation::ForTrap(kEqual, trap_id, node->InputAt(1));
2804 28733 : VisitWordCompareZero(node, node->InputAt(0), &cont);
2805 28728 : }
2806 :
2807 2578949 : void InstructionSelector::EmitIdentity(Node* node) {
2808 : OperandGenerator g(this);
2809 : MarkAsUsed(node->InputAt(0));
2810 2578949 : SetRename(node, node->InputAt(0));
2811 2578948 : }
2812 :
2813 0 : void InstructionSelector::VisitDeoptimize(DeoptimizeKind kind,
2814 : DeoptimizeReason reason,
2815 : VectorSlotPair const& feedback,
2816 : Node* value) {
2817 : EmitDeoptimize(kArchDeoptimize, 0, nullptr, 0, nullptr, kind, reason,
2818 43684 : feedback, value);
2819 0 : }
2820 :
2821 0 : void InstructionSelector::VisitThrow(Node* node) {
2822 : OperandGenerator g(this);
2823 : Emit(kArchThrowTerminator, g.NoOutput());
2824 0 : }
2825 :
2826 0 : void InstructionSelector::VisitDebugBreak(Node* node) {
2827 : OperandGenerator g(this);
2828 : Emit(kArchDebugBreak, g.NoOutput());
2829 0 : }
2830 :
2831 0 : void InstructionSelector::VisitUnreachable(Node* node) {
2832 : OperandGenerator g(this);
2833 : Emit(kArchDebugBreak, g.NoOutput());
2834 0 : }
2835 :
2836 0 : void InstructionSelector::VisitDeadValue(Node* node) {
2837 : OperandGenerator g(this);
2838 0 : MarkAsRepresentation(DeadValueRepresentationOf(node->op()), node);
2839 0 : Emit(kArchDebugBreak, g.DefineAsConstant(node));
2840 0 : }
2841 :
2842 4 : void InstructionSelector::VisitComment(Node* node) {
2843 : OperandGenerator g(this);
2844 4 : InstructionOperand operand(g.UseImmediate(node));
2845 4 : Emit(kArchComment, 0, nullptr, 1, &operand);
2846 4 : }
2847 :
2848 0 : void InstructionSelector::VisitUnsafePointerAdd(Node* node) {
2849 : #if V8_TARGET_ARCH_64_BIT
2850 6823 : VisitInt64Add(node);
2851 : #else // V8_TARGET_ARCH_64_BIT
2852 : VisitInt32Add(node);
2853 : #endif // V8_TARGET_ARCH_64_BIT
2854 0 : }
2855 :
2856 9383 : void InstructionSelector::VisitRetain(Node* node) {
2857 : OperandGenerator g(this);
2858 9383 : Emit(kArchNop, g.NoOutput(), g.UseAny(node->InputAt(0)));
2859 9383 : }
2860 :
2861 0 : bool InstructionSelector::CanProduceSignalingNaN(Node* node) {
2862 : // TODO(jarin) Improve the heuristic here.
2863 12309 : if (node->opcode() == IrOpcode::kFloat64Add ||
2864 12309 : node->opcode() == IrOpcode::kFloat64Sub ||
2865 : node->opcode() == IrOpcode::kFloat64Mul) {
2866 : return false;
2867 : }
2868 0 : return true;
2869 : }
2870 :
2871 3955867 : FrameStateDescriptor* InstructionSelector::GetFrameStateDescriptor(
2872 : Node* state) {
2873 : DCHECK_EQ(IrOpcode::kFrameState, state->opcode());
2874 : DCHECK_EQ(kFrameStateInputCount, state->InputCount());
2875 3955867 : FrameStateInfo state_info = FrameStateInfoOf(state->op());
2876 :
2877 : int parameters = static_cast<int>(
2878 3955869 : StateValuesAccess(state->InputAt(kFrameStateParametersInput)).size());
2879 : int locals = static_cast<int>(
2880 3955878 : StateValuesAccess(state->InputAt(kFrameStateLocalsInput)).size());
2881 : int stack = static_cast<int>(
2882 3955868 : StateValuesAccess(state->InputAt(kFrameStateStackInput)).size());
2883 :
2884 : DCHECK_EQ(parameters, state_info.parameter_count());
2885 : DCHECK_EQ(locals, state_info.local_count());
2886 :
2887 : FrameStateDescriptor* outer_state = nullptr;
2888 : Node* outer_node = state->InputAt(kFrameStateOuterStateInput);
2889 3955887 : if (outer_node->opcode() == IrOpcode::kFrameState) {
2890 355389 : outer_state = GetFrameStateDescriptor(outer_node);
2891 : }
2892 :
2893 : return new (instruction_zone()) FrameStateDescriptor(
2894 7911771 : instruction_zone(), state_info.type(), state_info.bailout_id(),
2895 7911771 : state_info.state_combine(), parameters, locals, stack,
2896 11867666 : state_info.shared_info(), outer_state);
2897 : }
2898 :
2899 : // static
2900 5092 : void InstructionSelector::CanonicalizeShuffle(bool inputs_equal,
2901 : uint8_t* shuffle,
2902 : bool* needs_swap,
2903 : bool* is_swizzle) {
2904 5092 : *needs_swap = false;
2905 : // Inputs equal, then it's a swizzle.
2906 5092 : if (inputs_equal) {
2907 4 : *is_swizzle = true;
2908 : } else {
2909 : // Inputs are distinct; check that both are required.
2910 : bool src0_is_used = false;
2911 : bool src1_is_used = false;
2912 167904 : for (int i = 0; i < kSimd128Size; ++i) {
2913 81408 : if (shuffle[i] < kSimd128Size) {
2914 : src0_is_used = true;
2915 : } else {
2916 : src1_is_used = true;
2917 : }
2918 : }
2919 5088 : if (src0_is_used && !src1_is_used) {
2920 1305 : *is_swizzle = true;
2921 3783 : } else if (src1_is_used && !src0_is_used) {
2922 1185 : *needs_swap = true;
2923 1185 : *is_swizzle = true;
2924 : } else {
2925 2598 : *is_swizzle = false;
2926 : // Canonicalize general 2 input shuffles so that the first input lanes are
2927 : // encountered first. This makes architectural shuffle pattern matching
2928 : // easier, since we only need to consider 1 input ordering instead of 2.
2929 2598 : if (shuffle[0] >= kSimd128Size) {
2930 : // The second operand is used first. Swap inputs and adjust the shuffle.
2931 505 : *needs_swap = true;
2932 16665 : for (int i = 0; i < kSimd128Size; ++i) {
2933 8080 : shuffle[i] ^= kSimd128Size;
2934 : }
2935 : }
2936 : }
2937 : }
2938 5092 : if (*is_swizzle) {
2939 42398 : for (int i = 0; i < kSimd128Size; ++i) shuffle[i] &= kSimd128Size - 1;
2940 : }
2941 5092 : }
2942 :
2943 5084 : void InstructionSelector::CanonicalizeShuffle(Node* node, uint8_t* shuffle,
2944 : bool* is_swizzle) {
2945 : // Get raw shuffle indices.
2946 5084 : memcpy(shuffle, OpParameter<uint8_t*>(node->op()), kSimd128Size);
2947 : bool needs_swap;
2948 5084 : bool inputs_equal = GetVirtualRegister(node->InputAt(0)) ==
2949 5084 : GetVirtualRegister(node->InputAt(1));
2950 5084 : CanonicalizeShuffle(inputs_equal, shuffle, &needs_swap, is_swizzle);
2951 5084 : if (needs_swap) {
2952 1688 : SwapShuffleInputs(node);
2953 : }
2954 : // Duplicate the first input; for some shuffles on some architectures, it's
2955 : // easiest to implement a swizzle as a shuffle so it might be used.
2956 5084 : if (*is_swizzle) {
2957 2488 : node->ReplaceInput(1, node->InputAt(0));
2958 : }
2959 5084 : }
2960 :
2961 : // static
2962 1928 : void InstructionSelector::SwapShuffleInputs(Node* node) {
2963 : Node* input0 = node->InputAt(0);
2964 : Node* input1 = node->InputAt(1);
2965 1928 : node->ReplaceInput(0, input1);
2966 1928 : node->ReplaceInput(1, input0);
2967 1928 : }
2968 :
2969 : // static
2970 559 : bool InstructionSelector::TryMatchIdentity(const uint8_t* shuffle) {
2971 9805 : for (int i = 0; i < kSimd128Size; ++i) {
2972 4933 : if (shuffle[i] != i) return false;
2973 : }
2974 : return true;
2975 : }
2976 :
2977 : // static
2978 3387 : bool InstructionSelector::TryMatch32x4Shuffle(const uint8_t* shuffle,
2979 : uint8_t* shuffle32x4) {
2980 12371 : for (int i = 0; i < 4; ++i) {
2981 6838 : if (shuffle[i * 4] % 4 != 0) return false;
2982 33473 : for (int j = 1; j < 4; ++j) {
2983 14975 : if (shuffle[i * 4 + j] - shuffle[i * 4 + j - 1] != 1) return false;
2984 : }
2985 4492 : shuffle32x4[i] = shuffle[i * 4] / 4;
2986 : }
2987 : return true;
2988 : }
2989 :
2990 : // static
2991 2347 : bool InstructionSelector::TryMatch16x8Shuffle(const uint8_t* shuffle,
2992 : uint8_t* shuffle16x8) {
2993 20351 : for (int i = 0; i < 8; ++i) {
2994 10308 : if (shuffle[i * 2] % 2 != 0) return false;
2995 27631 : for (int j = 1; j < 2; ++j) {
2996 9627 : if (shuffle[i * 2 + j] - shuffle[i * 2 + j - 1] != 1) return false;
2997 : }
2998 9002 : shuffle16x8[i] = shuffle[i * 2] / 2;
2999 : }
3000 : return true;
3001 : }
3002 :
3003 : // static
3004 5088 : bool InstructionSelector::TryMatchConcat(const uint8_t* shuffle,
3005 : uint8_t* offset) {
3006 : // Don't match the identity shuffle (e.g. [0 1 2 ... 15]).
3007 5088 : uint8_t start = shuffle[0];
3008 5088 : if (start == 0) return false;
3009 : DCHECK_GT(kSimd128Size, start); // The shuffle should be canonicalized.
3010 : // A concatenation is a series of consecutive indices, with at most one jump
3011 : // in the middle from the last lane to the first.
3012 15359 : for (int i = 1; i < kSimd128Size; ++i) {
3013 8959 : if ((shuffle[i]) != ((shuffle[i - 1] + 1))) {
3014 2946 : if (shuffle[i - 1] != 15) return false;
3015 161 : if (shuffle[i] % kSimd128Size != 0) return false;
3016 : }
3017 : }
3018 242 : *offset = start;
3019 242 : return true;
3020 : }
3021 :
3022 : // static
3023 1527 : bool InstructionSelector::TryMatchBlend(const uint8_t* shuffle) {
3024 6999 : for (int i = 0; i < 16; ++i) {
3025 4205 : if ((shuffle[i] & 0xF) != i) return false;
3026 : }
3027 : return true;
3028 : }
3029 :
3030 : // static
3031 5584 : int32_t InstructionSelector::Pack4Lanes(const uint8_t* shuffle) {
3032 : int32_t result = 0;
3033 50256 : for (int i = 3; i >= 0; --i) {
3034 22336 : result <<= 8;
3035 22336 : result |= shuffle[i];
3036 : }
3037 5584 : return result;
3038 : }
3039 :
3040 5741182 : bool InstructionSelector::NeedsPoisoning(IsSafetyCheck safety_check) const {
3041 5741182 : switch (poisoning_level_) {
3042 : case PoisoningMitigationLevel::kDontPoison:
3043 : return false;
3044 : case PoisoningMitigationLevel::kPoisonAll:
3045 24 : return safety_check != IsSafetyCheck::kNoSafetyCheck;
3046 : case PoisoningMitigationLevel::kPoisonCriticalOnly:
3047 0 : return safety_check == IsSafetyCheck::kCriticalSafetyCheck;
3048 : }
3049 0 : UNREACHABLE();
3050 : }
3051 :
3052 : } // namespace compiler
3053 : } // namespace internal
3054 120216 : } // namespace v8
|