From 38794a041f549d6fc0a6626398422c9a89f5ba38 Mon Sep 17 00:00:00 2001 From: Cameron Kaiser Date: Thu, 5 Mar 2020 21:19:41 -0800 Subject: [PATCH] #593: M1608256 (and clean up code) --- js/src/jit/IonAnalysis.cpp | 76 -------------------------------------- js/src/jit/IonAnalysis.h | 3 -- js/src/jit/IonBuilder.cpp | 6 +-- js/src/jit/Lowering.cpp | 62 ------------------------------- js/src/jit/MIR.h | 13 ++----- 5 files changed, 5 insertions(+), 155 deletions(-) diff --git a/js/src/jit/IonAnalysis.cpp b/js/src/jit/IonAnalysis.cpp index 77cc56763..0afc35f47 100644 --- a/js/src/jit/IonAnalysis.cpp +++ b/js/src/jit/IonAnalysis.cpp @@ -1875,82 +1875,6 @@ jit::ApplyTypeInformation(MIRGenerator* mir, MIRGraph& graph) return true; } -bool -jit::MakeMRegExpHoistable(MIRGenerator* mir, MIRGraph& graph) -{ - MOZ_CRASH("thou may not hoist this regex"); - return false; -#if(0) - // If we are compiling try blocks, regular expressions may be observable - // from catch blocks (which Ion does not compile). For now just disable the - // pass in this case. - if (graph.hasTryBlock()) - return true; - - for (ReversePostorderIterator block(graph.rpoBegin()); block != graph.rpoEnd(); block++) { - if (mir->shouldCancel("MakeMRegExpHoistable outer loop")) - return false; - - for (MDefinitionIterator iter(*block); iter; iter++) { - if (mir->shouldCancel("MakeMRegExpHoistable inner loop")) - return false; - - if (!iter->isRegExp()) - continue; - - MRegExp* regexp = iter->toRegExp(); - - // Test if MRegExp is hoistable by looking at all uses. - bool hoistable = true; - for (MUseIterator i = regexp->usesBegin(); i != regexp->usesEnd(); i++) { - if (mir->shouldCancel("IsRegExpHoistable inner loop")) - return false; - - // Ignore resume points. At this point all uses are listed. - // No DCE or GVN or something has happened. - if (i->consumer()->isResumePoint()) - continue; - - MOZ_ASSERT(i->consumer()->isDefinition()); - - // All MRegExp* MIR's don't adjust the regexp. - MDefinition* use = i->consumer()->toDefinition(); - if (use->isRegExpReplace()) - continue; - if (use->isRegExpExec()) - continue; - if (use->isRegExpTest()) - continue; - - hoistable = false; - break; - } - - if (!hoistable) - continue; - - // Make MRegExp hoistable - regexp->setMovable(); - - // That would be incorrect for global/sticky, because lastIndex could be wrong. - // Therefore setting the lastIndex to 0. That is faster than a not movable regexp. - RegExpObject* source = regexp->source(); - if (source->sticky() || source->global()) { - MOZ_ASSERT(regexp->mustClone()); - MConstant* zero = MConstant::New(graph.alloc(), Int32Value(0)); - regexp->block()->insertAfter(regexp, zero); - - MStoreFixedSlot* lastIndex = - MStoreFixedSlot::New(graph.alloc(), regexp, RegExpObject::lastIndexSlot(), zero); - regexp->block()->insertAfter(zero, lastIndex); - } - } - } - - return true; -#endif -} - bool jit::RenumberBlocks(MIRGraph& graph) { diff --git a/js/src/jit/IonAnalysis.h b/js/src/jit/IonAnalysis.h index c7726d269..8a28c3089 100644 --- a/js/src/jit/IonAnalysis.h +++ b/js/src/jit/IonAnalysis.h @@ -53,9 +53,6 @@ EliminateDeadCode(MIRGenerator* mir, MIRGraph& graph); bool ApplyTypeInformation(MIRGenerator* mir, MIRGraph& graph); -bool -MakeMRegExpHoistable(MIRGenerator* mir, MIRGraph& graph); - bool RenumberBlocks(MIRGraph& graph); diff --git a/js/src/jit/IonBuilder.cpp b/js/src/jit/IonBuilder.cpp index f62358572..d3637d7cc 100644 --- a/js/src/jit/IonBuilder.cpp +++ b/js/src/jit/IonBuilder.cpp @@ -12810,7 +12810,6 @@ IonBuilder::jsop_regexp(RegExpObject* reobj) // then check if this regex object only flows into known natives and can // avoid cloning in this case. - bool mustClone = true; TypeSet::ObjectKey* globalKey = TypeSet::ObjectKey::get(&script()->global()); if (!globalKey->hasFlags(constraints(), OBJECT_FLAG_REGEXP_FLAGS_SET)) { #ifdef DEBUG @@ -12824,12 +12823,9 @@ IonBuilder::jsop_regexp(RegExpObject* reobj) MOZ_ASSERT((origFlags & staticsFlags) == staticsFlags); } #endif - - if (!reobj->global() && !reobj->sticky()) - mustClone = false; } - MRegExp* regexp = MRegExp::New(alloc(), constraints(), reobj, mustClone); + MRegExp* regexp = MRegExp::New(alloc(), constraints(), reobj); current->add(regexp); current->push(regexp); diff --git a/js/src/jit/Lowering.cpp b/js/src/jit/Lowering.cpp index 57d25bae8..fbe99f519 100644 --- a/js/src/jit/Lowering.cpp +++ b/js/src/jit/Lowering.cpp @@ -2034,68 +2034,6 @@ LIRGenerator::visitToObjectOrNull(MToObjectOrNull* ins) assignSafepoint(lir, ins); } -static bool -MustCloneRegExpForCall(MCall* call, uint32_t useIndex) -{ - // We have a regex literal flowing into a call. Return |false| iff - // this is a native call that does not let the regex escape. - - JSFunction* target = call->getSingleTarget(); - if (!target || !target->isNative()) - return true; - - if (useIndex == MCall::IndexOfThis() && - (target->native() == regexp_exec || target->native() == regexp_test)) - { - return false; - } - - if (useIndex == MCall::IndexOfArgument(0) && - (target->native() == str_split || - target->native() == str_replace || - target->native() == str_match || - target->native() == str_search)) - { - return false; - } - - return true; -} - - -static bool -MustCloneRegExp(MRegExp* regexp) -{ - if (regexp->mustClone()) - return true; - - // If this regex literal only flows into known natives that don't let - // it escape, we don't have to clone it. - - for (MUseIterator iter(regexp->usesBegin()); iter != regexp->usesEnd(); iter++) { - MNode* node = iter->consumer(); - if (!node->isDefinition()) - return true; - - MDefinition* def = node->toDefinition(); - if (def->isRegExpTest()) { - MRegExpTest* test = def->toRegExpTest(); - if (test->indexOf(*iter) == 1) { - // Optimized RegExp.prototype.test. - MOZ_ASSERT(test->regexp() == regexp); - continue; - } - } else if (def->isCall()) { - MCall* call = def->toCall(); - if (!MustCloneRegExpForCall(call, call->indexOf(*iter))) - continue; - } - - return true; - } - return false; -} - void LIRGenerator::visitRegExp(MRegExp* ins) { diff --git a/js/src/jit/MIR.h b/js/src/jit/MIR.h index dabaeed53..b7c0b4522 100644 --- a/js/src/jit/MIR.h +++ b/js/src/jit/MIR.h @@ -7453,11 +7453,9 @@ class MDefFun class MRegExp : public MNullaryInstruction { CompilerGCPointer source_; - bool mustClone_; - MRegExp(CompilerConstraintList* constraints, RegExpObject* source, bool mustClone) - : source_(source), - mustClone_(mustClone) + MRegExp(CompilerConstraintList* constraints, RegExpObject* source) + : source_(source) { setResultType(MIRType_Object); setResultTypeSet(MakeSingletonTypeSet(constraints, source)); @@ -7467,14 +7465,11 @@ class MRegExp : public MNullaryInstruction INSTRUCTION_HEADER(RegExp) static MRegExp* New(TempAllocator& alloc, CompilerConstraintList* constraints, - RegExpObject* source, bool mustClone) + RegExpObject* source) { - return new(alloc) MRegExp(constraints, source, mustClone); + return new(alloc) MRegExp(constraints, source); } - bool mustClone() const { - return mustClone_; - } RegExpObject* source() const { return source_; }