Index: src/mips/virtual-frame-mips.h |
diff --git a/src/mips/virtual-frame-mips.h b/src/mips/virtual-frame-mips.h |
index b32e2aeedc1624b0e1c9ff8c17ddf6bbad2367c1..be8b74e84a2f9ec5af70b27c47ca951b9ed16257 100644 |
--- a/src/mips/virtual-frame-mips.h |
+++ b/src/mips/virtual-frame-mips.h |
@@ -30,11 +30,13 @@ |
#define V8_MIPS_VIRTUAL_FRAME_MIPS_H_ |
#include "register-allocator.h" |
-#include "scopes.h" |
namespace v8 { |
namespace internal { |
+// This dummy class is only used to create invalid virtual frames. |
+extern class InvalidVirtualFrameInitializer {}* kInvalidVirtualFrameInitializer; |
+ |
// ------------------------------------------------------------------------- |
// Virtual frames |
@@ -47,14 +49,54 @@ namespace internal { |
class VirtualFrame : public ZoneObject { |
public: |
+ class RegisterAllocationScope; |
// A utility class to introduce a scope where the virtual frame is |
// expected to remain spilled. The constructor spills the code |
- // generator's current frame, but no attempt is made to require it |
- // to stay spilled. It is intended as documentation while the code |
- // generator is being transformed. |
+ // generator's current frame, and keeps it spilled. |
class SpilledScope BASE_EMBEDDED { |
public: |
+ explicit SpilledScope(VirtualFrame* frame) |
+ : old_is_spilled_( |
+ Isolate::Current()->is_virtual_frame_in_spilled_scope()) { |
+ if (frame != NULL) { |
+ if (!old_is_spilled_) { |
+ frame->SpillAll(); |
+ } else { |
+ frame->AssertIsSpilled(); |
+ } |
+ } |
+ Isolate::Current()->set_is_virtual_frame_in_spilled_scope(true); |
+ } |
+ ~SpilledScope() { |
+ Isolate::Current()->set_is_virtual_frame_in_spilled_scope( |
+ old_is_spilled_); |
+ } |
+ static bool is_spilled() { |
+ return Isolate::Current()->is_virtual_frame_in_spilled_scope(); |
+ } |
+ |
+ private: |
+ int old_is_spilled_; |
+ |
SpilledScope() {} |
+ |
+ friend class RegisterAllocationScope; |
+ }; |
+ |
+ class RegisterAllocationScope BASE_EMBEDDED { |
+ public: |
+ // A utility class to introduce a scope where the virtual frame |
+ // is not spilled, ie. where register allocation occurs. Eventually |
+ // when RegisterAllocationScope is ubiquitous it can be removed |
+ // along with the (by then unused) SpilledScope class. |
+ inline explicit RegisterAllocationScope(CodeGenerator* cgen); |
+ inline ~RegisterAllocationScope(); |
+ |
+ private: |
+ CodeGenerator* cgen_; |
+ bool old_is_spilled_; |
+ |
+ RegisterAllocationScope() {} |
}; |
// An illegal index into the virtual frame. |
@@ -63,45 +105,49 @@ class VirtualFrame : public ZoneObject { |
// Construct an initial virtual frame on entry to a JS function. |
inline VirtualFrame(); |
+ // Construct an invalid virtual frame, used by JumpTargets. |
+ inline VirtualFrame(InvalidVirtualFrameInitializer* dummy); |
+ |
// Construct a virtual frame as a clone of an existing one. |
explicit inline VirtualFrame(VirtualFrame* original); |
- CodeGenerator* cgen() { return CodeGeneratorScope::Current(); } |
- MacroAssembler* masm() { return cgen()->masm(); } |
- |
- // Create a duplicate of an existing valid frame element. |
- FrameElement CopyElementAt(int index, |
- NumberInfo info = NumberInfo::Unknown()); |
+ inline CodeGenerator* cgen() const; |
+ inline MacroAssembler* masm(); |
// The number of elements on the virtual frame. |
- int element_count() { return elements_.length(); } |
+ int element_count() const { return element_count_; } |
// The height of the virtual expression stack. |
- int height() { |
- return element_count() - expression_base_index(); |
- } |
- |
- int register_location(int num) { |
- ASSERT(num >= 0 && num < RegisterAllocator::kNumRegisters); |
- return register_locations_[num]; |
- } |
- |
- int register_location(Register reg) { |
- return register_locations_[RegisterAllocator::ToNumber(reg)]; |
- } |
- |
- void set_register_location(Register reg, int index) { |
- register_locations_[RegisterAllocator::ToNumber(reg)] = index; |
- } |
+ inline int height() const; |
bool is_used(int num) { |
- ASSERT(num >= 0 && num < RegisterAllocator::kNumRegisters); |
- return register_locations_[num] != kIllegalIndex; |
- } |
- |
- bool is_used(Register reg) { |
- return register_locations_[RegisterAllocator::ToNumber(reg)] |
- != kIllegalIndex; |
+ switch (num) { |
+ case 0: { // a0. |
+ return kA0InUse[top_of_stack_state_]; |
+ } |
+ case 1: { // a1. |
+ return kA1InUse[top_of_stack_state_]; |
+ } |
+ case 2: |
+ case 3: |
+ case 4: |
+ case 5: |
+ case 6: { // a2 to a3, t0 to t2. |
+ ASSERT(num - kFirstAllocatedRegister < kNumberOfAllocatedRegisters); |
+ ASSERT(num >= kFirstAllocatedRegister); |
+ if ((register_allocation_map_ & |
+ (1 << (num - kFirstAllocatedRegister))) == 0) { |
+ return false; |
+ } else { |
+ return true; |
+ } |
+ } |
+ default: { |
+ ASSERT(num < kFirstAllocatedRegister || |
+ num >= kFirstAllocatedRegister + kNumberOfAllocatedRegisters); |
+ return false; |
+ } |
+ } |
} |
// Add extra in-memory elements to the top of the frame to match an actual |
@@ -110,53 +156,60 @@ class VirtualFrame : public ZoneObject { |
void Adjust(int count); |
// Forget elements from the top of the frame to match an actual frame (eg, |
- // the frame after a runtime call). No code is emitted. |
- void Forget(int count) { |
- ASSERT(count >= 0); |
- ASSERT(stack_pointer_ == element_count() - 1); |
- stack_pointer_ -= count; |
- // On mips, all elements are in memory, so there is no extra bookkeeping |
- // (registers, copies, etc.) beyond dropping the elements. |
- elements_.Rewind(stack_pointer_ + 1); |
- } |
+ // the frame after a runtime call). No code is emitted except to bring the |
+ // frame to a spilled state. |
+ void Forget(int count); |
- // Forget count elements from the top of the frame and adjust the stack |
- // pointer downward. This is used, for example, before merging frames at |
- // break, continue, and return targets. |
- void ForgetElements(int count); |
// Spill all values from the frame to memory. |
void SpillAll(); |
+ void AssertIsSpilled() const { |
+ ASSERT(top_of_stack_state_ == NO_TOS_REGISTERS); |
+ ASSERT(register_allocation_map_ == 0); |
+ } |
+ |
+ void AssertIsNotSpilled() { |
+ ASSERT(!SpilledScope::is_spilled()); |
+ } |
+ |
// Spill all occurrences of a specific register from the frame. |
void Spill(Register reg) { |
- if (is_used(reg)) SpillElementAt(register_location(reg)); |
+ UNIMPLEMENTED(); |
} |
// Spill all occurrences of an arbitrary register if possible. Return the |
// register spilled or no_reg if it was not possible to free any register |
- // (ie, they all have frame-external references). |
+ // (ie, they all have frame-external references). Unimplemented. |
Register SpillAnyRegister(); |
- // Prepare this virtual frame for merging to an expected frame by |
- // performing some state changes that do not require generating |
- // code. It is guaranteed that no code will be generated. |
- void PrepareMergeTo(VirtualFrame* expected); |
- |
// Make this virtual frame have a state identical to an expected virtual |
// frame. As a side effect, code may be emitted to make this frame match |
// the expected one. |
- void MergeTo(VirtualFrame* expected); |
+ void MergeTo(const VirtualFrame* expected, |
+ Condition cond = al, |
+ Register r1 = no_reg, |
+ const Operand& r2 = Operand(no_reg)); |
+ |
+ void MergeTo(VirtualFrame* expected, |
+ Condition cond = al, |
+ Register r1 = no_reg, |
+ const Operand& r2 = Operand(no_reg)); |
+ |
+ // Checks whether this frame can be branched to by the other frame. |
+ bool IsCompatibleWith(const VirtualFrame* other) const { |
+ return (tos_known_smi_map_ & (~other->tos_known_smi_map_)) == 0; |
+ } |
+ |
+ inline void ForgetTypeInfo() { |
+ tos_known_smi_map_ = 0; |
+ } |
// Detach a frame from its code generator, perhaps temporarily. This |
// tells the register allocator that it is free to use frame-internal |
// registers. Used when the code generator's frame is switched from this |
// one to NULL by an unconditional jump. |
void DetachFromCodeGenerator() { |
- RegisterAllocator* cgen_allocator = cgen()->allocator(); |
- for (int i = 0; i < RegisterAllocator::kNumRegisters; i++) { |
- if (is_used(i)) cgen_allocator->Unuse(i); |
- } |
} |
// (Re)attach a frame to its code generator. This informs the register |
@@ -164,10 +217,6 @@ class VirtualFrame : public ZoneObject { |
// Used when a code generator's frame is switched from NULL to this one by |
// binding a label. |
void AttachToCodeGenerator() { |
- RegisterAllocator* cgen_allocator = cgen()->allocator(); |
- for (int i = 0; i < RegisterAllocator::kNumRegisters; i++) { |
- if (is_used(i)) cgen_allocator->Unuse(i); |
- } |
} |
// Emit code for the physical JS entry and exit frame sequences. After |
@@ -177,176 +226,142 @@ class VirtualFrame : public ZoneObject { |
void Enter(); |
void Exit(); |
- // Prepare for returning from the frame by spilling locals and |
- // dropping all non-locals elements in the virtual frame. This |
- // avoids generating unnecessary merge code when jumping to the |
- // shared return site. Emits code for spills. |
- void PrepareForReturn(); |
+ // Prepare for returning from the frame by elements in the virtual frame. |
+ // This avoids generating unnecessary merge code when jumping to the shared |
+ // return site. No spill code emitted. Value to return should be in v0. |
+ inline void PrepareForReturn(); |
+ |
+ // Number of local variables after when we use a loop for allocating. |
+ static const int kLocalVarBound = 5; |
// Allocate and initialize the frame-allocated locals. |
void AllocateStackSlots(); |
// The current top of the expression stack as an assembly operand. |
- MemOperand Top() { return MemOperand(sp, 0); } |
+ MemOperand Top() { |
+ AssertIsSpilled(); |
+ return MemOperand(sp, 0); |
+ } |
// An element of the expression stack as an assembly operand. |
MemOperand ElementAt(int index) { |
- return MemOperand(sp, index * kPointerSize); |
- } |
- |
- // Random-access store to a frame-top relative frame element. The result |
- // becomes owned by the frame and is invalidated. |
- void SetElementAt(int index, Result* value); |
- |
- // Set a frame element to a constant. The index is frame-top relative. |
- void SetElementAt(int index, Handle<Object> value) { |
- Result temp(value); |
- SetElementAt(index, &temp); |
+ int adjusted_index = index - kVirtualElements[top_of_stack_state_]; |
+ ASSERT(adjusted_index >= 0); |
+ return MemOperand(sp, adjusted_index * kPointerSize); |
} |
- void PushElementAt(int index) { |
- PushFrameSlotAt(element_count() - index - 1); |
+ bool KnownSmiAt(int index) { |
+ if (index >= kTOSKnownSmiMapSize) return false; |
+ return (tos_known_smi_map_ & (1 << index)) != 0; |
} |
- |
// A frame-allocated local as an assembly operand. |
- MemOperand LocalAt(int index) { |
- ASSERT(0 <= index); |
- ASSERT(index < local_count()); |
- return MemOperand(s8_fp, kLocal0Offset - index * kPointerSize); |
- } |
- |
- // Push a copy of the value of a local frame slot on top of the frame. |
- void PushLocalAt(int index) { |
- PushFrameSlotAt(local0_index() + index); |
- } |
- |
- // Push the value of a local frame slot on top of the frame and invalidate |
- // the local slot. The slot should be written to before trying to read |
- // from it again. |
- void TakeLocalAt(int index) { |
- TakeFrameSlotAt(local0_index() + index); |
- } |
- |
- // Store the top value on the virtual frame into a local frame slot. The |
- // value is left in place on top of the frame. |
- void StoreToLocalAt(int index) { |
- StoreToFrameSlotAt(local0_index() + index); |
- } |
+ inline MemOperand LocalAt(int index); |
// Push the address of the receiver slot on the frame. |
void PushReceiverSlotAddress(); |
// The function frame slot. |
- MemOperand Function() { return MemOperand(s8_fp, kFunctionOffset); } |
- |
- // Push the function on top of the frame. |
- void PushFunction() { PushFrameSlotAt(function_index()); } |
+ MemOperand Function() { return MemOperand(fp, kFunctionOffset); } |
// The context frame slot. |
- MemOperand Context() { return MemOperand(s8_fp, kContextOffset); } |
- |
- // Save the value of the cp register to the context frame slot. |
- void SaveContextRegister(); |
- |
- // Restore the cp register from the value of the context frame |
- // slot. |
- void RestoreContextRegister(); |
+ MemOperand Context() { return MemOperand(fp, kContextOffset); } |
// A parameter as an assembly operand. |
- MemOperand ParameterAt(int index) { |
- // Index -1 corresponds to the receiver. |
- ASSERT(-1 <= index); // -1 is the receiver. |
- ASSERT(index <= parameter_count()); |
- uint16_t a = 0; // Number of argument slots. |
- return MemOperand(s8_fp, (1 + parameter_count() + a - index) *kPointerSize); |
- } |
- |
- // Push a copy of the value of a parameter frame slot on top of the frame. |
- void PushParameterAt(int index) { |
- PushFrameSlotAt(param0_index() + index); |
- } |
- |
- // Push the value of a paramter frame slot on top of the frame and |
- // invalidate the parameter slot. The slot should be written to before |
- // trying to read from it again. |
- void TakeParameterAt(int index) { |
- TakeFrameSlotAt(param0_index() + index); |
- } |
- |
- // Store the top value on the virtual frame into a parameter frame slot. |
- // The value is left in place on top of the frame. |
- void StoreToParameterAt(int index) { |
- StoreToFrameSlotAt(param0_index() + index); |
- } |
+ inline MemOperand ParameterAt(int index); |
// The receiver frame slot. |
- MemOperand Receiver() { return ParameterAt(-1); } |
+ inline MemOperand Receiver(); |
// Push a try-catch or try-finally handler on top of the virtual frame. |
void PushTryHandler(HandlerType type); |
// Call stub given the number of arguments it expects on (and |
// removes from) the stack. |
- void CallStub(CodeStub* stub, int arg_count) { |
- PrepareForCall(arg_count, arg_count); |
- RawCallStub(stub); |
- } |
+ inline void CallStub(CodeStub* stub, int arg_count); |
- void CallStub(CodeStub* stub, Result* arg); |
- |
- void CallStub(CodeStub* stub, Result* arg0, Result* arg1); |
+ // Call JS function from top of the stack with arguments |
+ // taken from the stack. |
+ void CallJSFunction(int arg_count); |
// Call runtime given the number of arguments expected on (and |
// removed from) the stack. |
- void CallRuntime(Runtime::Function* f, int arg_count); |
+ void CallRuntime(const Runtime::Function* f, int arg_count); |
void CallRuntime(Runtime::FunctionId id, int arg_count); |
- // Call runtime with sp aligned to 8 bytes. |
- void CallAlignedRuntime(Runtime::Function* f, int arg_count); |
- void CallAlignedRuntime(Runtime::FunctionId id, int arg_count); |
+#ifdef ENABLE_DEBUGGER_SUPPORT |
+ void DebugBreak(); |
+#endif |
// Invoke builtin given the number of arguments it expects on (and |
// removes from) the stack. |
void InvokeBuiltin(Builtins::JavaScript id, |
InvokeJSFlags flag, |
- Result* arg_count_register, |
int arg_count); |
+ // Call load IC. Receiver is on the stack and is consumed. Result is returned |
+ // in v0. |
+ void CallLoadIC(Handle<String> name, RelocInfo::Mode mode); |
+ |
+ // Call store IC. If the load is contextual, value is found on top of the |
+ // frame. If not, value and receiver are on the frame. Both are consumed. |
+ // Result is returned in v0. |
+ void CallStoreIC(Handle<String> name, bool is_contextual); |
+ |
+ // Call keyed load IC. Key and receiver are on the stack. Both are consumed. |
+ // Result is returned in v0. |
+ void CallKeyedLoadIC(); |
+ |
+ // Call keyed store IC. Value, key and receiver are on the stack. All three |
+ // are consumed. Result is returned in v0 (and a0). |
+ void CallKeyedStoreIC(); |
+ |
// Call into an IC stub given the number of arguments it removes |
- // from the stack. Register arguments are passed as results and |
- // consumed by the call. |
- void CallCodeObject(Handle<Code> ic, |
- RelocInfo::Mode rmode, |
- int dropped_args); |
+ // from the stack. Register arguments to the IC stub are implicit, |
+ // and depend on the type of IC stub. |
void CallCodeObject(Handle<Code> ic, |
RelocInfo::Mode rmode, |
- Result* arg, |
int dropped_args); |
- void CallCodeObject(Handle<Code> ic, |
- RelocInfo::Mode rmode, |
- Result* arg0, |
- Result* arg1, |
- int dropped_args, |
- bool set_auto_args_slots = false); |
// Drop a number of elements from the top of the expression stack. May |
// emit code to affect the physical frame. Does not clobber any registers |
// excepting possibly the stack pointer. |
void Drop(int count); |
- // Similar to VirtualFrame::Drop but we don't modify the actual stack. |
- // This is because we need to manually restore sp to the correct position. |
- void DropFromVFrameOnly(int count); |
// Drop one element. |
void Drop() { Drop(1); } |
- void DropFromVFrameOnly() { DropFromVFrameOnly(1); } |
- // Duplicate the top element of the frame. |
- void Dup() { PushFrameSlotAt(element_count() - 1); } |
+ // Pop an element from the top of the expression stack. Discards |
+ // the result. |
+ void Pop(); |
+ |
+ // Pop an element from the top of the expression stack. The register |
+ // will be one normally used for the top of stack register allocation |
+ // so you can't hold on to it if you push on the stack. |
+ Register PopToRegister(Register but_not_to_this_one = no_reg); |
+ |
+ // Look at the top of the stack. The register returned is aliased and |
+ // must be copied to a scratch register before modification. |
+ Register Peek(); |
+ |
+ // Look at the value beneath the top of the stack. The register returned is |
+ // aliased and must be copied to a scratch register before modification. |
+ Register Peek2(); |
+ |
+ // Duplicate the top of stack. |
+ void Dup(); |
+ |
+ // Duplicate the two elements on top of stack. |
+ void Dup2(); |
- // Pop an element from the top of the expression stack. Returns a |
- // Result, which may be a constant or a register. |
- Result Pop(); |
+ // Flushes all registers, but it puts a copy of the top-of-stack in a0. |
+ void SpillAllButCopyTOSToA0(); |
+ |
+ // Flushes all registers, but it puts a copy of the top-of-stack in a1. |
+ void SpillAllButCopyTOSToA1(); |
+ |
+ // Flushes all registers, but it puts a copy of the top-of-stack in a1 |
+ // and the next value on the stack in a0. |
+ void SpillAllButCopyTOSToA1A0(); |
// Pop and save an element from the top of the expression stack and |
// emit a corresponding pop instruction. |
@@ -355,40 +370,41 @@ class VirtualFrame : public ZoneObject { |
void EmitMultiPop(RegList regs); |
void EmitMultiPopReversed(RegList regs); |
+ |
+ // Takes the top two elements and puts them in a0 (top element) and a1 |
+ // (second element). |
+ void PopToA1A0(); |
+ |
+ // Takes the top element and puts it in a1. |
+ void PopToA1(); |
+ |
+ // Takes the top element and puts it in a0. |
+ void PopToA0(); |
+ |
// Push an element on top of the expression stack and emit a |
// corresponding push instruction. |
- void EmitPush(Register reg); |
- // Same but for multiple registers. |
- void EmitMultiPush(RegList regs); |
- void EmitMultiPushReversed(RegList regs); |
+ void EmitPush(Register reg, TypeInfo type_info = TypeInfo::Unknown()); |
+ void EmitPush(Operand operand, TypeInfo type_info = TypeInfo::Unknown()); |
+ void EmitPush(MemOperand operand, TypeInfo type_info = TypeInfo::Unknown()); |
+ void EmitPushRoot(Heap::RootListIndex index); |
- // Push an element on the virtual frame. |
- inline void Push(Register reg, NumberInfo info = NumberInfo::Unknown()); |
- inline void Push(Handle<Object> value); |
- inline void Push(Smi* value); |
+ // Overwrite the nth thing on the stack. If the nth position is in a |
+ // register then this turns into a Move, otherwise an sw. Afterwards |
+ // you can still use the register even if it is a register that can be |
+ // used for TOS (a0 or a1). |
+ void SetElementAt(Register reg, int this_far_down); |
- // Pushing a result invalidates it (its contents become owned by the frame). |
- void Push(Result* result) { |
- if (result->is_register()) { |
- Push(result->reg()); |
- } else { |
- ASSERT(result->is_constant()); |
- Push(result->handle()); |
- } |
- result->Unuse(); |
- } |
- |
- // Nip removes zero or more elements from immediately below the top |
- // of the frame, leaving the previous top-of-frame value on top of |
- // the frame. Nip(k) is equivalent to x = Pop(), Drop(k), Push(x). |
- inline void Nip(int num_dropped); |
+ // Get a register which is free and which must be immediately used to |
+ // push on the top of the stack. |
+ Register GetTOSRegister(); |
- // This pushes 4 arguments slots on the stack and saves asked 'a' registers |
- // 'a' registers are arguments register a0 to a3. |
- void EmitArgumentSlots(RegList reglist); |
+ // Same but for multiple registers. |
+ void EmitMultiPush(RegList regs); |
+ void EmitMultiPushReversed(RegList regs); |
- inline void SetTypeForLocalAt(int index, NumberInfo info); |
- inline void SetTypeForParamAt(int index, NumberInfo info); |
+ static Register scratch0() { return t4; } |
+ static Register scratch1() { return t5; } |
+ static Register scratch2() { return t6; } |
private: |
static const int kLocal0Offset = JavaScriptFrameConstants::kLocal0Offset; |
@@ -398,24 +414,51 @@ class VirtualFrame : public ZoneObject { |
static const int kHandlerSize = StackHandlerConstants::kSize / kPointerSize; |
static const int kPreallocatedElements = 5 + 8; // 8 expression stack slots. |
- ZoneList<FrameElement> elements_; |
+ // 5 states for the top of stack, which can be in memory or in a0 and a1. |
+ enum TopOfStack { NO_TOS_REGISTERS, A0_TOS, A1_TOS, A1_A0_TOS, A0_A1_TOS, |
+ TOS_STATES}; |
+ static const int kMaxTOSRegisters = 2; |
+ |
+ static const bool kA0InUse[TOS_STATES]; |
+ static const bool kA1InUse[TOS_STATES]; |
+ static const int kVirtualElements[TOS_STATES]; |
+ static const TopOfStack kStateAfterPop[TOS_STATES]; |
+ static const TopOfStack kStateAfterPush[TOS_STATES]; |
+ static const Register kTopRegister[TOS_STATES]; |
+ static const Register kBottomRegister[TOS_STATES]; |
+ |
+ // We allocate up to 5 locals in registers. |
+ static const int kNumberOfAllocatedRegisters = 5; |
+ // r2 to r6 are allocated to locals. |
+ static const int kFirstAllocatedRegister = 2; |
+ |
+ static const Register kAllocatedRegisters[kNumberOfAllocatedRegisters]; |
+ |
+ static Register AllocatedRegister(int r) { |
+ ASSERT(r >= 0 && r < kNumberOfAllocatedRegisters); |
+ return kAllocatedRegisters[r]; |
+ } |
- // The index of the element that is at the processor's stack pointer |
- // (the sp register). |
- int stack_pointer_; |
+ // The number of elements on the stack frame. |
+ int element_count_; |
+ TopOfStack top_of_stack_state_:3; |
+ int register_allocation_map_:kNumberOfAllocatedRegisters; |
+ static const int kTOSKnownSmiMapSize = 4; |
+ unsigned tos_known_smi_map_:kTOSKnownSmiMapSize; |
- // The index of the register frame element using each register, or |
- // kIllegalIndex if a register is not on the frame. |
- int register_locations_[RegisterAllocator::kNumRegisters]; |
+ // The index of the element that is at the processor's stack pointer |
+ // (the sp register). For now since everything is in memory it is given |
+ // by the number of elements on the not-very-virtual stack frame. |
+ int stack_pointer() { return element_count_ - 1; } |
// The number of frame-allocated locals and parameters respectively. |
- int parameter_count() { return cgen()->scope()->num_parameters(); } |
- int local_count() { return cgen()->scope()->num_stack_slots(); } |
+ inline int parameter_count() const; |
+ inline int local_count() const; |
// The index of the element that is at the processor's frame pointer |
// (the fp register). The parameters, receiver, function, and context |
// are below the frame pointer. |
- int frame_pointer() { return parameter_count() + 3; } |
+ inline int frame_pointer() const; |
// The index of the first parameter. The receiver lies below the first |
// parameter. |
@@ -423,75 +466,22 @@ class VirtualFrame : public ZoneObject { |
// The index of the context slot in the frame. It is immediately |
// below the frame pointer. |
- int context_index() { return frame_pointer() - 1; } |
+ inline int context_index(); |
// The index of the function slot in the frame. It is below the frame |
// pointer and context slot. |
- int function_index() { return frame_pointer() - 2; } |
+ inline int function_index(); |
// The index of the first local. Between the frame pointer and the |
// locals lies the return address. |
- int local0_index() { return frame_pointer() + 2; } |
+ inline int local0_index() const; |
// The index of the base of the expression stack. |
- int expression_base_index() { return local0_index() + local_count(); } |
+ inline int expression_base_index() const; |
// Convert a frame index into a frame pointer relative offset into the |
// actual stack. |
- int fp_relative(int index) { |
- ASSERT(index < element_count()); |
- ASSERT(frame_pointer() < element_count()); // FP is on the frame. |
- return (frame_pointer() - index) * kPointerSize; |
- } |
- |
- // Record an occurrence of a register in the virtual frame. This has the |
- // effect of incrementing the register's external reference count and |
- // of updating the index of the register's location in the frame. |
- void Use(Register reg, int index) { |
- ASSERT(!is_used(reg)); |
- set_register_location(reg, index); |
- cgen()->allocator()->Use(reg); |
- } |
- |
- // Record that a register reference has been dropped from the frame. This |
- // decrements the register's external reference count and invalidates the |
- // index of the register's location in the frame. |
- void Unuse(Register reg) { |
- ASSERT(is_used(reg)); |
- set_register_location(reg, kIllegalIndex); |
- cgen()->allocator()->Unuse(reg); |
- } |
- |
- // Spill the element at a particular index---write it to memory if |
- // necessary, free any associated register, and forget its value if |
- // constant. |
- void SpillElementAt(int index); |
- |
- // Sync the element at a particular index. If it is a register or |
- // constant that disagrees with the value on the stack, write it to memory. |
- // Keep the element type as register or constant, and clear the dirty bit. |
- void SyncElementAt(int index); |
- |
- // Sync the range of elements in [begin, end] with memory. |
- void SyncRange(int begin, int end); |
- |
- // Sync a single unsynced element that lies beneath or at the stack pointer. |
- void SyncElementBelowStackPointer(int index); |
- |
- // Sync a single unsynced element that lies just above the stack pointer. |
- void SyncElementByPushing(int index); |
- |
- // Push a copy of a frame slot (typically a local or parameter) on top of |
- // the frame. |
- inline void PushFrameSlotAt(int index); |
- |
- // Push a the value of a frame slot (typically a local or parameter) on |
- // top of the frame and invalidate the slot. |
- void TakeFrameSlotAt(int index); |
- |
- // Store the value on top of the frame to a frame slot (typically a local |
- // or parameter). |
- void StoreToFrameSlotAt(int index); |
+ inline int fp_relative(int index); |
// Spill all elements in registers. Spill the top spilled_args elements |
// on the frame. Sync all other frame elements. |
@@ -499,45 +489,37 @@ class VirtualFrame : public ZoneObject { |
// the effect of an upcoming call that will drop them from the stack. |
void PrepareForCall(int spilled_args, int dropped_args); |
- // Move frame elements currently in registers or constants, that |
- // should be in memory in the expected frame, to memory. |
- void MergeMoveRegistersToMemory(VirtualFrame* expected); |
- |
- // Make the register-to-register moves necessary to |
- // merge this frame with the expected frame. |
- // Register to memory moves must already have been made, |
- // and memory to register moves must follow this call. |
- // This is because some new memory-to-register moves are |
- // created in order to break cycles of register moves. |
- // Used in the implementation of MergeTo(). |
- void MergeMoveRegistersToRegisters(VirtualFrame* expected); |
- |
- // Make the memory-to-register and constant-to-register moves |
- // needed to make this frame equal the expected frame. |
- // Called after all register-to-memory and register-to-register |
- // moves have been made. After this function returns, the frames |
- // should be equal. |
- void MergeMoveMemoryToRegisters(VirtualFrame* expected); |
- |
- // Invalidates a frame slot (puts an invalid frame element in it). |
- // Copies on the frame are correctly handled, and if this slot was |
- // the backing store of copies, the index of the new backing store |
- // is returned. Otherwise, returns kIllegalIndex. |
- // Register counts are correctly updated. |
- int InvalidateFrameSlotAt(int index); |
- |
- // Call a code stub that has already been prepared for calling (via |
- // PrepareForCall). |
- void RawCallStub(CodeStub* stub); |
- |
- // Calls a code object which has already been prepared for calling |
- // (via PrepareForCall). |
- void RawCallCodeObject(Handle<Code> code, RelocInfo::Mode rmode); |
- |
- inline bool Equals(VirtualFrame* other); |
- |
- // Classes that need raw access to the elements_ array. |
- friend class DeferredCode; |
+ // If all top-of-stack registers are in use then the lowest one is pushed |
+ // onto the physical stack and made free. |
+ void EnsureOneFreeTOSRegister(); |
+ |
+ // Emit instructions to get the top of stack state from where we are to where |
+ // we want to be. |
+ void MergeTOSTo(TopOfStack expected_state, |
+ Condition cond = al, |
+ Register r1 = no_reg, |
+ const Operand& r2 = Operand(no_reg)); |
+ |
+ inline bool Equals(const VirtualFrame* other); |
+ |
+ inline void LowerHeight(int count) { |
+ element_count_ -= count; |
+ if (count >= kTOSKnownSmiMapSize) { |
+ tos_known_smi_map_ = 0; |
+ } else { |
+ tos_known_smi_map_ >>= count; |
+ } |
+ } |
+ |
+ inline void RaiseHeight(int count, unsigned known_smi_map = 0) { |
+ ASSERT(known_smi_map < (1u << count)); |
+ element_count_ += count; |
+ if (count >= kTOSKnownSmiMapSize) { |
+ tos_known_smi_map_ = known_smi_map; |
+ } else { |
+ tos_known_smi_map_ = ((tos_known_smi_map_ << count) | known_smi_map); |
+ } |
+ } |
friend class JumpTarget; |
}; |