Commit 6155b33a authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

[regexp] Remove dead DispatchTableConstructor

Bug: v8:9359
Change-Id: I1b490c928ed884f4ad33e005699f98614be75233
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1662306
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Auto-Submit: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62242}
parent 2c2dd893
......@@ -213,15 +213,6 @@ int TextElement::length() const {
UNREACHABLE();
}
DispatchTable* ChoiceNode::GetTable(bool ignore_case) {
if (table_ == nullptr) {
table_ = new (zone()) DispatchTable(zone());
DispatchTableConstructor cons(table_, ignore_case, zone());
cons.BuildTable(this);
}
return table_;
}
class RecursionCheck {
public:
explicit RecursionCheck(RegExpCompiler* compiler) : compiler_(compiler) {
......@@ -3606,107 +3597,6 @@ void TextNode::FillInBMInfo(Isolate* isolate, int initial_offset, int budget,
if (initial_offset == 0) set_bm_info(not_at_start, bm);
}
// -------------------------------------------------------------------
// Dispatch table construction
void DispatchTableConstructor::VisitEnd(EndNode* that) {
AddRange(CharacterRange::Everything());
}
void DispatchTableConstructor::BuildTable(ChoiceNode* node) {
node->set_being_calculated(true);
ZoneList<GuardedAlternative>* alternatives = node->alternatives();
for (int i = 0; i < alternatives->length(); i++) {
set_choice_index(i);
alternatives->at(i).node()->Accept(this);
}
node->set_being_calculated(false);
}
class AddDispatchRange {
public:
explicit AddDispatchRange(DispatchTableConstructor* constructor)
: constructor_(constructor) {}
void Call(uc32 from, DispatchTable::Entry entry);
private:
DispatchTableConstructor* constructor_;
};
void AddDispatchRange::Call(uc32 from, DispatchTable::Entry entry) {
constructor_->AddRange(CharacterRange::Range(from, entry.to()));
}
void DispatchTableConstructor::VisitChoice(ChoiceNode* node) {
if (node->being_calculated()) return;
DispatchTable* table = node->GetTable(ignore_case_);
AddDispatchRange adder(this);
table->ForEach(&adder);
}
void DispatchTableConstructor::VisitBackReference(BackReferenceNode* that) {
// TODO(160): Find the node that we refer back to and propagate its start
// set back to here. For now we just accept anything.
AddRange(CharacterRange::Everything());
}
void DispatchTableConstructor::VisitAssertion(AssertionNode* that) {
RegExpNode* target = that->on_success();
target->Accept(this);
}
static int CompareRangeByFrom(const CharacterRange* a,
const CharacterRange* b) {
return Compare<uc16>(a->from(), b->from());
}
void DispatchTableConstructor::AddInverse(ZoneList<CharacterRange>* ranges) {
ranges->Sort(CompareRangeByFrom);
uc16 last = 0;
for (int i = 0; i < ranges->length(); i++) {
CharacterRange range = ranges->at(i);
if (last < range.from())
AddRange(CharacterRange::Range(last, range.from() - 1));
if (range.to() >= last) {
if (range.to() == String::kMaxCodePoint) {
return;
} else {
last = range.to() + 1;
}
}
}
AddRange(CharacterRange::Range(last, String::kMaxCodePoint));
}
void DispatchTableConstructor::VisitText(TextNode* that) {
TextElement elm = that->elements()->at(0);
switch (elm.text_type()) {
case TextElement::ATOM: {
uc16 c = elm.atom()->data()[0];
AddRange(CharacterRange::Range(c, c));
break;
}
case TextElement::CHAR_CLASS: {
RegExpCharacterClass* tree = elm.char_class();
ZoneList<CharacterRange>* ranges = tree->ranges(that->zone());
if (tree->is_negated()) {
AddInverse(ranges);
} else {
for (int i = 0; i < ranges->length(); i++) AddRange(ranges->at(i));
}
break;
}
default: {
UNIMPLEMENTED();
}
}
}
void DispatchTableConstructor::VisitAction(ActionNode* that) {
RegExpNode* target = that->on_success();
target->Accept(this);
}
// static
RegExpNode* RegExpCompiler::OptionallyStepBackToLeadSurrogate(
RegExpCompiler* compiler, RegExpNode* on_success, JSRegExp::Flags flags) {
......
......@@ -164,38 +164,6 @@ class DispatchTable : public ZoneObject {
ZoneSplayTree<Config> tree_;
};
// Node visitor used to add the start set of the alternatives to the
// dispatch table of a choice node.
class V8_EXPORT_PRIVATE DispatchTableConstructor : public NodeVisitor {
public:
DispatchTableConstructor(DispatchTable* table, bool ignore_case, Zone* zone)
: table_(table),
choice_index_(-1),
ignore_case_(ignore_case),
zone_(zone) {}
void BuildTable(ChoiceNode* node);
void AddRange(CharacterRange range) {
table()->AddRange(range, choice_index_, zone_);
}
void AddInverse(ZoneList<CharacterRange>* ranges);
#define DECLARE_VISIT(Type) virtual void Visit##Type(Type##Node* that);
FOR_EACH_NODE_TYPE(DECLARE_VISIT)
#undef DECLARE_VISIT
DispatchTable* table() { return table_; }
void set_choice_index(int value) { choice_index_ = value; }
protected:
DispatchTable* table_;
int choice_index_;
bool ignore_case_;
Zone* zone_;
};
// Details of a quick mask-compare check that can look ahead in the
// input stream.
class QuickCheckDetails {
......
......@@ -18,8 +18,7 @@ namespace internal {
class DotPrinterImpl : public NodeVisitor {
public:
DotPrinterImpl(std::ostream& os, bool ignore_case) // NOLINT
: os_(os), ignore_case_(ignore_case) {}
explicit DotPrinterImpl(std::ostream& os) : os_(os) {}
void PrintNode(const char* label, RegExpNode* node);
void Visit(RegExpNode* node);
void PrintAttributes(RegExpNode* from);
......@@ -29,7 +28,6 @@ class DotPrinterImpl : public NodeVisitor {
#undef DECLARE_VISIT
private:
std::ostream& os_;
bool ignore_case_;
};
void DotPrinterImpl::PrintNode(const char* label, RegExpNode* node) {
......@@ -153,22 +151,11 @@ void DotPrinterImpl::PrintAttributes(RegExpNode* that) {
<< " [style=dashed, color=grey, arrowhead=none];\n";
}
static const bool kPrintDispatchTable = false;
void DotPrinterImpl::VisitChoice(ChoiceNode* that) {
if (kPrintDispatchTable) {
os_ << " n" << that << " [shape=Mrecord, label=\"";
TableEntryHeaderPrinter header_printer(os_);
that->GetTable(ignore_case_)->ForEach(&header_printer);
os_ << "\"]\n";
PrintAttributes(that);
TableEntryBodyPrinter body_printer(os_, that);
that->GetTable(ignore_case_)->ForEach(&body_printer);
} else {
os_ << " n" << that << " [shape=Mrecord, label=\"?\"];\n";
for (int i = 0; i < that->alternatives()->length(); i++) {
GuardedAlternative alt = that->alternatives()->at(i);
os_ << " n" << that << " -> n" << alt.node();
}
os_ << " n" << that << " [shape=Mrecord, label=\"?\"];\n";
for (int i = 0; i < that->alternatives()->length(); i++) {
GuardedAlternative alt = that->alternatives()->at(i);
os_ << " n" << that << " -> n" << alt.node();
}
for (int i = 0; i < that->alternatives()->length(); i++) {
GuardedAlternative alt = that->alternatives()->at(i);
......@@ -326,11 +313,10 @@ void DispatchTable::Dump() {
#endif // DEBUG
void DotPrinter::DotPrint(const char* label, RegExpNode* node,
bool ignore_case) {
void DotPrinter::DotPrint(const char* label, RegExpNode* node) {
#ifdef DEBUG
StdoutStream os;
DotPrinterImpl printer(os, ignore_case);
DotPrinterImpl printer(os);
printer.PrintNode(label, node);
#endif // DEBUG
}
......
......@@ -14,7 +14,7 @@ class RegExpNode;
class DotPrinter final : public AllStatic {
public:
static void DotPrint(const char* label, RegExpNode* node, bool ignore_case);
static void DotPrint(const char* label, RegExpNode* node);
};
} // namespace internal
......
......@@ -533,7 +533,6 @@ class ChoiceNode : public RegExpNode {
: RegExpNode(zone),
alternatives_(new (zone)
ZoneList<GuardedAlternative>(expected_size, zone)),
table_(nullptr),
not_at_start_(false),
being_calculated_(false) {}
void Accept(NodeVisitor* visitor) override;
......@@ -541,7 +540,6 @@ class ChoiceNode : public RegExpNode {
alternatives()->Add(node, zone());
}
ZoneList<GuardedAlternative>* alternatives() { return alternatives_; }
DispatchTable* GetTable(bool ignore_case);
void Emit(RegExpCompiler* compiler, Trace* trace) override;
int EatsAtLeast(int still_to_find, int budget, bool not_at_start) override;
int EatsAtLeastHelper(int still_to_find, int budget,
......@@ -567,8 +565,8 @@ class ChoiceNode : public RegExpNode {
ZoneList<GuardedAlternative>* alternatives_;
private:
friend class DispatchTableConstructor;
friend class Analysis;
void GenerateGuard(RegExpMacroAssembler* macro_assembler, Guard* guard,
Trace* trace);
int CalculatePreloadCharacters(RegExpCompiler* compiler, int eats_at_least);
......@@ -588,7 +586,7 @@ class ChoiceNode : public RegExpNode {
void EmitChoices(RegExpCompiler* compiler,
AlternativeGenerationList* alt_gens, int first_choice,
Trace* trace, PreloadState* preloads);
DispatchTable* table_;
// If true, this node is never checked at the start of the input.
// Allows a new trace to start with at_start() set to false.
bool not_at_start_;
......
......@@ -598,9 +598,8 @@ Handle<RegExpMatchInfo> RegExp::SetLastMatchInfo(
}
// static
void RegExp::DotPrintForTesting(const char* label, RegExpNode* node,
bool ignore_case) {
DotPrinter::DotPrint(label, node, ignore_case);
void RegExp::DotPrintForTesting(const char* label, RegExpNode* node) {
DotPrinter::DotPrint(label, node);
}
namespace {
......
......@@ -103,8 +103,7 @@ class RegExp final : public AllStatic {
bool is_one_byte);
V8_EXPORT_PRIVATE static void DotPrintForTesting(const char* label,
RegExpNode* node,
bool ignore_case);
RegExpNode* node);
static const int kRegExpTooLargeToOptimize = 20 * KB;
};
......
......@@ -560,9 +560,7 @@ static void Execute(const char* input, bool multiline, bool unicode,
RegExpNode* node = Compile(input, multiline, unicode, is_one_byte, &zone);
USE(node);
#ifdef DEBUG
if (dot_output) {
RegExp::DotPrintForTesting(input, node, false);
}
if (dot_output) RegExp::DotPrintForTesting(input, node);
#endif // DEBUG
}
......@@ -1432,43 +1430,6 @@ TEST(MacroAssembler) {
CHECK_EQ(42, captures[0]);
}
TEST(AddInverseToTable) {
static const int kLimit = 1000;
static const int kRangeCount = 16;
for (int t = 0; t < 10; t++) {
Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
ZoneList<CharacterRange>* ranges =
new(&zone) ZoneList<CharacterRange>(kRangeCount, &zone);
for (int i = 0; i < kRangeCount; i++) {
int from = PseudoRandom(t + 87, i + 25) % kLimit;
int to = from + (PseudoRandom(i + 87, t + 25) % (kLimit / 20));
if (to > kLimit) to = kLimit;
ranges->Add(CharacterRange::Range(from, to), &zone);
}
DispatchTable table(&zone);
DispatchTableConstructor cons(&table, false, &zone);
cons.set_choice_index(0);
cons.AddInverse(ranges);
for (int i = 0; i < kLimit; i++) {
bool is_on = false;
for (int j = 0; !is_on && j < kRangeCount; j++)
is_on = ranges->at(j).Contains(i);
OutSet* set = table.Get(i);
CHECK_EQ(is_on, set->Get(0) == false);
}
}
Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
ZoneList<CharacterRange>* ranges =
new(&zone) ZoneList<CharacterRange>(1, &zone);
ranges->Add(CharacterRange::Range(0xFFF0, 0xFFFE), &zone);
DispatchTable table(&zone);
DispatchTableConstructor cons(&table, false, &zone);
cons.set_choice_index(0);
cons.AddInverse(ranges);
CHECK(!table.Get(0xFFFE)->Get(0));
CHECK(table.Get(0xFFFF)->Get(0));
}
#ifndef V8_INTL_SUPPORT
static uc32 canonicalize(uc32 c) {
unibrow::uchar canon[unibrow::Ecma262Canonicalize::kMaxWidth];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment