Changeset 235322 in webkit for trunk/Source/JavaScriptCore/yarr/YarrJIT.cpp
- Timestamp:
- Aug 24, 2018, 11:22:29 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/yarr/YarrJIT.cpp
r235238 r235322 2235 2235 2236 2236 // If the parentheses are quantified Greedy then add a label to jump back 2237 // to if get a failed match from after the parentheses. For NonGreedy2237 // to if we get a failed match from after the parentheses. For NonGreedy 2238 2238 // parentheses, link the jump from before the subpattern to here. 2239 2239 if (term->quantityType == QuantifierGreedy) … … 2299 2299 // - To check for empty matches, which must be rejected. 2300 2300 // 2301 // At the head of a NonGreedy set of parentheses we'll immediately set the2302 // value on the stackto -1 (indicating a match skipping the subpattern),2301 // At the head of a NonGreedy set of parentheses we'll immediately set 'begin' 2302 // in the backtrack info to -1 (indicating a match skipping the subpattern), 2303 2303 // and plant a jump to the end. We'll also plant a label to backtrack to 2304 // to reenter the subpattern later, with a store to set up index on the2305 // second iteration.2304 // to reenter the subpattern later, with a store to set 'begin' to current index 2305 // on the second iteration. 2306 2306 // 2307 2307 // FIXME: for capturing parens, could use the index in the capture array? … … 2390 2390 2391 2391 // If the parentheses are quantified Greedy then add a label to jump back 2392 // to if get a failed match from after the parentheses. For NonGreedy2392 // to if we get a failed match from after the parentheses. For NonGreedy 2393 2393 // parentheses, link the jump from before the subpattern to here. 2394 2394 if (term->quantityType == QuantifierGreedy) { … … 2402 2402 YarrOp& beginOp = m_ops[op.m_previousOp]; 2403 2403 beginOp.m_jumps.link(this); 2404 op.m_reentry = label(); 2404 2405 } 2405 2406 #else // !YARR_JIT_ALL_PARENS_EXPRESSIONS … … 2963 2964 m_backtrackingState.link(this); 2964 2965 2965 if (term->quantityType == QuantifierGreedy) { 2966 RegisterID currParenContextReg = regT0; 2967 RegisterID newParenContextReg = regT1; 2968 2969 loadFromFrame(parenthesesFrameLocation + BackTrackInfoParentheses::parenContextHeadIndex(), currParenContextReg); 2970 2971 restoreParenContext(currParenContextReg, regT2, term->parentheses.subpatternId, term->parentheses.lastSubpatternId, parenthesesFrameLocation); 2972 2973 freeParenContext(currParenContextReg, newParenContextReg); 2974 storeToFrame(newParenContextReg, parenthesesFrameLocation + BackTrackInfoParentheses::parenContextHeadIndex()); 2975 const RegisterID countTemporary = regT0; 2976 loadFromFrame(parenthesesFrameLocation + BackTrackInfoParentheses::matchAmountIndex(), countTemporary); 2977 Jump zeroLengthMatch = branchTest32(Zero, countTemporary); 2978 2979 sub32(TrustedImm32(1), countTemporary); 2980 storeToFrame(countTemporary, parenthesesFrameLocation + BackTrackInfoParentheses::matchAmountIndex()); 2981 2966 RegisterID currParenContextReg = regT0; 2967 RegisterID newParenContextReg = regT1; 2968 2969 loadFromFrame(parenthesesFrameLocation + BackTrackInfoParentheses::parenContextHeadIndex(), currParenContextReg); 2970 2971 restoreParenContext(currParenContextReg, regT2, term->parentheses.subpatternId, term->parentheses.lastSubpatternId, parenthesesFrameLocation); 2972 2973 freeParenContext(currParenContextReg, newParenContextReg); 2974 storeToFrame(newParenContextReg, parenthesesFrameLocation + BackTrackInfoParentheses::parenContextHeadIndex()); 2975 2976 const RegisterID countTemporary = regT0; 2977 loadFromFrame(parenthesesFrameLocation + BackTrackInfoParentheses::matchAmountIndex(), countTemporary); 2978 Jump zeroLengthMatch = branchTest32(Zero, countTemporary); 2979 2980 sub32(TrustedImm32(1), countTemporary); 2981 storeToFrame(countTemporary, parenthesesFrameLocation + BackTrackInfoParentheses::matchAmountIndex()); 2982 2983 jump(m_ops[op.m_nextOp].m_reentry); 2984 2985 zeroLengthMatch.link(this); 2986 2987 // Clear the flag in the stackframe indicating we didn't run through the subpattern. 2988 storeToFrame(TrustedImm32(-1), parenthesesFrameLocation + BackTrackInfoParentheses::beginIndex()); 2989 2990 if (term->quantityType == QuantifierGreedy) 2982 2991 jump(m_ops[op.m_nextOp].m_reentry); 2983 2984 zeroLengthMatch.link(this);2985 2986 // Clear the flag in the stackframe indicating we didn't run through the subpattern.2987 storeToFrame(TrustedImm32(-1), parenthesesFrameLocation + BackTrackInfoParentheses::beginIndex());2988 2989 jump(m_ops[op.m_nextOp].m_reentry);2990 }2991 2992 2992 2993 // If Greedy, jump to the end. … … 3011 3012 m_backtrackingState.link(this); 3012 3013 3013 // Check whether we should backtrack back into the parentheses, or if we3014 // are currently in a state where we had skipped over the subpattern3015 // (in which case the flag value on the stack will be -1).3016 3014 unsigned parenthesesFrameLocation = term->frameLocation; 3017 Jump hadSkipped = branch32(Equal, Address(stackPointerRegister, (parenthesesFrameLocation + BackTrackInfoParentheses::beginIndex()) * sizeof(void*)), TrustedImm32(-1));3018 3015 3019 3016 if (term->quantityType == QuantifierGreedy) { 3017 // Check whether we should backtrack back into the parentheses, or if we 3018 // are currently in a state where we had skipped over the subpattern 3019 // (in which case the flag value on the stack will be -1). 3020 Jump hadSkipped = branch32(Equal, Address(stackPointerRegister, (parenthesesFrameLocation + BackTrackInfoParentheses::beginIndex()) * sizeof(void*)), TrustedImm32(-1)); 3021 3020 3022 // For Greedy parentheses, we skip after having already tried going 3021 3023 // through the subpattern, so if we get here we're done. … … 3028 3030 // matching path. 3029 3031 ASSERT(term->quantityType == QuantifierNonGreedy); 3032 3033 const RegisterID beginTemporary = regT0; 3034 const RegisterID countTemporary = regT1; 3035 3030 3036 YarrOp& beginOp = m_ops[op.m_previousOp]; 3031 hadSkipped.linkTo(beginOp.m_reentry, this); 3037 3038 loadFromFrame(parenthesesFrameLocation + BackTrackInfoParentheses::beginIndex(), beginTemporary); 3039 branch32(Equal, beginTemporary, TrustedImm32(-1)).linkTo(beginOp.m_reentry, this); 3040 3041 JumpList exceededMatchLimit; 3042 3043 if (term->quantityMaxCount != quantifyInfinite) { 3044 loadFromFrame(parenthesesFrameLocation + BackTrackInfoParentheses::matchAmountIndex(), countTemporary); 3045 exceededMatchLimit.append(branch32(AboveOrEqual, countTemporary, Imm32(term->quantityMaxCount.unsafeGet()))); 3046 } 3047 3048 branch32(Above, index, beginTemporary).linkTo(beginOp.m_reentry, this); 3049 3050 exceededMatchLimit.link(this); 3032 3051 } 3033 3052 … … 3103 3122 // Supported types of parentheses are 'Once' (quantityMaxCount == 1), 3104 3123 // 'Terminal' (non-capturing parentheses quantified as greedy 3105 // and infinite), and 0 based greedy quantified parentheses.3124 // and infinite), and 0 based greedy / non-greedy quantified parentheses. 3106 3125 // Alternatives will use the 'Simple' set of ops if either the 3107 3126 // subpattern is terminal (in which case we will never need to … … 3125 3144 m_failureReason = JITFailureReason::VariableCountedParenthesisWithNonZeroMinimum; 3126 3145 return; 3127 } if (term->quantityMaxCount == 1 && !term->parentheses.isCopy) { 3146 } 3147 3148 if (term->quantityMaxCount == 1 && !term->parentheses.isCopy) { 3128 3149 // Select the 'Once' nodes. 3129 3150 parenthesesBeginOpCode = OpParenthesesSubpatternOnceBegin; … … 3142 3163 } else { 3143 3164 #if ENABLE(YARR_JIT_ALL_PARENS_EXPRESSIONS) 3144 // We only handle generic parenthesis with greedycounts.3145 if (term->quantityType != QuantifierGreedy) {3165 // We only handle generic parenthesis with non-fixed counts. 3166 if (term->quantityType == QuantifierFixedCount) { 3146 3167 // This subpattern is not supported by the JIT. 3147 m_failureReason = JITFailureReason:: NonGreedyParenthesizedSubpattern;3168 m_failureReason = JITFailureReason::FixedCountParenthesizedSubpattern; 3148 3169 return; 3149 3170 } … … 3563 3584 #if ENABLE(YARR_JIT_ALL_PARENS_EXPRESSIONS) 3564 3585 if (m_containsNestedSubpatterns) 3565 codeBlock.setUsesPat ernContextBuffer();3586 codeBlock.setUsesPatternContextBuffer(); 3566 3587 #endif 3567 3588 … … 3775 3796 out.print("OpParenthesesSubpatternOnceBegin "); 3776 3797 if (term->capture()) 3777 out.printf("capturing pattern #%u\n", op.m_term->parentheses.subpatternId); 3798 out.printf("capturing pattern #%u", term->parentheses.subpatternId); 3799 else 3800 out.print("non-capturing"); 3801 term->dumpQuantifier(out); 3802 out.print("\n"); 3803 return(0); 3804 3805 case OpParenthesesSubpatternOnceEnd: 3806 out.print("OpParenthesesSubpatternOnceEnd "); 3807 if (term->capture()) 3808 out.printf("capturing pattern #%u", term->parentheses.subpatternId); 3809 else 3810 out.print("non-capturing"); 3811 term->dumpQuantifier(out); 3812 out.print("\n"); 3813 return(0); 3814 3815 case OpParenthesesSubpatternTerminalBegin: 3816 out.print("OpParenthesesSubpatternTerminalBegin "); 3817 if (term->capture()) 3818 out.printf("capturing pattern #%u\n", term->parentheses.subpatternId); 3778 3819 else 3779 3820 out.print("non-capturing\n"); 3780 3821 return(0); 3781 3822 3782 case OpParenthesesSubpatternOnceEnd: 3783 out.print("OpParenthesesSubpatternOnceEnd\n"); 3784 return(0); 3785 3786 case OpParenthesesSubpatternTerminalBegin: 3787 out.print("OpParenthesesSubpatternTerminalBegin "); 3823 case OpParenthesesSubpatternTerminalEnd: 3824 out.print("OpParenthesesSubpatternTerminalEnd "); 3788 3825 if (term->capture()) 3789 out.printf("capturing pattern #%u\n", op.m_term->parentheses.subpatternId);3826 out.printf("capturing pattern #%u\n", term->parentheses.subpatternId); 3790 3827 else 3791 3828 out.print("non-capturing\n"); 3792 3829 return(0); 3793 3830 3794 case OpParenthesesSubpatternTerminalEnd:3795 out.print("OpParenthesesSubpatternTerminalEnd ");3796 if (term->capture())3797 out.printf("capturing pattern #%u\n", op.m_term->parentheses.subpatternId);3798 else3799 out.print("non-capturing\n");3800 return(0);3801 3802 3831 case OpParenthesesSubpatternBegin: 3803 3832 out.print("OpParenthesesSubpatternBegin "); 3804 3833 if (term->capture()) 3805 out.printf("capturing pattern #%u \n", op.m_term->parentheses.subpatternId);3834 out.printf("capturing pattern #%u", term->parentheses.subpatternId); 3806 3835 else 3807 out.print("non-capturing\n"); 3836 out.print("non-capturing"); 3837 term->dumpQuantifier(out); 3838 out.print("\n"); 3808 3839 return(0); 3809 3840 … … 3811 3842 out.print("OpParenthesesSubpatternEnd "); 3812 3843 if (term->capture()) 3813 out.printf("capturing pattern #%u \n", op.m_term->parentheses.subpatternId);3844 out.printf("capturing pattern #%u", term->parentheses.subpatternId); 3814 3845 else 3815 out.print("non-capturing\n"); 3846 out.print("non-capturing"); 3847 term->dumpQuantifier(out); 3848 out.print("\n"); 3816 3849 return(0); 3817 3850 3818 3851 case OpParentheticalAssertionBegin: 3819 out.printf("OpParentheticalAssertionBegin%s\n", op.m_term->invert() ? " inverted" : "");3852 out.printf("OpParentheticalAssertionBegin%s\n", term->invert() ? " inverted" : ""); 3820 3853 return(0); 3821 3854 3822 3855 case OpParentheticalAssertionEnd: 3823 out.print("OpParentheticalAssertionEnd%s\n", op.m_term->invert() ? " inverted" : "");3856 out.print("OpParentheticalAssertionEnd%s\n", term->invert() ? " inverted" : ""); 3824 3857 return(0); 3825 3858 … … 3893 3926 dataLog("Can't JIT a pattern containing parenthesized subpatterns\n"); 3894 3927 break; 3895 case JITFailureReason:: NonGreedyParenthesizedSubpattern:3896 dataLog("Can't JIT a pattern containing non-greedyparenthesized subpatterns\n");3928 case JITFailureReason::FixedCountParenthesizedSubpattern: 3929 dataLog("Can't JIT a pattern containing fixed count parenthesized subpatterns\n"); 3897 3930 break; 3898 3931 case JITFailureReason::ExecutableMemoryAllocationFailure: … … 3910 3943 3911 3944 if (auto failureReason = codeBlock.failureReason()) { 3912 if (Options::dumpCompiledRegExpPatterns()) 3945 if (Options::dumpCompiledRegExpPatterns()) { 3946 pattern.dumpPatternString(WTF::dataFile(), patternString); 3947 dataLog(" : "); 3913 3948 dumpCompileFailure(*failureReason); 3949 } 3914 3950 } 3915 3951 }
Note:
See TracChangeset
for help on using the changeset viewer.