OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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/globals.h" // Needed here to get TARGET_ARCH_DBC. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_DBC. |
6 #if defined(TARGET_ARCH_DBC) | 6 #if defined(TARGET_ARCH_DBC) |
7 | 7 |
8 #include "vm/flow_graph_compiler.h" | 8 #include "vm/flow_graph_compiler.h" |
9 | 9 |
10 #include "vm/ast_printer.h" | 10 #include "vm/ast_printer.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 builder->AddPcMarker(Function::ZoneHandle(zone), slot_ix++); | 113 builder->AddPcMarker(Function::ZoneHandle(zone), slot_ix++); |
114 builder->AddConstant(Function::ZoneHandle(zone), slot_ix++); | 114 builder->AddConstant(Function::ZoneHandle(zone), slot_ix++); |
115 | 115 |
116 // Emit all values that are needed for materialization as a part of the | 116 // Emit all values that are needed for materialization as a part of the |
117 // expression stack for the bottom-most frame. This guarantees that GC | 117 // expression stack for the bottom-most frame. This guarantees that GC |
118 // will be able to find them during materialization. | 118 // will be able to find them during materialization. |
119 slot_ix = builder->EmitMaterializationArguments(slot_ix); | 119 slot_ix = builder->EmitMaterializationArguments(slot_ix); |
120 | 120 |
121 // For the innermost environment, set outgoing arguments and the locals. | 121 // For the innermost environment, set outgoing arguments and the locals. |
122 for (intptr_t i = current->Length() - 1; | 122 for (intptr_t i = current->Length() - 1; |
123 i >= current->fixed_parameter_count(); | 123 i >= current->fixed_parameter_count(); i--) { |
124 i--) { | |
125 builder->AddCopy(current->ValueAt(i), current->LocationAt(i), slot_ix++); | 124 builder->AddCopy(current->ValueAt(i), current->LocationAt(i), slot_ix++); |
126 } | 125 } |
127 | 126 |
128 builder->AddCallerFp(slot_ix++); | 127 builder->AddCallerFp(slot_ix++); |
129 | 128 |
130 Environment* previous = current; | 129 Environment* previous = current; |
131 current = current->outer(); | 130 current = current->outer(); |
132 while (current != NULL) { | 131 while (current != NULL) { |
133 // For any outer environment the deopt id is that of the call instruction | 132 // For any outer environment the deopt id is that of the call instruction |
134 // which is recorded in the outer environment. | 133 // which is recorded in the outer environment. |
135 builder->AddReturnAddress( | 134 builder->AddReturnAddress(current->function(), |
136 current->function(), | 135 Thread::ToDeoptAfter(current->deopt_id()), |
137 Thread::ToDeoptAfter(current->deopt_id()), | 136 slot_ix++); |
138 slot_ix++); | |
139 | 137 |
140 builder->AddPcMarker(previous->function(), slot_ix++); | 138 builder->AddPcMarker(previous->function(), slot_ix++); |
141 builder->AddConstant(previous->function(), slot_ix++); | 139 builder->AddConstant(previous->function(), slot_ix++); |
142 | 140 |
143 // The values of outgoing arguments can be changed from the inlined call so | 141 // The values of outgoing arguments can be changed from the inlined call so |
144 // we must read them from the previous environment. | 142 // we must read them from the previous environment. |
145 for (intptr_t i = previous->fixed_parameter_count() - 1; i >= 0; i--) { | 143 for (intptr_t i = previous->fixed_parameter_count() - 1; i >= 0; i--) { |
146 builder->AddCopy(previous->ValueAt(i), | 144 builder->AddCopy(previous->ValueAt(i), previous->LocationAt(i), |
147 previous->LocationAt(i), | |
148 slot_ix++); | 145 slot_ix++); |
149 } | 146 } |
150 | 147 |
151 // Set the locals, note that outgoing arguments are not in the environment. | 148 // Set the locals, note that outgoing arguments are not in the environment. |
152 for (intptr_t i = current->Length() - 1; | 149 for (intptr_t i = current->Length() - 1; |
153 i >= current->fixed_parameter_count(); | 150 i >= current->fixed_parameter_count(); i--) { |
154 i--) { | 151 builder->AddCopy(current->ValueAt(i), current->LocationAt(i), slot_ix++); |
155 builder->AddCopy(current->ValueAt(i), | |
156 current->LocationAt(i), | |
157 slot_ix++); | |
158 } | 152 } |
159 | 153 |
160 builder->AddCallerFp(slot_ix++); | 154 builder->AddCallerFp(slot_ix++); |
161 | 155 |
162 // Iterate on the outer environment. | 156 // Iterate on the outer environment. |
163 previous = current; | 157 previous = current; |
164 current = current->outer(); | 158 current = current->outer(); |
165 } | 159 } |
166 // The previous pointer is now the outermost environment. | 160 // The previous pointer is now the outermost environment. |
167 ASSERT(previous != NULL); | 161 ASSERT(previous != NULL); |
(...skipping 20 matching lines...) Expand all Loading... |
188 // deoptimization point in optimized code, after call. | 182 // deoptimization point in optimized code, after call. |
189 const intptr_t deopt_id_after = Thread::ToDeoptAfter(instr->deopt_id()); | 183 const intptr_t deopt_id_after = Thread::ToDeoptAfter(instr->deopt_id()); |
190 if (is_optimizing()) { | 184 if (is_optimizing()) { |
191 // Return/ReturnTOS instruction drops incoming arguments so | 185 // Return/ReturnTOS instruction drops incoming arguments so |
192 // we have to drop outgoing arguments from the innermost environment. | 186 // we have to drop outgoing arguments from the innermost environment. |
193 // On all other architectures caller drops outgoing arguments itself | 187 // On all other architectures caller drops outgoing arguments itself |
194 // hence the difference. | 188 // hence the difference. |
195 pending_deoptimization_env_->DropArguments(instr->ArgumentCount()); | 189 pending_deoptimization_env_->DropArguments(instr->ArgumentCount()); |
196 AddDeoptIndexAtCall(deopt_id_after); | 190 AddDeoptIndexAtCall(deopt_id_after); |
197 // This descriptor is needed for exception handling in optimized code. | 191 // This descriptor is needed for exception handling in optimized code. |
198 AddCurrentDescriptor(RawPcDescriptors::kOther, | 192 AddCurrentDescriptor(RawPcDescriptors::kOther, deopt_id_after, |
199 deopt_id_after, instr->token_pos()); | 193 instr->token_pos()); |
200 } else { | 194 } else { |
201 // Add deoptimization continuation point after the call and before the | 195 // Add deoptimization continuation point after the call and before the |
202 // arguments are removed. | 196 // arguments are removed. |
203 AddCurrentDescriptor(RawPcDescriptors::kDeopt, | 197 AddCurrentDescriptor(RawPcDescriptors::kDeopt, deopt_id_after, |
204 deopt_id_after, | |
205 instr->token_pos()); | 198 instr->token_pos()); |
206 } | 199 } |
207 } | 200 } |
208 | 201 |
209 | 202 |
210 void CompilerDeoptInfoWithStub::GenerateCode(FlowGraphCompiler* compiler, | 203 void CompilerDeoptInfoWithStub::GenerateCode(FlowGraphCompiler* compiler, |
211 intptr_t stub_ix) { | 204 intptr_t stub_ix) { |
212 UNREACHABLE(); | 205 UNREACHABLE(); |
213 } | 206 } |
214 | 207 |
(...skipping 22 matching lines...) Expand all Loading... |
237 __ PushConstant(dst_name); | 230 __ PushConstant(dst_name); |
238 | 231 |
239 if (dst_type.IsMalformedOrMalbounded()) { | 232 if (dst_type.IsMalformedOrMalbounded()) { |
240 __ BadTypeError(); | 233 __ BadTypeError(); |
241 } else { | 234 } else { |
242 bool may_be_smi = false; | 235 bool may_be_smi = false; |
243 if (!dst_type.IsVoidType() && dst_type.IsInstantiated()) { | 236 if (!dst_type.IsVoidType() && dst_type.IsInstantiated()) { |
244 const Class& type_class = Class::Handle(zone(), dst_type.type_class()); | 237 const Class& type_class = Class::Handle(zone(), dst_type.type_class()); |
245 if (type_class.NumTypeArguments() == 0) { | 238 if (type_class.NumTypeArguments() == 0) { |
246 const Class& smi_class = Class::Handle(zone(), Smi::Class()); | 239 const Class& smi_class = Class::Handle(zone(), Smi::Class()); |
247 may_be_smi = smi_class.IsSubtypeOf(TypeArguments::Handle(zone()), | 240 may_be_smi = smi_class.IsSubtypeOf( |
248 type_class, | 241 TypeArguments::Handle(zone()), type_class, |
249 TypeArguments::Handle(zone()), | 242 TypeArguments::Handle(zone()), NULL, NULL, Heap::kOld); |
250 NULL, | |
251 NULL, | |
252 Heap::kOld); | |
253 } | 243 } |
254 } | 244 } |
255 __ AssertAssignable(may_be_smi ? 1 : 0, __ AddConstant(test_cache)); | 245 __ AssertAssignable(may_be_smi ? 1 : 0, __ AddConstant(test_cache)); |
256 } | 246 } |
257 | 247 |
258 if (is_optimizing()) { | 248 if (is_optimizing()) { |
259 // Register allocator does not think that our first input (also used as | 249 // Register allocator does not think that our first input (also used as |
260 // output) needs to be kept alive across the call because that is how code | 250 // output) needs to be kept alive across the call because that is how code |
261 // is written on other platforms (where registers are always spilled across | 251 // is written on other platforms (where registers are always spilled across |
262 // the call): inputs are consumed by operation and output is produced so | 252 // the call): inputs are consumed by operation and output is produced so |
263 // neither are alive at the safepoint. | 253 // neither are alive at the safepoint. |
264 // We have to mark the slot alive manually to ensure that GC | 254 // We have to mark the slot alive manually to ensure that GC |
265 // visits it. | 255 // visits it. |
266 locs->SetStackBit(locs->out(0).reg()); | 256 locs->SetStackBit(locs->out(0).reg()); |
267 } | 257 } |
268 RecordSafepoint(locs); | 258 RecordSafepoint(locs); |
269 AddCurrentDescriptor(RawPcDescriptors::kOther, deopt_id, token_pos); | 259 AddCurrentDescriptor(RawPcDescriptors::kOther, deopt_id, token_pos); |
270 if (is_optimizing()) { | 260 if (is_optimizing()) { |
271 // Assert assignable keeps the instance on the stack as the result, | 261 // Assert assignable keeps the instance on the stack as the result, |
272 // all other arguments are popped. | 262 // all other arguments are popped. |
273 ASSERT(locs->out(0).reg() == locs->in(0).reg()); | 263 ASSERT(locs->out(0).reg() == locs->in(0).reg()); |
274 __ Drop1(); | 264 __ Drop1(); |
275 } | 265 } |
276 } | 266 } |
277 | 267 |
278 | 268 |
279 void FlowGraphCompiler::EmitInstructionEpilogue(Instruction* instr) { | 269 void FlowGraphCompiler::EmitInstructionEpilogue(Instruction* instr) { |
280 if (!is_optimizing()) { | 270 if (!is_optimizing()) { |
281 Definition* defn = instr->AsDefinition(); | 271 Definition* defn = instr->AsDefinition(); |
282 if ((defn != NULL) && | 272 if ((defn != NULL) && (defn->tag() != Instruction::kPushArgument) && |
283 (defn->tag() != Instruction::kPushArgument) && | |
284 (defn->tag() != Instruction::kStoreIndexed) && | 273 (defn->tag() != Instruction::kStoreIndexed) && |
285 (defn->tag() != Instruction::kStoreStaticField) && | 274 (defn->tag() != Instruction::kStoreStaticField) && |
286 (defn->tag() != Instruction::kStoreLocal) && | 275 (defn->tag() != Instruction::kStoreLocal) && |
287 (defn->tag() != Instruction::kStoreInstanceField) && | 276 (defn->tag() != Instruction::kStoreInstanceField) && |
288 (defn->tag() != Instruction::kDropTemps) && | 277 (defn->tag() != Instruction::kDropTemps) && !defn->HasTemp()) { |
289 !defn->HasTemp()) { | |
290 __ Drop1(); | 278 __ Drop1(); |
291 } | 279 } |
292 } | 280 } |
293 } | 281 } |
294 | 282 |
295 | 283 |
296 void FlowGraphCompiler::GenerateInlinedGetter(intptr_t offset) { | 284 void FlowGraphCompiler::GenerateInlinedGetter(intptr_t offset) { |
297 __ Move(0, -(1 + kParamEndSlotFromFp)); | 285 __ Move(0, -(1 + kParamEndSlotFromFp)); |
298 ASSERT(offset % kWordSize == 0); | 286 ASSERT(offset % kWordSize == 0); |
299 if (Utils::IsInt(8, offset/ kWordSize)) { | 287 if (Utils::IsInt(8, offset / kWordSize)) { |
300 __ LoadField(0, 0, offset / kWordSize); | 288 __ LoadField(0, 0, offset / kWordSize); |
301 } else { | 289 } else { |
302 __ LoadFieldExt(0, 0); | 290 __ LoadFieldExt(0, 0); |
303 __ Nop(offset / kWordSize); | 291 __ Nop(offset / kWordSize); |
304 } | 292 } |
305 __ Return(0); | 293 __ Return(0); |
306 } | 294 } |
307 | 295 |
308 | 296 |
309 void FlowGraphCompiler::GenerateInlinedSetter(intptr_t offset) { | 297 void FlowGraphCompiler::GenerateInlinedSetter(intptr_t offset) { |
310 __ Move(0, -(2 + kParamEndSlotFromFp)); | 298 __ Move(0, -(2 + kParamEndSlotFromFp)); |
311 __ Move(1, -(1 + kParamEndSlotFromFp)); | 299 __ Move(1, -(1 + kParamEndSlotFromFp)); |
312 ASSERT(offset % kWordSize == 0); | 300 ASSERT(offset % kWordSize == 0); |
313 if (Utils::IsInt(8, offset/ kWordSize)) { | 301 if (Utils::IsInt(8, offset / kWordSize)) { |
314 __ StoreField(0, offset / kWordSize, 1); | 302 __ StoreField(0, offset / kWordSize, 1); |
315 } else { | 303 } else { |
316 __ StoreFieldExt(0, 1); | 304 __ StoreFieldExt(0, 1); |
317 __ Nop(offset / kWordSize); | 305 __ Nop(offset / kWordSize); |
318 } | 306 } |
319 __ LoadConstant(0, Object::Handle()); | 307 __ LoadConstant(0, Object::Handle()); |
320 __ Return(0); | 308 __ Return(0); |
321 } | 309 } |
322 | 310 |
323 | 311 |
324 void FlowGraphCompiler::EmitFrameEntry() { | 312 void FlowGraphCompiler::EmitFrameEntry() { |
325 const Function& function = parsed_function().function(); | 313 const Function& function = parsed_function().function(); |
326 const intptr_t num_fixed_params = function.num_fixed_parameters(); | 314 const intptr_t num_fixed_params = function.num_fixed_parameters(); |
327 const int num_opt_pos_params = function.NumOptionalPositionalParameters(); | 315 const int num_opt_pos_params = function.NumOptionalPositionalParameters(); |
328 const int num_opt_named_params = function.NumOptionalNamedParameters(); | 316 const int num_opt_named_params = function.NumOptionalNamedParameters(); |
329 const int num_params = | 317 const int num_params = |
330 num_fixed_params + num_opt_pos_params + num_opt_named_params; | 318 num_fixed_params + num_opt_pos_params + num_opt_named_params; |
331 const bool has_optional_params = (num_opt_pos_params != 0) || | 319 const bool has_optional_params = |
332 (num_opt_named_params != 0); | 320 (num_opt_pos_params != 0) || (num_opt_named_params != 0); |
333 const int num_locals = parsed_function().num_stack_locals(); | 321 const int num_locals = parsed_function().num_stack_locals(); |
334 const intptr_t context_index = | 322 const intptr_t context_index = |
335 -parsed_function().current_context_var()->index() - 1; | 323 -parsed_function().current_context_var()->index() - 1; |
336 | 324 |
337 if (CanOptimizeFunction() && | 325 if (CanOptimizeFunction() && function.IsOptimizable() && |
338 function.IsOptimizable() && | |
339 (!is_optimizing() || may_reoptimize())) { | 326 (!is_optimizing() || may_reoptimize())) { |
340 __ HotCheck(!is_optimizing(), GetOptimizationThreshold()); | 327 __ HotCheck(!is_optimizing(), GetOptimizationThreshold()); |
341 } | 328 } |
342 | 329 |
343 if (has_optional_params) { | 330 if (has_optional_params) { |
344 __ EntryOptional(num_fixed_params, | 331 __ EntryOptional(num_fixed_params, num_opt_pos_params, |
345 num_opt_pos_params, | |
346 num_opt_named_params); | 332 num_opt_named_params); |
347 } else if (!is_optimizing()) { | 333 } else if (!is_optimizing()) { |
348 __ Entry(num_fixed_params, num_locals, context_index); | 334 __ Entry(num_fixed_params, num_locals, context_index); |
349 } else { | 335 } else { |
350 __ EntryOptimized(num_fixed_params, | 336 __ EntryOptimized(num_fixed_params, |
351 flow_graph_.graph_entry()->spill_slot_count()); | 337 flow_graph_.graph_entry()->spill_slot_count()); |
352 } | 338 } |
353 | 339 |
354 if (num_opt_named_params != 0) { | 340 if (num_opt_named_params != 0) { |
355 LocalScope* scope = parsed_function().node_sequence()->scope(); | 341 LocalScope* scope = parsed_function().node_sequence()->scope(); |
(...skipping 29 matching lines...) Expand all Loading... |
385 for (intptr_t i = 0; i < num_opt_pos_params; i++) { | 371 for (intptr_t i = 0; i < num_opt_pos_params; i++) { |
386 const Object& value = parsed_function().DefaultParameterValueAt(i); | 372 const Object& value = parsed_function().DefaultParameterValueAt(i); |
387 __ LoadConstant(num_fixed_params + i, value); | 373 __ LoadConstant(num_fixed_params + i, value); |
388 } | 374 } |
389 } | 375 } |
390 | 376 |
391 | 377 |
392 if (has_optional_params) { | 378 if (has_optional_params) { |
393 if (!is_optimizing()) { | 379 if (!is_optimizing()) { |
394 ASSERT(num_locals > 0); // There is always at least context_var. | 380 ASSERT(num_locals > 0); // There is always at least context_var. |
395 __ Frame(num_locals); // Reserve space for locals. | 381 __ Frame(num_locals); // Reserve space for locals. |
396 } else if (flow_graph_.graph_entry()->spill_slot_count() > | 382 } else if (flow_graph_.graph_entry()->spill_slot_count() > |
397 flow_graph_.num_copied_params()) { | 383 flow_graph_.num_copied_params()) { |
398 __ Frame(flow_graph_.graph_entry()->spill_slot_count() - | 384 __ Frame(flow_graph_.graph_entry()->spill_slot_count() - |
399 flow_graph_.num_copied_params()); | 385 flow_graph_.num_copied_params()); |
400 } | 386 } |
401 } | 387 } |
402 | 388 |
403 if (function.IsClosureFunction()) { | 389 if (function.IsClosureFunction()) { |
404 Register reg = is_optimizing() ? flow_graph_.num_copied_params() | 390 Register reg = |
405 : context_index; | 391 is_optimizing() ? flow_graph_.num_copied_params() : context_index; |
406 Register closure_reg = reg; | 392 Register closure_reg = reg; |
407 LocalScope* scope = parsed_function().node_sequence()->scope(); | 393 LocalScope* scope = parsed_function().node_sequence()->scope(); |
408 LocalVariable* local = scope->VariableAt(0); | 394 LocalVariable* local = scope->VariableAt(0); |
409 if (local->index() > 0) { | 395 if (local->index() > 0) { |
410 __ Move(reg, -local->index()); | 396 __ Move(reg, -local->index()); |
411 } else { | 397 } else { |
412 closure_reg = -local->index() - 1; | 398 closure_reg = -local->index() - 1; |
413 } | 399 } |
414 __ LoadField(reg, closure_reg, Closure::context_offset() / kWordSize); | 400 __ LoadField(reg, closure_reg, Closure::context_offset() / kWordSize); |
415 } else if (has_optional_params && !is_optimizing()) { | 401 } else if (has_optional_params && !is_optimizing()) { |
416 __ LoadConstant(context_index, | 402 __ LoadConstant(context_index, |
417 Object::Handle(isolate()->object_store()->empty_context())); | 403 Object::Handle(isolate()->object_store()->empty_context())); |
418 } | 404 } |
419 } | 405 } |
420 | 406 |
421 | 407 |
422 void FlowGraphCompiler::CompileGraph() { | 408 void FlowGraphCompiler::CompileGraph() { |
423 InitCompiler(); | 409 InitCompiler(); |
424 | 410 |
425 if (TryIntrinsify()) { | 411 if (TryIntrinsify()) { |
426 // Skip regular code generation. | 412 // Skip regular code generation. |
427 return; | 413 return; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 void ParallelMoveResolver::RestoreFpuScratch(FpuRegister reg) { | 548 void ParallelMoveResolver::RestoreFpuScratch(FpuRegister reg) { |
563 UNIMPLEMENTED(); | 549 UNIMPLEMENTED(); |
564 } | 550 } |
565 | 551 |
566 | 552 |
567 #undef __ | 553 #undef __ |
568 | 554 |
569 } // namespace dart | 555 } // namespace dart |
570 | 556 |
571 #endif // defined TARGET_ARCH_DBC | 557 #endif // defined TARGET_ARCH_DBC |
OLD | NEW |