Skip to content

Commit

Permalink
Bug 1831314 part 6 - Remove now-unused RegExpTester. r=iain
Browse files Browse the repository at this point in the history
  • Loading branch information
jandem committed May 12, 2023
1 parent 128e900 commit 3146c8d
Show file tree
Hide file tree
Showing 19 changed files with 3 additions and 244 deletions.
59 changes: 0 additions & 59 deletions js/src/builtin/RegExp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1287,65 +1287,6 @@ bool js::RegExpSearcherRaw(JSContext* cx, HandleObject regexp,
return RegExpSearcherImpl(cx, regexp, input, lastIndex, result);
}

/*
* ES 2017 draft rev 6a13789aa9e7c6de4e96b7d3e24d9e6eba6584ad 21.2.5.2.2
* steps 3, 9-14, except 12.a.i, 12.c.i.1.
*/
bool js::RegExpTester(JSContext* cx, unsigned argc, Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
MOZ_ASSERT(args.length() == 3);
MOZ_ASSERT(IsRegExpObject(args[0]));
MOZ_ASSERT(args[1].isString());
MOZ_ASSERT(args[2].isNumber());

RootedObject regexp(cx, &args[0].toObject());
RootedString string(cx, args[1].toString());

int32_t lastIndex;
MOZ_ALWAYS_TRUE(ToInt32(cx, args[2], &lastIndex));

/* Steps 3, 9-14, except 12.a.i, 12.c.i.1. */
VectorMatchPairs matches;
RegExpRunStatus status =
ExecuteRegExp(cx, regexp, string, lastIndex, &matches);

if (status == RegExpRunStatus_Error) {
return false;
}

if (status == RegExpRunStatus_Success) {
int32_t endIndex = matches[0].limit;
args.rval().setInt32(endIndex);
} else {
args.rval().setInt32(-1);
}
return true;
}

/*
* Separate interface for use by the JITs.
* This code cannot re-enter JIT code.
*/
bool js::RegExpTesterRaw(JSContext* cx, HandleObject regexp, HandleString input,
int32_t lastIndex, int32_t* endIndex) {
MOZ_ASSERT(lastIndex >= 0);

VectorMatchPairs matches;
RegExpRunStatus status =
ExecuteRegExp(cx, regexp, input, lastIndex, &matches);

if (status == RegExpRunStatus_Success) {
*endIndex = matches[0].limit;
return true;
}
if (status == RegExpRunStatus_Success_NotFound) {
*endIndex = -1;
return true;
}

return false;
}

template <bool CalledFromJit>
bool js::RegExpBuiltinExecMatchRaw(JSContext* cx, Handle<RegExpObject*> regexp,
HandleString input, int32_t lastIndex,
Expand Down
6 changes: 0 additions & 6 deletions js/src/builtin/RegExp.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@ JSObject* InitRegExpClass(JSContext* cx, HandleObject obj);
MatchPairs* maybeMatches,
int32_t* result);

[[nodiscard]] extern bool RegExpTester(JSContext* cx, unsigned argc, Value* vp);

[[nodiscard]] extern bool RegExpTesterRaw(JSContext* cx, HandleObject regexp,
HandleString input, int32_t lastIndex,
int32_t* endIndex);

