Commit d74ed4ca authored by plind44@gmail.com's avatar plind44@gmail.com

MIPS: replace RegExpCEntryStub with DirectCEntryStub.

Port r16618 (0eebc593)

Original commit message:
RegExpCEntryStub is therefore removed.

BUG=none
TEST=none
R=plind44@gmail.com

Review URL: https://codereview.chromium.org/24321002

Patch from Balazs Kilvady <kilvadyb@homejinni.com>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16927 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 40ad4cc7
......@@ -6126,9 +6126,16 @@ void ICCompareStub::GenerateMiss(MacroAssembler* masm) {
void DirectCEntryStub::Generate(MacroAssembler* masm) {
// No need to pop or drop anything, LeaveExitFrame will restore the old
// stack, thus dropping the allocated space for the return value.
// The saved ra is after the reserved stack space for the 4 args.
// Make place for arguments to fit C calling convention. Most of the callers
// of DirectCEntryStub::GenerateCall are using EnterExitFrame/LeaveExitFrame
// so they handle stack restoring and we don't have to do that here.
// Any caller of DirectCEntryStub::GenerateCall must take care of dropping
// kCArgsSlotsSize stack space after the call.
__ Subu(sp, sp, Operand(kCArgsSlotsSize));
// Place the return address on the stack, making the call
// GC safe. The RegExp backend also relies on this.
__ sw(ra, MemOperand(sp, kCArgsSlotsSize));
__ Call(t9); // Call the C++ function.
__ lw(t9, MemOperand(sp, kCArgsSlotsSize));
if (FLAG_debug_code && FLAG_enable_slow_asserts) {
......@@ -6145,33 +6152,11 @@ void DirectCEntryStub::Generate(MacroAssembler* masm) {
void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
Register target) {
__ Move(t9, target);
__ AssertStackIsAligned();
// Allocate space for arg slots.
__ Subu(sp, sp, kCArgsSlotsSize);
// Block the trampoline pool through the whole function to make sure the
// number of generated instructions is constant.
Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm);
// We need to get the current 'pc' value, which is not available on MIPS.
Label find_ra;
masm->bal(&find_ra); // ra = pc + 8.
masm->nop(); // Branch delay slot nop.
masm->bind(&find_ra);
const int kNumInstructionsToJump = 6;
masm->addiu(ra, ra, kNumInstructionsToJump * kPointerSize);
// Push return address (accessible to GC through exit frame pc).
// This spot for ra was reserved in EnterExitFrame.
masm->sw(ra, MemOperand(sp, kCArgsSlotsSize));
intptr_t loc =
reinterpret_cast<intptr_t>(GetCode(masm->isolate()).location());
masm->li(ra, Operand(loc, RelocInfo::CODE_TARGET), CONSTANT_SIZE);
// Call the function.
masm->Jump(t9);
// Make sure the stored 'ra' points to this position.
ASSERT_EQ(kNumInstructionsToJump, masm->InstructionsGeneratedSince(&find_ra));
__ Move(t9, target);
__ li(ra, Operand(loc, RelocInfo::CODE_TARGET), CONSTANT_SIZE);
__ Call(ra);
}
......
......@@ -455,22 +455,6 @@ class RecordWriteStub: public PlatformCodeStub {
};
// Enter C code from generated RegExp code in a way that allows
// the C code to fix the return address in case of a GC.
// Currently only needed on ARM and MIPS.
class RegExpCEntryStub: public PlatformCodeStub {
public:
RegExpCEntryStub() {}
virtual ~RegExpCEntryStub() {}
void Generate(MacroAssembler* masm);
private:
Major MajorKey() { return RegExpCEntry; }
int MinorKey() { return 0; }
bool NeedsImmovableCode() { return true; }
};
// Trampoline stub to call into native code. To call safely into native code
// in the presence of compacting GC (which can move code objects) we need to
// keep the code which called into native pinned in the memory. Currently the
......
......@@ -1063,15 +1063,56 @@ bool RegExpMacroAssemblerMIPS::CanReadUnaligned() {
// Private methods:
void RegExpMacroAssemblerMIPS::CallCheckStackGuardState(Register scratch) {
static const int num_arguments = 3;
__ PrepareCallCFunction(num_arguments, scratch);
int stack_alignment = OS::ActivationFrameAlignment();
// Align the stack pointer and save the original sp value on the stack.
__ mov(scratch, sp);
__ Subu(sp, sp, Operand(kPointerSize));
ASSERT(IsPowerOf2(stack_alignment));
__ And(sp, sp, Operand(-stack_alignment));
__ sw(scratch, MemOperand(sp));
__ mov(a2, frame_pointer());
// Code* of self.
__ li(a1, Operand(masm_->CodeObject()), CONSTANT_SIZE);
// a0 becomes return address pointer.
// We need to make room for the return address on the stack.
ASSERT(IsAligned(stack_alignment, kPointerSize));
__ Subu(sp, sp, Operand(stack_alignment));
// Stack pointer now points to cell where return address is to be written.
// Arguments are in registers, meaning we teat the return address as
// argument 5. Since DirectCEntryStub will handleallocating space for the C
// argument slots, we don't need to care about that here. This is how the
// stack will look (sp meaning the value of sp at this moment):
// [sp + 3] - empty slot if needed for alignment.
// [sp + 2] - saved sp.
// [sp + 1] - second word reserved for return value.
// [sp + 0] - first word reserved for return value.
// a0 will point to the return address, placed by DirectCEntry.
__ mov(a0, sp);
ExternalReference stack_guard_check =
ExternalReference::re_check_stack_guard_state(masm_->isolate());
CallCFunctionUsingStub(stack_guard_check, num_arguments);
__ li(t9, Operand(stack_guard_check));
DirectCEntryStub stub;
stub.GenerateCall(masm_, t9);
// DirectCEntryStub allocated space for the C argument slots so we have to
// drop them with the return address from the stack with loading saved sp.
// At this point stack must look:
// [sp + 7] - empty slot if needed for alignment.
// [sp + 6] - saved sp.
// [sp + 5] - second word reserved for return value.
// [sp + 4] - first word reserved for return value.
// [sp + 3] - C argument slot.
// [sp + 2] - C argument slot.
// [sp + 1] - C argument slot.
// [sp + 0] - C argument slot.
__ lw(sp, MemOperand(sp, stack_alignment + kCArgsSlotsSize));
__ li(code_pointer(), Operand(masm_->CodeObject()));
}
......@@ -1276,21 +1317,6 @@ void RegExpMacroAssemblerMIPS::CheckStackLimit() {
}
void RegExpMacroAssemblerMIPS::CallCFunctionUsingStub(
ExternalReference function,
int num_arguments) {
// Must pass all arguments in registers. The stub pushes on the stack.
ASSERT(num_arguments <= 4);
__ li(code_pointer(), Operand(function));
RegExpCEntryStub stub;
__ CallStub(&stub);
if (OS::ActivationFrameAlignment() != 0) {
__ lw(sp, MemOperand(sp, 16));
}
__ li(code_pointer(), Operand(masm_->CodeObject()), CONSTANT_SIZE);
}
void RegExpMacroAssemblerMIPS::LoadCurrentCharacterUnchecked(int cp_offset,
int characters) {
Register offset = current_input_offset();
......@@ -1312,23 +1338,6 @@ void RegExpMacroAssemblerMIPS::LoadCurrentCharacterUnchecked(int cp_offset,
}
void RegExpCEntryStub::Generate(MacroAssembler* masm_) {
int stack_alignment = OS::ActivationFrameAlignment();
if (stack_alignment < kPointerSize) stack_alignment = kPointerSize;
// Stack is already aligned for call, so decrement by alignment
// to make room for storing the return address.
__ Subu(sp, sp, Operand(stack_alignment + kCArgsSlotsSize));
const int return_address_offset = kCArgsSlotsSize;
__ Addu(a0, sp, return_address_offset);
__ sw(ra, MemOperand(a0, 0));
__ mov(t9, t1);
__ Call(t9);
__ lw(ra, MemOperand(sp, return_address_offset));
__ Addu(sp, sp, Operand(stack_alignment + kCArgsSlotsSize));
__ Jump(ra);
}
#undef __
#endif // V8_INTERPRETED_REGEXP
......
......@@ -217,14 +217,6 @@ class RegExpMacroAssemblerMIPS: public NativeRegExpMacroAssembler {
// and increments it by a word size.
inline void Pop(Register target);
// Calls a C function and cleans up the frame alignment done by
// by FrameAlign. The called function *is* allowed to trigger a garbage
// collection, but may not take more than four arguments (no arguments
// passed on the stack), and the first argument will be a pointer to the
// return address.
inline void CallCFunctionUsingStub(ExternalReference function,
int num_arguments);
Isolate* isolate() const { return masm_->isolate(); }
MacroAssembler* masm_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment