| 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/intrinsifier.h" | 7 #include "vm/intrinsifier.h" |
| 8 #include "vm/flags.h" | 8 #include "vm/flags.h" |
| 9 #include "vm/object.h" | 9 #include "vm/object.h" |
| 10 #include "vm/symbols.h" | 10 #include "vm/symbols.h" |
| 11 | 11 |
| 12 #include "vm/flow_graph.h" |
| 13 #include "vm/flow_graph_compiler.h" |
| 14 #include "vm/flow_graph_allocator.h" |
| 15 #include "vm/flow_graph_builder.h" |
| 16 #include "vm/il_printer.h" |
| 17 #include "vm/intermediate_language.h" |
| 18 #include "vm/parser.h" |
| 19 |
| 12 namespace dart { | 20 namespace dart { |
| 13 | 21 |
| 14 DEFINE_FLAG(bool, intrinsify, true, "Instrinsify when possible"); | 22 DEFINE_FLAG(bool, intrinsify, true, "Instrinsify when possible"); |
| 15 DECLARE_FLAG(bool, throw_on_javascript_int_overflow); | 23 DECLARE_FLAG(bool, throw_on_javascript_int_overflow); |
| 24 DECLARE_FLAG(bool, code_comments); |
| 25 DECLARE_FLAG(bool, print_flow_graph); |
| 26 DECLARE_FLAG(bool, print_flow_graph_optimized); |
| 16 | 27 |
| 17 bool Intrinsifier::CanIntrinsify(const Function& function) { | 28 bool Intrinsifier::CanIntrinsify(const Function& function) { |
| 18 if (!FLAG_intrinsify) return false; | 29 if (!FLAG_intrinsify) return false; |
| 19 if (function.IsClosureFunction()) return false; | 30 if (function.IsClosureFunction()) return false; |
| 20 // Can occur because of compile-all flag. | 31 // Can occur because of compile-all flag. |
| 21 if (function.is_external()) return false; | 32 if (function.is_external()) return false; |
| 22 return function.is_intrinsic(); | 33 return function.is_intrinsic(); |
| 23 } | 34 } |
| 24 | 35 |
| 25 | 36 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 52 func = cls.LookupFunctionAllowPrivate(str); \ | 63 func = cls.LookupFunctionAllowPrivate(str); \ |
| 53 } \ | 64 } \ |
| 54 ASSERT(!func.IsNull()); \ | 65 ASSERT(!func.IsNull()); \ |
| 55 func.set_is_intrinsic(true); | 66 func.set_is_intrinsic(true); |
| 56 | 67 |
| 57 // Set up all core lib functions that can be intrisified. | 68 // Set up all core lib functions that can be intrisified. |
| 58 lib = Library::CoreLibrary(); | 69 lib = Library::CoreLibrary(); |
| 59 ASSERT(!lib.IsNull()); | 70 ASSERT(!lib.IsNull()); |
| 60 CORE_LIB_INTRINSIC_LIST(SETUP_FUNCTION); | 71 CORE_LIB_INTRINSIC_LIST(SETUP_FUNCTION); |
| 61 CORE_INTEGER_LIB_INTRINSIC_LIST(SETUP_FUNCTION); | 72 CORE_INTEGER_LIB_INTRINSIC_LIST(SETUP_FUNCTION); |
| 73 GRAPH_CORE_INTRINSICS_LIST(SETUP_FUNCTION); |
| 62 | 74 |
| 63 // Set up all math lib functions that can be intrisified. | 75 // Set up all math lib functions that can be intrisified. |
| 64 lib = Library::MathLibrary(); | 76 lib = Library::MathLibrary(); |
| 65 ASSERT(!lib.IsNull()); | 77 ASSERT(!lib.IsNull()); |
| 66 MATH_LIB_INTRINSIC_LIST(SETUP_FUNCTION); | 78 MATH_LIB_INTRINSIC_LIST(SETUP_FUNCTION); |
| 67 | 79 |
| 68 // Set up all dart:typed_data lib functions that can be intrisified. | 80 // Set up all dart:typed_data lib functions that can be intrisified. |
| 69 lib = Library::TypedDataLibrary(); | 81 lib = Library::TypedDataLibrary(); |
| 70 ASSERT(!lib.IsNull()); | 82 ASSERT(!lib.IsNull()); |
| 71 TYPED_DATA_LIB_INTRINSIC_LIST(SETUP_FUNCTION); | 83 TYPED_DATA_LIB_INTRINSIC_LIST(SETUP_FUNCTION); |
| 84 GRAPH_TYPED_DATA_INTRINSICS_LIST(SETUP_FUNCTION); |
| 72 | 85 |
| 73 // Setup all dart:profiler lib functions that can be intrinsified. | 86 // Setup all dart:profiler lib functions that can be intrinsified. |
| 74 lib = Library::ProfilerLibrary(); | 87 lib = Library::ProfilerLibrary(); |
| 75 ASSERT(!lib.IsNull()); | 88 ASSERT(!lib.IsNull()); |
| 76 PROFILER_LIB_INTRINSIC_LIST(SETUP_FUNCTION); | 89 PROFILER_LIB_INTRINSIC_LIST(SETUP_FUNCTION); |
| 77 | 90 |
| 78 #undef SETUP_FUNCTION | 91 #undef SETUP_FUNCTION |
| 79 } | 92 } |
| 80 | 93 |
| 81 | 94 |
| 82 void Intrinsifier::Intrinsify(const Function& function, Assembler* assembler) { | 95 static void EmitCodeFor(FlowGraphCompiler* compiler, |
| 83 if (!CanIntrinsify(function)) return; | 96 FlowGraph* graph) { |
| 97 // The FlowGraph here is constructed by the intrinsics builder methods, and |
| 98 // is different from compiler->flow_graph(), the original method's flow graph. |
| 99 compiler->assembler()->Comment("Graph intrinsic"); |
| 100 for (intptr_t i = 0; i < graph->reverse_postorder().length(); i++) { |
| 101 BlockEntryInstr* block = graph->reverse_postorder()[i]; |
| 102 if (block->IsGraphEntry()) continue; // No code for graph entry needed. |
| 103 |
| 104 if (block->HasParallelMove()) { |
| 105 compiler->parallel_move_resolver()->EmitNativeCode( |
| 106 block->parallel_move()); |
| 107 } |
| 108 |
| 109 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) { |
| 110 Instruction* instr = it.Current(); |
| 111 if (FLAG_code_comments) compiler->EmitComment(instr); |
| 112 if (instr->IsParallelMove()) { |
| 113 compiler->parallel_move_resolver()->EmitNativeCode( |
| 114 instr->AsParallelMove()); |
| 115 } else { |
| 116 ASSERT(instr->locs() != NULL); |
| 117 // Calls are not supported in intrinsics code. |
| 118 ASSERT(!instr->locs()->always_calls()); |
| 119 instr->EmitNativeCode(compiler); |
| 120 } |
| 121 } |
| 122 } |
| 123 } |
| 124 |
| 125 |
| 126 bool Intrinsifier::GraphIntrinsify(ParsedFunction* parsed_function, |
| 127 FlowGraphCompiler* compiler) { |
| 128 ZoneGrowableArray<const ICData*>* ic_data_array = |
| 129 new ZoneGrowableArray<const ICData*>(); |
| 130 FlowGraphBuilder builder(parsed_function, |
| 131 *ic_data_array, |
| 132 NULL, // NULL = not inlining. |
| 133 Isolate::kNoDeoptId); // No OSR id. |
| 134 |
| 135 intptr_t block_id = builder.AllocateBlockId(); |
| 136 TargetEntryInstr* normal_entry = |
| 137 new TargetEntryInstr(block_id, |
| 138 CatchClauseNode::kInvalidTryIndex); |
| 139 GraphEntryInstr* graph_entry = new GraphEntryInstr( |
| 140 parsed_function, normal_entry, Isolate::kNoDeoptId); // No OSR id. |
| 141 FlowGraph* graph = new FlowGraph(builder, graph_entry, block_id); |
| 142 const Function& function = parsed_function->function(); |
| 143 switch (function.recognized_kind()) { |
| 144 #define EMIT_CASE(test_class_name, test_function_name, enum_name, fp) \ |
| 145 case MethodRecognizer::k##enum_name: \ |
| 146 ASSERT(function.CheckSourceFingerprint(fp)); \ |
| 147 if (!Build_##enum_name(graph)) return false; \ |
| 148 break; |
| 149 |
| 150 GRAPH_INTRINSICS_LIST(EMIT_CASE); |
| 151 default: |
| 152 return false; |
| 153 #undef EMIT_CASE |
| 154 } |
| 155 |
| 156 if (FLAG_print_flow_graph || FLAG_print_flow_graph_optimized) { |
| 157 OS::Print("Intrinsic graph before\n"); |
| 158 FlowGraphPrinter printer(*graph); |
| 159 printer.PrintBlocks(); |
| 160 } |
| 161 |
| 162 // Perform register allocation on the SSA graph. |
| 163 FlowGraphAllocator allocator(*graph, true); // Intrinsic mode. |
| 164 allocator.AllocateRegisters(); |
| 165 |
| 166 if (FLAG_print_flow_graph || FLAG_print_flow_graph_optimized) { |
| 167 OS::Print("Intrinsic graph after\n"); |
| 168 FlowGraphPrinter printer(*graph); |
| 169 printer.PrintBlocks(); |
| 170 } |
| 171 EmitCodeFor(compiler, graph); |
| 172 return true; |
| 173 } |
| 174 |
| 175 |
| 176 void Intrinsifier::Intrinsify(ParsedFunction* parsed_function, |
| 177 FlowGraphCompiler* compiler) { |
| 178 const Function& function = parsed_function->function(); |
| 179 if (!CanIntrinsify(function)) { |
| 180 return; |
| 181 } |
| 182 |
| 183 if (GraphIntrinsify(parsed_function, compiler)) { |
| 184 return; |
| 185 } |
| 84 | 186 |
| 85 #define EMIT_CASE(test_class_name, test_function_name, enum_name, fp) \ | 187 #define EMIT_CASE(test_class_name, test_function_name, enum_name, fp) \ |
| 86 case MethodRecognizer::k##enum_name: \ | 188 case MethodRecognizer::k##enum_name: \ |
| 87 ASSERT(function.CheckSourceFingerprint(fp)); \ | 189 ASSERT(function.CheckSourceFingerprint(fp)); \ |
| 88 assembler->Comment("Intrinsic"); \ | 190 compiler->assembler()->Comment("Intrinsic"); \ |
| 89 enum_name(assembler); \ | 191 enum_name(compiler->assembler()); \ |
| 90 break; | 192 break; |
| 91 | 193 |
| 92 if (FLAG_throw_on_javascript_int_overflow && (Smi::kBits >= 32)) { | 194 if (FLAG_throw_on_javascript_int_overflow && (Smi::kBits >= 32)) { |
| 93 // Integer intrinsics are in the core library, but we don't want to | 195 // Integer intrinsics are in the core library, but we don't want to |
| 94 // intrinsify when Smi > 32 bits if we are looking for javascript integer | 196 // intrinsify when Smi > 32 bits if we are looking for javascript integer |
| 95 // overflow. | 197 // overflow. |
| 96 switch (function.recognized_kind()) { | 198 switch (function.recognized_kind()) { |
| 97 CORE_LIB_INTRINSIC_LIST(EMIT_CASE); | 199 ALL_INTRINSICS_NO_INTEGER_LIB_LIST(EMIT_CASE); |
| 98 MATH_LIB_INTRINSIC_LIST(EMIT_CASE); | |
| 99 TYPED_DATA_LIB_INTRINSIC_LIST(EMIT_CASE); | |
| 100 PROFILER_LIB_INTRINSIC_LIST(EMIT_CASE); | |
| 101 default: | 200 default: |
| 102 break; | 201 break; |
| 103 } | 202 } |
| 104 } else { | 203 } else { |
| 105 switch (function.recognized_kind()) { | 204 switch (function.recognized_kind()) { |
| 106 CORE_LIB_INTRINSIC_LIST(EMIT_CASE); | 205 ALL_INTRINSICS_LIST(EMIT_CASE); |
| 107 CORE_INTEGER_LIB_INTRINSIC_LIST(EMIT_CASE); | |
| 108 MATH_LIB_INTRINSIC_LIST(EMIT_CASE); | |
| 109 TYPED_DATA_LIB_INTRINSIC_LIST(EMIT_CASE); | |
| 110 PROFILER_LIB_INTRINSIC_LIST(EMIT_CASE); | |
| 111 default: | 206 default: |
| 112 UNREACHABLE(); | 207 UNREACHABLE(); |
| 113 break; | 208 break; |
| 114 } | 209 } |
| 115 } | 210 } |
| 116 #undef EMIT_INTRINSIC | 211 #undef EMIT_INTRINSIC |
| 117 } | 212 } |
| 118 | 213 |
| 214 |
| 215 class BlockBuilder : public ValueObject { |
| 216 public: |
| 217 BlockBuilder(FlowGraph* flow_graph, TargetEntryInstr* entry) |
| 218 : flow_graph_(flow_graph), entry_(entry), current_(entry) { } |
| 219 |
| 220 Definition* AddToInitialDefinitions(Definition* def) { |
| 221 def->set_ssa_temp_index(flow_graph_->alloc_ssa_temp_index()); |
| 222 flow_graph_->AddToInitialDefinitions(def); |
| 223 return def; |
| 224 } |
| 225 |
| 226 Definition* AddDefinition(Definition* def) { |
| 227 def->set_ssa_temp_index(flow_graph_->alloc_ssa_temp_index()); |
| 228 current_ = current_->AppendInstruction(def); |
| 229 return def; |
| 230 } |
| 231 |
| 232 Instruction* AddInstruction(Instruction* instr) { |
| 233 current_ = current_->AppendInstruction(instr); |
| 234 return instr; |
| 235 } |
| 236 |
| 237 void AddIntrinsicReturn(Value* value) { |
| 238 ReturnInstr* instr = new ReturnInstr(TokenPos(), value); |
| 239 AddInstruction(instr); |
| 240 entry_->set_last_instruction(instr); |
| 241 } |
| 242 |
| 243 Definition* AddParameter(intptr_t index) { |
| 244 intptr_t adjustment = Intrinsifier::ParameterSlotFromSp(); |
| 245 return AddToInitialDefinitions( |
| 246 new ParameterInstr(adjustment + index, |
| 247 flow_graph_->graph_entry(), |
| 248 SPREG)); |
| 249 } |
| 250 |
| 251 intptr_t TokenPos() { |
| 252 return flow_graph_->parsed_function().function().token_pos(); |
| 253 } |
| 254 |
| 255 private: |
| 256 FlowGraph* flow_graph_; |
| 257 BlockEntryInstr* entry_; |
| 258 Instruction* current_; |
| 259 }; |
| 260 |
| 261 |
| 262 static void PrepareIndexedOp(BlockBuilder* builder, |
| 263 Definition* array, |
| 264 Definition* index, |
| 265 intptr_t length_offset) { |
| 266 intptr_t token_pos = builder->TokenPos(); |
| 267 builder->AddInstruction( |
| 268 new CheckSmiInstr(new Value(index), |
| 269 Isolate::kNoDeoptId, |
| 270 token_pos)); |
| 271 |
| 272 Definition* length = builder->AddDefinition( |
| 273 new LoadFieldInstr(new Value(array), |
| 274 length_offset, |
| 275 Type::ZoneHandle(Type::SmiType()), |
| 276 true)); // immutable |
| 277 builder->AddInstruction( |
| 278 new CheckArrayBoundInstr(new Value(length), |
| 279 new Value(index), |
| 280 Isolate::kNoDeoptId)); |
| 281 } |
| 282 |
| 283 |
| 284 bool Intrinsifier::Build_ObjectArrayGetIndexed(FlowGraph* flow_graph) { |
| 285 GraphEntryInstr* graph_entry = flow_graph->graph_entry(); |
| 286 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); |
| 287 BlockBuilder builder(flow_graph, normal_entry); |
| 288 |
| 289 Definition* index = builder.AddParameter(1); |
| 290 Definition* array = builder.AddParameter(2); |
| 291 |
| 292 PrepareIndexedOp(&builder, array, index, Array::length_offset()); |
| 293 |
| 294 Definition* result = builder.AddDefinition( |
| 295 new LoadIndexedInstr(new Value(array), |
| 296 new Value(index), |
| 297 Instance::ElementSizeFor(kArrayCid), // index scale |
| 298 kArrayCid, |
| 299 Isolate::kNoDeoptId, |
| 300 builder.TokenPos())); |
| 301 builder.AddIntrinsicReturn(new Value(result)); |
| 302 return true; |
| 303 } |
| 304 |
| 305 |
| 306 bool Intrinsifier::Build_ImmutableArrayGetIndexed(FlowGraph* flow_graph) { |
| 307 return Build_ObjectArrayGetIndexed(flow_graph); |
| 308 } |
| 309 |
| 310 |
| 311 bool Intrinsifier::Build_Uint8ArrayGetIndexed(FlowGraph* flow_graph) { |
| 312 GraphEntryInstr* graph_entry = flow_graph->graph_entry(); |
| 313 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); |
| 314 BlockBuilder builder(flow_graph, normal_entry); |
| 315 |
| 316 Definition* index = builder.AddParameter(1); |
| 317 Definition* array = builder.AddParameter(2); |
| 318 |
| 319 PrepareIndexedOp(&builder, array, index, TypedData::length_offset()); |
| 320 |
| 321 Definition* result = builder.AddDefinition( |
| 322 new LoadIndexedInstr(new Value(array), |
| 323 new Value(index), |
| 324 1, // index scale |
| 325 kTypedDataUint8ArrayCid, |
| 326 Isolate::kNoDeoptId, |
| 327 builder.TokenPos())); |
| 328 builder.AddIntrinsicReturn(new Value(result)); |
| 329 return true; |
| 330 } |
| 331 |
| 332 |
| 333 bool Intrinsifier::Build_ExternalUint8ArrayGetIndexed(FlowGraph* flow_graph) { |
| 334 GraphEntryInstr* graph_entry = flow_graph->graph_entry(); |
| 335 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); |
| 336 BlockBuilder builder(flow_graph, normal_entry); |
| 337 |
| 338 Definition* index = builder.AddParameter(1); |
| 339 Definition* array = builder.AddParameter(2); |
| 340 |
| 341 PrepareIndexedOp(&builder, array, index, ExternalTypedData::length_offset()); |
| 342 |
| 343 Definition* elements = builder.AddDefinition( |
| 344 new LoadUntaggedInstr(new Value(array), |
| 345 ExternalTypedData::data_offset())); |
| 346 Definition* result = builder.AddDefinition( |
| 347 new LoadIndexedInstr(new Value(elements), |
| 348 new Value(index), |
| 349 1, // index scale |
| 350 kExternalTypedDataUint8ArrayCid, |
| 351 Isolate::kNoDeoptId, |
| 352 builder.TokenPos())); |
| 353 builder.AddIntrinsicReturn(new Value(result)); |
| 354 return true; |
| 355 } |
| 356 |
| 357 |
| 358 bool Intrinsifier::Build_Uint8ArraySetIndexed(FlowGraph* flow_graph) { |
| 359 GraphEntryInstr* graph_entry = flow_graph->graph_entry(); |
| 360 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); |
| 361 BlockBuilder builder(flow_graph, normal_entry); |
| 362 |
| 363 Definition* value = builder.AddParameter(1); |
| 364 Definition* index = builder.AddParameter(2); |
| 365 Definition* array = builder.AddParameter(3); |
| 366 |
| 367 PrepareIndexedOp(&builder, array, index, TypedData::length_offset()); |
| 368 |
| 369 builder.AddInstruction( |
| 370 new CheckSmiInstr(new Value(value), |
| 371 Isolate::kNoDeoptId, |
| 372 builder.TokenPos())); |
| 373 |
| 374 builder.AddInstruction( |
| 375 new StoreIndexedInstr(new Value(array), |
| 376 new Value(index), |
| 377 new Value(value), |
| 378 kNoStoreBarrier, |
| 379 1, // index scale |
| 380 kTypedDataUint8ArrayCid, |
| 381 Isolate::kNoDeoptId, |
| 382 builder.TokenPos())); |
| 383 // Return null. |
| 384 Definition* null_def = builder.AddDefinition( |
| 385 new ConstantInstr(Object::ZoneHandle(Object::null()))); |
| 386 builder.AddIntrinsicReturn(new Value(null_def)); |
| 387 return true; |
| 388 } |
| 389 |
| 390 |
| 391 bool Intrinsifier::Build_ExternalUint8ArraySetIndexed(FlowGraph* flow_graph) { |
| 392 GraphEntryInstr* graph_entry = flow_graph->graph_entry(); |
| 393 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); |
| 394 BlockBuilder builder(flow_graph, normal_entry); |
| 395 |
| 396 Definition* value = builder.AddParameter(1); |
| 397 Definition* index = builder.AddParameter(2); |
| 398 Definition* array = builder.AddParameter(3); |
| 399 |
| 400 PrepareIndexedOp(&builder, array, index, ExternalTypedData::length_offset()); |
| 401 |
| 402 builder.AddInstruction( |
| 403 new CheckSmiInstr(new Value(value), |
| 404 Isolate::kNoDeoptId, |
| 405 builder.TokenPos())); |
| 406 Definition* elements = builder.AddDefinition( |
| 407 new LoadUntaggedInstr(new Value(array), |
| 408 ExternalTypedData::data_offset())); |
| 409 builder.AddInstruction( |
| 410 new StoreIndexedInstr(new Value(elements), |
| 411 new Value(index), |
| 412 new Value(value), |
| 413 kNoStoreBarrier, |
| 414 1, // index scale |
| 415 kExternalTypedDataUint8ArrayCid, |
| 416 Isolate::kNoDeoptId, |
| 417 builder.TokenPos())); |
| 418 // Return null. |
| 419 Definition* null_def = builder.AddDefinition( |
| 420 new ConstantInstr(Object::ZoneHandle(Object::null()))); |
| 421 builder.AddIntrinsicReturn(new Value(null_def)); |
| 422 return true; |
| 423 } |
| 424 |
| 425 |
| 426 bool Intrinsifier::Build_Float64ArraySetIndexed(FlowGraph* flow_graph) { |
| 427 if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false; |
| 428 |
| 429 GraphEntryInstr* graph_entry = flow_graph->graph_entry(); |
| 430 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); |
| 431 BlockBuilder builder(flow_graph, normal_entry); |
| 432 |
| 433 Definition* value = builder.AddParameter(1); |
| 434 Definition* index = builder.AddParameter(2); |
| 435 Definition* array = builder.AddParameter(3); |
| 436 |
| 437 PrepareIndexedOp(&builder, array, index, TypedData::length_offset()); |
| 438 |
| 439 const ICData& value_check = ICData::ZoneHandle(ICData::New( |
| 440 flow_graph->parsed_function().function(), |
| 441 String::Handle(flow_graph->parsed_function().function().name()), |
| 442 Object::empty_array(), // Dummy args. descr. |
| 443 Isolate::kNoDeoptId, |
| 444 1)); |
| 445 value_check.AddReceiverCheck(kDoubleCid, |
| 446 flow_graph->parsed_function().function()); |
| 447 builder.AddInstruction( |
| 448 new CheckClassInstr(new Value(value), |
| 449 Isolate::kNoDeoptId, |
| 450 value_check, |
| 451 builder.TokenPos())); |
| 452 Definition* double_value = builder.AddDefinition( |
| 453 new UnboxDoubleInstr(new Value(value), Isolate::kNoDeoptId)); |
| 454 // Manually adjust reaching type because there is no type propagation |
| 455 // when building intrinsics. |
| 456 double_value->AsUnboxDouble()->value()->SetReachingType( |
| 457 ZoneCompileType::Wrap(CompileType::FromCid(kDoubleCid))); |
| 458 |
| 459 builder.AddInstruction( |
| 460 new StoreIndexedInstr(new Value(array), |
| 461 new Value(index), |
| 462 new Value(double_value), |
| 463 kNoStoreBarrier, |
| 464 8, // index scale |
| 465 kTypedDataFloat64ArrayCid, |
| 466 Isolate::kNoDeoptId, |
| 467 builder.TokenPos())); |
| 468 // Return null. |
| 469 Definition* null_def = builder.AddDefinition( |
| 470 new ConstantInstr(Object::ZoneHandle(Object::null()))); |
| 471 builder.AddIntrinsicReturn(new Value(null_def)); |
| 472 return true; |
| 473 } |
| 474 |
| 475 |
| 476 bool Intrinsifier::Build_Float64ArrayGetIndexed(FlowGraph* flow_graph) { |
| 477 if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false; |
| 478 |
| 479 GraphEntryInstr* graph_entry = flow_graph->graph_entry(); |
| 480 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); |
| 481 BlockBuilder builder(flow_graph, normal_entry); |
| 482 |
| 483 Definition* index = builder.AddParameter(1); |
| 484 Definition* array = builder.AddParameter(2); |
| 485 |
| 486 PrepareIndexedOp(&builder, array, index, TypedData::length_offset()); |
| 487 |
| 488 Definition* unboxed_value = builder.AddDefinition( |
| 489 new LoadIndexedInstr(new Value(array), |
| 490 new Value(index), |
| 491 8, // index scale |
| 492 kTypedDataFloat64ArrayCid, |
| 493 Isolate::kNoDeoptId, |
| 494 builder.TokenPos())); |
| 495 Definition* result = builder.AddDefinition( |
| 496 new BoxDoubleInstr(new Value(unboxed_value))); |
| 497 builder.AddIntrinsicReturn(new Value(result)); |
| 498 return true; |
| 499 } |
| 500 |
| 501 |
| 502 static bool BuildLoadField(FlowGraph* flow_graph, intptr_t offset) { |
| 503 GraphEntryInstr* graph_entry = flow_graph->graph_entry(); |
| 504 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); |
| 505 BlockBuilder builder(flow_graph, normal_entry); |
| 506 |
| 507 Definition* array = builder.AddParameter(1); |
| 508 |
| 509 Definition* length = builder.AddDefinition( |
| 510 new LoadFieldInstr(new Value(array), |
| 511 offset, |
| 512 Type::ZoneHandle(), |
| 513 builder.TokenPos())); |
| 514 builder.AddIntrinsicReturn(new Value(length)); |
| 515 return true; |
| 516 } |
| 517 |
| 518 |
| 519 bool Intrinsifier::Build_ObjectArrayLength(FlowGraph* flow_graph) { |
| 520 return BuildLoadField(flow_graph, Array::length_offset()); |
| 521 } |
| 522 |
| 523 |
| 524 bool Intrinsifier::Build_ImmutableArrayLength(FlowGraph* flow_graph) { |
| 525 return BuildLoadField(flow_graph, Array::length_offset()); |
| 526 } |
| 527 |
| 528 |
| 529 bool Intrinsifier::Build_GrowableArrayLength(FlowGraph* flow_graph) { |
| 530 return BuildLoadField(flow_graph, GrowableObjectArray::length_offset()); |
| 531 } |
| 532 |
| 533 |
| 534 bool Intrinsifier::Build_StringBaseLength(FlowGraph* flow_graph) { |
| 535 return BuildLoadField(flow_graph, String::length_offset()); |
| 536 } |
| 537 |
| 538 |
| 539 bool Intrinsifier::Build_TypedDataLength(FlowGraph* flow_graph) { |
| 540 return BuildLoadField(flow_graph, TypedData::length_offset()); |
| 541 } |
| 542 |
| 543 |
| 544 bool Intrinsifier::Build_GrowableArrayCapacity(FlowGraph* flow_graph) { |
| 545 GraphEntryInstr* graph_entry = flow_graph->graph_entry(); |
| 546 TargetEntryInstr* normal_entry = graph_entry->normal_entry(); |
| 547 BlockBuilder builder(flow_graph, normal_entry); |
| 548 |
| 549 Definition* array = builder.AddParameter(1); |
| 550 |
| 551 Definition* backing_store = builder.AddDefinition( |
| 552 new LoadFieldInstr(new Value(array), |
| 553 GrowableObjectArray::data_offset(), |
| 554 Type::ZoneHandle(), |
| 555 builder.TokenPos())); |
| 556 Definition* capacity = builder.AddDefinition( |
| 557 new LoadFieldInstr(new Value(backing_store), |
| 558 Array::length_offset(), |
| 559 Type::ZoneHandle(), |
| 560 builder.TokenPos())); |
| 561 builder.AddIntrinsicReturn(new Value(capacity)); |
| 562 return true; |
| 563 } |
| 564 |
| 565 |
| 119 } // namespace dart | 566 } // namespace dart |
| OLD | NEW |