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 {
// TODO(victorgomes): Add the representation (Tagged/Untagged) in the
// InterpreterFrameState, so that we don't need to derefence a node.
ValueNode* value = current_interpreter_frame_.get(reg);
if (!value->IsUntaggedValue()) return value;
if (!value->is_untagged_value()) return value;
if (value->Is<CheckedSmiUntag>()) {
return value->input(0).node();
}
......@@ -236,7 +236,7 @@ class MaglevGraphBuilder {
// TODO(victorgomes): Add the representation (Tagged/Untagged) in the
// InterpreterFrameState, so that we don't need to derefence a node.
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();
// Untag any other value.
ValueNode* untagged = AddNewNode<CheckedSmiUntag>({value});
......
......@@ -350,7 +350,7 @@ class MergePointInterpreterFrameState {
ValueNode* TagValue(MaglevCompilationUnit& compilation_unit,
ValueNode* value) {
DCHECK(value->IsUntaggedValue());
DCHECK(value->is_untagged_value());
if (value->Is<CheckedSmiUntag>()) {
return value->input(0).node();
}
......@@ -375,7 +375,7 @@ class MergePointInterpreterFrameState {
ValueNode* EnsureTagged(MaglevCompilationUnit& compilation_unit,
ValueNode* value) {
if (value->IsUntaggedValue()) return TagValue(compilation_unit, value);
if (value->is_untagged_value()) return TagValue(compilation_unit, value);
return value;
}
......@@ -395,9 +395,7 @@ class MergePointInterpreterFrameState {
// 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.
DCHECK_EQ(result->owner(), owner);
if (unmerged->IsUntaggedValue()) {
unmerged = TagValue(compilation_unit, unmerged);
}
unmerged = EnsureTagged(compilation_unit, unmerged);
result->set_input(predecessors_so_far_, unmerged);
return result;
}
......
......@@ -191,6 +191,9 @@ class OpProperties {
constexpr bool non_memory_side_effects() const {
return kNonMemorySideEffectsBit::decode(bitfield_);
}
constexpr bool is_untagged_value() const {
return kUntaggedValueBit::decode(bitfield_);
}
constexpr bool is_pure() const {
return (bitfield_ | kPureMask) == kPureValue;
......@@ -222,6 +225,9 @@ class OpProperties {
static constexpr OpProperties NonMemorySideEffects() {
return OpProperties(kNonMemorySideEffectsBit::encode(true));
}
static constexpr OpProperties UntaggedValue() {
return OpProperties(kUntaggedValueBit::encode(true));
}
static constexpr OpProperties JSCall() {
return Call() | NonMemorySideEffects() | LazyDeopt();
}
......@@ -239,6 +245,7 @@ class OpProperties {
using kCanReadBit = kCanLazyDeoptBit::Next<bool, 1>;
using kCanWriteBit = kCanReadBit::Next<bool, 1>;
using kNonMemorySideEffectsBit = kCanWriteBit::Next<bool, 1>;
using kUntaggedValueBit = kNonMemorySideEffectsBit::Next<bool, 1>;
static const uint32_t kPureMask = kCanReadBit::kMask | kCanWriteBit::kMask |
kNonMemorySideEffectsBit::kMask;
......@@ -249,7 +256,7 @@ class OpProperties {
const uint32_t bitfield_;
public:
static const size_t kSize = kNonMemorySideEffectsBit::kLastUsedBit + 1;
static const size_t kSize = kUntaggedValueBit::kLastUsedBit + 1;
};
class ValueLocation {
......@@ -766,10 +773,11 @@ class ValueNode : public Node {
return compiler::AllocatedOperand::cast(spill_or_hint_);
}
bool IsUntaggedValue() const {
// TODO(victorgomes): Make this check faster somehow.
return Is<CheckedSmiUntag>() || Is<Int32AddWithOverflow>() ||
Is<Int32Constant>();
bool is_untagged_value() const { return properties().is_untagged_value(); }
ValueRepresentation value_representation() const {
return is_untagged_value() ? ValueRepresentation::kUntagged
: ValueRepresentation::kTagged;
}
protected:
......@@ -966,7 +974,8 @@ class CheckedSmiUntag : public FixedInputValueNodeT<1, CheckedSmiUntag> {
public:
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); }
......@@ -982,6 +991,8 @@ class Int32Constant : public FixedInputValueNodeT<0, Int32Constant> {
explicit Int32Constant(uint32_t bitfield, int32_t value)
: Base(bitfield), value_(value) {}
static constexpr OpProperties kProperties = OpProperties::UntaggedValue();
int32_t value() const { return value_; }
void AllocateVreg(MaglevVregAllocationState*, const ProcessingState&);
......@@ -999,7 +1010,8 @@ class Int32AddWithOverflow
public:
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 kRightIndex = 1;
......
......@@ -649,9 +649,7 @@ void StraightForwardRegisterAllocator::SpillAndClearRegisters() {
void StraightForwardRegisterAllocator::AllocateSpillSlot(ValueNode* node) {
DCHECK(!node->is_spilled());
uint32_t free_slot = top_of_stack_++;
compilation_unit_->push_stack_value_repr(node->IsUntaggedValue()
? ValueRepresentation::kUntagged
: ValueRepresentation::kTagged);
compilation_unit_->push_stack_value_repr(node->value_representation());
node->Spill(compiler::AllocatedOperand(compiler::AllocatedOperand::STACK_SLOT,
MachineRepresentation::kTagged,
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