Commit 8faef5af authored by Victor Gomes's avatar Victor Gomes Committed by V8 LUCI CQ

[maglev] Support Switch without fallthrough

Bug: v8:7700
Change-Id: I7dfc1e87b57455cc5b4622a67ac7c27df216c195
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3823126Reviewed-by: 's avatarJakob Linke <jgruber@chromium.org>
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Auto-Submit: Victor Gomes <victorgomes@chromium.org>
Commit-Queue: Jakob Linke <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82336}
parent de02b4c5
......@@ -292,8 +292,10 @@ void MaglevPrintingVisitor::PreProcessGraph(
const BasicBlockRef& target = node->Cast<Switch>()->targets()[i];
AddTargetIfNotNext(targets_, target.block_ptr(), *(block_it + 1));
}
BasicBlock* fallthrough_target = node->Cast<Switch>()->fallthrough();
AddTargetIfNotNext(targets_, fallthrough_target, *(block_it + 1));
if (node->Cast<Switch>()->has_fallthrough()) {
BasicBlock* fallthrough_target = node->Cast<Switch>()->fallthrough();
AddTargetIfNotNext(targets_, fallthrough_target, *(block_it + 1));
}
}
}
DCHECK(std::all_of(targets_.begin(), targets_.end(),
......@@ -534,11 +536,13 @@ void MaglevPrintingVisitor::Process(ControlNode* control_node,
&arrows_starting_here);
}
BasicBlock* fallthrough_target =
control_node->Cast<Switch>()->fallthrough();
has_fallthrough |=
!AddTargetIfNotNext(targets_, fallthrough_target, state.next_block(),
&arrows_starting_here);
if (control_node->Cast<Switch>()->has_fallthrough()) {
BasicBlock* fallthrough_target =
control_node->Cast<Switch>()->fallthrough();
has_fallthrough |=
!AddTargetIfNotNext(targets_, fallthrough_target, state.next_block(),
&arrows_starting_here);
}
PrintVerticalArrows(os_, targets_, arrows_starting_here);
PrintPaddedId(os_, graph_labeller, max_node_id_, control_node, "─");
......
......@@ -3060,7 +3060,11 @@ void Switch::GenerateCode(MaglevCodeGenState* code_gen_state,
}
__ Switch(kScratchRegister, ToRegister(value()), value_base(), labels.get(),
size());
DCHECK_EQ(fallthrough(), state.next_block());
if (has_fallthrough()) {
DCHECK_EQ(fallthrough(), state.next_block());
} else {
__ Trap();
}
}
void Jump::AllocateVreg(MaglevVregAllocationState* vreg_state) {}
......
......@@ -3655,6 +3655,14 @@ class Deopt : public ControlNode {
class Switch : public ConditionalControlNode {
public:
explicit Switch(uint64_t bitfield, int value_base, BasicBlockRef* targets,
int size)
: ConditionalControlNode(bitfield),
value_base_(value_base),
targets_(targets),
size_(size),
fallthrough_() {}
explicit Switch(uint64_t bitfield, int value_base, BasicBlockRef* targets,
int size, BasicBlockRef* fallthrough)
: ConditionalControlNode(bitfield),
......@@ -3667,7 +3675,11 @@ class Switch : public ConditionalControlNode {
const BasicBlockRef* targets() const { return targets_; }
int size() const { return size_; }
BasicBlock* fallthrough() const { return fallthrough_.block_ptr(); }
bool has_fallthrough() const { return fallthrough_.has_value(); }
BasicBlock* fallthrough() const {
DCHECK(has_fallthrough());
return fallthrough_.value().block_ptr();
}
Input& value() { return input(0); }
......@@ -3679,7 +3691,7 @@ class Switch : public ConditionalControlNode {
const int value_base_;
const BasicBlockRef* targets_;
const int size_;
BasicBlockRef fallthrough_;
base::Optional<BasicBlockRef> fallthrough_;
};
class BranchIfRootConstant
......
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