@@ -628,26 +628,26 @@ void RegExpMacroAssemblerARM::StoreRegExpStackPointerToMemory(
628628 __ str (src, MemOperand (scratch));
629629}
630630
631- void RegExpMacroAssemblerARM::PushRegExpBasePointer (Register scratch1,
632- Register scratch2) {
633- LoadRegExpStackPointerFromMemory (scratch1);
631+ void RegExpMacroAssemblerARM::PushRegExpBasePointer (Register stack_pointer,
632+ Register scratch) {
634633 ExternalReference ref =
635634 ExternalReference::address_of_regexp_stack_memory_top_address (isolate ());
636- __ mov (scratch2 , Operand (ref));
637- __ ldr (scratch2 , MemOperand (scratch2 ));
638- __ sub (scratch2, scratch1, scratch2 );
639- __ str (scratch2 , MemOperand (frame_pointer (), kRegExpStackBasePointer ));
635+ __ mov (scratch , Operand (ref));
636+ __ ldr (scratch , MemOperand (scratch ));
637+ __ sub (scratch, stack_pointer, scratch );
638+ __ str (scratch , MemOperand (frame_pointer (), kRegExpStackBasePointer ));
640639}
641640
642- void RegExpMacroAssemblerARM::PopRegExpBasePointer (Register scratch1 ,
643- Register scratch2 ) {
641+ void RegExpMacroAssemblerARM::PopRegExpBasePointer (Register stack_pointer_out ,
642+ Register scratch ) {
644643 ExternalReference ref =
645644 ExternalReference::address_of_regexp_stack_memory_top_address (isolate ());
646- __ ldr (scratch1, MemOperand (frame_pointer (), kRegExpStackBasePointer ));
647- __ mov (scratch2, Operand (ref));
648- __ ldr (scratch2, MemOperand (scratch2));
649- __ add (scratch1, scratch1, scratch2);
650- StoreRegExpStackPointerToMemory (scratch1, scratch2);
645+ __ ldr (stack_pointer_out,
646+ MemOperand (frame_pointer (), kRegExpStackBasePointer ));
647+ __ mov (scratch, Operand (ref));
648+ __ ldr (scratch, MemOperand (scratch));
649+ __ add (stack_pointer_out, stack_pointer_out, scratch);
650+ StoreRegExpStackPointerToMemory (stack_pointer_out, scratch);
651651}
652652
653653Handle<HeapObject> RegExpMacroAssemblerARM::GetCode (Handle<String> source) {
@@ -688,37 +688,43 @@ Handle<HeapObject> RegExpMacroAssemblerARM::GetCode(Handle<String> source) {
688688 kBacktrackCount - kSystemPointerSize );
689689 __ push (r0); // The regexp stack base ptr.
690690
691+ // Initialize backtrack stack pointer. It must not be clobbered from here on.
692+ // Note the backtrack_stackpointer is callee-saved.
693+ STATIC_ASSERT (backtrack_stackpointer () == r8);
694+ LoadRegExpStackPointerFromMemory (backtrack_stackpointer ());
695+
691696 // Store the regexp base pointer - we'll later restore it / write it to
692697 // memory when returning from this irregexp code object.
693- PushRegExpBasePointer (r0, r1);
694-
695- // Check if we have space on the stack for registers.
696- Label stack_limit_hit;
697- Label stack_ok;
698+ PushRegExpBasePointer (backtrack_stackpointer (), r1);
699+
700+ {
701+ // Check if we have space on the stack for registers.
702+ Label stack_limit_hit, stack_ok;
703+
704+ ExternalReference stack_limit =
705+ ExternalReference::address_of_jslimit (isolate ());
706+ __ mov (r0, Operand (stack_limit));
707+ __ ldr (r0, MemOperand (r0));
708+ __ sub (r0, sp, r0, SetCC);
709+ // Handle it if the stack pointer is already below the stack limit.
710+ __ b (ls, &stack_limit_hit);
711+ // Check if there is room for the variable number of registers above
712+ // the stack limit.
713+ __ cmp (r0, Operand (num_registers_ * kPointerSize ));
714+ __ b (hs, &stack_ok);
715+ // Exit with OutOfMemory exception. There is not enough space on the stack
716+ // for our working registers.
717+ __ mov (r0, Operand (EXCEPTION));
718+ __ jmp (&return_r0);
698719
699- ExternalReference stack_limit =
700- ExternalReference::address_of_jslimit (isolate ());
701- __ mov (r0, Operand (stack_limit));
702- __ ldr (r0, MemOperand (r0));
703- __ sub (r0, sp, r0, SetCC);
704- // Handle it if the stack pointer is already below the stack limit.
705- __ b (ls, &stack_limit_hit);
706- // Check if there is room for the variable number of registers above
707- // the stack limit.
708- __ cmp (r0, Operand (num_registers_ * kPointerSize ));
709- __ b (hs, &stack_ok);
710- // Exit with OutOfMemory exception. There is not enough space on the stack
711- // for our working registers.
712- __ mov (r0, Operand (EXCEPTION));
713- __ jmp (&return_r0);
714-
715- __ bind (&stack_limit_hit);
716- CallCheckStackGuardState ();
717- __ cmp (r0, Operand::Zero ());
718- // If returned value is non-zero, we exit with the returned value as result.
719- __ b (ne, &return_r0);
720+ __ bind (&stack_limit_hit);
721+ CallCheckStackGuardState ();
722+ __ cmp (r0, Operand::Zero ());
723+ // If returned value is non-zero, we exit with the returned value as result.
724+ __ b (ne, &return_r0);
720725
721- __ bind (&stack_ok);
726+ __ bind (&stack_ok);
727+ }
722728
723729 // Allocate space on stack for registers.
724730 __ AllocateStackSpace (num_registers_ * kPointerSize );
@@ -740,18 +746,21 @@ Handle<HeapObject> RegExpMacroAssemblerARM::GetCode(Handle<String> source) {
740746 // Initialize code pointer register
741747 __ mov (code_pointer (), Operand (masm_->CodeObject ()));
742748
743- Label load_char_start_regexp, start_regexp;
744- // Load newline if index is at start, previous character otherwise.
745- __ cmp (r1, Operand::Zero ());
746- __ b (ne, &load_char_start_regexp);
747- __ mov (current_character (), Operand (' \n ' ), LeaveCC, eq);
748- __ jmp (&start_regexp);
749-
750- // Global regexp restarts matching here.
751- __ bind (&load_char_start_regexp);
752- // Load previous char as initial value of current character register.
753- LoadCurrentCharacterUnchecked (-1 , 1 );
754- __ bind (&start_regexp);
749+ Label load_char_start_regexp;
750+ {
751+ Label start_regexp;
752+ // Load newline if index is at start, previous character otherwise.
753+ __ cmp (r1, Operand::Zero ());
754+ __ b (ne, &load_char_start_regexp);
755+ __ mov (current_character (), Operand (' \n ' ), LeaveCC, eq);
756+ __ jmp (&start_regexp);
757+
758+ // Global regexp restarts matching here.
759+ __ bind (&load_char_start_regexp);
760+ // Load previous char as initial value of current character register.
761+ LoadCurrentCharacterUnchecked (-1 , 1 );
762+ __ bind (&start_regexp);
763+ }
755764
756765 // Initialize on-stack registers.
757766 if (num_saved_registers_ > 0 ) { // Always is, if generated from a regexp.
@@ -772,9 +781,6 @@ Handle<HeapObject> RegExpMacroAssemblerARM::GetCode(Handle<String> source) {
772781 }
773782 }
774783
775- // Initialize backtrack stack pointer.
776- LoadRegExpStackPointerFromMemory (backtrack_stackpointer ());
777-
778784 __ jmp (&start_label_);
779785
780786 // Exit code:
@@ -841,6 +847,10 @@ Handle<HeapObject> RegExpMacroAssemblerARM::GetCode(Handle<String> source) {
841847 // Prepare r0 to initialize registers with its value in the next run.
842848 __ ldr (r0, MemOperand (frame_pointer (), kStringStartMinusOne ));
843849
850+ // Restore the original regexp stack pointer value (effectively, pop the
851+ // stored base pointer).
852+ PopRegExpBasePointer (backtrack_stackpointer (), r2);
853+
844854 if (global_with_zero_length_check ()) {
845855 // Special case for zero-length matches.
846856 // r4: capture start index
@@ -873,7 +883,7 @@ Handle<HeapObject> RegExpMacroAssemblerARM::GetCode(Handle<String> source) {
873883 __ bind (&return_r0);
874884 // Restore the original regexp stack pointer value (effectively, pop the
875885 // stored base pointer).
876- PopRegExpBasePointer (r1 , r2);
886+ PopRegExpBasePointer (backtrack_stackpointer () , r2);
877887
878888 // Skip sp past regexp registers and local variables..
879889 __ mov (sp, frame_pointer ());
0 commit comments