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

[maglev] Create RelationalComparisonNodes

Bug: v8:7700
Change-Id: Idc36a42307b05beefb2ff16e52c9a6c9b7a166f7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3500401Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Auto-Submit: Victor Gomes <victorgomes@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79386}
parent d5c23fda
......@@ -252,8 +252,10 @@ MAGLEV_UNIMPLEMENTED_BYTECODE(Construct)
MAGLEV_UNIMPLEMENTED_BYTECODE(ConstructWithSpread)
MAGLEV_UNIMPLEMENTED_BYTECODE(TestEqual)
MAGLEV_UNIMPLEMENTED_BYTECODE(TestEqualStrict)
void MaglevGraphBuilder::VisitTestLessThan() {
// TestLessThan <src> <slot>
template <typename RelNodeT>
void MaglevGraphBuilder::VisitRelNode() {
// Test[RelationComparison] <src> <slot>
ValueNode* left = LoadRegister(0);
FeedbackSlot slot_index = GetSlotOperand(1);
......@@ -261,14 +263,21 @@ void MaglevGraphBuilder::VisitTestLessThan() {
USE(slot_index); // TODO(v8:7700): Use the feedback info.
ValueNode* node = AddNewNode<LessThan>(
ValueNode* node = AddNewNode<RelNodeT>(
{left, right}, compiler::FeedbackSource{feedback(), slot_index});
SetAccumulator(node);
MarkPossibleSideEffect();
}
MAGLEV_UNIMPLEMENTED_BYTECODE(TestGreaterThan)
MAGLEV_UNIMPLEMENTED_BYTECODE(TestLessThanOrEqual)
MAGLEV_UNIMPLEMENTED_BYTECODE(TestGreaterThanOrEqual)
void MaglevGraphBuilder::VisitTestLessThan() { VisitRelNode<LessThan>(); }
void MaglevGraphBuilder::VisitTestLessThanOrEqual() {
VisitRelNode<LessThanOrEqual>();
}
void MaglevGraphBuilder::VisitTestGreaterThan() { VisitRelNode<GreaterThan>(); }
void MaglevGraphBuilder::VisitTestGreaterThanOrEqual() {
VisitRelNode<GreaterThanOrEqual>();
}
MAGLEV_UNIMPLEMENTED_BYTECODE(TestInstanceOf)
MAGLEV_UNIMPLEMENTED_BYTECODE(TestIn)
MAGLEV_UNIMPLEMENTED_BYTECODE(ToName)
......
......@@ -356,6 +356,9 @@ class MaglevGraphBuilder {
return block;
}
template <typename RelNodeT>
void VisitRelNode();
void MergeIntoFrameState(BasicBlock* block, int target);
void BuildBranchIfTrue(ValueNode* node, int true_target, int false_target);
void BuildBranchIfToBooleanTrue(ValueNode* node, int true_target,
......
......@@ -678,15 +678,18 @@ void Add::GenerateCode(MaglevCodeGenState* code_gen_state,
UNREACHABLE();
}
void LessThan::AllocateVreg(MaglevVregAllocationState* vreg_state,
const ProcessingState& state) {
template <class Derived>
void BinaryWithFeedbackNode<Derived>::AllocateRelationalComparisonVreg(
MaglevVregAllocationState* vreg_state, const ProcessingState& state) {
using D = BinaryOp_WithFeedbackDescriptor;
UseFixed(left_input(), D::GetRegisterParameter(D::kLeft));
UseFixed(right_input(), D::GetRegisterParameter(D::kRight));
DefineAsFixed(vreg_state, this, kReturnRegister0);
}
void LessThan::GenerateCode(MaglevCodeGenState* code_gen_state,
const ProcessingState& state) {
template <class Derived>
void BinaryWithFeedbackNode<Derived>::GenerateRelationalComparisonCode(
MaglevCodeGenState* code_gen_state, const ProcessingState& state) {
using D = BinaryOp_WithFeedbackDescriptor;
DCHECK_EQ(ToRegister(left_input()), D::GetRegisterParameter(D::kLeft));
DCHECK_EQ(ToRegister(right_input()), D::GetRegisterParameter(D::kRight));
......@@ -695,7 +698,59 @@ void LessThan::GenerateCode(MaglevCodeGenState* code_gen_state,
__ Move(D::GetRegisterParameter(D::kFeedbackVector), feedback().vector);
// TODO(jgruber): Implement full handling.
__ CallBuiltin(Builtin::kLessThan_WithFeedback);
switch (this->opcode()) {
case Opcode::kLessThan:
__ CallBuiltin(Builtin::kLessThan_WithFeedback);
break;
case Opcode::kLessThanOrEqual:
__ CallBuiltin(Builtin::kLessThanOrEqual_WithFeedback);
break;
case Opcode::kGreaterThan:
__ CallBuiltin(Builtin::kGreaterThan_WithFeedback);
break;
case Opcode::kGreaterThanOrEqual:
__ CallBuiltin(Builtin::kGreaterThanOrEqual_WithFeedback);
break;
default:
UNREACHABLE();
}
}
void LessThan::AllocateVreg(MaglevVregAllocationState* vreg_state,
const ProcessingState& state) {
Base::AllocateRelationalComparisonVreg(vreg_state, state);
}
void LessThan::GenerateCode(MaglevCodeGenState* code_gen_state,
const ProcessingState& state) {
Base::GenerateRelationalComparisonCode(code_gen_state, state);
}
void LessThanOrEqual::AllocateVreg(MaglevVregAllocationState* vreg_state,
const ProcessingState& state) {
Base::AllocateRelationalComparisonVreg(vreg_state, state);
}
void LessThanOrEqual::GenerateCode(MaglevCodeGenState* code_gen_state,
const ProcessingState& state) {
Base::GenerateRelationalComparisonCode(code_gen_state, state);
}
void GreaterThan::AllocateVreg(MaglevVregAllocationState* vreg_state,
const ProcessingState& state) {
Base::AllocateRelationalComparisonVreg(vreg_state, state);
}
void GreaterThan::GenerateCode(MaglevCodeGenState* code_gen_state,
const ProcessingState& state) {
Base::GenerateRelationalComparisonCode(code_gen_state, state);
}
void GreaterThanOrEqual::AllocateVreg(MaglevVregAllocationState* vreg_state,
const ProcessingState& state) {
Base::AllocateRelationalComparisonVreg(vreg_state, state);
}
void GreaterThanOrEqual::GenerateCode(MaglevCodeGenState* code_gen_state,
const ProcessingState& state) {
Base::GenerateRelationalComparisonCode(code_gen_state, state);
}
void Phi::AllocateVreg(MaglevVregAllocationState* vreg_state,
......
......@@ -40,9 +40,12 @@ class MaglevVregAllocationState;
V(CallProperty) \
V(CallUndefinedReceiver) \
V(Constant) \
V(GreaterThan) \
V(GreaterThanOrEqual) \
V(Increment) \
V(InitialValue) \
V(LessThan) \
V(LessThanOrEqual) \
V(LoadField) \
V(LoadGlobal) \
V(LoadNamedGeneric) \
......@@ -705,6 +708,9 @@ class BinaryWithFeedbackNode : public FixedInputValueNodeT<2, Derived> {
public:
compiler::FeedbackSource feedback() const { return feedback_; }
// The implementation currently calls runtime.
static constexpr OpProperties kProperties = OpProperties::Call();
static constexpr int kLeftIndex = 0;
static constexpr int kRightIndex = 1;
Input& left_input() { return Node::input(kLeftIndex); }
......@@ -715,6 +721,12 @@ class BinaryWithFeedbackNode : public FixedInputValueNodeT<2, Derived> {
const compiler::FeedbackSource& feedback)
: Base(input_count), feedback_(feedback) {}
// Only to be called when Derived is a RelationalComparisonNode.
void AllocateRelationalComparisonVreg(MaglevVregAllocationState*,
const ProcessingState&);
void GenerateRelationalComparisonCode(MaglevCodeGenState*,
const ProcessingState&);
protected:
const compiler::FeedbackSource feedback_;
};
......@@ -1013,8 +1025,42 @@ class LessThan : public BinaryWithFeedbackNode<LessThan> {
LessThan(size_t input_count, const compiler::FeedbackSource& feedback)
: Base(input_count, feedback) {}
// The implementation currently calls runtime.
static constexpr OpProperties kProperties = OpProperties::Call();
void AllocateVreg(MaglevVregAllocationState*, const ProcessingState&);
void GenerateCode(MaglevCodeGenState*, const ProcessingState&);
void PrintParams(std::ostream&, MaglevGraphLabeller*) const {}
};
class LessThanOrEqual : public BinaryWithFeedbackNode<LessThanOrEqual> {
using Base = BinaryWithFeedbackNode<LessThanOrEqual>;
public:
LessThanOrEqual(size_t input_count, const compiler::FeedbackSource& feedback)
: Base(input_count, feedback) {}
void AllocateVreg(MaglevVregAllocationState*, const ProcessingState&);
void GenerateCode(MaglevCodeGenState*, const ProcessingState&);
void PrintParams(std::ostream&, MaglevGraphLabeller*) const {}
};
class GreaterThan : public BinaryWithFeedbackNode<GreaterThan> {
using Base = BinaryWithFeedbackNode<GreaterThan>;
public:
GreaterThan(size_t input_count, const compiler::FeedbackSource& feedback)
: Base(input_count, feedback) {}
void AllocateVreg(MaglevVregAllocationState*, const ProcessingState&);
void GenerateCode(MaglevCodeGenState*, const ProcessingState&);
void PrintParams(std::ostream&, MaglevGraphLabeller*) const {}
};
class GreaterThanOrEqual : public BinaryWithFeedbackNode<GreaterThanOrEqual> {
using Base = BinaryWithFeedbackNode<GreaterThanOrEqual>;
public:
GreaterThanOrEqual(size_t input_count,
const compiler::FeedbackSource& feedback)
: Base(input_count, feedback) {}
void AllocateVreg(MaglevVregAllocationState*, const ProcessingState&);
void GenerateCode(MaglevCodeGenState*, const ProcessingState&);
......
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