Commit 48eabdcf authored by epertoso's avatar epertoso Committed by Commit bot

[turbofan] Refactor IsSame into NodeProperties.

BUG=

Review-Url: https://codereview.chromium.org/2635243002
Cr-Commit-Position: refs/heads/master@{#42439}
parent 98dbae79
......@@ -108,19 +108,6 @@ JSBuiltinReducer::JSBuiltinReducer(Editor* editor, JSGraph* jsgraph,
namespace {
// TODO(turbofan): Shall we move this to the NodeProperties? Or some (untyped)
// alias analyzer?
bool IsSame(Node* a, Node* b) {
if (a == b) {
return true;
} else if (a->opcode() == IrOpcode::kCheckHeapObject) {
return IsSame(a->InputAt(0), b);
} else if (b->opcode() == IrOpcode::kCheckHeapObject) {
return IsSame(a, b->InputAt(0));
}
return false;
}
MaybeHandle<Map> GetMapWitness(Node* node) {
Node* receiver = NodeProperties::GetValueInput(node, 1);
Node* effect = NodeProperties::GetEffectInput(node);
......@@ -128,7 +115,7 @@ MaybeHandle<Map> GetMapWitness(Node* node) {
// for the {receiver}, and if so use that map for the lowering below.
for (Node* dominator = effect;;) {
if (dominator->opcode() == IrOpcode::kCheckMaps &&
IsSame(dominator->InputAt(0), receiver)) {
NodeProperties::IsSame(dominator->InputAt(0), receiver)) {
ZoneHandleSet<Map> const& maps =
CheckMapsParametersOf(dominator->op()).maps();
return (maps.size() == 1) ? MaybeHandle<Map>(maps[0])
......@@ -914,7 +901,7 @@ bool HasInstanceTypeWitness(Node* receiver, Node* effect,
InstanceType instance_type) {
for (Node* dominator = effect;;) {
if (dominator->opcode() == IrOpcode::kCheckMaps &&
IsSame(dominator->InputAt(0), receiver)) {
NodeProperties::IsSame(dominator->InputAt(0), receiver)) {
ZoneHandleSet<Map> const& maps =
CheckMapsParametersOf(dominator->op()).maps();
// Check if all maps have the given {instance_type}.
......@@ -1621,7 +1608,7 @@ Node* GetStringWitness(Node* node) {
// the lowering below.
for (Node* dominator = effect;;) {
if (dominator->opcode() == IrOpcode::kCheckString &&
IsSame(dominator->InputAt(0), receiver)) {
NodeProperties::IsSame(dominator->InputAt(0), receiver)) {
return dominator;
}
if (dominator->op()->EffectInputCount() != 1) {
......
......@@ -223,19 +223,6 @@ Reduction JSCallReducer::ReduceFunctionPrototypeHasInstance(Node* node) {
namespace {
// TODO(turbofan): Shall we move this to the NodeProperties? Or some (untyped)
// alias analyzer?
bool IsSame(Node* a, Node* b) {
if (a == b) {
return true;
} else if (a->opcode() == IrOpcode::kCheckHeapObject) {
return IsSame(a->InputAt(0), b);
} else if (b->opcode() == IrOpcode::kCheckHeapObject) {
return IsSame(a, b->InputAt(0));
}
return false;
}
// TODO(turbofan): Share with similar functionality in JSInliningHeuristic
// and JSNativeContextSpecialization, i.e. move to NodeProperties helper?!
MaybeHandle<Map> InferReceiverMap(Node* node) {
......@@ -245,7 +232,7 @@ MaybeHandle<Map> InferReceiverMap(Node* node) {
// for the {receiver}, and if so use that map for the lowering below.
for (Node* dominator = effect;;) {
if (dominator->opcode() == IrOpcode::kCheckMaps &&
IsSame(dominator->InputAt(0), receiver)) {
NodeProperties::IsSame(dominator->InputAt(0), receiver)) {
if (dominator->op()->ValueInputCount() == 2) {
HeapObjectMatcher m(dominator->InputAt(1));
if (m.HasValue()) return Handle<Map>::cast(m.Value());
......
......@@ -278,19 +278,6 @@ Node* JSInliner::CreateTailCallerFrameState(Node* node, Node* frame_state) {
namespace {
// TODO(turbofan): Shall we move this to the NodeProperties? Or some (untyped)
// alias analyzer?
bool IsSame(Node* a, Node* b) {
if (a == b) {
return true;
} else if (a->opcode() == IrOpcode::kCheckHeapObject) {
return IsSame(a->InputAt(0), b);
} else if (b->opcode() == IrOpcode::kCheckHeapObject) {
return IsSame(a, b->InputAt(0));
}
return false;
}
// TODO(bmeurer): Unify this with the witness helper functions in the
// js-builtin-reducer.cc once we have a better understanding of the
// map tracking we want to do, and eventually changed the CheckMaps
......@@ -305,7 +292,7 @@ bool IsSame(Node* a, Node* b) {
bool NeedsConvertReceiver(Node* receiver, Node* effect) {
for (Node* dominator = effect;;) {
if (dominator->opcode() == IrOpcode::kCheckMaps &&
IsSame(dominator->InputAt(0), receiver)) {
NodeProperties::IsSame(dominator->InputAt(0), receiver)) {
// Check if all maps have the given {instance_type}.
ZoneHandleSet<Map> const& maps =
CheckMapsParametersOf(dominator->op()).maps();
......
......@@ -312,6 +312,20 @@ void NodeProperties::CollectControlProjections(Node* node, Node** projections,
#endif
}
// static
bool NodeProperties::IsSame(Node* a, Node* b) {
for (;;) {
if (a->opcode() == IrOpcode::kCheckHeapObject) {
a = GetValueInput(a, 0);
continue;
}
if (b->opcode() == IrOpcode::kCheckHeapObject) {
b = GetValueInput(b, 0);
continue;
}
return a == b;
}
}
// static
MaybeHandle<Context> NodeProperties::GetSpecializationContext(
......
......@@ -123,6 +123,9 @@ class V8_EXPORT_PRIVATE NodeProperties final {
// - Switch: [ IfValue, ..., IfDefault ]
static void CollectControlProjections(Node* node, Node** proj, size_t count);
// Checks if two nodes are the same, looking past {CheckHeapObject}.
static bool IsSame(Node* a, Node* b);
// ---------------------------------------------------------------------------
// Context.
......
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