| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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_IA32. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. |
| 6 #if defined(TARGET_ARCH_IA32) | 6 #if defined(TARGET_ARCH_IA32) |
| 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 24 matching lines...) Expand all Loading... |
| 35 if (registers_[i] != kNoRegister) { | 35 if (registers_[i] != kNoRegister) { |
| 36 __ pushl(registers_[i]); | 36 __ pushl(registers_[i]); |
| 37 } | 37 } |
| 38 } | 38 } |
| 39 } else { | 39 } else { |
| 40 // We have a deoptimization environment, we have to tear down the | 40 // We have a deoptimization environment, we have to tear down the |
| 41 // optimized frame and recreate a non-optimized one. | 41 // optimized frame and recreate a non-optimized one. |
| 42 const intptr_t fixed_parameter_count = | 42 const intptr_t fixed_parameter_count = |
| 43 deoptimization_env_->fixed_parameter_count(); | 43 deoptimization_env_->fixed_parameter_count(); |
| 44 | 44 |
| 45 // 1. Set the stack pointer to the top of the non-optimized frame. | |
| 46 const GrowableArray<Value*>& values = deoptimization_env_->values(); | 45 const GrowableArray<Value*>& values = deoptimization_env_->values(); |
| 47 const intptr_t local_slot_count = values.length() - fixed_parameter_count; | |
| 48 const intptr_t top_offset = | |
| 49 ParsedFunction::kFirstLocalSlotIndex - (local_slot_count - 1); | |
| 50 __ leal(ESP, Address(EBP, top_offset * kWordSize)); | |
| 51 | 46 |
| 52 // 2. Build and emit a parallel move representing the frame translation. | 47 // 1. Build a parallel move representing the frame translation. |
| 53 ParallelMoveInstr* move = new ParallelMoveInstr(); | 48 ParallelMoveInstr* move = new ParallelMoveInstr(); |
| 54 for (intptr_t i = 0; i < values.length(); i++) { | 49 for (intptr_t i = 0; i < values.length(); i++) { |
| 55 Location destination = Location::StackSlot(i - fixed_parameter_count); | 50 Location destination = Location::StackSlot(i - fixed_parameter_count); |
| 56 Location source = deoptimization_env_->LocationAt(i); | 51 Location source = deoptimization_env_->LocationAt(i); |
| 57 if (source.IsInvalid()) { | 52 if (source.IsInvalid()) { |
| 58 ASSERT(values[i]->IsConstant()); | 53 ASSERT(values[i]->IsConstant()); |
| 59 source = Location::Constant(values[i]->AsConstant()->value()); | 54 source = Location::Constant(values[i]->AsConstant()->value()); |
| 60 } | 55 } |
| 61 move->AddMove(destination, source); | 56 move->AddMove(destination, source); |
| 62 } | 57 } |
| 58 |
| 59 |
| 60 const intptr_t local_slot_count = values.length() - fixed_parameter_count; |
| 61 const intptr_t top_offset = |
| 62 ParsedFunction::kFirstLocalSlotIndex - (local_slot_count - 1); |
| 63 |
| 64 // ParallelMoveResolver will use push and pop to allocate internally a |
| 65 // scratch register for memory to memory moves. This means we have to |
| 66 // ensure that these stack manipulations will not interfere with actual |
| 67 // moves. If number of local slots exceed number of spill slots we need |
| 68 // to expand reserved stack area before resolving parallel move. Otherwise |
| 69 // we need to shrink stack area after resolving parallel move. This |
| 70 // guarantees that all moves happen below stack pointer and will not |
| 71 // interfere with additional push/pops. |
| 72 const intptr_t spill_slot_count = compiler->StackSize(); |
| 73 |
| 74 if (local_slot_count > spill_slot_count) { |
| 75 // Expand reserved stack area. |
| 76 __ leal(ESP, Address(EBP, top_offset * kWordSize)); |
| 77 } |
| 78 |
| 63 compiler->parallel_move_resolver()->EmitNativeCode(move); | 79 compiler->parallel_move_resolver()->EmitNativeCode(move); |
| 80 |
| 81 if (local_slot_count < spill_slot_count) { |
| 82 // Shrink reserved stack area. |
| 83 __ leal(ESP, Address(EBP, top_offset * kWordSize)); |
| 84 } |
| 64 } | 85 } |
| 65 | 86 |
| 66 if (compiler->IsLeaf()) { | 87 if (compiler->IsLeaf()) { |
| 67 Label L; | 88 Label L; |
| 68 __ call(&L); | 89 __ call(&L); |
| 69 const intptr_t offset = assem->CodeSize(); | 90 const intptr_t offset = assem->CodeSize(); |
| 70 __ Bind(&L); | 91 __ Bind(&L); |
| 71 __ popl(EAX); | 92 __ popl(EAX); |
| 72 __ subl(EAX, | 93 __ subl(EAX, |
| 73 Immediate(offset - AssemblerMacros::kOffsetOfSavedPCfromEntrypoint)); | 94 Immediate(offset - AssemblerMacros::kOffsetOfSavedPCfromEntrypoint)); |
| (...skipping 1171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1245 __ popl(ECX); | 1266 __ popl(ECX); |
| 1246 __ popl(EAX); | 1267 __ popl(EAX); |
| 1247 } | 1268 } |
| 1248 | 1269 |
| 1249 | 1270 |
| 1250 #undef __ | 1271 #undef __ |
| 1251 | 1272 |
| 1252 } // namespace dart | 1273 } // namespace dart |
| 1253 | 1274 |
| 1254 #endif // defined TARGET_ARCH_IA32 | 1275 #endif // defined TARGET_ARCH_IA32 |
| OLD | NEW |