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, | |
82 Zone* zone) | 81 Zone* zone) |
83 : RegExpMacroAssembler(zone), | 82 : RegExpMacroAssembler(zone), |
84 thread_(Thread::Current()), | 83 thread_(Thread::Current()), |
85 specialization_cid_(specialization_cid), | 84 specialization_cid_(specialization_cid), |
86 parsed_function_(parsed_function), | 85 parsed_function_(parsed_function), |
87 ic_data_array_(ic_data_array), | 86 ic_data_array_(ic_data_array), |
88 current_instruction_(NULL), | 87 current_instruction_(NULL), |
89 stack_(NULL), | 88 stack_(NULL), |
90 stack_pointer_(NULL), | 89 stack_pointer_(NULL), |
91 current_character_(NULL), | 90 current_character_(NULL), |
(...skipping 27 matching lines...) Expand all Loading... |
119 stack_array_cell_.SetAt( | 118 stack_array_cell_.SetAt( |
120 0, | 119 0, |
121 TypedData::Handle(zone, TypedData::New(kTypedDataInt32ArrayCid, | 120 TypedData::Handle(zone, TypedData::New(kTypedDataInt32ArrayCid, |
122 kMinStackSize / 4, Heap::kOld))); | 121 kMinStackSize / 4, Heap::kOld))); |
123 | 122 |
124 // Create and generate all preset blocks. | 123 // Create and generate all preset blocks. |
125 entry_block_ = new (zone) GraphEntryInstr( | 124 entry_block_ = new (zone) GraphEntryInstr( |
126 *parsed_function_, | 125 *parsed_function_, |
127 new (zone) TargetEntryInstr(block_id_.Alloc(), kInvalidTryIndex, | 126 new (zone) TargetEntryInstr(block_id_.Alloc(), kInvalidTryIndex, |
128 GetNextDeoptId()), | 127 GetNextDeoptId()), |
129 osr_id); | 128 Compiler::kNoOSRDeoptId); |
130 start_block_ = new (zone) | 129 start_block_ = new (zone) |
131 JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex, GetNextDeoptId()); | 130 JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex, GetNextDeoptId()); |
132 success_block_ = new (zone) | 131 success_block_ = new (zone) |
133 JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex, GetNextDeoptId()); | 132 JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex, GetNextDeoptId()); |
134 backtrack_block_ = new (zone) | 133 backtrack_block_ = new (zone) |
135 JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex, GetNextDeoptId()); | 134 JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex, GetNextDeoptId()); |
136 exit_block_ = new (zone) | 135 exit_block_ = new (zone) |
137 JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex, GetNextDeoptId()); | 136 JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex, GetNextDeoptId()); |
138 | 137 |
139 GenerateEntryBlock(); | 138 GenerateEntryBlock(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 StoreLocal(stack_pointer_, Bind(Int64Constant(-1))); | 216 StoreLocal(stack_pointer_, Bind(Int64Constant(-1))); |
218 | 217 |
219 // Jump to the start block. | 218 // Jump to the start block. |
220 current_instruction_->Goto(start_block_); | 219 current_instruction_->Goto(start_block_); |
221 } | 220 } |
222 | 221 |
223 | 222 |
224 void IRRegExpMacroAssembler::GenerateBacktrackBlock() { | 223 void IRRegExpMacroAssembler::GenerateBacktrackBlock() { |
225 set_current_instruction(backtrack_block_); | 224 set_current_instruction(backtrack_block_); |
226 TAG(); | 225 TAG(); |
227 CheckPreemption(/*is_backtrack=*/true); | 226 CheckPreemption(); |
228 | 227 |
229 const intptr_t entries_count = entry_block_->indirect_entries().length(); | 228 const intptr_t entries_count = entry_block_->indirect_entries().length(); |
230 | 229 |
231 TypedData& offsets = TypedData::ZoneHandle( | 230 TypedData& offsets = TypedData::ZoneHandle( |
232 Z, TypedData::New(kTypedDataInt32ArrayCid, entries_count, Heap::kOld)); | 231 Z, TypedData::New(kTypedDataInt32ArrayCid, entries_count, Heap::kOld)); |
233 | 232 |
234 PushArgumentInstr* block_offsets_push = | 233 PushArgumentInstr* block_offsets_push = |
235 PushArgument(Bind(new (Z) ConstantInstr(offsets))); | 234 PushArgument(Bind(new (Z) ConstantInstr(offsets))); |
236 PushArgumentInstr* block_id_push = PushArgument(Bind(PopStack())); | 235 PushArgumentInstr* block_id_push = PushArgument(Bind(PopStack())); |
237 | 236 |
(...skipping 1523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1761 new (Z) IndirectEntryInstr(block_id_.Alloc(), indirect_id_.Alloc(), | 1760 new (Z) IndirectEntryInstr(block_id_.Alloc(), indirect_id_.Alloc(), |
1762 kInvalidTryIndex, GetNextDeoptId()); | 1761 kInvalidTryIndex, GetNextDeoptId()); |
1763 blocks_.Add(target); | 1762 blocks_.Add(target); |
1764 | 1763 |
1765 target->AppendInstruction(new (Z) GotoInstr(dst, GetNextDeoptId())); | 1764 target->AppendInstruction(new (Z) GotoInstr(dst, GetNextDeoptId())); |
1766 | 1765 |
1767 return target; | 1766 return target; |
1768 } | 1767 } |
1769 | 1768 |
1770 | 1769 |
1771 void IRRegExpMacroAssembler::CheckPreemption(bool is_backtrack) { | 1770 void IRRegExpMacroAssembler::CheckPreemption() { |
1772 TAG(); | 1771 TAG(); |
1773 | 1772 AppendInstruction(new (Z) CheckStackOverflowInstr(TokenPosition::kNoSource, 0, |
1774 // We don't have the loop_depth available when compiling regexps, but | 1773 GetNextDeoptId())); |
1775 // we set loop_depth to a non-zero value because this instruction does | |
1776 // not act as an OSR entry outside loops. | |
1777 AppendInstruction(new (Z) CheckStackOverflowInstr( | |
1778 TokenPosition::kNoSource, | |
1779 /*loop_depth=*/1, GetNextDeoptId(), | |
1780 is_backtrack ? CheckStackOverflowInstr::kOsrAndPreemption | |
1781 : CheckStackOverflowInstr::kOsrOnly)); | |
1782 } | 1774 } |
1783 | 1775 |
1784 | 1776 |
1785 Definition* IRRegExpMacroAssembler::Add(PushArgumentInstr* lhs, | 1777 Definition* IRRegExpMacroAssembler::Add(PushArgumentInstr* lhs, |
1786 PushArgumentInstr* rhs) { | 1778 PushArgumentInstr* rhs) { |
1787 return InstanceCall(InstanceCallDescriptor::FromToken(Token::kADD), lhs, rhs); | 1779 return InstanceCall(InstanceCallDescriptor::FromToken(Token::kADD), lhs, rhs); |
1788 } | 1780 } |
1789 | 1781 |
1790 | 1782 |
1791 Definition* IRRegExpMacroAssembler::Sub(PushArgumentInstr* lhs, | 1783 Definition* IRRegExpMacroAssembler::Sub(PushArgumentInstr* lhs, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1860 | 1852 |
1861 return Bind(new (Z) LoadCodeUnitsInstr(pattern_val, index_val, characters, | 1853 return Bind(new (Z) LoadCodeUnitsInstr(pattern_val, index_val, characters, |
1862 specialization_cid_, | 1854 specialization_cid_, |
1863 TokenPosition::kNoSource)); | 1855 TokenPosition::kNoSource)); |
1864 } | 1856 } |
1865 | 1857 |
1866 | 1858 |
1867 #undef __ | 1859 #undef __ |
1868 | 1860 |
1869 } // namespace dart | 1861 } // namespace dart |
OLD | NEW |