| 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"); | |
| 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 Loading... |
| 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 Loading... |
| 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 16 matching lines...) Expand all Loading... |
| 288 } | 253 } |
| 289 | 254 |
| 290 Definition* AddParameter(intptr_t index) { | 255 Definition* AddParameter(intptr_t index) { |
| 291 intptr_t adjustment = Intrinsifier::ParameterSlotFromSp(); | 256 intptr_t adjustment = Intrinsifier::ParameterSlotFromSp(); |
| 292 return AddToInitialDefinitions( | 257 return AddToInitialDefinitions( |
| 293 new ParameterInstr(adjustment + index, | 258 new ParameterInstr(adjustment + index, |
| 294 flow_graph_->graph_entry(), | 259 flow_graph_->graph_entry(), |
| 295 SPREG)); | 260 SPREG)); |
| 296 } | 261 } |
| 297 | 262 |
| 298 Definition* AddCheckedUnbox(Representation rep, Definition* boxed) { | |
| 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)); | |
| 312 } | |
| 313 | |
| 314 TokenPosition TokenPos() { | 263 TokenPosition TokenPos() { |
| 315 return flow_graph_->function().token_pos(); | 264 return flow_graph_->function().token_pos(); |
| 316 } | 265 } |
| 317 | 266 |
| 318 Definition* AddNullDefinition() { | 267 Definition* AddNullDefinition() { |
| 319 return AddDefinition( | 268 return AddDefinition( |
| 320 new ConstantInstr(Object::ZoneHandle(Object::null()))); | 269 new ConstantInstr(Object::ZoneHandle(Object::null()))); |
| 321 } | 270 } |
| 322 | 271 |
| 323 Definition* AddUnboxInstr(Representation rep, Value* value) { | 272 Definition* AddUnboxInstr(Representation rep, Value* value) { |
| 324 Definition* unboxed_value = AddDefinition( | 273 Definition* unboxed_value = AddDefinition( |
| 325 UnboxInstr::Create(rep, value, Thread::kNoDeoptId)); | 274 UnboxInstr::Create(rep, value, Thread::kNoDeoptId)); |
| 326 // Manually adjust reaching type because there is no type propagation | 275 // Manually adjust reaching type because there is no type propagation |
| 327 // when building intrinsics. | 276 // when building intrinsics. |
| 328 unboxed_value->AsUnbox()->value()->SetReachingType(ZoneCompileType::Wrap( | 277 unboxed_value->AsUnbox()->value()->SetReachingType(ZoneCompileType::Wrap( |
| 329 CompileType::FromCid(CidForRepresentation(rep)))); | 278 CompileType::FromCid(CidForRepresentation(rep)))); |
| 330 return unboxed_value; | 279 return unboxed_value; |
| 331 } | 280 } |
| 332 | 281 |
| 333 Definition* AddUnboxInstr(Representation rep, Definition* boxed) { | |
| 334 return AddUnboxInstr(rep, new Value(boxed)); | |
| 335 } | |
| 336 | |
| 337 Definition* InvokeMathCFunction(MethodRecognizer::Kind recognized_kind, | |
| 338 ZoneGrowableArray<Value*>* args) { | |
| 339 return InvokeMathCFunctionHelper(recognized_kind, args); | |
| 340 } | |
| 341 | |
| 342 private: | 282 private: |
| 343 Definition* InvokeMathCFunctionHelper(MethodRecognizer::Kind recognized_kind, | |
| 344 ZoneGrowableArray<Value*>* args) { | |
| 345 InvokeMathCFunctionInstr* invoke_math_c_function = | |
| 346 new InvokeMathCFunctionInstr(args, | |
| 347 Thread::kNoDeoptId, | |
| 348 recognized_kind, | |
| 349 TokenPos()); | |
| 350 AddDefinition(invoke_math_c_function); | |
| 351 return invoke_math_c_function; | |
| 352 } | |
| 353 | |
| 354 | |
| 355 FlowGraph* flow_graph_; | 283 FlowGraph* flow_graph_; |
| 356 BlockEntryInstr* entry_; | 284 BlockEntryInstr* entry_; |
| 357 Instruction* current_; | 285 Instruction* current_; |
| 358 }; | 286 }; |
| 359 | 287 |
| 360 | 288 |
| 361 static void PrepareIndexedOp(BlockBuilder* builder, | 289 static void PrepareIndexedOp(BlockBuilder* builder, |
| 362 Definition* array, | 290 Definition* array, |
| 363 Definition* index, | 291 Definition* index, |
| 364 intptr_t length_offset) { | 292 intptr_t length_offset) { |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 Definition* unboxed_result = builder.AddDefinition( | 876 Definition* unboxed_result = builder.AddDefinition( |
| 949 new UnaryDoubleOpInstr(Token::kNEGATE, | 877 new UnaryDoubleOpInstr(Token::kNEGATE, |
| 950 new Value(unboxed_value), | 878 new Value(unboxed_value), |
| 951 Thread::kNoDeoptId)); | 879 Thread::kNoDeoptId)); |
| 952 Definition* result = builder.AddDefinition( | 880 Definition* result = builder.AddDefinition( |
| 953 BoxInstr::Create(kUnboxedDouble, new Value(unboxed_result))); | 881 BoxInstr::Create(kUnboxedDouble, new Value(unboxed_result))); |
| 954 builder.AddIntrinsicReturn(new Value(result)); | 882 builder.AddIntrinsicReturn(new Value(result)); |
| 955 return true; | 883 return true; |
| 956 } | 884 } |
| 957 | 885 |
| 958 | |
| 959 static bool BuildInvokeMathCFunction(BlockBuilder* builder, | |
| 960 MethodRecognizer::Kind kind) { | |
| 961 ZoneGrowableArray<Value*>* args = | |
| 962 new ZoneGrowableArray<Value*>(1); | |
| 963 | |
| 964 Definition* value = builder->AddParameter(1); | |
| 965 Definition* unboxed_value = builder->AddUnboxInstr(kUnboxedDouble, value); | |
| 966 args->Add(new Value(unboxed_value)); | |
| 967 | |
| 968 Definition* unboxed_result = | |
| 969 builder->InvokeMathCFunction(kind, args); | |
| 970 | |
| 971 Definition* result = builder->AddDefinition( | |
| 972 BoxInstr::Create(kUnboxedDouble, new Value(unboxed_result))); | |
| 973 | |
| 974 builder->AddIntrinsicReturn(new Value(result)); | |
| 975 | |
| 976 return true; | |
| 977 } | |
| 978 | |
| 979 | |
| 980 bool Intrinsifier::Build_MathSin(FlowGraph* flow_graph) { | |
| 981 if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false; | |
| 982 | |
| 983 GraphEntryInstr* graph_entry = flow_graph->graph_entry(); | |
| 984 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); | |
| 985 BlockBuilder builder(flow_graph, normal_entry); | |
| 986 | |
| 987 return BuildInvokeMathCFunction(&builder, | |
| 988 MethodRecognizer::kMathSin); | |
| 989 } | |
| 990 | |
| 991 | |
| 992 bool Intrinsifier::Build_MathCos(FlowGraph* flow_graph) { | |
| 993 if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false; | |
| 994 | |
| 995 GraphEntryInstr* graph_entry = flow_graph->graph_entry(); | |
| 996 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); | |
| 997 BlockBuilder builder(flow_graph, normal_entry); | |
| 998 | |
| 999 return BuildInvokeMathCFunction(&builder, | |
| 1000 MethodRecognizer::kMathCos); | |
| 1001 } | |
| 1002 | |
| 1003 | |
| 1004 bool Intrinsifier::Build_MathTan(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::kMathTan); | |
| 1013 } | |
| 1014 | |
| 1015 | |
| 1016 bool Intrinsifier::Build_MathAsin(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::kMathAsin); | |
| 1025 } | |
| 1026 | |
| 1027 | |
| 1028 bool Intrinsifier::Build_MathAcos(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::kMathAcos); | |
| 1037 } | |
| 1038 | |
| 1039 | |
| 1040 bool Intrinsifier::Build_MathAtan(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::kMathAtan); | |
| 1049 } | |
| 1050 | |
| 1051 | |
| 1052 bool Intrinsifier::Build_MathAtan2(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 Definition* value_a = builder.AddParameter(1); | |
| 1060 Definition* value_b = builder.AddParameter(2); | |
| 1061 | |
| 1062 Definition* unboxed_a = builder.AddUnboxInstr(kUnboxedDouble, value_a); | |
| 1063 Definition* unboxed_b = builder.AddUnboxInstr(kUnboxedDouble, value_b); | |
| 1064 | |
| 1065 // C's atan2 expects the arguments in the opposite order. | |
| 1066 ZoneGrowableArray<Value*>* args = | |
| 1067 new ZoneGrowableArray<Value*>(2); | |
| 1068 args->Add(new Value(unboxed_b)); | |
| 1069 args->Add(new Value(unboxed_a)); | |
| 1070 | |
| 1071 Definition* unboxed_result = | |
| 1072 builder.InvokeMathCFunction(MethodRecognizer::kMathAtan2, | |
| 1073 args); | |
| 1074 | |
| 1075 Definition* result = builder.AddDefinition( | |
| 1076 BoxInstr::Create(kUnboxedDouble, new Value(unboxed_result))); | |
| 1077 | |
| 1078 builder.AddIntrinsicReturn(new Value(result)); | |
| 1079 | |
| 1080 return true; | |
| 1081 } | |
| 1082 | |
| 1083 } // namespace dart | 886 } // namespace dart |
| OLD | NEW |