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 2949710 : InstructionSelector::InstructionSelector(
24 : Zone* zone, size_t node_count, Linkage* linkage,
25 8849282 : 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 8849434 : trace_turbo_(trace_turbo) {
58 2949862 : instructions_.reserve(node_count);
59 2949852 : continuation_inputs_.reserve(5);
60 2949853 : continuation_outputs_.reserve(2);
61 :
62 2949886 : if (trace_turbo_ == kEnableTraceTurboJson) {
63 4 : instr_origins_.assign(node_count, {-1, 0});
64 : }
65 2949886 : }
66 :
67 47073180 : bool InstructionSelector::SelectInstructions() {
68 : // Mark the inputs of all phis in loop headers as used.
69 : BasicBlockVector* blocks = schedule()->rpo_order();
70 26485391 : for (auto const block : *blocks) {
71 20585745 : if (!block->IsLoopHeader()) continue;
72 : DCHECK_LE(2u, block->PredecessorCount());
73 2527293 : for (Node* const phi : *block) {
74 2040493 : if (phi->opcode() != IrOpcode::kPhi) continue;
75 :
76 : // Mark all inputs as used.
77 1873722 : for (Node* const input : phi->inputs()) {
78 : MarkAsUsed(input);
79 : }
80 : }
81 : }
82 :
83 : // Visit each basic block in post order.
84 23535568 : for (auto i = blocks->rbegin(); i != blocks->rend(); ++i) {
85 20585674 : VisitBlock(*i);
86 20585715 : if (instruction_selection_failed()) return false;
87 : }
88 :
89 : // Schedule the selected instructions.
90 2949894 : if (UseInstructionScheduling()) {
91 2153 : scheduler_ = new (zone()) InstructionScheduler(zone(), sequence());
92 : }
93 :
94 67657076 : for (auto const block : *blocks) {
95 41171334 : InstructionBlock* instruction_block =
96 20585595 : sequence()->InstructionBlockAt(RpoNumber::FromInt(block->rpo_number()));
97 45510810 : for (size_t i = 0; i < instruction_block->phis().size(); i++) {
98 2169738 : UpdateRenamesInPhi(instruction_block->PhiAt(i));
99 : }
100 20585667 : size_t end = instruction_block->code_end();
101 20585667 : size_t start = instruction_block->code_start();
102 : DCHECK_LE(end, start);
103 20585667 : StartBlock(RpoNumber::FromInt(block->rpo_number()));
104 20585643 : if (end != start) {
105 64858930 : while (start-- > end + 1) {
106 129717940 : UpdateRenames(instructions_[start]);
107 44273235 : AddInstruction(instructions_[start]);
108 : }
109 20585732 : UpdateRenames(instructions_[end]);
110 20585812 : AddTerminator(instructions_[end]);
111 : }
112 20585768 : EndBlock(RpoNumber::FromInt(block->rpo_number()));
113 : }
114 : #if DEBUG
115 : sequence()->ValidateSSA();
116 : #endif
117 : return true;
118 : }
119 :
120 41042796 : void InstructionSelector::StartBlock(RpoNumber rpo) {
121 20585536 : if (UseInstructionScheduling()) {
122 : DCHECK_NOT_NULL(scheduler_);
123 128276 : scheduler_->StartBlock(rpo);
124 : } else {
125 20457260 : sequence()->StartBlock(rpo);
126 : }
127 20585636 : }
128 :
129 41043254 : void InstructionSelector::EndBlock(RpoNumber rpo) {
130 20585765 : if (UseInstructionScheduling()) {
131 : DCHECK_NOT_NULL(scheduler_);
132 128276 : scheduler_->EndBlock(rpo);
133 : } else {
134 20457489 : sequence()->EndBlock(rpo);
135 : }
136 20585872 : }
137 :
138 41043282 : void InstructionSelector::AddTerminator(Instruction* instr) {
139 20585779 : if (UseInstructionScheduling()) {
140 : DCHECK_NOT_NULL(scheduler_);
141 128276 : scheduler_->AddTerminator(instr);
142 : } else {
143 20457503 : sequence()->AddInstruction(instr);
144 : }
145 20585847 : }
146 :
147 88351950 : void InstructionSelector::AddInstruction(Instruction* instr) {
148 44273286 : if (UseInstructionScheduling()) {
149 : DCHECK_NOT_NULL(scheduler_);
150 194622 : scheduler_->AddInstruction(instr);
151 : } else {
152 44078664 : sequence()->AddInstruction(instr);
153 : }
154 44273290 : }
155 :
156 17750684 : Instruction* InstructionSelector::Emit(InstructionCode opcode,
157 : InstructionOperand output,
158 : size_t temp_count,
159 : InstructionOperand* temps) {
160 17750684 : size_t output_count = output.IsInvalid() ? 0 : 1;
161 17750684 : return Emit(opcode, output_count, &output, 0, nullptr, temp_count, temps);
162 : }
163 :
164 13369943 : Instruction* InstructionSelector::Emit(InstructionCode opcode,
165 : InstructionOperand output,
166 : InstructionOperand a, size_t temp_count,
167 : InstructionOperand* temps) {
168 13369943 : size_t output_count = output.IsInvalid() ? 0 : 1;
169 13369943 : return Emit(opcode, output_count, &output, 1, &a, temp_count, temps);
170 : }
171 :
172 1655063 : Instruction* InstructionSelector::Emit(InstructionCode opcode,
173 : InstructionOperand output,
174 : InstructionOperand a,
175 : InstructionOperand b, size_t temp_count,
176 : InstructionOperand* temps) {
177 1655063 : size_t output_count = output.IsInvalid() ? 0 : 1;
178 1655063 : InstructionOperand inputs[] = {a, b};
179 : size_t input_count = arraysize(inputs);
180 : return Emit(opcode, output_count, &output, input_count, inputs, temp_count,
181 1655063 : temps);
182 : }
183 :
184 2715 : 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 2715 : size_t output_count = output.IsInvalid() ? 0 : 1;
191 2715 : 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 2715 : 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 61909535 : 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 123819070 : if (output_count >= Instruction::kMaxOutputCount ||
236 123818959 : 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 61909526 : input_count, inputs, temp_count, temps);
245 61909481 : return Emit(instr);
246 : }
247 :
248 0 : Instruction* InstructionSelector::Emit(Instruction* instr) {
249 64858231 : instructions_.push_back(instr);
250 61909481 : return instr;
251 : }
252 :
253 45808014 : bool InstructionSelector::CanCover(Node* user, Node* node) const {
254 : // 1. Both {user} and {node} must be in the same basic block.
255 25234910 : if (schedule()->block(node) != schedule()->block(user)) {
256 : return false;
257 : }
258 : // 2. Pure {node}s must be owned by the {user}.
259 11630127 : if (node->op()->HasProperty(Operator::kPure)) {
260 8942977 : return node->OwnedBy(user);
261 : }
262 : // 3. Impure {node}s must match the effect level of {user}.
263 2687150 : if (GetEffectLevel(node) != GetEffectLevel(user)) {
264 : return false;
265 : }
266 : // 4. Only {node} must have value edges pointing to {user}.
267 18921342 : for (Edge const edge : node->use_edges()) {
268 6909529 : if (edge.from() != user && NodeProperties::IsValueEdge(edge)) {
269 164210 : return false;
270 : }
271 : }
272 2469041 : return true;
273 : }
274 :
275 796220 : bool InstructionSelector::CanCoverTransitively(Node* user, Node* node,
276 287389 : Node* node_input) const {
277 508830 : if (CanCover(user, node) && CanCover(node, node_input)) {
278 : // If {node} is pure, transitivity might not hold.
279 287390 : if (node->op()->HasProperty(Operator::kPure)) {
280 : // If {node_input} is pure, the effect levels do not matter.
281 287389 : if (node_input->op()->HasProperty(Operator::kPure)) return true;
282 : // Otherwise, {user} and {node_input} must have the same effect level.
283 283039 : return GetEffectLevel(user) == GetEffectLevel(node_input);
284 : }
285 : return true;
286 : }
287 : return false;
288 : }
289 :
290 163486 : bool InstructionSelector::IsOnlyUserOfNodeInSameBlock(Node* user,
291 374023 : Node* node) const {
292 163486 : BasicBlock* bb_user = schedule()->block(user);
293 163499 : BasicBlock* bb_node = schedule()->block(node);
294 163501 : if (bb_user != bb_node) return false;
295 504933 : for (Edge const edge : node->use_edges()) {
296 : Node* from = edge.from();
297 246126 : if ((from != user) && (schedule()->block(from) == bb_user)) {
298 : return false;
299 : }
300 : }
301 151186 : return true;
302 : }
303 :
304 256976977 : void InstructionSelector::UpdateRenames(Instruction* instruction) {
305 384236798 : for (size_t i = 0; i < instruction->InputCount(); i++) {
306 127259621 : TryRename(instruction->InputAt(i));
307 : }
308 64858778 : }
309 :
310 2169733 : void InstructionSelector::UpdateRenamesInPhi(PhiInstruction* phi) {
311 14709832 : for (size_t i = 0; i < phi->operands().size(); i++) {
312 5185182 : int vreg = phi->operands()[i];
313 : int renamed = GetRename(vreg);
314 5185182 : if (vreg != renamed) {
315 303738 : phi->RenameInput(i, renamed);
316 : }
317 : }
318 2169734 : }
319 :
320 0 : int InstructionSelector::GetRename(int virtual_register) {
321 : int rename = virtual_register;
322 : while (true) {
323 149494426 : if (static_cast<size_t>(rename) >= virtual_register_rename_.size()) break;
324 39800212 : int next = virtual_register_rename_[rename];
325 39800212 : if (next == InstructionOperand::kInvalidVirtualRegister) {
326 : break;
327 : }
328 : rename = next;
329 : }
330 0 : return rename;
331 : }
332 :
333 127259634 : void InstructionSelector::TryRename(InstructionOperand* op) {
334 254519268 : if (!op->IsUnallocated()) return;
335 : UnallocatedOperand* unalloc = UnallocatedOperand::cast(op);
336 : int vreg = unalloc->virtual_register();
337 : int rename = GetRename(vreg);
338 66821838 : if (rename != vreg) {
339 2436424 : *unalloc = UnallocatedOperand(*unalloc, rename);
340 : }
341 : }
342 :
343 2445004 : void InstructionSelector::SetRename(const Node* node, const Node* rename) {
344 2445004 : int vreg = GetVirtualRegister(node);
345 7335041 : if (static_cast<size_t>(vreg) >= virtual_register_rename_.size()) {
346 2143958 : int invalid = InstructionOperand::kInvalidVirtualRegister;
347 2143958 : virtual_register_rename_.resize(vreg + 1, invalid);
348 : }
349 2445017 : virtual_register_rename_[vreg] = GetVirtualRegister(rename);
350 2445027 : }
351 :
352 188997413 : int InstructionSelector::GetVirtualRegister(const Node* node) {
353 : DCHECK_NOT_NULL(node);
354 147601781 : size_t const id = node->id();
355 : DCHECK_LT(id, virtual_registers_.size());
356 336599275 : int virtual_register = virtual_registers_[id];
357 147601781 : if (virtual_register == InstructionOperand::kInvalidVirtualRegister) {
358 41395632 : virtual_register = sequence()->NextVirtualRegister();
359 41395713 : virtual_registers_[id] = virtual_register;
360 : }
361 147601862 : return virtual_register;
362 : }
363 :
364 250 : const std::map<NodeId, int> InstructionSelector::GetVirtualRegistersForTesting()
365 : const {
366 : std::map<NodeId, int> virtual_registers;
367 4772 : for (size_t n = 0; n < virtual_registers_.size(); ++n) {
368 4522 : if (virtual_registers_[n] != InstructionOperand::kInvalidVirtualRegister) {
369 728 : NodeId const id = static_cast<NodeId>(n);
370 1456 : virtual_registers.insert(std::make_pair(id, virtual_registers_[n]));
371 : }
372 : }
373 250 : return virtual_registers;
374 : }
375 :
376 49702419 : bool InstructionSelector::IsDefined(Node* node) const {
377 : DCHECK_NOT_NULL(node);
378 49702419 : size_t const id = node->id();
379 : DCHECK_LT(id, defined_.size());
380 50748276 : return defined_[id];
381 : }
382 :
383 36190556 : void InstructionSelector::MarkAsDefined(Node* node) {
384 : DCHECK_NOT_NULL(node);
385 36190556 : size_t const id = node->id();
386 : DCHECK_LT(id, defined_.size());
387 36190556 : defined_[id] = true;
388 12443548 : }
389 :
390 214414593 : 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 113597126 : if (node->opcode() == IrOpcode::kRetain) return true;
395 113588425 : if (!node->op()->HasProperty(Operator::kEliminatable)) return true;
396 100817467 : size_t const id = node->id();
397 : DCHECK_LT(id, used_.size());
398 201634934 : return used_[id];
399 : }
400 :
401 79328313 : void InstructionSelector::MarkAsUsed(Node* node) {
402 : DCHECK_NOT_NULL(node);
403 79328313 : size_t const id = node->id();
404 : DCHECK_LT(id, used_.size());
405 79328313 : used_[id] = true;
406 8709995 : }
407 :
408 20639865 : int InstructionSelector::GetEffectLevel(Node* node) const {
409 : DCHECK_NOT_NULL(node);
410 20639865 : size_t const id = node->id();
411 : DCHECK_LT(id, effect_level_.size());
412 38309541 : return effect_level_[id];
413 : }
414 :
415 121709320 : void InstructionSelector::SetEffectLevel(Node* node, int effect_level) {
416 : DCHECK_NOT_NULL(node);
417 121709320 : size_t const id = node->id();
418 : DCHECK_LT(id, effect_level_.size());
419 243418640 : effect_level_[id] = effect_level;
420 0 : }
421 :
422 11638330 : bool InstructionSelector::CanAddressRelativeToRootsRegister() const {
423 18087213 : return enable_roots_relative_addressing_ == kEnableRootsRelativeAddressing &&
424 11638330 : CanUseRootsRegister();
425 : }
426 :
427 9268635 : bool InstructionSelector::CanUseRootsRegister() const {
428 : return linkage()->GetIncomingDescriptor()->flags() &
429 2819752 : CallDescriptor::kCanUseRoots;
430 : }
431 :
432 0 : void InstructionSelector::MarkAsRepresentation(MachineRepresentation rep,
433 5334573 : const InstructionOperand& op) {
434 : UnallocatedOperand unalloc = UnallocatedOperand::cast(op);
435 5334573 : sequence()->MarkAsRepresentation(rep, unalloc.virtual_register());
436 0 : }
437 :
438 25829445 : void InstructionSelector::MarkAsRepresentation(MachineRepresentation rep,
439 25829601 : Node* node) {
440 51659046 : sequence()->MarkAsRepresentation(rep, GetVirtualRegister(node));
441 25829947 : }
442 :
443 : namespace {
444 :
445 21000023 : InstructionOperand OperandForDeopt(Isolate* isolate, OperandGenerator* g,
446 21000023 : Node* input, FrameStateInputKind kind,
447 : MachineRepresentation rep) {
448 21000023 : if (rep == MachineRepresentation::kNone) {
449 0 : return g->TempImmediate(FrameStateDescriptor::kImpossibleValue);
450 : }
451 :
452 21000023 : 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 610625 : return g->UseImmediate(input);
460 : case IrOpcode::kHeapConstant: {
461 5486550 : 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 5486550 : Handle<HeapObject> constant = HeapConstantOf(input->op());
473 : RootIndex root_index;
474 5486556 : 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 324 : return InstructionOperand();
479 : }
480 :
481 5486232 : 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 14902848 : switch (kind) {
491 : case FrameStateInputKind::kStackSlot:
492 12535374 : 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 2367474 : return g->UseAnyAtEnd(input);
497 : }
498 : }
499 0 : UNREACHABLE();
500 : }
501 :
502 : } // namespace
503 :
504 : class StateObjectDeduplicator {
505 : public:
506 : explicit StateObjectDeduplicator(Zone* zone) : objects_(zone) {}
507 : static const size_t kNotDuplicated = SIZE_MAX;
508 :
509 219016 : size_t GetObjectId(Node* node) {
510 : DCHECK(node->opcode() == IrOpcode::kTypedObjectState ||
511 : node->opcode() == IrOpcode::kObjectId ||
512 : node->opcode() == IrOpcode::kArgumentsElementsState);
513 393852 : for (size_t i = 0; i < objects_.size(); ++i) {
514 301567 : 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 312481 : if (HasObjectId(objects_[i]) && HasObjectId(node) &&
519 207840 : 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 92285 : size_t id = objects_.size();
533 121150 : objects_.push_back(node);
534 : return id;
535 : }
536 :
537 : private:
538 208561 : static bool HasObjectId(Node* node) {
539 208561 : 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 42942912 : size_t InstructionSelector::AddOperandToStateValueDescriptor(
548 : StateValueList* values, InstructionOperandVector* inputs,
549 21219594 : OperandGenerator* g, StateObjectDeduplicator* deduplicator, Node* input,
550 : MachineType type, FrameStateInputKind kind, Zone* zone) {
551 42942912 : if (input == nullptr) {
552 21815603 : values->PushOptimizedOut();
553 21815640 : return 0;
554 : }
555 :
556 21127309 : switch (input->opcode()) {
557 : case IrOpcode::kArgumentsElementsState: {
558 6054 : 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 6054 : return 0;
565 : }
566 : case IrOpcode::kArgumentsLengthState: {
567 6336 : values->PushArgumentsLength(ArgumentsStateTypeOf(input->op()));
568 6336 : return 0;
569 : }
570 : case IrOpcode::kObjectState: {
571 0 : UNREACHABLE();
572 : }
573 : case IrOpcode::kTypedObjectState:
574 : case IrOpcode::kObjectId: {
575 115096 : size_t id = deduplicator->GetObjectId(input);
576 115096 : if (id == StateObjectDeduplicator::kNotDuplicated) {
577 : DCHECK_EQ(IrOpcode::kTypedObjectState, input->opcode());
578 : size_t entries = 0;
579 : id = deduplicator->InsertObject(input);
580 92285 : StateValueList* nested = values->PushRecursiveField(zone, id);
581 92285 : int const input_count = input->op()->ValueInputCount();
582 92285 : ZoneVector<MachineType> const* types = MachineTypesOf(input->op());
583 647304 : for (int i = 0; i < input_count; ++i) {
584 : entries += AddOperandToStateValueDescriptor(
585 555019 : nested, inputs, g, deduplicator, input->InputAt(i), types->at(i),
586 555019 : 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 22811 : values->PushDuplicate(id);
594 22811 : return 0;
595 : }
596 : }
597 : default: {
598 : InstructionOperand op =
599 41999646 : OperandForDeopt(isolate(), g, input, kind, type.representation());
600 20999849 : if (op.kind() == InstructionOperand::INVALID) {
601 : // Invalid operand means the value is impossible or optimized-out.
602 324 : values->PushOptimizedOut();
603 331 : return 0;
604 : } else {
605 20999525 : inputs->push_back(op);
606 20999549 : values->PushPlain(type);
607 20999718 : return 1;
608 : }
609 : }
610 : }
611 : }
612 :
613 : // Returns the number of instruction operands added to inputs.
614 3357982 : size_t InstructionSelector::AddInputsToFrameStateDescriptor(
615 6716007 : 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 3357982 : if (descriptor->outer_state()) {
625 : entries += AddInputsToFrameStateDescriptor(
626 : descriptor->outer_state(), state->InputAt(kFrameStateOuterStateInput),
627 359202 : 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 3357994 : StateValueList* values_descriptor = descriptor->GetStateValueDescriptors();
642 :
643 : DCHECK_EQ(values_descriptor->size(), 0u);
644 3357994 : values_descriptor->ReserveSize(descriptor->GetSize());
645 :
646 : entries += AddOperandToStateValueDescriptor(
647 : values_descriptor, inputs, g, deduplicator, function,
648 3358008 : MachineType::AnyTagged(), FrameStateInputKind::kStackSlot, zone);
649 9106969 : for (StateValuesAccess::TypedNode input_node :
650 9106936 : StateValuesAccess(parameters)) {
651 : entries += AddOperandToStateValueDescriptor(values_descriptor, inputs, g,
652 : deduplicator, input_node.node,
653 9106944 : input_node.type, kind, zone);
654 : }
655 3358025 : if (descriptor->HasContext()) {
656 : entries += AddOperandToStateValueDescriptor(
657 : values_descriptor, inputs, g, deduplicator, context,
658 3281194 : MachineType::AnyTagged(), FrameStateInputKind::kStackSlot, zone);
659 : }
660 46804351 : for (StateValuesAccess::TypedNode input_node : StateValuesAccess(locals)) {
661 : entries += AddOperandToStateValueDescriptor(values_descriptor, inputs, g,
662 : deduplicator, input_node.node,
663 23402075 : input_node.type, kind, zone);
664 : }
665 6479504 : for (StateValuesAccess::TypedNode input_node : StateValuesAccess(stack)) {
666 : entries += AddOperandToStateValueDescriptor(values_descriptor, inputs, g,
667 : deduplicator, input_node.node,
668 3239762 : input_node.type, kind, zone);
669 : }
670 : DCHECK_EQ(initial_size + entries, inputs->size());
671 3358026 : return entries;
672 : }
673 :
674 554393 : Instruction* InstructionSelector::EmitWithContinuation(
675 : InstructionCode opcode, FlagsContinuation* cont) {
676 554393 : 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 4208892 : Instruction* InstructionSelector::EmitWithContinuation(
685 : InstructionCode opcode, InstructionOperand a, InstructionOperand b,
686 : FlagsContinuation* cont) {
687 4208892 : InstructionOperand inputs[] = {a, b};
688 : return EmitWithContinuation(opcode, 0, nullptr, arraysize(inputs), inputs,
689 4208892 : 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 6867866 : Instruction* InstructionSelector::EmitWithContinuation(
701 : InstructionCode opcode, size_t output_count, InstructionOperand* outputs,
702 25456399 : size_t input_count, InstructionOperand* inputs, FlagsContinuation* cont) {
703 : OperandGenerator g(this);
704 :
705 : opcode = cont->Encode(opcode);
706 :
707 13735907 : continuation_inputs_.resize(0);
708 20565836 : for (size_t i = 0; i < input_count; i++) {
709 13697825 : continuation_inputs_.push_back(inputs[i]);
710 : }
711 :
712 13736052 : continuation_outputs_.resize(0);
713 7904662 : for (size_t i = 0; i < output_count; i++) {
714 1036652 : continuation_outputs_.push_back(outputs[i]);
715 : }
716 :
717 6868010 : if (cont->IsBranch()) {
718 10384772 : continuation_inputs_.push_back(g.Label(cont->true_block()));
719 10384823 : continuation_inputs_.push_back(g.Label(cont->false_block()));
720 1675648 : } else if (cont->IsDeoptimize()) {
721 340308 : opcode |= MiscField::encode(static_cast<int>(input_count));
722 : AppendDeoptimizeArguments(&continuation_inputs_, cont->kind(),
723 340308 : cont->reason(), cont->feedback(),
724 340308 : cont->frame_state());
725 1335340 : } else if (cont->IsSet()) {
726 1215794 : continuation_outputs_.push_back(g.DefineAsRegister(cont->result()));
727 727441 : } else if (cont->IsTrap()) {
728 47236 : int trap_id = static_cast<int>(cont->trap_id());
729 94483 : 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 6868041 : emit_inputs_size ? &continuation_inputs_.front() : nullptr;
737 : size_t const emit_outputs_size = continuation_outputs_.size();
738 : auto* emit_outputs =
739 6868041 : emit_outputs_size ? &continuation_outputs_.front() : nullptr;
740 : return Emit(opcode, emit_outputs_size, emit_outputs, emit_inputs_size,
741 6868041 : emit_inputs, 0, nullptr);
742 : }
743 :
744 387898 : void InstructionSelector::AppendDeoptimizeArguments(
745 : InstructionOperandVector* args, DeoptimizeKind kind,
746 : DeoptimizeReason reason, VectorSlotPair const& feedback,
747 387901 : Node* frame_state) {
748 : OperandGenerator g(this);
749 387898 : FrameStateDescriptor* const descriptor = GetFrameStateDescriptor(frame_state);
750 : DCHECK_NE(DeoptimizeKind::kLazy, kind);
751 : int const state_id =
752 387901 : sequence()->AddDeoptimizationEntry(descriptor, kind, reason, feedback);
753 775804 : args->push_back(g.TempImmediate(state_id));
754 : StateObjectDeduplicator deduplicator(instruction_zone());
755 : AddInputsToFrameStateDescriptor(descriptor, frame_state, &g, &deduplicator,
756 : args, FrameStateInputKind::kAny,
757 387902 : instruction_zone());
758 387901 : }
759 :
760 47591 : 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 47591 : for (size_t i = 0; i < input_count; ++i) {
767 0 : args.push_back(inputs[i]);
768 : }
769 47591 : opcode |= MiscField::encode(static_cast<int>(input_count));
770 47591 : AppendDeoptimizeArguments(&args, kind, reason, feedback, frame_state);
771 : return Emit(opcode, output_count, outputs, args.size(), &args.front(), 0,
772 95182 : 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 : struct CallBuffer {
779 16422283 : CallBuffer(Zone* zone, const CallDescriptor* call_descriptor,
780 16422459 : 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 5474081 : pushed_nodes(zone) {
787 5474081 : output_nodes.reserve(call_descriptor->ReturnCount());
788 5474121 : outputs.reserve(call_descriptor->ReturnCount());
789 5474137 : pushed_nodes.reserve(input_count());
790 5474153 : instruction_args.reserve(input_count() + frame_state_value_count());
791 5474155 : }
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 16422340 : 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 2610922 : : (frame_state_descriptor->GetTotalSize() +
808 8085075 : 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 10948133 : void InstructionSelector::InitializeCallBuffer(Node* call, CallBuffer* buffer,
815 : CallBufferFlags flags,
816 : bool is_tail_call,
817 2610894 : int stack_param_delta) {
818 : OperandGenerator g(this);
819 13590258 : 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 5474091 : if (ret_count > 0) {
826 : // Collect the projections that represent multiple outputs from this call.
827 5323906 : if (ret_count == 1) {
828 : PushParameter result = {call, buffer->descriptor->GetReturnLocation(0)};
829 21366526 : buffer->output_nodes.push_back(result);
830 : } else {
831 6375 : buffer->output_nodes.resize(ret_count);
832 : int stack_count = 0;
833 37505 : for (size_t i = 0; i < ret_count; ++i) {
834 31130 : LinkageLocation location = buffer->descriptor->GetReturnLocation(i);
835 31130 : buffer->output_nodes[i] = PushParameter(nullptr, location);
836 31130 : if (location.IsCallerFrameSlot()) {
837 18378 : stack_count += location.GetSizeInPointers();
838 : }
839 : }
840 92316 : for (Edge const edge : call->use_edges()) {
841 39783 : if (!NodeProperties::IsValueEdge(edge)) continue;
842 16993 : Node* node = edge.from();
843 : DCHECK_EQ(IrOpcode::kProjection, node->opcode());
844 16993 : size_t const index = ProjectionIndexOf(node->op());
845 :
846 : DCHECK_LT(index, buffer->output_nodes.size());
847 : DCHECK(!buffer->output_nodes[index].node);
848 16993 : buffer->output_nodes[index].node = node;
849 : }
850 6375 : 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 5323917 : buffer->frame_state_descriptor == nullptr
856 : ? 0
857 : : buffer->frame_state_descriptor->state_combine()
858 5323917 : .ConsumedOutputCount();
859 21345268 : for (size_t i = 0; i < buffer->output_nodes.size(); i++) {
860 5348672 : bool output_is_live = buffer->output_nodes[i].node != nullptr ||
861 : i < outputs_needed_by_framestate;
862 5348672 : if (output_is_live) {
863 5334530 : 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 5334530 : : g.DefineAsLocation(output, location);
870 : MarkAsRepresentation(rep, op);
871 :
872 5334565 : if (!UnallocatedOperand::cast(op).HasFixedSlotPolicy()) {
873 5328228 : buffer->outputs.push_back(op);
874 5328238 : buffer->output_nodes[i].node = nullptr;
875 : }
876 : }
877 : }
878 : }
879 :
880 : // The first argument is always the callee code.
881 5356512 : Node* callee = call->InputAt(0);
882 : bool call_code_immediate = (flags & kCallCodeImmediate) != 0;
883 5474147 : bool call_address_immediate = (flags & kCallAddressImmediate) != 0;
884 5474147 : bool call_use_fixed_target_reg = (flags & kCallFixedTargetRegister) != 0;
885 : bool call_through_slot = (flags & kAllowCallThroughSlot) != 0;
886 10948294 : 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 : buffer->instruction_args.push_back(
894 4075263 : (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 12213044 : : g.UseRegister(callee));
901 4075283 : break;
902 : case CallDescriptor::kCallAddress:
903 : buffer->instruction_args.push_back(
904 110063 : (call_address_immediate &&
905 : callee->opcode() == IrOpcode::kExternalConstant)
906 : ? g.UseImmediate(callee)
907 : : call_use_fixed_target_reg
908 : ? g.UseFixed(callee, kJavaScriptCallCodeStartRegister)
909 245268 : : g.UseRegister(callee));
910 110063 : break;
911 : case CallDescriptor::kCallWasmFunction:
912 : case CallDescriptor::kCallWasmImportWrapper:
913 : buffer->instruction_args.push_back(
914 1171186 : (call_address_immediate &&
915 1076276 : (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 2437286 : : g.UseRegister(callee));
921 1171187 : 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 : buffer->instruction_args.push_back(
927 : call_use_fixed_target_reg
928 : ? g.UseFixed(callee, kJavaScriptCallCodeStartRegister)
929 23580 : : g.UseRegister(callee));
930 11790 : break;
931 : case CallDescriptor::kCallJSFunction:
932 : buffer->instruction_args.push_back(
933 211578 : g.UseLocation(callee, buffer->descriptor->GetInputLocation(0)));
934 105789 : 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 10948187 : 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 5474008 : if (buffer->frame_state_descriptor != nullptr) {
952 : Node* frame_state =
953 5221780 : 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 2610890 : 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 : int const state_id = sequence()->AddDeoptimizationEntry(
972 : buffer->frame_state_descriptor, DeoptimizeKind::kLazy,
973 5221784 : DeoptimizeReason::kUnknown, VectorSlotPair());
974 5221837 : buffer->instruction_args.push_back(g.TempImmediate(state_id));
975 :
976 : StateObjectDeduplicator deduplicator(instruction_zone());
977 :
978 : frame_state_entries =
979 : 1 + AddInputsToFrameStateDescriptor(
980 : buffer->frame_state_descriptor, frame_state, &g, &deduplicator,
981 : &buffer->instruction_args, FrameStateInputKind::kStackSlot,
982 2610923 : 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 5474042 : bool call_tail = (flags & kCallTail) != 0;
996 28690565 : 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 28690520 : if (index == 0) continue; // The first argument (callee) is already done.
1000 :
1001 17742384 : LinkageLocation location = buffer->descriptor->GetInputLocation(index);
1002 17742449 : if (call_tail) {
1003 : location = LinkageLocation::ConvertToTailCallerLocation(
1004 : location, stack_param_delta);
1005 : }
1006 17742449 : InstructionOperand op = g.UseLocation(*iter, location);
1007 : UnallocatedOperand unallocated = UnallocatedOperand::cast(op);
1008 17742468 : if (unallocated.HasFixedSlotPolicy() && !call_tail) {
1009 3062233 : int stack_index = -unallocated.fixed_slot_index() - 1;
1010 9186701 : if (static_cast<size_t>(stack_index) >= buffer->pushed_nodes.size()) {
1011 1389371 : buffer->pushed_nodes.resize(stack_index + 1);
1012 : }
1013 : PushParameter param = {*iter, location};
1014 3062235 : 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 14680242 : if (poisoning_level_ != PoisoningMitigationLevel::kDontPoison &&
1021 : unallocated.HasFixedRegisterPolicy()) {
1022 : int reg = unallocated.fixed_register_index();
1023 7 : if (Register::from_code(reg) == kSpeculationPoisonRegister) {
1024 0 : 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 14680235 : 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 5474113 : if (V8_TARGET_ARCH_STORES_RETURN_ADDRESS_ON_STACK && call_tail &&
1035 5474113 : 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 18710 : LinkageLocation::ForSavedCallerReturnAddress();
1041 : InstructionOperand return_address =
1042 : g.UsePointerLocation(LinkageLocation::ConvertToTailCallerLocation(
1043 : saved_return_location, stack_param_delta),
1044 18710 : saved_return_location);
1045 18710 : buffer->instruction_args.push_back(return_address);
1046 : }
1047 5474113 : }
1048 :
1049 21885538 : bool InstructionSelector::IsSourcePositionUsed(Node* node) {
1050 21885538 : return (source_position_mode_ == kAllSourcePositions ||
1051 7571247 : node->opcode() == IrOpcode::kCall ||
1052 7571252 : node->opcode() == IrOpcode::kCallWithCallerSavedRegisters ||
1053 7559947 : node->opcode() == IrOpcode::kTrapIf ||
1054 7524032 : node->opcode() == IrOpcode::kTrapUnless ||
1055 18491308 : node->opcode() == IrOpcode::kProtectedLoad ||
1056 11165708 : node->opcode() == IrOpcode::kProtectedStore);
1057 : }
1058 :
1059 82343012 : void InstructionSelector::VisitBlock(BasicBlock* block) {
1060 : DCHECK(!current_block_);
1061 20585919 : current_block_ = block;
1062 : auto current_num_instructions = [&] {
1063 : DCHECK_GE(kMaxInt, instructions_.size());
1064 486719886 : return static_cast<int>(instructions_.size());
1065 20585919 : };
1066 : int current_block_end = current_num_instructions();
1067 :
1068 : int effect_level = 0;
1069 266449962 : for (Node* const node : *block) {
1070 : SetEffectLevel(node, effect_level);
1071 220874805 : if (node->opcode() == IrOpcode::kStore ||
1072 108236123 : node->opcode() == IrOpcode::kUnalignedStore ||
1073 103067699 : node->opcode() == IrOpcode::kCall ||
1074 103067510 : node->opcode() == IrOpcode::kCallWithCallerSavedRegisters ||
1075 215508305 : node->opcode() == IrOpcode::kProtectedLoad ||
1076 : node->opcode() == IrOpcode::kProtectedStore) {
1077 10028600 : ++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 20585919 : if (block->control_input() != nullptr) {
1084 : SetEffectLevel(block->control_input(), effect_level);
1085 : }
1086 :
1087 68965503 : auto FinishEmittedInstructions = [&](Node* node, int instruction_start) {
1088 73063591 : if (instruction_selection_failed()) return false;
1089 137931224 : if (current_num_instructions() == instruction_start) return true;
1090 : std::reverse(instructions_.begin() + instruction_start,
1091 62584677 : instructions_.end());
1092 58486589 : if (!node) return true;
1093 49920023 : if (!source_positions_) return true;
1094 38003780 : SourcePosition source_position = source_positions_->GetSourcePosition(node);
1095 38003690 : if (source_position.IsKnown() && IsSourcePositionUsed(node)) {
1096 4098088 : sequence()->SetSourcePosition(instructions_[instruction_start],
1097 8196176 : source_position);
1098 : }
1099 : return true;
1100 20585919 : };
1101 :
1102 : // Generate code for the block control "top down", but schedule the code
1103 : // "bottom up".
1104 20585919 : VisitControl(block);
1105 20585509 : 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 245859603 : for (auto node : base::Reversed(*block)) {
1111 : int current_node_end = current_num_instructions();
1112 : // Skip nodes that are unused or already defined.
1113 161293472 : if (IsUsed(node) && !IsDefined(node)) {
1114 : // Generate code for this node "top down", but schedule the code "bottom
1115 : // up".
1116 48381304 : VisitNode(node);
1117 48380713 : if (!FinishEmittedInstructions(node, current_node_end)) return;
1118 : }
1119 112636977 : if (trace_turbo_ == kEnableTraceTurboJson) {
1120 118 : 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 20585665 : sequence()->InstructionBlockAt(RpoNumber::FromInt(block->rpo_number()));
1128 20585702 : if (current_num_instructions() == current_block_end) {
1129 : // Avoid empty block: insert a {kArchNop} instruction.
1130 2948626 : 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 20585682 : current_block_ = nullptr;
1135 : }
1136 :
1137 41211421 : 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 47598 : Node* input = block->control_input();
1158 41171617 : int instruction_end = static_cast<int>(instructions_.size());
1159 20585805 : switch (block->control()) {
1160 : case BasicBlock::kGoto:
1161 8567041 : VisitGoto(block->SuccessorAt(0));
1162 8567004 : 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 189392 : VisitCall(input, exception);
1168 189392 : VisitGoto(success);
1169 189392 : break;
1170 : }
1171 : case BasicBlock::kTailCall: {
1172 : DCHECK_EQ(IrOpcode::kTailCall, input->opcode());
1173 118262 : VisitTailCall(input);
1174 118262 : 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 5192406 : if (tbranch == fbranch) {
1181 0 : VisitGoto(tbranch);
1182 : } else {
1183 5192406 : 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 39811 : 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 39811 : size_t case_count = block->SuccessorCount() - 1;
1196 : ZoneVector<CaseInfo> cases(case_count, zone());
1197 482546 : for (size_t i = 0; i < case_count; ++i) {
1198 : BasicBlock* branch = block->SuccessorAt(i);
1199 1328205 : const IfValueParameters& p = IfValueParametersOf(branch->front()->op());
1200 885470 : cases[i] = CaseInfo{p.value(), p.comparison_order(), branch};
1201 442735 : if (min_value > p.value()) min_value = p.value();
1202 442735 : if (max_value < p.value()) max_value = p.value();
1203 : }
1204 : SwitchInfo sw(cases, min_value, max_value, default_branch);
1205 39811 : VisitSwitch(input, sw);
1206 : break;
1207 : }
1208 : case BasicBlock::kReturn: {
1209 : DCHECK_EQ(IrOpcode::kReturn, input->opcode());
1210 3264821 : VisitReturn(input);
1211 3264676 : break;
1212 : }
1213 : case BasicBlock::kDeoptimize: {
1214 47591 : DeoptimizeParameters p = DeoptimizeParametersOf(input->op());
1215 : Node* value = input->InputAt(0);
1216 47591 : 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 20585451 : if (trace_turbo_ == kEnableTraceTurboJson && input) {
1233 7 : int instruction_start = static_cast<int>(instructions_.size());
1234 7 : instr_origins_[input->id()] = {instruction_start, instruction_end};
1235 : }
1236 20585451 : }
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 51858151 : void InstructionSelector::VisitNode(Node* node) {
1250 : DCHECK_NOT_NULL(schedule()->block(node)); // should only use scheduled nodes.
1251 48381104 : 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 178588 : return MarkAsReference(node), VisitIfException(node);
1270 : case IrOpcode::kFinishRegion:
1271 : return MarkAsReference(node), VisitFinishRegion(node);
1272 : case IrOpcode::kParameter: {
1273 : MachineType type =
1274 6954157 : linkage()->GetParameterType(ParameterIndexOf(node->op()));
1275 3477177 : MarkAsRepresentation(type.representation(), node);
1276 3477273 : return VisitParameter(node);
1277 : }
1278 : case IrOpcode::kOsrValue:
1279 22711 : return MarkAsReference(node), VisitOsrValue(node);
1280 : case IrOpcode::kPhi: {
1281 2169718 : MachineRepresentation rep = PhiRepresentationOf(node->op());
1282 2169715 : if (rep == MachineRepresentation::kNone) return;
1283 2169722 : MarkAsRepresentation(rep, node);
1284 2169730 : return VisitPhi(node);
1285 : }
1286 : case IrOpcode::kProjection:
1287 343185 : return VisitProjection(node);
1288 : case IrOpcode::kInt32Constant:
1289 : case IrOpcode::kInt64Constant:
1290 : case IrOpcode::kExternalConstant:
1291 : case IrOpcode::kRelocatableInt32Constant:
1292 : case IrOpcode::kRelocatableInt64Constant:
1293 7662750 : return VisitConstant(node);
1294 : case IrOpcode::kFloat32Constant:
1295 13035 : return MarkAsFloat32(node), VisitConstant(node);
1296 : case IrOpcode::kFloat64Constant:
1297 203775 : return MarkAsFloat64(node), VisitConstant(node);
1298 : case IrOpcode::kHeapConstant:
1299 4953062 : return MarkAsReference(node), VisitConstant(node);
1300 : case IrOpcode::kNumberConstant: {
1301 667659 : double value = OpParameter<double>(node->op());
1302 667659 : if (!IsSmiDouble(value)) MarkAsReference(node);
1303 667659 : return VisitConstant(node);
1304 : }
1305 : case IrOpcode::kDelayedStringConstant:
1306 1770 : return MarkAsReference(node), VisitConstant(node);
1307 : case IrOpcode::kCall:
1308 5165759 : return VisitCall(node);
1309 : case IrOpcode::kCallWithCallerSavedRegisters:
1310 677 : return VisitCallWithCallerSavedRegisters(node);
1311 : case IrOpcode::kDeoptimizeIf:
1312 114333 : return VisitDeoptimizeIf(node);
1313 : case IrOpcode::kDeoptimizeUnless:
1314 225975 : return VisitDeoptimizeUnless(node);
1315 : case IrOpcode::kTrapIf:
1316 11305 : return VisitTrapIf(node, TrapIdOf(node->op()));
1317 : case IrOpcode::kTrapUnless:
1318 35944 : 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 170 : VisitDebugAbort(node);
1325 170 : 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 5 : VisitComment(node);
1337 5 : return;
1338 : case IrOpcode::kRetain:
1339 9221 : VisitRetain(node);
1340 9221 : return;
1341 : case IrOpcode::kLoad: {
1342 5728860 : LoadRepresentation type = LoadRepresentationOf(node->op());
1343 5728849 : MarkAsRepresentation(type.representation(), node);
1344 5728917 : 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 4402648 : return VisitStore(node);
1353 : case IrOpcode::kProtectedStore:
1354 257911 : return VisitProtectedStore(node);
1355 : case IrOpcode::kWord32And:
1356 200590 : return MarkAsWord32(node), VisitWord32And(node);
1357 : case IrOpcode::kWord32Or:
1358 81324 : return MarkAsWord32(node), VisitWord32Or(node);
1359 : case IrOpcode::kWord32Xor:
1360 42968 : return MarkAsWord32(node), VisitWord32Xor(node);
1361 : case IrOpcode::kWord32Shl:
1362 65081 : return MarkAsWord32(node), VisitWord32Shl(node);
1363 : case IrOpcode::kWord32Shr:
1364 119364 : return MarkAsWord32(node), VisitWord32Shr(node);
1365 : case IrOpcode::kWord32Sar:
1366 47365 : return MarkAsWord32(node), VisitWord32Sar(node);
1367 : case IrOpcode::kWord32Ror:
1368 68192 : return MarkAsWord32(node), VisitWord32Ror(node);
1369 : case IrOpcode::kWord32Equal:
1370 150348 : return VisitWord32Equal(node);
1371 : case IrOpcode::kWord32Clz:
1372 848 : return MarkAsWord32(node), VisitWord32Clz(node);
1373 : case IrOpcode::kWord32Ctz:
1374 737 : return MarkAsWord32(node), VisitWord32Ctz(node);
1375 : case IrOpcode::kWord32ReverseBits:
1376 0 : return MarkAsWord32(node), VisitWord32ReverseBits(node);
1377 : case IrOpcode::kWord32ReverseBytes:
1378 55 : return MarkAsWord32(node), VisitWord32ReverseBytes(node);
1379 : case IrOpcode::kInt32AbsWithOverflow:
1380 0 : return MarkAsWord32(node), VisitInt32AbsWithOverflow(node);
1381 : case IrOpcode::kWord32Popcnt:
1382 133 : return MarkAsWord32(node), VisitWord32Popcnt(node);
1383 : case IrOpcode::kWord64Popcnt:
1384 62 : return MarkAsWord32(node), VisitWord64Popcnt(node);
1385 : case IrOpcode::kWord64And:
1386 186201 : return MarkAsWord64(node), VisitWord64And(node);
1387 : case IrOpcode::kWord64Or:
1388 89396 : return MarkAsWord64(node), VisitWord64Or(node);
1389 : case IrOpcode::kWord64Xor:
1390 425 : return MarkAsWord64(node), VisitWord64Xor(node);
1391 : case IrOpcode::kWord64Shl:
1392 398032 : return MarkAsWord64(node), VisitWord64Shl(node);
1393 : case IrOpcode::kWord64Shr:
1394 44932 : return MarkAsWord64(node), VisitWord64Shr(node);
1395 : case IrOpcode::kWord64Sar:
1396 198444 : return MarkAsWord64(node), VisitWord64Sar(node);
1397 : case IrOpcode::kWord64Ror:
1398 186 : return MarkAsWord64(node), VisitWord64Ror(node);
1399 : case IrOpcode::kWord64Clz:
1400 47 : return MarkAsWord64(node), VisitWord64Clz(node);
1401 : case IrOpcode::kWord64Ctz:
1402 56 : return MarkAsWord64(node), VisitWord64Ctz(node);
1403 : case IrOpcode::kWord64ReverseBits:
1404 0 : return MarkAsWord64(node), VisitWord64ReverseBits(node);
1405 : case IrOpcode::kWord64ReverseBytes:
1406 15 : return MarkAsWord64(node), VisitWord64ReverseBytes(node);
1407 : case IrOpcode::kInt64AbsWithOverflow:
1408 0 : return MarkAsWord64(node), VisitInt64AbsWithOverflow(node);
1409 : case IrOpcode::kWord64Equal:
1410 39247 : return VisitWord64Equal(node);
1411 : case IrOpcode::kInt32Add:
1412 318693 : return MarkAsWord32(node), VisitInt32Add(node);
1413 : case IrOpcode::kInt32AddWithOverflow:
1414 17405 : return MarkAsWord32(node), VisitInt32AddWithOverflow(node);
1415 : case IrOpcode::kInt32Sub:
1416 77303 : return MarkAsWord32(node), VisitInt32Sub(node);
1417 : case IrOpcode::kInt32SubWithOverflow:
1418 17405 : return VisitInt32SubWithOverflow(node);
1419 : case IrOpcode::kInt32Mul:
1420 87065 : return MarkAsWord32(node), VisitInt32Mul(node);
1421 : case IrOpcode::kInt32MulWithOverflow:
1422 17405 : return MarkAsWord32(node), VisitInt32MulWithOverflow(node);
1423 : case IrOpcode::kInt32MulHigh:
1424 7731 : return VisitInt32MulHigh(node);
1425 : case IrOpcode::kInt32Div:
1426 36917 : return MarkAsWord32(node), VisitInt32Div(node);
1427 : case IrOpcode::kInt32Mod:
1428 37656 : return MarkAsWord32(node), VisitInt32Mod(node);
1429 : case IrOpcode::kInt32LessThan:
1430 68750 : return VisitInt32LessThan(node);
1431 : case IrOpcode::kInt32LessThanOrEqual:
1432 68319 : return VisitInt32LessThanOrEqual(node);
1433 : case IrOpcode::kUint32Div:
1434 35581 : return MarkAsWord32(node), VisitUint32Div(node);
1435 : case IrOpcode::kUint32LessThan:
1436 74096 : return VisitUint32LessThan(node);
1437 : case IrOpcode::kUint32LessThanOrEqual:
1438 68487 : return VisitUint32LessThanOrEqual(node);
1439 : case IrOpcode::kUint32Mod:
1440 35754 : return MarkAsWord32(node), VisitUint32Mod(node);
1441 : case IrOpcode::kUint32MulHigh:
1442 1554 : return VisitUint32MulHigh(node);
1443 : case IrOpcode::kInt64Add:
1444 2110591 : return MarkAsWord64(node), VisitInt64Add(node);
1445 : case IrOpcode::kInt64AddWithOverflow:
1446 33620 : return MarkAsWord64(node), VisitInt64AddWithOverflow(node);
1447 : case IrOpcode::kInt64Sub:
1448 35912 : return MarkAsWord64(node), VisitInt64Sub(node);
1449 : case IrOpcode::kInt64SubWithOverflow:
1450 33620 : return MarkAsWord64(node), VisitInt64SubWithOverflow(node);
1451 : case IrOpcode::kInt64Mul:
1452 22142 : return MarkAsWord64(node), VisitInt64Mul(node);
1453 : case IrOpcode::kInt64Div:
1454 2856 : return MarkAsWord64(node), VisitInt64Div(node);
1455 : case IrOpcode::kInt64Mod:
1456 1814 : return MarkAsWord64(node), VisitInt64Mod(node);
1457 : case IrOpcode::kInt64LessThan:
1458 1476 : return VisitInt64LessThan(node);
1459 : case IrOpcode::kInt64LessThanOrEqual:
1460 943 : return VisitInt64LessThanOrEqual(node);
1461 : case IrOpcode::kUint64Div:
1462 1832 : return MarkAsWord64(node), VisitUint64Div(node);
1463 : case IrOpcode::kUint64LessThan:
1464 6818 : return VisitUint64LessThan(node);
1465 : case IrOpcode::kUint64LessThanOrEqual:
1466 510 : return VisitUint64LessThanOrEqual(node);
1467 : case IrOpcode::kUint64Mod:
1468 1805 : return MarkAsWord64(node), VisitUint64Mod(node);
1469 : case IrOpcode::kBitcastTaggedToWord:
1470 1274153 : return MarkAsRepresentation(MachineType::PointerRepresentation(), node),
1471 : VisitBitcastTaggedToWord(node);
1472 : case IrOpcode::kBitcastWordToTagged:
1473 338456 : return MarkAsReference(node), VisitBitcastWordToTagged(node);
1474 : case IrOpcode::kBitcastWordToTaggedSigned:
1475 748733 : return MarkAsRepresentation(MachineRepresentation::kTaggedSigned, node),
1476 748733 : EmitIdentity(node);
1477 : case IrOpcode::kChangeFloat32ToFloat64:
1478 24163 : return MarkAsFloat64(node), VisitChangeFloat32ToFloat64(node);
1479 : case IrOpcode::kChangeInt32ToFloat64:
1480 399786 : return MarkAsFloat64(node), VisitChangeInt32ToFloat64(node);
1481 : case IrOpcode::kChangeInt64ToFloat64:
1482 353 : return MarkAsFloat64(node), VisitChangeInt64ToFloat64(node);
1483 : case IrOpcode::kChangeUint32ToFloat64:
1484 10798 : return MarkAsFloat64(node), VisitChangeUint32ToFloat64(node);
1485 : case IrOpcode::kChangeFloat64ToInt32:
1486 2020 : return MarkAsWord32(node), VisitChangeFloat64ToInt32(node);
1487 : case IrOpcode::kChangeFloat64ToInt64:
1488 28 : return MarkAsWord64(node), VisitChangeFloat64ToInt64(node);
1489 : case IrOpcode::kChangeFloat64ToUint32:
1490 814 : return MarkAsWord32(node), VisitChangeFloat64ToUint32(node);
1491 : case IrOpcode::kChangeFloat64ToUint64:
1492 3808 : return MarkAsWord64(node), VisitChangeFloat64ToUint64(node);
1493 : case IrOpcode::kFloat64SilenceNaN:
1494 : MarkAsFloat64(node);
1495 6001 : if (CanProduceSignalingNaN(node->InputAt(0))) {
1496 5818 : return VisitFloat64SilenceNaN(node);
1497 : } else {
1498 183 : return EmitIdentity(node);
1499 : }
1500 : case IrOpcode::kTruncateFloat64ToInt64:
1501 84 : return MarkAsWord64(node), VisitTruncateFloat64ToInt64(node);
1502 : case IrOpcode::kTruncateFloat64ToUint32:
1503 81 : return MarkAsWord32(node), VisitTruncateFloat64ToUint32(node);
1504 : case IrOpcode::kTruncateFloat32ToInt32:
1505 525 : return MarkAsWord32(node), VisitTruncateFloat32ToInt32(node);
1506 : case IrOpcode::kTruncateFloat32ToUint32:
1507 75 : return MarkAsWord32(node), VisitTruncateFloat32ToUint32(node);
1508 : case IrOpcode::kTryTruncateFloat32ToInt64:
1509 71 : return MarkAsWord64(node), VisitTryTruncateFloat32ToInt64(node);
1510 : case IrOpcode::kTryTruncateFloat64ToInt64:
1511 686 : return MarkAsWord64(node), VisitTryTruncateFloat64ToInt64(node);
1512 : case IrOpcode::kTryTruncateFloat32ToUint64:
1513 71 : return MarkAsWord64(node), VisitTryTruncateFloat32ToUint64(node);
1514 : case IrOpcode::kTryTruncateFloat64ToUint64:
1515 80 : return MarkAsWord64(node), VisitTryTruncateFloat64ToUint64(node);
1516 : case IrOpcode::kChangeInt32ToInt64:
1517 156684 : return MarkAsWord64(node), VisitChangeInt32ToInt64(node);
1518 : case IrOpcode::kChangeUint32ToUint64:
1519 289609 : return MarkAsWord64(node), VisitChangeUint32ToUint64(node);
1520 : case IrOpcode::kTruncateFloat64ToFloat32:
1521 20406 : return MarkAsFloat32(node), VisitTruncateFloat64ToFloat32(node);
1522 : case IrOpcode::kTruncateFloat64ToWord32:
1523 55897 : return MarkAsWord32(node), VisitTruncateFloat64ToWord32(node);
1524 : case IrOpcode::kTruncateInt64ToInt32:
1525 536326 : return MarkAsWord32(node), VisitTruncateInt64ToInt32(node);
1526 : case IrOpcode::kRoundFloat64ToInt32:
1527 130494 : return MarkAsWord32(node), VisitRoundFloat64ToInt32(node);
1528 : case IrOpcode::kRoundInt64ToFloat32:
1529 42 : return MarkAsFloat32(node), VisitRoundInt64ToFloat32(node);
1530 : case IrOpcode::kRoundInt32ToFloat32:
1531 1095 : return MarkAsFloat32(node), VisitRoundInt32ToFloat32(node);
1532 : case IrOpcode::kRoundInt64ToFloat64:
1533 3027 : return MarkAsFloat64(node), VisitRoundInt64ToFloat64(node);
1534 : case IrOpcode::kBitcastFloat32ToInt32:
1535 668 : return MarkAsWord32(node), VisitBitcastFloat32ToInt32(node);
1536 : case IrOpcode::kRoundUint32ToFloat32:
1537 112 : return MarkAsFloat32(node), VisitRoundUint32ToFloat32(node);
1538 : case IrOpcode::kRoundUint64ToFloat32:
1539 42 : return MarkAsFloat64(node), VisitRoundUint64ToFloat32(node);
1540 : case IrOpcode::kRoundUint64ToFloat64:
1541 3631 : return MarkAsFloat64(node), VisitRoundUint64ToFloat64(node);
1542 : case IrOpcode::kBitcastFloat64ToInt64:
1543 614 : return MarkAsWord64(node), VisitBitcastFloat64ToInt64(node);
1544 : case IrOpcode::kBitcastInt32ToFloat32:
1545 370 : return MarkAsFloat32(node), VisitBitcastInt32ToFloat32(node);
1546 : case IrOpcode::kBitcastInt64ToFloat64:
1547 193 : return MarkAsFloat64(node), VisitBitcastInt64ToFloat64(node);
1548 : case IrOpcode::kFloat32Add:
1549 2166 : return MarkAsFloat32(node), VisitFloat32Add(node);
1550 : case IrOpcode::kFloat32Sub:
1551 3177 : return MarkAsFloat32(node), VisitFloat32Sub(node);
1552 : case IrOpcode::kFloat32Neg:
1553 208 : return MarkAsFloat32(node), VisitFloat32Neg(node);
1554 : case IrOpcode::kFloat32Mul:
1555 1052 : return MarkAsFloat32(node), VisitFloat32Mul(node);
1556 : case IrOpcode::kFloat32Div:
1557 416 : return MarkAsFloat32(node), VisitFloat32Div(node);
1558 : case IrOpcode::kFloat32Abs:
1559 101 : return MarkAsFloat32(node), VisitFloat32Abs(node);
1560 : case IrOpcode::kFloat32Sqrt:
1561 209 : return MarkAsFloat32(node), VisitFloat32Sqrt(node);
1562 : case IrOpcode::kFloat32Equal:
1563 136 : return VisitFloat32Equal(node);
1564 : case IrOpcode::kFloat32LessThan:
1565 182 : return VisitFloat32LessThan(node);
1566 : case IrOpcode::kFloat32LessThanOrEqual:
1567 139 : return VisitFloat32LessThanOrEqual(node);
1568 : case IrOpcode::kFloat32Max:
1569 89 : return MarkAsFloat32(node), VisitFloat32Max(node);
1570 : case IrOpcode::kFloat32Min:
1571 94 : return MarkAsFloat32(node), VisitFloat32Min(node);
1572 : case IrOpcode::kFloat64Add:
1573 80725 : return MarkAsFloat64(node), VisitFloat64Add(node);
1574 : case IrOpcode::kFloat64Sub:
1575 16079 : return MarkAsFloat64(node), VisitFloat64Sub(node);
1576 : case IrOpcode::kFloat64Neg:
1577 9969 : return MarkAsFloat64(node), VisitFloat64Neg(node);
1578 : case IrOpcode::kFloat64Mul:
1579 14297 : return MarkAsFloat64(node), VisitFloat64Mul(node);
1580 : case IrOpcode::kFloat64Div:
1581 12147 : return MarkAsFloat64(node), VisitFloat64Div(node);
1582 : case IrOpcode::kFloat64Mod:
1583 1628 : return MarkAsFloat64(node), VisitFloat64Mod(node);
1584 : case IrOpcode::kFloat64Min:
1585 365 : return MarkAsFloat64(node), VisitFloat64Min(node);
1586 : case IrOpcode::kFloat64Max:
1587 282 : return MarkAsFloat64(node), VisitFloat64Max(node);
1588 : case IrOpcode::kFloat64Abs:
1589 665 : return MarkAsFloat64(node), VisitFloat64Abs(node);
1590 : case IrOpcode::kFloat64Acos:
1591 : return MarkAsFloat64(node), VisitFloat64Acos(node);
1592 : case IrOpcode::kFloat64Acosh:
1593 : return MarkAsFloat64(node), VisitFloat64Acosh(node);
1594 : case IrOpcode::kFloat64Asin:
1595 : return MarkAsFloat64(node), VisitFloat64Asin(node);
1596 : case IrOpcode::kFloat64Asinh:
1597 : return MarkAsFloat64(node), VisitFloat64Asinh(node);
1598 : case IrOpcode::kFloat64Atan:
1599 : return MarkAsFloat64(node), VisitFloat64Atan(node);
1600 : case IrOpcode::kFloat64Atanh:
1601 : return MarkAsFloat64(node), VisitFloat64Atanh(node);
1602 : case IrOpcode::kFloat64Atan2:
1603 : return MarkAsFloat64(node), VisitFloat64Atan2(node);
1604 : case IrOpcode::kFloat64Cbrt:
1605 : return MarkAsFloat64(node), VisitFloat64Cbrt(node);
1606 : case IrOpcode::kFloat64Cos:
1607 : return MarkAsFloat64(node), VisitFloat64Cos(node);
1608 : case IrOpcode::kFloat64Cosh:
1609 : return MarkAsFloat64(node), VisitFloat64Cosh(node);
1610 : case IrOpcode::kFloat64Exp:
1611 : return MarkAsFloat64(node), VisitFloat64Exp(node);
1612 : case IrOpcode::kFloat64Expm1:
1613 : return MarkAsFloat64(node), VisitFloat64Expm1(node);
1614 : case IrOpcode::kFloat64Log:
1615 : return MarkAsFloat64(node), VisitFloat64Log(node);
1616 : case IrOpcode::kFloat64Log1p:
1617 : return MarkAsFloat64(node), VisitFloat64Log1p(node);
1618 : case IrOpcode::kFloat64Log10:
1619 : return MarkAsFloat64(node), VisitFloat64Log10(node);
1620 : case IrOpcode::kFloat64Log2:
1621 : return MarkAsFloat64(node), VisitFloat64Log2(node);
1622 : case IrOpcode::kFloat64Pow:
1623 : return MarkAsFloat64(node), VisitFloat64Pow(node);
1624 : case IrOpcode::kFloat64Sin:
1625 : return MarkAsFloat64(node), VisitFloat64Sin(node);
1626 : case IrOpcode::kFloat64Sinh:
1627 : return MarkAsFloat64(node), VisitFloat64Sinh(node);
1628 : case IrOpcode::kFloat64Sqrt:
1629 477 : return MarkAsFloat64(node), VisitFloat64Sqrt(node);
1630 : case IrOpcode::kFloat64Tan:
1631 : return MarkAsFloat64(node), VisitFloat64Tan(node);
1632 : case IrOpcode::kFloat64Tanh:
1633 : return MarkAsFloat64(node), VisitFloat64Tanh(node);
1634 : case IrOpcode::kFloat64Equal:
1635 2732 : return VisitFloat64Equal(node);
1636 : case IrOpcode::kFloat64LessThan:
1637 4852 : return VisitFloat64LessThan(node);
1638 : case IrOpcode::kFloat64LessThanOrEqual:
1639 1409 : return VisitFloat64LessThanOrEqual(node);
1640 : case IrOpcode::kFloat32RoundDown:
1641 64 : return MarkAsFloat32(node), VisitFloat32RoundDown(node);
1642 : case IrOpcode::kFloat64RoundDown:
1643 26241 : return MarkAsFloat64(node), VisitFloat64RoundDown(node);
1644 : case IrOpcode::kFloat32RoundUp:
1645 64 : return MarkAsFloat32(node), VisitFloat32RoundUp(node);
1646 : case IrOpcode::kFloat64RoundUp:
1647 8524 : return MarkAsFloat64(node), VisitFloat64RoundUp(node);
1648 : case IrOpcode::kFloat32RoundTruncate:
1649 342 : return MarkAsFloat32(node), VisitFloat32RoundTruncate(node);
1650 : case IrOpcode::kFloat64RoundTruncate:
1651 8076 : return MarkAsFloat64(node), VisitFloat64RoundTruncate(node);
1652 : case IrOpcode::kFloat64RoundTiesAway:
1653 0 : return MarkAsFloat64(node), VisitFloat64RoundTiesAway(node);
1654 : case IrOpcode::kFloat32RoundTiesEven:
1655 33 : return MarkAsFloat32(node), VisitFloat32RoundTiesEven(node);
1656 : case IrOpcode::kFloat64RoundTiesEven:
1657 1069 : return MarkAsFloat64(node), VisitFloat64RoundTiesEven(node);
1658 : case IrOpcode::kFloat64ExtractLowWord32:
1659 117 : return MarkAsWord32(node), VisitFloat64ExtractLowWord32(node);
1660 : case IrOpcode::kFloat64ExtractHighWord32:
1661 100225 : return MarkAsWord32(node), VisitFloat64ExtractHighWord32(node);
1662 : case IrOpcode::kFloat64InsertLowWord32:
1663 117 : return MarkAsFloat64(node), VisitFloat64InsertLowWord32(node);
1664 : case IrOpcode::kFloat64InsertHighWord32:
1665 117 : return MarkAsFloat64(node), VisitFloat64InsertHighWord32(node);
1666 : case IrOpcode::kTaggedPoisonOnSpeculation:
1667 : return MarkAsReference(node), VisitTaggedPoisonOnSpeculation(node);
1668 : case IrOpcode::kWord32PoisonOnSpeculation:
1669 : return MarkAsWord32(node), VisitWord32PoisonOnSpeculation(node);
1670 : case IrOpcode::kWord64PoisonOnSpeculation:
1671 : return MarkAsWord64(node), VisitWord64PoisonOnSpeculation(node);
1672 : case IrOpcode::kStackSlot:
1673 1255 : return VisitStackSlot(node);
1674 : case IrOpcode::kLoadStackPointer:
1675 1 : return VisitLoadStackPointer(node);
1676 : case IrOpcode::kLoadFramePointer:
1677 30547 : return VisitLoadFramePointer(node);
1678 : case IrOpcode::kLoadParentFramePointer:
1679 49229 : return VisitLoadParentFramePointer(node);
1680 : case IrOpcode::kUnalignedLoad: {
1681 0 : LoadRepresentation type = LoadRepresentationOf(node->op());
1682 0 : MarkAsRepresentation(type.representation(), node);
1683 0 : return VisitUnalignedLoad(node);
1684 : }
1685 : case IrOpcode::kUnalignedStore:
1686 0 : return VisitUnalignedStore(node);
1687 : case IrOpcode::kInt32PairAdd:
1688 : MarkAsWord32(node);
1689 0 : MarkPairProjectionsAsWord32(node);
1690 0 : return VisitInt32PairAdd(node);
1691 : case IrOpcode::kInt32PairSub:
1692 : MarkAsWord32(node);
1693 0 : MarkPairProjectionsAsWord32(node);
1694 0 : return VisitInt32PairSub(node);
1695 : case IrOpcode::kInt32PairMul:
1696 : MarkAsWord32(node);
1697 0 : MarkPairProjectionsAsWord32(node);
1698 0 : return VisitInt32PairMul(node);
1699 : case IrOpcode::kWord32PairShl:
1700 : MarkAsWord32(node);
1701 0 : MarkPairProjectionsAsWord32(node);
1702 0 : return VisitWord32PairShl(node);
1703 : case IrOpcode::kWord32PairShr:
1704 : MarkAsWord32(node);
1705 0 : MarkPairProjectionsAsWord32(node);
1706 0 : return VisitWord32PairShr(node);
1707 : case IrOpcode::kWord32PairSar:
1708 : MarkAsWord32(node);
1709 0 : MarkPairProjectionsAsWord32(node);
1710 0 : return VisitWord32PairSar(node);
1711 : case IrOpcode::kWord32AtomicLoad: {
1712 1098 : LoadRepresentation type = LoadRepresentationOf(node->op());
1713 1098 : MarkAsRepresentation(type.representation(), node);
1714 1098 : return VisitWord32AtomicLoad(node);
1715 : }
1716 : case IrOpcode::kWord64AtomicLoad: {
1717 613 : LoadRepresentation type = LoadRepresentationOf(node->op());
1718 613 : MarkAsRepresentation(type.representation(), node);
1719 613 : return VisitWord64AtomicLoad(node);
1720 : }
1721 : case IrOpcode::kWord32AtomicStore:
1722 2130 : return VisitWord32AtomicStore(node);
1723 : case IrOpcode::kWord64AtomicStore:
1724 2627 : return VisitWord64AtomicStore(node);
1725 : case IrOpcode::kWord32AtomicPairStore:
1726 0 : return VisitWord32AtomicPairStore(node);
1727 : case IrOpcode::kWord32AtomicPairLoad: {
1728 : MarkAsWord32(node);
1729 0 : MarkPairProjectionsAsWord32(node);
1730 0 : return VisitWord32AtomicPairLoad(node);
1731 : }
1732 : #define ATOMIC_CASE(name, rep) \
1733 : case IrOpcode::k##rep##Atomic##name: { \
1734 : MachineType type = AtomicOpType(node->op()); \
1735 : MarkAsRepresentation(type.representation(), node); \
1736 : return Visit##rep##Atomic##name(node); \
1737 : }
1738 2660 : ATOMIC_CASE(Add, Word32)
1739 2164 : ATOMIC_CASE(Add, Word64)
1740 2744 : ATOMIC_CASE(Sub, Word32)
1741 2298 : ATOMIC_CASE(Sub, Word64)
1742 2406 : ATOMIC_CASE(And, Word32)
1743 2294 : ATOMIC_CASE(And, Word64)
1744 2454 : ATOMIC_CASE(Or, Word32)
1745 2343 : ATOMIC_CASE(Or, Word64)
1746 2883 : ATOMIC_CASE(Xor, Word32)
1747 2406 : ATOMIC_CASE(Xor, Word64)
1748 2412 : ATOMIC_CASE(Exchange, Word32)
1749 2237 : ATOMIC_CASE(Exchange, Word64)
1750 756 : ATOMIC_CASE(CompareExchange, Word32)
1751 354 : ATOMIC_CASE(CompareExchange, Word64)
1752 : #undef ATOMIC_CASE
1753 : #define ATOMIC_CASE(name) \
1754 : case IrOpcode::kWord32AtomicPair##name: { \
1755 : MarkAsWord32(node); \
1756 : MarkPairProjectionsAsWord32(node); \
1757 : return VisitWord32AtomicPair##name(node); \
1758 : }
1759 0 : ATOMIC_CASE(Add)
1760 0 : ATOMIC_CASE(Sub)
1761 0 : ATOMIC_CASE(And)
1762 0 : ATOMIC_CASE(Or)
1763 0 : ATOMIC_CASE(Xor)
1764 0 : ATOMIC_CASE(Exchange)
1765 0 : ATOMIC_CASE(CompareExchange)
1766 : #undef ATOMIC_CASE
1767 : case IrOpcode::kSpeculationFence:
1768 1 : return VisitSpeculationFence(node);
1769 : case IrOpcode::kProtectedLoad: {
1770 198465 : LoadRepresentation type = LoadRepresentationOf(node->op());
1771 198464 : MarkAsRepresentation(type.representation(), node);
1772 198467 : return VisitProtectedLoad(node);
1773 : }
1774 : case IrOpcode::kSignExtendWord8ToInt32:
1775 10 : return MarkAsWord32(node), VisitSignExtendWord8ToInt32(node);
1776 : case IrOpcode::kSignExtendWord16ToInt32:
1777 10 : return MarkAsWord32(node), VisitSignExtendWord16ToInt32(node);
1778 : case IrOpcode::kSignExtendWord8ToInt64:
1779 10 : return MarkAsWord64(node), VisitSignExtendWord8ToInt64(node);
1780 : case IrOpcode::kSignExtendWord16ToInt64:
1781 10 : return MarkAsWord64(node), VisitSignExtendWord16ToInt64(node);
1782 : case IrOpcode::kSignExtendWord32ToInt64:
1783 10 : return MarkAsWord64(node), VisitSignExtendWord32ToInt64(node);
1784 : case IrOpcode::kUnsafePointerAdd:
1785 6731 : MarkAsRepresentation(MachineType::PointerRepresentation(), node);
1786 : return VisitUnsafePointerAdd(node);
1787 : case IrOpcode::kF32x4Splat:
1788 350 : return MarkAsSimd128(node), VisitF32x4Splat(node);
1789 : case IrOpcode::kF32x4ExtractLane:
1790 680 : return MarkAsFloat32(node), VisitF32x4ExtractLane(node);
1791 : case IrOpcode::kF32x4ReplaceLane:
1792 80 : return MarkAsSimd128(node), VisitF32x4ReplaceLane(node);
1793 : case IrOpcode::kF32x4SConvertI32x4:
1794 5 : return MarkAsSimd128(node), VisitF32x4SConvertI32x4(node);
1795 : case IrOpcode::kF32x4UConvertI32x4:
1796 5 : return MarkAsSimd128(node), VisitF32x4UConvertI32x4(node);
1797 : case IrOpcode::kF32x4Abs:
1798 10 : return MarkAsSimd128(node), VisitF32x4Abs(node);
1799 : case IrOpcode::kF32x4Neg:
1800 10 : return MarkAsSimd128(node), VisitF32x4Neg(node);
1801 : case IrOpcode::kF32x4RecipApprox:
1802 10 : return MarkAsSimd128(node), VisitF32x4RecipApprox(node);
1803 : case IrOpcode::kF32x4RecipSqrtApprox:
1804 10 : return MarkAsSimd128(node), VisitF32x4RecipSqrtApprox(node);
1805 : case IrOpcode::kF32x4Add:
1806 30 : return MarkAsSimd128(node), VisitF32x4Add(node);
1807 : case IrOpcode::kF32x4AddHoriz:
1808 10 : return MarkAsSimd128(node), VisitF32x4AddHoriz(node);
1809 : case IrOpcode::kF32x4Sub:
1810 10 : return MarkAsSimd128(node), VisitF32x4Sub(node);
1811 : case IrOpcode::kF32x4Mul:
1812 10 : return MarkAsSimd128(node), VisitF32x4Mul(node);
1813 : case IrOpcode::kF32x4Min:
1814 10 : return MarkAsSimd128(node), VisitF32x4Min(node);
1815 : case IrOpcode::kF32x4Max:
1816 10 : return MarkAsSimd128(node), VisitF32x4Max(node);
1817 : case IrOpcode::kF32x4Eq:
1818 10 : return MarkAsSimd128(node), VisitF32x4Eq(node);
1819 : case IrOpcode::kF32x4Ne:
1820 10 : return MarkAsSimd128(node), VisitF32x4Ne(node);
1821 : case IrOpcode::kF32x4Lt:
1822 20 : return MarkAsSimd128(node), VisitF32x4Lt(node);
1823 : case IrOpcode::kF32x4Le:
1824 20 : return MarkAsSimd128(node), VisitF32x4Le(node);
1825 : case IrOpcode::kI32x4Splat:
1826 2090 : return MarkAsSimd128(node), VisitI32x4Splat(node);
1827 : case IrOpcode::kI32x4ExtractLane:
1828 7692 : return MarkAsWord32(node), VisitI32x4ExtractLane(node);
1829 : case IrOpcode::kI32x4ReplaceLane:
1830 2280 : return MarkAsSimd128(node), VisitI32x4ReplaceLane(node);
1831 : case IrOpcode::kI32x4SConvertF32x4:
1832 10 : return MarkAsSimd128(node), VisitI32x4SConvertF32x4(node);
1833 : case IrOpcode::kI32x4SConvertI16x8Low:
1834 10 : return MarkAsSimd128(node), VisitI32x4SConvertI16x8Low(node);
1835 : case IrOpcode::kI32x4SConvertI16x8High:
1836 10 : return MarkAsSimd128(node), VisitI32x4SConvertI16x8High(node);
1837 : case IrOpcode::kI32x4Neg:
1838 10 : return MarkAsSimd128(node), VisitI32x4Neg(node);
1839 : case IrOpcode::kI32x4Shl:
1840 310 : return MarkAsSimd128(node), VisitI32x4Shl(node);
1841 : case IrOpcode::kI32x4ShrS:
1842 310 : return MarkAsSimd128(node), VisitI32x4ShrS(node);
1843 : case IrOpcode::kI32x4Add:
1844 30 : return MarkAsSimd128(node), VisitI32x4Add(node);
1845 : case IrOpcode::kI32x4AddHoriz:
1846 10 : return MarkAsSimd128(node), VisitI32x4AddHoriz(node);
1847 : case IrOpcode::kI32x4Sub:
1848 10 : return MarkAsSimd128(node), VisitI32x4Sub(node);
1849 : case IrOpcode::kI32x4Mul:
1850 10 : return MarkAsSimd128(node), VisitI32x4Mul(node);
1851 : case IrOpcode::kI32x4MinS:
1852 10 : return MarkAsSimd128(node), VisitI32x4MinS(node);
1853 : case IrOpcode::kI32x4MaxS:
1854 10 : return MarkAsSimd128(node), VisitI32x4MaxS(node);
1855 : case IrOpcode::kI32x4Eq:
1856 30 : return MarkAsSimd128(node), VisitI32x4Eq(node);
1857 : case IrOpcode::kI32x4Ne:
1858 35 : return MarkAsSimd128(node), VisitI32x4Ne(node);
1859 : case IrOpcode::kI32x4GtS:
1860 20 : return MarkAsSimd128(node), VisitI32x4GtS(node);
1861 : case IrOpcode::kI32x4GeS:
1862 20 : return MarkAsSimd128(node), VisitI32x4GeS(node);
1863 : case IrOpcode::kI32x4UConvertF32x4:
1864 10 : return MarkAsSimd128(node), VisitI32x4UConvertF32x4(node);
1865 : case IrOpcode::kI32x4UConvertI16x8Low:
1866 10 : return MarkAsSimd128(node), VisitI32x4UConvertI16x8Low(node);
1867 : case IrOpcode::kI32x4UConvertI16x8High:
1868 10 : return MarkAsSimd128(node), VisitI32x4UConvertI16x8High(node);
1869 : case IrOpcode::kI32x4ShrU:
1870 310 : return MarkAsSimd128(node), VisitI32x4ShrU(node);
1871 : case IrOpcode::kI32x4MinU:
1872 10 : return MarkAsSimd128(node), VisitI32x4MinU(node);
1873 : case IrOpcode::kI32x4MaxU:
1874 10 : return MarkAsSimd128(node), VisitI32x4MaxU(node);
1875 : case IrOpcode::kI32x4GtU:
1876 20 : return MarkAsSimd128(node), VisitI32x4GtU(node);
1877 : case IrOpcode::kI32x4GeU:
1878 20 : return MarkAsSimd128(node), VisitI32x4GeU(node);
1879 : case IrOpcode::kI16x8Splat:
1880 980 : return MarkAsSimd128(node), VisitI16x8Splat(node);
1881 : case IrOpcode::kI16x8ExtractLane:
1882 6600 : return MarkAsWord32(node), VisitI16x8ExtractLane(node);
1883 : case IrOpcode::kI16x8ReplaceLane:
1884 120 : return MarkAsSimd128(node), VisitI16x8ReplaceLane(node);
1885 : case IrOpcode::kI16x8SConvertI8x16Low:
1886 10 : return MarkAsSimd128(node), VisitI16x8SConvertI8x16Low(node);
1887 : case IrOpcode::kI16x8SConvertI8x16High:
1888 10 : return MarkAsSimd128(node), VisitI16x8SConvertI8x16High(node);
1889 : case IrOpcode::kI16x8Neg:
1890 10 : return MarkAsSimd128(node), VisitI16x8Neg(node);
1891 : case IrOpcode::kI16x8Shl:
1892 150 : return MarkAsSimd128(node), VisitI16x8Shl(node);
1893 : case IrOpcode::kI16x8ShrS:
1894 150 : return MarkAsSimd128(node), VisitI16x8ShrS(node);
1895 : case IrOpcode::kI16x8SConvertI32x4:
1896 10 : return MarkAsSimd128(node), VisitI16x8SConvertI32x4(node);
1897 : case IrOpcode::kI16x8Add:
1898 10 : return MarkAsSimd128(node), VisitI16x8Add(node);
1899 : case IrOpcode::kI16x8AddSaturateS:
1900 10 : return MarkAsSimd128(node), VisitI16x8AddSaturateS(node);
1901 : case IrOpcode::kI16x8AddHoriz:
1902 10 : return MarkAsSimd128(node), VisitI16x8AddHoriz(node);
1903 : case IrOpcode::kI16x8Sub:
1904 10 : return MarkAsSimd128(node), VisitI16x8Sub(node);
1905 : case IrOpcode::kI16x8SubSaturateS:
1906 10 : return MarkAsSimd128(node), VisitI16x8SubSaturateS(node);
1907 : case IrOpcode::kI16x8Mul:
1908 10 : return MarkAsSimd128(node), VisitI16x8Mul(node);
1909 : case IrOpcode::kI16x8MinS:
1910 10 : return MarkAsSimd128(node), VisitI16x8MinS(node);
1911 : case IrOpcode::kI16x8MaxS:
1912 10 : return MarkAsSimd128(node), VisitI16x8MaxS(node);
1913 : case IrOpcode::kI16x8Eq:
1914 30 : return MarkAsSimd128(node), VisitI16x8Eq(node);
1915 : case IrOpcode::kI16x8Ne:
1916 35 : return MarkAsSimd128(node), VisitI16x8Ne(node);
1917 : case IrOpcode::kI16x8GtS:
1918 20 : return MarkAsSimd128(node), VisitI16x8GtS(node);
1919 : case IrOpcode::kI16x8GeS:
1920 20 : return MarkAsSimd128(node), VisitI16x8GeS(node);
1921 : case IrOpcode::kI16x8UConvertI8x16Low:
1922 10 : return MarkAsSimd128(node), VisitI16x8UConvertI8x16Low(node);
1923 : case IrOpcode::kI16x8UConvertI8x16High:
1924 10 : return MarkAsSimd128(node), VisitI16x8UConvertI8x16High(node);
1925 : case IrOpcode::kI16x8ShrU:
1926 150 : return MarkAsSimd128(node), VisitI16x8ShrU(node);
1927 : case IrOpcode::kI16x8UConvertI32x4:
1928 10 : return MarkAsSimd128(node), VisitI16x8UConvertI32x4(node);
1929 : case IrOpcode::kI16x8AddSaturateU:
1930 10 : return MarkAsSimd128(node), VisitI16x8AddSaturateU(node);
1931 : case IrOpcode::kI16x8SubSaturateU:
1932 10 : return MarkAsSimd128(node), VisitI16x8SubSaturateU(node);
1933 : case IrOpcode::kI16x8MinU:
1934 10 : return MarkAsSimd128(node), VisitI16x8MinU(node);
1935 : case IrOpcode::kI16x8MaxU:
1936 10 : return MarkAsSimd128(node), VisitI16x8MaxU(node);
1937 : case IrOpcode::kI16x8GtU:
1938 20 : return MarkAsSimd128(node), VisitI16x8GtU(node);
1939 : case IrOpcode::kI16x8GeU:
1940 20 : return MarkAsSimd128(node), VisitI16x8GeU(node);
1941 : case IrOpcode::kI8x16Splat:
1942 720 : return MarkAsSimd128(node), VisitI8x16Splat(node);
1943 : case IrOpcode::kI8x16ExtractLane:
1944 9880 : return MarkAsWord32(node), VisitI8x16ExtractLane(node);
1945 : case IrOpcode::kI8x16ReplaceLane:
1946 200 : return MarkAsSimd128(node), VisitI8x16ReplaceLane(node);
1947 : case IrOpcode::kI8x16Neg:
1948 10 : return MarkAsSimd128(node), VisitI8x16Neg(node);
1949 : case IrOpcode::kI8x16Shl:
1950 70 : return MarkAsSimd128(node), VisitI8x16Shl(node);
1951 : case IrOpcode::kI8x16ShrS:
1952 70 : return MarkAsSimd128(node), VisitI8x16ShrS(node);
1953 : case IrOpcode::kI8x16SConvertI16x8:
1954 10 : return MarkAsSimd128(node), VisitI8x16SConvertI16x8(node);
1955 : case IrOpcode::kI8x16Add:
1956 10 : return MarkAsSimd128(node), VisitI8x16Add(node);
1957 : case IrOpcode::kI8x16AddSaturateS:
1958 10 : return MarkAsSimd128(node), VisitI8x16AddSaturateS(node);
1959 : case IrOpcode::kI8x16Sub:
1960 10 : return MarkAsSimd128(node), VisitI8x16Sub(node);
1961 : case IrOpcode::kI8x16SubSaturateS:
1962 10 : return MarkAsSimd128(node), VisitI8x16SubSaturateS(node);
1963 : case IrOpcode::kI8x16Mul:
1964 10 : return MarkAsSimd128(node), VisitI8x16Mul(node);
1965 : case IrOpcode::kI8x16MinS:
1966 10 : return MarkAsSimd128(node), VisitI8x16MinS(node);
1967 : case IrOpcode::kI8x16MaxS:
1968 10 : return MarkAsSimd128(node), VisitI8x16MaxS(node);
1969 : case IrOpcode::kI8x16Eq:
1970 30 : return MarkAsSimd128(node), VisitI8x16Eq(node);
1971 : case IrOpcode::kI8x16Ne:
1972 35 : return MarkAsSimd128(node), VisitI8x16Ne(node);
1973 : case IrOpcode::kI8x16GtS:
1974 20 : return MarkAsSimd128(node), VisitI8x16GtS(node);
1975 : case IrOpcode::kI8x16GeS:
1976 20 : return MarkAsSimd128(node), VisitI8x16GeS(node);
1977 : case IrOpcode::kI8x16ShrU:
1978 70 : return MarkAsSimd128(node), VisitI8x16ShrU(node);
1979 : case IrOpcode::kI8x16UConvertI16x8:
1980 10 : return MarkAsSimd128(node), VisitI8x16UConvertI16x8(node);
1981 : case IrOpcode::kI8x16AddSaturateU:
1982 10 : return MarkAsSimd128(node), VisitI8x16AddSaturateU(node);
1983 : case IrOpcode::kI8x16SubSaturateU:
1984 10 : return MarkAsSimd128(node), VisitI8x16SubSaturateU(node);
1985 : case IrOpcode::kI8x16MinU:
1986 10 : return MarkAsSimd128(node), VisitI8x16MinU(node);
1987 : case IrOpcode::kI8x16MaxU:
1988 10 : return MarkAsSimd128(node), VisitI8x16MaxU(node);
1989 : case IrOpcode::kI8x16GtU:
1990 20 : return MarkAsSimd128(node), VisitI8x16GtU(node);
1991 : case IrOpcode::kI8x16GeU:
1992 20 : return MarkAsSimd128(node), VisitI16x8GeU(node);
1993 : case IrOpcode::kS128Zero:
1994 18 : return MarkAsSimd128(node), VisitS128Zero(node);
1995 : case IrOpcode::kS128And:
1996 10 : return MarkAsSimd128(node), VisitS128And(node);
1997 : case IrOpcode::kS128Or:
1998 10 : return MarkAsSimd128(node), VisitS128Or(node);
1999 : case IrOpcode::kS128Xor:
2000 10 : return MarkAsSimd128(node), VisitS128Xor(node);
2001 : case IrOpcode::kS128Not:
2002 10 : return MarkAsSimd128(node), VisitS128Not(node);
2003 : case IrOpcode::kS128Select:
2004 35 : return MarkAsSimd128(node), VisitS128Select(node);
2005 : case IrOpcode::kS8x16Shuffle:
2006 16310 : return MarkAsSimd128(node), VisitS8x16Shuffle(node);
2007 : case IrOpcode::kS1x4AnyTrue:
2008 45 : return MarkAsWord32(node), VisitS1x4AnyTrue(node);
2009 : case IrOpcode::kS1x4AllTrue:
2010 45 : return MarkAsWord32(node), VisitS1x4AllTrue(node);
2011 : case IrOpcode::kS1x8AnyTrue:
2012 45 : return MarkAsWord32(node), VisitS1x8AnyTrue(node);
2013 : case IrOpcode::kS1x8AllTrue:
2014 45 : return MarkAsWord32(node), VisitS1x8AllTrue(node);
2015 : case IrOpcode::kS1x16AnyTrue:
2016 45 : return MarkAsWord32(node), VisitS1x16AnyTrue(node);
2017 : case IrOpcode::kS1x16AllTrue:
2018 45 : return MarkAsWord32(node), VisitS1x16AllTrue(node);
2019 : default:
2020 0 : FATAL("Unexpected operator #%d:%s @ node #%d", node->opcode(),
2021 0 : node->op()->mnemonic(), node->id());
2022 : break;
2023 : }
2024 : }
2025 :
2026 0 : void InstructionSelector::EmitWordPoisonOnSpeculation(Node* node) {
2027 0 : if (poisoning_level_ != PoisoningMitigationLevel::kDontPoison) {
2028 : OperandGenerator g(this);
2029 0 : Node* input_node = NodeProperties::GetValueInput(node, 0);
2030 0 : InstructionOperand input = g.UseRegister(input_node);
2031 0 : InstructionOperand output = g.DefineSameAsFirst(node);
2032 0 : Emit(kArchWordPoisonOnSpeculation, output, input);
2033 : } else {
2034 0 : EmitIdentity(node);
2035 : }
2036 0 : }
2037 :
2038 0 : void InstructionSelector::VisitWord32PoisonOnSpeculation(Node* node) {
2039 0 : EmitWordPoisonOnSpeculation(node);
2040 0 : }
2041 :
2042 0 : void InstructionSelector::VisitWord64PoisonOnSpeculation(Node* node) {
2043 0 : EmitWordPoisonOnSpeculation(node);
2044 0 : }
2045 :
2046 0 : void InstructionSelector::VisitTaggedPoisonOnSpeculation(Node* node) {
2047 0 : EmitWordPoisonOnSpeculation(node);
2048 0 : }
2049 :
2050 1 : void InstructionSelector::VisitLoadStackPointer(Node* node) {
2051 : OperandGenerator g(this);
2052 1 : Emit(kArchStackPointer, g.DefineAsRegister(node));
2053 1 : }
2054 :
2055 30547 : void InstructionSelector::VisitLoadFramePointer(Node* node) {
2056 : OperandGenerator g(this);
2057 30547 : Emit(kArchFramePointer, g.DefineAsRegister(node));
2058 30547 : }
2059 :
2060 49229 : void InstructionSelector::VisitLoadParentFramePointer(Node* node) {
2061 : OperandGenerator g(this);
2062 49229 : Emit(kArchParentFramePointer, g.DefineAsRegister(node));
2063 49229 : }
2064 :
2065 0 : void InstructionSelector::VisitFloat64Acos(Node* node) {
2066 117 : VisitFloat64Ieee754Unop(node, kIeee754Float64Acos);
2067 0 : }
2068 :
2069 0 : void InstructionSelector::VisitFloat64Acosh(Node* node) {
2070 117 : VisitFloat64Ieee754Unop(node, kIeee754Float64Acosh);
2071 0 : }
2072 :
2073 0 : void InstructionSelector::VisitFloat64Asin(Node* node) {
2074 117 : VisitFloat64Ieee754Unop(node, kIeee754Float64Asin);
2075 0 : }
2076 :
2077 0 : void InstructionSelector::VisitFloat64Asinh(Node* node) {
2078 117 : VisitFloat64Ieee754Unop(node, kIeee754Float64Asinh);
2079 0 : }
2080 :
2081 0 : void InstructionSelector::VisitFloat64Atan(Node* node) {
2082 137 : VisitFloat64Ieee754Unop(node, kIeee754Float64Atan);
2083 0 : }
2084 :
2085 0 : void InstructionSelector::VisitFloat64Atanh(Node* node) {
2086 117 : VisitFloat64Ieee754Unop(node, kIeee754Float64Atanh);
2087 0 : }
2088 :
2089 0 : void InstructionSelector::VisitFloat64Atan2(Node* node) {
2090 134 : VisitFloat64Ieee754Binop(node, kIeee754Float64Atan2);
2091 0 : }
2092 :
2093 0 : void InstructionSelector::VisitFloat64Cbrt(Node* node) {
2094 117 : VisitFloat64Ieee754Unop(node, kIeee754Float64Cbrt);
2095 0 : }
2096 :
2097 0 : void InstructionSelector::VisitFloat64Cos(Node* node) {
2098 295 : VisitFloat64Ieee754Unop(node, kIeee754Float64Cos);
2099 0 : }
2100 :
2101 0 : void InstructionSelector::VisitFloat64Cosh(Node* node) {
2102 124 : VisitFloat64Ieee754Unop(node, kIeee754Float64Cosh);
2103 0 : }
2104 :
2105 0 : void InstructionSelector::VisitFloat64Exp(Node* node) {
2106 152 : VisitFloat64Ieee754Unop(node, kIeee754Float64Exp);
2107 0 : }
2108 :
2109 0 : void InstructionSelector::VisitFloat64Expm1(Node* node) {
2110 124 : VisitFloat64Ieee754Unop(node, kIeee754Float64Expm1);
2111 0 : }
2112 :
2113 0 : void InstructionSelector::VisitFloat64Log(Node* node) {
2114 288 : VisitFloat64Ieee754Unop(node, kIeee754Float64Log);
2115 0 : }
2116 :
2117 0 : void InstructionSelector::VisitFloat64Log1p(Node* node) {
2118 117 : VisitFloat64Ieee754Unop(node, kIeee754Float64Log1p);
2119 0 : }
2120 :
2121 0 : void InstructionSelector::VisitFloat64Log2(Node* node) {
2122 117 : VisitFloat64Ieee754Unop(node, kIeee754Float64Log2);
2123 0 : }
2124 :
2125 0 : void InstructionSelector::VisitFloat64Log10(Node* node) {
2126 117 : VisitFloat64Ieee754Unop(node, kIeee754Float64Log10);
2127 0 : }
2128 :
2129 0 : void InstructionSelector::VisitFloat64Pow(Node* node) {
2130 342 : VisitFloat64Ieee754Binop(node, kIeee754Float64Pow);
2131 0 : }
2132 :
2133 0 : void InstructionSelector::VisitFloat64Sin(Node* node) {
2134 298 : VisitFloat64Ieee754Unop(node, kIeee754Float64Sin);
2135 0 : }
2136 :
2137 0 : void InstructionSelector::VisitFloat64Sinh(Node* node) {
2138 124 : VisitFloat64Ieee754Unop(node, kIeee754Float64Sinh);
2139 0 : }
2140 :
2141 0 : void InstructionSelector::VisitFloat64Tan(Node* node) {
2142 173 : VisitFloat64Ieee754Unop(node, kIeee754Float64Tan);
2143 0 : }
2144 :
2145 0 : void InstructionSelector::VisitFloat64Tanh(Node* node) {
2146 124 : VisitFloat64Ieee754Unop(node, kIeee754Float64Tanh);
2147 0 : }
2148 :
2149 226051 : void InstructionSelector::EmitTableSwitch(const SwitchInfo& sw,
2150 304 : InstructionOperand& index_operand) {
2151 : OperandGenerator g(this);
2152 304 : size_t input_count = 2 + sw.value_range();
2153 : DCHECK_LE(sw.value_range(), std::numeric_limits<size_t>::max() - 2);
2154 : auto* inputs = zone()->NewArray<InstructionOperand>(input_count);
2155 304 : inputs[0] = index_operand;
2156 304 : InstructionOperand default_operand = g.Label(sw.default_branch());
2157 304 : std::fill(&inputs[1], &inputs[input_count], default_operand);
2158 225443 : for (const CaseInfo& c : sw.CasesUnsorted()) {
2159 449670 : size_t value = c.value - sw.min_value();
2160 : DCHECK_LE(0u, value);
2161 : DCHECK_LT(value + 2, input_count);
2162 224835 : inputs[value + 2] = g.Label(c.branch);
2163 : }
2164 304 : Emit(kArchTableSwitch, 0, nullptr, input_count, inputs, 0, nullptr);
2165 304 : }
2166 :
2167 0 : void InstructionSelector::EmitLookupSwitch(const SwitchInfo& sw,
2168 0 : InstructionOperand& value_operand) {
2169 : OperandGenerator g(this);
2170 0 : std::vector<CaseInfo> cases = sw.CasesSortedByOriginalOrder();
2171 0 : size_t input_count = 2 + sw.case_count() * 2;
2172 : DCHECK_LE(sw.case_count(), (std::numeric_limits<size_t>::max() - 2) / 2);
2173 : auto* inputs = zone()->NewArray<InstructionOperand>(input_count);
2174 0 : inputs[0] = value_operand;
2175 0 : inputs[1] = g.Label(sw.default_branch());
2176 0 : for (size_t index = 0; index < cases.size(); ++index) {
2177 : const CaseInfo& c = cases[index];
2178 0 : inputs[index * 2 + 2 + 0] = g.TempImmediate(c.value);
2179 0 : inputs[index * 2 + 2 + 1] = g.Label(c.branch);
2180 : }
2181 0 : Emit(kArchLookupSwitch, 0, nullptr, input_count, inputs, 0, nullptr);
2182 0 : }
2183 :
2184 39507 : void InstructionSelector::EmitBinarySearchSwitch(
2185 158027 : const SwitchInfo& sw, InstructionOperand& value_operand) {
2186 : OperandGenerator g(this);
2187 39507 : size_t input_count = 2 + sw.case_count() * 2;
2188 : DCHECK_LE(sw.case_count(), (std::numeric_limits<size_t>::max() - 2) / 2);
2189 : auto* inputs = zone()->NewArray<InstructionOperand>(input_count);
2190 39507 : inputs[0] = value_operand;
2191 79014 : inputs[1] = g.Label(sw.default_branch());
2192 39506 : std::vector<CaseInfo> cases = sw.CasesSortedByValue();
2193 : std::stable_sort(cases.begin(), cases.end(),
2194 39507 : [](CaseInfo a, CaseInfo b) { return a.value < b.value; });
2195 554323 : for (size_t index = 0; index < cases.size(); ++index) {
2196 : const CaseInfo& c = cases[index];
2197 217901 : inputs[index * 2 + 2 + 0] = g.TempImmediate(c.value);
2198 217901 : inputs[index * 2 + 2 + 1] = g.Label(c.branch);
2199 : }
2200 39507 : Emit(kArchBinarySearchSwitch, 0, nullptr, input_count, inputs, 0, nullptr);
2201 39507 : }
2202 :
2203 0 : void InstructionSelector::VisitBitcastTaggedToWord(Node* node) {
2204 1274153 : EmitIdentity(node);
2205 0 : }
2206 :
2207 338456 : void InstructionSelector::VisitBitcastWordToTagged(Node* node) {
2208 : OperandGenerator g(this);
2209 338456 : Emit(kArchNop, g.DefineSameAsFirst(node), g.Use(node->InputAt(0)));
2210 338458 : }
2211 :
2212 : // 32 bit targets do not implement the following instructions.
2213 : #if V8_TARGET_ARCH_32_BIT
2214 :
2215 : void InstructionSelector::VisitWord64And(Node* node) { UNIMPLEMENTED(); }
2216 :
2217 : void InstructionSelector::VisitWord64Or(Node* node) { UNIMPLEMENTED(); }
2218 :
2219 : void InstructionSelector::VisitWord64Xor(Node* node) { UNIMPLEMENTED(); }
2220 :
2221 : void InstructionSelector::VisitWord64Shl(Node* node) { UNIMPLEMENTED(); }
2222 :
2223 : void InstructionSelector::VisitWord64Shr(Node* node) { UNIMPLEMENTED(); }
2224 :
2225 : void InstructionSelector::VisitWord64Sar(Node* node) { UNIMPLEMENTED(); }
2226 :
2227 : void InstructionSelector::VisitWord64Ror(Node* node) { UNIMPLEMENTED(); }
2228 :
2229 : void InstructionSelector::VisitWord64Clz(Node* node) { UNIMPLEMENTED(); }
2230 :
2231 : void InstructionSelector::VisitWord64Ctz(Node* node) { UNIMPLEMENTED(); }
2232 :
2233 : void InstructionSelector::VisitWord64ReverseBits(Node* node) {
2234 : UNIMPLEMENTED();
2235 : }
2236 :
2237 : void InstructionSelector::VisitWord64Popcnt(Node* node) { UNIMPLEMENTED(); }
2238 :
2239 : void InstructionSelector::VisitWord64Equal(Node* node) { UNIMPLEMENTED(); }
2240 :
2241 : void InstructionSelector::VisitInt64Add(Node* node) { UNIMPLEMENTED(); }
2242 :
2243 : void InstructionSelector::VisitInt64AddWithOverflow(Node* node) {
2244 : UNIMPLEMENTED();
2245 : }
2246 :
2247 : void InstructionSelector::VisitInt64Sub(Node* node) { UNIMPLEMENTED(); }
2248 :
2249 : void InstructionSelector::VisitInt64SubWithOverflow(Node* node) {
2250 : UNIMPLEMENTED();
2251 : }
2252 :
2253 : void InstructionSelector::VisitInt64Mul(Node* node) { UNIMPLEMENTED(); }
2254 :
2255 : void InstructionSelector::VisitInt64Div(Node* node) { UNIMPLEMENTED(); }
2256 :
2257 : void InstructionSelector::VisitInt64LessThan(Node* node) { UNIMPLEMENTED(); }
2258 :
2259 : void InstructionSelector::VisitInt64LessThanOrEqual(Node* node) {
2260 : UNIMPLEMENTED();
2261 : }
2262 :
2263 : void InstructionSelector::VisitUint64Div(Node* node) { UNIMPLEMENTED(); }
2264 :
2265 : void InstructionSelector::VisitInt64Mod(Node* node) { UNIMPLEMENTED(); }
2266 :
2267 : void InstructionSelector::VisitUint64LessThan(Node* node) { UNIMPLEMENTED(); }
2268 :
2269 : void InstructionSelector::VisitUint64LessThanOrEqual(Node* node) {
2270 : UNIMPLEMENTED();
2271 : }
2272 :
2273 : void InstructionSelector::VisitUint64Mod(Node* node) { UNIMPLEMENTED(); }
2274 :
2275 : void InstructionSelector::VisitChangeInt32ToInt64(Node* node) {
2276 : UNIMPLEMENTED();
2277 : }
2278 :
2279 : void InstructionSelector::VisitChangeInt64ToFloat64(Node* node) {
2280 : UNIMPLEMENTED();
2281 : }
2282 :
2283 : void InstructionSelector::VisitChangeUint32ToUint64(Node* node) {
2284 : UNIMPLEMENTED();
2285 : }
2286 :
2287 : void InstructionSelector::VisitChangeFloat64ToInt64(Node* node) {
2288 : UNIMPLEMENTED();
2289 : }
2290 :
2291 : void InstructionSelector::VisitChangeFloat64ToUint64(Node* node) {
2292 : UNIMPLEMENTED();
2293 : }
2294 :
2295 : void InstructionSelector::VisitTruncateFloat64ToInt64(Node* node) {
2296 : UNIMPLEMENTED();
2297 : }
2298 :
2299 : void InstructionSelector::VisitTryTruncateFloat32ToInt64(Node* node) {
2300 : UNIMPLEMENTED();
2301 : }
2302 :
2303 : void InstructionSelector::VisitTryTruncateFloat64ToInt64(Node* node) {
2304 : UNIMPLEMENTED();
2305 : }
2306 :
2307 : void InstructionSelector::VisitTryTruncateFloat32ToUint64(Node* node) {
2308 : UNIMPLEMENTED();
2309 : }
2310 :
2311 : void InstructionSelector::VisitTryTruncateFloat64ToUint64(Node* node) {
2312 : UNIMPLEMENTED();
2313 : }
2314 :
2315 : void InstructionSelector::VisitTruncateInt64ToInt32(Node* node) {
2316 : UNIMPLEMENTED();
2317 : }
2318 :
2319 : void InstructionSelector::VisitRoundInt64ToFloat32(Node* node) {
2320 : UNIMPLEMENTED();
2321 : }
2322 :
2323 : void InstructionSelector::VisitRoundInt64ToFloat64(Node* node) {
2324 : UNIMPLEMENTED();
2325 : }
2326 :
2327 : void InstructionSelector::VisitRoundUint64ToFloat32(Node* node) {
2328 : UNIMPLEMENTED();
2329 : }
2330 :
2331 : void InstructionSelector::VisitRoundUint64ToFloat64(Node* node) {
2332 : UNIMPLEMENTED();
2333 : }
2334 :
2335 : void InstructionSelector::VisitBitcastFloat64ToInt64(Node* node) {
2336 : UNIMPLEMENTED();
2337 : }
2338 :
2339 : void InstructionSelector::VisitBitcastInt64ToFloat64(Node* node) {
2340 : UNIMPLEMENTED();
2341 : }
2342 :
2343 : void InstructionSelector::VisitSignExtendWord8ToInt64(Node* node) {
2344 : UNIMPLEMENTED();
2345 : }
2346 :
2347 : void InstructionSelector::VisitSignExtendWord16ToInt64(Node* node) {
2348 : UNIMPLEMENTED();
2349 : }
2350 :
2351 : void InstructionSelector::VisitSignExtendWord32ToInt64(Node* node) {
2352 : UNIMPLEMENTED();
2353 : }
2354 : #endif // V8_TARGET_ARCH_32_BIT
2355 :
2356 : // 64 bit targets do not implement the following instructions.
2357 : #if V8_TARGET_ARCH_64_BIT
2358 0 : void InstructionSelector::VisitInt32PairAdd(Node* node) { UNIMPLEMENTED(); }
2359 :
2360 0 : void InstructionSelector::VisitInt32PairSub(Node* node) { UNIMPLEMENTED(); }
2361 :
2362 0 : void InstructionSelector::VisitInt32PairMul(Node* node) { UNIMPLEMENTED(); }
2363 :
2364 0 : void InstructionSelector::VisitWord32PairShl(Node* node) { UNIMPLEMENTED(); }
2365 :
2366 0 : void InstructionSelector::VisitWord32PairShr(Node* node) { UNIMPLEMENTED(); }
2367 :
2368 0 : void InstructionSelector::VisitWord32PairSar(Node* node) { UNIMPLEMENTED(); }
2369 : #endif // V8_TARGET_ARCH_64_BIT
2370 :
2371 : #if !V8_TARGET_ARCH_IA32 && !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_MIPS
2372 0 : void InstructionSelector::VisitWord32AtomicPairLoad(Node* node) {
2373 0 : UNIMPLEMENTED();
2374 : }
2375 :
2376 0 : void InstructionSelector::VisitWord32AtomicPairStore(Node* node) {
2377 0 : UNIMPLEMENTED();
2378 : }
2379 :
2380 0 : void InstructionSelector::VisitWord32AtomicPairAdd(Node* node) {
2381 0 : UNIMPLEMENTED();
2382 : }
2383 :
2384 0 : void InstructionSelector::VisitWord32AtomicPairSub(Node* node) {
2385 0 : UNIMPLEMENTED();
2386 : }
2387 :
2388 0 : void InstructionSelector::VisitWord32AtomicPairAnd(Node* node) {
2389 0 : UNIMPLEMENTED();
2390 : }
2391 :
2392 0 : void InstructionSelector::VisitWord32AtomicPairOr(Node* node) {
2393 0 : UNIMPLEMENTED();
2394 : }
2395 :
2396 0 : void InstructionSelector::VisitWord32AtomicPairXor(Node* node) {
2397 0 : UNIMPLEMENTED();
2398 : }
2399 :
2400 0 : void InstructionSelector::VisitWord32AtomicPairExchange(Node* node) {
2401 0 : UNIMPLEMENTED();
2402 : }
2403 :
2404 0 : void InstructionSelector::VisitWord32AtomicPairCompareExchange(Node* node) {
2405 0 : UNIMPLEMENTED();
2406 : }
2407 : #endif // !V8_TARGET_ARCH_IA32 && !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_MIPS
2408 :
2409 : #if !V8_TARGET_ARCH_X64 && !V8_TARGET_ARCH_ARM64 && !V8_TARGET_ARCH_MIPS64 && \
2410 : !V8_TARGET_ARCH_S390 && !V8_TARGET_ARCH_PPC
2411 : void InstructionSelector::VisitWord64AtomicLoad(Node* node) { UNIMPLEMENTED(); }
2412 :
2413 : void InstructionSelector::VisitWord64AtomicStore(Node* node) {
2414 : UNIMPLEMENTED();
2415 : }
2416 :
2417 : void InstructionSelector::VisitWord64AtomicAdd(Node* node) { UNIMPLEMENTED(); }
2418 :
2419 : void InstructionSelector::VisitWord64AtomicSub(Node* node) { UNIMPLEMENTED(); }
2420 :
2421 : void InstructionSelector::VisitWord64AtomicAnd(Node* node) { UNIMPLEMENTED(); }
2422 :
2423 : void InstructionSelector::VisitWord64AtomicOr(Node* node) { UNIMPLEMENTED(); }
2424 :
2425 : void InstructionSelector::VisitWord64AtomicXor(Node* node) { UNIMPLEMENTED(); }
2426 :
2427 : void InstructionSelector::VisitWord64AtomicExchange(Node* node) {
2428 : UNIMPLEMENTED();
2429 : }
2430 :
2431 : void InstructionSelector::VisitWord64AtomicCompareExchange(Node* node) {
2432 : UNIMPLEMENTED();
2433 : }
2434 : #endif // !V8_TARGET_ARCH_X64 && !V8_TARGET_ARCH_ARM64 && !V8_TARGET_ARCH_PPC
2435 : // !V8_TARGET_ARCH_MIPS64 && !V8_TARGET_ARCH_S390
2436 :
2437 1 : void InstructionSelector::VisitFinishRegion(Node* node) { EmitIdentity(node); }
2438 :
2439 14012195 : void InstructionSelector::VisitParameter(Node* node) {
2440 : OperandGenerator g(this);
2441 3477128 : int index = ParameterIndexOf(node->op());
2442 : InstructionOperand op =
2443 3477210 : linkage()->ParameterHasSecondaryLocation(index)
2444 : ? g.DefineAsDualLocation(
2445 : node, linkage()->GetParameterLocation(index),
2446 207169 : linkage()->GetParameterSecondaryLocation(index))
2447 6954347 : : g.DefineAsLocation(node, linkage()->GetParameterLocation(index));
2448 :
2449 3477152 : Emit(kArchNop, op);
2450 3477159 : }
2451 :
2452 : namespace {
2453 : LinkageLocation ExceptionLocation() {
2454 : return LinkageLocation::ForRegister(kReturnRegister0.code(),
2455 : MachineType::IntPtr());
2456 : }
2457 : } // namespace
2458 :
2459 178588 : void InstructionSelector::VisitIfException(Node* node) {
2460 : OperandGenerator g(this);
2461 : DCHECK_EQ(IrOpcode::kCall, node->InputAt(1)->opcode());
2462 178588 : Emit(kArchNop, g.DefineAsLocation(node, ExceptionLocation()));
2463 178588 : }
2464 :
2465 68133 : void InstructionSelector::VisitOsrValue(Node* node) {
2466 : OperandGenerator g(this);
2467 22711 : int index = OsrValueIndexOf(node->op());
2468 : Emit(kArchNop,
2469 22711 : g.DefineAsLocation(node, linkage()->GetOsrValueLocation(index)));
2470 22711 : }
2471 :
2472 4339422 : void InstructionSelector::VisitPhi(Node* node) {
2473 2169711 : const int input_count = node->op()->ValueInputCount();
2474 : DCHECK_EQ(input_count, current_block_->PredecessorCount());
2475 : PhiInstruction* phi = new (instruction_zone())
2476 : PhiInstruction(instruction_zone(), GetVirtualRegister(node),
2477 4339443 : static_cast<size_t>(input_count));
2478 : sequence()
2479 : ->InstructionBlockAt(RpoNumber::FromInt(current_block_->rpo_number()))
2480 4339422 : ->AddPhi(phi);
2481 7354886 : for (int i = 0; i < input_count; ++i) {
2482 : Node* const input = node->InputAt(i);
2483 : MarkAsUsed(input);
2484 5185156 : phi->SetInput(static_cast<size_t>(i), GetVirtualRegister(input));
2485 : }
2486 2169730 : }
2487 :
2488 669381 : void InstructionSelector::VisitProjection(Node* node) {
2489 : OperandGenerator g(this);
2490 343179 : Node* value = node->InputAt(0);
2491 343179 : switch (value->opcode()) {
2492 : case IrOpcode::kInt32AddWithOverflow:
2493 : case IrOpcode::kInt32SubWithOverflow:
2494 : case IrOpcode::kInt32MulWithOverflow:
2495 : case IrOpcode::kInt64AddWithOverflow:
2496 : case IrOpcode::kInt64SubWithOverflow:
2497 : case IrOpcode::kTryTruncateFloat32ToInt64:
2498 : case IrOpcode::kTryTruncateFloat64ToInt64:
2499 : case IrOpcode::kTryTruncateFloat32ToUint64:
2500 : case IrOpcode::kTryTruncateFloat64ToUint64:
2501 : case IrOpcode::kInt32PairAdd:
2502 : case IrOpcode::kInt32PairSub:
2503 : case IrOpcode::kInt32PairMul:
2504 : case IrOpcode::kWord32PairShl:
2505 : case IrOpcode::kWord32PairShr:
2506 : case IrOpcode::kWord32PairSar:
2507 : case IrOpcode::kInt32AbsWithOverflow:
2508 : case IrOpcode::kInt64AbsWithOverflow:
2509 326202 : if (ProjectionIndexOf(node->op()) == 0u) {
2510 205843 : Emit(kArchNop, g.DefineSameAsFirst(node), g.Use(value));
2511 : } else {
2512 : DCHECK_EQ(1u, ProjectionIndexOf(node->op()));
2513 : MarkAsUsed(value);
2514 : }
2515 : break;
2516 : default:
2517 : break;
2518 : }
2519 343179 : }
2520 :
2521 13501992 : void InstructionSelector::VisitConstant(Node* node) {
2522 : // We must emit a NOP here because every live range needs a defining
2523 : // instruction in the register allocator.
2524 : OperandGenerator g(this);
2525 13501992 : Emit(kArchNop, g.DefineAsConstant(node));
2526 13502248 : }
2527 :
2528 21423338 : void InstructionSelector::VisitCall(Node* node, BasicBlock* handler) {
2529 : OperandGenerator g(this);
2530 13348820 : auto call_descriptor = CallDescriptorOf(node->op());
2531 :
2532 : FrameStateDescriptor* frame_state_descriptor = nullptr;
2533 5355836 : if (call_descriptor->NeedsFrameState()) {
2534 : frame_state_descriptor = GetFrameStateDescriptor(
2535 5221788 : node->InputAt(static_cast<int>(call_descriptor->InputCount())));
2536 : }
2537 :
2538 5355831 : CallBuffer buffer(zone(), call_descriptor, frame_state_descriptor);
2539 : CallDescriptor::Flags flags = call_descriptor->flags();
2540 :
2541 : // Compute InstructionOperands for inputs and outputs.
2542 : // TODO(turbofan): on some architectures it's probably better to use
2543 : // the code object in a register if there are multiple uses of it.
2544 : // Improve constant pool and the heuristics in the register allocator
2545 : // for where to emit constants.
2546 : CallBufferFlags call_buffer_flags(kCallCodeImmediate | kCallAddressImmediate);
2547 5355891 : if (flags & CallDescriptor::kAllowCallThroughSlot) {
2548 : // TODO(v8:6666): Remove kAllowCallThroughSlot and use a pc-relative call
2549 : // instead once builtins are embedded in every build configuration.
2550 : call_buffer_flags |= kAllowCallThroughSlot;
2551 : #ifndef V8_TARGET_ARCH_32_BIT
2552 : // kAllowCallThroughSlot is only supported on ia32.
2553 0 : UNREACHABLE();
2554 : #endif
2555 : }
2556 5355891 : InitializeCallBuffer(node, &buffer, call_buffer_flags, false);
2557 :
2558 5355857 : EmitPrepareArguments(&(buffer.pushed_nodes), call_descriptor, node);
2559 :
2560 : // Pass label of exception handler block.
2561 5355825 : if (handler) {
2562 : DCHECK_EQ(IrOpcode::kIfException, handler->front()->opcode());
2563 : flags |= CallDescriptor::kHasExceptionHandler;
2564 378784 : buffer.instruction_args.push_back(g.Label(handler));
2565 : }
2566 :
2567 : // Select the appropriate opcode based on the call type.
2568 : InstructionCode opcode = kArchNop;
2569 5355825 : switch (call_descriptor->kind()) {
2570 : case CallDescriptor::kCallAddress:
2571 26287 : opcode = kArchCallCFunction | MiscField::encode(static_cast<int>(
2572 26287 : call_descriptor->ParameterCount()));
2573 26287 : break;
2574 : case CallDescriptor::kCallCodeObject:
2575 4040780 : opcode = kArchCallCodeObject | MiscField::encode(flags);
2576 4040780 : break;
2577 : case CallDescriptor::kCallJSFunction:
2578 105789 : opcode = kArchCallJSFunction | MiscField::encode(flags);
2579 105789 : break;
2580 : case CallDescriptor::kCallWasmFunction:
2581 : case CallDescriptor::kCallWasmImportWrapper:
2582 1171172 : opcode = kArchCallWasmFunction | MiscField::encode(flags);
2583 1171172 : break;
2584 : case CallDescriptor::kCallBuiltinPointer:
2585 11790 : opcode = kArchCallBuiltinPointer | MiscField::encode(flags);
2586 11790 : break;
2587 : }
2588 :
2589 : // Emit the call instruction.
2590 5355825 : size_t const output_count = buffer.outputs.size();
2591 5355825 : auto* outputs = output_count ? &buffer.outputs.front() : nullptr;
2592 : Instruction* call_instr =
2593 : Emit(opcode, output_count, outputs, buffer.instruction_args.size(),
2594 10711650 : &buffer.instruction_args.front());
2595 10711726 : if (instruction_selection_failed()) return;
2596 : call_instr->MarkAsCall();
2597 :
2598 5355878 : EmitPrepareResults(&(buffer.output_nodes), call_descriptor, node);
2599 : }
2600 :
2601 677 : void InstructionSelector::VisitCallWithCallerSavedRegisters(
2602 677 : Node* node, BasicBlock* handler) {
2603 : OperandGenerator g(this);
2604 677 : const auto fp_mode = CallDescriptorOf(node->op())->get_save_fp_mode();
2605 677 : Emit(kArchSaveCallerRegisters | MiscField::encode(static_cast<int>(fp_mode)),
2606 677 : g.NoOutput());
2607 677 : VisitCall(node, handler);
2608 677 : Emit(kArchRestoreCallerRegisters |
2609 : MiscField::encode(static_cast<int>(fp_mode)),
2610 677 : g.NoOutput());
2611 677 : }
2612 :
2613 827834 : void InstructionSelector::VisitTailCall(Node* node) {
2614 : OperandGenerator g(this);
2615 236524 : auto call_descriptor = CallDescriptorOf(node->op());
2616 :
2617 : CallDescriptor* caller = linkage()->GetIncomingDescriptor();
2618 : DCHECK(caller->CanTailCall(node));
2619 118262 : const CallDescriptor* callee = CallDescriptorOf(node->op());
2620 118262 : int stack_param_delta = callee->GetStackParameterDelta(caller);
2621 118262 : CallBuffer buffer(zone(), call_descriptor, nullptr);
2622 :
2623 : // Compute InstructionOperands for inputs and outputs.
2624 : CallBufferFlags flags(kCallCodeImmediate | kCallTail);
2625 118262 : if (IsTailCallAddressImmediate()) {
2626 : flags |= kCallAddressImmediate;
2627 : }
2628 118262 : if (callee->flags() & CallDescriptor::kFixedTargetRegister) {
2629 : flags |= kCallFixedTargetRegister;
2630 : }
2631 : DCHECK_EQ(callee->flags() & CallDescriptor::kAllowCallThroughSlot, 0);
2632 118262 : InitializeCallBuffer(node, &buffer, flags, true, stack_param_delta);
2633 :
2634 : // Select the appropriate opcode based on the call type.
2635 : InstructionCode opcode;
2636 : InstructionOperandVector temps(zone());
2637 118262 : if (linkage()->GetIncomingDescriptor()->IsJSFunctionCall()) {
2638 1344 : switch (call_descriptor->kind()) {
2639 : case CallDescriptor::kCallCodeObject:
2640 : opcode = kArchTailCallCodeObjectFromJSFunction;
2641 : break;
2642 : default:
2643 0 : UNREACHABLE();
2644 : return;
2645 : }
2646 1344 : int temps_count = GetTempsCountForTailCallFromJSFunction();
2647 5376 : for (int i = 0; i < temps_count; i++) {
2648 8064 : temps.push_back(g.TempRegister());
2649 : }
2650 : } else {
2651 116918 : switch (call_descriptor->kind()) {
2652 : case CallDescriptor::kCallCodeObject:
2653 : opcode = kArchTailCallCodeObject;
2654 : break;
2655 : case CallDescriptor::kCallAddress:
2656 : opcode = kArchTailCallAddress;
2657 83776 : break;
2658 : case CallDescriptor::kCallWasmFunction:
2659 : opcode = kArchTailCallWasm;
2660 0 : break;
2661 : default:
2662 0 : UNREACHABLE();
2663 : return;
2664 : }
2665 : }
2666 118262 : opcode |= MiscField::encode(call_descriptor->flags());
2667 :
2668 118262 : Emit(kArchPrepareTailCall, g.NoOutput());
2669 :
2670 : // Add an immediate operand that represents the first slot that is unused
2671 : // with respect to the stack pointer that has been updated for the tail call
2672 : // instruction. This is used by backends that need to pad arguments for stack
2673 : // alignment, in order to store an optional slot of padding above the
2674 : // arguments.
2675 118262 : int optional_padding_slot = callee->GetFirstUnusedStackSlot();
2676 236524 : buffer.instruction_args.push_back(g.TempImmediate(optional_padding_slot));
2677 :
2678 : int first_unused_stack_slot =
2679 : (V8_TARGET_ARCH_STORES_RETURN_ADDRESS_ON_STACK ? true : false) +
2680 118262 : stack_param_delta;
2681 236524 : buffer.instruction_args.push_back(g.TempImmediate(first_unused_stack_slot));
2682 :
2683 : // Emit the tailcall instruction.
2684 : Emit(opcode, 0, nullptr, buffer.instruction_args.size(),
2685 : &buffer.instruction_args.front(), temps.size(),
2686 354786 : temps.empty() ? nullptr : &temps.front());
2687 118262 : }
2688 :
2689 8756401 : void InstructionSelector::VisitGoto(BasicBlock* target) {
2690 : // jump to the next block.
2691 : OperandGenerator g(this);
2692 8756401 : Emit(kArchJmp, g.NoOutput(), g.Label(target));
2693 8756395 : }
2694 :
2695 16280832 : void InstructionSelector::VisitReturn(Node* ret) {
2696 : OperandGenerator g(this);
2697 3264614 : const int input_count = linkage()->GetIncomingDescriptor()->ReturnCount() == 0
2698 : ? 1
2699 6497962 : : ret->op()->ValueInputCount();
2700 : DCHECK_GE(input_count, 1);
2701 3264614 : auto value_locations = zone()->NewArray<InstructionOperand>(input_count);
2702 3264828 : Node* pop_count = ret->InputAt(0);
2703 50990 : value_locations[0] = (pop_count->opcode() == IrOpcode::kInt32Constant ||
2704 : pop_count->opcode() == IrOpcode::kInt64Constant)
2705 : ? g.UseImmediate(pop_count)
2706 6478691 : : g.UseRegister(pop_count);
2707 3253745 : for (int i = 1; i < input_count; ++i) {
2708 : value_locations[i] =
2709 6507284 : g.UseLocation(ret->InputAt(i), linkage()->GetReturnLocation(i - 1));
2710 : }
2711 3264756 : Emit(kArchRet, 0, nullptr, input_count, value_locations);
2712 3264745 : }
2713 :
2714 5192374 : void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch,
2715 : BasicBlock* fbranch) {
2716 5192374 : if (NeedsPoisoning(IsSafetyCheckOf(branch->op()))) {
2717 : FlagsContinuation cont =
2718 : FlagsContinuation::ForBranchAndPoison(kNotEqual, tbranch, fbranch);
2719 0 : VisitWordCompareZero(branch, branch->InputAt(0), &cont);
2720 : } else {
2721 : FlagsContinuation cont =
2722 : FlagsContinuation::ForBranch(kNotEqual, tbranch, fbranch);
2723 5192348 : VisitWordCompareZero(branch, branch->InputAt(0), &cont);
2724 : }
2725 5192371 : }
2726 :
2727 114332 : void InstructionSelector::VisitDeoptimizeIf(Node* node) {
2728 114332 : DeoptimizeParameters p = DeoptimizeParametersOf(node->op());
2729 114334 : if (NeedsPoisoning(p.is_safety_check())) {
2730 : FlagsContinuation cont = FlagsContinuation::ForDeoptimizeAndPoison(
2731 : kNotEqual, p.kind(), p.reason(), p.feedback(), node->InputAt(1));
2732 0 : VisitWordCompareZero(node, node->InputAt(0), &cont);
2733 : } else {
2734 : FlagsContinuation cont = FlagsContinuation::ForDeoptimize(
2735 : kNotEqual, p.kind(), p.reason(), p.feedback(), node->InputAt(1));
2736 114334 : VisitWordCompareZero(node, node->InputAt(0), &cont);
2737 : }
2738 114336 : }
2739 :
2740 225975 : void InstructionSelector::VisitDeoptimizeUnless(Node* node) {
2741 225975 : DeoptimizeParameters p = DeoptimizeParametersOf(node->op());
2742 225975 : if (NeedsPoisoning(p.is_safety_check())) {
2743 : FlagsContinuation cont = FlagsContinuation::ForDeoptimizeAndPoison(
2744 : kEqual, p.kind(), p.reason(), p.feedback(), node->InputAt(1));
2745 0 : VisitWordCompareZero(node, node->InputAt(0), &cont);
2746 : } else {
2747 : FlagsContinuation cont = FlagsContinuation::ForDeoptimize(
2748 : kEqual, p.kind(), p.reason(), p.feedback(), node->InputAt(1));
2749 225975 : VisitWordCompareZero(node, node->InputAt(0), &cont);
2750 : }
2751 225975 : }
2752 :
2753 11297 : void InstructionSelector::VisitTrapIf(Node* node, TrapId trap_id) {
2754 : FlagsContinuation cont =
2755 : FlagsContinuation::ForTrap(kNotEqual, trap_id, node->InputAt(1));
2756 11308 : VisitWordCompareZero(node, node->InputAt(0), &cont);
2757 11310 : }
2758 :
2759 35935 : void InstructionSelector::VisitTrapUnless(Node* node, TrapId trap_id) {
2760 : FlagsContinuation cont =
2761 : FlagsContinuation::ForTrap(kEqual, trap_id, node->InputAt(1));
2762 35928 : VisitWordCompareZero(node, node->InputAt(0), &cont);
2763 35937 : }
2764 :
2765 2445004 : void InstructionSelector::EmitIdentity(Node* node) {
2766 : OperandGenerator g(this);
2767 : MarkAsUsed(node->InputAt(0));
2768 2445004 : SetRename(node, node->InputAt(0));
2769 2445027 : }
2770 :
2771 0 : void InstructionSelector::VisitDeoptimize(DeoptimizeKind kind,
2772 : DeoptimizeReason reason,
2773 : VectorSlotPair const& feedback,
2774 : Node* value) {
2775 : EmitDeoptimize(kArchDeoptimize, 0, nullptr, 0, nullptr, kind, reason,
2776 47591 : feedback, value);
2777 0 : }
2778 :
2779 0 : void InstructionSelector::VisitThrow(Node* node) {
2780 : OperandGenerator g(this);
2781 217852 : Emit(kArchThrowTerminator, g.NoOutput());
2782 0 : }
2783 :
2784 0 : void InstructionSelector::VisitDebugBreak(Node* node) {
2785 : OperandGenerator g(this);
2786 133294 : Emit(kArchDebugBreak, g.NoOutput());
2787 0 : }
2788 :
2789 0 : void InstructionSelector::VisitUnreachable(Node* node) {
2790 : OperandGenerator g(this);
2791 859 : Emit(kArchDebugBreak, g.NoOutput());
2792 0 : }
2793 :
2794 0 : void InstructionSelector::VisitDeadValue(Node* node) {
2795 : OperandGenerator g(this);
2796 0 : MarkAsRepresentation(DeadValueRepresentationOf(node->op()), node);
2797 0 : Emit(kArchDebugBreak, g.DefineAsConstant(node));
2798 0 : }
2799 :
2800 5 : void InstructionSelector::VisitComment(Node* node) {
2801 : OperandGenerator g(this);
2802 5 : InstructionOperand operand(g.UseImmediate(node));
2803 5 : Emit(kArchComment, 0, nullptr, 1, &operand);
2804 5 : }
2805 :
2806 0 : void InstructionSelector::VisitUnsafePointerAdd(Node* node) {
2807 : #if V8_TARGET_ARCH_64_BIT
2808 6731 : VisitInt64Add(node);
2809 : #else // V8_TARGET_ARCH_64_BIT
2810 : VisitInt32Add(node);
2811 : #endif // V8_TARGET_ARCH_64_BIT
2812 0 : }
2813 :
2814 9221 : void InstructionSelector::VisitRetain(Node* node) {
2815 : OperandGenerator g(this);
2816 9221 : Emit(kArchNop, g.NoOutput(), g.UseAny(node->InputAt(0)));
2817 9221 : }
2818 :
2819 6001 : bool InstructionSelector::CanProduceSignalingNaN(Node* node) {
2820 : // TODO(jarin) Improve the heuristic here.
2821 11827 : if (node->opcode() == IrOpcode::kFloat64Add ||
2822 11827 : node->opcode() == IrOpcode::kFloat64Sub ||
2823 : node->opcode() == IrOpcode::kFloat64Mul) {
2824 : return false;
2825 : }
2826 0 : return true;
2827 : }
2828 :
2829 3357989 : FrameStateDescriptor* InstructionSelector::GetFrameStateDescriptor(
2830 3357989 : Node* state) {
2831 : DCHECK_EQ(IrOpcode::kFrameState, state->opcode());
2832 : DCHECK_EQ(kFrameStateInputCount, state->InputCount());
2833 3357989 : FrameStateInfo state_info = FrameStateInfoOf(state->op());
2834 :
2835 : int parameters = static_cast<int>(
2836 3357997 : StateValuesAccess(state->InputAt(kFrameStateParametersInput)).size());
2837 : int locals = static_cast<int>(
2838 3358012 : StateValuesAccess(state->InputAt(kFrameStateLocalsInput)).size());
2839 : int stack = static_cast<int>(
2840 3358021 : StateValuesAccess(state->InputAt(kFrameStateStackInput)).size());
2841 :
2842 : DCHECK_EQ(parameters, state_info.parameter_count());
2843 : DCHECK_EQ(locals, state_info.local_count());
2844 :
2845 : FrameStateDescriptor* outer_state = nullptr;
2846 3358028 : Node* outer_node = state->InputAt(kFrameStateOuterStateInput);
2847 3358028 : if (outer_node->opcode() == IrOpcode::kFrameState) {
2848 359202 : outer_state = GetFrameStateDescriptor(outer_node);
2849 : }
2850 :
2851 : return new (instruction_zone()) FrameStateDescriptor(
2852 : instruction_zone(), state_info.type(), state_info.bailout_id(),
2853 : state_info.state_combine(), parameters, locals, stack,
2854 10074088 : state_info.shared_info(), outer_state);
2855 : }
2856 :
2857 : // static
2858 16318 : void InstructionSelector::CanonicalizeShuffle(bool inputs_equal,
2859 : uint8_t* shuffle,
2860 : bool* needs_swap,
2861 : bool* is_swizzle) {
2862 16318 : *needs_swap = false;
2863 : // Inputs equal, then it's a swizzle.
2864 16318 : if (inputs_equal) {
2865 4 : *is_swizzle = true;
2866 : } else {
2867 : // Inputs are distinct; check that both are required.
2868 : bool src0_is_used = false;
2869 : bool src1_is_used = false;
2870 261024 : for (int i = 0; i < kSimd128Size; ++i) {
2871 261024 : if (shuffle[i] < kSimd128Size) {
2872 : src0_is_used = true;
2873 : } else {
2874 : src1_is_used = true;
2875 : }
2876 : }
2877 16314 : if (src0_is_used && !src1_is_used) {
2878 3941 : *is_swizzle = true;
2879 12373 : } else if (src1_is_used && !src0_is_used) {
2880 3056 : *needs_swap = true;
2881 3056 : *is_swizzle = true;
2882 : } else {
2883 9317 : *is_swizzle = false;
2884 : // Canonicalize general 2 input shuffles so that the first input lanes are
2885 : // encountered first. This makes architectural shuffle pattern matching
2886 : // easier, since we only need to consider 1 input ordering instead of 2.
2887 9317 : if (shuffle[0] >= kSimd128Size) {
2888 : // The second operand is used first. Swap inputs and adjust the shuffle.
2889 1291 : *needs_swap = true;
2890 21947 : for (int i = 0; i < kSimd128Size; ++i) {
2891 20656 : shuffle[i] ^= kSimd128Size;
2892 : }
2893 : }
2894 : }
2895 : }
2896 16318 : if (*is_swizzle) {
2897 112016 : for (int i = 0; i < kSimd128Size; ++i) shuffle[i] &= kSimd128Size - 1;
2898 : }
2899 16318 : }
2900 :
2901 16310 : void InstructionSelector::CanonicalizeShuffle(Node* node, uint8_t* shuffle,
2902 : bool* is_swizzle) {
2903 : // Get raw shuffle indices.
2904 16310 : memcpy(shuffle, OpParameter<uint8_t*>(node->op()), kSimd128Size);
2905 : bool needs_swap;
2906 16310 : bool inputs_equal = GetVirtualRegister(node->InputAt(0)) ==
2907 16310 : GetVirtualRegister(node->InputAt(1));
2908 16310 : CanonicalizeShuffle(inputs_equal, shuffle, &needs_swap, is_swizzle);
2909 16310 : if (needs_swap) {
2910 4345 : SwapShuffleInputs(node);
2911 : }
2912 : // Duplicate the first input; for some shuffles on some architectures, it's
2913 : // easiest to implement a swizzle as a shuffle so it might be used.
2914 16310 : if (*is_swizzle) {
2915 6995 : node->ReplaceInput(1, node->InputAt(0));
2916 : }
2917 16310 : }
2918 :
2919 : // static
2920 4945 : void InstructionSelector::SwapShuffleInputs(Node* node) {
2921 : Node* input0 = node->InputAt(0);
2922 : Node* input1 = node->InputAt(1);
2923 4945 : node->ReplaceInput(0, input1);
2924 4945 : node->ReplaceInput(1, input0);
2925 4945 : }
2926 :
2927 : // static
2928 1603 : bool InstructionSelector::TryMatchIdentity(const uint8_t* shuffle) {
2929 13494 : for (int i = 0; i < kSimd128Size; ++i) {
2930 12858 : if (shuffle[i] != i) return false;
2931 : }
2932 : return true;
2933 : }
2934 :
2935 : // static
2936 10083 : bool InstructionSelector::TryMatch32x4Shuffle(const uint8_t* shuffle,
2937 : uint8_t* shuffle32x4) {
2938 24907 : for (int i = 0; i < 4; ++i) {
2939 21351 : if (shuffle[i * 4] % 4 != 0) return false;
2940 45984 : for (int j = 1; j < 4; ++j) {
2941 48515 : if (shuffle[i * 4 + j] - shuffle[i * 4 + j - 1] != 1) return false;
2942 : }
2943 14824 : shuffle32x4[i] = shuffle[i * 4] / 4;
2944 : }
2945 : return true;
2946 : }
2947 :
2948 : // static
2949 6528 : bool InstructionSelector::TryMatch16x8Shuffle(const uint8_t* shuffle,
2950 : uint8_t* shuffle16x8) {
2951 33458 : for (int i = 0; i < 8; ++i) {
2952 30282 : if (shuffle[i * 2] % 2 != 0) return false;
2953 26930 : for (int j = 1; j < 2; ++j) {
2954 28311 : if (shuffle[i * 2 + j] - shuffle[i * 2 + j - 1] != 1) return false;
2955 : }
2956 26930 : shuffle16x8[i] = shuffle[i * 2] / 2;
2957 : }
2958 : return true;
2959 : }
2960 :
2961 : // static
2962 16314 : bool InstructionSelector::TryMatchConcat(const uint8_t* shuffle,
2963 : uint8_t* offset) {
2964 : // Don't match the identity shuffle (e.g. [0 1 2 ... 15]).
2965 16314 : uint8_t start = shuffle[0];
2966 16314 : if (start == 0) return false;
2967 : DCHECK_GT(kSimd128Size, start); // The shuffle should be canonicalized.
2968 : // A concatenation is a series of consecutive indices, with at most one jump
2969 : // in the middle from the last lane to the first.
2970 18068 : for (int i = 1; i < kSimd128Size; ++i) {
2971 27449 : if ((shuffle[i]) != ((shuffle[i - 1] + 1))) {
2972 9682 : if (shuffle[i - 1] != 15) return false;
2973 461 : if (shuffle[i] % kSimd128Size != 0) return false;
2974 : }
2975 : }
2976 602 : *offset = start;
2977 602 : return true;
2978 : }
2979 :
2980 : // static
2981 5133 : bool InstructionSelector::TryMatchBlend(const uint8_t* shuffle) {
2982 13885 : for (int i = 0; i < 16; ++i) {
2983 13743 : if ((shuffle[i] & 0xF) != i) return false;
2984 : }
2985 : return true;
2986 : }
2987 :
2988 : // static
2989 15320 : int32_t InstructionSelector::Pack4Lanes(const uint8_t* shuffle) {
2990 : int32_t result = 0;
2991 76600 : for (int i = 3; i >= 0; --i) {
2992 61280 : result <<= 8;
2993 61280 : result |= shuffle[i];
2994 : }
2995 15320 : return result;
2996 : }
2997 :
2998 5532654 : bool InstructionSelector::NeedsPoisoning(IsSafetyCheck safety_check) const {
2999 5532654 : switch (poisoning_level_) {
3000 : case PoisoningMitigationLevel::kDontPoison:
3001 : return false;
3002 : case PoisoningMitigationLevel::kPoisonAll:
3003 24 : return safety_check != IsSafetyCheck::kNoSafetyCheck;
3004 : case PoisoningMitigationLevel::kPoisonCriticalOnly:
3005 0 : return safety_check == IsSafetyCheck::kCriticalSafetyCheck;
3006 : }
3007 0 : UNREACHABLE();
3008 : }
3009 :
3010 : } // namespace compiler
3011 : } // namespace internal
3012 183867 : } // namespace v8
|