template <bool CalledFromJit>
[[nodiscard]] extern bool RegExpBuiltinExecMatchRaw(
JSContext* cx, Handle<RegExpObject*> regexp, HandleString input,
Expand Down
11 changes: 2 additions & 9 deletions js/src/jit/CacheIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6695,7 +6695,7 @@ AttachDecision InlinableNativeIRGenerator::tryAttachIntrinsicRegExpExec() {
return AttachDecision::Attach;
}

AttachDecision InlinableNativeIRGenerator::tryAttachRegExpMatcherSearcherTester(
AttachDecision InlinableNativeIRGenerator::tryAttachRegExpMatcherSearcher(
InlinableNative native) {
// Self-hosted code calls this with (object, string, number) arguments.
MOZ_ASSERT(argc_ == 3);
Expand Down Expand Up @@ -6736,12 +6736,6 @@ AttachDecision InlinableNativeIRGenerator::tryAttachRegExpMatcherSearcherTester(
trackAttached("RegExpSearcher");
break;

case InlinableNative::RegExpTester:
writer.callRegExpTesterResult(reId, inputId, lastIndexId);
writer.returnFromIC();
trackAttached("RegExpTester");
break;

default:
MOZ_CRASH("Unexpected native");
}
Expand Down Expand Up @@ -10598,8 +10592,7 @@ AttachDecision InlinableNativeIRGenerator::tryAttachStub() {
/* isPossiblyWrapped = */ true);
case InlinableNative::RegExpMatcher:
case InlinableNative::RegExpSearcher:
case InlinableNative::RegExpTester:
return tryAttachRegExpMatcherSearcherTester(native);
return tryAttachRegExpMatcherSearcher(native);
case InlinableNative::RegExpPrototypeOptimizable:
return tryAttachRegExpPrototypeOptimizable();
case InlinableNative::RegExpInstanceOptimizable:
Expand Down
22 changes: 0 additions & 22 deletions js/src/jit/CacheIRCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8150,28 +8150,6 @@ bool CacheIRCompiler::emitCallRegExpSearcherResult(ObjOperandId regexpId,
return true;
}

bool CacheIRCompiler::emitCallRegExpTesterResult(ObjOperandId regexpId,
StringOperandId inputId,
Int32OperandId lastIndexId) {
JitSpew(JitSpew_Codegen, "%s", __FUNCTION__);

AutoCallVM callvm(masm, this, allocator);

Register regexp = allocator.useRegister(masm, regexpId);
Register input = allocator.useRegister(masm, inputId);
Register lastIndex = allocator.useRegister(masm, lastIndexId);

callvm.prepare();
masm.Push(lastIndex);
masm.Push(input);
masm.Push(regexp);

using Fn = bool (*)(JSContext*, HandleObject regexp, HandleString input,
int32_t lastIndex, int32_t* result);
callvm.call<Fn, RegExpTesterRaw>();
return true;
}

bool CacheIRCompiler::emitRegExpBuiltinExecMatchResult(
ObjOperandId regexpId, StringOperandId inputId) {
JitSpew(JitSpew_Codegen, "%s", __FUNCTION__);
Expand Down
2 changes: 1 addition & 1 deletion js/src/jit/CacheIRGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ class MOZ_RAII InlinableNativeIRGenerator {
AttachDecision tryAttachGuardToClass(InlinableNative native);
AttachDecision tryAttachHasClass(const JSClass* clasp,
bool isPossiblyWrapped);
AttachDecision tryAttachRegExpMatcherSearcherTester(InlinableNative native);
AttachDecision tryAttachRegExpMatcherSearcher(InlinableNative native);
AttachDecision tryAttachRegExpPrototypeOptimizable();
AttachDecision tryAttachRegExpInstanceOptimizable();
AttachDecision tryAttachIntrinsicRegExpBuiltinExec();
Expand Down
9 changes: 0 additions & 9 deletions js/src/jit/CacheIROps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,6 @@
input: StringId
lastIndex: Int32Id

- name: CallRegExpTesterResult
shared: true
transpile: true
cost_estimate: 5
args:
regexp: ObjId
input: StringId
lastIndex: Int32Id

- name: RegExpBuiltinExecMatchResult
shared: true
transpile: true
Expand Down
55 changes: 0 additions & 55 deletions js/src/jit/CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3219,61 +3219,6 @@ JitCode* JitRealm::generateRegExpTesterStub(JSContext* cx) {
return code;
}

class OutOfLineRegExpTester : public OutOfLineCodeBase<CodeGenerator> {
LRegExpTester* lir_;

public:
explicit OutOfLineRegExpTester(LRegExpTester* lir) : lir_(lir) {}

void accept(CodeGenerator* codegen) override {
codegen->visitOutOfLineRegExpTester(this);
}

LRegExpTester* lir() const { return lir_; }
};

void CodeGenerator::visitOutOfLineRegExpTester(OutOfLineRegExpTester* ool) {
LRegExpTester* lir = ool->lir();
Register lastIndex = ToRegister(lir->lastIndex());
Register input = ToRegister(lir->string());
Register regexp = ToRegister(lir->regexp());

pushArg(lastIndex);
pushArg(input);
pushArg(regexp);

// We are not using oolCallVM because we are in a Call, and that live
// registers are already saved by the the register allocator.
using Fn = bool (*)(JSContext* cx, HandleObject regexp, HandleString input,
int32_t lastIndex, int32_t* result);
callVM<Fn, RegExpTesterRaw>(lir);

masm.jump(ool->rejoin());
}

void CodeGenerator::visitRegExpTester(LRegExpTester* lir) {
MOZ_ASSERT(ToRegister(lir->regexp()) == RegExpTesterRegExpReg);
MOZ_ASSERT(ToRegister(lir->string()) == RegExpTesterStringReg);
MOZ_ASSERT(ToRegister(lir->lastIndex()) == RegExpTesterLastIndexReg);
MOZ_ASSERT(ToRegister(lir->output()) == ReturnReg);

static_assert(RegExpTesterRegExpReg != ReturnReg);
static_assert(RegExpTesterStringReg != ReturnReg);
static_assert(RegExpTesterLastIndexReg != ReturnReg);

OutOfLineRegExpTester* ool = new (alloc()) OutOfLineRegExpTester(lir);
addOutOfLineCode(ool, lir->mir());

const JitRealm* jitRealm = gen->realm->jitRealm();
JitCode* regExpTesterStub =
jitRealm->regExpTesterStubNoBarrier(&realmStubsToReadBarrier_);
masm.call(regExpTesterStub);

masm.branch32(Assembler::Equal, ReturnReg, Imm32(RegExpTesterResultFailed),
ool->entry());
masm.bind(ool->rejoin());
}

class OutOfLineRegExpExecTest : public OutOfLineCodeBase<CodeGenerator> {
LRegExpExecTest* lir_;

Expand Down
2 changes: 0 additions & 2 deletions js/src/jit/CodeGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class OutOfLineIsCallable;
class OutOfLineIsConstructor;
class OutOfLineRegExpMatcher;
class OutOfLineRegExpSearcher;
class OutOfLineRegExpTester;
class OutOfLineRegExpExecMatch;
class OutOfLineRegExpExecTest;
class OutOfLineRegExpPrototypeOptimizable;
Expand Down Expand Up @@ -138,7 +137,6 @@ class CodeGenerator final : public CodeGeneratorSpecific {

void visitOutOfLineRegExpMatcher(OutOfLineRegExpMatcher* ool);
void visitOutOfLineRegExpSearcher(OutOfLineRegExpSearcher* ool);
void visitOutOfLineRegExpTester(OutOfLineRegExpTester* ool);
void visitOutOfLineRegExpExecMatch(OutOfLineRegExpExecMatch* ool);
void visitOutOfLineRegExpExecTest(OutOfLineRegExpExecTest* ool);
void visitOutOfLineRegExpPrototypeOptimizable(
Expand Down
1 change: 0 additions & 1 deletion js/src/jit/InlinableNatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ bool js::jit::CanInlineNativeCrossRealm(InlinableNative native) {
case InlinableNative::IsPossiblyWrappedRegExpObject:
case InlinableNative::RegExpMatcher:
case InlinableNative::RegExpSearcher:
case InlinableNative::RegExpTester:
case InlinableNative::RegExpPrototypeOptimizable:
case InlinableNative::RegExpInstanceOptimizable:
case InlinableNative::GetFirstDollarIndex:
Expand Down
1 change: 0 additions & 1 deletion js/src/jit/InlinableNatives.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@
\
_(RegExpMatcher) \
_(RegExpSearcher) \
_(RegExpTester) \
_(IsRegExpObject) \
_(IsPossiblyWrappedRegExpObject) \
_(RegExpPrototypeOptimizable) \
Expand Down
9 changes: 0 additions & 9 deletions js/src/jit/LIROps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1491,15 +1491,6 @@
call_instruction: true
mir_op: true

- name: RegExpTester
result_type: WordSized
operands:
regexp: WordSized
string: WordSized
lastIndex: WordSized
call_instruction: true
mir_op: true

- name: RegExpExecMatch
result_type: BoxedValue
operands:
Expand Down
13 changes: 0 additions & 13 deletions js/src/jit/Lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3133,19 +3133,6 @@ void LIRGenerator::visitRegExpSearcher(MRegExpSearcher* ins) {
assignSafepoint(lir, ins);
}

void LIRGenerator::visitRegExpTester(MRegExpTester* ins) {
MOZ_ASSERT(ins->regexp()->type() == MIRType::Object);
MOZ_ASSERT(ins->string()->type() == MIRType::String);
MOZ_ASSERT(ins->lastIndex()->type() == MIRType::Int32);

LRegExpTester* lir = new (alloc()) LRegExpTester(
useFixedAtStart(ins->regexp(), RegExpTesterRegExpReg),
useFixedAtStart(ins->string(), RegExpTesterStringReg),
useFixedAtStart(ins->lastIndex(), RegExpTesterLastIndexReg));
defineReturn(lir, ins);
assignSafepoint(lir, ins);
}

void LIRGenerator::visitRegExpExecMatch(MRegExpExecMatch* ins) {
MOZ_ASSERT(ins->regexp()->type() == MIRType::Object);
MOZ_ASSERT(ins->string()->type() == MIRType::String);
Expand Down
9 changes: 0 additions & 9 deletions js/src/jit/MIROps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1084,15 +1084,6 @@
possibly_calls: true
can_recover: true

- name: RegExpTester
operands:
regexp: Object
string: String
lastIndex: Int32
result_type: Int32
possibly_calls: true
can_recover: true

- name: RegExpExecMatch
operands:
regexp: Object
Expand Down
22 changes: 0 additions & 22 deletions js/src/jit/Recover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1469,28 +1469,6 @@ bool RRegExpSearcher::recover(JSContext* cx, SnapshotIterator& iter) const {
return true;
}

bool MRegExpTester::writeRecoverData(CompactBufferWriter& writer) const {
MOZ_ASSERT(canRecoverOnBailout());
writer.writeUnsigned(uint32_t(RInstruction::Recover_RegExpTester));
return true;
}

RRegExpTester::RRegExpTester(CompactBufferReader& reader) {}

bool RRegExpTester::recover(JSContext* cx, SnapshotIterator& iter) const {
RootedString string(cx, iter.read().toString());
RootedObject regexp(cx, &iter.read().toObject());
int32_t lastIndex = iter.read().toInt32();
int32_t endIndex;

if (!js::RegExpTesterRaw(cx, regexp, string, lastIndex, &endIndex)) {
return false;
}

iter.storeInstructionResult(Int32Value(endIndex));
return true;
}

bool MTypeOf::writeRecoverData(CompactBufferWriter& writer) const {
MOZ_ASSERT(canRecoverOnBailout());
writer.writeUnsigned(uint32_t(RInstruction::Recover_TypeOf));
Expand Down
9 changes: 0 additions & 9 deletions js/src/jit/Recover.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ namespace jit {
_(NaNToZero) \
_(RegExpMatcher) \
_(RegExpSearcher) \
_(RegExpTester) \
_(StringReplace) \
_(Substr) \
_(TypeOf) \
Expand Down Expand Up @@ -694,14 +693,6 @@ class RRegExpSearcher final : public RInstruction {
SnapshotIterator& iter) const override;
};

class RRegExpTester final : public RInstruction {
public:
RINSTRUCTION_HEADER_NUM_OP_(RegExpTester, 3)

[[nodiscard]] bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
};

class RStringReplace final : public RInstruction {
private:
bool isFlatReplacement_;
Expand Down
1 change: 0 additions & 1 deletion js/src/jit/VMFunctionList-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ namespace jit {
_(RegExpBuiltinExecTestRaw, js::RegExpBuiltinExecTestRaw<true>) \
_(RegExpMatcherRaw, js::RegExpMatcherRaw) \
_(RegExpSearcherRaw, js::RegExpSearcherRaw) \
_(RegExpTesterRaw, js::RegExpTesterRaw) \
_(SameValue, js::SameValue) \
_(SetArrayLength, js::jit::SetArrayLength) \
_(SetElementMegamorphicNoCache, js::jit::SetElementMegamorphic<false>) \
Expand Down
14 changes: 0 additions & 14 deletions js/src/jit/WarpCacheIRTranspiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3517,20 +3517,6 @@ bool WarpCacheIRTranspiler::emitCallRegExpSearcherResult(
return resumeAfter(searcher);
}

bool WarpCacheIRTranspiler::emitCallRegExpTesterResult(
ObjOperandId regexpId, StringOperandId inputId,
Int32OperandId lastIndexId) {
MDefinition* regexp = getOperand(regexpId);
MDefinition* input = getOperand(inputId);
MDefinition* lastIndex = getOperand(lastIndexId);

auto* tester = MRegExpTester::New(alloc(), regexp, input, lastIndex);
addEffectful(tester);
pushResult(tester);

return resumeAfter(tester);
}

bool WarpCacheIRTranspiler::emitRegExpBuiltinExecMatchResult(
ObjOperandId regexpId, StringOperandId inputId) {
MDefinition* regexp = getOperand(regexpId);
Expand Down
1 change: 0 additions & 1 deletion js/src/jit/WarpOracle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,6 @@ AbortReasonOr<Ok> WarpScriptOracle::maybeInlineIC(WarpOpSnapshotList& snapshots,
return abort(AbortReason::Error);
}
break;
case CacheOp::CallRegExpTesterResult:
case CacheOp::RegExpBuiltinExecTestResult:
if (!cx_->realm()->jitRealm()->ensureRegExpTesterStubExists(cx_)) {
return abort(AbortReason::Error);
Expand Down
Loading

0 comments on commit 3146c8d

Please sign in to comment.