OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 CodeGenState state(this); | 195 CodeGenState state(this); |
196 | 196 |
197 // Entry: | 197 // Entry: |
198 // Stack: receiver, arguments, return address. | 198 // Stack: receiver, arguments, return address. |
199 // ebp: caller's frame pointer | 199 // ebp: caller's frame pointer |
200 // esp: stack pointer | 200 // esp: stack pointer |
201 // edi: called JS function | 201 // edi: called JS function |
202 // esi: callee's context | 202 // esi: callee's context |
203 allocator_->Initialize(); | 203 allocator_->Initialize(); |
204 | 204 |
205 if (info->mode() == CompilationInfo::PRIMARY) { | 205 frame_->Enter(); |
206 frame_->Enter(); | |
207 | 206 |
208 // Allocate space for locals and initialize them. | 207 // Allocate space for locals and initialize them. |
209 frame_->AllocateStackSlots(); | 208 frame_->AllocateStackSlots(); |
210 | 209 |
211 // Allocate the local context if needed. | 210 // Allocate the local context if needed. |
212 int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; | 211 int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
213 if (heap_slots > 0) { | 212 if (heap_slots > 0) { |
214 Comment cmnt(masm_, "[ allocate local context"); | 213 Comment cmnt(masm_, "[ allocate local context"); |
215 // Allocate local context. | 214 // Allocate local context. |
216 // Get outer context and create a new context based on it. | 215 // Get outer context and create a new context based on it. |
217 frame_->PushFunction(); | 216 frame_->PushFunction(); |
218 Result context; | 217 Result context; |
219 if (heap_slots <= FastNewContextStub::kMaximumSlots) { | 218 if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
220 FastNewContextStub stub(heap_slots); | 219 FastNewContextStub stub(heap_slots); |
221 context = frame_->CallStub(&stub, 1); | 220 context = frame_->CallStub(&stub, 1); |
222 } else { | 221 } else { |
223 context = frame_->CallRuntime(Runtime::kNewContext, 1); | 222 context = frame_->CallRuntime(Runtime::kNewContext, 1); |
224 } | 223 } |
225 | 224 |
226 // Update context local. | 225 // Update context local. |
227 frame_->SaveContextRegister(); | 226 frame_->SaveContextRegister(); |
228 | 227 |
229 // Verify that the runtime call result and esi agree. | 228 // Verify that the runtime call result and esi agree. |
230 if (FLAG_debug_code) { | 229 if (FLAG_debug_code) { |
231 __ cmp(context.reg(), Operand(esi)); | 230 __ cmp(context.reg(), Operand(esi)); |
232 __ Assert(equal, "Runtime::NewContext should end up in esi"); | 231 __ Assert(equal, "Runtime::NewContext should end up in esi"); |
| 232 } |
| 233 } |
| 234 |
| 235 // TODO(1241774): Improve this code: |
| 236 // 1) only needed if we have a context |
| 237 // 2) no need to recompute context ptr every single time |
| 238 // 3) don't copy parameter operand code from SlotOperand! |
| 239 { |
| 240 Comment cmnt2(masm_, "[ copy context parameters into .context"); |
| 241 // Note that iteration order is relevant here! If we have the same |
| 242 // parameter twice (e.g., function (x, y, x)), and that parameter |
| 243 // needs to be copied into the context, it must be the last argument |
| 244 // passed to the parameter that needs to be copied. This is a rare |
| 245 // case so we don't check for it, instead we rely on the copying |
| 246 // order: such a parameter is copied repeatedly into the same |
| 247 // context location and thus the last value is what is seen inside |
| 248 // the function. |
| 249 for (int i = 0; i < scope()->num_parameters(); i++) { |
| 250 Variable* par = scope()->parameter(i); |
| 251 Slot* slot = par->slot(); |
| 252 if (slot != NULL && slot->type() == Slot::CONTEXT) { |
| 253 // The use of SlotOperand below is safe in unspilled code |
| 254 // because the slot is guaranteed to be a context slot. |
| 255 // |
| 256 // There are no parameters in the global scope. |
| 257 ASSERT(!scope()->is_global_scope()); |
| 258 frame_->PushParameterAt(i); |
| 259 Result value = frame_->Pop(); |
| 260 value.ToRegister(); |
| 261 |
| 262 // SlotOperand loads context.reg() with the context object |
| 263 // stored to, used below in RecordWrite. |
| 264 Result context = allocator_->Allocate(); |
| 265 ASSERT(context.is_valid()); |
| 266 __ mov(SlotOperand(slot, context.reg()), value.reg()); |
| 267 int offset = FixedArray::kHeaderSize + slot->index() * kPointerSize; |
| 268 Result scratch = allocator_->Allocate(); |
| 269 ASSERT(scratch.is_valid()); |
| 270 frame_->Spill(context.reg()); |
| 271 frame_->Spill(value.reg()); |
| 272 __ RecordWrite(context.reg(), offset, value.reg(), scratch.reg()); |
233 } | 273 } |
234 } | 274 } |
| 275 } |
235 | 276 |
236 // TODO(1241774): Improve this code: | 277 // Store the arguments object. This must happen after context |
237 // 1) only needed if we have a context | 278 // initialization because the arguments object may be stored in |
238 // 2) no need to recompute context ptr every single time | 279 // the context. |
239 // 3) don't copy parameter operand code from SlotOperand! | 280 if (ArgumentsMode() != NO_ARGUMENTS_ALLOCATION) { |
240 { | 281 StoreArgumentsObject(true); |
241 Comment cmnt2(masm_, "[ copy context parameters into .context"); | 282 } |
242 // Note that iteration order is relevant here! If we have the same | |
243 // parameter twice (e.g., function (x, y, x)), and that parameter | |
244 // needs to be copied into the context, it must be the last argument | |
245 // passed to the parameter that needs to be copied. This is a rare | |
246 // case so we don't check for it, instead we rely on the copying | |
247 // order: such a parameter is copied repeatedly into the same | |
248 // context location and thus the last value is what is seen inside | |
249 // the function. | |
250 for (int i = 0; i < scope()->num_parameters(); i++) { | |
251 Variable* par = scope()->parameter(i); | |
252 Slot* slot = par->slot(); | |
253 if (slot != NULL && slot->type() == Slot::CONTEXT) { | |
254 // The use of SlotOperand below is safe in unspilled code | |
255 // because the slot is guaranteed to be a context slot. | |
256 // | |
257 // There are no parameters in the global scope. | |
258 ASSERT(!scope()->is_global_scope()); | |
259 frame_->PushParameterAt(i); | |
260 Result value = frame_->Pop(); | |
261 value.ToRegister(); | |
262 | 283 |
263 // SlotOperand loads context.reg() with the context object | 284 // Initialize ThisFunction reference if present. |
264 // stored to, used below in RecordWrite. | 285 if (scope()->is_function_scope() && scope()->function() != NULL) { |
265 Result context = allocator_->Allocate(); | 286 frame_->Push(Factory::the_hole_value()); |
266 ASSERT(context.is_valid()); | 287 StoreToSlot(scope()->function()->slot(), NOT_CONST_INIT); |
267 __ mov(SlotOperand(slot, context.reg()), value.reg()); | 288 } |
268 int offset = FixedArray::kHeaderSize + slot->index() * kPointerSize; | |
269 Result scratch = allocator_->Allocate(); | |
270 ASSERT(scratch.is_valid()); | |
271 frame_->Spill(context.reg()); | |
272 frame_->Spill(value.reg()); | |
273 __ RecordWrite(context.reg(), offset, value.reg(), scratch.reg()); | |
274 } | |
275 } | |
276 } | |
277 | 289 |
278 // Store the arguments object. This must happen after context | |
279 // initialization because the arguments object may be stored in | |
280 // the context. | |
281 if (ArgumentsMode() != NO_ARGUMENTS_ALLOCATION) { | |
282 StoreArgumentsObject(true); | |
283 } | |
284 | |
285 // Initialize ThisFunction reference if present. | |
286 if (scope()->is_function_scope() && scope()->function() != NULL) { | |
287 frame_->Push(Factory::the_hole_value()); | |
288 StoreToSlot(scope()->function()->slot(), NOT_CONST_INIT); | |
289 } | |
290 } else { | |
291 // When used as the secondary compiler for splitting, ebp, esi, | |
292 // and edi have been pushed on the stack. Adjust the virtual | |
293 // frame to match this state. | |
294 frame_->Adjust(3); | |
295 allocator_->Unuse(edi); | |
296 | |
297 // Bind all the bailout labels to the beginning of the function. | |
298 List<CompilationInfo::Bailout*>* bailouts = info->bailouts(); | |
299 for (int i = 0; i < bailouts->length(); i++) { | |
300 __ bind(bailouts->at(i)->label()); | |
301 } | |
302 } | |
303 | 290 |
304 // Initialize the function return target after the locals are set | 291 // Initialize the function return target after the locals are set |
305 // up, because it needs the expected frame height from the frame. | 292 // up, because it needs the expected frame height from the frame. |
306 function_return_.set_direction(JumpTarget::BIDIRECTIONAL); | 293 function_return_.set_direction(JumpTarget::BIDIRECTIONAL); |
307 function_return_is_shadowed_ = false; | 294 function_return_is_shadowed_ = false; |
308 | 295 |
309 // Generate code to 'execute' declarations and initialize functions | 296 // Generate code to 'execute' declarations and initialize functions |
310 // (source elements). In case of an illegal redeclaration we need to | 297 // (source elements). In case of an illegal redeclaration we need to |
311 // handle that instead of processing the declarations. | 298 // handle that instead of processing the declarations. |
312 if (scope()->HasIllegalRedeclaration()) { | 299 if (scope()->HasIllegalRedeclaration()) { |
(...skipping 14088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14401 masm.GetCode(&desc); | 14388 masm.GetCode(&desc); |
14402 // Call the function from C++. | 14389 // Call the function from C++. |
14403 return FUNCTION_CAST<MemCopyFunction>(buffer); | 14390 return FUNCTION_CAST<MemCopyFunction>(buffer); |
14404 } | 14391 } |
14405 | 14392 |
14406 #undef __ | 14393 #undef __ |
14407 | 14394 |
14408 } } // namespace v8::internal | 14395 } } // namespace v8::internal |
14409 | 14396 |
14410 #endif // V8_TARGET_ARCH_IA32 | 14397 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |