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

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

Issue 13474009: Implements optional parameter handling in MIPS vm. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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_MIPS. 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_MIPS.
6 #if defined(TARGET_ARCH_MIPS) 6 #if defined(TARGET_ARCH_MIPS)
7 7
8 #include "vm/flow_graph_compiler.h" 8 #include "vm/flow_graph_compiler.h"
9 9
10 #include "lib/error.h" 10 #include "lib/error.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 159
160 void FlowGraphCompiler::EmitInstructionEpilogue(Instruction* instr) { 160 void FlowGraphCompiler::EmitInstructionEpilogue(Instruction* instr) {
161 if (is_optimizing()) return; 161 if (is_optimizing()) return;
162 Definition* defn = instr->AsDefinition(); 162 Definition* defn = instr->AsDefinition();
163 if ((defn != NULL) && defn->is_used()) { 163 if ((defn != NULL) && defn->is_used()) {
164 __ Push(defn->locs()->out().reg()); 164 __ Push(defn->locs()->out().reg());
165 } 165 }
166 } 166 }
167 167
168 168
169 // Input parameters:
170 // S4: arguments descriptor array.
169 void FlowGraphCompiler::CopyParameters() { 171 void FlowGraphCompiler::CopyParameters() {
170 UNIMPLEMENTED(); 172 __ Comment("Copy parameters");
173 const Function& function = parsed_function().function();
174 LocalScope* scope = parsed_function().node_sequence()->scope();
175 const int num_fixed_params = function.num_fixed_parameters();
176 const int num_opt_pos_params = function.NumOptionalPositionalParameters();
177 const int num_opt_named_params = function.NumOptionalNamedParameters();
178 const int num_params =
179 num_fixed_params + num_opt_pos_params + num_opt_named_params;
180 ASSERT(function.NumParameters() == num_params);
181 ASSERT(parsed_function().first_parameter_index() == kFirstLocalSlotIndex);
182
183 // Check that min_num_pos_args <= num_pos_args <= max_num_pos_args,
184 // where num_pos_args is the number of positional arguments passed in.
185 const int min_num_pos_args = num_fixed_params;
186 const int max_num_pos_args = num_fixed_params + num_opt_pos_params;
187
188 __ lw(T2, FieldAddress(S4, ArgumentsDescriptor::positional_count_offset()));
189 // Check that min_num_pos_args <= num_pos_args.
190 Label wrong_num_arguments;
191 __ addiu(T3, T2, Immediate(-Smi::RawValue(min_num_pos_args)));
192 __ bltz(T3, &wrong_num_arguments);
193
194 // Check that num_pos_args <= max_num_pos_args.
195 __ addiu(T3, T2, Immediate(-Smi::RawValue(max_num_pos_args)));
196 __ bgtz(T3, &wrong_num_arguments);
197
198 // Copy positional arguments.
199 // Argument i passed at fp[kLastParamSlotIndex + num_args - 1 - i] is copied
200 // to fp[kFirstLocalSlotIndex - i].
201
202 __ lw(T1, FieldAddress(S4, ArgumentsDescriptor::count_offset()));
203 // Since T1 and T2 are Smi, use LSL 1 instead of LSL 2.
204 // Let T1 point to the last passed positional argument, i.e. to
205 // fp[kLastParamSlotIndex + num_args - 1 - (num_pos_args - 1)].
206 __ subu(T1, T1, T2);
207 __ sll(T1, T1, 1);
208 __ addu(T1, FP, T1);
209 __ addiu(T1, T1, Immediate(kLastParamSlotIndex * kWordSize));
210
211 // Let T0 point to the last copied positional argument, i.e. to
212 // fp[kFirstLocalSlotIndex - (num_pos_args - 1)].
213 __ addiu(T0, FP, Immediate((kFirstLocalSlotIndex + 1) * kWordSize));
214 __ sll(T3, T2, 1); // T2 is a Smi.
215 __ subu(T0, T0, T3);
216
217 Label loop, loop_condition;
218 __ b(&loop_condition);
219 __ delay_slot()->SmiUntag(T2);
220 // We do not use the final allocation index of the variable here, i.e.
221 // scope->VariableAt(i)->index(), because captured variables still need
222 // to be copied to the context that is not yet allocated.
223 __ Bind(&loop);
224 __ addu(T4, T1, T2);
225 __ addu(T5, T0, T2);
226 __ lw(TMP, Address(T4));
227 __ sw(TMP, Address(T5));
228 __ Bind(&loop_condition);
229 __ addiu(T2, T2, Immediate(-4));
regis 2013/04/03 21:44:29 -kWordSize would be better.
230 __ bgez(T2, &loop);
231
232 // Copy or initialize optional named arguments.
233 Label all_arguments_processed;
234 if (num_opt_named_params > 0) {
235 // Start by alphabetically sorting the names of the optional parameters.
236 LocalVariable** opt_param = new LocalVariable*[num_opt_named_params];
237 int* opt_param_position = new int[num_opt_named_params];
238 for (int pos = num_fixed_params; pos < num_params; pos++) {
239 LocalVariable* parameter = scope->VariableAt(pos);
240 const String& opt_param_name = parameter->name();
241 int i = pos - num_fixed_params;
242 while (--i >= 0) {
243 LocalVariable* param_i = opt_param[i];
244 const intptr_t result = opt_param_name.CompareTo(param_i->name());
245 ASSERT(result != 0);
246 if (result > 0) break;
247 opt_param[i + 1] = opt_param[i];
248 opt_param_position[i + 1] = opt_param_position[i];
249 }
250 opt_param[i + 1] = parameter;
251 opt_param_position[i + 1] = pos;
252 }
253 // Generate code handling each optional parameter in alphabetical order.
254 __ lw(T1, FieldAddress(S4, ArgumentsDescriptor::count_offset()));
255 __ lw(T2, FieldAddress(S4, ArgumentsDescriptor::positional_count_offset()));
256 __ SmiUntag(T2);
257 // Let T1 point to the first passed argument, i.e. to
258 // fp[kLastParamSlotIndex + num_args - 1 - 0]; num_args (T1) is Smi.
259 __ sll(T3, T1, 1);
260 __ addu(T1, FP, T3);
261 __ addiu(T1, T1, Immediate((kLastParamSlotIndex - 1) * kWordSize));
262 // Let T0 point to the entry of the first named argument.
263 __ addiu(T0, S4, Immediate(
264 ArgumentsDescriptor::first_named_entry_offset() - kHeapObjectTag));
265 for (int i = 0; i < num_opt_named_params; i++) {
266 Label load_default_value, assign_optional_parameter;
267 const int param_pos = opt_param_position[i];
268 // Check if this named parameter was passed in.
269 // Load T3 with the name of the argument.
270 __ lw(T3, Address(T0, ArgumentsDescriptor::name_offset()));
271 ASSERT(opt_param[i]->name().IsSymbol());
272 __ LoadObject(T4, opt_param[i]->name());
273 __ bne(T3, T4, &load_default_value);
274
275 // Load T3 with passed-in argument at provided arg_pos, i.e. at
276 // fp[kLastParamSlotIndex + num_args - 1 - arg_pos].
277 __ lw(T3, Address(T0, ArgumentsDescriptor::position_offset()));
278 // T3 is arg_pos as Smi.
279 // Point to next named entry.
280 __ addiu(T0, T0, Immediate(ArgumentsDescriptor::named_entry_size()));
281 __ subu(T3, ZR, T3);
282 __ sll(T3, T3, 1);
283 __ addu(T3, T1, T3);
284 __ b(&assign_optional_parameter);
285 __ delay_slot()->lw(T3, Address(T3));
286
287 __ Bind(&load_default_value);
288 // Load T3 with default argument.
289 const Object& value = Object::ZoneHandle(
290 parsed_function().default_parameter_values().At(
291 param_pos - num_fixed_params));
292 __ LoadObject(T3, value);
293 __ Bind(&assign_optional_parameter);
294 // Assign T3 to fp[kFirstLocalSlotIndex - param_pos].
295 // We do not use the final allocation index of the variable here, i.e.
296 // scope->VariableAt(i)->index(), because captured variables still need
297 // to be copied to the context that is not yet allocated.
298 const intptr_t computed_param_pos = kFirstLocalSlotIndex - param_pos;
299 __ sw(T3, Address(FP, computed_param_pos * kWordSize));
300 }
301 delete[] opt_param;
302 delete[] opt_param_position;
303 // Check that T0 now points to the null terminator in the array descriptor.
304 __ lw(T3, Address(T0));
305 __ LoadImmediate(T4, reinterpret_cast<int32_t>(Object::null()));
306 __ beq(T3, T4, &all_arguments_processed);
307 } else {
308 ASSERT(num_opt_pos_params > 0);
309 __ lw(T2,
310 FieldAddress(S4, ArgumentsDescriptor::positional_count_offset()));
311 __ SmiUntag(T2);
312 for (int i = 0; i < num_opt_pos_params; i++) {
313 Label next_parameter;
314 // Handle this optional positional parameter only if k or fewer positional
315 // arguments have been passed, where k is param_pos, the position of this
316 // optional parameter in the formal parameter list.
317 const int param_pos = num_fixed_params + i;
318 __ addiu(T3, T2, Immediate(-param_pos));
319 __ bgtz(T3, &next_parameter);
320 // Load T3 with default argument.
321 const Object& value = Object::ZoneHandle(
322 parsed_function().default_parameter_values().At(i));
323 __ LoadObject(T3, value);
324 // Assign T3 to fp[kFirstLocalSlotIndex - param_pos].
325 // We do not use the final allocation index of the variable here, i.e.
326 // scope->VariableAt(i)->index(), because captured variables still need
327 // to be copied to the context that is not yet allocated.
328 const intptr_t computed_param_pos = kFirstLocalSlotIndex - param_pos;
329 __ sw(T3, Address(FP, computed_param_pos * kWordSize));
330 __ Bind(&next_parameter);
331 }
332 __ lw(T1, FieldAddress(S4, ArgumentsDescriptor::count_offset()));
333 __ SmiUntag(T1);
334 // Check that T2 equals T1, i.e. no named arguments passed.
335 __ beq(T2, T2, &all_arguments_processed);
336 }
337
338 __ Bind(&wrong_num_arguments);
339 if (StackSize() != 0) {
340 // We need to unwind the space we reserved for locals and copied parameters.
341 // The NoSuchMethodFunction stub does not expect to see that area on the
342 // stack.
343 __ addiu(SP, SP, Immediate(StackSize() * kWordSize));
344 }
345 // The call below has an empty stackmap because we have just
346 // dropped the spill slots.
347 BitmapBuilder* empty_stack_bitmap = new BitmapBuilder();
348
349 // Invoke noSuchMethod function passing the original name of the function.
350 // If the function is a closure function, use "call" as the original name.
351 const String& name = String::Handle(
352 function.IsClosureFunction() ? Symbols::Call().raw() : function.name());
353 const int kNumArgsChecked = 1;
354 const ICData& ic_data = ICData::ZoneHandle(
355 ICData::New(function, name, Isolate::kNoDeoptId, kNumArgsChecked));
356 __ LoadObject(S5, ic_data);
357 // FP - 4 : saved PP, object pool pointer of caller.
358 // FP + 0 : previous frame pointer.
359 // FP + 4 : return address.
360 // FP + 8 : PC marker, for easy identification of RawInstruction obj.
361 // FP + 12: last argument (arg n-1).
362 // SP + 0 : saved PP.
363 // SP + 16 + 4*(n-1) : first argument (arg 0).
364 // S5 : ic-data.
365 // S4 : arguments descriptor array.
366 __ BranchLink(&StubCode::CallNoSuchMethodFunctionLabel());
367 if (is_optimizing()) {
368 stackmap_table_builder_->AddEntry(assembler()->CodeSize(),
369 empty_stack_bitmap,
370 0); // No registers.
371 }
372 // The noSuchMethod call may return.
373 __ LeaveDartFrame();
374 __ Ret();
375
376 __ Bind(&all_arguments_processed);
377 // Nullify originally passed arguments only after they have been copied and
378 // checked, otherwise noSuchMethod would not see their original values.
379 // This step can be skipped in case we decide that formal parameters are
380 // implicitly final, since garbage collecting the unmodified value is not
381 // an issue anymore.
382
383 // S4 : arguments descriptor array.
384 __ lw(T2, FieldAddress(S4, ArgumentsDescriptor::count_offset()));
385 __ SmiUntag(T2);
386
387 __ LoadImmediate(TMP, reinterpret_cast<intptr_t>(Object::null()));
388 Label null_args_loop, null_args_loop_condition;
389 __ b(&null_args_loop_condition);
390 __ delay_slot()->addiu(T1, FP, Immediate(kLastParamSlotIndex * kWordSize));
391 __ Bind(&null_args_loop);
392 __ addu(T3, T1, T2);
393 __ sw(TMP, Address(T3));
394 __ Bind(&null_args_loop_condition);
395 __ addiu(T2, T2, Immediate(-4));
regis 2013/04/03 21:44:29 ditto
396 __ bgez(T2, &null_args_loop);
171 } 397 }
172 398
173 399
174 void FlowGraphCompiler::GenerateInlinedGetter(intptr_t offset) { 400 void FlowGraphCompiler::GenerateInlinedGetter(intptr_t offset) {
175 UNIMPLEMENTED(); 401 UNIMPLEMENTED();
176 } 402 }
177 403
178 404
179 void FlowGraphCompiler::GenerateInlinedSetter(intptr_t offset) { 405 void FlowGraphCompiler::GenerateInlinedSetter(intptr_t offset) {
180 UNIMPLEMENTED(); 406 UNIMPLEMENTED();
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 } 679 }
454 680
455 681
456 void FlowGraphCompiler::EmitInstanceCall(ExternalLabel* target_label, 682 void FlowGraphCompiler::EmitInstanceCall(ExternalLabel* target_label,
457 const ICData& ic_data, 683 const ICData& ic_data,
458 const Array& arguments_descriptor, 684 const Array& arguments_descriptor,
459 intptr_t argument_count, 685 intptr_t argument_count,
460 intptr_t deopt_id, 686 intptr_t deopt_id,
461 intptr_t token_pos, 687 intptr_t token_pos,
462 LocationSummary* locs) { 688 LocationSummary* locs) {
463 UNIMPLEMENTED(); 689 __ LoadObject(S4, arguments_descriptor);
690 __ LoadObject(S5, ic_data);
691 GenerateDartCall(deopt_id,
692 token_pos,
693 target_label,
694 PcDescriptors::kIcCall,
695 locs);
696 __ Drop(argument_count);
464 } 697 }
465 698
466 699
467 void FlowGraphCompiler::EmitMegamorphicInstanceCall( 700 void FlowGraphCompiler::EmitMegamorphicInstanceCall(
468 const ICData& ic_data, 701 const ICData& ic_data,
469 const Array& arguments_descriptor, 702 const Array& arguments_descriptor,
470 intptr_t argument_count, 703 intptr_t argument_count,
471 intptr_t deopt_id, 704 intptr_t deopt_id,
472 intptr_t token_pos, 705 intptr_t token_pos,
473 LocationSummary* locs) { 706 LocationSummary* locs) {
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 901
669 902
670 void ParallelMoveResolver::Exchange(const Address& mem1, const Address& mem2) { 903 void ParallelMoveResolver::Exchange(const Address& mem1, const Address& mem2) {
671 UNIMPLEMENTED(); 904 UNIMPLEMENTED();
672 } 905 }
673 906
674 907
675 } // namespace dart 908 } // namespace dart
676 909
677 #endif // defined TARGET_ARCH_MIPS 910 #endif // defined TARGET_ARCH_MIPS
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698