Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: runtime/vm/intrinsifier.cc

Issue 1821783002: Add graph intrinsics for many math library functions (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/intermediate_language.cc ('k') | runtime/vm/method_recognizer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 121
98 static void EmitCodeFor(FlowGraphCompiler* compiler, 122 static void EmitCodeFor(FlowGraphCompiler* compiler,
99 FlowGraph* graph) { 123 FlowGraph* graph) {
100 // The FlowGraph here is constructed by the intrinsics builder methods, and 124 // The FlowGraph here is constructed by the intrinsics builder methods, and
101 // is different from compiler->flow_graph(), the original method's flow graph. 125 // is different from compiler->flow_graph(), the original method's flow graph.
102 compiler->assembler()->Comment("Graph intrinsic"); 126 compiler->assembler()->Comment("Graph intrinsic begin");
103 for (intptr_t i = 0; i < graph->reverse_postorder().length(); i++) { 127 for (intptr_t i = 0; i < graph->reverse_postorder().length(); i++) {
104 BlockEntryInstr* block = graph->reverse_postorder()[i]; 128 BlockEntryInstr* block = graph->reverse_postorder()[i];
105 if (block->IsGraphEntry()) continue; // No code for graph entry needed. 129 if (block->IsGraphEntry()) continue; // No code for graph entry needed.
106 130
107 if (block->HasParallelMove()) { 131 if (block->HasParallelMove()) {
108 compiler->parallel_move_resolver()->EmitNativeCode( 132 compiler->parallel_move_resolver()->EmitNativeCode(
109 block->parallel_move()); 133 block->parallel_move());
110 } 134 }
111 135
112 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) { 136 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) {
113 Instruction* instr = it.Current(); 137 Instruction* instr = it.Current();
114 if (FLAG_code_comments) compiler->EmitComment(instr); 138 if (FLAG_code_comments) compiler->EmitComment(instr);
115 if (instr->IsParallelMove()) { 139 if (instr->IsParallelMove()) {
116 compiler->parallel_move_resolver()->EmitNativeCode( 140 compiler->parallel_move_resolver()->EmitNativeCode(
117 instr->AsParallelMove()); 141 instr->AsParallelMove());
142 } else if (instr->IsInvokeMathCFunction()) {
143 ASSERT(instr->locs() != NULL);
144 // InvokeMathCFunction always calls, but it uses registers that
145 // are free for the intrinsic to use.
146 instr->EmitNativeCode(compiler);
118 } else { 147 } else {
119 ASSERT(instr->locs() != NULL); 148 ASSERT(instr->locs() != NULL);
120 // Calls are not supported in intrinsics code. 149 // Calls are not supported in intrinsics code.
121 ASSERT(!instr->locs()->always_calls()); 150 ASSERT(!instr->locs()->always_calls());
122 instr->EmitNativeCode(compiler); 151 instr->EmitNativeCode(compiler);
123 } 152 }
124 } 153 }
125 } 154 }
155 compiler->assembler()->Comment("Graph intrinsic end");
126 } 156 }
127 157
128 158
129 bool Intrinsifier::GraphIntrinsify(const ParsedFunction& parsed_function, 159 bool Intrinsifier::GraphIntrinsify(const ParsedFunction& parsed_function,
130 FlowGraphCompiler* compiler) { 160 FlowGraphCompiler* compiler) {
131 ZoneGrowableArray<const ICData*>* ic_data_array = 161 ZoneGrowableArray<const ICData*>* ic_data_array =
132 new ZoneGrowableArray<const ICData*>(); 162 new ZoneGrowableArray<const ICData*>();
133 FlowGraphBuilder builder(parsed_function, 163 FlowGraphBuilder builder(parsed_function,
134 *ic_data_array, 164 *ic_data_array,
135 NULL, // NULL = not inlining. 165 NULL, // NULL = not inlining.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 return kFloat32x4Cid; 247 return kFloat32x4Cid;
218 case kUnboxedUint32: 248 case kUnboxedUint32:
219 return kDynamicCid; // smi or mint. 249 return kDynamicCid; // smi or mint.
220 default: 250 default:
221 UNREACHABLE(); 251 UNREACHABLE();
222 return kIllegalCid; 252 return kIllegalCid;
223 } 253 }
224 } 254 }
225 255
226 256
257 // Notes about the graph intrinsics:
258 //
259 // IR instructions which would jump to a deoptimization sequence on failure
260 // instead branch to the intrinsic slow path.
261 //
227 class BlockBuilder : public ValueObject { 262 class BlockBuilder : public ValueObject {
228 public: 263 public:
229 BlockBuilder(FlowGraph* flow_graph, TargetEntryInstr* entry) 264 BlockBuilder(FlowGraph* flow_graph, TargetEntryInstr* entry)
230 : flow_graph_(flow_graph), entry_(entry), current_(entry) { } 265 : flow_graph_(flow_graph), entry_(entry), current_(entry) { }
231 266
232 Definition* AddToInitialDefinitions(Definition* def) { 267 Definition* AddToInitialDefinitions(Definition* def) {
233 def->set_ssa_temp_index(flow_graph_->alloc_ssa_temp_index()); 268 def->set_ssa_temp_index(flow_graph_->alloc_ssa_temp_index());
234 flow_graph_->AddToInitialDefinitions(def); 269 flow_graph_->AddToInitialDefinitions(def);
235 return def; 270 return def;
236 } 271 }
(...skipping 16 matching lines...) Expand all
253 } 288 }
254 289
255 Definition* AddParameter(intptr_t index) { 290 Definition* AddParameter(intptr_t index) {
256 intptr_t adjustment = Intrinsifier::ParameterSlotFromSp(); 291 intptr_t adjustment = Intrinsifier::ParameterSlotFromSp();
257 return AddToInitialDefinitions( 292 return AddToInitialDefinitions(
258 new ParameterInstr(adjustment + index, 293 new ParameterInstr(adjustment + index,
259 flow_graph_->graph_entry(), 294 flow_graph_->graph_entry(),
260 SPREG)); 295 SPREG));
261 } 296 }
262 297
298 Definition* AddCheckedUnbox(Representation rep, Definition* boxed) {
Florian Schneider 2016/03/22 16:26:21 Remove if not needed anymore.
299 const ICData& value_check = ICData::ZoneHandle(ICData::New(
300 flow_graph_->function(),
301 String::Handle(flow_graph_->function().name()),
302 Object::empty_array(), // Dummy args. descr.
303 Thread::kNoDeoptId,
304 1));
305 value_check.AddReceiverCheck(CidForRepresentation(rep),
306 flow_graph_->function());
307 AddInstruction(new CheckClassInstr(new Value(boxed),
308 Thread::kNoDeoptId,
309 value_check,
310 TokenPos()));
311 return AddUnboxInstr(rep, new Value(boxed), /* is_checked = */ true);
312 }
313
263 TokenPosition TokenPos() { 314 TokenPosition TokenPos() {
264 return flow_graph_->function().token_pos(); 315 return flow_graph_->function().token_pos();
265 } 316 }
266 317
267 Definition* AddNullDefinition() { 318 Definition* AddNullDefinition() {
268 return AddDefinition( 319 return AddDefinition(
269 new ConstantInstr(Object::ZoneHandle(Object::null()))); 320 new ConstantInstr(Object::ZoneHandle(Object::null())));
270 } 321 }
271 322
272 Definition* AddUnboxInstr(Representation rep, Value* value) { 323 Definition* AddUnboxInstr(Representation rep,
324 Value* value,
325 bool is_checked) {
273 Definition* unboxed_value = AddDefinition( 326 Definition* unboxed_value = AddDefinition(
274 UnboxInstr::Create(rep, value, Thread::kNoDeoptId)); 327 UnboxInstr::Create(rep, value, Thread::kNoDeoptId));
275 // Manually adjust reaching type because there is no type propagation 328 if (is_checked) {
276 // when building intrinsics. 329 // The type of |value| has already been checked and it is safe to
277 unboxed_value->AsUnbox()->value()->SetReachingType(ZoneCompileType::Wrap( 330 // adjust reaching type. This is done manually because there is no type
278 CompileType::FromCid(CidForRepresentation(rep)))); 331 // propagation when building intrinsics.
332 unboxed_value->AsUnbox()->value()->SetReachingType(ZoneCompileType::Wrap(
333 CompileType::FromCid(CidForRepresentation(rep))));
334 }
279 return unboxed_value; 335 return unboxed_value;
280 } 336 }
281 337
338 Definition* AddUnboxInstr(Representation rep,
339 Definition* boxed,
340 bool is_checked) {
341 return AddUnboxInstr(rep, new Value(boxed), is_checked);
342 }
343
344 Definition* InvokeMathCFunction(MethodRecognizer::Kind recognized_kind,
345 ZoneGrowableArray<Value*>* args) {
346 return InvokeMathCFunctionHelper(recognized_kind, args);
347 }
348
282 private: 349 private:
350 Definition* InvokeMathCFunctionHelper(MethodRecognizer::Kind recognized_kind,
351 ZoneGrowableArray<Value*>* args) {
352 InvokeMathCFunctionInstr* invoke_math_c_function =
353 new InvokeMathCFunctionInstr(args,
354 Thread::kNoDeoptId,
355 recognized_kind,
356 TokenPos());
357 AddDefinition(invoke_math_c_function);
358 return invoke_math_c_function;
359 }
360
361
283 FlowGraph* flow_graph_; 362 FlowGraph* flow_graph_;
284 BlockEntryInstr* entry_; 363 BlockEntryInstr* entry_;
285 Instruction* current_; 364 Instruction* current_;
286 }; 365 };
287 366
288 367
289 static void PrepareIndexedOp(BlockBuilder* builder, 368 static void PrepareIndexedOp(BlockBuilder* builder,
290 Definition* array, 369 Definition* array,
291 Definition* index, 370 Definition* index,
292 intptr_t length_offset) { 371 intptr_t length_offset) {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); 532 TargetEntryInstr* normal_entry = graph_entry->normal_entry();
454 BlockBuilder builder(flow_graph, normal_entry); 533 BlockBuilder builder(flow_graph, normal_entry);
455 534
456 Definition* value = builder.AddParameter(1); 535 Definition* value = builder.AddParameter(1);
457 Definition* index = builder.AddParameter(2); 536 Definition* index = builder.AddParameter(2);
458 Definition* array = builder.AddParameter(3); 537 Definition* array = builder.AddParameter(3);
459 538
460 PrepareIndexedOp(&builder, array, index, TypedData::length_offset()); 539 PrepareIndexedOp(&builder, array, index, TypedData::length_offset());
461 540
462 Definition* unboxed_value = 541 Definition* unboxed_value =
463 builder.AddUnboxInstr(kUnboxedUint32, new Value(value)); 542 builder.AddUnboxInstr(kUnboxedUint32,
543 new Value(value),
544 /* is_checked = */ true);
464 545
465 builder.AddInstruction( 546 builder.AddInstruction(
466 new StoreIndexedInstr(new Value(array), 547 new StoreIndexedInstr(new Value(array),
467 new Value(index), 548 new Value(index),
468 new Value(unboxed_value), 549 new Value(unboxed_value),
469 kNoStoreBarrier, 550 kNoStoreBarrier,
470 4, // index scale 551 4, // index scale
471 kTypedDataUint32ArrayCid, 552 kTypedDataUint32ArrayCid,
472 Thread::kNoDeoptId, 553 Thread::kNoDeoptId,
473 builder.TokenPos())); 554 builder.TokenPos()));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 Object::empty_array(), // Dummy args. descr. 602 Object::empty_array(), // Dummy args. descr.
522 Thread::kNoDeoptId, 603 Thread::kNoDeoptId,
523 1)); 604 1));
524 value_check.AddReceiverCheck(kDoubleCid, flow_graph->function()); 605 value_check.AddReceiverCheck(kDoubleCid, flow_graph->function());
525 builder.AddInstruction( 606 builder.AddInstruction(
526 new CheckClassInstr(new Value(value), 607 new CheckClassInstr(new Value(value),
527 Thread::kNoDeoptId, 608 Thread::kNoDeoptId,
528 value_check, 609 value_check,
529 builder.TokenPos())); 610 builder.TokenPos()));
530 Definition* double_value = 611 Definition* double_value =
531 builder.AddUnboxInstr(kUnboxedDouble, new Value(value)); 612 builder.AddUnboxInstr(kUnboxedDouble,
613 new Value(value),
614 /* is_checked = */ true);
532 615
533 builder.AddInstruction( 616 builder.AddInstruction(
534 new StoreIndexedInstr(new Value(array), 617 new StoreIndexedInstr(new Value(array),
535 new Value(index), 618 new Value(index),
536 new Value(double_value), 619 new Value(double_value),
537 kNoStoreBarrier, 620 kNoStoreBarrier,
538 8, // index scale 621 8, // index scale
539 kTypedDataFloat64ArrayCid, 622 kTypedDataFloat64ArrayCid,
540 Thread::kNoDeoptId, 623 Thread::kNoDeoptId,
541 builder.TokenPos())); 624 builder.TokenPos()));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 Thread::kNoDeoptId, 672 Thread::kNoDeoptId,
590 1)); 673 1));
591 value_check.AddReceiverCheck(kFloat32x4Cid, flow_graph->function()); 674 value_check.AddReceiverCheck(kFloat32x4Cid, flow_graph->function());
592 // Check argument. Receiver (left) is known to be a Float32x4. 675 // Check argument. Receiver (left) is known to be a Float32x4.
593 builder.AddInstruction( 676 builder.AddInstruction(
594 new CheckClassInstr(new Value(right), 677 new CheckClassInstr(new Value(right),
595 Thread::kNoDeoptId, 678 Thread::kNoDeoptId,
596 value_check, 679 value_check,
597 builder.TokenPos())); 680 builder.TokenPos()));
598 Definition* left_simd = 681 Definition* left_simd =
599 builder.AddUnboxInstr(kUnboxedFloat32x4, new Value(left)); 682 builder.AddUnboxInstr(kUnboxedFloat32x4,
683 new Value(left),
684 /* is_checked = */ true);
600 685
601 Definition* right_simd = 686 Definition* right_simd =
602 builder.AddUnboxInstr(kUnboxedFloat32x4, new Value(right)); 687 builder.AddUnboxInstr(kUnboxedFloat32x4,
688 new Value(right),
689 /* is_checked = */ true);
603 690
604 Definition* unboxed_result = builder.AddDefinition( 691 Definition* unboxed_result = builder.AddDefinition(
605 new BinaryFloat32x4OpInstr(kind, 692 new BinaryFloat32x4OpInstr(kind,
606 new Value(left_simd), 693 new Value(left_simd),
607 new Value(right_simd), 694 new Value(right_simd),
608 Thread::kNoDeoptId)); 695 Thread::kNoDeoptId));
609 Definition* result = builder.AddDefinition( 696 Definition* result = builder.AddDefinition(
610 BoxInstr::Create(kUnboxedFloat32x4, new Value(unboxed_result))); 697 BoxInstr::Create(kUnboxedFloat32x4, new Value(unboxed_result)));
611 builder.AddIntrinsicReturn(new Value(result)); 698 builder.AddIntrinsicReturn(new Value(result));
612 return true; 699 return true;
(...skipping 18 matching lines...) Expand all
631 static bool BuildFloat32x4Shuffle(FlowGraph* flow_graph, 718 static bool BuildFloat32x4Shuffle(FlowGraph* flow_graph,
632 MethodRecognizer::Kind kind) { 719 MethodRecognizer::Kind kind) {
633 if (!FlowGraphCompiler::SupportsUnboxedSimd128()) return false; 720 if (!FlowGraphCompiler::SupportsUnboxedSimd128()) return false;
634 GraphEntryInstr* graph_entry = flow_graph->graph_entry(); 721 GraphEntryInstr* graph_entry = flow_graph->graph_entry();
635 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); 722 TargetEntryInstr* normal_entry = graph_entry->normal_entry();
636 BlockBuilder builder(flow_graph, normal_entry); 723 BlockBuilder builder(flow_graph, normal_entry);
637 724
638 Definition* receiver = builder.AddParameter(1); 725 Definition* receiver = builder.AddParameter(1);
639 726
640 Definition* unboxed_receiver = 727 Definition* unboxed_receiver =
641 builder.AddUnboxInstr(kUnboxedFloat32x4, new Value(receiver)); 728 builder.AddUnboxInstr(kUnboxedFloat32x4,
729 new Value(receiver),
730 /* is_checked = */ true);
642 731
643 Definition* unboxed_result = builder.AddDefinition( 732 Definition* unboxed_result = builder.AddDefinition(
644 new Simd32x4ShuffleInstr(kind, 733 new Simd32x4ShuffleInstr(kind,
645 new Value(unboxed_receiver), 734 new Value(unboxed_receiver),
646 0, 735 0,
647 Thread::kNoDeoptId)); 736 Thread::kNoDeoptId));
648 737
649 Definition* result = builder.AddDefinition( 738 Definition* result = builder.AddDefinition(
650 BoxInstr::Create(kUnboxedDouble, new Value(unboxed_result))); 739 BoxInstr::Create(kUnboxedDouble, new Value(unboxed_result)));
651 builder.AddIntrinsicReturn(new Value(result)); 740 builder.AddIntrinsicReturn(new Value(result));
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 } 954 }
866 955
867 956
868 bool Intrinsifier::Build_DoubleFlipSignBit(FlowGraph* flow_graph) { 957 bool Intrinsifier::Build_DoubleFlipSignBit(FlowGraph* flow_graph) {
869 GraphEntryInstr* graph_entry = flow_graph->graph_entry(); 958 GraphEntryInstr* graph_entry = flow_graph->graph_entry();
870 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); 959 TargetEntryInstr* normal_entry = graph_entry->normal_entry();
871 BlockBuilder builder(flow_graph, normal_entry); 960 BlockBuilder builder(flow_graph, normal_entry);
872 961
873 Definition* receiver = builder.AddParameter(1); 962 Definition* receiver = builder.AddParameter(1);
874 Definition* unboxed_value = 963 Definition* unboxed_value =
875 builder.AddUnboxInstr(kUnboxedDouble, new Value(receiver)); 964 builder.AddUnboxInstr(kUnboxedDouble,
965 new Value(receiver),
966 /* is_checked = */ true);
876 Definition* unboxed_result = builder.AddDefinition( 967 Definition* unboxed_result = builder.AddDefinition(
877 new UnaryDoubleOpInstr(Token::kNEGATE, 968 new UnaryDoubleOpInstr(Token::kNEGATE,
878 new Value(unboxed_value), 969 new Value(unboxed_value),
879 Thread::kNoDeoptId)); 970 Thread::kNoDeoptId));
880 Definition* result = builder.AddDefinition( 971 Definition* result = builder.AddDefinition(
881 BoxInstr::Create(kUnboxedDouble, new Value(unboxed_result))); 972 BoxInstr::Create(kUnboxedDouble, new Value(unboxed_result)));
882 builder.AddIntrinsicReturn(new Value(result)); 973 builder.AddIntrinsicReturn(new Value(result));
883 return true; 974 return true;
884 } 975 }
885 976
977
978 static bool BuildInvokeMathCFunction(BlockBuilder* builder,
979 MethodRecognizer::Kind kind,
980 intptr_t num_parameters = 1) {
981 ZoneGrowableArray<Value*>* args =
982 new ZoneGrowableArray<Value*>(num_parameters);
983
984 for (intptr_t i = 0; i < num_parameters; i++) {
985 const intptr_t parameter_index = (num_parameters - i);
986 Definition* value = builder->AddParameter(parameter_index);
987 Definition* unboxed_value =
988 builder->AddUnboxInstr(kUnboxedDouble, value, /* is_checked = */ false);
989 args->Add(new Value(unboxed_value));
990 }
991
992 Definition* unboxed_result =
993 builder->InvokeMathCFunction(kind, args);
994
995 Definition* result = builder->AddDefinition(
996 BoxInstr::Create(kUnboxedDouble, new Value(unboxed_result)));
997
998 builder->AddIntrinsicReturn(new Value(result));
999
1000 return true;
1001 }
1002
1003
1004 bool Intrinsifier::Build_MathSin(FlowGraph* flow_graph) {
1005 if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false;
1006
1007 GraphEntryInstr* graph_entry = flow_graph->graph_entry();
1008 TargetEntryInstr* normal_entry = graph_entry->normal_entry();
1009 BlockBuilder builder(flow_graph, normal_entry);
1010
1011 return BuildInvokeMathCFunction(&builder,
1012 MethodRecognizer::kMathSin);
1013 }
1014
1015
1016 bool Intrinsifier::Build_MathCos(FlowGraph* flow_graph) {
1017 if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false;
1018
1019 GraphEntryInstr* graph_entry = flow_graph->graph_entry();
1020 TargetEntryInstr* normal_entry = graph_entry->normal_entry();
1021 BlockBuilder builder(flow_graph, normal_entry);
1022
1023 return BuildInvokeMathCFunction(&builder,
1024 MethodRecognizer::kMathCos);
1025 }
1026
1027
1028 bool Intrinsifier::Build_MathTan(FlowGraph* flow_graph) {
1029 if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false;
1030
1031 GraphEntryInstr* graph_entry = flow_graph->graph_entry();
1032 TargetEntryInstr* normal_entry = graph_entry->normal_entry();
1033 BlockBuilder builder(flow_graph, normal_entry);
1034
1035 return BuildInvokeMathCFunction(&builder,
1036 MethodRecognizer::kMathTan);
1037 }
1038
1039
1040 bool Intrinsifier::Build_MathAsin(FlowGraph* flow_graph) {
1041 if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false;
1042
1043 GraphEntryInstr* graph_entry = flow_graph->graph_entry();
1044 TargetEntryInstr* normal_entry = graph_entry->normal_entry();
1045 BlockBuilder builder(flow_graph, normal_entry);
1046
1047 return BuildInvokeMathCFunction(&builder,
1048 MethodRecognizer::kMathAsin);
1049 }
1050
1051
1052 bool Intrinsifier::Build_MathAcos(FlowGraph* flow_graph) {
1053 if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false;
1054
1055 GraphEntryInstr* graph_entry = flow_graph->graph_entry();
1056 TargetEntryInstr* normal_entry = graph_entry->normal_entry();
1057 BlockBuilder builder(flow_graph, normal_entry);
1058
1059 return BuildInvokeMathCFunction(&builder,
1060 MethodRecognizer::kMathAcos);
1061 }
1062
1063
1064 bool Intrinsifier::Build_MathAtan(FlowGraph* flow_graph) {
1065 if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false;
1066
1067 GraphEntryInstr* graph_entry = flow_graph->graph_entry();
1068 TargetEntryInstr* normal_entry = graph_entry->normal_entry();
1069 BlockBuilder builder(flow_graph, normal_entry);
1070
1071 return BuildInvokeMathCFunction(&builder,
1072 MethodRecognizer::kMathAtan);
1073 }
1074
1075
1076 bool Intrinsifier::Build_MathAtan2(FlowGraph* flow_graph) {
1077 if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false;
1078
1079 GraphEntryInstr* graph_entry = flow_graph->graph_entry();
1080 TargetEntryInstr* normal_entry = graph_entry->normal_entry();
1081 BlockBuilder builder(flow_graph, normal_entry);
1082
1083 return BuildInvokeMathCFunction(&builder,
1084 MethodRecognizer::kMathAtan2,
1085 /* num_parameters = */ 2);
1086 }
1087
886 } // namespace dart 1088 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/intermediate_language.cc ('k') | runtime/vm/method_recognizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698