OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 // Class for intrinsifying functions. | 4 // Class for intrinsifying functions. |
5 | 5 |
6 #include "vm/assembler.h" | 6 #include "vm/assembler.h" |
7 #include "vm/compiler.h" | 7 #include "vm/compiler.h" |
8 #include "vm/flags.h" | 8 #include "vm/flags.h" |
9 #include "vm/flow_graph.h" | 9 #include "vm/flow_graph.h" |
10 #include "vm/flow_graph_compiler.h" | 10 #include "vm/flow_graph_compiler.h" |
11 #include "vm/flow_graph_allocator.h" | 11 #include "vm/flow_graph_allocator.h" |
12 #include "vm/flow_graph_builder.h" | 12 #include "vm/flow_graph_builder.h" |
13 #include "vm/il_printer.h" | 13 #include "vm/il_printer.h" |
14 #include "vm/intermediate_language.h" | 14 #include "vm/intermediate_language.h" |
15 #include "vm/intrinsifier.h" | 15 #include "vm/intrinsifier.h" |
16 #include "vm/object.h" | 16 #include "vm/object.h" |
17 #include "vm/parser.h" | 17 #include "vm/parser.h" |
18 #include "vm/symbols.h" | 18 #include "vm/symbols.h" |
19 | 19 |
20 | 20 |
21 namespace dart { | 21 namespace dart { |
22 | 22 |
23 DEFINE_FLAG(bool, intrinsify, true, "Instrinsify when possible"); | 23 DEFINE_FLAG(bool, intrinsify, true, "Instrinsify when possible"); |
| 24 DEFINE_FLAG(bool, trace_intrinsifier, false, "Trace intrinsifier"); |
24 DECLARE_FLAG(bool, code_comments); | 25 DECLARE_FLAG(bool, code_comments); |
25 DECLARE_FLAG(bool, print_flow_graph); | 26 DECLARE_FLAG(bool, print_flow_graph); |
26 DECLARE_FLAG(bool, print_flow_graph_optimized); | 27 DECLARE_FLAG(bool, print_flow_graph_optimized); |
27 | 28 |
28 bool Intrinsifier::CanIntrinsify(const Function& function) { | 29 bool Intrinsifier::CanIntrinsify(const Function& function) { |
| 30 if (FLAG_trace_intrinsifier) { |
| 31 THR_Print("CanIntrinsify %s ->", function.ToQualifiedCString()); |
| 32 } |
29 if (!FLAG_intrinsify) return false; | 33 if (!FLAG_intrinsify) return false; |
30 if (function.IsClosureFunction()) return false; | 34 if (function.IsClosureFunction()) { |
| 35 if (FLAG_trace_intrinsifier) { |
| 36 THR_Print("No, closure function.\n"); |
| 37 } |
| 38 return false; |
| 39 } |
31 // Can occur because of compile-all flag. | 40 // Can occur because of compile-all flag. |
32 if (function.is_external()) return false; | 41 if (function.is_external()) { |
33 return function.is_intrinsic(); | 42 if (FLAG_trace_intrinsifier) { |
| 43 THR_Print("No, external function.\n"); |
| 44 } |
| 45 return false; |
| 46 } |
| 47 if (!function.is_intrinsic()) { |
| 48 if (FLAG_trace_intrinsifier) { |
| 49 THR_Print("No, not intrinsic function.\n"); |
| 50 } |
| 51 return false; |
| 52 } |
| 53 if (FLAG_trace_intrinsifier) { |
| 54 THR_Print("Yes.\n"); |
| 55 } |
| 56 return true; |
34 } | 57 } |
35 | 58 |
36 | 59 |
37 #if defined(DART_NO_SNAPSHOT) | 60 #if defined(DART_NO_SNAPSHOT) |
38 void Intrinsifier::InitializeState() { | 61 void Intrinsifier::InitializeState() { |
39 Thread* thread = Thread::Current(); | 62 Thread* thread = Thread::Current(); |
40 Zone* zone = thread->zone(); | 63 Zone* zone = thread->zone(); |
41 Library& lib = Library::Handle(zone); | 64 Library& lib = Library::Handle(zone); |
42 Class& cls = Class::Handle(zone); | 65 Class& cls = Class::Handle(zone); |
43 Function& func = Function::Handle(zone); | 66 Function& func = Function::Handle(zone); |
(...skipping 27 matching lines...) Expand all Loading... |
71 lib = Library::CoreLibrary(); | 94 lib = Library::CoreLibrary(); |
72 ASSERT(!lib.IsNull()); | 95 ASSERT(!lib.IsNull()); |
73 CORE_LIB_INTRINSIC_LIST(SETUP_FUNCTION); | 96 CORE_LIB_INTRINSIC_LIST(SETUP_FUNCTION); |
74 CORE_INTEGER_LIB_INTRINSIC_LIST(SETUP_FUNCTION); | 97 CORE_INTEGER_LIB_INTRINSIC_LIST(SETUP_FUNCTION); |
75 GRAPH_CORE_INTRINSICS_LIST(SETUP_FUNCTION); | 98 GRAPH_CORE_INTRINSICS_LIST(SETUP_FUNCTION); |
76 | 99 |
77 // Set up all math lib functions that can be intrinsified. | 100 // Set up all math lib functions that can be intrinsified. |
78 lib = Library::MathLibrary(); | 101 lib = Library::MathLibrary(); |
79 ASSERT(!lib.IsNull()); | 102 ASSERT(!lib.IsNull()); |
80 MATH_LIB_INTRINSIC_LIST(SETUP_FUNCTION); | 103 MATH_LIB_INTRINSIC_LIST(SETUP_FUNCTION); |
| 104 GRAPH_MATH_LIB_INTRINSIC_LIST(SETUP_FUNCTION); |
81 | 105 |
82 // Set up all dart:typed_data lib functions that can be intrinsified. | 106 // Set up all dart:typed_data lib functions that can be intrinsified. |
83 lib = Library::TypedDataLibrary(); | 107 lib = Library::TypedDataLibrary(); |
84 ASSERT(!lib.IsNull()); | 108 ASSERT(!lib.IsNull()); |
85 TYPED_DATA_LIB_INTRINSIC_LIST(SETUP_FUNCTION); | 109 TYPED_DATA_LIB_INTRINSIC_LIST(SETUP_FUNCTION); |
86 GRAPH_TYPED_DATA_INTRINSICS_LIST(SETUP_FUNCTION); | 110 GRAPH_TYPED_DATA_INTRINSICS_LIST(SETUP_FUNCTION); |
87 | 111 |
88 // Setup all dart:developer lib functions that can be intrinsified. | 112 // Setup all dart:developer lib functions that can be intrinsified. |
89 lib = Library::DeveloperLibrary(); | 113 lib = Library::DeveloperLibrary(); |
90 ASSERT(!lib.IsNull()); | 114 ASSERT(!lib.IsNull()); |
91 DEVELOPER_LIB_INTRINSIC_LIST(SETUP_FUNCTION); | 115 DEVELOPER_LIB_INTRINSIC_LIST(SETUP_FUNCTION); |
92 | 116 |
93 #undef SETUP_FUNCTION | 117 #undef SETUP_FUNCTION |
94 } | 118 } |
95 #endif // defined(DART_NO_SNAPSHOT). | 119 #endif // defined(DART_NO_SNAPSHOT). |
96 | 120 |
97 | |
98 static void EmitCodeFor(FlowGraphCompiler* compiler, | 121 static void EmitCodeFor(FlowGraphCompiler* compiler, |
99 FlowGraph* graph) { | 122 FlowGraph* graph) { |
100 // The FlowGraph here is constructed by the intrinsics builder methods, and | 123 // The FlowGraph here is constructed by the intrinsics builder methods, and |
101 // is different from compiler->flow_graph(), the original method's flow graph. | 124 // is different from compiler->flow_graph(), the original method's flow graph. |
102 compiler->assembler()->Comment("Graph intrinsic"); | 125 compiler->assembler()->Comment("Graph intrinsic begin"); |
103 for (intptr_t i = 0; i < graph->reverse_postorder().length(); i++) { | 126 for (intptr_t i = 0; i < graph->reverse_postorder().length(); i++) { |
104 BlockEntryInstr* block = graph->reverse_postorder()[i]; | 127 BlockEntryInstr* block = graph->reverse_postorder()[i]; |
105 if (block->IsGraphEntry()) continue; // No code for graph entry needed. | 128 if (block->IsGraphEntry()) continue; // No code for graph entry needed. |
106 | 129 |
107 if (block->HasParallelMove()) { | 130 if (block->HasParallelMove()) { |
108 compiler->parallel_move_resolver()->EmitNativeCode( | 131 compiler->parallel_move_resolver()->EmitNativeCode( |
109 block->parallel_move()); | 132 block->parallel_move()); |
110 } | 133 } |
111 | 134 |
112 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) { | 135 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) { |
113 Instruction* instr = it.Current(); | 136 Instruction* instr = it.Current(); |
114 if (FLAG_code_comments) compiler->EmitComment(instr); | 137 if (FLAG_code_comments) compiler->EmitComment(instr); |
115 if (instr->IsParallelMove()) { | 138 if (instr->IsParallelMove()) { |
116 compiler->parallel_move_resolver()->EmitNativeCode( | 139 compiler->parallel_move_resolver()->EmitNativeCode( |
117 instr->AsParallelMove()); | 140 instr->AsParallelMove()); |
| 141 } else if (instr->IsInvokeMathCFunction()) { |
| 142 ASSERT(instr->locs() != NULL); |
| 143 Intrinsifier::IntrinsicCallPrologue(compiler->assembler()); |
| 144 instr->EmitNativeCode(compiler); |
| 145 Intrinsifier::IntrinsicCallEpilogue(compiler->assembler()); |
118 } else { | 146 } else { |
119 ASSERT(instr->locs() != NULL); | 147 ASSERT(instr->locs() != NULL); |
120 // Calls are not supported in intrinsics code. | 148 // Calls are not supported in intrinsics code. |
121 ASSERT(!instr->locs()->always_calls()); | 149 ASSERT(!instr->locs()->always_calls()); |
122 instr->EmitNativeCode(compiler); | 150 instr->EmitNativeCode(compiler); |
123 } | 151 } |
124 } | 152 } |
125 } | 153 } |
| 154 compiler->assembler()->Comment("Graph intrinsic end"); |
126 } | 155 } |
127 | 156 |
128 | 157 |
129 bool Intrinsifier::GraphIntrinsify(const ParsedFunction& parsed_function, | 158 bool Intrinsifier::GraphIntrinsify(const ParsedFunction& parsed_function, |
130 FlowGraphCompiler* compiler) { | 159 FlowGraphCompiler* compiler) { |
131 ZoneGrowableArray<const ICData*>* ic_data_array = | 160 ZoneGrowableArray<const ICData*>* ic_data_array = |
132 new ZoneGrowableArray<const ICData*>(); | 161 new ZoneGrowableArray<const ICData*>(); |
133 FlowGraphBuilder builder(parsed_function, | 162 FlowGraphBuilder builder(parsed_function, |
134 *ic_data_array, | 163 *ic_data_array, |
135 NULL, // NULL = not inlining. | 164 NULL, // NULL = not inlining. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 return kFloat32x4Cid; | 246 return kFloat32x4Cid; |
218 case kUnboxedUint32: | 247 case kUnboxedUint32: |
219 return kDynamicCid; // smi or mint. | 248 return kDynamicCid; // smi or mint. |
220 default: | 249 default: |
221 UNREACHABLE(); | 250 UNREACHABLE(); |
222 return kIllegalCid; | 251 return kIllegalCid; |
223 } | 252 } |
224 } | 253 } |
225 | 254 |
226 | 255 |
| 256 // Notes about the graph intrinsics: |
| 257 // |
| 258 // IR instructions which would jump to a deoptimization sequence on failure |
| 259 // instead branch to the intrinsic slow path. |
| 260 // |
227 class BlockBuilder : public ValueObject { | 261 class BlockBuilder : public ValueObject { |
228 public: | 262 public: |
229 BlockBuilder(FlowGraph* flow_graph, TargetEntryInstr* entry) | 263 BlockBuilder(FlowGraph* flow_graph, TargetEntryInstr* entry) |
230 : flow_graph_(flow_graph), entry_(entry), current_(entry) { } | 264 : flow_graph_(flow_graph), entry_(entry), current_(entry) { } |
231 | 265 |
232 Definition* AddToInitialDefinitions(Definition* def) { | 266 Definition* AddToInitialDefinitions(Definition* def) { |
233 def->set_ssa_temp_index(flow_graph_->alloc_ssa_temp_index()); | 267 def->set_ssa_temp_index(flow_graph_->alloc_ssa_temp_index()); |
234 flow_graph_->AddToInitialDefinitions(def); | 268 flow_graph_->AddToInitialDefinitions(def); |
235 return def; | 269 return def; |
236 } | 270 } |
(...skipping 25 matching lines...) Expand all Loading... |
262 | 296 |
263 TokenPosition TokenPos() { | 297 TokenPosition TokenPos() { |
264 return flow_graph_->function().token_pos(); | 298 return flow_graph_->function().token_pos(); |
265 } | 299 } |
266 | 300 |
267 Definition* AddNullDefinition() { | 301 Definition* AddNullDefinition() { |
268 return AddDefinition( | 302 return AddDefinition( |
269 new ConstantInstr(Object::ZoneHandle(Object::null()))); | 303 new ConstantInstr(Object::ZoneHandle(Object::null()))); |
270 } | 304 } |
271 | 305 |
272 Definition* AddUnboxInstr(Representation rep, Value* value) { | 306 Definition* AddUnboxInstr(Representation rep, |
| 307 Value* value, |
| 308 bool is_checked) { |
273 Definition* unboxed_value = AddDefinition( | 309 Definition* unboxed_value = AddDefinition( |
274 UnboxInstr::Create(rep, value, Thread::kNoDeoptId)); | 310 UnboxInstr::Create(rep, value, Thread::kNoDeoptId)); |
275 // Manually adjust reaching type because there is no type propagation | 311 if (is_checked) { |
276 // when building intrinsics. | 312 // The type of |value| has already been checked and it is safe to |
277 unboxed_value->AsUnbox()->value()->SetReachingType(ZoneCompileType::Wrap( | 313 // adjust reaching type. This is done manually because there is no type |
278 CompileType::FromCid(CidForRepresentation(rep)))); | 314 // propagation when building intrinsics. |
| 315 unboxed_value->AsUnbox()->value()->SetReachingType(ZoneCompileType::Wrap( |
| 316 CompileType::FromCid(CidForRepresentation(rep)))); |
| 317 } |
279 return unboxed_value; | 318 return unboxed_value; |
280 } | 319 } |
281 | 320 |
| 321 Definition* AddUnboxInstr(Representation rep, |
| 322 Definition* boxed, |
| 323 bool is_checked) { |
| 324 return AddUnboxInstr(rep, new Value(boxed), is_checked); |
| 325 } |
| 326 |
| 327 Definition* InvokeMathCFunction(MethodRecognizer::Kind recognized_kind, |
| 328 ZoneGrowableArray<Value*>* args) { |
| 329 return InvokeMathCFunctionHelper(recognized_kind, args); |
| 330 } |
| 331 |
282 private: | 332 private: |
| 333 Definition* InvokeMathCFunctionHelper(MethodRecognizer::Kind recognized_kind, |
| 334 ZoneGrowableArray<Value*>* args) { |
| 335 InvokeMathCFunctionInstr* invoke_math_c_function = |
| 336 new InvokeMathCFunctionInstr(args, |
| 337 Thread::kNoDeoptId, |
| 338 recognized_kind, |
| 339 TokenPos()); |
| 340 AddDefinition(invoke_math_c_function); |
| 341 return invoke_math_c_function; |
| 342 } |
| 343 |
| 344 |
283 FlowGraph* flow_graph_; | 345 FlowGraph* flow_graph_; |
284 BlockEntryInstr* entry_; | 346 BlockEntryInstr* entry_; |
285 Instruction* current_; | 347 Instruction* current_; |
286 }; | 348 }; |
287 | 349 |
288 | 350 |
289 static void PrepareIndexedOp(BlockBuilder* builder, | 351 static void PrepareIndexedOp(BlockBuilder* builder, |
290 Definition* array, | 352 Definition* array, |
291 Definition* index, | 353 Definition* index, |
292 intptr_t length_offset) { | 354 intptr_t length_offset) { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); | 515 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); |
454 BlockBuilder builder(flow_graph, normal_entry); | 516 BlockBuilder builder(flow_graph, normal_entry); |
455 | 517 |
456 Definition* value = builder.AddParameter(1); | 518 Definition* value = builder.AddParameter(1); |
457 Definition* index = builder.AddParameter(2); | 519 Definition* index = builder.AddParameter(2); |
458 Definition* array = builder.AddParameter(3); | 520 Definition* array = builder.AddParameter(3); |
459 | 521 |
460 PrepareIndexedOp(&builder, array, index, TypedData::length_offset()); | 522 PrepareIndexedOp(&builder, array, index, TypedData::length_offset()); |
461 | 523 |
462 Definition* unboxed_value = | 524 Definition* unboxed_value = |
463 builder.AddUnboxInstr(kUnboxedUint32, new Value(value)); | 525 builder.AddUnboxInstr(kUnboxedUint32, |
| 526 new Value(value), |
| 527 /* is_checked = */ true); |
464 | 528 |
465 builder.AddInstruction( | 529 builder.AddInstruction( |
466 new StoreIndexedInstr(new Value(array), | 530 new StoreIndexedInstr(new Value(array), |
467 new Value(index), | 531 new Value(index), |
468 new Value(unboxed_value), | 532 new Value(unboxed_value), |
469 kNoStoreBarrier, | 533 kNoStoreBarrier, |
470 4, // index scale | 534 4, // index scale |
471 kTypedDataUint32ArrayCid, | 535 kTypedDataUint32ArrayCid, |
472 Thread::kNoDeoptId, | 536 Thread::kNoDeoptId, |
473 builder.TokenPos())); | 537 builder.TokenPos())); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 Object::empty_array(), // Dummy args. descr. | 585 Object::empty_array(), // Dummy args. descr. |
522 Thread::kNoDeoptId, | 586 Thread::kNoDeoptId, |
523 1)); | 587 1)); |
524 value_check.AddReceiverCheck(kDoubleCid, flow_graph->function()); | 588 value_check.AddReceiverCheck(kDoubleCid, flow_graph->function()); |
525 builder.AddInstruction( | 589 builder.AddInstruction( |
526 new CheckClassInstr(new Value(value), | 590 new CheckClassInstr(new Value(value), |
527 Thread::kNoDeoptId, | 591 Thread::kNoDeoptId, |
528 value_check, | 592 value_check, |
529 builder.TokenPos())); | 593 builder.TokenPos())); |
530 Definition* double_value = | 594 Definition* double_value = |
531 builder.AddUnboxInstr(kUnboxedDouble, new Value(value)); | 595 builder.AddUnboxInstr(kUnboxedDouble, |
| 596 new Value(value), |
| 597 /* is_checked = */ true); |
532 | 598 |
533 builder.AddInstruction( | 599 builder.AddInstruction( |
534 new StoreIndexedInstr(new Value(array), | 600 new StoreIndexedInstr(new Value(array), |
535 new Value(index), | 601 new Value(index), |
536 new Value(double_value), | 602 new Value(double_value), |
537 kNoStoreBarrier, | 603 kNoStoreBarrier, |
538 8, // index scale | 604 8, // index scale |
539 kTypedDataFloat64ArrayCid, | 605 kTypedDataFloat64ArrayCid, |
540 Thread::kNoDeoptId, | 606 Thread::kNoDeoptId, |
541 builder.TokenPos())); | 607 builder.TokenPos())); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 Thread::kNoDeoptId, | 655 Thread::kNoDeoptId, |
590 1)); | 656 1)); |
591 value_check.AddReceiverCheck(kFloat32x4Cid, flow_graph->function()); | 657 value_check.AddReceiverCheck(kFloat32x4Cid, flow_graph->function()); |
592 // Check argument. Receiver (left) is known to be a Float32x4. | 658 // Check argument. Receiver (left) is known to be a Float32x4. |
593 builder.AddInstruction( | 659 builder.AddInstruction( |
594 new CheckClassInstr(new Value(right), | 660 new CheckClassInstr(new Value(right), |
595 Thread::kNoDeoptId, | 661 Thread::kNoDeoptId, |
596 value_check, | 662 value_check, |
597 builder.TokenPos())); | 663 builder.TokenPos())); |
598 Definition* left_simd = | 664 Definition* left_simd = |
599 builder.AddUnboxInstr(kUnboxedFloat32x4, new Value(left)); | 665 builder.AddUnboxInstr(kUnboxedFloat32x4, |
| 666 new Value(left), |
| 667 /* is_checked = */ true); |
600 | 668 |
601 Definition* right_simd = | 669 Definition* right_simd = |
602 builder.AddUnboxInstr(kUnboxedFloat32x4, new Value(right)); | 670 builder.AddUnboxInstr(kUnboxedFloat32x4, |
| 671 new Value(right), |
| 672 /* is_checked = */ true); |
603 | 673 |
604 Definition* unboxed_result = builder.AddDefinition( | 674 Definition* unboxed_result = builder.AddDefinition( |
605 new BinaryFloat32x4OpInstr(kind, | 675 new BinaryFloat32x4OpInstr(kind, |
606 new Value(left_simd), | 676 new Value(left_simd), |
607 new Value(right_simd), | 677 new Value(right_simd), |
608 Thread::kNoDeoptId)); | 678 Thread::kNoDeoptId)); |
609 Definition* result = builder.AddDefinition( | 679 Definition* result = builder.AddDefinition( |
610 BoxInstr::Create(kUnboxedFloat32x4, new Value(unboxed_result))); | 680 BoxInstr::Create(kUnboxedFloat32x4, new Value(unboxed_result))); |
611 builder.AddIntrinsicReturn(new Value(result)); | 681 builder.AddIntrinsicReturn(new Value(result)); |
612 return true; | 682 return true; |
(...skipping 18 matching lines...) Expand all Loading... |
631 static bool BuildFloat32x4Shuffle(FlowGraph* flow_graph, | 701 static bool BuildFloat32x4Shuffle(FlowGraph* flow_graph, |
632 MethodRecognizer::Kind kind) { | 702 MethodRecognizer::Kind kind) { |
633 if (!FlowGraphCompiler::SupportsUnboxedSimd128()) return false; | 703 if (!FlowGraphCompiler::SupportsUnboxedSimd128()) return false; |
634 GraphEntryInstr* graph_entry = flow_graph->graph_entry(); | 704 GraphEntryInstr* graph_entry = flow_graph->graph_entry(); |
635 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); | 705 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); |
636 BlockBuilder builder(flow_graph, normal_entry); | 706 BlockBuilder builder(flow_graph, normal_entry); |
637 | 707 |
638 Definition* receiver = builder.AddParameter(1); | 708 Definition* receiver = builder.AddParameter(1); |
639 | 709 |
640 Definition* unboxed_receiver = | 710 Definition* unboxed_receiver = |
641 builder.AddUnboxInstr(kUnboxedFloat32x4, new Value(receiver)); | 711 builder.AddUnboxInstr(kUnboxedFloat32x4, |
| 712 new Value(receiver), |
| 713 /* is_checked = */ true); |
642 | 714 |
643 Definition* unboxed_result = builder.AddDefinition( | 715 Definition* unboxed_result = builder.AddDefinition( |
644 new Simd32x4ShuffleInstr(kind, | 716 new Simd32x4ShuffleInstr(kind, |
645 new Value(unboxed_receiver), | 717 new Value(unboxed_receiver), |
646 0, | 718 0, |
647 Thread::kNoDeoptId)); | 719 Thread::kNoDeoptId)); |
648 | 720 |
649 Definition* result = builder.AddDefinition( | 721 Definition* result = builder.AddDefinition( |
650 BoxInstr::Create(kUnboxedDouble, new Value(unboxed_result))); | 722 BoxInstr::Create(kUnboxedDouble, new Value(unboxed_result))); |
651 builder.AddIntrinsicReturn(new Value(result)); | 723 builder.AddIntrinsicReturn(new Value(result)); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 } | 937 } |
866 | 938 |
867 | 939 |
868 bool Intrinsifier::Build_DoubleFlipSignBit(FlowGraph* flow_graph) { | 940 bool Intrinsifier::Build_DoubleFlipSignBit(FlowGraph* flow_graph) { |
869 GraphEntryInstr* graph_entry = flow_graph->graph_entry(); | 941 GraphEntryInstr* graph_entry = flow_graph->graph_entry(); |
870 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); | 942 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); |
871 BlockBuilder builder(flow_graph, normal_entry); | 943 BlockBuilder builder(flow_graph, normal_entry); |
872 | 944 |
873 Definition* receiver = builder.AddParameter(1); | 945 Definition* receiver = builder.AddParameter(1); |
874 Definition* unboxed_value = | 946 Definition* unboxed_value = |
875 builder.AddUnboxInstr(kUnboxedDouble, new Value(receiver)); | 947 builder.AddUnboxInstr(kUnboxedDouble, |
| 948 new Value(receiver), |
| 949 /* is_checked = */ true); |
876 Definition* unboxed_result = builder.AddDefinition( | 950 Definition* unboxed_result = builder.AddDefinition( |
877 new UnaryDoubleOpInstr(Token::kNEGATE, | 951 new UnaryDoubleOpInstr(Token::kNEGATE, |
878 new Value(unboxed_value), | 952 new Value(unboxed_value), |
879 Thread::kNoDeoptId)); | 953 Thread::kNoDeoptId)); |
880 Definition* result = builder.AddDefinition( | 954 Definition* result = builder.AddDefinition( |
881 BoxInstr::Create(kUnboxedDouble, new Value(unboxed_result))); | 955 BoxInstr::Create(kUnboxedDouble, new Value(unboxed_result))); |
882 builder.AddIntrinsicReturn(new Value(result)); | 956 builder.AddIntrinsicReturn(new Value(result)); |
883 return true; | 957 return true; |
884 } | 958 } |
885 | 959 |
| 960 |
| 961 static bool BuildInvokeMathCFunction(BlockBuilder* builder, |
| 962 MethodRecognizer::Kind kind, |
| 963 intptr_t num_parameters = 1) { |
| 964 ZoneGrowableArray<Value*>* args = |
| 965 new ZoneGrowableArray<Value*>(num_parameters); |
| 966 |
| 967 for (intptr_t i = 0; i < num_parameters; i++) { |
| 968 const intptr_t parameter_index = (num_parameters - i); |
| 969 Definition* value = builder->AddParameter(parameter_index); |
| 970 Definition* unboxed_value = |
| 971 builder->AddUnboxInstr(kUnboxedDouble, value, /* is_checked = */ false); |
| 972 args->Add(new Value(unboxed_value)); |
| 973 } |
| 974 |
| 975 Definition* unboxed_result = |
| 976 builder->InvokeMathCFunction(kind, args); |
| 977 |
| 978 Definition* result = builder->AddDefinition( |
| 979 BoxInstr::Create(kUnboxedDouble, new Value(unboxed_result))); |
| 980 |
| 981 builder->AddIntrinsicReturn(new Value(result)); |
| 982 |
| 983 return true; |
| 984 } |
| 985 |
| 986 |
| 987 bool Intrinsifier::Build_MathSin(FlowGraph* flow_graph) { |
| 988 if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false; |
| 989 |
| 990 GraphEntryInstr* graph_entry = flow_graph->graph_entry(); |
| 991 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); |
| 992 BlockBuilder builder(flow_graph, normal_entry); |
| 993 |
| 994 return BuildInvokeMathCFunction(&builder, |
| 995 MethodRecognizer::kMathSin); |
| 996 } |
| 997 |
| 998 |
| 999 bool Intrinsifier::Build_MathCos(FlowGraph* flow_graph) { |
| 1000 if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false; |
| 1001 |
| 1002 GraphEntryInstr* graph_entry = flow_graph->graph_entry(); |
| 1003 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); |
| 1004 BlockBuilder builder(flow_graph, normal_entry); |
| 1005 |
| 1006 return BuildInvokeMathCFunction(&builder, |
| 1007 MethodRecognizer::kMathCos); |
| 1008 } |
| 1009 |
| 1010 |
| 1011 bool Intrinsifier::Build_MathTan(FlowGraph* flow_graph) { |
| 1012 if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false; |
| 1013 |
| 1014 GraphEntryInstr* graph_entry = flow_graph->graph_entry(); |
| 1015 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); |
| 1016 BlockBuilder builder(flow_graph, normal_entry); |
| 1017 |
| 1018 return BuildInvokeMathCFunction(&builder, |
| 1019 MethodRecognizer::kMathTan); |
| 1020 } |
| 1021 |
| 1022 |
| 1023 bool Intrinsifier::Build_MathAsin(FlowGraph* flow_graph) { |
| 1024 if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false; |
| 1025 |
| 1026 GraphEntryInstr* graph_entry = flow_graph->graph_entry(); |
| 1027 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); |
| 1028 BlockBuilder builder(flow_graph, normal_entry); |
| 1029 |
| 1030 return BuildInvokeMathCFunction(&builder, |
| 1031 MethodRecognizer::kMathAsin); |
| 1032 } |
| 1033 |
| 1034 |
| 1035 bool Intrinsifier::Build_MathAcos(FlowGraph* flow_graph) { |
| 1036 if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false; |
| 1037 |
| 1038 GraphEntryInstr* graph_entry = flow_graph->graph_entry(); |
| 1039 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); |
| 1040 BlockBuilder builder(flow_graph, normal_entry); |
| 1041 |
| 1042 return BuildInvokeMathCFunction(&builder, |
| 1043 MethodRecognizer::kMathAcos); |
| 1044 } |
| 1045 |
| 1046 |
| 1047 bool Intrinsifier::Build_MathAtan(FlowGraph* flow_graph) { |
| 1048 if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false; |
| 1049 |
| 1050 GraphEntryInstr* graph_entry = flow_graph->graph_entry(); |
| 1051 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); |
| 1052 BlockBuilder builder(flow_graph, normal_entry); |
| 1053 |
| 1054 return BuildInvokeMathCFunction(&builder, |
| 1055 MethodRecognizer::kMathAtan); |
| 1056 } |
| 1057 |
| 1058 |
| 1059 bool Intrinsifier::Build_MathAtan2(FlowGraph* flow_graph) { |
| 1060 if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false; |
| 1061 |
| 1062 GraphEntryInstr* graph_entry = flow_graph->graph_entry(); |
| 1063 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); |
| 1064 BlockBuilder builder(flow_graph, normal_entry); |
| 1065 |
| 1066 return BuildInvokeMathCFunction(&builder, |
| 1067 MethodRecognizer::kMathAtan2, |
| 1068 /* num_parameters = */ 2); |
| 1069 } |
| 1070 |
886 } // namespace dart | 1071 } // namespace dart |
OLD | NEW |