Temporarily rolling out r60267, I appear to have hoesed perf at the last minute....
authorbarraclough@apple.com <barraclough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 May 2010 05:17:20 +0000 (05:17 +0000)
committerbarraclough@apple.com <barraclough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 May 2010 05:17:20 +0000 (05:17 +0000)
Reviewed by NOBODY (revert).

* yarr/RegexCompiler.cpp:
(JSC::Yarr::RegexPatternConstructor::atomBackReference):
(JSC::Yarr::RegexPatternConstructor::quantifyAtom):
* yarr/RegexJIT.cpp:
(JSC::Yarr::RegexGenerator::TermGenerationState::term):
(JSC::Yarr::RegexGenerator::generateParenthesesSingle):
(JSC::Yarr::RegexGenerator::generateTerm):
(JSC::Yarr::RegexGenerator::RegexGenerator):
(JSC::Yarr::jitCompileRegex):
* yarr/RegexPattern.h:
(JSC::Yarr::RegexPattern::RegexPattern):
(JSC::Yarr::RegexPattern::reset):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@60271 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/yarr/RegexCompiler.cpp
JavaScriptCore/yarr/RegexJIT.cpp
JavaScriptCore/yarr/RegexPattern.h

index c1285eb..66d0559 100644 (file)
@@ -1,3 +1,22 @@
+2010-05-26  Gavin Barraclough  <barraclough@apple.com>
+
+        Reviewed by NOBODY (revert).
+
+        Temporarily rolling out r60267, I appear to have hoesed perf at the last minute. :-/ Fixing.
+
+        * yarr/RegexCompiler.cpp:
+        (JSC::Yarr::RegexPatternConstructor::atomBackReference):
+        (JSC::Yarr::RegexPatternConstructor::quantifyAtom):
+        * yarr/RegexJIT.cpp:
+        (JSC::Yarr::RegexGenerator::TermGenerationState::term):
+        (JSC::Yarr::RegexGenerator::generateParenthesesSingle):
+        (JSC::Yarr::RegexGenerator::generateTerm):
+        (JSC::Yarr::RegexGenerator::RegexGenerator):
+        (JSC::Yarr::jitCompileRegex):
+        * yarr/RegexPattern.h:
+        (JSC::Yarr::RegexPattern::RegexPattern):
+        (JSC::Yarr::RegexPattern::reset):
+
 2010-05-26  Gustavo Noronha Silva  <gns@gnome.org>
 
         Build fixes for make distcheck.
