diff options
Diffstat (limited to 'Source/JavaScriptCore/yarr/YarrJIT.cpp')
-rw-r--r-- | Source/JavaScriptCore/yarr/YarrJIT.cpp | 103 |
1 files changed, 61 insertions, 42 deletions
diff --git a/Source/JavaScriptCore/yarr/YarrJIT.cpp b/Source/JavaScriptCore/yarr/YarrJIT.cpp index ae59cba..e34e6f4 100644 --- a/Source/JavaScriptCore/yarr/YarrJIT.cpp +++ b/Source/JavaScriptCore/yarr/YarrJIT.cpp @@ -27,9 +27,7 @@ #include "YarrJIT.h" #include "ASCIICType.h" -#include "JSGlobalData.h" #include "LinkBuffer.h" -#include "MacroAssembler.h" #include "Yarr.h" #if ENABLE(YARR_JIT) @@ -407,9 +405,9 @@ class YarrGenerator : private MacroAssembler { --m_parenNestingLevel; } - ParenthesesTail* addParenthesesTail(PatternTerm& term, ParenthesesTail* nextOuterParenTail) + ParenthesesTail* addParenthesesTail(PatternTerm& term, JumpList* jumpListToPriorParen) { - ParenthesesTail* parenthesesTail = new ParenthesesTail(term, m_parenNestingLevel, nextOuterParenTail); + ParenthesesTail* parenthesesTail = new ParenthesesTail(term, m_parenNestingLevel, jumpListToPriorParen); m_parenTails.append(parenthesesTail); m_parenTailsForIteration.append(parenthesesTail); @@ -606,9 +604,9 @@ class YarrGenerator : private MacroAssembler { m_nextBacktrack->setLabel(label); } - void copyBacktrackToLabel(BacktrackDestination& rhs) + void propagateBacktrackToLabel(const BacktrackDestination& rhs) { - if (rhs.m_backtrackToLabel) + if (!m_backtrackToLabel && rhs.m_backtrackToLabel) m_backtrackToLabel = rhs.m_backtrackToLabel; } @@ -618,6 +616,11 @@ class YarrGenerator : private MacroAssembler { m_backtrackToLabel = backtrackToLabel; } + bool hasBacktrackToLabel() + { + return m_backtrackToLabel; + } + void setBacktrackJumpList(JumpList* jumpList) { m_backtrackType = BacktrackJumpList; @@ -634,8 +637,10 @@ class YarrGenerator : private MacroAssembler { if (m_subDataLabelPtr) { *m_subDataLabelPtr = dp; m_subDataLabelPtr = 0; - } else + } else { + ASSERT(!hasDataLabel()); m_dataLabelPtr = dp; + } } void clearSubDataLabelPtr() @@ -748,6 +753,12 @@ class YarrGenerator : private MacroAssembler { return false; } + void linkBacktrackToLabel(Label backtrackLabel) + { + if (m_backtrackToLabel) + *m_backtrackToLabel = backtrackLabel; + } + void linkAlternativeBacktracks(YarrGenerator* generator, bool nextIteration = false) { Label hereLabel = generator->label(); @@ -802,7 +813,7 @@ class YarrGenerator : private MacroAssembler { , checkedTotal(checkedTotal) , m_subParenNum(0) , m_linkedBacktrack(0) - , m_parenthesesTail(0) + , m_jumpList(0) { } @@ -863,14 +874,14 @@ class YarrGenerator : private MacroAssembler { return !disjunction->m_parent; } - void setParenthesesTail(ParenthesesTail* parenthesesTail) + void setJumpListToPriorParen(JumpList* jumpList) { - m_parenthesesTail = parenthesesTail; + m_jumpList = jumpList; } - ParenthesesTail* getParenthesesTail() + JumpList* getJumpListToPriorParen() { - return m_parenthesesTail; + return m_jumpList; } PatternTerm& lookaheadTerm() @@ -919,24 +930,19 @@ class YarrGenerator : private MacroAssembler { return m_backtrack.plantJumpToBacktrackIfExists(generator); } - bool linkDataLabelToBacktrackIfExists(YarrGenerator* generator, DataLabelPtr dataLabel) + void linkDataLabelToBacktrackIfExists(YarrGenerator* generator, DataLabelPtr dataLabel) { // If we have a stack offset backtrack destination, use it directly if (m_backtrack.isStackOffset()) { generator->m_expressionState.addIndirectJumpEntry(m_backtrack.getStackOffset(), dataLabel); m_backtrack.clearSubDataLabelPtr(); } else { - // Otherwise set the data label (which may be linked) - setBacktrackDataLabel(dataLabel); - - if ((m_backtrack.isLabel()) && (m_backtrack.hasDataLabel())) { - generator->m_expressionState.m_backtrackRecords.append(AlternativeBacktrackRecord(m_backtrack.getDataLabel(), m_backtrack.getLabel())); - m_backtrack.clearDataLabel(); - return true; - } + // If we have a backtrack label, connect the datalabel to it directly. + if (m_backtrack.isLabel()) + generator->m_expressionState.m_backtrackRecords.append(AlternativeBacktrackRecord(dataLabel, m_backtrack.getLabel())); + else + setBacktrackDataLabel(dataLabel); } - - return false; } void addBacktrackJump(Jump jump) @@ -990,6 +996,10 @@ class YarrGenerator : private MacroAssembler { { if (doJump) m_backtrack.jumpToBacktrack(generator, backtrack.getBacktrackJumps()); + + if (m_backtrack.isLabel() && backtrack.hasBacktrackToLabel()) + backtrack.linkBacktrackToLabel(m_backtrack.getLabel()); + if (backtrack.hasDestination()) { if (m_backtrack.hasDataLabel()) generator->m_expressionState.addDataLabelToNextIteration(m_backtrack.getDataLabel()); @@ -1006,16 +1016,15 @@ class YarrGenerator : private MacroAssembler { unsigned m_subParenNum; BacktrackDestination m_backtrack; BacktrackDestination* m_linkedBacktrack; - ParenthesesTail* m_parenthesesTail; - + JumpList* m_jumpList; }; struct ParenthesesTail { - ParenthesesTail(PatternTerm& term, int nestingLevel, ParenthesesTail* nextOuterParenTail) + ParenthesesTail(PatternTerm& term, int nestingLevel, JumpList* jumpListToPriorParen) : m_term(term) , m_nestingLevel(nestingLevel) , m_subParenIndex(0) - , m_nextOuterParenTail(nextOuterParenTail) + , m_jumpListToPriorParen(jumpListToPriorParen) { } @@ -1041,7 +1050,7 @@ class YarrGenerator : private MacroAssembler { if (m_doDirectBacktrack) state.propagateBacktrackingFrom(generator, m_parenBacktrack, false); else { - stateBacktrack.setBacktrackJumpList(&m_pattBacktrackJumps); + stateBacktrack.setBacktrackJumpList(&m_afterBacktrackJumps); stateBacktrack.setBacktrackSourceLabel(&m_backtrackFromAfterParens); } } @@ -1054,7 +1063,7 @@ class YarrGenerator : private MacroAssembler { void addAfterParenJump(Jump jump) { - m_pattBacktrackJumps.append(jump); + m_afterBacktrackJumps.append(jump); } bool generateCode(YarrGenerator* generator, JumpList& jumpsToNext, bool priorBackTrackFallThrough, bool nextBacktrackFallThrough) @@ -1080,12 +1089,9 @@ class YarrGenerator : private MacroAssembler { if (m_backtrackToLabel.isSet()) { m_backtrack.setLabel(m_backtrackToLabel); nextBacktrackFallThrough = false; - } else if (!m_subParenIndex && m_nextOuterParenTail) { - // If we don't have a destination and we are the first term of a nested paren, go - // back to the outer paren. - // There is an optimization if the next outer paren is the next paren to be emitted. - // In that case we really want the else clause. - m_backtrack.setBacktrackJumpList(&m_nextOuterParenTail->m_withinBacktrackJumps); + } else if (m_jumpListToPriorParen) { + // If we don't have a destination, go back to either the prior paren or the next outer paren. + m_backtrack.setBacktrackJumpList(m_jumpListToPriorParen); nextBacktrackFallThrough = false; } else m_backtrack.setBacktrackJumpList(&jumpsToNext); @@ -1098,7 +1104,7 @@ class YarrGenerator : private MacroAssembler { if (m_dataAfterLabelPtr.isSet()) generator->m_expressionState.m_backtrackRecords.append(AlternativeBacktrackRecord(m_dataAfterLabelPtr, m_backtrackFromAfterParens)); - m_pattBacktrackJumps.link(generator); + m_afterBacktrackJumps.link(generator); if (m_term.quantityType == QuantifierGreedy) { // If this is -1 we have now tested with both with and without the parens. @@ -1138,14 +1144,14 @@ class YarrGenerator : private MacroAssembler { PatternTerm& m_term; int m_nestingLevel; unsigned m_subParenIndex; - ParenthesesTail* m_nextOuterParenTail; + JumpList* m_jumpListToPriorParen; Label m_nonGreedyTryParentheses; Label m_fallThrough; Label m_backtrackToLabel; Label m_backtrackFromAfterParens; DataLabelPtr m_dataAfterLabelPtr; - JumpList m_pattBacktrackJumps; JumpList m_withinBacktrackJumps; + JumpList m_afterBacktrackJumps; BacktrackDestination m_parenBacktrack; BacktrackDestination m_backtrack; bool m_doDirectBacktrack; @@ -1570,8 +1576,10 @@ class YarrGenerator : private MacroAssembler { JumpList successes; bool propogateBacktrack = false; - for (state.resetAlternative(); state.alternativeValid(); state.nextAlternative()) { + // Save current state's paren jump list for use with each alternative + JumpList* outerJumpList = state.getJumpListToPriorParen(); + for (state.resetAlternative(); state.alternativeValid(); state.nextAlternative(), state.setJumpListToPriorParen(outerJumpList)) { PatternAlternative* alternative = state.alternative(); optimizeAlternative(alternative); @@ -1638,13 +1646,21 @@ class YarrGenerator : private MacroAssembler { m_expressionState.incrementParenNestingLevel(); TermGenerationState parenthesesState(disjunction, state.checkedTotal); + + // Use the current state's jump list for the nested parentheses. + parenthesesState.setJumpListToPriorParen(state.getJumpListToPriorParen()); + generateParenthesesDisjunction(state.term(), parenthesesState, alternativeFrameLocation); // this expects that any backtracks back out of the parentheses will be in the // parenthesesState's m_backTrackJumps vector, and that if they need backtracking // they will have set an entry point on the parenthesesState's m_backtrackLabel. BacktrackDestination& parenthesesBacktrack = parenthesesState.getBacktrackDestination(); + BacktrackDestination& stateBacktrack = state.getBacktrackDestination(); + state.propagateBacktrackingFrom(this, parenthesesBacktrack); - state.getBacktrackDestination().copyBacktrackToLabel(parenthesesBacktrack); + stateBacktrack.propagateBacktrackToLabel(parenthesesBacktrack); + + state.setJumpListToPriorParen(parenthesesState.getJumpListToPriorParen()); m_expressionState.decrementParenNestingLevel(); } else { @@ -1670,14 +1686,14 @@ class YarrGenerator : private MacroAssembler { store32(index, Address(output, (term.parentheses.subpatternId << 1) * sizeof(int))); } - ParenthesesTail* parenthesesTail = m_expressionState.addParenthesesTail(term, state.getParenthesesTail()); + ParenthesesTail* parenthesesTail = m_expressionState.addParenthesesTail(term, state.getJumpListToPriorParen()); m_expressionState.incrementParenNestingLevel(); TermGenerationState parenthesesState(disjunction, state.checkedTotal); // Save the parenthesesTail for backtracking from nested parens to this one. - parenthesesState.setParenthesesTail(parenthesesTail); + parenthesesState.setJumpListToPriorParen(&parenthesesTail->m_withinBacktrackJumps); // generate the body of the parentheses generateParenthesesDisjunction(state.term(), parenthesesState, alternativeFrameLocation); @@ -1701,6 +1717,8 @@ class YarrGenerator : private MacroAssembler { parenthesesTail->processBacktracks(this, state, parenthesesState, nonGreedyTryParentheses, label()); + state.setJumpListToPriorParen(&parenthesesTail->m_afterBacktrackJumps); + parenthesesState.getBacktrackDestination().clear(); if (term.quantityType == QuantifierNonGreedy) @@ -1960,6 +1978,7 @@ class YarrGenerator : private MacroAssembler { // if there are any more alternatives, plant the check for input before looping. if (state.alternativeValid()) { + state.setJumpListToPriorParen(0); PatternAlternative* nextAlternative = state.alternative(); if (!setRepeatAlternativeLabels && !nextAlternative->onceThrough()) { // We have handled non-repeating alternatives, jump to next iteration |