Skip to content
Permalink
Browse files
2010-04-14 Peter Varga <pvarga@inf.u-szeged.hu>
        Reviewed by Geoffrey Garen.

        Move the YARR JIT fallback detection from RegexJIT.cpp to
        RegexCompiler.cpp.

        https://bugs.webkit.org/show_bug.cgi?id=37571

        * yarr/RegexCompiler.cpp:
        (JSC::Yarr::RegexPatternConstructor::atomBackReference):
        (JSC::Yarr::RegexPatternConstructor::quantifyAtom):
        * yarr/RegexJIT.cpp:
        (JSC::Yarr::RegexGenerator::generateTerm):
        (JSC::Yarr::RegexGenerator::RegexGenerator):
        (JSC::Yarr::jitCompileRegex):
        * yarr/RegexJIT.h:
        (JSC::Yarr::RegexCodeBlock::operator!):
        * yarr/RegexPattern.h:
        (JSC::Yarr::RegexPattern::RegexPattern):
        (JSC::Yarr::RegexPattern::reset):

Canonical link: https://commits.webkit.org/48896@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@57608 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
eseidel committed Apr 14, 2010
1 parent e78dc5b commit d122b0d1378104f8dceeb9fcbc2757b7e1e7f2b5
Showing 5 changed files with 38 additions and 17 deletions.
@@ -1,3 +1,25 @@
2010-04-14 Peter Varga <pvarga@inf.u-szeged.hu>

Reviewed by Geoffrey Garen.

Move the YARR JIT fallback detection from RegexJIT.cpp to
RegexCompiler.cpp.

https://bugs.webkit.org/show_bug.cgi?id=37571

* yarr/RegexCompiler.cpp:
(JSC::Yarr::RegexPatternConstructor::atomBackReference):
(JSC::Yarr::RegexPatternConstructor::quantifyAtom):
* yarr/RegexJIT.cpp:
(JSC::Yarr::RegexGenerator::generateTerm):
(JSC::Yarr::RegexGenerator::RegexGenerator):
(JSC::Yarr::jitCompileRegex):
* yarr/RegexJIT.h:
(JSC::Yarr::RegexCodeBlock::operator!):
* yarr/RegexPattern.h:
(JSC::Yarr::RegexPattern::RegexPattern):
(JSC::Yarr::RegexPattern::reset):

2010-04-14 Kent Hansen <kent.hansen@nokia.com>

Reviewed by Maciej Stachowiak.
@@ -469,6 +469,7 @@ class RegexPatternConstructor {
void atomBackReference(unsigned subpatternId)
{
ASSERT(subpatternId);
m_pattern.m_shouldFallBack = true;
m_pattern.m_maxBackReference = std::max(m_pattern.m_maxBackReference, subpatternId);

if (subpatternId > m_pattern.m_numSubpatterns) {
@@ -544,6 +545,9 @@ class RegexPatternConstructor {
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)
@@ -1088,17 +1088,15 @@ class RegexGenerator : private MacroAssembler {
break;

case PatternTerm::TypeBackReference:
m_generationFailed = true;
ASSERT_NOT_REACHED();
break;

case PatternTerm::TypeForwardReference:
break;

case PatternTerm::TypeParenthesesSubpattern:
if ((term.quantityCount == 1) && !term.parentheses.isCopy)
generateParenthesesSingle(state);
else
m_generationFailed = true;
ASSERT((term.quantityCount == 1) && !term.parentheses.isCopy); // must fallback to pcre before this point
generateParenthesesSingle(state);
break;

case PatternTerm::TypeParentheticalAssertion:
@@ -1351,7 +1349,6 @@ class RegexGenerator : private MacroAssembler {
public:
RegexGenerator(RegexPattern& pattern)
: m_pattern(pattern)
, m_generationFailed(false)
{
}

@@ -1381,15 +1378,9 @@ class RegexGenerator : private MacroAssembler {
jitObject.set(patchBuffer.finalizeCode());
}

bool generationFailed()
{
return m_generationFailed;
}

private:
RegexPattern& m_pattern;
Vector<AlternativeBacktrackRecord> m_backtrackRecords;
bool m_generationFailed;
};

void jitCompileRegex(JSGlobalData* globalData, RegexCodeBlock& jitObject, const UString& patternString, unsigned& numSubpatterns, const char*& error, bool ignoreCase, bool multiline)
@@ -1401,13 +1392,13 @@ void jitCompileRegex(JSGlobalData* globalData, RegexCodeBlock& jitObject, const

numSubpatterns = pattern.m_numSubpatterns;

RegexGenerator generator(pattern);
generator.compile(globalData, jitObject);

if (generator.generationFailed()) {
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);
}
}

@@ -66,7 +66,7 @@ class RegexCodeBlock {
JSRegExp* getFallback() { return m_fallback; }
void setFallback(JSRegExp* fallback) { m_fallback = fallback; }

bool operator!() { return !m_ref.m_code.executableAddress(); }
bool operator!() { return (!m_ref.m_code.executableAddress() && !m_fallback); }
void set(MacroAssembler::CodeRef ref) { m_ref = ref; }

int execute(const UChar* input, unsigned start, unsigned length, int* output)
@@ -247,6 +247,7 @@ struct RegexPattern {
, m_multiline(multiline)
, m_numSubpatterns(0)
, m_maxBackReference(0)
, m_shouldFallBack(false)
, newlineCached(0)
, digitsCached(0)
, spacesCached(0)
@@ -268,6 +269,8 @@ struct RegexPattern {
m_numSubpatterns = 0;
m_maxBackReference = 0;

m_shouldFallBack = false;

newlineCached = 0;
digitsCached = 0;
spacesCached = 0;
@@ -334,6 +337,7 @@ struct RegexPattern {
bool m_multiline;
unsigned m_numSubpatterns;
unsigned m_maxBackReference;
bool m_shouldFallBack;
PatternDisjunction* m_body;
Vector<PatternDisjunction*, 4> m_disjunctions;
Vector<CharacterClass*> m_userCharacterClasses;

0 comments on commit d122b0d

Please sign in to comment.