index bcfc188..9fbe213 100644 (file)
@@ -372,7 +372,7 @@ public:
     void atomBackReference(unsigned subpatternId)
     {
         ASSERT(subpatternId);
-        m_pattern.m_containsBackreferences = true;
+        m_pattern.m_shouldFallBack = true;
         m_pattern.m_maxBackReference = std::max(m_pattern.m_maxBackReference, subpatternId);
 
         if (subpatternId > m_pattern.m_numSubpatterns) {
@@ -448,6 +448,9 @@ public:
             return;
         }
 
+        if (max > 1 && term.type == PatternTerm::TypeParenthesesSubpattern)
+            m_pattern.m_shouldFallBack = true;
+
         if (min == 0)
             term.quantify(max, greedy   ? QuantifierGreedy : QuantifierNonGreedy);
         else if (min == max)
index b277a9c..e33dba0 100644 (file)
@@ -345,15 +345,6 @@ class RegexGenerator : private MacroAssembler {
             ASSERT(alternativeValid());
             return alternative()->m_terms[t];
         }
-        bool isLastTerm()
-        {
-            ASSERT(alternativeValid());
-            return (t + 1) == alternative()->m_terms.size();
-        }
-        bool isMainDisjunction()
-        {
-            return !disjunction->m_parent;
-        }
 
         PatternTerm& lookaheadTerm()
         {
@@ -911,11 +902,6 @@ class RegexGenerator : private MacroAssembler {
         PatternDisjunction* disjunction = term.parentheses.disjunction;
         ASSERT(term.quantityCount == 1);
 
-        if (!term.parentheses.isCopy) {
-            m_shouldFallBack = true;
-            return;
-        }
-
         unsigned preCheckedCount = ((term.quantityCount == 1) && (term.quantityType == QuantifierFixedCount)) ? disjunction->m_minimumSize : 0;
 
         unsigned parenthesesFrameLocation = term.frameLocation;
@@ -1003,58 +989,6 @@ class RegexGenerator : private MacroAssembler {
         }
     }
 
-    void generateParenthesesGreedyNoBacktrack(TermGenerationState& state)
-    {
-        PatternTerm& parenthesesTerm = state.term();
-        PatternDisjunction* disjunction = parenthesesTerm.parentheses.disjunction;
-        ASSERT(parenthesesTerm.type == PatternTerm::TypeParenthesesSubpattern);
-        ASSERT(parenthesesTerm.quantityCount != 1); // Handled by generateParenthesesSingle.
-
-        // Capturing not yet implemented!
-        if (parenthesesTerm.invertOrCapture) {
-            m_shouldFallBack = true;
-            return;
-        }
-
-        // Quantification limit not yet implemented!
-        if (parenthesesTerm.quantityCount != 0xffffffff) {
-            m_shouldFallBack = true;
-            return;
-        }
-
-        TermGenerationState parenthesesState(disjunction, state.checkedTotal);
-
-        Label matchAgain(this);
-        for (parenthesesState.resetAlternative(); parenthesesState.alternativeValid(); parenthesesState.nextAlternative()) {
-
-            PatternAlternative* alternative = parenthesesState.alternative();
-            optimizeAlternative(alternative);
-
-            int countToCheck = alternative->m_minimumSize;
-            if (countToCheck) {
-                parenthesesState.addBacktrackJump(jumpIfNoAvailableInput(countToCheck));
-                parenthesesState.checkedTotal += countToCheck;
-            }
-
-            for (parenthesesState.resetTerm(); parenthesesState.termValid(); parenthesesState.nextTerm())
-                generateTerm(parenthesesState);
-
-            // If we get here, we matched! Limit not yet supported, so just try to match more!
-            jump(matchAgain);
-            
-            parenthesesState.linkAlternativeBacktracks(this);
-            // We get here if the alternative fails to match - fall through to the next iteration, or out of the loop.
-
-            if (countToCheck) {
-                sub32(Imm32(countToCheck), index);
-                parenthesesState.checkedTotal -= countToCheck;
-            }
-        }
-
-        // If the last alternative falls through to here, we have a failed match...
-        // Which means that we match whatever we have matched up to this point (even if nothing).
-    }
-
     void generateParentheticalAssertion(TermGenerationState& state)
     {
         PatternTerm& term = state.term();
@@ -1166,24 +1100,15 @@ class RegexGenerator : private MacroAssembler {
             break;
 
         case PatternTerm::TypeBackReference:
-            m_shouldFallBack = true;
+            ASSERT_NOT_REACHED();
             break;
 
         case PatternTerm::TypeForwardReference:
             break;
 
         case PatternTerm::TypeParenthesesSubpattern:
-            if (term.quantityCount == 1) {
-                generateParenthesesSingle(state);
-                break;
-            } else if (state.isLastTerm() && state.isMainDisjunction()) { // Is this is the last term of the main disjunction?
-                // If this has a greedy quantifier, then it will never need to backtrack!
-                if (term.quantityType == QuantifierGreedy) {
-                    generateParenthesesGreedyNoBacktrack(state);
-                    break;
-                }
-            }
-            m_shouldFallBack = true;
+            ASSERT((term.quantityCount == 1) && !term.parentheses.isCopy); // must fallback to pcre before this point
+            generateParenthesesSingle(state);
             break;
 
         case PatternTerm::TypeParentheticalAssertion:
@@ -1436,7 +1361,6 @@ class RegexGenerator : private MacroAssembler {
 public:
     RegexGenerator(RegexPattern& pattern)
         : m_pattern(pattern)
-        , m_shouldFallBack(false)
     {
     }
 
@@ -1466,34 +1390,28 @@ public:
         jitObject.set(patchBuffer.finalizeCode());
     }
 
-    bool shouldFallBack()
-    {
-        return m_shouldFallBack;
-    }
-
 private:
     RegexPattern& m_pattern;
-    bool m_shouldFallBack;
     Vector<AlternativeBacktrackRecord> m_backtrackRecords;
 };
 
 void jitCompileRegex(JSGlobalData* globalData, RegexCodeBlock& jitObject, const UString& patternString, unsigned& numSubpatterns, const char*& error, bool ignoreCase, bool multiline)
 {
     RegexPattern pattern(ignoreCase, multiline);
+
     if ((error = compileRegex(patternString, pattern)))
         return;
+
     numSubpatterns = pattern.m_numSubpatterns;
 
-    if (!pattern.m_containsBackreferences) {
+    if (pattern.m_shouldFallBack) {
+        JSRegExpIgnoreCaseOption ignoreCaseOption = ignoreCase ? JSRegExpIgnoreCase : JSRegExpDoNotIgnoreCase;
+        JSRegExpMultilineOption multilineOption = multiline ? JSRegExpMultiline : JSRegExpSingleLine;
+        jitObject.setFallback(jsRegExpCompile(reinterpret_cast<const UChar*>(patternString.data()), patternString.size(), ignoreCaseOption, multilineOption, &numSubpatterns, &error));
+    } else {
         RegexGenerator generator(pattern);
         generator.compile(globalData, jitObject);
-        if (!generator.shouldFallBack())
-            return;
     }
-
-    JSRegExpIgnoreCaseOption ignoreCaseOption = ignoreCase ? JSRegExpIgnoreCase : JSRegExpDoNotIgnoreCase;
-    JSRegExpMultilineOption multilineOption = multiline ? JSRegExpMultiline : JSRegExpSingleLine;
-    jitObject.setFallback(jsRegExpCompile(reinterpret_cast<const UChar*>(patternString.data()), patternString.size(), ignoreCaseOption, multilineOption, &numSubpatterns, &error));
 }
 
 }}
index 61d6ad6..3271cc1 100644 (file)
@@ -271,7 +271,7 @@ struct RegexPattern {
         , m_multiline(multiline)
         , m_numSubpatterns(0)
         , m_maxBackReference(0)
-        , m_containsBackreferences(false)
+        , m_shouldFallBack(false)
         , newlineCached(0)
         , digitsCached(0)
         , spacesCached(0)
@@ -293,7 +293,7 @@ struct RegexPattern {
         m_numSubpatterns = 0;
         m_maxBackReference = 0;
 
-        m_containsBackreferences = false;
+        m_shouldFallBack = false;
 
         newlineCached = 0;
         digitsCached = 0;
@@ -361,7 +361,7 @@ struct RegexPattern {
     bool m_multiline;
     unsigned m_numSubpatterns;
     unsigned m_maxBackReference;
-    bool m_containsBackreferences;
+    bool m_shouldFallBack;
     PatternDisjunction* m_body;
     Vector<PatternDisjunction*, 4> m_disjunctions;
     Vector<CharacterClass*> m_userCharacterClasses;