Flutter Engine
The Flutter Engine
graph_intrinsifier.cc
Go to the documentation of this file.
1// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4// Class for intrinsifying functions.
5
18#include "vm/cpu.h"
19#include "vm/flag_list.h"
20
21namespace dart {
22
23DECLARE_FLAG(bool, print_flow_graph);
24DECLARE_FLAG(bool, print_flow_graph_optimized);
25
27 public:
29 : compiler_(compiler), old_is_optimizing_(compiler->is_optimizing()) {
30 compiler_->is_optimizing_ = true;
31 }
33 compiler_->is_optimizing_ = old_is_optimizing_;
34 }
35
36 private:
37 FlowGraphCompiler* compiler_;
38 bool old_is_optimizing_;
39};
40
41namespace compiler {
42
44 // For graph intrinsics we run the linearscan register allocator, which will
45 // pass opt=true for MakeLocationSummary. We therefore also have to ensure
46 // `compiler->is_optimizing()` is set to true during EmitNativeCode.
47 GraphIntrinsicCodeGenScope optimizing_scope(compiler);
48
49 compiler->assembler()->Comment("Graph intrinsic begin");
50 for (intptr_t i = 0; i < graph->reverse_postorder().length(); i++) {
51 BlockEntryInstr* block = graph->reverse_postorder()[i];
52 if (block->IsGraphEntry()) continue; // No code for graph entry needed.
53
54 if (block->HasParallelMove()) {
56 }
57
58 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) {
59 Instruction* instr = it.Current();
60 if (FLAG_code_comments) compiler->EmitComment(instr);
61 // Calls are not supported in intrinsics code.
62 ASSERT(instr->IsParallelMove() ||
63 (instr->locs() != nullptr && !instr->locs()->always_calls()));
65 }
66 }
67 compiler->assembler()->Comment("Graph intrinsic end");
68}
69
72 ASSERT(!parsed_function.function().HasOptionalParameters());
73 PrologueInfo prologue_info(-1, -1);
74
75 auto graph_entry =
76 new GraphEntryInstr(parsed_function, Compiler::kNoOSRDeoptId);
77
78 intptr_t block_id = 1; // 0 is GraphEntry.
79 graph_entry->set_normal_entry(
80 new FunctionEntryInstr(graph_entry, block_id, kInvalidTryIndex,
81 CompilerState::Current().GetNextDeoptId()));
82
83 FlowGraph* graph =
84 new FlowGraph(parsed_function, graph_entry, block_id, prologue_info,
86 compiler->set_intrinsic_flow_graph(*graph);
87
88 const Function& function = parsed_function.function();
89
90 switch (function.recognized_kind()) {
91#define EMIT_CASE(class_name, function_name, enum_name, fp) \
92 case MethodRecognizer::k##enum_name: \
93 if (!Build_##enum_name(graph)) return false; \
94 break;
95
97#undef EMIT_CASE
98 default:
99 return false;
100 }
101
102 if (FLAG_support_il_printer && FLAG_print_flow_graph &&
104 THR_Print("Intrinsic graph before\n");
105 FlowGraphPrinter printer(*graph);
106 printer.PrintBlocks();
107 }
108
109 // Prepare for register allocation (cf. FinalizeGraph).
110 graph->RemoveRedefinitions();
111
112 // Ensure dominators are re-computed. Normally this is done during SSA
113 // construction (which we don't do for graph intrinsics).
114 GrowableArray<BitVector*> dominance_frontier;
115 graph->ComputeDominators(&dominance_frontier);
116
117 CompilerPassState state(parsed_function.thread(), graph,
118 /*speculative_inlining_policy*/ nullptr);
120
121 if (FLAG_support_il_printer && FLAG_print_flow_graph &&
123 THR_Print("Intrinsic graph after\n");
124 FlowGraphPrinter printer(*graph);
125 printer.PrintBlocks();
126 }
127 EmitCodeFor(compiler, graph);
128 return true;
129}
130
132 switch (cid) {
133 case kDoubleCid:
134 return kUnboxedDouble;
135 case kFloat32x4Cid:
136 return kUnboxedFloat32x4;
137 case kInt32x4Cid:
138 return kUnboxedInt32x4;
139 case kFloat64x2Cid:
140 return kUnboxedFloat64x2;
141 default:
142 UNREACHABLE();
143 return kNoRepresentation;
144 }
145}
146
147// Notes about the graph intrinsics:
148//
149// IR instructions which would jump to a deoptimization sequence on failure
150// instead branch to the intrinsic slow path.
151//
154 Definition* array,
155 Definition* index,
156 const Slot& length_field) {
157 Definition* length = builder->AddDefinition(
158 new LoadFieldInstr(new Value(array), length_field, InstructionSource()));
159 // Note that the intrinsifier must always use deopting array bound
160 // checks, because intrinsics currently don't support calls.
161 Definition* safe_index = new CheckArrayBoundInstr(
162 new Value(length), new Value(index), DeoptId::kNone);
163 builder->AddDefinition(safe_index);
164 return safe_index;
165}
166
167static void VerifyParameterIsBoxed(BlockBuilder* builder, intptr_t arg_index) {
168 const auto& function = builder->function();
169 if (function.is_unboxed_parameter_at(arg_index)) {
170 FATAL("Unsupported unboxed parameter %" Pd " in %s", arg_index,
171 function.ToFullyQualifiedCString());
172 }
173}
174
177 Representation representation,
178 intptr_t arg_index) {
179 const auto& function = builder->function();
180 if (function.is_unboxed_parameter_at(arg_index)) {
181 return builder->AddDefinition(
182 BoxInstr::Create(representation, new Value(value)));
183 } else {
184 return value;
185 }
186}
187
190 Representation representation) {
191 const auto& function = builder->function();
192 ASSERT(!function.has_unboxed_record_return());
194 if (representation == kUnboxedFloat) {
195 result = builder->AddDefinition(
197 representation = kUnboxedDouble;
198 }
199 if (!function.has_unboxed_return()) {
200 result = builder->AddDefinition(BoxInstr::Create(
201 Boxing::NativeRepresentation(representation), new Value(result)));
202 }
203 return result;
204}
205
207 Definition* value) {
208 const auto& function = builder->function();
209 ASSERT(!function.has_unboxed_record_return());
210 if (function.has_unboxed_return() && value->representation() == kTagged) {
212 new Value(value), /* is_checked = */ true);
213 } else {
214 return value;
215 }
216}
217
218static bool IntrinsifyArraySetIndexed(FlowGraph* flow_graph,
219 intptr_t array_cid) {
220 GraphEntryInstr* graph_entry = flow_graph->graph_entry();
221 auto normal_entry = graph_entry->normal_entry();
222 BlockBuilder builder(flow_graph, normal_entry, /*with_frame=*/false);
223
224 Definition* array = builder.AddParameter(0);
225 Definition* index = builder.AddParameter(1);
226 Definition* value = builder.AddParameter(2);
227
230
231 index = CreateBoxedParameterIfNeeded(&builder, index, kUnboxedInt64, 1);
232 index = PrepareIndexedOp(flow_graph, &builder, array, index,
234
235 // Value check/conversion.
236 auto const rep = RepresentationUtils::RepresentationOfArrayElement(array_cid);
237 if (IsClampedTypedDataBaseClassId(array_cid)) {
238#if defined(TARGET_ARCH_IS_32_BIT)
239 // On 32-bit architectures, clamping operations need the exact value
240 // for proper operations. On 64-bit architectures, kUnboxedIntPtr
241 // maps to kUnboxedInt64. All other situations get away with
242 // truncating even non-smi values.
243 builder.AddInstruction(
244 new CheckSmiInstr(new Value(value), DeoptId::kNone, builder.Source()));
245#endif
246 }
248 // Use same truncating unbox-instruction for int32 and uint32.
249 auto const unbox_rep = rep == kUnboxedInt32 ? kUnboxedUint32 : rep;
250 value = builder.AddUnboxInstr(unbox_rep, new Value(value),
251 /* is_checked = */ false);
252 } else if (RepresentationUtils::IsUnboxed(rep)) {
253 Zone* zone = flow_graph->zone();
254 Cids* value_check = Cids::CreateMonomorphic(zone, Boxing::BoxCid(rep));
255 builder.AddInstruction(new CheckClassInstr(new Value(value), DeoptId::kNone,
256 *value_check, builder.Source()));
257 value = builder.AddUnboxInstr(rep, new Value(value),
258 /* is_checked = */ true);
259 }
260
261 if (IsExternalTypedDataClassId(array_cid)) {
262 array = builder.AddDefinition(new LoadFieldInstr(
263 new Value(array), Slot::PointerBase_data(),
265 }
266 // No store barrier.
268 IsTypedDataClassId(array_cid));
269 builder.AddInstruction(new StoreIndexedInstr(
270 new Value(array), new Value(index), new Value(value), kNoStoreBarrier,
271 /*index_unboxed=*/false,
272 /*index_scale=*/target::Instance::ElementSizeFor(array_cid), array_cid,
274 // Return null.
275 Definition* null_def = builder.AddNullDefinition();
276 builder.AddReturn(new Value(null_def));
277 return true;
278}
279
280#define DEFINE_ARRAY_SETTER_INTRINSIC(enum_name) \
281 bool GraphIntrinsifier::Build_##enum_name##SetIndexed( \
282 FlowGraph* flow_graph) { \
283 return IntrinsifyArraySetIndexed( \
284 flow_graph, MethodRecognizer::MethodKindToReceiverCid( \
285 MethodRecognizer::k##enum_name##SetIndexed)); \
286 }
287
290DEFINE_ARRAY_SETTER_INTRINSIC(ExternalUint8Array)
291DEFINE_ARRAY_SETTER_INTRINSIC(Uint8ClampedArray)
292DEFINE_ARRAY_SETTER_INTRINSIC(ExternalUint8ClampedArray)
299
300#undef DEFINE_ARRAY_SETTER_INTRINSIC
301
302#define DEFINE_FLOAT_ARRAY_SETTER_INTRINSIC(enum_name) \
303 bool GraphIntrinsifier::Build_##enum_name##SetIndexed( \
304 FlowGraph* flow_graph) { \
305 return IntrinsifyArraySetIndexed( \
306 flow_graph, MethodRecognizer::MethodKindToReceiverCid( \
307 MethodRecognizer::k##enum_name##SetIndexed)); \
308 }
309
312
313#undef DEFINE_FLOAT_ARRAY_SETTER_INTRINSIC
314
315#define DEFINE_SIMD_ARRAY_SETTER_INTRINSIC(enum_name) \
316 bool GraphIntrinsifier::Build_##enum_name##SetIndexed( \
317 FlowGraph* flow_graph) { \
318 if (!FlowGraphCompiler::SupportsUnboxedSimd128()) { \
319 return false; \
320 } \
321 return IntrinsifyArraySetIndexed( \
322 flow_graph, MethodRecognizer::MethodKindToReceiverCid( \
323 MethodRecognizer::k##enum_name##SetIndexed)); \
324 }
325
329
330#undef DEFINE_SIMD_ARRAY_SETTER_INTRINSIC
331
332static bool BuildSimdOp(FlowGraph* flow_graph, intptr_t cid, Token::Kind kind) {
334
335 auto const rep = RepresentationForCid(cid);
336
337 Zone* zone = flow_graph->zone();
338 GraphEntryInstr* graph_entry = flow_graph->graph_entry();
339 auto normal_entry = graph_entry->normal_entry();
340 BlockBuilder builder(flow_graph, normal_entry, /*with_frame=*/false);
341
342 Definition* left = builder.AddParameter(0);
343 Definition* right = builder.AddParameter(1);
344
347
348 Cids* value_check = Cids::CreateMonomorphic(zone, cid);
349 // Check argument. Receiver (left) is known to be a Float32x4.
350 builder.AddInstruction(new CheckClassInstr(new Value(right), DeoptId::kNone,
351 *value_check, builder.Source()));
352 Definition* left_simd = builder.AddUnboxInstr(rep, new Value(left),
353 /* is_checked = */ true);
354
355 Definition* right_simd = builder.AddUnboxInstr(rep, new Value(right),
356 /* is_checked = */ true);
357
358 Definition* unboxed_result = builder.AddDefinition(SimdOpInstr::Create(
359 SimdOpInstr::KindForOperator(cid, kind), new Value(left_simd),
360 new Value(right_simd), DeoptId::kNone));
361 Definition* result = CreateBoxedResultIfNeeded(&builder, unboxed_result, rep);
362
363 builder.AddReturn(new Value(result));
364 return true;
365}
366
367bool GraphIntrinsifier::Build_Float32x4Mul(FlowGraph* flow_graph) {
368 return BuildSimdOp(flow_graph, kFloat32x4Cid, Token::kMUL);
369}
370
371bool GraphIntrinsifier::Build_Float32x4Div(FlowGraph* flow_graph) {
372 return BuildSimdOp(flow_graph, kFloat32x4Cid, Token::kDIV);
373}
374
375bool GraphIntrinsifier::Build_Float32x4Sub(FlowGraph* flow_graph) {
376 return BuildSimdOp(flow_graph, kFloat32x4Cid, Token::kSUB);
377}
378
379bool GraphIntrinsifier::Build_Float32x4Add(FlowGraph* flow_graph) {
380 return BuildSimdOp(flow_graph, kFloat32x4Cid, Token::kADD);
381}
382
383bool GraphIntrinsifier::Build_Float64x2Mul(FlowGraph* flow_graph) {
384 return BuildSimdOp(flow_graph, kFloat64x2Cid, Token::kMUL);
385}
386
387bool GraphIntrinsifier::Build_Float64x2Div(FlowGraph* flow_graph) {
388 return BuildSimdOp(flow_graph, kFloat64x2Cid, Token::kDIV);
389}
390
391bool GraphIntrinsifier::Build_Float64x2Sub(FlowGraph* flow_graph) {
392 return BuildSimdOp(flow_graph, kFloat64x2Cid, Token::kSUB);
393}
394
395bool GraphIntrinsifier::Build_Float64x2Add(FlowGraph* flow_graph) {
396 return BuildSimdOp(flow_graph, kFloat64x2Cid, Token::kADD);
397}
398
399static bool BuildFloat32x4Get(FlowGraph* flow_graph,
402 return false;
403 }
404 GraphEntryInstr* graph_entry = flow_graph->graph_entry();
405 auto normal_entry = graph_entry->normal_entry();
406 BlockBuilder builder(flow_graph, normal_entry, /*with_frame=*/false);
407
408 Definition* receiver = builder.AddParameter(0);
409
410 const auto& function = flow_graph->function();
411 Definition* unboxed_receiver =
412 !function.is_unboxed_parameter_at(0)
413 ? builder.AddUnboxInstr(kUnboxedFloat32x4, new Value(receiver),
414 /* is_checked = */ true)
415 : receiver;
416
417 Definition* unboxed_result = builder.AddDefinition(
418 SimdOpInstr::Create(kind, new Value(unboxed_receiver), DeoptId::kNone));
419
421 CreateBoxedResultIfNeeded(&builder, unboxed_result, kUnboxedDouble);
422
423 builder.AddReturn(new Value(result));
424 return true;
425}
426
427bool GraphIntrinsifier::Build_Float32x4GetX(FlowGraph* flow_graph) {
428 return BuildFloat32x4Get(flow_graph, MethodRecognizer::kFloat32x4GetX);
429}
430
431bool GraphIntrinsifier::Build_Float32x4GetY(FlowGraph* flow_graph) {
432 return BuildFloat32x4Get(flow_graph, MethodRecognizer::kFloat32x4GetY);
433}
434
435bool GraphIntrinsifier::Build_Float32x4GetZ(FlowGraph* flow_graph) {
436 return BuildFloat32x4Get(flow_graph, MethodRecognizer::kFloat32x4GetZ);
437}
438
439bool GraphIntrinsifier::Build_Float32x4GetW(FlowGraph* flow_graph) {
440 return BuildFloat32x4Get(flow_graph, MethodRecognizer::kFloat32x4GetW);
441}
442
443static bool BuildLoadField(FlowGraph* flow_graph, const Slot& field) {
444 GraphEntryInstr* graph_entry = flow_graph->graph_entry();
445 auto normal_entry = graph_entry->normal_entry();
446 BlockBuilder builder(flow_graph, normal_entry, /*with_frame=*/false);
447
448 Definition* array = builder.AddParameter(0);
450
451 Definition* length = builder.AddDefinition(
452 new LoadFieldInstr(new Value(array), field, builder.Source()));
453
455 builder.AddReturn(new Value(length));
456 return true;
457}
458
459bool GraphIntrinsifier::Build_ObjectArrayLength(FlowGraph* flow_graph) {
460 return BuildLoadField(flow_graph, Slot::Array_length());
461}
462
463bool GraphIntrinsifier::Build_GrowableArrayLength(FlowGraph* flow_graph) {
464 return BuildLoadField(flow_graph, Slot::GrowableObjectArray_length());
465}
466
467bool GraphIntrinsifier::Build_StringBaseLength(FlowGraph* flow_graph) {
468 return BuildLoadField(flow_graph, Slot::String_length());
469}
470
471bool GraphIntrinsifier::Build_TypedListBaseLength(FlowGraph* flow_graph) {
472 return BuildLoadField(flow_graph, Slot::TypedDataBase_length());
473}
474
475bool GraphIntrinsifier::Build_ByteDataViewLength(FlowGraph* flow_graph) {
476 return BuildLoadField(flow_graph, Slot::TypedDataBase_length());
477}
478
479bool GraphIntrinsifier::Build_GrowableArrayCapacity(FlowGraph* flow_graph) {
480 GraphEntryInstr* graph_entry = flow_graph->graph_entry();
481 auto normal_entry = graph_entry->normal_entry();
482 BlockBuilder builder(flow_graph, normal_entry, /*with_frame=*/false);
483
484 Definition* array = builder.AddParameter(0);
486
487 Definition* backing_store = builder.AddDefinition(new LoadFieldInstr(
488 new Value(array), Slot::GrowableObjectArray_data(), builder.Source()));
489 Definition* capacity = builder.AddDefinition(new LoadFieldInstr(
490 new Value(backing_store), Slot::Array_length(), builder.Source()));
491 capacity = CreateUnboxedResultIfNeeded(&builder, capacity);
492 builder.AddReturn(new Value(capacity));
493 return true;
494}
495
496bool GraphIntrinsifier::Build_ObjectArraySetIndexedUnchecked(
497 FlowGraph* flow_graph) {
498 GraphEntryInstr* graph_entry = flow_graph->graph_entry();
499 auto normal_entry = graph_entry->normal_entry();
500 BlockBuilder builder(flow_graph, normal_entry, /*with_frame=*/false);
501
502 Definition* array = builder.AddParameter(0);
503 Definition* index = builder.AddParameter(1);
504 Definition* value = builder.AddParameter(2);
505
508
509 index = CreateBoxedParameterIfNeeded(&builder, index, kUnboxedInt64, 1);
510 index = PrepareIndexedOp(flow_graph, &builder, array, index,
511 Slot::Array_length());
512
513 builder.AddInstruction(new StoreIndexedInstr(
514 new Value(array), new Value(index), new Value(value), kEmitStoreBarrier,
515 /*index_unboxed=*/false,
516 /*index_scale=*/target::Instance::ElementSizeFor(kArrayCid), kArrayCid,
518 // Return null.
519 Definition* null_def = builder.AddNullDefinition();
520 builder.AddReturn(new Value(null_def));
521 return true;
522}
523
524bool GraphIntrinsifier::Build_GrowableArraySetIndexedUnchecked(
525 FlowGraph* flow_graph) {
526 GraphEntryInstr* graph_entry = flow_graph->graph_entry();
527 auto normal_entry = graph_entry->normal_entry();
528 BlockBuilder builder(flow_graph, normal_entry, /*with_frame=*/false);
529
530 Definition* array = builder.AddParameter(0);
531 Definition* index = builder.AddParameter(1);
532 Definition* value = builder.AddParameter(2);
533
536
537 index = CreateBoxedParameterIfNeeded(&builder, index, kUnboxedInt64, 1);
538 index = PrepareIndexedOp(flow_graph, &builder, array, index,
539 Slot::GrowableObjectArray_length());
540
541 Definition* backing_store = builder.AddDefinition(new LoadFieldInstr(
542 new Value(array), Slot::GrowableObjectArray_data(), builder.Source()));
543
544 builder.AddInstruction(new StoreIndexedInstr(
545 new Value(backing_store), new Value(index), new Value(value),
546 kEmitStoreBarrier, /*index_unboxed=*/false,
547 /*index_scale=*/target::Instance::ElementSizeFor(kArrayCid), kArrayCid,
549 // Return null.
550 Definition* null_def = builder.AddNullDefinition();
551 builder.AddReturn(new Value(null_def));
552 return true;
553}
554
555bool GraphIntrinsifier::Build_GrowableArraySetData(FlowGraph* flow_graph) {
556 GraphEntryInstr* graph_entry = flow_graph->graph_entry();
557 auto normal_entry = graph_entry->normal_entry();
558 BlockBuilder builder(flow_graph, normal_entry, /*with_frame=*/false);
559
560 Definition* growable_array = builder.AddParameter(0);
561 Definition* data = builder.AddParameter(1);
562 Zone* zone = flow_graph->zone();
563
566
567 Cids* value_check = Cids::CreateMonomorphic(zone, kArrayCid);
568 builder.AddInstruction(new CheckClassInstr(new Value(data), DeoptId::kNone,
569 *value_check, builder.Source()));
570
571 builder.AddInstruction(new StoreFieldInstr(
572 Slot::GrowableObjectArray_data(), new Value(growable_array),
573 new Value(data), kEmitStoreBarrier, builder.Source()));
574 // Return null.
575 Definition* null_def = builder.AddNullDefinition();
576 builder.AddReturn(new Value(null_def));
577 return true;
578}
579
580bool GraphIntrinsifier::Build_GrowableArraySetLength(FlowGraph* flow_graph) {
581 GraphEntryInstr* graph_entry = flow_graph->graph_entry();
582 auto normal_entry = graph_entry->normal_entry();
583 BlockBuilder builder(flow_graph, normal_entry, /*with_frame=*/false);
584
585 Definition* growable_array = builder.AddParameter(0);
586 Definition* length = builder.AddParameter(1);
587
590
591 builder.AddInstruction(
592 new CheckSmiInstr(new Value(length), DeoptId::kNone, builder.Source()));
593 builder.AddInstruction(new StoreFieldInstr(
594 Slot::GrowableObjectArray_length(), new Value(growable_array),
595 new Value(length), kNoStoreBarrier, builder.Source()));
596 Definition* null_def = builder.AddNullDefinition();
597 builder.AddReturn(new Value(null_def));
598 return true;
599}
600
601static bool BuildUnarySmiOp(FlowGraph* flow_graph, Token::Kind op_kind) {
602 ASSERT(!flow_graph->function().has_unboxed_return());
603 ASSERT(!flow_graph->function().is_unboxed_parameter_at(0));
604 GraphEntryInstr* graph_entry = flow_graph->graph_entry();
605 auto normal_entry = graph_entry->normal_entry();
606 BlockBuilder builder(flow_graph, normal_entry, /*with_frame=*/false);
607 Definition* left = builder.AddParameter(0);
608 builder.AddInstruction(
609 new CheckSmiInstr(new Value(left), DeoptId::kNone, builder.Source()));
610 Definition* result = builder.AddDefinition(
611 new UnarySmiOpInstr(op_kind, new Value(left), DeoptId::kNone));
612 builder.AddReturn(new Value(result));
613 return true;
614}
615
616bool GraphIntrinsifier::Build_Smi_bitNegate(FlowGraph* flow_graph) {
617 return BuildUnarySmiOp(flow_graph, Token::kBIT_NOT);
618}
619
620bool GraphIntrinsifier::Build_Integer_negate(FlowGraph* flow_graph) {
621 return BuildUnarySmiOp(flow_graph, Token::kNEGATE);
622}
623
624static bool BuildBinarySmiOp(FlowGraph* flow_graph, Token::Kind op_kind) {
625 ASSERT(!flow_graph->function().has_unboxed_return());
626 ASSERT(!flow_graph->function().is_unboxed_parameter_at(0));
627 ASSERT(!flow_graph->function().is_unboxed_parameter_at(1));
628 GraphEntryInstr* graph_entry = flow_graph->graph_entry();
629 auto normal_entry = graph_entry->normal_entry();
630 BlockBuilder builder(flow_graph, normal_entry, /*with_frame=*/false);
631 Definition* left = builder.AddParameter(0);
632 Definition* right = builder.AddParameter(1);
633 builder.AddInstruction(
634 new CheckSmiInstr(new Value(left), DeoptId::kNone, builder.Source()));
635 builder.AddInstruction(
636 new CheckSmiInstr(new Value(right), DeoptId::kNone, builder.Source()));
637 Definition* result = builder.AddDefinition(new BinarySmiOpInstr(
638 op_kind, new Value(left), new Value(right), DeoptId::kNone));
639 builder.AddReturn(new Value(result));
640 return true;
641}
642
643bool GraphIntrinsifier::Build_Integer_add(FlowGraph* flow_graph) {
644 return BuildBinarySmiOp(flow_graph, Token::kADD);
645}
646
647bool GraphIntrinsifier::Build_Integer_sub(FlowGraph* flow_graph) {
648 return BuildBinarySmiOp(flow_graph, Token::kSUB);
649}
650
651bool GraphIntrinsifier::Build_Integer_mul(FlowGraph* flow_graph) {
652 return BuildBinarySmiOp(flow_graph, Token::kMUL);
653}
654
655bool GraphIntrinsifier::Build_Integer_mod(FlowGraph* flow_graph) {
656 return BuildBinarySmiOp(flow_graph, Token::kMOD);
657}
658
659bool GraphIntrinsifier::Build_Integer_truncDivide(FlowGraph* flow_graph) {
660 return BuildBinarySmiOp(flow_graph, Token::kTRUNCDIV);
661}
662
663bool GraphIntrinsifier::Build_Integer_bitAnd(FlowGraph* flow_graph) {
664 return BuildBinarySmiOp(flow_graph, Token::kBIT_AND);
665}
666
667bool GraphIntrinsifier::Build_Integer_bitOr(FlowGraph* flow_graph) {
668 return BuildBinarySmiOp(flow_graph, Token::kBIT_OR);
669}
670
671bool GraphIntrinsifier::Build_Integer_bitXor(FlowGraph* flow_graph) {
672 return BuildBinarySmiOp(flow_graph, Token::kBIT_XOR);
673}
674
675bool GraphIntrinsifier::Build_Integer_sar(FlowGraph* flow_graph) {
676 return BuildBinarySmiOp(flow_graph, Token::kSHR);
677}
678
679bool GraphIntrinsifier::Build_Integer_shr(FlowGraph* flow_graph) {
680 return BuildBinarySmiOp(flow_graph, Token::kUSHR);
681}
682
685 intptr_t index,
686 bool is_checked) {
687 const auto& function = builder->function();
688 if (function.is_unboxed_double_parameter_at(index)) {
689 return value;
690 } else if (function.is_unboxed_integer_parameter_at(index)) {
692 // Int64ToDoubleInstr is not implemented in 32-bit platforms
693 return nullptr;
694 }
695 auto to_double = new Int64ToDoubleInstr(new Value(value), DeoptId::kNone);
696 return builder->AddDefinition(to_double);
697 } else {
698 ASSERT(!function.is_unboxed_parameter_at(index));
699 return builder->AddUnboxInstr(kUnboxedDouble, value, is_checked);
700 }
701}
702
703bool GraphIntrinsifier::Build_DoubleFlipSignBit(FlowGraph* flow_graph) {
704 GraphEntryInstr* graph_entry = flow_graph->graph_entry();
705 auto normal_entry = graph_entry->normal_entry();
706 BlockBuilder builder(flow_graph, normal_entry, /*with_frame=*/false);
707
708 Definition* receiver = builder.AddParameter(0);
710 &builder, receiver, 0, /* is_checked = */ true);
711 if (unboxed_value == nullptr) {
712 return false;
713 }
714 Definition* unboxed_result = builder.AddDefinition(new UnaryDoubleOpInstr(
715 Token::kNEGATE, new Value(unboxed_value), DeoptId::kNone));
716 Definition* result =
717 CreateBoxedResultIfNeeded(&builder, unboxed_result, kUnboxedDouble);
718 builder.AddReturn(new Value(result));
719 return true;
720}
721
722} // namespace compiler
723} // namespace dart
emscripten::val Uint32Array
Definition: WasmCommon.h:34
emscripten::val Uint16Array
Definition: WasmCommon.h:33
emscripten::val Float32Array
Definition: WasmCommon.h:35
emscripten::val Uint8Array
Definition: WasmCommon.h:32
#define UNREACHABLE()
Definition: assert.h:248
ParallelMoveInstr * parallel_move() const
Definition: il.h:1689
bool HasParallelMove() const
Definition: il.h:1691
static BoxInstr * Create(Representation from, Value *value)
Definition: il.cc:4007
Definition: il.h:736
static Cids * CreateMonomorphic(Zone *zone, intptr_t cid)
Definition: il.cc:691
static void RunGraphIntrinsicPipeline(CompilerPassState *state)
static CompilerState & Current()
static constexpr intptr_t kNoOSRDeoptId
Definition: compiler.h:73
static constexpr intptr_t kNone
Definition: deopt_id.h:27
static bool SupportsUnboxedSimd128()
static bool ShouldPrint(const Function &function, uint8_t **compiler_pass_filter=nullptr)
Definition: il_printer.cc:1715
const GrowableArray< BlockEntryInstr * > & reverse_postorder() const
Definition: flow_graph.h:207
GraphEntryInstr * graph_entry() const
Definition: flow_graph.h:268
Zone * zone() const
Definition: flow_graph.h:261
static Representation ReturnRepresentationOf(const Function &function)
Definition: flow_graph.cc:125
void RemoveRedefinitions(bool keep_checks=false)
Definition: flow_graph.cc:1810
void ComputeDominators(GrowableArray< BitVector * > *dominance_frontier)
Definition: flow_graph.cc:975
const Function & function() const
Definition: flow_graph.h:130
bool has_unboxed_return() const
Definition: object.h:3803
bool HasOptionalParameters() const
Definition: object.cc:8859
bool is_unboxed_parameter_at(intptr_t index) const
Definition: object.h:3773
FunctionEntryInstr * normal_entry() const
Definition: il.h:2001
GraphIntrinsicCodeGenScope(FlowGraphCompiler *compiler)
virtual void EmitNativeCode(FlowGraphCompiler *compiler)
Definition: il.h:1213
LocationSummary * locs()
Definition: il.h:1192
bool always_calls() const
Definition: locations.h:918
const Function & function() const
Definition: parser.h:73
Thread * thread() const
Definition: parser.h:211
static SimdOpInstr * Create(Kind kind, Value *left, Value *right, intptr_t deopt_id)
Definition: il.h:11322
static Kind KindForOperator(MethodRecognizer::Kind kind)
Definition: il.cc:8234
static const Slot & GetLengthFieldForArrayCid(intptr_t array_cid)
Definition: slot.cc:249
Definition: il.h:75
static bool GraphIntrinsify(const ParsedFunction &parsed_function, FlowGraphCompiler *compiler)
static word ElementSizeFor(intptr_t cid)
Definition: runtime_api.cc:581
#define THR_Print(format,...)
Definition: log.h:20
#define ASSERT(E)
#define FATAL(error)
AtkStateType state
uint8_t value
GAsyncResult * result
constexpr bool FLAG_support_il_printer
Definition: flag_list.h:48
Dart_NativeFunction function
Definition: fuchsia.cc:51
#define EMIT_CASE(class_name, function_name, enum_name, fp)
#define DEFINE_SIMD_ARRAY_SETTER_INTRINSIC(enum_name)
#define DEFINE_FLOAT_ARRAY_SETTER_INTRINSIC(enum_name)
#define DEFINE_ARRAY_SETTER_INTRINSIC(enum_name)
size_t length
static constexpr intptr_t kWordSize
Definition: runtime_api.h:274
static void VerifyParameterIsBoxed(BlockBuilder *builder, intptr_t arg_index)
static bool BuildBinarySmiOp(FlowGraph *flow_graph, Token::Kind op_kind)
static bool IntrinsifyArraySetIndexed(FlowGraph *flow_graph, intptr_t array_cid)
static Definition * CreateBoxedParameterIfNeeded(BlockBuilder *builder, Definition *value, Representation representation, intptr_t arg_index)
static void EmitCodeFor(FlowGraphCompiler *compiler, FlowGraph *graph)
static Definition * PrepareIndexedOp(FlowGraph *flow_graph, BlockBuilder *builder, Definition *array, Definition *index, const Slot &length_field)
static bool BuildSimdOp(FlowGraph *flow_graph, intptr_t cid, Token::Kind kind)
static Representation RepresentationForCid(intptr_t cid)
static Definition * CreateUnboxedResultIfNeeded(BlockBuilder *builder, Definition *value)
static bool BuildFloat32x4Get(FlowGraph *flow_graph, MethodRecognizer::Kind kind)
static Definition * ConvertOrUnboxDoubleParameter(BlockBuilder *builder, Definition *value, intptr_t index, bool is_checked)
static bool BuildUnarySmiOp(FlowGraph *flow_graph, Token::Kind op_kind)
static bool BuildLoadField(FlowGraph *flow_graph, const Slot &field)
static Definition * CreateBoxedResultIfNeeded(BlockBuilder *builder, Definition *value, Representation representation)
Definition: dart_vm.cc:33
bool IsTypedDataClassId(intptr_t index)
Definition: class_id.h:433
@ TypedDataBase_length
Definition: il_test.cc:1250
@ kNoStoreBarrier
Definition: il.h:6301
@ kEmitStoreBarrier
Definition: il.h:6301
Representation
Definition: locations.h:66
bool IsClampedTypedDataBaseClassId(intptr_t index)
Definition: class_id.h:461
const intptr_t cid
static int8_t data[kExtLength]
static constexpr intptr_t kInvalidTryIndex
bool IsExternalTypedDataClassId(intptr_t index)
Definition: class_id.h:447
@ kAlignedAccess
Definition: il.h:6766
DECLARE_FLAG(bool, show_invisible_frames)
#define Pd
Definition: globals.h:408
#define GRAPH_INTRINSICS_LIST(V)
static constexpr Representation NativeRepresentation(Representation rep)
Definition: il.h:8504
static intptr_t BoxCid(Representation rep)
Definition: il.cc:493
static constexpr bool IsUnboxedInteger(Representation rep)
Definition: locations.h:92
static constexpr bool IsUnboxed(Representation rep)
Definition: locations.h:101
static Representation RepresentationOfArrayElement(classid_t cid)
Definition: locations.cc:79