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

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

Issue 2896903002: Shuffle around deopt id allocation to give the flow graph builder a chance to record other data as … (Closed)
Patch Set: . Created 3 years, 7 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/regexp_assembler_ir.h ('k') | no next file » | 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 4
5 #include "vm/regexp_assembler_ir.h" 5 #include "vm/regexp_assembler_ir.h"
6 6
7 #include "vm/bit_vector.h" 7 #include "vm/bit_vector.h"
8 #include "vm/compiler.h" 8 #include "vm/compiler.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/flow_graph_builder.h" 10 #include "vm/flow_graph_builder.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 * during processing, and convert them to standard indexes when copying them 73 * during processing, and convert them to standard indexes when copying them
74 * to matches_param_ on successful match. 74 * to matches_param_ on successful match.
75 */ 75 */
76 IRRegExpMacroAssembler::IRRegExpMacroAssembler( 76 IRRegExpMacroAssembler::IRRegExpMacroAssembler(
77 intptr_t specialization_cid, 77 intptr_t specialization_cid,
78 intptr_t capture_count, 78 intptr_t capture_count,
79 const ParsedFunction* parsed_function, 79 const ParsedFunction* parsed_function,
80 const ZoneGrowableArray<const ICData*>& ic_data_array, 80 const ZoneGrowableArray<const ICData*>& ic_data_array,
81 Zone* zone) 81 Zone* zone)
82 : RegExpMacroAssembler(zone), 82 : RegExpMacroAssembler(zone),
83 thread_(Thread::Current()),
83 specialization_cid_(specialization_cid), 84 specialization_cid_(specialization_cid),
84 parsed_function_(parsed_function), 85 parsed_function_(parsed_function),
85 ic_data_array_(ic_data_array), 86 ic_data_array_(ic_data_array),
86 current_instruction_(NULL), 87 current_instruction_(NULL),
87 stack_(NULL), 88 stack_(NULL),
88 stack_pointer_(NULL), 89 stack_pointer_(NULL),
89 current_character_(NULL), 90 current_character_(NULL),
90 current_position_(NULL), 91 current_position_(NULL),
91 string_param_(NULL), 92 string_param_(NULL),
92 string_param_length_(NULL), 93 string_param_length_(NULL),
(...skipping 22 matching lines...) Expand all
115 // backing is indirectly referred to so we can reuse it on subsequent matches 116 // backing is indirectly referred to so we can reuse it on subsequent matches
116 // even in the case where the backing has been enlarged and thus reallocated. 117 // even in the case where the backing has been enlarged and thus reallocated.
117 stack_array_cell_.SetAt( 118 stack_array_cell_.SetAt(
118 0, 119 0,
119 TypedData::Handle(zone, TypedData::New(kTypedDataInt32ArrayCid, 120 TypedData::Handle(zone, TypedData::New(kTypedDataInt32ArrayCid,
120 kMinStackSize / 4, Heap::kOld))); 121 kMinStackSize / 4, Heap::kOld)));
121 122
122 // Create and generate all preset blocks. 123 // Create and generate all preset blocks.
123 entry_block_ = new (zone) GraphEntryInstr( 124 entry_block_ = new (zone) GraphEntryInstr(
124 *parsed_function_, 125 *parsed_function_,
125 new (zone) TargetEntryInstr(block_id_.Alloc(), kInvalidTryIndex), 126 new (zone) TargetEntryInstr(block_id_.Alloc(), kInvalidTryIndex,
127 GetNextDeoptId()),
126 Compiler::kNoOSRDeoptId); 128 Compiler::kNoOSRDeoptId);
127 start_block_ = new (zone) JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex); 129 start_block_ = new (zone)
128 success_block_ = 130 JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex, GetNextDeoptId());
129 new (zone) JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex); 131 success_block_ = new (zone)
130 backtrack_block_ = 132 JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex, GetNextDeoptId());
131 new (zone) JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex); 133 backtrack_block_ = new (zone)
132 exit_block_ = new (zone) JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex); 134 JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex, GetNextDeoptId());
135 exit_block_ = new (zone)
136 JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex, GetNextDeoptId());
133 137
134 GenerateEntryBlock(); 138 GenerateEntryBlock();
135 GenerateSuccessBlock(); 139 GenerateSuccessBlock();
136 GenerateExitBlock(); 140 GenerateExitBlock();
137 141
138 blocks_.Add(entry_block_); 142 blocks_.Add(entry_block_);
139 blocks_.Add(entry_block_->normal_entry()); 143 blocks_.Add(entry_block_->normal_entry());
140 blocks_.Add(start_block_); 144 blocks_.Add(start_block_);
141 blocks_.Add(success_block_); 145 blocks_.Add(success_block_);
142 blocks_.Add(backtrack_block_); 146 blocks_.Add(backtrack_block_);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 } 249 }
246 250
247 251
248 void IRRegExpMacroAssembler::GenerateSuccessBlock() { 252 void IRRegExpMacroAssembler::GenerateSuccessBlock() {
249 set_current_instruction(success_block_); 253 set_current_instruction(success_block_);
250 TAG(); 254 TAG();
251 255
252 Value* type = Bind(new (Z) ConstantInstr( 256 Value* type = Bind(new (Z) ConstantInstr(
253 TypeArguments::ZoneHandle(Z, TypeArguments::null()))); 257 TypeArguments::ZoneHandle(Z, TypeArguments::null())));
254 Value* length = Bind(Uint64Constant(saved_registers_count_)); 258 Value* length = Bind(Uint64Constant(saved_registers_count_));
255 Value* array = 259 Value* array = Bind(new (Z) CreateArrayInstr(TokenPosition::kNoSource, type,
256 Bind(new (Z) CreateArrayInstr(TokenPosition::kNoSource, type, length)); 260 length, GetNextDeoptId()));
257 StoreLocal(result_, array); 261 StoreLocal(result_, array);
258 262
259 // Store captured offsets in the `matches` parameter. 263 // Store captured offsets in the `matches` parameter.
260 for (intptr_t i = 0; i < saved_registers_count_; i++) { 264 for (intptr_t i = 0; i < saved_registers_count_; i++) {
261 PushArgumentInstr* matches_push = PushLocal(result_); 265 PushArgumentInstr* matches_push = PushLocal(result_);
262 PushArgumentInstr* index_push = PushArgument(Bind(Uint64Constant(i))); 266 PushArgumentInstr* index_push = PushArgument(Bind(Uint64Constant(i)));
263 267
264 // Convert negative offsets from the end of the string to string indices. 268 // Convert negative offsets from the end of the string to string indices.
265 // TODO(zerny): use positive offsets from the get-go. 269 // TODO(zerny): use positive offsets from the get-go.
266 PushArgumentInstr* offset_push = PushArgument(LoadRegister(i)); 270 PushArgumentInstr* offset_push = PushArgument(LoadRegister(i));
267 PushArgumentInstr* len_push = PushLocal(string_param_length_); 271 PushArgumentInstr* len_push = PushLocal(string_param_length_);
268 PushArgumentInstr* value_push = 272 PushArgumentInstr* value_push =
269 PushArgument(Bind(Add(offset_push, len_push))); 273 PushArgument(Bind(Add(offset_push, len_push)));
270 274
271 Do(InstanceCall(InstanceCallDescriptor::FromToken(Token::kASSIGN_INDEX), 275 Do(InstanceCall(InstanceCallDescriptor::FromToken(Token::kASSIGN_INDEX),
272 matches_push, index_push, value_push)); 276 matches_push, index_push, value_push));
273 } 277 }
274 278
275 // Print the result if tracing. 279 // Print the result if tracing.
276 PRINT(PushLocal(result_)); 280 PRINT(PushLocal(result_));
277 281
278 // Return true on success. 282 // Return true on success.
279 AppendInstruction( 283 AppendInstruction(new (Z) ReturnInstr(
280 new (Z) ReturnInstr(TokenPosition::kNoSource, Bind(LoadLocal(result_)))); 284 TokenPosition::kNoSource, Bind(LoadLocal(result_)), GetNextDeoptId()));
281 } 285 }
282 286
283 287
284 void IRRegExpMacroAssembler::GenerateExitBlock() { 288 void IRRegExpMacroAssembler::GenerateExitBlock() {
285 set_current_instruction(exit_block_); 289 set_current_instruction(exit_block_);
286 TAG(); 290 TAG();
287 291
288 // Return false on failure. 292 // Return false on failure.
289 AppendInstruction( 293 AppendInstruction(new (Z) ReturnInstr(
290 new (Z) ReturnInstr(TokenPosition::kNoSource, Bind(LoadLocal(result_)))); 294 TokenPosition::kNoSource, Bind(LoadLocal(result_)), GetNextDeoptId()));
291 } 295 }
292 296
293 297
294 void IRRegExpMacroAssembler::FinalizeRegistersArray() { 298 void IRRegExpMacroAssembler::FinalizeRegistersArray() {
295 ASSERT(registers_count_ >= saved_registers_count_); 299 ASSERT(registers_count_ >= saved_registers_count_);
296 registers_array_ = 300 registers_array_ =
297 TypedData::New(kTypedDataInt32ArrayCid, registers_count_, Heap::kOld); 301 TypedData::New(kTypedDataInt32ArrayCid, registers_count_, Heap::kOld);
298 } 302 }
299 303
300 304
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 default: 486 default:
483 UNREACHABLE(); 487 UNREACHABLE();
484 } 488 }
485 489
486 ASSERT(intermediate_operator != Token::kILLEGAL); 490 ASSERT(intermediate_operator != Token::kILLEGAL);
487 491
488 Value* lhs_value = Bind(InstanceCall( 492 Value* lhs_value = Bind(InstanceCall(
489 InstanceCallDescriptor::FromToken(intermediate_operator), lhs, rhs)); 493 InstanceCallDescriptor::FromToken(intermediate_operator), lhs, rhs));
490 Value* rhs_value = Bind(BoolConstant(true)); 494 Value* rhs_value = Bind(BoolConstant(true));
491 495
492 return new (Z) StrictCompareInstr(TokenPosition::kNoSource, strict_comparison, 496 return new (Z)
493 lhs_value, rhs_value, true); 497 StrictCompareInstr(TokenPosition::kNoSource, strict_comparison, lhs_value,
498 rhs_value, true, GetNextDeoptId());
494 } 499 }
495 500
496 ComparisonInstr* IRRegExpMacroAssembler::Comparison(ComparisonKind kind, 501 ComparisonInstr* IRRegExpMacroAssembler::Comparison(ComparisonKind kind,
497 Definition* lhs, 502 Definition* lhs,
498 Definition* rhs) { 503 Definition* rhs) {
499 PushArgumentInstr* lhs_push = PushArgument(Bind(lhs)); 504 PushArgumentInstr* lhs_push = PushArgument(Bind(lhs));
500 PushArgumentInstr* rhs_push = PushArgument(Bind(rhs)); 505 PushArgumentInstr* rhs_push = PushArgument(Bind(rhs));
501 return Comparison(kind, lhs_push, rhs_push); 506 return Comparison(kind, lhs_push, rhs_push);
502 } 507 }
503 508
(...skipping 27 matching lines...) Expand all
531 arguments->Add(arg2); 536 arguments->Add(arg2);
532 537
533 return StaticCall(function, arguments); 538 return StaticCall(function, arguments);
534 } 539 }
535 540
536 541
537 StaticCallInstr* IRRegExpMacroAssembler::StaticCall( 542 StaticCallInstr* IRRegExpMacroAssembler::StaticCall(
538 const Function& function, 543 const Function& function,
539 ZoneGrowableArray<PushArgumentInstr*>* arguments) const { 544 ZoneGrowableArray<PushArgumentInstr*>* arguments) const {
540 const intptr_t kTypeArgsLen = 0; 545 const intptr_t kTypeArgsLen = 0;
541 return new (Z) 546 return new (Z) StaticCallInstr(TokenPosition::kNoSource, function,
542 StaticCallInstr(TokenPosition::kNoSource, function, kTypeArgsLen, 547 kTypeArgsLen, Object::null_array(), arguments,
543 Object::null_array(), arguments, ic_data_array_); 548 ic_data_array_, GetNextDeoptId());
544 } 549 }
545 550
546 551
547 InstanceCallInstr* IRRegExpMacroAssembler::InstanceCall( 552 InstanceCallInstr* IRRegExpMacroAssembler::InstanceCall(
548 const InstanceCallDescriptor& desc, 553 const InstanceCallDescriptor& desc,
549 PushArgumentInstr* arg1) const { 554 PushArgumentInstr* arg1) const {
550 ZoneGrowableArray<PushArgumentInstr*>* arguments = 555 ZoneGrowableArray<PushArgumentInstr*>* arguments =
551 new (Z) ZoneGrowableArray<PushArgumentInstr*>(1); 556 new (Z) ZoneGrowableArray<PushArgumentInstr*>(1);
552 arguments->Add(arg1); 557 arguments->Add(arg1);
553 558
(...skipping 26 matching lines...) Expand all
580 arguments->Add(arg3); 585 arguments->Add(arg3);
581 586
582 return InstanceCall(desc, arguments); 587 return InstanceCall(desc, arguments);
583 } 588 }
584 589
585 590
586 InstanceCallInstr* IRRegExpMacroAssembler::InstanceCall( 591 InstanceCallInstr* IRRegExpMacroAssembler::InstanceCall(
587 const InstanceCallDescriptor& desc, 592 const InstanceCallDescriptor& desc,
588 ZoneGrowableArray<PushArgumentInstr*>* arguments) const { 593 ZoneGrowableArray<PushArgumentInstr*>* arguments) const {
589 const intptr_t kTypeArgsLen = 0; 594 const intptr_t kTypeArgsLen = 0;
590 return new (Z) 595 return new (Z) InstanceCallInstr(
591 InstanceCallInstr(TokenPosition::kNoSource, desc.name, desc.token_kind, 596 TokenPosition::kNoSource, desc.name, desc.token_kind, arguments,
592 arguments, kTypeArgsLen, Object::null_array(), 597 kTypeArgsLen, Object::null_array(), desc.checked_argument_count,
593 desc.checked_argument_count, ic_data_array_); 598 ic_data_array_, GetNextDeoptId());
594 } 599 }
595 600
596 601
597 LoadLocalInstr* IRRegExpMacroAssembler::LoadLocal(LocalVariable* local) const { 602 LoadLocalInstr* IRRegExpMacroAssembler::LoadLocal(LocalVariable* local) const {
598 return new (Z) LoadLocalInstr(*local, TokenPosition::kNoSource); 603 return new (Z) LoadLocalInstr(*local, TokenPosition::kNoSource);
599 } 604 }
600 605
601 606
602 void IRRegExpMacroAssembler::StoreLocal(LocalVariable* local, Value* value) { 607 void IRRegExpMacroAssembler::StoreLocal(LocalVariable* local, Value* value) {
603 Do(new (Z) StoreLocalInstr(*local, value, TokenPosition::kNoSource)); 608 Do(new (Z) StoreLocalInstr(*local, value, TokenPosition::kNoSource));
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 void IRRegExpMacroAssembler::CheckStackLimit() { 1569 void IRRegExpMacroAssembler::CheckStackLimit() {
1565 TAG(); 1570 TAG();
1566 PushArgumentInstr* stack_push = PushLocal(stack_); 1571 PushArgumentInstr* stack_push = PushLocal(stack_);
1567 PushArgumentInstr* length_push = PushArgument( 1572 PushArgumentInstr* length_push = PushArgument(
1568 Bind(InstanceCall(InstanceCallDescriptor(String::ZoneHandle( 1573 Bind(InstanceCall(InstanceCallDescriptor(String::ZoneHandle(
1569 Field::GetterSymbol(Symbols::Length()))), 1574 Field::GetterSymbol(Symbols::Length()))),
1570 stack_push))); 1575 stack_push)));
1571 PushArgumentInstr* capacity_push = PushArgument(Bind(Sub( 1576 PushArgumentInstr* capacity_push = PushArgument(Bind(Sub(
1572 length_push, PushArgument(Bind(Uint64Constant(stack_limit_slack())))))); 1577 length_push, PushArgument(Bind(Uint64Constant(stack_limit_slack()))))));
1573 PushArgumentInstr* stack_pointer_push = PushLocal(stack_pointer_); 1578 PushArgumentInstr* stack_pointer_push = PushLocal(stack_pointer_);
1574 BranchInstr* branch = 1579 BranchInstr* branch = new (Z) BranchInstr(
1575 new (Z) BranchInstr(Comparison(kGT, capacity_push, stack_pointer_push)); 1580 Comparison(kGT, capacity_push, stack_pointer_push), GetNextDeoptId());
1576 CloseBlockWith(branch); 1581 CloseBlockWith(branch);
1577 1582
1578 BlockLabel grow_stack; 1583 BlockLabel grow_stack;
1579 BlockLabel fallthrough; 1584 BlockLabel fallthrough;
1580 *branch->true_successor_address() = TargetWithJoinGoto(fallthrough.block()); 1585 *branch->true_successor_address() = TargetWithJoinGoto(fallthrough.block());
1581 *branch->false_successor_address() = TargetWithJoinGoto(grow_stack.block()); 1586 *branch->false_successor_address() = TargetWithJoinGoto(grow_stack.block());
1582 1587
1583 BindBlock(&grow_stack); 1588 BindBlock(&grow_stack);
1584 GrowStack(); 1589 GrowStack();
1585 1590
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1721 JoinEntryInstr* true_successor_block = backtrack_block_; 1726 JoinEntryInstr* true_successor_block = backtrack_block_;
1722 if (true_successor != NULL) { 1727 if (true_successor != NULL) {
1723 true_successor->SetLinked(); 1728 true_successor->SetLinked();
1724 true_successor_block = true_successor->block(); 1729 true_successor_block = true_successor->block();
1725 } 1730 }
1726 ASSERT(true_successor_block != NULL); 1731 ASSERT(true_successor_block != NULL);
1727 1732
1728 // If the condition is not true, fall through to a new block. 1733 // If the condition is not true, fall through to a new block.
1729 BlockLabel fallthrough; 1734 BlockLabel fallthrough;
1730 1735
1731 BranchInstr* branch = new (Z) BranchInstr(comparison); 1736 BranchInstr* branch = new (Z) BranchInstr(comparison, GetNextDeoptId());
1732 *branch->true_successor_address() = TargetWithJoinGoto(true_successor_block); 1737 *branch->true_successor_address() = TargetWithJoinGoto(true_successor_block);
1733 *branch->false_successor_address() = TargetWithJoinGoto(fallthrough.block()); 1738 *branch->false_successor_address() = TargetWithJoinGoto(fallthrough.block());
1734 1739
1735 CloseBlockWith(branch); 1740 CloseBlockWith(branch);
1736 BindBlock(&fallthrough); 1741 BindBlock(&fallthrough);
1737 } 1742 }
1738 1743
1739 1744
1740 TargetEntryInstr* IRRegExpMacroAssembler::TargetWithJoinGoto( 1745 TargetEntryInstr* IRRegExpMacroAssembler::TargetWithJoinGoto(
1741 JoinEntryInstr* dst) { 1746 JoinEntryInstr* dst) {
1742 TargetEntryInstr* target = 1747 TargetEntryInstr* target = new (Z)
1743 new (Z) TargetEntryInstr(block_id_.Alloc(), kInvalidTryIndex); 1748 TargetEntryInstr(block_id_.Alloc(), kInvalidTryIndex, GetNextDeoptId());
1744 blocks_.Add(target); 1749 blocks_.Add(target);
1745 1750
1746 target->AppendInstruction(new (Z) GotoInstr(dst)); 1751 target->AppendInstruction(new (Z) GotoInstr(dst, GetNextDeoptId()));
1747 1752
1748 return target; 1753 return target;
1749 } 1754 }
1750 1755
1751 1756
1752 IndirectEntryInstr* IRRegExpMacroAssembler::IndirectWithJoinGoto( 1757 IndirectEntryInstr* IRRegExpMacroAssembler::IndirectWithJoinGoto(
1753 JoinEntryInstr* dst) { 1758 JoinEntryInstr* dst) {
1754 IndirectEntryInstr* target = new (Z) IndirectEntryInstr( 1759 IndirectEntryInstr* target =
1755 block_id_.Alloc(), indirect_id_.Alloc(), kInvalidTryIndex); 1760 new (Z) IndirectEntryInstr(block_id_.Alloc(), indirect_id_.Alloc(),
1761 kInvalidTryIndex, GetNextDeoptId());
1756 blocks_.Add(target); 1762 blocks_.Add(target);
1757 1763
1758 target->AppendInstruction(new (Z) GotoInstr(dst)); 1764 target->AppendInstruction(new (Z) GotoInstr(dst, GetNextDeoptId()));
1759 1765
1760 return target; 1766 return target;
1761 } 1767 }
1762 1768
1763 1769
1764 void IRRegExpMacroAssembler::CheckPreemption() { 1770 void IRRegExpMacroAssembler::CheckPreemption() {
1765 TAG(); 1771 TAG();
1766 AppendInstruction(new (Z) 1772 AppendInstruction(new (Z) CheckStackOverflowInstr(TokenPosition::kNoSource, 0,
1767 CheckStackOverflowInstr(TokenPosition::kNoSource, 0)); 1773 GetNextDeoptId()));
1768 } 1774 }
1769 1775
1770 1776
1771 Definition* IRRegExpMacroAssembler::Add(PushArgumentInstr* lhs, 1777 Definition* IRRegExpMacroAssembler::Add(PushArgumentInstr* lhs,
1772 PushArgumentInstr* rhs) { 1778 PushArgumentInstr* rhs) {
1773 return InstanceCall(InstanceCallDescriptor::FromToken(Token::kADD), lhs, rhs); 1779 return InstanceCall(InstanceCallDescriptor::FromToken(Token::kADD), lhs, rhs);
1774 } 1780 }
1775 1781
1776 1782
1777 Definition* IRRegExpMacroAssembler::Sub(PushArgumentInstr* lhs, 1783 Definition* IRRegExpMacroAssembler::Sub(PushArgumentInstr* lhs,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1846 1852
1847 return Bind(new (Z) LoadCodeUnitsInstr(pattern_val, index_val, characters, 1853 return Bind(new (Z) LoadCodeUnitsInstr(pattern_val, index_val, characters,
1848 specialization_cid_, 1854 specialization_cid_,
1849 TokenPosition::kNoSource)); 1855 TokenPosition::kNoSource));
1850 } 1856 }
1851 1857
1852 1858
1853 #undef __ 1859 #undef __
1854 1860
1855 } // namespace dart 1861 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/regexp_assembler_ir.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698