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

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

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