Skip to content

Commit

Permalink
[maglev] Support TestInstanceOf (generic)
Browse files Browse the repository at this point in the history
Bug: v8:7700
Change-Id: I2cfb80046798e77f4392f16ebb8b3e89632d3da4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3762570
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Auto-Submit: Victor Gomes <victorgomes@chromium.org>
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81743}
  • Loading branch information
victorgomes authored and V8 LUCI CQ committed Jul 15, 2022
1 parent 7f9c35d commit 2db0c1c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/maglev/maglev-graph-builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,21 @@ void MaglevGraphBuilder::VisitTestGreaterThanOrEqual() {
VisitCompareOperation<Operation::kGreaterThanOrEqual>();
}

MAGLEV_UNIMPLEMENTED_BYTECODE(TestInstanceOf)
void MaglevGraphBuilder::VisitTestInstanceOf() {
// TestInstanceOf <src> <feedback_slot>
ValueNode* object = LoadRegisterTagged(0);
ValueNode* callable = GetAccumulatorTagged();
FeedbackSlot slot = GetSlotOperand(1);
compiler::FeedbackSource feedback_source{feedback(), slot};

// TODO(victorgomes): Check feedback slot and a do static lookup for
// @@hasInstance.
USE(feedback_source);

ValueNode* context = GetContext();
SetAccumulator(AddNewNode<TestInstanceOf>({context, object, callable}));
}

MAGLEV_UNIMPLEMENTED_BYTECODE(TestIn)
MAGLEV_UNIMPLEMENTED_BYTECODE(ToName)
MAGLEV_UNIMPLEMENTED_BYTECODE(ToNumber)
Expand Down
1 change: 1 addition & 0 deletions src/maglev/maglev-graph-verifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class MaglevGraphVerifier {
case Opcode::kSetNamedGeneric:
case Opcode::kDefineNamedOwnGeneric:
case Opcode::kGetKeyedGeneric:
case Opcode::kTestInstanceOf:
DCHECK_EQ(node->input_count(), 3);
CheckValueInputIs(node, 0, ValueRepresentation::kTagged);
CheckValueInputIs(node, 1, ValueRepresentation::kTagged);
Expand Down
19 changes: 19 additions & 0 deletions src/maglev/maglev-ir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1735,6 +1735,25 @@ void TaggedEqual::GenerateCode(MaglevCodeGenState* code_gen_state,
__ bind(&done);
}

void TestInstanceOf::AllocateVreg(MaglevVregAllocationState* vreg_state) {
using D = CallInterfaceDescriptorFor<Builtin::kInstanceOf>::type;
UseFixed(context(), kContextRegister);
UseFixed(object(), D::GetRegisterParameter(D::kLeft));
UseFixed(callable(), D::GetRegisterParameter(D::kRight));
DefineAsFixed(vreg_state, this, kReturnRegister0);
}
void TestInstanceOf::GenerateCode(MaglevCodeGenState* code_gen_state,
const ProcessingState& state) {
#ifdef DEBUG
using D = CallInterfaceDescriptorFor<Builtin::kInstanceOf>::type;
DCHECK_EQ(ToRegister(context()), kContextRegister);
DCHECK_EQ(ToRegister(object()), D::GetRegisterParameter(D::kLeft));
DCHECK_EQ(ToRegister(callable()), D::GetRegisterParameter(D::kRight));
#endif
__ CallBuiltin(Builtin::kInstanceOf);
code_gen_state->DefineLazyDeoptPoint(lazy_deopt_info());
}

void TestUndetectable::AllocateVreg(MaglevVregAllocationState* vreg_state) {
UseRegister(value());
set_temporaries_needed(1);
Expand Down
19 changes: 19 additions & 0 deletions src/maglev/maglev-ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class CompactInterpreterFrameState;
V(Float64Box) \
V(CheckedFloat64Unbox) \
V(TaggedEqual) \
V(TestInstanceOf) \
V(TestUndetectable) \
CONSTANT_VALUE_NODE_LIST(V) \
INT32_OPERATIONS_NODE_LIST(V) \
Expand Down Expand Up @@ -1557,6 +1558,24 @@ class TaggedEqual : public FixedInputValueNodeT<2, TaggedEqual> {
void PrintParams(std::ostream&, MaglevGraphLabeller*) const {}
};

class TestInstanceOf : public FixedInputValueNodeT<3, TestInstanceOf> {
using Base = FixedInputValueNodeT<3, TestInstanceOf>;

public:
explicit TestInstanceOf(uint64_t bitfield) : Base(bitfield) {}

// The implementation currently calls runtime.
static constexpr OpProperties kProperties = OpProperties::JSCall();

Input& context() { return input(0); }
Input& object() { return input(1); }
Input& callable() { return input(2); }

void AllocateVreg(MaglevVregAllocationState*);
void GenerateCode(MaglevCodeGenState*, const ProcessingState&);
void PrintParams(std::ostream&, MaglevGraphLabeller*) const {}
};

class TestUndetectable : public FixedInputValueNodeT<1, TestUndetectable> {
using Base = FixedInputValueNodeT<1, TestUndetectable>;

Expand Down

0 comments on commit 2db0c1c

Please sign in to comment.