Commit 5f1b06e3 authored by Victor Gomes's avatar Victor Gomes Committed by V8 LUCI CQ

[maglev] Support JumpIf[Not]Null and JumpIf[Not]Undefined

Additionally, the CL creates a BranchIfRootConstant node and updates
JumpIfTrue and JumpIfFalse.

Bug: v8:7700
Change-Id: I7ee98f4b726ffef0f7969231b598d6216b09ccfc
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3769828Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Auto-Submit: Victor Gomes <victorgomes@chromium.org>
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81798}
parent 4e8b60af
...@@ -1794,12 +1794,30 @@ void MaglevGraphBuilder::MergeIntoInlinedReturnFrameState( ...@@ -1794,12 +1794,30 @@ void MaglevGraphBuilder::MergeIntoInlinedReturnFrameState(
} }
} }
void MaglevGraphBuilder::BuildBranchIfRootConstant(ValueNode* node,
int true_target,
int false_target,
RootIndex root_index) {
BasicBlock* block = FinishBlock<BranchIfRootConstant>(
next_offset(), {node}, &jump_targets_[true_target],
&jump_targets_[false_target], root_index);
MergeIntoFrameState(block, iterator_.GetJumpTargetOffset());
}
void MaglevGraphBuilder::BuildBranchIfTrue(ValueNode* node, int true_target, void MaglevGraphBuilder::BuildBranchIfTrue(ValueNode* node, int true_target,
int false_target) { int false_target) {
BasicBlock* block = FinishBlock<BranchIfTrue>(next_offset(), {node}, BuildBranchIfRootConstant(node, true_target, false_target,
&jump_targets_[true_target], RootIndex::kTrueValue);
&jump_targets_[false_target]); }
MergeIntoFrameState(block, iterator_.GetJumpTargetOffset()); void MaglevGraphBuilder::BuildBranchIfNull(ValueNode* node, int true_target,
int false_target) {
BuildBranchIfRootConstant(node, true_target, false_target,
RootIndex::kNullValue);
}
void MaglevGraphBuilder::BuildBranchIfUndefined(ValueNode* node,
int true_target,
int false_target) {
BuildBranchIfRootConstant(node, true_target, false_target,
RootIndex::kUndefinedValue);
} }
void MaglevGraphBuilder::BuildBranchIfToBooleanTrue(ValueNode* node, void MaglevGraphBuilder::BuildBranchIfToBooleanTrue(ValueNode* node,
int true_target, int true_target,
...@@ -1825,10 +1843,22 @@ void MaglevGraphBuilder::VisitJumpIfFalse() { ...@@ -1825,10 +1843,22 @@ void MaglevGraphBuilder::VisitJumpIfFalse() {
BuildBranchIfTrue(GetAccumulatorTagged(), next_offset(), BuildBranchIfTrue(GetAccumulatorTagged(), next_offset(),
iterator_.GetJumpTargetOffset()); iterator_.GetJumpTargetOffset());
} }
MAGLEV_UNIMPLEMENTED_BYTECODE(JumpIfNull) void MaglevGraphBuilder::VisitJumpIfNull() {
MAGLEV_UNIMPLEMENTED_BYTECODE(JumpIfNotNull) BuildBranchIfNull(GetAccumulatorTagged(), iterator_.GetJumpTargetOffset(),
MAGLEV_UNIMPLEMENTED_BYTECODE(JumpIfUndefined) next_offset());
MAGLEV_UNIMPLEMENTED_BYTECODE(JumpIfNotUndefined) }
void MaglevGraphBuilder::VisitJumpIfNotNull() {
BuildBranchIfNull(GetAccumulatorTagged(), next_offset(),
iterator_.GetJumpTargetOffset());
}
void MaglevGraphBuilder::VisitJumpIfUndefined() {
BuildBranchIfUndefined(GetAccumulatorTagged(),
iterator_.GetJumpTargetOffset(), next_offset());
}
void MaglevGraphBuilder::VisitJumpIfNotUndefined() {
BuildBranchIfUndefined(GetAccumulatorTagged(), next_offset(),
iterator_.GetJumpTargetOffset());
}
MAGLEV_UNIMPLEMENTED_BYTECODE(JumpIfUndefinedOrNull) MAGLEV_UNIMPLEMENTED_BYTECODE(JumpIfUndefinedOrNull)
MAGLEV_UNIMPLEMENTED_BYTECODE(JumpIfJSReceiver) MAGLEV_UNIMPLEMENTED_BYTECODE(JumpIfJSReceiver)
MAGLEV_UNIMPLEMENTED_BYTECODE(SwitchOnSmiNoFeedback) MAGLEV_UNIMPLEMENTED_BYTECODE(SwitchOnSmiNoFeedback)
......
...@@ -698,7 +698,12 @@ class MaglevGraphBuilder { ...@@ -698,7 +698,12 @@ class MaglevGraphBuilder {
void MergeDeadIntoFrameState(int target); void MergeDeadIntoFrameState(int target);
void MergeDeadLoopIntoFrameState(int target); void MergeDeadLoopIntoFrameState(int target);
void MergeIntoInlinedReturnFrameState(BasicBlock* block); void MergeIntoInlinedReturnFrameState(BasicBlock* block);
void BuildBranchIfRootConstant(ValueNode* node, int true_target,
int false_target, RootIndex root_index);
void BuildBranchIfTrue(ValueNode* node, int true_target, int false_target); void BuildBranchIfTrue(ValueNode* node, int true_target, int false_target);
void BuildBranchIfNull(ValueNode* node, int true_target, int false_target);
void BuildBranchIfUndefined(ValueNode* node, int true_target,
int false_target);
void BuildBranchIfToBooleanTrue(ValueNode* node, int true_target, void BuildBranchIfToBooleanTrue(ValueNode* node, int true_target,
int false_target); int false_target);
......
...@@ -101,7 +101,7 @@ class MaglevGraphVerifier { ...@@ -101,7 +101,7 @@ class MaglevGraphVerifier {
case Opcode::kCheckedInternalizedString: case Opcode::kCheckedInternalizedString:
// TODO(victorgomes): Can we check that the input is Boolean? // TODO(victorgomes): Can we check that the input is Boolean?
case Opcode::kBranchIfToBooleanTrue: case Opcode::kBranchIfToBooleanTrue:
case Opcode::kBranchIfTrue: case Opcode::kBranchIfRootConstant:
case Opcode::kCheckedFloat64Unbox: case Opcode::kCheckedFloat64Unbox:
case Opcode::kCreateFunctionContext: case Opcode::kCreateFunctionContext:
case Opcode::kCreateClosure: case Opcode::kCreateClosure:
......
...@@ -2117,11 +2117,11 @@ void JumpLoop::GenerateCode(MaglevCodeGenState* code_gen_state, ...@@ -2117,11 +2117,11 @@ void JumpLoop::GenerateCode(MaglevCodeGenState* code_gen_state,
__ jmp(target()->label()); __ jmp(target()->label());
} }
void BranchIfTrue::AllocateVreg(MaglevVregAllocationState* vreg_state) { void BranchIfRootConstant::AllocateVreg(MaglevVregAllocationState* vreg_state) {
UseRegister(condition_input()); UseRegister(condition_input());
} }
void BranchIfTrue::GenerateCode(MaglevCodeGenState* code_gen_state, void BranchIfRootConstant::GenerateCode(MaglevCodeGenState* code_gen_state,
const ProcessingState& state) { const ProcessingState& state) {
Register value = ToRegister(condition_input()); Register value = ToRegister(condition_input());
auto* next_block = state.next_block(); auto* next_block = state.next_block();
...@@ -2130,10 +2130,10 @@ void BranchIfTrue::GenerateCode(MaglevCodeGenState* code_gen_state, ...@@ -2130,10 +2130,10 @@ void BranchIfTrue::GenerateCode(MaglevCodeGenState* code_gen_state,
// over whatever the next block emitted is. // over whatever the next block emitted is.
if (if_false() == next_block) { if (if_false() == next_block) {
// Jump over the false block if true, otherwise fall through into it. // Jump over the false block if true, otherwise fall through into it.
__ JumpIfRoot(value, RootIndex::kTrueValue, if_true()->label()); __ JumpIfRoot(value, root_index(), if_true()->label());
} else { } else {
// Jump to the false block if true. // Jump to the false block if true.
__ JumpIfNotRoot(value, RootIndex::kTrueValue, if_false()->label()); __ JumpIfNotRoot(value, root_index(), if_false()->label());
// Jump to the true block if it's not the next block. // Jump to the true block if it's not the next block.
if (if_true() != next_block) { if (if_true() != next_block) {
__ jmp(if_true()->label()); __ jmp(if_true()->label());
......
...@@ -172,7 +172,7 @@ class CompactInterpreterFrameState; ...@@ -172,7 +172,7 @@ class CompactInterpreterFrameState;
VALUE_NODE_LIST(V) VALUE_NODE_LIST(V)
#define CONDITIONAL_CONTROL_NODE_LIST(V) \ #define CONDITIONAL_CONTROL_NODE_LIST(V) \
V(BranchIfTrue) \ V(BranchIfRootConstant) \
V(BranchIfToBooleanTrue) \ V(BranchIfToBooleanTrue) \
V(BranchIfReferenceCompare) \ V(BranchIfReferenceCompare) \
V(BranchIfInt32Compare) \ V(BranchIfInt32Compare) \
...@@ -2898,19 +2898,25 @@ class Deopt : public ControlNode { ...@@ -2898,19 +2898,25 @@ class Deopt : public ControlNode {
DeoptimizeReason reason_; DeoptimizeReason reason_;
}; };
class BranchIfTrue : public ConditionalControlNodeT<1, BranchIfTrue> { class BranchIfRootConstant
using Base = ConditionalControlNodeT<1, BranchIfTrue>; : public ConditionalControlNodeT<1, BranchIfRootConstant> {
using Base = ConditionalControlNodeT<1, BranchIfRootConstant>;
public: public:
explicit BranchIfTrue(uint64_t bitfield, BasicBlockRef* if_true_refs, explicit BranchIfRootConstant(uint64_t bitfield, BasicBlockRef* if_true_refs,
BasicBlockRef* if_false_refs) BasicBlockRef* if_false_refs,
: Base(bitfield, if_true_refs, if_false_refs) {} RootIndex root_index)
: Base(bitfield, if_true_refs, if_false_refs), root_index_(root_index) {}
RootIndex root_index() { return root_index_; }
Input& condition_input() { return input(0); } Input& condition_input() { return input(0); }
void AllocateVreg(MaglevVregAllocationState*); void AllocateVreg(MaglevVregAllocationState*);
void GenerateCode(MaglevCodeGenState*, const ProcessingState&); void GenerateCode(MaglevCodeGenState*, const ProcessingState&);
void PrintParams(std::ostream&, MaglevGraphLabeller*) const {} void PrintParams(std::ostream&, MaglevGraphLabeller*) const {}
private:
RootIndex root_index_;
}; };
class BranchIfToBooleanTrue class BranchIfToBooleanTrue
......
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