Bug 1629670: Change ForceByteCode to CodeKind r=mgaudet

The current ForceByteCodeEnum is a glorified boolean. This patch replaces it with a three-value bytecode/jitcode/either enum, which will make our tiering-up logic slightly nicer in the next patch.

Differential Revision: https://phabricator.services.mozilla.com/D70951

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Iain Ireland 2020-04-15 20:54:38 +00:00
Родитель 8dad7c3e77
Коммит c467363eb7
2 изменённых файлов: 32 добавлений и 25 удалений

Просмотреть файл

@ -576,7 +576,7 @@ JSLinearString* RegExpObject::toString(JSContext* cx) const {
/* static */
bool RegExpShared::dumpBytecode(JSContext* cx, MutableHandleRegExpShared re,
HandleLinearString input) {
if (!RegExpShared::compileIfNecessary(cx, re, input, ForceByteCode)) {
if (!RegExpShared::compileIfNecessary(cx, re, input, CodeKind::Bytecode)) {
return false;
}
@ -992,25 +992,26 @@ void RegExpShared::finalize(JSFreeOp* fop) {
/* static */
bool RegExpShared::compile(JSContext* cx, MutableHandleRegExpShared re,
HandleLinearString input, ForceByteCodeEnum force) {
HandleLinearString input,
RegExpShared::CodeKind codeKind) {
TraceLoggerThread* logger = TraceLoggerForCurrentThread(cx);
AutoTraceLog logCompile(logger, TraceLogger_IrregexpCompile);
RootedAtom pattern(cx, re->getSource());
return compile(cx, re, pattern, input, force);
return compile(cx, re, pattern, input, codeKind);
}
#ifdef ENABLE_NEW_REGEXP
bool RegExpShared::compile(JSContext* cx, MutableHandleRegExpShared re,
HandleAtom pattern, HandleLinearString input,
ForceByteCodeEnum force) {
RegExpShared::CodeKind code) {
MOZ_CRASH("TODO");
}
/* static */
bool RegExpShared::compileIfNecessary(JSContext* cx,
MutableHandleRegExpShared re,
HandleLinearString input,
ForceByteCodeEnum force) {
RegExpShared::CodeKind codeKind) {
bool needsCompile = false;
if (re->kind() == RegExpShared::Kind::Unparsed) {
needsCompile = true;
@ -1034,7 +1035,7 @@ RegExpRunStatus RegExpShared::execute(JSContext* cx,
// TODO: Add tracelogger support
/* Compile the code at point-of-use. */
if (!compileIfNecessary(cx, re, input, DontForceByteCode)) {
if (!compileIfNecessary(cx, re, input, RegExpShared::CodeKind::Any)) {
return RegExpRunStatus_Error;
}
@ -1119,7 +1120,7 @@ void RegExpShared::useRegExpMatch(size_t pairCount) {
/* static */
bool RegExpShared::compile(JSContext* cx, MutableHandleRegExpShared re,
HandleAtom pattern, HandleLinearString input,
ForceByteCodeEnum force) {
RegExpShared::CodeKind codeKind) {
if (!re->ignoreCase() && !StringHasRegExpMetaChars(pattern)) {
re->canStringMatch = true;
}
@ -1139,12 +1140,12 @@ bool RegExpShared::compile(JSContext* cx, MutableHandleRegExpShared re,
// Add one to account for the whole-match capture.
re->pairCount_ = data.capture_count + 1;
bool forceBytecode = codeKind == RegExpShared::CodeKind::Bytecode;
JitCodeTables tables;
irregexp::RegExpCode code = irregexp::CompilePattern(
cx, allocScope.alloc(), re, &data, input, false /* global() */,
re->ignoreCase(), input->hasLatin1Chars(),
/*match_only = */ false, force == ForceByteCode, re->sticky(),
re->unicode(), tables);
re->ignoreCase(), input->hasLatin1Chars(), /*match_only = */ false,
forceBytecode, re->sticky(), re->unicode(), tables);
if (code.empty()) {
return false;
}
@ -1178,11 +1179,11 @@ bool RegExpShared::compile(JSContext* cx, MutableHandleRegExpShared re,
bool RegExpShared::compileIfNecessary(JSContext* cx,
MutableHandleRegExpShared re,
HandleLinearString input,
ForceByteCodeEnum force) {
if (re->isCompiled(input->hasLatin1Chars(), force)) {
RegExpShared::CodeKind codeKind) {
if (re->isCompiled(input->hasLatin1Chars(), codeKind)) {
return true;
}
return compile(cx, re, input, force);
return compile(cx, re, input, codeKind);
}
/* static */
@ -1194,7 +1195,7 @@ RegExpRunStatus RegExpShared::execute(JSContext* cx,
TraceLoggerThread* logger = TraceLoggerForCurrentThread(cx);
/* Compile the code at point-of-use. */
if (!compileIfNecessary(cx, re, input, DontForceByteCode)) {
if (!compileIfNecessary(cx, re, input, RegExpShared::CodeKind::Any)) {
return RegExpRunStatus_Error;
}
@ -1260,7 +1261,7 @@ RegExpRunStatus RegExpShared::execute(JSContext* cx,
} while (false);
// Compile bytecode for the RegExp if necessary.
if (!compileIfNecessary(cx, re, input, ForceByteCode)) {
if (!compileIfNecessary(cx, re, input, RegExpShared::CodeKind::Bytecode)) {
return RegExpRunStatus_Error;
}

Просмотреть файл

@ -74,8 +74,8 @@ struct RegExpByteCodeHeader {
*/
class RegExpShared : public gc::TenuredCell {
public:
enum ForceByteCodeEnum { DontForceByteCode, ForceByteCode };
enum class Kind { Unparsed, Atom, RegExp };
enum class CodeKind { Bytecode, Jitcode, Any };
#ifdef ENABLE_NEW_REGEXP
using ByteCode = js::irregexp::ByteArrayData;
@ -94,8 +94,16 @@ class RegExpShared : public gc::TenuredCell {
WeakHeapPtr<jit::JitCode*> jitCode;
ByteCode* byteCode = nullptr;
bool compiled(ForceByteCodeEnum force = DontForceByteCode) const {
return byteCode || (force == DontForceByteCode && jitCode);
bool compiled(CodeKind kind = CodeKind::Any) const {
switch (kind) {
case CodeKind::Bytecode:
return !!byteCode;
case CodeKind::Jitcode:
return !!jitCode;
case CodeKind::Any:
return !!byteCode || !!jitCode;
}
MOZ_CRASH("Unreachable");
}
size_t byteCodeLength() const {
@ -135,14 +143,13 @@ class RegExpShared : public gc::TenuredCell {
RegExpShared(JSAtom* source, JS::RegExpFlags flags);
static bool compile(JSContext* cx, MutableHandleRegExpShared res,
HandleLinearString input, ForceByteCodeEnum force);
HandleLinearString input, CodeKind code);
static bool compile(JSContext* cx, MutableHandleRegExpShared res,
HandleAtom pattern, HandleLinearString input,
ForceByteCodeEnum force);
CodeKind code);
static bool compileIfNecessary(JSContext* cx, MutableHandleRegExpShared res,
HandleLinearString input,
ForceByteCodeEnum force);
HandleLinearString input, CodeKind code);
const RegExpCompilation& compilation(bool latin1) const {
return compilationArray[CompilationIndex(latin1)];
@ -218,9 +225,8 @@ class RegExpShared : public gc::TenuredCell {
bool unicode() const { return flags.unicode(); }
bool sticky() const { return flags.sticky(); }
bool isCompiled(bool latin1,
ForceByteCodeEnum force = DontForceByteCode) const {
return compilation(latin1).compiled(force);
bool isCompiled(bool latin1, CodeKind codeKind = CodeKind::Any) const {
return compilation(latin1).compiled(codeKind);
}
bool isCompiled() const { return isCompiled(true) || isCompiled(false); }