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

[maglev] Add ValueRepresentation to Node properties

This allows to easily introduce new nodes with untagged represenation.
It also speeds up the is_untagged_value check.

Bug: v8:7700
Change-Id: Ie391d32ae7742dbad481674de262050c0d564ee6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3581773
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Auto-Submit: Victor Gomes <victorgomes@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79941}
parent 0c9012d9
...@@ -222,7 +222,7 @@ class MaglevGraphBuilder { ...@@ -222,7 +222,7 @@ class MaglevGraphBuilder {
// TODO(victorgomes): Add the representation (Tagged/Untagged) in the // TODO(victorgomes): Add the representation (Tagged/Untagged) in the
// InterpreterFrameState, so that we don't need to derefence a node. // InterpreterFrameState, so that we don't need to derefence a node.
ValueNode* value = current_interpreter_frame_.get(reg); ValueNode* value = current_interpreter_frame_.get(reg);
if (!value->IsUntaggedValue()) return value; if (!value->is_untagged_value()) return value;
if (value->Is<CheckedSmiUntag>()) { if (value->Is<CheckedSmiUntag>()) {
return value->input(0).node(); return value->input(0).node();
} }
...@@ -236,7 +236,7 @@ class MaglevGraphBuilder { ...@@ -236,7 +236,7 @@ class MaglevGraphBuilder {
// TODO(victorgomes): Add the representation (Tagged/Untagged) in the // TODO(victorgomes): Add the representation (Tagged/Untagged) in the
// InterpreterFrameState, so that we don't need to derefence a node. // InterpreterFrameState, so that we don't need to derefence a node.
ValueNode* value = current_interpreter_frame_.get(reg); ValueNode* value = current_interpreter_frame_.get(reg);
if (value->IsUntaggedValue()) return value; if (value->is_untagged_value()) return value;
if (value->Is<CheckedSmiTag>()) return value->input(0).node(); if (value->Is<CheckedSmiTag>()) return value->input(0).node();
// Untag any other value. // Untag any other value.
ValueNode* untagged = AddNewNode<CheckedSmiUntag>({value}); ValueNode* untagged = AddNewNode<CheckedSmiUntag>({value});
......
...@@ -350,7 +350,7 @@ class MergePointInterpreterFrameState { ...@@ -350,7 +350,7 @@ class MergePointInterpreterFrameState {
ValueNode* TagValue(MaglevCompilationUnit& compilation_unit, ValueNode* TagValue(MaglevCompilationUnit& compilation_unit,
ValueNode* value) { ValueNode* value) {
DCHECK(value->IsUntaggedValue()); DCHECK(value->is_untagged_value());
if (value->Is<CheckedSmiUntag>()) { if (value->Is<CheckedSmiUntag>()) {
return value->input(0).node(); return value->input(0).node();
} }
...@@ -375,7 +375,7 @@ class MergePointInterpreterFrameState { ...@@ -375,7 +375,7 @@ class MergePointInterpreterFrameState {
ValueNode* EnsureTagged(MaglevCompilationUnit& compilation_unit, ValueNode* EnsureTagged(MaglevCompilationUnit& compilation_unit,
ValueNode* value) { ValueNode* value) {
if (value->IsUntaggedValue()) return TagValue(compilation_unit, value); if (value->is_untagged_value()) return TagValue(compilation_unit, value);
return value; return value;
} }
...@@ -395,9 +395,7 @@ class MergePointInterpreterFrameState { ...@@ -395,9 +395,7 @@ class MergePointInterpreterFrameState {
// It's possible that merged == unmerged at this point since loop-phis are // It's possible that merged == unmerged at this point since loop-phis are
// not dropped if they are only assigned to themselves in the loop. // not dropped if they are only assigned to themselves in the loop.
DCHECK_EQ(result->owner(), owner); DCHECK_EQ(result->owner(), owner);
if (unmerged->IsUntaggedValue()) { unmerged = EnsureTagged(compilation_unit, unmerged);
unmerged = TagValue(compilation_unit, unmerged);
}
result->set_input(predecessors_so_far_, unmerged); result->set_input(predecessors_so_far_, unmerged);
return result; return result;
} }
......
...@@ -191,6 +191,9 @@ class OpProperties { ...@@ -191,6 +191,9 @@ class OpProperties {
constexpr bool non_memory_side_effects() const { constexpr bool non_memory_side_effects() const {
return kNonMemorySideEffectsBit::decode(bitfield_); return kNonMemorySideEffectsBit::decode(bitfield_);
} }
constexpr bool is_untagged_value() const {
return kUntaggedValueBit::decode(bitfield_);
}
constexpr bool is_pure() const { constexpr bool is_pure() const {
return (bitfield_ | kPureMask) == kPureValue; return (bitfield_ | kPureMask) == kPureValue;
...@@ -222,6 +225,9 @@ class OpProperties { ...@@ -222,6 +225,9 @@ class OpProperties {
static constexpr OpProperties NonMemorySideEffects() { static constexpr OpProperties NonMemorySideEffects() {
return OpProperties(kNonMemorySideEffectsBit::encode(true)); return OpProperties(kNonMemorySideEffectsBit::encode(true));
} }
static constexpr OpProperties UntaggedValue() {
return OpProperties(kUntaggedValueBit::encode(true));
}
static constexpr OpProperties JSCall() { static constexpr OpProperties JSCall() {
return Call() | NonMemorySideEffects() | LazyDeopt(); return Call() | NonMemorySideEffects() | LazyDeopt();
} }
...@@ -239,6 +245,7 @@ class OpProperties { ...@@ -239,6 +245,7 @@ class OpProperties {
using kCanReadBit = kCanLazyDeoptBit::Next<bool, 1>; using kCanReadBit = kCanLazyDeoptBit::Next<bool, 1>;
using kCanWriteBit = kCanReadBit::Next<bool, 1>; using kCanWriteBit = kCanReadBit::Next<bool, 1>;
using kNonMemorySideEffectsBit = kCanWriteBit::Next<bool, 1>; using kNonMemorySideEffectsBit = kCanWriteBit::Next<bool, 1>;
using kUntaggedValueBit = kNonMemorySideEffectsBit::Next<bool, 1>;
static const uint32_t kPureMask = kCanReadBit::kMask | kCanWriteBit::kMask | static const uint32_t kPureMask = kCanReadBit::kMask | kCanWriteBit::kMask |
kNonMemorySideEffectsBit::kMask; kNonMemorySideEffectsBit::kMask;
...@@ -249,7 +256,7 @@ class OpProperties { ...@@ -249,7 +256,7 @@ class OpProperties {
const uint32_t bitfield_; const uint32_t bitfield_;
public: public:
static const size_t kSize = kNonMemorySideEffectsBit::kLastUsedBit + 1; static const size_t kSize = kUntaggedValueBit::kLastUsedBit + 1;
}; };
class ValueLocation { class ValueLocation {
...@@ -766,10 +773,11 @@ class ValueNode : public Node { ...@@ -766,10 +773,11 @@ class ValueNode : public Node {
return compiler::AllocatedOperand::cast(spill_or_hint_); return compiler::AllocatedOperand::cast(spill_or_hint_);
} }
bool IsUntaggedValue() const { bool is_untagged_value() const { return properties().is_untagged_value(); }
// TODO(victorgomes): Make this check faster somehow.
return Is<CheckedSmiUntag>() || Is<Int32AddWithOverflow>() || ValueRepresentation value_representation() const {
Is<Int32Constant>(); return is_untagged_value() ? ValueRepresentation::kUntagged
: ValueRepresentation::kTagged;
} }
protected: protected:
...@@ -966,7 +974,8 @@ class CheckedSmiUntag : public FixedInputValueNodeT<1, CheckedSmiUntag> { ...@@ -966,7 +974,8 @@ class CheckedSmiUntag : public FixedInputValueNodeT<1, CheckedSmiUntag> {
public: public:
explicit CheckedSmiUntag(uint32_t bitfield) : Base(bitfield) {} explicit CheckedSmiUntag(uint32_t bitfield) : Base(bitfield) {}
static constexpr OpProperties kProperties = OpProperties::EagerDeopt(); static constexpr OpProperties kProperties =
OpProperties::EagerDeopt() | OpProperties::UntaggedValue();
Input& input() { return Node::input(0); } Input& input() { return Node::input(0); }
...@@ -982,6 +991,8 @@ class Int32Constant : public FixedInputValueNodeT<0, Int32Constant> { ...@@ -982,6 +991,8 @@ class Int32Constant : public FixedInputValueNodeT<0, Int32Constant> {
explicit Int32Constant(uint32_t bitfield, int32_t value) explicit Int32Constant(uint32_t bitfield, int32_t value)
: Base(bitfield), value_(value) {} : Base(bitfield), value_(value) {}
static constexpr OpProperties kProperties = OpProperties::UntaggedValue();
int32_t value() const { return value_; } int32_t value() const { return value_; }
void AllocateVreg(MaglevVregAllocationState*, const ProcessingState&); void AllocateVreg(MaglevVregAllocationState*, const ProcessingState&);
...@@ -999,7 +1010,8 @@ class Int32AddWithOverflow ...@@ -999,7 +1010,8 @@ class Int32AddWithOverflow
public: public:
explicit Int32AddWithOverflow(uint32_t bitfield) : Base(bitfield) {} explicit Int32AddWithOverflow(uint32_t bitfield) : Base(bitfield) {}
static constexpr OpProperties kProperties = OpProperties::EagerDeopt(); static constexpr OpProperties kProperties =
OpProperties::EagerDeopt() | OpProperties::UntaggedValue();
static constexpr int kLeftIndex = 0; static constexpr int kLeftIndex = 0;
static constexpr int kRightIndex = 1; static constexpr int kRightIndex = 1;
......
...@@ -649,9 +649,7 @@ void StraightForwardRegisterAllocator::SpillAndClearRegisters() { ...@@ -649,9 +649,7 @@ void StraightForwardRegisterAllocator::SpillAndClearRegisters() {
void StraightForwardRegisterAllocator::AllocateSpillSlot(ValueNode* node) { void StraightForwardRegisterAllocator::AllocateSpillSlot(ValueNode* node) {
DCHECK(!node->is_spilled()); DCHECK(!node->is_spilled());
uint32_t free_slot = top_of_stack_++; uint32_t free_slot = top_of_stack_++;
compilation_unit_->push_stack_value_repr(node->IsUntaggedValue() compilation_unit_->push_stack_value_repr(node->value_representation());
? ValueRepresentation::kUntagged
: ValueRepresentation::kTagged);
node->Spill(compiler::AllocatedOperand(compiler::AllocatedOperand::STACK_SLOT, node->Spill(compiler::AllocatedOperand(compiler::AllocatedOperand::STACK_SLOT,
MachineRepresentation::kTagged, MachineRepresentation::kTagged,
free_slot)); free_slot));
......
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