OLD | NEW |
---|---|
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 * indices of -1 denote non-matched groups. Note that we store these indices | 71 * indices of -1 denote non-matched groups. Note that we store these indices |
72 * as a negative offset from the end of the string in registers_array_ | 72 * as a negative offset from the end of the string in registers_array_ |
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 intptr_t osr_id, | |
81 Zone* zone) | 82 Zone* zone) |
82 : RegExpMacroAssembler(zone), | 83 : RegExpMacroAssembler(zone), |
83 thread_(Thread::Current()), | 84 thread_(Thread::Current()), |
84 specialization_cid_(specialization_cid), | 85 specialization_cid_(specialization_cid), |
85 parsed_function_(parsed_function), | 86 parsed_function_(parsed_function), |
86 ic_data_array_(ic_data_array), | 87 ic_data_array_(ic_data_array), |
87 current_instruction_(NULL), | 88 current_instruction_(NULL), |
88 stack_(NULL), | 89 stack_(NULL), |
89 stack_pointer_(NULL), | 90 stack_pointer_(NULL), |
90 current_character_(NULL), | 91 current_character_(NULL), |
(...skipping 27 matching lines...) Expand all Loading... | |
118 stack_array_cell_.SetAt( | 119 stack_array_cell_.SetAt( |
119 0, | 120 0, |
120 TypedData::Handle(zone, TypedData::New(kTypedDataInt32ArrayCid, | 121 TypedData::Handle(zone, TypedData::New(kTypedDataInt32ArrayCid, |
121 kMinStackSize / 4, Heap::kOld))); | 122 kMinStackSize / 4, Heap::kOld))); |
122 | 123 |
123 // Create and generate all preset blocks. | 124 // Create and generate all preset blocks. |
124 entry_block_ = new (zone) GraphEntryInstr( | 125 entry_block_ = new (zone) GraphEntryInstr( |
125 *parsed_function_, | 126 *parsed_function_, |
126 new (zone) TargetEntryInstr(block_id_.Alloc(), kInvalidTryIndex, | 127 new (zone) TargetEntryInstr(block_id_.Alloc(), kInvalidTryIndex, |
127 GetNextDeoptId()), | 128 GetNextDeoptId()), |
128 Compiler::kNoOSRDeoptId); | 129 osr_id); |
129 start_block_ = new (zone) | 130 start_block_ = new (zone) |
130 JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex, GetNextDeoptId()); | 131 JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex, GetNextDeoptId()); |
131 success_block_ = new (zone) | 132 success_block_ = new (zone) |
132 JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex, GetNextDeoptId()); | 133 JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex, GetNextDeoptId()); |
133 backtrack_block_ = new (zone) | 134 backtrack_block_ = new (zone) |
134 JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex, GetNextDeoptId()); | 135 JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex, GetNextDeoptId()); |
135 exit_block_ = new (zone) | 136 exit_block_ = new (zone) |
136 JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex, GetNextDeoptId()); | 137 JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex, GetNextDeoptId()); |
137 | 138 |
138 GenerateEntryBlock(); | 139 GenerateEntryBlock(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 StoreLocal(stack_pointer_, Bind(Int64Constant(-1))); | 217 StoreLocal(stack_pointer_, Bind(Int64Constant(-1))); |
217 | 218 |
218 // Jump to the start block. | 219 // Jump to the start block. |
219 current_instruction_->Goto(start_block_); | 220 current_instruction_->Goto(start_block_); |
220 } | 221 } |
221 | 222 |
222 | 223 |
223 void IRRegExpMacroAssembler::GenerateBacktrackBlock() { | 224 void IRRegExpMacroAssembler::GenerateBacktrackBlock() { |
224 set_current_instruction(backtrack_block_); | 225 set_current_instruction(backtrack_block_); |
225 TAG(); | 226 TAG(); |
226 CheckPreemption(); | 227 CheckPreemption(/*is_backtrack=*/true); |
227 | 228 |
228 const intptr_t entries_count = entry_block_->indirect_entries().length(); | 229 const intptr_t entries_count = entry_block_->indirect_entries().length(); |
229 | 230 |
230 TypedData& offsets = TypedData::ZoneHandle( | 231 TypedData& offsets = TypedData::ZoneHandle( |
231 Z, TypedData::New(kTypedDataInt32ArrayCid, entries_count, Heap::kOld)); | 232 Z, TypedData::New(kTypedDataInt32ArrayCid, entries_count, Heap::kOld)); |
232 | 233 |
233 PushArgumentInstr* block_offsets_push = | 234 PushArgumentInstr* block_offsets_push = |
234 PushArgument(Bind(new (Z) ConstantInstr(offsets))); | 235 PushArgument(Bind(new (Z) ConstantInstr(offsets))); |
235 PushArgumentInstr* block_id_push = PushArgument(Bind(PopStack())); | 236 PushArgumentInstr* block_id_push = PushArgument(Bind(PopStack())); |
236 | 237 |
(...skipping 1523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1760 new (Z) IndirectEntryInstr(block_id_.Alloc(), indirect_id_.Alloc(), | 1761 new (Z) IndirectEntryInstr(block_id_.Alloc(), indirect_id_.Alloc(), |
1761 kInvalidTryIndex, GetNextDeoptId()); | 1762 kInvalidTryIndex, GetNextDeoptId()); |
1762 blocks_.Add(target); | 1763 blocks_.Add(target); |
1763 | 1764 |
1764 target->AppendInstruction(new (Z) GotoInstr(dst, GetNextDeoptId())); | 1765 target->AppendInstruction(new (Z) GotoInstr(dst, GetNextDeoptId())); |
1765 | 1766 |
1766 return target; | 1767 return target; |
1767 } | 1768 } |
1768 | 1769 |
1769 | 1770 |
1770 void IRRegExpMacroAssembler::CheckPreemption() { | 1771 void IRRegExpMacroAssembler::CheckPreemption(bool is_backtrack) { |
1771 TAG(); | 1772 TAG(); |
1772 AppendInstruction(new (Z) CheckStackOverflowInstr(TokenPosition::kNoSource, 0, | 1773 |
1773 GetNextDeoptId())); | 1774 // Setting non-zero loop_depth turns this CheckStackOverflow into |
erikcorry
2017/06/21 07:54:07
This is confusing. "Turns it into an OSR entry" s
Vyacheslav Egorov (Google)
2017/06/21 11:42:04
Done.
| |
1775 // an OSR entry. | |
1776 AppendInstruction(new (Z) CheckStackOverflowInstr( | |
1777 TokenPosition::kNoSource, | |
1778 /*loop_depth=*/1, GetNextDeoptId(), | |
1779 is_backtrack ? CheckStackOverflowInstr::kFull | |
1780 : CheckStackOverflowInstr::kOsrEntry)); | |
1774 } | 1781 } |
1775 | 1782 |
1776 | 1783 |
1777 Definition* IRRegExpMacroAssembler::Add(PushArgumentInstr* lhs, | 1784 Definition* IRRegExpMacroAssembler::Add(PushArgumentInstr* lhs, |
1778 PushArgumentInstr* rhs) { | 1785 PushArgumentInstr* rhs) { |
1779 return InstanceCall(InstanceCallDescriptor::FromToken(Token::kADD), lhs, rhs); | 1786 return InstanceCall(InstanceCallDescriptor::FromToken(Token::kADD), lhs, rhs); |
1780 } | 1787 } |
1781 | 1788 |
1782 | 1789 |
1783 Definition* IRRegExpMacroAssembler::Sub(PushArgumentInstr* lhs, | 1790 Definition* IRRegExpMacroAssembler::Sub(PushArgumentInstr* lhs, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1852 | 1859 |
1853 return Bind(new (Z) LoadCodeUnitsInstr(pattern_val, index_val, characters, | 1860 return Bind(new (Z) LoadCodeUnitsInstr(pattern_val, index_val, characters, |
1854 specialization_cid_, | 1861 specialization_cid_, |
1855 TokenPosition::kNoSource)); | 1862 TokenPosition::kNoSource)); |
1856 } | 1863 } |
1857 | 1864 |
1858 | 1865 |
1859 #undef __ | 1866 #undef __ |
1860 | 1867 |
1861 } // namespace dart | 1868 } // namespace dart |
OLD | NEW |