@@ -665,26 +665,26 @@ void RegExpMacroAssemblerPPC::StoreRegExpStackPointerToMemory(
665665 __ StoreU64 (src, MemOperand (scratch));
666666}
667667
668- void RegExpMacroAssemblerPPC::PushRegExpBasePointer (Register scratch1,
669- Register scratch2) {
670- LoadRegExpStackPointerFromMemory (scratch1);
668+ void RegExpMacroAssemblerPPC::PushRegExpBasePointer (Register stack_pointer,
669+ Register scratch) {
671670 ExternalReference ref =
672671 ExternalReference::address_of_regexp_stack_memory_top_address (isolate ());
673- __ mov (scratch2 , Operand (ref));
674- __ LoadU64 (scratch2 , MemOperand (scratch2 ));
675- __ SubS64 (scratch2, scratch1, scratch2 );
676- __ StoreU64 (scratch2 , MemOperand (frame_pointer (), kRegExpStackBasePointer ));
672+ __ mov (scratch , Operand (ref));
673+ __ LoadU64 (scratch , MemOperand (scratch ));
674+ __ SubS64 (scratch, stack_pointer, scratch );
675+ __ StoreU64 (scratch , MemOperand (frame_pointer (), kRegExpStackBasePointer ));
677676}
678677
679- void RegExpMacroAssemblerPPC::PopRegExpBasePointer (Register scratch1 ,
680- Register scratch2 ) {
678+ void RegExpMacroAssemblerPPC::PopRegExpBasePointer (Register stack_pointer_out ,
679+ Register scratch ) {
681680 ExternalReference ref =
682681 ExternalReference::address_of_regexp_stack_memory_top_address (isolate ());
683- __ LoadU64 (scratch1, MemOperand (frame_pointer (), kRegExpStackBasePointer ));
684- __ mov (scratch2, Operand (ref));
685- __ LoadU64 (scratch2, MemOperand (scratch2));
686- __ AddS64 (scratch1, scratch1, scratch2);
687- StoreRegExpStackPointerToMemory (scratch1, scratch2);
682+ __ LoadU64 (stack_pointer_out,
683+ MemOperand (frame_pointer (), kRegExpStackBasePointer ));
684+ __ mov (scratch, Operand (ref));
685+ __ LoadU64 (scratch, MemOperand (scratch));
686+ __ AddS64 (stack_pointer_out, stack_pointer_out, scratch);
687+ StoreRegExpStackPointerToMemory (stack_pointer_out, scratch);
688688}
689689
690690Handle<HeapObject> RegExpMacroAssemblerPPC::GetCode (Handle<String> source) {
@@ -743,37 +743,44 @@ Handle<HeapObject> RegExpMacroAssemblerPPC::GetCode(Handle<String> source) {
743743 kBacktrackCount - kSystemPointerSize );
744744 __ push (r3); // The regexp stack base ptr.
745745
746+ // Initialize backtrack stack pointer. It must not be clobbered from here
747+ // on. Note the backtrack_stackpointer is callee-saved.
748+ STATIC_ASSERT (backtrack_stackpointer () == r29);
749+ LoadRegExpStackPointerFromMemory (backtrack_stackpointer ());
750+
746751 // Store the regexp base pointer - we'll later restore it / write it to
747752 // memory when returning from this irregexp code object.
748- PushRegExpBasePointer (r3, r4);
749-
750- // Check if we have space on the stack for registers.
751- Label stack_limit_hit;
752- Label stack_ok;
753-
754- ExternalReference stack_limit =
755- ExternalReference::address_of_jslimit (isolate ());
756- __ mov (r3, Operand (stack_limit));
757- __ LoadU64 (r3, MemOperand (r3));
758- __ sub (r3, sp, r3, LeaveOE, SetRC);
759- // Handle it if the stack pointer is already below the stack limit.
760- __ ble (&stack_limit_hit, cr0);
761- // Check if there is room for the variable number of registers above
762- // the stack limit.
763- __ CmpU64 (r3, Operand (num_registers_ * kSystemPointerSize ), r0);
764- __ bge (&stack_ok);
765- // Exit with OutOfMemory exception. There is not enough space on the stack
766- // for our working registers.
767- __ li (r3, Operand (EXCEPTION));
768- __ b (&return_r3);
769-
770- __ bind (&stack_limit_hit);
771- CallCheckStackGuardState (r3);
772- __ cmpi (r3, Operand::Zero ());
773- // If returned value is non-zero, we exit with the returned value as result.
774- __ bne (&return_r3);
753+ PushRegExpBasePointer (backtrack_stackpointer (), r4);
754+
755+ {
756+ // Check if we have space on the stack for registers.
757+ Label stack_limit_hit, stack_ok;
758+
759+ ExternalReference stack_limit =
760+ ExternalReference::address_of_jslimit (isolate ());
761+ __ mov (r3, Operand (stack_limit));
762+ __ LoadU64 (r3, MemOperand (r3));
763+ __ sub (r3, sp, r3, LeaveOE, SetRC);
764+ // Handle it if the stack pointer is already below the stack limit.
765+ __ ble (&stack_limit_hit, cr0);
766+ // Check if there is room for the variable number of registers above
767+ // the stack limit.
768+ __ CmpU64 (r3, Operand (num_registers_ * kSystemPointerSize ), r0);
769+ __ bge (&stack_ok);
770+ // Exit with OutOfMemory exception. There is not enough space on the stack
771+ // for our working registers.
772+ __ li (r3, Operand (EXCEPTION));
773+ __ b (&return_r3);
774+
775+ __ bind (&stack_limit_hit);
776+ CallCheckStackGuardState (r3);
777+ __ cmpi (r3, Operand::Zero ());
778+ // If returned value is non-zero, we exit with the returned value as
779+ // result.
780+ __ bne (&return_r3);
775781
776- __ bind (&stack_ok);
782+ __ bind (&stack_ok);
783+ }
777784
778785 // Allocate space on stack for registers.
779786 __ AddS64 (sp, sp, Operand (-num_registers_ * kSystemPointerSize ), r0);
@@ -800,18 +807,21 @@ Handle<HeapObject> RegExpMacroAssemblerPPC::GetCode(Handle<String> source) {
800807 // Initialize code pointer register
801808 __ mov (code_pointer (), Operand (masm_->CodeObject ()));
802809
803- Label load_char_start_regexp, start_regexp;
804- // Load newline if index is at start, previous character otherwise.
805- __ cmpi (r4, Operand::Zero ());
806- __ bne (&load_char_start_regexp);
807- __ li (current_character (), Operand (' \n ' ));
808- __ b (&start_regexp);
809-
810- // Global regexp restarts matching here.
811- __ bind (&load_char_start_regexp);
812- // Load previous char as initial value of current character register.
813- LoadCurrentCharacterUnchecked (-1 , 1 );
814- __ bind (&start_regexp);
810+ Label load_char_start_regexp;
811+ {
812+ Label start_regexp;
813+ // Load newline if index is at start, previous character otherwise.
814+ __ cmpi (r4, Operand::Zero ());
815+ __ bne (&load_char_start_regexp);
816+ __ li (current_character (), Operand (' \n ' ));
817+ __ b (&start_regexp);
818+
819+ // Global regexp restarts matching here.
820+ __ bind (&load_char_start_regexp);
821+ // Load previous char as initial value of current character register.
822+ LoadCurrentCharacterUnchecked (-1 , 1 );
823+ __ bind (&start_regexp);
824+ }
815825
816826 // Initialize on-stack registers.
817827 if (num_saved_registers_ > 0 ) { // Always is, if generated from a regexp.
@@ -833,9 +843,6 @@ Handle<HeapObject> RegExpMacroAssemblerPPC::GetCode(Handle<String> source) {
833843 }
834844 }
835845
836- // Initialize backtrack stack pointer.
837- LoadRegExpStackPointerFromMemory (backtrack_stackpointer ());
838-
839846 __ b (&start_label_);
840847
841848 // Exit code:
@@ -906,6 +913,10 @@ Handle<HeapObject> RegExpMacroAssemblerPPC::GetCode(Handle<String> source) {
906913 // Prepare r3 to initialize registers with its value in the next run.
907914 __ LoadU64 (r3, MemOperand (frame_pointer (), kStringStartMinusOne ));
908915
916+ // Restore the original regexp stack pointer value (effectively, pop the
917+ // stored base pointer).
918+ PopRegExpBasePointer (backtrack_stackpointer (), r5);
919+
909920 if (global_with_zero_length_check ()) {
910921 // Special case for zero-length matches.
911922 // r25: capture start index
@@ -938,7 +949,7 @@ Handle<HeapObject> RegExpMacroAssemblerPPC::GetCode(Handle<String> source) {
938949 __ bind (&return_r3);
939950 // Restore the original regexp stack pointer value (effectively, pop the
940951 // stored base pointer).
941- PopRegExpBasePointer (r4 , r5);
952+ PopRegExpBasePointer (backtrack_stackpointer () , r5);
942953
943954 // Skip sp past regexp registers and local variables..
944955 __ mr (sp, frame_pointer ());
0 commit comments